Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:37:12

0001 //===--- AllTUsExecution.h - Execute actions on all TUs. -*- C++ --------*-===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 //
0009 //  This file defines a tool executor that runs given actions on all TUs in the
0010 //  compilation database. Tool results are deuplicated by the result key.
0011 //
0012 //===----------------------------------------------------------------------===//
0013 
0014 #ifndef LLVM_CLANG_TOOLING_ALLTUSEXECUTION_H
0015 #define LLVM_CLANG_TOOLING_ALLTUSEXECUTION_H
0016 
0017 #include "clang/Tooling/ArgumentsAdjusters.h"
0018 #include "clang/Tooling/Execution.h"
0019 #include <optional>
0020 
0021 namespace clang {
0022 namespace tooling {
0023 
0024 /// Executes given frontend actions on all files/TUs in the compilation
0025 /// database.
0026 class AllTUsToolExecutor : public ToolExecutor {
0027 public:
0028   static const char *ExecutorName;
0029 
0030   /// Init with \p CompilationDatabase.
0031   /// This uses \p ThreadCount threads to exececute the actions on all files in
0032   /// parallel. If \p ThreadCount is 0, this uses `llvm::hardware_concurrency`.
0033   AllTUsToolExecutor(const CompilationDatabase &Compilations,
0034                      unsigned ThreadCount,
0035                      std::shared_ptr<PCHContainerOperations> PCHContainerOps =
0036                          std::make_shared<PCHContainerOperations>());
0037 
0038   /// Init with \p CommonOptionsParser. This is expected to be used by
0039   /// `createExecutorFromCommandLineArgs` based on commandline options.
0040   ///
0041   /// The executor takes ownership of \p Options.
0042   AllTUsToolExecutor(CommonOptionsParser Options, unsigned ThreadCount,
0043                      std::shared_ptr<PCHContainerOperations> PCHContainerOps =
0044                          std::make_shared<PCHContainerOperations>());
0045 
0046   StringRef getExecutorName() const override { return ExecutorName; }
0047 
0048   using ToolExecutor::execute;
0049 
0050   llvm::Error
0051   execute(llvm::ArrayRef<
0052           std::pair<std::unique_ptr<FrontendActionFactory>, ArgumentsAdjuster>>
0053               Actions) override;
0054 
0055   ExecutionContext *getExecutionContext() override { return &Context; };
0056 
0057   ToolResults *getToolResults() override { return Results.get(); }
0058 
0059   void mapVirtualFile(StringRef FilePath, StringRef Content) override {
0060     OverlayFiles[FilePath] = std::string(Content);
0061   }
0062 
0063 private:
0064   // Used to store the parser when the executor is initialized with parser.
0065   std::optional<CommonOptionsParser> OptionsParser;
0066   const CompilationDatabase &Compilations;
0067   std::unique_ptr<ToolResults> Results;
0068   ExecutionContext Context;
0069   llvm::StringMap<std::string> OverlayFiles;
0070   unsigned ThreadCount;
0071 };
0072 
0073 extern llvm::cl::opt<unsigned> ExecutorConcurrency;
0074 extern llvm::cl::opt<std::string> Filter;
0075 
0076 } // end namespace tooling
0077 } // end namespace clang
0078 
0079 #endif // LLVM_CLANG_TOOLING_ALLTUSEXECUTION_H