Index: include/clang/Tooling/CommonOptionsParser.h =================================================================== --- include/clang/Tooling/CommonOptionsParser.h +++ 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 @@ 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 Index: lib/Tooling/CommonOptionsParser.cpp =================================================================== --- lib/Tooling/CommonOptionsParser.cpp +++ 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 @@ "\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 appendArgumentsAdjuster(ArgumentsAdjuster Adjuster) { - Adjusters.push_back(std::move(Adjuster)); - } - - std::vector - getCompileCommands(StringRef FilePath) const override { - return adjustCommands(Compilations->getCompileCommands(FilePath)); - } +void ArgumentsAdjustingCompilations::appendArgumentsAdjuster( + ArgumentsAdjuster Adjuster) { + Adjusters.push_back(std::move(Adjuster)); +} - std::vector getAllFiles() const override { - return Compilations->getAllFiles(); - } +std::vector ArgumentsAdjustingCompilations::getCompileCommands( + StringRef FilePath) const { + return adjustCommands(Compilations->getCompileCommands(FilePath)); +} - std::vector getAllCompileCommands() const override { - return adjustCommands(Compilations->getAllCompileCommands()); - } +std::vector +ArgumentsAdjustingCompilations::getAllFiles() const { + return Compilations->getAllFiles(); +} -private: - std::unique_ptr Compilations; - std::vector Adjusters; +std::vector +ArgumentsAdjustingCompilations::getAllCompileCommands() const { + return adjustCommands(Compilations->getAllCompileCommands()); +} - 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,