36
36
#include " swift/AST/PlatformKind.h"
37
37
#include " swift/AST/Requirement.h"
38
38
#include " swift/AST/TrailingCallArguments.h"
39
- #include " swift/AST/TypeLoc.h"
40
39
#include " llvm/ADT/SmallVector.h"
41
40
#include " llvm/ADT/StringRef.h"
42
41
#include " llvm/Support/ErrorHandling.h"
@@ -56,6 +55,7 @@ class LazyConformanceLoader;
56
55
class LazyMemberLoader ;
57
56
class PatternBindingInitializer ;
58
57
class TrailingWhereClause ;
58
+ class TypeExpr ;
59
59
60
60
// / TypeAttributes - These are attributes that may be applied to types.
61
61
class TypeAttributes {
@@ -1110,47 +1110,41 @@ class DynamicReplacementAttr final
1110
1110
1111
1111
// / The \c @_typeEraser(TypeEraserType) attribute.
1112
1112
class TypeEraserAttr final : public DeclAttribute {
1113
- TypeLoc TypeEraserLoc ;
1113
+ TypeExpr *TypeEraserExpr ;
1114
1114
LazyMemberLoader *Resolver;
1115
1115
uint64_t ResolverContextData;
1116
1116
1117
1117
friend class ResolveTypeEraserTypeRequest ;
1118
1118
1119
- TypeEraserAttr (SourceLoc atLoc, SourceRange range, TypeLoc typeEraserLoc ,
1119
+ TypeEraserAttr (SourceLoc atLoc, SourceRange range, TypeExpr *typeEraserExpr ,
1120
1120
LazyMemberLoader *Resolver, uint64_t Data)
1121
1121
: DeclAttribute(DAK_TypeEraser, atLoc, range, /* Implicit=*/ false ),
1122
- TypeEraserLoc (typeEraserLoc ),
1122
+ TypeEraserExpr (typeEraserExpr ),
1123
1123
Resolver(Resolver), ResolverContextData(Data) {}
1124
1124
1125
1125
public:
1126
1126
static TypeEraserAttr *create (ASTContext &ctx,
1127
1127
SourceLoc atLoc, SourceRange range,
1128
- TypeLoc typeEraserLoc );
1128
+ TypeExpr *typeEraserRepr );
1129
1129
1130
1130
static TypeEraserAttr *create (ASTContext &ctx,
1131
1131
LazyMemberLoader *Resolver,
1132
1132
uint64_t Data);
1133
1133
1134
1134
// / Retrieve the parsed type repr for this attribute, if it
1135
1135
// / was parsed. Else returns \c nullptr.
1136
- TypeRepr *getParsedTypeEraserTypeRepr () const {
1137
- return TypeEraserLoc.getTypeRepr ();
1138
- }
1136
+ TypeRepr *getParsedTypeEraserTypeRepr () const ;
1139
1137
1140
1138
// / Retrieve the parsed location for this attribute, if it was parsed.
1141
- SourceLoc getLoc () const {
1142
- return TypeEraserLoc.getLoc ();
1143
- }
1139
+ SourceLoc getLoc () const ;
1144
1140
1145
1141
// / Retrieve the resolved type of this attribute if it has been resolved by a
1146
1142
// / successful call to \c getResolvedType(). Otherwise,
1147
1143
// / returns \c Type()
1148
1144
// /
1149
1145
// / This entrypoint is only suitable for syntactic clients like the
1150
1146
// / AST printer. Semantic clients should use \c getResolvedType() instead.
1151
- Type getTypeWithoutResolving () const {
1152
- return TypeEraserLoc.getType ();
1153
- }
1147
+ Type getTypeWithoutResolving () const ;
1154
1148
1155
1149
// / Returns \c true if the type eraser type has a valid implementation of the
1156
1150
// / erasing initializer for the given protocol.
@@ -1464,25 +1458,26 @@ class SpecializeAttr : public DeclAttribute {
1464
1458
// / The @_implements attribute, which treats a decl as the implementation for
1465
1459
// / some named protocol requirement (but otherwise not-visible by that name).
1466
1460
class ImplementsAttr : public DeclAttribute {
1467
-
1468
- TypeLoc ProtocolType;
1461
+ TypeExpr *ProtocolType;
1469
1462
DeclName MemberName;
1470
1463
DeclNameLoc MemberNameLoc;
1471
1464
1472
1465
public:
1473
1466
ImplementsAttr (SourceLoc atLoc, SourceRange Range,
1474
- TypeLoc ProtocolType,
1467
+ TypeExpr * ProtocolType,
1475
1468
DeclName MemberName,
1476
1469
DeclNameLoc MemberNameLoc);
1477
1470
1478
1471
static ImplementsAttr *create (ASTContext &Ctx, SourceLoc atLoc,
1479
1472
SourceRange Range,
1480
- TypeLoc ProtocolType,
1473
+ TypeExpr * ProtocolType,
1481
1474
DeclName MemberName,
1482
1475
DeclNameLoc MemberNameLoc);
1483
1476
1484
- TypeLoc getProtocolType () const ;
1485
- TypeLoc &getProtocolType ();
1477
+ void setProtocolType (Type ty);
1478
+ Type getProtocolType () const ;
1479
+ TypeRepr *getProtocolTypeRepr () const ;
1480
+
1486
1481
DeclName getMemberName () const { return MemberName; }
1487
1482
DeclNameLoc getMemberNameLoc () const { return MemberNameLoc; }
1488
1483
@@ -1595,27 +1590,27 @@ class ClangImporterSynthesizedTypeAttr : public DeclAttribute {
1595
1590
// / Defines a custom attribute.
1596
1591
class CustomAttr final : public DeclAttribute,
1597
1592
public TrailingCallArguments<CustomAttr> {
1598
- TypeLoc type ;
1593
+ TypeExpr *typeExpr ;
1599
1594
Expr *arg;
1600
1595
PatternBindingInitializer *initContext;
1601
1596
Expr *semanticInit = nullptr ;
1602
1597
1603
1598
unsigned hasArgLabelLocs : 1 ;
1604
1599
unsigned numArgLabels : 16 ;
1605
1600
1606
- CustomAttr (SourceLoc atLoc, SourceRange range, TypeLoc type,
1601
+ CustomAttr (SourceLoc atLoc, SourceRange range, TypeExpr * type,
1607
1602
PatternBindingInitializer *initContext, Expr *arg,
1608
1603
ArrayRef<Identifier> argLabels, ArrayRef<SourceLoc> argLabelLocs,
1609
1604
bool implicit);
1610
1605
1611
1606
public:
1612
- static CustomAttr *create (ASTContext &ctx, SourceLoc atLoc, TypeLoc type,
1607
+ static CustomAttr *create (ASTContext &ctx, SourceLoc atLoc, TypeExpr * type,
1613
1608
bool implicit = false ) {
1614
1609
return create (ctx, atLoc, type, false , nullptr , SourceLoc (), { }, { }, { },
1615
1610
SourceLoc (), implicit);
1616
1611
}
1617
1612
1618
- static CustomAttr *create (ASTContext &ctx, SourceLoc atLoc, TypeLoc type,
1613
+ static CustomAttr *create (ASTContext &ctx, SourceLoc atLoc, TypeExpr * type,
1619
1614
bool hasInitializer,
1620
1615
PatternBindingInitializer *initContext,
1621
1616
SourceLoc lParenLoc,
@@ -1628,8 +1623,8 @@ class CustomAttr final : public DeclAttribute,
1628
1623
unsigned getNumArguments () const { return numArgLabels; }
1629
1624
bool hasArgumentLabelLocs () const { return hasArgLabelLocs; }
1630
1625
1631
- TypeLoc & getTypeLoc () { return type; }
1632
- const TypeLoc & getTypeLoc () const { return type; }
1626
+ TypeRepr * getTypeRepr () const ;
1627
+ Type getType () const ;
1633
1628
1634
1629
Expr *getArg () const { return arg; }
1635
1630
void setArg (Expr *newArg) { arg = newArg; }
@@ -1642,6 +1637,14 @@ class CustomAttr final : public DeclAttribute,
1642
1637
static bool classof (const DeclAttribute *DA) {
1643
1638
return DA->getKind () == DAK_Custom;
1644
1639
}
1640
+
1641
+ private:
1642
+ friend class CustomAttrNominalRequest ;
1643
+ void resetTypeInformation (TypeExpr *repr);
1644
+
1645
+ private:
1646
+ friend class CustomAttrTypeRequest ;
1647
+ void setType (Type ty);
1645
1648
};
1646
1649
1647
1650
// / Relates a property to its projection value property, as described by a property wrapper. For
0 commit comments