aboutsummaryrefslogtreecommitdiff
path: root/xsde/cxx/parser
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2010-10-08 15:35:23 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2010-10-08 15:35:23 +0200
commit7db026e8056914d113ac0bbfd9bdc4908a9e7874 (patch)
tree0ab15cb8b0ee160a10cca21edaf0aca1e97e8921 /xsde/cxx/parser
parent4f38adc11ab1a3a1ab2dd3f958c917182be7d71f (diff)
Add support for the whiteSpace facet
Use the same mechanism to handle whitespace processing for build-in types and enumerations.
Diffstat (limited to 'xsde/cxx/parser')
-rw-r--r--xsde/cxx/parser/elements.cxx43
-rw-r--r--xsde/cxx/parser/elements.hxx5
-rw-r--r--xsde/cxx/parser/parser-header.cxx38
-rw-r--r--xsde/cxx/parser/parser-inline.cxx162
4 files changed, 133 insertions, 115 deletions
diff --git a/xsde/cxx/parser/elements.cxx b/xsde/cxx/parser/elements.cxx
index 7cf1fec..2c138ce 100644
--- a/xsde/cxx/parser/elements.cxx
+++ b/xsde/cxx/parser/elements.cxx
@@ -193,6 +193,49 @@ namespace CXX
return t.context ().get<String> ("p:impl");
}
+ Boolean Context::
+ has_facets (SemanticGraph::Complex& c)
+ {
+ if (restriction_p (c))
+ {
+ using SemanticGraph::Restricts;
+ Restricts& r (dynamic_cast<Restricts&> (c.inherits ()));
+
+ if (r.facet_empty ())
+ return false;
+
+ SemanticGraph::Type& ub (ultimate_base (c));
+ Restricts::FacetIterator end (r.facet_end ());
+
+ if ((ub.is_a<SemanticGraph::Fundamental::String> () ||
+ ub.is_a<SemanticGraph::Fundamental::AnyURI> ()) &&
+ r.facet_find (L"whiteSpace") != end)
+ return true;
+
+ if (validation)
+ {
+ if (ub.is_a<SemanticGraph::Fundamental::Short> () ||
+ ub.is_a<SemanticGraph::Fundamental::UnsignedByte> () ||
+ ub.is_a<SemanticGraph::Fundamental::UnsignedShort> () ||
+ ub.is_a<SemanticGraph::Fundamental::UnsignedInt> () ||
+ ub.is_a<SemanticGraph::Fundamental::String> () ||
+ ub.is_a<SemanticGraph::Fundamental::AnyURI> ())
+ {
+ if (r.facet_find (L"length") != end ||
+ r.facet_find (L"minLength") != end ||
+ r.facet_find (L"maxLength") != end ||
+ r.facet_find (L"minInclusive") != end ||
+ r.facet_find (L"minExclusive") != end ||
+ r.facet_find (L"maxInclusive") != end ||
+ r.facet_find (L"maxExclusive") != end)
+ return true;
+ }
+ }
+ }
+
+ return false;
+ }
+
// Includes
//
Void TypeForward::
diff --git a/xsde/cxx/parser/elements.hxx b/xsde/cxx/parser/elements.hxx
index 4af395f..497577f 100644
--- a/xsde/cxx/parser/elements.hxx
+++ b/xsde/cxx/parser/elements.hxx
@@ -163,6 +163,11 @@ namespace CXX
static String const&
eimpl (SemanticGraph::Type&);
+
+ public:
+ Boolean
+ has_facets (SemanticGraph::Complex& c);
+
public:
CLI::Options const& options;
String& xml_parser;
diff --git a/xsde/cxx/parser/parser-header.cxx b/xsde/cxx/parser/parser-header.cxx
index f03d588..11176f9 100644
--- a/xsde/cxx/parser/parser-header.cxx
+++ b/xsde/cxx/parser/parser-header.cxx
@@ -28,13 +28,15 @@ namespace CXX
SemanticGraph::Type& base (e.inherits ().base ());
String fq_base (fq_name (base));
- Boolean facets (false); // Whether we need to set facets.
+ Boolean enum_facets (false); // Whether we need to set enum facets.
if (validation)
{
- StringBasedType t (facets);
+ StringBasedType t (enum_facets);
t.dispatch (e);
}
+ Boolean facets (enum_facets || has_facets (e));
+
os << "class " << name << ": public " <<
(mixin ? "virtual " : "") << fq_base
<< "{"
@@ -101,7 +103,7 @@ namespace CXX
<< name << " (" << name << "*, void*);";
}
- if (facets)
+ if (enum_facets)
{
UnsignedLong enum_count (0);
@@ -737,6 +739,7 @@ namespace CXX
//
Boolean hb (c.inherits_p ());
Boolean restriction (restriction_p (c));
+ Boolean facets (has_facets (c));
Boolean he (has<Traversal::Element> (c));
Boolean ha (has<Traversal::Attribute> (c));
@@ -752,35 +755,6 @@ namespace CXX
names (c, names_test);
}
- Boolean facets (false); // Defines facets.
- if (validation && restriction)
- {
- SemanticGraph::Type& ub (ultimate_base (c));
-
- if (ub.is_a<SemanticGraph::Fundamental::Short> () ||
- ub.is_a<SemanticGraph::Fundamental::UnsignedByte> () ||
- ub.is_a<SemanticGraph::Fundamental::UnsignedShort> () ||
- ub.is_a<SemanticGraph::Fundamental::UnsignedInt> () ||
- ub.is_a<SemanticGraph::Fundamental::String> ())
- {
- using SemanticGraph::Restricts;
- Restricts& r (dynamic_cast<Restricts&> (c.inherits ()));
-
- if (!r.facet_empty ())
- {
- Restricts::FacetIterator end (r.facet_end ());
- facets =
- r.facet_find (L"length") != end ||
- r.facet_find (L"minLength") != end ||
- r.facet_find (L"maxLength") != end ||
- r.facet_find (L"minInclusive") != end ||
- r.facet_find (L"minExclusive") != end ||
- r.facet_find (L"maxInclusive") != end ||
- r.facet_find (L"maxExclusive") != end;
- }
- }
- }
-
//
//
os << "class " << name << ": public ";
diff --git a/xsde/cxx/parser/parser-inline.cxx b/xsde/cxx/parser/parser-inline.cxx
index 528ff86..984eca6 100644
--- a/xsde/cxx/parser/parser-inline.cxx
+++ b/xsde/cxx/parser/parser-inline.cxx
@@ -14,6 +14,61 @@ namespace CXX
{
namespace
{
+ Void
+ facet_calls (SemanticGraph::Complex& c, Context& ctx)
+ {
+ std::wostream& os (ctx.os);
+
+ using SemanticGraph::Restricts;
+ Restricts& r (dynamic_cast<Restricts&> (c.inherits ()));
+
+ for (Restricts::FacetIterator i (r.facet_begin ());
+ i != r.facet_end (); ++i)
+ {
+ if (i->first == L"length")
+ {
+ os << "this->_length_facet (" << i->second << "UL);";
+ }
+ else if (i->first == L"minLength")
+ {
+ os << "this->_min_length_facet (" << i->second << "UL);";
+ }
+ else if (i->first == L"maxLength")
+ {
+ os << "this->_max_length_facet (" << i->second << "UL);";
+ }
+ else if (i->first == L"minInclusive")
+ {
+ os << "this->_min_facet (" << i->second << ", true);";
+ }
+ else if (i->first == L"minExclusive")
+ {
+ os << "this->_min_facet (" << i->second << ", false);";
+ }
+ else if (i->first == L"maxInclusive")
+ {
+ os << "this->_max_facet (" << i->second << ", true);";
+ }
+ else if (i->first == L"maxExclusive")
+ {
+ os << "this->_max_facet (" << i->second << ", false);";
+ }
+ else if (i->first == L"whiteSpace")
+ {
+ os << "this->_whitespace_facet (";
+
+ if (i->second == L"preserve")
+ os << "0";
+ else if (i->second == L"replace")
+ os << "1";
+ else if (i->second == L"collapse")
+ os << "2";
+
+ os << ");";
+ }
+ }
+ }
+
struct Enumeration: Traversal::Enumeration, Context
{
Enumeration (Context& c)
@@ -26,21 +81,23 @@ namespace CXX
{
String const& name (ename (e));
- Boolean facets (false); // Whether we need to set facets.
+ Boolean enum_facets (false); // Whether we need to set enum facets.
if (validation)
{
- StringBasedType t (facets);
+ StringBasedType t (enum_facets);
t.dispatch (e);
}
UnsignedLong enum_count (0);
- if (facets)
+ if (enum_facets)
{
for (Type::NamesIterator i (e.names_begin ()), end (e.names_end ());
i != end; ++i)
++enum_count;
}
+ Boolean facets (enum_facets || has_facets (e));
+
if (facets || tiein)
os << "// " << name << endl
<< "//" << endl
@@ -51,10 +108,9 @@ namespace CXX
os << inl
<< name << "::" << endl
<< name << " ()" << endl
- << "{"
- << "this->_enumeration_facet (_xsde_" << name << "_enums_, " <<
- enum_count << "UL);"
- << "}";
+ << "{";
+ facet_calls (e, enum_count);
+ os << "}";
}
if (tiein)
@@ -76,8 +132,7 @@ namespace CXX
<< "{";
if (facets)
- os << "this->_enumeration_facet (_xsde_" << name <<
- "_enums_, " << enum_count << "UL);";
+ facet_calls (e, enum_count);
os << "}";
@@ -89,12 +144,22 @@ namespace CXX
<< "{";
if (facets)
- os << "this->_enumeration_facet (_xsde_" << name <<
- "_enums_, " << enum_count << "UL);";
+ facet_calls (e, enum_count);
os << "}";
}
}
+
+ private:
+ Void
+ facet_calls (Type& e, UnsignedLong enum_count)
+ {
+ Parser::facet_calls (e, *this);
+
+ if (enum_count != 0)
+ os << "this->_enumeration_facet (_xsde_" << ename (e) <<
+ "_enums_, " << enum_count << "UL);";
+ }
};
//
@@ -454,6 +519,7 @@ namespace CXX
traverse (Type& c)
{
Boolean hb (c.inherits_p ());
+ Boolean facets (has_facets (c));
Boolean he (has<Traversal::Element> (c));
Boolean ha (has<Traversal::Attribute> (c));
@@ -469,35 +535,6 @@ namespace CXX
Boolean restriction (restriction_p (c));
- Boolean facets (false); // Defines facets.
- if (validation && restriction)
- {
- SemanticGraph::Type& ub (ultimate_base (c));
-
- if (ub.is_a<SemanticGraph::Fundamental::Short> () ||
- ub.is_a<SemanticGraph::Fundamental::UnsignedByte> () ||
- ub.is_a<SemanticGraph::Fundamental::UnsignedShort> () ||
- ub.is_a<SemanticGraph::Fundamental::UnsignedInt> () ||
- ub.is_a<SemanticGraph::Fundamental::String> ())
- {
- using SemanticGraph::Restricts;
- Restricts& r (dynamic_cast<Restricts&> (c.inherits ()));
-
- if (!r.facet_empty ())
- {
- Restricts::FacetIterator end (r.facet_end ());
- facets =
- r.facet_find (L"length") != end ||
- r.facet_find (L"minLength") != end ||
- r.facet_find (L"maxLength") != end ||
- r.facet_find (L"minInclusive") != end ||
- r.facet_find (L"minExclusive") != end ||
- r.facet_find (L"maxInclusive") != end ||
- r.facet_find (L"maxExclusive") != end;
- }
- }
- }
-
if (!(tiein || facets ||
(!restriction && (he || ha)) ||
(validation && (he || hae || hra))))
@@ -643,7 +680,7 @@ namespace CXX
os << "{";
if (facets)
- facet_calls (c);
+ facet_calls (c, *this);
os << "}";
@@ -721,54 +758,13 @@ namespace CXX
os << "{";
if (facets)
- facet_calls (c);
+ facet_calls (c, *this);
os << "}";
}
}
private:
- Void
- facet_calls (Type& c)
- {
- using SemanticGraph::Restricts;
- Restricts& r (dynamic_cast<Restricts&> (c.inherits ()));
-
- for (Restricts::FacetIterator i (r.facet_begin ());
- i != r.facet_end (); ++i)
- {
- if (i->first == L"length")
- {
- os << "this->_length_facet (" << i->second << "UL);";
- }
- else if (i->first == L"minLength")
- {
- os << "this->_min_length_facet (" << i->second << "UL);";
- }
- else if (i->first == L"maxLength")
- {
- os << "this->_max_length_facet (" << i->second << "UL);";
- }
- else if (i->first == L"minInclusive")
- {
- os << "this->_min_facet (" << i->second << ", true);";
- }
- else if (i->first == L"minExclusive")
- {
- os << "this->_min_facet (" << i->second << ", false);";
- }
- else if (i->first == L"maxInclusive")
- {
- os << "this->_max_facet (" << i->second << ", true);";
- }
- else if (i->first == L"maxExclusive")
- {
- os << "this->_max_facet (" << i->second << ", false);";
- }
- }
- }
-
- private:
//
//
Traversal::Compositor compositor_accessor_;