[clang-tools-extra] r294192 - [clang-tidy] getPreviousNonCommentToken -> getPreviousToken

Alexander Kornienko via cfe-commits cfe-commits at lists.llvm.org
Mon Feb 6 07:46:33 PST 2017


Author: alexfh
Date: Mon Feb  6 09:46:33 2017
New Revision: 294192

URL: http://llvm.org/viewvc/llvm-project?rev=294192&view=rev
Log:
[clang-tidy] getPreviousNonCommentToken -> getPreviousToken

Modified:
    clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp
    clang-tools-extra/trunk/clang-tidy/misc/SuspiciousSemicolonCheck.cpp
    clang-tools-extra/trunk/clang-tidy/utils/FixItHintUtils.cpp
    clang-tools-extra/trunk/clang-tidy/utils/LexerUtils.cpp
    clang-tools-extra/trunk/clang-tidy/utils/LexerUtils.h

Modified: clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp?rev=294192&r1=294191&r2=294192&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp Mon Feb  6 09:46:33 2017
@@ -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;

Modified: clang-tools-extra/trunk/clang-tidy/misc/SuspiciousSemicolonCheck.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/misc/SuspiciousSemicolonCheck.cpp?rev=294192&r1=294191&r2=294192&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/misc/SuspiciousSemicolonCheck.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/misc/SuspiciousSemicolonCheck.cpp Mon Feb  6 09:46:33 2017
@@ -40,7 +40,7 @@ void SuspiciousSemicolonCheck::check(con
     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);
 

Modified: clang-tools-extra/trunk/clang-tidy/utils/FixItHintUtils.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/utils/FixItHintUtils.cpp?rev=294192&r1=294191&r2=294192&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/utils/FixItHintUtils.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/utils/FixItHintUtils.cpp Mon Feb  6 09:46:33 2017
@@ -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(),

Modified: clang-tools-extra/trunk/clang-tidy/utils/LexerUtils.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/utils/LexerUtils.cpp?rev=294192&r1=294191&r2=294192&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/utils/LexerUtils.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/utils/LexerUtils.cpp Mon Feb  6 09:46:33 2017
@@ -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 A
                                           Context.getLangOpts());
     if (!Lexer::getRawToken(Location, Token, SourceManager,
                             Context.getLangOpts()) &&
-        !Token.is(tok::comment)) {
+        (!SkipComments || !Token.is(tok::comment))) {
       break;
     }
     Location = Location.getLocWithOffset(-1);

Modified: clang-tools-extra/trunk/clang-tidy/utils/LexerUtils.h
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/utils/LexerUtils.h?rev=294192&r1=294191&r2=294192&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/utils/LexerUtils.h (original)
+++ clang-tools-extra/trunk/clang-tidy/utils/LexerUtils.h Mon Feb  6 09:46:33 2017
@@ -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




More information about the cfe-commits mailing list