Skip to content

Commit a9a998d

Browse files
committed
[NFC] AST: Rename ComponentIdentTypeReprIdentTypeRepr
1 parent 3038086 commit a9a998d

25 files changed

+243
-246
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: 35 additions & 29 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
assert(!GenericArgs.empty());
373382
#ifndef NDEBUG
@@ -413,36 +422,33 @@ class GenericIdentTypeRepr final : public ComponentIdentTypeRepr,
413422
/// [Int].Bar
414423
/// \endcode
415424
class MemberTypeRepr final : public DeclRefTypeRepr,
416-
private llvm::TrailingObjects<MemberTypeRepr,
417-
ComponentIdentTypeRepr *> {
425+
private llvm::TrailingObjects<MemberTypeRepr, IdentTypeRepr *> {
418426
friend TrailingObjects;
419427

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

423-
MemberTypeRepr(TypeRepr *Base,
424-
ArrayRef<ComponentIdentTypeRepr *> MemberComponents)
431+
MemberTypeRepr(TypeRepr *Base, ArrayRef<IdentTypeRepr *> MemberComponents)
425432
: DeclRefTypeRepr(TypeReprKind::Member), Base(Base) {
426433
Bits.MemberTypeRepr.NumMemberComponents = MemberComponents.size();
427434
assert(MemberComponents.size() > 0 &&
428-
"should have just used the single ComponentIdentTypeRepr directly");
435+
"MemberTypeRepr requires at least 1 member component");
429436
std::uninitialized_copy(MemberComponents.begin(), MemberComponents.end(),
430-
getTrailingObjects<ComponentIdentTypeRepr *>());
437+
getTrailingObjects<IdentTypeRepr *>());
431438
}
432439

433440
public:
434-
static MemberTypeRepr *
435-
create(const ASTContext &Ctx, TypeRepr *Base,
436-
ArrayRef<ComponentIdentTypeRepr *> MemberComponents);
441+
static MemberTypeRepr *create(const ASTContext &Ctx, TypeRepr *Base,
442+
ArrayRef<IdentTypeRepr *> MemberComponents);
437443

438444
TypeRepr *getBaseComponent() const { return Base; }
439445

