Make for-loop initializer detector use post traverse statement
This commit is contained in:
parent
5a2d5ed933
commit
a0b9775f13
@ -58,10 +58,6 @@ bool OperationFinderAstVisitor::dataTraverseStmtPre(clang::Stmt* stmt)
|
|||||||
_op_finder->forLoopEntered();
|
_op_finder->forLoopEntered();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
_checkIfForLoopInitDone(stmt);
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -70,34 +66,15 @@ bool OperationFinderAstVisitor::dataTraverseStmtPost(clang::Stmt* stmt)
|
|||||||
{
|
{
|
||||||
assert(_context);
|
assert(_context);
|
||||||
|
|
||||||
if (clang::dyn_cast<clang::ForStmt>(stmt))
|
if (_loop_init && _loop_init == stmt)
|
||||||
|
{
|
||||||
|
_op_finder->forLoopEntered();
|
||||||
|
_loop_init = nullptr;
|
||||||
|
}
|
||||||
|
else if (clang::dyn_cast<clang::ForStmt>(stmt))
|
||||||
|
{
|
||||||
_op_finder->forLoopExited();
|
_op_finder->forLoopExited();
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void OperationFinderAstVisitor::_checkIfForLoopInitDone(clang::Stmt* stmt)
|
|
||||||
{
|
|
||||||
if (!_loop_init || stmt == _loop_init)
|
|
||||||
return;
|
|
||||||
|
|
||||||
const auto [file, line, column] = resolveLocationsWithLoc(stmt->getEndLoc(), _context->getSourceManager());
|
|
||||||
const auto [for_file, for_line, for_column] = resolveLocationsWithLoc(_loop_init->getEndLoc(), _context->getSourceManager());
|
|
||||||
|
|
||||||
bool is_done = false;
|
|
||||||
|
|
||||||
if (line > for_line)
|
|
||||||
{
|
|
||||||
is_done = true;
|
|
||||||
}
|
|
||||||
else if (line == for_line && column > for_column)
|
|
||||||
{
|
|
||||||
is_done = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (is_done)
|
|
||||||
{
|
|
||||||
_loop_init = nullptr;
|
|
||||||
_op_finder->forLoopEntered();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@ -25,8 +25,6 @@ public:
|
|||||||
bool dataTraverseStmtPost(clang::Stmt* stmt);
|
bool dataTraverseStmtPost(clang::Stmt* stmt);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void _checkIfForLoopInitDone(clang::Stmt* stmt);
|
|
||||||
|
|
||||||
clang::ASTContext* _context;
|
clang::ASTContext* _context;
|
||||||
OperationFinder* _op_finder;
|
OperationFinder* _op_finder;
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user