summaryrefslogtreecommitdiff
path: root/cpp/src
diff options
context:
space:
mode:
Diffstat (limited to 'cpp/src')
-rw-r--r--cpp/src/Slice/Grammer.y55
-rw-r--r--cpp/src/Slice/Parser.cpp144
-rw-r--r--cpp/src/Slice/Parser.h121
-rw-r--r--cpp/src/Slice/Scanner.l4
-rw-r--r--cpp/src/slice2cpp/Gen.cpp114
-rw-r--r--cpp/src/slice2cpp/Gen.h1
-rw-r--r--cpp/src/slice2cpp/GenUtil.cpp40
7 files changed, 388 insertions, 91 deletions
diff --git a/cpp/src/Slice/Grammer.y b/cpp/src/Slice/Grammer.y
index dea4d9bbffd..5988491cdf9 100644
--- a/cpp/src/Slice/Grammer.y
+++ b/cpp/src/Slice/Grammer.y
@@ -43,6 +43,7 @@ yyerror(const char* s)
%token ICE_LOCAL_OBJECT
%token ICE_NATIVE
%token ICE_VECTOR
+%token ICE_ENUM
%token ICE_IDENTIFIER
%token ICE_OP_IDENTIFIER
@@ -78,19 +79,22 @@ definitions
// ----------------------------------------------------------------------
definition
// ----------------------------------------------------------------------
-: module
+: module_def
{
}
-| class
+| class_def
{
}
| class_decl
{
}
-| native
+| native_def
{
}
-| vector
+| vector_def
+{
+}
+| enum_def
{
}
;
@@ -125,7 +129,7 @@ export
;
// ----------------------------------------------------------------------
-module
+module_def
// ----------------------------------------------------------------------
: ICE_MODULE ICE_IDENTIFIER
{
@@ -141,7 +145,7 @@ module
;
// ----------------------------------------------------------------------
-class
+class_def
// ----------------------------------------------------------------------
: ICE_CLASS ICE_IDENTIFIER extends
{
@@ -417,7 +421,7 @@ return_type
;
// ----------------------------------------------------------------------
-native
+native_def
// ----------------------------------------------------------------------
: ICE_NATIVE ICE_IDENTIFIER
{
@@ -428,7 +432,7 @@ native
;
// ----------------------------------------------------------------------
-vector
+vector_def
// ----------------------------------------------------------------------
: ICE_VECTOR '<' type '>' ICE_IDENTIFIER
{
@@ -440,6 +444,41 @@ vector
;
// ----------------------------------------------------------------------
+enum_def
+// ----------------------------------------------------------------------
+: ICE_ENUM ICE_IDENTIFIER '{' enumerators '}'
+{
+ String_ptr ident = String_ptr::dynamicCast($2);
+ Enumerators_ptr enumerators = Enumerators_ptr::dynamicCast($4);
+ Container_ptr cont = parser -> currentContainer();
+ Enum_ptr en = cont -> createEnum(ident -> v, enumerators -> v);
+}
+;
+
+// ----------------------------------------------------------------------
+enumerators
+// ----------------------------------------------------------------------
+: ICE_IDENTIFIER ',' enumerators
+{
+ String_ptr ident = String_ptr::dynamicCast($1);
+ Container_ptr cont = parser -> currentContainer();
+ Enumerator_ptr en = cont -> createEnumerator(ident -> v);
+ Enumerators_ptr ens = Enumerators_ptr::dynamicCast($3);
+ ens -> v.push_front(ident -> v);
+ $$ = ens;
+}
+| ICE_IDENTIFIER
+{
+ String_ptr ident = String_ptr::dynamicCast($1);
+ Container_ptr cont = parser -> currentContainer();
+ Enumerator_ptr en = cont -> createEnumerator(ident -> v);
+ Enumerators_ptr ens = new Enumerators;
+ ens -> v.push_front(ident -> v);
+ $$ = ens;
+}
+;
+
+// ----------------------------------------------------------------------
scoped_name
// ----------------------------------------------------------------------
: ICE_IDENTIFIER
diff --git a/cpp/src/Slice/Parser.cpp b/cpp/src/Slice/Parser.cpp
index 35af49c2dcc..58048ca2ca7 100644
--- a/cpp/src/Slice/Parser.cpp
+++ b/cpp/src/Slice/Parser.cpp
@@ -27,6 +27,8 @@ void __Ice::incRef(String* p) { p -> __incRef(); }
void __Ice::decRef(String* p) { p -> __decRef(); }
void __Ice::incRef(Parameters* p) { p -> __incRef(); }
void __Ice::decRef(Parameters* p) { p -> __decRef(); }
+void __Ice::incRef(Enumerators* p) { p -> __incRef(); }
+void __Ice::decRef(Enumerators* p) { p -> __decRef(); }
void __Ice::incRef(Throws* p) { p -> __incRef(); }
void __Ice::decRef(Throws* p) { p -> __decRef(); }
void __Ice::incRef(DataMember* p) { p -> __incRef(); }
@@ -53,10 +55,14 @@ void __Ice::incRef(Proxy* p) { p -> __incRef(); }
void __Ice::decRef(Proxy* p) { p -> __decRef(); }
void __Ice::incRef(Operation* p) { p -> __incRef(); }
void __Ice::decRef(Operation* p) { p -> __decRef(); }
-void __Ice::incRef(Native* p) { p -> __incRef(); }
-void __Ice::decRef(Native* p) { p -> __decRef(); }
void __Ice::incRef(Vector* p) { p -> __incRef(); }
void __Ice::decRef(Vector* p) { p -> __decRef(); }
+void __Ice::incRef(Enum* p) { p -> __incRef(); }
+void __Ice::decRef(Enum* p) { p -> __decRef(); }
+void __Ice::incRef(Enumerator* p) { p -> __incRef(); }
+void __Ice::decRef(Enumerator* p) { p -> __decRef(); }
+void __Ice::incRef(Native* p) { p -> __incRef(); }
+void __Ice::decRef(Native* p) { p -> __decRef(); }
void __Ice::incRef(Parser* p) { p -> __incRef(); }
void __Ice::decRef(Parser* p) { p -> __decRef(); }
@@ -313,15 +319,15 @@ Slice::Container::createClassDecl(const string& name, bool local)
return cl;
}
-Native_ptr
-Slice::Container::createNative(const string& name)
+Vector_ptr
+Slice::Container::createVector(const string& name, const Type_ptr& type)
{
list<Contained_ptr> matches = parser_ -> findContents(thisScope() + name);
if(!matches.empty())
{
if(parser_ -> ignRedefs())
{
- Native_ptr p = Native_ptr::dynamicCast(matches.front());
+ Vector_ptr p = Vector_ptr::dynamicCast(matches.front());
if(p)
return p;
}
@@ -329,20 +335,20 @@ Slice::Container::createNative(const string& name)
assert(false); // TODO: Already exits
}
- Native_ptr p = new Native(this, name);
+ Vector_ptr p = new Vector(this, name, type);
contents_.push_back(p);
return p;
}
-Vector_ptr
-Slice::Container::createVector(const string& name, const Type_ptr& type)
+Enum_ptr
+Slice::Container::createEnum(const string& name, const StringList& enumerators)
{
list<Contained_ptr> matches = parser_ -> findContents(thisScope() + name);
if(!matches.empty())
{
if(parser_ -> ignRedefs())
{
- Vector_ptr p = Vector_ptr::dynamicCast(matches.front());
+ Enum_ptr p = Enum_ptr::dynamicCast(matches.front());
if(p)
return p;
}
@@ -350,7 +356,49 @@ Slice::Container::createVector(const string& name, const Type_ptr& type)
assert(false); // TODO: Already exits
}
- Vector_ptr p = new Vector(this, name, type);
+ Enum_ptr p = new Enum(this, name, enumerators);
+ contents_.push_back(p);
+ return p;
+}
+
+Enumerator_ptr
+Slice::Container::createEnumerator(const std::string& name)
+{
+ list<Contained_ptr> matches = parser_ -> findContents(thisScope() + name);
+ if(!matches.empty())
+ {
+ if(parser_ -> ignRedefs())
+ {
+ Enumerator_ptr p = Enumerator_ptr::dynamicCast(matches.front());
+ if(p)
+ return p;
+ }
+
+ assert(false); // TODO: Already exits
+ }
+
+ Enumerator_ptr p = new Enumerator(this, name);
+ contents_.push_back(p);
+ return p;
+}
+
+Native_ptr
+Slice::Container::createNative(const string& name)
+{
+ list<Contained_ptr> matches = parser_ -> findContents(thisScope() + name);
+ if(!matches.empty())
+ {
+ if(parser_ -> ignRedefs())
+ {
+ Native_ptr p = Native_ptr::dynamicCast(matches.front());
+ if(p)
+ return p;
+ }
+
+ assert(false); // TODO: Already exits
+ }
+
+ Native_ptr p = new Native(this, name);
contents_.push_back(p);
return p;
}
@@ -652,10 +700,10 @@ Slice::ClassDef::destroy()
Operation_ptr
Slice::ClassDef::createOperation(const string& name,
- const Type_ptr& returnType,
- const TypeNameList& inParams,
- const TypeNameList& outParams,
- const TypeList& throws)
+ const Type_ptr& returnType,
+ const TypeStringList& inParams,
+ const TypeStringList& outParams,
+ const TypeList& throws)
{
list<Contained_ptr> matches = parser_ -> findContents(thisScope() + name);
if(!matches.empty())
@@ -812,13 +860,13 @@ Slice::Operation::returnType()
return returnType_;
}
-TypeNameList
+TypeStringList
Slice::Operation::inputParameters()
{
return inParams_;
}
-TypeNameList
+TypeStringList
Slice::Operation::outputParameters()
{
return outParams_;
@@ -843,11 +891,11 @@ Slice::Operation::visit(ParserVisitor* visitor)
}
Slice::Operation::Operation(const Container_ptr& container,
- const string& name,
- const Type_ptr& returnType,
- const TypeNameList& inParams,
- const TypeNameList& outParams,
- const TypeList& throws)
+ const string& name,
+ const Type_ptr& returnType,
+ const TypeStringList& inParams,
+ const TypeStringList& outParams,
+ const TypeList& throws)
: Contained(container, name),
SyntaxTreeBase(container -> parser()),
returnType_(returnType),
@@ -936,8 +984,8 @@ Slice::Vector::visit(ParserVisitor* visitor)
}
Slice::Vector::Vector(const Container_ptr& container,
- const string& name,
- const Type_ptr& type)
+ const string& name,
+ const Type_ptr& type)
: Constructed(container, name),
Type(container -> parser()),
Contained(container, name),
@@ -947,6 +995,56 @@ Slice::Vector::Vector(const Container_ptr& container,
}
// ----------------------------------------------------------------------
+// Enum
+// ----------------------------------------------------------------------
+
+Slice::StringList
+Slice::Enum::enumerators()
+{
+ return enumerators_;
+}
+
+Slice::Contained::ContainedType
+Slice::Enum::containedType()
+{
+ return ContainedTypeEnum;
+}
+
+void
+Slice::Enum::visit(ParserVisitor* visitor)
+{
+ visitor -> visitEnum(this);
+}
+
+Slice::Enum::Enum(const Container_ptr& container,
+ const string& name,
+ const StringList& enumerators)
+ : Constructed(container, name),
+ Type(container -> parser()),
+ Contained(container, name),
+ SyntaxTreeBase(container -> parser()),
+ enumerators_(enumerators)
+{
+}
+
+// ----------------------------------------------------------------------
+// Enumerator
+// ----------------------------------------------------------------------
+
+Slice::Contained::ContainedType
+Slice::Enumerator::containedType()
+{
+ return ContainedTypeEnumerator;
+}
+
+Slice::Enumerator::Enumerator(const Container_ptr& container,
+ const string& name)
+ : Contained(container, name),
+ SyntaxTreeBase(container -> parser())
+{
+}
+
+// ----------------------------------------------------------------------
// Parser
// ----------------------------------------------------------------------
diff --git a/cpp/src/Slice/Parser.h b/cpp/src/Slice/Parser.h
index d11c1eee07c..2c58d2e6794 100644
--- a/cpp/src/Slice/Parser.h
+++ b/cpp/src/Slice/Parser.h
@@ -33,6 +33,7 @@ namespace Slice
class Token;
class String;
class Parameters;
+class Enumerators;
class Throws;
class SyntaxTreeBase;
class Type;
@@ -46,8 +47,10 @@ class ClassDef;
class Proxy;
class Operation;
class DataMember;
-class Native;
class Vector;
+class Enum;
+class Enumerator;
+class Native;
class Parser;
}
@@ -61,6 +64,8 @@ void ICE_API incRef(::Slice::String*);
void ICE_API decRef(::Slice::String*);
void ICE_API incRef(::Slice::Parameters*);
void ICE_API decRef(::Slice::Parameters*);
+void ICE_API incRef(::Slice::Enumerators*);
+void ICE_API decRef(::Slice::Enumerators*);
void ICE_API incRef(::Slice::Throws*);
void ICE_API decRef(::Slice::Throws*);
void ICE_API incRef(::Slice::SyntaxTreeBase*);
@@ -87,10 +92,14 @@ void ICE_API incRef(::Slice::Operation*);
void ICE_API decRef(::Slice::Operation*);
void ICE_API incRef(::Slice::DataMember*);
void ICE_API decRef(::Slice::DataMember*);
-void ICE_API incRef(::Slice::Native*);
-void ICE_API decRef(::Slice::Native*);
void ICE_API incRef(::Slice::Vector*);
void ICE_API decRef(::Slice::Vector*);
+void ICE_API incRef(::Slice::Enum*);
+void ICE_API decRef(::Slice::Enum*);
+void ICE_API incRef(::Slice::Enumerator*);
+void ICE_API decRef(::Slice::Enumerator*);
+void ICE_API incRef(::Slice::Native*);
+void ICE_API decRef(::Slice::Native*);
void ICE_API incRef(::Slice::Parser*);
void ICE_API decRef(::Slice::Parser*);
@@ -102,6 +111,7 @@ namespace Slice
typedef ::__Ice::Handle<Token> Token_ptr;
typedef ::__Ice::Handle<String> String_ptr;
typedef ::__Ice::Handle<Parameters> Parameters_ptr;
+typedef ::__Ice::Handle<Enumerators> Enumerators_ptr;
typedef ::__Ice::Handle<Throws> Throws_ptr;
typedef ::__Ice::Handle<SyntaxTreeBase> SyntaxTreeBase_ptr;
typedef ::__Ice::Handle<Type> Type_ptr;
@@ -115,8 +125,10 @@ typedef ::__Ice::Handle<ClassDef> ClassDef_ptr;
typedef ::__Ice::Handle<Proxy> Proxy_ptr;
typedef ::__Ice::Handle<Operation> Operation_ptr;
typedef ::__Ice::Handle<DataMember> DataMember_ptr;
-typedef ::__Ice::Handle<Native> Native_ptr;
typedef ::__Ice::Handle<Vector> Vector_ptr;
+typedef ::__Ice::Handle<Enum> Enum_ptr;
+typedef ::__Ice::Handle<Enumerator> Enumerator_ptr;
+typedef ::__Ice::Handle<Native> Native_ptr;
typedef ::__Ice::Handle<Parser> Parser_ptr;
}
@@ -125,8 +137,9 @@ namespace Slice
{
typedef std::list<Type_ptr> TypeList;
-typedef std::pair<Type_ptr, std::string> TypeName;
-typedef std::list<TypeName> TypeNameList;
+typedef std::list<std::string> StringList;
+typedef std::pair<Type_ptr, std::string> TypeString;
+typedef std::list<TypeString> TypeStringList;
// ----------------------------------------------------------------------
// ParserVisitor
@@ -147,6 +160,7 @@ public:
virtual void visitOperation(const Operation_ptr&) { };
virtual void visitDataMember(const DataMember_ptr&) { };
virtual void visitVector(const Vector_ptr&) { };
+ virtual void visitEnum(const Enum_ptr&) { };
virtual void visitNative(const Native_ptr&) { };
};
@@ -181,7 +195,19 @@ class ICE_API Parameters : virtual public Token
public:
Parameters() { }
- TypeNameList v;
+ TypeStringList v;
+};
+
+// ----------------------------------------------------------------------
+// Enumerators
+// ----------------------------------------------------------------------
+
+class ICE_API Enumerators : virtual public Token
+{
+public:
+
+ Enumerators() { }
+ StringList v;
};
// ----------------------------------------------------------------------
@@ -278,6 +304,8 @@ public:
enum ContainedType
{
ContainedTypeVector,
+ ContainedTypeEnum,
+ ContainedTypeEnumerator,
ContainedTypeNative,
ContainedTypeModule,
ContainedTypeClass,
@@ -314,6 +342,8 @@ public:
ClassDef_ptr createClassDef(const std::string&, const ClassDef_ptr&, bool);
ClassDecl_ptr createClassDecl(const std::string&, bool);
Vector_ptr createVector(const std::string&, const Type_ptr&);
+ Enum_ptr createEnum(const std::string&, const StringList&);
+ Enumerator_ptr createEnumerator(const std::string&);
Native_ptr createNative(const std::string&);
std::list<Type_ptr> lookupType(const std::string&);
int includeLevel();
@@ -402,7 +432,7 @@ public:
virtual void destroy();
Operation_ptr createOperation(const std::string&, const Type_ptr&,
- const TypeNameList&, const TypeNameList&,
+ const TypeStringList&, const TypeStringList&,
const TypeList&);
DataMember_ptr createDataMember(const std::string&, const Type_ptr&);
ClassDef_ptr base();
@@ -451,8 +481,8 @@ class ICE_API Operation : virtual public Contained
public:
Type_ptr returnType();
- TypeNameList inputParameters();
- TypeNameList outputParameters();
+ TypeStringList inputParameters();
+ TypeStringList outputParameters();
TypeList throws();
virtual ContainedType containedType();
virtual void visit(ParserVisitor*);
@@ -462,14 +492,14 @@ protected:
Operation(const Container_ptr&,
const std::string&,
const Type_ptr&,
- const TypeNameList&,
- const TypeNameList&,
+ const TypeStringList&,
+ const TypeStringList&,
const TypeList&);
friend class ICE_API ClassDef;
Type_ptr returnType_;
- TypeNameList inParams_;
- TypeNameList outParams_;
+ TypeStringList inParams_;
+ TypeStringList outParams_;
TypeList throws_;
};
@@ -496,43 +526,82 @@ protected:
};
// ----------------------------------------------------------------------
-// Native
+// Vector
// ----------------------------------------------------------------------
-class Native : virtual public Constructed
+class ICE_API Vector : virtual public Constructed
{
public:
+ Type_ptr type();
virtual ContainedType containedType();
virtual void visit(ParserVisitor*);
protected:
- Native(const Container_ptr&,
- const std::string&);
- friend class Container;
+ Vector(const Container_ptr&,
+ const std::string&,
+ const Type_ptr&);
+ friend class ICE_API Container;
+
+ Type_ptr type_;
};
// ----------------------------------------------------------------------
-// Vector
+// Enum
// ----------------------------------------------------------------------
-class ICE_API Vector : virtual public Constructed
+class ICE_API Enum : virtual public Constructed
{
public:
- Type_ptr type();
+ StringList enumerators();
virtual ContainedType containedType();
virtual void visit(ParserVisitor*);
protected:
- Vector(const Container_ptr&,
- const std::string&,
- const Type_ptr&);
+ Enum(const Container_ptr&,
+ const std::string&,
+ const StringList&);
friend class ICE_API Container;
+
+ StringList enumerators_;
+};
- Type_ptr type_;
+// ----------------------------------------------------------------------
+// Enumerator
+// ----------------------------------------------------------------------
+
+class ICE_API Enumerator : virtual public Contained
+{
+public:
+
+ virtual ContainedType containedType();
+
+protected:
+
+ Enumerator(const Container_ptr&,
+ const std::string&);
+ friend class ICE_API Container;
+};
+
+// ----------------------------------------------------------------------
+// Native
+// ----------------------------------------------------------------------
+
+class Native : virtual public Constructed
+{
+public:
+
+ virtual ContainedType containedType();
+ virtual void visit(ParserVisitor*);
+
+protected:
+
+ Native(const Container_ptr&,
+ const std::string&);
+ friend class Container;
};
// ----------------------------------------------------------------------
diff --git a/cpp/src/Slice/Scanner.l b/cpp/src/Slice/Scanner.l
index 6f8dd5c4f36..e8e6838daba 100644
--- a/cpp/src/Slice/Scanner.l
+++ b/cpp/src/Slice/Scanner.l
@@ -171,6 +171,10 @@ L [a-zA-Z_]
return ICE_VECTOR;
}
+"enum" {
+ return ICE_ENUM;
+}
+
"\\"?{L}({L}|{D})* {
char* s = yytext;
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)