clang-tools 20.0.0git
|
Discover usages of expressions consisting of index or iterator access. More...
#include <LoopConvertUtils.h>
Public Member Functions | |
ForLoopIndexUseVisitor (ASTContext *Context, const VarDecl *IndexVar, const VarDecl *EndVar, const Expr *ContainerExpr, const Expr *ArrayBoundExpr, bool ContainerNeedsDereference) | |
bool | findAndVerifyUsages (const Stmt *Body) |
Finds all uses of IndexVar in Body, placing all usages in Usages, and returns true if IndexVar was only used in a way consistent with a range-based for loop. | |
void | addComponents (const ComponentVector &Components) |
Add a set of components that we should consider relevant to the container. | |
const UsageResult & | getUsages () const |
Accessor for Usages. | |
void | addUsage (const Usage &U) |
Adds the Usage if it was not added before. | |
const Expr * | getContainerIndexed () const |
Get the container indexed by IndexVar, if any. | |
const DeclStmt * | getAliasDecl () const |
Returns the statement declaring the variable created as an alias for the loop element, if any. | |
Confidence::Level | getConfidenceLevel () const |
Accessor for ConfidenceLevel. | |
bool | aliasUseRequired () const |
Indicates if the alias declaration was in a place where it cannot simply be removed but rather replaced with a use of the alias variable. | |
bool | aliasFromForInit () const |
Indicates if the alias declaration came from the init clause of a nested for loop. | |
Friends | |
class | RecursiveASTVisitor< ForLoopIndexUseVisitor > |
Discover usages of expressions consisting of index or iterator access.
Given an index variable, recursively crawls a for loop to discover if the index variable is used in a way consistent with range-based for loop access.
Definition at line 286 of file LoopConvertUtils.h.
clang::tidy::modernize::ForLoopIndexUseVisitor::ForLoopIndexUseVisitor | ( | ASTContext * | Context, |
const VarDecl * | IndexVar, | ||
const VarDecl * | EndVar, | ||
const Expr * | ContainerExpr, | ||
const Expr * | ArrayBoundExpr, | ||
bool | ContainerNeedsDereference | ||
) |
Definition at line 449 of file LoopConvertUtils.cpp.
void clang::tidy::modernize::ForLoopIndexUseVisitor::addComponents | ( | const ComponentVector & | Components | ) |
Add a set of components that we should consider relevant to the container.
Definition at line 469 of file LoopConvertUtils.cpp.
void clang::tidy::modernize::ForLoopIndexUseVisitor::addUsage | ( | const Usage & | U | ) |
Adds the Usage if it was not added before.
Definition at line 482 of file LoopConvertUtils.cpp.
References clang::tidy::modernize::Usage::Range.
|
inline |
Indicates if the alias declaration came from the init clause of a nested for loop.
SourceRanges provided by Clang for DeclStmts in this case need to be adjusted.
Definition at line 338 of file LoopConvertUtils.h.
|
inline |
Indicates if the alias declaration was in a place where it cannot simply be removed but rather replaced with a use of the alias variable.
For example, variables declared in the condition of an if, switch, or for stmt.
Definition at line 333 of file LoopConvertUtils.h.
bool clang::tidy::modernize::ForLoopIndexUseVisitor::findAndVerifyUsages | ( | const Stmt * | Body | ) |
Finds all uses of IndexVar in Body, placing all usages in Usages, and returns true if IndexVar was only used in a way consistent with a range-based for loop.
The general strategy is to reject any DeclRefExprs referencing IndexVar, with the exception of certain acceptable patterns. For arrays, the DeclRefExpr for IndexVar must appear as the index of an ArraySubscriptExpression. Iterator-based loops may dereference IndexVar or call methods through operator-> (builtin or overloaded). Array-like containers may use IndexVar as a parameter to the at() member function and in overloaded operator[].
Definition at line 464 of file LoopConvertUtils.cpp.
|
inline |
Returns the statement declaring the variable created as an alias for the loop element, if any.
Definition at line 322 of file LoopConvertUtils.h.
|
inline |
Accessor for ConfidenceLevel.
Definition at line 325 of file LoopConvertUtils.h.
References clang::tidy::modernize::Confidence::getLevel().
|
inline |
Get the container indexed by IndexVar, if any.
Definition at line 318 of file LoopConvertUtils.h.
|
inline |
Accessor for Usages.
Definition at line 312 of file LoopConvertUtils.h.
|
friend |
Definition at line 338 of file LoopConvertUtils.h.