<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><br><div><div>On Aug 22, 2010, at 3:54 AM, Ilya Mirsky wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div dir="ltr">Hi all,<br><br>I'm working on a Source-to-source translator, which should introduce various modifications to the original source code.<br>I'm doing the modifications from an ASTConsumer, calling clang/Rewrite/Rewriter methods, and using the different visitors (clang/AST/*Visitor) to access all Decl/Stmt.<br>
The problems I'm having:<br><br><ol><li>Changing function names: if I change the name with FunctionDecl::SetDeclName it doesn't reflect in RewriteBuffer. If I want to use the Rewriter::ReplaceText method I don't know how to determine the exact SourceLocation of the function's identifier.</li></ol></div></blockquote><div><br></div>Decl::getLocation() points at the name of the function. It's not recommended to call SetDeclName at all, since you'll be breaking semantic invariants in the AST.<br><blockquote type="cite"><div dir="ltr"><ol start="2">
<li>Retrieving params value in calls: CallExpr::getArg(i) gives me the Arg Expr, and I can easily get its type, but how can I get it's value? I don't need to evaluate the Expr, just get the corresponding string code.</li></ol></div></blockquote>You can getSourceRange() on the expression and then grab the string representation of the expression from the source buffer.<br><blockquote type="cite"><div dir="ltr"><ol start="3">
<li>Modifying signatures(params list): I'm having difficulties with FucntionDecl::setParams (Kind of a custom defined type), and Rewriter::ReplaceText requires the exact source location of the params list, which I'm unable to determine.</li>
</ol></div></blockquote></div><span class="Apple-tab-span" style="white-space:pre"><div><span class="Apple-tab-span" style="white-space:pre">I</span>t's not recommended to call setParams, since you'll be breaking semantic invariants in the AST. You should be able to use getSourceRange() on the parameters in the list (possibly also relying on the range information in the TypeSourceInfo for the parameters, directly) to compute the source range covering all of the parameters, if you want to rewrite them.</div><div><span class="Apple-tab-span" style="white-space:pre"><br></span></div> </span>- Doug</body></html>