@@ -96,13 +96,14 @@ class CFunctionSignatureTypePrinter
96
96
PrimitiveTypeMapping &typeMapping, OutputLanguageMode languageMode,
97
97
SwiftToClangInteropContext &interopContext,
98
98
CFunctionSignatureTypePrinterModifierDelegate modifiersDelegate,
99
- const ModuleDecl *moduleContext,
99
+ const ModuleDecl *moduleContext, DeclAndTypePrinter &declPrinter,
100
100
FunctionSignatureTypeUse typeUseKind =
101
101
FunctionSignatureTypeUse::ParamType)
102
102
: ClangSyntaxPrinter(os), cPrologueOS(cPrologueOS),
103
103
typeMapping (typeMapping), interopContext(interopContext),
104
104
languageMode(languageMode), modifiersDelegate(modifiersDelegate),
105
- moduleContext(moduleContext), typeUseKind(typeUseKind) {}
105
+ moduleContext(moduleContext), declPrinter(declPrinter),
106
+ typeUseKind(typeUseKind) {}
106
107
107
108
void printInoutTypeModifier () {
108
109
os << (languageMode == swift::OutputLanguageMode::Cxx ? " &"
@@ -197,6 +198,9 @@ class CFunctionSignatureTypePrinter
197
198
// Handle known type names.
198
199
if (printIfKnownSimpleType (decl, optionalKind, isInOutParam))
199
200
return ClangRepresentation::representable;
201
+ if (!declPrinter.shouldInclude (decl))
202
+ return ClangRepresentation::unsupported; // FIXME: propagate why it's not
203
+ // exposed.
200
204
// FIXME: Handle optional structures.
201
205
if (typeUseKind == FunctionSignatureTypeUse::ParamType) {
202
206
if (languageMode != OutputLanguageMode::Cxx &&
@@ -292,6 +296,7 @@ class CFunctionSignatureTypePrinter
292
296
OutputLanguageMode languageMode;
293
297
CFunctionSignatureTypePrinterModifierDelegate modifiersDelegate;
294
298
const ModuleDecl *moduleContext;
299
+ DeclAndTypePrinter &declPrinter;
295
300
FunctionSignatureTypeUse typeUseKind;
296
301
};
297
302
@@ -304,7 +309,7 @@ DeclAndTypeClangFunctionPrinter::printClangFunctionReturnType(
304
309
CFunctionSignatureTypePrinter typePrinter (
305
310
os, cPrologueOS, typeMapping, outputLang, interopContext,
306
311
CFunctionSignatureTypePrinterModifierDelegate (), moduleContext,
307
- FunctionSignatureTypeUse::ReturnType);
312
+ declPrinter, FunctionSignatureTypeUse::ReturnType);
308
313
// Param for indirect return cannot be marked as inout
309
314
return typePrinter.visit (ty, optKind, /* isInOutParam=*/ false );
310
315
}
@@ -344,9 +349,9 @@ ClangRepresentation DeclAndTypeClangFunctionPrinter::printFunctionSignature(
344
349
-> ClangRepresentation {
345
350
// FIXME: add support for noescape and PrintMultiPartType,
346
351
// see DeclAndTypePrinter::print.
347
- CFunctionSignatureTypePrinter typePrinter (os, cPrologueOS, typeMapping,
348
- outputLang, interopContext,
349
- delegate, emittedModule );
352
+ CFunctionSignatureTypePrinter typePrinter (
353
+ os, cPrologueOS, typeMapping, outputLang, interopContext, delegate ,
354
+ emittedModule, declPrinter );
350
355
auto result = typePrinter.visit (ty, optionalKind, isInOutParam);
351
356
352
357
if (!name.empty ()) {
@@ -385,6 +390,12 @@ ClangRepresentation DeclAndTypeClangFunctionPrinter::printFunctionSignature(
385
390
.isUnsupported ())
386
391
return resultingRepresentation;
387
392
} else {
393
+ // FIXME: also try to figure out if indirect is representable using a type
394
+ // visitor?
395
+ if (const auto *NT = resultTy->getNominalOrBoundGenericNominal ()) {
396
+ if (!declPrinter.shouldInclude (NT))
397
+ return ClangRepresentation::unsupported;
398
+ }
388
399
os << " void" ;
389
400
}
390
401
@@ -701,9 +712,11 @@ void DeclAndTypeClangFunctionPrinter::printCxxMethod(
701
712
isa<FuncDecl>(FD) ? cast<FuncDecl>(FD)->isMutating () : false ;
702
713
modifiers.isConst =
703
714
!isa<ClassDecl>(typeDeclContext) && !isMutating && !isConstructor;
704
- printFunctionSignature (
715
+ auto result = printFunctionSignature (
705
716
FD, isConstructor ? " init" : cxx_translation::getNameForCxx (FD), resultTy,
706
717
FunctionSignatureKind::CxxInlineThunk, {}, modifiers);
718
+ assert (!result.isUnsupported () && " C signature should be unsupported too" );
719
+
707
720
if (!isDefinition) {
708
721
os << " ;\n " ;
709
722
return ;
@@ -763,9 +776,10 @@ void DeclAndTypeClangFunctionPrinter::printCxxPropertyAccessorMethod(
763
776
modifiers.qualifierContext = typeDeclContext;
764
777
modifiers.isInline = true ;
765
778
modifiers.isConst = accessor->isGetter () && !isa<ClassDecl>(typeDeclContext);
766
- printFunctionSignature (accessor, remapPropertyName (accessor, resultTy),
767
- resultTy, FunctionSignatureKind::CxxInlineThunk, {},
768
- modifiers);
779
+ auto result = printFunctionSignature (
780
+ accessor, remapPropertyName (accessor, resultTy), resultTy,
781
+ FunctionSignatureKind::CxxInlineThunk, {}, modifiers);
782
+ assert (!result.isUnsupported () && " C signature should be unsupported too!" );
769
783
if (!isDefinition) {
770
784
os << " ;\n " ;
771
785
return ;
0 commit comments