diff options
Diffstat (limited to 'xsd/xsd/processing')
-rw-r--r-- | xsd/xsd/processing/cardinality/processor.cxx | 105 | ||||
-rw-r--r-- | xsd/xsd/processing/cardinality/processor.hxx | 11 | ||||
-rw-r--r-- | xsd/xsd/processing/inheritance/processor.cxx | 95 | ||||
-rw-r--r-- | xsd/xsd/processing/inheritance/processor.hxx | 11 |
4 files changed, 118 insertions, 104 deletions
diff --git a/xsd/xsd/processing/cardinality/processor.cxx b/xsd/xsd/processing/cardinality/processor.cxx index 473c412..f43395a 100644 --- a/xsd/xsd/processing/cardinality/processor.cxx +++ b/xsd/xsd/processing/cardinality/processor.cxx @@ -1,26 +1,23 @@ // file : processing/cardinality/processor.cxx -// author : Boris Kolpackov <boris@codesynthesis.com> -// copyright : Copyright (c) 2006-2010 Code Synthesis Tools CC +// copyright : Copyright (c) 2006-2014 Code Synthesis Tools CC // license : GNU GPL v2 + exceptions; see accompanying LICENSE file -#include <processing/cardinality/processor.hxx> - -#include <elements.hxx> +#include <map> #include <xsd-frontend/semantic-graph.hxx> #include <xsd-frontend/traversal.hxx> -#include <cult/containers/map.hxx> +#include <elements.hxx> + +#include <processing/cardinality/processor.hxx> + +using namespace std; namespace Processing { - using namespace Cult; - namespace SemanticGraph = XSDFrontend::SemanticGraph; namespace Traversal = XSDFrontend::Traversal; - typedef WideString String; - namespace Cardinality { namespace @@ -39,8 +36,7 @@ namespace Processing { } - ElementInfo (SemanticGraph::Element& e, - UnsignedLong min_, UnsignedLong max_) + ElementInfo (SemanticGraph::Element& e, size_t min_, size_t max_) : min (min_), max (max_), e_ (&e) { } @@ -53,13 +49,13 @@ namespace Processing } public: - UnsignedLong min, max; + size_t min, max; private: SemanticGraph::Element* e_; }; - typedef Cult::Containers::Map<String, ElementInfo> ElementInfoMap; + typedef map<String, ElementInfo> ElementInfoMap; // // @@ -75,8 +71,7 @@ namespace Processing { } - AnyInfo (SemanticGraph::Any& a, - UnsignedLong min_, UnsignedLong max_) + AnyInfo (SemanticGraph::Any& a, size_t min_, size_t max_) : min (min_), max (max_), a_ (&a) { } @@ -89,13 +84,13 @@ namespace Processing } public: - UnsignedLong min, max; + size_t min, max; private: SemanticGraph::Any* a_; }; - typedef Cult::Containers::Map<String, AnyInfo> AnyInfoMap; + typedef map<String, AnyInfo> AnyInfoMap; // // @@ -105,13 +100,13 @@ namespace Processing Traversal::Element, Traversal::Any { - virtual Void + virtual void traverse (SemanticGraph::All& a) { traverse_sequence (a); } - virtual Void + virtual void traverse (SemanticGraph::Choice& c) { using SemanticGraph::Compositor; @@ -135,20 +130,26 @@ namespace Processing // those that are we need to choose minimum between // the two for min and maximum for max. // - for (ElementInfoMap::Iterator i (el_map.begin ()); + for (ElementInfoMap::iterator i (el_map.begin ()); i != el_map.end (); ++i) { String const& name (i->first); ElementInfo& ei (i->second); - ElementInfoMap::Iterator j (t.el_map.find (name)); + ElementInfoMap::iterator j (t.el_map.find (name)); if (j == t.el_map.end ()) ei.min = 0; else { ei.min = j->second.min < ei.min ? j->second.min : ei.min; - ei.max = j->second.max > ei.max ? j->second.max : ei.max; + + // Unbounded is encoded as 0. + // + if (j->second.max == 0 || ei.max == 0) + ei.max = 0; + else + ei.max = j->second.max > ei.max ? j->second.max : ei.max; } } @@ -156,13 +157,13 @@ namespace Processing // not in the map, we need to add to the map and set their // min to 0. // - for (ElementInfoMap::Iterator i (t.el_map.begin ()); + for (ElementInfoMap::iterator i (t.el_map.begin ()); i != t.el_map.end (); ++i) { String const& name (i->first); ElementInfo& ei (i->second); - ElementInfoMap::Iterator j (el_map.find (name)); + ElementInfoMap::iterator j (el_map.find (name)); if (j == el_map.end ()) el_map[name] = ElementInfo (ei.element (), 0, ei.max); @@ -173,7 +174,7 @@ namespace Processing // we need to copy them from each arm of choice and set min to // 0. // - for (AnyInfoMap::Iterator i (t.any_map.begin ()); + for (AnyInfoMap::iterator i (t.any_map.begin ()); i != t.any_map.end (); ++i) { String const& name (i->first); @@ -187,19 +188,19 @@ namespace Processing // Choice's min and max. // - UnsignedLong cmin (c.min ()), cmax (c.max ()); + size_t cmin (c.min ()), cmax (c.max ()); // Iterate over elements and wildcards in the maps and multiply // their cardinality by cmin and cmax. // - for (ElementInfoMap::Iterator i (el_map.begin ()); + for (ElementInfoMap::iterator i (el_map.begin ()); i != el_map.end (); ++i) { i->second.min *= cmin; i->second.max *= cmax; } - for (AnyInfoMap::Iterator i (any_map.begin ()); + for (AnyInfoMap::iterator i (any_map.begin ()); i != any_map.end (); ++i) { i->second.min *= cmin; // Not really necessary since min == 0. @@ -207,20 +208,20 @@ namespace Processing } } - virtual Void + virtual void traverse (SemanticGraph::Sequence& s) { traverse_sequence (s); } - Void + void traverse_sequence (SemanticGraph::Compositor& c) { using SemanticGraph::Compositor; // Sequence's min and max. // - UnsignedLong smin (c.min ()), smax (c.max ()); + size_t smin (c.min ()), smax (c.max ()); // Go over all particles we contain and add them to the map. // @@ -232,14 +233,14 @@ namespace Processing // Handle elements. // - for (ElementInfoMap::Iterator i (t.el_map.begin ()); + for (ElementInfoMap::iterator i (t.el_map.begin ()); i != t.el_map.end (); ++i) { String const& name (i->first); ElementInfo& ei (i->second); - UnsignedLong min (ei.min * smin); - UnsignedLong max (ei.max * smax); - ElementInfoMap::Iterator j (el_map.find (name)); + size_t min (ei.min * smin); + size_t max (ei.max * smax); + ElementInfoMap::iterator j (el_map.find (name)); if (j != el_map.end ()) { @@ -255,13 +256,13 @@ namespace Processing // Handle wildcards. // - for (AnyInfoMap::Iterator i (t.any_map.begin ()); + for (AnyInfoMap::iterator i (t.any_map.begin ()); i != t.any_map.end (); ++i) { String const& name (i->first); AnyInfo& ai (i->second); - UnsignedLong min (ai.min * smin); - UnsignedLong max (ai.max * smax); + size_t min (ai.min * smin); + size_t max (ai.max * smax); assert (any_map.find (name) == any_map.end ()); @@ -270,7 +271,7 @@ namespace Processing } } - virtual Void + virtual void traverse (SemanticGraph::Element& e) { SemanticGraph::ContainsParticle& cp (e.contained_particle ()); @@ -282,7 +283,7 @@ namespace Processing el_map[name] = ElementInfo (e, cp.min (), cp.max ()); } - virtual Void + virtual void traverse (SemanticGraph::Any& a) { SemanticGraph::ContainsParticle& cp (a.contained_particle ()); @@ -300,7 +301,7 @@ namespace Processing // struct Complex: Traversal::Complex { - virtual Void + virtual void traverse (Type& c) { if (c.contains_compositor_p ()) @@ -308,21 +309,21 @@ namespace Processing Particle t; t.dispatch (c.contains_compositor ().compositor ()); - for (ElementInfoMap::Iterator i (t.el_map.begin ()); + for (ElementInfoMap::iterator i (t.el_map.begin ()); i != t.el_map.end (); ++i) { ElementInfo& ei (i->second); - FrontendElements::Context& ctx (ei.element ().context ()); + SemanticGraph::Context& ctx (ei.element ().context ()); ctx.set ("min", ei.min); ctx.set ("max", ei.max); } - for (AnyInfoMap::Iterator i (t.any_map.begin ()); + for (AnyInfoMap::iterator i (t.any_map.begin ()); i != t.any_map.end (); ++i) { AnyInfo& ai (i->second); - FrontendElements::Context& ctx (ai.any ().context ()); + SemanticGraph::Context& ctx (ai.any ().context ()); ctx.set ("min", ai.min); ctx.set ("max", ai.max); @@ -340,13 +341,13 @@ namespace Processing // struct Attribute: Traversal::Attribute { - virtual Void + virtual void traverse (Type& a) { - FrontendElements::Context& ctx (a.context ()); + SemanticGraph::Context& ctx (a.context ()); - ctx.set ("min", a.optional_p () ? 0UL : 1UL); - ctx.set ("max", 1UL); + ctx.set ("min", size_t (a.optional_p () ? 0 : 1)); + ctx.set ("max", size_t (1)); } }; @@ -355,7 +356,7 @@ namespace Processing // struct Uses: Traversal::Uses { - virtual Void + virtual void traverse (Type& u) { SemanticGraph::Schema& s (u.schema ()); @@ -369,7 +370,7 @@ namespace Processing }; } - Void Processor:: + void Processor:: process (SemanticGraph::Schema& tu, SemanticGraph::Path const&) { Traversal::Schema schema; diff --git a/xsd/xsd/processing/cardinality/processor.hxx b/xsd/xsd/processing/cardinality/processor.hxx index 31c6ef8..2b4ebe0 100644 --- a/xsd/xsd/processing/cardinality/processor.hxx +++ b/xsd/xsd/processing/cardinality/processor.hxx @@ -1,28 +1,25 @@ // file : processing/cardinality/processor.hxx -// author : Boris Kolpackov <boris@codesynthesis.com> -// copyright : Copyright (c) 2006-2010 Code Synthesis Tools CC +// copyright : Copyright (c) 2006-2014 Code Synthesis Tools CC // license : GNU GPL v2 + exceptions; see accompanying LICENSE file #ifndef PROCESSING_CARDINALITY_PROCESSOR_HXX #define PROCESSING_CARDINALITY_PROCESSOR_HXX -#include <cult/types.hxx> - #include <xsd-frontend/semantic-graph/elements.hxx> // Path #include <xsd-frontend/semantic-graph/schema.hxx> +#include <types.hxx> + namespace Processing { namespace Cardinality { - using namespace Cult::Types; - class Processor { public: struct Failed {}; - Void + void process (XSDFrontend::SemanticGraph::Schema&, XSDFrontend::SemanticGraph::Path const& file); }; diff --git a/xsd/xsd/processing/inheritance/processor.cxx b/xsd/xsd/processing/inheritance/processor.cxx index d92ea6c..6680a39 100644 --- a/xsd/xsd/processing/inheritance/processor.cxx +++ b/xsd/xsd/processing/inheritance/processor.cxx @@ -1,8 +1,10 @@ // file : processing/inheritance/processor.cxx -// author : Boris Kolpackov <boris@codesynthesis.com> -// copyright : Copyright (c) 2006-2010 Code Synthesis Tools CC +// copyright : Copyright (c) 2006-2014 Code Synthesis Tools CC // license : GNU GPL v2 + exceptions; see accompanying LICENSE file +#include <set> +#include <iostream> + #include <processing/inheritance/processor.hxx> #include <elements.hxx> @@ -10,21 +12,13 @@ #include <xsd-frontend/semantic-graph.hxx> #include <xsd-frontend/traversal.hxx> -#include <cult/containers/set.hxx> - -#include <iostream> -using std::wcerr; -using std::endl; +using namespace std; namespace Processing { - using namespace Cult; - namespace SemanticGraph = XSDFrontend::SemanticGraph; namespace Traversal = XSDFrontend::Traversal; - typedef WideString String; - namespace Inheritance { namespace @@ -43,15 +37,14 @@ namespace Processing String member_xpath; }; - inline Boolean + inline bool operator< (Dep const& a, Dep const& b) { return &a.type < &b.type; } - typedef Containers::Set<Dep> DepSet; - typedef Containers::Set<SemanticGraph::Type*> TypeSet; - + typedef set<Dep> DepSet; + typedef set<SemanticGraph::Type*> TypeSet; String xpath (SemanticGraph::Nameable& n) @@ -88,7 +81,7 @@ namespace Processing *this >> names_ >> *this; } - virtual Void + virtual void traverse (SemanticGraph::Complex& c) { using SemanticGraph::Complex; @@ -103,14 +96,14 @@ namespace Processing names (c); } - virtual Void + virtual void traverse (SemanticGraph::Member& m) { SemanticGraph::Type& t (m.type ()); if (!t.named_p () && types_seen_.find (&t) == types_seen_.end ()) { - FrontendElements::Context& ctx (t.context ()); + SemanticGraph::Context& ctx (t.context ()); last_xpath_ = xpath (m); @@ -158,14 +151,14 @@ namespace Processing } template <typename E> - Void + void add_edge_left (E& e) { node_.add_edge_left (e, arg_); } template <typename E> - Void + void add_edge_right (E& e) { node_.add_edge_right (e, arg_); @@ -185,26 +178,26 @@ namespace Processing { Global (SemanticGraph::Schema& root, SemanticGraph::Schema& schema, - Boolean& failed) + bool& failed) : root_ (root), schema_ (schema), failed_ (failed) { } - virtual Void + virtual void traverse (SemanticGraph::Type& t) { if (t.named_p ()) types_seen_.insert (&t); } - virtual Void + virtual void traverse (SemanticGraph::Complex& c) { check_dep (c, c); types_seen_.insert (&c); }; - virtual Void + virtual void traverse (SemanticGraph::Element& e) { SemanticGraph::Type& t (e.type ()); @@ -218,7 +211,7 @@ namespace Processing }; private: - Void + void check_dep (SemanticGraph::Nameable& global, SemanticGraph::Type& type) { @@ -236,12 +229,19 @@ namespace Processing complex.dispatch (type); } - for (DepSet::ConstIterator i (prereqs.begin ()); + for (DepSet::const_iterator i (prereqs.begin ()); i != prereqs.end (); ++i) { Dep const& dep (*i); Type& t (dep.type); + // Ignore IDREF templates. + // + if (!t.named_p () && + (t.is_a<SemanticGraph::Fundamental::IdRef> () || + t.is_a<SemanticGraph::Fundamental::IdRefs> ())) + continue; + // We won't be able to generate compilable code in case of a // dependency on ourselves (e.g., a member element with // anonymous type that inherits from us). @@ -311,7 +311,6 @@ namespace Processing continue; } - //wcerr << "type '" << t.name () << "' needs to be moved " << // "before " << (global.is_a<Type> () ? "type" : "element") << // " '" << global.name () << "'" << endl; @@ -328,6 +327,11 @@ namespace Processing // Insert a new Names edge before global. // { + // t.scope () and global.scope () can be different in + // case of the chameleon inclusion. + // + Scope& scope (global.scope ()); + // Convert to the insert-after call. // Scope::NamesIterator i (scope.find (global.named ())); @@ -353,7 +357,7 @@ namespace Processing private: // Return true if root sources s. // - Boolean + bool sources_p (SemanticGraph::Schema& root, SemanticGraph::Schema& s) { using SemanticGraph::Schema; @@ -376,40 +380,55 @@ namespace Processing SemanticGraph::Schema& root_; SemanticGraph::Schema& schema_; TypeSet types_seen_; - Boolean& failed_; + bool& failed_; }; + // Sources traverser that goes into each schema only once. + // + struct Sources: Traversal::Sources + { + virtual void + traverse (SemanticGraph::Sources& s) + { + if (schemas_.insert (&s.schema ()).second) + Traversal::Sources::traverse (s); + } + + private: + set<SemanticGraph::Schema*> schemas_; + }; + // Go into included/imported schemas while making sure we don't // process the same stuff more than once. // struct Uses: Traversal::Includes, Traversal::Imports { - Uses (SemanticGraph::Schema& root, Boolean& failed) + Uses (SemanticGraph::Schema& root, bool& failed) : root_ (root), failed_ (failed) { } - virtual Void + virtual void traverse (SemanticGraph::Includes& i) { traverse (i.schema ()); } - virtual Void + virtual void traverse (SemanticGraph::Imports& i) { traverse (i.schema ()); } private: - Void + void traverse (SemanticGraph::Schema& s) { if (!s.context ().count ("processing-inheritance-seen")) { Traversal::Schema schema; - Traversal::Sources sources; + Sources sources; schema >> sources >> schema; schema >> *this; @@ -431,21 +450,21 @@ namespace Processing private: SemanticGraph::Schema& root_; - Boolean& failed_; + bool& failed_; }; } - Void Processor:: + void Processor:: process (SemanticGraph::Schema& tu, SemanticGraph::Path const&) { - Boolean failed (false); + bool failed (false); // We need to process include/imported schemas since other // parts of the process, for example, name processors can // rely on the order of types in the schema. // Traversal::Schema schema; - Traversal::Sources sources; + Sources sources; Uses uses (tu, failed); schema >> sources >> schema; diff --git a/xsd/xsd/processing/inheritance/processor.hxx b/xsd/xsd/processing/inheritance/processor.hxx index aba3b49..46a33c7 100644 --- a/xsd/xsd/processing/inheritance/processor.hxx +++ b/xsd/xsd/processing/inheritance/processor.hxx @@ -1,28 +1,25 @@ // file : processing/inheritance/processor.hxx -// author : Boris Kolpackov <boris@codesynthesis.com> -// copyright : Copyright (c) 2006-2010 Code Synthesis Tools CC +// copyright : Copyright (c) 2006-2014 Code Synthesis Tools CC // license : GNU GPL v2 + exceptions; see accompanying LICENSE file #ifndef PROCESSING_INHERITANCE_PROCESSOR_HXX #define PROCESSING_INHERITANCE_PROCESSOR_HXX -#include <cult/types.hxx> - #include <xsd-frontend/semantic-graph/elements.hxx> // Path #include <xsd-frontend/semantic-graph/schema.hxx> +#include <types.hxx> + namespace Processing { namespace Inheritance { - using namespace Cult::Types; - class Processor { public: struct Failed {}; - Void + void process (XSDFrontend::SemanticGraph::Schema&, XSDFrontend::SemanticGraph::Path const& file); }; |