@@ -543,25 +543,29 @@ class DeclAndTypePrinter::Implementation
543
543
std::tie (objectType, optKind) = getObjectTypeAndOptionality (
544
544
paramType->getNominalOrBoundGenericNominal (), paramType);
545
545
auto objectTypeDecl = objectType->getNominalOrBoundGenericNominal ();
546
+ assert (objectTypeDecl != nullptr || paramType->isOptional ());
546
547
547
- if (auto knownCxxType =
548
- owningPrinter.typeMapping .getKnownCxxTypeInfo (
549
- objectTypeDecl)) {
548
+ if (objectTypeDecl &&
549
+ owningPrinter.typeMapping .getKnownCxxTypeInfo (objectTypeDecl)) {
550
550
outOfLineOS << " " << types[paramType] << " result;\n " ;
551
551
outOfLineOS << " "
552
552
" memcpy(&result, payloadFromDestruction, "
553
553
" sizeof(result));\n " ;
554
554
outOfLineOS << " return result;\n " ;
555
555
} else {
556
+ bool isOptional = false ;
557
+ if (!objectTypeDecl) {
558
+ objectTypeDecl = paramType->getNominalOrBoundGenericNominal ();
559
+ isOptional = true ;
560
+ }
556
561
outOfLineOS << " return swift::" ;
557
562
outOfLineOS << cxx_synthesis::getCxxImplNamespaceName ();
558
563
outOfLineOS << " ::implClassFor<" ;
559
- outOfLineSyntaxPrinter.printModuleNamespaceQualifiersIfNeeded (
560
- objectTypeDecl-> getModuleContext () ,
564
+ outOfLineSyntaxPrinter.printNominalTypeReference (
565
+ objectTypeDecl,
561
566
elementDecl->getParentEnum ()->getModuleContext ());
562
- outOfLineSyntaxPrinter.printBaseName (objectTypeDecl);
563
567
outOfLineOS << " >::type" ;
564
- if (isa<ClassDecl>(objectTypeDecl)) {
568
+ if (!isOptional && isa<ClassDecl>(objectTypeDecl)) {
565
569
outOfLineOS << " ::makeRetained(*reinterpret_cast<void "
566
570
" **>(payloadFromDestruction));\n " ;
567
571
} else {
@@ -570,10 +574,9 @@ class DeclAndTypePrinter::Implementation
570
574
outOfLineOS << " swift::"
571
575
<< cxx_synthesis::getCxxImplNamespaceName ();
572
576
outOfLineOS << " ::implClassFor<" ;
573
- outOfLineSyntaxPrinter.printModuleNamespaceQualifiersIfNeeded (
574
- objectTypeDecl-> getModuleContext () ,
577
+ outOfLineSyntaxPrinter.printNominalTypeReference (
578
+ objectTypeDecl,
575
579
elementDecl->getParentEnum ()->getModuleContext ());
576
- outOfLineSyntaxPrinter.printBaseName (objectTypeDecl);
577
580
outOfLineOS << " >::type" ;
578
581
outOfLineOS << " ::initializeWithTake(result, "
579
582
" payloadFromDestruction);\n " ;
@@ -707,14 +710,15 @@ class DeclAndTypePrinter::Implementation
707
710
ED, paramType);
708
711
auto objectTypeDecl =
709
712
objectType->getNominalOrBoundGenericNominal ();
710
- assert (objectTypeDecl != nullptr );
713
+ assert (objectTypeDecl != nullptr || paramType-> isOptional () );
711
714
712
- if (owningPrinter.typeMapping .getKnownCxxTypeInfo (
715
+ if (objectTypeDecl &&
716
+ owningPrinter.typeMapping .getKnownCxxTypeInfo (
713
717
objectTypeDecl)) {
714
718
outOfLineOS
715
719
<< " memcpy(result._getOpaquePointer(), &val, "
716
720
" sizeof(val));\n " ;
717
- } else if (isa <ClassDecl>(objectTypeDecl)) {
721
+ } else if (isa_and_nonnull <ClassDecl>(objectTypeDecl)) {
718
722
outOfLineOS
719
723
<< " auto op = swift::"
720
724
<< cxx_synthesis::getCxxImplNamespaceName ()
@@ -725,46 +729,31 @@ class DeclAndTypePrinter::Implementation
725
729
objectTypeDecl =
726
730
paramType->getNominalOrBoundGenericNominal ();
727
731
outOfLineOS << " alignas(" ;
728
- outOfLineSyntaxPrinter
729
- .printModuleNamespaceQualifiersIfNeeded (
730
- objectTypeDecl->getModuleContext (),
731
- ED->getModuleContext ());
732
- outOfLineSyntaxPrinter.printBaseName (objectTypeDecl);
732
+ outOfLineSyntaxPrinter.printNominalTypeReference (
733
+ objectTypeDecl, ED->getModuleContext ());
733
734
outOfLineOS << " ) unsigned char buffer[sizeof(" ;
734
- outOfLineSyntaxPrinter
735
- .printModuleNamespaceQualifiersIfNeeded (
736
- objectTypeDecl->getModuleContext (),
737
- ED->getModuleContext ());
738
- outOfLineSyntaxPrinter.printBaseName (objectTypeDecl);
735
+ outOfLineSyntaxPrinter.printNominalTypeReference (
736
+ objectTypeDecl, ED->getModuleContext ());
739
737
outOfLineOS << " )];\n " ;
740
738
outOfLineOS << " auto *valCopy = new(buffer) " ;
741
- outOfLineSyntaxPrinter
742
- .printModuleNamespaceQualifiersIfNeeded (
743
- objectTypeDecl->getModuleContext (),
744
- ED->getModuleContext ());
745
- outOfLineSyntaxPrinter.printBaseName (objectTypeDecl);
739
+ outOfLineSyntaxPrinter.printNominalTypeReference (
740
+ objectTypeDecl, ED->getModuleContext ());
746
741
outOfLineOS << " (val);\n " ;
747
742
outOfLineOS << " " ;
748
743
outOfLineOS << cxx_synthesis::getCxxSwiftNamespaceName ()
749
744
<< " ::" ;
750
745
outOfLineOS << cxx_synthesis::getCxxImplNamespaceName ();
751
746
outOfLineOS << " ::implClassFor<" ;
752
- outOfLineSyntaxPrinter
753
- .printModuleNamespaceQualifiersIfNeeded (
754
- objectTypeDecl->getModuleContext (),
755
- ED->getModuleContext ());
756
- outOfLineSyntaxPrinter.printBaseName (objectTypeDecl);
747
+ outOfLineSyntaxPrinter.printNominalTypeReference (
748
+ objectTypeDecl, ED->getModuleContext ());
757
749
outOfLineOS << " >::type::initializeWithTake(result._"
758
750
" getOpaquePointer(), " ;
759
751
outOfLineOS << cxx_synthesis::getCxxSwiftNamespaceName ()
760
752
<< " ::" ;
761
753
outOfLineOS << cxx_synthesis::getCxxImplNamespaceName ();
762
754
outOfLineOS << " ::implClassFor<" ;
763
- outOfLineSyntaxPrinter
764
- .printModuleNamespaceQualifiersIfNeeded (
765
- objectTypeDecl->getModuleContext (),
766
- ED->getModuleContext ());
767
- outOfLineSyntaxPrinter.printBaseName (objectTypeDecl);
755
+ outOfLineSyntaxPrinter.printNominalTypeReference (
756
+ objectTypeDecl, ED->getModuleContext ());
768
757
outOfLineOS << " >::type::getOpaquePointer(*valCopy)" ;
769
758
outOfLineOS << " );\n " ;
770
759
}
@@ -2912,9 +2901,6 @@ static bool isEnumExposableToCxx(const ValueDecl *VD,
2912
2901
if (auto *params = elementDecl->getParameterList ()) {
2913
2902
for (const auto *param : *params) {
2914
2903
auto paramType = param->getInterfaceType ();
2915
- // TODO: properly support exporting these optionals. rdar://131112273
2916
- if (paramType->isOptional () && paramType->getOptionalObjectType ()->isTypeParameter ())
2917
- return false ;
2918
2904
if (DeclAndTypeClangFunctionPrinter::getTypeRepresentation (
2919
2905
printer.getTypeMapping (), printer.getInteropContext (),
2920
2906
printer, enumDecl->getModuleContext (), paramType)
0 commit comments