@@ -1374,6 +1374,82 @@ class alignas(RequirementRepr) TrailingWhereClause final :
1374
1374
}
1375
1375
};
1376
1376
1377
+ class GenericContext : public DeclContext {
1378
+ private:
1379
+ GenericParamList *GenericParams = nullptr ;
1380
+
1381
+ // / The trailing where clause.
1382
+ // /
1383
+ // / Note that this is not currently serialized, because semantic analysis
1384
+ // / moves the trailing where clause into the generic parameter list.
1385
+ TrailingWhereClause *TrailingWhere = nullptr ;
1386
+
1387
+ // / The generic signature or environment of this declaration.
1388
+ // /
1389
+ // / When this declaration stores only a signature, the generic
1390
+ // / environment will be lazily loaded.
1391
+ mutable llvm::PointerUnion<GenericSignature *, GenericEnvironment *>
1392
+ GenericSigOrEnv;
1393
+
1394
+ // / Lazily populate the generic environment.
1395
+ GenericEnvironment *getLazyGenericEnvironmentSlow () const ;
1396
+
1397
+ protected:
1398
+ GenericContext (DeclContextKind Kind, DeclContext *Parent)
1399
+ : DeclContext(Kind, Parent) { }
1400
+
1401
+ public:
1402
+ // / \brief Retrieve the set of parameters to a generic subscript, or null if
1403
+ // / this subscript is not generic.
1404
+ GenericParamList *getGenericParams () const { return GenericParams; }
1405
+
1406
+ void setGenericParams (GenericParamList *GenericParams);
1407
+
1408
+ // / \brief Determine whether this subscript has generic parameters
1409
+ // / of its own.
1410
+ bool isGeneric () const { return GenericParams != nullptr ; }
1411
+
1412
+ // / Retrieve the trailing where clause for this extension, if any.
1413
+ TrailingWhereClause *getTrailingWhereClause () const {
1414
+ return TrailingWhere;
1415
+ }
1416
+
1417
+ // / Set the trailing where clause for this extension.
1418
+ void setTrailingWhereClause (TrailingWhereClause *trailingWhereClause) {
1419
+ TrailingWhere = trailingWhereClause;
1420
+ }
1421
+
1422
+ // / Retrieve the generic signature for this subscript.
1423
+ GenericSignature *getGenericSignature () const ;
1424
+
1425
+ // / Retrieve the generic context for this subscript.
1426
+ GenericEnvironment *getGenericEnvironment () const ;
1427
+
1428
+ // / Retrieve the innermost generic parameter types.
1429
+ ArrayRef<GenericTypeParamType *> getInnermostGenericParamTypes () const {
1430
+ if (auto sig = getGenericSignature ())
1431
+ return sig->getInnermostGenericParams ();
1432
+ else
1433
+ return { };
1434
+ }
1435
+
1436
+ // / Retrieve the generic requirements.
1437
+ ArrayRef<Requirement> getGenericRequirements () const {
1438
+ if (auto sig = getGenericSignature ())
1439
+ return sig->getRequirements ();
1440
+ else
1441
+ return { };
1442
+ }
1443
+
1444
+ // / Set a lazy generic environment.
1445
+ void setLazyGenericEnvironment (LazyMemberLoader *lazyLoader,
1446
+ GenericSignature *genericSig,
1447
+ uint64_t genericEnvData);
1448
+
1449
+ // / Set the generic context of this subscript.
1450
+ void setGenericEnvironment (GenericEnvironment *genericEnv);
1451
+ };
1452
+
1377
1453
// / Describes what kind of name is being imported.
1378
1454
// /
1379
1455
// / If the enumerators here are changed, make sure to update all diagnostics
@@ -1483,32 +1559,16 @@ class ImportDecl final : public Decl,
1483
1559
// / ExtensionDecl - This represents a type extension containing methods
1484
1560
// / associated with the type. This is not a ValueDecl and has no Type because
1485
1561
// / there are no runtime values of the Extension's type.
1486
- class ExtensionDecl final : public Decl, public DeclContext ,
1562
+ class ExtensionDecl final : public Decl, public GenericContext ,
1487
1563
public IterableDeclContext {
1488
1564
SourceLoc ExtensionLoc; // Location of 'extension' keyword.
1489
1565
SourceRange Braces;
1490
1566
1491
1567
// / The type being extended.
1492
1568
TypeLoc ExtendedType;
1493
1569
1494
- // / The generic parameters of the extension.
1495
- GenericParamList *GenericParams = nullptr ;
1496
-
1497
- // / The generic signature or environment of this extension.
1498
- // /
1499
- // / When this extension stores only a signature, the generic environment
1500
- // / will be lazily loaded.
1501
- mutable llvm::PointerUnion<GenericSignature *, GenericEnvironment *>
1502
- GenericSigOrEnv;
1503
-
1504
1570
MutableArrayRef<TypeLoc> Inherited;
1505
1571
1506
- // / The trailing where clause.
1507
- // /
1508
- // / Note that this is not currently serialized, because semantic analysis
1509
- // / moves the trailing where clause into the generic parameter list.
1510
- TrailingWhereClause *TrailingWhere;
1511
-
1512
1572
// / \brief The next extension in the linked list of extensions.
1513
1573
// /
1514
1574
// / The bit indicates whether this extension has been resolved to refer to
@@ -1543,9 +1603,6 @@ class ExtensionDecl final : public Decl, public DeclContext,
1543
1603
// / Slow path for \c takeConformanceLoader().
1544
1604
std::pair<LazyMemberLoader *, uint64_t > takeConformanceLoaderSlow ();
1545
1605
1546
- // / Lazily populate the generic environment.
1547
- GenericEnvironment *getLazyGenericEnvironmentSlow () const ;
1548
-
1549
1606
public:
1550
1607
using Decl::getASTContext;
1551
1608
@@ -1566,45 +1623,6 @@ class ExtensionDecl final : public Decl, public DeclContext,
1566
1623
SourceRange getBraces () const { return Braces; }
1567
1624
void setBraces (SourceRange braces) { Braces = braces; }
1568
1625
1569
- // / Retrieve the innermost generic parameter list.
1570
- GenericParamList *getGenericParams () const {
1571
- return GenericParams;
1572
- }
1573
-
1574
- void setGenericParams (GenericParamList *params);
1575
-
1576
- // / Retrieve the trailing where clause for this extension, if any.
1577
- TrailingWhereClause *getTrailingWhereClause () const {
1578
- return TrailingWhere;
1579
- }
1580
-
1581
- // / Set the trailing where clause for this extension.
1582
- void setTrailingWhereClause (TrailingWhereClause *trailingWhereClause) {
1583
- TrailingWhere = trailingWhereClause;
1584
- }
1585
-
1586
- // / Retrieve the generic requirements.
1587
- ArrayRef<Requirement> getGenericRequirements () const {
1588
- if (auto sig = getGenericSignature ())
1589
- return sig->getRequirements ();
1590
- else
1591
- return { };
1592
- }
1593
-
1594
- // / Retrieve the generic signature for this type.
1595
- GenericSignature *getGenericSignature () const ;
1596
-
1597
- // / Retrieve the generic context for this type.
1598
- GenericEnvironment *getGenericEnvironment () const ;
1599
-
1600
- // / Set a lazy generic environment.
1601
- void setLazyGenericEnvironment (LazyMemberLoader *lazyLoader,
1602
- GenericSignature *genericSig,
1603
- uint64_t genericEnvData);
1604
-
1605
- // / Set the generic context of this extension.
1606
- void setGenericEnvironment (GenericEnvironment *genericEnv);
1607
-
1608
1626
// / Retrieve the type being extended.
1609
1627
Type getExtendedType () const { return ExtendedType.getType (); }
1610
1628
@@ -2351,61 +2369,13 @@ class TypeDecl : public ValueDecl {
2351
2369
2352
2370
// / A type declaration that can have generic parameters attached to it. Because
2353
2371
// / it has these generic parameters, it is always a DeclContext.
2354
- class GenericTypeDecl : public TypeDecl , public DeclContext {
2355
- GenericParamList *GenericParams = nullptr ;
2356
-
2357
- // / The generic signature or environment of this type.
2358
- // /
2359
- // / When this function stores only a signature, the generic environment
2360
- // / will be lazily loaded.
2361
- mutable llvm::PointerUnion<GenericSignature *, GenericEnvironment *>
2362
- GenericSigOrEnv;
2363
-
2364
- // / Lazily populate the generic environment.
2365
- GenericEnvironment *getLazyGenericEnvironmentSlow () const ;
2366
-
2372
+ class GenericTypeDecl : public TypeDecl , public GenericContext {
2367
2373
public:
2368
2374
GenericTypeDecl (DeclKind K, DeclContext *DC,
2369
2375
Identifier name, SourceLoc nameLoc,
2370
2376
MutableArrayRef<TypeLoc> inherited,
2371
2377
GenericParamList *GenericParams);
2372
2378
2373
- GenericParamList *getGenericParams () const { return GenericParams; }
2374
-
2375
- // / Provide the set of parameters to a generic type, or null if
2376
- // / this function is not generic.
2377
- void setGenericParams (GenericParamList *params);
2378
-
2379
- // / Retrieve the innermost generic parameter types.
2380
- ArrayRef<GenericTypeParamType *> getInnermostGenericParamTypes () const {
2381
- if (auto sig = getGenericSignature ())
2382
- return sig->getInnermostGenericParams ();
2383
- else
2384
- return { };
2385
- }
2386
-
2387
- // / Retrieve the generic requirements.
2388
- ArrayRef<Requirement> getGenericRequirements () const {
2389
- if (auto sig = getGenericSignature ())
2390
- return sig->getRequirements ();
2391
- else
2392
- return { };
2393
- }
2394
-
2395
- // / Retrieve the generic signature for this type.
2396
- GenericSignature *getGenericSignature () const ;
2397
-
2398
- // / Retrieve the generic context for this type.
2399
- GenericEnvironment *getGenericEnvironment () const ;
2400
-
2401
- // / Set a lazy generic environment.
2402
- void setLazyGenericEnvironment (LazyMemberLoader *lazyLoader,
2403
- GenericSignature *genericSig,
2404
- uint64_t genericEnvData);
2405
-
2406
- // / Set the generic context of this function.
2407
- void setGenericEnvironment (GenericEnvironment *genericEnv);
2408
-
2409
2379
// Resolve ambiguity due to multiple base classes.
2410
2380
using TypeDecl::getASTContext;
2411
2381
using DeclContext::operator new ;
@@ -4639,7 +4609,7 @@ struct ImportAsMemberStatus {
4639
4609
};
4640
4610
4641
4611
// / \brief Base class for function-like declarations.
4642
- class AbstractFunctionDecl : public ValueDecl , public DeclContext {
4612
+ class AbstractFunctionDecl : public ValueDecl , public GenericContext {
4643
4613
public:
4644
4614
enum class BodyKind {
4645
4615
// / The function did not have a body in the source code file.
@@ -4690,15 +4660,6 @@ class AbstractFunctionDecl : public ValueDecl, public DeclContext {
4690
4660
SourceRange BodyRange;
4691
4661
};
4692
4662
4693
- GenericParamList *GenericParams;
4694
-
4695
- // / The generic signature or environment of this function.
4696
- // /
4697
- // / When this function stores only a signature, the generic environment
4698
- // / will be lazily loaded.
4699
- mutable llvm::PointerUnion<GenericSignature *, GenericEnvironment *>
4700
- GenericSigOrEnv;
4701
-
4702
4663
CaptureInfo Captures;
4703
4664
4704
4665
// / Location of the 'throws' token.
@@ -4711,8 +4672,8 @@ class AbstractFunctionDecl : public ValueDecl, public DeclContext {
4711
4672
unsigned NumParameterLists,
4712
4673
GenericParamList *GenericParams)
4713
4674
: ValueDecl(Kind, Parent, Name, NameLoc),
4714
- DeclContext (DeclContextKind::AbstractFunctionDecl, Parent),
4715
- Body(nullptr ), GenericParams( nullptr ), ThrowsLoc(ThrowsLoc) {
4675
+ GenericContext (DeclContextKind::AbstractFunctionDecl, Parent),
4676
+ Body(nullptr ), ThrowsLoc(ThrowsLoc) {
4716
4677
setBodyKind (BodyKind::None);
4717
4678
setGenericParams (GenericParams);
4718
4679
AbstractFunctionDeclBits.NumParameterLists = NumParameterLists;
@@ -4727,30 +4688,11 @@ class AbstractFunctionDecl : public ValueDecl, public DeclContext {
4727
4688
AbstractFunctionDeclBits.BodyKind = unsigned (K);
4728
4689
}
4729
4690
4730
- void setGenericParams (GenericParamList *GenericParams);
4731
-
4732
- // / Lazily populate the generic environment.
4733
- GenericEnvironment *getLazyGenericEnvironmentSlow () const ;
4734
-
4735
4691
public:
4736
4692
// / \brief Should this declaration be treated as if annotated with transparent
4737
4693
// / attribute.
4738
4694
bool isTransparent () const ;
4739
4695
4740
- // / Retrieve the generic signature for this function.
4741
- GenericSignature *getGenericSignature () const ;
4742
-
4743
- // / Retrieve the generic context for this function.
4744
- GenericEnvironment *getGenericEnvironment () const ;
4745
-
4746
- // / Set a lazy generic environment.
4747
- void setLazyGenericEnvironment (LazyMemberLoader *lazyLoader,
4748
- GenericSignature *genericSig,
4749
- uint64_t genericEnvData);
4750
-
4751
- // / Set the generic context of this function.
4752
- void setGenericEnvironment (GenericEnvironment *genericEnv);
4753
-
4754
4696
// Expose our import as member status
4755
4697
bool isImportAsMember () const { return IAMStatus.isImportAsMember (); }
4756
4698
bool isImportAsInstanceMember () const { return IAMStatus.isInstance (); }
@@ -4930,14 +4872,6 @@ class AbstractFunctionDecl : public ValueDecl, public DeclContext {
4930
4872
}
4931
4873
ParamDecl *getImplicitSelfDecl ();
4932
4874
4933
- // / \brief Retrieve the set of parameters to a generic function, or null if
4934
- // / this function is not generic.
4935
- GenericParamList *getGenericParams () const { return GenericParams; }
4936
-
4937
- // / \brief Determine whether this is a generic function, which can only be
4938
- // / used when each of the archetypes is bound to a particular concrete type.
4939
- bool isGeneric () const { return GenericParams != nullptr ; }
4940
-
4941
4875
// / Retrieve the declaration that this method overrides, if any.
4942
4876
AbstractFunctionDecl *getOverriddenDecl () const ;
4943
4877
0 commit comments