[cfe-dev] check an AST node's parent node ?

Philip Craig philipjcraig at gmail.com
Mon Jan 7 23:47:47 PST 2013


On 8 January 2013 16:48, kevinlynx <kevinlynx at gmail.com> wrote:
> In my coding standard checking tool, it limits comma expression usage,
> except in a for statment, i.e:
>
>     x++, x+=1; // this will be marked as invalid usage
>     for (x = 0, y = 0; ...) // but this comma expression is valid
>
> I can implement `VisitBinComma`, this function will be called when parsed
> comma expression. But how to know if this comma expression is in a for
> statment ?

The simplest way is to implement TraverseForStmt, and set a flag to
indicate you are within a for statement.

Another option may be to use a ParentMap
(http://clang.llvm.org/doxygen/classclang_1_1ParentMap.html). I
haven't experimented with it yet though.

>
> Thanks.
>
>
> _______________________________________________
> 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