summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2021-12-10 11:53:35 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2021-12-10 11:53:35 +0200
commit87140ae9f841798752ae4e5422698a4090f16329 (patch)
treefa55c77eadbed14a160d34b7a03870cd3db3fc14
parent2a700917616a2cc0e751adb76d8f71348a80b0d8 (diff)
Omit instantiating serializers for abstract elements, similar to parsing
-rw-r--r--libxsd/xsd/cxx/tree/type-serializer-map.hxx5
-rw-r--r--libxsd/xsd/cxx/tree/type-serializer-map.txx11
-rw-r--r--xsd/xsd/cxx/tree/serialization-source.cxx30
3 files changed, 42 insertions, 4 deletions
diff --git a/libxsd/xsd/cxx/tree/type-serializer-map.hxx b/libxsd/xsd/cxx/tree/type-serializer-map.hxx
index 38b2fb9..50869b5 100644
--- a/libxsd/xsd/cxx/tree/type-serializer-map.hxx
+++ b/libxsd/xsd/cxx/tree/type-serializer-map.hxx
@@ -216,8 +216,11 @@ namespace xsd
template<unsigned long id, typename C, typename T>
struct element_serializer_initializer
{
+ typedef typename type_serializer_map<C>::serializer serializer;
+
element_serializer_initializer (const C* root_name, const C* root_ns,
- const C* subst_name, const C* subst_ns);
+ const C* subst_name, const C* subst_ns,
+ serializer);
~element_serializer_initializer ();
diff --git a/libxsd/xsd/cxx/tree/type-serializer-map.txx b/libxsd/xsd/cxx/tree/type-serializer-map.txx
index 1acdad2..a6c690a 100644
--- a/libxsd/xsd/cxx/tree/type-serializer-map.txx
+++ b/libxsd/xsd/cxx/tree/type-serializer-map.txx
@@ -550,14 +550,21 @@ namespace xsd
template<unsigned long id, typename C, typename T>
element_serializer_initializer<id, C, T>::
element_serializer_initializer (const C* root_name, const C* root_ns,
- const C* subst_name, const C* subst_ns)
+ const C* subst_name, const C* subst_ns,
+ serializer s)
: root_name_ (root_name), root_ns_ (root_ns)
{
+ // Note that we still have to use real typeid (instead of, say, NULL)
+ // for abstract elements to make sure we have separate entries for
+ // each of them. We can assume that such a typeid can never be looked
+ // up (since it's impossible to instantiate the corresponding abstract
+ // type).
+ //
type_serializer_map_instance<id, C> ().register_element (
xml::qualified_name<C> (root_name, root_ns),
xml::qualified_name<C> (subst_name, subst_ns),
typeid (T),
- &serializer_impl<T>);
+ s);
}
template<unsigned long id, typename C, typename T>
diff --git a/xsd/xsd/cxx/tree/serialization-source.cxx b/xsd/xsd/cxx/tree/serialization-source.cxx
index 9be7499..08b81d6 100644
--- a/xsd/xsd/cxx/tree/serialization-source.cxx
+++ b/xsd/xsd/cxx/tree/serialization-source.cxx
@@ -999,8 +999,25 @@ namespace CXX
virtual void
traverse (Type& e)
{
+ // Similar to parsing, we cannot just omit this element if it's
+ // abstract because it may serve as a "link" between the root of the
+ // substitution group and a non-abstract element that uses this
+ // element as its root (see
+ // element_serializer_map::find_substitution() for details).
+ //
if (polymorphic && e.substitutes_p ())
{
+ SemanticGraph::Type& t (e.type ());
+
+ // Check if this element is abstract.
+ //
+ bool abst;
+ {
+ SemanticGraph::Complex* tc;
+ abst = (tc = dynamic_cast<SemanticGraph::Complex*> (&t)) != 0 &&
+ tc->abstract_p ();
+ }
+
Type& r (e.substitutes ().root ());
String const& name (ename (e));
@@ -1016,7 +1033,18 @@ namespace CXX
<< strlit (r.name ()) << "," << endl
<< strlit (r.namespace_ ().name ()) << "," << endl
<< strlit (e.name ()) << "," << endl
- << strlit (e.namespace_ ().name ()) << ");"
+ << strlit (e.namespace_ ().name ()) << "," << endl;
+
+ if (abst)
+ os << "0";
+ else
+ {
+ os << "&::xsd::cxx::tree::serializer_impl< ";
+ belongs (e, belongs_);
+ os << " >";
+ }
+
+ os << ");"
<< endl
<< endl;
}