@@ -544,13 +544,33 @@ namespace {
544
544
545
545
explicit PrintDecl (raw_ostream &os, unsigned indent = 0 )
546
546
: OS(os), Indent(indent) { }
547
-
547
+
548
+ private:
548
549
void printRec (Decl *D) { PrintDecl (OS, Indent + 2 ).visit (D); }
549
550
void printRec (Expr *E) { E->dump (OS, Indent+2 ); }
550
551
void printRec (Stmt *S, const ASTContext &Ctx) { S->dump (OS, &Ctx, Indent+2 ); }
551
552
void printRec (Pattern *P) { PrintPattern (OS, Indent+2 ).visit (P); }
552
553
void printRec (TypeRepr *T);
553
554
555
+ void printWhereRequirements (
556
+ PointerUnion<const AssociatedTypeDecl *, const GenericContext *> Owner)
557
+ const {
558
+ const auto printWhere = [&](const TrailingWhereClause *Where) {
559
+ if (Where) {
560
+ OS << " where requirements: " ;
561
+ Where->print (OS, /* printWhereKeyword*/ false );
562
+ }
563
+ };
564
+
565
+ if (const auto GC = Owner.dyn_cast <const GenericContext *>()) {
566
+ if (!GC->isGeneric () || isa<ProtocolDecl>(GC))
567
+ printWhere (GC->getTrailingWhereClause ());
568
+ } else {
569
+ const auto ATD = Owner.get <const AssociatedTypeDecl *>();
570
+ printWhere (ATD->getTrailingWhereClause ());
571
+ }
572
+ }
573
+
554
574
// Print a field with a value.
555
575
template <typename T>
556
576
raw_ostream &printField (StringRef name, const T &value) {
@@ -588,6 +608,7 @@ namespace {
588
608
[&] { OS << " , " ; });
589
609
}
590
610
611
+ public:
591
612
void visitImportDecl (ImportDecl *ID) {
592
613
printCommon (ID, " import_decl" );
593
614
@@ -610,12 +631,7 @@ namespace {
610
631
printCommon (ED, " extension_decl" , ExtensionColor);
611
632
OS << ' ' ;
612
633
ED->getExtendedType ().print (OS);
613
- printInherited (ED->getInherited ());
614
- for (Decl *Member : ED->getMembers ()) {
615
- OS << ' \n ' ;
616
- printRec (Member);
617
- }
618
- PrintWithColorRAII (OS, ParenthesisColor) << ' )' ;
634
+ printCommonPost (ED);
619
635
}
620
636
621
637
void printDeclName (const ValueDecl *D) {
@@ -637,6 +653,7 @@ namespace {
637
653
} else {
638
654
PrintWithColorRAII (OS, TypeColor) << " <<<unresolved>>>" ;
639
655
}
656
+ printWhereRequirements (TAD);
640
657
PrintWithColorRAII (OS, ParenthesisColor) << ' )' ;
641
658
}
642
659
@@ -680,10 +697,7 @@ namespace {
680
697
OS << " default=" ;
681
698
defaultDef.print (OS);
682
699
}
683
- if (auto whereClause = decl->getTrailingWhereClause ()) {
684
- OS << " where requirements: " ;
685
- whereClause->print (OS, /* printWhereKeyword*/ false );
686
- }
700
+ printWhereRequirements (decl);
687
701
if (decl->overriddenDeclsComputed ()) {
688
702
OS << " overridden=" ;
689
703
interleave (decl->getOverriddenDecls (),
@@ -708,19 +722,7 @@ namespace {
708
722
} else {
709
723
OS << " <null>" ;
710
724
}
711
- printInherited (PD->getInherited ());
712
- if (auto whereClause = PD->getTrailingWhereClause ()) {
713
- OS << " where requirements: " ;
714
- interleave (whereClause->getRequirements (),
715
- [&](const RequirementRepr &req) { req.print (OS); },
716
- [&] { OS << " , " ; });
717
- }
718
-
719
- for (auto VD : PD->getMembers ()) {
720
- OS << ' \n ' ;
721
- printRec (VD);
722
- }
723
- PrintWithColorRAII (OS, ParenthesisColor) << ' )' ;
725
+ printCommonPost (PD);
724
726
}
725
727
726
728
void printCommon (ValueDecl *VD, const char *Name,
@@ -796,6 +798,28 @@ namespace {
796
798
}
797
799
}
798
800
801
+ void printCommonPost (const IterableDeclContext *IDC) {
802
+ switch (IDC->getIterableContextKind ()) {
803
+ case IterableDeclContextKind::NominalTypeDecl: {
804
+ const auto NTD = cast<NominalTypeDecl>(IDC);
805
+ printInherited (NTD->getInherited ());
806
+ printWhereRequirements (NTD);
807
+ break ;
808
+ }
809
+ case IterableDeclContextKind::ExtensionDecl:
810
+ const auto ED = cast<ExtensionDecl>(IDC);
811
+ printInherited (ED->getInherited ());
812
+ printWhereRequirements (ED);
813
+ break ;
814
+ }
815
+
816
+ for (Decl *D : IDC->getMembers ()) {
817
+ OS << ' \n ' ;
818
+ printRec (D);
819
+ }
820
+ PrintWithColorRAII (OS, ParenthesisColor) << ' )' ;
821
+ }
822
+
799
823
void visitSourceFile (const SourceFile &SF) {
800
824
OS.indent (Indent);
801
825
PrintWithColorRAII (OS, ParenthesisColor) << ' (' ;
@@ -870,12 +894,7 @@ namespace {
870
894
871
895
void visitEnumDecl (EnumDecl *ED) {
872
896
printCommon (ED, " enum_decl" );
873
- printInherited (ED->getInherited ());
874
- for (Decl *D : ED->getMembers ()) {
875
- OS << ' \n ' ;
876
- printRec (D);
877
- }
878
- PrintWithColorRAII (OS, ParenthesisColor) << ' )' ;
897
+ printCommonPost (ED);
879
898
}
880
899
881
900
void visitEnumElementDecl (EnumElementDecl *EED) {
@@ -885,24 +904,14 @@ namespace {
885
904
886
905
void visitStructDecl (StructDecl *SD) {
887
906
printCommon (SD, " struct_decl" );
888
- printInherited (SD->getInherited ());
889
- for (Decl *D : SD->getMembers ()) {
890
- OS << ' \n ' ;
891
- printRec (D);
892
- }
893
- PrintWithColorRAII (OS, ParenthesisColor) << ' )' ;
907
+ printCommonPost (SD);
894
908
}
895
909
896
910
void visitClassDecl (ClassDecl *CD) {
897
911
printCommon (CD, " class_decl" );
898
912
if (CD->getAttrs ().hasAttribute <StaticInitializeObjCMetadataAttr>())
899
913
OS << " @_staticInitializeObjCMetadata" ;
900
- printInherited (CD->getInherited ());
901
- for (Decl *D : CD->getMembers ()) {
902
- OS << ' \n ' ;
903
- printRec (D);
904
- }
905
- PrintWithColorRAII (OS, ParenthesisColor) << ' )' ;
914
+ printCommonPost (CD);
906
915
}
907
916
908
917
void visitPatternBindingDecl (PatternBindingDecl *PBD) {
0 commit comments