[cfe-dev] How do i use TraverseXYZ such as TraverseRecordDecl?
Adam Smalin
acidzombie24 at gmail.com
Wed Jun 22 10:12:07 PDT 2011
Using this as my input file
struct AA {
int a, b, c;
};
void funcAZ() {}
int main(){
struct AA aa;
int a=1;
}
I am able to print out the functions and the int field a, b, c. However i
decided to use TraverseFieldDecl and i stepped through it to see what it
did. I'm confused by it
How do i use TraverseFieldDecl to call a function which i can run the code
marked with /*thisline*/ ?
class PrintFunctionsConsumer : public ASTConsumer, public
RecursiveASTVisitor<PrintFunctionsConsumer> {
public:
virtual void HandleTopLevelDecl(DeclGroupRef DG) {
for (DeclGroupRef::iterator i = DG.begin(), e = DG.end(); i != e;
++i) {
Decl *D = *i;
if (const NamedDecl *ND = dyn_cast<NamedDecl>(D)){
llvm::errs() << "top-level-decl: \"" <<
ND->getNameAsString() << "\"\n";
}
//this->TraverseFieldDecl(D);
if (auto *ND = dyn_cast_or_null<RecordDecl>(D)){
/*!!!!!!!!*/ this->TraverseRecordDecl(ND);
for(auto c = ND->decls_begin(); c!=ND->decls_end(); ++c){
auto v = *c;
/*thisline*/ v=v;
if(const FieldDecl*f = dyn_cast<FieldDecl>(v)){
//v->getName
llvm::errs() << "field: " << f->getName() << "\n";
}
}
}
}
}
};
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20110622/77042726/attachment.html>
More information about the cfe-dev
mailing list