summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--slicer/slicer/common.ice1
-rw-r--r--slicer/slicer/modelPartsTypes.h5
-rw-r--r--slicer/slicer/modelPartsTypes.impl.h41
-rw-r--r--slicer/test/collections.ice4
-rw-r--r--slicer/test/locals.ice16
-rw-r--r--slicer/tool/parser.cpp18
-rw-r--r--slicer/tool/parser.h2
7 files changed, 73 insertions, 14 deletions
diff --git a/slicer/slicer/common.ice b/slicer/slicer/common.ice
index 5d87d0a..96d3a85 100644
--- a/slicer/slicer/common.ice
+++ b/slicer/slicer/common.ice
@@ -12,6 +12,7 @@ module Slicer {
string name;
};
exception UnsupportedModelType extends RuntimeError { };
+ exception LocalTypeException extends RuntimeError { };
exception NoConversionFound extends RuntimeError {
string type;
};
diff --git a/slicer/slicer/modelPartsTypes.h b/slicer/slicer/modelPartsTypes.h
index 5297865..93b4bb5 100644
--- a/slicer/slicer/modelPartsTypes.h
+++ b/slicer/slicer/modelPartsTypes.h
@@ -5,6 +5,11 @@
namespace Slicer {
template<typename T>
+ struct isLocal {
+ static constexpr bool value = false;
+ };
+
+ template<typename T>
class DLL_PUBLIC ModelPartForRoot : public ModelPartForRootBase {
public:
ModelPartForRoot(T & o);
diff --git a/slicer/slicer/modelPartsTypes.impl.h b/slicer/slicer/modelPartsTypes.impl.h
index d04dd9c..b19f937 100644
--- a/slicer/slicer/modelPartsTypes.impl.h
+++ b/slicer/slicer/modelPartsTypes.impl.h
@@ -41,8 +41,13 @@ namespace Slicer {
return ModelObject && mp->HasValue();
}
+#define IfLocal(T) \
+ typename std::enable_if<Slicer::isLocal<T>::value>::type
+#define IfNotLocal(T) \
+ typename std::enable_if<!Slicer::isLocal<T>::value>::type
+
template<typename T>
- void
+ IfNotLocal(T)
typeWrite(::Ice::OutputStreamPtr & s, const ::IceUtil::Optional<T> & m)
{
typedef Ice::StreamableTraits<T> traits;
@@ -55,14 +60,28 @@ namespace Slicer {
}
template<typename T>
- void
+ IfLocal(T)
+ typeWrite(::Ice::OutputStreamPtr &, const ::IceUtil::Optional<T> &)
+ {
+ throw LocalTypeException();
+ }
+
+ template<typename T>
+ IfNotLocal(T)
typeWrite(::Ice::OutputStreamPtr & s, const T & m)
{
s->write(m);
}
template<typename T>
- void
+ IfLocal(T)
+ typeWrite(::Ice::OutputStreamPtr &, const T &)
+ {
+ throw LocalTypeException();
+ }
+
+ template<typename T>
+ IfNotLocal(T)
typeRead(::Ice::InputStreamPtr & s, ::IceUtil::Optional<T> & m)
{
typedef Ice::StreamableTraits<T> traits;
@@ -79,13 +98,27 @@ namespace Slicer {
}
template<typename T>
- void
+ IfLocal(T)
+ typeRead(::Ice::InputStreamPtr &, ::IceUtil::Optional<T> &)
+ {
+ throw LocalTypeException();
+ }
+
+ template<typename T>
+ IfNotLocal(T)
typeRead(::Ice::InputStreamPtr & s, T & m)
{
s->read(m);
}
template<typename T>
+ IfLocal(T)
+ typeRead(::Ice::InputStreamPtr &, T &)
+ {
+ throw LocalTypeException();
+ }
+
+ template<typename T>
void ModelPartForRoot<T>::Write(::Ice::OutputStreamPtr & s) const
{
typeWrite(s, *ModelObject);
diff --git a/slicer/test/collections.ice b/slicer/test/collections.ice
index 5ff54bd..c9845e0 100644
--- a/slicer/test/collections.ice
+++ b/slicer/test/collections.ice
@@ -8,9 +8,9 @@ module TestModule {
sequence<string> SimpleSeq;
sequence<BuiltIns> BuiltInSeq;
sequence<ClassType> Classes;
- sequence<StructType> Structs;
+ local sequence<StructType> Structs;
dictionary<int, ClassType> ClassMap;
- dictionary<int, StructType> StructMap;
+ local dictionary<int, StructType> StructMap;
};
#endif
diff --git a/slicer/test/locals.ice b/slicer/test/locals.ice
new file mode 100644
index 0000000..eb914dd
--- /dev/null
+++ b/slicer/test/locals.ice
@@ -0,0 +1,16 @@
+#ifndef SLICER_TEST_LOCALS
+#define SLICER_TEST_LOCALS
+
+module Locals {
+ local struct S {
+ int a;
+ };
+ local sequence<S> Ss;
+ local dictionary<int, S> Sd;
+ local enum E {
+ a, b
+ };
+};
+
+#endif
+
diff --git a/slicer/tool/parser.cpp b/slicer/tool/parser.cpp
index 23a804b..c2c98d0 100644
--- a/slicer/tool/parser.cpp
+++ b/slicer/tool/parser.cpp
@@ -159,10 +159,14 @@ namespace Slicer {
return true;
}
-
void
- Slicer::defineRootName(const std::string & type, const std::string & name) const
+ Slicer::defineRoot(const std::string & type, const std::string & name, const Slice::TypePtr & stype) const
{
+ if (stype->isLocal()) {
+ fprintbf(cpp, "template<>\n");
+ fprintbf(cpp, "struct isLocal< %s > { static constexpr bool value = true; };\n\n",
+ type);
+ }
fprintbf(cpp, "template<> DLL_PUBLIC\n");
fprintbf(cpp, "const std::string ModelPartForRoot< %s >::rootName(\"%s\");\n\n",
type, name);
@@ -192,7 +196,7 @@ namespace Slicer {
typeId ? *typeId : "slicer-typeid");
auto name = metaDataValue("slicer:root:", c->getMetaData());
- defineRootName(typeToString(decl), name ? *name : c->name());
+ defineRoot(typeToString(decl), name ? *name : c->name(), decl);
auto typeName = metaDataValue("slicer:typename:", c->getMetaData());
fprintbf(cpp, "template<> DLL_PUBLIC\n");
@@ -242,7 +246,7 @@ namespace Slicer {
visitComplexDataMembers(c, c->dataMembers());
auto name = metaDataValue("slicer:root:", c->getMetaData());
- defineRootName(c->scoped(), name ? *name : c->name());
+ defineRoot(c->scoped(), name ? *name : c->name(), c);
fprintbf(cpp, "template<> DLL_PUBLIC\nconst Metadata ModelPartForComplex< %s >::metadata ",
c->scoped());
@@ -339,7 +343,7 @@ namespace Slicer {
e->scoped());
auto name = metaDataValue("slicer:root:", e->getMetaData());
- defineRootName(e->scoped(), name ? *name : e->name());
+ defineRoot(e->scoped(), name ? *name : e->name(), e);
defineMODELPART(e->scoped(), e, e->getMetaData());
}
@@ -381,7 +385,7 @@ namespace Slicer {
ename ? *ename : "element");
auto name = metaDataValue("slicer:root:", s->getMetaData());
- defineRootName(s->scoped(), name ? *name : s->name());
+ defineRoot(s->scoped(), name ? *name : s->name(), s);
fprintbf(cpp, "template<> DLL_PUBLIC\nconst Metadata ModelPartForSequence< %s >::metadata ",
s->scoped());
@@ -435,7 +439,7 @@ namespace Slicer {
fprintbf(cpp, "\n");
auto name = metaDataValue("slicer:root:", d->getMetaData());
- defineRootName(d->scoped(), name ? *name : d->name());
+ defineRoot(d->scoped(), name ? *name : d->name(), d);
fprintbf(cpp, "template<> DLL_PUBLIC\nconst Metadata ModelPartForDictionary< %s >::metadata ",
d->scoped());
diff --git a/slicer/tool/parser.h b/slicer/tool/parser.h
index ffc771d..9495607 100644
--- a/slicer/tool/parser.h
+++ b/slicer/tool/parser.h
@@ -62,7 +62,7 @@ namespace Slicer {
void visitComplexDataMembers(Slice::ConstructedPtr t, const Slice::DataMemberList &) const;
void defineConversions(Slice::DataMemberPtr dm) const;
- void defineRootName(const std::string & type, const std::string & name) const;
+ void defineRoot(const std::string & type, const std::string & name, const Slice::TypePtr & stype) const;
bool hasMetadata(const std::list<std::string> & metadata) const;
void copyMetadata(const std::list<std::string> & metadata) const;