Hi
I am using HandleTopLevelDecl function of ASTConsumer to get the names of functions in a file.
The code is working fine and outputs function names with C files, but when i give a cpp file containing class as input, its not printing
any function names
Need help with this problem.
Thanks
Manavender
Hi!
manavender reddy meinte am 20.08.2010 03:47:
The code is working fine and outputs function names with C files, but
when i give a cpp file containing class as input, its not printing
any function names
Are you sure you use functions in this cpp file? If you mean the
classes' methods instead ... those are not at the top level but *inside*
the classes.
In this case you will have to look inside the classes (CXXRecordDecl)
and get their respective methods
CXXRecordDecl::method_iterator
CXXRecordDecl::method_begin()
CXXRecordDecl::method_end()
Regards, Jan.
manavender reddy meinte am 20.08.2010 18:22:
So if i cant use HandleTopLevelDecl, then which what
function in ASTConsumer can i get the information about a class ?
Of course you can use 'HandleTopLevelDecl'. Just check if the current
declaration happens to be a C++ class declaration and if so iterate
through its methods
void HandleTopLevelDecl(DeclGroupRef DG) {
for (DeclGroupRef::iterator i = DG.begin(),
e = DG.end(); i != e; ++i) {
const Decl *D = *i;
if (!isa<CXXRecordDecl>(D))
return;
const CXXRecordDecl *CRD = cast<CXXRecordDecl>(D);
for (CXXRecordDecl::method_iterator
cMeth = CRD->method_begin(),
endMeth = CRD->method_end();
cMeth != endMeth; ++cMeth) {
CXXMethodDecl* mD = *cMeth;
//do something with this method
}
}
Regards, Jan.