@@ -29,6 +29,7 @@ namespace tooling {
2929namespace dependencies {
3030
3131class DependencyScanningWorkerFilesystem ;
32+ class CompilerInstanceWithContext ;
3233
3334// / A command-line tool invocation that is part of building a TU.
3435// /
@@ -89,6 +90,8 @@ class DependencyScanningWorker {
8990 DependencyScanningWorker (DependencyScanningService &Service,
9091 llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> FS);
9192
93+ ~DependencyScanningWorker ();
94+
9295 // / Run the dependency scanning tool for a given clang driver command-line,
9396 // / and report the discovered dependencies to the provided consumer. If
9497 // / TUBuffer is not nullopt, it is used as TU input for the dependency
@@ -103,18 +106,6 @@ class DependencyScanningWorker {
103106 DiagnosticConsumer &DiagConsumer,
104107 std::optional<llvm::MemoryBufferRef> TUBuffer = std::nullopt );
105108
106- // / Run the dependency scanning tool for a given clang driver command-line
107- // / for a specific module.
108- // /
109- // / \returns false if clang errors occurred (with diagnostics reported to
110- // / \c DiagConsumer), true otherwise.
111- bool computeDependencies (StringRef WorkingDirectory,
112- const std::vector<std::string> &CommandLine,
113- DependencyConsumer &DepConsumer,
114- DependencyActionController &Controller,
115- DiagnosticConsumer &DiagConsumer,
116- StringRef ModuleName);
117-
118109 // / Run the dependency scanning tool for a given clang driver command-line
119110 // / for a specific translation unit via file system or memory buffer.
120111 // /
@@ -125,16 +116,46 @@ class DependencyScanningWorker {
125116 DependencyConsumer &Consumer, DependencyActionController &Controller,
126117 std::optional<llvm::MemoryBufferRef> TUBuffer = std::nullopt );
127118
128- // / Run the dependency scanning tool for a given clang driver command-line
129- // / for a specific module.
130- // /
131- // / \returns A \c StringError with the diagnostic output if clang errors
132- // / occurred, success otherwise.
133- llvm::Error computeDependencies (StringRef WorkingDirectory,
134- const std::vector<std::string> &CommandLine,
135- DependencyConsumer &Consumer,
136- DependencyActionController &Controller,
137- StringRef ModuleName);
119+ // / The three method below implements a new interface for by name
120+ // / dependency scanning. They together enable the dependency scanning worker
121+ // / to more effectively perform scanning for a sequence of modules
122+ // / by name when the CWD and CommandLine do not change across the queries.
123+
124+ // / @brief Initializing the context and the compiler instance.
125+ // / @param CWD The current working directory used during the scan.
126+ // / @param CommandLine The commandline used for the scan.
127+ // / @return Error if the initializaiton fails.
128+ llvm::Error initializeCompilerInstanceWithContextOrError (
129+ StringRef CWD, const std::vector<std::string> &CommandLine);
130+
131+ // / @brief Performaces dependency scanning for the module whose name is
132+ // / specified.
133+ // / @param ModuleName The name of the module whose dependency will be
134+ // / scanned.
135+ // / @param Consumer The dependency consumer that stores the results.
136+ // / @param Controller The controller for the dependency scanning action.
137+ // / @return Error if the scanner incurs errors.
138+ llvm::Error computeDependenciesByNameWithContextOrError (
139+ StringRef ModuleName, DependencyConsumer &Consumer,
140+ DependencyActionController &Controller);
141+
142+ // / @brief Finalizes the diagnostics engine and deletes the compiler instance.
143+ // / @return Error if errors occur during finalization.
144+ llvm::Error finalizeCompilerInstanceWithContextOrError ();
145+
146+ // / The three methods below provides the same functionality as the
147+ // / three methods above. Instead of returning `llvm::Error`s, these
148+ // / three methods return a flag to indicate if the call is successful.
149+ // / The initialization function asks the client for a DiagnosticsConsumer
150+ // / that it direct the diagnostics to.
151+ bool initializeCompilerInstanceWithContext (
152+ StringRef CWD, const std::vector<std::string> &CommandLine,
153+ DiagnosticConsumer *DC = nullptr );
154+ bool
155+ computeDependenciesByNameWithContext (StringRef ModuleName,
156+ DependencyConsumer &Consumer,
157+ DependencyActionController &Controller);
158+ bool finalizeCompilerInstance ();
138159
139160 llvm::vfs::FileSystem &getVFS () const { return *BaseFS; }
140161
@@ -151,14 +172,16 @@ class DependencyScanningWorker {
151172 // / (passed in the constructor).
152173 llvm::IntrusiveRefCntPtr<DependencyScanningWorkerFilesystem> DepFS;
153174
175+ friend CompilerInstanceWithContext;
176+ std::unique_ptr<CompilerInstanceWithContext> CIWithContext;
177+
154178 // / Private helper functions.
155179 bool scanDependencies (StringRef WorkingDirectory,
156180 const std::vector<std::string> &CommandLine,
157181 DependencyConsumer &Consumer,
158182 DependencyActionController &Controller,
159183 DiagnosticConsumer &DC,
160- llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> FS,
161- std::optional<StringRef> ModuleName);
184+ llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> FS);
162185};
163186
164187} // end namespace dependencies
0 commit comments