@@ -667,24 +667,41 @@ namespace {
667
667
if (!decl) return Visit (type->desugar ());
668
668
669
669
Type mappedType = getAdjustedTypeDeclReferenceType (decl);
670
- ImportHint hint = ImportHint::None;
671
670
672
671
if (getSwiftNewtypeAttr (type->getDecl (), Impl.CurrentVersion )) {
673
672
if (isCFTypeDecl (type->getDecl ())) {
674
- hint = ImportHint::SwiftNewtypeFromCFPointer;
675
- } else {
673
+ return {mappedType, ImportHint::SwiftNewtypeFromCFPointer};
674
+ }
675
+
676
+ auto underlying = Visit (type->getDecl ()->getUnderlyingType ());
677
+ switch (underlying.Hint ) {
678
+ case ImportHint::None:
679
+ case ImportHint::Void:
680
+ case ImportHint::Block:
681
+ case ImportHint::CFPointer:
682
+ case ImportHint::ObjCPointer:
683
+ case ImportHint::CFunctionPointer:
684
+ case ImportHint::OtherPointer:
685
+ case ImportHint::SwiftNewtypeFromCFPointer:
686
+ return {mappedType, underlying.Hint };
687
+
688
+ case ImportHint::BOOL:
689
+ case ImportHint::Boolean:
690
+ case ImportHint::NSUInteger:
691
+ // Toss out the special rules for these types; we still want to
692
+ // import as a wrapper.
693
+ return {mappedType, ImportHint::None};
694
+
695
+ case ImportHint::ObjCBridged:
676
696
// If the underlying type was bridged, the wrapper type is
677
- // only useful in bridged cases.
678
- auto underlying = Visit (type->getDecl ()->getUnderlyingType ());
679
- if (underlying.Hint == ImportHint::ObjCBridged) {
680
- return { underlying.AbstractType ,
681
- ImportHint (ImportHint::ObjCBridged, mappedType) };
682
- }
683
- hint = underlying.Hint ;
697
+ // only useful in bridged cases. Exit early.
698
+ return { underlying.AbstractType ,
699
+ ImportHint (ImportHint::ObjCBridged, mappedType) };
684
700
}
701
+ }
685
702
686
703
// For certain special typedefs, we don't want to use the imported type.
687
- } else if (auto specialKind = Impl.getSpecialTypedefKind (type->getDecl ())) {
704
+ if (auto specialKind = Impl.getSpecialTypedefKind (type->getDecl ())) {
688
705
switch (specialKind.getValue ()) {
689
706
case MappedTypeNameKind::DoNothing:
690
707
case MappedTypeNameKind::DefineAndUse:
@@ -696,6 +713,7 @@ namespace {
696
713
break ;
697
714
}
698
715
716
+ ImportHint hint = ImportHint::None;
699
717
if (type->getDecl ()->getName () == " BOOL" ) {
700
718
hint = ImportHint::BOOL;
701
719
} else if (type->getDecl ()->getName () == " Boolean" ) {
@@ -711,64 +729,62 @@ namespace {
711
729
hint = ImportHint::OtherPointer;
712
730
}
713
731
// Any other interesting mapped types should be hinted here.
732
+ return { mappedType, hint };
733
+ }
714
734
715
735
// Otherwise, recurse on the underlying type. We need to recompute
716
736
// the hint, and if the typedef uses different bridgeability than the
717
737
// context then we may also need to bypass the typedef.
718
- } else {
719
- auto underlyingType = type->desugar ();
738
+ auto underlyingType = type->desugar ();
720
739
721
- // Figure out the bridgeability we would normally use for this typedef.
722
- auto typedefBridgeability =
740
+ // Figure out the bridgeability we would normally use for this typedef.
741
+ auto typedefBridgeability =
723
742
getTypedefBridgeability (type->getDecl (), underlyingType);
724
743
725
- // Figure out the typedef we should actually use.
726
- auto underlyingBridgeability = Bridging;
727
- SwiftTypeConverter innerConverter (Impl, AllowNSUIntegerAsInt,
728
- underlyingBridgeability);
729
- auto underlyingResult = innerConverter.Visit (underlyingType);
730
-
731
- // If we used different bridgeability than this typedef normally
732
- // would because we're in a non-bridgeable context, and therefore
733
- // the underlying type is different from the mapping of the typedef,
734
- // use the underlying type.
735
- if (underlyingBridgeability != typedefBridgeability &&
736
- !underlyingResult.AbstractType ->isEqual (mappedType)) {
737
- return underlyingResult;
738
- }
744
+ // Figure out the typedef we should actually use.
745
+ auto underlyingBridgeability = Bridging;
746
+ SwiftTypeConverter innerConverter (Impl, AllowNSUIntegerAsInt,
747
+ underlyingBridgeability);
748
+ auto underlyingResult = innerConverter.Visit (underlyingType);
749
+
750
+ // If we used different bridgeability than this typedef normally
751
+ // would because we're in a non-bridgeable context, and therefore
752
+ // the underlying type is different from the mapping of the typedef,
753
+ // use the underlying type.
754
+ if (underlyingBridgeability != typedefBridgeability &&
755
+ !underlyingResult.AbstractType ->isEqual (mappedType)) {
756
+ return underlyingResult;
757
+ }
739
758
740
759
#ifndef NDEBUG
741
- switch (underlyingResult.Hint ) {
742
- case ImportHint::Block:
743
- case ImportHint::ObjCBridged:
744
- // Bridging is fine for Objective-C and blocks.
760
+ switch (underlyingResult.Hint ) {
761
+ case ImportHint::Block:
762
+ case ImportHint::ObjCBridged:
763
+ // Bridging is fine for Objective-C and blocks.
764
+ break ;
765
+ case ImportHint::NSUInteger:
766
+ // NSUInteger might be imported as Int rather than UInt depending
767
+ // on where the import lives.
768
+ if (underlyingResult.AbstractType ->getAnyNominal () ==
769
+ Impl.SwiftContext .getIntDecl ())
745
770
break ;
746
- case ImportHint::NSUInteger:
747
- // NSUInteger might be imported as Int rather than UInt depending
748
- // on where the import lives.
749
- if (underlyingResult.AbstractType ->getAnyNominal () ==
750
- Impl.SwiftContext .getIntDecl ())
751
- break ;
752
- LLVM_FALLTHROUGH;
753
- default :
754
- if (!underlyingResult.AbstractType ->isEqual (mappedType)) {
755
- underlyingResult.AbstractType ->dump ();
756
- mappedType->dump ();
757
- }
758
- assert (underlyingResult.AbstractType ->isEqual (mappedType) &&
759
- " typedef without special typedef kind was mapped "
760
- " differently from its underlying type?" );
771
+ LLVM_FALLTHROUGH;
772
+ default :
773
+ if (!underlyingResult.AbstractType ->isEqual (mappedType)) {
774
+ underlyingResult.AbstractType ->dump ();
775
+ mappedType->dump ();
761
776
}
777
+ assert (underlyingResult.AbstractType ->isEqual (mappedType) &&
778
+ " typedef without special typedef kind was mapped "
779
+ " differently from its underlying type?" );
780
+ }
762
781
#endif
763
- hint = underlyingResult.Hint ;
764
782
765
- // If the imported typealias is unavailable, return the
766
- // underlying type.
767
- if (decl->getAttrs ().isUnavailable (Impl.SwiftContext ))
768
- mappedType = underlyingResult.AbstractType ;
769
- }
783
+ // If the imported typealias is unavailable, return the underlying type.
784
+ if (decl->getAttrs ().isUnavailable (Impl.SwiftContext ))
785
+ return underlyingResult;
770
786
771
- return { mappedType, hint };
787
+ return { mappedType, underlyingResult. Hint };
772
788
}
773
789
774
790
#define SUGAR_TYPE (KIND ) \
0 commit comments