clang  6.0.0svn
StandaloneExecution.h
Go to the documentation of this file.
1 //===--- StandaloneExecution.h - Standalone execution. -*- C++ ----------*-===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file defines standalone execution of clang tools.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #ifndef LLVM_CLANG_TOOLING_STANDALONEEXECUTION_H
15 #define LLVM_CLANG_TOOLING_STANDALONEEXECUTION_H
16 
19 
20 namespace clang {
21 namespace tooling {
22 
23 /// \brief A standalone executor that runs FrontendActions on a given set of
24 /// TUs in sequence.
25 ///
26 /// By default, this executor uses the following arguments adjusters (as defined
27 /// in `clang/Tooling/ArgumentsAdjusters.h`):
28 /// - `getClangStripOutputAdjuster()`
29 /// - `getClangSyntaxOnlyAdjuster()`
30 /// - `getClangStripDependencyFileAdjuster()`
32 public:
33  static const char *ExecutorName;
34 
35  /// \brief Init with \p CompilationDatabase and the paths of all files to be
36  /// proccessed.
38  const CompilationDatabase &Compilations,
39  llvm::ArrayRef<std::string> SourcePaths,
40  std::shared_ptr<PCHContainerOperations> PCHContainerOps =
41  std::make_shared<PCHContainerOperations>());
42 
43  /// \brief Init with \p CommonOptionsParser. This is expected to be used by
44  /// `createExecutorFromCommandLineArgs` based on commandline options.
45  ///
46  /// The executor takes ownership of \p Options.
48  CommonOptionsParser Options,
49  std::shared_ptr<PCHContainerOperations> PCHContainerOps =
50  std::make_shared<PCHContainerOperations>());
51 
52  StringRef getExecutorName() const override { return ExecutorName; }
53 
55 
58  std::pair<std::unique_ptr<FrontendActionFactory>, ArgumentsAdjuster>>
59  Actions) override;
60 
61  /// \brief Set a \c DiagnosticConsumer to use during parsing.
63  Tool.setDiagnosticConsumer(DiagConsumer);
64  }
65 
66  ExecutionContext *getExecutionContext() override { return &Context; };
67 
68  ToolResults *getToolResults() override { return &Results; }
69 
71  return Tool.getSourcePaths();
72  }
73 
74  void mapVirtualFile(StringRef FilePath, StringRef Content) override {
75  Tool.mapVirtualFile(FilePath, Content);
76  }
77 
78  /// \brief Returns the file manager used in the tool.
79  ///
80  /// The file manager is shared between all translation units.
81  FileManager &getFiles() { return Tool.getFiles(); }
82 
83 private:
84  // Used to store the parser when the executor is initialized with parser.
86  // FIXME: The standalone executor is currently just a wrapper of `ClangTool`.
87  // Merge `ClangTool` implementation into the this.
88  ClangTool Tool;
89  ExecutionContext Context;
90  InMemoryToolResults Results;
91  ArgumentsAdjuster ArgsAdjuster;
92 };
93 
94 } // end namespace tooling
95 } // end namespace clang
96 
97 #endif // LLVM_CLANG_TOOLING_STANDALONEEXECUTION_H
virtual llvm::Error execute(llvm::ArrayRef< std::pair< std::unique_ptr< FrontendActionFactory >, ArgumentsAdjuster >> Actions)=0
Executes each action with a corresponding arguments adjuster.
void setDiagnosticConsumer(DiagnosticConsumer *DiagConsumer)
Set a DiagnosticConsumer to use during parsing.
Definition: Tooling.h:307
ExecutionContext * getExecutionContext() override
Returns a reference to the execution context.
Implements support for file system lookup, file system caching, and directory search management...
Definition: FileManager.h:116
llvm::Error execute(llvm::ArrayRef< std::pair< std::unique_ptr< FrontendActionFactory >, ArgumentsAdjuster >> Actions) override
Executes each action with a corresponding arguments adjuster.
Utility to run a FrontendAction over a set of files.
Definition: Tooling.h:289
FileManager & getFiles()
Returns the file manager used in the tool.
Abstract interface, implemented by clients of the front-end, which formats and prints fully processed...
Definition: Diagnostic.h:1397
The context of an execution, including the information about compilation and results.
Definition: Execution.h:66
void mapVirtualFile(StringRef FilePath, StringRef Content)
Map a virtual file to be used while running the tool.
Definition: Tooling.cpp:346
std::function< CommandLineArguments(const CommandLineArguments &, StringRef Filename)> ArgumentsAdjuster
A prototype of a command line adjuster.
Interface for executing clang frontend actions.
Definition: Execution.h:100
FileManager & getFiles()
Returns the file manager used in the tool.
Definition: Tooling.h:338
llvm::ArrayRef< std::string > getSourcePaths() const
A standalone executor that runs FrontendActions on a given set of TUs in sequence.
Interface for compilation databases.
A parser for options common to all command-line Clang tools.
void setDiagnosticConsumer(DiagnosticConsumer *DiagConsumer)
Set a DiagnosticConsumer to use during parsing.
StringRef getExecutorName() const override
Returns the name of a specific executor.
Dataflow Directional Tag Classes.
An abstraction for the result of a tool execution.
Definition: Execution.h:44
llvm::ArrayRef< std::string > getSourcePaths() const
Definition: Tooling.h:340
StandaloneToolExecutor(const CompilationDatabase &Compilations, llvm::ArrayRef< std::string > SourcePaths, std::shared_ptr< PCHContainerOperations > PCHContainerOps=std::make_shared< PCHContainerOperations >())
Init with CompilationDatabase and the paths of all files to be proccessed.
void mapVirtualFile(StringRef FilePath, StringRef Content) override
Map a virtual file to be used while running the tool.
ToolResults * getToolResults() override
Returns a reference to the result container.