summaryrefslogtreecommitdiff
path: root/cpp/src
diff options
context:
space:
mode:
authorMarc Laukien <marc@zeroc.com>2001-09-07 21:31:09 +0000
committerMarc Laukien <marc@zeroc.com>2001-09-07 21:31:09 +0000
commit3bc54265fc832fbd3da9dd17cfda4f8f0e26874c (patch)
tree2f7a19e6f6127ae26b07a489e837b8d79b565b20 /cpp/src
parentStarted to add structs and maps (diff)
downloadice-3bc54265fc832fbd3da9dd17cfda4f8f0e26874c.tar.bz2
ice-3bc54265fc832fbd3da9dd17cfda4f8f0e26874c.tar.xz
ice-3bc54265fc832fbd3da9dd17cfda4f8f0e26874c.zip
sequence, dictionary
Diffstat (limited to 'cpp/src')
-rw-r--r--cpp/src/Slice/Grammer.y20
-rw-r--r--cpp/src/Slice/Parser.cpp79
-rw-r--r--cpp/src/Slice/Scanner.l8
-rw-r--r--cpp/src/slice2cpp/Gen.cpp68
-rw-r--r--cpp/src/slice2cpp/Gen.h3
-rw-r--r--cpp/src/slice2cpp/GenUtil.cpp18
-rw-r--r--cpp/src/slice2docbook/Gen.cpp147
-rw-r--r--cpp/src/slice2docbook/Gen.h1
8 files changed, 271 insertions, 73 deletions
diff --git a/cpp/src/Slice/Grammer.y b/cpp/src/Slice/Grammer.y
index 026daa19d42..30520b322a4 100644
--- a/cpp/src/Slice/Grammer.y
+++ b/cpp/src/Slice/Grammer.y
@@ -45,8 +45,8 @@ yyerror(const char* s)
%token ICE_OBJECT
%token ICE_LOCAL_OBJECT
%token ICE_NATIVE
-%token ICE_VECTOR
-%token ICE_MAP
+%token ICE_SEQUENCE
+%token ICE_DICTIONARY
%token ICE_ENUM
%token ICE_NONMUTATING
%token ICE_IDENTIFIER
@@ -105,10 +105,10 @@ definition
| native_def
{
}
-| vector_def
+| sequence_def
{
}
-| map_def
+| dictionary_def
{
}
| enum_def
@@ -706,27 +706,27 @@ native_def
;
// ----------------------------------------------------------------------
-vector_def
+sequence_def
// ----------------------------------------------------------------------
-: ICE_VECTOR '<' type '>' ICE_IDENTIFIER
+: ICE_SEQUENCE '<' type '>' ICE_IDENTIFIER
{
StringTokPtr ident = StringTokPtr::dynamicCast($5);
TypePtr type = TypePtr::dynamicCast($3);
ContainerPtr cont = unit->currentContainer();
- cont->createVector(ident->v, type);
+ cont->createSequence(ident->v, type);
}
;
// ----------------------------------------------------------------------
-map_def
+dictionary_def
// ----------------------------------------------------------------------
-: ICE_MAP '<' type ',' type '>' ICE_IDENTIFIER
+: ICE_DICTIONARY '<' type ',' type '>' ICE_IDENTIFIER
{
StringTokPtr ident = StringTokPtr::dynamicCast($7);
TypePtr keyType = TypePtr::dynamicCast($3);
TypePtr valueType = TypePtr::dynamicCast($5);
ContainerPtr cont = unit->currentContainer();
- cont->createMap(ident->v, keyType, valueType);
+ cont->createDictionary(ident->v, keyType, valueType);
}
;
diff --git a/cpp/src/Slice/Parser.cpp b/cpp/src/Slice/Parser.cpp
index ac26565e3a2..5b655387fd1 100644
--- a/cpp/src/Slice/Parser.cpp
+++ b/cpp/src/Slice/Parser.cpp
@@ -49,10 +49,10 @@ void IceInternal::incRef(Operation* p) { p->__incRef(); }
void IceInternal::decRef(Operation* p) { p->__decRef(); }
void IceInternal::incRef(DataMember* p) { p->__incRef(); }
void IceInternal::decRef(DataMember* p) { p->__decRef(); }
-void IceInternal::incRef(Vector* p) { p->__incRef(); }
-void IceInternal::decRef(Vector* p) { p->__decRef(); }
-void IceInternal::incRef(Map* p) { p->__incRef(); }
-void IceInternal::decRef(Map* p) { p->__decRef(); }
+void IceInternal::incRef(Sequence* p) { p->__incRef(); }
+void IceInternal::decRef(Sequence* p) { p->__decRef(); }
+void IceInternal::incRef(Dictionary* p) { p->__incRef(); }
+void IceInternal::decRef(Dictionary* p) { p->__decRef(); }
void IceInternal::incRef(Enum* p) { p->__incRef(); }
void IceInternal::decRef(Enum* p) { p->__decRef(); }
void IceInternal::incRef(Enumerator* p) { p->__incRef(); }
@@ -406,13 +406,13 @@ Slice::Container::createStruct(const string& name)
return p;
}
-VectorPtr
-Slice::Container::createVector(const string& name, const TypePtr& type)
+SequencePtr
+Slice::Container::createSequence(const string& name, const TypePtr& type)
{
ContainedList matches = _unit->findContents(thisScope() + name);
if (!matches.empty())
{
- VectorPtr p = VectorPtr::dynamicCast(matches.front());
+ SequencePtr p = SequencePtr::dynamicCast(matches.front());
if (p)
{
if (_unit->ignRedefs())
@@ -420,7 +420,7 @@ Slice::Container::createVector(const string& name, const TypePtr& type)
return p;
}
- string msg = "redefinition of vector `";
+ string msg = "redefinition of sequence `";
msg += name;
msg += "'";
_unit->error(msg);
@@ -429,23 +429,23 @@ Slice::Container::createVector(const string& name, const TypePtr& type)
string msg = "redefinition of `";
msg += name;
- msg += "' as vector";
+ msg += "' as sequence";
_unit->error(msg);
return 0;
}
- VectorPtr p = new Vector(this, name, type);
+ SequencePtr p = new Sequence(this, name, type);
_contents.push_back(p);
return p;
}
-MapPtr
-Slice::Container::createMap(const string& name, const TypePtr& keyType, const TypePtr& valueType)
+DictionaryPtr
+Slice::Container::createDictionary(const string& name, const TypePtr& keyType, const TypePtr& valueType)
{
ContainedList matches = _unit->findContents(thisScope() + name);
if (!matches.empty())
{
- MapPtr p = MapPtr::dynamicCast(matches.front());
+ DictionaryPtr p = DictionaryPtr::dynamicCast(matches.front());
if (p)
{
if (_unit->ignRedefs())
@@ -453,7 +453,7 @@ Slice::Container::createMap(const string& name, const TypePtr& keyType, const Ty
return p;
}
- string msg = "redefinition of map `";
+ string msg = "redefinition of dictionary `";
msg += name;
msg += "'";
_unit->error(msg);
@@ -462,12 +462,12 @@ Slice::Container::createMap(const string& name, const TypePtr& keyType, const Ty
string msg = "redefinition of `";
msg += name;
- msg += "' as map";
+ msg += "' as dictionary";
_unit->error(msg);
return 0;
}
- MapPtr p = new Map(this, name, keyType, valueType);
+ DictionaryPtr p = new Dictionary(this, name, keyType, valueType);
_contents.push_back(p);
return p;
}
@@ -747,13 +747,13 @@ Slice::Container::structs()
return result;
}
-VectorList
-Slice::Container::vectors()
+SequenceList
+Slice::Container::sequences()
{
- VectorList result;
+ SequenceList result;
for (ContainedList::const_iterator p = _contents.begin(); p != _contents.end(); ++p)
{
- VectorPtr q = VectorPtr::dynamicCast(*p);
+ SequencePtr q = SequencePtr::dynamicCast(*p);
if (q)
{
result.push_back(q);
@@ -762,13 +762,13 @@ Slice::Container::vectors()
return result;
}
-MapList
-Slice::Container::maps()
+DictionaryList
+Slice::Container::dictionaries()
{
- MapList result;
+ DictionaryList result;
for (ContainedList::const_iterator p = _contents.begin(); p != _contents.end(); ++p)
{
- MapPtr q = MapPtr::dynamicCast(*p);
+ DictionaryPtr q = DictionaryPtr::dynamicCast(*p);
if (q)
{
result.push_back(q);
@@ -1647,28 +1647,28 @@ Slice::Native::Native(const ContainerPtr& container, const string& name) :
}
// ----------------------------------------------------------------------
-// Vector
+// Sequence
// ----------------------------------------------------------------------
TypePtr
-Slice::Vector::type()
+Slice::Sequence::type()
{
return _type;
}
Slice::Contained::ContainedType
-Slice::Vector::containedType()
+Slice::Sequence::containedType()
{
- return ContainedTypeVector;
+ return ContainedTypeSequence;
}
void
-Slice::Vector::visit(ParserVisitor* visitor)
+Slice::Sequence::visit(ParserVisitor* visitor)
{
- visitor->visitVector(this);
+ visitor->visitSequence(this);
}
-Slice::Vector::Vector(const ContainerPtr& container, const string& name, const TypePtr& type) :
+Slice::Sequence::Sequence(const ContainerPtr& container, const string& name, const TypePtr& type) :
Constructed(container, name),
Type(container->unit()),
Contained(container, name),
@@ -1678,34 +1678,35 @@ Slice::Vector::Vector(const ContainerPtr& container, const string& name, const T
}
// ----------------------------------------------------------------------
-// Map
+// Dictionary
// ----------------------------------------------------------------------
TypePtr
-Slice::Map::keyType()
+Slice::Dictionary::keyType()
{
return _keyType;
}
TypePtr
-Slice::Map::valueType()
+Slice::Dictionary::valueType()
{
return _valueType;
}
Slice::Contained::ContainedType
-Slice::Map::containedType()
+Slice::Dictionary::containedType()
{
- return ContainedTypeMap;
+ return ContainedTypeDictionary;
}
void
-Slice::Map::visit(ParserVisitor* visitor)
+Slice::Dictionary::visit(ParserVisitor* visitor)
{
- visitor->visitMap(this);
+ visitor->visitDictionary(this);
}
-Slice::Map::Map(const ContainerPtr& container, const string& name, const TypePtr& keyType, const TypePtr& valueType) :
+Slice::Dictionary::Dictionary(const ContainerPtr& container, const string& name, const TypePtr& keyType,
+ const TypePtr& valueType) :
Constructed(container, name),
Type(container->unit()),
Contained(container, name),
diff --git a/cpp/src/Slice/Scanner.l b/cpp/src/Slice/Scanner.l
index bb4980ebc32..28ae3658b92 100644
--- a/cpp/src/Slice/Scanner.l
+++ b/cpp/src/Slice/Scanner.l
@@ -181,12 +181,12 @@ L [a-zA-Z_]
return ICE_NATIVE;
}
-"vector" {
- return ICE_VECTOR;
+"sequence" {
+ return ICE_SEQUENCE;
}
-"map" {
- return ICE_MAP;
+"dictionary" {
+ return ICE_DICTIONARY;
}
"enum" {
diff --git a/cpp/src/slice2cpp/Gen.cpp b/cpp/src/slice2cpp/Gen.cpp
index bdd00d101c4..040da988a2c 100644
--- a/cpp/src/slice2cpp/Gen.cpp
+++ b/cpp/src/slice2cpp/Gen.cpp
@@ -280,11 +280,11 @@ Slice::Gen::TypesVisitor::visitModuleEnd(const ModulePtr& p)
}
void
-Slice::Gen::TypesVisitor::visitVector(const VectorPtr& p)
+Slice::Gen::TypesVisitor::visitSequence(const SequencePtr& p)
{
string name = p->name();
- TypePtr subtype = p->type();
- string s = typeToString(subtype);
+ TypePtr type = p->type();
+ string s = typeToString(type);
if (s[0] == ':')
{
s.insert(0, " ");
@@ -292,7 +292,7 @@ Slice::Gen::TypesVisitor::visitVector(const VectorPtr& p)
H << sp;
H << nl << "typedef ::std::vector<" << s << "> " << name << ';';
- BuiltinPtr builtin = BuiltinPtr::dynamicCast(subtype);
+ BuiltinPtr builtin = BuiltinPtr::dynamicCast(type);
if (!builtin)
{
string scoped = p->scoped();
@@ -315,7 +315,7 @@ Slice::Gen::TypesVisitor::visitVector(const VectorPtr& p)
C << nl << scoped << "::const_iterator p;";
C << nl << "for (p = v.begin(); p != v.end(); ++p)";
C << sb;
- writeMarshalUnmarshalCode(C, subtype, "*p", true);
+ writeMarshalUnmarshalCode(C, type, "*p", true);
C << eb;
C << eb;
C << sp;
@@ -331,7 +331,7 @@ Slice::Gen::TypesVisitor::visitVector(const VectorPtr& p)
C.zeroIndent();
C << nl << "#ifdef WIN32"; // STLBUG
C.restoreIndent();
- C << nl << "v.push_back(" << typeToString(subtype) << "());";
+ C << nl << "v.push_back(" << typeToString(type) << "());";
C.zeroIndent();
C << nl << "#else";
C.restoreIndent();
@@ -339,13 +339,67 @@ Slice::Gen::TypesVisitor::visitVector(const VectorPtr& p)
C.zeroIndent();
C << nl << "#endif";
C.restoreIndent();
- writeMarshalUnmarshalCode(C, subtype, "v.back()", false);
+ writeMarshalUnmarshalCode(C, type, "v.back()", false);
C << eb;
C << eb;
}
}
void
+Slice::Gen::TypesVisitor::visitDictionary(const DictionaryPtr& p)
+{
+ string name = p->name();
+ TypePtr keyType = p->keyType();
+ TypePtr valueType = p->valueType();
+ string ks = typeToString(keyType);
+ if (ks[0] == ':')
+ {
+ ks.insert(0, " ");
+ }
+ string vs = typeToString(valueType);
+ H << sp;
+ H << nl << "typedef ::std::map<" << ks << ", " << vs << "> " << name << ';';
+
+ string scoped = p->scoped();
+ string scope = p->scope();
+ if (scope.length())
+ {
+ scope.erase(0, 2);
+ }
+
+ H << sp;
+ H << nl << "class __U__" << name << " { };";
+ H << nl << "void" << _dllExport << " __write(::IceInternal::Stream*, const " << name << "&, __U__" << name << ");";
+ H << nl << "void" << _dllExport << " __read(::IceInternal::Stream*, " << name << "&, __U__" << name << ");";
+ C << sp;
+ C << nl << "void" << nl << scope << "::__write(::IceInternal::Stream* __os, const " << scoped << "& v, ::"
+ << scope << "::__U__" << name << ')';
+ C << sb;
+ C << nl << "__os->write(::Ice::Int(v.size()));";
+ C << nl << scoped << "::const_iterator p;";
+ C << nl << "for (p = v.begin(); p != v.end(); ++p)";
+ C << sb;
+ writeMarshalUnmarshalCode(C, keyType, "p->first", true);
+ writeMarshalUnmarshalCode(C, valueType, "p->second", true);
+ C << eb;
+ C << eb;
+ C << sp;
+ C << nl << "void" << nl << scope << "::__read(::IceInternal::Stream* __is, " << scoped << "& v, ::" << scope
+ << "::__U__" << name << ')';
+ C << sb;
+ C << nl << "::Ice::Int sz;";
+ C << nl << "__is->read(sz);";
+ C << nl << "while (sz--)";
+ C << sb;
+ C << nl << "::std::pair<" << ks << ", " << vs << "> pair;";
+ writeMarshalUnmarshalCode(C, keyType, "pair.first", false);
+ writeMarshalUnmarshalCode(C, valueType, "pair.second", false);
+ C << nl << "v.insert(v.end(), pair);";
+ C << eb;
+ C << eb;
+}
+
+void
Slice::Gen::TypesVisitor::visitEnum(const EnumPtr& p)
{
string name = p->name();
diff --git a/cpp/src/slice2cpp/Gen.h b/cpp/src/slice2cpp/Gen.h
index 7019d69d868..77002b264a3 100644
--- a/cpp/src/slice2cpp/Gen.h
+++ b/cpp/src/slice2cpp/Gen.h
@@ -53,7 +53,8 @@ private:
virtual void visitModuleStart(const ModulePtr&);
virtual void visitModuleEnd(const ModulePtr&);
- virtual void visitVector(const VectorPtr&);
+ virtual void visitSequence(const SequencePtr&);
+ virtual void visitDictionary(const DictionaryPtr&);
virtual void visitEnum(const EnumPtr&);
virtual void visitNative(const NativePtr&);
diff --git a/cpp/src/slice2cpp/GenUtil.cpp b/cpp/src/slice2cpp/GenUtil.cpp
index 4249d7a7cda..1a94c7a1a41 100644
--- a/cpp/src/slice2cpp/GenUtil.cpp
+++ b/cpp/src/slice2cpp/GenUtil.cpp
@@ -287,21 +287,29 @@ Slice::writeMarshalUnmarshalCode(Output& out, const TypePtr& type, const string&
return;
}
- VectorPtr vec = VectorPtr::dynamicCast(type);
- if (vec)
+ SequencePtr seq = SequencePtr::dynamicCast(type);
+ if (seq)
{
- if (BuiltinPtr::dynamicCast(vec->type()))
+ if (BuiltinPtr::dynamicCast(seq->type()))
{
out << nl << stream << "->" << func << param << ");";
}
else
{
- out << nl << vec->scope() << "::__" << func << stream << ", " << param << ", " << vec->scope()
- << "::__U__" << vec->name() << "());";
+ out << nl << seq->scope() << "::__" << func << stream << ", " << param << ", " << seq->scope()
+ << "::__U__" << seq->name() << "());";
}
return;
}
+ DictionaryPtr dict = DictionaryPtr::dynamicCast(type);
+ if (dict)
+ {
+ out << nl << dict->scope() << "::__" << func << stream << ", " << param << ", " << dict->scope()
+ << "::__U__" << dict->name() << "());";
+ return;
+ }
+
NativePtr native = NativePtr::dynamicCast(type);
assert(!native); // TODO
diff --git a/cpp/src/slice2docbook/Gen.cpp b/cpp/src/slice2docbook/Gen.cpp
index f0dbc86d38c..d65d7588f23 100644
--- a/cpp/src/slice2docbook/Gen.cpp
+++ b/cpp/src/slice2docbook/Gen.cpp
@@ -173,14 +173,60 @@ Slice::Gen::visitContainer(const ContainerPtr& p)
end();
}
- VectorList vectors = p->vectors();
- vectors.sort();
- if (!vectors.empty())
+ StructList structs = p->structs();
+ structs.sort();
+ if (!structs.empty())
{
- start("section", "Vector Index");
+ start("section", "Struct Index");
start("variablelist");
- for (VectorList::iterator q = vectors.begin(); q != vectors.end(); ++q)
+ for (StructList::iterator q = structs.begin(); q != structs.end(); ++q)
+ {
+ start("varlistentry");
+ start("term");
+ O << nl << toString(*q, p);
+ end();
+ start("listitem");
+ printSummary(*q);
+ end();
+ end();
+ }
+
+ end();
+ end();
+ }
+
+ SequenceList sequences = p->sequences();
+ sequences.sort();
+ if (!sequences.empty())
+ {
+ start("section", "Sequence Index");
+ start("variablelist");
+
+ for (SequenceList::iterator q = sequences.begin(); q != sequences.end(); ++q)
+ {
+ start("varlistentry");
+ start("term");
+ O << nl << toString(*q, p);
+ end();
+ start("listitem");
+ printSummary(*q);
+ end();
+ end();
+ }
+
+ end();
+ end();
+ }
+
+ DictionaryList dictionaries = p->dictionaries();
+ dictionaries.sort();
+ if (!dictionaries.empty())
+ {
+ start("section", "Dictionary Index");
+ start("variablelist");
+
+ for (DictionaryList::iterator q = dictionaries.begin(); q != dictionaries.end(); ++q)
{
start("varlistentry");
start("term");
@@ -245,14 +291,14 @@ Slice::Gen::visitContainer(const ContainerPtr& p)
end();
{
- for (VectorList::iterator q = vectors.begin(); q != vectors.end(); ++q)
+ for (SequenceList::iterator q = sequences.begin(); q != sequences.end(); ++q)
{
TypePtr type = (*q)->type();
start("section id=" + scopedToId((*q)->scoped()), (*q)->name());
O.zeroIndent();
- O << nl << "<synopsis>vector&lt; " << toString(type, p) << " &gt; <type>" << (*q)->name()
+ O << nl << "<synopsis>sequence&lt; " << toString(type, p) << " &gt; <type>" << (*q)->name()
<< "</type>;</synopsis>";
O.restoreIndent();
@@ -263,6 +309,25 @@ Slice::Gen::visitContainer(const ContainerPtr& p)
}
{
+ for (DictionaryList::iterator q = dictionaries.begin(); q != dictionaries.end(); ++q)
+ {
+ TypePtr keyType = (*q)->keyType();
+ TypePtr valueType = (*q)->valueType();
+
+ start("section id=" + scopedToId((*q)->scoped()), (*q)->name());
+
+ O.zeroIndent();
+ O << nl << "<synopsis>dictionary&lt; " << toString(keyType, p) << ", " << toString(valueType, p)
+ << " &gt; <type>" << (*q)->name() << "</type>;</synopsis>";
+ O.restoreIndent();
+
+ printComment(*q);
+
+ end();
+ }
+ }
+
+ {
for (EnumList::iterator q = enums.begin(); q != enums.end(); ++q)
{
start("section id=" + scopedToId((*q)->scoped()), (*q)->name());
@@ -504,6 +569,66 @@ Slice::Gen::visitClassDefStart(const ClassDefPtr& p)
}
void
+Slice::Gen::visitStructStart(const StructPtr& p)
+{
+ start(_chapter + " id=" + scopedToId(p->scoped()), p->scoped().substr(2));
+
+ start("section", "Overview");
+ O.zeroIndent();
+ O << nl << "<synopsis>";
+ O << "struct <structname>" << p->name() << "</structname>";
+ O << "</synopsis>";
+ O.restoreIndent();
+
+ printComment(p);
+
+ DataMemberList dataMembers = p->dataMembers();
+ dataMembers.sort();
+ if (!dataMembers.empty())
+ {
+ start("section", "Data Member Index");
+ start("variablelist");
+
+ for (DataMemberList::iterator q = dataMembers.begin(); q != dataMembers.end(); ++q)
+ {
+ start("varlistentry");
+ start("term");
+ O << nl << toString(*q, p);
+ end();
+ start("listitem");
+ printSummary(*q);
+ end();
+ end();
+ }
+
+ end();
+ end();
+ }
+
+ end();
+
+ {
+ for (DataMemberList::iterator q = dataMembers.begin(); q != dataMembers.end(); ++q)
+ {
+ TypePtr type = (*q)->type();
+
+ start("section id=" + scopedToId((*q)->scoped()), (*q)->name());
+
+ O.zeroIndent();
+ O << nl << "<synopsis>" << toString(type, p) << " <structfield>" << (*q)->name()
+ << "</structfield>;</synopsis>";
+ O.restoreIndent();
+
+ printComment(*q);
+
+ end();
+ }
+ }
+
+ end();
+}
+
+void
Slice::Gen::printHeader()
{
static const char* header =
@@ -836,6 +961,14 @@ Slice::Gen::toString(const SyntaxTreeBasePtr& p, const ContainerPtr& container)
s = getScopedMinimized(cl, container);
}
+ StructPtr st = StructPtr::dynamicCast(p);
+ if (st)
+ {
+ tag = "structname";
+ linkend = scopedToId(st->scoped());
+ s = getScopedMinimized(st, container);
+ }
+
if (s.empty())
{
ContainedPtr contained = ContainedPtr::dynamicCast(p);
diff --git a/cpp/src/slice2docbook/Gen.h b/cpp/src/slice2docbook/Gen.h
index bb2fa8c5b31..86fcc9c881f 100644
--- a/cpp/src/slice2docbook/Gen.h
+++ b/cpp/src/slice2docbook/Gen.h
@@ -34,6 +34,7 @@ public:
virtual void visitModuleStart(const ModulePtr&);
virtual void visitContainer(const ContainerPtr&);
virtual void visitClassDefStart(const ClassDefPtr&);
+ virtual void visitStructStart(const StructPtr&);
private: