summaryrefslogtreecommitdiff
path: root/cpp/src/slice2cpp
diff options
context:
space:
mode:
authorMichi Henning <michi@zeroc.com>2006-02-03 03:52:47 +0000
committerMichi Henning <michi@zeroc.com>2006-02-03 03:52:47 +0000
commitdb2fb08fa0a424110b695d6686d4b74c87243183 (patch)
treed5dc47e9a8c5b3672c343e692d10121ae3f9912d /cpp/src/slice2cpp
parentAdded missing dependencies for custom build step. (diff)
downloadice-db2fb08fa0a424110b695d6686d4b74c87243183.tar.bz2
ice-db2fb08fa0a424110b695d6686d4b74c87243183.tar.xz
ice-db2fb08fa0a424110b695d6686d4b74c87243183.zip
Fixed bug in initializer list for one-shot constructors of classes.
Diffstat (limited to 'cpp/src/slice2cpp')
-rw-r--r--cpp/src/slice2cpp/Gen.cpp129
-rw-r--r--cpp/src/slice2cpp/Gen.h2
2 files changed, 90 insertions, 41 deletions
diff --git a/cpp/src/slice2cpp/Gen.cpp b/cpp/src/slice2cpp/Gen.cpp
index 21851b71304..58afc6fb28c 100644
--- a/cpp/src/slice2cpp/Gen.cpp
+++ b/cpp/src/slice2cpp/Gen.cpp
@@ -2322,7 +2322,6 @@ Slice::Gen::ObjectVisitor::visitClassDefStart(const ClassDefPtr& p)
vector<string> params;
vector<string> allTypes;
vector<string> allParamDecls;
- vector<string>::const_iterator pi;
DataMemberList::const_iterator q;
for(q = dataMembers.begin(); q != dataMembers.end(); ++q)
@@ -2390,46 +2389,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 += "__ice_" + (*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
@@ -3420,6 +3380,93 @@ Slice::Gen::ObjectVisitor::emitGCClearCode(const TypePtr& p, const string& prefi
}
}
+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/slice2cpp/Gen.h b/cpp/src/slice2cpp/Gen.h
index e419b82a508..db91856bb20 100644
--- a/cpp/src/slice2cpp/Gen.h
+++ b/cpp/src/slice2cpp/Gen.h
@@ -236,6 +236,8 @@ private:
void emitGCFunctions(const ClassDefPtr&);
void emitGCInsertCode(const TypePtr&, const std::string&, const std::string&, int);
void emitGCClearCode(const TypePtr&, const std::string&, const std::string&, int);
+ bool emitVirtualBaseInitializers(const ClassDefPtr&, bool);
+ void emitOneShotConstructor(const ClassDefPtr&);
void emitUpcall(const ClassDefPtr&, const std::string&);
::IceUtil::Output& H;