[cfe-dev] How to get member functions from a cpp file using HandleTopLevelDecl

Jan Bierbaum s3306700 at inf.tu-dresden.de
Fri Aug 20 10:41:47 PDT 2010


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.



More information about the cfe-dev mailing list