@@ -2201,6 +2201,37 @@ ImportedName NameImporter::importNameImpl(const clang::NamedDecl *D,
2201
2201
return importNameImpl (classTemplateSpecDecl->getSpecializedTemplate (),
2202
2202
version, givenName);
2203
2203
if (!isa<clang::ClassTemplatePartialSpecializationDecl>(D)) {
2204
+ auto getSwiftBuiltinTypeName =
2205
+ [&](const clang::BuiltinType *builtin) -> std::optional<StringRef> {
2206
+ Type swiftType = nullptr ;
2207
+ switch (builtin->getKind ()) {
2208
+ case clang::BuiltinType::Void:
2209
+ swiftType = swiftCtx.getNamedSwiftType (swiftCtx.getStdlibModule (),
2210
+ " Void" );
2211
+ break ;
2212
+ #define MAP_BUILTIN_TYPE (CLANG_BUILTIN_KIND, SWIFT_TYPE_NAME ) \
2213
+ case clang::BuiltinType::CLANG_BUILTIN_KIND: \
2214
+ swiftType = swiftCtx.getNamedSwiftType (swiftCtx.getStdlibModule (), \
2215
+ #SWIFT_TYPE_NAME); \
2216
+ break ;
2217
+ #define MAP_BUILTIN_CCHAR_TYPE (CLANG_BUILTIN_KIND, SWIFT_TYPE_NAME ) \
2218
+ case clang::BuiltinType::CLANG_BUILTIN_KIND: \
2219
+ swiftType = swiftCtx.getNamedSwiftType (swiftCtx.getStdlibModule (), \
2220
+ #SWIFT_TYPE_NAME); \
2221
+ break ;
2222
+ #include " swift/ClangImporter/BuiltinMappedTypes.def"
2223
+ default :
2224
+ break ;
2225
+ }
2226
+
2227
+ if (swiftType) {
2228
+ if (auto nominal = swiftType->getAs <NominalType>()) {
2229
+ return nominal->getDecl ()->getNameStr ();
2230
+ }
2231
+ }
2232
+ return std::nullopt;
2233
+ };
2234
+
2204
2235
// When constructing the name of a C++ template, don't expand all the
2205
2236
// template, only expand one layer. Here we want to prioritize
2206
2237
// readability over total completeness.
@@ -2210,38 +2241,16 @@ ImportedName NameImporter::importNameImpl(const clang::NamedDecl *D,
2210
2241
buffer << " <" ;
2211
2242
llvm::interleaveComma (classTemplateSpecDecl->getTemplateArgs ().asArray (),
2212
2243
buffer,
2213
- [&buffer, this , version](const clang::TemplateArgument& arg) {
2244
+ [&buffer, this , version, &getSwiftBuiltinTypeName ](const clang::TemplateArgument& arg) {
2214
2245
// Use import name here so builtin types such as "int" map to their
2215
2246
// Swift equivalent ("Int32").
2216
2247
if (arg.getKind () == clang::TemplateArgument::Type) {
2217
2248
auto ty = arg.getAsType ().getTypePtr ();
2218
2249
if (auto builtin = dyn_cast<clang::BuiltinType>(ty)) {
2219
2250
auto &ctx = swiftCtx;
2220
- Type swiftType = nullptr ;
2221
- switch (builtin->getKind ()) {
2222
- case clang::BuiltinType::Void:
2223
- swiftType = ctx.getNamedSwiftType (ctx.getStdlibModule (), " Void" );
2224
- break ;
2225
- #define MAP_BUILTIN_TYPE (CLANG_BUILTIN_KIND, SWIFT_TYPE_NAME ) \
2226
- case clang::BuiltinType::CLANG_BUILTIN_KIND: \
2227
- swiftType = ctx.getNamedSwiftType (ctx.getStdlibModule (), \
2228
- #SWIFT_TYPE_NAME); \
2229
- break ;
2230
- #define MAP_BUILTIN_CCHAR_TYPE (CLANG_BUILTIN_KIND, SWIFT_TYPE_NAME ) \
2231
- case clang::BuiltinType::CLANG_BUILTIN_KIND: \
2232
- swiftType = ctx.getNamedSwiftType (ctx.getStdlibModule (), \
2233
- #SWIFT_TYPE_NAME); \
2234
- break ;
2235
- #include " swift/ClangImporter/BuiltinMappedTypes.def"
2236
- default :
2237
- break ;
2238
- }
2239
-
2240
- if (swiftType) {
2241
- if (auto nominal = dyn_cast<NominalType>(swiftType->getCanonicalType ())) {
2242
- buffer << nominal->getDecl ()->getNameStr ();
2243
- return ;
2244
- }
2251
+ if (auto swiftTypeName = getSwiftBuiltinTypeName (builtin)) {
2252
+ buffer << *swiftTypeName;
2253
+ return ;
2245
2254
}
2246
2255
} else {
2247
2256
// FIXME: Generalize this to cover pointer to
@@ -2282,6 +2291,16 @@ ImportedName NameImporter::importNameImpl(const clang::NamedDecl *D,
2282
2291
return ;
2283
2292
}
2284
2293
}
2294
+ } else if (arg.getKind () == clang::TemplateArgument::Integral) {
2295
+ buffer << " _" ;
2296
+ if (arg.getIntegralType ()->isBuiltinType ()) {
2297
+ if (auto swiftTypeName = getSwiftBuiltinTypeName (
2298
+ arg.getIntegralType ()->getAs <clang::BuiltinType>())) {
2299
+ buffer << *swiftTypeName << " _" ;
2300
+ }
2301
+ }
2302
+ arg.getAsIntegral ().print (buffer, true );
2303
+ return ;
2285
2304
}
2286
2305
buffer << " _" ;
2287
2306
});
0 commit comments