[cfe-dev] Stmt::getLocEnd() behaviour
Joshua Cranmer
pidgeot18 at gmail.com
Wed Mar 28 13:29:19 PDT 2012
On 3/28/2012 3:00 PM, Robert Ankeney wrote:
> I coupled a
> RecursiveASTVisitor with a rewriter, and when visiting an IfStmt, I
> expected getLocEnd() to point at the end of the if statement. What I
> get instead is somewhere inside the stmt. Is that expected behaviour?
My recollection is that getLocEnd() returns the start of the last token,
not the end of it, which generally means that you have to always do a
scan to find the end of the current token from the location anyways.
That said, considering that braces appear to use the location of the `}'
as the end location, the fact that a statement expression doesn't reset
the end location to the location of the `;' is probably a bug.
> A few more questions:
> How do I find the points inside the if statement to insert braces?
> (after the expression and after the statement)
You can get the location of the then statement as an open location, and
the locEnd (modulo what I said above) as a close location.
> How best to check if the statement within the if is a CompoundStmt?
if (isa<CompoundStmt>(ifstmt.getThen()))
As a final note, I might advise that it's probably better to run the
output through your favorite code prettifier than to compute things like
indentation in a clang pass.
--
Joshua Cranmer
News submodule owner
DXR coauthor
More information about the cfe-dev
mailing list