Skip to content

Commit c9bd89b

Browse files
committed
[interop][SwiftToCxx] NFC, extract code to remap a property name to its own function
1 parent 760d59e commit c9bd89b

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

lib/PrintAsClang/PrintClangFunction.cpp

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -504,28 +504,31 @@ void DeclAndTypeClangFunctionPrinter::printCxxMethod(
504504
os << " }\n";
505505
}
506506

507-
void DeclAndTypeClangFunctionPrinter::printCxxPropertyAccessorMethod(
508-
const NominalTypeDecl *typeDeclContext, const AccessorDecl *accessor,
509-
StringRef swiftSymbolName, Type resultTy, bool isDefinition) {
510-
assert(accessor->isSetter() || accessor->getParameters()->size() == 0);
511-
os << " ";
512-
507+
static std::string remapPropertyName(const AccessorDecl *accessor) {
513508
StringRef propertyName;
514509
// For a getter or setter, go through the variable or subscript decl.
515510
propertyName = accessor->getStorage()->getBaseIdentifier().str();
516-
517511
std::string name;
518512
llvm::raw_string_ostream nameOS(name);
519513
// FIXME: some names are remapped differently. (e.g. isX).
520514
nameOS << (accessor->isSetter() ? "set" : "get")
521515
<< char(std::toupper(propertyName[0])) << propertyName.drop_front();
516+
nameOS.flush();
517+
return name;
518+
}
519+
520+
void DeclAndTypeClangFunctionPrinter::printCxxPropertyAccessorMethod(
521+
const NominalTypeDecl *typeDeclContext, const AccessorDecl *accessor,
522+
StringRef swiftSymbolName, Type resultTy, bool isDefinition) {
523+
assert(accessor->isSetter() || accessor->getParameters()->size() == 0);
524+
os << " ";
522525

523526
FunctionSignatureModifiers modifiers;
524527
if (isDefinition)
525528
modifiers.qualifierContext = typeDeclContext;
526529
modifiers.isInline = true;
527530
modifiers.isConst = accessor->isGetter();
528-
printFunctionSignature(accessor, nameOS.str(), resultTy,
531+
printFunctionSignature(accessor, remapPropertyName(accessor), resultTy,
529532
FunctionSignatureKind::CxxInlineThunk, {}, modifiers);
530533
if (!isDefinition) {
531534
os << ";\n";

0 commit comments

Comments
 (0)