I'm trying to write a source to source translator using libTooling.
I'm using ASTMatchers to try to find if
statements that don't have curly braces and then use a rewriter to add the braces.
The matcher I'm using is:
ifStmt(unless(hasDescendant(compoundStmt())))
Then I just get the start and end locations, and rewrite the curly braces.
Here's the source code for that:
if (const IfStmt *IfS = Result.Nodes.getNodeAs<clang::IfStmt>("ifStmt")) {
const Stmt *Then = IfS->getThen();
Rewrite.InsertText(Then->getLocStart(), "{", true, true);
Rewrite.InsertText(Then->getLocEnd(),"}",true,true);
Now the problem is that for some reason the end location is always off by 2 characters. Why is this so?