diff options
Diffstat (limited to 'contrib/llvm/tools/clang/lib/Rewrite/Rewriter.cpp')
-rw-r--r-- | contrib/llvm/tools/clang/lib/Rewrite/Rewriter.cpp | 20 |
1 files changed, 13 insertions, 7 deletions
diff --git a/contrib/llvm/tools/clang/lib/Rewrite/Rewriter.cpp b/contrib/llvm/tools/clang/lib/Rewrite/Rewriter.cpp index 376678a..92e2b03 100644 --- a/contrib/llvm/tools/clang/lib/Rewrite/Rewriter.cpp +++ b/contrib/llvm/tools/clang/lib/Rewrite/Rewriter.cpp @@ -40,7 +40,7 @@ void RewriteBuffer::RemoveText(unsigned OrigOffset, unsigned Size) { AddReplaceDelta(OrigOffset, -Size); } -void RewriteBuffer::InsertText(unsigned OrigOffset, const llvm::StringRef &Str, +void RewriteBuffer::InsertText(unsigned OrigOffset, llvm::StringRef Str, bool InsertAfter) { // Nothing to insert, exit early. @@ -57,7 +57,7 @@ void RewriteBuffer::InsertText(unsigned OrigOffset, const llvm::StringRef &Str, /// buffer with a new string. This is effectively a combined "remove+insert" /// operation. void RewriteBuffer::ReplaceText(unsigned OrigOffset, unsigned OrigLength, - const llvm::StringRef &NewStr) { + llvm::StringRef NewStr) { unsigned RealOffset = getMappedOffset(OrigOffset, true); Buffer.erase(RealOffset, OrigLength); Buffer.insert(RealOffset, NewStr.begin(), NewStr.end()); @@ -72,7 +72,7 @@ void RewriteBuffer::ReplaceText(unsigned OrigOffset, unsigned OrigLength, /// getRangeSize - Return the size in bytes of the specified range if they /// are in the same file. If not, this returns -1. -int Rewriter::getRangeSize(SourceRange Range) const { +int Rewriter::getRangeSize(const CharSourceRange &Range) const { if (!isRewritable(Range.getBegin()) || !isRewritable(Range.getEnd())) return -1; @@ -97,12 +97,18 @@ int Rewriter::getRangeSize(SourceRange Range) const { // Adjust the end offset to the end of the last token, instead of being the - // start of the last token. - EndOff += Lexer::MeasureTokenLength(Range.getEnd(), *SourceMgr, *LangOpts); + // start of the last token if this is a token range. + if (Range.isTokenRange()) + EndOff += Lexer::MeasureTokenLength(Range.getEnd(), *SourceMgr, *LangOpts); return EndOff-StartOff; } +int Rewriter::getRangeSize(SourceRange Range) const { + return getRangeSize(CharSourceRange::getTokenRange(Range)); +} + + /// getRewrittenText - Return the rewritten form of the text in the specified /// range. If the start or end of the range was unrewritable or if they are /// in different buffers, this returns an empty string. @@ -179,7 +185,7 @@ RewriteBuffer &Rewriter::getEditBuffer(FileID FID) { /// InsertText - Insert the specified string at the specified location in the /// original buffer. -bool Rewriter::InsertText(SourceLocation Loc, const llvm::StringRef &Str, +bool Rewriter::InsertText(SourceLocation Loc, llvm::StringRef Str, bool InsertAfter) { if (!isRewritable(Loc)) return true; FileID FID; @@ -201,7 +207,7 @@ bool Rewriter::RemoveText(SourceLocation Start, unsigned Length) { /// buffer with a new string. This is effectively a combined "remove/insert" /// operation. bool Rewriter::ReplaceText(SourceLocation Start, unsigned OrigLength, - const llvm::StringRef &NewStr) { + llvm::StringRef NewStr) { if (!isRewritable(Start)) return true; FileID StartFileID; unsigned StartOffs = getLocationOffsetAndFileID(Start, StartFileID); |