[cfe-dev] accessing struct's members
ret val
retval386 at gmail.com
Tue Oct 25 07:20:39 PDT 2011
I'm a bit confused, these elements I'm iterating over(FieldDecls) cant
also be VarDecls? Also I'm getting much more output than I was
expecting/thought possible from my code. Anyone mind taking a look?
Thanks
bool VisitDecl(Decl *D) {
RecordDecl *recordDecl = dyn_cast<RecordDecl>(D);
if(recordDecl != NULL) {
errs() << "RecordDecl, ";
for(RecordDecl::field_iterator i =
recordDecl->field_begin(); i != recordDecl->field_end(); ++i) {
VarDecl *varDecl = dyn_cast<VarDecl>(*i);
if(varDecl != NULL)
errs() << "VarDecl\n";
else
errs() << "NOT VarDecl\n";
}
}
return true;
}
Output:
RecordDecl, NOT VarDecl
NOT VarDecl
NOT VarDecl
NOT VarDecl
RecordDecl, NOT VarDecl
NOT VarDecl
On Mon, Oct 24, 2011 at 4:18 PM, Eli Friedman <eli.friedman at gmail.com> wrote:
> On Mon, Oct 24, 2011 at 1:04 PM, ret val <retval386 at gmail.com> wrote:
>> I'm using a RecursiveASTVisitor and implementing its VisitDecl()
>> method. Once I find one thats a stuct(by calling isStructureType()),
>> how can I iterate over its members?
>
> RecordDecl::field_begin and RecordDecl::field_end.
>
>> Ive looked for uses of isStructureType() in the sources, expecting to
>> see it before getting its members and so far I haven't found any
>> examples.
>
> Take a look at lib/AST/RecordLayoutBuilder.cpp.
>
> -Eli
>
On Mon, Oct 24, 2011 at 4:17 PM, Joshua Cranmer <Pidgeot18 at gmail.com> wrote:
> On 10/24/2011 3:04 PM, ret val wrote:
>> I'm using a RecursiveASTVisitor and implementing its VisitDecl()
>> method. Once I find one thats a stuct(by calling isStructureType()),
>> how can I iterate over its members?
>
> All structs should be RecordDecls; the iterator for the fields is
> field_begin()/field_end()
>
> --
> Joshua Cranmer
> News submodule owner
> DXR coauthor
>
> _______________________________________________
> 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