Skip to content

Commit e118026

Browse files
committed
[NFC] Migrator: Refactor for recursive MemberTypeRepr representation
1 parent a239768 commit e118026

File tree

3 files changed

+14
-11
lines changed

3 files changed

+14
-11
lines changed

include/swift/AST/TypeRepr.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,8 @@ class DeclRefTypeRepr : public TypeRepr {
362362
/// The identifier that describes the last component.
363363
DeclNameRef getNameRef() const;
364364

365+
ArrayRef<TypeRepr *> getGenericArgs() const;
366+
365367
static bool classof(const TypeRepr *T) {
366368
return T->getKind() == TypeReprKind::SimpleIdent ||
367369
T->getKind() == TypeReprKind::GenericIdent ||

lib/AST/TypeRepr.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,15 @@ TypeDecl *DeclRefTypeRepr::getBoundDecl() const {
209209
->getBoundDecl();
210210
}
211211

212+
ArrayRef<TypeRepr *> DeclRefTypeRepr::getGenericArgs() const {
213+
auto *lastComp = const_cast<DeclRefTypeRepr *>(this)->getLastComponent();
214+
if (auto *genericTR = dyn_cast<GenericIdentTypeRepr>(lastComp)) {
215+
return genericTR->getGenericArgs();
216+
}
217+
218+
return {};
219+
}
220+
212221
DeclNameRef DeclRefTypeRepr::getNameRef() const {
213222
return const_cast<DeclRefTypeRepr *>(this)->getLastComponent()->getNameRef();
214223
}

lib/Migrator/APIDiffMigratorPass.cpp

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,8 @@ class ChildIndexFinder : public TypeReprVisitor<ChildIndexFinder, FoundResult> {
9292
}
9393

9494
bool isUserTypeAlias(TypeRepr *T) const {
95-
if (auto Ident = dyn_cast<IdentTypeRepr>(T)) {
96-
if (auto Bound = Ident->getBoundDecl()) {
95+
if (auto *DeclRefTR = dyn_cast<DeclRefTypeRepr>(T)) {
96+
if (auto *Bound = DeclRefTR->getBoundDecl()) {
9797
return isa<TypeAliasDecl>(Bound) &&
9898
!Bound->getModuleContext()->isSystemModule();
9999
}
@@ -189,18 +189,10 @@ class ChildIndexFinder : public TypeReprVisitor<ChildIndexFinder, FoundResult> {
189189
/*Suffixable=*/false);
190190
}
191191

192-
FoundResult visitSimpleIdentTypeRepr(SimpleIdentTypeRepr *T) {
193-
return handleParent(T, ArrayRef<TypeRepr*>());
194-
}
195-
196-
FoundResult visitGenericIdentTypeRepr(GenericIdentTypeRepr *T) {
192+
FoundResult visitDeclRefTypeRepr(DeclRefTypeRepr *T) {
197193
return handleParent(T, T->getGenericArgs());
198194
}
199195

200-
FoundResult visitMemberTypeRepr(MemberTypeRepr *T) {
201-
return visit(T->getLastComponent());
202-
}
203-
204196
FoundResult visitOptionalTypeRepr(OptionalTypeRepr *T) {
205197
return handleParent(T, T->getBase(), /*Optional=*/true);
206198
}

0 commit comments

Comments
 (0)