[cfe-dev] Unable to parse a class

Sandra Kupfer sandra at hocobo.com
Fri Jan 24 10:55:17 PST 2014


I am trying to parse the following in a .cpp file:

class Foo
{
public:

Foo* foo( Foo* ptr )
{
Foo local = *ptr;
return &local;
}
};


int main( int argc, char** argv )
{
Foo f;
        Foo* fPtr = f.foo( &f );
return 0;
}

I have created a CompilerInstance as follows:

    CompilerInstance compilerInstance;

    LangOptions languageOptions;
    languageOptions.CPlusPlus = 1;

    CompilerInvocation compilerInvocation;
    compilerInvocation.setLangDefaults( languageOptions, IK_CXX );
    compilerInstance.setInvocation( &compilerInvocation );


In my RecursiveASTVisitor, I have overloaded the following:

    bool VisitCXXRecordDecl( CXXRecordDecl* recordPtr )
    {
        return true;
    }

    bool VisitCXXMethodDecl( CXXMethodDecl* methodPtr )
    {
        return true;
    }

    bool VisitFunctionDecl( FunctionDecl *f )

    {
        return true;
    }

When traversing the AST, VisitFunctionDecl gets called for the main
function, but VisitCXXRecordDecl and VisitCXXMethodDecl never get
called. Does anyone know why they are not getting called and/or how to
get them to be called?


Thanks,

Sandra
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20140124/05c4c96a/attachment.html>


More information about the cfe-dev mailing list