@@ -587,13 +587,10 @@ class alignas(1 << DeclAlignInBits) Decl : public ASTAllocated<Decl> {
587
587
588
588
SWIFT_INLINE_BITFIELD_EMPTY (TypeDecl, ValueDecl);
589
589
590
- SWIFT_INLINE_BITFIELD_FULL (GenericTypeParamDecl, TypeDecl, 16 +16 +1 +1 +1 ,
591
- : NumPadBits,
592
-
590
+ SWIFT_INLINE_BITFIELD_FULL (GenericTypeParamDecl, TypeDecl, 16 +16 +8 +1 ,
593
591
Depth : 16 ,
594
592
Index : 16 ,
595
- ParameterPack : 1 ,
596
- Value : 1 ,
593
+ ParamKind : 8 ,
597
594
598
595
// / Whether this generic parameter represents an opaque type.
599
596
IsOpaqueType : 1
@@ -3772,17 +3769,11 @@ class GenericTypeParamDecl final
3772
3769
}
3773
3770
3774
3771
size_t numTrailingObjects (OverloadToken<SourceLoc>) const {
3775
- auto numSourceLocs = 0 ;
3776
-
3777
- if (isParameterPack ()) {
3778
- numSourceLocs += 1 ;
3779
- }
3780
-
3781
- if (isValue ()) {
3782
- numSourceLocs += 1 ;
3772
+ if (isParameterPack () || isValue ()) {
3773
+ return 1 ;
3783
3774
}
3784
3775
3785
- return numSourceLocs ;
3776
+ return 0 ;
3786
3777
}
3787
3778
3788
3779
// / Construct a new generic type parameter.
@@ -3793,24 +3784,16 @@ class GenericTypeParamDecl final
3793
3784
// /
3794
3785
// / \param name The name of the generic parameter.
3795
3786
// / \param nameLoc The location of the name.
3796
- // / \param eachLoc The location of the 'each' keyword for a type parameter
3797
- // / pack.
3798
- // / \param letLoc The location of the 'let' keyword for a variable type
3799
- // / parameter.
3787
+ // / \param specifierLoc The location of the 'each' or 'let' keyword for pack
3788
+ // / or value parameters.
3800
3789
// / \param depth The generic signature depth.
3801
3790
// / \param index The index of the parameter in the generic signature.
3802
- // / \param isParameterPack Whether the generic parameter is for a type
3803
- // / parameter pack, denoted by \c <each T>.
3804
- // / \param isValue Whether the generic parameter is for a value type
3805
- // / parameter, denoted by \c <let N: Int>.
3806
- // / \param isOpaqueType Whether the generic parameter is written as an opaque
3807
- // / parameter e.g 'some Collection'.
3791
+ // / \param paramKind The kind of generic type parameter this is.
3808
3792
// / \param opaqueTypeRepr The TypeRepr of an opaque generic parameter.
3809
3793
// /
3810
3794
GenericTypeParamDecl (DeclContext *dc, Identifier name, SourceLoc nameLoc,
3811
- SourceLoc eachLoc, SourceLoc letLoc, unsigned depth,
3812
- unsigned index, bool isParameterPack, bool isValue,
3813
- bool isOpaqueType, TypeRepr *opaqueTypeRepr);
3795
+ SourceLoc specifierLoc, unsigned depth, unsigned index,
3796
+ GenericTypeParamKind paramKind, TypeRepr *opaqueTypeRepr);
3814
3797
3815
3798
// / Construct a new generic type parameter.
3816
3799
// /
@@ -3820,25 +3803,17 @@ class GenericTypeParamDecl final
3820
3803
// /
3821
3804
// / \param name The name of the generic parameter.
3822
3805
// / \param nameLoc The location of the name.
3823
- // / \param eachLoc The location of the 'each' keyword for a type parameter
3824
- // / pack.
3825
- // / \param letLoc The location of the 'let' keyword for a variable type
3826
- // / parameter.
3806
+ // / \param specifierLoc The location of the 'each' or 'let' keyword for pack
3807
+ // / or value parameters.
3827
3808
// / \param depth The generic signature depth.
3828
3809
// / \param index The index of the parameter in the generic signature.
3829
- // / \param isParameterPack Whether the generic parameter is for a type
3830
- // / parameter pack, denoted by \c <each T>.
3831
- // / \param isValue Whether the generic parameter is for a value type
3832
- // / parameter, denoted by \c <let N: Int>.
3833
- // / \param isOpaqueType Whether the generic parameter is written as an opaque
3834
- // / parameter e.g 'some Collection'.
3810
+ // / \param paramKind The kind of generic type parameter this is.
3835
3811
// / \param opaqueTypeRepr The TypeRepr of an opaque generic parameter.
3836
3812
// /
3837
3813
static GenericTypeParamDecl *create (DeclContext *dc, Identifier name,
3838
- SourceLoc nameLoc, SourceLoc eachLoc,
3839
- SourceLoc letLoc, unsigned depth,
3840
- unsigned index, bool isParameterPack,
3841
- bool isValue, bool isOpaqueType,
3814
+ SourceLoc nameLoc, SourceLoc specifierLoc,
3815
+ unsigned depth, unsigned index,
3816
+ GenericTypeParamKind paramKind,
3842
3817
TypeRepr *opaqueTypeRepr);
3843
3818
3844
3819
public:
@@ -3847,11 +3822,10 @@ class GenericTypeParamDecl final
3847
3822
// / Construct a new generic type parameter. This should only be used by the
3848
3823
// / ClangImporter, use \c GenericTypeParamDecl::create[...] instead.
3849
3824
GenericTypeParamDecl (DeclContext *dc, Identifier name, SourceLoc nameLoc,
3850
- SourceLoc eachLoc, SourceLoc letLoc, unsigned depth,
3851
- unsigned index, bool isParameterPack, bool isValue)
3852
- : GenericTypeParamDecl(dc, name, nameLoc, eachLoc, letLoc, depth, index,
3853
- isParameterPack, isValue, /* isOpaqueType*/ false ,
3854
- nullptr ) {
3825
+ SourceLoc specifierLoc, unsigned depth, unsigned index,
3826
+ GenericTypeParamKind paramKind)
3827
+ : GenericTypeParamDecl(dc, name, nameLoc, specifierLoc, depth, index,
3828
+ paramKind, nullptr ) {
3855
3829
}
3856
3830
3857
3831
// / Construct a deserialized generic type parameter.
@@ -3863,17 +3837,11 @@ class GenericTypeParamDecl final
3863
3837
// / \param name The name of the generic parameter.
3864
3838
// / \param depth The generic signature depth.
3865
3839
// / \param index The index of the parameter in the generic signature.
3866
- // / \param isParameterPack Whether the generic parameter is for a type
3867
- // / parameter pack, denoted by \c <each T>.
3868
- // / \param isValue Whether the generic parameter is for a variable type
3869
- // / parameter, denoted by \c <let N: Int>.
3870
- // / \param isOpaqueType Whether the generic parameter is written as an opaque
3871
- // / parameter e.g 'some Collection'.
3840
+ // / \param paramKind The kind of generic type parameter this is.
3872
3841
// /
3873
3842
static GenericTypeParamDecl *
3874
3843
createDeserialized (DeclContext *dc, Identifier name, unsigned depth,
3875
- unsigned index, bool isParameterPack, bool isValue,
3876
- bool isOpaqueType);
3844
+ unsigned index, GenericTypeParamKind paramKind);
3877
3845
3878
3846
// / Construct a new parsed generic type parameter.
3879
3847
// /
@@ -3883,22 +3851,16 @@ class GenericTypeParamDecl final
3883
3851
// /
3884
3852
// / \param name The name of the generic parameter.
3885
3853
// / \param nameLoc The location of the name.
3886
- // / \param eachLoc The location of the 'each' keyword for a type parameter
3887
- // / pack.
3888
- // / \param letLoc The location of the 'let' keyword for a variable type
3889
- // / parameter.
3854
+ // / \param specifierLoc The location of the 'each' or 'let' keyword for pack
3855
+ // / or value parameters.
3890
3856
// / \param index The index of the parameter in the generic signature.
3891
- // / \param isParameterPack Whether the generic parameter is for a type
3892
- // / parameter pack, denoted by \c <each T>.
3893
- // / \param isValue Whether the generic parameter is for a variable type
3894
- // / parameter, denoted by \c <let N: Int>.
3857
+ // / \param paramKind The kind of generic type parameter this is.
3895
3858
// /
3896
3859
static GenericTypeParamDecl *createParsed (DeclContext *dc, Identifier name,
3897
3860
SourceLoc nameLoc,
3898
- SourceLoc eachLoc, SourceLoc letLoc ,
3861
+ SourceLoc specifierLoc ,
3899
3862
unsigned index,
3900
- bool isParameterPack,
3901
- bool isValue);
3863
+ GenericTypeParamKind paramKind);
3902
3864
3903
3865
// / Construct a new implicit generic type parameter.
3904
3866
// /
@@ -3909,25 +3871,17 @@ class GenericTypeParamDecl final
3909
3871
// / \param name The name of the generic parameter.
3910
3872
// / \param depth The generic signature depth.
3911
3873
// / \param index The index of the parameter in the generic signature.
3912
- // / \param isParameterPack Whether the generic parameter is for a type
3913
- // / parameter pack, denoted by \c <each T>.
3914
- // / \param isValue Whether the generic parameter is for a variable type
3915
- // / parameter, denoted by \c <let N: Int>.
3916
- // / \param isOpaqueType Whether the generic parameter is written as an opaque
3917
- // / parameter e.g 'some Collection'.
3874
+ // / \param paramKind The kind of generic type parameter this is.
3918
3875
// / \param opaqueTypeRepr The TypeRepr of an opaque generic parameter.
3919
3876
// / \param nameLoc The location of the name.
3920
- // / \param eachLoc The location of the 'each' keyword for a type parameter
3921
- // / pack.
3922
- // / \param letLoc The location of the 'let' keyword for a variable type
3923
- // / parameter.
3877
+ // / \param specifierLoc The location of the 'each' or 'let' keyword for pack
3878
+ // / or value parameters.
3924
3879
// /
3925
3880
static GenericTypeParamDecl *
3926
3881
createImplicit (DeclContext *dc, Identifier name, unsigned depth,
3927
- unsigned index, bool isParameterPack = false ,
3928
- bool isValue = false , bool isOpaqueType = false ,
3882
+ unsigned index, GenericTypeParamKind paramKind,
3929
3883
TypeRepr *opaqueTypeRepr = nullptr , SourceLoc nameLoc = {},
3930
- SourceLoc eachLoc = {}, SourceLoc letLoc = {});
3884
+ SourceLoc specifierLoc = {});
3931
3885
3932
3886
// / The depth of this generic type parameter, i.e., the number of outer
3933
3887
// / levels of generic parameter lists that enclose this type parameter.
@@ -3949,14 +3903,21 @@ class GenericTypeParamDecl final
3949
3903
assert (Bits.GenericTypeParamDecl .Depth == depth && " Truncation" );
3950
3904
}
3951
3905
3906
+ // / The kind of generic type parameter this is.
3907
+ GenericTypeParamKind getParamKind () const {
3908
+ return (GenericTypeParamKind) Bits.GenericTypeParamDecl .ParamKind ;
3909
+ }
3910
+
3952
3911
// / Returns \c true if this generic type parameter is declared as a type
3953
3912
// / parameter pack.
3954
3913
// /
3955
3914
// / \code
3956
3915
// / func foo<each T>(_ : for each T) { }
3957
3916
// / struct Foo<each T> { }
3958
3917
// / \endcode
3959
- bool isParameterPack () const { return Bits.GenericTypeParamDecl .ParameterPack ; }
3918
+ bool isParameterPack () const {
3919
+ return getParamKind () == GenericTypeParamKind::Pack;
3920
+ }
3960
3921
3961
3922
// / Returns \c true if this generic type parameter is declared as a value
3962
3923
// / type parameter.
@@ -3965,9 +3926,13 @@ class GenericTypeParamDecl final
3965
3926
// / struct Vector<Element, let N: Int>
3966
3927
// / \endcode
3967
3928
bool isValue () const {
3968
- return Bits. GenericTypeParamDecl . Value ;
3929
+ return getParamKind () == GenericTypeParamKind:: Value;
3969
3930
}
3970
3931
3932
+ // / Returns the underlying value type associated with this generic value
3933
+ // / parameter. E.g. if this is 'let N: Int' returns 'Int'.
3934
+ Type getValueType () const ;
3935
+
3971
3936
// / Determine whether this generic parameter represents an opaque type.
3972
3937
// /
3973
3938
// / \code
@@ -4004,14 +3969,31 @@ class GenericTypeParamDecl final
4004
3969
// / Here 'T' and 'U' have indexes 0 and 1, respectively. 'V' has index 0.
4005
3970
unsigned getIndex () const { return Bits.GenericTypeParamDecl .Index ; }
4006
3971
4007
- // / Retrieve the 'each' keyword location for a type parameter pack \c each T
3972
+ // / Retrieve either the 'each' keyword or the 'let' keyword location for this
3973
+ // / generic parameter depending on if it's a parameter pack or a value.
3974
+ SourceLoc getSpecifierLoc () const {
3975
+ if (!isParameterPack () && !isValue ())
3976
+ return SourceLoc ();
3977
+
3978
+ return *getTrailingObjects<SourceLoc>();
3979
+ }
3980
+
3981
+ // / Retrieve the 'each' keyword location for a type parameter pack \c each T.
4008
3982
SourceLoc getEachLoc () const {
4009
3983
if (!isParameterPack ())
4010
3984
return SourceLoc ();
4011
3985
4012
3986
return *getTrailingObjects<SourceLoc>();
4013
3987
}
4014
3988
3989
+ // / Retrieve the 'let' keyword location for a value parameter \c let N.
3990
+ SourceLoc getLetLoc () const {
3991
+ if (!isValue ())
3992
+ return SourceLoc ();
3993
+
3994
+ return *getTrailingObjects<SourceLoc>();
3995
+ }
3996
+
4015
3997
SourceLoc getStartLoc () const { return getNameLoc (); }
4016
3998
SourceRange getSourceRange () const ;
4017
3999
0 commit comments