@@ -123,9 +123,11 @@ const clang::ASTContext &clangCtx) {
123
123
124
124
} // end anonymous namespace
125
125
126
- const clang::Type *ClangTypeConverter::getFunctionType (
127
- ArrayRef<AnyFunctionType::Param> params, Type resultTy,
128
- AnyFunctionType::Representation repr, bool templateArgument) {
126
+ template <bool templateArgument>
127
+ const clang::Type *
128
+ ClangTypeConverter::getFunctionType (ArrayRef<AnyFunctionType::Param> params,
129
+ Type resultTy,
130
+ AnyFunctionType::Representation repr) {
129
131
auto resultClangTy =
130
132
templateArgument ? convertTemplateArgument (resultTy) : convert (resultTy);
131
133
if (resultClangTy.isNull ())
@@ -167,9 +169,11 @@ const clang::Type *ClangTypeConverter::getFunctionType(
167
169
llvm_unreachable (" invalid representation" );
168
170
}
169
171
170
- const clang::Type *ClangTypeConverter::getFunctionType (
171
- ArrayRef<SILParameterInfo> params, std::optional<SILResultInfo> result,
172
- SILFunctionType::Representation repr, bool templateArgument) {
172
+ template <bool templateArgument>
173
+ const clang::Type *
174
+ ClangTypeConverter::getFunctionType (ArrayRef<SILParameterInfo> params,
175
+ std::optional<SILResultInfo> result,
176
+ SILFunctionType::Representation repr) {
173
177
clang::QualType resultClangTy = ClangASTContext.VoidTy ;
174
178
if (result) {
175
179
// Using the interface type is sufficient as type parameters get mapped to
@@ -571,18 +575,18 @@ ClangTypeConverter::visitBoundGenericType(BoundGenericType *type) {
571
575
}
572
576
573
577
if (auto kind = classifyPointer (type))
574
- return convertPointerType (argType, kind. value () ,
575
- /* templateArgument= */ false );
578
+ return convertPointerType< /* templateArgument= */ false > (argType,
579
+ kind. value () );
576
580
577
581
if (auto width = classifySIMD (type))
578
- return convertSIMDType (argType, width.value (), /* templateArgument= */ false );
582
+ return convertSIMDType< /* templateArgument= */ false > (argType, width.value ());
579
583
580
584
return clang::QualType ();
581
585
}
582
586
587
+ template <bool templateArgument>
583
588
clang::QualType ClangTypeConverter::convertSIMDType (CanType scalarType,
584
- unsigned width,
585
- bool templateArgument) {
589
+ unsigned width) {
586
590
clang::QualType scalarTy = templateArgument
587
591
? convertTemplateArgument (scalarType)
588
592
: convert (scalarType);
@@ -594,9 +598,9 @@ clang::QualType ClangTypeConverter::convertSIMDType(CanType scalarType,
594
598
return vectorTy;
595
599
}
596
600
601
+ template <bool templateArgument>
597
602
clang::QualType ClangTypeConverter::convertPointerType (CanType pointeeType,
598
- PointerKind kind,
599
- bool templateArgument) {
603
+ PointerKind kind) {
600
604
switch (kind) {
601
605
case PointerKind::Unmanaged:
602
606
return templateArgument ? clang::QualType () : convert (pointeeType);
@@ -657,8 +661,8 @@ clang::QualType ClangTypeConverter::visitEnumType(EnumType *type) {
657
661
return convert (type->getDecl ()->getRawType ());
658
662
}
659
663
660
- clang::QualType ClangTypeConverter::visitFunctionType (FunctionType *type,
661
- bool templateArgument ) {
664
+ template < bool templateArgument>
665
+ clang::QualType ClangTypeConverter::visitFunctionType (FunctionType *type ) {
662
666
const clang::Type *clangTy = nullptr ;
663
667
auto repr = type->getRepresentation ();
664
668
bool useClangTypes = type->getASTContext ().LangOpts .UseClangFunctionTypes ;
@@ -672,15 +676,15 @@ clang::QualType ClangTypeConverter::visitFunctionType(FunctionType *type,
672
676
auto newRepr = (repr == FunctionTypeRepresentation::Swift
673
677
? FunctionTypeRepresentation::Block
674
678
: repr);
675
- clangTy = getFunctionType (type->getParams (), type-> getResult (), newRepr ,
676
- templateArgument );
679
+ clangTy = getFunctionType<templateArgument> (type->getParams (),
680
+ type-> getResult (), newRepr );
677
681
}
678
682
return clang::QualType (clangTy, 0 );
679
683
}
680
684
685
+ template <bool templateArgument>
681
686
clang::QualType
682
- ClangTypeConverter::visitSILFunctionType (SILFunctionType *type,
683
- bool templateArgument) {
687
+ ClangTypeConverter::visitSILFunctionType (SILFunctionType *type) {
684
688
const clang::Type *clangTy = nullptr ;
685
689
auto repr = type->getRepresentation ();
686
690
bool useClangTypes = type->getASTContext ().LangOpts .UseClangFunctionTypes ;
@@ -698,8 +702,8 @@ ClangTypeConverter::visitSILFunctionType(SILFunctionType *type,
698
702
auto optionalResult = results.empty ()
699
703
? std::nullopt
700
704
: std::optional<SILResultInfo>(results[0 ]);
701
- clangTy = getFunctionType (type->getParameters (), optionalResult, newRepr ,
702
- templateArgument );
705
+ clangTy = getFunctionType<templateArgument> (type->getParameters (),
706
+ optionalResult, newRepr );
703
707
}
704
708
return clang::QualType (clangTy, 0 );
705
709
}
@@ -984,8 +988,8 @@ clang::QualType ClangTypeConverter::convertTemplateArgument(Type type) {
984
988
auto pointeeType = argType->getAs <BoundGenericType>()
985
989
->getGenericArgs ()[0 ]
986
990
->getCanonicalType ();
987
- return convertPointerType (pointeeType, kind. value () ,
988
- /* templateArgument= */ true );
991
+ return convertPointerType< /* templateArgument= */ true > (pointeeType,
992
+ kind. value () );
989
993
});
990
994
991
995
// Arbitrary optional types are not (yet) supported
@@ -994,28 +998,28 @@ clang::QualType ClangTypeConverter::convertTemplateArgument(Type type) {
994
998
995
999
if (auto kind = classifyPointer (boundGenericType))
996
1000
return withCache ([&]() {
997
- return convertPointerType (argType, kind. value () ,
998
- /* templateArgument= */ true );
1001
+ return convertPointerType< /* templateArgument= */ true > (argType,
1002
+ kind. value () );
999
1003
});
1000
1004
1001
1005
if (auto width = classifySIMD (boundGenericType))
1002
1006
return withCache ([&]() {
1003
- return convertSIMDType (argType, width. value () ,
1004
- /* templateArgument= */ true );
1007
+ return convertSIMDType< /* templateArgument= */ true > (argType,
1008
+ width. value () );
1005
1009
});
1006
1010
1007
1011
return clang::QualType ();
1008
1012
}
1009
1013
1010
1014
if (auto functionType = type->getAs <FunctionType>()) {
1011
1015
return withCache ([&]() {
1012
- return visitFunctionType (functionType, /* templateArgument=*/ true );
1016
+ return visitFunctionType< /* templateArgument=*/ true >(functionType );
1013
1017
});
1014
1018
}
1015
1019
1016
1020
if (auto functionType = type->getAs <SILFunctionType>()) {
1017
1021
return withCache ([&]() {
1018
- return visitSILFunctionType (functionType, /* templateArgument=*/ true );
1022
+ return visitSILFunctionType< /* templateArgument=*/ true >(functionType );
1019
1023
});
1020
1024
}
1021
1025
0 commit comments