[AST] Introduce explicit actions for ASTWalker

Replace the use of bool and pointer returns for
`walkToXXXPre`/`walkToXXXPost`, and instead use
explicit actions such as `Action::Continue(E)`,
`Action::SkipChildren(E)`, and `Action::Stop()`.
There are also conditional variants, e.g
`Action::SkipChildrenIf`, `Action::VisitChildrenIf`,
and `Action::StopIf`.

There is still more work that can be done here, in
particular:

- SourceEntityWalker still needs to be migrated.
- Some uses of `return false` in pre-visitation
methods can likely now be replaced by
`Action::Stop`.
- We still use bool and pointer returns internally
within the ASTWalker traversal, which could likely
be improved.

But I'm leaving those as future work for now as
this patch is already large enough.
This commit is contained in:
Hamish Knight
2022-09-13 10:35:29 +01:00
parent 6804623a82
commit 4716f61fba
68 changed files with 1827 additions and 1375 deletions

View File

@@ -968,15 +968,15 @@ public:
llvm::MutableArrayRef<TextEntity*> FuncEnts)
: SM(SM), BufferID(BufferID), FuncEnts(FuncEnts) {}
bool walkToDeclPre(Decl *D) override {
PreWalkAction walkToDeclPre(Decl *D) override {
if (D->isImplicit())
return false; // Skip body.
return Action::SkipChildren(); // Skip body.
if (FuncEnts.empty())
return false;
return Action::SkipChildren();
if (!isa<AbstractFunctionDecl>(D) && !isa<SubscriptDecl>(D))
return true;
return Action::Continue();
unsigned Offset = SM.getLocOffsetInBuffer(D->getLoc(), BufferID);
auto Found = FuncEnts.end();
@@ -989,14 +989,14 @@ public:
});
}
if (Found == FuncEnts.end() || (*Found)->LocOffset != Offset)
return false;
return Action::SkipChildren();
if (auto FD = dyn_cast<AbstractFunctionDecl>(D)) {
addParameters(FD, **Found, SM, BufferID);
} else {
addParameters(cast<SubscriptDecl>(D), **Found, SM, BufferID);
}
FuncEnts = llvm::MutableArrayRef<TextEntity*>(Found+1, FuncEnts.end());
return false; // skip body.
return Action::SkipChildren(); // skip body.
}
};
} // end anonymous namespace