@@ -434,12 +434,15 @@ class DeclAndTypePrinter::Implementation
434
434
435
435
os << " inline bool is" << name << " () const;\n " ;
436
436
437
+ outOfLineSyntaxPrinter
438
+ .printNominalTypeOutsideMemberDeclTemplateSpecifiers (ED);
437
439
outOfLineOS << " inline bool " ;
438
- outOfLineSyntaxPrinter.printBaseName (ED);
439
- outOfLineOS << " ::is" << name << " () const {\n " ;
440
+ outOfLineSyntaxPrinter.printNominalTypeQualifier (
441
+ ED, /* moduleContext=*/ ED->getModuleContext ());
442
+ outOfLineOS << " is" << name << " () const {\n " ;
440
443
outOfLineOS << " return *this == " ;
441
- outOfLineSyntaxPrinter.printBaseName (ED);
442
- outOfLineOS << " :: " ;
444
+ outOfLineSyntaxPrinter.printNominalTypeQualifier (
445
+ ED, /* moduleContext= */ ED-> getModuleContext ()) ;
443
446
outOfLineSyntaxPrinter.printIdentifier (caseName);
444
447
outOfLineOS << " ;\n " ;
445
448
outOfLineOS << " }\n " ;
@@ -464,6 +467,8 @@ class DeclAndTypePrinter::Implementation
464
467
ClangSyntaxPrinter (nameOS).printIdentifier (elementDecl->getNameStr ());
465
468
name[0 ] = std::toupper (name[0 ]);
466
469
470
+ if (ED->isGeneric ())
471
+ return ;
467
472
clangFuncPrinter.printCustomCxxFunction (
468
473
{paramType},
469
474
[&](auto &types) {
@@ -553,107 +558,115 @@ class DeclAndTypePrinter::Implementation
553
558
neededTypes.push_back (paramType);
554
559
}
555
560
556
- clangFuncPrinter.printCustomCxxFunction (
557
- neededTypes,
558
- [&](auto &types) {
559
- // Printing function name and return type
560
- os << " inline " ;
561
- syntaxPrinter.printBaseName (elementDecl->getParentEnum ());
562
- os << " operator()" ;
563
-
564
- outOfLineOS << " inline " ;
565
- outOfLineSyntaxPrinter.printBaseName (
566
- elementDecl->getParentEnum ());
567
- outOfLineOS << ' ' ;
568
- outOfLineSyntaxPrinter.printBaseName (
569
- elementDecl->getParentEnum ());
570
- outOfLineOS << " ::_impl_" << elementDecl->getNameStr ()
571
- << " ::operator()" ;
572
- },
573
- [&](auto &types) {
574
- // Printing parameters
575
- if (!paramType) {
576
- return ;
577
- }
578
- assert (objectTypeDecl != nullptr );
579
- if (owningPrinter.typeMapping .getKnownCxxTypeInfo (
580
- objectTypeDecl)) {
581
- os << types[paramType] << " val" ;
582
- outOfLineOS << types[paramType] << " val" ;
583
- } else {
584
- os << " const " << types[paramType] << " &val" ;
585
- outOfLineOS << " const " << types[paramType] << " &val" ;
586
- }
587
- },
588
- true ,
589
- [&](auto &types) {
590
- // Printing function body
591
- outOfLineOS << " auto result = " ;
592
- outOfLineSyntaxPrinter.printBaseName (
593
- elementDecl->getParentEnum ());
594
- outOfLineOS << " ::_make();\n " ;
595
-
596
- if (paramType) {
561
+ // FIXME: support generic constructor.
562
+ if (!ED->isGeneric ())
563
+ clangFuncPrinter.printCustomCxxFunction (
564
+ neededTypes,
565
+ [&](auto &types) {
566
+ // Printing function name and return type
567
+ os << " inline " ;
568
+ syntaxPrinter.printBaseName (elementDecl->getParentEnum ());
569
+ os << " operator()" ;
570
+
571
+ outOfLineOS << " inline " ;
572
+ outOfLineSyntaxPrinter.printBaseName (
573
+ elementDecl->getParentEnum ());
574
+ outOfLineOS << ' ' ;
575
+ outOfLineSyntaxPrinter.printBaseName (
576
+ elementDecl->getParentEnum ());
577
+ outOfLineOS << " ::_impl_" << elementDecl->getNameStr ()
578
+ << " ::operator()" ;
579
+ },
580
+ [&](auto &types) {
581
+ // Printing parameters
582
+ if (!paramType) {
583
+ return ;
584
+ }
597
585
assert (objectTypeDecl != nullptr );
598
-
599
586
if (owningPrinter.typeMapping .getKnownCxxTypeInfo (
600
587
objectTypeDecl)) {
601
- outOfLineOS << " memcpy(result._getOpaquePointer(), &val, "
602
- " sizeof(val));\n " ;
588
+ os << types[paramType] << " val" ;
589
+ outOfLineOS << types[paramType] << " val" ;
590
+ } else {
591
+ os << " const " << types[paramType] << " &val" ;
592
+ outOfLineOS << " const " << types[paramType] << " &val" ;
593
+ }
594
+ },
595
+ true ,
596
+ [&](auto &types) {
597
+ // Printing function body
598
+ outOfLineOS << " auto result = " ;
599
+ outOfLineSyntaxPrinter.printBaseName (
600
+ elementDecl->getParentEnum ());
601
+ outOfLineOS << " ::_make();\n " ;
602
+
603
+ if (paramType) {
604
+ assert (objectTypeDecl != nullptr );
605
+
606
+ if (owningPrinter.typeMapping .getKnownCxxTypeInfo (
607
+ objectTypeDecl)) {
608
+ outOfLineOS
609
+ << " memcpy(result._getOpaquePointer(), &val, "
610
+ " sizeof(val));\n " ;
611
+ } else {
612
+ outOfLineOS << " alignas(" ;
613
+ outOfLineSyntaxPrinter
614
+ .printModuleNamespaceQualifiersIfNeeded (
615
+ objectTypeDecl->getModuleContext (),
616
+ ED->getModuleContext ());
617
+ outOfLineSyntaxPrinter.printBaseName (objectTypeDecl);
618
+ outOfLineOS << " ) unsigned char buffer[sizeof(" ;
619
+ outOfLineSyntaxPrinter
620
+ .printModuleNamespaceQualifiersIfNeeded (
621
+ objectTypeDecl->getModuleContext (),
622
+ ED->getModuleContext ());
623
+ outOfLineSyntaxPrinter.printBaseName (objectTypeDecl);
624
+ outOfLineOS << " )];\n " ;
625
+ outOfLineOS << " auto *valCopy = new(buffer) " ;
626
+ outOfLineSyntaxPrinter
627
+ .printModuleNamespaceQualifiersIfNeeded (
628
+ objectTypeDecl->getModuleContext (),
629
+ ED->getModuleContext ());
630
+ outOfLineSyntaxPrinter.printBaseName (objectTypeDecl);
631
+ outOfLineOS << " (val);\n " ;
632
+ outOfLineOS << " " ;
633
+ outOfLineOS << cxx_synthesis::getCxxSwiftNamespaceName ()
634
+ << " ::" ;
635
+ outOfLineOS << cxx_synthesis::getCxxImplNamespaceName ();
636
+ outOfLineOS << " ::implClassFor<" ;
637
+ outOfLineSyntaxPrinter
638
+ .printModuleNamespaceQualifiersIfNeeded (
639
+ objectTypeDecl->getModuleContext (),
640
+ ED->getModuleContext ());
641
+ outOfLineSyntaxPrinter.printBaseName (objectTypeDecl);
642
+ outOfLineOS << " >::type::initializeWithTake(result._"
643
+ " getOpaquePointer(), " ;
644
+ outOfLineOS << cxx_synthesis::getCxxSwiftNamespaceName ()
645
+ << " ::" ;
646
+ outOfLineOS << cxx_synthesis::getCxxImplNamespaceName ();
647
+ outOfLineOS << " ::implClassFor<" ;
648
+ outOfLineSyntaxPrinter
649
+ .printModuleNamespaceQualifiersIfNeeded (
650
+ objectTypeDecl->getModuleContext (),
651
+ ED->getModuleContext ());
652
+ outOfLineSyntaxPrinter.printBaseName (objectTypeDecl);
653
+ outOfLineOS << " >::type::getOpaquePointer(*valCopy)" ;
654
+ outOfLineOS << " );\n " ;
655
+ }
656
+ }
657
+
658
+ outOfLineOS << " result._destructiveInjectEnumTag(" ;
659
+ if (ED->isResilient ()) {
660
+ outOfLineOS << cxx_synthesis::getCxxImplNamespaceName ()
661
+ << " ::" << elementInfo->globalVariableName ;
603
662
} else {
604
- outOfLineOS << " alignas(" ;
605
- outOfLineSyntaxPrinter.printModuleNamespaceQualifiersIfNeeded (
606
- objectTypeDecl->getModuleContext (),
607
- ED->getModuleContext ());
608
- outOfLineSyntaxPrinter.printBaseName (objectTypeDecl);
609
- outOfLineOS << " ) unsigned char buffer[sizeof(" ;
610
- outOfLineSyntaxPrinter.printModuleNamespaceQualifiersIfNeeded (
611
- objectTypeDecl->getModuleContext (),
612
- ED->getModuleContext ());
613
- outOfLineSyntaxPrinter.printBaseName (objectTypeDecl);
614
- outOfLineOS << " )];\n " ;
615
- outOfLineOS << " auto *valCopy = new(buffer) " ;
616
- outOfLineSyntaxPrinter.printModuleNamespaceQualifiersIfNeeded (
617
- objectTypeDecl->getModuleContext (),
618
- ED->getModuleContext ());
619
- outOfLineSyntaxPrinter.printBaseName (objectTypeDecl);
620
- outOfLineOS << " (val);\n " ;
621
- outOfLineOS << " " ;
622
- outOfLineOS << cxx_synthesis::getCxxSwiftNamespaceName ()
623
- << " ::" ;
624
- outOfLineOS << cxx_synthesis::getCxxImplNamespaceName ();
625
- outOfLineOS << " ::implClassFor<" ;
626
- outOfLineSyntaxPrinter.printModuleNamespaceQualifiersIfNeeded (
627
- objectTypeDecl->getModuleContext (),
628
- ED->getModuleContext ());
629
- outOfLineSyntaxPrinter.printBaseName (objectTypeDecl);
630
- outOfLineOS << " >::type::initializeWithTake(result._"
631
- " getOpaquePointer(), " ;
632
- outOfLineOS << cxx_synthesis::getCxxSwiftNamespaceName ()
633
- << " ::" ;
634
- outOfLineOS << cxx_synthesis::getCxxImplNamespaceName ();
635
- outOfLineOS << " ::implClassFor<" ;
636
- outOfLineSyntaxPrinter.printModuleNamespaceQualifiersIfNeeded (
637
- objectTypeDecl->getModuleContext (),
638
- ED->getModuleContext ());
639
- outOfLineSyntaxPrinter.printBaseName (objectTypeDecl);
640
- outOfLineOS << " >::type::getOpaquePointer(*valCopy)" ;
641
- outOfLineOS << " );\n " ;
663
+ outOfLineOS << elementInfo->tag ;
642
664
}
643
- }
644
-
645
- outOfLineOS << " result._destructiveInjectEnumTag(" ;
646
- if (ED->isResilient ()) {
647
- outOfLineOS << cxx_synthesis::getCxxImplNamespaceName ()
648
- << " ::" << elementInfo->globalVariableName ;
649
- } else {
650
- outOfLineOS << elementInfo->tag ;
651
- }
652
- outOfLineOS << " );\n " ;
653
- outOfLineOS << " return result;\n " ;
654
- outOfLineOS << " " ;
655
- },
656
- ED->getModuleContext (), outOfLineOS);
665
+ outOfLineOS << " );\n " ;
666
+ outOfLineOS << " return result;\n " ;
667
+ outOfLineOS << " " ;
668
+ },
669
+ ED->getModuleContext (), outOfLineOS);
657
670
}
658
671
os << " } " ;
659
672
syntaxPrinter.printIdentifier (caseName);
0 commit comments