@@ -77,13 +77,17 @@ class CFunctionSignatureTypePrinter
77
77
languageMode(languageMode), typeUseKind(typeUseKind) {}
78
78
79
79
bool printIfKnownSimpleType (const TypeDecl *typeDecl,
80
- Optional<OptionalTypeKind> optionalKind) {
80
+ Optional<OptionalTypeKind> optionalKind,
81
+ bool isInOutParam) {
81
82
auto knownTypeInfo = getKnownTypeInfo (typeDecl, typeMapping, languageMode);
82
83
if (!knownTypeInfo)
83
84
return false ;
84
85
os << knownTypeInfo->name ;
85
- if (knownTypeInfo->canBeNullable )
86
+ if (knownTypeInfo->canBeNullable ) {
86
87
printNullability (optionalKind);
88
+ } else if (isInOutParam) {
89
+ os << (languageMode == swift::OutputLanguageMode::Cxx ? " &" : " *" );
90
+ }
87
91
return true ;
88
92
}
89
93
@@ -106,7 +110,7 @@ class CFunctionSignatureTypePrinter
106
110
Optional<OptionalTypeKind> optionalKind,
107
111
bool isInOutParam) {
108
112
const TypeAliasDecl *alias = aliasTy->getDecl ();
109
- if (printIfKnownSimpleType (alias, optionalKind))
113
+ if (printIfKnownSimpleType (alias, optionalKind, isInOutParam ))
110
114
return ;
111
115
112
116
visitPart (aliasTy->getSinglyDesugaredType (), optionalKind, isInOutParam);
@@ -117,7 +121,7 @@ class CFunctionSignatureTypePrinter
117
121
const StructDecl *SD = ST->getStructOrBoundGenericStruct ();
118
122
119
123
// Handle known type names.
120
- if (printIfKnownSimpleType (SD, optionalKind))
124
+ if (printIfKnownSimpleType (SD, optionalKind, isInOutParam ))
121
125
return ;
122
126
// FIXME: Handle optional structures.
123
127
if (typeUseKind == FunctionSignatureTypeUse::ParamType) {
@@ -168,16 +172,6 @@ void DeclAndTypeClangFunctionPrinter::printFunctionSignature(
168
172
outputLang, interopContext);
169
173
typePrinter.visit (ty, optionalKind, isInOutParam);
170
174
171
- if (isInOutParam) {
172
- if (outputLang == OutputLanguageMode::Cxx &&
173
- isKnownCxxType (ty, typeMapping)) {
174
- os << " &" ;
175
- } else if (outputLang == OutputLanguageMode::ObjC &&
176
- isKnownCType (ty, typeMapping)) {
177
- os << " *" ;
178
- }
179
- }
180
-
181
175
if (!name.empty ()) {
182
176
os << ' ' ;
183
177
ClangSyntaxPrinter (os).printIdentifier (name);
@@ -197,9 +191,8 @@ void DeclAndTypeClangFunctionPrinter::printFunctionSignature(
197
191
CFunctionSignatureTypePrinter typePrinter (
198
192
os, cPrologueOS, typeMapping, outputLang, interopContext,
199
193
FunctionSignatureTypeUse::ReturnType);
200
- // Pass false because it's a parameter for indirect return.
201
- // Not an actual parameter, which means it can never be inout
202
- typePrinter.visit (objTy, retKind, false );
194
+ // Param for indirect return cannot be marked as inout
195
+ typePrinter.visit (objTy, retKind, /* isInOutParam=*/ false );
203
196
} else {
204
197
os << " void" ;
205
198
}
0 commit comments