@@ -191,7 +191,7 @@ static clang::CanQualType getClangVectorType(const clang::ASTContext &ctx,
191
191
clang::VectorType::VectorKind vecKind,
192
192
StringRef numEltsString) {
193
193
unsigned numElts;
194
- bool failedParse = numEltsString.getAsInteger < unsigned > (10 , numElts);
194
+ bool failedParse = numEltsString.getAsInteger (10 , numElts);
195
195
assert (!failedParse && " vector type name didn't end in count?" );
196
196
(void ) failedParse;
197
197
@@ -366,36 +366,33 @@ clang::CanQualType GenClangType::visitTupleType(CanTupleType type) {
366
366
return ctx.getCanonicalType (
367
367
ctx.getConstantArrayType (clangEltTy, size,
368
368
clang::ArrayType::Normal, 0 ));
369
-
370
- llvm_unreachable (" Unexpected tuple type in Clang type generation!" );
371
369
}
372
370
373
371
clang::CanQualType GenClangType::visitProtocolType (CanProtocolType type) {
374
372
auto proto = type->getDecl ();
373
+ auto &clangCtx = getClangASTContext ();
375
374
376
- // Single protocol -> id<Proto>
377
- if (proto->isObjC ()) {
378
- auto &clangCtx = getClangASTContext ();
379
- clang::IdentifierInfo *name = &clangCtx.Idents .get (proto->getName ().get ());
380
- auto *PDecl = clang::ObjCProtocolDecl::Create (
381
- const_cast <clang::ASTContext &>(clangCtx),
382
- clangCtx.getTranslationUnitDecl (), name,
383
- clang::SourceLocation (), clang::SourceLocation (), nullptr );
384
-
385
- // Attach an objc_runtime_name attribute with the Objective-C name to use
386
- // for this protocol.
387
- SmallString<64 > runtimeNameBuffer;
388
- PDecl->addAttr (clang::ObjCRuntimeNameAttr::CreateImplicit (
389
- PDecl->getASTContext (),
390
- proto->getObjCRuntimeName (runtimeNameBuffer)));
391
-
392
- auto clangType = clangCtx.getObjCObjectType (clangCtx.ObjCBuiltinIdTy ,
393
- &PDecl, 1 );
394
- auto ptrTy = clangCtx.getObjCObjectPointerType (clangType);
395
- return clangCtx.getCanonicalType (ptrTy);
396
- }
375
+ if (!proto->isObjC ())
376
+ return getClangIdType (clangCtx);
397
377
398
- return getClangIdType (getClangASTContext ());
378
+ // Single protocol -> id<Proto>
379
+ clang::IdentifierInfo *name = &clangCtx.Idents .get (proto->getName ().get ());
380
+ auto *PDecl = clang::ObjCProtocolDecl::Create (
381
+ const_cast <clang::ASTContext &>(clangCtx),
382
+ clangCtx.getTranslationUnitDecl (), name,
383
+ clang::SourceLocation (), clang::SourceLocation (), nullptr );
384
+
385
+ // Attach an objc_runtime_name attribute with the Objective-C name to use
386
+ // for this protocol.
387
+ SmallString<64 > runtimeNameBuffer;
388
+ PDecl->addAttr (clang::ObjCRuntimeNameAttr::CreateImplicit (
389
+ PDecl->getASTContext (),
390
+ proto->getObjCRuntimeName (runtimeNameBuffer)));
391
+
392
+ auto clangType = clangCtx.getObjCObjectType (clangCtx.ObjCBuiltinIdTy ,
393
+ &PDecl, 1 );
394
+ auto ptrTy = clangCtx.getObjCObjectPointerType (clangType);
395
+ return clangCtx.getCanonicalType (ptrTy);
399
396
}
400
397
401
398
clang::CanQualType GenClangType::visitMetatypeType (CanMetatypeType type) {
@@ -409,29 +406,30 @@ GenClangType::visitExistentialMetatypeType(CanExistentialMetatypeType type) {
409
406
410
407
clang::CanQualType GenClangType::visitClassType (CanClassType type) {
411
408
auto &clangCtx = getClangASTContext ();
412
- // produce the clang type INTF * if it is imported ObjC object.
413
409
auto swiftDecl = type->getDecl ();
414
- if (swiftDecl->isObjC ()) {
415
- clang::IdentifierInfo *ForwardClassId =
416
- &clangCtx.Idents .get (swiftDecl->getName ().get ());
417
- auto *CDecl = clang::ObjCInterfaceDecl::Create (
418
- clangCtx, clangCtx.getTranslationUnitDecl (),
419
- clang::SourceLocation (), ForwardClassId,
420
- /* typeParamList*/ nullptr , /* PrevDecl=*/ nullptr ,
421
- clang::SourceLocation ());
422
-
423
- // Attach an objc_runtime_name attribute with the Objective-C name to use
424
- // for this class.
425
- SmallString<64 > runtimeNameBuffer;
426
- CDecl->addAttr (clang::ObjCRuntimeNameAttr::CreateImplicit (
427
- CDecl->getASTContext (),
428
- swiftDecl->getObjCRuntimeName (runtimeNameBuffer)));
429
-
430
- auto clangType = clangCtx.getObjCInterfaceType (CDecl);
431
- auto ptrTy = clangCtx.getObjCObjectPointerType (clangType);
432
- return clangCtx.getCanonicalType (ptrTy);
433
- }
434
- return getClangIdType (clangCtx);
410
+
411
+ if (!swiftDecl->isObjC ())
412
+ return getClangIdType (clangCtx);
413
+
414
+ // produce the clang type INTF * if it is imported ObjC object.
415
+ clang::IdentifierInfo *ForwardClassId =
416
+ &clangCtx.Idents .get (swiftDecl->getName ().get ());
417
+ auto *CDecl = clang::ObjCInterfaceDecl::Create (
418
+ clangCtx, clangCtx.getTranslationUnitDecl (),
419
+ clang::SourceLocation (), ForwardClassId,
420
+ /* typeParamList*/ nullptr , /* PrevDecl=*/ nullptr ,
421
+ clang::SourceLocation ());
422
+
423
+ // Attach an objc_runtime_name attribute with the Objective-C name to use
424
+ // for this class.
425
+ SmallString<64 > runtimeNameBuffer;
426
+ CDecl->addAttr (clang::ObjCRuntimeNameAttr::CreateImplicit (
427
+ CDecl->getASTContext (),
428
+ swiftDecl->getObjCRuntimeName (runtimeNameBuffer)));
429
+
430
+ auto clangType = clangCtx.getObjCInterfaceType (CDecl);
431
+ auto ptrTy = clangCtx.getObjCObjectPointerType (clangType);
432
+ return clangCtx.getCanonicalType (ptrTy);
435
433
}
436
434
437
435
clang::CanQualType GenClangType::visitBoundGenericClassType (
@@ -443,8 +441,7 @@ clang::CanQualType GenClangType::visitBoundGenericClassType(
443
441
444
442
clang::CanQualType
445
443
GenClangType::visitBoundGenericType (CanBoundGenericType type) {
446
- // We only expect *Pointer<T>, ImplicitlyUnwrappedOptional<T>, and Optional<T>.
447
- // The first two are structs; the last is an enum.
444
+ // We only expect *Pointer<T>, SIMD*<T> and Optional<T>.
448
445
if (auto underlyingTy =
449
446
SILType::getPrimitiveObjectType (type).getOptionalObjectType ()) {
450
447
// The underlying type could be a bridged type, which makes any
@@ -685,15 +682,13 @@ clang::CanQualType GenClangType::visitBuiltinRawPointerType(
685
682
clang::CanQualType GenClangType::visitBuiltinIntegerType (
686
683
CanBuiltinIntegerType type) {
687
684
auto &ctx = getClangASTContext ();
688
- if (type->getWidth ().isPointerWidth ()) {
685
+ if (type->getWidth ().isPointerWidth ())
689
686
return ctx.getCanonicalType (ctx.getUIntPtrType ());
690
- }
691
- if (type->getWidth ().isFixedWidth ()) {
692
- auto width = type->getWidth ().getFixedWidth ();
693
- if (width == 1 ) return ctx.BoolTy ;
694
- return ctx.getCanonicalType (ctx.getIntTypeForBitwidth (width, /* signed*/ 0 ));
695
- }
696
- llvm_unreachable (" " );
687
+ assert (type->getWidth ().isFixedWidth ());
688
+ auto width = type->getWidth ().getFixedWidth ();
689
+ if (width == 1 )
690
+ return ctx.BoolTy ;
691
+ return ctx.getCanonicalType (ctx.getIntTypeForBitwidth (width, /* signed*/ 0 ));
697
692
}
698
693
699
694
clang::CanQualType GenClangType::visitBuiltinFloatType (
0 commit comments