@@ -613,20 +613,65 @@ class CodeCompletionExpr : public Expr {
613
613
614
614
// / LiteralExpr - Common base class between the literals.
615
615
class LiteralExpr : public Expr {
616
+ // Set by Sema:
617
+ ConcreteDeclRef Initializer;
618
+
616
619
public:
617
620
LiteralExpr (ExprKind Kind, bool Implicit) : Expr(Kind, Implicit) {}
618
621
619
622
static bool classof (const Expr *E) {
620
623
return E->getKind () >= ExprKind::First_LiteralExpr &&
621
624
E->getKind () <= ExprKind::Last_LiteralExpr;
622
625
}
626
+
627
+ // / Retrieve the initializer that will be used to construct the
628
+ // / literal from the result of the initializer.
629
+ // /
630
+ // / Only literals that have no builtin literal conformance will have
631
+ // / this initializer, which will be called on the result of the builtin
632
+ // / initializer.
633
+ ConcreteDeclRef getInitializer () const { return Initializer; }
634
+
635
+ // / Set the initializer that will be used to construct the literal.
636
+ void setInitializer (ConcreteDeclRef initializer) {
637
+ Initializer = initializer;
638
+ }
639
+ };
640
+
641
+ // / BuiltinLiteralExpr - Common base class between all literals
642
+ // / that provides BuiltinInitializer
643
+ class BuiltinLiteralExpr : public LiteralExpr {
644
+ // Set by Seam:
645
+ ConcreteDeclRef BuiltinInitializer;
646
+
647
+ public:
648
+ BuiltinLiteralExpr (ExprKind Kind, bool Implicit)
649
+ : LiteralExpr(Kind, Implicit) {}
650
+
651
+ static bool classof (const Expr *E) {
652
+ return E->getKind () >= ExprKind::First_BuiltinLiteralExpr &&
653
+ E->getKind () <= ExprKind::Last_BuiltinLiteralExpr;
654
+ }
655
+
656
+ // / Retrieve the builtin initializer that will be used to construct the
657
+ // / literal.
658
+ // /
659
+ // / Any type-checked literal will have a builtin initializer, which is
660
+ // / called first to form a concrete Swift type.
661
+ ConcreteDeclRef getBuiltinInitializer () const { return BuiltinInitializer; }
662
+
663
+ // / Set the builtin initializer that will be used to construct the
664
+ // / literal.
665
+ void setBuiltinInitializer (ConcreteDeclRef builtinInitializer) {
666
+ BuiltinInitializer = builtinInitializer;
667
+ }
623
668
};
624
669
625
670
// / The 'nil' literal.
626
671
// /
627
672
class NilLiteralExpr : public LiteralExpr {
628
673
SourceLoc Loc;
629
- ConcreteDeclRef Initializer;
674
+
630
675
public:
631
676
NilLiteralExpr (SourceLoc Loc, bool Implicit = false )
632
677
: LiteralExpr(ExprKind::NilLiteral, Implicit), Loc(Loc) {
@@ -635,42 +680,30 @@ class NilLiteralExpr : public LiteralExpr {
635
680
SourceRange getSourceRange () const {
636
681
return Loc;
637
682
}
638
-
639
- // / Retrieve the initializer that will be used to construct the 'nil'
640
- // / literal from the result of the initializer.
641
- ConcreteDeclRef getInitializer () const { return Initializer; }
642
-
643
- // / Set the initializer that will be used to construct the 'nil' literal.
644
- void setInitializer (ConcreteDeclRef initializer) {
645
- Initializer = initializer;
646
- }
647
683
648
684
static bool classof (const Expr *E) {
649
685
return E->getKind () == ExprKind::NilLiteral;
650
686
}
651
687
};
652
688
653
689
// / Abstract base class for numeric literals, potentially with a sign.
654
- class NumberLiteralExpr : public LiteralExpr {
690
+ class NumberLiteralExpr : public BuiltinLiteralExpr {
655
691
// / The value of the literal as an ASTContext-owned string. Underscores must
656
692
// / be stripped.
657
693
StringRef Val; // Use StringRef instead of APInt or APFloat, which leak.
658
- ConcreteDeclRef BuiltinInitializer;
659
- ConcreteDeclRef Initializer;
660
694
661
695
protected:
662
696
SourceLoc MinusLoc;
663
697
SourceLoc DigitsLoc;
664
698
665
699
public:
666
- NumberLiteralExpr (ExprKind Kind,
667
- StringRef Val, SourceLoc DigitsLoc, bool Implicit)
668
- : LiteralExpr(Kind, Implicit), Val(Val), DigitsLoc(DigitsLoc)
669
- {
670
- Bits.NumberLiteralExpr .IsNegative = false ;
671
- Bits.NumberLiteralExpr .IsExplicitConversion = false ;
672
- }
673
-
700
+ NumberLiteralExpr (ExprKind Kind, StringRef Val, SourceLoc DigitsLoc,
701
+ bool Implicit)
702
+ : BuiltinLiteralExpr(Kind, Implicit), Val(Val), DigitsLoc(DigitsLoc) {
703
+ Bits.NumberLiteralExpr .IsNegative = false ;
704
+ Bits.NumberLiteralExpr .IsExplicitConversion = false ;
705
+ }
706
+
674
707
bool isNegative () const { return Bits.NumberLiteralExpr .IsNegative ; }
675
708
void setNegative (SourceLoc Loc) {
676
709
MinusLoc = Loc;
@@ -701,32 +734,6 @@ class NumberLiteralExpr : public LiteralExpr {
701
734
return DigitsLoc;
702
735
}
703
736
704
- // / Retrieve the builtin initializer that will be used to construct the
705
- // / boolean literal.
706
- // /
707
- // / Any type-checked boolean literal will have a builtin initializer, which is
708
- // / called first to form a concrete Swift type.
709
- ConcreteDeclRef getBuiltinInitializer () const { return BuiltinInitializer; }
710
-
711
- // / Set the builtin initializer that will be used to construct the boolean
712
- // / literal.
713
- void setBuiltinInitializer (ConcreteDeclRef builtinInitializer) {
714
- BuiltinInitializer = builtinInitializer;
715
- }
716
-
717
- // / Retrieve the initializer that will be used to construct the boolean
718
- // / literal from the result of the initializer.
719
- // /
720
- // / Only boolean literals that have no builtin literal conformance will have
721
- // / this initializer, which will be called on the result of the builtin
722
- // / initializer.
723
- ConcreteDeclRef getInitializer () const { return Initializer; }
724
-
725
- // / Set the initializer that will be used to construct the boolean literal.
726
- void setInitializer (ConcreteDeclRef initializer) {
727
- Initializer = initializer;
728
- }
729
-
730
737
static bool classof (const Expr *E) {
731
738
return E->getKind () >= ExprKind::First_NumberLiteralExpr
732
739
&& E->getKind () <= ExprKind::Last_NumberLiteralExpr;
@@ -790,14 +797,12 @@ class FloatLiteralExpr : public NumberLiteralExpr {
790
797
791
798
// / A Boolean literal ('true' or 'false')
792
799
// /
793
- class BooleanLiteralExpr : public LiteralExpr {
800
+ class BooleanLiteralExpr : public BuiltinLiteralExpr {
794
801
SourceLoc Loc;
795
- ConcreteDeclRef BuiltinInitializer;
796
- ConcreteDeclRef Initializer;
797
802
798
803
public:
799
804
BooleanLiteralExpr (bool Value, SourceLoc Loc, bool Implicit = false )
800
- : LiteralExpr (ExprKind::BooleanLiteral, Implicit), Loc(Loc) {
805
+ : BuiltinLiteralExpr (ExprKind::BooleanLiteral, Implicit), Loc(Loc) {
801
806
Bits.BooleanLiteralExpr .Value = Value;
802
807
}
803
808
@@ -808,43 +813,15 @@ class BooleanLiteralExpr : public LiteralExpr {
808
813
return Loc;
809
814
}
810
815
811
- // / Retrieve the builtin initializer that will be used to construct the
812
- // / boolean literal.
813
- // /
814
- // / Any type-checked boolean literal will have a builtin initializer, which is
815
- // / called first to form a concrete Swift type.
816
- ConcreteDeclRef getBuiltinInitializer () const { return BuiltinInitializer; }
817
-
818
- // / Set the builtin initializer that will be used to construct the boolean
819
- // / literal.
820
- void setBuiltinInitializer (ConcreteDeclRef builtinInitializer) {
821
- BuiltinInitializer = builtinInitializer;
822
- }
823
-
824
- // / Retrieve the initializer that will be used to construct the boolean
825
- // / literal from the result of the initializer.
826
- // /
827
- // / Only boolean literals that have no builtin literal conformance will have
828
- // / this initializer, which will be called on the result of the builtin
829
- // / initializer.
830
- ConcreteDeclRef getInitializer () const { return Initializer; }
831
-
832
- // / Set the initializer that will be used to construct the boolean literal.
833
- void setInitializer (ConcreteDeclRef initializer) {
834
- Initializer = initializer;
835
- }
836
-
837
816
static bool classof (const Expr *E) {
838
817
return E->getKind () == ExprKind::BooleanLiteral;
839
818
}
840
819
};
841
-
820
+
842
821
// / StringLiteralExpr - String literal, like '"foo"'.
843
- class StringLiteralExpr : public LiteralExpr {
822
+ class StringLiteralExpr : public BuiltinLiteralExpr {
844
823
StringRef Val;
845
824
SourceRange Range;
846
- ConcreteDeclRef BuiltinInitializer;
847
- ConcreteDeclRef Initializer;
848
825
849
826
public:
850
827
// / The encoding that should be used for the string literal.
@@ -879,32 +856,6 @@ class StringLiteralExpr : public LiteralExpr {
879
856
return Bits.StringLiteralExpr .IsSingleExtendedGraphemeCluster ;
880
857
}
881
858
882
- // / Retrieve the builtin initializer that will be used to construct the string
883
- // / literal.
884
- // /
885
- // / Any type-checked string literal will have a builtin initializer, which is
886
- // / called first to form a concrete Swift type.
887
- ConcreteDeclRef getBuiltinInitializer () const { return BuiltinInitializer; }
888
-
889
- // / Set the builtin initializer that will be used to construct the string
890
- // / literal.
891
- void setBuiltinInitializer (ConcreteDeclRef builtinInitializer) {
892
- BuiltinInitializer = builtinInitializer;
893
- }
894
-
895
- // / Retrieve the initializer that will be used to construct the string
896
- // / literal from the result of the initializer.
897
- // /
898
- // / Only string literals that have no builtin literal conformance will have
899
- // / this initializer, which will be called on the result of the builtin
900
- // / initializer.
901
- ConcreteDeclRef getInitializer () const { return Initializer; }
902
-
903
- // / Set the initializer that will be used to construct the string literal.
904
- void setInitializer (ConcreteDeclRef initializer) {
905
- Initializer = initializer;
906
- }
907
-
908
859
static bool classof (const Expr *E) {
909
860
return E->getKind () == ExprKind::StringLiteral;
910
861
}
@@ -973,7 +924,6 @@ class InterpolatedStringLiteralExpr : public LiteralExpr {
973
924
// Set by Sema:
974
925
OpaqueValueExpr *interpolationExpr = nullptr ;
975
926
ConcreteDeclRef builderInit;
976
- ConcreteDeclRef resultInit;
977
927
Expr *interpolationCountExpr = nullptr ;
978
928
Expr *literalCapacityExpr = nullptr ;
979
929
@@ -995,11 +945,6 @@ class InterpolatedStringLiteralExpr : public LiteralExpr {
995
945
void setBuilderInit (ConcreteDeclRef decl) { builderInit = decl; }
996
946
ConcreteDeclRef getBuilderInit () const { return builderInit; }
997
947
998
- // / Sets the decl that constructs the final result type after the
999
- // / AppendingExpr has been evaluated.
1000
- void setResultInit (ConcreteDeclRef decl) { resultInit = decl; }
1001
- ConcreteDeclRef getResultInit () const { return resultInit; }
1002
-
1003
948
// / Sets the OpaqueValueExpr that is passed into AppendingExpr as the SubExpr
1004
949
// / that the tap operates on.
1005
950
void setInterpolationExpr (OpaqueValueExpr *expr) { interpolationExpr = expr; }
@@ -1059,7 +1004,7 @@ class InterpolatedStringLiteralExpr : public LiteralExpr {
1059
1004
1060
1005
// / MagicIdentifierLiteralExpr - A magic identifier like #file which expands
1061
1006
// / out to a literal at SILGen time.
1062
- class MagicIdentifierLiteralExpr : public LiteralExpr {
1007
+ class MagicIdentifierLiteralExpr : public BuiltinLiteralExpr {
1063
1008
public:
1064
1009
enum Kind : unsigned {
1065
1010
#define MAGIC_IDENTIFIER (NAME, STRING, SYNTAX_KIND ) NAME,
@@ -1077,17 +1022,16 @@ class MagicIdentifierLiteralExpr : public LiteralExpr {
1077
1022
1078
1023
private:
1079
1024
SourceLoc Loc;
1080
- ConcreteDeclRef BuiltinInitializer;
1081
- ConcreteDeclRef Initializer;
1082
1025
1083
1026
public:
1084
1027
MagicIdentifierLiteralExpr (Kind kind, SourceLoc loc, bool implicit = false )
1085
- : LiteralExpr(ExprKind::MagicIdentifierLiteral, implicit), Loc(loc) {
1028
+ : BuiltinLiteralExpr(ExprKind::MagicIdentifierLiteral, implicit),
1029
+ Loc (loc) {
1086
1030
Bits.MagicIdentifierLiteralExpr .Kind = static_cast <unsigned >(kind);
1087
1031
Bits.MagicIdentifierLiteralExpr .StringEncoding
1088
1032
= static_cast <unsigned >(StringLiteralExpr::UTF8);
1089
1033
}
1090
-
1034
+
1091
1035
Kind getKind () const {
1092
1036
return static_cast <Kind>(Bits.MagicIdentifierLiteralExpr .Kind );
1093
1037
}
@@ -1123,35 +1067,6 @@ class MagicIdentifierLiteralExpr : public LiteralExpr {
1123
1067
= static_cast <unsigned >(encoding);
1124
1068
}
1125
1069
1126
- // / Retrieve the builtin initializer that will be used to construct the
1127
- // / literal.
1128
- // /
1129
- // / Any type-checked literal will have a builtin initializer, which is
1130
- // / called first to form a concrete Swift type.
1131
- ConcreteDeclRef getBuiltinInitializer () const {
1132
- return BuiltinInitializer;
1133
- }
1134
-
1135
- // / Set the builtin initializer that will be used to construct the literal.
1136
- void setBuiltinInitializer (ConcreteDeclRef builtinInitializer) {
1137
- BuiltinInitializer = builtinInitializer;
1138
- }
1139
-
1140
- // / Retrieve the initializer that will be used to construct the literal from
1141
- // / the result of the initializer.
1142
- // /
1143
- // / Only literals that have no builtin literal conformance will have
1144
- // / this initializer, which will be called on the result of the builtin
1145
- // / initializer.
1146
- ConcreteDeclRef getInitializer () const {
1147
- return Initializer;
1148
- }
1149
-
1150
- // / Set the initializer that will be used to construct the literal.
1151
- void setInitializer (ConcreteDeclRef initializer) {
1152
- Initializer = initializer;
1153
- }
1154
-
1155
1070
static bool classof (const Expr *E) {
1156
1071
return E->getKind () == ExprKind::MagicIdentifierLiteral;
1157
1072
}
@@ -1174,7 +1089,6 @@ class ObjectLiteralExpr final
1174
1089
private:
1175
1090
Expr *Arg;
1176
1091
SourceLoc PoundLoc;
1177
- ConcreteDeclRef Initializer;
1178
1092
1179
1093
ObjectLiteralExpr (SourceLoc PoundLoc, LiteralKind LitKind,
1180
1094
Expr *Arg,
@@ -1237,15 +1151,6 @@ class ObjectLiteralExpr final
1237
1151
1238
1152
StringRef getLiteralKindPlainName () const ;
1239
1153
1240
- // / Retrieve the initializer that will be used to construct the 'object'
1241
- // / literal from the result of the initializer.
1242
- ConcreteDeclRef getInitializer () const { return Initializer; }
1243
-
1244
- // / Set the initializer that will be used to construct the 'object' literal.
1245
- void setInitializer (ConcreteDeclRef initializer) {
1246
- Initializer = initializer;
1247
- }
1248
-
1249
1154
static bool classof (const Expr *E) {
1250
1155
return E->getKind () == ExprKind::ObjectLiteral;
1251
1156
}
0 commit comments