@@ -753,9 +753,9 @@ class DeclAndTypePrinter::Implementation
753
753
typeDeclContext, accessor, funcABI->getSymbolName (), resultTy,
754
754
/* isDefinition=*/ false );
755
755
} else {
756
- declPrinter.printCxxMethod (typeDeclContext, AFD,
757
- funcABI->getSymbolName (), resultTy,
758
- /* isDefinition=*/ false );
756
+ declPrinter.printCxxMethod (
757
+ typeDeclContext, AFD, funcABI->getSymbolName (), resultTy,
758
+ /* isDefinition=*/ false , funcABI-> additionalParams );
759
759
}
760
760
761
761
DeclAndTypeClangFunctionPrinter defPrinter (
@@ -769,9 +769,9 @@ class DeclAndTypePrinter::Implementation
769
769
typeDeclContext, accessor, funcABI->getSymbolName (), resultTy,
770
770
/* isDefinition=*/ true );
771
771
} else {
772
- defPrinter.printCxxMethod (typeDeclContext, AFD,
773
- funcABI->getSymbolName (), resultTy,
774
- /* isDefinition=*/ true );
772
+ defPrinter.printCxxMethod (
773
+ typeDeclContext, AFD, funcABI->getSymbolName (), resultTy,
774
+ /* isDefinition=*/ true , funcABI-> additionalParams );
775
775
}
776
776
777
777
// FIXME: SWIFT_WARN_UNUSED_RESULT
@@ -1068,6 +1068,9 @@ class DeclAndTypePrinter::Implementation
1068
1068
1069
1069
bool useMangledSymbolName () const { return !isCDecl; }
1070
1070
1071
+ SmallVector<DeclAndTypeClangFunctionPrinter::AdditionalParam, 2 >
1072
+ additionalParams;
1073
+
1071
1074
private:
1072
1075
bool isCDecl;
1073
1076
StringRef symbolName;
@@ -1078,7 +1081,8 @@ class DeclAndTypePrinter::Implementation
1078
1081
AbstractFunctionDecl *FD, Type resultTy,
1079
1082
llvm::SmallVector<IRABIDetailsProvider::ABIAdditionalParam, 1 > ABIparams,
1080
1083
llvm::SmallVector<DeclAndTypeClangFunctionPrinter::AdditionalParam, 2 >
1081
- ¶ms) {
1084
+ ¶ms,
1085
+ Optional<NominalTypeDecl *> selfTypeDeclContext = None) {
1082
1086
for (auto param : ABIparams) {
1083
1087
if (param.role == IRABIDetailsProvider::ABIAdditionalParam::
1084
1088
ABIParameterRole::GenericRequirementRole)
@@ -1090,7 +1094,9 @@ class DeclAndTypePrinter::Implementation
1090
1094
IRABIDetailsProvider::ABIAdditionalParam::ABIParameterRole::Self)
1091
1095
params.push_back (
1092
1096
{DeclAndTypeClangFunctionPrinter::AdditionalParam::Role::Self,
1093
- resultTy->getASTContext ().getOpaquePointerType (),
1097
+ selfTypeDeclContext
1098
+ ? (*selfTypeDeclContext)->getDeclaredType ()
1099
+ : resultTy->getASTContext ().getOpaquePointerType (),
1094
1100
/* isIndirect=*/
1095
1101
isa<FuncDecl>(FD) ? cast<FuncDecl>(FD)->isMutating () : false });
1096
1102
else if (param.role == IRABIDetailsProvider::ABIAdditionalParam::
@@ -1135,23 +1141,29 @@ class DeclAndTypePrinter::Implementation
1135
1141
owningPrinter.interopContext , owningPrinter);
1136
1142
auto ABIparams = owningPrinter.interopContext .getIrABIDetails ()
1137
1143
.getFunctionABIAdditionalParams (FD);
1138
- llvm::SmallVector<DeclAndTypeClangFunctionPrinter::AdditionalParam, 2 >
1139
- additionalParams;
1140
- if (selfTypeDeclContext && !isa<ConstructorDecl>(FD)) {
1141
- additionalParams.push_back (
1144
+ // FIXME: Ideally direct 'self' would come from IR provider too.
1145
+ if (selfTypeDeclContext && !isa<ConstructorDecl>(FD) &&
1146
+ llvm::find_if (
1147
+ ABIparams,
1148
+ [](const IRABIDetailsProvider::ABIAdditionalParam &Param) {
1149
+ return Param.role == IRABIDetailsProvider::ABIAdditionalParam::
1150
+ ABIParameterRole::Self;
1151
+ }) == ABIparams.end ()) {
1152
+ funcABI.additionalParams .push_back (
1142
1153
{DeclAndTypeClangFunctionPrinter::AdditionalParam::Role::Self,
1143
1154
(*selfTypeDeclContext)->getDeclaredType (),
1144
1155
/* isIndirect=*/
1145
1156
isa<FuncDecl>(FD) ? cast<FuncDecl>(FD)->isMutating () : false });
1146
1157
}
1147
- // FIXME: Fix the method 'self' parameter.
1148
- if (!selfTypeDeclContext && !ABIparams.empty ())
1149
- convertABIAdditionalParams (FD, resultTy, ABIparams, additionalParams);
1158
+ if (!ABIparams.empty ())
1159
+ convertABIAdditionalParams (FD, resultTy, ABIparams,
1160
+ funcABI.additionalParams ,
1161
+ /* selfContext=*/ selfTypeDeclContext);
1150
1162
1151
1163
auto representation = funcPrinter.printFunctionSignature (
1152
1164
FD, funcABI.getSymbolName (), resultTy,
1153
1165
DeclAndTypeClangFunctionPrinter::FunctionSignatureKind::CFunctionProto,
1154
- additionalParams);
1166
+ funcABI. additionalParams );
1155
1167
if (representation.isUnsupported ()) {
1156
1168
// FIXME: Emit remark about unemitted declaration.
1157
1169
return None;
@@ -1195,12 +1207,6 @@ class DeclAndTypePrinter::Implementation
1195
1207
DeclAndTypeClangFunctionPrinter funcPrinter (
1196
1208
os, owningPrinter.prologueOS , owningPrinter.typeMapping ,
1197
1209
owningPrinter.interopContext , owningPrinter);
1198
- llvm::SmallVector<DeclAndTypeClangFunctionPrinter::AdditionalParam, 2 >
1199
- additionalParams;
1200
- auto ABIparams = owningPrinter.interopContext .getIrABIDetails ()
1201
- .getFunctionABIAdditionalParams (FD);
1202
- if (!ABIparams.empty ())
1203
- convertABIAdditionalParams (FD, resultTy, ABIparams, additionalParams);
1204
1210
DeclAndTypeClangFunctionPrinter::FunctionSignatureModifiers modifiers;
1205
1211
modifiers.isInline = true ;
1206
1212
auto result = funcPrinter.printFunctionSignature (
@@ -1215,9 +1221,10 @@ class DeclAndTypePrinter::Implementation
1215
1221
printFunctionClangAttributes (FD, funcTy);
1216
1222
printAvailability (FD);
1217
1223
os << " {\n " ;
1218
- funcPrinter.printCxxThunkBody (
1219
- funcABI.getSymbolName (), FD->getModuleContext (), resultTy,
1220
- FD->getParameters (), additionalParams, funcTy->isThrowing (), funcTy);
1224
+ funcPrinter.printCxxThunkBody (funcABI.getSymbolName (),
1225
+ FD->getModuleContext (), resultTy,
1226
+ FD->getParameters (), funcABI.additionalParams ,
1227
+ funcTy->isThrowing (), funcTy);
1221
1228
os << " }\n " ;
1222
1229
}
1223
1230
0 commit comments