clang 23.0.0git
DependencyActionController.h
Go to the documentation of this file.
1//===----------------------------------------------------------------------===//
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#ifndef LLVM_CLANG_DEPENDENCYSCANNING_DEPENDENCYACTIONCONTROLLER_H
10#define LLVM_CLANG_DEPENDENCYSCANNING_DEPENDENCYACTIONCONTROLLER_H
11
12#include <memory>
13#include <optional>
14#include <string>
15
16namespace clang {
17
21
22namespace dependencies {
23struct ModuleDeps;
24
25/// An output from a module compilation, such as the path of the module file.
26enum class ModuleOutputKind {
27 /// The module file (.pcm). Required.
29 /// The path of the dependency file (.d), if any.
31 /// The null-separated list of names to use as the targets in the dependency
32 /// file, if any. Defaults to the value of \c ModuleFile, as in the driver.
34 /// The path of the serialized diagnostic file (.dia), if any.
36};
37
38/// Dependency scanner callbacks that are used during scanning to influence the
39/// behaviour of the scan - for example, to customize the scanned invocations.
41public:
42 virtual ~DependencyActionController() = default;
43
44 /// Creates a copy of the controller. The result must be both thread-safe.
45 virtual std::unique_ptr<DependencyActionController> clone() const = 0;
46
47 /// Provides output path for a given module dependency. Must be thread-safe.
48 virtual std::string lookupModuleOutput(const ModuleDeps &MD,
49 ModuleOutputKind Kind) = 0;
50
51 /// Initializes the scan invocation.
52 virtual void initializeScanInvocation(CompilerInvocation &ScanInvocation) {}
53
54 /// Initializes the scan instance and modifies the resulting TU invocation.
55 /// Returns true on success, false on failure.
56 virtual bool initialize(CompilerInstance &ScanInstance,
57 CompilerInvocation &NewInvocation) {
58 return true;
59 }
60
61 /// Finalizes the scan instance and modifies the resulting TU invocation.
62 /// Returns true on success, false on failure.
63 virtual bool finalize(CompilerInstance &ScanInstance,
64 CompilerInvocation &NewInvocation) {
65 return true;
66 }
67
68 /// Returns the cache key for the resulting invocation, or nullopt.
69 virtual std::optional<std::string>
70 getCacheKey(const CompilerInvocation &NewInvocation) {
71 return std::nullopt;
72 }
73
74 /// Initializes the module scan instance.
75 /// Returns true on success, false on failure.
76 virtual bool initializeModuleBuild(CompilerInstance &ModuleScanInstance) {
77 return true;
78 }
79
80 /// Finalizes the module scan instance.
81 /// Returns true on success, false on failure.
82 virtual bool finalizeModuleBuild(CompilerInstance &ModuleScanInstance) {
83 return true;
84 }
85
86 /// Modifies the resulting module invocation and the associated structure.
87 /// Returns true on success, false on failure.
88 virtual bool finalizeModuleInvocation(CompilerInstance &ScanInstance,
90 const ModuleDeps &MD) {
91 return true;
92 }
93};
94} // namespace dependencies
95} // namespace clang
96
97#endif // LLVM_CLANG_DEPENDENCYSCANNING_DEPENDENCYACTIONCONTROLLER_H
CompilerInstance - Helper class for managing a single instance of the Clang compiler.
Helper class for holding the data necessary to invoke the compiler.
Same as CompilerInvocation, but with copy-on-write optimization.
Dependency scanner callbacks that are used during scanning to influence the behaviour of the scan - f...
virtual std::unique_ptr< DependencyActionController > clone() const =0
Creates a copy of the controller. The result must be both thread-safe.
virtual bool finalizeModuleInvocation(CompilerInstance &ScanInstance, CowCompilerInvocation &CI, const ModuleDeps &MD)
Modifies the resulting module invocation and the associated structure.
virtual void initializeScanInvocation(CompilerInvocation &ScanInvocation)
Initializes the scan invocation.
virtual std::string lookupModuleOutput(const ModuleDeps &MD, ModuleOutputKind Kind)=0
Provides output path for a given module dependency. Must be thread-safe.
virtual std::optional< std::string > getCacheKey(const CompilerInvocation &NewInvocation)
Returns the cache key for the resulting invocation, or nullopt.
virtual bool initialize(CompilerInstance &ScanInstance, CompilerInvocation &NewInvocation)
Initializes the scan instance and modifies the resulting TU invocation.
virtual bool initializeModuleBuild(CompilerInstance &ModuleScanInstance)
Initializes the module scan instance.
virtual bool finalize(CompilerInstance &ScanInstance, CompilerInvocation &NewInvocation)
Finalizes the scan instance and modifies the resulting TU invocation.
virtual bool finalizeModuleBuild(CompilerInstance &ModuleScanInstance)
Finalizes the module scan instance.
ModuleOutputKind
An output from a module compilation, such as the path of the module file.
@ DiagnosticSerializationFile
The path of the serialized diagnostic file (.dia), if any.
@ DependencyFile
The path of the dependency file (.d), if any.
@ DependencyTargets
The null-separated list of names to use as the targets in the dependency file, if any.
@ ModuleFile
The module file (.pcm). Required.
The JSON file list parser is used to communicate input to InstallAPI.