Skip to content

Commit ca4eed9

Browse files
committed
[clang][cas] Remove PPCallbacks from DependencyActionController
These were only used by include-tree, and we now have a mechanism to inject PPCallbacks without going through DependencyActionController. Remove them and simplify the IncludeTreeActionController. (cherry picked from commit c603c65)
1 parent 30c89b9 commit ca4eed9

File tree

2 files changed

+13
-42
lines changed

2 files changed

+13
-42
lines changed

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

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -102,13 +102,6 @@ class DependencyActionController {
102102
return llvm::Error::success();
103103
}
104104

105-
virtual void enteredInclude(Preprocessor &PP, FileID FID) {}
106-
107-
virtual void exitedInclude(Preprocessor &PP, FileID IncludedBy,
108-
FileID Include, SourceLocation ExitLoc) {}
109-
110-
virtual void handleHasIncludeCheck(Preprocessor &PP, bool Result) {}
111-
112105
/// FIXME: This is temporary until we eliminate the split between consumers in
113106
/// \p DependencyScanningTool and collectors in \p DependencyScanningWorker
114107
/// and have them both in the same file. see FIXME in \p

clang/lib/Tooling/DependencyScanning/IncludeTreeActionController.cpp

Lines changed: 13 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,6 @@ class IncludeTreeActionController : public CallbackActionController {
3535
Error initialize(CompilerInstance &ScanInstance,
3636
CompilerInvocation &NewInvocation) override;
3737

38-
void enteredInclude(Preprocessor &PP, FileID FID) override;
39-
40-
void exitedInclude(Preprocessor &PP, FileID IncludedBy, FileID Include,
41-
SourceLocation ExitLoc) override;
42-
43-
void handleHasIncludeCheck(Preprocessor &PP, bool Result) override;
44-
4538
const DepscanPrefixMapping *getPrefixMapping() override {
4639
return &PrefixMapping;
4740
}
@@ -60,6 +53,8 @@ class IncludeTreeActionController : public CallbackActionController {
6053
CASOptions CASOpts;
6154
DepscanPrefixMapping PrefixMapping;
6255
llvm::PrefixMapper PrefixMapper;
56+
// IncludeTreePPCallbacks keeps a pointer to the current builder, so use a
57+
// pointer so the builder cannot move when resizing.
6358
SmallVector<std::unique_ptr<IncludeTreeBuilder>> BuilderStack;
6459
std::optional<cas::IncludeTreeRoot> IncludeTreeResult;
6560
};
@@ -147,23 +142,22 @@ struct PPCallbacksDependencyCollector : public DependencyCollector {
147142
};
148143

149144
struct IncludeTreePPCallbacks : public PPCallbacks {
150-
DependencyActionController &Controller;
145+
IncludeTreeBuilder &Builder;
151146
Preprocessor &PP;
152147

153148
public:
154-
IncludeTreePPCallbacks(DependencyActionController &Controller,
155-
Preprocessor &PP)
156-
: Controller(Controller), PP(PP) {}
149+
IncludeTreePPCallbacks(IncludeTreeBuilder &Builder, Preprocessor &PP)
150+
: Builder(Builder), PP(PP) {}
157151

158152
void LexedFileChanged(FileID FID, LexedFileChangeReason Reason,
159153
SrcMgr::CharacteristicKind FileType, FileID PrevFID,
160154
SourceLocation Loc) override {
161155
switch (Reason) {
162156
case LexedFileChangeReason::EnterFile:
163-
Controller.enteredInclude(PP, FID);
157+
Builder.enteredInclude(PP, FID);
164158
break;
165159
case LexedFileChangeReason::ExitFile: {
166-
Controller.exitedInclude(PP, FID, PrevFID, Loc);
160+
Builder.exitedInclude(PP, FID, PrevFID, Loc);
167161
break;
168162
}
169163
}
@@ -172,7 +166,7 @@ struct IncludeTreePPCallbacks : public PPCallbacks {
172166
void HasInclude(SourceLocation Loc, StringRef FileName, bool IsAngled,
173167
OptionalFileEntryRef File,
174168
SrcMgr::CharacteristicKind FileType) override {
175-
Controller.handleHasIncludeCheck(PP, File.has_value());
169+
Builder.handleHasIncludeCheck(PP, File.has_value());
176170
}
177171
};
178172
} // namespace
@@ -221,38 +215,22 @@ Error IncludeTreeActionController::initialize(
221215
};
222216
ensurePathRemapping();
223217

218+
BuilderStack.push_back(
219+
std::make_unique<IncludeTreeBuilder>(DB, PrefixMapper));
220+
224221
// Attach callbacks for the IncludeTree of the TU. The preprocessor
225222
// does not exist yet, so we need to indirect this via DependencyCollector.
226223
auto DC = std::make_shared<PPCallbacksDependencyCollector>(
227-
[this](Preprocessor &PP) {
228-
return std::make_unique<IncludeTreePPCallbacks>(*this, PP);
224+
[&Builder = current()](Preprocessor &PP) {
225+
return std::make_unique<IncludeTreePPCallbacks>(Builder, PP);
229226
});
230227
ScanInstance.addDependencyCollector(std::move(DC));
231228

232229
CASOpts = ScanInstance.getCASOpts();
233230

234-
BuilderStack.push_back(
235-
std::make_unique<IncludeTreeBuilder>(DB, PrefixMapper));
236-
237231
return Error::success();
238232
}
239233

240-
void IncludeTreeActionController::enteredInclude(Preprocessor &PP, FileID FID) {
241-
current().enteredInclude(PP, FID);
242-
}
243-
244-
void IncludeTreeActionController::exitedInclude(Preprocessor &PP,
245-
FileID IncludedBy,
246-
FileID Include,
247-
SourceLocation ExitLoc) {
248-
current().exitedInclude(PP, IncludedBy, Include, ExitLoc);
249-
}
250-
251-
void IncludeTreeActionController::handleHasIncludeCheck(Preprocessor &PP,
252-
bool Result) {
253-
current().handleHasIncludeCheck(PP, Result);
254-
}
255-
256234
Error IncludeTreeActionController::finalize(CompilerInstance &ScanInstance,
257235
CompilerInvocation &NewInvocation) {
258236
assert(!IncludeTreeResult);

0 commit comments

Comments
 (0)