Skip to content

Commit 64c953f

Browse files
committed
[ASTScope] Customize getClassName() for GenericTypeOrExtensionScope
The subclasses of `GenericTypeOrExtensionScope` are customized by a `Portion` mix-in class that effectively makes each into several different scope nodes: one for the "whole decl", one for the where clause, one for the body. Re-introduce the customized `getClassName()` operation so we get the nicer debugging dumps.
1 parent a2aed2a commit 64c953f

File tree

2 files changed

+26
-3
lines changed

2 files changed

+26
-3
lines changed

include/swift/AST/ASTScope.h

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ class ASTScopeImpl : public ASTAllocated<ASTScopeImpl> {
246246

247247
public:
248248
const SourceFile *getSourceFile() const;
249-
StringRef getClassName() const;
249+
std::string getClassName() const;
250250

251251
/// Print out this scope for debugging/reporting purposes.
252252
void print(llvm::raw_ostream &out, unsigned level = 0, bool lastChild = false,
@@ -609,6 +609,8 @@ class GenericTypeOrExtensionScope : public ASTScopeImpl {
609609
virtual bool doesDeclHaveABody() const;
610610
const char *portionName() const { return portion->portionName; }
611611

612+
std::string getClassName() const;
613+
612614
public:
613615
// Only for DeclScope, not BodyScope
614616
// Returns the where clause scope, or the parent if none
@@ -630,6 +632,13 @@ class GenericTypeOrExtensionScope : public ASTScopeImpl {
630632
public:
631633
NullablePtr<const ASTScopeImpl> getLookupLimit() const override;
632634
virtual NullablePtr<const ASTScopeImpl> getLookupLimitForDecl() const;
635+
636+
static bool classof(const ASTScopeImpl *scope) {
637+
return scope->getKind() == ScopeKind::NominalType ||
638+
scope->getKind() == ScopeKind::Extension ||
639+
scope->getKind() == ScopeKind::TypeAlias ||
640+
scope->getKind() == ScopeKind::OpaqueType;
641+
}
633642
};
634643

635644
class GenericTypeScope : public GenericTypeOrExtensionScope {
@@ -656,6 +665,11 @@ class IterableTypeScope : public GenericTypeScope {
656665

657666
public:
658667
NullablePtr<ASTScopeImpl> insertionPointForDeferredExpansion() override;
668+
669+
static bool classof(const ASTScopeImpl *scope) {
670+
return scope->getKind() == ScopeKind::NominalType ||
671+
scope->getKind() == ScopeKind::Extension;
672+
}
659673
};
660674

661675
class NominalTypeScope final : public IterableTypeScope {

lib/AST/ASTScope.cpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,13 +160,22 @@ DoCatchStmtScope::getCatchNodeBody() const {
160160
return { const_cast<DoCatchStmt *>(stmt), body };
161161
}
162162

163-
StringRef ASTScopeImpl::getClassName() const {
163+
std::string ASTScopeImpl::getClassName() const {
164+
// GenericTypeOrExtensionScope provides a custom implementation that deals
165+
// with declaration names and "portions".
166+
if (auto generic = dyn_cast<GenericTypeOrExtensionScope>(this))
167+
return generic->getClassName();
168+
164169
switch (getKind()) {
165-
#define SCOPE_NODE(Name) case ScopeKind::Name: return #Name;
170+
#define SCOPE_NODE(Name) case ScopeKind::Name: return #Name "Scope";
166171
#include "swift/AST/ASTScopeNodes.def"
167172
}
168173
}
169174

175+
std::string GenericTypeOrExtensionScope::getClassName() const {
176+
return declKindName() + portionName() + "Scope";
177+
}
178+
170179
NullablePtr<Decl> ASTScopeImpl::getDeclIfAny() const {
171180
switch (getKind()) {
172181
// Declaration scope nodes extract the decl directly.

0 commit comments

Comments
 (0)