[cfe-dev] Question about InsertTextBefore() a function decl whose return type is typedef'd.

Yogesh Chobe via cfe-dev cfe-dev at lists.llvm.org
Mon Sep 7 21:54:57 PDT 2015

Hi All,

In the ASTVisitor, when I hit VisitDecl(Decl* d) for a function of
interest, I am inserting some code above that function using
TheRewriter.InsertTextBefore(d->getSourceRange().getBegin(), someString);

This has been working out great for a while, but I hit upon some user code
which has a typedef'd return type. In this case, I don't see anything being
inserted. My hypothesis is that the typedef is expanded at the point where
I am inserting into the AST and when I write the user code back to disk,
the expanded type and my changes are all replaced by the typedef'd symbol.

I tried to do a getLocWithOffset(-1) type of thing to the getBegin() but
that did not help. Is there a way to say insertAfterPreviousLine() kind of
a thing? I am using the 3.5 release version and I could not find an easy
way to get a handle to the line above the function declaration.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20150907/8c68abb0/attachment.html>

More information about the cfe-dev mailing list