JonasToth created this revision. JonasToth added reviewers: alexfh, aaron.ballman, hokein. Herald added subscribers: cfe-commits, kbarton, xazax.hun, nemanjai. JonasToth added a project: clang-tools-extra.
This patch is a small refactoring necessary for 'readability-isolate-declaration' and does not introduce functional changes. Repository: rCTE Clang Tools Extra https://reviews.llvm.org/D52684 Files: clang-tidy/bugprone/ArgumentCommentCheck.cpp clang-tidy/bugprone/SuspiciousSemicolonCheck.cpp clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp clang-tidy/utils/LexerUtils.cpp clang-tidy/utils/LexerUtils.h Index: clang-tidy/utils/LexerUtils.h =================================================================== --- clang-tidy/utils/LexerUtils.h +++ clang-tidy/utils/LexerUtils.h @@ -19,8 +19,8 @@ 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 Index: clang-tidy/utils/LexerUtils.cpp =================================================================== --- clang-tidy/utils/LexerUtils.cpp +++ clang-tidy/utils/LexerUtils.cpp @@ -14,19 +14,15 @@ 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; } Index: clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp =================================================================== --- clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp +++ clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp @@ -120,12 +120,14 @@ 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: Index: clang-tidy/bugprone/SuspiciousSemicolonCheck.cpp =================================================================== --- clang-tidy/bugprone/SuspiciousSemicolonCheck.cpp +++ clang-tidy/bugprone/SuspiciousSemicolonCheck.cpp @@ -40,7 +40,8 @@ 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); Index: clang-tidy/bugprone/ArgumentCommentCheck.cpp =================================================================== --- clang-tidy/bugprone/ArgumentCommentCheck.cpp +++ clang-tidy/bugprone/ArgumentCommentCheck.cpp @@ -91,8 +91,9 @@ 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();
Index: clang-tidy/utils/LexerUtils.h =================================================================== --- clang-tidy/utils/LexerUtils.h +++ clang-tidy/utils/LexerUtils.h @@ -19,8 +19,8 @@ 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 Index: clang-tidy/utils/LexerUtils.cpp =================================================================== --- clang-tidy/utils/LexerUtils.cpp +++ clang-tidy/utils/LexerUtils.cpp @@ -14,19 +14,15 @@ 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; } Index: clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp =================================================================== --- clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp +++ clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp @@ -120,12 +120,14 @@ 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: Index: clang-tidy/bugprone/SuspiciousSemicolonCheck.cpp =================================================================== --- clang-tidy/bugprone/SuspiciousSemicolonCheck.cpp +++ clang-tidy/bugprone/SuspiciousSemicolonCheck.cpp @@ -40,7 +40,8 @@ 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); Index: clang-tidy/bugprone/ArgumentCommentCheck.cpp =================================================================== --- clang-tidy/bugprone/ArgumentCommentCheck.cpp +++ clang-tidy/bugprone/ArgumentCommentCheck.cpp @@ -91,8 +91,9 @@ 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();
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits