@@ -3166,15 +3166,20 @@ class AbstractTypeParamDecl : public TypeDecl {
3166
3166
// / \code
3167
3167
// / func min<T : Comparable>(x : T, y : T) -> T { ... }
3168
3168
// / \endcode
3169
- class GenericTypeParamDecl final :
3170
- public AbstractTypeParamDecl,
3171
- private llvm::TrailingObjects<GenericTypeParamDecl, TypeRepr *>{
3169
+ class GenericTypeParamDecl final
3170
+ : public AbstractTypeParamDecl,
3171
+ private llvm::TrailingObjects<GenericTypeParamDecl, TypeRepr *,
3172
+ SourceLoc> {
3172
3173
friend TrailingObjects;
3173
3174
3174
- size_t numTrailingObjects (OverloadToken<OpaqueReturnTypeRepr *>) const {
3175
+ size_t numTrailingObjects (OverloadToken<TypeRepr *>) const {
3175
3176
return isOpaqueType () ? 1 : 0 ;
3176
3177
}
3177
3178
3179
+ size_t numTrailingObjects (OverloadToken<SourceLoc>) const {
3180
+ return isParameterPack () ? 1 : 0 ;
3181
+ }
3182
+
3178
3183
// / Construct a new generic type parameter.
3179
3184
// /
3180
3185
// / \param dc The DeclContext in which the generic type parameter's owner
@@ -3183,11 +3188,20 @@ class GenericTypeParamDecl final :
3183
3188
// /
3184
3189
// / \param name The name of the generic parameter.
3185
3190
// / \param nameLoc The location of the name.
3191
+ // / \param ellipsisLoc The location of the ellipsis for a type parameter pack.
3192
+ // / \param depth The generic signature depth.
3193
+ // / \param index The index of the parameter in the generic signature.
3194
+ // / \param isParameterPack Whether the generic parameter is for a type
3195
+ // / parameter pack, denoted by \c <T...>.
3196
+ // / \param isOpaqueType Whether the generic parameter is written as an opaque
3197
+ // / parameter e.g 'some Collection'.
3198
+ // / \param opaqueTypeRepr The TypeRepr of an opaque generic parameter.
3199
+ // /
3186
3200
GenericTypeParamDecl (DeclContext *dc, Identifier name, SourceLoc nameLoc,
3187
- bool isParameterPack, unsigned depth, unsigned index,
3188
- bool isOpaqueType, TypeRepr *typeRepr);
3201
+ SourceLoc ellipsisLoc, unsigned depth, unsigned index,
3202
+ bool isParameterPack, bool isOpaqueType,
3203
+ TypeRepr *opaqueTypeRepr);
3189
3204
3190
- public:
3191
3205
// / Construct a new generic type parameter.
3192
3206
// /
3193
3207
// / \param dc The DeclContext in which the generic type parameter's owner
@@ -3196,17 +3210,91 @@ class GenericTypeParamDecl final :
3196
3210
// /
3197
3211
// / \param name The name of the generic parameter.
3198
3212
// / \param nameLoc The location of the name.
3199
- GenericTypeParamDecl (DeclContext *dc, Identifier name, SourceLoc nameLoc,
3200
- bool isParameterPack, unsigned depth, unsigned index)
3201
- : GenericTypeParamDecl(dc, name, nameLoc, isParameterPack, depth, index,
3202
- false , nullptr ) { }
3213
+ // / \param ellipsisLoc The location of the ellipsis for a type parameter pack.
3214
+ // / \param depth The generic signature depth.
3215
+ // / \param index The index of the parameter in the generic signature.
3216
+ // / \param isParameterPack Whether the generic parameter is for a type
3217
+ // / parameter pack, denoted by \c <T...>.
3218
+ // / \param isOpaqueType Whether the generic parameter is written as an opaque
3219
+ // / parameter e.g 'some Collection'.
3220
+ // / \param opaqueTypeRepr The TypeRepr of an opaque generic parameter.
3221
+ // /
3222
+ static GenericTypeParamDecl *create (DeclContext *dc, Identifier name,
3223
+ SourceLoc nameLoc, SourceLoc ellipsisLoc,
3224
+ unsigned depth, unsigned index,
3225
+ bool isParameterPack, bool isOpaqueType,
3226
+ TypeRepr *opaqueTypeRepr);
3203
3227
3228
+ public:
3204
3229
static const unsigned InvalidDepth = 0xFFFF ;
3205
3230
3231
+ // / Construct a new generic type parameter. This should only be used by the
3232
+ // / ClangImporter, use \c GenericTypeParamDecl::create[...] instead.
3233
+ GenericTypeParamDecl (DeclContext *dc, Identifier name, SourceLoc nameLoc,
3234
+ SourceLoc ellipsisLoc, unsigned depth, unsigned index,
3235
+ bool isParameterPack)
3236
+ : GenericTypeParamDecl(dc, name, nameLoc, ellipsisLoc, depth, index,
3237
+ isParameterPack, /* isOpaqueType*/ false , nullptr ) {
3238
+ }
3239
+
3240
+ // / Construct a deserialized generic type parameter.
3241
+ // /
3242
+ // / \param dc The DeclContext in which the generic type parameter's owner
3243
+ // / occurs. This should later be overwritten with the actual declaration
3244
+ // / context that owns the type parameter.
3245
+ // /
3246
+ // / \param name The name of the generic parameter.
3247
+ // / \param depth The generic signature depth.
3248
+ // / \param index The index of the parameter in the generic signature.
3249
+ // / \param isParameterPack Whether the generic parameter is for a type
3250
+ // / parameter pack, denoted by \c <T...>.
3251
+ // / \param isOpaqueType Whether the generic parameter is written as an opaque
3252
+ // / parameter e.g 'some Collection'.
3253
+ // /
3254
+ static GenericTypeParamDecl *
3255
+ createDeserialized (DeclContext *dc, Identifier name, unsigned depth,
3256
+ unsigned index, bool isParameterPack, bool isOpaqueType);
3257
+
3258
+ // / Construct a new parsed generic type parameter.
3259
+ // /
3260
+ // / \param dc The DeclContext in which the generic type parameter's owner
3261
+ // / occurs. This should later be overwritten with the actual declaration
3262
+ // / context that owns the type parameter.
3263
+ // /
3264
+ // / \param name The name of the generic parameter.
3265
+ // / \param nameLoc The location of the name.
3266
+ // / \param ellipsisLoc The location of the ellipsis for a type parameter pack.
3267
+ // / \param index The index of the parameter in the generic signature.
3268
+ // / \param isParameterPack Whether the generic parameter is for a type
3269
+ // / parameter pack, denoted by \c <T...>.
3270
+ // /
3271
+ static GenericTypeParamDecl *
3272
+ createParsed (DeclContext *dc, Identifier name, SourceLoc nameLoc,
3273
+ SourceLoc ellipsisLoc, unsigned index, bool isParameterPack);
3274
+
3275
+ // / Construct a new implicit generic type parameter.
3276
+ // /
3277
+ // / \param dc The DeclContext in which the generic type parameter's owner
3278
+ // / occurs. This should later be overwritten with the actual declaration
3279
+ // / context that owns the type parameter.
3280
+ // /
3281
+ // / \param name The name of the generic parameter.
3282
+ // / \param depth The generic signature depth.
3283
+ // / \param index The index of the parameter in the generic signature.
3284
+ // / \param isParameterPack Whether the generic parameter is for a type
3285
+ // / parameter pack, denoted by \c <T...>.
3286
+ // / \param isOpaqueType Whether the generic parameter is written as an opaque
3287
+ // / parameter e.g 'some Collection'.
3288
+ // / \param opaqueTypeRepr The TypeRepr of an opaque generic parameter.
3289
+ // / \param nameLoc The location of the name.
3290
+ // / \param ellipsisLoc The location of the ellipsis for a type parameter pack.
3291
+ // /
3206
3292
static GenericTypeParamDecl *
3207
- create (DeclContext *dc, Identifier name, SourceLoc nameLoc,
3208
- bool isParameterPack, unsigned depth, unsigned index,
3209
- bool isOpaqueType, TypeRepr *typeRepr);
3293
+ createImplicit (DeclContext *dc, Identifier name, unsigned depth,
3294
+ unsigned index, bool isParameterPack = false ,
3295
+ bool isOpaqueType = false , TypeRepr *opaqueTypeRepr = nullptr ,
3296
+ SourceLoc nameLoc = SourceLoc(),
3297
+ SourceLoc ellipsisLoc = SourceLoc());
3210
3298
3211
3299
// / The depth of this generic type parameter, i.e., the number of outer
3212
3300
// / levels of generic parameter lists that enclose this type parameter.
@@ -3273,6 +3361,14 @@ class GenericTypeParamDecl final :
3273
3361
// / Here 'T' and 'U' have indexes 0 and 1, respectively. 'V' has index 0.
3274
3362
unsigned getIndex () const { return Bits.GenericTypeParamDecl .Index ; }
3275
3363
3364
+ // / Retrieve the ellipsis location for a type parameter pack \c T...
3365
+ SourceLoc getEllipsisLoc () const {
3366
+ if (!isParameterPack ())
3367
+ return SourceLoc ();
3368
+
3369
+ return *getTrailingObjects<SourceLoc>();
3370
+ }
3371
+
3276
3372
SourceLoc getStartLoc () const { return getNameLoc (); }
3277
3373
SourceRange getSourceRange () const ;
3278
3374
0 commit comments