]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/clang/include/clang/Tooling/AllTUsExecution.h
Merge llvm, clang, compiler-rt, libc++, libunwind, lld, lldb and openmp
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / clang / include / clang / Tooling / AllTUsExecution.h
1 //===--- AllTUsExecution.h - Execute actions on all TUs. -*- 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 a tool executor that runs given actions on all TUs in the
11 //  compilation database. Tool results are deuplicated by the result key.
12 //
13 //===----------------------------------------------------------------------===//
14
15 #ifndef LLVM_CLANG_TOOLING_ALLTUSEXECUTION_H
16 #define LLVM_CLANG_TOOLING_ALLTUSEXECUTION_H
17
18 #include "clang/Tooling/ArgumentsAdjusters.h"
19 #include "clang/Tooling/Execution.h"
20
21 namespace clang {
22 namespace tooling {
23
24 /// Executes given frontend actions on all files/TUs in the compilation
25 /// database.
26 class AllTUsToolExecutor : public ToolExecutor {
27 public:
28   static const char *ExecutorName;
29
30   /// Init with \p CompilationDatabase.
31   /// This uses \p ThreadCount threads to exececute the actions on all files in
32   /// parallel. If \p ThreadCount is 0, this uses `llvm::hardware_concurrency`.
33   AllTUsToolExecutor(const CompilationDatabase &Compilations,
34                      unsigned ThreadCount,
35                      std::shared_ptr<PCHContainerOperations> PCHContainerOps =
36                          std::make_shared<PCHContainerOperations>());
37
38   /// Init with \p CommonOptionsParser. This is expected to be used by
39   /// `createExecutorFromCommandLineArgs` based on commandline options.
40   ///
41   /// The executor takes ownership of \p Options.
42   AllTUsToolExecutor(CommonOptionsParser Options, unsigned ThreadCount,
43                      std::shared_ptr<PCHContainerOperations> PCHContainerOps =
44                          std::make_shared<PCHContainerOperations>());
45
46   StringRef getExecutorName() const override { return ExecutorName; }
47
48   bool isSingleProcess() const override { return true; }
49
50   using ToolExecutor::execute;
51
52   llvm::Error
53   execute(llvm::ArrayRef<
54           std::pair<std::unique_ptr<FrontendActionFactory>, ArgumentsAdjuster>>
55               Actions) override;
56
57   ExecutionContext *getExecutionContext() override { return &Context; };
58
59   ToolResults *getToolResults() override { return Results.get(); }
60
61   void mapVirtualFile(StringRef FilePath, StringRef Content) override {
62     OverlayFiles[FilePath] = Content;
63   }
64
65 private:
66   // Used to store the parser when the executor is initialized with parser.
67   llvm::Optional<CommonOptionsParser> OptionsParser;
68   const CompilationDatabase &Compilations;
69   std::unique_ptr<ToolResults> Results;
70   ExecutionContext Context;
71   llvm::StringMap<std::string> OverlayFiles;
72   unsigned ThreadCount;
73 };
74
75 extern llvm::cl::opt<std::string> Filter;
76
77 } // end namespace tooling
78 } // end namespace clang
79
80 #endif // LLVM_CLANG_TOOLING_ALLTUSEXECUTION_H