clang-tools 3.8.0

- Main Page
- Namespaces
- Classes
- Files

- Class List
- Class Index
- Class Hierarchy
- Class Members

Public Member Functions | Friends | List of all members
clang::tidy::modernize::ForLoopIndexUseVisitor Class Reference

Discover usages of expressions consisting of index or iterator access. More...

`#include <LoopConvertUtils.h>`

Inheritance diagram for clang::tidy::modernize::ForLoopIndexUseVisitor:
[legend]
Collaboration diagram for clang::tidy::modernize::ForLoopIndexUseVisitor:
[legend]

## 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 >

## Detailed Description

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 277 of file LoopConvertUtils.h.

## Constructor & Destructor Documentation

clang::tidy::modernize::ForLoopIndexUseVisitor::ForLoopIndexUseVisitor | ( | ASTContext * | Context,
|  | const VarDecl * | IndexVar,
|  | const VarDecl * | EndVar,
|  | const Expr * | ContainerExpr,
|  | const Expr * | ArrayBoundExpr,
|  | bool | ContainerNeedsDereference
| ) |  |

Definition at line 436 of file LoopConvertUtils.cpp.

## Member Function Documentation

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 458 of file LoopConvertUtils.cpp.

Referenced by clang::tidy::modernize::LoopConvertCheck::check().

void clang::tidy::modernize::ForLoopIndexUseVisitor::addUsage | ( | const Usage & | U | ) |

Adds the Usage if it was not added before.

Definition at line 471 of file LoopConvertUtils.cpp.

References clang::tidy::modernize::Usage::Range.

bool clang::tidy::modernize::ForLoopIndexUseVisitor::aliasFromForInit | ( |  | ) | const
| 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 329 of file LoopConvertUtils.h.

Referenced by clang::tidy::modernize::LoopConvertCheck::check().

bool clang::tidy::modernize::ForLoopIndexUseVisitor::aliasUseRequired | ( |  | ) | const
| 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 324 of file LoopConvertUtils.h.

Referenced by clang::tidy::modernize::LoopConvertCheck::check().

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 453 of file LoopConvertUtils.cpp.

Referenced by clang::tidy::modernize::LoopConvertCheck::check().

const DeclStmt* clang::tidy::modernize::ForLoopIndexUseVisitor::getAliasDecl | ( |  | ) | const
| inline

Returns the statement declaring the variable created as an alias for the loop element, if any.

Definition at line 313 of file LoopConvertUtils.h.

Referenced by clang::tidy::modernize::LoopConvertCheck::check().

Confidence::Level clang::tidy::modernize::ForLoopIndexUseVisitor::getConfidenceLevel | ( |  | ) | const
| inline

Accessor for ConfidenceLevel.

Definition at line 316 of file LoopConvertUtils.h.

References clang::tidy::modernize::Confidence::getLevel().

Referenced by clang::tidy::modernize::LoopConvertCheck::check().

const Expr* clang::tidy::modernize::ForLoopIndexUseVisitor::getContainerIndexed | ( |  | ) | const
| inline

Get the container indexed by IndexVar, if any.

Definition at line 309 of file LoopConvertUtils.h.

Referenced by clang::tidy::modernize::LoopConvertCheck::check().

const UsageResult& clang::tidy::modernize::ForLoopIndexUseVisitor::getUsages | ( |  | ) | const
| inline

Accessor for Usages.

Definition at line 303 of file LoopConvertUtils.h.

Referenced by clang::tidy::modernize::LoopConvertCheck::check().

## Friends And Related Function Documentation

friend class RecursiveASTVisitor< ForLoopIndexUseVisitor >
| friend

Definition at line 334 of file LoopConvertUtils.h.

The documentation for this class was generated from the following files:

- LoopConvertUtils.h
- LoopConvertUtils.cpp