summaryrefslogtreecommitdiff
path: root/cpp/src/slice2cpp
diff options
context:
space:
mode:
Diffstat (limited to 'cpp/src/slice2cpp')
-rw-r--r--cpp/src/slice2cpp/Gen.cpp138
1 files changed, 58 insertions, 80 deletions
diff --git a/cpp/src/slice2cpp/Gen.cpp b/cpp/src/slice2cpp/Gen.cpp
index a99e81ee046..6f6aa7c2627 100644
--- a/cpp/src/slice2cpp/Gen.cpp
+++ b/cpp/src/slice2cpp/Gen.cpp
@@ -246,6 +246,8 @@ Slice::Gen::generate(const UnitPtr& p)
H << "\n#include <" << changeInclude(*q, _includePaths) << "." << _headerExtension << ">";
}
+ H << "\n#include <Ice/UndefSysMacros.h>";
+
printVersionCheck(H);
printVersionCheck(C);
@@ -402,10 +404,6 @@ Slice::Gen::TypesVisitor::visitExceptionStart(const ExceptionPtr& p)
}
}
- H.zeroIndent();
- H << sp << "#undef " << name;
- H.restoreIndent();
-
H << sp << nl << "class " << _dllExport << name << " : ";
H.useCurrentPosAsIndent();
H << "public ";
@@ -453,9 +451,9 @@ Slice::Gen::TypesVisitor::visitExceptionStart(const ExceptionPtr& p)
if(p->isLocal())
{
- C << sp << nl << scoped << "::" << name << spar << "const char* __file" << "int __line" << epar << " :";
+ C << sp << nl << scoped.substr(2) << "::" << name << spar << "const char* __file" << "int __line" << epar
+ << " :";
C.inc();
- C << nl;
emitUpcall(base, "(__file, __line)", true);
C.dec();
C << sb;
@@ -464,10 +462,8 @@ Slice::Gen::TypesVisitor::visitExceptionStart(const ExceptionPtr& p)
if(!allTypes.empty())
{
- writeUndefines(C, params);
-
C << sp << nl;
- C << scoped << "::" << name << spar;
+ C << scoped.substr(2) << "::" << name << spar;
if(p->isLocal())
{
C << "const char* __file" << "int __line";
@@ -477,34 +473,37 @@ Slice::Gen::TypesVisitor::visitExceptionStart(const ExceptionPtr& p)
{
C << " :";
C.inc();
- C << nl;
- }
- if(p->isLocal() || !baseParams.empty())
- {
- if(p->isLocal())
+ string upcall;
+ if(!allParamDecls.empty())
{
- C << (base ? fixKwd(base->scoped()) : "::Ice::LocalException") << spar << "__file" << "__line";
+ upcall = "(";
+ if(p->isLocal())
+ {
+ upcall += "__file, __line";
+ }
+ for(pi = baseParams.begin(); pi != baseParams.end(); ++pi)
+ {
+ if(p->isLocal() || pi != baseParams.begin())
+ {
+ upcall += ", ";
+ }
+ upcall += *pi;
+ }
+ upcall += ")";
}
- else
+ if(!params.empty())
{
- C << fixKwd(base->scoped()) << spar;
+ upcall += ",";
}
- C << baseParams << epar;
+ emitUpcall(base, upcall, p->isLocal());
}
- if(!params.empty())
+ for(pi = params.begin(); pi != params.end(); ++pi)
{
- if(p->isLocal() || !baseParams.empty())
- {
- C << ',' << nl;
- }
- for(pi = params.begin(); pi != params.end(); ++pi)
+ if(pi != params.begin())
{
- if(pi != params.begin())
- {
- C << ',' << nl;
- }
- C << *pi << "(__" << *pi << ')';
+ C << ",";
}
+ C << nl << *pi << "(__" << *pi << ')';
}
if(p->isLocal() || !baseParams.empty() || !params.empty())
{
@@ -1258,11 +1257,11 @@ Slice::Gen::TypesVisitor::emitUpcall(const ExceptionPtr& base, const string& cal
C.zeroIndent();
C << nl << "#if defined(_MSC_VER) && (_MSC_VER < 1300) // VC++ 6 compiler bug"; // COMPILERBUG
C.restoreIndent();
- C << nl << (base ? fixKwd(base->name()) : (isLocal ? "LocalException" : "Exception")) << call;
+ C << nl << (base ? fixKwd(base->name()) : (isLocal ? "LocalException" : "UserException")) << call;
C.zeroIndent();
C << nl << "#else";
C.restoreIndent();
- C << nl << (base ? fixKwd(base->scoped()) : (isLocal ? "::Ice::LocalException" : "::Ice::Exception")) << call;
+ C << nl << (base ? fixKwd(base->scoped()) : (isLocal ? "::Ice::LocalException" : "::Ice::UserException")) << call;
C.zeroIndent();
C << nl << "#endif";
C.restoreIndent();
@@ -2224,15 +2223,15 @@ Slice::Gen::ObjectVisitor::visitClassDefStart(const ClassDefPtr& p)
string name = fixKwd(p->name());
string scoped = fixKwd(p->scoped());
ClassList bases = p->bases();
- bool hasBaseClass = !bases.empty() && !bases.front()->isInterface();
+ ClassDefPtr base;
+ if(!bases.empty() && !bases.front()->isInterface())
+ {
+ base = bases.front();
+ }
DataMemberList dataMembers = p->dataMembers();
DataMemberList allDataMembers = p->allDataMembers();
DataMemberList::const_iterator q;
- H.zeroIndent();
- H << sp << nl << "#undef " << name;
- H.restoreIndent();
-
H << sp << nl << "class " << _dllExport << name << " : ";
H.useCurrentPosAsIndent();
if(bases.empty())
@@ -2294,11 +2293,14 @@ Slice::Gen::ObjectVisitor::visitClassDefStart(const ClassDefPtr& p)
}
H << name << spar << allTypes << epar << ';';
}
- H << nl << name << "(const " << name << "&)";
- if(allDataMembers.empty())
- {
- H << " {}";
- }
+
+ /*
+ * Strong guarantee: commented-out code marked "String guarantee" generates
+ * a copy-assignment operator that provides the strong exception guarantee.
+ * For now, this is commented out, and we use the compiler-generated
+ * copy-assignment operator. However, that one does not provide the strong
+ * guarantee.
+
H << ';';
if(!p->isAbstract())
{
@@ -2329,15 +2331,17 @@ Slice::Gen::ObjectVisitor::visitClassDefStart(const ClassDefPtr& p)
}
H << eb;
+ * Strong guarantee
+ */
+
if(!allParamDecls.empty())
{
- writeUndefines(C, params);
C << sp << nl << scoped.substr(2) << "::" << name << spar << allParamDecls << epar << " :";
C.inc();
- if(hasBaseClass)
+ if(base)
{
string upcall;
- if(!allParamDecls.empty() && hasBaseClass)
+ if(!allParamDecls.empty() && base)
{
upcall = "(";
DataMemberList baseDataMembers = bases.front()->allDataMembers();
@@ -2355,7 +2359,7 @@ Slice::Gen::ObjectVisitor::visitClassDefStart(const ClassDefPtr& p)
{
upcall += ",";
}
- emitUpcall(bases.front(), upcall);
+ emitUpcall(base, upcall);
}
C << nl;
for(pi = params.begin(); pi != params.end(); ++pi)
@@ -2371,33 +2375,8 @@ Slice::Gen::ObjectVisitor::visitClassDefStart(const ClassDefPtr& p)
C << eb;
}
- if(!allParamDecls.empty())
- {
- C << sp << nl << scoped.substr(2) << "::" << name << "(const " << name << "& __rhs)";
- C << " :";
- C.inc();
- if(hasBaseClass)
- {
- string upcall = "(__rhs)";
- if(!params.empty())
- {
- upcall += ",";
- }
- emitUpcall(bases.front(), upcall);
- }
- C << nl;
- for(pi = params.begin(); pi != params.end(); ++pi)
- {
- if(pi != params.begin())
- {
- C << ',' << nl;
- }
- C << *pi << '(' << "__rhs." << *pi << ')';
- }
- C.dec();
- C << sb;
- C << eb;
- }
+ /*
+ * Strong guarantee
if(!allDataMembers.empty())
{
@@ -2405,9 +2384,9 @@ Slice::Gen::ObjectVisitor::visitClassDefStart(const ClassDefPtr& p)
C << nl << scoped.substr(2) << "::__swap(" << name << "& __lhs, " << name << "& __rhs) throw()";
C << sb;
- if(hasBaseClass)
+ if(base)
{
- emitUpcall(bases.front(), "::__swap(__lhs, __rhs);");
+ emitUpcall(base, "::__swap(__lhs, __rhs);");
}
//
@@ -2469,6 +2448,8 @@ Slice::Gen::ObjectVisitor::visitClassDefStart(const ClassDefPtr& p)
}
}
+ * Strong guarantee
+ */
}
if(!p->isAbstract() && !p->isLocal())
@@ -2479,9 +2460,9 @@ Slice::Gen::ObjectVisitor::visitClassDefStart(const ClassDefPtr& p)
C << nl << "void ";
C << nl << fixKwd(p->scoped()).substr(2) << "::__copyMembers(" << fixKwd(p->scoped() + "Ptr") << " __to) const";
C << sb;
- if(hasBaseClass)
+ if(base)
{
- emitUpcall(bases.front(), "::__copyMembers(__to);");
+ emitUpcall(base, "::__copyMembers(__to);");
}
for(q = dataMembers.begin(); q != dataMembers.end(); ++q)
{
@@ -2496,10 +2477,7 @@ Slice::Gen::ObjectVisitor::visitClassDefStart(const ClassDefPtr& p)
C << nl << fixKwd(p->scoped()).substr(2) << "::ice_clone() const";
C << sb;
C << nl << fixKwd(p->scope()) << p->name() << "Ptr __p = new " << fixKwd(p->scoped()) << ';';
- if(hasBaseClass)
- {
- emitUpcall(p, "::__copyMembers(__p);");
- }
+ emitUpcall(p, "::__copyMembers(__p);");
C << nl << "return __p;";
C << eb;
}