2020#include " swift/AST/CaptureInfo.h"
2121#include " swift/AST/ConcreteDeclRef.h"
2222#include " swift/AST/DeclNameLoc.h"
23+ #include " swift/AST/FunctionRefKind.h"
2324#include " swift/AST/ProtocolConformanceRef.h"
2425#include " swift/AST/TypeAlignments.h"
2526#include " swift/AST/TypeLoc.h"
@@ -53,7 +54,7 @@ namespace swift {
5354 class PatternBindingDecl ;
5455 class ParameterList ;
5556 class EnumElementDecl ;
56-
57+
5758enum class ExprKind : uint8_t {
5859#define EXPR (Id, Parent ) Id,
5960#define EXPR_RANGE (Id, FirstId, LastId ) \
@@ -114,7 +115,7 @@ enum class AccessSemantics : unsigned char {
114115 // / polymorphism is expected.
115116 Ordinary,
116117};
117-
118+
118119// / Expr - Base class for all expressions in swift.
119120class alignas (8 ) Expr {
120121 Expr (const Expr&) = delete ;
@@ -164,10 +165,21 @@ class alignas(8) Expr {
164165 friend class DeclRefExpr ;
165166 unsigned : NumExprBits;
166167 unsigned Semantics : 2 ; // an AccessSemantics
168+ unsigned FunctionRefKind : 2 ;
167169 };
168- enum { NumDeclRefExprBits = NumExprBits + 2 };
170+ enum { NumDeclRefExprBits = NumExprBits + 4 };
169171 static_assert (NumDeclRefExprBits <= 32 , " fits in an unsigned" );
170172
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+
171183 class MemberRefExprBitfields {
172184 friend class MemberRefExpr ;
173185 unsigned : NumExprBits;
@@ -246,6 +258,15 @@ class alignas(8) Expr {
246258 enum { NumOverloadSetRefExprBits = NumExprBits };
247259 static_assert (NumOverloadSetRefExprBits <= 32 , " fits in an unsigned" );
248260
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+
249270 class BooleanLiteralExprBitfields {
250271 friend class BooleanLiteralExpr ;
251272 unsigned : NumLiteralExprBits;
@@ -398,12 +419,14 @@ class alignas(8) Expr {
398419 NumberLiteralExprBitfields NumberLiteralExprBits;
399420 StringLiteralExprBitfields StringLiteralExprBits;
400421 DeclRefExprBitfields DeclRefExprBits;
422+ UnresolvedDeclRefExprBitfields UnresolvedDeclRefExprBits;
401423 TupleExprBitfields TupleExprBits;
402424 MemberRefExprBitfields MemberRefExprBits;
403425 SubscriptExprBitfields SubscriptExprBits;
404426 DynamicSubscriptExprBitfields DynamicSubscriptExprBits;
405427 UnresolvedMemberExprBitfields UnresolvedMemberExprBits;
406428 OverloadSetRefExprBitfields OverloadSetRefExprBits;
429+ OverloadedDeclRefExprBitfields OverloadedDeclRefExprBits;
407430 BooleanLiteralExprBitfields BooleanLiteralExprBits;
408431 MagicIdentifierLiteralExprBitfields MagicIdentifierLiteralExprBits;
409432 ObjectLiteralExprBitfields ObjectLiteralExprBits;
@@ -1212,6 +1235,9 @@ class DeclRefExpr : public Expr {
12121235 Type Ty = Type())
12131236 : Expr(ExprKind::DeclRef, Implicit, Ty), DOrSpecialized(D), Loc(Loc) {
12141237 DeclRefExprBits.Semantics = (unsigned ) semantics;
1238+ DeclRefExprBits.FunctionRefKind =
1239+ static_cast <unsigned >(Loc.isCompound () ? FunctionRefKind::Compound
1240+ : FunctionRefKind::Unapplied);
12151241 }
12161242
12171243 // / Retrieve the declaration to which this expression refers.
@@ -1254,6 +1280,16 @@ class DeclRefExpr : public Expr {
12541280 SourceLoc getLoc () const { return Loc.getBaseNameLoc (); }
12551281 DeclNameLoc getNameLoc () const { return Loc; }
12561282
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+
12571293 static bool classof (const Expr *E) {
12581294 return E->getKind () == ExprKind::DeclRef;
12591295 }
@@ -1388,26 +1424,42 @@ class OverloadSetRefExpr : public Expr {
13881424
13891425// / OverloadedDeclRefExpr - A reference to an overloaded name that should
13901426// / eventually be resolved (by overload resolution) to a value reference.
1391- class OverloadedDeclRefExpr : public OverloadSetRefExpr {
1427+ class OverloadedDeclRefExpr final : public OverloadSetRefExpr {
13921428 DeclNameLoc Loc;
1393- bool IsSpecialized = false ;
13941429
13951430public:
13961431 OverloadedDeclRefExpr (ArrayRef<ValueDecl*> Decls, DeclNameLoc Loc,
1432+ bool isSpecialized,
1433+ FunctionRefKind functionRefKind,
13971434 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+ }
14001441
14011442 DeclNameLoc getNameLoc () const { return Loc; }
14021443 SourceLoc getLoc () const { return Loc.getBaseNameLoc (); }
14031444 SourceRange getSourceRange () const { return Loc.getSourceRange (); }
14041445
1405- void setSpecialized (bool specialized) { IsSpecialized = specialized; }
1406-
14071446 // / \brief Determine whether this declaration reference was immediately
14081447 // / 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+
14111463 static bool classof (const Expr *E) {
14121464 return E->getKind () == ExprKind::OverloadedDeclRef;
14131465 }
@@ -1421,29 +1473,48 @@ class OverloadedDeclRefExpr : public OverloadSetRefExpr {
14211473class UnresolvedDeclRefExpr : public Expr {
14221474 DeclName Name;
14231475 DeclNameLoc Loc;
1424- DeclRefKind RefKind;
1425- bool IsSpecialized = false ;
14261476
14271477public:
14281478 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);
14311486 }
14321487
14331488 bool hasName () const { return static_cast <bool >(Name); }
14341489 DeclName getName () const { return Name; }
1435- DeclRefKind getRefKind () const { return RefKind; }
14361490
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+ }
14381498
14391499 // / \brief Determine whether this declaration reference was immediately
14401500 // / 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+ }
14421513
14431514 DeclNameLoc getNameLoc () const { return Loc; }
14441515
14451516 SourceRange getSourceRange () const { return Loc.getSourceRange (); }
1446-
1517+
14471518 static bool classof (const Expr *E) {
14481519 return E->getKind () == ExprKind::UnresolvedDeclRef;
14491520 }
0 commit comments