clang-tools  6.0.0svn
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:
Inheritance graph
[legend]
Collaboration diagram for clang::tidy::modernize::DependencyFinderASTVisitor:
Collaboration graph
[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 110 of file LoopConvertUtils.h.

Constructor & Destructor Documentation

◆ DependencyFinderASTVisitor()

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

Definition at line 113 of file LoopConvertUtils.h.

Member Function Documentation

◆ dependsOnInsideVariable()

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

Friends And Related Function Documentation

◆ clang::RecursiveASTVisitor< DependencyFinderASTVisitor >

friend class clang::RecursiveASTVisitor< DependencyFinderASTVisitor >
friend

Definition at line 156 of file LoopConvertUtils.h.


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