summaryrefslogtreecommitdiffstats
path: root/clang/lib/Tooling/FixIt.cpp
diff options
context:
space:
mode:
authorYitzhak Mandelbaum <yitzhakm@google.com>2019-03-13 19:48:51 +0000
committerYitzhak Mandelbaum <yitzhakm@google.com>2019-03-13 19:48:51 +0000
commit60a4163f6d442e2c312bb88f5c219f0ac58daf0f (patch)
tree74ec039ab35b6ac0842288c561377042cf28f721 /clang/lib/Tooling/FixIt.cpp
parent0253620f891086458e1acc51d691d324e1a50388 (diff)
downloadbcm5719-llvm-60a4163f6d442e2c312bb88f5c219f0ac58daf0f.tar.gz
bcm5719-llvm-60a4163f6d442e2c312bb88f5c219f0ac58daf0f.zip
[LibTooling] Add retrieval of extended AST-node source to FixIt library
Summary: Introduces variants of `getText` and `getSourceRange` that extract the source text of an AST node potentially with a trailing token. Some of the new functions manipulate `CharSourceRange`s, rather than `SourceRange`s, because they document and dynamically enforce their type. So, this revision also updates the corresponding existing FixIt functions to manipulate `CharSourceRange`s. This change is not strictly necessary, but seems like the correct choice, to keep the API self-consistent. This revision is the first in a series intended to improve the abstractions available to users for writing source-to-source transformations. A full discussion of the end goal can be found on the cfe-dev list with subject "[RFC] Easier source-to-source transformations with clang tooling". Reviewers: ilya-biryukov Reviewed By: ilya-biryukov Subscribers: kimgr, riccibruno, JonasToth, jdoerfert, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D58556 llvm-svn: 356095
Diffstat (limited to 'clang/lib/Tooling/FixIt.cpp')
-rw-r--r--clang/lib/Tooling/FixIt.cpp16
1 files changed, 12 insertions, 4 deletions
diff --git a/clang/lib/Tooling/FixIt.cpp b/clang/lib/Tooling/FixIt.cpp
index c828c18871f..ca12a5642a1 100644
--- a/clang/lib/Tooling/FixIt.cpp
+++ b/clang/lib/Tooling/FixIt.cpp
@@ -18,12 +18,20 @@ namespace tooling {
namespace fixit {
namespace internal {
-StringRef getText(SourceRange Range, const ASTContext &Context) {
- return Lexer::getSourceText(CharSourceRange::getTokenRange(Range),
- Context.getSourceManager(),
+StringRef getText(CharSourceRange Range, const ASTContext &Context) {
+ return Lexer::getSourceText(Range, Context.getSourceManager(),
Context.getLangOpts());
}
-} // end namespace internal
+
+CharSourceRange maybeExtendRange(CharSourceRange Range, tok::TokenKind Next,
+ ASTContext &Context) {
+ Optional<Token> Tok = Lexer::findNextToken(
+ Range.getEnd(), Context.getSourceManager(), Context.getLangOpts());
+ if (!Tok || !Tok->is(Next))
+ return Range;
+ return CharSourceRange::getTokenRange(Range.getBegin(), Tok->getLocation());
+}
+} // namespace internal
} // end namespace fixit
} // end namespace tooling
OpenPOWER on IntegriCloud