[ASTScope] Introduce isa/cast/dyn_cast support to ASTScope hierarchy

The ASTScope class hierarchy rooted at ASTScopeImpl is relying entirely
on overridden virtual functions and, in some cases, string comparisons
on the class name, to provide customization for the various classes.
Introduce proper LLVM dynamic casting support to this class hierarchy,
eliminating the string comparisons and the manually-specified
implementations of `getClassName` (which is now used only for printing).

We've been meaning to do this for years, but today I got angry enough.
This commit is contained in:
Doug Gregor
2023-12-06 09:43:21 -08:00
parent dd80cf79e6
commit 1e20686d12
6 changed files with 354 additions and 140 deletions

View File

@@ -116,8 +116,7 @@ SourceRange FunctionBodyScope::getSourceRangeOfThisASTNode(
const bool omitAssertions) const {
// If this function body scope is synthesized for a body macro, use the
// real source range.
if (getChildren().size() == 1 &&
getChildren()[0]->getClassName() == "ASTSourceFileScope") {
if (getChildren().size() == 1 && isa<ASTSourceFileScope>(getChildren()[0])) {
return decl->getBodySourceRange();
}