diff options
author | Jose <jose@zeroc.com> | 2019-07-30 12:45:29 +0200 |
---|---|---|
committer | Jose <jose@zeroc.com> | 2019-07-31 13:13:40 +0200 |
commit | 3e71d9e1a29bc8169452b039bb723406ff8ef0fe (patch) | |
tree | cfde39529b1a21d6f4c4e87b2a92a366eafc9993 /cpp/src | |
parent | Update .npmignore to ignore .tgz files (diff) | |
download | ice-3e71d9e1a29bc8169452b039bb723406ff8ef0fe.tar.bz2 ice-3e71d9e1a29bc8169452b039bb723406ff8ef0fe.tar.xz ice-3e71d9e1a29bc8169452b039bb723406ff8ef0fe.zip |
Fixes for C++ & Swift generated code - Close #458
Diffstat (limited to 'cpp/src')
-rw-r--r-- | cpp/src/Slice/CPlusPlusUtil.cpp | 6 | ||||
-rw-r--r-- | cpp/src/Slice/CPlusPlusUtil.h | 2 | ||||
-rw-r--r-- | cpp/src/slice2cpp/Gen.cpp | 61 | ||||
-rw-r--r-- | cpp/src/slice2swift/SwiftUtil.cpp | 55 |
4 files changed, 92 insertions, 32 deletions
diff --git a/cpp/src/Slice/CPlusPlusUtil.cpp b/cpp/src/Slice/CPlusPlusUtil.cpp index 0ea48a5a2d1..de253779684 100644 --- a/cpp/src/Slice/CPlusPlusUtil.cpp +++ b/cpp/src/Slice/CPlusPlusUtil.cpp @@ -1619,8 +1619,12 @@ Slice::writeStreamHelpers(Output& out, } void -Slice::writeIceTuple(::IceUtilInternal::Output& out, const string& scope, DataMemberList dataMembers, int typeCtx) +Slice::writeIceTuple(::IceUtilInternal::Output& out, DataMemberList dataMembers, int typeCtx) { + // + // Use an empty scope to get full qualified names from calls to typeToString. + // + const string scope = ""; out << nl << "std::tuple<"; for(DataMemberList::const_iterator q = dataMembers.begin(); q != dataMembers.end(); ++q) { diff --git a/cpp/src/Slice/CPlusPlusUtil.h b/cpp/src/Slice/CPlusPlusUtil.h index b8fa3ad9e46..0380971c617 100644 --- a/cpp/src/Slice/CPlusPlusUtil.h +++ b/cpp/src/Slice/CPlusPlusUtil.h @@ -59,7 +59,7 @@ void writeEndCode(::IceUtilInternal::Output&, const ParamDeclList&, const Operat void writeMarshalUnmarshalDataMemberInHolder(IceUtilInternal::Output&, const std::string&, const DataMemberPtr&, bool); void writeMarshalUnmarshalAllInHolder(IceUtilInternal::Output&, const std::string&, const DataMemberList&, bool, bool); void writeStreamHelpers(::IceUtilInternal::Output&, const ContainedPtr&, DataMemberList, bool, bool, bool); -void writeIceTuple(::IceUtilInternal::Output&, const std::string&, DataMemberList, int); +void writeIceTuple(::IceUtilInternal::Output&, DataMemberList, int); bool findMetaData(const std::string&, const ClassDeclPtr&, std::string&); bool findMetaData(const std::string&, const StringList&, std::string&); diff --git a/cpp/src/slice2cpp/Gen.cpp b/cpp/src/slice2cpp/Gen.cpp index eab9a81b8cb..bab73d8a16e 100644 --- a/cpp/src/slice2cpp/Gen.cpp +++ b/cpp/src/slice2cpp/Gen.cpp @@ -1880,20 +1880,11 @@ Slice::Gen::TypesVisitor::visitDataMember(const DataMemberPtr& p) ContainerPtr container = p->container(); string name = fixKwd(p->name()); - string scope = ""; - StructPtr st = StructPtr::dynamicCast(container); - if(st) - { - scope = fixKwd(st->scope()); - } - - ExceptionPtr ex = ExceptionPtr::dynamicCast(container); - if(ex) - { - scope = fixKwd(ex->scope()); - } - writeDocSummary(H, p); + // + // Use an empty scope to get full qualified names from calls to typeToString. + // + const string scope = ""; H << nl << typeToString(p->type(), p->optional(), scope, p->getMetaData(), _useWstring) << ' ' << name << ';'; } @@ -3910,7 +3901,11 @@ Slice::Gen::ObjectVisitor::emitDataMember(const DataMemberPtr& p) ClassDefPtr cl = ClassDefPtr::dynamicCast(container); int typeContext = cl->isLocal() ? TypeContextLocal | _useWstring : _useWstring; writeDocSummary(H, p); - H << nl << typeToString(p->type(), p->optional(), fixKwd(cl->scope()), p->getMetaData(), typeContext) << ' ' + // + // Use an empty scope to get full qualified names from calls to typeToString. + // + const string scope = ""; + H << nl << typeToString(p->type(), p->optional(), scope, p->getMetaData(), typeContext) << ' ' << name << ';'; } @@ -4101,7 +4096,10 @@ void Slice::Gen::ObjectVisitor::emitOneShotConstructor(const ClassDefPtr& p) { DataMemberList allDataMembers = p->allDataMembers(); - string scope = fixKwd(p->scope()); + // + // Use an empty scope to get full qualified names from calls to typeToString. + // + const string scope = ""; if(!allDataMembers.empty()) { @@ -6447,7 +6445,7 @@ Slice::Gen::Cpp11TypesVisitor::visitExceptionStart(const ExceptionPtr& p) H << nl << " * Obtains a tuple containing all of the exception's data members."; H << nl << " * @return The data members in a tuple."; H << nl << " */"; - writeIceTuple(H, scope, p->allDataMembers(), _useWstring); + writeIceTuple(H, p->allDataMembers(), _useWstring); H << sp; H << nl << "/**"; @@ -6607,7 +6605,7 @@ Slice::Gen::Cpp11TypesVisitor::visitStructEnd(const StructPtr& p) H << nl << " * Obtains a tuple containing all of the struct's data members."; H << nl << " * @return The data members in a tuple."; H << nl << " */"; - writeIceTuple(H, fixKwd(p->scope()), p->dataMembers(), _useWstring); + writeIceTuple(H, p->dataMembers(), _useWstring); H << eb << ';'; _useWstring = resetUseWstring(_useWstringHist); } @@ -6615,7 +6613,10 @@ Slice::Gen::Cpp11TypesVisitor::visitStructEnd(const StructPtr& p) void Slice::Gen::Cpp11TypesVisitor::visitDataMember(const DataMemberPtr& p) { - string scope = fixKwd(ContainedPtr::dynamicCast(p->container())->scope()); + // + // Use an empty scope to get full qualified names from calls to typeToString. + // + const string scope = ""; string name = fixKwd(p->name()); writeDocSummary(H, p); H << nl << typeToString(p->type(), p->optional(), scope, p->getMetaData(), _useWstring | TypeContextCpp11) @@ -6877,7 +6878,10 @@ Slice::Gen::Cpp11ProxyVisitor::visitOperation(const OperationPtr& p) if(ret) { - futureOutParams.push_back(typeToString(ret, retIsOpt, clScope, p->getMetaData(), _useWstring | + // + // Use empty scope to get full qualified names in types used with future declarations. + // + futureOutParams.push_back(typeToString(ret, retIsOpt, "", p->getMetaData(), _useWstring | TypeContextCpp11)); lambdaOutParams.push_back(typeToString(ret, retIsOpt, clScope, p->getMetaData(), _useWstring | @@ -6893,7 +6897,10 @@ Slice::Gen::Cpp11ProxyVisitor::visitOperation(const OperationPtr& p) if((*q)->isOutParam()) { - futureOutParams.push_back(typeToString((*q)->type(), (*q)->optional(), clScope, metaData, + // + // Use empty scope to get full qualified names in types used with future declarations. + // + futureOutParams.push_back(typeToString((*q)->type(), (*q)->optional(), "", metaData, _useWstring | TypeContextCpp11)); lambdaOutParams.push_back(typeToString((*q)->type(), (*q)->optional(), clScope, metaData, _useWstring | TypeContextInParam | TypeContextCpp11)); @@ -6980,7 +6987,7 @@ Slice::Gen::Cpp11ProxyVisitor::visitOperation(const OperationPtr& p) H << "auto _result = "; } - H << "_makePromiseOutgoing<" << getUnqualified(futureT, cl->scoped()) << ">"; + H << "_makePromiseOutgoing<" << futureT << ">"; H << spar << "true, this" << "&" + cl->name() + "Prx::_iceI_" + name; for(ParamDeclList::const_iterator q = inParams.begin(); q != inParams.end(); ++q) @@ -7391,7 +7398,10 @@ Slice::Gen::Cpp11ObjectVisitor::emitDataMember(const DataMemberPtr& p) int typeContext = _useWstring | TypeContextCpp11; ContainerPtr container = p->container(); ClassDefPtr cl = ClassDefPtr::dynamicCast(container); - string scope = fixKwd(cl->scope()); + // + // Use empty scope to get full qualified names in types used with future declarations. + // + string scope = ""; if(cl->isLocal()) { typeContext |= TypeContextLocal; @@ -8512,7 +8522,7 @@ Slice::Gen::Cpp11ValueVisitor::visitClassDefStart(const ClassDefPtr& p) H << nl << " * Obtains a tuple containing all of the value's data members."; H << nl << " * @return The data members in a tuple."; H << nl << " */"; - writeIceTuple(H, fixKwd(p->scope()), p->allDataMembers(), _useWstring); + writeIceTuple(H, p->allDataMembers(), _useWstring); H << sp; H << nl << "/**"; @@ -8751,7 +8761,10 @@ void Slice::Gen::Cpp11ObjectVisitor::emitOneShotConstructor(const ClassDefPtr& p) { DataMemberList allDataMembers = p->allDataMembers(); - string scope = fixKwd(p->scope()); + // + // Use empty scope to get full qualified names in types used with future declarations. + // + string scope = ""; if(!allDataMembers.empty()) { vector<string> allParamDecls; diff --git a/cpp/src/slice2swift/SwiftUtil.cpp b/cpp/src/slice2swift/SwiftUtil.cpp index 626b43847bc..c2d554a836b 100644 --- a/cpp/src/slice2swift/SwiftUtil.cpp +++ b/cpp/src/slice2swift/SwiftUtil.cpp @@ -1579,10 +1579,27 @@ SwiftGenerator::writeMembers(IceUtilInternal::Output& out, { DataMemberPtr member = *q; TypePtr type = member->type(); - string defaultValue = member->defaultValue(); + const string defaultValue = member->defaultValue(); + + const string memberName = fixIdent(member->name()); + string memberType = typeToString(type, p, member->getMetaData(), member->optional(), typeCtx); + + // + // If the member type is equal to the member name, create a local type alias + // to avoid ambiguity. + // + string alias; + if(!protocol && memberName == memberType && (StructPtr::dynamicCast(type) || + SequencePtr::dynamicCast(type) || + DictionaryPtr::dynamicCast(type))) + { + ModulePtr m = getTopLevelModule(type); + alias = m->name() + "_" + memberType; + out << nl << "typealias " << alias << " = " << memberType; + } + writeMemberDoc(out, member); - out << nl << access << "var " << fixIdent(member->name()) << ": " - << typeToString(type, p, member->getMetaData(), member->optional(), typeCtx); + out << nl << access << "var " << memberName << ": " << memberType; if(protocol) { out << " { get set }"; @@ -1590,8 +1607,15 @@ SwiftGenerator::writeMembers(IceUtilInternal::Output& out, else { out << " = "; - writeConstantValue(out, type, member->defaultValueType(), defaultValue, p->getMetaData(), swiftModule, - member->optional()); + if(alias.empty()) + { + writeConstantValue(out, type, member->defaultValueType(), defaultValue, p->getMetaData(), swiftModule, + member->optional()); + } + else + { + out << alias << "()"; + } } } } @@ -1728,7 +1752,26 @@ SwiftGenerator::writeMarshalUnmarshalCode(Output &out, { args += ", value: "; } - args += getUnqualified(getAbsolute(type), swiftModule) + ".self"; + string memberType = getUnqualified(getAbsolute(type), swiftModule); + string memberName; + const string memberPrefix = "self."; + if(param.find(memberPrefix) == 0) + { + memberName = param.substr(memberPrefix.size()); + } + + string alias; + // + // If the member type is equal to the member name, create a local type alias + // to avoid ambiguity. + // + if(memberType == memberName) + { + ModulePtr m = getTopLevelModule(type); + alias = m->name() + "_" + memberType; + out << nl << "typealias " << alias << " = " << memberType; + } + args += (alias.empty() ? memberType : alias) + ".self"; out << nl << "try " << stream << ".read(" << args << ") { " << param << " = $0 " << "}"; } } |