[cfe-dev] Get function body of overwritten functions while traversing AST
Frime
friedie04 at gmx.de
Mon Feb 24 05:25:36 PST 2014
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()<<"NO BODY: "<<name;
}
}
}
the clang seems to ignore the redeclaration in the derived classes.. The
result is that for this functions my code prints "NO BODY:..."
I also tried method = method->getMostRecentDecl(); without success..
Any suggestions or code snippets?
Thank you very much!
--
View this message in context: http://clang-developers.42468.n3.nabble.com/Get-function-body-of-overwritten-functions-while-traversing-AST-tp4038044.html
Sent from the Clang Developers mailing list archive at Nabble.com.
More information about the cfe-dev
mailing list