summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--slicer/slicer/parser.cpp17
-rw-r--r--slicer/slicer/parser.h1
2 files changed, 14 insertions, 4 deletions
diff --git a/slicer/slicer/parser.cpp b/slicer/slicer/parser.cpp
index b8f3f89..7cd45f1 100644
--- a/slicer/slicer/parser.cpp
+++ b/slicer/slicer/parser.cpp
@@ -123,6 +123,15 @@ namespace Slicer {
return true;
}
+
+ void
+ Slicer::defineRootName(const std::string & type, const std::string & name) const
+ {
+ fprintf(cpp, "template<>\n");
+ fprintf(cpp, "std::string ModelPartForRoot< %s >::rootName(\"%s\");\n\n",
+ type.c_str(), name.c_str());
+ }
+
bool
Slicer::visitClassDefStart(const Slice::ClassDefPtr & c)
{
@@ -143,11 +152,8 @@ namespace Slicer {
typeToString(decl).c_str(),
typeId ? typeId->c_str() : "slicer-typeid");
- fprintf(cpp, "template<>\n");
auto name = metaDataValue("slicer:root:", c->getMetaData());
- fprintf(cpp, "std::string ModelPartForRoot< %s >::rootName(\"%s\");\n\n",
- typeToString(decl).c_str(),
- name ? name->c_str() : c->name().c_str());
+ defineRootName(typeToString(decl), name ? *name : c->name());
auto typeName = metaDataValue("slicer:typename:", c->getMetaData());
fprintf(cpp, "static void registerClass_%u() __attribute__ ((constructor(210)));\n", classNo);
@@ -314,6 +320,9 @@ namespace Slicer {
s->scoped().c_str(),
ename ? ename->c_str() : "element");
+ auto name = metaDataValue("slicer:root:", s->getMetaData());
+ defineRootName(s->scoped(), name ? *name : s->name());
+
fprintf(cpp, "template<>\nMetadata ModelPartForSequence< %s >::metadata ",
s->scoped().c_str());
copyMetadata(s->getMetaData());
diff --git a/slicer/slicer/parser.h b/slicer/slicer/parser.h
index 7965b4b..6253cf5 100644
--- a/slicer/slicer/parser.h
+++ b/slicer/slicer/parser.h
@@ -47,6 +47,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 copyMetadata(const std::list<std::string> & metadata) const;
static Conversions getAllConversions(Slice::DataMemberPtr dm);