[cfe-dev] RecursiveASTVisitor::TraverseStmt for UnaryOperator's

Mathieu Baudet mathieu.baudet at gmail.com
Mon Mar 31 09:52:57 PDT 2014


Hi Hugues,

I'm just guessing here, but have you tried to override
shouldUseDataRecursionFor() to always return false?

-- Mathieu

2014-03-28 10:18 GMT+00:00 Hugues de Lassus <hugues.de-lassus at imag.fr>:
> Hi everyone,
>
> I have a RecursiveASTVisitor that overrides the TraverseStmt method and
> store every node in a stack, to be able to know what the last traversed Stmt
> was when visiting a node, like this :
>
> bool MyVisitor::TraverseStmt(Stmt* S) {
>     DEBUG(llvm::errs() << S << "\n";
>                 S->dumpColor());
>
>     NodeStack.push_back(DynTypedNode::create<Stmt>(*S));
>     RecursiveASTVisitor::TraverseStmt(S);
>     NodeStack.pop_back();
>     return true;
> }
>
> I did not find if there was already a way to do that in Clang, but still, it
> works well for almost every node.
> But *almost* means that it does not traverse at least *some* UnaryOperator's
> nodes. It does traverse UO_(Post|Pre)(Inc|Dec) nodes but never does it
> traverse UO_AddrOf nor UO_Deref nodes.
>
> This is the output snippet I get for *array = 3 :
> 0x2a0e7b8
> BinaryOperator 0x2a0e7b8 'int' '='
> |-UnaryOperator 0x2a0e778 'int' lvalue prefix '*'
> | `-ImplicitCastExpr 0x2a0e760 'int *' <ArrayToPointerDecay>
> |   `-DeclRefExpr 0x2a0e738 'int [2]' lvalue Var 0x29e0450 'array' 'int [2]'
> `-IntegerLiteral 0x2a0e798 'int' 3
> 0x2a0e760
> ImplicitCastExpr 0x2a0e760 'int *' <ArrayToPointerDecay>
> `-DeclRefExpr 0x2a0e738 'int [2]' lvalue Var 0x29e0450 'array' 'int [2]'
> 0x2a0e738
> DeclRefExpr 0x2a0e738 'int [2]' lvalue Var 0x29e0450 'array' 'int [2]'
> no uoparent was found for array
> 0x2a0e798
> IntegerLiteral 0x2a0e798 'int' 3
>
> It does show that we "skip" the UO traversal. But for ++x; it does dump the
> UOperator node. Would this be a bug?
>
> I also tried to override TraverseUnaryOperator but my program never went
> through this method, even though I when I commented out TraverseStmt.
>
> Does anyone have an idea why UO_AddrOf and UO_Deref are never traversed ?
>
> --
>
> Hugues de Lassus Saint-Geniès
>
> _______________________________________________
> 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