summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp4
-rw-r--r--clang-tools-extra/clang-tidy/misc/SuspiciousSemicolonCheck.cpp2
-rw-r--r--clang-tools-extra/clang-tidy/utils/FixItHintUtils.cpp2
-rw-r--r--clang-tools-extra/clang-tidy/utils/LexerUtils.cpp6
-rw-r--r--clang-tools-extra/clang-tidy/utils/LexerUtils.h7
5 files changed, 10 insertions, 11 deletions
diff --git a/clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp b/clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp
index 804b2b0579d..16955f8817e 100644
--- a/clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp
+++ b/clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp
@@ -125,12 +125,12 @@ struct IntializerInsertion {
SourceLocation Location;
switch (Placement) {
case InitializerPlacement::New:
- Location = utils::lexer::getPreviousNonCommentToken(
+ Location = utils::lexer::getPreviousToken(
Context, Constructor.getBody()->getLocStart())
.getLocation();
break;
case InitializerPlacement::Before:
- Location = utils::lexer::getPreviousNonCommentToken(
+ Location = utils::lexer::getPreviousToken(
Context, Where->getSourceRange().getBegin())
.getLocation();
break;
diff --git a/clang-tools-extra/clang-tidy/misc/SuspiciousSemicolonCheck.cpp b/clang-tools-extra/clang-tidy/misc/SuspiciousSemicolonCheck.cpp
index 1d26de9eb70..f8bcd214c03 100644
--- a/clang-tools-extra/clang-tidy/misc/SuspiciousSemicolonCheck.cpp
+++ b/clang-tools-extra/clang-tidy/misc/SuspiciousSemicolonCheck.cpp
@@ -40,7 +40,7 @@ void SuspiciousSemicolonCheck::check(const MatchFinder::MatchResult &Result) {
return;
ASTContext &Ctxt = *Result.Context;
- auto Token = utils::lexer::getPreviousNonCommentToken(Ctxt, LocStart);
+ auto Token = utils::lexer::getPreviousToken(Ctxt, LocStart);
auto &SM = *Result.SourceManager;
unsigned SemicolonLine = SM.getSpellingLineNumber(LocStart);
diff --git a/clang-tools-extra/clang-tidy/utils/FixItHintUtils.cpp b/clang-tools-extra/clang-tidy/utils/FixItHintUtils.cpp
index d385cef2248..0627e51931e 100644
--- a/clang-tools-extra/clang-tidy/utils/FixItHintUtils.cpp
+++ b/clang-tools-extra/clang-tidy/utils/FixItHintUtils.cpp
@@ -18,7 +18,7 @@ namespace fixit {
FixItHint changeVarDeclToReference(const VarDecl &Var, ASTContext &Context) {
SourceLocation AmpLocation = Var.getLocation();
- auto Token = utils::lexer::getPreviousNonCommentToken(Context, AmpLocation);
+ auto Token = utils::lexer::getPreviousToken(Context, AmpLocation);
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 f80661d68db..d0272191300 100644
--- a/clang-tools-extra/clang-tidy/utils/LexerUtils.cpp
+++ b/clang-tools-extra/clang-tidy/utils/LexerUtils.cpp
@@ -14,8 +14,8 @@ namespace tidy {
namespace utils {
namespace lexer {
-Token getPreviousNonCommentToken(const ASTContext &Context,
- SourceLocation Location) {
+Token getPreviousToken(const ASTContext &Context, SourceLocation Location,
+ bool SkipComments) {
const auto &SourceManager = Context.getSourceManager();
Token Token;
Token.setKind(tok::unknown);
@@ -27,7 +27,7 @@ Token getPreviousNonCommentToken(const ASTContext &Context,
Context.getLangOpts());
if (!Lexer::getRawToken(Location, Token, SourceManager,
Context.getLangOpts()) &&
- !Token.is(tok::comment)) {
+ (!SkipComments || !Token.is(tok::comment))) {
break;
}
Location = Location.getLocWithOffset(-1);
diff --git a/clang-tools-extra/clang-tidy/utils/LexerUtils.h b/clang-tools-extra/clang-tidy/utils/LexerUtils.h
index f2185927ae3..f7bcd6f63d2 100644
--- a/clang-tools-extra/clang-tidy/utils/LexerUtils.h
+++ b/clang-tools-extra/clang-tidy/utils/LexerUtils.h
@@ -18,10 +18,9 @@ namespace tidy {
namespace utils {
namespace lexer {
-/// Returns previous non-comment token skipping over any comment text or
-/// ``tok::unknown`` if not found.
-Token getPreviousNonCommentToken(const ASTContext &Context,
- SourceLocation Location);
+/// Returns previous token or ``tok::unknown`` if not found.
+Token getPreviousToken(const ASTContext &Context, SourceLocation Location,
+ bool SkipComments = true);
} // namespace lexer
} // namespace utils
OpenPOWER on IntegriCloud