From 7db026e8056914d113ac0bbfd9bdc4908a9e7874 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Fri, 8 Oct 2010 15:35:23 +0200 Subject: Add support for the whiteSpace facet Use the same mechanism to handle whitespace processing for build-in types and enumerations. --- xsde/cxx/parser/elements.cxx | 43 ++++++++++ xsde/cxx/parser/elements.hxx | 5 ++ xsde/cxx/parser/parser-header.cxx | 38 ++------- xsde/cxx/parser/parser-inline.cxx | 162 +++++++++++++++++++------------------- 4 files changed, 133 insertions(+), 115 deletions(-) (limited to 'xsde/cxx/parser') 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 ("p:impl"); } + Boolean Context:: + has_facets (SemanticGraph::Complex& c) + { + if (restriction_p (c)) + { + using SemanticGraph::Restricts; + Restricts& r (dynamic_cast (c.inherits ())); + + if (r.facet_empty ()) + return false; + + SemanticGraph::Type& ub (ultimate_base (c)); + Restricts::FacetIterator end (r.facet_end ()); + + if ((ub.is_a () || + ub.is_a ()) && + r.facet_find (L"whiteSpace") != end) + return true; + + if (validation) + { + if (ub.is_a () || + ub.is_a () || + ub.is_a () || + ub.is_a () || + ub.is_a () || + ub.is_a ()) + { + 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 (c)); Boolean ha (has (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 () || - ub.is_a () || - ub.is_a () || - ub.is_a () || - ub.is_a ()) - { - using SemanticGraph::Restricts; - Restricts& r (dynamic_cast (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 (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 (c)); Boolean ha (has (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 () || - ub.is_a () || - ub.is_a () || - ub.is_a () || - ub.is_a ()) - { - using SemanticGraph::Restricts; - Restricts& r (dynamic_cast (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 (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_; -- cgit v1.1