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 /libxsd-frontend/xsd-frontend/generators/dependencies.cxx | |
parent | a15cf65c44d5c224169c32ef5495b68c758134b7 (diff) |
Imported Upstream version 4.0.0upstream/4.0.0
Diffstat (limited to 'libxsd-frontend/xsd-frontend/generators/dependencies.cxx')
-rw-r--r-- | libxsd-frontend/xsd-frontend/generators/dependencies.cxx | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/libxsd-frontend/xsd-frontend/generators/dependencies.cxx b/libxsd-frontend/xsd-frontend/generators/dependencies.cxx new file mode 100644 index 0000000..55e7ae8 --- /dev/null +++ b/libxsd-frontend/xsd-frontend/generators/dependencies.cxx @@ -0,0 +1,70 @@ +// file : xsd-frontend/generators/dependencies.cxx +// copyright : Copyright (c) 2006-2014 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <xsd-frontend/semantic-graph.hxx> +#include <xsd-frontend/traversal.hxx> + +#include <xsd-frontend/generators/dependencies.hxx> + +namespace XSDFrontend +{ + typedef std::vector<SemanticGraph::Path> Paths; + + namespace + { + // Go into included/imported (but not implied) schemas while making + // sure we don't process the same stuff more than once. + // + struct Uses: Traversal::Uses + { + Uses (Paths& p): paths_ (p) {} + + virtual void + traverse (Type& u) + { + if (u.is_a<SemanticGraph::Implies> ()) + return; + + SemanticGraph::Schema& s (u.schema ()); + + if (!s.context ().count ("xsd-frontend-dependencies-seen")) + { + s.context ().set ("xsd-frontend-dependencies-seen", true); + + // While the edge contains the exact path that was found in the + // schema, the schema node itself has the reative to the including + // or importing schema path, which is what we want. + // + paths_.push_back (s.file ()); + Traversal::Uses::traverse (u); + } + } + + private: + Paths& paths_; + }; + } + + namespace Generators + { + Paths Dependencies:: + generate (SemanticGraph::Schema& s, SemanticGraph::Path const& p) + { + Paths r; + r.push_back (p); + + Traversal::Schema schema; + Uses uses (r); + + schema >> uses >> schema; + + // Some twisted schemas do recusive inclusions. + // + s.context ().set ("xsd-frontend-dependencies-seen", true); + + schema.dispatch (s); + return r; + } + } +} |