@@ -472,6 +472,14 @@ class CFunctionSignatureTypePrinter
472472 return visitPart (ds->getSelfType (), optionalKind, isInOutParam);
473473 }
474474
475+ ClangRepresentation visitMetatypeType (MetatypeType *mt,
476+ Optional<OptionalTypeKind> optionalKind,
477+ bool isInOutParam) {
478+ if (typeUseKind == FunctionSignatureTypeUse::TypeReference)
479+ return visitPart (mt->getInstanceType (), optionalKind, isInOutParam);
480+ return ClangRepresentation::unsupported;
481+ }
482+
475483 ClangRepresentation visitPart (Type Ty,
476484 Optional<OptionalTypeKind> optionalKind,
477485 bool isInOutParam) {
@@ -1056,7 +1064,7 @@ void DeclAndTypeClangFunctionPrinter::printCxxThunkBody(
10561064 const AbstractFunctionDecl *FD, const LoweredFunctionSignature &signature,
10571065 StringRef swiftSymbolName, const NominalTypeDecl *typeDeclContext,
10581066 const ModuleDecl *moduleContext, Type resultTy, const ParameterList *params,
1059- bool hasThrows, const AnyFunctionType *funcType) {
1067+ bool hasThrows, const AnyFunctionType *funcType, bool isStaticMethod ) {
10601068 if (typeDeclContext)
10611069 ClangSyntaxPrinter (os).printNominalTypeOutsideMemberDeclInnerStaticAssert (
10621070 typeDeclContext);
@@ -1085,15 +1093,15 @@ void DeclAndTypeClangFunctionPrinter::printCxxThunkBody(
10851093 emitNewParam ();
10861094 std::string paramName;
10871095 if (param.isSelfParameter ()) {
1088- bool needsStaticSelf = isa<ConstructorDecl>(FD);
1096+ bool needsStaticSelf = isa<ConstructorDecl>(FD) || isStaticMethod ;
10891097 if (needsStaticSelf) {
10901098 os << " swift::TypeMetadataTrait<" ;
10911099 CFunctionSignatureTypePrinter typePrinter (
10921100 os, cPrologueOS, typeMapping, OutputLanguageMode::Cxx,
10931101 interopContext, CFunctionSignatureTypePrinterModifierDelegate (),
10941102 moduleContext, declPrinter,
10951103 FunctionSignatureTypeUse::TypeReference);
1096- auto result = typePrinter.visit (param.getType (), OTK_None,
1104+ auto result = typePrinter.visit (param.getInterfaceType (), OTK_None,
10971105 /* isInOutParam=*/ false );
10981106 assert (!result.isUnsupported ());
10991107 os << " >::getTypeMetadata()" ;
@@ -1285,7 +1293,6 @@ void DeclAndTypeClangFunctionPrinter::printCxxThunkBody(
12851293 });
12861294 }
12871295 }
1288-
12891296}
12901297
12911298static StringRef getConstructorName (const AbstractFunctionDecl *FD) {
@@ -1301,19 +1308,19 @@ static StringRef getConstructorName(const AbstractFunctionDecl *FD) {
13011308void DeclAndTypeClangFunctionPrinter::printCxxMethod (
13021309 const NominalTypeDecl *typeDeclContext, const AbstractFunctionDecl *FD,
13031310 const LoweredFunctionSignature &signature, StringRef swiftSymbolName,
1304- Type resultTy, bool isDefinition) {
1311+ Type resultTy, bool isStatic, bool isDefinition) {
13051312 bool isConstructor = isa<ConstructorDecl>(FD);
13061313 os << " " ;
13071314
13081315 FunctionSignatureModifiers modifiers;
13091316 if (isDefinition)
13101317 modifiers.qualifierContext = typeDeclContext;
1311- modifiers.isStatic = isConstructor && !isDefinition;
1318+ modifiers.isStatic = (isStatic || isConstructor) && !isDefinition;
13121319 modifiers.isInline = true ;
13131320 bool isMutating =
13141321 isa<FuncDecl>(FD) ? cast<FuncDecl>(FD)->isMutating () : false ;
1315- modifiers.isConst =
1316- !isa<ClassDecl>(typeDeclContext) && !isMutating && !isConstructor ;
1322+ modifiers.isConst = !isa<ClassDecl>(typeDeclContext) && !isMutating &&
1323+ !isConstructor && !isStatic ;
13171324 modifiers.hasSymbolUSR = !isDefinition;
13181325 auto result = printFunctionSignature (
13191326 FD, signature,
@@ -1329,10 +1336,10 @@ void DeclAndTypeClangFunctionPrinter::printCxxMethod(
13291336
13301337 os << " {\n " ;
13311338 // FIXME: should it be objTy for resultTy?
1332- printCxxThunkBody (FD, signature, swiftSymbolName, typeDeclContext,
1333- FD-> getModuleContext (), resultTy , FD->getParameters (),
1334- FD->hasThrows (),
1335- FD->getInterfaceType ()->castTo <AnyFunctionType>());
1339+ printCxxThunkBody (
1340+ FD, signature, swiftSymbolName, typeDeclContext , FD->getModuleContext (),
1341+ resultTy, FD-> getParameters (), FD->hasThrows (),
1342+ FD->getInterfaceType ()->castTo <AnyFunctionType>(), isStatic );
13361343 os << " }\n " ;
13371344}
13381345
0 commit comments