aboutsummaryrefslogtreecommitdiff
path: root/clang-tidy/utils
diff options
context:
space:
mode:
authorJonas Toth <jonas.toth@gmail.com>2018-10-05 14:15:19 +0000
committerJonas Toth <jonas.toth@gmail.com>2018-10-05 14:15:19 +0000
commit6bb33f45717cc46ae84ae41b922a534a435437bb (patch)
tree8c6bdce1c8b96231f0dcb0e198eeaae419ee1d63 /clang-tidy/utils
parent4e1ab6ce0c9fe2b50ab7ae30460964ba2e0fd1be (diff)
[clang-tidy] NFC refactor lexer-utils to be usable without ASTContext
Summary: This patch is a small refactoring necessary for 'readability-isolate-declaration' and does not introduce functional changes. It allows to use the utility functions without a full `ASTContext` and requires only the `SourceManager` and the `LangOpts`. Reviewers: alexfh, aaron.ballman, hokein Reviewed By: alexfh Subscribers: nemanjai, xazax.hun, kbarton, cfe-commits Tags: #clang-tools-extra Differential Revision: https://reviews.llvm.org/D52684 git-svn-id: https://llvm.org/svn/llvm-project/clang-tools-extra/trunk@343850 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'clang-tidy/utils')
-rw-r--r--clang-tidy/utils/FixItHintUtils.cpp3
-rw-r--r--clang-tidy/utils/LexerUtils.cpp14
-rw-r--r--clang-tidy/utils/LexerUtils.h4
3 files changed, 9 insertions, 12 deletions
diff --git a/clang-tidy/utils/FixItHintUtils.cpp b/clang-tidy/utils/FixItHintUtils.cpp
index 0627e519..9da93653 100644
--- a/clang-tidy/utils/FixItHintUtils.cpp
+++ b/clang-tidy/utils/FixItHintUtils.cpp
@@ -18,7 +18,8 @@ namespace fixit {
FixItHint changeVarDeclToReference(const VarDecl &Var, ASTContext &Context) {
SourceLocation AmpLocation = Var.getLocation();
- auto Token = utils::lexer::getPreviousToken(Context, AmpLocation);
+ auto Token = utils::lexer::getPreviousToken(
+ AmpLocation, Context.getSourceManager(), Context.getLangOpts());
if (!Token.is(tok::unknown))
AmpLocation = Lexer::getLocForEndOfToken(Token.getLocation(), 0,
Context.getSourceManager(),
diff --git a/clang-tidy/utils/LexerUtils.cpp b/clang-tidy/utils/LexerUtils.cpp
index d0272191..1b52347e 100644
--- a/clang-tidy/utils/LexerUtils.cpp
+++ b/clang-tidy/utils/LexerUtils.cpp
@@ -14,19 +14,15 @@ namespace tidy {
namespace utils {
namespace lexer {
-Token getPreviousToken(const ASTContext &Context, SourceLocation Location,
- bool SkipComments) {
- const auto &SourceManager = Context.getSourceManager();
+Token getPreviousToken(SourceLocation Location, const SourceManager &SM,
+ const LangOptions &LangOpts, bool SkipComments) {
Token Token;
Token.setKind(tok::unknown);
Location = Location.getLocWithOffset(-1);
- auto StartOfFile =
- SourceManager.getLocForStartOfFile(SourceManager.getFileID(Location));
+ auto StartOfFile = SM.getLocForStartOfFile(SM.getFileID(Location));
while (Location != StartOfFile) {
- Location = Lexer::GetBeginningOfToken(Location, SourceManager,
- Context.getLangOpts());
- if (!Lexer::getRawToken(Location, Token, SourceManager,
- Context.getLangOpts()) &&
+ Location = Lexer::GetBeginningOfToken(Location, SM, LangOpts);
+ if (!Lexer::getRawToken(Location, Token, SM, LangOpts) &&
(!SkipComments || !Token.is(tok::comment))) {
break;
}
diff --git a/clang-tidy/utils/LexerUtils.h b/clang-tidy/utils/LexerUtils.h
index f7bcd6f6..0eb5e56e 100644
--- a/clang-tidy/utils/LexerUtils.h
+++ b/clang-tidy/utils/LexerUtils.h
@@ -19,8 +19,8 @@ namespace utils {
namespace lexer {
/// Returns previous token or ``tok::unknown`` if not found.
-Token getPreviousToken(const ASTContext &Context, SourceLocation Location,
- bool SkipComments = true);
+Token getPreviousToken(SourceLocation Location, const SourceManager &SM,
+ const LangOptions &LangOpts, bool SkipComments = true);
} // namespace lexer
} // namespace utils