<div dir="ltr">Hi,<br><div>As a CXXRecordDecl is a DeclContext, you could simply use the iterators you get by calling </div><div>decls_begin and decls_end.</div><div>For more sophisticated way, you could implement some visitor and VisitDeclContext from there.</div><div><br></div><div>Manasij Mukherjee</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Fri, May 22, 2015 at 10:24 PM, Lu Niu <span dir="ltr"><<a href="mailto:qqibrow@gmail.com" target="_blank">qqibrow@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Hi,<div><br></div><div>I am new to clang AST and try to parse a struct like below:</div><div><br></div><div><div>struct Foo {</div><div>    int a;</div><div>    double b;</div><div>};</div></div><div><br></div><div><br></div><div>the ast-dump result is like:</div><div><br></div><div><div>CXXRecordDecl 0x202c768 </home/lniu/ClangCheck/main.cpp:5:1, line:8:1> line:5:8 struct Foo definition</div><div>|-CXXRecordDecl 0x202c880 <col:1, col:8> col:8 implicit struct Foo</div><div>|-FieldDecl 0x202c920 <line:6:5, col:9> col:9 a 'int'</div><div>`-FieldDecl 0x202c978 <line:7:5, col:12> col:12 b 'double'</div></div><div><br></div><div>My question is How to traverse all children FieldDecl from parent CXXRecordDecl? </div><div><br></div><div>I follow the tutorial here <a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__clang.llvm.org_docs_RAVFrontendAction.html&d=AwMFaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=CnzuN65ENJ1H9py9XLiRvC_UQz6u3oG6GUNn7_wosSM&m=TqPuWCZLnY-IO9LafQXkcSpIk762vbbWxET56jjf77Q&s=9gYIUUh9eBetgoGJVhAy58A1YT1jXy3LmcfhmQEMiew&e=" target="_blank">http://clang.llvm.org/docs/RAVFrontendAction.html</a> 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.</div><div><br></div><div>bool VisitCXXRecordDecl(CXXRecordDecl *Declaration) {<br></div><div><br></div><div>for(ChildrenDecl decl : Declaration.getChildren()) {</div><div>// do sth here</div><div>}</div><div><br></div><div>}</div><div><br></div><div>I don't know whether I am on the right path. Any idea is welcome. Thank you!</div><div><br></div><div>Best,</div><div>Lu</div><div><br></div></div>
<br>_______________________________________________<br>
cfe-dev mailing list<br>
<a href="mailto:cfe-dev@cs.uiuc.edu">cfe-dev@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev</a><br>
<br></blockquote></div><br></div>