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::DependencyFinderASTVisitor Class Reference

Class used to determine if an expression is dependent on a variable declared inside of the loop where it would be used. More...

`#include <LoopConvertUtils.h>`

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

## Public Member Functions
| DependencyFinderASTVisitor (const StmtParentMap *StmtParents, const DeclParentMap *DeclParents, const ReplacedVarsMap *ReplacedVars, const clang::Stmt *ContainingStmt)
bool | dependsOnInsideVariable (const clang::Stmt *Body)
| Run the analysis on Body, and return true iff the expression depends on some variable declared within ContainingStmt. More...

## Friends
class | clang::RecursiveASTVisitor< DependencyFinderASTVisitor >

## Detailed Description

Class used to determine if an expression is dependent on a variable declared inside of the loop where it would be used.

Definition at line 103 of file LoopConvertUtils.h.

## Constructor & Destructor Documentation

clang::tidy::modernize::DependencyFinderASTVisitor::DependencyFinderASTVisitor | ( | const StmtParentMap * | StmtParents,
|  | const DeclParentMap * | DeclParents,
|  | const ReplacedVarsMap * | ReplacedVars,
|  | const clang::Stmt * | ContainingStmt
| ) |  |
| inline

Definition at line 106 of file LoopConvertUtils.h.

## Member Function Documentation

bool clang::tidy::modernize::DependencyFinderASTVisitor::dependsOnInsideVariable | ( | const clang::Stmt * | Body | ) |
| inline

Run the analysis on Body, and return true iff the expression depends on some variable declared within ContainingStmt.

This is intended to protect against hoisting the container expression outside of an inner context if part of that expression is declared in that inner context.

For example,

const int N = 10, M = 20;
int arr[N][M];
int getRow();
for (int i = 0; i < M; ++i) {
int k = getRow();
printf("%d:", arr[k][i]);
}

At first glance, this loop looks like it could be changed to

for (int elem : arr[k]) {
int k = getIndex();
printf("%d:", elem);
}

But this is malformed, since `k` is used before it is defined!

In order to avoid this, this class looks at the container expression `arr[k]` and decides whether or not it contains a sub-expression declared within the the loop body.

Definition at line 143 of file LoopConvertUtils.h.

## Friends And Related Function Documentation

friend class clang::RecursiveASTVisitor< DependencyFinderASTVisitor >
| friend

Definition at line 149 of file LoopConvertUtils.h.

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

- LoopConvertUtils.h
- LoopConvertUtils.cpp