@@ -259,6 +259,44 @@ static bool isSignToken(const clang::Token &tok) {
259
259
tok.is (clang::tok::tilde);
260
260
}
261
261
262
+ static Optional<clang::QualType> builtinTypeForToken (const clang::Token &tok,
263
+ const clang::ASTContext &context) {
264
+ switch (tok.getKind ()) {
265
+ case clang::tok::kw_short:
266
+ return clang::QualType (context.ShortTy );
267
+ case clang::tok::kw_long:
268
+ return clang::QualType (context.LongTy );
269
+ case clang::tok::kw___int64:
270
+ return clang::QualType (context.LongLongTy );
271
+ case clang::tok::kw___int128:
272
+ return clang::QualType (context.Int128Ty );
273
+ case clang::tok::kw_signed:
274
+ return clang::QualType (context.IntTy );
275
+ case clang::tok::kw_unsigned:
276
+ return clang::QualType (context.UnsignedIntTy );
277
+ case clang::tok::kw_void:
278
+ return clang::QualType (context.VoidTy );
279
+ case clang::tok::kw_char:
280
+ return clang::QualType (context.CharTy );
281
+ case clang::tok::kw_int:
282
+ return clang::QualType (context.IntTy );
283
+ case clang::tok::kw_float:
284
+ return clang::QualType (context.FloatTy );
285
+ case clang::tok::kw_double:
286
+ return clang::QualType (context.DoubleTy );
287
+ case clang::tok::kw_wchar_t :
288
+ return clang::QualType (context.WCharTy );
289
+ case clang::tok::kw_bool:
290
+ return clang::QualType (context.BoolTy );
291
+ case clang::tok::kw_char16_t :
292
+ return clang::QualType (context.Char16Ty );
293
+ case clang::tok::kw_char32_t :
294
+ return clang::QualType (context.Char32Ty );
295
+ default :
296
+ return llvm::None;
297
+ }
298
+ }
299
+
262
300
static ValueDecl *importMacro (ClangImporter::Implementation &impl,
263
301
DeclContext *DC,
264
302
Identifier name,
@@ -284,27 +322,36 @@ static ValueDecl *importMacro(ClangImporter::Implementation &impl,
284
322
clang::QualType castClangType;
285
323
if (numTokens > 3 &&
286
324
tokenI[0 ].is (clang::tok::l_paren) &&
287
- tokenI[1 ].is (clang::tok::identifier) &&
325
+ (tokenI[1 ].is (clang::tok::identifier) ||
326
+ impl.getClangSema ().isSimpleTypeSpecifier (tokenI[1 ].getKind ())) &&
288
327
tokenI[2 ].is (clang::tok::r_paren)) {
289
328
if (castType) {
290
329
// this is a nested cast
291
330
return nullptr ;
292
331
}
293
332
294
- auto identifierInfo = tokenI[1 ].getIdentifierInfo ();
295
- if (identifierInfo->isStr (" id" )) {
296
- castTypeIsId = true ;
297
- }
298
- auto identifierName = identifierInfo->getName ();
299
- auto &identifier = impl.getClangASTContext ().Idents .get (identifierName);
300
- auto parsedType = impl.getClangSema ().getTypeName (identifier,
301
- clang::SourceLocation (),
302
- /* scope*/ nullptr );
303
- if (parsedType) {
304
- castClangType = parsedType.get ();
305
- castType = &castClangType;
333
+ if (tokenI[1 ].is (clang::tok::identifier)) {
334
+ auto identifierInfo = tokenI[1 ].getIdentifierInfo ();
335
+ if (identifierInfo->isStr (" id" )) {
336
+ castTypeIsId = true ;
337
+ }
338
+ auto identifierName = identifierInfo->getName ();
339
+ auto &identifier = impl.getClangASTContext ().Idents .get (identifierName);
340
+ auto parsedType = impl.getClangSema ().getTypeName (identifier,
341
+ clang::SourceLocation (),
342
+ /* scope*/ nullptr );
343
+ if (parsedType) {
344
+ castClangType = parsedType.get ();
345
+ castType = &castClangType;
346
+ } else {
347
+ return nullptr ;
348
+ }
306
349
} else {
307
- return nullptr ;
350
+ auto builtinType = builtinTypeForToken (tokenI[1 ],
351
+ impl.getClangASTContext ());
352
+ if (builtinType) {
353
+ castType = &builtinType.getValue ();
354
+ }
308
355
}
309
356
tokenI += 3 ;
310
357
numTokens -= 3 ;
0 commit comments