[cfe-dev] behaviour of EvaluatedExprVisitor vs. StmtVisitor

Ted Kremenek kremenek at apple.com
Tue Aug 16 16:24:06 PDT 2011


EvaluatedExprVisitor does a recursive visit of an expression:

/// \begin Given a potentially-evaluated expression, this visitor visits all
/// of its potentially-evaluated subexpressions, recursively.

The CFG is linearized, which means every expression appears in the CFG.   There are three expressions in the CFG: the reference to 'y', and implicit lvalue-to-rvalue cast around 'y', and the initialization of 'x'.  The latter two have the reference to 'y' as a nested expression.  This means if you visit each one, you will see 'y' three times.

On Aug 16, 2011, at 4:11 PM, Caitlin Sadowski wrote:

> 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
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev




More information about the cfe-dev mailing list