Skip to content

Commit d9777a0

Browse files
committed
[NFC] AST/ASTDumper: Refactor for recursive MemberTypeRepr representation
1 parent e5413c9 commit d9777a0

File tree

4 files changed

+16
-18
lines changed

4 files changed

+16
-18
lines changed

include/swift/AST/TypeRepr.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,11 @@ class DeclRefTypeRepr : public TypeRepr {
356356
/// is a \c MemberTypeRepr, and the method returns its last member component.
357357
IdentTypeRepr *getLastComponent();
358358

359-
/// The type declaration the last component is bound to.
359+
/// Returns whether this instance has been bound to a type declaration. This
360+
/// happens during type resolution.
361+
bool isBound() const;
362+
363+
/// Returns the type declaration this instance has been bound to.
360364
TypeDecl *getBoundDecl() const;
361365

362366
/// The identifier that describes the last component.

lib/AST/ASTDumper.cpp

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3294,30 +3294,21 @@ class PrintTypeRepr : public TypeReprVisitor<PrintTypeRepr, void, StringRef>,
32943294
printRec(T->getTypeRepr());
32953295
}
32963296

3297-
void visitIdentTypeRepr(IdentTypeRepr *T, StringRef label) {
3298-
printCommon("type_ident", label);
3297+
void visitDeclRefTypeRepr(DeclRefTypeRepr *T, StringRef label) {
3298+
printCommon(isa<IdentTypeRepr>(T) ? "type_ident" : "type_member", label);
32993299

33003300
printFieldQuoted(T->getNameRef(), "id", IdentifierColor);
33013301
if (T->isBound())
33023302
printFieldQuoted(T->getBoundDecl()->printRef(), "bind");
33033303
else
33043304
printFlag("unbound");
33053305

3306-
if (auto *GenIdT = dyn_cast<GenericIdentTypeRepr>(T)) {
3307-
for (auto genArg : GenIdT->getGenericArgs()) {
3308-
printRec(genArg);
3309-
}
3306+
if (auto *memberTR = dyn_cast<MemberTypeRepr>(T)) {
3307+
printRec(memberTR->getBase());
33103308
}
33113309

3312-
printFoot();
3313-
}
3314-
3315-
void visitMemberTypeRepr(MemberTypeRepr *T, StringRef label) {
3316-
printCommon("type_member", label);
3317-
3318-
printRec(T->getRoot());
3319-
for (auto *comp : T->getMemberComponents()) {
3320-
printRec(comp);
3310+
for (auto *genArg : T->getGenericArgs()) {
3311+
printRec(genArg);
33213312
}
33223313

33233314
printFoot();

lib/AST/TypeRepr.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,10 @@ const TypeRepr *DeclRefTypeRepr::getRoot() const {
203203
return cast<MemberTypeRepr>(this)->getRoot();
204204
}
205205

206+
bool DeclRefTypeRepr::isBound() const {
207+
return const_cast<DeclRefTypeRepr *>(this)->getLastComponent()->isBound();
208+
}
209+
206210
TypeDecl *DeclRefTypeRepr::getBoundDecl() const {
207211
return const_cast<DeclRefTypeRepr *>(this)
208212
->getLastComponent()

test/Frontend/dump-parse.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,7 @@ struct SelfParam {
126126

127127
// CHECK-LABEL: (func_decl range=[{{.+}}] "dumpMemberTypeRepr()"
128128
// CHECK-NEXT: (parameter_list range=[{{.+}}])
129-
// CHECK-NEXT: (result=type_member
129+
// CHECK-NEXT: (result=type_member id="Element" unbound
130130
// CHECK-NEXT: (type_ident id="Array" unbound
131131
// CHECK-NEXT: (type_ident id="Bool" unbound))
132-
// CHECK-NEXT: (type_ident id="Element" unbound))
133132
func dumpMemberTypeRepr() -> Array<Bool>.Element { true }

0 commit comments

Comments
 (0)