[cfe-dev] behaviour of EvaluatedExprVisitor vs. StmtVisitor

Caitlin Sadowski supertri at google.com
Tue Aug 16 16:11:20 PDT 2011


I am trying to visit each expression inside of a CFGBlock exactly
once. To do this, I iterate through the statements in a block, and
then call a visitor on each statement.

    for (CFGBlock::const_iterator I = CurrBlock->begin(), E = CurrBlock->end();
         I != E; ++I) {
      if (const CFGStmt *CfgStmt = dyn_cast<CFGStmt>(&*I)) {
        MyVisitor.Visit(CfgStmt->getStmt());
      }
    }

However, I have been having some strange behaviour. When MyVisitor is
a subclass of EvaluatedExprVisitor<MyVisitor>, I end up seeing some
DeclRefExprs multiple times. In contrast, when MyVisitor is a subclass
of StmtVisitor<MyVisitor>, I see the DeclRefExprs just once. Is this
expected behaviour?

For a more specific example, it looks like when visiting the CFGBlocks
inside this function:

void myFunction() {
  int x = y;
}

with EvaluatedExprVisitor<MyVisitor>, I visit the DeclRefExpr for y three times.

Cheers,

Caitlin



More information about the cfe-dev mailing list