summaryrefslogtreecommitdiff
path: root/cpp/src
diff options
context:
space:
mode:
authorJose <pepone@users.noreply.github.com>2023-08-09 09:27:00 +0200
committerGitHub <noreply@github.com>2023-08-09 09:27:00 +0200
commitbadafe8b848181a720ab96b48da6abc170fd918c (patch)
tree4b24dbf02f578cb6c68a43fa45a71b4cb8f2405b /cpp/src
parentFix GCC13 build failure - #1489 (#1490) (diff)
downloadice-badafe8b848181a720ab96b48da6abc170fd918c.tar.bz2
ice-badafe8b848181a720ab96b48da6abc170fd918c.tar.xz
ice-badafe8b848181a720ab96b48da6abc170fd918c.zip
Fix Objective-C build failures (#1496)
Diffstat (limited to 'cpp/src')
-rw-r--r--cpp/src/slice2objc/Gen.cpp15
-rw-r--r--cpp/src/slice2objc/ObjCUtil.cpp40
-rw-r--r--cpp/src/slice2objc/ObjCUtil.h1
3 files changed, 44 insertions, 12 deletions
diff --git a/cpp/src/slice2objc/Gen.cpp b/cpp/src/slice2objc/Gen.cpp
index c52ea9bbf17..3923e3fabaf 100644
--- a/cpp/src/slice2objc/Gen.cpp
+++ b/cpp/src/slice2objc/Gen.cpp
@@ -3106,23 +3106,14 @@ Slice::Gen::DelegateMVisitor::visitOperation(const OperationPtr& p)
if(returnType)
{
_M << nl << outTypeToString(returnType, p->returnIsOptional(), true) << " ret";
- if(!isValueType(returnType))
- {
- _M << " = nil;";
- }
- else
- {
- _M << ";";
- }
+ _M << " = " << defaultValue(returnType, p->returnIsOptional()) << ";";
}
if(p->returnsData())
{
for(ParamDeclList::const_iterator op = outParams.begin(); op != outParams.end(); ++op)
{
- if(!isValueType((*op)->type()))
- {
- _M << nl << "*" << getParamName(*op, true) << " = nil;";
- }
+ _M << nl << "*" << getParamName(*op, true) << " = " << defaultValue((*op)->type(), (*op)->optional())
+ << ";";
}
}
_M << nl << "if(!ok)";
diff --git a/cpp/src/slice2objc/ObjCUtil.cpp b/cpp/src/slice2objc/ObjCUtil.cpp
index 1848cbcbf4d..cf7e34fd5f0 100644
--- a/cpp/src/slice2objc/ObjCUtil.cpp
+++ b/cpp/src/slice2objc/ObjCUtil.cpp
@@ -427,6 +427,46 @@ Slice::ObjCGenerator::typeToObjCTypeString(const TypePtr& type)
}
}
+string
+Slice::ObjCGenerator::defaultValue(const TypePtr& type, bool isOptional)
+{
+ if(isValueType(type) && !isOptional)
+ {
+ if(EnumPtr::dynamicCast(type))
+ {
+ return "0";
+ }
+ BuiltinPtr builtin = BuiltinPtr::dynamicCast(type);
+ if(builtin)
+ {
+ switch(builtin->kind())
+ {
+ case Builtin::KindBool:
+ return "NO";
+ case Builtin::KindByte:
+ case Builtin::KindShort:
+ case Builtin::KindInt:
+ case Builtin::KindLong:
+ return "0";
+ case Builtin::KindFloat:
+ case Builtin::KindDouble:
+ return "0.0";
+ default:
+ {
+ assert(false);
+ return "???";
+ }
+ }
+ }
+ assert(false);
+ return "???";
+ }
+ else
+ {
+ return "nil";
+ }
+}
+
bool
Slice::ObjCGenerator::isValueType(const TypePtr& type)
{
diff --git a/cpp/src/slice2objc/ObjCUtil.h b/cpp/src/slice2objc/ObjCUtil.h
index 0c5176d67d8..4520ee7082a 100644
--- a/cpp/src/slice2objc/ObjCUtil.h
+++ b/cpp/src/slice2objc/ObjCUtil.h
@@ -52,6 +52,7 @@ protected:
static std::string inTypeToString(const TypePtr&, bool, bool = false, bool = false);
static std::string outTypeToString(const TypePtr&, bool, bool = false, bool = false);
static std::string typeToObjCTypeString(const TypePtr&);
+ static std::string defaultValue(const TypePtr&, bool);
static bool isValueType(const TypePtr&);
static bool isString(const TypePtr&);
static bool isClass(const TypePtr&);