@@ -156,6 +156,10 @@ class alignas(8) Expr {
156
156
157
157
SWIFT_INLINE_BITFIELD_EMPTY (LiteralExpr, Expr);
158
158
SWIFT_INLINE_BITFIELD_EMPTY (IdentityExpr, Expr);
159
+ SWIFT_INLINE_BITFIELD (LookupExpr, Expr, 1 ,
160
+ IsSuper : 1
161
+ );
162
+ SWIFT_INLINE_BITFIELD_EMPTY (DynamicLookupExpr, LookupExpr);
159
163
160
164
SWIFT_INLINE_BITFIELD (ParenExpr, IdentityExpr, 1 ,
161
165
// / \brief Whether we're wrapping a trailing closure expression.
@@ -182,9 +186,8 @@ class alignas(8) Expr {
182
186
FunctionRefKind : 2
183
187
);
184
188
185
- SWIFT_INLINE_BITFIELD (MemberRefExpr, Expr, 2 +1 ,
186
- Semantics : 2 , // an AccessSemantics
187
- IsSuper : 1
189
+ SWIFT_INLINE_BITFIELD (MemberRefExpr, LookupExpr, 2 ,
190
+ Semantics : 2 // an AccessSemantics
188
191
);
189
192
190
193
SWIFT_INLINE_BITFIELD_FULL (TupleElementExpr, Expr, 32 ,
@@ -210,9 +213,8 @@ class alignas(8) Expr {
210
213
FunctionRefKind : 2
211
214
);
212
215
213
- SWIFT_INLINE_BITFIELD_FULL (SubscriptExpr, Expr , 2 +1 +16 + 1 + 1 ,
216
+ SWIFT_INLINE_BITFIELD_FULL (SubscriptExpr, LookupExpr , 2 +1 +1 + 16 ,
214
217
Semantics : 2 , // an AccessSemantics
215
- IsSuper : 1 ,
216
218
// / Whether the SubscriptExpr also has source locations for the argument
217
219
// / label.
218
220
HasArgLabelLocs : 1 ,
@@ -223,7 +225,7 @@ class alignas(8) Expr {
223
225
NumArgLabels : 16
224
226
);
225
227
226
- SWIFT_INLINE_BITFIELD_FULL (DynamicSubscriptExpr, Expr , 1 +1 +16 ,
228
+ SWIFT_INLINE_BITFIELD_FULL (DynamicSubscriptExpr, DynamicLookupExpr , 1 +1 +16 ,
227
229
// / Whether the DynamicSubscriptExpr also has source locations for the
228
230
// / argument label.
229
231
HasArgLabelLocs : 1 ,
@@ -1489,47 +1491,79 @@ class UnresolvedDeclRefExpr : public Expr {
1489
1491
return E->getKind () == ExprKind::UnresolvedDeclRef;
1490
1492
}
1491
1493
};
1494
+
1495
+ // / LookupExpr - This abstract class represents 'a.b', 'a[]', etc where we
1496
+ // / are referring to a member of a type, such as a property, variable, etc.
1497
+ class LookupExpr : public Expr {
1498
+ Expr *Base;
1499
+ ConcreteDeclRef Member;
1500
+
1501
+ protected:
1502
+ explicit LookupExpr (ExprKind Kind, Expr *base, ConcreteDeclRef member,
1503
+ bool Implicit)
1504
+ : Expr(Kind, Implicit), Base(base), Member(member) {
1505
+ Bits.LookupExpr .IsSuper = false ;
1506
+ assert (Base);
1507
+ }
1508
+
1509
+ public:
1510
+ // / Retrieve the base of the expression.
1511
+ Expr *getBase () const { return Base; }
1512
+
1513
+ // / Replace the base of the expression.
1514
+ void setBase (Expr *E) { Base = E; }
1515
+
1516
+ // / Retrieve the member to which this access refers.
1517
+ ConcreteDeclRef getMember () const { return Member; }
1518
+
1519
+ // / Determine whether the operation has a known underlying declaration or not.
1520
+ bool hasDecl () const { return static_cast <bool >(Member); }
1492
1521
1522
+ // / Retrieve the declaration that this /// operation refers to.
1523
+ // / Only valid when \c hasDecl() is true.
1524
+ ConcreteDeclRef getDecl () const {
1525
+ assert (hasDecl () && " No subscript declaration known!" );
1526
+ return getMember ();
1527
+ }
1528
+
1529
+ // / Determine whether this reference refers to the superclass's property.
1530
+ bool isSuper () const { return Bits.LookupExpr .IsSuper ; }
1531
+
1532
+ // / Set whether this reference refers to the superclass's property.
1533
+ void setIsSuper (bool isSuper) { Bits.LookupExpr .IsSuper = isSuper; }
1534
+
1535
+ static bool classof (const Expr *E) {
1536
+ return E->getKind () >= ExprKind::First_LookupExpr &&
1537
+ E->getKind () <= ExprKind::Last_LookupExpr;
1538
+ }
1539
+ };
1540
+
1493
1541
// / MemberRefExpr - This represents 'a.b' where we are referring to a member
1494
1542
// / of a type, such as a property or variable.
1495
1543
// /
1496
1544
// / Note that methods found via 'dot' syntax are expressed as DotSyntaxCallExpr
1497
1545
// / nodes, because 'a.f' is actually an application of 'a' (the implicit object
1498
1546
// / argument) to the function 'f'.
1499
- class MemberRefExpr : public Expr {
1500
- Expr *Base;
1501
- ConcreteDeclRef Member;
1547
+ class MemberRefExpr : public LookupExpr {
1502
1548
SourceLoc DotLoc;
1503
1549
DeclNameLoc NameLoc;
1504
1550
1505
1551
public:
1506
1552
MemberRefExpr (Expr *base, SourceLoc dotLoc, ConcreteDeclRef member,
1507
1553
DeclNameLoc loc, bool Implicit,
1508
1554
AccessSemantics semantics = AccessSemantics::Ordinary);
1509
- Expr *getBase () const { return Base; }
1510
- ConcreteDeclRef getMember () const { return Member; }
1511
- DeclNameLoc getNameLoc () const { return NameLoc; }
1512
1555
SourceLoc getDotLoc () const { return DotLoc; }
1513
-
1514
- void setBase (Expr *E) { Base = E; }
1556
+ DeclNameLoc getNameLoc () const { return NameLoc; }
1515
1557
1516
1558
// / Return true if this member access is direct, meaning that it
1517
1559
// / does not call the getter or setter.
1518
1560
AccessSemantics getAccessSemantics () const {
1519
1561
return (AccessSemantics) Bits.MemberRefExpr .Semantics ;
1520
1562
}
1521
1563
1522
- // / Determine whether this member reference refers to the
1523
- // / superclass's property.
1524
- bool isSuper () const { return Bits.MemberRefExpr .IsSuper ; }
1525
-
1526
- // / Set whether this member reference refers to the superclass's
1527
- // / property.
1528
- void setIsSuper (bool isSuper) { Bits.MemberRefExpr .IsSuper = isSuper; }
1529
-
1530
1564
SourceLoc getLoc () const { return NameLoc.getBaseNameLoc (); }
1531
1565
SourceLoc getStartLoc () const {
1532
- SourceLoc BaseStartLoc = Base ->getStartLoc ();
1566
+ SourceLoc BaseStartLoc = getBase () ->getStartLoc ();
1533
1567
if (BaseStartLoc.isInvalid () || NameLoc.isInvalid ()) {
1534
1568
return NameLoc.getBaseNameLoc ();
1535
1569
} else {
@@ -1548,24 +1582,12 @@ class MemberRefExpr : public Expr {
1548
1582
// / Common base for expressions that involve dynamic lookup, which
1549
1583
// / determines at runtime whether a particular method, property, or
1550
1584
// / subscript is available.
1551
- class DynamicLookupExpr : public Expr {
1585
+ class DynamicLookupExpr : public LookupExpr {
1552
1586
protected:
1553
- Expr *Base;
1554
- ConcreteDeclRef Member;
1555
-
1556
1587
explicit DynamicLookupExpr (ExprKind kind, ConcreteDeclRef member, Expr *base)
1557
- : Expr (kind, /* Implicit=*/ false ), Base(base), Member(member ) { }
1588
+ : LookupExpr (kind, base, member, /* Implicit=*/ false ) { }
1558
1589
1559
1590
public:
1560
- // / Retrieve the member to which this access refers.
1561
- ConcreteDeclRef getMember () const { return Member; }
1562
-
1563
- // / Retrieve the base of the expression.
1564
- Expr *getBase () const { return Base; }
1565
-
1566
- // / Replace the base of the expression.
1567
- void setBase (Expr *base) { Base = base; }
1568
-
1569
1591
static bool classof (const Expr *E) {
1570
1592
return E->getKind () >= ExprKind::First_DynamicLookupExpr &&
1571
1593
E->getKind () <= ExprKind::Last_DynamicLookupExpr;
@@ -1608,7 +1630,7 @@ class DynamicMemberRefExpr : public DynamicLookupExpr {
1608
1630
SourceLoc getLoc () const { return NameLoc.getBaseNameLoc (); }
1609
1631
1610
1632
SourceLoc getStartLoc () const {
1611
- SourceLoc BaseStartLoc = Base ->getStartLoc ();
1633
+ SourceLoc BaseStartLoc = getBase () ->getStartLoc ();
1612
1634
if (BaseStartLoc.isInvalid () || NameLoc.isInvalid ()) {
1613
1635
return NameLoc.getBaseNameLoc ();
1614
1636
} else {
@@ -1676,12 +1698,6 @@ class DynamicSubscriptExpr final
1676
1698
ConcreteDeclRef decl,
1677
1699
bool implicit);
1678
1700
1679
- // / Retrieve the base of the expression.
1680
- Expr *getBase () const { return Base; }
1681
-
1682
- // / Replace the base of the expression.
1683
- void setBase (Expr *base) { Base = base; }
1684
-
1685
1701
// / getIndex - Retrieve the index of the subscript expression, i.e., the
1686
1702
// / "offset" into the base value.
1687
1703
Expr *getIndex () const { return Index; }
@@ -1702,7 +1718,7 @@ class DynamicSubscriptExpr final
1702
1718
1703
1719
SourceLoc getLoc () const { return Index->getStartLoc (); }
1704
1720
1705
- SourceLoc getStartLoc () const { return Base ->getStartLoc (); }
1721
+ SourceLoc getStartLoc () const { return getBase () ->getStartLoc (); }
1706
1722
SourceLoc getEndLoc () const { return Index->getEndLoc (); }
1707
1723
1708
1724
static bool classof (const Expr *E) {
@@ -2230,12 +2246,10 @@ class DictionaryExpr final : public CollectionExpr,
2230
2246
// / type-checked and well-formed subscript expression refers to a subscript
2231
2247
// / declaration, which provides a getter and (optionally) a setter that will
2232
2248
// / be used to perform reads/writes.
2233
- class SubscriptExpr final : public Expr ,
2249
+ class SubscriptExpr final : public LookupExpr ,
2234
2250
public TrailingCallArguments<SubscriptExpr> {
2235
2251
friend TrailingCallArguments;
2236
2252
2237
- ConcreteDeclRef TheDecl;
2238
- Expr *Base;
2239
2253
Expr *Index;
2240
2254
2241
2255
SubscriptExpr (Expr *base, Expr *index, ArrayRef<Identifier> argLabels,
@@ -2267,11 +2281,6 @@ class SubscriptExpr final : public Expr,
2267
2281
AccessSemantics semantics
2268
2282
= AccessSemantics::Ordinary);
2269
2283
2270
- // / getBase - Retrieve the base of the subscript expression, i.e., the
2271
- // / value being indexed.
2272
- Expr *getBase () const { return Base; }
2273
- void setBase (Expr *E) { Base = E; }
2274
-
2275
2284
// / getIndex - Retrieve the index of the subscript expression, i.e., the
2276
2285
// / "offset" into the base value.
2277
2286
Expr *getIndex () const { return Index; }
@@ -2296,30 +2305,11 @@ class SubscriptExpr final : public Expr,
2296
2305
return (AccessSemantics) Bits.SubscriptExpr .Semantics ;
2297
2306
}
2298
2307
2299
- // / Determine whether this member reference refers to the
2300
- // / superclass's property.
2301
- bool isSuper () const { return Bits.SubscriptExpr .IsSuper ; }
2302
-
2303
- // / Set whether this member reference refers to the superclass's
2304
- // / property.
2305
- void setIsSuper (bool isSuper) { Bits.SubscriptExpr .IsSuper = isSuper; }
2306
-
2307
- // / Determine whether subscript operation has a known underlying
2308
- // / subscript declaration or not.
2309
- bool hasDecl () const { return static_cast <bool >(TheDecl); }
2310
-
2311
- // / Retrieve the subscript declaration that this subscripting
2312
- // / operation refers to. Only valid when \c hasDecl() is true.
2313
- ConcreteDeclRef getDecl () const {
2314
- assert (hasDecl () && " No subscript declaration known!" );
2315
- return TheDecl;
2316
- }
2317
-
2318
2308
SourceLoc getLoc () const { return Index->getStartLoc (); }
2319
- SourceLoc getStartLoc () const { return Base ->getStartLoc (); }
2309
+ SourceLoc getStartLoc () const { return getBase () ->getStartLoc (); }
2320
2310
SourceLoc getEndLoc () const {
2321
2311
auto end = Index->getEndLoc ();
2322
- return end.isValid () ? end : Base ->getEndLoc ();
2312
+ return end.isValid () ? end : getBase () ->getEndLoc ();
2323
2313
}
2324
2314
2325
2315
static bool classof (const Expr *E) {
0 commit comments