mattbeardsley created this revision.
mattbeardsley added reviewers: thakis, hans.
Herald added subscribers: carlosgalvezp, xazax.hun, mgorny.
mattbeardsley requested review of this revision.
Herald added a reviewer: jdoerfert.
Herald added subscribers: cfe-commits, sstefan1.
Herald added a project: clang-tools-extra.

The following removed the only use of the clang-tidy plugin code:
https://reviews.llvm.org/D97693

This removes the rest of the now-unused and now-untested clang-tidy plugin code.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D116137

Files:
  clang-tools-extra/clang-tidy/CMakeLists.txt
  clang-tools-extra/clang-tidy/ClangTidy.cpp
  clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp
  clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.h
  clang-tools-extra/clang-tidy/plugin/CMakeLists.txt
  clang-tools-extra/clang-tidy/plugin/ClangTidyPlugin.cpp

Index: clang-tools-extra/clang-tidy/plugin/ClangTidyPlugin.cpp
===================================================================
--- clang-tools-extra/clang-tidy/plugin/ClangTidyPlugin.cpp
+++ /dev/null
@@ -1,86 +0,0 @@
-//===- ClangTidyPlugin.cpp - clang-tidy as a clang plugin -----------------===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-
-#include "../ClangTidy.h"
-#include "../ClangTidyDiagnosticConsumer.h"
-#include "../ClangTidyForceLinker.h"
-#include "../ClangTidyModule.h"
-#include "clang/Frontend/CompilerInstance.h"
-#include "clang/Frontend/FrontendPluginRegistry.h"
-#include "clang/Frontend/MultiplexConsumer.h"
-
-namespace clang {
-namespace tidy {
-
-/// The core clang tidy plugin action. This just provides the AST consumer and
-/// command line flag parsing for using clang-tidy as a clang plugin.
-class ClangTidyPluginAction : public PluginASTAction {
-  /// Wrapper to grant the context and diagnostics engine the same lifetime as
-  /// the action.
-  /// We use MultiplexConsumer to avoid writing out all the forwarding methods.
-  class WrapConsumer : public MultiplexConsumer {
-    std::unique_ptr<ClangTidyContext> Context;
-    std::unique_ptr<DiagnosticsEngine> DiagEngine;
-
-  public:
-    WrapConsumer(std::unique_ptr<ClangTidyContext> Context,
-                 std::unique_ptr<DiagnosticsEngine> DiagEngine,
-                 std::vector<std::unique_ptr<ASTConsumer>> Consumer)
-        : MultiplexConsumer(std::move(Consumer)), Context(std::move(Context)),
-          DiagEngine(std::move(DiagEngine)) {}
-  };
-
-public:
-  std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &Compiler,
-                                                 StringRef File) override {
-    // Create and set diagnostics engine
-    auto *DiagConsumer =
-        new ClangTidyDiagnosticConsumer(*Context, &Compiler.getDiagnostics());
-    auto DiagEngine = std::make_unique<DiagnosticsEngine>(
-        new DiagnosticIDs, new DiagnosticOptions, DiagConsumer);
-    Context->setDiagnosticsEngine(DiagEngine.get());
-
-    // Create the AST consumer.
-    ClangTidyASTConsumerFactory Factory(*Context);
-    std::vector<std::unique_ptr<ASTConsumer>> Vec;
-    Vec.push_back(Factory.createASTConsumer(Compiler, File));
-
-    return std::make_unique<WrapConsumer>(
-        std::move(Context), std::move(DiagEngine), std::move(Vec));
-  }
-
-  bool ParseArgs(const CompilerInstance &,
-                 const std::vector<std::string> &Args) override {
-    ClangTidyGlobalOptions GlobalOptions;
-    ClangTidyOptions DefaultOptions;
-    ClangTidyOptions OverrideOptions;
-
-    // Parse the extra command line args.
-    // FIXME: This is very limited at the moment.
-    for (StringRef Arg : Args)
-      if (Arg.startswith("-checks="))
-        OverrideOptions.Checks = std::string(Arg.substr(strlen("-checks=")));
-
-    auto Options = std::make_unique<FileOptionsProvider>(
-        GlobalOptions, DefaultOptions, OverrideOptions);
-    Context = std::make_unique<ClangTidyContext>(std::move(Options));
-    return true;
-  }
-
-private:
-  std::unique_ptr<ClangTidyContext> Context;
-};
-} // namespace tidy
-} // namespace clang
-
-// This anchor is used to force the linker to link in the generated object file
-// and thus register the clang-tidy plugin.
-volatile int ClangTidyPluginAnchorSource = 0;
-
-static clang::FrontendPluginRegistry::Add<clang::tidy::ClangTidyPluginAction>
-    X("clang-tidy", "clang-tidy");
Index: clang-tools-extra/clang-tidy/plugin/CMakeLists.txt
===================================================================
--- clang-tools-extra/clang-tidy/plugin/CMakeLists.txt
+++ /dev/null
@@ -1,20 +0,0 @@
-add_clang_library(clangTidyPlugin
-  ClangTidyPlugin.cpp
-
-  LINK_LIBS
-  clangTidy
-  ${ALL_CLANG_TIDY_CHECKS}
-
-  DEPENDS
-  omp_gen
-  )
-
-clang_target_link_libraries(clangTidyPlugin
-  PRIVATE
-  clangAST
-  clangASTMatchers
-  clangBasic
-  clangFrontend
-  clangSema
-  clangTooling
-  )
Index: clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.h
===================================================================
--- clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.h
+++ clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.h
@@ -250,7 +250,6 @@
 class ClangTidyDiagnosticConsumer : public DiagnosticConsumer {
 public:
   ClangTidyDiagnosticConsumer(ClangTidyContext &Ctx,
-                              DiagnosticsEngine *ExternalDiagEngine = nullptr,
                               bool RemoveIncompatibleErrors = true,
                               bool GetFixesFromNotes = false,
                               bool EnableNolintBlocks = true);
@@ -278,10 +277,7 @@
   void checkFilters(SourceLocation Location, const SourceManager &Sources);
   bool passesLineFilter(StringRef FileName, unsigned LineNumber) const;
 
-  void forwardDiagnostic(const Diagnostic &Info);
-
   ClangTidyContext &Context;
-  DiagnosticsEngine *ExternalDiagEngine;
   bool RemoveIncompatibleErrors;
   bool GetFixesFromNotes;
   bool EnableNolintBlocks;
Index: clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp
===================================================================
--- clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp
+++ clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp
@@ -273,14 +273,12 @@
 }
 
 ClangTidyDiagnosticConsumer::ClangTidyDiagnosticConsumer(
-    ClangTidyContext &Ctx, DiagnosticsEngine *ExternalDiagEngine,
-    bool RemoveIncompatibleErrors, bool GetFixesFromNotes,
-    bool EnableNolintBlocks)
-    : Context(Ctx), ExternalDiagEngine(ExternalDiagEngine),
-      RemoveIncompatibleErrors(RemoveIncompatibleErrors),
-      GetFixesFromNotes(GetFixesFromNotes),
-      EnableNolintBlocks(EnableNolintBlocks), LastErrorRelatesToUserCode(false),
-      LastErrorPassesLineFilter(false), LastErrorWasIgnored(false) {}
+    ClangTidyContext &Ctx, bool RemoveIncompatibleErrors,
+    bool GetFixesFromNotes, bool EnableNolintBlocks)
+    : Context(Ctx),  RemoveIncompatibleErrors(RemoveIncompatibleErrors),
+      GetFixesFromNotes(GetFixesFromNotes), EnableNolintBlocks(EnableNolintBlocks),
+      LastErrorRelatesToUserCode(false), LastErrorPassesLineFilter(false),
+      LastErrorWasIgnored(false) {}
 
 void ClangTidyDiagnosticConsumer::finalizeLastError() {
   if (!Errors.empty()) {
@@ -600,22 +598,16 @@
                         IsWarningAsError);
   }
 
