bool FreezeScript::AnalyzeInitVisitor::visitStructStart(const StructPtr& v) { if(v->isLocal()) { return false; } string scoped = v->scoped(); TypeList l = _oldUnit->lookupTypeNoBuiltin(scoped, false); if(!l.empty()) { StructPtr s = StructPtr::dynamicCast(l.front()); if(!s) { typeChange(l.front(), scoped, "struct"); } else { return false; } } _out.newline(); _out.newline(); _out << "<!-- struct " << scoped << " -->"; _out << se("init") << attr("type", scoped); _out << ee; return false; }
bool FreezeScript::AnalyzeTransformVisitor::visitStructStart(const StructPtr& v) { if(v->isLocal()) { return false; } string scoped = v->scoped(); if(ignoreType(scoped)) { return false; } TypeList l = _newUnit->lookupTypeNoBuiltin(scoped, false); if(l.empty()) { _missingTypes.push_back(scoped); return false; } StructPtr newStruct = StructPtr::dynamicCast(l.front()); if(!newStruct) { if(!_ignoreTypeChanges) { typeChange(scoped, v, l.front()); } return false; } _out.newline(); _out.newline(); _out << "<!-- struct " << scoped << " -->"; _out << se("transform") << attr("type", scoped); DataMemberList oldMembers = v->dataMembers(); DataMemberList newMembers = newStruct->dataMembers(); compareMembers(oldMembers, newMembers); _out << ee; return false; }
bool Slice::ChecksumVisitor::visitStructStart(const StructPtr& p) { if (p->isLocal()) { return false; } ostringstream ostr; ostr << "struct " << p->name() << endl; DataMemberList members = p->dataMembers(); for (DataMemberList::iterator q = members.begin(); q != members.end(); ++q) { ostr << typeToString((*q)->type()) << ' ' << (*q)->name() << endl; } updateMap(p->scoped(), ostr.str()); return false; }
string Slice::inputTypeToString(const TypePtr& type, bool optional, const StringList& metaData, int typeCtx, bool cpp11) { static const char* cpp98InputBuiltinTable[] = { "::Ice::Byte", "bool", "::Ice::Short", "::Ice::Int", "::Ice::Long", "::Ice::Float", "::Ice::Double", "const ::std::string&", "const ::Ice::ObjectPtr&", "const ::Ice::ObjectPrx&", "const ::Ice::LocalObjectPtr&", "const ::Ice::ValuePtr&" }; static const char* cpp11InputLocalBuiltinTable[] = { "::Ice::Byte", "bool", "short", "int", "long long int", "float", "double", "const ::std::string&", "const ::std::shared_ptr<::Ice::Object>&", "const ::std::shared_ptr<::Ice::ObjectPrx>&", "const ::std::shared_ptr<void>&", "const ::std::shared_ptr<::Ice::Value>&" }; static const char* cpp11InputBuiltinTable[] = { "::Ice::Byte", "bool", "short", "int", "long long int", "float", "double", "::std::string&", "::std::shared_ptr<::Ice::Object>", "::std::shared_ptr<::Ice::ObjectPrx>", "::std::shared_ptr<void>", "::std::shared_ptr<::Ice::Value>" }; typeCtx |= TypeContextInParam; if(optional) { if(cpp11 && !(typeCtx & TypeContextLocalOperation) && !(typeCtx & TypeContextAMD)) { return "IceUtil::Optional<" + toTemplateArg(typeToString(type, metaData, typeCtx, cpp11)) +">"; } else { return "const IceUtil::Optional<" + toTemplateArg(typeToString(type, metaData, typeCtx, cpp11)) +">&"; } } BuiltinPtr builtin = BuiltinPtr::dynamicCast(type); if(builtin) { if(builtin->kind() == Builtin::KindString) { if(cpp11 && !(typeCtx & TypeContextLocalOperation) && !(typeCtx & TypeContextAMD)) { return stringTypeToString(type, metaData, typeCtx); } else { return string("const ") + stringTypeToString(type, metaData, typeCtx) + "&"; } } else { if(cpp11) { if(builtin->kind() == Builtin::KindObject && !(typeCtx & TypeContextLocalOperation)) { if(typeCtx & TypeContextAMD) { return "const ::std::shared_ptr<::Ice::Value>&"; } else { return "::std::shared_ptr<::Ice::Value>"; } } else { if(typeCtx & TypeContextLocalOperation || typeCtx & TypeContextAMD) { return cpp11InputLocalBuiltinTable[builtin->kind()]; } else { return cpp11InputBuiltinTable[builtin->kind()]; } } } else { return cpp98InputBuiltinTable[builtin->kind()]; } } } ClassDeclPtr cl = ClassDeclPtr::dynamicCast(type); if(cl) { string t; if(cpp11) { if(findMetaData("cpp11:type:", cl, t)) { return t; } else if(cl->isLocal() || (typeCtx & TypeContextLocalOperation)) { if(cl->definition() && cl->definition()->isDelegate()) { return classDefToDelegateString(cl->definition(), typeCtx, cpp11); } else if(typeCtx & TypeContextDelegate) { return "::std::shared_ptr<" + fixKwd(cl->scoped()) + ">"; } else { return "const ::std::shared_ptr<" + fixKwd(cl->scoped()) + ">&"; } } else { if(typeCtx & TypeContextAMD) { if(cl->isInterface()) { return "const ::std::shared_ptr<::Ice::Value>&"; } else { return "const ::std::shared_ptr<" + fixKwd(cl->scoped()) + ">&"; } } else { if(cl->isInterface()) { return "::std::shared_ptr<::Ice::Value>"; } else { return "::std::shared_ptr<" + fixKwd(cl->scoped()) + ">"; } } } } else { return "const " + fixKwd(cl->scoped() + "Ptr&"); } } StructPtr st = StructPtr::dynamicCast(type); if(st) { if(cpp11) { if(st->isLocal() || (typeCtx & TypeContextLocalOperation) || (typeCtx & TypeContextAMD)) { return "const " + fixKwd(st->scoped()) + "&"; } else { return fixKwd(st->scoped()); } } else { if(findMetaData(st->getMetaData()) == "%class") { return "const " + fixKwd(st->scoped() + "Ptr&"); } else { return "const " + fixKwd(st->scoped()) + "&"; } } } ProxyPtr proxy = ProxyPtr::dynamicCast(type); if(proxy) { if(cpp11) { ClassDefPtr def = proxy->_class()->definition(); // // Non local classes without operations map to the base // proxy class shared_ptr<Ice::ObjectPrx> // if(typeCtx & TypeContextLocalOperation) { if(def && !def->isInterface() && def->allOperations().empty()) { return "const ::std::shared_ptr<::Ice::ObjectPrx>&"; } else { return "const ::std::shared_ptr<" + fixKwd(proxy->_class()->scoped() + "Prx") + ">&"; } } else { string t; if(def && !def->isInterface() && def->allOperations().empty()) { t = "::std::shared_ptr<::Ice::ObjectPrx>"; } else { t = "::std::shared_ptr<" + fixKwd(proxy->_class()->scoped() + "Prx") + ">"; } return (typeCtx & TypeContextAMD) ? ("const " + t + "&") : t; } } else { return "const " + fixKwd(proxy->_class()->scoped() + "Prx&"); } } EnumPtr en = EnumPtr::dynamicCast(type); if(en) { return fixKwd(en->scoped()); } SequencePtr seq = SequencePtr::dynamicCast(type); if(seq) { if(cpp11 && !(typeCtx & TypeContextLocalOperation) && !(typeCtx & TypeContextAMD)) { return sequenceTypeToString(seq, metaData, typeCtx); } else { return "const " + sequenceTypeToString(seq, metaData, typeCtx) + "&"; } } DictionaryPtr dict = DictionaryPtr::dynamicCast(type); if(dict) { if(cpp11 && !(typeCtx & TypeContextLocalOperation) && !(typeCtx & TypeContextAMD)) { return dictionaryTypeToString(dict, metaData, typeCtx); } else { return "const " + dictionaryTypeToString(dict, metaData, typeCtx) + "&"; } } ContainedPtr contained = ContainedPtr::dynamicCast(type); if(contained) { if(cpp11 && !(typeCtx & TypeContextLocalOperation) && !(typeCtx & TypeContextAMD)) { return fixKwd(contained->scoped()); } else { return "const " + fixKwd(contained->scoped()) + "&"; } } return "???"; }
bool FreezeScript::AnalyzeTransformVisitor::visitStructStart(const StructPtr& v) { if(v->isLocal()) { return false; } string scoped = v->scoped(); if(ignoreType(scoped)) { return false; } TypeList l = _newUnit->lookupTypeNoBuiltin(scoped, false); if(l.empty()) { _missingTypes.push_back(scoped); return false; } // // Allow transforming from struct to class. // StructPtr newStruct = StructPtr::dynamicCast(l.front()); ClassDeclPtr decl = ClassDeclPtr::dynamicCast(l.front()); ClassDefPtr newClass; if(decl) { newClass = decl->definition(); if(!newClass) { _missingTypes.push_back(scoped); return false; } } else if(!newStruct) { if(!_ignoreTypeChanges) { typeChange(scoped, v, l.front()); } return false; } _out.newline(); _out.newline(); if(newClass) { _out << "<!-- class " << scoped << " -->"; } else { _out << "<!-- struct " << scoped << " -->"; } _out << se("transform") << attr("type", scoped); DataMemberList oldMembers, newMembers; if(newClass) { oldMembers = v->dataMembers(); newMembers = newClass->allDataMembers(); } else { oldMembers = v->dataMembers(); newMembers = newStruct->dataMembers(); } compareMembers(oldMembers, newMembers); _out << ee; return false; }