summaryrefslogtreecommitdiff
path: root/cpp/src/slice2cpp
diff options
context:
space:
mode:
authorMarc Laukien <marc@zeroc.com>2001-07-06 21:19:04 +0000
committerMarc Laukien <marc@zeroc.com>2001-07-06 21:19:04 +0000
commit3330a193df2550dff331238080a5920923a681b8 (patch)
treeb6ff9c6e05be6807b56d38366de99367cb0c81a2 /cpp/src/slice2cpp
parentaddTemporary (diff)
downloadice-3330a193df2550dff331238080a5920923a681b8.tar.bz2
ice-3330a193df2550dff331238080a5920923a681b8.tar.xz
ice-3330a193df2550dff331238080a5920923a681b8.zip
enums
Diffstat (limited to 'cpp/src/slice2cpp')
-rw-r--r--cpp/src/slice2cpp/Gen.cpp114
-rw-r--r--cpp/src/slice2cpp/Gen.h1
-rw-r--r--cpp/src/slice2cpp/GenUtil.cpp40
3 files changed, 121 insertions, 34 deletions
diff --git a/cpp/src/slice2cpp/Gen.cpp b/cpp/src/slice2cpp/Gen.cpp
index 794cfc4c061..80411a97c25 100644
--- a/cpp/src/slice2cpp/Gen.cpp
+++ b/cpp/src/slice2cpp/Gen.cpp
@@ -244,13 +244,15 @@ Slice::Gen::TypesVisitor::visitVector(const Vector_ptr& p)
scope.erase(0, 2);
H << sp;
+ H << nl << "class __U__" << name << " { };";
H << nl << "void" << dllExport_ << " __write(::__Ice::Stream*, const "
- << name << "&);";
+ << name << "&, __U__" << name << ");";
H << nl << "void" << dllExport_ << " __read(::__Ice::Stream*, "
- << name << "&);";
+ << name << "&, __U__" << name << ");";
C << sp;
C << nl << "void" << nl << scope
- << "::__write(::__Ice::Stream* __os, const " << scoped << "& v)";
+ << "::__write(::__Ice::Stream* __os, const " << scoped << "& v, ::"
+ << scope << "::__U__" << name << ')';
C << sb;
C << nl << "__os -> write(::Ice::Int(v.size()));";
C << nl << scoped << "::const_iterator p;";
@@ -261,7 +263,8 @@ Slice::Gen::TypesVisitor::visitVector(const Vector_ptr& p)
C << eb;
C << sp;
C << nl << "void" << nl << scope
- << "::__read(::__Ice::Stream* __is, " << scoped << "& v)";
+ << "::__read(::__Ice::Stream* __is, " << scoped << "& v, ::"
+ << scope << "::__U__" << name << ')';
C << sb;
C << nl << "::Ice::Int sz;";
C << nl << "__is -> read(sz);";
@@ -287,6 +290,79 @@ Slice::Gen::TypesVisitor::visitVector(const Vector_ptr& p)
}
void
+Slice::Gen::TypesVisitor::visitEnum(const Enum_ptr& p)
+{
+ string name = p -> name();
+ StringList enumerators = p -> enumerators();
+ H << sp;
+ H << nl << "enum " << name;
+ H << sb;
+ StringList::iterator en = enumerators.begin();
+ while(en != enumerators.end())
+ {
+ H << nl << *en;
+ if(++en != enumerators.end())
+ H << ',';
+ }
+ H << eb << ';';
+
+ string scoped = p -> scoped();
+ string scope = p -> scope();
+ if(scope.length())
+ scope.erase(0, 2);
+
+ int sz = enumerators.size();
+
+ H << sp;
+ H << nl << "void" << dllExport_ << " __write(::__Ice::Stream*, " << name
+ << ");";
+ H << nl << "void" << dllExport_ << " __read(::__Ice::Stream*, " << name
+ << "&);";
+ C << sp;
+ C << nl << "void" << nl << scope
+ << "::__write(::__Ice::Stream* __os, " << scoped << " v)";
+ C << sb;
+ if(sz <= numeric_limits<Ice::Byte>::max())
+ C << nl << "__os -> write(static_cast< ::Ice::Byte>(v));";
+ else if(sz <= numeric_limits<Ice::Short>::max())
+ C << nl << "__os -> write(static_cast< ::Ice::Short>(v));";
+ else if(sz <= numeric_limits<Ice::Int>::max())
+ C << nl << "__os -> write(static_cast< ::Ice::Int>(v));";
+ else
+ C << nl << "__os -> write(static_cast< ::Ice::Long>(v));";
+ C << eb;
+ C << sp;
+ C << nl << "void" << nl << scope << "::__read(::__Ice::Stream* __is, "
+ << scoped << "& v)";
+ C << sb;
+ if(sz <= numeric_limits<Ice::Byte>::max())
+ {
+ C << nl << "::Ice::Byte val;";
+ C << nl << "__is -> read(val);";
+ C << nl << "v = static_cast< " << scoped << ">(val);";
+ }
+ else if(sz <= numeric_limits<Ice::Short>::max())
+ {
+ C << nl << "::Ice::Short val;";
+ C << nl << "__is -> read(val);";
+ C << nl << "v = static_cast< " << scoped << ">(val);";
+ }
+ else if(sz <= numeric_limits<Ice::Int>::max())
+ {
+ C << nl << "::Ice::Int val;";
+ C << nl << "__is -> read(val);";
+ C << nl << "v = static_cast< " << scoped << ">(val);";
+ }
+ else
+ {
+ C << nl << "::Ice::Long val;";
+ C << nl << "__is -> read(val);";
+ C << nl << "v = static_cast< " << scoped << ">(val);";
+ }
+ C << eb;
+}
+
+void
Slice::Gen::TypesVisitor::visitNative(const Native_ptr& p)
{
string name = p -> name();
@@ -466,9 +542,9 @@ Slice::Gen::ProxyVisitor::visitOperation(const Operation_ptr& p)
Type_ptr ret = p -> returnType();
string retS = returnTypeToString(ret);
- TypeNameList inParams = p -> inputParameters();
- TypeNameList outParams = p -> outputParameters();
- TypeNameList::iterator q;
+ TypeStringList inParams = p -> inputParameters();
+ TypeStringList outParams = p -> outputParameters();
+ TypeStringList::iterator q;
string params = "(";
string paramsDecl = "("; // With declarators
@@ -624,9 +700,9 @@ Slice::Gen::DelegateVisitor::visitOperation(const Operation_ptr& p)
Type_ptr ret = p -> returnType();
string retS = returnTypeToString(ret);
- TypeNameList inParams = p -> inputParameters();
- TypeNameList outParams = p -> outputParameters();
- TypeNameList::iterator q;
+ TypeStringList inParams = p -> inputParameters();
+ TypeStringList outParams = p -> outputParameters();
+ TypeStringList::iterator q;
string params = "(";
string args = "(";
@@ -766,9 +842,9 @@ Slice::Gen::DelegateMVisitor::visitOperation(const Operation_ptr& p)
Type_ptr ret = p -> returnType();
string retS = returnTypeToString(ret);
- TypeNameList inParams = p -> inputParameters();
- TypeNameList outParams = p -> outputParameters();
- TypeNameList::iterator q;
+ TypeStringList inParams = p -> inputParameters();
+ TypeStringList outParams = p -> outputParameters();
+ TypeStringList::iterator q;
string params = "(";
string paramsDecl = "("; // With declarators
@@ -840,7 +916,7 @@ Slice::Gen::DelegateMVisitor::visitOperation(const Operation_ptr& p)
C.dec();
C << nl << "case " << cnt++ << ':';
C.sb();
- TypeNameList li;
+ TypeStringList li;
li.push_back(make_pair(*r, string("__ex")));
writeAllocateCode(C, li, 0);
writeUnmarshalCode(C, li, 0);
@@ -860,7 +936,7 @@ Slice::Gen::DelegateMVisitor::visitOperation(const Operation_ptr& p)
<< "throw ::Ice::UnknownUserException(__FILE__, __LINE__);";
C.dec();
}
- writeAllocateCode(C, TypeNameList(), ret);
+ writeAllocateCode(C, TypeStringList(), ret);
writeUnmarshalCode(C, outParams, ret);
if(ret)
C << nl << "return __ret;";
@@ -1103,7 +1179,7 @@ Slice::Gen::ObjectVisitor::visitClassDefEnd(const ClassDef_ptr& p)
H << nl << "virtual void __write(::__Ice::Stream*);";
H << nl << "virtual void __read(::__Ice::Stream*);";
H << eb << ';';
- TypeNameList memberList;
+ TypeStringList memberList;
list<DataMember_ptr> dataMembers = p -> dataMembers();
list<DataMember_ptr>::const_iterator q;
for(q = dataMembers.begin(); q != dataMembers.end(); ++q)
@@ -1166,9 +1242,9 @@ Slice::Gen::ObjectVisitor::visitOperation(const Operation_ptr& p)
Type_ptr ret = p -> returnType();
string retS = returnTypeToString(ret);
- TypeNameList inParams = p -> inputParameters();
- TypeNameList outParams = p -> outputParameters();
- TypeNameList::iterator q;
+ TypeStringList inParams = p -> inputParameters();
+ TypeStringList outParams = p -> outputParameters();
+ TypeStringList::iterator q;
string params = "(";
string paramsDecl = "("; // With declarators
diff --git a/cpp/src/slice2cpp/Gen.h b/cpp/src/slice2cpp/Gen.h
index 70bafa015ab..c6062512d43 100644
--- a/cpp/src/slice2cpp/Gen.h
+++ b/cpp/src/slice2cpp/Gen.h
@@ -54,6 +54,7 @@ private:
virtual void visitModuleStart(const Module_ptr&);
virtual void visitModuleEnd(const Module_ptr&);
virtual void visitVector(const Vector_ptr&);
+ virtual void visitEnum(const Enum_ptr&);
virtual void visitNative(const Native_ptr&);
private:
diff --git a/cpp/src/slice2cpp/GenUtil.cpp b/cpp/src/slice2cpp/GenUtil.cpp
index 1fa9a009d91..c1adfddd283 100644
--- a/cpp/src/slice2cpp/GenUtil.cpp
+++ b/cpp/src/slice2cpp/GenUtil.cpp
@@ -9,6 +9,7 @@
// **********************************************************************
#include <GenUtil.h>
+#include <limits>
using namespace std;
using namespace Slice;
@@ -91,6 +92,10 @@ Slice::inputTypeToString(const Type_ptr& type)
if(proxy)
return "const " + proxy -> _class() -> scoped() + "_prx&";
+ Enum_ptr en = Enum_ptr::dynamicCast(type);
+ if(en)
+ return en -> scoped();
+
Native_ptr native = Native_ptr::dynamicCast(type);
if(native)
return native -> scoped();
@@ -146,7 +151,7 @@ Slice::outputTypeToString(const Type_ptr& type)
void
Slice::writeMarshalUnmarshalCode(Output& out, const Type_ptr& type,
- const string& param, bool marshal)
+ const string& param, bool marshal)
{
const char* func = marshal ? "write(" : "read(";
const char* stream = marshal ? "__os" : "__is";
@@ -157,16 +162,6 @@ Slice::writeMarshalUnmarshalCode(Output& out, const Type_ptr& type,
return;
}
- Vector_ptr vector = Vector_ptr::dynamicCast(type);
- if(vector && Builtin_ptr::dynamicCast(vector -> type()))
- {
- out << nl << stream << " -> " << func << param << ");";
- return;
- }
-
- Native_ptr native = Native_ptr::dynamicCast(type);
- assert(!native); // TODO
-
ClassDecl_ptr cl = ClassDecl_ptr::dynamicCast(type);
if(cl)
{
@@ -210,6 +205,21 @@ Slice::writeMarshalUnmarshalCode(Output& out, const Type_ptr& type,
return;
}
+ Vector_ptr vec = Vector_ptr::dynamicCast(type);
+ if(vec)
+ {
+ if(Builtin_ptr::dynamicCast(vec -> type()))
+ out << nl << stream << " -> " << func << param << ");";
+ else
+ out << nl << vec -> scope() << "::__" << func << stream\
+ << ", " << param << ", " << vec -> scope()
+ << "::__U__" << vec -> name() << "());";
+ return;
+ }
+
+ Native_ptr native = Native_ptr::dynamicCast(type);
+ assert(!native); // TODO
+
Constructed_ptr constructed = Constructed_ptr::dynamicCast(type);
if(!constructed)
{
@@ -224,8 +234,8 @@ Slice::writeMarshalUnmarshalCode(Output& out, const Type_ptr& type,
void
Slice::writeMarshalCode(Output& out,
- const list<pair<Type_ptr, string> >& params,
- const Type_ptr& ret)
+ const list<pair<Type_ptr, string> >& params,
+ const Type_ptr& ret)
{
list<pair<Type_ptr, string> >::const_iterator p;
for(p = params.begin(); p != params.end(); ++p)
@@ -248,8 +258,8 @@ Slice::writeUnmarshalCode(Output& out,
void
Slice::writeAllocateCode(Output& out,
- const list<pair<Type_ptr, string> >& params,
- const Type_ptr& ret)
+ const list<pair<Type_ptr, string> >& params,
+ const Type_ptr& ret)
{
list<pair<Type_ptr, string> > ps = params;
if(ret)