aboutsummaryrefslogtreecommitdiff
path: root/Rewrite/Rewriter.cpp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2008-01-31 19:51:04 +0000
committerChris Lattner <sabre@nondot.org>2008-01-31 19:51:04 +0000
commitaadaf78d65daef3ac1b45e4ad6136ce859962fe2 (patch)
tree0cb0e0359b64e32b5583be90184008f12d7072cb /Rewrite/Rewriter.cpp
parentf3dd57e5378bcf5fc9f05832e92479a535d9cd8a (diff)
add some helper methods for removing and replacing text, this makes the
rewriter more robust. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@46622 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'Rewrite/Rewriter.cpp')
-rw-r--r--Rewrite/Rewriter.cpp16
1 files changed, 8 insertions, 8 deletions
diff --git a/Rewrite/Rewriter.cpp b/Rewrite/Rewriter.cpp
index 9370145e47..440d1d39fd 100644
--- a/Rewrite/Rewriter.cpp
+++ b/Rewrite/Rewriter.cpp
@@ -204,8 +204,7 @@ RewriteBuffer &Rewriter::getEditBuffer(unsigned FileID) {
}
/// InsertText - Insert the specified string at the specified location in the
-/// original buffer. This method is only valid on rewritable source
-/// locations.
+/// original buffer.
bool Rewriter::InsertText(SourceLocation Loc,
const char *StrData, unsigned StrLen) {
if (!isRewritable(Loc)) return true;
@@ -215,26 +214,27 @@ bool Rewriter::InsertText(SourceLocation Loc,
return false;
}
-/// RemoveText - Remove the specified text region. This method is only valid
-/// on a rewritable source location.
-void Rewriter::RemoveText(SourceLocation Start, unsigned Length) {
- assert(isRewritable(Start) && "Not a rewritable location!");
+/// RemoveText - Remove the specified text region.
+bool Rewriter::RemoveText(SourceLocation Start, unsigned Length) {
+ if (!isRewritable(Start)) return true;
unsigned FileID;
unsigned StartOffs = getLocationOffsetAndFileID(Start, FileID);
getEditBuffer(FileID).RemoveText(StartOffs, Length);
+ return false;
}
/// ReplaceText - This method replaces a range of characters in the input
/// buffer with a new string. This is effectively a combined "remove/insert"
/// operation.
-void Rewriter::ReplaceText(SourceLocation Start, unsigned OrigLength,
+bool Rewriter::ReplaceText(SourceLocation Start, unsigned OrigLength,
const char *NewStr, unsigned NewLength) {
- assert(isRewritable(Start) && "Not a rewritable location!");
+ if (!isRewritable(Start)) return true;
unsigned StartFileID;
unsigned StartOffs = getLocationOffsetAndFileID(Start, StartFileID);
getEditBuffer(StartFileID).ReplaceText(StartOffs, OrigLength,
NewStr, NewLength);
+ return false;
}
/// ReplaceStmt - This replaces a Stmt/Expr with another, using the pretty