From aadaf78d65daef3ac1b45e4ad6136ce859962fe2 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Thu, 31 Jan 2008 19:51:04 +0000 Subject: 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 --- Rewrite/Rewriter.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'Rewrite/Rewriter.cpp') 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 -- cgit v1.2.3-18-g5258