@@ -565,7 +565,8 @@ ClangTypeConverter::visitBoundGenericType(BoundGenericType *type) {
565
565
}
566
566
567
567
if (auto kind = classifyPointer (type))
568
- return convertPointerType (argType, kind.value (), /* templateArgument=*/ false );
568
+ return convertPointerType (argType, kind.value (),
569
+ /* templateArgument=*/ false );
569
570
570
571
if (auto width = classifySIMD (type))
571
572
return convertSIMDType (argType, width.value (), /* templateArgument=*/ false );
@@ -576,8 +577,9 @@ ClangTypeConverter::visitBoundGenericType(BoundGenericType *type) {
576
577
clang::QualType ClangTypeConverter::convertSIMDType (CanType scalarType,
577
578
unsigned width,
578
579
bool templateArgument) {
579
- clang::QualType scalarTy = templateArgument ? convertTemplateArgument (scalarType)
580
- : convert (scalarType);
580
+ clang::QualType scalarTy = templateArgument
581
+ ? convertTemplateArgument (scalarType)
582
+ : convert (scalarType);
581
583
if (scalarTy.isNull ())
582
584
return clang::QualType ();
583
585
@@ -599,13 +601,15 @@ clang::QualType ClangTypeConverter::convertPointerType(CanType pointeeType,
599
601
LLVM_FALLTHROUGH;
600
602
601
603
case PointerKind::UnsafeMutablePointer: {
602
- auto clangTy = templateArgument ? convertTemplateArgument (pointeeType) : convert (pointeeType);
604
+ auto clangTy = templateArgument ? convertTemplateArgument (pointeeType)
605
+ : convert (pointeeType);
603
606
if (clangTy.isNull ())
604
607
return clang::QualType ();
605
608
return ClangASTContext.getPointerType (clangTy);
606
609
}
607
610
case PointerKind::UnsafePointer: {
608
- auto clangTy = templateArgument ? convertTemplateArgument (pointeeType) : convert (pointeeType);
611
+ auto clangTy = templateArgument ? convertTemplateArgument (pointeeType)
612
+ : convert (pointeeType);
609
613
if (clangTy.isNull ())
610
614
return clang::QualType ();
611
615
return ClangASTContext.getPointerType (clangTy.withConst ());
@@ -958,8 +962,11 @@ clang::QualType ClangTypeConverter::convertTemplateArgument(Type type) {
958
962
if (boundGenericType->getDecl ()->isOptionalDecl ()) {
959
963
if (auto kind = classifyPointer (argType))
960
964
return withCache ([&]() {
961
- auto pointeeType = argType->getAs <BoundGenericType>()->getGenericArgs ()[0 ]->getCanonicalType ();
962
- return convertPointerType (pointeeType, kind.value (), /* templateArgument=*/ true );
965
+ auto pointeeType = argType->getAs <BoundGenericType>()
966
+ ->getGenericArgs ()[0 ]
967
+ ->getCanonicalType ();
968
+ return convertPointerType (pointeeType, kind.value (),
969
+ /* templateArgument=*/ true );
963
970
});
964
971
965
972
// Arbitrary optional types are not (yet) supported
@@ -968,12 +975,14 @@ clang::QualType ClangTypeConverter::convertTemplateArgument(Type type) {
968
975
969
976
if (auto kind = classifyPointer (boundGenericType))
970
977
return withCache ([&]() {
971
- return convertPointerType (argType, kind.value (), /* templateArgument=*/ true );
978
+ return convertPointerType (argType, kind.value (),
979
+ /* templateArgument=*/ true );
972
980
});
973
981
974
982
if (auto width = classifySIMD (boundGenericType))
975
983
return withCache ([&]() {
976
- return convertSIMDType (argType, width.value (), /* templateArgument=*/ true );
984
+ return convertSIMDType (argType, width.value (),
985
+ /* templateArgument=*/ true );
977
986
});
978
987
979
988
return clang::QualType ();
@@ -1025,20 +1034,22 @@ ClangTypeConverter::getClangTemplateArguments(
1025
1034
return errorInfo;
1026
1035
}
1027
1036
1028
- std::optional<ClangTypeConverter::PointerKind> ClangTypeConverter::classifyPointer (Type type) {
1037
+ std::optional<ClangTypeConverter::PointerKind>
1038
+ ClangTypeConverter::classifyPointer (Type type) {
1029
1039
auto generic = type->getAs <BoundGenericType>();
1030
1040
if (!generic || generic->getGenericArgs ().size () != 1 )
1031
1041
// Must have got something other than a *Pointer<T>
1032
1042
return std::nullopt;
1033
1043
1034
- return llvm::StringSwitch<std::optional<PointerKind>>(generic->getDecl ()->getName ().str ())
1035
- .Case (" UnsafeMutablePointer" , PointerKind::UnsafeMutablePointer)
1036
- .Case (" UnsafePointer" , PointerKind::UnsafePointer)
1037
- .Case (" AutoreleasingUnsafeMutablePointer" ,
1038
- PointerKind::AutoreleasingUnsafeMutablePointer)
1039
- .Case (" Unmanaged" , PointerKind::Unmanaged)
1040
- .Case (" CFunctionPointer" , PointerKind::CFunctionPointer)
1041
- .Default (std::nullopt);
1044
+ return llvm::StringSwitch<std::optional<PointerKind>>(
1045
+ generic->getDecl ()->getName ().str ())
1046
+ .Case (" UnsafeMutablePointer" , PointerKind::UnsafeMutablePointer)
1047
+ .Case (" UnsafePointer" , PointerKind::UnsafePointer)
1048
+ .Case (" AutoreleasingUnsafeMutablePointer" ,
1049
+ PointerKind::AutoreleasingUnsafeMutablePointer)
1050
+ .Case (" Unmanaged" , PointerKind::Unmanaged)
1051
+ .Case (" CFunctionPointer" , PointerKind::CFunctionPointer)
1052
+ .Default (std::nullopt);
1042
1053
}
1043
1054
1044
1055
std::optional<unsigned > ClangTypeConverter::classifySIMD (Type type) {
@@ -1051,7 +1062,7 @@ std::optional<unsigned> ClangTypeConverter::classifySIMD(Type type) {
1051
1062
if (!name.starts_with (" SIMD" ))
1052
1063
return std::nullopt;
1053
1064
name.consume_front (" SIMD" );
1054
-
1065
+
1055
1066
unsigned width;
1056
1067
if (/* failed to*/ name.getAsInteger <unsigned >(10 , width))
1057
1068
return std::nullopt;
0 commit comments