summaryrefslogtreecommitdiff
path: root/xsd
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2010-01-08 14:49:11 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2010-01-08 14:49:11 +0200
commit3f8c237b1abe02df8147170f2fc037edc3f384db (patch)
tree2531f2fddd4cadaab27cd37eb37ebcac3481acec /xsd
parent0153d99ab976ac88f432099ddfe840e15d4f6a8e (diff)
Add support for default/fixed values of QName type
Diffstat (limited to 'xsd')
-rw-r--r--xsd/cxx/tree/default-value.cxx30
-rw-r--r--xsd/cxx/tree/elements.cxx29
-rw-r--r--xsd/cxx/tree/elements.hxx6
-rw-r--r--xsd/cxx/tree/name-processor.cxx5
-rw-r--r--xsd/cxx/tree/serialization-source.cxx4
-rw-r--r--xsd/cxx/tree/stream-extraction-source.cxx4
-rw-r--r--xsd/cxx/tree/stream-insertion-source.cxx4
-rw-r--r--xsd/cxx/tree/stream-source.cxx4
-rw-r--r--xsd/cxx/tree/tree-header.cxx12
-rw-r--r--xsd/cxx/tree/tree-inline.cxx5
-rw-r--r--xsd/cxx/tree/tree-source.cxx35
11 files changed, 53 insertions, 85 deletions
diff --git a/xsd/cxx/tree/default-value.cxx b/xsd/cxx/tree/default-value.cxx
index c859949..05679f7 100644
--- a/xsd/cxx/tree/default-value.cxx
+++ b/xsd/cxx/tree/default-value.cxx
@@ -514,8 +514,36 @@ namespace CXX
// Qualified name.
//
Void InitValue::
- traverse (SemanticGraph::Fundamental::QName&)
+ traverse (SemanticGraph::Fundamental::QName& t)
{
+ Size p (value_.rfind ('#'));
+
+ if (p != String::npos)
+ {
+ String ns (value_, 0, p);
+ String qname (value_, p + 1, String::npos);
+
+ collapse (ns);
+ collapse (qname);
+
+ p = qname.find (':');
+
+ String name;
+ if (p != String::npos)
+ name.assign (qname, p + 1, String::npos);
+ else
+ name = qname;
+
+ os << fq_name (t) << " (" << strlit (ns) << ", " <<
+ strlit (name) << ")";
+ }
+ else
+ {
+ // Unqualified name.
+ //
+ collapse (value_);
+ os << fq_name (t) << " (" << strlit (value_) << ")";
+ }
}
// ID/IDREF.
diff --git a/xsd/cxx/tree/elements.cxx b/xsd/cxx/tree/elements.cxx
index 599fc27..d9615ac 100644
--- a/xsd/cxx/tree/elements.cxx
+++ b/xsd/cxx/tree/elements.cxx
@@ -471,25 +471,6 @@ namespace CXX
return false;
}
- Boolean Context::
- is_qname (SemanticGraph::Type& t)
- {
- using SemanticGraph::Complex;
- using SemanticGraph::Fundamental::QName;
-
- if (t.is_a<QName> ())
- return true;
-
- if (Complex* c = dynamic_cast<Complex*> (&t))
- {
- if (c->inherits_p () && ultimate_base (*c).is_a<QName> ())
- return true;
- }
-
- return false;
- }
-
-
Void Context::
write_annotation (SemanticGraph::Annotation& a)
{
@@ -658,7 +639,7 @@ namespace CXX
Void GenerateDefaultCtor::
traverse (SemanticGraph::Attribute& a)
{
- if (min (a) == 1 && !(a.fixed () && !is_qname (a.type ())))
+ if (min (a) == 1 && !a.fixed ())
generate_ = true;
}
@@ -713,7 +694,7 @@ namespace CXX
Void GenerateFromBaseCtor::Traverser::
traverse (SemanticGraph::Attribute& a)
{
- if (min (a) == 1 && !(a.fixed () && !is_qname (a.type ())))
+ if (min (a) == 1 && !a.fixed ())
generate_ = true;
}
@@ -857,7 +838,7 @@ namespace CXX
// default or required fixed values here. Instead we are
// going to default-initialize them.
//
- if (min (a) == 1 && !(a.fixed () && !is_qname (a.type ())))
+ if (min (a) == 1 && !a.fixed ())
{
String const& name (ename (a));
@@ -993,7 +974,7 @@ namespace CXX
// default or required fixed values here. Instead we are
// going to default-initialize them.
//
- if (min (a) == 1 && !(a.fixed () && !is_qname (a.type ())))
+ if (min (a) == 1 && !a.fixed ())
{
os << comma () << "const " << etype (a) << "&";
@@ -1085,7 +1066,7 @@ namespace CXX
// default or required fixed values here. Instead we are
// going to default-initialize them.
//
- if (min (a) == 1 && !(a.fixed () && !is_qname (a.type ())))
+ if (min (a) == 1 && !a.fixed ())
{
os << comma () << "const " << etype (a) << "&";
diff --git a/xsd/cxx/tree/elements.hxx b/xsd/cxx/tree/elements.hxx
index 563f47c..0af42c9 100644
--- a/xsd/cxx/tree/elements.hxx
+++ b/xsd/cxx/tree/elements.hxx
@@ -150,12 +150,6 @@ namespace CXX
renamed_type (SemanticGraph::Type const&, String& name) const;
public:
- // Return true if this type is-a QName.
- //
- Boolean
- is_qname (SemanticGraph::Type&);
-
- public:
// Performs a number of processing steps, including forcing a new
// line after 80 characters as well as "commentizing" the text by
// adding '* ' after each newline.
diff --git a/xsd/cxx/tree/name-processor.cxx b/xsd/cxx/tree/name-processor.cxx
index 7732162..c90433f 100644
--- a/xsd/cxx/tree/name-processor.cxx
+++ b/xsd/cxx/tree/name-processor.cxx
@@ -674,8 +674,7 @@ namespace CXX
String const& b (m.context ().get<String> ("name"));
Boolean def_attr (m.default_ () &&
- m.is_a<SemanticGraph::Attribute> () &&
- !Tree::Context::is_qname (m.type ()));
+ m.is_a<SemanticGraph::Attribute> ());
// Accessors/modifiers. Note that we postpone inserting the
// names into the name_set to avoid over-escaping.
@@ -799,7 +798,7 @@ namespace CXX
// Default value.
//
- if (m.default_ () && !Tree::Context::is_qname (m.type ()))
+ if (m.default_ ())
{
Boolean simple (true);
diff --git a/xsd/cxx/tree/serialization-source.cxx b/xsd/cxx/tree/serialization-source.cxx
index d38e28d..69f66c0 100644
--- a/xsd/cxx/tree/serialization-source.cxx
+++ b/xsd/cxx/tree/serialization-source.cxx
@@ -583,9 +583,7 @@ namespace CXX
os << "// " << comment (a.name ()) << endl
<< "//" << endl;
- Boolean def (a.default_ () && !is_qname (a.type ()));
-
- if (a.optional () && !def)
+ if (a.optional () && !a.default_ ())
{
os << "if (i." << aname << " ())"
<< "{"
diff --git a/xsd/cxx/tree/stream-extraction-source.cxx b/xsd/cxx/tree/stream-extraction-source.cxx
index 1f45042..c777f30 100644
--- a/xsd/cxx/tree/stream-extraction-source.cxx
+++ b/xsd/cxx/tree/stream-extraction-source.cxx
@@ -477,9 +477,7 @@ namespace CXX
traverser.dispatch (a.type ());
}
- Boolean def (a.default_ () && !is_qname (a.type ()));
-
- if (a.optional () && !def)
+ if (a.optional () && !a.default_ ())
{
os << "{"
<< "bool p;"
diff --git a/xsd/cxx/tree/stream-insertion-source.cxx b/xsd/cxx/tree/stream-insertion-source.cxx
index adc8082..d7e721d 100644
--- a/xsd/cxx/tree/stream-insertion-source.cxx
+++ b/xsd/cxx/tree/stream-insertion-source.cxx
@@ -341,9 +341,7 @@ namespace CXX
{
String const& aname (eaname (a));
- Boolean def (a.default_ () && !is_qname (a.type ()));
-
- if (a.optional () && !def)
+ if (a.optional () && !a.default_ ())
{
os << "{"
<< "bool p (x." << aname << " ());"
diff --git a/xsd/cxx/tree/stream-source.cxx b/xsd/cxx/tree/stream-source.cxx
index 6518b52..a93d49e 100644
--- a/xsd/cxx/tree/stream-source.cxx
+++ b/xsd/cxx/tree/stream-source.cxx
@@ -317,9 +317,7 @@ namespace CXX
{
String const& aname (eaname (a));
- Boolean def (a.default_ () && !is_qname (a.type ()));
-
- if (a.optional () && !def)
+ if (a.optional () && !a.default_ ())
{
os << "if (i." << aname << " ())"
<< "{"
diff --git a/xsd/cxx/tree/tree-header.cxx b/xsd/cxx/tree/tree-header.cxx
index 66e3b7e..fa5820d 100644
--- a/xsd/cxx/tree/tree-header.cxx
+++ b/xsd/cxx/tree/tree-header.cxx
@@ -1076,8 +1076,7 @@ namespace CXX
}
Boolean def_attr (m.default_ () &&
- m.is_a<SemanticGraph::Attribute> () &&
- !is_qname (m.type ()));
+ m.is_a<SemanticGraph::Attribute> ());
if (max (m) != 1)
{
@@ -1347,7 +1346,7 @@ namespace CXX
// default_value
//
- if (m.default_ () && !is_qname (m.type ()))
+ if (m.default_ ())
{
Boolean simple (true);
@@ -1763,7 +1762,7 @@ namespace CXX
String const& type (etype (m));
Boolean el (m.is_a<SemanticGraph::Element> ());
- Boolean def_attr (m.default_ () && !el && !is_qname (m.type ()));
+ Boolean def_attr (m.default_ () && !el);
if (doxygen)
{
@@ -2136,8 +2135,7 @@ namespace CXX
String const& member (emember (m));
Boolean def_attr (m.default_ () &&
- m.is_a<SemanticGraph::Attribute> () &&
- !is_qname (m.type ()));
+ m.is_a<SemanticGraph::Attribute> ());
if (max (m) != 1)
{
@@ -2161,7 +2159,7 @@ namespace CXX
// default_value
//
- if (m.default_ () && !is_qname (m.type ()))
+ if (m.default_ ())
{
Boolean simple (true);
diff --git a/xsd/cxx/tree/tree-inline.cxx b/xsd/cxx/tree/tree-inline.cxx
index 6909e7c..a075d3f 100644
--- a/xsd/cxx/tree/tree-inline.cxx
+++ b/xsd/cxx/tree/tree-inline.cxx
@@ -444,8 +444,7 @@ namespace CXX
}
Boolean def_attr (m.default_ () &&
- m.is_a<SemanticGraph::Attribute> () &&
- !is_qname (m.type ()));
+ m.is_a<SemanticGraph::Attribute> ());
if (max (m) != 1)
{
@@ -600,7 +599,7 @@ namespace CXX
// default_value
//
- if (m.default_ () && !is_qname (m.type ()))
+ if (m.default_ ())
{
Boolean simple (true);
diff --git a/xsd/cxx/tree/tree-source.cxx b/xsd/cxx/tree/tree-source.cxx
index 49a846c..4a94520 100644
--- a/xsd/cxx/tree/tree-source.cxx
+++ b/xsd/cxx/tree/tree-source.cxx
@@ -557,7 +557,7 @@ namespace CXX
// default_value
//
- if (m.default_ () && !is_qname (m.type ()))
+ if (m.default_ ())
{
SemanticGraph::Type& t (m.type ());
Boolean simple (true);
@@ -1190,31 +1190,8 @@ namespace CXX
if (a.default_ ())
{
- Boolean fund (false);
- {
- IsFundamentalType traverser (fund);
- traverser.dispatch (a.type ());
- }
-
- String const& tr (etraits (a)); // traits type name
-
- if (fund || !is_qname (a.type ()))
- {
- os << "this->" << member << ".set (" <<
- edefault_value (a) << " ());";
- }
- else
- {
- // Parse the default value in the context of the element.
- //
- os << "::std::auto_ptr< " << etype (a) << " > r (" << endl
- << tr << "::create (" << endl
- << string_type << " (" << L << strlit (a.value ()) <<
- ")," << endl
- << "&p.element (), f, this));"
- << endl
- << "this->" << member << ".set (r);";
- }
+ os << "this->" << member << ".set (" <<
+ edefault_value (a) << " ());";
}
else
os << "throw ::xsd::cxx::tree::expected_attribute< " <<
@@ -1330,7 +1307,7 @@ namespace CXX
// Note that we are not including attributes with default
// or required fixed values here.
//
- if (min (a) == 1 && !(a.fixed () && !is_qname (a.type ())))
+ if (min (a) == 1 && !a.fixed ())
{
// one
//
@@ -1407,7 +1384,7 @@ namespace CXX
{
String const& member (emember (a));
- Boolean def (a.default_ () && !is_qname (a.type ()));
+ Boolean def (a.default_ ());
if (min (a) == 0 && !def)
{
@@ -1643,7 +1620,7 @@ namespace CXX
{
String const& member (emember (a));
- if (a.default_ () && !is_qname (a.type ()))
+ if (a.default_ ())
{
// This is an attribute with default or fixed value. We are
// going to initialize it to its default value.