[cfe-dev] check an AST node's parent node ?
Jordan Rose
jordan_rose at apple.com
Tue Jan 8 09:31:39 PST 2013
Careful with this; the body of a for-statement is also within the for statement:
for (int i = 0; i < 10; ++i) {
++i, --i;
}
Not familiar with the RecursiveASTVisitor traversal, so I can't tell you exactly how to do it. Maybe you already got this correct.
Jordan
On Jan 8, 2013, at 0:10 , kevinlynx <kevinlynx at gmail.com> wrote:
> Thanks, I use TraverseForStmt to solve this problem. And this makes me know TraverseXXX methods better.
>
>
> ------------------ Original ------------------
> From: "Philip Craig"<philipjcraig at gmail.com>;
> Date: Tue, Jan 8, 2013 03:47 PM
> To: "kevinlynx"<kevinlynx at gmail.com>;
> Cc: "cfe-dev"<cfe-dev at cs.uiuc.edu>;
> Subject: Re: [cfe-dev] check an AST node's parent node ?
>
> 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
> >
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20130108/5244d9f6/attachment.html>
More information about the cfe-dev
mailing list