-  if (ExternalDiagEngine) {
-    // If there is an external diagnostics engine, like in the
-    // ClangTidyPluginAction case, forward the diagnostics to it.
-    forwardDiagnostic(Info);
-  } else {
-    ClangTidyDiagnosticRenderer Converter(
-        Context.getLangOpts(), &Context.DiagEngine->getDiagnosticOptions(),
-        Errors.back());
-    SmallString<100> Message;
-    Info.FormatDiagnostic(Message);
-    FullSourceLoc Loc;
-    if (Info.getLocation().isValid() && Info.hasSourceManager())
+  ClangTidyDiagnosticRenderer Converter(
+      Context.getLangOpts(), &Context.DiagEngine->getDiagnosticOptions(),
+      Errors.back());
+  SmallString<100> Message;
+  Info.FormatDiagnostic(Message);
+  FullSourceLoc Loc;
+  if (Info.getLocation().isValid() && Info.hasSourceManager())
       Loc = FullSourceLoc(Info.getLocation(), Info.getSourceManager());
-    Converter.emitDiagnostic(Loc, DiagLevel, Message, Info.getRanges(),
-                             Info.getFixItHints());
-  }
+  Converter.emitDiagnostic(Loc, DiagLevel, Message, Info.getRanges(),
+                           Info.getFixItHints());
 
   if (Info.hasSourceManager())
     checkFilters(Info.getLocation(), Info.getSourceManager());
@@ -643,71 +635,6 @@
   return false;
 }
 
