Skip to content

Commit 705e562

Browse files
committed
improve based on code review feedback
1 parent f033aad commit 705e562

File tree

1 file changed

+10
-17
lines changed

1 file changed

+10
-17
lines changed

lib/PrintAsClang/PrintClangFunction.cpp

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -77,13 +77,17 @@ class CFunctionSignatureTypePrinter
7777
languageMode(languageMode), typeUseKind(typeUseKind) {}
7878

7979
bool printIfKnownSimpleType(const TypeDecl *typeDecl,
80-
Optional<OptionalTypeKind> optionalKind) {
80+
Optional<OptionalTypeKind> optionalKind,
81+
bool isInOutParam) {
8182
auto knownTypeInfo = getKnownTypeInfo(typeDecl, typeMapping, languageMode);
8283
if (!knownTypeInfo)
8384
return false;
8485
os << knownTypeInfo->name;
85-
if (knownTypeInfo->canBeNullable)
86+
if (knownTypeInfo->canBeNullable) {
8687
printNullability(optionalKind);
88+
} else if (isInOutParam) {
89+
os << (languageMode == swift::OutputLanguageMode::Cxx ? " &" : " *");
90+
}
8791
return true;
8892
}
8993

@@ -106,7 +110,7 @@ class CFunctionSignatureTypePrinter
106110
Optional<OptionalTypeKind> optionalKind,
107111
bool isInOutParam) {
108112
const TypeAliasDecl *alias = aliasTy->getDecl();
109-
if (printIfKnownSimpleType(alias, optionalKind))
113+
if (printIfKnownSimpleType(alias, optionalKind, isInOutParam))
110114
return;
111115

112116
visitPart(aliasTy->getSinglyDesugaredType(), optionalKind, isInOutParam);
@@ -117,7 +121,7 @@ class CFunctionSignatureTypePrinter
117121
const StructDecl *SD = ST->getStructOrBoundGenericStruct();
118122

119123
// Handle known type names.
120-
if (printIfKnownSimpleType(SD, optionalKind))
124+
if (printIfKnownSimpleType(SD, optionalKind, isInOutParam))
121125
return;
122126
// FIXME: Handle optional structures.
123127
if (typeUseKind == FunctionSignatureTypeUse::ParamType) {
@@ -168,16 +172,6 @@ void DeclAndTypeClangFunctionPrinter::printFunctionSignature(
168172
outputLang, interopContext);
169173
typePrinter.visit(ty, optionalKind, isInOutParam);
170174

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-
181175
if (!name.empty()) {
182176
os << ' ';
183177
ClangSyntaxPrinter(os).printIdentifier(name);
@@ -197,9 +191,8 @@ void DeclAndTypeClangFunctionPrinter::printFunctionSignature(
197191
CFunctionSignatureTypePrinter typePrinter(
198192
os, cPrologueOS, typeMapping, outputLang, interopContext,
199193
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);
203196
} else {
204197
os << "void";
205198
}

0 commit comments

Comments
 (0)