[cfe-dev] Iterating over a CFGBlock excluding subexpressions
Stefan Schulze Frielinghaus via cfe-dev
cfe-dev at lists.llvm.org
Mon Mar 16 09:13:37 PDT 2020
Hi all,
Is there some way to iterate over a CFGBlock excluding subexpressions?
Currently I iterate over a CFGBlock as e.g.
const CFGBlock *block;
/* ... */
for (const auto &I : *block) {
if (Optional<CFGStmt> S = I.getAs<CFGStmt>())
foo(const_cast<Stmt*>(S->getStmt()));
}
where function foo *recursively* descends into statements. This has the
drawback that I visit some (sub)expressions twice: one time via the loop and
another time by recursively descending into subexpressions via function foo.
For example, a CFGBlock for a single statement e1=e2 looks as follows:
<begin> (e2) (e1) (e1=e2) <end>
Therefore, I would first call foo for e2, then for e1, and in the end for e1=e2
where I would recursively call foo for e1 and e2 again. Although they have been
visited previously.
Maybe this is not the supposed way to iterate over a CFGBlock?
Cheers,
Stefan
More information about the cfe-dev
mailing list