void Slice::Ruby::CodeVisitor::visitClassDecl(const ClassDeclPtr& p) { // // Emit forward declarations. // string scoped = p->scoped(); if(_classHistory.count(scoped) == 0) { string name = "T_" + fixIdent(p->name(), IdentToUpper); _out << sp << nl << "if not defined?(" << getAbsolute(p, IdentToUpper, "T_") << ')'; _out.inc(); if(p->isLocal()) { _out << nl << name << " = ::Ice::__declareLocalClass('" << scoped << "')"; } else { _out << nl << name << " = ::Ice::__declareClass('" << scoped << "')"; _out << nl << name << "Prx = ::Ice::__declareProxy('" << scoped << "')"; } _out.dec(); _out << nl << "end"; _classHistory.insert(scoped); // Avoid redundant declarations. } }
string Slice::JsGenerator::getStaticId(const TypePtr& type) { BuiltinPtr b = BuiltinPtr::dynamicCast(type); ClassDeclPtr cl = ClassDeclPtr::dynamicCast(type); assert((b && b->kind() == Builtin::KindObject) || cl); if(b) { return "Ice.ObjectImpl.ice_staticId()"; } else if(cl->isInterface()) { ContainedPtr cont = ContainedPtr::dynamicCast(cl->container()); assert(cont); return fixId(cont->scoped()) + "." + cl->name() + "Disp_.ice_staticId()"; } else { return fixId(cl->scoped()) + ".ice_staticId()"; } }
void Slice::ObjCGenerator::writeMarshalUnmarshalCode(Output &out, const TypePtr& type, const string& param, bool marshal, bool autoreleased) const { string stream = marshal ? "os_" : "is_"; BuiltinPtr builtin = BuiltinPtr::dynamicCast(type); if(builtin) { string name; if(builtin->kind() == Builtin::KindObject) { if(marshal) { out << nl << "[" << stream << " writeObject:" << param << "];"; } else { if(autoreleased) { out << nl << "[" << stream << " readObject:&" << param << "];"; } else { out << nl << "[" << stream << " newObject:&" << param << "];"; } } } else if(builtin->kind() == Builtin::KindObjectProxy) { if(marshal) { out << nl << "[" << stream << " writeProxy:" << param << "];"; } else { if(autoreleased) { out << nl << param << " = [" << stream << " readProxy:[ICEObjectPrx class]];"; } else { out << nl << param << " = [" << stream << " newProxy:[ICEObjectPrx class]];"; } } } else { if(marshal) { out << nl << "[" << stream << " write" << getBuiltinName(builtin) << ":" << param << "];"; } else { if(autoreleased || isValueType(builtin)) { out << nl << param << " = [" << stream << " read" << getBuiltinName(builtin) << "];"; } else { out << nl << param << " = [" << stream << " new" << getBuiltinName(builtin) << "];"; } } } return; } ProxyPtr prx = ProxyPtr::dynamicCast(type); if(prx) { if(marshal) { out << nl << "[" << stream << " writeProxy:(id<ICEObjectPrx>)" << param << "];"; } else { string name = moduleName(findModule(prx->_class())) + prx->_class()->name() + "Prx"; out << nl << param << " = (id<" << name << ">)[" << stream; if(autoreleased) { out << " readProxy:"; } else { out << " newProxy:"; } // // We use objc_getClass to get the proxy class instead of [name class]. This is to avoid // a warning if the proxy is forward declared. // if(prx->_class()->definition()) { out << "[" << name << " class]];"; } else { out << "objc_getClass(\"" << name << "\")];"; } } return; } ClassDeclPtr cl = ClassDeclPtr::dynamicCast(type); if(cl) { if(marshal) { // Cast avoids warning for forward-declared classes. out << nl << "[" << stream << " writeObject:(ICEObject*)" << param << "];"; } else { if(autoreleased) { out << nl << "[" << stream << " " << "readObject:(ICEObject**)&" << param; } else { out << nl << "[" << stream << " " << "newObject:(ICEObject**)&" << param; } if(cl->isInterface()) { out << "];"; } else { string name = moduleName(findModule(cl)) + cl->name(); if(cl->definition()) { out << " expectedType:[" << name << " class]];"; } else { out << " expectedType:objc_getClass(\"" << name << "\")];"; } } } return; } EnumPtr en = EnumPtr::dynamicCast(type); if(en) { if(marshal) { out << nl << "[" << stream << " writeEnumerator:" << param << " min:" << en->minValue() << " max:" << en->maxValue() << "];"; } else { out << nl << param << " = " << "[" << stream << " readEnumerator:" << en->minValue() << " max:" << en->maxValue() << "];"; } return; } ContainedPtr c = ContainedPtr::dynamicCast(type); assert(c); string name = moduleName(findModule(c)) + c->name() + "Helper"; if(marshal) { out << nl << "[" + name << " write:" << param << " stream:" << stream << "];"; } else { if(StructPtr::dynamicCast(type)) { if(autoreleased) { out << nl << param << " = [" << name << " read:" << stream << " value:" << param << "];"; } else { out << nl << param << " = [" << name << " readRetained:" << stream << " value:" << param << "];"; } } else { if(autoreleased) { out << nl << param << " = [" << name << " read:" << stream << "];"; } else { out << nl << param << " = [" << name << " readRetained:" << stream << "];"; } } } }