Skip to content

Commit 1df792a

Browse files
committed
[NFC] Convert TypeRepr to use DeclName(Loc)?
Replaces `ComponentIdentTypeRepr::getIdentifier()` and `getIdLoc()` with `getNameRef()` and `getNameLoc()`, which use `DeclName` and `DeclNameRef` respectively.
1 parent 4c41794 commit 1df792a

26 files changed

+198
-198
lines changed

include/swift/AST/Attr.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ class TypeAttributes {
6868

6969
struct Convention {
7070
StringRef Name = {};
71-
StringRef WitnessMethodProtocol = {};
71+
DeclName WitnessMethodProtocol = {};
7272
StringRef ClangType = {};
7373
// Carry the source location for diagnostics.
7474
SourceLoc ClangTypeLoc = {};
@@ -78,7 +78,7 @@ class TypeAttributes {
7878
/// Don't use this function if you are creating a C convention as you
7979
/// probably need a ClangType field as well.
8080
static Convention makeSwiftConvention(StringRef name) {
81-
return {name, "", "", {}};
81+
return {name, DeclName(), "", {}};
8282
}
8383
};
8484

include/swift/AST/DiagnosticsParse.def

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ ERROR(lex_conflict_marker_in_file,none,
207207
//------------------------------------------------------------------------------
208208

209209
NOTE(note_in_decl_extension,none,
210-
"in %select{declaration|extension}0 of %1", (bool, Identifier))
210+
"in %select{declaration|extension}0 of %1", (bool, DeclName))
211211
ERROR(line_directive_style_deprecated,none,
212212
"#line directive was renamed to #sourceLocation",
213213
())

include/swift/AST/DiagnosticsSema.def

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -781,21 +781,21 @@ NOTE(invalid_redecl_prev,none,
781781
"%0 previously declared here", (DeclName))
782782

783783
ERROR(ambiguous_type_base,none,
784-
"%0 is ambiguous for type lookup in this context", (Identifier))
784+
"%0 is ambiguous for type lookup in this context", (DeclName))
785785
ERROR(invalid_member_type,none,
786-
"%0 is not a member type of %1", (Identifier, Type))
786+
"%0 is not a member type of %1", (DeclName, Type))
787787
ERROR(invalid_member_type_suggest,none,
788788
"%0 does not have a member type named %1; did you mean %2?",
789-
(Type, Identifier, Identifier))
789+
(Type, DeclName, DeclName))
790790
ERROR(invalid_member_reference,none,
791791
"%0 %1 is not a member type of %2",
792-
(DescriptiveDeclKind, Identifier, Type))
792+
(DescriptiveDeclKind, DeclName, Type))
793793
ERROR(ambiguous_member_type,none,
794-
"ambiguous type name %0 in %1", (Identifier, Type))
794+
"ambiguous type name %0 in %1", (DeclName, Type))
795795
ERROR(no_module_type,none,
796-
"no type named %0 in module %1", (Identifier, Identifier))
796+
"no type named %0 in module %1", (DeclName, Identifier))
797797
ERROR(ambiguous_module_type,none,
798-
"ambiguous type name %0 in module %1", (Identifier, Identifier))
798+
"ambiguous type name %0 in module %1", (DeclName, Identifier))
799799
ERROR(use_nonmatching_operator,none,
800800
"%0 is not a %select{binary|prefix unary|postfix unary}1 operator",
801801
(DeclName, unsigned))
@@ -828,9 +828,9 @@ NOTE(confusable_character,none,
828828
"did you mean to use '%2'?",
829829
(bool, StringRef, StringRef))
830830
ERROR(use_undeclared_type,none,
831-
"use of undeclared type %0", (Identifier))
831+
"use of undeclared type %0", (DeclName))
832832
ERROR(use_undeclared_type_did_you_mean,none,
833-
"use of undeclared type %0; did you mean to use '%1'?", (Identifier, StringRef))
833+
"use of undeclared type %0; did you mean to use '%1'?", (DeclName, StringRef))
834834
NOTE(note_typo_candidate_implicit_member,none,
835835
"did you mean the implicitly-synthesized %1 '%0'?", (StringRef, StringRef))
836836
NOTE(note_remapped_type,none,
@@ -2178,10 +2178,10 @@ WARNING(append_interpolation_access_control,none,
21782178
// Protocols and existentials
21792179
ERROR(assoc_type_outside_of_protocol,none,
21802180
"associated type %0 can only be used with a concrete type or "
2181-
"generic parameter base", (Identifier))
2181+
"generic parameter base", (DeclName))
21822182
ERROR(typealias_outside_of_protocol,none,
21832183
"type alias %0 can only be used with a concrete type or "
2184-
"generic parameter base", (Identifier))
2184+
"generic parameter base", (DeclName))
21852185

