@@ -123,9 +123,11 @@ const clang::ASTContext &clangCtx) {
123123
124124} // end anonymous namespace
125125
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) {
129131 auto resultClangTy =
130132 templateArgument ? convertTemplateArgument (resultTy) : convert (resultTy);
131133 if (resultClangTy.isNull ())
@@ -167,9 +169,11 @@ const clang::Type *ClangTypeConverter::getFunctionType(
167169 llvm_unreachable (" invalid representation" );
168170}
169171
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) {
173177 clang::QualType resultClangTy = ClangASTContext.VoidTy ;
174178 if (result) {
175179 // Using the interface type is sufficient as type parameters get mapped to
@@ -571,18 +575,18 @@ ClangTypeConverter::visitBoundGenericType(BoundGenericType *type) {
571575 }
572576
573577 if (auto kind = classifyPointer (type))
574- return convertPointerType (argType, kind. value () ,
575- /* templateArgument= */ false );
578+ return convertPointerType< /* templateArgument= */ false > (argType,
579+ kind. value () );
576580
577581 if (auto width = classifySIMD (type))
578- return convertSIMDType (argType, width.value (), /* templateArgument= */ false );
582+ return convertSIMDType< /* templateArgument= */ false > (argType, width.value ());
579583
580584 return clang::QualType ();
581585}
582586
587+ template <bool templateArgument>
583588clang::QualType ClangTypeConverter::convertSIMDType (CanType scalarType,
584- unsigned width,
585- bool templateArgument) {
589+ unsigned width) {
586590 clang::QualType scalarTy = templateArgument
587591 ? convertTemplateArgument (scalarType)
588592 : convert (scalarType);
@@ -594,9 +598,9 @@ clang::QualType ClangTypeConverter::convertSIMDType(CanType scalarType,
594598 return vectorTy;
595599}
596600
601+ template <bool templateArgument>
597602clang::QualType ClangTypeConverter::convertPointerType (CanType pointeeType,
598- PointerKind kind,
599- bool templateArgument) {
603+ PointerKind kind) {
600604 switch (kind) {
601605 case PointerKind::Unmanaged:
602606 return templateArgument ? clang::QualType () : convert (pointeeType);
@@ -657,8 +661,8 @@ clang::QualType ClangTypeConverter::visitEnumType(EnumType *type) {
657661 return convert (type->getDecl ()->getRawType ());
658662}
659663
660- clang::QualType ClangTypeConverter::visitFunctionType (FunctionType *type,
661- bool templateArgument ) {
664+ template < bool templateArgument>
665+ clang::QualType ClangTypeConverter::visitFunctionType (FunctionType *type ) {
662666 const clang::Type *clangTy = nullptr ;
663667 auto repr = type->getRepresentation ();
664668 bool useClangTypes = type->getASTContext ().LangOpts .UseClangFunctionTypes ;
@@ -672,15 +676,15 @@ clang::QualType ClangTypeConverter::visitFunctionType(FunctionType *type,
672676 auto newRepr = (repr == FunctionTypeRepresentation::Swift
673677 ? FunctionTypeRepresentation::Block
674678 : repr);
675- clangTy = getFunctionType (type->getParams (), type-> getResult (), newRepr ,
676- templateArgument );
679+ clangTy = getFunctionType<templateArgument> (type->getParams (),
680+ type-> getResult (), newRepr );
677681 }
678682 return clang::QualType (clangTy, 0 );
679683}
680684
685+ template <bool templateArgument>
681686clang::QualType
682- ClangTypeConverter::visitSILFunctionType (SILFunctionType *type,
683- bool templateArgument) {
687+ ClangTypeConverter::visitSILFunctionType (SILFunctionType *type) {
684688 const clang::Type *clangTy = nullptr ;
685689 auto repr = type->getRepresentation ();
686690 bool useClangTypes = type->getASTContext ().LangOpts .UseClangFunctionTypes ;
@@ -698,8 +702,8 @@ ClangTypeConverter::visitSILFunctionType(SILFunctionType *type,
698702 auto optionalResult = results.empty ()
699703 ? std::nullopt
700704 : std::optional<SILResultInfo>(results[0 ]);
701- clangTy = getFunctionType (type->getParameters (), optionalResult, newRepr ,
702- templateArgument );
705+ clangTy = getFunctionType<templateArgument> (type->getParameters (),
706+ optionalResult, newRepr );
703707 }
704708 return clang::QualType (clangTy, 0 );
705709}
@@ -984,8 +988,8 @@ clang::QualType ClangTypeConverter::convertTemplateArgument(Type type) {
984988 auto pointeeType = argType->getAs <BoundGenericType>()
985989 ->getGenericArgs ()[0 ]
986990 ->getCanonicalType ();
987- return convertPointerType (pointeeType, kind. value () ,
988- /* templateArgument= */ true );
991+ return convertPointerType< /* templateArgument= */ true > (pointeeType,
992+ kind. value () );
989993 });
990994
991995 // Arbitrary optional types are not (yet) supported
@@ -994,28 +998,28 @@ clang::QualType ClangTypeConverter::convertTemplateArgument(Type type) {
994998
995999 if (auto kind = classifyPointer (boundGenericType))
9961000 return withCache ([&]() {
997- return convertPointerType (argType, kind. value () ,
998- /* templateArgument= */ true );
1001+ return convertPointerType< /* templateArgument= */ true > (argType,
1002+ kind. value () );
9991003 });
10001004
10011005 if (auto width = classifySIMD (boundGenericType))
10021006 return withCache ([&]() {
1003- return convertSIMDType (argType, width. value () ,
1004- /* templateArgument= */ true );
1007+ return convertSIMDType< /* templateArgument= */ true > (argType,
1008+ width. value () );
10051009 });
10061010
10071011 return clang::QualType ();
10081012 }
10091013
10101014 if (auto functionType = type->getAs <FunctionType>()) {
10111015 return withCache ([&]() {
1012- return visitFunctionType (functionType, /* templateArgument=*/ true );
1016+ return visitFunctionType< /* templateArgument=*/ true >(functionType );
10131017 });
10141018 }
10151019
10161020 if (auto functionType = type->getAs <SILFunctionType>()) {
10171021 return withCache ([&]() {
1018- return visitSILFunctionType (functionType, /* templateArgument=*/ true );
1022+ return visitSILFunctionType< /* templateArgument=*/ true >(functionType );
10191023 });
10201024 }
10211025
0 commit comments