@@ -594,15 +594,12 @@ class PrintAST : public ASTVisitor<PrintAST> {
594
594
bool openBracket = true , bool closeBracket = true );
595
595
void printNominalDeclGenericParams (NominalTypeDecl *decl);
596
596
void printNominalDeclGenericRequirements (NominalTypeDecl *decl);
597
- void printInherited (const Decl *decl,
598
- ArrayRef<TypeLoc> inherited,
599
- ArrayRef<ProtocolDecl *> protos,
600
- Type superclass = {});
601
-
602
- void printInherited (const NominalTypeDecl *decl);
603
- void printInherited (const EnumDecl *D);
604
- void printInherited (const ExtensionDecl *decl);
597
+ void printInherited (const Decl *decl, ArrayRef<TypeLoc> inherited);
598
+
599
+ void printInherited (const NominalTypeDecl *D);
600
+ void printInherited (const ExtensionDecl *D);
605
601
void printInherited (const GenericTypeParamDecl *D);
602
+ void printInherited (const AssociatedTypeDecl *D);
606
603
607
604
void printEnumElement (EnumElementDecl *elt);
608
605
@@ -1659,93 +1656,55 @@ void PrintAST::printNominalDeclGenericRequirements(NominalTypeDecl *decl) {
1659
1656
printGenericSignature (GenericSig, PrintRequirements | InnermostOnly);
1660
1657
}
1661
1658
1662
- void PrintAST::printInherited (const Decl *decl,
1663
- ArrayRef<TypeLoc> inherited,
1664
- ArrayRef<ProtocolDecl *> protos,
1665
- Type superclass) {
1666
- if (inherited.empty () && superclass.isNull ()) {
1667
- if (protos.empty ())
1668
- return ;
1669
- }
1670
-
1671
- if (inherited.empty ()) {
1672
- bool PrintedColon = false ;
1673
- bool PrintedInherited = false ;
1674
-
1675
- if (superclass) {
1676
- bool ShouldPrintSuper = true ;
1677
- if (auto NTD = superclass->getAnyNominal ()) {
1678
- ShouldPrintSuper = shouldPrint (NTD);
1679
- }
1680
- if (ShouldPrintSuper) {
1681
- Printer << " : " ;
1682
- superclass.print (Printer, Options);
1683
- PrintedInherited = true ;
1684
- }
1659
+ void PrintAST::printInherited (const Decl *decl, ArrayRef<TypeLoc> inherited) {
1660
+ SmallVector<TypeLoc, 6 > TypesToPrint;
1661
+ for (auto TL : inherited) {
1662
+ if (auto Ty = TL.getType ()) {
1663
+ if (auto NTD = Ty->getAnyNominal ())
1664
+ if (!shouldPrint (NTD))
1665
+ continue ;
1685
1666
}
1667
+ TypesToPrint.push_back (TL);
1668
+ }
1686
1669
1687
- for (auto Proto : protos) {
1688
- if (!shouldPrint (Proto))
1670
+ auto &ctx = decl->getASTContext ();
1671
+ for (auto attr : decl->getAttrs ().getAttributes <SynthesizedProtocolAttr>()) {
1672
+ if (auto *proto = ctx.getProtocol (attr->getProtocolKind ())) {
1673
+ if (!shouldPrint (proto))
1689
1674
continue ;
1690
- if (auto Enum = dyn_cast<EnumDecl>(decl)) {
1691
- // Conformance to RawRepresentable is implied by having a raw type.
1692
- if (Enum->hasRawType ()
1693
- && Proto->isSpecificProtocol (KnownProtocolKind::RawRepresentable))
1694
- continue ;
1695
- // Conformance to Equatable and Hashable is implied by being a "simple"
1696
- // no-payload enum with cases.
1697
- if (Enum->hasCases ()
1698
- && Enum->hasOnlyCasesWithoutAssociatedValues ()
1699
- && (Proto->isSpecificProtocol (KnownProtocolKind::Equatable)
1700
- || Proto->isSpecificProtocol (KnownProtocolKind::Hashable)))
1701
- continue ;
1702
- }
1703
-
1704
- if (PrintedInherited)
1705
- Printer << " , " ;
1706
- else if (!PrintedColon)
1707
- Printer << " : " ;
1708
- Proto->getDeclaredType ()->print (Printer, Options);
1709
- PrintedInherited = true ;
1710
- PrintedColon = true ;
1711
- }
1712
- } else {
1713
- SmallVector<TypeLoc, 6 > TypesToPrint;
1714
- for (auto TL : inherited) {
1715
- if (auto Ty = TL.getType ()) {
1716
- if (auto NTD = Ty->getAnyNominal ())
1717
- if (!shouldPrint (NTD))
1718
- continue ;
1719
- }
1720
- TypesToPrint.push_back (TL);
1675
+ if (attr->getProtocolKind () == KnownProtocolKind::RawRepresentable &&
1676
+ isa<EnumDecl>(decl) &&
1677
+ cast<EnumDecl>(decl)->hasRawType ())
1678
+ continue ;
1679
+ TypesToPrint.push_back (TypeLoc::withoutLoc (proto->getDeclaredType ()));
1721
1680
}
1722
- if (TypesToPrint.empty ())
1723
- return ;
1681
+ }
1682
+ if (TypesToPrint.empty ())
1683
+ return ;
1724
1684
1725
- Printer << " : " ;
1685
+ Printer << " : " ;
1726
1686
1727
- interleave (TypesToPrint, [&](TypeLoc TL) {
1728
- printTypeLoc (TL);
1729
- }, [&]() {
1730
- Printer << " , " ;
1731
- });
1732
- }
1687
+ interleave (TypesToPrint, [&](TypeLoc TL) {
1688
+ printTypeLoc (TL);
1689
+ }, [&]() {
1690
+ Printer << " , " ;
1691
+ });
1733
1692
}
1734
1693
1735
- void PrintAST::printInherited (const NominalTypeDecl *decl ) {
1736
- printInherited (decl, decl ->getInherited (), { }, nullptr );
1694
+ void PrintAST::printInherited (const NominalTypeDecl *D ) {
1695
+ printInherited (D, D ->getInherited ());
1737
1696
}
1738
1697
1739
- void PrintAST::printInherited (const EnumDecl *decl ) {
1740
- printInherited (decl, decl ->getInherited (), { } );
1698
+ void PrintAST::printInherited (const ExtensionDecl *D ) {
1699
+ printInherited (D, D ->getInherited ());
1741
1700
}
1742
1701
1743
- void PrintAST::printInherited (const ExtensionDecl *decl ) {
1744
- printInherited (decl, decl ->getInherited (), { } );
1702
+ void PrintAST::printInherited (const GenericTypeParamDecl *D ) {
1703
+ printInherited (D, D ->getInherited ());
1745
1704
}
1746
1705
1747
- void PrintAST::printInherited (const GenericTypeParamDecl *D) {
1748
- printInherited (D, D->getInherited (), { } );
1706
+ void PrintAST::printInherited (const AssociatedTypeDecl *D) {
1707
+ printInherited (D, D->getInherited ());
1749
1708
}
1750
1709
1751
1710
static void getModuleEntities (const clang::Module *ClangMod,
@@ -2022,7 +1981,7 @@ void PrintAST::visitGenericTypeParamDecl(GenericTypeParamDecl *decl) {
2022
1981
Printer.printName (decl->getName (), PrintNameContext::GenericParameter);
2023
1982
});
2024
1983
2025
- printInherited (decl, decl-> getInherited (), { } );
1984
+ printInherited (decl);
2026
1985
}
2027
1986
2028
1987
void PrintAST::visitAssociatedTypeDecl (AssociatedTypeDecl *decl) {
@@ -2039,7 +1998,7 @@ void PrintAST::visitAssociatedTypeDecl(AssociatedTypeDecl *decl) {
2039
1998
if (proto->isRequirementSignatureComputed ()) {
2040
1999
printInheritedFromRequirementSignature (proto, decl);
2041
2000
} else {
2042
- printInherited (decl, decl-> getInherited (), { } );
2001
+ printInherited (decl);
2043
2002
}
2044
2003
2045
2004
if (!decl->getDefaultDefinitionLoc ().isNull ()) {
0 commit comments