21862186
ERROR(objc_protocol_inherits_non_objc_protocol,none,
21872187
"@objc protocol %0 cannot refine non-@objc protocol %1", (Type, Type))

include/swift/AST/Expr.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1340,19 +1340,19 @@ class TypeExpr : public Expr {
13401340

13411341

13421342
/// Create a TypeExpr for a TypeDecl at the specified location.
1343-
static TypeExpr *createForDecl(SourceLoc Loc, TypeDecl *D,
1343+
static TypeExpr *createForDecl(DeclNameLoc Loc, TypeDecl *D,
13441344
DeclContext *DC,
13451345
bool isImplicit);
13461346

13471347
/// Create a TypeExpr for a member TypeDecl of the given parent TypeDecl.
1348-
static TypeExpr *createForMemberDecl(SourceLoc ParentNameLoc,
1348+
static TypeExpr *createForMemberDecl(DeclNameLoc ParentNameLoc,
13491349
TypeDecl *Parent,
1350-
SourceLoc NameLoc,
1350+
DeclNameLoc NameLoc,
13511351
TypeDecl *Decl);
13521352

13531353
/// Create a TypeExpr for a member TypeDecl of the given parent IdentTypeRepr.
13541354
static TypeExpr *createForMemberDecl(IdentTypeRepr *ParentTR,
1355-
SourceLoc NameLoc,
1355+
DeclNameLoc NameLoc,
13561356
TypeDecl *Decl);
13571357

13581358
/// Create a TypeExpr from an IdentTypeRepr with the given arguments applied

include/swift/AST/TypeRepr.h

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -256,30 +256,30 @@ class IdentTypeRepr : public TypeRepr {
256256
};
257257

258258
class ComponentIdentTypeRepr : public IdentTypeRepr {
259-
SourceLoc Loc;
259+
DeclNameLoc Loc;
260260

261261
/// Either the identifier or declaration that describes this
262262
/// component.
263263
///
264264
/// The initial parsed representation is always an identifier, and
265265
/// name binding will resolve this to a specific declaration.
266-
llvm::PointerUnion<Identifier, TypeDecl *> IdOrDecl;
266+
llvm::PointerUnion<DeclName, TypeDecl *> IdOrDecl;
267267

268268
/// The declaration context from which the bound declaration was
269269
/// found. only valid if IdOrDecl is a TypeDecl.
270270
DeclContext *DC;
271271

272272
protected:
273-
ComponentIdentTypeRepr(TypeReprKind K, SourceLoc Loc, Identifier Id)
273+
ComponentIdentTypeRepr(TypeReprKind K, DeclNameLoc Loc, DeclName Id)
274274
: IdentTypeRepr(K), Loc(Loc), IdOrDecl(Id), DC(nullptr) {}
275275

276276
public:
277-
SourceLoc getIdLoc() const { return Loc; }
278-
Identifier getIdentifier() const;
277+
DeclNameLoc getNameLoc() const { return Loc; }
278+
DeclName getNameRef() const;
279279

280280
/// Replace the identifier with a new identifier, e.g., due to typo
281281
/// correction.
282-
void overwriteIdentifier(Identifier newId) { IdOrDecl = newId; }
282+
void overwriteNameRef(DeclName newId) { IdOrDecl = newId; }
283283

284284
/// Return true if this has been name-bound already.
285285
bool isBound() const { return IdOrDecl.is<TypeDecl *>(); }
@@ -305,20 +305,20 @@ class ComponentIdentTypeRepr : public IdentTypeRepr {
305305
protected:
306306
void printImpl(ASTPrinter &Printer, const PrintOptions &Opts) const;
307307

308-
SourceLoc getLocImpl() const { return Loc; }
308+
SourceLoc getLocImpl() const { return Loc.getBaseNameLoc(); }
309309
friend class TypeRepr;
310310
};
311311

312312
/// A simple identifier type like "Int".
313313
class SimpleIdentTypeRepr : public ComponentIdentTypeRepr {
314314
public:
315-
SimpleIdentTypeRepr(SourceLoc Loc, Identifier Id)
315+
SimpleIdentTypeRepr(DeclNameLoc Loc, DeclName Id)
316316
: ComponentIdentTypeRepr(TypeReprKind::SimpleIdent, Loc, Id) {}
317317

318318
// SmallVector::emplace_back will never need to call this because
319319
// we reserve the right size, but it does try statically.
320320
SimpleIdentTypeRepr(const SimpleIdentTypeRepr &repr)
321-
: SimpleIdentTypeRepr(repr.getLoc(), repr.getIdentifier()) {
321+
: SimpleIdentTypeRepr(repr.getNameLoc(), repr.getNameRef()) {
322322
llvm_unreachable("should not be called dynamically");
323323
}
324324

@@ -328,8 +328,8 @@ class SimpleIdentTypeRepr : public ComponentIdentTypeRepr {
328328
static bool classof(const SimpleIdentTypeRepr *T) { return true; }
329329

330330
private:
331-
SourceLoc getStartLocImpl() const { return getIdLoc(); }
332-
SourceLoc getEndLocImpl() const { return getIdLoc(); }
331+
SourceLoc getStartLocImpl() const { return getNameLoc().getStartLoc(); }
332+
SourceLoc getEndLocImpl() const { return getNameLoc().getEndLoc(); }
333333
friend class TypeRepr;
334334
};
335335

@@ -342,7 +342,7 @@ class GenericIdentTypeRepr final : public ComponentIdentTypeRepr,
342342
friend TrailingObjects;
343343
SourceRange AngleBrackets;
344344

345-
GenericIdentTypeRepr(SourceLoc Loc, Identifier Id,
345+
GenericIdentTypeRepr(DeclNameLoc Loc, DeclName Id,
346346
ArrayRef<TypeRepr*> GenericArgs,
347347
SourceRange AngleBrackets)
348348
: ComponentIdentTypeRepr(TypeReprKind::GenericIdent, Loc, Id),
@@ -359,8 +359,8 @@ class GenericIdentTypeRepr final : public ComponentIdentTypeRepr,
359359

360360
public:
361361
static GenericIdentTypeRepr *create(const ASTContext &C,
362-
SourceLoc Loc,
363-
Identifier Id,
362+
DeclNameLoc Loc,
363+
DeclName Id,
364364
ArrayRef<TypeRepr*> GenericArgs,
365365
SourceRange AngleBrackets);
366366

@@ -380,7 +380,7 @@ class GenericIdentTypeRepr final : public ComponentIdentTypeRepr,
380380
static bool classof(const GenericIdentTypeRepr *T) { return true; }
381381

382382
private:
383-
SourceLoc getStartLocImpl() const { return getIdLoc(); }
383+
SourceLoc getStartLocImpl() const { return getNameLoc().getStartLoc(); }
384384
SourceLoc getEndLocImpl() const { return AngleBrackets.End; }
385385
friend class TypeRepr;
386386
};

lib/AST/ASTDumper.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2884,7 +2884,7 @@ class PrintTypeRepr : public TypeReprVisitor<PrintTypeRepr> {
28842884
OS << '\n';
28852885
printCommon("component");
28862886
PrintWithColorRAII(OS, IdentifierColor)
2887-
<< " id='" << comp->getIdentifier() << '\'';
2887+
<< " id='" << comp->getNameRef() << '\'';
28882888
OS << " bind=";
28892889
if (comp->isBound())
28902890
comp->getBoundDecl()->dumpRef(OS);
@@ -3599,7 +3599,7 @@ namespace {
35993599
if (auto assocType = T->getAssocType()) {
36003600
printField("assoc_type", assocType->printRef());
36013601
} else {
3602-
printField("name", T->getName().str());
3602+
printField("name", T->getName());
36033603
}
36043604
printRec("base", T->getBase());
36053605
PrintWithColorRAII(OS, ParenthesisColor) << ')';

lib/AST/ASTPrinter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2834,7 +2834,7 @@ void PrintAST::visitFuncDecl(FuncDecl *decl) {
28342834
// TypeRepr is not getting 'typechecked'. See
28352835
// \c resolveTopLevelIdentTypeComponent function in TypeCheckType.cpp.
28362836
if (auto *simId = dyn_cast_or_null<SimpleIdentTypeRepr>(ResultTyLoc.getTypeRepr())) {
2837-
if (simId->getIdentifier() == Ctx.Id_Self)
2837+
if (simId->getNameRef().isSimpleName(Ctx.Id_Self))
28382838
ResultTyLoc = TypeLoc::withoutLoc(ResultTy);
28392839
}
28402840
Printer << " -> ";

lib/AST/Attr.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ void TypeAttributes::getConventionArguments(SmallVectorImpl<char> &buf) const {
8888
llvm::raw_svector_ostream stream(buf);
8989
auto &convention = ConventionArguments.getValue();
9090
stream << convention.Name;
91-
if (!convention.WitnessMethodProtocol.empty()) {
91+
if (convention.WitnessMethodProtocol) {
9292
stream << ": " << convention.WitnessMethodProtocol;
9393
return;
9494
}

lib/AST/Decl.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1741,12 +1741,12 @@ static bool isDefaultInitializable(const TypeRepr *typeRepr, ASTContext &ctx) {
17411741
// Also support the desugared 'Optional<T>' spelling.
17421742
if (!ctx.isSwiftVersionAtLeast(5)) {
17431743
if (auto *identRepr = dyn_cast<SimpleIdentTypeRepr>(typeRepr)) {
1744-
if (identRepr->getIdentifier() == ctx.Id_Void)
1744+
if (identRepr->getNameRef().getBaseIdentifier() == ctx.Id_Void)
17451745
return true;
17461746
}
17471747

17481748
if (auto *identRepr = dyn_cast<GenericIdentTypeRepr>(typeRepr)) {
1749-
if (identRepr->getIdentifier() == ctx.Id_Optional &&
1749+
if (identRepr->getNameRef().getBaseIdentifier() == ctx.Id_Optional &&
17501750
identRepr->getNumGenericArgs() == 1)
17511751
return true;
17521752
}

lib/AST/Expr.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1882,7 +1882,7 @@ Type TypeExpr::getInstanceType(
18821882
}
18831883

18841884

1885-
TypeExpr *TypeExpr::createForDecl(SourceLoc Loc, TypeDecl *Decl,
1885+
TypeExpr *TypeExpr::createForDecl(DeclNameLoc Loc, TypeDecl *Decl,
18861886
DeclContext *DC,
18871887
bool isImplicit) {
18881888
ASTContext &C = Decl->getASTContext();
@@ -1895,9 +1895,9 @@ TypeExpr *TypeExpr::createForDecl(SourceLoc Loc, TypeDecl *Decl,
18951895
return result;
18961896
}
18971897

1898-
TypeExpr *TypeExpr::createForMemberDecl(SourceLoc ParentNameLoc,
1898+
TypeExpr *TypeExpr::createForMemberDecl(DeclNameLoc ParentNameLoc,
18991899
TypeDecl *Parent,
1900-
SourceLoc NameLoc,
1900+
DeclNameLoc NameLoc,
19011901
TypeDecl *Decl) {
19021902
ASTContext &C = Decl->getASTContext();
19031903
assert(ParentNameLoc.isValid());
@@ -1923,7 +1923,7 @@ TypeExpr *TypeExpr::createForMemberDecl(SourceLoc ParentNameLoc,
19231923
}
19241924

19251925
TypeExpr *TypeExpr::createForMemberDecl(IdentTypeRepr *ParentTR,
1926-
SourceLoc NameLoc,
1926+
DeclNameLoc NameLoc,
19271927
TypeDecl *Decl) {
19281928
ASTContext &C = Decl->getASTContext();
19291929

@@ -1983,7 +1983,7 @@ TypeExpr *TypeExpr::createForSpecializedDecl(IdentTypeRepr *ParentTR,
19831983
}
19841984

19851985
auto *genericComp = GenericIdentTypeRepr::create(C,
1986-
last->getIdLoc(), last->getIdentifier(),
1986+
last->getNameLoc(), last->getNameRef(),
19871987
Args, AngleLocs);
19881988
genericComp->setValue(last->getBoundDecl(), last->getDeclContext());
19891989
components.push_back(genericComp);

0 commit comments

Comments
 (0)