clang-tools
10.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. More... | |
void | addComponents (const ComponentVector &Components) |
Add a set of components that we should consider relevant to the container. More... | |
const UsageResult & | getUsages () const |
Accessor for Usages. More... | |
void | addUsage (const Usage &U) |
Adds the Usage if it was not added before. More... | |
const Expr * | getContainerIndexed () const |
Get the container indexed by IndexVar, if any. More... | |
const DeclStmt * | getAliasDecl () const |
Returns the statement declaring the variable created as an alias for the loop element, if any. More... | |
Confidence::Level | getConfidenceLevel () const |
Accessor for ConfidenceLevel. More... | |
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. More... | |
bool | aliasFromForInit () const |
Indicates if the alias declaration came from the init clause of a nested for loop. More... | |
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 283 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 448 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 470 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 483 of file LoopConvertUtils.cpp.
|
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 335 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 330 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 465 of file LoopConvertUtils.cpp.
|
inline |
Returns the statement declaring the variable created as an alias for the loop element, if any.
Definition at line 319 of file LoopConvertUtils.h.
|
inline |
Accessor for ConfidenceLevel.
Definition at line 322 of file LoopConvertUtils.h.
|
inline |
Get the container indexed by IndexVar, if any.
Definition at line 315 of file LoopConvertUtils.h.
|
inline |
Accessor for Usages.
Definition at line 309 of file LoopConvertUtils.h.
References clang::tidy::readability::addUsage().
|
friend |
Definition at line 340 of file LoopConvertUtils.h.