aboutsummaryrefslogtreecommitdiff
path: root/xsd
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2010-04-14 17:22:48 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2010-04-14 17:22:48 +0200
commitad02b4ec2d8b0044e03ae5f39e75564118d7ce70 (patch)
treea3d72e0df553a2efb197142cb9f3480f19b376d2 /xsd
parent7207d957dcc2425fc89bab11efd6c5941d630956 (diff)
Do not suppress from-base c-tors for hierarchies with custom types
Diffstat (limited to 'xsd')
-rw-r--r--xsd/cxx/tree/elements.cxx32
-rw-r--r--xsd/cxx/tree/elements.hxx12
-rw-r--r--xsd/cxx/tree/tree-header.cxx12
3 files changed, 47 insertions, 9 deletions
diff --git a/xsd/cxx/tree/elements.cxx b/xsd/cxx/tree/elements.cxx
index 503ca72..76a7f9f 100644
--- a/xsd/cxx/tree/elements.cxx
+++ b/xsd/cxx/tree/elements.cxx
@@ -678,7 +678,9 @@ namespace CXX
//
GenerateFromBaseCtor::
GenerateFromBaseCtor (Context& c, Boolean& generate)
- : traverser_ (c, generate)
+ : generate_ (generate),
+ custom_ (false),
+ traverser_ (c, generate, custom_)
{
inherits_ >> traverser_;
}
@@ -687,23 +689,47 @@ namespace CXX
traverse (SemanticGraph::Complex& c)
{
inherits (c, inherits_);
+
+ if (!generate_ && custom_)
+ {
+ // We have a customized type in the hierarchy. In this case we
+ // want to generate the c-tor unless base and ultimate-base are
+ // the same (see CtorArgs).
+ //
+ SemanticGraph::Type& b (c.inherits ().base ());
+ generate_ = b.is_a<SemanticGraph::Complex> () &&
+ !b.is_a<SemanticGraph::Enumeration> ();
+ }
}
GenerateFromBaseCtor::Traverser::
- Traverser (Context& c, Boolean& generate)
- : Context (c), generate_ (generate)
+ Traverser (Context& c, Boolean& generate, Boolean& custom)
+ : Context (c), generate_ (generate), custom_ (custom)
{
*this >> inherits_ >> *this;
*this >> names_ >> *this;
}
Void GenerateFromBaseCtor::Traverser::
+ traverse (SemanticGraph::Type& t)
+ {
+ if (!custom_)
+ {
+ String tmp;
+ custom_ = custom_type (t, tmp);
+ }
+ }
+
+ Void GenerateFromBaseCtor::Traverser::
traverse (SemanticGraph::Complex& c)
{
names (c, names_);
if (!generate_)
inherits (c, inherits_);
+
+ if (!generate_)
+ traverse (static_cast<SemanticGraph::Type&> (c));
}
Void GenerateFromBaseCtor::Traverser::
diff --git a/xsd/cxx/tree/elements.hxx b/xsd/cxx/tree/elements.hxx
index 083ed09..d72cfd1 100644
--- a/xsd/cxx/tree/elements.hxx
+++ b/xsd/cxx/tree/elements.hxx
@@ -1424,16 +1424,23 @@ namespace CXX
traverse (SemanticGraph::Complex& c);
private:
+ Boolean& generate_;
+ Boolean custom_;
+
// Note that we are not interested in anyAttribute since it is always
// mapped to a sequence.
//
- struct Traverser: Traversal::Complex,
+ struct Traverser: Traversal::Type,
+ Traversal::Complex,
Traversal::Element,
Traversal::Attribute,
Traversal::Any,
Context
{
- Traverser (Context& c, Boolean& generate);
+ Traverser (Context& c, Boolean& generate, Boolean& custom);
+
+ virtual Void
+ traverse (SemanticGraph::Type&);
virtual Void
traverse (SemanticGraph::Complex&);
@@ -1449,6 +1456,7 @@ namespace CXX
private:
Boolean& generate_;
+ Boolean& custom_;
private:
Traversal::Inherits inherits_;
diff --git a/xsd/cxx/tree/tree-header.cxx b/xsd/cxx/tree/tree-header.cxx
index 100a81c..835a40f 100644
--- a/xsd/cxx/tree/tree-header.cxx
+++ b/xsd/cxx/tree/tree-header.cxx
@@ -2428,7 +2428,7 @@ namespace CXX
//
if (options.value<CLI::generate_default_ctor> ())
{
- // c-tor (ultimate-base all-non-optional-members) will become
+ // c-tor (ultimate-base, all-non-optional-members) will become
// default c-tor if our inheritance hierarchy has no required
// members and no simple base. We can also collide with
// c-tor (all-non-optional-members) if we have no required
@@ -2462,9 +2462,13 @@ namespace CXX
//
if (options.value<CLI::generate_from_base_ctor> ())
{
- // c-tor (ultimate-base, all-non-optional-members) will become
- // c-tor (base, all-non-optional-members) unless our immediate
- // base's hierarchy has some non-optional members.
+ // c-tor (base, all-non-optional-members) will be equivalent to
+ // c-tor (ultimate-base, all-non-optional-members) unless our
+ // immediate base's hierarchy has some non-optional members.
+ // We also need to generate this c-tor when one of the types
+ // in our inheritance hierarchy was customized since the
+ // customized version may not necessarily be convertible to
+ // the base without loss of information.
//
Boolean generate (false);
{