diff options
Diffstat (limited to 'cpp/src/slice2objc/ObjCUtil.cpp')
-rw-r--r-- | cpp/src/slice2objc/ObjCUtil.cpp | 40 |
1 files changed, 40 insertions, 0 deletions
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) { |