Skip to content

Commit 1bb407a

Browse files
committed
[NFC] AST: Rename ComponentIdentTypeReprIdentTypeRepr
1 parent ad5d55c commit 1bb407a

26 files changed

+245
-249
lines changed

include/swift/AST/Expr.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1341,8 +1341,7 @@ class TypeExpr : public Expr {
13411341
/// Create a \c TypeExpr for a member \c TypeDecl of the given parent
13421342
/// \c DeclRefTypeRepr.
13431343
static TypeExpr *createForMemberDecl(DeclRefTypeRepr *ParentTR,
1344-
DeclNameLoc NameLoc,
1345-
TypeDecl *Decl);
1344+
DeclNameLoc NameLoc, TypeDecl *Decl);
13461345

13471346
/// Create a \c TypeExpr from an \c DeclRefTypeRepr with the given arguments
13481347
/// applied at the specified location.

include/swift/AST/TypeDeclFinder.h

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
namespace swift {
2020

2121
class BoundGenericType;
22-
class ComponentIdentTypeRepr;
22+
class IdentTypeRepr;
2323
class NominalType;
2424
class TypeAliasType;
2525

@@ -44,7 +44,7 @@ class TypeDeclFinder : public TypeWalker {
4444
/// equivalently and where generic arguments can be walked to separately from
4545
/// the generic type.
4646
class SimpleTypeDeclFinder : public TypeDeclFinder {
47-
/// The function to call when a ComponentIdentTypeRepr is seen.
47+
/// The function to call when a \c IdentTypeRepr is seen.
4848
llvm::function_ref<Action(const TypeDecl *)> Callback;
4949

5050
Action visitNominalType(NominalType *ty) override;
@@ -57,20 +57,21 @@ class SimpleTypeDeclFinder : public TypeDeclFinder {
5757
: Callback(callback) {}
5858
};
5959

60-
/// Walks a TypeRepr to find all ComponentIdentTypeReprs with bound TypeDecls.
60+
/// Walks a \c TypeRepr to find all \c IdentTypeRepr nodes with bound
61+
/// type declarations.
6162
///
6263
/// Subclasses can either override #visitTypeDecl if they only care about
63-
/// types on their own, or #visitComponentIdentTypeRepr if they want to keep
64+
/// types on their own, or #visitIdentTypeRepr if they want to keep
6465
/// the TypeRepr around.
6566
class TypeReprIdentFinder : public ASTWalker {
66-
/// The function to call when a ComponentIdentTypeRepr is seen.
67-
llvm::function_ref<bool(const ComponentIdentTypeRepr *)> Callback;
67+
/// The function to call when a \c IdentTypeRepr is seen.
68+
llvm::function_ref<bool(const IdentTypeRepr *)> Callback;
6869

6970
PostWalkAction walkToTypeReprPost(TypeRepr *TR) override;
7071

7172
public:
7273
explicit TypeReprIdentFinder(
73-
llvm::function_ref<bool(const ComponentIdentTypeRepr *)> callback)
74+
llvm::function_ref<bool(const IdentTypeRepr *)> callback)
7475
: Callback(callback) {}
7576
};
7677

include/swift/AST/TypeRepr.h

Lines changed: 37 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -80,17 +80,15 @@ class alignas(1 << TypeReprAlignInBits) TypeRepr
8080
);
8181

8282
SWIFT_INLINE_BITFIELD_EMPTY(DeclRefTypeRepr, TypeRepr);
83-
SWIFT_INLINE_BITFIELD_EMPTY(ComponentIdentTypeRepr, DeclRefTypeRepr);
83+
SWIFT_INLINE_BITFIELD_EMPTY(IdentTypeRepr, DeclRefTypeRepr);
8484

85-
SWIFT_INLINE_BITFIELD_FULL(GenericIdentTypeRepr, ComponentIdentTypeRepr, 32,
85+
SWIFT_INLINE_BITFIELD_FULL(GenericIdentTypeRepr, IdentTypeRepr, 32,
8686
: NumPadBits,
8787
NumGenericArgs : 32
8888
);
8989

9090
SWIFT_INLINE_BITFIELD_FULL(MemberTypeRepr, DeclRefTypeRepr, 32,
91-
: NumPadBits,
92-
NumMemberComponents : 32
93-
);
91+
: NumPadBits, NumMemberComponents : 32);
9492

9593
SWIFT_INLINE_BITFIELD_FULL(CompositionTypeRepr, TypeRepr, 32,
9694
: NumPadBits,
@@ -245,7 +243,7 @@ class AttributedTypeRepr : public TypeRepr {
245243
friend class TypeRepr;
246244
};
247245

248-
class ComponentIdentTypeRepr;
246+
class IdentTypeRepr;
249247

250248
/// This is the abstract base class for types that directly reference a
251249
/// type declaration. In written syntax, this type representation consists of
@@ -258,8 +256,13 @@ class DeclRefTypeRepr : public TypeRepr {
258256
explicit DeclRefTypeRepr(TypeReprKind K) : TypeRepr(K) {}
259257

260258
public:
259+
/// Returns \c this if it is a \c IdentTypeRepr. Otherwise, \c this
260+
/// is a \c MemberTypeRepr, and the method returns its base component.
261261
TypeRepr *getBaseComponent();
262-
ComponentIdentTypeRepr *getLastComponent();
262+
263+
/// Returns \c this if it is a \c IdentTypeRepr. Otherwise, \c this
264+
/// is a \c MemberTypeRepr, and the method returns its last member component.
265+
IdentTypeRepr *getLastComponent();
263266

264267
/// The type declaration the last component is bound to.
265268
TypeDecl *getBoundDecl() const;
@@ -275,7 +278,12 @@ class DeclRefTypeRepr : public TypeRepr {
275278
static bool classof(const DeclRefTypeRepr *T) { return true; }
276279
};
277280

278-
class ComponentIdentTypeRepr : public DeclRefTypeRepr {
281+
/// An identifier type with an optional set of generic arguments.
282+
/// \code
283+
/// Foo
284+
/// Bar<Gen>
285+
/// \endcode
286+
class IdentTypeRepr : public DeclRefTypeRepr {
279287
DeclNameLoc Loc;
280288

281289
/// Either the identifier or declaration that describes this
@@ -290,7 +298,7 @@ class ComponentIdentTypeRepr : public DeclRefTypeRepr {
290298
DeclContext *DC;
291299

292300
protected:
293-
ComponentIdentTypeRepr(TypeReprKind K, DeclNameLoc Loc, DeclNameRef Id)
301+
IdentTypeRepr(TypeReprKind K, DeclNameLoc Loc, DeclNameRef Id)
294302
: DeclRefTypeRepr(K), Loc(Loc), IdOrDecl(Id), DC(nullptr) {}
295303

296304
public:
@@ -321,7 +329,7 @@ class ComponentIdentTypeRepr : public DeclRefTypeRepr {
321329
return T->getKind() == TypeReprKind::SimpleIdent ||
322330
T->getKind() == TypeReprKind::GenericIdent;
323331
}
324-
static bool classof(const ComponentIdentTypeRepr *T) { return true; }
332+
static bool classof(const IdentTypeRepr *T) { return true; }
325333

326334
protected:
327335
void printImpl(ASTPrinter &Printer, const PrintOptions &Opts) const;
@@ -331,10 +339,10 @@ class ComponentIdentTypeRepr : public DeclRefTypeRepr {
331339
};
332340

333341
/// A simple identifier type like "Int".
334-
class SimpleIdentTypeRepr : public ComponentIdentTypeRepr {
342+
class SimpleIdentTypeRepr : public IdentTypeRepr {
335343
public:
336344
SimpleIdentTypeRepr(DeclNameLoc Loc, DeclNameRef Id)
337-
: ComponentIdentTypeRepr(TypeReprKind::SimpleIdent, Loc, Id) {}
345+
: IdentTypeRepr(TypeReprKind::SimpleIdent, Loc, Id) {}
338346

339347
// SmallVector::emplace_back will never need to call this because
340348
// we reserve the right size, but it does try statically.
@@ -358,16 +366,17 @@ class SimpleIdentTypeRepr : public ComponentIdentTypeRepr {
358366
/// \code
359367
/// Bar<Gen>
360368
/// \endcode
361-
class GenericIdentTypeRepr final : public ComponentIdentTypeRepr,
362-
private llvm::TrailingObjects<GenericIdentTypeRepr, TypeRepr *> {
369+
class GenericIdentTypeRepr final
370+
: public IdentTypeRepr,
371+
private llvm::TrailingObjects<GenericIdentTypeRepr, TypeRepr *> {
363372
friend TrailingObjects;
364373
SourceRange AngleBrackets;
365374

366375
GenericIdentTypeRepr(DeclNameLoc Loc, DeclNameRef Id,
367-
ArrayRef<TypeRepr*> GenericArgs,
376+
ArrayRef<TypeRepr *> GenericArgs,
368377
SourceRange AngleBrackets)
369-
: ComponentIdentTypeRepr(TypeReprKind::GenericIdent, Loc, Id),
370-
AngleBrackets(AngleBrackets) {
378+
: IdentTypeRepr(TypeReprKind::GenericIdent, Loc, Id),
379+
AngleBrackets(AngleBrackets) {
371380
Bits.GenericIdentTypeRepr.NumGenericArgs = GenericArgs.size();
372381
#ifndef NDEBUG
373382
for (auto arg : GenericArgs)
@@ -412,39 +421,36 @@ class GenericIdentTypeRepr final : public ComponentIdentTypeRepr,
412421
/// [Int].Bar
413422
/// \endcode
414423
class MemberTypeRepr final : public DeclRefTypeRepr,
415-
private llvm::TrailingObjects<MemberTypeRepr,
416-
ComponentIdentTypeRepr *> {
424+
private llvm::TrailingObjects<MemberTypeRepr, IdentTypeRepr *> {
417425
friend TrailingObjects;
418426

419427
/// The base component, which is not necessarily an identifier type.
420428
TypeRepr *Base;
421429

422-
MemberTypeRepr(TypeRepr *Base,
423-
ArrayRef<ComponentIdentTypeRepr *> MemberComponents)
430+
MemberTypeRepr(TypeRepr *Base, ArrayRef<IdentTypeRepr *> MemberComponents)
424431
: DeclRefTypeRepr(TypeReprKind::Member), Base(Base) {
425432
Bits.MemberTypeRepr.NumMemberComponents = MemberComponents.size();
426433
assert(MemberComponents.size() > 0 &&
427-
"should have just used the single ComponentIdentTypeRepr directly");
434+
"MemberTypeRepr requires at least 1 member component");
428435
std::uninitialized_copy(MemberComponents.begin(), MemberComponents.end(),
429-
getTrailingObjects<ComponentIdentTypeRepr *>());
436+
getTrailingObjects<IdentTypeRepr *>());
430437
}
431438

432439
public:
433-
static MemberTypeRepr *
434-
create(const ASTContext &Ctx, TypeRepr *Base,
435-
ArrayRef<ComponentIdentTypeRepr *> MemberComponents);
440+
static MemberTypeRepr *create(const ASTContext &Ctx, TypeRepr *Base,
441+
ArrayRef<IdentTypeRepr *> MemberComponents);
436442

437-
static MemberTypeRepr *
438-
create(const ASTContext &Ctx, ArrayRef<ComponentIdentTypeRepr *> Components);
443+
static MemberTypeRepr *create(const ASTContext &Ctx,
444+
ArrayRef<IdentTypeRepr *> Components);
439445

440446
TypeRepr *getBaseComponent() const { return Base; }
441447

442-
ArrayRef<ComponentIdentTypeRepr *> getMemberComponents() const {
443-
return {getTrailingObjects<ComponentIdentTypeRepr *>(),
448+
ArrayRef<IdentTypeRepr *> getMemberComponents() const {
449+
return {getTrailingObjects<IdentTypeRepr *>(),
444450
Bits.MemberTypeRepr.NumMemberComponents};
445451
}
446452

447-
ComponentIdentTypeRepr *getLastComponent() const {
453+
IdentTypeRepr *getLastComponent() const {
448454
return getMemberComponents().back();
449455
}
450456

include/swift/AST/TypeReprNodes.def

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,9 @@ TYPEREPR(Error, TypeRepr)
4646
TYPEREPR(Attributed, TypeRepr)
4747

4848
ABSTRACT_TYPEREPR(DeclRef, TypeRepr)
49-
ABSTRACT_TYPEREPR(ComponentIdent, DeclRefTypeRepr)
50-
TYPEREPR(SimpleIdent, ComponentIdentTypeRepr)
51-
TYPEREPR(GenericIdent, ComponentIdentTypeRepr)
49+
ABSTRACT_TYPEREPR(Ident, DeclRefTypeRepr)
50+
TYPEREPR(SimpleIdent, IdentTypeRepr)
51+
TYPEREPR(GenericIdent, IdentTypeRepr)
5252
TYPEREPR(Member, DeclRefTypeRepr)
5353

5454
TYPEREPR(Function, TypeRepr)

include/swift/Parse/IDEInspectionCallbacks.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,10 +163,10 @@ class IDEInspectionCallbacks {
163163
virtual void completeTypeSimpleBeginning() {};
164164

165165
/// Complete a given type identifier after we have consumed the dot.
166-
virtual void completeTypeIdentifierWithDot(DeclRefTypeRepr *TR) {};
166+
virtual void completeTypeIdentifierWithDot(DeclRefTypeRepr *TR){};
167167

168168
/// Complete a given type identifier when there is no trailing dot.
169-
virtual void completeTypeIdentifierWithoutDot(DeclRefTypeRepr *TR) {};
169+
virtual void completeTypeIdentifierWithoutDot(DeclRefTypeRepr *TR){};
170170

171171
/// Complete the beginning of a case statement at the top of switch stmt.
172172
virtual void completeCaseStmtKeyword() {};

lib/AST/ASTDumper.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3112,7 +3112,7 @@ class PrintTypeRepr : public TypeReprVisitor<PrintTypeRepr> {
31123112
printRec(T->getTypeRepr());
31133113
}
31143114

3115-
void visitComponentIdentTypeRepr(ComponentIdentTypeRepr *T) {
3115+
void visitIdentTypeRepr(IdentTypeRepr *T) {
31163116
printCommon("type_ident");
31173117

31183118
PrintWithColorRAII(OS, IdentifierColor)

lib/AST/CASTBridging.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -499,7 +499,7 @@ void *TupleTypeRepr_create(void *ctx, BridgedArrayRef elements, void *lParenLoc,
499499

500500
void *DeclRefTypeRepr_create(void *ctx, BridgedArrayRef bridgedComponents) {
501501
ASTContext &Context = *static_cast<ASTContext *>(ctx);
502-
auto components = getArrayRef<ComponentIdentTypeRepr *>(bridgedComponents);
502+
auto components = getArrayRef<IdentTypeRepr *>(bridgedComponents);
503503
if (components.size() == 1) {
504504
return components.front();
505505
}

lib/AST/Expr.cpp

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2225,12 +2225,11 @@ TypeExpr *TypeExpr::createForMemberDecl(DeclNameLoc ParentNameLoc,
22252225
}
22262226

22272227
TypeExpr *TypeExpr::createForMemberDecl(DeclRefTypeRepr *ParentTR,
2228-
DeclNameLoc NameLoc,
2229-
TypeDecl *Decl) {
2228+
DeclNameLoc NameLoc, TypeDecl *Decl) {
22302229
ASTContext &C = Decl->getASTContext();
22312230

22322231
// Create a new list of components.
2233-
SmallVector<ComponentIdentTypeRepr *, 2> Components;
2232+
SmallVector<IdentTypeRepr *, 2> Components;
22342233
if (auto *MemberTR = dyn_cast<MemberTypeRepr>(ParentTR)) {
22352234
auto MemberComps = MemberTR->getMemberComponents();
22362235
Components.append(MemberComps.begin(), MemberComps.end());
@@ -2269,9 +2268,9 @@ TypeExpr *TypeExpr::createForSpecializedDecl(DeclRefTypeRepr *ParentTR,
22692268
//
22702269
// FIXME: Once we can model generic typealiases properly, rip
22712270
// this out.
2272-
auto isUnboundGenericComponent = [](ComponentIdentTypeRepr *TR) -> bool {
2273-
if (isa<SimpleIdentTypeRepr>(TR)) {
2274-
auto *decl = dyn_cast_or_null<GenericTypeDecl>(TR->getBoundDecl());
2271+
auto isUnboundGenericComponent = [](IdentTypeRepr *ITR) -> bool {
2272+
if (isa<SimpleIdentTypeRepr>(ITR)) {
2273+
auto *decl = dyn_cast_or_null<GenericTypeDecl>(ITR->getBoundDecl());
22752274
if (decl && decl->isGeneric())
22762275
return true;
22772276
}
@@ -2285,7 +2284,7 @@ TypeExpr *TypeExpr::createForSpecializedDecl(DeclRefTypeRepr *ParentTR,
22852284
}
22862285

22872286
if (auto *identBase =
2288-
dyn_cast<ComponentIdentTypeRepr>(memberTR->getBaseComponent())) {
2287+
dyn_cast<IdentTypeRepr>(memberTR->getBaseComponent())) {
22892288
if (isUnboundGenericComponent(identBase))
22902289
return nullptr;
22912290
}
@@ -2302,7 +2301,7 @@ TypeExpr *TypeExpr::createForSpecializedDecl(DeclRefTypeRepr *ParentTR,
23022301

23032302
// Create a new list of member components, replacing the last one with the
23042303
// new specialized one.
2305-
SmallVector<ComponentIdentTypeRepr *, 2> newMemberComps;
2304+
SmallVector<IdentTypeRepr *, 2> newMemberComps;
23062305
newMemberComps.append(oldMemberComps.begin(), oldMemberComps.end());
23072306
newMemberComps.push_back(genericComp);
23082307

lib/AST/NameLookup.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2257,8 +2257,8 @@ resolveTypeDeclsToNominal(Evaluator &evaluator,
22572257
// TypeRepr version: Builtin.AnyObject
22582258
if (auto typeRepr = typealias->getUnderlyingTypeRepr()) {
22592259
if (auto memberTR = dyn_cast<MemberTypeRepr>(typeRepr)) {
2260-
if (auto identBase = dyn_cast<ComponentIdentTypeRepr>(
2261-
memberTR->getBaseComponent())) {
2260+
if (auto identBase =
2261+
dyn_cast<IdentTypeRepr>(memberTR->getBaseComponent())) {
22622262
auto memberComps = memberTR->getMemberComponents();
22632263
if (memberComps.size() == 1 &&
22642264
identBase->getNameRef().isSimpleName("Builtin") &&
@@ -2429,7 +2429,7 @@ directReferencesForDeclRefTypeRepr(Evaluator &evaluator, ASTContext &ctx,
24292429
DirectlyReferencedTypeDecls current;
24302430

24312431
auto *baseComp = repr->getBaseComponent();
2432-
if (auto *identBase = dyn_cast<ComponentIdentTypeRepr>(baseComp)) {
2432+
if (auto *identBase = dyn_cast<IdentTypeRepr>(baseComp)) {
24332433
// If we already set a declaration, use it.
24342434
if (auto *typeDecl = identBase->getBoundDecl()) {
24352435
current = {1, typeDecl};

lib/AST/TypeDeclFinder.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ SimpleTypeDeclFinder::visitTypeAliasType(TypeAliasType *ty) {
5151

5252
ASTWalker::PostWalkAction
5353
TypeReprIdentFinder::walkToTypeReprPost(TypeRepr *TR) {
54-
auto CITR = dyn_cast<ComponentIdentTypeRepr>(TR);
55-
if (!CITR || !CITR->getBoundDecl())
54+
auto ITR = dyn_cast<IdentTypeRepr>(TR);
55+
if (!ITR || !ITR->getBoundDecl())
5656
return Action::Continue();
57-
return Action::StopIf(!Callback(CITR));
57+
return Action::StopIf(!Callback(ITR));
5858
}

lib/AST/TypeRepr.cpp

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -138,20 +138,20 @@ DeclNameRef DeclRefTypeRepr::getNameRef() const {
138138
}
139139

140140
TypeRepr *DeclRefTypeRepr::getBaseComponent() {
141-
if (auto *Comp = dyn_cast<ComponentIdentTypeRepr>(this))
142-
return Comp;
141+
if (auto *ITR = dyn_cast<IdentTypeRepr>(this))
142+
return ITR;
143143

144144
return cast<MemberTypeRepr>(this)->getBaseComponent();
145145
}
146146

147-
ComponentIdentTypeRepr *DeclRefTypeRepr::getLastComponent() {
148-
if (auto *Comp = dyn_cast<ComponentIdentTypeRepr>(this))
149-
return Comp;
147+
IdentTypeRepr *DeclRefTypeRepr::getLastComponent() {
148+
if (auto *ITR = dyn_cast<IdentTypeRepr>(this))
149+
return ITR;
150150

151151
return cast<MemberTypeRepr>(this)->getLastComponent();
152152
}
153153

154-
DeclNameRef ComponentIdentTypeRepr::getNameRef() const {
154+
DeclNameRef IdentTypeRepr::getNameRef() const {
155155
if (IdOrDecl.is<DeclNameRef>())
156156
return IdOrDecl.get<DeclNameRef>();
157157

@@ -280,8 +280,8 @@ static void printGenericArgs(ASTPrinter &Printer, const PrintOptions &Opts,
280280
Printer << ">";
281281
}
282282

283-
void ComponentIdentTypeRepr::printImpl(ASTPrinter &Printer,
284-
const PrintOptions &Opts) const {
283+
void IdentTypeRepr::printImpl(ASTPrinter &Printer,
284+
const PrintOptions &Opts) const {
285285
if (auto *TD = dyn_cast_or_null<TypeDecl>(getBoundDecl())) {
286286
if (auto MD = dyn_cast<ModuleDecl>(TD))
287287
Printer.printModuleRef(MD, getNameRef().getBaseIdentifier());
@@ -386,16 +386,14 @@ GenericIdentTypeRepr *GenericIdentTypeRepr::create(const ASTContext &C,
386386

387387
MemberTypeRepr *
388388
MemberTypeRepr::create(const ASTContext &C, TypeRepr *Base,
389-
ArrayRef<ComponentIdentTypeRepr *> MemberComponents) {
390-
auto size =
391-
totalSizeToAlloc<ComponentIdentTypeRepr *>(MemberComponents.size());
389+
ArrayRef<IdentTypeRepr *> MemberComponents) {
390+
auto size = totalSizeToAlloc<IdentTypeRepr *>(MemberComponents.size());
392391
auto mem = C.Allocate(size, alignof(MemberTypeRepr));
393392
return new (mem) MemberTypeRepr(Base, MemberComponents);
394393
}
395394

396-
MemberTypeRepr *
397-
MemberTypeRepr::create(const ASTContext &Ctx,
398-
ArrayRef<ComponentIdentTypeRepr *> Components) {
395+
MemberTypeRepr *MemberTypeRepr::create(const ASTContext &Ctx,
396+
ArrayRef<IdentTypeRepr *> Components) {
399397
return create(Ctx, Components.front(), Components.drop_front());
400398
}
401399

0 commit comments

Comments
 (0)