diff options
author | Joel E. Denny <jdenny.ornl@gmail.com> | 2019-07-06 02:55:06 +0000 |
---|---|---|
committer | Joel E. Denny <jdenny.ornl@gmail.com> | 2019-07-06 02:55:06 +0000 |
commit | 44d8911714132c985b74ed6e0835c9dfbeff3edc (patch) | |
tree | b53f9a8f1afeffc11d0129151c304945b66ff361 /lib/Rewrite | |
parent | 5d92f4b318e5974b1a23f13f0f8c4ec5e5cc1f3c (diff) | |
download | clang-44d8911714132c985b74ed6e0835c9dfbeff3edc.tar.gz |
[Rewrite] Extend to further accept CharSourceRange
Some Rewrite functions are already overloaded to accept
CharSourceRange, and this extends others in the same manner. I'm
calling these in code that's not ready to upstream, but I figure they
might be useful to others in the meantime.
Reviewed By: jdoerfert
Differential Revision: https://reviews.llvm.org/D61467
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@365258 91177308-0d34-0410-b5e6-96231b3b80d8
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(); |