clang 19.0.0git
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#include <optional>
20
21namespace clang {
22namespace tooling {
23
24/// Executes given frontend actions on all files/TUs in the compilation
25/// database.
27public:
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
49
50 llvm::Error
52 std::pair<std::unique_ptr<FrontendActionFactory>, ArgumentsAdjuster>>
53 Actions) override;
54
55 ExecutionContext *getExecutionContext() override { return &Context; };
56
57 ToolResults *getToolResults() override { return Results.get(); }
58
59 void mapVirtualFile(StringRef FilePath, StringRef Content) override {
60 OverlayFiles[FilePath] = std::string(Content);
61 }
62
63private:
64 // Used to store the parser when the executor is initialized with parser.
65 std::optional<CommonOptionsParser> OptionsParser;
66 const CompilationDatabase &Compilations;
67 std::unique_ptr<ToolResults> Results;
68 ExecutionContext Context;
69 llvm::StringMap<std::string> OverlayFiles;
70 unsigned ThreadCount;
71};
72
73extern llvm::cl::opt<unsigned> ExecutorConcurrency;
74extern llvm::cl::opt<std::string> Filter;
75
76} // end namespace tooling
77} // end namespace clang
78
79#endif // LLVM_CLANG_TOOLING_ALLTUSEXECUTION_H
Executes given frontend actions on all files/TUs in the compilation database.
ToolResults * getToolResults() override
Returns a reference to the result container.
void mapVirtualFile(StringRef FilePath, StringRef Content) override
Map a virtual file to be used while running the tool.
llvm::Error execute(llvm::ArrayRef< std::pair< std::unique_ptr< FrontendActionFactory >, ArgumentsAdjuster > > Actions) override
Executes each action with a corresponding arguments adjuster.
ExecutionContext * getExecutionContext() override
Returns a reference to the execution context.
StringRef getExecutorName() const override
Returns the name of a specific executor.
A parser for options common to all command-line Clang tools.
Interface for compilation databases.
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
virtual llvm::Error execute(llvm::ArrayRef< std::pair< std::unique_ptr< FrontendActionFactory >, ArgumentsAdjuster > > Actions)=0
Executes each action with a corresponding arguments adjuster.
An abstraction for the result of a tool execution.
Definition: Execution.h:46
llvm::cl::opt< unsigned > ExecutorConcurrency
std::function< CommandLineArguments(const CommandLineArguments &, StringRef Filename)> ArgumentsAdjuster
A prototype of a command line adjuster.
llvm::cl::opt< std::string > Filter
The JSON file list parser is used to communicate input to InstallAPI.