20
20
#include " swift/AST/CaptureInfo.h"
21
21
#include " swift/AST/ConcreteDeclRef.h"
22
22
#include " swift/AST/DeclNameLoc.h"
23
+ #include " swift/AST/FunctionRefKind.h"
23
24
#include " swift/AST/ProtocolConformanceRef.h"
24
25
#include " swift/AST/TypeAlignments.h"
25
26
#include " swift/AST/TypeLoc.h"
@@ -53,7 +54,7 @@ namespace swift {
53
54
class PatternBindingDecl ;
54
55
class ParameterList ;
55
56
class EnumElementDecl ;
56
-
57
+
57
58
enum class ExprKind : uint8_t {
58
59
#define EXPR (Id, Parent ) Id,
59
60
#define EXPR_RANGE (Id, FirstId, LastId ) \
@@ -114,7 +115,7 @@ enum class AccessSemantics : unsigned char {
114
115
// / polymorphism is expected.
115
116
Ordinary,
116
117
};
117
-
118
+
118
119
// / Expr - Base class for all expressions in swift.
119
120
class alignas (8 ) Expr {
120
121
Expr (const Expr&) = delete ;
@@ -164,10 +165,21 @@ class alignas(8) Expr {
164
165
friend class DeclRefExpr ;
165
166
unsigned : NumExprBits;
166
167
unsigned Semantics : 2 ; // an AccessSemantics
168
+ unsigned FunctionRefKind : 2 ;
167
169
};
168
- enum { NumDeclRefExprBits = NumExprBits + 2 };
170
+ enum { NumDeclRefExprBits = NumExprBits + 4 };
169
171
static_assert (NumDeclRefExprBits <= 32 , " fits in an unsigned" );
170
172
173
+ class UnresolvedDeclRefExprBitfields {
174
+ friend class UnresolvedDeclRefExpr ;
175
+ unsigned : NumExprBits;
176
+ unsigned DeclRefKind : 2 ;
177
+ unsigned IsSpecialized : 1 ;
178
+ unsigned FunctionRefKind : 2 ;
179
+ };
180
+ enum { NumUnresolvedDeclRefExprBits = NumExprBits + 5 };
181
+ static_assert (NumUnresolvedDeclRefExprBits <= 32 , " fits in an unsigned" );
182
+
171
183
class MemberRefExprBitfields {
172
184
friend class MemberRefExpr ;
173
185
unsigned : NumExprBits;
@@ -193,6 +205,14 @@ class alignas(8) Expr {
193
205
enum { NumTupleExprBits = NumExprBits + 3 };
194
206
static_assert (NumTupleExprBits <= 32 , " fits in an unsigned" );
195
207
208
+ class UnresolvedDotExprBitfields {
209
+ friend class UnresolvedDotExpr ;
210
+ unsigned : NumExprBits;
211
+ unsigned FunctionRefKind : 2 ;
212
+ };
213
+ enum { NumUnresolvedDotExprExprBits = NumExprBits + 2 };
214
+ static_assert (NumUnresolvedDotExprExprBits <= 32 , " fits in an unsigned" );
215
+
196
216
class SubscriptExprBitfields {
197
217
friend class SubscriptExpr ;
198
218
unsigned : NumExprBits;
@@ -242,10 +262,19 @@ class alignas(8) Expr {
242
262
class OverloadSetRefExprBitfields {
243
263
friend class OverloadSetRefExpr ;
244
264
unsigned : NumExprBits;
265
+ unsigned FunctionRefKind : 2 ;
245
266
};
246
- enum { NumOverloadSetRefExprBits = NumExprBits };
267
+ enum { NumOverloadSetRefExprBits = NumExprBits + 2 };
247
268
static_assert (NumOverloadSetRefExprBits <= 32 , " fits in an unsigned" );
248
269
270
+ class OverloadedDeclRefExprBitfields {
271
+ friend class OverloadedDeclRefExpr ;
272
+ unsigned : NumOverloadSetRefExprBits;
273
+ unsigned IsSpecialized : 1 ;
274
+ };
275
+ enum { NumOverloadedDeclRefExprBits = NumOverloadSetRefExprBits + 1 };
276
+ static_assert (NumOverloadedDeclRefExprBits <= 32 , " fits in an unsigned" );
277
+
249
278
class BooleanLiteralExprBitfields {
250
279
friend class BooleanLiteralExpr ;
251
280
unsigned : NumLiteralExprBits;
@@ -398,12 +427,15 @@ class alignas(8) Expr {
398
427
NumberLiteralExprBitfields NumberLiteralExprBits;
399
428
StringLiteralExprBitfields StringLiteralExprBits;
400
429
DeclRefExprBitfields DeclRefExprBits;
430
+ UnresolvedDeclRefExprBitfields UnresolvedDeclRefExprBits;
401
431
TupleExprBitfields TupleExprBits;
402
432
MemberRefExprBitfields MemberRefExprBits;
433
+ UnresolvedDotExprBitfields UnresolvedDotExprBits;
403
434
SubscriptExprBitfields SubscriptExprBits;
404
435
DynamicSubscriptExprBitfields DynamicSubscriptExprBits;
405
436
UnresolvedMemberExprBitfields UnresolvedMemberExprBits;
406
437
OverloadSetRefExprBitfields OverloadSetRefExprBits;
438
+ OverloadedDeclRefExprBitfields OverloadedDeclRefExprBits;
407
439
BooleanLiteralExprBitfields BooleanLiteralExprBits;
408
440
MagicIdentifierLiteralExprBitfields MagicIdentifierLiteralExprBits;
409
441
ObjectLiteralExprBitfields ObjectLiteralExprBits;
@@ -1212,6 +1244,9 @@ class DeclRefExpr : public Expr {
1212
1244
Type Ty = Type())
1213
1245
: Expr(ExprKind::DeclRef, Implicit, Ty), DOrSpecialized(D), Loc(Loc) {
1214
1246
DeclRefExprBits.Semantics = (unsigned ) semantics;
1247
+ DeclRefExprBits.FunctionRefKind =
1248
+ static_cast <unsigned >(Loc.isCompound () ? FunctionRefKind::Compound
1249
+ : FunctionRefKind::Unapplied);
1215
1250
}
1216
1251
1217
1252
// / Retrieve the declaration to which this expression refers.
@@ -1254,6 +1289,16 @@ class DeclRefExpr : public Expr {
1254
1289
SourceLoc getLoc () const { return Loc.getBaseNameLoc (); }
1255
1290
DeclNameLoc getNameLoc () const { return Loc; }
1256
1291
1292
+ // / Retrieve the kind of function reference.
1293
+ FunctionRefKind getFunctionRefKind () const {
1294
+ return static_cast <FunctionRefKind>(DeclRefExprBits.FunctionRefKind );
1295
+ }
1296
+
1297
+ // / Set the kind of function reference.
1298
+ void setFunctionRefKind (FunctionRefKind refKind) {
1299
+ DeclRefExprBits.FunctionRefKind = static_cast <unsigned >(refKind);
1300
+ }
1301
+
1257
1302
static bool classof (const Expr *E) {
1258
1303
return E->getKind () == ExprKind::DeclRef;
1259
1304
}
@@ -1364,9 +1409,12 @@ class OverloadSetRefExpr : public Expr {
1364
1409
ArrayRef<ValueDecl*> Decls;
1365
1410
1366
1411
protected:
1367
- OverloadSetRefExpr (ExprKind Kind, ArrayRef<ValueDecl*> decls, bool Implicit,
1368
- Type Ty)
1369
- : Expr(Kind, Implicit, Ty), Decls(decls) {}
1412
+ OverloadSetRefExpr (ExprKind Kind, ArrayRef<ValueDecl*> decls,
1413
+ FunctionRefKind functionRefKind, bool Implicit, Type Ty)
1414
+ : Expr(Kind, Implicit, Ty), Decls(decls) {
1415
+ OverloadSetRefExprBits.FunctionRefKind =
1416
+ static_cast <unsigned >(functionRefKind);
1417
+ }
1370
1418
1371
1419
public:
1372
1420
ArrayRef<ValueDecl*> getDecls () const { return Decls; }
@@ -1380,6 +1428,17 @@ class OverloadSetRefExpr : public Expr {
1380
1428
// / concrete base object (which is not a metatype).
1381
1429
bool hasBaseObject () const ;
1382
1430
1431
+ // / Retrieve the kind of function reference.
1432
+ FunctionRefKind getFunctionRefKind () const {
1433
+ return static_cast <FunctionRefKind>(
1434
+ OverloadSetRefExprBits.FunctionRefKind );
1435
+ }
1436
+
1437
+ // / Set the kind of function reference.
1438
+ void setFunctionRefKind (FunctionRefKind refKind) {
1439
+ OverloadSetRefExprBits.FunctionRefKind = static_cast <unsigned >(refKind);
1440
+ }
1441
+
1383
1442
static bool classof (const Expr *E) {
1384
1443
return E->getKind () >= ExprKind::First_OverloadSetRefExpr &&
1385
1444
E->getKind () <= ExprKind::Last_OverloadSetRefExpr;
@@ -1388,26 +1447,30 @@ class OverloadSetRefExpr : public Expr {
1388
1447
1389
1448
// / OverloadedDeclRefExpr - A reference to an overloaded name that should
1390
1449
// / eventually be resolved (by overload resolution) to a value reference.
1391
- class OverloadedDeclRefExpr : public OverloadSetRefExpr {
1450
+ class OverloadedDeclRefExpr final : public OverloadSetRefExpr {
1392
1451
DeclNameLoc Loc;
1393
- bool IsSpecialized = false ;
1394
1452
1395
1453
public:
1396
1454
OverloadedDeclRefExpr (ArrayRef<ValueDecl*> Decls, DeclNameLoc Loc,
1455
+ bool isSpecialized,
1456
+ FunctionRefKind functionRefKind,
1397
1457
bool Implicit, Type Ty = Type())
1398
- : OverloadSetRefExpr(ExprKind::OverloadedDeclRef, Decls, Implicit, Ty),
1399
- Loc (Loc) { }
1458
+ : OverloadSetRefExpr(ExprKind::OverloadedDeclRef, Decls, functionRefKind,
1459
+ Implicit, Ty),
1460
+ Loc (Loc) {
1461
+ OverloadedDeclRefExprBits.IsSpecialized = isSpecialized;
1462
+ }
1400
1463
1401
1464
DeclNameLoc getNameLoc () const { return Loc; }
1402
1465
SourceLoc getLoc () const { return Loc.getBaseNameLoc (); }
1403
1466
SourceRange getSourceRange () const { return Loc.getSourceRange (); }
1404
1467
1405
- void setSpecialized (bool specialized) { IsSpecialized = specialized; }
1406
-
1407
1468
// / \brief Determine whether this declaration reference was immediately
1408
1469
// / specialized by <...>.
1409
- bool isSpecialized () const { return IsSpecialized; }
1410
-
1470
+ bool isSpecialized () const {
1471
+ return OverloadedDeclRefExprBits.IsSpecialized ;
1472
+ }
1473
+
1411
1474
static bool classof (const Expr *E) {
1412
1475
return E->getKind () == ExprKind::OverloadedDeclRef;
1413
1476
}
@@ -1421,29 +1484,48 @@ class OverloadedDeclRefExpr : public OverloadSetRefExpr {
1421
1484
class UnresolvedDeclRefExpr : public Expr {
1422
1485
DeclName Name;
1423
1486
DeclNameLoc Loc;
1424
- DeclRefKind RefKind;
1425
- bool IsSpecialized = false ;
1426
1487
1427
1488
public:
1428
1489
UnresolvedDeclRefExpr (DeclName name, DeclRefKind refKind, DeclNameLoc loc)
1429
- : Expr(ExprKind::UnresolvedDeclRef, /* Implicit=*/ loc.isInvalid()),
1430
- Name (name), Loc(loc), RefKind(refKind) {
1490
+ : Expr(ExprKind::UnresolvedDeclRef, /* Implicit=*/ loc.isInvalid()),
1491
+ Name (name), Loc(loc) {
1492
+ UnresolvedDeclRefExprBits.DeclRefKind = static_cast <unsigned >(refKind);
1493
+ UnresolvedDeclRefExprBits.IsSpecialized = false ;
1494
+ UnresolvedDeclRefExprBits.FunctionRefKind =
1495
+ static_cast <unsigned >(Loc.isCompound () ? FunctionRefKind::Compound
1496
+ : FunctionRefKind::Unapplied);
1431
1497
}
1432
1498
1433
1499
bool hasName () const { return static_cast <bool >(Name); }
1434
1500
DeclName getName () const { return Name; }
1435
- DeclRefKind getRefKind () const { return RefKind; }
1436
1501
1437
- void setSpecialized (bool specialized) { IsSpecialized = specialized; }
1502
+ DeclRefKind getRefKind () const {
1503
+ return static_cast <DeclRefKind>(UnresolvedDeclRefExprBits.DeclRefKind );
1504
+ }
1505
+
1506
+ void setSpecialized (bool specialized) {
1507
+ UnresolvedDeclRefExprBits.IsSpecialized = specialized;
1508
+ }
1438
1509
1439
1510
// / \brief Determine whether this declaration reference was immediately
1440
1511
// / specialized by <...>.
1441
- bool isSpecialized () const { return IsSpecialized; }
1512
+ bool isSpecialized () const { return UnresolvedDeclRefExprBits.IsSpecialized ; }
1513
+
1514
+ // / Retrieve the kind of function reference.
1515
+ FunctionRefKind getFunctionRefKind () const {
1516
+ return static_cast <FunctionRefKind>(
1517
+ UnresolvedDeclRefExprBits.FunctionRefKind );
1518
+ }
1519
+
1520
+ // / Set the kind of function reference.
1521
+ void setFunctionRefKind (FunctionRefKind refKind) {
1522
+ UnresolvedDeclRefExprBits.FunctionRefKind = static_cast <unsigned >(refKind);
1523
+ }
1442
1524
1443
1525
DeclNameLoc getNameLoc () const { return Loc; }
1444
1526
1445
1527
SourceRange getSourceRange () const { return Loc.getSourceRange (); }
1446
-
1528
+
1447
1529
static bool classof (const Expr *E) {
1448
1530
return E->getKind () == ExprKind::UnresolvedDeclRef;
1449
1531
}
@@ -2246,8 +2328,12 @@ class UnresolvedDotExpr : public Expr {
2246
2328
public:
2247
2329
UnresolvedDotExpr (Expr *subexpr, SourceLoc dotloc, DeclName name,
2248
2330
DeclNameLoc nameloc, bool Implicit)
2249
- : Expr(ExprKind::UnresolvedDot, Implicit), SubExpr(subexpr), DotLoc(dotloc),
2250
- NameLoc (nameloc), Name(name) {}
2331
+ : Expr(ExprKind::UnresolvedDot, Implicit), SubExpr(subexpr), DotLoc(dotloc),
2332
+ NameLoc (nameloc), Name(name) {
2333
+ UnresolvedDotExprBits.FunctionRefKind =
2334
+ static_cast <unsigned >(NameLoc.isCompound () ? FunctionRefKind::Compound
2335
+ : FunctionRefKind::Unapplied);
2336
+ }
2251
2337
2252
2338
SourceLoc getLoc () const { return NameLoc.getBaseNameLoc (); }
2253
2339
@@ -2266,6 +2352,16 @@ class UnresolvedDotExpr : public Expr {
2266
2352
DeclName getName () const { return Name; }
2267
2353
DeclNameLoc getNameLoc () const { return NameLoc; }
2268
2354
2355
+ // / Retrieve the kind of function reference.
2356
+ FunctionRefKind getFunctionRefKind () const {
2357
+ return static_cast <FunctionRefKind>(UnresolvedDotExprBits.FunctionRefKind );
2358
+ }
2359
+
2360
+ // / Set the kind of function reference.
2361
+ void setFunctionRefKind (FunctionRefKind refKind) {
2362
+ UnresolvedDotExprBits.FunctionRefKind = static_cast <unsigned >(refKind);
2363
+ }
2364
+
2269
2365
static bool classof (const Expr *E) {
2270
2366
return E->getKind () == ExprKind::UnresolvedDot;
2271
2367
}
0 commit comments