[clang-tidy] Move all checks to the new registerPPCallbacks API
authorAlexander Kornienko <alexfh@google.com>
Fri, 22 Mar 2019 18:58:12 +0000 (18:58 +0000)
committerAlexander Kornienko <alexfh@google.com>
Fri, 22 Mar 2019 18:58:12 +0000 (18:58 +0000)
llvm-svn: 356796

45 files changed:
clang-tools-extra/clang-tidy/abseil/StringFindStartswithCheck.cpp
clang-tools-extra/clang-tidy/abseil/StringFindStartswithCheck.h
clang-tools-extra/clang-tidy/bugprone/LambdaFunctionNameCheck.cpp
clang-tools-extra/clang-tidy/bugprone/LambdaFunctionNameCheck.h
clang-tools-extra/clang-tidy/bugprone/MacroParenthesesCheck.cpp
clang-tools-extra/clang-tidy/bugprone/MacroParenthesesCheck.h
clang-tools-extra/clang-tidy/bugprone/MacroRepeatedSideEffectsCheck.cpp
clang-tools-extra/clang-tidy/bugprone/MacroRepeatedSideEffectsCheck.h
clang-tools-extra/clang-tidy/cert/SetLongJmpCheck.cpp
clang-tools-extra/clang-tidy/cert/SetLongJmpCheck.h
clang-tools-extra/clang-tidy/cppcoreguidelines/MacroUsageCheck.cpp
clang-tools-extra/clang-tidy/cppcoreguidelines/MacroUsageCheck.h
clang-tools-extra/clang-tidy/cppcoreguidelines/ProBoundsConstantArrayIndexCheck.cpp
clang-tools-extra/clang-tidy/cppcoreguidelines/ProBoundsConstantArrayIndexCheck.h
clang-tools-extra/clang-tidy/fuchsia/RestrictSystemIncludesCheck.cpp
clang-tools-extra/clang-tidy/fuchsia/RestrictSystemIncludesCheck.h
clang-tools-extra/clang-tidy/google/AvoidUnderscoreInGoogletestNameCheck.cpp
clang-tools-extra/clang-tidy/google/AvoidUnderscoreInGoogletestNameCheck.h
clang-tools-extra/clang-tidy/google/TodoCommentCheck.cpp
clang-tools-extra/clang-tidy/google/TodoCommentCheck.h
clang-tools-extra/clang-tidy/llvm/IncludeOrderCheck.cpp
clang-tools-extra/clang-tidy/llvm/IncludeOrderCheck.h
clang-tools-extra/clang-tidy/modernize/DeprecatedHeadersCheck.cpp
clang-tools-extra/clang-tidy/modernize/DeprecatedHeadersCheck.h
clang-tools-extra/clang-tidy/modernize/MakeSmartPtrCheck.cpp
clang-tools-extra/clang-tidy/modernize/MakeSmartPtrCheck.h
clang-tools-extra/clang-tidy/modernize/PassByValueCheck.cpp
clang-tools-extra/clang-tidy/modernize/PassByValueCheck.h
clang-tools-extra/clang-tidy/modernize/ReplaceAutoPtrCheck.cpp
clang-tools-extra/clang-tidy/modernize/ReplaceAutoPtrCheck.h
clang-tools-extra/clang-tidy/modernize/ReplaceRandomShuffleCheck.cpp
clang-tools-extra/clang-tidy/modernize/ReplaceRandomShuffleCheck.h
clang-tools-extra/clang-tidy/performance/MoveConstructorInitCheck.cpp
clang-tools-extra/clang-tidy/performance/MoveConstructorInitCheck.h
clang-tools-extra/clang-tidy/performance/TypePromotionInMathFnCheck.cpp
clang-tools-extra/clang-tidy/performance/TypePromotionInMathFnCheck.h
clang-tools-extra/clang-tidy/performance/UnnecessaryValueParamCheck.cpp
clang-tools-extra/clang-tidy/performance/UnnecessaryValueParamCheck.h
clang-tools-extra/clang-tidy/readability/RedundantPreprocessorCheck.cpp
clang-tools-extra/clang-tidy/readability/RedundantPreprocessorCheck.h
clang-tools-extra/clang-tidy/utils/HeaderGuard.cpp
clang-tools-extra/clang-tidy/utils/HeaderGuard.h
clang-tools-extra/clang-tidy/utils/IncludeInserter.h
clang-tools-extra/unittests/clang-tidy/ClangTidyTest.h
clang-tools-extra/unittests/clang-tidy/IncludeInserterTest.cpp

