summaryrefslogtreecommitdiff
path: root/contrib/utility/Example/Introspection/Traversal
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/utility/Example/Introspection/Traversal')
-rw-r--r--contrib/utility/Example/Introspection/Traversal/Makefile22
-rw-r--r--contrib/utility/Example/Introspection/Traversal/SyntaxTree.cpp119
-rw-r--r--contrib/utility/Example/Introspection/Traversal/SyntaxTree.hpp95
-rw-r--r--contrib/utility/Example/Introspection/Traversal/Traversal.cpp105
-rw-r--r--contrib/utility/Example/Introspection/Traversal/Traversal.hpp157
-rw-r--r--contrib/utility/Example/Introspection/Traversal/driver.cpp91
6 files changed, 0 insertions, 589 deletions
diff --git a/contrib/utility/Example/Introspection/Traversal/Makefile b/contrib/utility/Example/Introspection/Traversal/Makefile
deleted file mode 100644
index c9b1a8da46a..00000000000
--- a/contrib/utility/Example/Introspection/Traversal/Makefile
+++ /dev/null
@@ -1,22 +0,0 @@
-# file : Example/Introspection/Traversal/Makefile
-# author : Boris Kolpackov <boris@kolpackov.net>
-# copyright : Copyright (c) 2002-2003 Boris Kolpackov
-# license : http://kolpackov.net/license.html
-
-root := ../../..
-
-include $(root)/BuildRules/Bootstrap.rules
-
-$(call include, $(root)/BuildRules/Executable.pre.rules)
-
-
-cxx_translation_units := SyntaxTree.cpp Traversal.cpp driver.cpp
-
-module_base := driver
-
-CXX_PREPROCESS_FLAGS += -I $(root)
-
-CXX_LINK_LIBS += -L$(root)/Utility/Introspection -lIntrospection
-
-$(call include, $(root)/BuildRules/Executable.post.rules)
-# $Id$
diff --git a/contrib/utility/Example/Introspection/Traversal/SyntaxTree.cpp b/contrib/utility/Example/Introspection/Traversal/SyntaxTree.cpp
deleted file mode 100644
index 71115ff2b24..00000000000
--- a/contrib/utility/Example/Introspection/Traversal/SyntaxTree.cpp
+++ /dev/null
@@ -1,119 +0,0 @@
-// file : Example/Introspection/Traversal/SyntaxTree.cpp
-// author : Boris Kolpackov <boris@kolpackov.net>
-// copyright : Copyright (c) 2002-2003 Boris Kolpackov
-// license : http://kolpackov.net/license.html
-
-#include "SyntaxTree.hpp"
-
-using namespace Utility::Introspection;
-
-namespace SyntaxTree
-{
-
- // Node
- //
- //
-
- namespace
- {
- TypeInfo
- node_init_ ()
- {
- TypeInfo ti (typeid (Node));
- ti.add_base (Access::PUBLIC, true, Object::static_type_info ());
- return ti;
- }
-
- TypeInfo node_ (node_init_ ());
- }
-
- TypeInfo const& Node::
- static_type_info () { return node_; }
-
-
- // Declaration
- //
- //
-
- namespace
- {
- TypeInfo
- declaration_init_ ()
- {
- TypeInfo ti (typeid (Declaration));
- ti.add_base (Access::PUBLIC, true, Node::static_type_info ());
- return ti;
- }
-
- TypeInfo declaration_ (declaration_init_ ());
- }
-
- TypeInfo const& Declaration::
- static_type_info () { return declaration_; }
-
-
- // Scope
- //
- //
-
- namespace
- {
- TypeInfo
- scope_init_ ()
- {
- TypeInfo ti (typeid (Scope));
- ti.add_base (Access::PUBLIC, true, Declaration::static_type_info ());
- return ti;
- }
-
- TypeInfo scope_ (scope_init_ ());
- }
-
- TypeInfo const& Scope::
- static_type_info () { return scope_; }
-
-
- // InterfaceDecl
- //
- //
-
- namespace
- {
- TypeInfo
- interface_decl_init_ ()
- {
- TypeInfo ti (typeid (InterfaceDecl));
- ti.add_base (Access::PUBLIC, true, Declaration::static_type_info ());
- return ti;
- }
-
- TypeInfo interface_decl_ (interface_decl_init_ ());
- }
-
- TypeInfo const& InterfaceDecl::
- static_type_info () { return interface_decl_; }
-
-
- // InterfaceDef
- //
- //
-
- namespace
- {
- TypeInfo
- interface_def_init_ ()
- {
- TypeInfo ti (typeid (InterfaceDef));
- ti.add_base (Access::PUBLIC, true, InterfaceDecl::static_type_info ());
- ti.add_base (Access::PUBLIC, true, Scope::static_type_info ());
- return ti;
- }
-
- TypeInfo interface_def_ (interface_def_init_ ());
- }
-
- TypeInfo const& InterfaceDef::
- static_type_info () { return interface_def_; }
-
-}
-//$Id$
diff --git a/contrib/utility/Example/Introspection/Traversal/SyntaxTree.hpp b/contrib/utility/Example/Introspection/Traversal/SyntaxTree.hpp
deleted file mode 100644
index 7bd824ce683..00000000000
--- a/contrib/utility/Example/Introspection/Traversal/SyntaxTree.hpp
+++ /dev/null
@@ -1,95 +0,0 @@
-// file : Example/Introspection/Traversal/SyntaxTree.hpp
-// author : Boris Kolpackov <boris@kolpackov.net>
-// copyright : Copyright (c) 2002-2003 Boris Kolpackov
-// license : http://kolpackov.net/license.html
-
-#ifndef SYNTAX_TREE_HPP
-#define SYNTAX_TREE_HPP
-
-#include <vector>
-
-#include "Utility/Introspection/Introspection.hpp"
-
-namespace SyntaxTree
-{
- //
- //
- //
-
- struct Node : virtual Utility::Introspection::Object
- {
- Node ()
- {
- type_info (static_type_info ());
- }
-
- static Utility::Introspection::TypeInfo const&
- static_type_info ();
- };
-
- //
- //
- //
-
- struct Declaration : virtual Node
- {
- Declaration ()
- {
- type_info (static_type_info ());
- }
-
- static Utility::Introspection::TypeInfo const&
- static_type_info ();
- };
-
- typedef
- std::vector<Declaration*>
- DeclarationList;
-
- //
- //
- //
- struct Scope : virtual Declaration
- {
- Scope ()
- {
- type_info (static_type_info ());
- }
-
- static Utility::Introspection::TypeInfo const&
- static_type_info ();
-
- DeclarationList content_;
- };
-
- //
- //
- //
- struct InterfaceDecl : virtual Declaration
- {
- InterfaceDecl ()
- {
- type_info (static_type_info ());
- }
-
- static Utility::Introspection::TypeInfo const&
- static_type_info ();
- };
-
- //
- //
- //
- struct InterfaceDef : virtual InterfaceDecl, virtual Scope
- {
- InterfaceDef ()
- {
- type_info (static_type_info ());
- }
-
- static Utility::Introspection::TypeInfo const&
- static_type_info ();
- };
-}
-
-#endif // SYNTAX_TREE_HPP
-//$Id$
diff --git a/contrib/utility/Example/Introspection/Traversal/Traversal.cpp b/contrib/utility/Example/Introspection/Traversal/Traversal.cpp
deleted file mode 100644
index 9fa94327c2c..00000000000
--- a/contrib/utility/Example/Introspection/Traversal/Traversal.cpp
+++ /dev/null
@@ -1,105 +0,0 @@
-// file : Example/Introspection/Traversal/Traversal.cpp
-// author : Boris Kolpackov <boris@kolpackov.net>
-// copyright : Copyright (c) 2002-2003 Boris Kolpackov
-// license : http://kolpackov.net/license.html
-
-#include "Traversal.hpp"
-
-#include <set>
-#include <map>
-
-using namespace Utility::Introspection;
-
-namespace Traversal
-{
- // Dispatcher
- //
- //
-
- struct TypeInfoComparator
- {
- bool
- operator () (TypeInfo const& x, TypeInfo const& y) const
- {
- return x.type_id () < y.type_id ();
- }
- };
-
- typedef
- std::map<TypeInfo, unsigned long, TypeInfoComparator>
- LevelMap;
-
- typedef
- std::set<TypeInfo, TypeInfoComparator>
- TypeInfoSet;
-
- unsigned long
- compute_levels (TypeInfo const& ti, unsigned long cur, LevelMap& map)
- {
- unsigned long ret = cur;
-
- if (map.find (ti) == map.end () || map[ti] < cur) map[ti] = cur;
-
- for (TypeInfo::BaseIterator i = ti.begin_base ();
- i != ti.end_base ();
- i++)
- {
- unsigned long t = compute_levels (i->type_info (), cur + 1, map);
- if (t > ret) ret = t;
- }
-
- return ret;
- }
-
- void
- flatten_tree (TypeInfo const& ti, TypeInfoSet& set)
- {
- set.insert (ti);
-
- for (TypeInfo::BaseIterator i = ti.begin_base ();
- i != ti.end_base ();
- i++)
- {
- flatten_tree (i->type_info (), set);
- }
- }
-
- void Dispatcher::
- dispatch (SyntaxTree::Node* n)
- {
- LevelMap levels;
-
- unsigned long max = compute_levels (n->type_info (), 0, levels);
-
- for (unsigned long l = 0; l < max + 1; l++)
- {
- TypeInfoSet dispatched;
-
- for (LevelMap::const_iterator i = levels.begin ();
- i != levels.end ();
- i++)
- {
- if (i->second == l)
- {
- TraversalMap::const_iterator v =
- traversal_map_.find (i->first.type_id ());
-
- if (v != traversal_map_.end ())
- {
- v->second->traverse (n);
- flatten_tree (i->first, dispatched);
- }
- }
- }
-
- // Remove traversed types from level map.
- for (TypeInfoSet::const_iterator i = dispatched.begin ();
- i != dispatched.end ();
- i++)
- {
- levels.erase (*i);
- }
- }
- }
-}
-//$Id$
diff --git a/contrib/utility/Example/Introspection/Traversal/Traversal.hpp b/contrib/utility/Example/Introspection/Traversal/Traversal.hpp
deleted file mode 100644
index 7ee84523fc0..00000000000
--- a/contrib/utility/Example/Introspection/Traversal/Traversal.hpp
+++ /dev/null
@@ -1,157 +0,0 @@
-// file : Example/Introspection/Traversal/Traversal.hpp
-// author : Boris Kolpackov <boris@kolpackov.net>
-// copyright : Copyright (c) 2002-2003 Boris Kolpackov
-// license : http://kolpackov.net/license.html
-
-#ifndef TRAVERSAL_HPP
-#define TRAVERSAL_HPP
-
-#include <map>
-#include <iostream>
-
-#include "Utility/Introspection/Introspection.hpp"
-
-#include "SyntaxTree.hpp"
-
-namespace Traversal
-{
- class Traverser;
-
- //
- //
- //
- class Dispatcher
- {
- public:
- virtual
- ~Dispatcher ()
- {
- }
-
- virtual void
- dispatch (SyntaxTree::Node* n);
-
- protected:
- void
- map (Utility::Introspection::TypeId id, Traverser* t)
- {
- traversal_map_[id] = t;
- }
-
- private:
- typedef
- std::map<Utility::Introspection::TypeId, Traverser*>
- TraversalMap;
-
- TraversalMap traversal_map_;
- };
-
-
- //
- //
- //
- class Traverser : public virtual Dispatcher
- {
- public:
- virtual void
- traverse (SyntaxTree::Node* n) = 0;
- };
-
- //
- //
- //
- struct Node : Traverser
- {
- Node ()
- {
- map (typeid (SyntaxTree::Node), this);
- }
-
- virtual void
- traverse (SyntaxTree::Node*)
- {
- std::cerr << "node" << std::endl;
- }
- };
-
-
- //
- //
- //
- struct Declaration : Traverser
- {
- Declaration ()
- {
- map (typeid (SyntaxTree::Declaration), this);
- }
-
- virtual void
- traverse (SyntaxTree::Node*)
- {
- std::cerr << "declaration" << std::endl;
- }
- };
-
- //
- //
- //
- struct Scope : Traverser
- {
- Scope ()
- {
- map (typeid (SyntaxTree::Scope), this);
- }
-
- virtual void
- traverse (SyntaxTree::Node* n)
- {
- std::cerr << "scope" << std::endl;
-
- SyntaxTree::Scope* s = dynamic_cast<SyntaxTree::Scope*> (n);
-
- for (SyntaxTree::DeclarationList::iterator i = s->content_.begin ();
- i != s->content_.end ();
- i++)
- {
- dispatch (*i);
- }
- }
- };
-
- //
- //
- //
- struct InterfaceDecl : Traverser
- {
- InterfaceDecl ()
- {
- map (typeid (SyntaxTree::InterfaceDecl), this);
- }
-
- virtual void
- traverse (SyntaxTree::Node*)
- {
- std::cerr << "interface declaration" << std::endl;
- }
- };
-
- //
- //
- //
- struct InterfaceDef : Traverser
- {
- InterfaceDef ()
- {
- map (typeid (SyntaxTree::InterfaceDef), this);
- }
-
- virtual void
- traverse (SyntaxTree::Node*)
- {
- std::cerr << "interface definition" << std::endl;
- }
- };
-}
-
-#endif // TRAVERSAL_HPP
-//$Id$
diff --git a/contrib/utility/Example/Introspection/Traversal/driver.cpp b/contrib/utility/Example/Introspection/Traversal/driver.cpp
deleted file mode 100644
index 35891ef58cc..00000000000
--- a/contrib/utility/Example/Introspection/Traversal/driver.cpp
+++ /dev/null
@@ -1,91 +0,0 @@
-// file : Example/Introspection/Traversal/driver.cpp
-// author : Boris Kolpackov <boris@kolpackov.net>
-// copyright : Copyright (c) 2002-2003 Boris Kolpackov
-// license : http://kolpackov.net/license.html
-
-#include <iostream>
-
-#include "SyntaxTree.hpp"
-#include "Traversal.hpp"
-
-int
-main ()
-{
- using namespace SyntaxTree;
-
- /*
- Create a syntax tree that looks something like this:
-
- scope
- {
- interface declaration;
-
- scope
- {
- interface definition
- {
- decalartion;
- };
- };
- };
-
- */
-
- Scope s1;
-
- InterfaceDecl i1;
- s1.content_.push_back (&i1);
-
- Scope s2;
- s1.content_.push_back (&s2);
-
- InterfaceDef i2;
- s2.content_.push_back (&i2);
-
- Declaration d1;
- i2.content_.push_back (&d1);
-
- SyntaxTree::Node* root = &s1;
-
- // Now different ways of traversing this tree:
-
- {
- std::cout << "test #1" << std::endl;
-
- struct Generator : Traversal::Declaration, Traversal::Scope
- {
- };
-
- Generator g;
- g.dispatch (root);
-
- std::cout << std::endl;
- }
-
- {
- std::cout << "test #2" << std::endl;
-
- struct Generator : Traversal::Scope, Traversal::InterfaceDecl
- {
- };
-
- Generator g;
- g.dispatch (root);
-
- std::cout << std::endl;
- }
-
- {
- std::cout << "test #3" << std::endl;
-
- struct Generator : Traversal::Scope, Traversal::InterfaceDef
- {
- };
-
- Generator g;
- g.dispatch (root);
-
- std::cout << std::endl;
- }
-}
-//$Id$