[cfe-dev] TraverseDecl: a problem with a header
Pedro Delgado Perez
pedro.delgadoperez at mail.uca.es
Tue Jan 28 01:07:31 PST 2014
Hi,
As I was already suspecting, I overlooked something:
bool MyClass::VisitCXXRecordDecl(CXXRecordDecl *Declaration) {
if(!(Declaration->hasDefinition()))
return false;
allClasses.push_back(Declaration);
return true;
}
I was returning false in this method, so it stopped traversing the tree. Sorry for the mistake.
However, by the way, I am still interested in knowing how can I fix the problem of the missing header.
Pedro.
El día 27 ene 2014 14:04, Pedro Delgado Perez <pedro.delgadoperez at mail.uca.es> escribió:
> 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:
>
> 1. 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 found
>> # include <stdarg.h>
>>
>
> This hasn't been a problem so far, but I was wondering how I can avoid that message.
>
> 2. 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.
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20140128/722d7863/attachment.html>
More information about the cfe-dev
mailing list