Get function body of overwritten functions while traversing AST

Hi folks!

I'm using libclang for parsing C++ Code. The goal is to cut out the
implementation of functions which i need for roundtrip engineering in a Code
Generator. My code works perfectly for functions that are not overwritten by
subclasses. But if i derive Interfaces, the decl->hasBody() function returns
false. So how do i get the implementaion of overwritten functions?

So here is my current code:

// overwritten function in a Subclass of RecursiveASTVisitor
bool FindNamedClassVisitor::VisitDecl(Decl *decl)
{
if(const CXXMethodDecl* method = dyn_cast<CXXMethodDecl>(decl))
{
    FullSourceLoc FullLocation = Context->getFullLoc(method->getLocStart());
    if (FullLocation.isValid()&& !FullLocation.isInSystemHeader())
    {
        QString name =
QString::fromStdString(method->getParent()->getNameAsString()) + "::" +
QString::fromStdString(method->getNameAsString());
        if(decl->hasBody())
        {
            QString impl =
QString::fromStdString(decl2str(decl->getSourceRange()));

            hash.insert(name, impl);
            qDebug()<<name;
        }
        else
        {
            qDebug()&lt;&lt;&quot;NO BODY: &quot;&lt;&lt;name;
        }
    }
}

the clang seems to ignore the redeclaration in the derived classes.. The
result is that for this functions my code prints &quot;NO BODY:...&quot;

I also tried method = method->getMostRecentDecl(); without success..

Any suggestions or code snippets?

Thank you very much!

Hi folks!

I'm using libclang for parsing C++ Code. The goal is to cut out the
implementation of functions which i need for roundtrip engineering in a
Code
Generator. My code works perfectly for functions that are not overwritten
by
subclasses. But if i derive Interfaces, the decl->hasBody() function
returns
false. So how do i get the implementaion of overwritten functions?

So here is my current code:

// overwritten function in a Subclass of RecursiveASTVisitor
bool FindNamedClassVisitor::VisitDecl(Decl *decl)
{
if(const CXXMethodDecl* method = dyn_cast<CXXMethodDecl>(decl))
{
    FullSourceLoc FullLocation =
Context->getFullLoc(method->getLocStart());
    if (FullLocation.isValid()&& !FullLocation.isInSystemHeader())
    {
        QString name =
QString::fromStdString(method->getParent()->getNameAsString()) + "::" +
QString::fromStdString(method->getNameAsString());
        if(decl->hasBody())
        {
            QString impl =
QString::fromStdString(decl2str(decl->getSourceRange()));

            hash.insert(name, impl);
            qDebug()<<name;
        }
        else
        {
            qDebug()&lt;&lt;&quot;NO BODY: &quot;&lt;&lt;name;
        }
    }
}

the clang seems to ignore the redeclaration in the derived classes.. The
result is that for this functions my code prints &quot;NO BODY:...&quot;

I also tried method = method->getMostRecentDecl(); without success..

Any suggestions or code snippets?

Can you give an example of code you're trying to run it over?