Clang Project

clang_source_code/include/clang/Tooling/AllTUsExecution.h
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
17#include "clang/Tooling/ArgumentsAdjusters.h"
18#include "clang/Tooling/Execution.h"
19
20namespace clang {
21namespace tooling {
22
23/// Executes given frontend actions on all files/TUs in the compilation
24/// database.
25class AllTUsToolExecutor : public ToolExecutor {
26public:
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<PCHContainerOperationsPCHContainerOps =
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 Optionsunsigned ThreadCount,
42                     std::shared_ptr<PCHContainerOperationsPCHContainerOps =
43                         std::make_shared<PCHContainerOperations>());
44
45  StringRef getExecutorName() const override { return ExecutorName; }
46
47  bool isSingleProcess() const override { return true; }
48
49  using ToolExecutor::execute;
50
51  llvm::Error
52  execute(llvm::ArrayRef<
53          std::pair<std::unique_ptr<FrontendActionFactory>, ArgumentsAdjuster>>
54              Actions) override;
55
56  ExecutionContext *getExecutionContext() override { return &Context; };
57
58  ToolResults *getToolResults() override { return Results.get(); }
59
60  void mapVirtualFile(StringRef FilePathStringRef Content) override {
61    OverlayFiles[FilePath] = Content;
62  }
63
64private:
65  // Used to store the parser when the executor is initialized with parser.
66  llvm::Optional<CommonOptionsParserOptionsParser;
67  const CompilationDatabase &Compilations;
68  std::unique_ptr<ToolResultsResults;
69  ExecutionContext Context;
70  llvm::StringMap<std::string> OverlayFiles;
71  unsigned ThreadCount;
72};
73
74extern llvm::cl::opt<std::string> Filter;
75
76// end namespace tooling
77// end namespace clang
78
79#endif // LLVM_CLANG_TOOLING_ALLTUSEXECUTION_H
80
clang::tooling::AllTUsToolExecutor::ExecutorName
clang::tooling::AllTUsToolExecutor::getExecutorName
clang::tooling::AllTUsToolExecutor::isSingleProcess
clang::tooling::AllTUsToolExecutor::execute
clang::tooling::AllTUsToolExecutor::getExecutionContext
clang::tooling::AllTUsToolExecutor::getToolResults
clang::tooling::AllTUsToolExecutor::mapVirtualFile
clang::tooling::AllTUsToolExecutor::OptionsParser
clang::tooling::AllTUsToolExecutor::Compilations
clang::tooling::AllTUsToolExecutor::Results
clang::tooling::AllTUsToolExecutor::Context
clang::tooling::AllTUsToolExecutor::OverlayFiles
clang::tooling::AllTUsToolExecutor::ThreadCount