diff options
Diffstat (limited to 'cpp/src')
-rw-r--r-- | cpp/src/Slice/JavaUtil.cpp | 179 | ||||
-rw-r--r-- | cpp/src/Slice/Parser.cpp | 139 | ||||
-rw-r--r-- | cpp/src/slice2cppe/Gen.cpp | 11 | ||||
-rw-r--r-- | cpp/src/slice2cppe/Main.cpp | 2 | ||||
-rw-r--r-- | cpp/src/slice2javae/Gen.cpp | 147 | ||||
-rw-r--r-- | cpp/src/slice2javae/Main.cpp | 2 |
6 files changed, 255 insertions, 225 deletions
diff --git a/cpp/src/Slice/JavaUtil.cpp b/cpp/src/Slice/JavaUtil.cpp index 88ca2adf72f..049b62da2f4 100644 --- a/cpp/src/Slice/JavaUtil.cpp +++ b/cpp/src/Slice/JavaUtil.cpp @@ -154,6 +154,13 @@ Slice::JavaGenerator::JavaGenerator(const string& dir) : { } +Slice::JavaGenerator::JavaGenerator(const string& dir, Slice::FeatureProfile profile) : + _featureProfile(profile), + _dir(dir), + _out(0) +{ +} + Slice::JavaGenerator::~JavaGenerator() { assert(_out == 0); @@ -660,28 +667,31 @@ Slice::JavaGenerator::writeMarshalUnmarshalCode(Output& out, } case Builtin::KindObject: { - if(marshal) - { - out << nl << stream << ".writeObject(" << v << ");"; - } - else - { - if(holder) + if(_featureProfile != Slice::IceE) + { + if(marshal) { - out << nl << stream << ".readObject(" << param << ".getPatcher());"; + out << nl << stream << ".writeObject(" << v << ");"; } else { - if(patchParams.empty()) - { - out << nl << stream << ".readObject(new Patcher());"; - } - else - { - out << nl << stream << ".readObject(" << patchParams << ");"; - } + if(holder) + { + out << nl << stream << ".readObject(" << param << ".getPatcher());"; + } + else + { + if(patchParams.empty()) + { + out << nl << stream << ".readObject(new Patcher());"; + } + else + { + out << nl << stream << ".readObject(" << patchParams << ");"; + } + } } - } + } break; } case Builtin::KindObjectProxy: @@ -723,29 +733,32 @@ Slice::JavaGenerator::writeMarshalUnmarshalCode(Output& out, ClassDeclPtr cl = ClassDeclPtr::dynamicCast(type); if(cl) { - if(marshal) - { - out << nl << stream << ".writeObject(" << v << ");"; - } - else - { - string typeS = typeToString(type, TypeModeIn, package); - if(holder) + if(_featureProfile != Slice::IceE) + { + if(marshal) { - out << nl << stream << ".readObject(" << param << ".getPatcher());"; + out << nl << stream << ".writeObject(" << v << ");"; } else { - if(patchParams.empty()) - { - out << nl << stream << ".readObject(new Patcher());"; - } - else - { - out << nl << stream << ".readObject(" << patchParams << ");"; - } + string typeS = typeToString(type, TypeModeIn, package); + if(holder) + { + out << nl << stream << ".readObject(" << param << ".getPatcher());"; + } + else + { + if(patchParams.empty()) + { + out << nl << stream << ".readObject(new Patcher());"; + } + else + { + out << nl << stream << ".readObject(" << patchParams << ");"; + } + } } - } + } return; } @@ -1551,28 +1564,31 @@ Slice::JavaGenerator::writeStreamMarshalUnmarshalCode(Output& out, } case Builtin::KindObject: { - if(marshal) - { - out << nl << stream << ".writeObject(" << v << ");"; - } - else - { - if(holder) - { - out << nl << stream << ".readObject((Ice.ReadObjectCallback)" << param << ".getPatcher());"; - } - else - { - if(patchParams.empty()) - { - out << nl << stream << ".readObject(new Patcher());"; - } - else - { - out << nl << stream << ".readObject(" << patchParams << ");"; - } - } - } + if(_featureProfile != Slice::IceE) + { + if(marshal) + { + out << nl << stream << ".writeObject(" << v << ");"; + } + else + { + if(holder) + { + out << nl << stream << ".readObject((Ice.ReadObjectCallback)" << param << ".getPatcher());"; + } + else + { + if(patchParams.empty()) + { + out << nl << stream << ".readObject(new Patcher());"; + } + else + { + out << nl << stream << ".readObject(" << patchParams << ");"; + } + } + } + } break; } case Builtin::KindObjectProxy: @@ -1614,29 +1630,32 @@ Slice::JavaGenerator::writeStreamMarshalUnmarshalCode(Output& out, ClassDeclPtr cl = ClassDeclPtr::dynamicCast(type); if(cl) { - if(marshal) - { - out << nl << stream << ".writeObject(" << v << ");"; - } - else - { - string typeS = typeToString(type, TypeModeIn, package); - if(holder) - { - out << nl << stream << ".readObject(" << param << ".getPatcher());"; - } - else - { - if(patchParams.empty()) - { - out << nl << stream << ".readObject(new Patcher());"; - } - else - { - out << nl << stream << ".readObject(" << patchParams << ");"; - } - } - } + if(_featureProfile != Slice::IceE) + { + if(marshal) + { + out << nl << stream << ".writeObject(" << v << ");"; + } + else + { + string typeS = typeToString(type, TypeModeIn, package); + if(holder) + { + out << nl << stream << ".readObject(" << param << ".getPatcher());"; + } + else + { + if(patchParams.empty()) + { + out << nl << stream << ".readObject(new Patcher());"; + } + else + { + out << nl << stream << ".readObject(" << patchParams << ");"; + } + } + } + } return; } diff --git a/cpp/src/Slice/Parser.cpp b/cpp/src/Slice/Parser.cpp index d9cfc8ba2e2..6460efcaad4 100644 --- a/cpp/src/Slice/Parser.cpp +++ b/cpp/src/Slice/Parser.cpp @@ -760,6 +760,17 @@ Slice::Container::createSequence(const string& name, const TypePtr& type, bool l { checkPrefix(name); + if(_unit->profile() == IceE && !local) + { + BuiltinPtr builtin = BuiltinPtr::dynamicCast(type); + if((builtin && builtin->kind() == Builtin::KindObject) || ClassDeclPtr::dynamicCast(type)) + { + string msg = "Sequence `" + name + "' cannot contain object values."; + _unit->error(msg); + return 0; + } + } + ContainedList matches = _unit->findContents(thisScope() + name); if(!matches.empty()) { @@ -809,6 +820,17 @@ Slice::Container::createDictionary(const string& name, const TypePtr& keyType, c { checkPrefix(name); + if(_unit->profile() == IceE && !local) + { + BuiltinPtr builtin = BuiltinPtr::dynamicCast(valueType); + if((builtin && builtin->kind() == Builtin::KindObject) || ClassDeclPtr::dynamicCast(valueType)) + { + string msg = "Dictionary `" + name + "' cannot contain object values."; + _unit->error(msg); + return 0; + } + } + ContainedList matches = _unit->findContents(thisScope() + name); if(!matches.empty()) { @@ -2526,6 +2548,28 @@ Slice::ClassDef::createDataMember(const string& name, const TypePtr& type) { checkPrefix(name); + if(_unit->profile() == IceE) + { + if(!isLocal()) + { + BuiltinPtr builtin = BuiltinPtr::dynamicCast(type); + if((builtin && builtin->kind() == Builtin::KindObject)) + { + string msg = "Class data member `" + name + "' cannot be a value object."; + _unit->error(msg); + return 0; + } + + ClassDeclPtr classDecl = ClassDeclPtr::dynamicCast(type); + if(classDecl != 0 && !classDecl->isLocal()) + { + string msg = "Class data member `" + name + "' cannot be a value object."; + _unit->error(msg); + return 0; + } + } + } + assert(!isInterface()); ContainedList matches = _unit->findContents(thisScope() + name); if(!matches.empty()) @@ -2970,6 +3014,28 @@ Slice::Exception::createDataMember(const string& name, const TypePtr& type) { checkPrefix(name); + if(_unit->profile() == IceE) + { + if(!isLocal()) + { + BuiltinPtr builtin = BuiltinPtr::dynamicCast(type); + if((builtin && builtin->kind() == Builtin::KindObject)) + { + string msg = "Exception data member `" + name + "' cannot be a value object."; + _unit->error(msg); + return 0; + } + + ClassDeclPtr classDecl = ClassDeclPtr::dynamicCast(type); + if(classDecl != 0 && !classDecl->isLocal()) + { + string msg = "Exception data member `" + name + "' cannot be a value object."; + _unit->error(msg); + return 0; + } + } + } + ContainedList matches = _unit->findContents(thisScope() + name); if(!matches.empty()) { @@ -3241,6 +3307,27 @@ Slice::Struct::createDataMember(const string& name, const TypePtr& type) { checkPrefix(name); + if(_unit->profile() == IceE) + { + if(!isLocal()) + { + BuiltinPtr builtin = BuiltinPtr::dynamicCast(type); + if((builtin && builtin->kind() == Builtin::KindObject)) + { + string msg = "Struct data member `" + name + "' cannot be a value object."; + _unit->error(msg); + return 0; + } + ClassDeclPtr classDecl = ClassDeclPtr::dynamicCast(type); + if(classDecl != 0 && !classDecl->isLocal()) + { + string msg = "Struct data member `" + name + "' cannot be a value object."; + _unit->error(msg); + return 0; + } + } + } + ContainedList matches = _unit->findContents(thisScope() + name); if(!matches.empty()) { @@ -4086,6 +4173,29 @@ Slice::Operation::createParamDecl(const string& name, const TypePtr& type, bool { checkPrefix(name); + if(_unit->profile() == IceE) + { + ClassDefPtr cl = ClassDefPtr::dynamicCast(this->container()); + assert(cl); + if(!cl->isLocal()) + { + BuiltinPtr builtin = BuiltinPtr::dynamicCast(type); + if((builtin && builtin->kind() == Builtin::KindObject)) + { + string msg = "Object `" + name + "' cannot be passed by value."; + _unit->error(msg); + return 0; + } + ClassDeclPtr classDecl = ClassDeclPtr::dynamicCast(type); + if(classDecl != 0 && !classDecl->isLocal()) + { + string msg = "Object `" + name + "' cannot be passed by value."; + _unit->error(msg); + return 0; + } + } + } + ContainedList matches = _unit->findContents(thisScope() + name); if(!matches.empty()) { @@ -4372,6 +4482,26 @@ Slice::Operation::Operation(const ContainerPtr& container, _returnType(returnType), _mode(mode) { + if(_unit->profile() == IceE) + { + ClassDefPtr cl = ClassDefPtr::dynamicCast(this->container()); + assert(cl); + if(!cl->isLocal()) + { + BuiltinPtr builtin = BuiltinPtr::dynamicCast(returnType); + if((builtin && builtin->kind() == Builtin::KindObject)) + { + string msg = "Method `" + name + "' cannot return an object by value."; + _unit->error(msg); + } + ClassDeclPtr classDecl = ClassDeclPtr::dynamicCast(returnType); + if(classDecl != 0 && !classDecl->isLocal()) + { + string msg = "Method `" + name + "' cannot return an object by value."; + _unit->error(msg); + } + } + } } // ---------------------------------------------------------------------- @@ -4970,6 +5100,12 @@ Slice::Unit::usesConsts() const return false; } +FeatureProfile +Slice::Unit::profile() const +{ + return _featureProfile; +} + StringList Slice::Unit::includeFiles() const { @@ -4977,7 +5113,7 @@ Slice::Unit::includeFiles() const } int -Slice::Unit::parse(FILE* file, bool debug) +Slice::Unit::parse(FILE* file, bool debug, Slice::FeatureProfile profile) { slice_debug = debug ? 1 : 0; @@ -4987,6 +5123,7 @@ Slice::Unit::parse(FILE* file, bool debug) _currentComment = ""; _currentLine = 1; _currentIncludeLevel = 0; + _featureProfile = profile; pushContainer(this); pushDefinitionContext(); diff --git a/cpp/src/slice2cppe/Gen.cpp b/cpp/src/slice2cppe/Gen.cpp index 0ea98bc91ff..2b1a50518c8 100644 --- a/cpp/src/slice2cppe/Gen.cpp +++ b/cpp/src/slice2cppe/Gen.cpp @@ -2607,16 +2607,13 @@ Slice::Gen::ImplVisitor::writeDecl(Output& out, const string& name, const TypePt out << " = 0.0"; break; } + case Builtin::KindObject: case Builtin::KindString: case Builtin::KindObjectProxy: case Builtin::KindLocalObject: { break; } - case Builtin::KindObject: // XXX we should do something about this not being permitted here. - { - assert("Slice classes not support in IceE" == 0); - } } } @@ -2662,17 +2659,13 @@ Slice::Gen::ImplVisitor::writeReturn(Output& out, const TypePtr& type) out << nl << "return ::std::string();"; break; } + case Builtin::KindObject: case Builtin::KindObjectProxy: case Builtin::KindLocalObject: { out << nl << "return 0;"; break; } - case Builtin::KindObject: // XXX we should do something about this not being permitted here. - { - assert("Slice classes not support in IceE" == 0); - } - } } else diff --git a/cpp/src/slice2cppe/Main.cpp b/cpp/src/slice2cppe/Main.cpp index 87a5f82ebfd..0b463233774 100644 --- a/cpp/src/slice2cppe/Main.cpp +++ b/cpp/src/slice2cppe/Main.cpp @@ -189,7 +189,7 @@ main(int argc, char* argv[]) else { UnitPtr u = Unit::createUnit(false, false, ice, caseSensitive); - int parseStatus = u->parse(cppHandle, debug); + int parseStatus = u->parse(cppHandle, debug, Slice::IceE); if(!icecpp.close()) { diff --git a/cpp/src/slice2javae/Gen.cpp b/cpp/src/slice2javae/Gen.cpp index 2179a969ebc..ae512fe9188 100644 --- a/cpp/src/slice2javae/Gen.cpp +++ b/cpp/src/slice2javae/Gen.cpp @@ -62,7 +62,7 @@ sliceModeToIceMode(const OperationPtr& op) } Slice::JavaVisitor::JavaVisitor(const string& dir) : - JavaGenerator(dir) + JavaGenerator(dir, Slice::IceE) { } @@ -501,10 +501,6 @@ Slice::JavaVisitor::writeDispatch(Output& out, const ClassDefPtr& p) writeMarshalUnmarshalCode(out, package, paramType, paramName, false, iter, false, metaData); } } - if(op->sendsClasses()) - { - out << nl << "__is.readPendingObjects();"; - } // // Create holders for 'out' parameters. @@ -559,10 +555,6 @@ Slice::JavaVisitor::writeDispatch(Output& out, const ClassDefPtr& p) { writeMarshalUnmarshalCode(out, package, ret, "__ret", true, iter, false, opMetaData); } - if(op->returnsClasses()) - { - out << nl << "__os.writePendingObjects();"; - } out << nl << "return IceInternal.DispatchStatus.DispatchOK;"; // @@ -1252,31 +1244,6 @@ Slice::Gen::TypesVisitor::visitClassDefStart(const ClassDefPtr& p) out << sb; // - // Default factory for non-abstract classes. - // - if(!p->isAbstract() && !p->isLocal()) - { - out << sp; - out << nl << "private static class __F extends Ice.LocalObjectImpl implements Ice.ObjectFactory"; - out << sb; - out << nl << "public Ice.Object" << nl << "create(String type)"; - out << sb; - out << nl << "assert(type.equals(ice_staticId()));"; - out << nl << "return new " << fixKwd(name) << "();"; - out << eb; - out << sp << nl << "public void" << nl << "destroy()"; - out << sb; - out << eb; - out << eb; - out << nl << "private static Ice.ObjectFactory _factory = new __F();"; - out << sp; - out << nl << "public static Ice.ObjectFactory" << nl << "ice_factory()"; - out << sb; - out << nl << "return _factory;"; - out << eb; - } - - // // Marshalling & dispatch support. // if(!p->isInterface() && !p->isLocal()) @@ -1566,14 +1533,6 @@ Slice::Gen::TypesVisitor::visitExceptionEnd(const ExceptionPtr& p) for(d = members.begin(); d != members.end(); ++d) { ostringstream patchParams; - BuiltinPtr builtin = BuiltinPtr::dynamicCast((*d)->type()); - if((builtin && builtin->kind() == Builtin::KindObject) || ClassDeclPtr::dynamicCast((*d)->type())) - { - if(classMembers.size() > 1 || allClassMembers.size() > 1) - { - patchParams << "new Patcher(" << classMemberCount++ << ')'; - } - } StringList metaData = (*d)->getMetaData(); writeMarshalUnmarshalCode(out, package, (*d)->type(), fixKwd((*d)->name()), false, iter, false, metaData, patchParams.str()); @@ -1585,16 +1544,6 @@ Slice::Gen::TypesVisitor::visitExceptionEnd(const ExceptionPtr& p) } out << eb; - if(p->usesClasses()) - { - if(!base || base && !base->usesClasses()) - { - out << sp << nl << "public boolean" << nl << "__usesClasses()"; - out << sb; - out << nl << "return true;"; - out << eb; - } - } } out << eb; @@ -1842,14 +1791,6 @@ Slice::Gen::TypesVisitor::visitStructEnd(const StructPtr& p) for(d = members.begin(); d != members.end(); ++d) { ostringstream patchParams; - BuiltinPtr builtin = BuiltinPtr::dynamicCast((*d)->type()); - if((builtin && builtin->kind() == Builtin::KindObject) || ClassDeclPtr::dynamicCast((*d)->type())) - { - if(classMembers.size() > 1) - { - patchParams << "new Patcher(" << classMemberCount++ << ')'; - } - } StringList metaData = (*d)->getMetaData(); writeMarshalUnmarshalCode(out, package, (*d)->type(), fixKwd((*d)->name()), false, iter, false, metaData, patchParams.str()); @@ -2195,33 +2136,6 @@ Slice::Gen::HolderVisitor::writeHolder(const TypePtr& p) out << sb; out << nl << "this.value = value;"; out << eb; - if(!p->isLocal()) - { - BuiltinPtr builtin = BuiltinPtr::dynamicCast(p); - if((builtin && builtin->kind() == Builtin::KindObject) || ClassDeclPtr::dynamicCast(p)) - { - out << sp << nl << "public class Patcher implements IceInternal.Patcher"; - out << sb; - out << nl << "public void"; - out << nl << "patch(Ice.Object v)"; - out << sb; - out << nl << "value = (" << typeS << ")v;"; - out << eb; - - out << sp << nl << "public String" << nl << "type()"; - out << sb; - out << nl << "return \"" << p->typeId() << "\";"; - out << eb; - - out << eb; - - out << sp << nl << "public Patcher"; - out << nl << "getPatcher()"; - out << sb; - out << nl << "return new Patcher();"; - out << eb; - } - } out << sp << nl << "public " << typeS << " value;"; out << eb; close(); @@ -2642,11 +2556,12 @@ Slice::Gen::HelperVisitor::visitDictionary(const DictionaryPtr& p) break; } case Builtin::KindString: - case Builtin::KindObject: case Builtin::KindObjectProxy: { break; } + + case Builtin::KindObject: case Builtin::KindLocalObject: { assert(false); @@ -2811,16 +2726,12 @@ Slice::Gen::HelperVisitor::visitDictionary(const DictionaryPtr& p) out << nl << "java.lang.String " << arg << " = __is.readString();"; break; } - case Builtin::KindObject: - { - out << nl << "__is.readObject(new Patcher(__r, __key));"; - break; - } case Builtin::KindObjectProxy: { out << nl << "Ice.ObjectPrx " << arg << " = __is.readProxy();"; break; } + case Builtin::KindObject: case Builtin::KindLocalObject: { assert(false); @@ -2831,17 +2742,8 @@ Slice::Gen::HelperVisitor::visitDictionary(const DictionaryPtr& p) else { string s = typeToString(type, TypeModeIn, package); - BuiltinPtr builtin2 = BuiltinPtr::dynamicCast(type); - if((builtin2 && builtin2->kind() == Builtin::KindObject) || ClassDeclPtr::dynamicCast(type)) - { - writeMarshalUnmarshalCode(out, package, type, arg, false, iter, false, StringList(), - "new Patcher(__r, __key)"); - } - else - { - out << nl << s << ' ' << arg << ';'; - writeMarshalUnmarshalCode(out, package, type, arg, false, iter, false); - } + out << nl << s << ' ' << arg << ';'; + writeMarshalUnmarshalCode(out, package, type, arg, false, iter, false); } } if(!(builtin && builtin->kind() == Builtin::KindObject) && !ClassDeclPtr::dynamicCast(value)) @@ -3047,10 +2949,6 @@ Slice::Gen::DelegateVisitor::visitClassDefStart(const ClassDefPtr& p) writeMarshalUnmarshalCode(out, package, (*pli)->type(), fixKwd((*pli)->name()), true, iter, false, (*pli)->getMetaData()); } - if(op->sendsClasses()) - { - out << nl << "__os.writePendingObjects();"; - } out << eb; out << nl << "catch(Ice.LocalException __ex)"; out << sb; @@ -3086,33 +2984,12 @@ Slice::Gen::DelegateVisitor::visitClassDefStart(const ClassDefPtr& p) } if(ret) { - BuiltinPtr builtin = BuiltinPtr::dynamicCast(ret); - if((builtin && builtin->kind() == Builtin::KindObject) || ClassDeclPtr::dynamicCast(ret)) - { - out << nl << retS << "Holder __ret = new " << retS << "Holder();"; - out << nl << "__is.readObject(__ret.getPatcher());"; - } - else - { - out << nl << retS << " __ret;"; - writeMarshalUnmarshalCode(out, package, ret, "__ret", false, iter, false, opMetaData); - } + out << nl << retS << " __ret;"; + writeMarshalUnmarshalCode(out, package, ret, "__ret", false, iter, false, opMetaData); } - if(op->returnsClasses()) - { - out << nl << "__is.readPendingObjects();"; - } if(ret) { - BuiltinPtr builtin = BuiltinPtr::dynamicCast(ret); - if((builtin && builtin->kind() == Builtin::KindObject) || ClassDeclPtr::dynamicCast(ret)) - { - out << nl << "return __ret.value;"; - } - else - { - out << nl << "return __ret;"; - } + out << nl << "return __ret;"; } out << eb; out << nl << "catch(Ice.LocalException __ex)"; @@ -3294,13 +3171,17 @@ Slice::Gen::BaseImplVisitor::writeReturn(Output& out, const TypePtr& type) break; } case Builtin::KindString: - case Builtin::KindObject: case Builtin::KindObjectProxy: case Builtin::KindLocalObject: { out << nl << "return null;"; break; } + case Builtin::KindObject: + { + assert("Ice objects cannot be returned by value in IceE." == 0); + break; + } } return; } diff --git a/cpp/src/slice2javae/Main.cpp b/cpp/src/slice2javae/Main.cpp index 00ac6db90f0..e9e8e24afbf 100644 --- a/cpp/src/slice2javae/Main.cpp +++ b/cpp/src/slice2javae/Main.cpp @@ -188,7 +188,7 @@ main(int argc, char* argv[]) else { UnitPtr p = Unit::createUnit(false, false, ice, caseSensitive); - int parseStatus = p->parse(cppHandle, debug); + int parseStatus = p->parse(cppHandle, debug, Slice::IceE); if(!icecpp.close()) { |