@@ -85,12 +85,13 @@ class CFunctionSignatureTypePrinter
85
85
PrimitiveTypeMapping &typeMapping, OutputLanguageMode languageMode,
86
86
SwiftToClangInteropContext &interopContext,
87
87
CFunctionSignatureTypePrinterModifierDelegate modifiersDelegate,
88
+ const ModuleDecl *moduleContext,
88
89
FunctionSignatureTypeUse typeUseKind =
89
90
FunctionSignatureTypeUse::ParamType)
90
91
: ClangSyntaxPrinter(os), cPrologueOS(cPrologueOS),
91
92
typeMapping (typeMapping), interopContext(interopContext),
92
93
languageMode(languageMode), modifiersDelegate(modifiersDelegate),
93
- typeUseKind(typeUseKind) {}
94
+ moduleContext(moduleContext), typeUseKind(typeUseKind) {}
94
95
95
96
bool printIfKnownSimpleType (const TypeDecl *typeDecl,
96
97
Optional<OptionalTypeKind> optionalKind,
@@ -168,11 +169,12 @@ class CFunctionSignatureTypePrinter
168
169
169
170
} else {
170
171
ClangValueTypePrinter (os, cPrologueOS, typeMapping, interopContext)
171
- .printValueTypeParameterType (decl, languageMode, isInOutParam);
172
+ .printValueTypeParameterType (decl, languageMode, moduleContext,
173
+ isInOutParam);
172
174
}
173
175
} else
174
176
ClangValueTypePrinter (os, cPrologueOS, typeMapping, interopContext)
175
- .printValueTypeReturnType (decl, languageMode);
177
+ .printValueTypeReturnType (decl, languageMode, moduleContext );
176
178
}
177
179
178
180
void visitPart (Type Ty, Optional<OptionalTypeKind> optionalKind,
@@ -186,6 +188,7 @@ class CFunctionSignatureTypePrinter
186
188
SwiftToClangInteropContext &interopContext;
187
189
OutputLanguageMode languageMode;
188
190
CFunctionSignatureTypePrinterModifierDelegate modifiersDelegate;
191
+ const ModuleDecl *moduleContext;
189
192
FunctionSignatureTypeUse typeUseKind;
190
193
};
191
194
@@ -195,6 +198,7 @@ void DeclAndTypeClangFunctionPrinter::printFunctionSignature(
195
198
const AbstractFunctionDecl *FD, StringRef name, Type resultTy,
196
199
FunctionSignatureKind kind, ArrayRef<AdditionalParam> additionalParams,
197
200
FunctionSignatureModifiers modifiers) {
201
+ auto emittedModule = FD->getModuleContext ();
198
202
OutputLanguageMode outputLang = kind == FunctionSignatureKind::CFunctionProto
199
203
? OutputLanguageMode::ObjC
200
204
: OutputLanguageMode::Cxx;
@@ -205,8 +209,9 @@ void DeclAndTypeClangFunctionPrinter::printFunctionSignature(
205
209
CFunctionSignatureTypePrinterModifierDelegate delegate = {}) {
206
210
// FIXME: add support for noescape and PrintMultiPartType,
207
211
// see DeclAndTypePrinter::print.
208
- CFunctionSignatureTypePrinter typePrinter (
209
- os, cPrologueOS, typeMapping, outputLang, interopContext, delegate);
212
+ CFunctionSignatureTypePrinter typePrinter (os, cPrologueOS, typeMapping,
213
+ outputLang, interopContext,
214
+ delegate, emittedModule);
210
215
typePrinter.visit (ty, optionalKind, isInOutParam);
211
216
212
217
if (!name.empty ()) {
@@ -228,7 +233,7 @@ void DeclAndTypeClangFunctionPrinter::printFunctionSignature(
228
233
DeclAndTypePrinter::getObjectTypeAndOptionality (FD, resultTy);
229
234
CFunctionSignatureTypePrinter typePrinter (
230
235
os, cPrologueOS, typeMapping, outputLang, interopContext,
231
- CFunctionSignatureTypePrinterModifierDelegate (),
236
+ CFunctionSignatureTypePrinterModifierDelegate (), emittedModule,
232
237
FunctionSignatureTypeUse::ReturnType);
233
238
// Param for indirect return cannot be marked as inout
234
239
typePrinter.visit (objTy, retKind, /* isInOutParam=*/ false );
@@ -312,8 +317,8 @@ void DeclAndTypeClangFunctionPrinter::printFunctionSignature(
312
317
}
313
318
314
319
void DeclAndTypeClangFunctionPrinter::printCxxToCFunctionParameterUse (
315
- Type type, StringRef name, bool isInOut , bool isIndirect ,
316
- llvm::Optional<AdditionalParam::Role> paramRole) {
320
+ Type type, StringRef name, const ModuleDecl *moduleContext , bool isInOut ,
321
+ bool isIndirect, llvm::Optional<AdditionalParam::Role> paramRole) {
317
322
auto namePrinter = [&]() { ClangSyntaxPrinter (os).printIdentifier (name); };
318
323
if (!isKnownCxxType (type, typeMapping) &&
319
324
!hasKnownOptionalNullableCxxMapping (type)) {
@@ -323,7 +328,7 @@ void DeclAndTypeClangFunctionPrinter::printCxxToCFunctionParameterUse(
323
328
.printParameterCxxToCUseScaffold (
324
329
isIndirect || decl->isResilient () ||
325
330
interopContext.getIrABIDetails ().shouldPassIndirectly (type),
326
- decl, namePrinter, isInOut,
331
+ decl, moduleContext, namePrinter, isInOut,
327
332
/* isSelf=*/ paramRole &&
328
333
*paramRole == AdditionalParam::Role::Self);
329
334
return ;
@@ -339,12 +344,14 @@ void DeclAndTypeClangFunctionPrinter::printCxxToCFunctionParameterUse(
339
344
340
345
void DeclAndTypeClangFunctionPrinter::printCxxToCFunctionParameterUse (
341
346
const ParamDecl *param, StringRef name) {
342
- printCxxToCFunctionParameterUse (param->getType (), name, param->isInOut ());
347
+ printCxxToCFunctionParameterUse (param->getType (), name,
348
+ param->getModuleContext (), param->isInOut ());
343
349
}
344
350
345
351
void DeclAndTypeClangFunctionPrinter::printCxxThunkBody (
346
- StringRef swiftSymbolName, Type resultTy, const ParameterList *params,
347
- ArrayRef<AdditionalParam> additionalParams, bool hasThrows) {
352
+ StringRef swiftSymbolName, const ModuleDecl *moduleContext, Type resultTy,
353
+ const ParameterList *params, ArrayRef<AdditionalParam> additionalParams,
354
+ bool hasThrows) {
348
355
if (hasThrows) {
349
356
os << " void* opaqueError = nullptr;\n " ;
350
357
os << " void* self = nullptr;\n " ;
@@ -382,17 +389,17 @@ void DeclAndTypeClangFunctionPrinter::printCxxThunkBody(
382
389
os << " , " ;
383
390
interleaveComma (additionalParams, os, [&](const AdditionalParam ¶m) {
384
391
if (param.role == AdditionalParam::Role::Self && !hasThrows)
385
- printCxxToCFunctionParameterUse (param. type , " *this " , /* isInOut= */ false ,
386
- /* isIndirect =*/ param. isIndirect ,
387
- param.role );
392
+ printCxxToCFunctionParameterUse (
393
+ param. type , " *this " , moduleContext, /* isInOut =*/ false ,
394
+ /* isIndirect= */ param. isIndirect , param.role );
388
395
else if (param.role == AdditionalParam::Role::Self && hasThrows)
389
- printCxxToCFunctionParameterUse (param. type , " self " , /* isInOut= */ false ,
390
- /* isIndirect =*/ param. isIndirect ,
391
- param.role );
396
+ printCxxToCFunctionParameterUse (
397
+ param. type , " self " , moduleContext, /* isInOut =*/ false ,
398
+ /* isIndirect= */ param. isIndirect , param.role );
392
399
else if (param.role == AdditionalParam::Role::Error && hasThrows)
393
- printCxxToCFunctionParameterUse (param. type , " &opaqueError " , /* isInOut= */ false ,
394
- /* isIndirect =*/ param. isIndirect ,
395
- param.role );
400
+ printCxxToCFunctionParameterUse (
401
+ param. type , " &opaqueError " , moduleContext, /* isInOut =*/ false ,
402
+ /* isIndirect= */ param. isIndirect , param.role );
396
403
});
397
404
}
398
405
@@ -412,12 +419,13 @@ void DeclAndTypeClangFunctionPrinter::printCxxThunkBody(
412
419
interopContext);
413
420
if (isIndirect) {
414
421
valueTypePrinter.printValueTypeIndirectReturnScaffold (
415
- decl, [&](StringRef returnParam) {
422
+ decl, moduleContext, [&](StringRef returnParam) {
416
423
printCallToCFunc (/* additionalParam=*/ returnParam);
417
424
});
418
425
} else {
419
426
valueTypePrinter.printValueTypeDirectReturnScaffold (
420
- decl, [&]() { printCallToCFunc (/* additionalParam=*/ None); });
427
+ decl, moduleContext,
428
+ [&]() { printCallToCFunc (/* additionalParam=*/ None); });
421
429
}
422
430
return ;
423
431
}
@@ -464,8 +472,8 @@ void DeclAndTypeClangFunctionPrinter::printCxxMethod(
464
472
typeDeclContext->getDeclaredType (),
465
473
/* isIndirect=*/ isMutating,
466
474
});
467
- printCxxThunkBody (swiftSymbolName, resultTy, FD->getParameters () ,
468
- additionalParams, FD->hasThrows ());
475
+ printCxxThunkBody (swiftSymbolName, FD->getModuleContext (), resultTy ,
476
+ FD-> getParameters (), additionalParams, FD->hasThrows ());
469
477
os << " }\n " ;
470
478
}
471
479
@@ -482,7 +490,7 @@ void DeclAndTypeClangFunctionPrinter::printCxxPropertyAccessorMethod(
482
490
CFunctionSignatureTypePrinter typePrinter (
483
491
os, cPrologueOS, typeMapping, OutputLanguageMode::Cxx, interopContext,
484
492
CFunctionSignatureTypePrinterModifierDelegate (),
485
- FunctionSignatureTypeUse::ReturnType);
493
+ accessor-> getModuleContext (), FunctionSignatureTypeUse::ReturnType);
486
494
typePrinter.visit (objTy, retKind, /* isInOut=*/ false );
487
495
488
496
ClangSyntaxPrinter printer (os);
@@ -506,7 +514,8 @@ void DeclAndTypeClangFunctionPrinter::printCxxPropertyAccessorMethod(
506
514
}
507
515
os << " {\n " ;
508
516
// FIXME: should it be objTy for resultTy?
509
- printCxxThunkBody (swiftSymbolName, resultTy, accessor->getParameters (),
517
+ printCxxThunkBody (swiftSymbolName, accessor->getModuleContext (), resultTy,
518
+ accessor->getParameters (),
510
519
{AdditionalParam{AdditionalParam::Role::Self,
511
520
typeDeclContext->getDeclaredType (),
512
521
/* isIndirect=*/ false }});
0 commit comments