r311170 - [CommonOptionsParser] Expose ArgumentsAdjustingCompilationDatabase

Johannes Altmanninger via cfe-commits cfe-commits at lists.llvm.org
Fri Aug 18 09:21:08 PDT 2017


Author: krobelus
Date: Fri Aug 18 09:21:08 2017
New Revision: 311170

URL: http://llvm.org/viewvc/llvm-project?rev=311170&view=rev
Log:
[CommonOptionsParser] Expose ArgumentsAdjustingCompilationDatabase

This is useful for tools such as clang-diff which do not use
CommonOptionsParser due to the need for multiple compilation databases.

Modified:
    cfe/trunk/include/clang/Tooling/CommonOptionsParser.h
    cfe/trunk/lib/Tooling/CommonOptionsParser.cpp

Modified: cfe/trunk/include/clang/Tooling/CommonOptionsParser.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Tooling/CommonOptionsParser.h?rev=311170&r1=311169&r2=311170&view=diff
==============================================================================
--- cfe/trunk/include/clang/Tooling/CommonOptionsParser.h (original)
+++ cfe/trunk/include/clang/Tooling/CommonOptionsParser.h Fri Aug 18 09:21:08 2017
@@ -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
 

Modified: cfe/trunk/lib/Tooling/CommonOptionsParser.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Tooling/CommonOptionsParser.cpp?rev=311170&r1=311169&r2=311170&view=diff
==============================================================================
--- cfe/trunk/lib/Tooling/CommonOptionsParser.cpp (original)
+++ cfe/trunk/lib/Tooling/CommonOptionsParser.cpp Fri Aug 18 09:21:08 2017
@@ -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::H
     "\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));
-  }
-
-  std::vector<std::string> getAllFiles() const override {
-    return Compilations->getAllFiles();
-  }
-
-  std::vector<CompileCommand> getAllCompileCommands() const override {
-    return adjustCommands(Compilations->getAllCompileCommands());
-  }
-
-private:
-  std::unique_ptr<CompilationDatabase> Compilations;
-  std::vector<ArgumentsAdjuster> Adjusters;
-
-  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
+void ArgumentsAdjustingCompilations::appendArgumentsAdjuster(
+    ArgumentsAdjuster Adjuster) {
+  Adjusters.push_back(std::move(Adjuster));
+}
+
+std::vector<CompileCommand> ArgumentsAdjustingCompilations::getCompileCommands(
+    StringRef FilePath) const {
+  return adjustCommands(Compilations->getCompileCommands(FilePath));
+}
+
+std::vector<std::string>
+ArgumentsAdjustingCompilations::getAllFiles() const {
+  return Compilations->getAllFiles();
+}
+
+std::vector<CompileCommand>
+ArgumentsAdjustingCompilations::getAllCompileCommands() const {
+  return adjustCommands(Compilations->getAllCompileCommands());
+}
+
+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,




More information about the cfe-commits mailing list