index 9009647..3fd9fd4 100644 (file)
@@ -114,11 +114,10 @@ void StringFindStartswithCheck::check(const MatchFinder::MatchResult &Result) {
 }
 
 void StringFindStartswithCheck::registerPPCallbacks(
-    CompilerInstance &Compiler) {
-  IncludeInserter = llvm::make_unique<clang::tidy::utils::IncludeInserter>(
-      Compiler.getSourceManager(), Compiler.getLangOpts(), IncludeStyle);
-  Compiler.getPreprocessor().addPPCallbacks(
-      IncludeInserter->CreatePPCallbacks());
+    const SourceManager &SM, Preprocessor *PP, Preprocessor *ModuleExpanderPP) {
+  IncludeInserter = llvm::make_unique<utils::IncludeInserter>(SM, getLangOpts(),
+                                                              IncludeStyle);
+  PP->addPPCallbacks(IncludeInserter->CreatePPCallbacks());
 }
 
 void StringFindStartswithCheck::storeOptions(
index 68bae50..8a702f7 100644 (file)
@@ -28,7 +28,8 @@ class StringFindStartswithCheck : public ClangTidyCheck {
 public:
   using ClangTidyCheck::ClangTidyCheck;
   StringFindStartswithCheck(StringRef Name, ClangTidyContext *Context);
-  void registerPPCallbacks(CompilerInstance &Compiler) override;
+  void registerPPCallbacks(const SourceManager &SM, Preprocessor *PP,
+                           Preprocessor *ModuleExpanderPP) override;
   void registerMatchers(ast_matchers::MatchFinder *Finder) override;
   void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
   void storeOptions(ClangTidyOptions::OptionMap &Opts) override;
index bcd1ab8..cc8cb3b 100644 (file)
@@ -64,10 +64,10 @@ void LambdaFunctionNameCheck::registerMatchers(MatchFinder *Finder) {
                      this);
 }
 
-void LambdaFunctionNameCheck::registerPPCallbacks(CompilerInstance &Compiler) {
-  Compiler.getPreprocessor().addPPCallbacks(
-      llvm::make_unique<MacroExpansionsWithFileAndLine>(
-          &SuppressMacroExpansions));
+void LambdaFunctionNameCheck::registerPPCallbacks(
+    const SourceManager &SM, Preprocessor *PP, Preprocessor *ModuleExpanderPP) {
+  PP->addPPCallbacks(llvm::make_unique<MacroExpansionsWithFileAndLine>(
+      &SuppressMacroExpansions));
 }
 
 void LambdaFunctionNameCheck::check(const MatchFinder::MatchResult &Result) {
index b00df53..64cb945 100644 (file)
@@ -36,7 +36,8 @@ public:
   LambdaFunctionNameCheck(StringRef Name, ClangTidyContext *Context)
       : ClangTidyCheck(Name, Context) {}
   void registerMatchers(ast_matchers::MatchFinder *Finder) override;
-  void registerPPCallbacks(CompilerInstance &Compiler) override;
+  void registerPPCallbacks(const SourceManager &SM, Preprocessor *PP,
+                           Preprocessor *ModuleExpanderPP) override;
   void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
 
 private:
index 2bebf4a..874cd47 100644 (file)
@@ -248,10 +248,9 @@ void MacroParenthesesPPCallbacks::argument(const Token &MacroNameTok,
   }
 }
 
-void MacroParenthesesCheck::registerPPCallbacks(CompilerInstance &Compiler) {
-  Compiler.getPreprocessor().addPPCallbacks(
-      llvm::make_unique<MacroParenthesesPPCallbacks>(
-          &Compiler.getPreprocessor(), this));
+void MacroParenthesesCheck::registerPPCallbacks(
+    const SourceManager &SM, Preprocessor *PP, Preprocessor *ModuleExpanderPP) {
+  PP->addPPCallbacks(llvm::make_unique<MacroParenthesesPPCallbacks>(PP, this));
 }
 
 } // namespace bugprone
index 4b9e181..9446991 100644 (file)
@@ -32,7 +32,8 @@ class MacroParenthesesCheck : public ClangTidyCheck {
 public:
   MacroParenthesesCheck(StringRef Name, ClangTidyContext *Context)
       : ClangTidyCheck(Name, Context) {}
-  void registerPPCallbacks(CompilerInstance &Compiler) override;
+  void registerPPCallbacks(const SourceManager &SM, Preprocessor *PP,
+                           Preprocessor *ModuleExpanderPP) override;
 };
 
 } // namespace bugprone
index 91ec094..ee70346 100644 (file)
@@ -172,10 +172,8 @@ bool MacroRepeatedPPCallbacks::hasSideEffects(
 }
 
 void MacroRepeatedSideEffectsCheck::registerPPCallbacks(
-    CompilerInstance &Compiler) {
-  Compiler.getPreprocessor().addPPCallbacks(
-      ::llvm::make_unique<MacroRepeatedPPCallbacks>(
-          *this, Compiler.getPreprocessor()));
+    const SourceManager &SM, Preprocessor *PP, Preprocessor *ModuleExpanderPP) {
+  PP->addPPCallbacks(::llvm::make_unique<MacroRepeatedPPCallbacks>(*this, *PP));
 }
 
 } // namespace bugprone
index 6917c5b..eff3a12 100644 (file)
@@ -20,7 +20,8 @@ class MacroRepeatedSideEffectsCheck : public ClangTidyCheck {
 public:
   MacroRepeatedSideEffectsCheck(StringRef Name, ClangTidyContext *Context)
       : ClangTidyCheck(Name, Context) {}
-  void registerPPCallbacks(CompilerInstance &Compiler) override;
+  void registerPPCallbacks(const SourceManager &SM, Preprocessor *PP,
+                           Preprocessor *ModuleExpanderPP) override;
 };
 
 } // namespace bugprone
