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