440-
ArrayRef<ComponentIdentTypeRepr *> getMemberComponents() const {
441-
return {getTrailingObjects<ComponentIdentTypeRepr *>(),
446+
ArrayRef<IdentTypeRepr *> getMemberComponents() const {
447+
return {getTrailingObjects<IdentTypeRepr *>(),
442448
Bits.MemberTypeRepr.NumMemberComponents};
443449
}
444450

445-
ComponentIdentTypeRepr *getLastComponent() const {
451+
IdentTypeRepr *getLastComponent() const {
446452
return getMemberComponents().back();
447453
}
448454

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/CodeCompletionCallbacks.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,10 +163,10 @@ class CodeCompletionCallbacks {
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
@@ -3088,7 +3088,7 @@ class PrintTypeRepr : public TypeReprVisitor<PrintTypeRepr> {
30883088
printRec(T->getTypeRepr());
30893089
}
30903090

3091-
void visitComponentIdentTypeRepr(ComponentIdentTypeRepr *T) {
3091+
void visitIdentTypeRepr(IdentTypeRepr *T) {
30923092
printCommon("type_ident");
30933093

30943094
PrintWithColorRAII(OS, IdentifierColor)

lib/AST/CASTBridging.cpp

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

410410
void *DeclRefTypeRepr_create(void *ctx, BridgedArrayRef bridgedComponents) {
411411
ASTContext &Context = *static_cast<ASTContext *>(ctx);
412-
auto components = getArrayRef<ComponentIdentTypeRepr *>(bridgedComponents);
412+
auto components = getArrayRef<IdentTypeRepr *>(bridgedComponents);
413413
if (components.size() == 1) {
414414
return components.front();
415415
}

lib/AST/Expr.cpp

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

21612161
TypeExpr *TypeExpr::createForMemberDecl(DeclRefTypeRepr *ParentTR,
2162-
DeclNameLoc NameLoc,
2163-
TypeDecl *Decl) {
2162+
DeclNameLoc NameLoc, TypeDecl *Decl) {
21642163
ASTContext &C = Decl->getASTContext();
21652164

21662165
// Create a new list of components.
2167-
SmallVector<ComponentIdentTypeRepr *, 2> Components;
2166+
SmallVector<IdentTypeRepr *, 2> Components;
21682167
if (auto *MemberTR = dyn_cast<MemberTypeRepr>(ParentTR)) {
21692168
auto MemberComps = MemberTR->getMemberComponents();
21702169
Components.append(MemberComps.begin(), MemberComps.end());
@@ -2203,9 +2202,9 @@ TypeExpr *TypeExpr::createForSpecializedDecl(DeclRefTypeRepr *ParentTR,
22032202
//
22042203
// FIXME: Once we can model generic typealiases properly, rip
22052204
// this out.
2206-
auto isUnboundGenericComponent = [](ComponentIdentTypeRepr *TR) -> bool {
2207-
if (isa<SimpleIdentTypeRepr>(TR)) {
2208-
auto *decl = dyn_cast_or_null<GenericTypeDecl>(TR->getBoundDecl());
2205+
auto isUnboundGenericComponent = [](IdentTypeRepr *ITR) -> bool {
2206+
if (isa<SimpleIdentTypeRepr>(ITR)) {
2207+
auto *decl = dyn_cast_or_null<GenericTypeDecl>(ITR->getBoundDecl());
22092208
if (decl && decl->isGeneric())
22102209
return true;
22112210
}
@@ -2219,7 +2218,7 @@ TypeExpr *TypeExpr::createForSpecializedDecl(DeclRefTypeRepr *ParentTR,
22192218
}
22202219

22212220
if (auto *identBase =
2222-
dyn_cast<ComponentIdentTypeRepr>(memberTR->getBaseComponent())) {
2221+
dyn_cast<IdentTypeRepr>(memberTR->getBaseComponent())) {
22232222
if (isUnboundGenericComponent(identBase))
22242223
return nullptr;
22252224
}
@@ -2236,7 +2235,7 @@ TypeExpr *TypeExpr::createForSpecializedDecl(DeclRefTypeRepr *ParentTR,
22362235

22372236
// Create a new list of member components, replacing the last one with the
22382237
// new specialized one.
2239-
SmallVector<ComponentIdentTypeRepr *, 2> newMemberComps;
2238+
SmallVector<IdentTypeRepr *, 2> newMemberComps;
22402239
newMemberComps.append(oldMemberComps.begin(), oldMemberComps.end());
22412240
newMemberComps.push_back(genericComp);
22422241

lib/AST/NameLookup.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2268,8 +2268,8 @@ resolveTypeDeclsToNominal(Evaluator &evaluator,
22682268
// TypeRepr version: Builtin.AnyObject
22692269
if (auto typeRepr = typealias->getUnderlyingTypeRepr()) {
22702270
if (auto memberTR = dyn_cast<MemberTypeRepr>(typeRepr)) {
2271-
if (auto identBase = dyn_cast<ComponentIdentTypeRepr>(
2272-
memberTR->getBaseComponent())) {
2271+
if (auto identBase =
2272+
dyn_cast<IdentTypeRepr>(memberTR->getBaseComponent())) {
22732273
auto memberComps = memberTR->getMemberComponents();
22742274
if (memberComps.size() == 1 &&
22752275
identBase->getNameRef().isSimpleName("Builtin") &&
@@ -2440,7 +2440,7 @@ directReferencesForDeclRefTypeRepr(Evaluator &evaluator, ASTContext &ctx,
24402440
DirectlyReferencedTypeDecls current;
24412441

24422442
auto *baseComp = repr->getBaseComponent();
2443-
if (auto *identBase = dyn_cast<ComponentIdentTypeRepr>(baseComp)) {
2443+
if (auto *identBase = dyn_cast<IdentTypeRepr>(baseComp)) {
24442444
// If we already set a declaration, use it.
24452445
if (auto *typeDecl = identBase->getBoundDecl()) {
24462446
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: 10 additions & 11 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,9 +386,8 @@ 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
}

lib/IDE/CodeCompletion.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -201,10 +201,9 @@ class CodeCompletionCallbacksImpl : public CodeCompletionCallbacks {
201201
if (isa<MemberTypeRepr>(declRefTR))
202202
return false;
203203

204-
const auto *component = cast<ComponentIdentTypeRepr>(declRefTR);
204+
const auto *identTR = cast<IdentTypeRepr>(declRefTR);
205205
ImportPath::Module::Builder builder(
206-
component->getNameRef().getBaseIdentifier(),
207-
component->getLoc());
206+
identTR->getNameRef().getBaseIdentifier(), identTR->getLoc());
208207

209208
if (auto Module = Context.getLoadedModule(builder.get()))
210209
ParsedTypeLoc.setType(ModuleType::get(Module));

0 commit comments

Comments
 (0)