summaryrefslogtreecommitdiff
path: root/cli/cli/traversal
diff options
context:
space:
mode:
authorKaren Arutyunov <karen@codesynthesis.com>2020-04-08 14:51:57 +0300
committerKaren Arutyunov <karen@codesynthesis.com>2020-04-27 11:38:53 +0300
commit720c5a33b6a49cf328fdd7611f49153cf8f60247 (patch)
tree9725f3d1f42ec90fde84520f49647edea013ce5e /cli/cli/traversal
parent3183f3bb927a90783ae0aeaf190a0919377aabe4 (diff)
Separate tests and examples into individual packages
Also make cli module to be explicitly enabled via the config.cli configuration variable.
Diffstat (limited to 'cli/cli/traversal')
-rw-r--r--cli/cli/traversal/class.cxx49
-rw-r--r--cli/cli/traversal/class.hxx41
-rw-r--r--cli/cli/traversal/doc.hxx16
-rw-r--r--cli/cli/traversal/elements.cxx14
-rw-r--r--cli/cli/traversal/elements.hxx142
-rw-r--r--cli/cli/traversal/expression.hxx16
-rw-r--r--cli/cli/traversal/namespace.cxx26
-rw-r--r--cli/cli/traversal/namespace.hxx26
-rw-r--r--cli/cli/traversal/option.cxx59
-rw-r--r--cli/cli/traversal/option.hxx74
-rw-r--r--cli/cli/traversal/unit.cxx46
-rw-r--r--cli/cli/traversal/unit.hxx58
12 files changed, 567 insertions, 0 deletions
diff --git a/cli/cli/traversal/class.cxx b/cli/cli/traversal/class.cxx
new file mode 100644
index 0000000..b920f1f
--- /dev/null
+++ b/cli/cli/traversal/class.cxx
@@ -0,0 +1,49 @@
+// file : cli/traversal/class.cxx
+// author : Boris Kolpackov <boris@codesynthesis.com>
+// license : MIT; see accompanying LICENSE file
+
+#include <cli/traversal/class.hxx>
+
+namespace traversal
+{
+ // inherits
+ //
+ void inherits::
+ traverse (type& i)
+ {
+ dispatch (i.base ());
+ }
+
+ // class_
+ //
+ void class_::
+ traverse (type& c)
+ {
+ pre (c);
+ inherits (c);
+ names (c);
+ post (c);
+ }
+
+ void class_::
+ inherits (type& c)
+ {
+ inherits (c, *this);
+ }
+
+ void class_::
+ inherits (type& c, edge_dispatcher& d)
+ {
+ iterate_and_dispatch (c.inherits_begin (), c.inherits_end (), d);
+ }
+
+ void class_::
+ pre (type&)
+ {
+ }
+
+ void class_::
+ post (type&)
+ {
+ }
+}
diff --git a/cli/cli/traversal/class.hxx b/cli/cli/traversal/class.hxx
new file mode 100644
index 0000000..38cbefc
--- /dev/null
+++ b/cli/cli/traversal/class.hxx
@@ -0,0 +1,41 @@
+// file : cli/traversal/class.hxx
+// author : Boris Kolpackov <boris@codesynthesis.com>
+// license : MIT; see accompanying LICENSE file
+
+#ifndef CLI_TRAVERSAL_CLASS_HXX
+#define CLI_TRAVERSAL_CLASS_HXX
+
+#include <cli/traversal/elements.hxx>
+#include <cli/semantics/class.hxx>
+
+namespace traversal
+{
+ struct inherits: edge<semantics::inherits>
+ {
+ inherits () {}
+ inherits (node_dispatcher& n) {node_traverser (n);}
+
+ virtual void
+ traverse (type&);
+ };
+
+ struct class_: scope_template<semantics::class_>
+ {
+ virtual void
+ traverse (type&);
+
+ virtual void
+ pre (type&);
+
+ virtual void
+ inherits (type&);
+
+ virtual void
+ inherits (type&, edge_dispatcher&);
+
+ virtual void
+ post (type&);
+ };
+}
+
+#endif // CLI_TRAVERSAL_CLASS_HXX
diff --git a/cli/cli/traversal/doc.hxx b/cli/cli/traversal/doc.hxx
new file mode 100644
index 0000000..70a6dfd
--- /dev/null
+++ b/cli/cli/traversal/doc.hxx
@@ -0,0 +1,16 @@
+// file : cli/traversal/doc.hxx
+// author : Boris Kolpackov <boris@codesynthesis.com>
+// license : MIT; see accompanying LICENSE file
+
+#ifndef CLI_TRAVERSAL_DOC_HXX
+#define CLI_TRAVERSAL_DOC_HXX
+
+#include <cli/traversal/elements.hxx>
+#include <cli/semantics/doc.hxx>
+
+namespace traversal
+{
+ struct doc: node<semantics::doc> {};
+}
+
+#endif // CLI_TRAVERSAL_DOC_HXX
diff --git a/cli/cli/traversal/elements.cxx b/cli/cli/traversal/elements.cxx
new file mode 100644
index 0000000..f3353f2
--- /dev/null
+++ b/cli/cli/traversal/elements.cxx
@@ -0,0 +1,14 @@
+// file : cli/traversal/elements.cxx
+// author : Boris Kolpackov <boris@codesynthesis.com>
+// license : MIT; see accompanying LICENSE file
+
+#include <cli/traversal/elements.hxx>
+
+namespace traversal
+{
+ void names::
+ traverse (type& e)
+ {
+ dispatch (e.named ());
+ }
+}
diff --git a/cli/cli/traversal/elements.hxx b/cli/cli/traversal/elements.hxx
new file mode 100644
index 0000000..a2ada23
--- /dev/null
+++ b/cli/cli/traversal/elements.hxx
@@ -0,0 +1,142 @@
+// file : cli/traversal/elements.hxx
+// author : Boris Kolpackov <boris@codesynthesis.com>
+// license : MIT; see accompanying LICENSE file
+
+#ifndef CLI_TRAVERSAL_ELEMENTS_HXX
+#define CLI_TRAVERSAL_ELEMENTS_HXX
+
+#include <cutl/compiler/traversal.hxx>
+
+#include <cli/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)
+ {
+ this->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/cli/traversal/expression.hxx b/cli/cli/traversal/expression.hxx
new file mode 100644
index 0000000..0888455
--- /dev/null
+++ b/cli/cli/traversal/expression.hxx
@@ -0,0 +1,16 @@
+// file : cli/traversal/expression.hxx
+// author : Boris Kolpackov <boris@codesynthesis.com>
+// license : MIT; see accompanying LICENSE file
+
+#ifndef CLI_TRAVERSAL_EXPRESSION_HXX
+#define CLI_TRAVERSAL_EXPRESSION_HXX
+
+#include <cli/traversal/elements.hxx>
+#include <cli/semantics/expression.hxx>
+
+namespace traversal
+{
+ struct expression: node<semantics::expression> {};
+}
+
+#endif // CLI_TRAVERSAL_EXPRESSION_HXX
diff --git a/cli/cli/traversal/namespace.cxx b/cli/cli/traversal/namespace.cxx
new file mode 100644
index 0000000..c938f77
--- /dev/null
+++ b/cli/cli/traversal/namespace.cxx
@@ -0,0 +1,26 @@
+// file : cli/traversal/namespace.cxx
+// author : Boris Kolpackov <boris@codesynthesis.com>
+// license : MIT; see accompanying LICENSE file
+
+#include <cli/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/cli/traversal/namespace.hxx b/cli/cli/traversal/namespace.hxx
new file mode 100644
index 0000000..5709f2a
--- /dev/null
+++ b/cli/cli/traversal/namespace.hxx
@@ -0,0 +1,26 @@
+// file : cli/traversal/namespace.hxx
+// author : Boris Kolpackov <boris@codesynthesis.com>
+// license : MIT; see accompanying LICENSE file
+
+#ifndef CLI_TRAVERSAL_NAMESPACE_HXX
+#define CLI_TRAVERSAL_NAMESPACE_HXX
+
+#include <cli/traversal/elements.hxx>
+#include <cli/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/cli/traversal/option.cxx b/cli/cli/traversal/option.cxx
new file mode 100644
index 0000000..ff5dcce
--- /dev/null
+++ b/cli/cli/traversal/option.cxx
@@ -0,0 +1,59 @@
+// file : cli/traversal/option.cxx
+// author : Boris Kolpackov <boris@codesynthesis.com>
+// license : MIT; see accompanying LICENSE file
+
+#include <cli/traversal/option.hxx>
+#include <cli/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/cli/traversal/option.hxx b/cli/cli/traversal/option.hxx
new file mode 100644
index 0000000..e11fa21
--- /dev/null
+++ b/cli/cli/traversal/option.hxx
@@ -0,0 +1,74 @@
+// file : cli/traversal/option.hxx
+// author : Boris Kolpackov <boris@codesynthesis.com>
+// license : MIT; see accompanying LICENSE file
+
+#ifndef CLI_TRAVERSAL_OPTION_HXX
+#define CLI_TRAVERSAL_OPTION_HXX
+
+#include <cli/traversal/elements.hxx>
+#include <cli/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/cli/traversal/unit.cxx b/cli/cli/traversal/unit.cxx
new file mode 100644
index 0000000..cf10d1d
--- /dev/null
+++ b/cli/cli/traversal/unit.cxx
@@ -0,0 +1,46 @@
+// file : cli/traversal/unit.cxx
+// author : Boris Kolpackov <boris@codesynthesis.com>
+// license : MIT; see accompanying LICENSE file
+
+#include <cli/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/cli/traversal/unit.hxx b/cli/cli/traversal/unit.hxx
new file mode 100644
index 0000000..eab42aa
--- /dev/null
+++ b/cli/cli/traversal/unit.hxx
@@ -0,0 +1,58 @@
+// file : cli/traversal/unit.hxx
+// author : Boris Kolpackov <boris@codesynthesis.com>
+// license : MIT; see accompanying LICENSE file
+
+#ifndef CLI_TRAVERSAL_UNIT_HXX
+#define CLI_TRAVERSAL_UNIT_HXX
+
+#include <cli/traversal/elements.hxx>
+#include <cli/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