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/processing/inheritance/processor.cxx | |
parent | a15cf65c44d5c224169c32ef5495b68c758134b7 (diff) |
Imported Upstream version 4.0.0upstream/4.0.0
Diffstat (limited to 'xsd/xsd/processing/inheritance/processor.cxx')
-rw-r--r-- | xsd/xsd/processing/inheritance/processor.cxx | 95 |
1 files changed, 57 insertions, 38 deletions
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; |