-void ClangTidyDiagnosticConsumer::forwardDiagnostic(const Diagnostic &Info) {
-  // Acquire a diagnostic ID also in the external diagnostics engine.
-  auto DiagLevelAndFormatString =
-      Context.getDiagLevelAndFormatString(Info.getID(), Info.getLocation());
-  unsigned ExternalID = ExternalDiagEngine->getDiagnosticIDs()->getCustomDiagID(
-      DiagLevelAndFormatString.first, DiagLevelAndFormatString.second);
-
-  // Forward the details.
-  auto Builder = ExternalDiagEngine->Report(Info.getLocation(), ExternalID);
-  for (auto Hint : Info.getFixItHints())
-    Builder << Hint;
-  for (auto Range : Info.getRanges())
-    Builder << Range;
-  for (unsigned Index = 0; Index < Info.getNumArgs(); ++Index) {
-    DiagnosticsEngine::ArgumentKind Kind = Info.getArgKind(Index);
-    switch (Kind) {
-    case clang::DiagnosticsEngine::ak_std_string:
-      Builder << Info.getArgStdStr(Index);
-      break;
-    case clang::DiagnosticsEngine::ak_c_string:
-      Builder << Info.getArgCStr(Index);
-      break;
-    case clang::DiagnosticsEngine::ak_sint:
-      Builder << Info.getArgSInt(Index);
-      break;
-    case clang::DiagnosticsEngine::ak_uint:
-      Builder << Info.getArgUInt(Index);
-      break;
-    case clang::DiagnosticsEngine::ak_tokenkind:
-      Builder << static_cast<tok::TokenKind>(Info.getRawArg(Index));
-      break;
-    case clang::DiagnosticsEngine::ak_identifierinfo:
-      Builder << Info.getArgIdentifier(Index);
-      break;
-    case clang::DiagnosticsEngine::ak_qual:
-      Builder << Qualifiers::fromOpaqueValue(Info.getRawArg(Index));
-      break;
-    case clang::DiagnosticsEngine::ak_qualtype:
-      Builder << QualType::getFromOpaquePtr((void *)Info.getRawArg(Index));
-      break;
-    case clang::DiagnosticsEngine::ak_declarationname:
-      Builder << DeclarationName::getFromOpaqueInteger(Info.getRawArg(Index));
-      break;
-    case clang::DiagnosticsEngine::ak_nameddecl:
-      Builder << reinterpret_cast<const NamedDecl *>(Info.getRawArg(Index));
-      break;
-    case clang::DiagnosticsEngine::ak_nestednamespec:
-      Builder << reinterpret_cast<NestedNameSpecifier *>(Info.getRawArg(Index));
-      break;
-    case clang::DiagnosticsEngine::ak_declcontext:
-      Builder << reinterpret_cast<DeclContext *>(Info.getRawArg(Index));
-      break;
-    case clang::DiagnosticsEngine::ak_qualtype_pair:
-      assert(false); // This one is not passed around.
-      break;
-    case clang::DiagnosticsEngine::ak_attr:
-      Builder << reinterpret_cast<Attr *>(Info.getRawArg(Index));
-      break;
-    case clang::DiagnosticsEngine::ak_addrspace:
-      Builder << static_cast<LangAS>(Info.getRawArg(Index));
-      break;
-    }
-  }
-}
-
 void ClangTidyDiagnosticConsumer::checkFilters(SourceLocation Location,
                                                const SourceManager &Sources) {
   // Invalid location may mean a diagnostic in a command line, don't skip these.
Index: clang-tools-extra/clang-tidy/ClangTidy.cpp
===================================================================
--- clang-tools-extra/clang-tidy/ClangTidy.cpp
+++ clang-tools-extra/clang-tidy/ClangTidy.cpp
@@ -542,7 +542,7 @@
   Context.setEnableProfiling(EnableCheckProfile);
   Context.setProfileStoragePrefix(StoreCheckProfile);
 
-  ClangTidyDiagnosticConsumer DiagConsumer(Context, nullptr, true, ApplyAnyFix);
+  ClangTidyDiagnosticConsumer DiagConsumer(Context, true, ApplyAnyFix);
   DiagnosticsEngine DE(new DiagnosticIDs(), new DiagnosticOptions(),
                        &DiagConsumer, /*ShouldOwnClient=*/false);
   Context.setDiagnosticsEngine(&DE);
Index: clang-tools-extra/clang-tidy/CMakeLists.txt
===================================================================
--- clang-tools-extra/clang-tidy/CMakeLists.txt
+++ clang-tools-extra/clang-tidy/CMakeLists.txt
@@ -117,7 +117,6 @@
 
 # Other subtargets. These may reference ALL_CLANG_TIDY_CHECKS
 # and must be below its definition.
-add_subdirectory(plugin)
 add_subdirectory(tool)
 add_subdirectory(utils)
 
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
  • [PATCH] D116137: [clang-tid... Matt Beardsley via Phabricator via cfe-commits

Reply via email to