]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/clang/include/clang/Tooling/StandaloneExecution.h
Merge clang 7.0.1 and several follow-up changes
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / clang / include / clang / Tooling / StandaloneExecution.h
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
17 #include "clang/Tooling/ArgumentsAdjusters.h"
18 #include "clang/Tooling/Execution.h"
19
20 namespace clang {
21 namespace tooling {
22
23 /// 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()`
31 class StandaloneToolExecutor : public ToolExecutor {
32 public:
33   static const char *ExecutorName;
34
35   /// Init with \p CompilationDatabase and the paths of all files to be
36   /// proccessed.
37   StandaloneToolExecutor(
38       const CompilationDatabase &Compilations,
39       llvm::ArrayRef<std::string> SourcePaths,
40       IntrusiveRefCntPtr<vfs::FileSystem> BaseFS = vfs::getRealFileSystem(),
41       std::shared_ptr<PCHContainerOperations> PCHContainerOps =
42           std::make_shared<PCHContainerOperations>());
43
44   /// Init with \p CommonOptionsParser. This is expected to be used by
45   /// `createExecutorFromCommandLineArgs` based on commandline options.
46   ///
47   /// The executor takes ownership of \p Options.
48   StandaloneToolExecutor(
49       CommonOptionsParser Options,
50       std::shared_ptr<PCHContainerOperations> PCHContainerOps =
51           std::make_shared<PCHContainerOperations>());
52
53   StringRef getExecutorName() const override { return ExecutorName; }
54
55   using ToolExecutor::execute;
56
57   llvm::Error
58   execute(llvm::ArrayRef<
59           std::pair<std::unique_ptr<FrontendActionFactory>, ArgumentsAdjuster>>
60               Actions) override;
61
62   /// Set a \c DiagnosticConsumer to use during parsing.
63   void setDiagnosticConsumer(DiagnosticConsumer *DiagConsumer) {
64     Tool.setDiagnosticConsumer(DiagConsumer);
65   }
66
67   ExecutionContext *getExecutionContext() override { return &Context; };
68
69   ToolResults *getToolResults() override { return &Results; }
70
71   llvm::ArrayRef<std::string> getSourcePaths() const {
72     return Tool.getSourcePaths();
73   }
74
75   void mapVirtualFile(StringRef FilePath, StringRef Content) override {
76     Tool.mapVirtualFile(FilePath, Content);
77   }
78
79   /// Returns the file manager used in the tool.
80   ///
81   /// The file manager is shared between all translation units.
82   FileManager &getFiles() { return Tool.getFiles(); }
83
84 private:
85   // Used to store the parser when the executor is initialized with parser.
86   llvm::Optional<CommonOptionsParser> OptionsParser;
87   // FIXME: The standalone executor is currently just a wrapper of `ClangTool`.
88   // Merge `ClangTool` implementation into the this.
89   ClangTool Tool;
90   ExecutionContext Context;
91   InMemoryToolResults Results;
92   ArgumentsAdjuster ArgsAdjuster;
93 };
94
95 } // end namespace tooling
96 } // end namespace clang
97
98 #endif // LLVM_CLANG_TOOLING_STANDALONEEXECUTION_H