Skip to content

Commit 8bc7d8e

Browse files
committed
[clang][deps][cas] Remove DependencyScanningConsumerBase
The separation between DependencyConsumer and DependencyScanningConsumerBase was causing spurious merge issues. There is no type safety provided by having an empty base class, so just use the main consumer and make all the base callbacks error.
1 parent e27dc40 commit 8bc7d8e

File tree

2 files changed

+29
-19
lines changed

2 files changed

+29
-19
lines changed

clang/include/clang/Tooling/DependencyScanning/DependencyScanningWorker.h

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,10 @@ namespace dependencies {
3434

3535
class DependencyScanningWorkerFilesystem;
3636

37-
class DependencyScanningConsumerBase {
37+
class DependencyConsumer {
3838
public:
39-
virtual ~DependencyScanningConsumerBase() {}
40-
};
39+
virtual ~DependencyConsumer() {}
4140

42-
class DependencyConsumer : public DependencyScanningConsumerBase {
43-
public:
4441
virtual void
4542
handleDependencyOutputOpts(const DependencyOutputOptions &Opts) = 0;
4643

@@ -55,14 +52,31 @@ class DependencyConsumer : public DependencyScanningConsumerBase {
5552

5653
// FIXME: This may need to merge with \p DependencyConsumer in order to support
5754
// clang modules for the include-tree.
58-
class PPIncludeActionsConsumer : public DependencyScanningConsumerBase {
55+
class PPIncludeActionsConsumer : public DependencyConsumer {
5956
public:
6057
virtual void enteredInclude(Preprocessor &PP, FileID FID) = 0;
6158

6259
virtual void exitedInclude(Preprocessor &PP, FileID IncludedBy,
6360
FileID Include, SourceLocation ExitLoc) = 0;
6461

6562
virtual void handleHasIncludeCheck(Preprocessor &PP, bool Result) = 0;
63+
64+
protected:
65+
void handleDependencyOutputOpts(const DependencyOutputOptions &Opts) override {
66+
llvm::report_fatal_error("unexpected callback for include-tree");
67+
}
68+
void handleFileDependency(StringRef Filename) override {
69+
llvm::report_fatal_error("unexpected callback for include-tree");
70+
}
71+
void handlePrebuiltModuleDependency(PrebuiltModuleDep PMD) override {
72+
llvm::report_fatal_error("unexpected callback for include-tree");
73+
}
74+
void handleModuleDependency(ModuleDeps MD) override {
75+
llvm::report_fatal_error("unexpected callback for include-tree");
76+
}
77+
void handleContextHash(std::string Hash) override {
78+
llvm::report_fatal_error("unexpected callback for include-tree");
79+
}
6680
};
6781

6882
/// An individual dependency scanning worker that is able to run on its own
@@ -85,7 +99,7 @@ class DependencyScanningWorker {
8599
/// occurred, success otherwise.
86100
llvm::Error computeDependencies(StringRef WorkingDirectory,
87101
const std::vector<std::string> &CommandLine,
88-
DependencyScanningConsumerBase &Consumer,
102+
DependencyConsumer &Consumer,
89103
llvm::Optional<StringRef> ModuleName = None);
90104

91105
/// Scan from a compiler invocation.
@@ -95,7 +109,7 @@ class DependencyScanningWorker {
95109
/// \p DiagOpts.DiagnosticSerializationFile setting is set for the invocation.
96110
void computeDependenciesFromCompilerInvocation(
97111
std::shared_ptr<CompilerInvocation> Invocation,
98-
StringRef WorkingDirectory, DependencyScanningConsumerBase &Consumer,
112+
StringRef WorkingDirectory, DependencyConsumer &Consumer,
99113
DiagnosticConsumer &DiagsConsumer, raw_ostream *VerboseOS,
100114
bool DiagGenerationAsCompilation);
101115

clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ class IncludeTreeCollector : public DependencyFileGenerator {
195195
class DependencyScanningAction : public tooling::ToolAction {
196196
public:
197197
DependencyScanningAction(
198-
StringRef WorkingDirectory, DependencyScanningConsumerBase &Consumer,
198+
StringRef WorkingDirectory, DependencyConsumer &Consumer,
199199
const CASOptions &CASOpts,
200200
llvm::IntrusiveRefCntPtr<DependencyScanningWorkerFilesystem> DepFS,
201201
llvm::IntrusiveRefCntPtr<DependencyScanningCASFilesystem> DepCASFS,
@@ -315,8 +315,7 @@ class DependencyScanningAction : public tooling::ToolAction {
315315
case ScanningOutputFormat::Tree:
316316
ScanInstance.addDependencyCollector(
317317
std::make_shared<DependencyConsumerForwarder>(
318-
std::move(Opts), WorkingDirectory,
319-
static_cast<DependencyConsumer &>(Consumer), EmitDependencyFile));
318+
std::move(Opts), WorkingDirectory, Consumer, EmitDependencyFile));
320319
break;
321320
case ScanningOutputFormat::IncludeTree: {
322321
ScanInstance.addDependencyCollector(
@@ -328,8 +327,7 @@ class DependencyScanningAction : public tooling::ToolAction {
328327
case ScanningOutputFormat::Full:
329328
case ScanningOutputFormat::FullTree:
330329
ScanInstance.addDependencyCollector(std::make_shared<ModuleDepCollector>(
331-
std::move(Opts), ScanInstance,
332-
static_cast<DependencyConsumer &>(Consumer),
330+
std::move(Opts), ScanInstance, Consumer,
333331
std::move(OriginalInvocation), OptimizeArgs));
334332
break;
335333
}
@@ -372,7 +370,7 @@ class DependencyScanningAction : public tooling::ToolAction {
372370

373371
private:
374372
StringRef WorkingDirectory;
375-
DependencyScanningConsumerBase &Consumer;
373+
DependencyConsumer &Consumer;
376374
const CASOptions &CASOpts;
377375
llvm::IntrusiveRefCntPtr<DependencyScanningWorkerFilesystem> DepFS;
378376
llvm::IntrusiveRefCntPtr<DependencyScanningCASFilesystem> DepCASFS;
@@ -452,8 +450,7 @@ runWithDiags(DiagnosticOptions *DiagOpts,
452450

453451
llvm::Error DependencyScanningWorker::computeDependencies(
454452
StringRef WorkingDirectory, const std::vector<std::string> &CommandLine,
455-
DependencyScanningConsumerBase &Consumer,
456-
llvm::Optional<StringRef> ModuleName) {
453+
DependencyConsumer &Consumer, llvm::Optional<StringRef> ModuleName) {
457454
// Reset what might have been modified in the previous worker invocation.
458455
RealFS->setCurrentWorkingDirectory(WorkingDirectory);
459456
if (Files)
@@ -503,9 +500,8 @@ llvm::Error DependencyScanningWorker::computeDependencies(
503500

504501
void DependencyScanningWorker::computeDependenciesFromCompilerInvocation(
505502
std::shared_ptr<CompilerInvocation> Invocation, StringRef WorkingDirectory,
506-
DependencyScanningConsumerBase &DepsConsumer,
507-
DiagnosticConsumer &DiagsConsumer, raw_ostream *VerboseOS,
508-
bool DiagGenerationAsCompilation) {
503+
DependencyConsumer &DepsConsumer, DiagnosticConsumer &DiagsConsumer,
504+
raw_ostream *VerboseOS, bool DiagGenerationAsCompilation) {
509505
RealFS->setCurrentWorkingDirectory(WorkingDirectory);
510506

511507
// Adjust the invocation.

0 commit comments

Comments
 (0)