diff --git a/clang/include/clang/Tooling/CommonOptionsParser.h b/clang/include/clang/Tooling/CommonOptionsParser.h index 3d630c5f7609..c535603d365d 100644 --- a/clang/include/clang/Tooling/CommonOptionsParser.h +++ b/clang/include/clang/Tooling/CommonOptionsParser.h @@ -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 ExtraArgsAfter; }; +class ArgumentsAdjustingCompilations : public CompilationDatabase { +public: + ArgumentsAdjustingCompilations( + std::unique_ptr Compilations) + : Compilations(std::move(Compilations)) {} + + void appendArgumentsAdjuster(ArgumentsAdjuster Adjuster); + + std::vector + getCompileCommands(StringRef FilePath) const override; + + std::vector getAllFiles() const override; + + std::vector getAllCompileCommands() const override; + +private: + std::unique_ptr Compilations; + std::vector Adjusters; + + std::vector + adjustCommands(std::vector Commands) const; +}; + } // namespace tooling } // namespace clang diff --git a/clang/lib/Tooling/CommonOptionsParser.cpp b/clang/lib/Tooling/CommonOptionsParser.cpp index 9e9689e6b252..3ef223fa5566 100644 --- a/clang/lib/Tooling/CommonOptionsParser.cpp +++ b/clang/lib/Tooling/CommonOptionsParser.cpp @@ -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 Compilations) - : Compilations(std::move(Compilations)) {} +void ArgumentsAdjustingCompilations::appendArgumentsAdjuster( + ArgumentsAdjuster Adjuster) { + Adjusters.push_back(std::move(Adjuster)); +} - void appendArgumentsAdjuster(ArgumentsAdjuster Adjuster) { - Adjusters.push_back(std::move(Adjuster)); - } +std::vector ArgumentsAdjustingCompilations::getCompileCommands( + StringRef FilePath) const { + return adjustCommands(Compilations->getCompileCommands(FilePath)); +} - std::vector - getCompileCommands(StringRef FilePath) const override { - return adjustCommands(Compilations->getCompileCommands(FilePath)); - } +std::vector +ArgumentsAdjustingCompilations::getAllFiles() const { + return Compilations->getAllFiles(); +} - std::vector getAllFiles() const override { - return Compilations->getAllFiles(); - } +std::vector +ArgumentsAdjustingCompilations::getAllCompileCommands() const { + return adjustCommands(Compilations->getAllCompileCommands()); +} - std::vector getAllCompileCommands() const override { - return adjustCommands(Compilations->getAllCompileCommands()); - } - -private: - std::unique_ptr Compilations; - std::vector Adjusters; - - std::vector - adjustCommands(std::vector Commands) const { - for (CompileCommand &Command : Commands) - for (const auto &Adjuster : Adjusters) - Command.CommandLine = Adjuster(Command.CommandLine, Command.Filename); - return Commands; - } -}; -} // namespace +std::vector ArgumentsAdjustingCompilations::adjustCommands( + std::vector 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,