aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2012-12-19 10:41:09 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2012-12-19 10:41:09 +0200
commit3c55d0d6934cb037a5fb2b5729b6603d8b7ca7e5 (patch)
tree51ffef8b67ef2bd276854b6ce128584198ba777a
parent0e7a03c98185396928dd36715567f7727a8f1c9b (diff)
Add generator that returns list of included/imported schemas
-rw-r--r--xsd-frontend/generators/dependencies.cxx71
-rw-r--r--xsd-frontend/generators/dependencies.hxx33
-rw-r--r--xsd-frontend/makefile2
3 files changed, 106 insertions, 0 deletions
diff --git a/xsd-frontend/generators/dependencies.cxx b/xsd-frontend/generators/dependencies.cxx
new file mode 100644
index 0000000..e618d4f
--- /dev/null
+++ b/xsd-frontend/generators/dependencies.cxx
@@ -0,0 +1,71 @@
+// file : xsd-frontend/generators/dependencies.cxx
+// author : Boris Kolpackov <boris@codesynthesis.com>
+// copyright : Copyright (c) 2006-2011 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;
+ }
+ }
+}
diff --git a/xsd-frontend/generators/dependencies.hxx b/xsd-frontend/generators/dependencies.hxx
new file mode 100644
index 0000000..762ee42
--- /dev/null
+++ b/xsd-frontend/generators/dependencies.hxx
@@ -0,0 +1,33 @@
+// file : xsd-frontend/generators/dependencies.hxx
+// author : Boris Kolpackov <boris@codesynthesis.com>
+// copyright : Copyright (c) 2006-2011 Code Synthesis Tools CC
+// license : GNU GPL v2 + exceptions; see accompanying LICENSE file
+
+#ifndef XSD_FRONTEND_GENERATORS_DEPENDENCIES_HXX
+#define XSD_FRONTEND_GENERATORS_DEPENDENCIES_HXX
+
+#include <vector>
+
+#include <xsd-frontend/types.hxx>
+
+#include <xsd-frontend/semantic-graph/elements.hxx> // Path
+#include <xsd-frontend/semantic-graph/schema.hxx>
+
+namespace XSDFrontend
+{
+ namespace Generators
+ {
+ // Return the list of included/imported schema paths (transitively and
+ // including the main schema file) which can then be used to produce
+ // make dependencies, etc.
+ //
+ class Dependencies
+ {
+ public:
+ std::vector<SemanticGraph::Path>
+ generate (SemanticGraph::Schema&, SemanticGraph::Path const&);
+ };
+ }
+}
+
+#endif // XSD_FRONTEND_GENERATORS_DEPENDENCIES_HXX
diff --git a/xsd-frontend/makefile b/xsd-frontend/makefile
index 68b427a..51ce8f2 100644
--- a/xsd-frontend/makefile
+++ b/xsd-frontend/makefile
@@ -44,6 +44,8 @@ cxx_tun += transformations/anonymous.cxx \
transformations/schema-per-type.cxx \
transformations/simplifier.cxx
+cxx_tun += generators/dependencies.cxx
+
cxx_tun += types.cxx parser.cxx schema-dom-parser.cxx