index fb8c583..87ac2de 100644 (file)
@@ -41,7 +41,9 @@ public:
 };
 } // namespace
 
-void SetLongJmpCheck::registerPPCallbacks(CompilerInstance &Compiler) {
+void SetLongJmpCheck::registerPPCallbacks(const SourceManager &SM,
+                                          Preprocessor *PP,
+                                          Preprocessor *ModuleExpanderPP) {
   // This checker only applies to C++, where exception handling is a superior
   // solution to setjmp/longjmp calls.
   if (!getLangOpts().CPlusPlus)
@@ -49,8 +51,7 @@ void SetLongJmpCheck::registerPPCallbacks(CompilerInstance &Compiler) {
 
   // Per [headers]p5, setjmp must be exposed as a macro instead of a function,
   // despite the allowance in C for setjmp to also be an extern function.
-  Compiler.getPreprocessor().addPPCallbacks(
-      llvm::make_unique<SetJmpMacroCallbacks>(*this));
+  PP->addPPCallbacks(llvm::make_unique<SetJmpMacroCallbacks>(*this));
 }
 
 void SetLongJmpCheck::registerMatchers(MatchFinder *Finder) {
index 660545d..38445c4 100644 (file)
@@ -25,7 +25,8 @@ public:
       : ClangTidyCheck(Name, Context) {}
   void registerMatchers(ast_matchers::MatchFinder *Finder) override;
   void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
-  void registerPPCallbacks(CompilerInstance &Compiler) override;
+  void registerPPCallbacks(const SourceManager &SM, Preprocessor *PP,
+                           Preprocessor *ModuleExpanderPP) override;
 };
 
 } // namespace cert
index 07351b8..01c25d2 100644 (file)
@@ -67,14 +67,14 @@ void MacroUsageCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) {
   Options.store(Opts, "IgnoreCommandLineMacros", IgnoreCommandLineMacros);
 }
 
