summaryrefslogtreecommitdiffstats
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
commita78c249af6bed83854d28449c4763ad1fd22806e (patch)
treefae17e5712cadc974836eda0c0a04af8dc49f151
parent5fb9746c49d60a51c95a3ffcb183531a64c2ffb8 (diff)
downloadbcm5719-llvm-a78c249af6bed83854d28449c4763ad1fd22806e.tar.gz
bcm5719-llvm-a78c249af6bed83854d28449c4763ad1fd22806e.zip
[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 llvm-svn: 343850
-rw-r--r--clang-tools-extra/clang-tidy/bugprone/ArgumentCommentCheck.cpp5
-rw-r--r--clang-tools-extra/clang-tidy/bugprone/SuspiciousSemicolonCheck.cpp3
-rw-r--r--clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp6
-rw-r--r--clang-tools-extra/clang-tidy/utils/FixItHintUtils.cpp3
-rw-r--r--clang-tools-extra/clang-tidy/utils/LexerUtils.cpp14
-rw-r--r--clang-tools-extra/clang-tidy/utils/LexerUtils.h4
6 files changed, 18 insertions, 17 deletions
diff --git a/clang-tools-extra/clang-tidy/bugprone/ArgumentCommentCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/ArgumentCommentCheck.cpp
index 068f2c57d03..62f30f79b31 100644
--- a/clang-tools-extra/clang-tidy/bugprone/ArgumentCommentCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/ArgumentCommentCheck.cpp
@@ -91,8 +91,9 @@ static std::vector<std::pair<SourceLocation, StringRef>>
getCommentsBeforeLoc(ASTContext *Ctx, SourceLocation Loc) {
std::vector<std::pair<SourceLocation, StringRef>> Comments;
while (Loc.isValid()) {
- clang::Token Tok =
- utils::lexer::getPreviousToken(*Ctx, Loc, /*SkipComments=*/false);
+ clang::Token Tok = utils::lexer::getPreviousToken(
+ Loc, Ctx->getSourceManager(), Ctx->getLangOpts(),
+ /*SkipComments=*/false);
if (Tok.isNot(tok::comment))
break;
Loc = Tok.getLocation();
diff --git a/clang-tools-extra/clang-tidy/bugprone/SuspiciousSemicolonCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/SuspiciousSemicolonCheck.cpp
index ae6f2ee6472..f92fc37f1da 100644
--- a/clang-tools-extra/clang-tidy/bugprone/SuspiciousSemicolonCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/SuspiciousSemicolonCheck.cpp
@@ -40,7 +40,8 @@ void SuspiciousSemicolonCheck::check(const MatchFinder::MatchResult &Result) {
return;
ASTContext &Ctxt = *Result.Context;
- auto Token = utils::lexer::getPreviousToken(Ctxt, LocStart);
+ auto Token = utils::lexer::getPreviousToken(LocStart, Ctxt.getSourceManager(),
+ Ctxt.getLangOpts());
auto &SM = *Result.SourceManager;
unsigned SemicolonLine = SM.getSpellingLineNumber(LocStart);
diff --git a/clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp b/clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp
index 142ac2ed787..82f50a1a8fd 100644
--- a/clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp
+++ b/clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp
@@ -120,12 +120,14 @@ struct IntializerInsertion {
switch (Placement) {
case InitializerPlacement::New:
Location = utils::lexer::getPreviousToken(
- Context, Constructor.getBody()->getBeginLoc())
+ Constructor.getBody()->getBeginLoc(),
+ Context.getSourceManager(), Context.getLangOpts())
.getLocation();
break;
case InitializerPlacement::Before:
Location = utils::lexer::getPreviousToken(
- Context, Where->getSourceRange().getBegin())
+ Where->getSourceRange().getBegin(),
+ Context.getSourceManager(), Context.getLangOpts())
.getLocation();
break;
case InitializerPlacement::After:
diff --git a/clang-tools-extra/clang-tidy/utils/FixItHintUtils.cpp b/clang-tools-extra/clang-tidy/utils/FixItHintUtils.cpp
index 0627e51931e..9da93653dc0 100644
--- a/clang-tools-extra/clang-tidy/utils/FixItHintUtils.cpp
+++ b/clang-tools-extra/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-tools-extra/clang-tidy/utils/LexerUtils.cpp b/clang-tools-extra/clang-tidy/utils/LexerUtils.cpp
index d0272191300..1b52347e45d 100644
--- a/clang-tools-extra/clang-tidy/utils/LexerUtils.cpp
+++ b/clang-tools-extra/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-tools-extra/clang-tidy/utils/LexerUtils.h b/clang-tools-extra/clang-tidy/utils/LexerUtils.h
index f7bcd6f63d2..0eb5e56ef64 100644
--- a/clang-tools-extra/clang-tidy/utils/LexerUtils.h
+++ b/clang-tools-extra/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
OpenPOWER on IntegriCloud