[cfe-dev] How to traverse all children FieldDecl from parent CXXRecordDecl

Richard Smith richard at metafoo.co.uk
Sun May 24 09:08:30 PDT 2015


On 23 May 2015 6:57 am, "Lu Niu" <qqibrow at gmail.com> wrote:
>
> Hi,
>
> I am new to clang AST and try to parse a struct like below:
>
> struct Foo {
>     int a;
>     double b;
> };
>
>
> the ast-dump result is like:
>
> CXXRecordDecl 0x202c768 </home/lniu/ClangCheck/main.cpp:5:1, line:8:1>
line:5:8 struct Foo definition
> |-CXXRecordDecl 0x202c880 <col:1, col:8> col:8 implicit struct Foo
> |-FieldDecl 0x202c920 <line:6:5, col:9> col:9 a 'int'
> `-FieldDecl 0x202c978 <line:7:5, col:12> col:12 b 'double'
>
> My question is How to traverse all children FieldDecl from parent
CXXRecordDecl?
>
> I follow the tutorial here
http://clang.llvm.org/docs/RAVFrontendAction.html and try to solve this
inside bool VisitCXXRecordDecl(CXXRecordDecl *Declaration) from a
RecursiveASTVisitor<FindNamedClassVisitor>. I am expecting pseudo code like
below but couldn't find the api.
>
> bool VisitCXXRecordDecl(CXXRecordDecl *Declaration) {
>
> for(ChildrenDecl decl : Declaration.getChildren()) {
> // do sth here
> }
>
> }
>
> I don't know whether I am on the right path. Any idea is welcome. Thank
you!

Use RecordDecl::fields.

> Best,
> Lu
>
>
> _______________________________________________
> 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/20150524/7e8f9df4/attachment.html>


More information about the cfe-dev mailing list