aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--tests/cxx/tree/polymorphism/ostream/makefile2
-rw-r--r--tests/cxx/tree/polymorphism/ostream/output5
-rw-r--r--tests/cxx/tree/polymorphism/ostream/test.xml13
-rw-r--r--tests/cxx/tree/polymorphism/ostream/test.xsd18
-rw-r--r--xsd/cxx/tree/elements.cxx26
-rw-r--r--xsd/cxx/tree/elements.hxx6
-rw-r--r--xsd/cxx/tree/serialization-source.cxx16
-rw-r--r--xsd/cxx/tree/stream-extraction-source.cxx16
-rw-r--r--xsd/cxx/tree/stream-insertion-source.cxx16
-rw-r--r--xsd/cxx/tree/stream-source.cxx16
-rw-r--r--xsd/cxx/tree/tree-source.cxx56
11 files changed, 153 insertions, 37 deletions
diff --git a/tests/cxx/tree/polymorphism/ostream/makefile b/tests/cxx/tree/polymorphism/ostream/makefile
index c6dd0b0..777d716 100644
--- a/tests/cxx/tree/polymorphism/ostream/makefile
+++ b/tests/cxx/tree/polymorphism/ostream/makefile
@@ -35,7 +35,7 @@ gen := $(addprefix $(out_base)/,$(genf))
$(gen): xsd := $(out_root)/xsd/xsd
$(gen): xsd_options := --generate-polymorphic --polymorphic-type-all \
---generate-ostream
+--root-element root --generate-ostream
$(gen): $(out_root)/xsd/xsd
$(call include-dep,$(dep))
diff --git a/tests/cxx/tree/polymorphism/ostream/output b/tests/cxx/tree/polymorphism/ostream/output
index bf0e814..e7fbd68 100644
--- a/tests/cxx/tree/polymorphism/ostream/output
+++ b/tests/cxx/tree/polymorphism/ostream/output
@@ -11,3 +11,8 @@ a: a
fund: 1
c: c1
c: c2
+base:
+a: a
+fund: 1
+d: d1
+d: d2
diff --git a/tests/cxx/tree/polymorphism/ostream/test.xml b/tests/cxx/tree/polymorphism/ostream/test.xml
index 157e15c..5409d2a 100644
--- a/tests/cxx/tree/polymorphism/ostream/test.xml
+++ b/tests/cxx/tree/polymorphism/ostream/test.xml
@@ -1,9 +1,10 @@
-<t:root xmlns:t="test"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="test test.xsd">
+<root xmlns="test"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="test test.xsd">
<base><a>a</a><fund>1</fund></base>
- <base xsi:type="t:derived1"><a>a</a><fund>1</fund><b>b</b></base>
- <base xsi:type="t:derived2"><a>a</a><fund>1</fund><c>c1</c><c>c2</c></base>
+ <base xsi:type="derived1"><a>a</a><fund>1</fund><b>b</b></base>
+ <base xsi:type="derived2"><a>a</a><fund>1</fund><c>c1</c><c>c2</c></base>
+ <derived3><a>a</a><fund>1</fund><d>d1</d><d>d2</d></derived3>
-</t:root>
+</root>
diff --git a/tests/cxx/tree/polymorphism/ostream/test.xsd b/tests/cxx/tree/polymorphism/ostream/test.xsd
index cc1f7a8..ddeaeae 100644
--- a/tests/cxx/tree/polymorphism/ostream/test.xsd
+++ b/tests/cxx/tree/polymorphism/ostream/test.xsd
@@ -1,5 +1,6 @@
<?xml version="1.0"?>
-<schema xmlns="http://www.w3.org/2001/XMLSchema" xmlns:t="test" targetNamespace="test">
+<schema xmlns="http://www.w3.org/2001/XMLSchema" xmlns:t="test"
+ targetNamespace="test" elementFormDefault="qualified">
<complexType name="base">
<sequence>
@@ -7,6 +8,7 @@
<element name="fund" type="int"/>
</sequence>
</complexType>
+ <element name="base" type="t:base"/>
<complexType name="derived1">
<complexContent>
@@ -28,9 +30,21 @@
</complexContent>
</complexType>
+ <element name="derived3" substitutionGroup="t:base">
+ <complexType>
+ <complexContent>
+ <extension base="t:base">
+ <sequence>
+ <element name="d" type="string" maxOccurs="unbounded"/>
+ </sequence>
+ </extension>
+ </complexContent>
+ </complexType>
+ </element>
+
<complexType name="type">
<sequence>
- <element name="base" type="t:base" maxOccurs="unbounded"/>
+ <element ref="t:base" maxOccurs="unbounded"/>
</sequence>
</complexType>
diff --git a/xsd/cxx/tree/elements.cxx b/xsd/cxx/tree/elements.cxx
index 3c59e6a..0b69fff 100644
--- a/xsd/cxx/tree/elements.cxx
+++ b/xsd/cxx/tree/elements.cxx
@@ -622,6 +622,32 @@ namespace CXX
return t.context ().get<Boolean> ("polymorphic");
}
+ Boolean Context::
+ anonymous_substitutes_p (SemanticGraph::Type& t)
+ {
+ // ID/IDREF templates cannot match.
+ //
+ if (!t.named_p () &&
+ (t.is_a<SemanticGraph::Fundamental::Id> () ||
+ t.is_a<SemanticGraph::Fundamental::IdRef> ()))
+ return false;
+
+ // See which elements this type classifies.
+ //
+ for (SemanticGraph::Type::ClassifiesIterator i (t.classifies_begin ()),
+ e (t.classifies_end ()); i != e; ++i)
+ {
+ if (SemanticGraph::Element* e =
+ dynamic_cast<SemanticGraph::Element*> (&i->instance ()))
+ {
+ if (e->substitutes_p ())
+ return true;
+ }
+ }
+
+ return false;
+ }
+
// GenerateDefautCtor
//
GenerateDefaultCtor::
diff --git a/xsd/cxx/tree/elements.hxx b/xsd/cxx/tree/elements.hxx
index 4977045..369dc3a 100644
--- a/xsd/cxx/tree/elements.hxx
+++ b/xsd/cxx/tree/elements.hxx
@@ -170,6 +170,12 @@ namespace CXX
return t.context ().count ("anonymous");
}
+ // Return true if this anonymous type is defined in an element
+ // that belongs to a substitution group.
+ //
+ Boolean
+ anonymous_substitutes_p (SemanticGraph::Type&);
+
// Escaped names.
//
public:
diff --git a/xsd/cxx/tree/serialization-source.cxx b/xsd/cxx/tree/serialization-source.cxx
index 6519d32..05588bd 100644
--- a/xsd/cxx/tree/serialization-source.cxx
+++ b/xsd/cxx/tree/serialization-source.cxx
@@ -91,7 +91,9 @@ namespace CXX
<< "l << static_cast< const " << base << "& > (i);"
<< "}";
- // Register with type factory map.
+ // Register with type factory map. If this type is anonymous
+ // but substitutes, then it will be registered as part of the
+ // substitution registration.
//
if (polymorphic && polymorphic_p (l) && !anonymous_p (l))
{
@@ -171,7 +173,9 @@ namespace CXX
<< "l << static_cast< const " << base << "& > (i);"
<< "}";
- // Register with type factory map.
+ // Register with type factory map. If this type is anonymous
+ // but substitutes, then it will be registered as part of the
+ // substitution registration.
//
if (polymorphic && polymorphic_p (u) && !anonymous_p (u))
{
@@ -253,7 +257,9 @@ namespace CXX
<< "}";
- // Register with type factory map.
+ // Register with type factory map. If this type is anonymous
+ // but substitutes, then it will be registered as part of the
+ // substitution registration.
//
if (polymorphic && polymorphic_p (e) && !anonymous_p (e))
{
@@ -805,7 +811,9 @@ namespace CXX
os << "}";
}
- // Register with type factory map.
+ // Register with type factory map. If this type is anonymous
+ // but substitutes, then it will be registered as part of the
+ // substitution registration.
//
if (polymorphic && polymorphic_p (c) && !anonymous_p (c))
{
diff --git a/xsd/cxx/tree/stream-extraction-source.cxx b/xsd/cxx/tree/stream-extraction-source.cxx
index c2bbeb0..e1d1679 100644
--- a/xsd/cxx/tree/stream-extraction-source.cxx
+++ b/xsd/cxx/tree/stream-extraction-source.cxx
@@ -61,7 +61,9 @@ namespace CXX
// Register with type map.
//
- if (polymorphic && polymorphic_p (l) && !anonymous_p (l))
+ if (polymorphic &&
+ polymorphic_p (l) &&
+ (!anonymous_p (l) || anonymous_substitutes_p (l)))
{
// Note that we are using the original type name.
//
@@ -129,7 +131,9 @@ namespace CXX
// Register with type map.
//
- if (polymorphic && polymorphic_p (u) && !anonymous_p (u))
+ if (polymorphic &&
+ polymorphic_p (u) &&
+ (!anonymous_p (u) || anonymous_substitutes_p (u)))
{
// Note that we are using the original type name.
//
@@ -222,7 +226,9 @@ namespace CXX
// Register with type map.
//
- if (polymorphic && polymorphic_p (e) && !anonymous_p (e))
+ if (polymorphic &&
+ polymorphic_p (e) &&
+ (!anonymous_p (e) || anonymous_substitutes_p (e)))
{
// Note that we are using the original type name.
//
@@ -656,7 +662,9 @@ namespace CXX
// Register with type map.
//
- if (polymorphic && polymorphic_p (c) && !anonymous_p (c))
+ if (polymorphic &&
+ polymorphic_p (c) &&
+ (!anonymous_p (c) || anonymous_substitutes_p (c)))
{
// Note that we are using the original type name.
//
diff --git a/xsd/cxx/tree/stream-insertion-source.cxx b/xsd/cxx/tree/stream-insertion-source.cxx
index 9af8a33..00d9ae2 100644
--- a/xsd/cxx/tree/stream-insertion-source.cxx
+++ b/xsd/cxx/tree/stream-insertion-source.cxx
@@ -60,7 +60,9 @@ namespace CXX
// Register with type map.
//
- if (polymorphic && polymorphic_p (l) && !anonymous_p (l))
+ if (polymorphic &&
+ polymorphic_p (l) &&
+ (!anonymous_p (l) || anonymous_substitutes_p (l)))
{
// Note that we are using the original type name.
//
@@ -128,7 +130,9 @@ namespace CXX
// Register with type map.
//
- if (polymorphic && polymorphic_p (u) && !anonymous_p (u))
+ if (polymorphic &&
+ polymorphic_p (u) &&
+ (!anonymous_p (u) || anonymous_substitutes_p (u)))
{
// Note that we are using the original type name.
//
@@ -215,7 +219,9 @@ namespace CXX
// Register with type map.
//
- if (polymorphic && polymorphic_p (e) && !anonymous_p (e))
+ if (polymorphic &&
+ polymorphic_p (e) &&
+ (!anonymous_p (e) || anonymous_substitutes_p (e)))
{
// Note that we are using the original type name.
//
@@ -436,7 +442,9 @@ namespace CXX
// Register with type map.
//
- if (polymorphic && polymorphic_p (c) && !anonymous_p (c))
+ if (polymorphic &&
+ polymorphic_p (c) &&
+ (!anonymous_p (c) || anonymous_substitutes_p (c)))
{
// Note that we are using the original type name.
//
diff --git a/xsd/cxx/tree/stream-source.cxx b/xsd/cxx/tree/stream-source.cxx
index 7c4954c..1d4b5d9 100644
--- a/xsd/cxx/tree/stream-source.cxx
+++ b/xsd/cxx/tree/stream-source.cxx
@@ -52,7 +52,9 @@ namespace CXX
// Register with ostream map.
//
- if (polymorphic && polymorphic_p (l) && !anonymous_p (l))
+ if (polymorphic &&
+ polymorphic_p (l) &&
+ (!anonymous_p (l) || anonymous_substitutes_p (l)))
{
// Note that we are using the original type name.
//
@@ -107,7 +109,9 @@ namespace CXX
// Register with ostream map.
//
- if (polymorphic && polymorphic_p (u) && !anonymous_p (u))
+ if (polymorphic &&
+ polymorphic_p (u) &&
+ (!anonymous_p (u) || anonymous_substitutes_p (u)))
{
// Note that we are using the original type name.
//
@@ -185,7 +189,9 @@ namespace CXX
// Register with ostream map.
//
- if (polymorphic && polymorphic_p (e) && !anonymous_p (e))
+ if (polymorphic &&
+ polymorphic_p (e) &&
+ (!anonymous_p (e) || anonymous_substitutes_p (e)))
{
// Note that we are using the original type name.
//
@@ -380,7 +386,9 @@ namespace CXX
// Register with ostream map.
//
- if (polymorphic && polymorphic_p (c) && !anonymous_p (c))
+ if (polymorphic &&
+ polymorphic_p (c) &&
+ (!anonymous_p (c) || anonymous_substitutes_p (c)))
{
// Note that we are using the original type name.
//
diff --git a/xsd/cxx/tree/tree-source.cxx b/xsd/cxx/tree/tree-source.cxx
index d322027..c20876b 100644
--- a/xsd/cxx/tree/tree-source.cxx
+++ b/xsd/cxx/tree/tree-source.cxx
@@ -105,13 +105,17 @@ namespace CXX
// Register with type factory map.
//
- if (polymorphic && polymorphic_p (l) && !anonymous_p (l))
+ if (polymorphic && polymorphic_p (l))
{
// Note that we are using the original type name.
//
String const& name (ename (l));
- if (!options.value<CLI::suppress_parsing> ())
+ // If this type is anonymous but substitutes, then it will
+ // be registered as part of the substitution registration.
+ //
+ if (!anonymous_p (l) && !options.value<CLI::suppress_parsing> ())
+ {
os << "static" << endl
<< "const ::xsd::cxx::tree::type_factory_initializer< 0, " <<
char_type << ", " << name << " >" << endl
@@ -119,13 +123,17 @@ namespace CXX
<< strlit (l.name ()) << "," << endl
<< strlit (xml_ns_name (l)) << ");"
<< endl;
+ }
- if (options.value<CLI::generate_comparison> ())
+ if ((!anonymous_p (l) || anonymous_substitutes_p (l)) &&
+ options.value<CLI::generate_comparison> ())
+ {
os << "static" << endl
<< "const ::xsd::cxx::tree::comparison_initializer< 0, " <<
char_type << ", " << name << " >" << endl
<< "_xsd_" << name << "_comparison_init;"
<< endl;
+ }
}
}
@@ -212,13 +220,17 @@ namespace CXX
// Register with type factory map.
//
- if (polymorphic && polymorphic_p (u) && !anonymous_p (u))
+ if (polymorphic && polymorphic_p (u))
{
// Note that we are using the original type name.
//
String const& name (ename (u));
- if (!options.value<CLI::suppress_parsing> ())
+ // If this type is anonymous but substitutes, then it will
+ // be registered as part of the substitution registration.
+ //
+ if (!anonymous_p (u) && !options.value<CLI::suppress_parsing> ())
+ {
os << "static" << endl
<< "const ::xsd::cxx::tree::type_factory_initializer< 0, " <<
char_type << ", " << name << " >" << endl
@@ -226,13 +238,17 @@ namespace CXX
<< strlit (u.name ()) << "," << endl
<< strlit (xml_ns_name (u)) << ");"
<< endl;
+ }
- if (options.value<CLI::generate_comparison> ())
+ if ((!anonymous_p (u) || anonymous_substitutes_p (u)) &&
+ options.value<CLI::generate_comparison> ())
+ {
os << "static" << endl
<< "const ::xsd::cxx::tree::comparison_initializer< 0, " <<
char_type << ", " << name << " >" << endl
<< "_xsd_" << name << "_comparison_init;"
<< endl;
+ }
}
}
};
@@ -504,13 +520,17 @@ namespace CXX
// Register with type factory map.
//
- if (polymorphic && polymorphic_p (e) && !anonymous_p (e))
+ if (polymorphic && polymorphic_p (e))
{
// Note that we are using the original type name.
//
String const& name (ename (e));
- if (!options.value<CLI::suppress_parsing> ())
+ // If this type is anonymous but substitutes, then it will
+ // be registered as part of the substitution registration.
+ //
+ if (!anonymous_p (e) && !options.value<CLI::suppress_parsing> ())
+ {
os << "static" << endl
<< "const ::xsd::cxx::tree::type_factory_initializer< 0, " <<
char_type << ", " << name << " >" << endl
@@ -518,13 +538,17 @@ namespace CXX
<< strlit (e.name ()) << "," << endl
<< strlit (xml_ns_name (e)) << ");"
<< endl;
+ }
- if (options.value<CLI::generate_comparison> ())
+ if ((!anonymous_p (e) || anonymous_substitutes_p (e)) &&
+ options.value<CLI::generate_comparison> ())
+ {
os << "static" << endl
<< "const ::xsd::cxx::tree::comparison_initializer< 0, " <<
char_type << ", " << name << " >" << endl
<< "_xsd_" << name << "_comparison_init;"
<< endl;
+ }
}
}
@@ -3057,13 +3081,17 @@ namespace CXX
// Register with type factory map.
//
- if (polymorphic && polymorphic_p (c) && !anonymous_p (c))
+ if (polymorphic && polymorphic_p (c))
{
// Note that we are using the original type name.
//
String const& name (ename (c));
- if (!options.value<CLI::suppress_parsing> ())
+ // If this type is anonymous but substitutes, then it will
+ // be registered as part of the substitution registration.
+ //
+ if (!anonymous_p (c) && !options.value<CLI::suppress_parsing> ())
+ {
os << "static" << endl
<< "const ::xsd::cxx::tree::type_factory_initializer< 0, " <<
char_type << ", " << name << " >" << endl
@@ -3071,13 +3099,17 @@ namespace CXX
<< strlit (c.name ()) << "," << endl
<< strlit (xml_ns_name (c)) << ");"
<< endl;
+ }
- if (options.value<CLI::generate_comparison> ())
+ if ((!anonymous_p (c) || anonymous_substitutes_p (c)) &&
+ options.value<CLI::generate_comparison> ())
+ {
os << "static" << endl
<< "const ::xsd::cxx::tree::comparison_initializer< 0, " <<
char_type << ", " << name << " >" << endl
<< "_xsd_" << name << "_comparison_init;"
<< endl;
+ }
}
// Comparison operators.