diff options
Diffstat (limited to 'cpp/src')
-rw-r--r-- | cpp/src/Slice/CPlusPlusUtil.cpp | 86 | ||||
-rw-r--r-- | cpp/src/slice2cppe/Gen.cpp | 57 |
2 files changed, 105 insertions, 38 deletions
diff --git a/cpp/src/Slice/CPlusPlusUtil.cpp b/cpp/src/Slice/CPlusPlusUtil.cpp index 13800c2fcfe..cd711376f1f 100644 --- a/cpp/src/Slice/CPlusPlusUtil.cpp +++ b/cpp/src/Slice/CPlusPlusUtil.cpp @@ -120,7 +120,7 @@ Slice::printDllExportStuff(Output& out, const string& dllExport) } string -Slice::typeToString(const TypePtr& type) +Slice::typeToString(const TypePtr& type, const StringList& metaData) { static const char* builtinTable[] = { @@ -154,6 +154,18 @@ Slice::typeToString(const TypePtr& type) { return fixKwd(proxy->_class()->scoped() + "Prx"); } + + SequencePtr seq = SequencePtr::dynamicCast(type); + if(seq) + { + string seqType = findMetaData(metaData); + if(seqType == "array") + { + TypePtr seqType = seq->type(); + string s = typeToString(seqType); + return "::std::pair<const " + s + "*, const " + s + "*>"; + } + } ContainedPtr contained = ContainedPtr::dynamicCast(type); if(contained) @@ -182,7 +194,7 @@ Slice::returnTypeToString(const TypePtr& type) } string -Slice::inputTypeToString(const TypePtr& type) +Slice::inputTypeToString(const TypePtr& type, const StringList& metaData) { static const char* inputBuiltinTable[] = { @@ -222,6 +234,18 @@ Slice::inputTypeToString(const TypePtr& type) { return fixKwd(en->scoped()); } + + SequencePtr seq = SequencePtr::dynamicCast(type); + if(seq) + { + string seqType = findMetaData(metaData); + if(seqType == "array") + { + TypePtr seqType = seq->type(); + string s = typeToString(seqType); + return "const ::std::pair<const " + s + "*, const " + s + "*>&"; + } + } ContainedPtr contained = ContainedPtr::dynamicCast(type); if(contained) @@ -395,7 +419,7 @@ Slice::fixKwd(const string& name) void Slice::writeMarshalUnmarshalCode(Output& out, const TypePtr& type, const string& param, bool marshal, - const string& str, bool pointer) + const string& str, bool pointer, const StringList& metaData) { string fixedParam = fixKwd(param); @@ -470,16 +494,39 @@ Slice::writeMarshalUnmarshalCode(Output& out, const TypePtr& type, const string& SequencePtr seq = SequencePtr::dynamicCast(type); if(seq) { + string seqType = findMetaData(metaData); builtin = BuiltinPtr::dynamicCast(seq->type()); if(builtin && builtin->kind() != Builtin::KindObject && builtin->kind() != Builtin::KindObjectProxy) { - out << nl << stream << deref << func << fixedParam << ");"; + if(seqType == "array" && builtin->kind() != Builtin::KindByte) + { + out << nl << typeToString(type) << " __" << fixedParam << ";"; + out << nl << stream << deref << func << "__" << fixedParam << ");"; + } + else + { + out << nl << stream << deref << func << fixedParam << ");"; + } } else { string scope = fixKwd(seq->scope()); - out << nl << scope << "__" << func << (pointer ? "" : "&") << stream << ", " - << fixedParam << ", " << scope << "__U__" << fixKwd(seq->name()) << "());"; + if(seqType == "array") + { + out << nl << typeToString(type) << " __" << fixedParam << ";"; + out << nl << scope << "__" << func << (pointer ? "" : "&") << stream << ", __" + << fixedParam << ", " << scope << "__U__" << fixKwd(seq->name()) << "());"; + } + else + { + out << nl << scope << "__" << func << (pointer ? "" : "&") << stream << ", " + << fixedParam << ", " << scope << "__U__" << fixKwd(seq->name()) << "());"; + } + } + if(seqType == "array" && (!builtin || builtin->kind() != Builtin::KindByte)) + { + out << nl << fixedParam << ".first" << " = &__" << fixedParam << ".front();"; + out << nl << fixedParam << ".second" << " = &__" << fixedParam << ".back() + 1;"; } return; } @@ -936,3 +983,30 @@ Slice::writeStreamUnmarshalCode(Output& out, const list<pair<TypePtr, string> >& writeStreamMarshalUnmarshalCode(out, ret, "__ret", false, ""); } } + +string +Slice::findMetaData(const StringList& metaData) +{ + static const string prefix = "cpp:"; + for(StringList::const_iterator q = metaData.begin(); q != metaData.end(); ++q) + { + string str = *q; + if(str.find(prefix) == 0) + { + string::size_type pos = str.find(':', prefix.size()); + if(pos != string::npos) + { + if(str.substr(prefix.size(), pos - prefix.size()) == "type") + { + return str.substr(pos + 1); + } + } + else + { + return str.substr(prefix.size()); + } + } + } + + return ""; +} diff --git a/cpp/src/slice2cppe/Gen.cpp b/cpp/src/slice2cppe/Gen.cpp index e259cef6fc4..15566bff723 100644 --- a/cpp/src/slice2cppe/Gen.cpp +++ b/cpp/src/slice2cppe/Gen.cpp @@ -1483,6 +1483,7 @@ Slice::Gen::DelegateVisitor::visitOperation(const OperationPtr& p) string paramName = fixKwd((*q)->name()); TypePtr type = (*q)->type(); bool isOutParam = (*q)->isOutParam(); + string typeString; if(isOutParam) { @@ -2164,15 +2165,9 @@ Slice::Gen::ObjectVisitor::visitOperation(const OperationPtr& p) ContainerPtr container = p->container(); ClassDefPtr cl = ClassDefPtr::dynamicCast(container); - string classNameAMD = "AMD_" + cl->name(); - string classScope = fixKwd(cl->scope()); - string classScopedAMD = classScope + classNameAMD; - string paramsAMD = "(const " + classScopedAMD + '_' + name + "Ptr&, "; - string paramsDeclAMD = "(const " + classScopedAMD + '_' + name + "Ptr& __cb, "; - string argsAMD = "(__cb, "; - TypeStringList inParams; + ParamDeclList inParams; TypeStringList outParams; ParamDeclList paramList = p->parameters(); for(ParamDeclList::const_iterator q = paramList.begin(); q != paramList.end(); ++q) @@ -2180,6 +2175,8 @@ Slice::Gen::ObjectVisitor::visitOperation(const OperationPtr& p) string paramName = fixKwd((*q)->name()); TypePtr type = (*q)->type(); bool isOutParam = (*q)->isOutParam(); + StringList metaData = (*q)->getMetaData(); + string typeString; if(isOutParam) { @@ -2188,8 +2185,8 @@ Slice::Gen::ObjectVisitor::visitOperation(const OperationPtr& p) } else { - inParams.push_back(make_pair(type, paramName)); - typeString = inputTypeToString((*q)->type()); + inParams.push_back(*q); + typeString = inputTypeToString(type, metaData); } if(q != paramList.begin()) @@ -2204,18 +2201,6 @@ Slice::Gen::ObjectVisitor::visitOperation(const OperationPtr& p) paramsDecl += ' '; paramsDecl += paramName; args += paramName; - - if(!isOutParam) - { - paramsAMD += typeString; - paramsAMD += ", "; - paramsDeclAMD += typeString; - paramsDeclAMD += ' '; - paramsDeclAMD += paramName; - paramsDeclAMD += ", "; - argsAMD += paramName; - argsAMD += ", "; - } } if(!cl->isLocal()) @@ -2238,10 +2223,6 @@ Slice::Gen::ObjectVisitor::visitOperation(const OperationPtr& p) args += ')'; } - paramsAMD += "const ::Ice::Current& = ::Ice::Current())"; - paramsDeclAMD += "const ::Ice::Current& __current)"; - argsAMD += "__current)"; - bool nonmutating = p->mode() == Operation::Nonmutating; H << sp; @@ -2284,8 +2265,17 @@ Slice::Gen::ObjectVisitor::visitOperation(const OperationPtr& p) { C << nl << "::IceInternal::BasicStream* __os = __in.os();"; } - writeAllocateCode(C, inParams, 0); - writeUnmarshalCode(C, inParams, 0); + + ParamDeclList::const_iterator pli; + for(pli = inParams.begin(); pli != inParams.end(); ++pli) + { + C << nl << typeToString((*pli)->type(), (*pli)->getMetaData()) << ' ' << fixKwd((*pli)->name()) << ';'; + } + for(pli = inParams.begin(); pli != inParams.end(); ++pli) + { + writeMarshalUnmarshalCode(C, (*pli)->type(), fixKwd((*pli)->name()), false, "", true, + (*pli)->getMetaData()); + } writeAllocateCode(C, outParams, 0); if(!throws.empty()) { @@ -2716,7 +2706,6 @@ Slice::Gen::ImplVisitor::visitClassDefStart(const ClassDefPtr& p) string name = p->name(); string scope = fixKwd(p->scope()); string cls = scope.substr(2) + name + "I"; - string classScopedAMD = scope + "AMD_" + name; ClassList bases = p->bases(); ClassDefPtr base; @@ -2769,6 +2758,8 @@ Slice::Gen::ImplVisitor::visitClassDefStart(const ClassDefPtr& p) { H << ',' << nl; } + + StringList metaData = (*q)->getMetaData(); #if defined(__SUNPRO_CC) && (__SUNPRO_CC==0x550) // // Work around for Sun CC 5.5 bug #4853566 @@ -2780,11 +2771,11 @@ Slice::Gen::ImplVisitor::visitClassDefStart(const ClassDefPtr& p) } else { - typeString = inputTypeToString((*q)->type()); + typeString = inputTypeToString((*q)->type(), metaData); } #else string typeString = (*q)->isOutParam() ? - outputTypeToString((*q)->type()) : inputTypeToString((*q)->type()); + outputTypeToString((*q)->type()) : inputTypeToString((*q)->type(), metaData); #endif H << typeString; } @@ -2811,6 +2802,8 @@ Slice::Gen::ImplVisitor::visitClassDefStart(const ClassDefPtr& p) { C << ',' << nl; } + + StringList metaData = (*q)->getMetaData(); #if defined(__SUNPRO_CC) && (__SUNPRO_CC==0x550) // // Work around for Sun CC 5.5 bug #4853566 @@ -2822,11 +2815,11 @@ Slice::Gen::ImplVisitor::visitClassDefStart(const ClassDefPtr& p) } else { - typeString = inputTypeToString((*q)->type()); + typeString = inputTypeToString((*q)->type(), metaData); } #else string typeString = (*q)->isOutParam() ? - outputTypeToString((*q)->type()) : inputTypeToString((*q)->type()); + outputTypeToString((*q)->type()) : inputTypeToString((*q)->type(), metaData); #endif C << typeString << ' ' << fixKwd((*q)->name()); } |