[cfe-dev] Getting precise SourceLocation for VarDecl

Himanshu via cfe-dev cfe-dev at lists.llvm.org
Wed Jul 27 10:49:56 PDT 2016


Hi All,

I am working on a rewriter that needs to replace certain variable
declarations. Let me create a simplified example here. Consider the
following DeclStmt:

size_t v, *u = NULL, w = 10;

In my RecursiveASTVisitor I implement VisitVarDecl, and use
the rewriter.replace(SourceRange, ...) API. I create the SourceRange using
VarDecl::getLocStart and getLocEnd. But this leads to the whole DeclStmt
being replaced even if only want to replace u or w. I tried using the
getInnerLocStart, but it leads to the same issue. How should I get the
correct start and end locations for each individual VarDecl?


Thanks!
-
Himanshu
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20160727/4c1243c5/attachment.html>


More information about the cfe-dev mailing list