void Slice::ObjCGenerator::writeOptMemberMarshalUnmarshalCode(Output &out, const TypePtr& type, const string& param, bool marshal) const { string stream = marshal ? "os_" : "is_"; string optionalHelper; string helper; BuiltinPtr builtin = BuiltinPtr::dynamicCast(type); if(builtin) { if(builtin->kind() == Builtin::KindObjectProxy) { optionalHelper = "ICEVarLengthOptionalHelper"; helper = "[ICEProxyHelper class]"; } else { writeMarshalUnmarshalCode(out, type, param, marshal, false); return; } } ClassDeclPtr cl = ClassDeclPtr::dynamicCast(type); if(cl) { writeMarshalUnmarshalCode(out, type, param, marshal, false); return; } EnumPtr en = EnumPtr::dynamicCast(type); if(en) { writeMarshalUnmarshalCode(out, type, param, marshal, false); return; } ProxyPtr prx = ProxyPtr::dynamicCast(type); if(prx) { optionalHelper = "ICEVarLengthOptionalHelper"; helper = "objc_getClass(\"" + moduleName(findModule(prx->_class())) + prx->_class()->name() + "PrxHelper\")"; } StructPtr st = StructPtr::dynamicCast(type); if(st) { if(st->isVariableLength()) { optionalHelper = "ICEVarLengthOptionalHelper"; } else { optionalHelper = "ICEFixedLengthOptionalHelper"; } helper = "[" + typeToString(st) + "Helper class]"; } SequencePtr seq = SequencePtr::dynamicCast(type); if(seq) { TypePtr element = seq->type(); if(element->isVariableLength()) { optionalHelper = "ICEVarLengthOptionalHelper"; } else if(element->minWireSize() == 1) { writeMarshalUnmarshalCode(out, type, param, marshal, false); return; } else { optionalHelper = "ICEFixedSequenceOptionalHelper"; } helper = "[" + moduleName(findModule(seq)) + seq->name() + "Helper class]"; } DictionaryPtr d = DictionaryPtr::dynamicCast(type); if(d) { if(d->keyType()->isVariableLength() || d->valueType()->isVariableLength()) { optionalHelper = "ICEVarLengthOptionalHelper"; } else { optionalHelper = "ICEFixedDictionaryOptionalHelper"; } helper = "[" + moduleName(findModule(d)) + d->name() + "Helper class]"; } out << nl; if(marshal) { out << "[" << optionalHelper << " write:" << param << " stream:" << stream << " helper:" << helper << "];"; } else { out << param << " = [" << optionalHelper << " readRetained:" << stream << " helper:" << helper << "];"; } }
string Slice::ObjCGenerator::getOptionalFormat(const TypePtr& type) { BuiltinPtr bp = BuiltinPtr::dynamicCast(type); if(bp) { switch(bp->kind()) { case Builtin::KindByte: case Builtin::KindBool: { return "ICEOptionalFormatF1"; } case Builtin::KindShort: { return "ICEOptionalFormatF2"; } case Builtin::KindInt: case Builtin::KindFloat: { return "ICEOptionalFormatF4"; } case Builtin::KindLong: case Builtin::KindDouble: { return "ICEOptionalFormatF8"; } case Builtin::KindString: { return "ICEOptionalFormatVSize"; } case Builtin::KindObject: case Builtin::KindValue: { return "ICEOptionalFormatClass"; } case Builtin::KindObjectProxy: { return "ICEOptionalFormatFSize"; } case Builtin::KindLocalObject: { assert(false); break; } } } if(EnumPtr::dynamicCast(type)) { return "ICEOptionalFormatSize"; } SequencePtr seq = SequencePtr::dynamicCast(type); if(seq) { return seq->type()->isVariableLength() ? "ICEOptionalFormatFSize" : "ICEOptionalFormatVSize"; } DictionaryPtr d = DictionaryPtr::dynamicCast(type); if(d) { return (d->keyType()->isVariableLength() || d->valueType()->isVariableLength()) ? "ICEOptionalFormatFSize" : "ICEOptionalFormatVSize"; } StructPtr st = StructPtr::dynamicCast(type); if(st) { return st->isVariableLength() ? "ICEOptionalFormatFSize" : "ICEOptionalFormatVSize"; } if(ProxyPtr::dynamicCast(type)) { return "ICEOptionalFormatFSize"; } ClassDeclPtr cl = ClassDeclPtr::dynamicCast(type); assert(cl); return "ICEOptionalFormatClass"; }