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