diff options
Diffstat (limited to 'cpp/src/slice2cppe')
-rw-r--r-- | cpp/src/slice2cppe/Gen.cpp | 148 | ||||
-rw-r--r-- | cpp/src/slice2cppe/Gen.h | 2 |
2 files changed, 100 insertions, 50 deletions
diff --git a/cpp/src/slice2cppe/Gen.cpp b/cpp/src/slice2cppe/Gen.cpp index d5e16aa66ba..be6a5fad300 100644 --- a/cpp/src/slice2cppe/Gen.cpp +++ b/cpp/src/slice2cppe/Gen.cpp @@ -384,10 +384,9 @@ Slice::Gen::TypesVisitor::visitExceptionStart(const ExceptionPtr& p) for(q = allDataMembers.begin(); q != allDataMembers.end(); ++q) { - string paramName = fixKwd((*q)->name()); string typeName = inputTypeToString((*q)->type(), (*q)->getMetaData()); allTypes.push_back(typeName); - allParamDecls.push_back(typeName + " __ice_" + paramName); + allParamDecls.push_back(typeName + " __ice_" + (*q)->name()); } if(base) @@ -395,7 +394,7 @@ Slice::Gen::TypesVisitor::visitExceptionStart(const ExceptionPtr& p) DataMemberList baseDataMembers = base->allDataMembers(); for(q = baseDataMembers.begin(); q != baseDataMembers.end(); ++q) { - baseParams.push_back("__ice_" + fixKwd((*q)->name())); + baseParams.push_back("__ice_" + (*q)->name()); } } @@ -427,7 +426,10 @@ Slice::Gen::TypesVisitor::visitExceptionStart(const ExceptionPtr& p) { H << " {}"; } - H << ';'; + else + { + H << ';'; + } if(!allTypes.empty()) { H << nl; @@ -772,8 +774,8 @@ Slice::Gen::TypesVisitor::visitSequence(const SequencePtr& p) TypePtr type = p->type(); string s = typeToString(type); StringList metaData = p->getMetaData(); - string seqType = findMetaData(metaData, false); - if(!seqType.empty()) + string seqType = findMetaData(metaData); + if(!seqType.empty() && seqType != "array" && seqType.find("range") != 0) { H << sp << nl << "typedef " << seqType << ' ' << name << ';'; } @@ -1805,7 +1807,6 @@ Slice::Gen::ObjectVisitor::visitClassDefStart(const ClassDefPtr& p) vector<string> allTypes; vector<string> allParamDecls; DataMemberList::const_iterator q; - vector<string>::const_iterator pi; for(q = dataMembers.begin(); q != dataMembers.end(); ++q) { @@ -1814,15 +1815,14 @@ Slice::Gen::ObjectVisitor::visitClassDefStart(const ClassDefPtr& p) for(q = allDataMembers.begin(); q != allDataMembers.end(); ++q) { - string paramName = fixKwd((*q)->name()); string typeName = inputTypeToString((*q)->type(), (*q)->getMetaData()); allTypes.push_back(typeName); - allParamDecls.push_back(typeName + " __ice_" + paramName); + allParamDecls.push_back(typeName + " __ice_" + (*q)->name()); } if(!p->isInterface()) { - H << nl << name << "() {};"; + H << nl << name << "() {}"; if(!allParamDecls.empty()) { H << nl; @@ -1873,46 +1873,7 @@ Slice::Gen::ObjectVisitor::visitClassDefStart(const ClassDefPtr& p) * Strong guarantee */ - if(!allParamDecls.empty()) - { - C << sp << nl << scoped.substr(2) << "::" << name << spar << allParamDecls << epar << " :"; - C.inc(); - if(base) - { - string upcall; - if(!allParamDecls.empty() && base) - { - upcall = "("; - DataMemberList baseDataMembers = bases.front()->allDataMembers(); - for(q = baseDataMembers.begin(); q != baseDataMembers.end(); ++q) - { - if(q != baseDataMembers.begin()) - { - upcall += ", "; - } - upcall += fixKwd((*q)->name()); - } - upcall += ")"; - } - if(!params.empty()) - { - upcall += ","; - } - emitUpcall(base, upcall); - } - C << nl; - for(pi = params.begin(); pi != params.end(); ++pi) - { - if(pi != params.begin()) - { - C << ',' << nl; - } - C << *pi << '(' << "__ice_" << *pi << ')'; - } - C.dec(); - C << sb; - C << eb; - } + emitOneShotConstructor(p); /* * Strong guarantee @@ -2378,6 +2339,93 @@ Slice::Gen::ObjectVisitor::visitDataMember(const DataMemberPtr& p) H << nl << s << ' ' << name << ';'; } +bool +Slice::Gen::ObjectVisitor::emitVirtualBaseInitializers(const ClassDefPtr& p, bool first) +{ + DataMemberList allDataMembers = p->allDataMembers(); + if(allDataMembers.empty()) + { + return false; + } + + if(!first) + { + C << ","; + } + + string upcall = "("; + DataMemberList::const_iterator q; + for(q = allDataMembers.begin(); q != allDataMembers.end(); ++q) + { + if(q != allDataMembers.begin()) + { + upcall += ", "; + } + upcall += "__ice_" + (*q)->name(); + } + upcall += ")"; + + C << nl << fixKwd(p->name()) << upcall; + + ClassList bases = p->bases(); + ClassDefPtr base; + if(!bases.empty() && !bases.front()->isInterface()) + { + emitVirtualBaseInitializers(bases.front(), false); + } + + return true; +} + +void +Slice::Gen::ObjectVisitor::emitOneShotConstructor(const ClassDefPtr& p) +{ + DataMemberList allDataMembers = p->allDataMembers(); + DataMemberList::const_iterator q; + + vector<string> allParamDecls; + + for(q = allDataMembers.begin(); q != allDataMembers.end(); ++q) + { + string typeName = inputTypeToString((*q)->type()); + allParamDecls.push_back(typeName + " __ice_" + (*q)->name()); + } + + if(!allDataMembers.empty()) + { + C << sp << nl << p->scoped().substr(2) << "::" << fixKwd(p->name()) << spar << allParamDecls << epar << " :"; + C.inc(); + + DataMemberList dataMembers = p->dataMembers(); + + ClassList bases = p->bases(); + ClassDefPtr base; + if(!bases.empty() && !bases.front()->isInterface()) + { + if(emitVirtualBaseInitializers(bases.front(), true) && !dataMembers.empty()) + { + C << ','; + } + } + + C << nl; + + for(q = dataMembers.begin(); q != dataMembers.end(); ++q) + { + if(q != dataMembers.begin()) + { + C << ',' << nl; + } + string memberName = fixKwd((*q)->name()); + C << memberName << '(' << "__ice_" << memberName << ')'; + } + + C.dec(); + C << sb; + C << eb; + } +} + void Slice::Gen::ObjectVisitor::emitUpcall(const ClassDefPtr& base, const string& call) { diff --git a/cpp/src/slice2cppe/Gen.h b/cpp/src/slice2cppe/Gen.h index 77a29656ed9..b1d9406a7ce 100644 --- a/cpp/src/slice2cppe/Gen.h +++ b/cpp/src/slice2cppe/Gen.h @@ -190,6 +190,8 @@ private: private: + bool emitVirtualBaseInitializers(const ClassDefPtr&, bool); + void emitOneShotConstructor(const ClassDefPtr&); void emitUpcall(const ClassDefPtr&, const std::string&); ::IceUtil::Output& H; |