diff options
author | Jörg Frings-Fürst <debian@jff-webhosting.net> | 2014-07-23 15:25:44 +0200 |
---|---|---|
committer | Jörg Frings-Fürst <debian@jff-webhosting.net> | 2014-07-23 15:25:44 +0200 |
commit | 8286ac511144e4f17d34eac9affb97e50646344a (patch) | |
tree | f1af7320d7b6be6be059216d0ad08ac7b4f73fd0 /xsd/xsd/cxx/parser/element-validation-source.cxx | |
parent | a15cf65c44d5c224169c32ef5495b68c758134b7 (diff) |
Imported Upstream version 4.0.0upstream/4.0.0
Diffstat (limited to 'xsd/xsd/cxx/parser/element-validation-source.cxx')
-rw-r--r-- | xsd/xsd/cxx/parser/element-validation-source.cxx | 213 |
1 files changed, 114 insertions, 99 deletions
diff --git a/xsd/xsd/cxx/parser/element-validation-source.cxx b/xsd/xsd/cxx/parser/element-validation-source.cxx index 211a0d3..b2c244e 100644 --- a/xsd/xsd/cxx/parser/element-validation-source.cxx +++ b/xsd/xsd/cxx/parser/element-validation-source.cxx @@ -1,14 +1,15 @@ // file : xsd/cxx/parser/element-validation-source.cxx -// author : Boris Kolpackov <boris@codesynthesis.com> -// copyright : Copyright (c) 2005-2010 Code Synthesis Tools CC +// copyright : Copyright (c) 2005-2014 Code Synthesis Tools CC // license : GNU GPL v2 + exceptions; see accompanying LICENSE file +#include <vector> + #include <cxx/parser/element-validation-source.hxx> #include <xsd-frontend/semantic-graph.hxx> #include <xsd-frontend/traversal.hxx> -#include <cult/containers/vector.hxx> +using namespace std; namespace CXX { @@ -16,8 +17,7 @@ namespace CXX { namespace { - typedef Cult::Containers::Vector<SemanticGraph::Particle*> Particles; - + typedef vector<SemanticGraph::Particle*> Particles; // // @@ -31,7 +31,7 @@ namespace CXX { } - virtual Void + virtual void traverse (SemanticGraph::Element& e) { String const& name (e.name ()); @@ -62,7 +62,7 @@ namespace CXX } } - virtual Void + virtual void traverse (SemanticGraph::Any& a) { String const& ns (a.definition_namespace ().name ()); @@ -109,7 +109,7 @@ namespace CXX } } - virtual Void + virtual void traverse (SemanticGraph::Compositor& c) { // This compositor should already have been tested for @@ -117,9 +117,9 @@ namespace CXX // Particles const& p (c.context ().get<Particles> ("prefixes")); - Boolean paren (p.size () != 1); + bool paren (p.size () != 1); - for (Particles::ConstIterator i (p.begin ()), e (p.end ()); + for (Particles::const_iterator i (p.begin ()), e (p.end ()); i != e;) { if (paren) @@ -150,21 +150,21 @@ namespace CXX { } - virtual Void + virtual void traverse (SemanticGraph::Element& e) { String ns (e.qualified_p () ? e.namespace_ ().name () : String ()); os << strlit (ns) << ", " << strlit (e.name ()); } - virtual Void + virtual void traverse (SemanticGraph::Any& a) { String const& ns (*a.namespace_begin ()); os << strlit (ns) << ", " << L << "\"*\""; } - virtual Void + virtual void traverse (SemanticGraph::Compositor& c) { Particles const& p (c.context ().get<Particles> ("prefixes")); @@ -187,7 +187,7 @@ namespace CXX // Generate sub-parser setup code as well as the pre/post calls. // - Void + void pre_post_calls (SemanticGraph::Particle& p) { using SemanticGraph::Element; @@ -196,20 +196,23 @@ namespace CXX if (Element* e = dynamic_cast<Element*> (&p)) { SemanticGraph::Type& type (e->type ()); - Boolean poly (polymorphic && !anonymous (type)); + String const& fq_type (fq_name (type)); + bool poly (polymorphic && !anonymous (type)); String name, inst, def_parser, map; if (e->context ().count("name")) { name = ename (*e); - inst = poly ? emember_cache (*e) : emember (*e); if (poly) { def_parser = emember (*e); map = emember_map (*e); + inst = "p"; } + else + inst = L"this->" + emember (*e); } else { @@ -222,13 +225,15 @@ namespace CXX Element& fe (dynamic_cast<Element&>(ip.first->named ())); name = ename (fe); - inst = poly ? emember_cache (fe) : emember (fe); if (poly) { def_parser = emember (fe); map = emember_map (fe); + inst = "p"; } + else + inst = L"this->" + emember (fe); } if (poly) @@ -243,8 +248,10 @@ namespace CXX type_id += type_ns; } - os << "if (t == 0 && this->" << def_parser << " != 0)" << endl - << "this->" << inst << " = this->" << def_parser << ";" + os << fq_type << "* p = 0;" + << endl + << "if (t == 0 && this->" << def_parser << " != 0)" << endl + << inst << " = this->" << def_parser << ";" << "else" << "{" << string_type << " ts (" << fq_name (type) << @@ -254,7 +261,7 @@ namespace CXX << "t = &ts;" << endl << "if (this->" << def_parser << " != 0 && *t == ts)" << endl - << "this->" << inst << " = this->" << def_parser << ";" + << inst << " = this->" << def_parser << ";" << "else" << "{"; @@ -269,36 +276,51 @@ namespace CXX " > (*t);" << endl << "if (this->" << map << " != 0)" << endl - << "this->" << inst << " = dynamic_cast< " << - fq_name (type) << "* > (" << endl + << inst << " = dynamic_cast< " << fq_type << "* > (" << endl << "this->" << map << "->find (*t));" - << "else" << endl - << "this->" << inst << " = 0;" << "}" << "}"; } os << "this->" << complex_base << "::context_.top ()." << - "parser_ = this->" << inst << ";" + "parser_ = " << inst << ";" << endl - << "if (this->" << inst << ")" << endl - << "this->" << inst << "->pre ();" + << "if (" << inst << ")" << endl + << inst << "->pre ();" << "}" << "else" // start - << "{" - << "if (this->" << inst << ")" + << "{"; + + if (poly) + os << fq_type << "* p =" << endl + << "dynamic_cast< " << fq_type << "* > (" << endl + << "this->" << complex_base << "::context_.top ().parser_);" + << endl; + + os << "if (" << inst << ")" << "{"; String const& ret (ret_type (type)); String const& post (post_name (type)); if (ret == L"void") - os << "this->" << inst << "->" << post << " ();" + os << inst << "->" << post << " ();" << "this->" << name << " ();"; else - os << arg_type (type) << " tmp (this->" << inst << "->" << - post << " ());" - << "this->" << name << " (tmp);"; + { + // Don't create an lvalue in C++11 (think std::unique_ptr). + // In C++98 we do it for compatibility with older/broken + // compilers (e.g., IBM xlC that needs an lvalue to pass + // std::auto_ptr). + // + if (std == cxx_version::cxx98) + os << arg_type (type) << " tmp (" << inst << "->" << + post << " ());" + << "this->" << name << " (tmp);"; + else + os << "this->" << name << " (" << inst << "->" << + post << " ());"; + } os << "}"; } @@ -331,10 +353,10 @@ namespace CXX { } - virtual Void + virtual void traverse (SemanticGraph::Element& e) { - UnsignedLong state (e.context ().get<UnsignedLong> ("state")); + size_t state (e.context ().get<size_t> ("state")); if (state != 0) os << "else "; @@ -382,14 +404,14 @@ namespace CXX { } - virtual Void + virtual void traverse (SemanticGraph::Particle& p) { using SemanticGraph::Element; - UnsignedLong state (p.context ().get<UnsignedLong> ("state")); + size_t state (p.context ().get<size_t> ("state")); - UnsignedLong min (p.min ()), max (p.max ()); + size_t min (p.min ()), max (p.max ()); os << "case " << state << "UL:" << endl << "{"; @@ -465,15 +487,15 @@ namespace CXX << "}"; // case } - virtual Void + virtual void traverse (SemanticGraph::Compositor& c) { using SemanticGraph::Compositor; - UnsignedLong max (c.max ()); - UnsignedLong min (c.context ().get<UnsignedLong> ("effective-min")); - UnsignedLong n (c.context ().get<UnsignedLong> ("comp-number")); - UnsignedLong state (c.context ().get<UnsignedLong> ("state")); + size_t max (c.max ()); + size_t min (c.context ().get<size_t> ("effective-min")); + size_t n (c.context ().get<size_t> ("comp-number")); + size_t state (c.context ().get<size_t> ("state")); String func (c.is_a<SemanticGraph::Choice> () ? "choice_" : "sequence_"); @@ -483,7 +505,7 @@ namespace CXX << "unsigned long s (~0UL);" << endl; - Boolean first (true); + bool first (true); for (Compositor::ContainsIterator ci (c.contains_begin ()); ci != c.contains_end (); ++ci) @@ -496,7 +518,7 @@ namespace CXX if (!p.context ().count ("prefix")) break; - UnsignedLong state (p.context ().get<UnsignedLong> ("state")); + size_t state (p.context ().get<size_t> ("state")); if (first) first = false; @@ -599,8 +621,8 @@ namespace CXX ParticleInCompositor { ParticleInSequence (Context& c, - UnsignedLong state, - UnsignedLong next_state, + size_t state, + size_t next_state, SemanticGraph::Complex& type) : ParticleInCompositor (c, type), state_ (state), particle_name_ (c) @@ -617,10 +639,10 @@ namespace CXX next_state_ = L"~0"; } - virtual Void + virtual void traverse (SemanticGraph::Particle& p) { - UnsignedLong min (p.min ()), max (p.max ()); + size_t min (p.min ()), max (p.max ()); os << "case " << state_ << "UL:" << endl << "{" @@ -694,14 +716,14 @@ namespace CXX << "}"; // case } - virtual Void + virtual void traverse (SemanticGraph::Compositor& c) { using SemanticGraph::Compositor; - UnsignedLong max (c.max ()); - UnsignedLong min (c.context ().get<UnsignedLong> ("effective-min")); - UnsignedLong n (c.context ().get<UnsignedLong> ("comp-number")); + size_t max (c.max ()); + size_t min (c.context ().get<size_t> ("effective-min")); + size_t n (c.context ().get<size_t> ("comp-number")); String func (c.is_a<SemanticGraph::Choice> () ? "choice_" : "sequence_"); @@ -711,7 +733,7 @@ namespace CXX << "unsigned long s (~0UL);" << endl; - Boolean first (true); + bool first (true); for (Compositor::ContainsIterator ci (c.contains_begin ()); ci != c.contains_end (); ++ci) @@ -724,7 +746,7 @@ namespace CXX if (!p.context ().count ("prefix")) break; - UnsignedLong state (p.context ().get<UnsignedLong> ("state")); + size_t state (p.context ().get<size_t> ("state")); if (first) first = false; @@ -816,7 +838,7 @@ namespace CXX } private: - UnsignedLong state_; + size_t state_; String next_state_; ParticleName particle_name_; @@ -837,7 +859,7 @@ namespace CXX } - virtual Void + virtual void traverse (SemanticGraph::All& a) { if (!a.context().count ("comp-number")) // Empty compositor. @@ -878,7 +900,7 @@ namespace CXX Element& e (dynamic_cast<Element&> (ci->particle ())); String ns (e.qualified_p () ? e.namespace_ ().name () : String ()); - UnsignedLong state (e.context ().get<UnsignedLong> ("state")); + size_t state (e.context ().get<size_t> ("state")); os << "if (count[" << state << "UL] == 0)" << endl << "this->_expected_element (" << endl @@ -894,7 +916,7 @@ namespace CXX << "}"; } - virtual Void + virtual void traverse (SemanticGraph::Choice& c) { if (!c.context().count ("comp-number")) // Empty compositor. @@ -902,7 +924,7 @@ namespace CXX using SemanticGraph::Compositor; - UnsignedLong n (c.context ().get<UnsignedLong> ("comp-number")); + size_t n (c.context ().get<size_t> ("comp-number")); os << "void " << ename (type_) << "::" << endl << "choice_" << n << " (unsigned long& state," << endl @@ -940,7 +962,7 @@ namespace CXX Traversal::Choice::traverse (c); } - virtual Void + virtual void traverse (SemanticGraph::Sequence& s) { if (!s.context().count ("comp-number")) // Empty compositor. @@ -948,7 +970,7 @@ namespace CXX using SemanticGraph::Compositor; - UnsignedLong n (s.context ().get<UnsignedLong> ("comp-number")); + size_t n (s.context ().get<size_t> ("comp-number")); os << "void " << ename (type_) << "::" << endl << "sequence_" << n << " (unsigned long& state," << endl @@ -963,7 +985,7 @@ namespace CXX << "switch (state)" << "{"; - UnsignedLong state (0); + size_t state (0); for (Compositor::ContainsIterator ci (s.contains_begin ()), ce (s.contains_end ()); ci != ce;) @@ -986,7 +1008,7 @@ namespace CXX ci->particle ().is_a<Compositor> () && !ci->particle ().context().count ("comp-number")); - UnsignedLong next (ci == ce ? 0 : state + 1); + size_t next (ci == ce ? 0 : state + 1); ParticleInSequence t (*this, state++, next, type_); t.dispatch (p); @@ -1014,12 +1036,12 @@ namespace CXX Traversal::Compositor, Context { - CompositorPre (Context& c, SemanticGraph::Complex& type) - : Context (c), type_ (type) + CompositorPre (Context& c) + : Context (c) { } - virtual Void + virtual void traverse (SemanticGraph::All& a) { // Clear the counts and push the initial state. @@ -1031,7 +1053,7 @@ namespace CXX traverse (c); } - virtual Void + virtual void traverse (SemanticGraph::Compositor&) // Choice and sequence. { os << "v_state_& vs = *static_cast< v_state_* > (" << @@ -1042,9 +1064,6 @@ namespace CXX << "vd.state = 0;" << "vd.count = 0;"; } - - private: - SemanticGraph::Complex& type_; }; @@ -1060,7 +1079,7 @@ namespace CXX { } - virtual Void + virtual void traverse (SemanticGraph::All&) { // The 'all' state machine reaches the final state only @@ -1078,14 +1097,14 @@ namespace CXX << endl; } - virtual Void + virtual void traverse (SemanticGraph::Compositor& c) // Choice and sequence. { using SemanticGraph::Compositor; - UnsignedLong max (c.max ()); - UnsignedLong min (c.context ().get<UnsignedLong> ("effective-min")); - UnsignedLong n (c.context ().get<UnsignedLong> ("comp-number")); + size_t max (c.max ()); + size_t min (c.context ().get<size_t> ("effective-min")); + size_t n (c.context ().get<size_t> ("comp-number")); String func (c.is_a<SemanticGraph::Choice> () ? "choice_" : "sequence_"); @@ -1117,7 +1136,7 @@ namespace CXX << "unsigned long s = ~0UL;" << endl; - Boolean first (true); + bool first (true); // Note that we don't need to worry about the compositor // being empty - this case is handled by our caller. @@ -1133,7 +1152,7 @@ namespace CXX if (!p.context ().count ("prefix")) break; - UnsignedLong state (p.context ().get<UnsignedLong> ("state")); + size_t state (p.context ().get<size_t> ("state")); if (first) first = false; @@ -1230,12 +1249,12 @@ namespace CXX Traversal::Compositor, Context { - CompositorEndElement (Context& c, SemanticGraph::Complex& type) - : Context (c), type_ (type) + CompositorEndElement (Context& c) + : Context (c) { } - virtual Void + virtual void traverse (SemanticGraph::All&) { os << "all_0 (vd.state, v_all_count_.top (), " << @@ -1243,7 +1262,7 @@ namespace CXX << endl; } - virtual Void + virtual void traverse (SemanticGraph::Compositor&) // Choice and sequence. { os << "assert (vd.func != 0);" @@ -1253,9 +1272,6 @@ namespace CXX << "vs.size--;" // pop << endl; } - - private: - SemanticGraph::Complex& type_; }; @@ -1265,12 +1281,12 @@ namespace CXX Traversal::Compositor, Context { - CompositorPost (Context& c, SemanticGraph::Complex& type) - : Context (c), type_ (type), particle_name_ (c) + CompositorPost (Context& c) + : Context (c), particle_name_ (c) { } - virtual Void + virtual void traverse (SemanticGraph::All& a) { using SemanticGraph::Element; @@ -1289,7 +1305,7 @@ namespace CXX << "all_0 (vd.state, v_all_count_.top (), empty, empty, 0, true);" << "}"; - if (a.context ().get<UnsignedLong> ("effective-min") != 0) + if (a.context ().get<size_t> ("effective-min") != 0) { os << "else" << endl << "this->_expected_element (" << endl; @@ -1304,10 +1320,10 @@ namespace CXX << "v_all_count_.pop ();"; } - virtual Void + virtual void traverse (SemanticGraph::Compositor& c) // Choice and sequence. { - UnsignedLong min (c.context ().get<UnsignedLong> ("effective-min")); + size_t min (c.context ().get<size_t> ("effective-min")); os << "v_state_& vs = *static_cast< v_state_* > (" << "this->v_state_stack_.top ());" @@ -1343,7 +1359,6 @@ namespace CXX } private: - SemanticGraph::Complex& type_; ParticleName particle_name_; }; @@ -1357,7 +1372,7 @@ namespace CXX { } - virtual Void + virtual void traverse (Type& c) { // Nothing to generate if we don't have any elements and wildcards. @@ -1374,7 +1389,7 @@ namespace CXX // Don't use restriction_p here since we don't want special // treatment of anyType. // - Boolean restriction ( + bool restriction ( c.inherits_p () && c.inherits ().is_a<SemanticGraph::Restricts> ()); @@ -1476,7 +1491,7 @@ namespace CXX } { - CompositorEndElement t (*this, c); + CompositorEndElement t (*this); t.dispatch (comp); } @@ -1495,7 +1510,7 @@ namespace CXX << endl; { - CompositorPre t (*this, c); + CompositorPre t (*this); t.dispatch (comp); } @@ -1543,7 +1558,7 @@ namespace CXX } { - CompositorPost t (*this, c); + CompositorPost t (*this); t.dispatch (c.contains_compositor ().compositor ()); } @@ -1559,7 +1574,7 @@ namespace CXX }; } - Void + void generate_element_validation_source (Context& ctx) { ctx.os << "#include <cassert>" << endl @@ -1567,7 +1582,7 @@ namespace CXX Traversal::Schema schema; - Traversal::Sources sources; + Sources sources; Traversal::Names schema_names; Namespace ns (ctx); |