summaryrefslogtreecommitdiff
path: root/cli/traversal
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2009-09-05 16:29:23 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2009-09-05 16:29:23 +0200
commit4974b4763bd60eb875f93a71dbe2fe82ecfed9fc (patch)
tree9353fb3fec3fa5f77f1faaf6da8185e3d006e7ba /cli/traversal
parente2299f6d95ba3264072d6ddc49f153ad73fd9d24 (diff)
Add semantic graph and traversal mechanism
The parser now builds the semantic graph.
Diffstat (limited to 'cli/traversal')
-rw-r--r--cli/traversal/class.cxx27
-rw-r--r--cli/traversal/class.hxx27
-rw-r--r--cli/traversal/elements.cxx15
-rw-r--r--cli/traversal/elements.hxx143
-rw-r--r--cli/traversal/expression.hxx17
-rw-r--r--cli/traversal/namespace.cxx27
-rw-r--r--cli/traversal/namespace.hxx27
-rw-r--r--cli/traversal/option.cxx60
-rw-r--r--cli/traversal/option.hxx75
-rw-r--r--cli/traversal/unit.cxx47
-rw-r--r--cli/traversal/unit.hxx59
11 files changed, 524 insertions, 0 deletions
diff --git a/cli/traversal/class.cxx b/cli/traversal/class.cxx
new file mode 100644
index 0000000..54af3e1
--- /dev/null
+++ b/cli/traversal/class.cxx
@@ -0,0 +1,27 @@
+// file : cli/traversal/class.cxx
+// author : Boris Kolpackov <boris@codesynthesis.com>
+// copyright : Copyright (c) 2009 Code Synthesis Tools CC
+// license : MIT; see accompanying LICENSE file
+
+#include <traversal/class.hxx>
+
+namespace traversal
+{
+ void class_::
+ traverse (type& c)
+ {
+ pre (c);
+ names (c);
+ post (c);
+ }
+
+ void class_::
+ pre (type&)
+ {
+ }
+
+ void class_::
+ post (type&)
+ {
+ }
+}
diff --git a/cli/traversal/class.hxx b/cli/traversal/class.hxx
new file mode 100644
index 0000000..d4610d9
--- /dev/null
+++ b/cli/traversal/class.hxx
@@ -0,0 +1,27 @@
+// file : cli/traversal/class.hxx
+// author : Boris Kolpackov <boris@codesynthesis.com>
+// copyright : Copyright (c) 2009 Code Synthesis Tools CC
+// license : MIT; see accompanying LICENSE file
+
+#ifndef CLI_TRAVERSAL_CLASS_HXX
+#define CLI_TRAVERSAL_CLASS_HXX
+
+#include <traversal/elements.hxx>
+#include <semantics/class.hxx>
+
+namespace traversal
+{
+ struct class_: scope_template<semantics::class_>
+ {
+ virtual void
+ traverse (type&);
+
+ virtual void
+ pre (type&);
+
+ virtual void
+ post (type&);
+ };
+}
+
+#endif // CLI_TRAVERSAL_CLASS_HXX
diff --git a/cli/traversal/elements.cxx b/cli/traversal/elements.cxx
new file mode 100644
index 0000000..acabc3c
--- /dev/null
+++ b/cli/traversal/elements.cxx
@@ -0,0 +1,15 @@
+// file : cli/traversal/elements.cxx
+// author : Boris Kolpackov <boris@codesynthesis.com>
+// copyright : Copyright (c) 2009 Code Synthesis Tools CC
+// license : MIT; see accompanying LICENSE file
+
+#include <traversal/elements.hxx>
+
+namespace traversal
+{
+ void names::
+ traverse (type& e)
+ {
+ dispatch (e.named ());
+ }
+}
diff --git a/cli/traversal/elements.hxx b/cli/traversal/elements.hxx
new file mode 100644
index 0000000..ac57af4
--- /dev/null
+++ b/cli/traversal/elements.hxx
@@ -0,0 +1,143 @@
+// file : cli/traversal/elements.hxx
+// author : Boris Kolpackov <boris@codesynthesis.com>
+// copyright : Copyright (c) 2009 Code Synthesis Tools CC
+// license : MIT; see accompanying LICENSE file
+
+#ifndef CLI_TRAVERSAL_ELEMENTS_HXX
+#define CLI_TRAVERSAL_ELEMENTS_HXX
+
+#include <cutl/compiler/traversal.hxx>
+
+#include <semantics/elements.hxx>
+
+namespace traversal
+{
+ using namespace cutl;
+
+ //
+ //
+ typedef compiler::dispatcher<semantics::node> node_dispatcher;
+ typedef compiler::dispatcher<semantics::edge> edge_dispatcher;
+
+ //
+ //
+ struct node_base: node_dispatcher, edge_dispatcher
+ {
+ void
+ edge_traverser (edge_dispatcher& d)
+ {
+ edge_dispatcher::traverser (d);
+ }
+
+ edge_dispatcher&
+ edge_traverser ()
+ {
+ return *this;
+ }
+
+ using node_dispatcher::dispatch;
+ using edge_dispatcher::dispatch;
+
+ using edge_dispatcher::iterate_and_dispatch;
+ };
+
+ struct edge_base: edge_dispatcher, node_dispatcher
+ {
+ void
+ node_traverser (node_dispatcher& d)
+ {
+ node_dispatcher::traverser (d);
+ }
+
+ node_dispatcher&
+ node_traverser ()
+ {
+ return *this;
+ }
+
+ using edge_dispatcher::dispatch;
+ using node_dispatcher::dispatch;
+
+ using node_dispatcher::iterate_and_dispatch;
+ };
+
+ inline edge_base&
+ operator>> (node_base& n, edge_base& e)
+ {
+ n.edge_traverser (e);
+ return e;
+ }
+
+ inline node_base&
+ operator>> (edge_base& e, node_base& n)
+ {
+ e.node_traverser (n);
+ return n;
+ }
+
+ //
+ //
+ template <typename X>
+ struct node: compiler::traverser_impl<X, semantics::node>,
+ virtual node_base
+ {
+ };
+
+ template <typename X>
+ struct edge: compiler::traverser_impl<X, semantics::edge>,
+ virtual edge_base
+ {
+ };
+
+ // Edges
+ //
+
+ struct names: edge<semantics::names>
+ {
+ names ()
+ {
+ }
+
+ names (node_dispatcher& n)
+ {
+ node_traverser (n);
+ }
+
+ virtual void
+ traverse (type&);
+ };
+
+ // Nodes
+ //
+
+ struct nameable: node<semantics::nameable> {};
+
+ template <typename T>
+ struct scope_template: node<T>
+ {
+ public:
+ virtual void
+ traverse (T& s)
+ {
+ names (s);
+ }
+
+ virtual void
+ names (T& s)
+ {
+ names (s, *this);
+ }
+
+ virtual void
+ names (T& s, edge_dispatcher& d)
+ {
+ iterate_and_dispatch (s.names_begin (), s.names_end (), d);
+ }
+ };
+
+ typedef scope_template<semantics::scope> scope;
+
+ struct type: node<semantics::type> {};
+}
+
+#endif // CLI_TRAVERSAL_ELEMENTS_HXX
diff --git a/cli/traversal/expression.hxx b/cli/traversal/expression.hxx
new file mode 100644
index 0000000..71d9f6e
--- /dev/null
+++ b/cli/traversal/expression.hxx
@@ -0,0 +1,17 @@
+// file : cli/traversal/expression.hxx
+// author : Boris Kolpackov <boris@codesynthesis.com>
+// copyright : Copyright (c) 2009 Code Synthesis Tools CC
+// license : MIT; see accompanying LICENSE file
+
+#ifndef CLI_TRAVERSAL_EXPRESSION_HXX
+#define CLI_TRAVERSAL_EXPRESSION_HXX
+
+#include <traversal/elements.hxx>
+#include <semantics/expression.hxx>
+
+namespace traversal
+{
+ struct expression: node<semantics::expression> {};
+}
+
+#endif // CLI_TRAVERSAL_EXPRESSION_HXX
diff --git a/cli/traversal/namespace.cxx b/cli/traversal/namespace.cxx
new file mode 100644
index 0000000..47547db
--- /dev/null
+++ b/cli/traversal/namespace.cxx
@@ -0,0 +1,27 @@
+// file : cli/traversal/namespace.cxx
+// author : Boris Kolpackov <boris@codesynthesis.com>
+// copyright : Copyright (c) 2009 Code Synthesis Tools CC
+// license : MIT; see accompanying LICENSE file
+
+#include <traversal/namespace.hxx>
+
+namespace traversal
+{
+ void namespace_::
+ traverse (type& n)
+ {
+ pre (n);
+ names (n);
+ post (n);
+ }
+
+ void namespace_::
+ pre (type&)
+ {
+ }
+
+ void namespace_::
+ post (type&)
+ {
+ }
+}
diff --git a/cli/traversal/namespace.hxx b/cli/traversal/namespace.hxx
new file mode 100644
index 0000000..5903582
--- /dev/null
+++ b/cli/traversal/namespace.hxx
@@ -0,0 +1,27 @@
+// file : cli/traversal/namespace.hxx
+// author : Boris Kolpackov <boris@codesynthesis.com>
+// copyright : Copyright (c) 2009 Code Synthesis Tools CC
+// license : MIT; see accompanying LICENSE file
+
+#ifndef CLI_TRAVERSAL_NAMESPACE_HXX
+#define CLI_TRAVERSAL_NAMESPACE_HXX
+
+#include <traversal/elements.hxx>
+#include <semantics/namespace.hxx>
+
+namespace traversal
+{
+ struct namespace_: scope_template<semantics::namespace_>
+ {
+ virtual void
+ traverse (type&);
+
+ virtual void
+ pre (type&);
+
+ virtual void
+ post (type&);
+ };
+}
+
+#endif // CLI_TRAVERSAL_NAMESPACE_HXX
diff --git a/cli/traversal/option.cxx b/cli/traversal/option.cxx
new file mode 100644
index 0000000..64e728c
--- /dev/null
+++ b/cli/traversal/option.cxx
@@ -0,0 +1,60 @@
+// file : cli/traversal/option.cxx
+// author : Boris Kolpackov <boris@codesynthesis.com>
+// copyright : Copyright (c) 2009 Code Synthesis Tools CC
+// license : MIT; see accompanying LICENSE file
+
+#include <traversal/option.hxx>
+#include <traversal/expression.hxx>
+
+namespace traversal
+{
+ // belongs
+ //
+ void belongs::
+ traverse (type& e)
+ {
+ dispatch (e.type ());
+ }
+
+ // initialized
+ //
+ void initialized::
+ traverse (type& e)
+ {
+ dispatch (e.expression ());
+ }
+
+ // option
+ //
+ void option::
+ traverse (type& o)
+ {
+ pre (o);
+ belongs (o);
+ if (o.initialized_p ())
+ initialized (o);
+ post (o);
+ }
+
+ void option::
+ pre (type&)
+ {
+ }
+
+ void option::
+ belongs (type& o)
+ {
+ belongs (o, edge_traverser ());
+ }
+
+ void option::
+ initialized (type& o)
+ {
+ initialized (o, edge_traverser ());
+ }
+
+ void option::
+ post (type&)
+ {
+ }
+}
diff --git a/cli/traversal/option.hxx b/cli/traversal/option.hxx
new file mode 100644
index 0000000..4ff2a58
--- /dev/null
+++ b/cli/traversal/option.hxx
@@ -0,0 +1,75 @@
+// file : cli/traversal/option.hxx
+// author : Boris Kolpackov <boris@codesynthesis.com>
+// copyright : Copyright (c) 2009 Code Synthesis Tools CC
+// license : MIT; see accompanying LICENSE file
+
+#ifndef CLI_TRAVERSAL_OPTION_HXX
+#define CLI_TRAVERSAL_OPTION_HXX
+
+#include <traversal/elements.hxx>
+#include <semantics/option.hxx>
+
+namespace traversal
+{
+ struct belongs: edge<semantics::belongs>
+ {
+ belongs ()
+ {
+ }
+
+ belongs (node_dispatcher& n)
+ {
+ node_traverser (n);
+ }
+
+ virtual void
+ traverse (type&);
+ };
+
+ struct initialized: edge<semantics::initialized>
+ {
+ initialized ()
+ {
+ }
+
+ initialized (node_dispatcher& n)
+ {
+ node_traverser (n);
+ }
+
+ virtual void
+ traverse (type&);
+ };
+
+ struct option: node<semantics::option>
+ {
+ virtual void
+ traverse (type&);
+
+ virtual void
+ pre (type&);
+
+ virtual void
+ belongs (type&);
+
+ virtual void
+ initialized (type&);
+
+ virtual void
+ post (type&);
+
+ void
+ belongs (type& o, edge_dispatcher& d)
+ {
+ d.dispatch (o.belongs ());
+ }
+
+ void
+ initialized (type& o, edge_dispatcher& d)
+ {
+ d.dispatch (o.initialized ());
+ }
+ };
+}
+
+#endif // CLI_TRAVERSAL_OPTION_HXX
diff --git a/cli/traversal/unit.cxx b/cli/traversal/unit.cxx
new file mode 100644
index 0000000..32b2e0d
--- /dev/null
+++ b/cli/traversal/unit.cxx
@@ -0,0 +1,47 @@
+// file : cli/traversal/unit.cxx
+// author : Boris Kolpackov <boris@codesynthesis.com>
+// copyright : Copyright (c) 2009 Code Synthesis Tools CC
+// license : MIT; see accompanying LICENSE file
+
+#include <traversal/unit.hxx>
+
+namespace traversal
+{
+ // cxx_includes
+ //
+ void cxx_includes::
+ traverse (type& e)
+ {
+ dispatch (e.includee ());
+ }
+
+ // cli_includes
+ //
+ void cli_includes::
+ traverse (type& e)
+ {
+ dispatch (e.includee ());
+ }
+
+ // cli_unit
+ //
+ void cli_unit::
+ traverse (type& u)
+ {
+ pre (u);
+ iterate_and_dispatch (
+ u.includes_begin (), u.includes_end (), edge_traverser ());
+ names (u);
+ post (u);
+ }
+
+ void cli_unit::
+ pre (type&)
+ {
+ }
+
+ void cli_unit::
+ post (type&)
+ {
+ }
+}
diff --git a/cli/traversal/unit.hxx b/cli/traversal/unit.hxx
new file mode 100644
index 0000000..25ec556
--- /dev/null
+++ b/cli/traversal/unit.hxx
@@ -0,0 +1,59 @@
+// file : cli/traversal/unit.hxx
+// author : Boris Kolpackov <boris@codesynthesis.com>
+// copyright : Copyright (c) 2009 Code Synthesis Tools CC
+// license : MIT; see accompanying LICENSE file
+
+#ifndef CLI_TRAVERSAL_UNIT_HXX
+#define CLI_TRAVERSAL_UNIT_HXX
+
+#include <traversal/elements.hxx>
+#include <semantics/unit.hxx>
+
+namespace traversal
+{
+ struct cxx_includes: edge<semantics::cxx_includes>
+ {
+ cxx_includes ()
+ {
+ }
+
+ cxx_includes (node_dispatcher& n)
+ {
+ node_traverser (n);
+ }
+
+ virtual void
+ traverse (type&);
+ };
+
+ struct cli_includes: edge<semantics::cli_includes>
+ {
+ cli_includes ()
+ {
+ }
+
+ cli_includes (node_dispatcher& n)
+ {
+ node_traverser (n);
+ }
+
+ virtual void
+ traverse (type&);
+ };
+
+ struct cxx_unit: node<semantics::cxx_unit> {};
+
+ struct cli_unit: scope_template<semantics::cli_unit>
+ {
+ virtual void
+ traverse (type&);
+
+ virtual void
+ pre (type&);
+
+ virtual void
+ post (type&);
+ };
+}
+
+#endif // CLI_TRAVERSAL_UNIT_HXX