clang  10.0.0svn
AllTUsExecution.h
Go to the documentation of this file.
1 //===--- AllTUsExecution.h - Execute actions on all TUs. -*- C++ --------*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file defines a tool executor that runs given actions on all TUs in the
10 // compilation database. Tool results are deuplicated by the result key.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #ifndef LLVM_CLANG_TOOLING_ALLTUSEXECUTION_H
15 #define LLVM_CLANG_TOOLING_ALLTUSEXECUTION_H
16 
19 
20 namespace clang {
21 namespace tooling {
22 
23 /// Executes given frontend actions on all files/TUs in the compilation
24 /// database.
26 public:
27  static const char *ExecutorName;
28 
29  /// Init with \p CompilationDatabase.
30  /// This uses \p ThreadCount threads to exececute the actions on all files in
31  /// parallel. If \p ThreadCount is 0, this uses `llvm::hardware_concurrency`.
32  AllTUsToolExecutor(const CompilationDatabase &Compilations,
33  unsigned ThreadCount,
34  std::shared_ptr<PCHContainerOperations> PCHContainerOps =
35  std::make_shared<PCHContainerOperations>());
36 
37  /// Init with \p CommonOptionsParser. This is expected to be used by
38  /// `createExecutorFromCommandLineArgs` based on commandline options.
39  ///
40  /// The executor takes ownership of \p Options.
41  AllTUsToolExecutor(CommonOptionsParser Options, unsigned ThreadCount,
42  std::shared_ptr<PCHContainerOperations> PCHContainerOps =
43  std::make_shared<PCHContainerOperations>());
44 
45  StringRef getExecutorName() const override { return ExecutorName; }
46 
48 
51  std::pair<std::unique_ptr<FrontendActionFactory>, ArgumentsAdjuster>>
52  Actions) override;
53 
54  ExecutionContext *getExecutionContext() override { return &Context; };
55 
56  ToolResults *getToolResults() override { return Results.get(); }
57 
58  void mapVirtualFile(StringRef FilePath, StringRef Content) override {
59  OverlayFiles[FilePath] = Content;
60  }
61 
62 private:
63  // Used to store the parser when the executor is initialized with parser.
65  const CompilationDatabase &Compilations;
66  std::unique_ptr<ToolResults> Results;
67  ExecutionContext Context;
68  llvm::StringMap<std::string> OverlayFiles;
69  unsigned ThreadCount;
70 };
71 
72 extern llvm::cl::opt<unsigned> ExecutorConcurrency;
73 extern llvm::cl::opt<std::string> Filter;
74 
75 } // end namespace tooling
76 } // end namespace clang
77 
78 #endif // LLVM_CLANG_TOOLING_ALLTUSEXECUTION_H
virtual llvm::Error execute(llvm::ArrayRef< std::pair< std::unique_ptr< FrontendActionFactory >, ArgumentsAdjuster >> Actions)=0
Executes each action with a corresponding arguments adjuster.
ExecutionContext * getExecutionContext() override
Returns a reference to the execution context.
void mapVirtualFile(StringRef FilePath, StringRef Content) override
Map a virtual file to be used while running the tool.
StringRef getExecutorName() const override
Returns the name of a specific executor.
The context of an execution, including the information about compilation and results.
Definition: Execution.h:77
Interface for executing clang frontend actions.
Definition: Execution.h:111
std::function< CommandLineArguments(const CommandLineArguments &, StringRef Filename)> ArgumentsAdjuster
A prototype of a command line adjuster.
llvm::Error execute(llvm::ArrayRef< std::pair< std::unique_ptr< FrontendActionFactory >, ArgumentsAdjuster >> Actions) override
Executes each action with a corresponding arguments adjuster.
Interface for compilation databases.
llvm::cl::opt< std::string > Filter
A parser for options common to all command-line Clang tools.
Executes given frontend actions on all files/TUs in the compilation database.
Dataflow Directional Tag Classes.
An abstraction for the result of a tool execution.
Definition: Execution.h:46
AllTUsToolExecutor(const CompilationDatabase &Compilations, unsigned ThreadCount, std::shared_ptr< PCHContainerOperations > PCHContainerOps=std::make_shared< PCHContainerOperations >())
Init with CompilationDatabase.
ToolResults * getToolResults() override
Returns a reference to the result container.
llvm::cl::opt< unsigned > ExecutorConcurrency