Hi,
This is part of my code using TraverseDecl:
list<const CXXRecordDecl*> allClasses;
void MyClass::HandleTranslationUnit(ASTContext &Context) {
TranslationUnitDecl *D = Context.getTranslationUnitDecl();
// Run Recursive AST Visitor
TraverseDecl(D);
}
bool MyClass::VisitCXXRecordDecl(CXXRecordDecl *Declaration) {
if(!(Declaration->hasDefinition()))
return false;
allClasses.push_back(Declaration);
return true;
}
And I use them in this way:
void MyClass::run(const MatchFinder::MatchResult &Result) {
Context = Result.Context;
…
HandleTranslationUnit(*Context);
if(!allClasses.empty()){
for(list<const CXXRecordDecl*>::const_iterator i = allClasses.begin(); i != allClasses.end(); i++){
const CXXRecordDecl *BaseClass = *i;
…
}
}
}
Well, up to now I have been using this with simple fragments of code, and it was working perfectly. But then, I tested a file with the header “iostream” and:
- First, I got this at the beginning
In file included from /home/pedro/prueba_op.cpp:1:
In file included from /usr/lib/gcc/x86_64-linux-gnu/4.6/…/…/…/…/include/c++/4.6/iostream:40:
In file included from /usr/lib/gcc/x86_64-linux-gnu/4.6/…/…/…/…/include/c++/4.6/ostream:40:
In file included from /usr/lib/gcc/x86_64-linux-gnu/4.6/…/…/…/…/include/c++/4.6/ios:39:
In file included from /usr/lib/gcc/x86_64-linux-gnu/4.6/…/…/…/…/include/c++/4.6/iosfwd:42:
In file included from /usr/lib/gcc/x86_64-linux-gnu/4.6/…/…/…/…/include/c++/4.6/bits/postypes.h:42:
In file included from /usr/lib/gcc/x86_64-linux-gnu/4.6/…/…/…/…/include/c++/4.6/cwchar:46:
/usr/include/wchar.h:40:11: fatal error: ‘stdarg.h’ file not foundinclude <stdarg.h>
This hasn’t been a problem so far, but I was wondering how I can avoid that message.
- Second, when I include this header, the classes in my file are not visited with TraverseDecl, in spite of they are in the same TranslationUnitDecl; it only processes some classes in the header, as _Rep or basic_ios… Does anybody know what can be the problem? Maybe is a detail that I am overlooking, but I’m not able to find the solution.
Thanks in advance,
Pedro.