void CodeVisitor::startNamespace(const ContainedPtr& cont) { if(_ns) { string scope = cont->scope(); scope = scope.substr(2); // Removing leading '::' scope = scope.substr(0, scope.length() - 2); // Removing trailing '::' _out << sp << nl << "namespace " << scopedToName(scope, true); _out << sb; } }
string Slice::Ruby::getAbsolute(const ContainedPtr& cont, IdentStyle style, const string& prefix) { string scope = fixIdent(cont->scope(), IdentToUpper); if(prefix.empty()) { return scope + fixIdent(cont->name(), style); } else { return scope + prefix + fixIdent(cont->name(), style); } }
string Slice::PHP::getAbsolute(const ContainedPtr& cont, bool ns, const string& prefix, const string& suffix) { return scopedToName(cont->scope() + prefix + cont->name() + suffix, ns); }
string Slice::JsGenerator::typeToString(const TypePtr& type, const ContainedPtr& toplevel, const vector<pair<string, string> >& imports, bool typescript, bool definition) { if(!type) { return "void"; } bool local = false; if(toplevel) { if(ConstructedPtr::dynamicCast(toplevel)) { local = ConstructedPtr::dynamicCast(toplevel)->isLocal(); } else if(ClassDefPtr::dynamicCast(toplevel)) { local = ClassDefPtr::dynamicCast(toplevel)->isLocal(); } } static const char* typeScriptBuiltinTable[] = { "number", // byte "boolean", // bool "number", // short "number", // int "Ice.Long", // long "number", // float "number", // double "string", "Ice.Object", "Ice.ObjectPrx", "Object", "Ice.Value" }; static const char* javaScriptBuiltinTable[] = { "Number", // byte "Boolean", // bool "Number", // short "Number", // int "Ice.Long", // long "Number", // float "Number", // double "String", "Ice.Value", "Ice.ObjectPrx", "Object", "Ice.Value" }; BuiltinPtr builtin = BuiltinPtr::dynamicCast(type); if(builtin) { if(typescript) { int kind = (!local && builtin->kind() == Builtin::KindObject) ? Builtin::KindValue : builtin->kind(); ostringstream os; if(getModuleMetadata(type) == "ice" && getModuleMetadata(toplevel) != "ice") { os << "iceNS0."; } os << getUnqualified(typeScriptBuiltinTable[kind], toplevel->scope(), "iceNS0."); return os.str(); } else { return javaScriptBuiltinTable[builtin->kind()]; } } ClassDeclPtr cl = ClassDeclPtr::dynamicCast(type); if(cl) { string prefix; ostringstream os; if(typescript) { if(cl->isInterface() && !local) { prefix = importPrefix("Ice.Value", toplevel); } else { prefix = importPrefix(ContainedPtr::dynamicCast(cl), toplevel, imports); } } os << prefix; if(!prefix.empty() && typescript) { if(cl->isInterface() && !local) { os << getUnqualified("Ice.Value", toplevel->scope(), prefix); } else { os << getUnqualified(fixId(cl->scoped()), toplevel->scope(), prefix); } } else { os << fixId(cl->scoped()); } return os.str(); } ProxyPtr proxy = ProxyPtr::dynamicCast(type); if(proxy) { ostringstream os; ClassDefPtr def = proxy->_class()->definition(); if(!def->isInterface() && def->allOperations().empty()) { if(getModuleMetadata(toplevel) != "ice") { os << "iceNS0."; } os << getUnqualified(typeScriptBuiltinTable[Builtin::KindObjectProxy], toplevel->scope(), getModuleMetadata(toplevel)); } else { string prefix; if(typescript) { prefix = importPrefix(ContainedPtr::dynamicCast(def), toplevel, imports); os << prefix; } if(prefix.empty() && typescript) { os << getUnqualified(fixId(proxy->_class()->scoped() + "Prx"), toplevel->scope(), prefix); } else { os << fixId(proxy->_class()->scoped() + "Prx"); } } return os.str(); } if(!typescript || definition) { SequencePtr seq = SequencePtr::dynamicCast(type); if (seq) { BuiltinPtr b = BuiltinPtr::dynamicCast(seq->type()); if (b && b->kind() == Builtin::KindByte) { return "Uint8Array"; } else { return typeToString(seq->type(), toplevel, imports, typescript) + "[]"; } } DictionaryPtr d = DictionaryPtr::dynamicCast(type); if(d) { const TypePtr keyType = d->keyType(); BuiltinPtr builtin = BuiltinPtr::dynamicCast(keyType); ostringstream os; if ((builtin && builtin->kind() == Builtin::KindLong) || StructPtr::dynamicCast(keyType)) { const string prefix = importPrefix("Ice.HashMap", toplevel); os << prefix << getUnqualified("Ice.HashMap", toplevel->scope(), prefix); } else { os << "Map"; } if (typescript) { os << "<" << typeToString(keyType, toplevel, imports, true) << ", " << typeToString(d->valueType(), toplevel, imports, true) << ">"; } return os.str(); } } ContainedPtr contained = ContainedPtr::dynamicCast(type); if(contained) { ostringstream os; string prefix; if(typescript) { prefix = importPrefix(contained, toplevel, imports); os << prefix; } if(prefix.empty() && typescript) { os << getUnqualified(fixId(contained->scoped()), toplevel->scope(), prefix); } else { os << fixId(contained->scoped()); } return os.str(); } return "???"; }