Skip to content

Commit 5b7a8b6

Browse files
committed
[NFC] AST: Rename MemberTypeReprQualifiedIdentTypeRepr
1 parent 5d848e7 commit 5b7a8b6

22 files changed

+209
-193
lines changed

include/swift/AST/ASTWalker.h

+6-5
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,8 @@ enum class MacroWalking {
102102
None
103103
};
104104

105-
/// A scheme for walking a `MemberTypeRepr`.
106-
enum class MemberTypeReprWalkingScheme {
105+
/// A scheme for walking a `QualifiedIdentTypeRepr`.
106+
enum class QualifiedIdentTypeReprWalkingScheme {
107107
/// Walk in source order, such that each subsequent dot-separated component is
108108
/// a child of the previous one. For example, walk `A.B<T.U>.C` like so
109109
/// (top-down order):
@@ -593,9 +593,10 @@ class ASTWalker {
593593
return Action::Continue();
594594
}
595595

596-
/// This method configures how to walk `MemberTypeRepr` nodes.
597-
virtual MemberTypeReprWalkingScheme getMemberTypeReprWalkingScheme() const {
598-
return MemberTypeReprWalkingScheme::ASTOrderRecursive;
596+
/// This method configures how to walk `QualifiedIdentTypeRepr` nodes.
597+
virtual QualifiedIdentTypeReprWalkingScheme
598+
getQualifiedIdentTypeReprWalkingScheme() const {
599+
return QualifiedIdentTypeReprWalkingScheme::ASTOrderRecursive;
599600
}
600601

601602
/// This method configures whether the walker should explore into the generic

include/swift/AST/TypeRepr.h

+17-15
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,7 @@ class DeclRefTypeRepr : public TypeRepr {
410410

411411
static bool classof(const TypeRepr *T) {
412412
return T->getKind() == TypeReprKind::UnqualifiedIdent ||
413-
T->getKind() == TypeReprKind::Member;
413+
T->getKind() == TypeReprKind::QualifiedIdent;
414414
}
415415
static bool classof(const DeclRefTypeRepr *T) { return true; }
416416

@@ -474,9 +474,10 @@ class UnqualifiedIdentTypeRepr final
474474
/// Foo.Bar<Gen>.Baz
475475
/// [Int].Bar
476476
/// \endcode
477-
class MemberTypeRepr final
477+
class QualifiedIdentTypeRepr final
478478
: public DeclRefTypeRepr,
479-
private llvm::TrailingObjects<MemberTypeRepr, TypeRepr *, SourceRange> {
479+
private llvm::TrailingObjects<QualifiedIdentTypeRepr, TypeRepr *,
480+
SourceRange> {
480481
friend TrailingObjects;
481482

482483
/// The qualifier or base type representation. For example, `A.B` for `A.B.C`.
@@ -486,19 +487,20 @@ class MemberTypeRepr final
486487
return getNumGenericArgs();
487488
}
488489

489-
MemberTypeRepr(TypeRepr *Base, DeclNameRef Name, DeclNameLoc NameLoc);
490+
QualifiedIdentTypeRepr(TypeRepr *Base, DeclNameRef Name, DeclNameLoc NameLoc);
490491

491-
MemberTypeRepr(TypeRepr *Base, DeclNameRef Name, DeclNameLoc NameLoc,
492-
ArrayRef<TypeRepr *> GenericArgs, SourceRange AngleBrackets);
492+
QualifiedIdentTypeRepr(TypeRepr *Base, DeclNameRef Name, DeclNameLoc NameLoc,
493+
ArrayRef<TypeRepr *> GenericArgs,
494+
SourceRange AngleBrackets);
493495

494496
public:
495-
static MemberTypeRepr *create(const ASTContext &C, TypeRepr *Base,
496-
DeclNameLoc NameLoc, DeclNameRef Name);
497+
static QualifiedIdentTypeRepr *create(const ASTContext &C, TypeRepr *Base,
498+
DeclNameLoc NameLoc, DeclNameRef Name);
497499

498-
static MemberTypeRepr *create(const ASTContext &C, TypeRepr *Base,
499-
DeclNameLoc NameLoc, DeclNameRef Name,
500-
ArrayRef<TypeRepr *> GenericArgs,
501-
SourceRange AngleBrackets);
500+
static QualifiedIdentTypeRepr *create(const ASTContext &C, TypeRepr *Base,
501+
DeclNameLoc NameLoc, DeclNameRef Name,
502+
ArrayRef<TypeRepr *> GenericArgs,
503+
SourceRange AngleBrackets);
502504

503505
/// Returns the qualifier or base type representation. For example, `A.B`
504506
/// for `A.B.C`.
@@ -512,9 +514,9 @@ class MemberTypeRepr final
512514
SourceRange getAngleBrackets() const;
513515

514516
static bool classof(const TypeRepr *T) {
515-
return T->getKind() == TypeReprKind::Member;
517+
return T->getKind() == TypeReprKind::QualifiedIdent;
516518
}
517-
static bool classof(const MemberTypeRepr *T) { return true; }
519+
static bool classof(const QualifiedIdentTypeRepr *T) { return true; }
518520

519521
private:
520522
SourceLoc getStartLocImpl() const;
@@ -1603,7 +1605,7 @@ inline bool TypeRepr::isSimple() const {
16031605
case TypeReprKind::PackElement:
16041606
return false;
16051607
case TypeReprKind::UnqualifiedIdent:
1606-
case TypeReprKind::Member:
1608+
case TypeReprKind::QualifiedIdent:
16071609
case TypeReprKind::Metatype:
16081610
case TypeReprKind::Protocol:
16091611
case TypeReprKind::Dictionary:

include/swift/AST/TypeReprNodes.def

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ TYPEREPR(Attributed, TypeRepr)
4747

4848
ABSTRACT_TYPEREPR(DeclRef, TypeRepr)
4949
TYPEREPR(UnqualifiedIdent, DeclRefTypeRepr)
50-
TYPEREPR(Member, DeclRefTypeRepr)
50+
TYPEREPR(QualifiedIdent, DeclRefTypeRepr)
5151
TYPEREPR(Function, TypeRepr)
5252
TYPEREPR(Array, TypeRepr)
5353
TYPEREPR(Dictionary, TypeRepr)

lib/AST/ASTDumper.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -3298,7 +3298,7 @@ class PrintTypeRepr : public TypeReprVisitor<PrintTypeRepr, void, StringRef>,
32983298

32993299
void visitDeclRefTypeRepr(DeclRefTypeRepr *T, StringRef label) {
33003300
printCommon(isa<UnqualifiedIdentTypeRepr>(T) ? "type_unqualified_ident"
3301-
: "type_member",
3301+
: "type_qualified_ident",
33023302
label);
33033303

33043304
printFieldQuoted(T->getNameRef(), "id", IdentifierColor);
@@ -3307,8 +3307,8 @@ class PrintTypeRepr : public TypeReprVisitor<PrintTypeRepr, void, StringRef>,
33073307
else
33083308
printFlag("unbound");
33093309

3310-
if (auto *memberTR = dyn_cast<MemberTypeRepr>(T)) {
3311-
printRec(memberTR->getBase());
3310+
if (auto *qualIdentTR = dyn_cast<QualifiedIdentTypeRepr>(T)) {
3311+
printRec(qualIdentTR->getBase());
33123312
}
33133313

33143314
for (auto *genArg : T->getGenericArgs()) {

lib/AST/ASTWalker.cpp

+17-17
Original file line numberDiff line numberDiff line change
@@ -1627,19 +1627,19 @@ class Traversal : public ASTVisitor<Traversal, Expr*, Stmt*,
16271627
}
16281628

16291629
private:
1630-
/// Walk a `MemberTypeRepr` in source order such that each subsequent
1630+
/// Walk a `QualifiedIdentTypeRepr` in source order such that each subsequent
16311631
/// dot-separated component is a child of the previous one
1632-
[[nodiscard]] bool doItInSourceOrderRecursive(MemberTypeRepr *T);
1632+
[[nodiscard]] bool doItInSourceOrderRecursive(QualifiedIdentTypeRepr *T);
16331633

16341634
public:
16351635
/// Returns true on failure.
16361636
[[nodiscard]]
16371637
bool doIt(TypeRepr *T) {
1638-
if (auto *MTR = dyn_cast<MemberTypeRepr>(T)) {
1639-
switch (Walker.getMemberTypeReprWalkingScheme()) {
1640-
case MemberTypeReprWalkingScheme::SourceOrderRecursive:
1641-
return doItInSourceOrderRecursive(MTR);
1642-
case MemberTypeReprWalkingScheme::ASTOrderRecursive:
1638+
if (auto *QualIdentTR = dyn_cast<QualifiedIdentTypeRepr>(T)) {
1639+
switch (Walker.getQualifiedIdentTypeReprWalkingScheme()) {
1640+
case QualifiedIdentTypeReprWalkingScheme::SourceOrderRecursive:
1641+
return doItInSourceOrderRecursive(QualIdentTR);
1642+
case QualifiedIdentTypeReprWalkingScheme::ASTOrderRecursive:
16431643
break;
16441644
}
16451645
}
@@ -1723,11 +1723,11 @@ class Traversal : public ASTVisitor<Traversal, Expr*, Stmt*,
17231723

17241724
} // end anonymous namespace
17251725

1726-
bool Traversal::doItInSourceOrderRecursive(MemberTypeRepr *T) {
1726+
bool Traversal::doItInSourceOrderRecursive(QualifiedIdentTypeRepr *T) {
17271727
// Qualified types are modeled resursively such that each previous
17281728
// dot-separated component is a child of the next one. To walk a member type
17291729
// representation according to
1730-
// `MemberTypeReprWalkingScheme::SourceOrderRecursive`:
1730+
// `QualifiedIdentTypeReprWalkingScheme::SourceOrderRecursive`:
17311731

17321732
// 1. Pre-walk the dot-separated components in source order. If asked to skip
17331733
// the children of a given component:
@@ -1737,8 +1737,8 @@ bool Traversal::doItInSourceOrderRecursive(MemberTypeRepr *T) {
17371737
doItInSourceOrderPre = [&](TypeRepr *T,
17381738
std::optional<unsigned> &StartPostWalkDepth,
17391739
unsigned Depth) {
1740-
if (auto *MemberTR = dyn_cast<MemberTypeRepr>(T)) {
1741-
if (doItInSourceOrderPre(MemberTR->getBase(), StartPostWalkDepth,
1740+
if (auto *QualIdentTR = dyn_cast<QualifiedIdentTypeRepr>(T)) {
1741+
if (doItInSourceOrderPre(QualIdentTR->getBase(), StartPostWalkDepth,
17421742
Depth + 1)) {
17431743
return true;
17441744
}
@@ -1789,9 +1789,9 @@ bool Traversal::doItInSourceOrderRecursive(MemberTypeRepr *T) {
17891789
}
17901790
}
17911791

1792-
if (auto *MemberTR = dyn_cast<MemberTypeRepr>(T)) {
1793-
return doItInSourceOrderPost(MemberTR->getBase(), StartPostWalkDepth,
1794-
Depth + 1);
1792+
if (auto *QualIdentTR = dyn_cast<QualifiedIdentTypeRepr>(T)) {
1793+
return doItInSourceOrderPost(QualIdentTR->getBase(),
1794+
StartPostWalkDepth, Depth + 1);
17951795
}
17961796

17971797
return false;
@@ -2231,8 +2231,8 @@ bool Traversal::visitAttributedTypeRepr(AttributedTypeRepr *T) {
22312231
}
22322232

22332233
bool Traversal::visitDeclRefTypeRepr(DeclRefTypeRepr *T) {
2234-
if (auto *memberTR = dyn_cast<MemberTypeRepr>(T)) {
2235-
if (doIt(memberTR->getBase())) {
2234+
if (auto *qualIdentTR = dyn_cast<QualifiedIdentTypeRepr>(T)) {
2235+
if (doIt(qualIdentTR->getBase())) {
22362236
return true;
22372237
}
22382238
}
@@ -2250,7 +2250,7 @@ bool Traversal::visitUnqualifiedIdentTypeRepr(UnqualifiedIdentTypeRepr *T) {
22502250
return visitDeclRefTypeRepr(T);
22512251
}
22522252

2253-
bool Traversal::visitMemberTypeRepr(MemberTypeRepr *T) {
2253+
bool Traversal::visitQualifiedIdentTypeRepr(QualifiedIdentTypeRepr *T) {
22542254
return visitDeclRefTypeRepr(T);
22552255
}
22562256

lib/AST/Attr.cpp

+4-3
Original file line numberDiff line numberDiff line change
@@ -2756,10 +2756,11 @@ CustomAttr::destructureMacroRef() {
27562756
return {nullptr, nullptr};
27572757
if (auto *unqualIdentType = dyn_cast<UnqualifiedIdentTypeRepr>(typeRepr))
27582758
return {nullptr, unqualIdentType};
2759-
if (auto *memType = dyn_cast<MemberTypeRepr>(typeRepr)) {
2760-
if (auto *base = dyn_cast<UnqualifiedIdentTypeRepr>(memType->getBase())) {
2759+
if (auto *qualIdentType = dyn_cast<QualifiedIdentTypeRepr>(typeRepr)) {
2760+
if (auto *base =
2761+
dyn_cast<UnqualifiedIdentTypeRepr>(qualIdentType->getBase())) {
27612762
if (!base->hasGenericArgList())
2762-
return {base, memType};
2763+
return {base, qualIdentType};
27632764
}
27642765
}
27652766
return {nullptr, nullptr};

lib/AST/Expr.cpp

+14-14
Original file line numberDiff line numberDiff line change
@@ -2241,22 +2241,22 @@ TypeExpr *TypeExpr::createForMemberDecl(DeclNameLoc ParentNameLoc,
22412241
Parent->createNameRef());
22422242
BaseTR->setValue(Parent, nullptr);
22432243

2244-
auto *MemberTR =
2245-
MemberTypeRepr::create(C, BaseTR, NameLoc, Decl->createNameRef());
2246-
MemberTR->setValue(Decl, nullptr);
2244+
auto *QualIdentTR =
2245+
QualifiedIdentTypeRepr::create(C, BaseTR, NameLoc, Decl->createNameRef());
2246+
QualIdentTR->setValue(Decl, nullptr);
22472247

2248-
return new (C) TypeExpr(MemberTR);
2248+
return new (C) TypeExpr(QualIdentTR);
22492249
}
22502250

22512251
TypeExpr *TypeExpr::createForMemberDecl(TypeRepr *ParentTR, DeclNameLoc NameLoc,
22522252
TypeDecl *Decl) {
22532253
ASTContext &C = Decl->getASTContext();
22542254

2255-
auto *MemberTR =
2256-
MemberTypeRepr::create(C, ParentTR, NameLoc, Decl->createNameRef());
2257-
MemberTR->setValue(Decl, nullptr);
2255+
auto *QualIdentTR = QualifiedIdentTypeRepr::create(C, ParentTR, NameLoc,
2256+
Decl->createNameRef());
2257+
QualIdentTR->setValue(Decl, nullptr);
22582258

2259-
return new (C) TypeExpr(MemberTR);
2259+
return new (C) TypeExpr(QualIdentTR);
22602260
}
22612261

22622262
TypeExpr *TypeExpr::createForSpecializedDecl(DeclRefTypeRepr *ParentTR,
@@ -2275,7 +2275,7 @@ TypeExpr *TypeExpr::createForSpecializedDecl(DeclRefTypeRepr *ParentTR,
22752275
C, ParentTR->getNameLoc(), ParentTR->getNameRef(), Args, AngleLocs);
22762276
specializedTR->setValue(boundDecl, ParentTR->getDeclContext());
22772277
} else {
2278-
auto *const memberTR = cast<MemberTypeRepr>(ParentTR);
2278+
auto *const qualIdentTR = cast<QualifiedIdentTypeRepr>(ParentTR);
22792279
if (isa<TypeAliasDecl>(boundDecl)) {
22802280
// If any of our parent types are unbound, bail out and let
22812281
// the constraint solver can infer generic parameters for them.
@@ -2289,7 +2289,7 @@ TypeExpr *TypeExpr::createForSpecializedDecl(DeclRefTypeRepr *ParentTR,
22892289
//
22902290
// FIXME: Once we can model generic typealiases properly, rip
22912291
// this out.
2292-
MemberTypeRepr *currTR = memberTR;
2292+
QualifiedIdentTypeRepr *currTR = qualIdentTR;
22932293
while (auto *declRefBaseTR =
22942294
dyn_cast<DeclRefTypeRepr>(currTR->getBase())) {
22952295
if (!declRefBaseTR->hasGenericArgList()) {
@@ -2299,16 +2299,16 @@ TypeExpr *TypeExpr::createForSpecializedDecl(DeclRefTypeRepr *ParentTR,
22992299
return nullptr;
23002300
}
23012301

2302-
currTR = dyn_cast<MemberTypeRepr>(declRefBaseTR);
2302+
currTR = dyn_cast<QualifiedIdentTypeRepr>(declRefBaseTR);
23032303
if (!currTR) {
23042304
break;
23052305
}
23062306
}
23072307
}
23082308

2309-
specializedTR =
2310-
MemberTypeRepr::create(C, memberTR->getBase(), ParentTR->getNameLoc(),
2311-
ParentTR->getNameRef(), Args, AngleLocs);
2309+
specializedTR = QualifiedIdentTypeRepr::create(
2310+
C, qualIdentTR->getBase(), ParentTR->getNameLoc(),
2311+
ParentTR->getNameRef(), Args, AngleLocs);
23122312
specializedTR->setValue(boundDecl, ParentTR->getDeclContext());
23132313
}
23142314

lib/AST/NameLookup.cpp

+13-12
Original file line numberDiff line numberDiff line change
@@ -2774,11 +2774,12 @@ resolveTypeDeclsToNominal(Evaluator &evaluator,
27742774
anyObject = true;
27752775
}
27762776
// TypeRepr version: Builtin.AnyObject
2777-
else if (auto *memberTR = dyn_cast_or_null<MemberTypeRepr>(
2777+
else if (auto *qualIdentTR = dyn_cast_or_null<QualifiedIdentTypeRepr>(
27782778
typealias->getUnderlyingTypeRepr())) {
2779-
if (!memberTR->hasGenericArgList() &&
2780-
memberTR->getNameRef().isSimpleName("AnyObject") &&
2781-
memberTR->getBase()->isSimpleUnqualifiedIdentifier("Builtin")) {
2779+
if (!qualIdentTR->hasGenericArgList() &&
2780+
qualIdentTR->getNameRef().isSimpleName("AnyObject") &&
2781+
qualIdentTR->getBase()->isSimpleUnqualifiedIdentifier(
2782+
"Builtin")) {
27822783
anyObject = true;
27832784
}
27842785
}
@@ -2941,9 +2942,9 @@ static DirectlyReferencedTypeDecls
29412942
directReferencesForDeclRefTypeRepr(Evaluator &evaluator, ASTContext &ctx,
29422943
DeclRefTypeRepr *repr, DeclContext *dc,
29432944
bool allowUsableFromInline) {
2944-
if (auto *memberTR = dyn_cast<MemberTypeRepr>(repr)) {
2945+
if (auto *qualIdentTR = dyn_cast<QualifiedIdentTypeRepr>(repr)) {
29452946
auto result = directReferencesForTypeRepr(
2946-
evaluator, ctx, memberTR->getBase(), dc, allowUsableFromInline);
2947+
evaluator, ctx, qualIdentTR->getBase(), dc, allowUsableFromInline);
29472948

29482949
// For a qualified identifier, perform qualified name lookup.
29492950
result.first = directReferencesForQualifiedTypeLookup(
@@ -2993,7 +2994,7 @@ directReferencesForTypeRepr(Evaluator &evaluator,
29932994
return result;
29942995
}
29952996

2996-
case TypeReprKind::Member:
2997+
case TypeReprKind::QualifiedIdent:
29972998
case TypeReprKind::UnqualifiedIdent:
29982999
return directReferencesForDeclRefTypeRepr(evaluator, ctx,
29993000
cast<DeclRefTypeRepr>(typeRepr),
@@ -3495,9 +3496,9 @@ CollectedOpaqueReprs swift::collectOpaqueTypeReprs(TypeRepr *r, ASTContext &ctx,
34953496
// We only care about the type of an outermost member type
34963497
// representation. For example, in `A<T>.B.C<U>`, check `C` and generic
34973498
// arguments `U` and `T`, but not `A` or `B`.
3498-
if (auto *parentMemberTR =
3499-
dyn_cast_or_null<MemberTypeRepr>(Parent.getAsTypeRepr())) {
3500-
if (repr == parentMemberTR->getBase()) {
3499+
if (auto *parentQualIdentTR = dyn_cast_or_null<QualifiedIdentTypeRepr>(
3500+
Parent.getAsTypeRepr())) {
3501+
if (repr == parentQualIdentTR->getBase()) {
35013502
return Action::Continue();
35023503
}
35033504
}
@@ -3765,8 +3766,8 @@ CustomAttrNominalRequest::evaluate(Evaluator &evaluator,
37653766
auto *baseTR = UnqualifiedIdentTypeRepr::create(
37663767
ctx, nameLoc, DeclNameRef(moduleName));
37673768

3768-
auto *newTE = new (ctx)
3769-
TypeExpr(MemberTypeRepr::create(ctx, baseTR, nameLoc, name));
3769+
auto *newTE = new (ctx) TypeExpr(
3770+
QualifiedIdentTypeRepr::create(ctx, baseTR, nameLoc, name));
37703771
attr->resetTypeInformation(newTE);
37713772
return nominal;
37723773
}

0 commit comments

Comments
 (0)