@@ -448,7 +448,8 @@ FuncDecl_create(BridgedASTContext cContext, BridgedDeclContext cDeclContext,
448
448
BridgedIdentifier cName, BridgedSourceLoc cNameLoc,
449
449
void *_Nullable opaqueGenericParamList,
450
450
void *opaqueParameterList, BridgedSourceLoc cAsyncLoc,
451
- BridgedSourceLoc cThrowsLoc, void *_Nullable opaqueReturnType) {
451
+ BridgedSourceLoc cThrowsLoc, void *_Nullable opaqueReturnType,
452
+ void *_Nullable opaqueGenericWhereClause) {
452
453
ASTContext &context = convertASTContext (cContext);
453
454
454
455
auto *paramList = static_cast <ParameterList *>(opaqueParameterList);
@@ -463,6 +464,8 @@ FuncDecl_create(BridgedASTContext cContext, BridgedDeclContext cDeclContext,
463
464
static_cast <GenericParamList *>(opaqueGenericParamList), paramList,
464
465
static_cast <TypeRepr *>(opaqueReturnType),
465
466
convertDeclContext (cDeclContext));
467
+ out->setTrailingWhereClause (
468
+ static_cast <TrailingWhereClause *>(opaqueGenericWhereClause));
466
469
467
470
return {bridgeDeclContext (out), static_cast <FuncDecl *>(out),
468
471
static_cast <Decl *>(out)};
@@ -527,11 +530,14 @@ void *ClosureExpr_create(BridgedASTContext cContext, void *body,
527
530
return (Expr *)out;
528
531
}
529
532
530
- void *TypeAliasDecl_create (
531
- BridgedASTContext cContext, BridgedDeclContext cDeclContext,
532
- BridgedSourceLoc cAliasKeywordLoc, BridgedIdentifier cName,
533
- BridgedSourceLoc cNameLoc, void *_Nullable opaqueGenericParamList,
534
- BridgedSourceLoc cEqualLoc, void *opaqueUnderlyingType) {
533
+ void *TypeAliasDecl_create (BridgedASTContext cContext,
534
+ BridgedDeclContext cDeclContext,
535
+ BridgedSourceLoc cAliasKeywordLoc,
536
+ BridgedIdentifier cName, BridgedSourceLoc cNameLoc,
537
+ void *_Nullable opaqueGenericParamList,
538
+ BridgedSourceLoc cEqualLoc,
539
+ void *opaqueUnderlyingType,
540
+ void *_Nullable opaqueGenericWhereClause) {
535
541
ASTContext &context = convertASTContext (cContext);
536
542
537
543
auto *decl = new (context) TypeAliasDecl (
@@ -540,6 +546,8 @@ void *TypeAliasDecl_create(
540
546
static_cast <GenericParamList *>(opaqueGenericParamList),
541
547
convertDeclContext (cDeclContext));
542
548
decl->setUnderlyingTypeRepr (static_cast <TypeRepr *>(opaqueUnderlyingType));
549
+ decl->setTrailingWhereClause (
550
+ static_cast <TrailingWhereClause *>(opaqueGenericWhereClause));
543
551
544
552
return static_cast <Decl *>(decl);
545
553
}
@@ -569,7 +577,8 @@ BridgedDeclContextAndDecl StructDecl_create(
569
577
BridgedASTContext cContext, BridgedDeclContext cDeclContext,
570
578
BridgedSourceLoc cStructKeywordLoc, BridgedIdentifier cName,
571
579
BridgedSourceLoc cNameLoc, void *_Nullable opaqueGenericParamList,
572
- BridgedArrayRef cInheritedTypes, BridgedSourceRange cBraceRange) {
580
+ BridgedArrayRef cInheritedTypes, void *_Nullable opaqueGenericWhereClause,
581
+ BridgedSourceRange cBraceRange) {
573
582
ASTContext &context = convertASTContext (cContext);
574
583
575
584
auto *decl = new (context) StructDecl (
@@ -578,6 +587,8 @@ BridgedDeclContextAndDecl StructDecl_create(
578
587
context.AllocateCopy (convertToInheritedEntries (cInheritedTypes)),
579
588
static_cast <GenericParamList *>(opaqueGenericParamList),
580
589
convertDeclContext (cDeclContext));
590
+ decl->setTrailingWhereClause (
591
+ static_cast <TrailingWhereClause *>(opaqueGenericWhereClause));
581
592
decl->setBraces (convertSourceRange (cBraceRange));
582
593
583
594
return {bridgeDeclContext (decl), static_cast <Decl *>(decl)};
@@ -587,7 +598,8 @@ BridgedDeclContextAndDecl ClassDecl_create(
587
598
BridgedASTContext cContext, BridgedDeclContext cDeclContext,
588
599
BridgedSourceLoc cClassKeywordLoc, BridgedIdentifier cName,
589
600
BridgedSourceLoc cNameLoc, void *_Nullable opaqueGenericParamList,
590
- BridgedArrayRef cInheritedTypes, BridgedSourceRange cBraceRange) {
601
+ BridgedArrayRef cInheritedTypes, void *_Nullable opaqueGenericWhereClause,
602
+ BridgedSourceRange cBraceRange) {
591
603
ASTContext &context = convertASTContext (cContext);
592
604
593
605
auto *decl = new (context) ClassDecl (
@@ -596,6 +608,8 @@ BridgedDeclContextAndDecl ClassDecl_create(
596
608
context.AllocateCopy (convertToInheritedEntries (cInheritedTypes)),
597
609
static_cast <GenericParamList *>(opaqueGenericParamList),
598
610
convertDeclContext (cDeclContext), false );
611
+ decl->setTrailingWhereClause (
612
+ static_cast <TrailingWhereClause *>(opaqueGenericWhereClause));
599
613
decl->setBraces (convertSourceRange (cBraceRange));
600
614
601
615
return {bridgeDeclContext (decl), static_cast <Decl *>(decl)};
@@ -605,7 +619,8 @@ BridgedDeclContextAndDecl ProtocolDecl_create(
605
619
BridgedASTContext cContext, BridgedDeclContext cDeclContext,
606
620
BridgedSourceLoc cProtocolKeywordLoc, BridgedIdentifier cName,
607
621
BridgedSourceLoc cNameLoc, BridgedArrayRef cPrimaryAssociatedTypeNames,
608
- BridgedArrayRef cInheritedTypes, BridgedSourceRange cBraceRange) {
622
+ BridgedArrayRef cInheritedTypes, void *_Nullable opaqueGenericWhereClause,
623
+ BridgedSourceRange cBraceRange) {
609
624
SmallVector<PrimaryAssociatedTypeName, 2 > primaryAssociatedTypeNames;
610
625
for (auto &pair : convertArrayRef<BridgedIdentifierAndSourceLoc>(
611
626
cPrimaryAssociatedTypeNames)) {
@@ -619,7 +634,7 @@ BridgedDeclContextAndDecl ProtocolDecl_create(
619
634
convertSourceLoc (cNameLoc), convertIdentifier (cName),
620
635
context.AllocateCopy (primaryAssociatedTypeNames),
621
636
context.AllocateCopy (convertToInheritedEntries (cInheritedTypes)),
622
- nullptr );
637
+ static_cast <TrailingWhereClause *>(opaqueGenericWhereClause) );
623
638
decl->setBraces (convertSourceRange (cBraceRange));
624
639
625
640
return {bridgeDeclContext (decl), static_cast <Decl *>(decl)};
@@ -631,14 +646,15 @@ void *AssociatedTypeDecl_create(BridgedASTContext cContext,
631
646
BridgedIdentifier cName,
632
647
BridgedSourceLoc cNameLoc,
633
648
BridgedArrayRef cInheritedTypes,
634
- void *_Nullable opaqueDefaultType) {
649
+ void *_Nullable opaqueDefaultType,
650
+ void *_Nullable opaqueGenericWhereClause) {
635
651
ASTContext &context = convertASTContext (cContext);
636
652
637
653
auto *decl = AssociatedTypeDecl::createParsed (
638
654
context, convertDeclContext (cDeclContext),
639
655
convertSourceLoc (cAssociatedtypeKeywordLoc), convertIdentifier (cName),
640
656
convertSourceLoc (cNameLoc), static_cast <TypeRepr *>(opaqueDefaultType),
641
- nullptr );
657
+ static_cast <TrailingWhereClause *>(opaqueGenericWhereClause) );
642
658
decl->setInherited (
643
659
context.AllocateCopy (convertToInheritedEntries (cInheritedTypes)));
644
660
@@ -863,32 +879,22 @@ void *ExistentialTypeRepr_create(BridgedASTContext cContext,
863
879
}
864
880
865
881
void *GenericParamList_create (BridgedASTContext cContext,
866
- BridgedSourceLoc cLAngleLoc,
867
- BridgedArrayRef params,
868
- BridgedSourceLoc cWhereLoc, BridgedArrayRef reqs,
869
- BridgedSourceLoc cRAngleLoc) {
870
- ASTContext &context = convertASTContext (cContext);
871
- SmallVector<RequirementRepr> requirements;
872
- for (auto req : convertArrayRef<BridgedRequirementRepr>(reqs)) {
873
- switch (req.Kind ) {
874
- case BridgedRequirementReprKindTypeConstraint:
875
- requirements.push_back (RequirementRepr::getTypeConstraint (
876
- (TypeRepr *)req.FirstType , convertSourceLoc (req.SeparatorLoc ),
877
- (TypeRepr *)req.SecondType , /* isExpansionPattern*/ false ));
878
- break ;
879
- case BridgedRequirementReprKindSameType:
880
- requirements.push_back (RequirementRepr::getSameType (
881
- (TypeRepr *)req.FirstType , convertSourceLoc (req.SeparatorLoc ),
882
- (TypeRepr *)req.SecondType , /* isExpansionPattern*/ false ));
883
- break ;
884
- case BridgedRequirementReprKindLayoutConstraint:
885
- llvm_unreachable (" cannot handle layout constraints!" );
886
- }
882
+ BridgedSourceLoc cLeftAngleLoc,
883
+ BridgedArrayRef cParameters,
884
+ void *_Nullable opaqueGenericWhereClause,
885
+ BridgedSourceLoc cRightAngleLoc) {
886
+ SourceLoc whereLoc;
887
+ ArrayRef<RequirementRepr> requirements;
888
+ if (auto *genericWhereClause =
889
+ static_cast <TrailingWhereClause *>(opaqueGenericWhereClause)) {
890
+ whereLoc = genericWhereClause->getWhereLoc ();
891
+ requirements = genericWhereClause->getRequirements ();
887
892
}
893
+
888
894
return GenericParamList::create (
889
- context , convertSourceLoc (cLAngleLoc ),
890
- convertArrayRef<GenericTypeParamDecl *>(params) ,
891
- convertSourceLoc (cWhereLoc), requirements, convertSourceLoc (cRAngleLoc ));
895
+ convertASTContext (cContext) , convertSourceLoc (cLeftAngleLoc ),
896
+ convertArrayRef<GenericTypeParamDecl *>(cParameters), whereLoc ,
897
+ requirements, convertSourceLoc (cRightAngleLoc ));
892
898
}
893
899
894
900
void *GenericTypeParamDecl_create (BridgedASTContext cContext,
@@ -913,6 +919,43 @@ void *GenericTypeParamDecl_create(BridgedASTContext cContext,
913
919
return decl;
914
920
}
915
921
922
+ void *TrailingWhereClause_create (BridgedASTContext cContext,
923
+ BridgedSourceLoc cWhereKeywordLoc,
924
+ BridgedArrayRef cRequirements) {
925
+ SmallVector<RequirementRepr> requirements;
926
+ for (auto &cReq : convertArrayRef<BridgedRequirementRepr>(cRequirements)) {
927
+ switch (cReq.Kind ) {
928
+ case BridgedRequirementReprKindTypeConstraint:
929
+ requirements.push_back (RequirementRepr::getTypeConstraint (
930
+ static_cast <TypeRepr *>(cReq.FirstType ),
931
+ convertSourceLoc (cReq.SeparatorLoc ),
932
+ static_cast <TypeRepr *>(cReq.SecondType ),
933
+ /* isExpansionPattern*/ false ));
934
+ break ;
935
+ case BridgedRequirementReprKindSameType:
936
+ requirements.push_back (
937
+ RequirementRepr::getSameType (static_cast <TypeRepr *>(cReq.FirstType ),
938
+ convertSourceLoc (cReq.SeparatorLoc ),
939
+ static_cast <TypeRepr *>(cReq.SecondType ),
940
+ /* isExpansionPattern*/ false ));
941
+ break ;
942
+ case BridgedRequirementReprKindLayoutConstraint:
943
+ llvm_unreachable (" cannot handle layout constraints!" );
944
+ }
945
+ }
946
+
947
+ SourceLoc whereKeywordLoc = convertSourceLoc (cWhereKeywordLoc);
948
+ SourceLoc endLoc;
949
+ if (requirements.empty ()) {
950
+ endLoc = whereKeywordLoc;
951
+ } else {
952
+ endLoc = requirements.back ().getSourceRange ().End ;
953
+ }
954
+
955
+ return TrailingWhereClause::create (convertASTContext (cContext),
956
+ whereKeywordLoc, endLoc, requirements);
957
+ }
958
+
916
959
void *ParameterList_create (BridgedASTContext cContext,
917
960
BridgedSourceLoc cLeftParenLoc,
918
961
BridgedArrayRef cParameters,
0 commit comments