From a01ddc787b5c8b1cf11e975d3586908d3629954c Mon Sep 17 00:00:00 2001 From: Simon Atanasyan Date: Wed, 9 May 2012 16:18:30 +0000 Subject: Declare abstract class ArgumentsAdjuster. This abstract interface describes a command line argument adjuster, which is responsible for command line arguments modification before the arguments are used to run a frontend action. Define class ClangSyntaxOnlyAdjuster implements ArgumentsAdjuster interface. This class converts input command line arguments to the "syntax check only" variant. Reviewed by Manuel Klimek. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@156478 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Tooling/Tooling.cpp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'lib/Tooling/Tooling.cpp') diff --git a/lib/Tooling/Tooling.cpp b/lib/Tooling/Tooling.cpp index 9b4d4e2e23..abd670380e 100644 --- a/lib/Tooling/Tooling.cpp +++ b/lib/Tooling/Tooling.cpp @@ -12,6 +12,7 @@ // //===----------------------------------------------------------------------===// +#include "clang/Tooling/ArgumentsAdjusters.h" #include "clang/Tooling/Tooling.h" #include "clang/Tooling/CompilationDatabase.h" #include "clang/Driver/Compilation.h" @@ -253,7 +254,8 @@ void ToolInvocation::addFileMappingsTo(SourceManager &Sources) { ClangTool::ClangTool(const CompilationDatabase &Compilations, ArrayRef SourcePaths) - : Files((FileSystemOptions())) { + : Files((FileSystemOptions())), + ArgsAdjuster(new ClangSyntaxOnlyAdjuster()) { llvm::SmallString<1024> BaseDirectory; if (const char *PWD = ::getenv("PWD")) BaseDirectory = PWD; @@ -285,6 +287,10 @@ void ClangTool::mapVirtualFile(StringRef FilePath, StringRef Content) { MappedFileContents.push_back(std::make_pair(FilePath, Content)); } +void ClangTool::setArgumentsAdjuster(ArgumentsAdjuster *Adjuster) { + ArgsAdjuster.reset(Adjuster); +} + int ClangTool::run(FrontendActionFactory *ActionFactory) { bool ProcessingFailed = false; for (unsigned I = 0; I < CompileCommands.size(); ++I) { @@ -299,8 +305,8 @@ int ClangTool::run(FrontendActionFactory *ActionFactory) { if (chdir(CompileCommands[I].second.Directory.c_str())) llvm::report_fatal_error("Cannot chdir into \"" + CompileCommands[I].second.Directory + "\n!"); - std::vector &CommandLine = - CompileCommands[I].second.CommandLine; + std::vector CommandLine = + ArgsAdjuster->Adjust(CompileCommands[I].second.CommandLine); llvm::outs() << "Processing: " << File << ".\n"; ToolInvocation Invocation(CommandLine, ActionFactory->create(), &Files); for (int I = 0, E = MappedFileContents.size(); I != E; ++I) { -- cgit v1.2.3-18-g5258