[cfe-dev] Get function body of overwritten functions while traversing AST

Manuel Klimek klimek at google.com
Tue Feb 25 04:31:39 PST 2014


On Mon, Feb 24, 2014 at 2:25 PM, Frime <friedie04 at gmx.de> wrote:

> 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?
>

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


>
> 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.
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20140225/4fad163d/attachment.html>


More information about the cfe-dev mailing list