1212
1313#include " DeclAndTypePrinter.h"
1414#include " CxxSynthesis.h"
15+ #include " PrimitiveTypeMapping.h"
1516
1617#include " swift/AST/ASTContext.h"
1718#include " swift/AST/ASTMangler.h"
@@ -1442,7 +1443,7 @@ class DeclAndTypePrinter::Implementation
14421443 // / Otherwise returns null.
14431444 const ClassDecl *getObjCBridgedClass (const NominalTypeDecl *nominal) {
14441445 // Print known types as their unbridged type.
1445- if (getKnownTypeInfo (nominal))
1446+ if (owningPrinter. typeMapping . getKnownObjCTypeInfo (nominal))
14461447 return nullptr ;
14471448
14481449 // Print imported bridgeable decls as their unbridged type.
@@ -1546,102 +1547,6 @@ class DeclAndTypePrinter::Implementation
15461547 return false ;
15471548 }
15481549
1549- // / If \p typeDecl is one of the standard library types used to map in Clang
1550- // / primitives and basic types, return the info in \c specialNames containing
1551- // / the Clang name and whether it can be nullable in C.
1552- Optional<CTypeInfo> getKnownTypeInfo (const TypeDecl *typeDecl) {
1553- auto &specialNames = owningPrinter.specialNames ;
1554- if (specialNames.empty ()) {
1555- ASTContext &ctx = getASTContext ();
1556- #define MAP (SWIFT_NAME, CLANG_REPR, NEEDS_NULLABILITY ) \
1557- specialNames[{ctx.StdlibModuleName , ctx.getIdentifier (#SWIFT_NAME)}] = \
1558- { CLANG_REPR, NEEDS_NULLABILITY }
1559-
1560- MAP (CBool, " bool" , false );
1561-
1562- MAP (CChar, " char" , false );
1563- MAP (CWideChar, " wchar_t" , false );
1564- MAP (CChar16, " char16_t" , false );
1565- MAP (CChar32, " char32_t" , false );
1566-
1567- MAP (CSignedChar, " signed char" , false );
1568- MAP (CShort, " short" , false );
1569- MAP (CInt, " int" , false );
1570- MAP (CLong, " long" , false );
1571- MAP (CLongLong, " long long" , false );
1572-
1573- MAP (CUnsignedChar, " unsigned char" , false );
1574- MAP (CUnsignedShort, " unsigned short" , false );
1575- MAP (CUnsignedInt, " unsigned int" , false );
1576- MAP (CUnsignedLong, " unsigned long" , false );
1577- MAP (CUnsignedLongLong, " unsigned long long" , false );
1578-
1579- MAP (CFloat, " float" , false );
1580- MAP (CDouble, " double" , false );
1581-
1582- MAP (Int8, " int8_t" , false );
1583- MAP (Int16, " int16_t" , false );
1584- MAP (Int32, " int32_t" , false );
1585- MAP (Int64, " int64_t" , false );
1586- MAP (UInt8, " uint8_t" , false );
1587- MAP (UInt16, " uint16_t" , false );
1588- MAP (UInt32, " uint32_t" , false );
1589- MAP (UInt64, " uint64_t" , false );
1590-
1591- MAP (Float, " float" , false );
1592- MAP (Double, " double" , false );
1593- MAP (Float32, " float" , false );
1594- MAP (Float64, " double" , false );
1595-
1596- MAP (Int, " NSInteger" , false );
1597- MAP (UInt, " NSUInteger" , false );
1598- MAP (Bool, " BOOL" , false );
1599-
1600- MAP (OpaquePointer, " void *" , true );
1601- MAP (UnsafeRawPointer, " void const *" , true );
1602- MAP (UnsafeMutableRawPointer, " void *" , true );
1603-
1604- Identifier ID_ObjectiveC = ctx.Id_ObjectiveC ;
1605- specialNames[{ID_ObjectiveC, ctx.getIdentifier (" ObjCBool" )}]
1606- = { " BOOL" , false };
1607- specialNames[{ID_ObjectiveC, ctx.getIdentifier (" Selector" )}]
1608- = { " SEL" , true };
1609- specialNames[{ID_ObjectiveC,
1610- ctx.getIdentifier (
1611- ctx.getSwiftName (KnownFoundationEntity::NSZone))}]
1612- = { " struct _NSZone *" , true };
1613-
1614- specialNames[{ctx.Id_Darwin , ctx.getIdentifier (" DarwinBoolean" )}]
1615- = { " Boolean" , false };
1616-
1617- specialNames[{ctx.Id_CoreGraphics , ctx.Id_CGFloat }]
1618- = { " CGFloat" , false };
1619-
1620- specialNames[{ctx.Id_CoreFoundation , ctx.Id_CGFloat }]
1621- = { " CGFloat" , false };
1622-
1623- // Use typedefs we set up for SIMD vector types.
1624- #define MAP_SIMD_TYPE (BASENAME, _, __ ) \
1625- specialNames[{ctx.Id_simd , ctx.getIdentifier (#BASENAME " 2" )}] \
1626- = { " swift_" #BASENAME " 2" , false }; \
1627- specialNames[{ctx.Id_simd , ctx.getIdentifier (#BASENAME " 3" )}] \
1628- = { " swift_" #BASENAME " 3" , false }; \
1629- specialNames[{ctx.Id_simd , ctx.getIdentifier (#BASENAME " 4" )}] \
1630- = { " swift_" #BASENAME " 4" , false };
1631- #include " swift/ClangImporter/SIMDMappedTypes.def"
1632- static_assert (SWIFT_MAX_IMPORTED_SIMD_ELEMENTS == 4 ,
1633- " must add or remove special name mappings if max number of "
1634- " SIMD elements is changed" );
1635- }
1636-
1637- Identifier moduleName = typeDecl->getModuleContext ()->getName ();
1638- Identifier name = typeDecl->getName ();
1639- auto iter = specialNames.find ({moduleName, name});
1640- if (iter == specialNames.end ())
1641- return None;
1642- return iter->second ;
1643- }
1644-
16451550 // / If \p typeDecl is one of the standard library types used to map in Clang
16461551 // / primitives and basic types, print out the appropriate spelling and
16471552 // / return true.
@@ -1650,7 +1555,8 @@ class DeclAndTypePrinter::Implementation
16501555 // / for interfacing with C and Objective-C.
16511556 bool printIfKnownSimpleType (const TypeDecl *typeDecl,
16521557 Optional<OptionalTypeKind> optionalKind) {
1653- Optional<CTypeInfo> knownTypeInfo = getKnownTypeInfo (typeDecl);
1558+ auto knownTypeInfo =
1559+ owningPrinter.typeMapping .getKnownObjCTypeInfo (typeDecl);
16541560 if (!knownTypeInfo)
16551561 return false ;
16561562 os << knownTypeInfo->name ;
0 commit comments