]> granicus.if.org Git - clang/commitdiff
[CommonOptionsParser] Expose ArgumentsAdjustingCompilationDatabase
authorJohannes Altmanninger <aclopte@gmail.com>
Fri, 18 Aug 2017 16:21:08 +0000 (16:21 +0000)
committerJohannes Altmanninger <aclopte@gmail.com>
Fri, 18 Aug 2017 16:21:08 +0000 (16:21 +0000)
This is useful for tools such as clang-diff which do not use
CommonOptionsParser due to the need for multiple compilation databases.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@311170 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Tooling/CommonOptionsParser.h
lib/Tooling/CommonOptionsParser.cpp

index 3d630c5f7609cddae5a2163d673d06287827fce3..c535603d365dd36904e3d45a245a0f8117d311c6 100644 (file)
@@ -27,6 +27,7 @@
 #ifndef LLVM_CLANG_TOOLING_COMMONOPTIONSPARSER_H
 #define LLVM_CLANG_TOOLING_COMMONOPTIONSPARSER_H
 
+#include "clang/Tooling/ArgumentsAdjusters.h"
 #include "clang/Tooling/CompilationDatabase.h"
 #include "llvm/Support/CommandLine.h"
 
@@ -111,6 +112,29 @@ private:
   std::vector<std::string> ExtraArgsAfter;
 };
 
+class ArgumentsAdjustingCompilations : public CompilationDatabase {
+public:
+  ArgumentsAdjustingCompilations(
+      std::unique_ptr<CompilationDatabase> Compilations)
+      : Compilations(std::move(Compilations)) {}
+
+  void appendArgumentsAdjuster(ArgumentsAdjuster Adjuster);
+
+  std::vector<CompileCommand>
+  getCompileCommands(StringRef FilePath) const override;
+
+  std::vector<std::string> getAllFiles() const override;
+
+  std::vector<CompileCommand> getAllCompileCommands() const override;
+
+private:
+  std::unique_ptr<CompilationDatabase> Compilations;
+  std::vector<ArgumentsAdjuster> Adjusters;
+
+  std::vector<CompileCommand>
+  adjustCommands(std::vector<CompileCommand> Commands) const;
+};
+
 }  // namespace tooling
 }  // namespace clang
 
index 9e9689e6b2524a4bb00d684862d6eb83e7f1bf4e..3ef223fa55662df0db4a5680fd9d04dc91182196 100644 (file)
@@ -25,7 +25,6 @@
 //===----------------------------------------------------------------------===//
 
 #include "llvm/Support/CommandLine.h"
-#include "clang/Tooling/ArgumentsAdjusters.h"
 #include "clang/Tooling/CommonOptionsParser.h"
 #include "clang/Tooling/Tooling.h"
 
@@ -54,43 +53,33 @@ const char *const CommonOptionsParser::HelpMessage =
     "\tsuffix of a path in the compile command database.\n"
     "\n";
 
-namespace {
-class ArgumentsAdjustingCompilations : public CompilationDatabase {
-public:
-  ArgumentsAdjustingCompilations(
-      std::unique_ptr<CompilationDatabase> Compilations)
-      : Compilations(std::move(Compilations)) {}
-
-  void appendArgumentsAdjuster(ArgumentsAdjuster Adjuster) {
-    Adjusters.push_back(std::move(Adjuster));
-  }
-
-  std::vector<CompileCommand>
-  getCompileCommands(StringRef FilePath) const override {
-    return adjustCommands(Compilations->getCompileCommands(FilePath));
-  }
+void ArgumentsAdjustingCompilations::appendArgumentsAdjuster(
+    ArgumentsAdjuster Adjuster) {
+  Adjusters.push_back(std::move(Adjuster));
+}
 
-  std::vector<std::string> getAllFiles() const override {
-    return Compilations->getAllFiles();
-  }
+std::vector<CompileCommand> ArgumentsAdjustingCompilations::getCompileCommands(
+    StringRef FilePath) const {
+  return adjustCommands(Compilations->getCompileCommands(FilePath));
+}
 
-  std::vector<CompileCommand> getAllCompileCommands() const override {
-    return adjustCommands(Compilations->getAllCompileCommands());
-  }
+std::vector<std::string>
+ArgumentsAdjustingCompilations::getAllFiles() const {
+  return Compilations->getAllFiles();
+}
 
-private:
-  std::unique_ptr<CompilationDatabase> Compilations;
-  std::vector<ArgumentsAdjuster> Adjusters;
+std::vector<CompileCommand>
+ArgumentsAdjustingCompilations::getAllCompileCommands() const {
+  return adjustCommands(Compilations->getAllCompileCommands());
+}
 
-  std::vector<CompileCommand>
-  adjustCommands(std::vector<CompileCommand> Commands) const {
-    for (CompileCommand &Command : Commands)
-      for (const auto &Adjuster : Adjusters)
-        Command.CommandLine = Adjuster(Command.CommandLine, Command.Filename);
-    return Commands;
-  }
-};
-} // namespace
+std::vector<CompileCommand> ArgumentsAdjustingCompilations::adjustCommands(
+    std::vector<CompileCommand> Commands) const {
+  for (CompileCommand &Command : Commands)
+    for (const auto &Adjuster : Adjusters)
+      Command.CommandLine = Adjuster(Command.CommandLine, Command.Filename);
+  return Commands;
+}
 
 CommonOptionsParser::CommonOptionsParser(
     int &argc, const char **argv, cl::OptionCategory &Category,