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;
@@ -246,6 +258,15 @@ class alignas(8) Expr {
246
258
enum { NumOverloadSetRefExprBits = NumExprBits };
247
259
static_assert (NumOverloadSetRefExprBits <= 32 , " fits in an unsigned" );
248
260
261
+ class OverloadedDeclRefExprBitfields {
262
+ friend class OverloadedDeclRefExpr ;
263
+ unsigned : NumOverloadSetRefExprBits;
264
+ unsigned IsSpecialized : 1 ;
265
+ unsigned FunctionRefKind : 2 ;
266
+ };
267
+ enum { NumOverloadedDeclRefExprBits = NumOverloadSetRefExprBits + 3 };
268
+ static_assert (NumOverloadedDeclRefExprBits <= 32 , " fits in an unsigned" );
269
+
249
270
class BooleanLiteralExprBitfields {
250
271
friend class BooleanLiteralExpr ;
251
272
unsigned : NumLiteralExprBits;
@@ -398,12 +419,14 @@ class alignas(8) Expr {
398
419
NumberLiteralExprBitfields NumberLiteralExprBits;
399
420
StringLiteralExprBitfields StringLiteralExprBits;
400
421
DeclRefExprBitfields DeclRefExprBits;
422
+ UnresolvedDeclRefExprBitfields UnresolvedDeclRefExprBits;
401
423
TupleExprBitfields TupleExprBits;
402
424
MemberRefExprBitfields MemberRefExprBits;
403
425
SubscriptExprBitfields SubscriptExprBits;
404
426
DynamicSubscriptExprBitfields DynamicSubscriptExprBits;
405
427
UnresolvedMemberExprBitfields UnresolvedMemberExprBits;
406
428
OverloadSetRefExprBitfields OverloadSetRefExprBits;
429
+ OverloadedDeclRefExprBitfields OverloadedDeclRefExprBits;
407
430
BooleanLiteralExprBitfields BooleanLiteralExprBits;
408
431
MagicIdentifierLiteralExprBitfields MagicIdentifierLiteralExprBits;
409
432
ObjectLiteralExprBitfields ObjectLiteralExprBits;
@@ -1212,6 +1235,9 @@ class DeclRefExpr : public Expr {
1212
1235
Type Ty = Type())
1213
1236
: Expr(ExprKind::DeclRef, Implicit, Ty), DOrSpecialized(D), Loc(Loc) {
1214
1237
DeclRefExprBits.Semantics = (unsigned ) semantics;
1238
+ DeclRefExprBits.FunctionRefKind =
1239
+ static_cast <unsigned >(Loc.isCompound () ? FunctionRefKind::Compound
1240
+ : FunctionRefKind::Unapplied);
1215
1241
}
1216
1242
1217
1243
// / Retrieve the declaration to which this expression refers.
@@ -1254,6 +1280,16 @@ class DeclRefExpr : public Expr {
1254
1280
SourceLoc getLoc () const { return Loc.getBaseNameLoc (); }
1255
1281
DeclNameLoc getNameLoc () const { return Loc; }
1256
1282
1283
+ // / Retrieve the kind of function reference.
1284
+ FunctionRefKind getFunctionRefKind () const {
1285
+ return static_cast <FunctionRefKind>(DeclRefExprBits.FunctionRefKind );
1286
+ }
1287
+
1288
+ // / Set the kind of function reference.
1289
+ void setFunctionRefKind (FunctionRefKind refKind) {
1290
+ DeclRefExprBits.FunctionRefKind = static_cast <unsigned >(refKind);
1291
+ }
1292
+
1257
1293
static bool classof (const Expr *E) {
1258
1294
return E->getKind () == ExprKind::DeclRef;
1259
1295
}
@@ -1388,26 +1424,42 @@ class OverloadSetRefExpr : public Expr {
1388
1424
1389
1425
// / OverloadedDeclRefExpr - A reference to an overloaded name that should
1390
1426
// / eventually be resolved (by overload resolution) to a value reference.
1391
- class OverloadedDeclRefExpr : public OverloadSetRefExpr {
1427
+ class OverloadedDeclRefExpr final : public OverloadSetRefExpr {
1392
1428
DeclNameLoc Loc;
1393
- bool IsSpecialized = false ;
1394
1429
1395
1430
public:
1396
1431
OverloadedDeclRefExpr (ArrayRef<ValueDecl*> Decls, DeclNameLoc Loc,
1432
+ bool isSpecialized,
1433
+ FunctionRefKind functionRefKind,
1397
1434
bool Implicit, Type Ty = Type())
1398
- : OverloadSetRefExpr(ExprKind::OverloadedDeclRef, Decls, Implicit, Ty),
1399
- Loc (Loc) { }
1435
+ : OverloadSetRefExpr(ExprKind::OverloadedDeclRef, Decls, Implicit, Ty),
1436
+ Loc (Loc) {
1437
+ OverloadedDeclRefExprBits.IsSpecialized = isSpecialized;
1438
+ OverloadedDeclRefExprBits.FunctionRefKind =
1439
+ static_cast <unsigned >(functionRefKind);
1440
+ }
1400
1441
1401
1442
DeclNameLoc getNameLoc () const { return Loc; }
1402
1443
SourceLoc getLoc () const { return Loc.getBaseNameLoc (); }
1403
1444
SourceRange getSourceRange () const { return Loc.getSourceRange (); }
1404
1445
1405
- void setSpecialized (bool specialized) { IsSpecialized = specialized; }
1406
-
1407
1446
// / \brief Determine whether this declaration reference was immediately
1408
1447
// / specialized by <...>.
1409
- bool isSpecialized () const { return IsSpecialized; }
1410
-
1448
+ bool isSpecialized () const {
1449
+ return OverloadedDeclRefExprBits.IsSpecialized ;
1450
+ }
1451
+
1452
+ // / Retrieve the kind of function reference.
1453
+ FunctionRefKind getFunctionRefKind () const {
1454
+ return static_cast <FunctionRefKind>(
1455
+ OverloadedDeclRefExprBits.FunctionRefKind );
1456
+ }
1457
+
1458
+ // / Set the kind of function reference.
1459
+ void setFunctionRefKind (FunctionRefKind refKind) {
1460
+ OverloadedDeclRefExprBits.FunctionRefKind = static_cast <unsigned >(refKind);
1461
+ }
1462
+
1411
1463
static bool classof (const Expr *E) {
1412
1464
return E->getKind () == ExprKind::OverloadedDeclRef;
1413
1465
}
@@ -1421,29 +1473,48 @@ class OverloadedDeclRefExpr : public OverloadSetRefExpr {
1421
1473
class UnresolvedDeclRefExpr : public Expr {
1422
1474
DeclName Name;
1423
1475
DeclNameLoc Loc;
1424
- DeclRefKind RefKind;
1425
- bool IsSpecialized = false ;
1426
1476
1427
1477
public:
1428
1478
UnresolvedDeclRefExpr (DeclName name, DeclRefKind refKind, DeclNameLoc loc)
1429
- : Expr(ExprKind::UnresolvedDeclRef, /* Implicit=*/ loc.isInvalid()),
1430
- Name (name), Loc(loc), RefKind(refKind) {
1479
+ : Expr(ExprKind::UnresolvedDeclRef, /* Implicit=*/ loc.isInvalid()),
1480
+ Name (name), Loc(loc) {
1481
+ UnresolvedDeclRefExprBits.DeclRefKind = static_cast <unsigned >(refKind);
1482
+ UnresolvedDeclRefExprBits.IsSpecialized = false ;
1483
+ UnresolvedDeclRefExprBits.FunctionRefKind =
1484
+ static_cast <unsigned >(Loc.isCompound () ? FunctionRefKind::Compound
1485
+ : FunctionRefKind::Unapplied);
1431
1486
}
1432
1487
1433
1488
bool hasName () const { return static_cast <bool >(Name); }
1434
1489
DeclName getName () const { return Name; }
1435
- DeclRefKind getRefKind () const { return RefKind; }
1436
1490
1437
- void setSpecialized (bool specialized) { IsSpecialized = specialized; }
1491
+ DeclRefKind getRefKind () const {
1492
+ return static_cast <DeclRefKind>(UnresolvedDeclRefExprBits.DeclRefKind );
1493
+ }
1494
+
1495
+ void setSpecialized (bool specialized) {
1496
+ UnresolvedDeclRefExprBits.IsSpecialized = specialized;
1497
+ }
1438
1498
1439
1499
// / \brief Determine whether this declaration reference was immediately
1440
1500
// / specialized by <...>.
1441
- bool isSpecialized () const { return IsSpecialized; }
1501
+ bool isSpecialized () const { return UnresolvedDeclRefExprBits.IsSpecialized ; }
1502
+
1503
+ // / Retrieve the kind of function reference.
1504
+ FunctionRefKind getFunctionRefKind () const {
1505
+ return static_cast <FunctionRefKind>(
1506
+ UnresolvedDeclRefExprBits.FunctionRefKind );
1507
+ }
1508
+
1509
+ // / Set the kind of function reference.
1510
+ void setFunctionRefKind (FunctionRefKind refKind) {
1511
+ UnresolvedDeclRefExprBits.FunctionRefKind = static_cast <unsigned >(refKind);
1512
+ }
1442
1513
1443
1514
DeclNameLoc getNameLoc () const { return Loc; }
1444
1515
1445
1516
SourceRange getSourceRange () const { return Loc.getSourceRange (); }
1446
-
1517
+
1447
1518
static bool classof (const Expr *E) {
1448
1519
return E->getKind () == ExprKind::UnresolvedDeclRef;
1449
1520
}
0 commit comments