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;
@@ -193,6 +205,14 @@ class alignas(8) Expr {
193205 enum { NumTupleExprBits = NumExprBits + 3 };
194206 static_assert (NumTupleExprBits <= 32 , " fits in an unsigned" );
195207
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+
196216 class SubscriptExprBitfields {
197217 friend class SubscriptExpr ;
198218 unsigned : NumExprBits;
@@ -242,10 +262,19 @@ class alignas(8) Expr {
242262 class OverloadSetRefExprBitfields {
243263 friend class OverloadSetRefExpr ;
244264 unsigned : NumExprBits;
265+ unsigned FunctionRefKind : 2 ;
245266 };
246- enum { NumOverloadSetRefExprBits = NumExprBits };
267+ enum { NumOverloadSetRefExprBits = NumExprBits + 2 };
247268 static_assert (NumOverloadSetRefExprBits <= 32 , " fits in an unsigned" );
248269
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+
249278 class BooleanLiteralExprBitfields {
250279 friend class BooleanLiteralExpr ;
251280 unsigned : NumLiteralExprBits;
@@ -398,12 +427,15 @@ class alignas(8) Expr {
398427 NumberLiteralExprBitfields NumberLiteralExprBits;
399428 StringLiteralExprBitfields StringLiteralExprBits;
400429 DeclRefExprBitfields DeclRefExprBits;
430+ UnresolvedDeclRefExprBitfields UnresolvedDeclRefExprBits;
401431 TupleExprBitfields TupleExprBits;
402432 MemberRefExprBitfields MemberRefExprBits;
433+ UnresolvedDotExprBitfields UnresolvedDotExprBits;
403434 SubscriptExprBitfields SubscriptExprBits;
404435 DynamicSubscriptExprBitfields DynamicSubscriptExprBits;
405436 UnresolvedMemberExprBitfields UnresolvedMemberExprBits;
406437 OverloadSetRefExprBitfields OverloadSetRefExprBits;
438+ OverloadedDeclRefExprBitfields OverloadedDeclRefExprBits;
407439 BooleanLiteralExprBitfields BooleanLiteralExprBits;
408440 MagicIdentifierLiteralExprBitfields MagicIdentifierLiteralExprBits;
409441 ObjectLiteralExprBitfields ObjectLiteralExprBits;
@@ -1212,6 +1244,9 @@ class DeclRefExpr : public Expr {
12121244 Type Ty = Type())
12131245 : Expr(ExprKind::DeclRef, Implicit, Ty), DOrSpecialized(D), Loc(Loc) {
12141246 DeclRefExprBits.Semantics = (unsigned ) semantics;
1247+ DeclRefExprBits.FunctionRefKind =
1248+ static_cast <unsigned >(Loc.isCompound () ? FunctionRefKind::Compound
1249+ : FunctionRefKind::Unapplied);
12151250 }
12161251
12171252 // / Retrieve the declaration to which this expression refers.
@@ -1254,6 +1289,16 @@ class DeclRefExpr : public Expr {
12541289 SourceLoc getLoc () const { return Loc.getBaseNameLoc (); }
12551290 DeclNameLoc getNameLoc () const { return Loc; }
12561291
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+
12571302 static bool classof (const Expr *E) {
12581303 return E->getKind () == ExprKind::DeclRef;
12591304 }
@@ -1364,9 +1409,12 @@ class OverloadSetRefExpr : public Expr {
13641409 ArrayRef<ValueDecl*> Decls;
13651410
13661411protected:
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+ }
13701418
13711419public:
13721420 ArrayRef<ValueDecl*> getDecls () const { return Decls; }
@@ -1380,6 +1428,17 @@ class OverloadSetRefExpr : public Expr {
13801428 // / concrete base object (which is not a metatype).
13811429 bool hasBaseObject () const ;
13821430
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+
13831442 static bool classof (const Expr *E) {
13841443 return E->getKind () >= ExprKind::First_OverloadSetRefExpr &&
13851444 E->getKind () <= ExprKind::Last_OverloadSetRefExpr;
@@ -1388,26 +1447,30 @@ class OverloadSetRefExpr : public Expr {
13881447
13891448// / OverloadedDeclRefExpr - A reference to an overloaded name that should
13901449// / eventually be resolved (by overload resolution) to a value reference.
1391- class OverloadedDeclRefExpr : public OverloadSetRefExpr {
1450+ class OverloadedDeclRefExpr final : public OverloadSetRefExpr {
13921451 DeclNameLoc Loc;
1393- bool IsSpecialized = false ;
13941452
13951453public:
13961454 OverloadedDeclRefExpr (ArrayRef<ValueDecl*> Decls, DeclNameLoc Loc,
1455+ bool isSpecialized,
1456+ FunctionRefKind functionRefKind,
13971457 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+ }
14001463
14011464 DeclNameLoc getNameLoc () const { return Loc; }
14021465 SourceLoc getLoc () const { return Loc.getBaseNameLoc (); }
14031466 SourceRange getSourceRange () const { return Loc.getSourceRange (); }
14041467
1405- void setSpecialized (bool specialized) { IsSpecialized = specialized; }
1406-
14071468 // / \brief Determine whether this declaration reference was immediately
14081469 // / specialized by <...>.
1409- bool isSpecialized () const { return IsSpecialized; }
1410-
1470+ bool isSpecialized () const {
1471+ return OverloadedDeclRefExprBits.IsSpecialized ;
1472+ }
1473+
14111474 static bool classof (const Expr *E) {
14121475 return E->getKind () == ExprKind::OverloadedDeclRef;
14131476 }
@@ -1421,29 +1484,48 @@ class OverloadedDeclRefExpr : public OverloadSetRefExpr {
14211484class UnresolvedDeclRefExpr : public Expr {
14221485 DeclName Name;
14231486 DeclNameLoc Loc;
1424- DeclRefKind RefKind;
1425- bool IsSpecialized = false ;
14261487
14271488public:
14281489 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);
14311497 }
14321498
14331499 bool hasName () const { return static_cast <bool >(Name); }
14341500 DeclName getName () const { return Name; }
1435- DeclRefKind getRefKind () const { return RefKind; }
14361501
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+ }
14381509
14391510 // / \brief Determine whether this declaration reference was immediately
14401511 // / 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+ }
14421524
14431525 DeclNameLoc getNameLoc () const { return Loc; }
14441526
14451527 SourceRange getSourceRange () const { return Loc.getSourceRange (); }
1446-
1528+
14471529 static bool classof (const Expr *E) {
14481530 return E->getKind () == ExprKind::UnresolvedDeclRef;
14491531 }
@@ -2246,8 +2328,12 @@ class UnresolvedDotExpr : public Expr {
22462328public:
22472329 UnresolvedDotExpr (Expr *subexpr, SourceLoc dotloc, DeclName name,
22482330 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+ }
22512337
22522338 SourceLoc getLoc () const { return NameLoc.getBaseNameLoc (); }
22532339
@@ -2266,6 +2352,16 @@ class UnresolvedDotExpr : public Expr {
22662352 DeclName getName () const { return Name; }
22672353 DeclNameLoc getNameLoc () const { return NameLoc; }
22682354
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+
22692365 static bool classof (const Expr *E) {
22702366 return E->getKind () == ExprKind::UnresolvedDot;
22712367 }
0 commit comments