summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--slicer/slicer/modelPartsTypes.impl.h11
-rw-r--r--slicer/test/serializers.cpp2
-rw-r--r--slicer/tool/parser.cpp74
-rw-r--r--slicer/tool/parser.h2
4 files changed, 54 insertions, 35 deletions
diff --git a/slicer/slicer/modelPartsTypes.impl.h b/slicer/slicer/modelPartsTypes.impl.h
index 2de1780..46c028b 100644
--- a/slicer/slicer/modelPartsTypes.impl.h
+++ b/slicer/slicer/modelPartsTypes.impl.h
@@ -4,13 +4,16 @@
#include "modelPartsTypes.h"
#include "common.h"
-#define MODELPARTFOR(Type, ModelPartType) \
- template class ModelPartType<Type>; \
- template<> ModelPartPtr ModelPart::CreateFor(Type & s) { return new ModelPartType<Type>(s); } \
- template<> ModelPartPtr ModelPart::CreateFor(IceUtil::Optional<Type> & s) { return new ModelPartForOptional<ModelPartType<Type> >(s); } \
+#define CUSTOMMODELPARTFOR(Type, BaseModelPart, ModelPartType) \
+ template class BaseModelPart; \
+ template<> ModelPartPtr ModelPart::CreateFor(Type & s) { return new ModelPartType(s); } \
+ template<> ModelPartPtr ModelPart::CreateFor(IceUtil::Optional<Type> & s) { return new ModelPartForOptional<ModelPartType>(s); } \
template<> ModelPartForRootPtr ModelPart::CreateRootFor(Type & s) { return new ModelPartForRoot<Type>(s); } \
template<> ModelPartForRootPtr ModelPart::CreateRootFor(IceUtil::Optional<Type> & s) { return new ModelPartForRoot<IceUtil::Optional<Type> >(s); } \
+#define MODELPARTFOR(Type, ModelPartType) \
+ CUSTOMMODELPARTFOR(Type, ModelPartType<Type>, ModelPartType<Type>)
+
namespace Slicer {
// ModelPartForRoot
template<typename T>
diff --git a/slicer/test/serializers.cpp b/slicer/test/serializers.cpp
index 01c6688..329135f 100644
--- a/slicer/test/serializers.cpp
+++ b/slicer/test/serializers.cpp
@@ -586,6 +586,6 @@ BOOST_AUTO_TEST_SUITE_END();
BOOST_AUTO_TEST_CASE( customerModelPartCounters )
{
- BOOST_REQUIRE_EQUAL(7, TestModule::completions);
+ BOOST_REQUIRE_EQUAL(27, TestModule::completions);
}
diff --git a/slicer/tool/parser.cpp b/slicer/tool/parser.cpp
index a1b6f66..302ea63 100644
--- a/slicer/tool/parser.cpp
+++ b/slicer/tool/parser.cpp
@@ -230,8 +230,7 @@ namespace Slicer {
c->scoped());
copyMetadata(c->getMetaData());
- fprintbf(cpp, "MODELPARTFOR(::IceInternal::Handle< %s >, ModelPartForClass);\n\n",
- c->scoped());
+ defineMODELPART(stringbf("::IceInternal::Handle< %s >", c->scoped()), decl, c->getMetaData());
classNo += 1;
@@ -257,8 +256,7 @@ namespace Slicer {
c->scoped());
copyMetadata(c->getMetaData());
- fprintbf(cpp, "MODELPARTFOR(%s, ModelPartForStruct);\n\n",
- c->scoped());
+ defineMODELPART(c->scoped(), c, c->getMetaData());
return true;
}
@@ -363,8 +361,7 @@ namespace Slicer {
auto name = metaDataValue("slicer:root:", e->getMetaData());
defineRootName(e->scoped(), name ? *name : e->name());
- fprintbf(cpp, "MODELPARTFOR(%s, ModelPartForEnum);\n\n",
- e->scoped());
+ defineMODELPART(e->scoped(), e, e->getMetaData());
}
void
@@ -410,8 +407,7 @@ namespace Slicer {
s->scoped());
copyMetadata(s->getMetaData());
- fprintbf(cpp, "MODELPARTFOR(%s, ModelPartForSequence);\n\n",
- s->scoped());
+ defineMODELPART(s->scoped(), s, s->getMetaData());
}
void
@@ -470,8 +466,7 @@ namespace Slicer {
d->scoped());
copyMetadata(d->getMetaData());
- fprintbf(cpp, "MODELPARTFOR(%s, ModelPartForDictionary);\n\n",
- d->scoped());
+ defineMODELPART(d->scoped(), d, d->getMetaData());
}
void
@@ -497,27 +492,33 @@ namespace Slicer {
boost::algorithm::replace_all_copy(*cmp, ".", "::"));
}
else {
- if (auto builtin = Slice::BuiltinPtr::dynamicCast(type)) {
- fprintbf(cpp, "ModelPartForSimple");
- }
- else if (auto complexClass = Slice::ClassDeclPtr::dynamicCast(type)) {
- fprintbf(cpp, "ModelPartForClass");
- }
- else if (auto complexStruct = Slice::StructPtr::dynamicCast(type)) {
- fprintbf(cpp, "ModelPartForStruct");
- }
- else if (auto sequence = Slice::SequencePtr::dynamicCast(type)) {
- fprintbf(cpp, "ModelPartForSequence");
- }
- else if (auto dictionary = Slice::DictionaryPtr::dynamicCast(type)) {
- fprintbf(cpp, "ModelPartForDictionary");
- }
- else if (auto enumeration = Slice::EnumPtr::dynamicCast(type)) {
- fprintbf(cpp, "ModelPartForEnum");
- }
- fprintbf(cpp, "< %s >",
- Slice::typeToString(type));
+ fprintbf(cpp, "%s< %s >",
+ getBasicModelPart(type), Slice::typeToString(type));
+ }
+ }
+
+ std::string
+ Slicer::getBasicModelPart(const Slice::TypePtr & type) const
+ {
+ if (auto builtin = Slice::BuiltinPtr::dynamicCast(type)) {
+ return "ModelPartForSimple";
+ }
+ else if (auto complexClass = Slice::ClassDeclPtr::dynamicCast(type)) {
+ return "ModelPartForClass";
+ }
+ else if (auto complexStruct = Slice::StructPtr::dynamicCast(type)) {
+ return "ModelPartForStruct";
+ }
+ else if (auto sequence = Slice::SequencePtr::dynamicCast(type)) {
+ return "ModelPartForSequence";
+ }
+ else if (auto dictionary = Slice::DictionaryPtr::dynamicCast(type)) {
+ return "ModelPartForDictionary";
+ }
+ else if (auto enumeration = Slice::EnumPtr::dynamicCast(type)) {
+ return "ModelPartForEnum";
}
+ throw CompilerError("Unknown basic type");
}
bool
@@ -578,6 +579,19 @@ namespace Slicer {
return rtn;
}
+ void
+ Slicer::defineMODELPART(const std::string & type, const Slice::TypePtr & stype, const Slice::StringList & metadata) const
+ {
+ if (auto cmp = metaDataValue("slicer:custommodelpart:", metadata)) {
+ fprintbf(cpp, "CUSTOMMODELPARTFOR(%s, %s< %s >, ::%s);\n\n",
+ type, getBasicModelPart(stype), type, boost::algorithm::replace_all_copy(*cmp, ".", "::"));
+ }
+ else {
+ fprintbf(cpp, "MODELPARTFOR(%s, %s);\n\n",
+ type, getBasicModelPart(stype));
+ }
+ }
+
unsigned int
Slicer::Components() const
{
diff --git a/slicer/tool/parser.h b/slicer/tool/parser.h
index b8bdf0b..ffc771d 100644
--- a/slicer/tool/parser.h
+++ b/slicer/tool/parser.h
@@ -56,6 +56,8 @@ namespace Slicer {
private:
void createNewModelPartPtrFor(const Slice::TypePtr & type, const Slice::DataMemberPtr & dm = Slice::DataMemberPtr(), const Slice::StringList & md = Slice::StringList()) const;
+ std::string getBasicModelPart(const Slice::TypePtr & type) const;
+ void defineMODELPART(const std::string & type, const Slice::TypePtr & stype, const Slice::StringList & metadata) const;
void visitComplexDataMembers(Slice::ConstructedPtr t, const Slice::DataMemberList &) const;