@@ -2328,23 +2328,86 @@ class TypeDecl : public ValueDecl {
2328
2328
}
2329
2329
};
2330
2330
2331
+ // / A type declaration that can have generic parameters attached to it. Because
2332
+ // / it has these generic parameters, it is always a DeclContext.
2333
+ class GenericTypeDecl : public TypeDecl , public DeclContext {
2334
+ GenericParamList *GenericParams = nullptr ;
2335
+
2336
+ // / \brief The generic signature of this type.
2337
+ // /
2338
+ // / This is the semantic representation of a generic parameters and the
2339
+ // / requirements placed on them.
2340
+ // /
2341
+ // / FIXME: The generic parameters here are also derivable from
2342
+ // / \c GenericParams. However, we likely want to make \c GenericParams
2343
+ // / the parsed representation, and not part of the module file.
2344
+ GenericSignature *GenericSig = nullptr ;
2345
+ // friend class DeclContext;
2346
+
2347
+ public:
2348
+ GenericTypeDecl (DeclKind K, DeclContext *DC,
2349
+ Identifier name, SourceLoc nameLoc,
2350
+ MutableArrayRef<TypeLoc> inherited,
2351
+ GenericParamList *GenericParams);
2352
+
2353
+ GenericParamList *getGenericParams () const { return GenericParams; }
2354
+
2355
+ // / Provide the set of parameters to a generic type, or null if
2356
+ // / this function is not generic.
2357
+ void setGenericParams (GenericParamList *params);
2358
+
2359
+ // / Set the generic signature of this type.
2360
+ void setGenericSignature (GenericSignature *sig);
2361
+
2362
+ // / Retrieve the innermost generic parameter types.
2363
+ ArrayRef<GenericTypeParamType *> getInnermostGenericParamTypes () const {
2364
+ if (!GenericSig)
2365
+ return { };
2366
+
2367
+ return GenericSig->getInnermostGenericParams ();
2368
+ }
2369
+
2370
+ // / Retrieve the generic requirements.
2371
+ ArrayRef<Requirement> getGenericRequirements () const {
2372
+ if (!GenericSig)
2373
+ return { };
2374
+
2375
+ return GenericSig->getRequirements ();
2376
+ }
2377
+
2378
+ // / Retrieve the generic signature.
2379
+ GenericSignature *getGenericSignature () const {
2380
+ return GenericSig;
2381
+ }
2382
+
2383
+ // Resolve ambiguity due to multiple base classes.
2384
+ using TypeDecl::getASTContext;
2385
+ using DeclContext::operator new ;
2386
+ using TypeDecl::getDeclaredInterfaceType;
2387
+
2388
+ static bool classof (const DeclContext *C) {
2389
+ return C->getContextKind () == DeclContextKind::GenericTypeDecl;
2390
+ }
2391
+ };
2392
+
2393
+
2394
+
2331
2395
// / TypeAliasDecl - This is a declaration of a typealias, for example:
2332
2396
// /
2333
- // / typealias foo = int
2397
+ // / typealias Foo = Int
2334
2398
// /
2335
2399
// / TypeAliasDecl's always have 'MetatypeType' type.
2336
2400
// /
2337
2401
class TypeAliasDecl : public TypeDecl {
2338
2402
// / The type that represents this (sugared) name alias.
2339
2403
mutable NameAliasType *AliasTy;
2340
2404
2341
- SourceLoc TypeAliasLoc; // The location of the 'typealias' keyword
2405
+ SourceLoc TypeAliasLoc; // The location of the 'typealias' keyword
2342
2406
TypeLoc UnderlyingTy;
2343
2407
2344
2408
public:
2345
2409
TypeAliasDecl (SourceLoc TypeAliasLoc, Identifier Name,
2346
- SourceLoc NameLoc, TypeLoc UnderlyingTy,
2347
- DeclContext *DC);
2410
+ SourceLoc NameLoc, TypeLoc UnderlyingTy, DeclContext *DC);
2348
2411
2349
2412
SourceLoc getStartLoc () const { return TypeAliasLoc; }
2350
2413
SourceRange getSourceRange () const ;
@@ -2581,29 +2644,15 @@ enum PointerTypeKind : unsigned {
2581
2644
// / These are not added to their enclosing type unless forced.
2582
2645
typedef std::function<void (SmallVectorImpl<Decl *> &)> DelayedDecl;
2583
2646
2584
- // / NominalTypeDecl - a declaration of a nominal type, like a struct. This
2585
- // / decl is always a DeclContext.
2586
- class NominalTypeDecl : public TypeDecl , public DeclContext ,
2587
- public IterableDeclContext {
2647
+ // / NominalTypeDecl - a declaration of a nominal type, like a struct.
2648
+ class NominalTypeDecl : public GenericTypeDecl , public IterableDeclContext {
2588
2649
SourceRange Braces;
2589
2650
2590
2651
// / \brief The set of implicit members and protocols added to imported enum
2591
2652
// / types. These members and protocols are added to the NominalDecl only if
2592
2653
// / the nominal type is directly or indirectly referenced.
2593
2654
std::unique_ptr<DelayedDecl> DelayedMembers;
2594
2655
2595
- GenericParamList *GenericParams;
2596
-
2597
- // / \brief The generic signature of this type.
2598
- // /
2599
- // / This is the semantic representation of a generic parameters and the
2600
- // / requirements placed on them.
2601
- // /
2602
- // / FIXME: The generic parameters here are also derivable from
2603
- // / \c GenericParams. However, we likely want to make \c GenericParams
2604
- // / the parsed representation, and not part of the module file.
2605
- GenericSignature *GenericSig = nullptr ;
2606
-
2607
2656
// / \brief The first extension of this type.
2608
2657
ExtensionDecl *FirstExtension = nullptr ;
2609
2658
@@ -2693,10 +2742,9 @@ class NominalTypeDecl : public TypeDecl, public DeclContext,
2693
2742
SourceLoc NameLoc,
2694
2743
MutableArrayRef<TypeLoc> inherited,
2695
2744
GenericParamList *GenericParams) :
2696
- TypeDecl (K, DC, name, NameLoc, inherited),
2697
- DeclContext (DeclContextKind::NominalTypeDecl, DC),
2745
+ GenericTypeDecl (K, DC, name, NameLoc, inherited, GenericParams),
2698
2746
IterableDeclContext (IterableDeclContextKind::NominalTypeDecl),
2699
- GenericParams ( nullptr ), DeclaredTy(nullptr )
2747
+ DeclaredTy (nullptr )
2700
2748
{
2701
2749
setGenericParams (GenericParams);
2702
2750
NominalTypeDeclBits.HasDelayedMembers = false ;
@@ -2711,8 +2759,6 @@ class NominalTypeDecl : public TypeDecl, public DeclContext,
2711
2759
friend class ProtocolType ;
2712
2760
2713
2761
public:
2714
- using TypeDecl::getASTContext;
2715
-
2716
2762
DeclRange getMembers (bool forceDelayedMembers = true ) const ;
2717
2763
SourceRange getBraces () const { return Braces; }
2718
2764
@@ -2778,36 +2824,6 @@ class NominalTypeDecl : public TypeDecl, public DeclContext,
2778
2824
return SearchedForFailableInits;
2779
2825
}
2780
2826
2781
- GenericParamList *getGenericParams () const { return GenericParams; }
2782
-
2783
- // / Provide the set of parameters to a generic type, or null if
2784
- // / this function is not generic.
2785
- void setGenericParams (GenericParamList *params);
2786
-
2787
- // / Set the generic signature of this type.
2788
- void setGenericSignature (GenericSignature *sig);
2789
-
2790
- // / Retrieve the innermost generic parameter types.
2791
- ArrayRef<GenericTypeParamType *> getInnermostGenericParamTypes () const {
2792
- if (!GenericSig)
2793
- return { };
2794
-
2795
- return GenericSig->getInnermostGenericParams ();
2796
- }
2797
-
2798
- // / Retrieve the generic requirements.
2799
- ArrayRef<Requirement> getGenericRequirements () const {
2800
- if (!GenericSig)
2801
- return { };
2802
-
2803
- return GenericSig->getRequirements ();
2804
- }
2805
-
2806
- // / Retrieve the generic signature.
2807
- GenericSignature *getGenericSignature () const {
2808
- return GenericSig;
2809
- }
2810
-
2811
2827
// / getDeclaredType - Retrieve the type declared by this entity.
2812
2828
Type getDeclaredType () const { return DeclaredTy; }
2813
2829
@@ -2895,8 +2911,6 @@ class NominalTypeDecl : public TypeDecl, public DeclContext,
2895
2911
2896
2912
void setConformanceLoader (LazyMemberLoader *resolver, uint64_t contextData);
2897
2913
2898
- using TypeDecl::getDeclaredInterfaceType;
2899
-
2900
2914
// / classifyAsOptionalType - Decide whether this declaration is one
2901
2915
// / of the library-intrinsic Optional<T> or ImplicitlyUnwrappedOptional<T> types.
2902
2916
OptionalTypeKind classifyAsOptionalType () const ;
@@ -2936,17 +2950,21 @@ class NominalTypeDecl : public TypeDecl, public DeclContext,
2936
2950
return D->getKind () >= DeclKind::First_NominalTypeDecl &&
2937
2951
D->getKind () <= DeclKind::Last_NominalTypeDecl;
2938
2952
}
2953
+ static bool classof (const GenericTypeDecl *D) {
2954
+ return D->getKind () >= DeclKind::First_NominalTypeDecl &&
2955
+ D->getKind () <= DeclKind::Last_NominalTypeDecl;
2956
+ }
2957
+
2939
2958
static bool classof (const DeclContext *C) {
2940
- return C->getContextKind () == DeclContextKind::NominalTypeDecl;
2959
+ auto GTD = dyn_cast<GenericTypeDecl>(C);
2960
+ return GTD && classof (GTD);
2941
2961
}
2942
2962
static bool classof (const IterableDeclContext *C) {
2943
2963
return C->getIterableContextKind ()
2944
2964
== IterableDeclContextKind::NominalTypeDecl;
2945
2965
}
2946
2966
static bool classof (const NominalTypeDecl *D) { return true ; }
2947
2967
static bool classof (const ExtensionDecl *D) { return false ; }
2948
-
2949
- using DeclContext::operator new ;
2950
2968
};
2951
2969
2952
2970
// / \brief This is the declaration of an enum.
@@ -2960,8 +2978,8 @@ class NominalTypeDecl : public TypeDecl, public DeclContext,
2960
2978
// / }
2961
2979
// /
2962
2980
// / enum Optional<T> {
2963
- // / case None
2964
- // / case Some (T)
2981
+ // / case none
2982
+ // / case some (T)
2965
2983
// / }
2966
2984
// / \endcode
2967
2985
// /
@@ -3027,14 +3045,19 @@ class EnumDecl : public NominalTypeDecl {
3027
3045
static bool classof (const Decl *D) {
3028
3046
return D->getKind () == DeclKind::Enum;
3029
3047
}
3048
+ static bool classof (const GenericTypeDecl *D) {
3049
+ return D->getKind () == DeclKind::Enum;
3050
+ }
3030
3051
static bool classof (const NominalTypeDecl *D) {
3031
3052
return D->getKind () == DeclKind::Enum;
3032
3053
}
3033
3054
static bool classof (const DeclContext *C) {
3034
- return isa<NominalTypeDecl>(C) && classof (cast<NominalTypeDecl>(C));
3055
+ auto GTD = dyn_cast<GenericTypeDecl>(C);
3056
+ return GTD && classof (static_cast <const Decl*>(GTD));
3035
3057
}
3036
3058
static bool classof (const IterableDeclContext *C) {
3037
- return isa<NominalTypeDecl>(C) && classof (cast<NominalTypeDecl>(C));
3059
+ auto NTD = dyn_cast<NominalTypeDecl>(C);
3060
+ return NTD && classof (NTD);
3038
3061
}
3039
3062
3040
3063
// / Determine whether this enum declares a raw type in its inheritance clause.
@@ -3086,14 +3109,19 @@ class StructDecl : public NominalTypeDecl {
3086
3109
static bool classof (const Decl *D) {
3087
3110
return D->getKind () == DeclKind::Struct;
3088
3111
}
3112
+ static bool classof (const GenericTypeDecl *D) {
3113
+ return D->getKind () == DeclKind::Struct;
3114
+ }
3089
3115
static bool classof (const NominalTypeDecl *D) {
3090
3116
return D->getKind () == DeclKind::Struct;
3091
3117
}
3092
3118
static bool classof (const DeclContext *C) {
3093
- return isa<NominalTypeDecl>(C) && classof (cast<NominalTypeDecl>(C));
3119
+ auto GTD = dyn_cast<GenericTypeDecl>(C);
3120
+ return GTD && classof (static_cast <const Decl*>(GTD));
3094
3121
}
3095
3122
static bool classof (const IterableDeclContext *C) {
3096
- return isa<NominalTypeDecl>(C) && classof (cast<NominalTypeDecl>(C));
3123
+ auto NTD = dyn_cast<NominalTypeDecl>(C);
3124
+ return NTD && classof (NTD);
3097
3125
}
3098
3126
3099
3127
// / Does this struct contain unreferenceable storage, such as C fields that
@@ -3282,14 +3310,19 @@ class ClassDecl : public NominalTypeDecl {
3282
3310
static bool classof (const Decl *D) {
3283
3311
return D->getKind () == DeclKind::Class;
3284
3312
}
3313
+ static bool classof (const GenericTypeDecl *D) {
3314
+ return D->getKind () == DeclKind::Class;
3315
+ }
3285
3316
static bool classof (const NominalTypeDecl *D) {
3286
3317
return D->getKind () == DeclKind::Class;
3287
3318
}
3288
3319
static bool classof (const DeclContext *C) {
3289
- return isa<NominalTypeDecl>(C) && classof (cast<NominalTypeDecl>(C));
3320
+ auto GTD = dyn_cast<GenericTypeDecl>(C);
3321
+ return GTD && classof (static_cast <const Decl*>(GTD));
3290
3322
}
3291
3323
static bool classof (const IterableDeclContext *C) {
3292
- return isa<NominalTypeDecl>(C) && classof (cast<NominalTypeDecl>(C));
3324
+ auto NTD = dyn_cast<NominalTypeDecl>(C);
3325
+ return NTD && classof (NTD);
3293
3326
}
3294
3327
};
3295
3328
@@ -3544,14 +3577,19 @@ class ProtocolDecl : public NominalTypeDecl {
3544
3577
static bool classof (const Decl *D) {
3545
3578
return D->getKind () == DeclKind::Protocol;
3546
3579
}
3580
+ static bool classof (const GenericTypeDecl *D) {
3581
+ return D->getKind () == DeclKind::Protocol;
3582
+ }
3547
3583
static bool classof (const NominalTypeDecl *D) {
3548
3584
return D->getKind () == DeclKind::Protocol;
3549
3585
}
3550
3586
static bool classof (const DeclContext *C) {
3551
- return isa<NominalTypeDecl>(C) && classof (cast<NominalTypeDecl>(C));
3587
+ auto GTD = dyn_cast<GenericTypeDecl>(C);
3588
+ return GTD && classof (static_cast <const Decl*>(GTD));
3552
3589
}
3553
3590
static bool classof (const IterableDeclContext *C) {
3554
- return isa<NominalTypeDecl>(C) && classof (cast<NominalTypeDecl>(C));
3591
+ auto NTD = dyn_cast<NominalTypeDecl>(C);
3592
+ return NTD && classof (NTD);
3555
3593
}
3556
3594
};
3557
3595
0 commit comments