Make rewriter::inserttext return a bool to indicate if it failed.
Add a RewriteTest::ReplaceStmt method to factor the 'checking for
rewrite failed + emitting diagnostic if so' code.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@46619 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/Rewrite/Rewriter.cpp b/Rewrite/Rewriter.cpp
index 62d0432..9370145 100644
--- a/Rewrite/Rewriter.cpp
+++ b/Rewrite/Rewriter.cpp
@@ -206,12 +206,13 @@
/// InsertText - Insert the specified string at the specified location in the
/// original buffer. This method is only valid on rewritable source
/// locations.
-void Rewriter::InsertText(SourceLocation Loc,
+bool Rewriter::InsertText(SourceLocation Loc,
const char *StrData, unsigned StrLen) {
- assert(isRewritable(Loc) && "Not a rewritable location!");
+ if (!isRewritable(Loc)) return true;
unsigned FileID;
unsigned StartOffs = getLocationOffsetAndFileID(Loc, FileID);
getEditBuffer(FileID).InsertText(StartOffs, StrData, StrLen);
+ return false;
}
/// RemoveText - Remove the specified text region. This method is only valid