//===- DependencyScanner.h - Performs module dependency scanning *- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// #ifndef LLVM_CLANG_TOOLING_DEPENDENCYSCANNING_DEPENDENCYSCANNER_H #define LLVM_CLANG_TOOLING_DEPENDENCYSCANNING_DEPENDENCYSCANNER_H #include "clang/Frontend/CompilerInstance.h" #include "clang/Frontend/CompilerInvocation.h" #include "clang/Serialization/ObjectFilePCHContainerReader.h" #include "clang/Tooling/DependencyScanning/DependencyScanningFilesystem.h" #include "clang/Tooling/DependencyScanning/ModuleDepCollector.h" namespace clang { class DiagnosticConsumer; namespace tooling { namespace dependencies { class DependencyScanningService; class DependencyConsumer; class DependencyActionController; class DependencyScanningWorkerFilesystem; class DependencyScanningAction { public: DependencyScanningAction( DependencyScanningService &Service, StringRef WorkingDirectory, DependencyConsumer &Consumer, DependencyActionController &Controller, llvm::IntrusiveRefCntPtr DepFS, std::optional ModuleName = std::nullopt) : Service(Service), WorkingDirectory(WorkingDirectory), Consumer(Consumer), Controller(Controller), DepFS(std::move(DepFS)), ModuleName(ModuleName) {} bool runInvocation(std::shared_ptr Invocation, IntrusiveRefCntPtr FS, std::shared_ptr PCHContainerOps, DiagnosticConsumer *DiagConsumer); bool hasScanned() const { return Scanned; } bool hasDiagConsumerFinished() const { return DiagConsumerFinished; } /// Take the cc1 arguments corresponding to the most recent invocation used /// with this action. Any modifications implied by the discovered dependencies /// will have already been applied. std::vector takeLastCC1Arguments() { std::vector Result; std::swap(Result, LastCC1Arguments); // Reset LastCC1Arguments to empty. return Result; } private: void setLastCC1Arguments(CompilerInvocation &&CI) { if (MDC) MDC->applyDiscoveredDependencies(CI); LastCC1Arguments = CI.getCC1CommandLine(); } DependencyScanningService &Service; StringRef WorkingDirectory; DependencyConsumer &Consumer; DependencyActionController &Controller; llvm::IntrusiveRefCntPtr DepFS; std::optional ModuleName; std::optional ScanInstanceStorage; std::shared_ptr MDC; std::vector LastCC1Arguments; bool Scanned = false; bool DiagConsumerFinished = false; }; // Helper functions void sanitizeDiagOpts(DiagnosticOptions &DiagOpts); } // namespace dependencies } // namespace tooling } // namespace clang #endif