diff options
Diffstat (limited to 'lib/Rewrite')
-rw-r--r-- | lib/Rewrite/Rewriter.cpp | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/lib/Rewrite/Rewriter.cpp b/lib/Rewrite/Rewriter.cpp index 281cf6f1be..881399e98e 100644 --- a/lib/Rewrite/Rewriter.cpp +++ b/lib/Rewrite/Rewriter.cpp @@ -170,7 +170,7 @@ int Rewriter::getRangeSize(SourceRange Range, RewriteOptions opts) const { /// in different buffers, this returns an empty string. /// /// Note that this method is not particularly efficient. -std::string Rewriter::getRewrittenText(SourceRange Range) const { +std::string Rewriter::getRewrittenText(CharSourceRange Range) const { if (!isRewritable(Range.getBegin()) || !isRewritable(Range.getEnd())) return {}; @@ -193,7 +193,9 @@ std::string Rewriter::getRewrittenText(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); + if (Range.isTokenRange()) + EndOff += + Lexer::MeasureTokenLength(Range.getEnd(), *SourceMgr, *LangOpts); return std::string(Ptr, Ptr+EndOff-StartOff); } @@ -203,7 +205,8 @@ std::string Rewriter::getRewrittenText(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); + if (Range.isTokenRange()) + EndOff += Lexer::MeasureTokenLength(Range.getEnd(), *SourceMgr, *LangOpts); // Advance the iterators to the right spot, yay for linear time algorithms. RewriteBuffer::iterator Start = RB.begin(); |