-void MacroUsageCheck::registerPPCallbacks(CompilerInstance &Compiler) {
+void MacroUsageCheck::registerPPCallbacks(const SourceManager &SM,
+                                          Preprocessor *PP,
+                                          Preprocessor *ModuleExpanderPP) {
   if (!getLangOpts().CPlusPlus11)
     return;
 
-  Compiler.getPreprocessor().addPPCallbacks(
-      llvm::make_unique<MacroUsageCallbacks>(this, Compiler.getSourceManager(),
-                                             AllowedRegexp, CheckCapsOnly,
-                                             IgnoreCommandLineMacros));
+  PP->addPPCallbacks(llvm::make_unique<MacroUsageCallbacks>(
+      this, SM, AllowedRegexp, CheckCapsOnly, IgnoreCommandLineMacros));
 }
 
 void MacroUsageCheck::warnMacro(const MacroDirective *MD, StringRef MacroName) {
index fc96e33..978edd8 100644 (file)
@@ -30,7 +30,8 @@ public:
         CheckCapsOnly(Options.get("CheckCapsOnly", 0)),
         IgnoreCommandLineMacros(Options.get("IgnoreCommandLineMacros", 1)) {}
   void storeOptions(ClangTidyOptions::OptionMap &Opts) override;
-  void registerPPCallbacks(CompilerInstance &Compiler) override;
+  void registerPPCallbacks(const SourceManager &SM, Preprocessor *PP,
+                           Preprocessor *ModuleExpanderPP) override;
   void warnMacro(const MacroDirective *MD, StringRef MacroName);
   void warnNaming(const MacroDirective *MD, StringRef MacroName);
 
index 32e3fb5..28fccfd 100644 (file)
@@ -31,13 +31,13 @@ void ProBoundsConstantArrayIndexCheck::storeOptions(
 }
 
 void ProBoundsConstantArrayIndexCheck::registerPPCallbacks(
-    CompilerInstance &Compiler) {
+    const SourceManager &SM, Preprocessor *PP, Preprocessor *ModuleExpanderPP) {
   if (!getLangOpts().CPlusPlus)
     return;
 
-  Inserter.reset(new utils::IncludeInserter(
-      Compiler.getSourceManager(), Compiler.getLangOpts(), IncludeStyle));
-  Compiler.getPreprocessor().addPPCallbacks(Inserter->CreatePPCallbacks());
+  Inserter = llvm::make_unique<utils::IncludeInserter>(SM, getLangOpts(),
+                                                       IncludeStyle);
+  PP->addPPCallbacks(Inserter->CreatePPCallbacks());
 }
 
 void ProBoundsConstantArrayIndexCheck::registerMatchers(MatchFinder *Finder) {
index c056926..c75795a 100644 (file)
@@ -28,7 +28,8 @@ class ProBoundsConstantArrayIndexCheck : public ClangTidyCheck {
 
 public:
   ProBoundsConstantArrayIndexCheck(StringRef Name, ClangTidyContext *Context);
-  void registerPPCallbacks(CompilerInstance &Compiler) override;
+  void registerPPCallbacks(const SourceManager &SM, Preprocessor *PP,
+                           Preprocessor *ModuleExpanderPP) override;
   void registerMatchers(ast_matchers::MatchFinder *Finder) override;
   void storeOptions(ClangTidyOptions::OptionMap &Opts) override;
   void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
index e42e32c..08981fc 100644 (file)
@@ -23,7 +23,7 @@ namespace fuchsia {
 class RestrictedIncludesPPCallbacks : public PPCallbacks {
 public:
   explicit RestrictedIncludesPPCallbacks(RestrictSystemIncludesCheck &Check,
-                                         SourceManager &SM)
+                                         const SourceManager &SM)
       : Check(Check), SM(SM) {}
 
   void InclusionDirective(SourceLocation HashLoc, const Token &IncludeTok,
@@ -53,7 +53,7 @@ private:
   llvm::SmallDenseMap<FileID, FileIncludes> IncludeDirectives;
 
   RestrictSystemIncludesCheck &Check;
-  SourceManager &SM;
+  const SourceManager &SM;
 };
 
 void RestrictedIncludesPPCallbacks::InclusionDirective(
@@ -101,10 +101,9 @@ void RestrictedIncludesPPCallbacks::EndOfMainFile() {
 }
 
 void RestrictSystemIncludesCheck::registerPPCallbacks(
-    CompilerInstance &Compiler) {
-  Compiler.getPreprocessor().addPPCallbacks(
-      llvm::make_unique<RestrictedIncludesPPCallbacks>(
-          *this, Compiler.getSourceManager()));
+    const SourceManager &SM, Preprocessor *PP, Preprocessor *ModuleExpanderPP) {
+  PP->addPPCallbacks(
+      llvm::make_unique<RestrictedIncludesPPCallbacks>(*this, SM));
 }
 
 void RestrictSystemIncludesCheck::storeOptions(
index 64da2e7..a9aca34 100644 (file)
@@ -29,7 +29,8 @@ public:
         AllowedIncludes(Options.get("Includes", "*")),
         AllowedIncludesGlobList(AllowedIncludes) {}
 
-  void registerPPCallbacks(CompilerInstance &Compiler) override;
+  void registerPPCallbacks(const SourceManager &SM, Preprocessor *PP,
+                           Preprocessor *ModuleExpanderPP) override;
   void storeOptions(ClangTidyOptions::OptionMap &Opts) override;
   bool contains(StringRef FileName) {
     return AllowedIncludesGlobList.contains(FileName);
index fbc47b7..d279343 100644 (file)
@@ -77,10 +77,9 @@ private:
 } // namespace
 
 void AvoidUnderscoreInGoogletestNameCheck::registerPPCallbacks(
-    CompilerInstance &Compiler) {
-  Compiler.getPreprocessor().addPPCallbacks(
-      llvm::make_unique<AvoidUnderscoreInGoogletestNameCallback>(
-          &Compiler.getPreprocessor(), this));
+    const SourceManager &SM, Preprocessor *PP, Preprocessor *ModuleExpanderPP) {
+  PP->addPPCallbacks(
+      llvm::make_unique<AvoidUnderscoreInGoogletestNameCallback>(PP, this));
 }
 
 } // namespace readability
index 8a1a2f2..2a8afd6 100644 (file)
@@ -22,7 +22,8 @@ class AvoidUnderscoreInGoogletestNameCheck : public ClangTidyCheck {
 public:
   using ClangTidyCheck::ClangTidyCheck;
 
-  void registerPPCallbacks(CompilerInstance &Compiler) override;
+  void registerPPCallbacks(const SourceManager &SM, Preprocessor *PP,
+                           Preprocessor *ModuleExpanderPP) override;
 };
 
 } // namespace readability
index c46f07d..40d65a6 100644 (file)
@@ -55,8 +55,10 @@ TodoCommentCheck::TodoCommentCheck(StringRef Name, ClangTidyContext *Context)
       Handler(llvm::make_unique<TodoCommentHandler>(
           *this, Context->getOptions().User)) {}
 
-void TodoCommentCheck::registerPPCallbacks(CompilerInstance &Compiler) {
-  Compiler.getPreprocessor().addCommentHandler(Handler.get());
+void TodoCommentCheck::registerPPCallbacks(const SourceManager &SM,
+                                           Preprocessor *PP,
+                                           Preprocessor *ModuleExpanderPP) {
+  PP->addCommentHandler(Handler.get());
 }
 
 } // namespace readability
index eb89dd0..8f7564f 100644 (file)
@@ -22,7 +22,8 @@ namespace readability {
 class TodoCommentCheck : public ClangTidyCheck {
 public:
   TodoCommentCheck(StringRef Name, ClangTidyContext *Context);
-  void registerPPCallbacks(CompilerInstance &Compiler) override;
+  void registerPPCallbacks(const SourceManager &SM, Preprocessor *PP,
+                           Preprocessor *ModuleExpanderPP) override;
 
 private:
   class TodoCommentHandler;
index 3d23644..9c3ab0b 100644 (file)
@@ -20,7 +20,8 @@ namespace llvm {
 namespace {
 class IncludeOrderPPCallbacks : public PPCallbacks {
 public:
-  explicit IncludeOrderPPCallbacks(ClangTidyCheck &Check, SourceManager &SM)
+  explicit IncludeOrderPPCallbacks(ClangTidyCheck &Check,
+                                   const SourceManager &SM)
       : LookForMainModule(true), Check(Check), SM(SM) {}
 
   void InclusionDirective(SourceLocation HashLoc, const Token &IncludeTok,
@@ -45,14 +46,14 @@ private:
   bool LookForMainModule;
 
   ClangTidyCheck &Check;
-  SourceManager &SM;
+  const SourceManager &SM;
 };
 } // namespace
 
-void IncludeOrderCheck::registerPPCallbacks(CompilerInstance &Compiler) {
-  Compiler.getPreprocessor().addPPCallbacks(
-      ::llvm::make_unique<IncludeOrderPPCallbacks>(
-          *this, Compiler.getSourceManager()));
+void IncludeOrderCheck::registerPPCallbacks(const SourceManager &SM,
+                                            Preprocessor *PP,
+                                            Preprocessor *ModuleExpanderPP) {
+  PP->addPPCallbacks(::llvm::make_unique<IncludeOrderPPCallbacks>(*this, SM));
 }
 
 static int getPriority(StringRef Filename, bool IsAngled, bool IsMainModule) {
index b10496e..9ccf028 100644 (file)
@@ -22,7 +22,8 @@ class IncludeOrderCheck : public ClangTidyCheck {
 public:
   IncludeOrderCheck(StringRef Name, ClangTidyContext *Context)
       : ClangTidyCheck(Name, Context) {}
-  void registerPPCallbacks(CompilerInstance &Compiler) override;
+  void registerPPCallbacks(const SourceManager &SM, Preprocessor *PP,
+                           Preprocessor *ModuleExpanderPP) override;
 };
 
 } // namespace llvm
index ffc041b..af4d47c 100644 (file)
@@ -40,11 +40,11 @@ private:
 };
 } // namespace
 
-void DeprecatedHeadersCheck::registerPPCallbacks(CompilerInstance &Compiler) {
-  if (this->getLangOpts().CPlusPlus) {
-    Compiler.getPreprocessor().addPPCallbacks(
-        ::llvm::make_unique<IncludeModernizePPCallbacks>(*this,
-                                                         this->getLangOpts()));
+void DeprecatedHeadersCheck::registerPPCallbacks(
+    const SourceManager &SM, Preprocessor *PP, Preprocessor *ModuleExpanderPP) {
+  if (getLangOpts().CPlusPlus) {
+    PP->addPPCallbacks(
+        ::llvm::make_unique<IncludeModernizePPCallbacks>(*this, getLangOpts()));
   }
 }
 
index 4be4ad9..1a3544a 100644 (file)
@@ -36,7 +36,8 @@ class DeprecatedHeadersCheck : public ClangTidyCheck {
 public:
   DeprecatedHeadersCheck(StringRef Name, ClangTidyContext *Context)
       : ClangTidyCheck(Name, Context) {}
-  void registerPPCallbacks(CompilerInstance &Compiler) override;
+  void registerPPCallbacks(const SourceManager &SM, Preprocessor *PP,
+                           Preprocessor *ModuleExpanderPP) override;
 };
 
 } // namespace modernize
index 9b0c5d8..5a152c8 100644 (file)
@@ -65,11 +65,13 @@ bool MakeSmartPtrCheck::isLanguageVersionSupported(
   return LangOpts.CPlusPlus11;
 }
 
-void MakeSmartPtrCheck::registerPPCallbacks(CompilerInstance &Compiler) {
+void MakeSmartPtrCheck::registerPPCallbacks(const SourceManager &SM,
+                                            Preprocessor *PP,
+                                            Preprocessor *ModuleExpanderPP) {
   if (isLanguageVersionSupported(getLangOpts())) {
-    Inserter = llvm::make_unique<utils::IncludeInserter>(
-        Compiler.getSourceManager(), Compiler.getLangOpts(), IncludeStyle);
-    Compiler.getPreprocessor().addPPCallbacks(Inserter->CreatePPCallbacks());
+    Inserter = llvm::make_unique<utils::IncludeInserter>(SM, getLangOpts(),
+                                                         IncludeStyle);
+    PP->addPPCallbacks(Inserter->CreatePPCallbacks());
   }
 }
 
index 82855e2..62f88d4 100644 (file)
@@ -26,7 +26,8 @@ public:
   MakeSmartPtrCheck(StringRef Name, ClangTidyContext *Context,
                     StringRef MakeSmartPtrFunctionName);
   void registerMatchers(ast_matchers::MatchFinder *Finder) final;
-  void registerPPCallbacks(clang::CompilerInstance &Compiler) override;
+  void registerPPCallbacks(const SourceManager &SM, Preprocessor *PP,
+                           Preprocessor *ModuleExpanderPP) override;
   void check(const ast_matchers::MatchFinder::MatchResult &Result) final;
   void storeOptions(ClangTidyOptions::OptionMap &Opts) override;
 
index 15c3725..a83e54a 100644 (file)
@@ -164,14 +164,16 @@ void PassByValueCheck::registerMatchers(MatchFinder *Finder) {
       this);
 }
 
-void PassByValueCheck::registerPPCallbacks(CompilerInstance &Compiler) {
+void PassByValueCheck::registerPPCallbacks(const SourceManager &SM,
+                                           Preprocessor *PP,
+                                           Preprocessor *ModuleExpanderPP) {
   // Only register the preprocessor callbacks for C++; the functionality
   // currently does not provide any benefit to other languages, despite being
   // benign.
   if (getLangOpts().CPlusPlus) {
-    Inserter.reset(new utils::IncludeInserter(
-        Compiler.getSourceManager(), Compiler.getLangOpts(), IncludeStyle));
-    Compiler.getPreprocessor().addPPCallbacks(Inserter->CreatePPCallbacks());
+    Inserter = llvm::make_unique<utils::IncludeInserter>(SM, getLangOpts(),
+                                                         IncludeStyle);
+    PP->addPPCallbacks(Inserter->CreatePPCallbacks());
   }
 }
 
index fde6517..7201747 100644 (file)
@@ -22,7 +22,8 @@ class PassByValueCheck : public ClangTidyCheck {
 public:
   PassByValueCheck(StringRef Name, ClangTidyContext *Context);
   void storeOptions(ClangTidyOptions::OptionMap &Opts) override;
-  void registerPPCallbacks(clang::CompilerInstance &Compiler) override;
+  void registerPPCallbacks(const SourceManager &SM, Preprocessor *PP,
+                           Preprocessor *ModuleExpanderPP) override;
   void registerMatchers(ast_matchers::MatchFinder *Finder) override;
   void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
 
index 0de835e..c1c2235 100644 (file)
@@ -132,15 +132,17 @@ void ReplaceAutoPtrCheck::registerMatchers(MatchFinder *Finder) {
                      this);
 }
 
-void ReplaceAutoPtrCheck::registerPPCallbacks(CompilerInstance &Compiler) {
+void ReplaceAutoPtrCheck::registerPPCallbacks(const SourceManager &SM,
+                                              Preprocessor *PP,
+                                              Preprocessor *ModuleExpanderPP) {
   // Only register the preprocessor callbacks for C++; the functionality
   // currently does not provide any benefit to other languages, despite being
   // benign.
   if (!getLangOpts().CPlusPlus)
     return;
-  Inserter.reset(new utils::IncludeInserter(
-      Compiler.getSourceManager(), Compiler.getLangOpts(), IncludeStyle));
-  Compiler.getPreprocessor().addPPCallbacks(Inserter->CreatePPCallbacks());
+  Inserter = llvm::make_unique<utils::IncludeInserter>(SM, getLangOpts(),
+                                                       IncludeStyle);
+  PP->addPPCallbacks(Inserter->CreatePPCallbacks());
 }
 
 void ReplaceAutoPtrCheck::check(const MatchFinder::MatchResult &Result) {
index 174676e..94f0a84 100644 (file)
@@ -45,7 +45,8 @@ public:
   ReplaceAutoPtrCheck(StringRef Name, ClangTidyContext *Context);
   void storeOptions(ClangTidyOptions::OptionMap &Opts) override;
   void registerMatchers(ast_matchers::MatchFinder *Finder) override;
-  void registerPPCallbacks(CompilerInstance &Compiler) override;
+  void registerPPCallbacks(const SourceManager &SM, Preprocessor *PP,
+                           Preprocessor *ModuleExpanderPP) override;
   void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
 
 private:
index 73afec7..44c108c 100644 (file)
@@ -43,11 +43,10 @@ void ReplaceRandomShuffleCheck::registerMatchers(MatchFinder *Finder) {
 }
 
 void ReplaceRandomShuffleCheck::registerPPCallbacks(
-    CompilerInstance &Compiler) {
-  IncludeInserter = llvm::make_unique<utils::IncludeInserter>(
-      Compiler.getSourceManager(), Compiler.getLangOpts(), IncludeStyle);
-  Compiler.getPreprocessor().addPPCallbacks(
-      IncludeInserter->CreatePPCallbacks());
+    const SourceManager &SM, Preprocessor *PP, Preprocessor *ModuleExpanderPP) {
+  IncludeInserter = llvm::make_unique<utils::IncludeInserter>(SM, getLangOpts(),
+                                                              IncludeStyle);
+  PP->addPPCallbacks(IncludeInserter->CreatePPCallbacks());
 }
 
 void ReplaceRandomShuffleCheck::storeOptions(
index 6536708..d697049 100644 (file)
@@ -24,7 +24,8 @@ namespace modernize {
 class ReplaceRandomShuffleCheck : public ClangTidyCheck {
 public:
   ReplaceRandomShuffleCheck(StringRef Name, ClangTidyContext *Context);
-  void registerPPCallbacks(CompilerInstance &Compiler) override;
+  void registerPPCallbacks(const SourceManager &SM, Preprocessor *PP,
+                           Preprocessor *ModuleExpanderPP) override;
   void storeOptions(ClangTidyOptions::OptionMap &Opts) override;
   void registerMatchers(ast_matchers::MatchFinder *Finder) override;
   void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
index abc5f4f..aa5c819 100644 (file)
@@ -91,10 +91,11 @@ void MoveConstructorInitCheck::check(const MatchFinder::MatchResult &Result) {
   }
 }
 
-void MoveConstructorInitCheck::registerPPCallbacks(CompilerInstance &Compiler) {
-  Inserter.reset(new utils::IncludeInserter(
-      Compiler.getSourceManager(), Compiler.getLangOpts(), IncludeStyle));
-  Compiler.getPreprocessor().addPPCallbacks(Inserter->CreatePPCallbacks());
+void MoveConstructorInitCheck::registerPPCallbacks(
+    const SourceManager &SM, Preprocessor *PP, Preprocessor *ModuleExpanderPP) {
+  Inserter = llvm::make_unique<utils::IncludeInserter>(SM, getLangOpts(),
+                                                       IncludeStyle);
+  PP->addPPCallbacks(Inserter->CreatePPCallbacks());
 }
 
 void MoveConstructorInitCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) {
index 34a202e..e3ebc85 100644 (file)
@@ -28,7 +28,8 @@ public:
   MoveConstructorInitCheck(StringRef Name, ClangTidyContext *Context);
   void registerMatchers(ast_matchers::MatchFinder *Finder) override;
   void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
-  void registerPPCallbacks(clang::CompilerInstance &Compiler) override;
+  void registerPPCallbacks(const SourceManager &SM, Preprocessor *PP,
+                           Preprocessor *ModuleExpanderPP) override;
   void storeOptions(ClangTidyOptions::OptionMap &Opts) override;
 
 private:
index 7b9b1f7..652a6f9 100644 (file)
@@ -35,11 +35,10 @@ TypePromotionInMathFnCheck::TypePromotionInMathFnCheck(
           Options.getLocalOrGlobal("IncludeStyle", "llvm"))) {}
 
 void TypePromotionInMathFnCheck::registerPPCallbacks(
-    CompilerInstance &Compiler) {
-  IncludeInserter = llvm::make_unique<utils::IncludeInserter>(
-      Compiler.getSourceManager(), Compiler.getLangOpts(), IncludeStyle);
-  Compiler.getPreprocessor().addPPCallbacks(
-      IncludeInserter->CreatePPCallbacks());
+    const SourceManager &SM, Preprocessor *PP, Preprocessor *ModuleExpanderPP) {
+  IncludeInserter = llvm::make_unique<utils::IncludeInserter>(SM, getLangOpts(),
+                                                              IncludeStyle);
+  PP->addPPCallbacks(IncludeInserter->CreatePPCallbacks());
 }
 
 void TypePromotionInMathFnCheck::storeOptions(
index bb5900a..809080a 100644 (file)
@@ -29,7 +29,8 @@ class TypePromotionInMathFnCheck : public ClangTidyCheck {
 public:
   TypePromotionInMathFnCheck(StringRef Name, ClangTidyContext *Context);
 
-  void registerPPCallbacks(CompilerInstance &Compiler) override;
+  void registerPPCallbacks(const SourceManager &SM, Preprocessor *PP,
+                           Preprocessor *ModuleExpanderPP) override;
   void storeOptions(ClangTidyOptions::OptionMap &Opts) override;
   void registerMatchers(ast_matchers::MatchFinder *Finder) override;
   void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
index 44f5fc2..cf66081 100644 (file)
@@ -168,10 +168,10 @@ void UnnecessaryValueParamCheck::check(const MatchFinder::MatchResult &Result) {
 }
 
 void UnnecessaryValueParamCheck::registerPPCallbacks(
-    CompilerInstance &Compiler) {
-  Inserter.reset(new utils::IncludeInserter(
-      Compiler.getSourceManager(), Compiler.getLangOpts(), IncludeStyle));
-  Compiler.getPreprocessor().addPPCallbacks(Inserter->CreatePPCallbacks());
+    const SourceManager &SM, Preprocessor *PP, Preprocessor *ModuleExpanderPP) {
+  Inserter = llvm::make_unique<utils::IncludeInserter>(SM, getLangOpts(),
+                                                       IncludeStyle);
+  PP->addPPCallbacks(Inserter->CreatePPCallbacks());
 }
 
 void UnnecessaryValueParamCheck::storeOptions(
index 84252ed..dcaefb8 100644 (file)
@@ -27,7 +27,8 @@ public:
   UnnecessaryValueParamCheck(StringRef Name, ClangTidyContext *Context);
   void registerMatchers(ast_matchers::MatchFinder *Finder) override;
   void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
-  void registerPPCallbacks(CompilerInstance &Compiler) override;
+  void registerPPCallbacks(const SourceManager &SM, Preprocessor *PP,
+                           Preprocessor *ModuleExpanderPP) override;
   void storeOptions(ClangTidyOptions::OptionMap &Opts) override;
   void onEndOfTranslationUnit() override;
 
index e208c58..ea46d53 100644 (file)
@@ -97,10 +97,9 @@ private:
 } // namespace
 
 void RedundantPreprocessorCheck::registerPPCallbacks(
-    CompilerInstance &Compiler) {
-  Compiler.getPreprocessor().addPPCallbacks(
-      ::llvm::make_unique<RedundantPreprocessorCallbacks>(
-          *this, Compiler.getPreprocessor()));
+    const SourceManager &SM, Preprocessor *PP, Preprocessor *ModuleExpanderPP) {
+  PP->addPPCallbacks(
+      ::llvm::make_unique<RedundantPreprocessorCallbacks>(*this, *PP));
 }
 
 } // namespace readability
index cb70ac7..4be8b94 100644 (file)
@@ -24,7 +24,8 @@ class RedundantPreprocessorCheck : public ClangTidyCheck {
 public:
   RedundantPreprocessorCheck(StringRef Name, ClangTidyContext *Context)
       : ClangTidyCheck(Name, Context) {}
-  void registerPPCallbacks(CompilerInstance &Compiler) override;
+  void registerPPCallbacks(const SourceManager &SM, Preprocessor *PP,
+                           Preprocessor *ModuleExpanderPP) override;
 };
 
 } // namespace readability
index cc56b3f..366d7d4 100644 (file)
@@ -266,10 +266,10 @@ private:
 };
 } // namespace
 
-void HeaderGuardCheck::registerPPCallbacks(CompilerInstance &Compiler) {
-  Compiler.getPreprocessor().addPPCallbacks(
-      llvm::make_unique<HeaderGuardPPCallbacks>(&Compiler.getPreprocessor(),
-                                                this));
+void HeaderGuardCheck::registerPPCallbacks(const SourceManager &SM,
+                                           Preprocessor *PP,
+                                           Preprocessor *ModuleExpanderPP) {
+  PP->addPPCallbacks(llvm::make_unique<HeaderGuardPPCallbacks>(PP, this));
 }
 
 bool HeaderGuardCheck::shouldSuggestEndifComment(StringRef FileName) {
index f2062e5..8ece331 100644 (file)
@@ -32,7 +32,8 @@ public:
     utils::parseHeaderFileExtensions(RawStringHeaderFileExtensions,
                                      HeaderFileExtensions, ',');
   }
-  void registerPPCallbacks(CompilerInstance &Compiler) override;
+  void registerPPCallbacks(const SourceManager &SM, Preprocessor *PP,
+                           Preprocessor *ModuleExpanderPP) override;
 
   /// Returns ``true`` if the check should suggest inserting a trailing comment
   /// on the ``#endif`` of the header guard. It will use the same name as
index a56b5ab..36c16ac 100644 (file)
@@ -31,11 +31,11 @@ namespace utils {
 ///
 /// class MyCheck : public ClangTidyCheck {
 ///  public:
-///   void registerPPCallbacks(CompilerInstance& Compiler) override {
-///     Inserter = llvm::make_unique<IncludeInserter>(&Compiler.getSourceManager(),
-///                                                   &Compiler.getLangOpts());
-///     Compiler.getPreprocessor().addPPCallbacks(
-///         Inserter->CreatePPCallbacks());
+///   void registerPPCallbacks(const SourceManager &SM, Preprocessor *PP,
+///                            Preprocessor *ModuleExpanderPP) override {
+///     Inserter = llvm::make_unique<IncludeInserter>(
+///         SM, getLangOpts(), utils::IncludeSorter::IS_Google);
+///     PP->addPPCallbacks(Inserter->CreatePPCallbacks());
 ///   }
 ///
 ///   void registerMatchers(ast_matchers::MatchFinder* Finder) override { ... }
index ca886e4..25409d4 100644 (file)
@@ -39,9 +39,11 @@ private:
     Context.setCurrentFile(File);
     Context.setASTContext(&Compiler.getASTContext());
 
+    Preprocessor *PP = &Compiler.getPreprocessor();
     for (auto &Check : Checks) {
       Check->registerMatchers(&Finder);
       Check->registerPPCallbacks(Compiler);
+      Check->registerPPCallbacks(Compiler.getSourceManager(), PP, PP);
     }
     return Finder.newASTConsumer();
   }
index bf9a350..89b2567 100644 (file)
@@ -31,12 +31,11 @@ public:
   IncludeInserterCheckBase(StringRef CheckName, ClangTidyContext *Context)
       : ClangTidyCheck(CheckName, Context) {}
 
-  void registerPPCallbacks(CompilerInstance &Compiler) override {
-    Inserter.reset(new utils::IncludeInserter(
-        Compiler.getSourceManager(),
-        Compiler.getLangOpts(),
-        utils::IncludeSorter::IS_Google));
-    Compiler.getPreprocessor().addPPCallbacks(Inserter->CreatePPCallbacks());
+  void registerPPCallbacks(const SourceManager &SM, Preprocessor *PP,
+                           Preprocessor *ModuleExpanderPP) override {
+    Inserter = llvm::make_unique<utils::IncludeInserter>(
+        SM, getLangOpts(), utils::IncludeSorter::IS_Google);
+    PP->addPPCallbacks(Inserter->CreatePPCallbacks());
   }
 
   void registerMatchers(ast_matchers::MatchFinder *Finder) override {