summaryrefslogtreecommitdiff
path: root/CIAO/CCF/Example
diff options
context:
space:
mode:
Diffstat (limited to 'CIAO/CCF/Example')
-rw-r--r--CIAO/CCF/Example/CIDL/LocalExecutorMapping/ExecutorMappingGenerator.cpp1860
-rw-r--r--CIAO/CCF/Example/CIDL/LocalExecutorMapping/ExecutorMappingGenerator.hpp34
-rw-r--r--CIAO/CCF/Example/CIDL/LocalExecutorMapping/cidlc.cpp228
-rw-r--r--CIAO/CCF/Example/CIDL/LocalExecutorMapping/test-0.idl21
-rw-r--r--CIAO/CCF/Example/CIDL/LocalExecutorMapping/test-0_exec.idl.orig6
-rw-r--r--CIAO/CCF/Example/CIDL/LocalExecutorMapping/test-1.idl23
-rw-r--r--CIAO/CCF/Example/CIDL/LocalExecutorMapping/test-1_exec.idl.orig33
-rw-r--r--CIAO/CCF/Example/CIDL/LocalExecutorMapping/test-2.cidl18
-rw-r--r--CIAO/CCF/Example/CIDL/LocalExecutorMapping/test-2.idl74
-rw-r--r--CIAO/CCF/Example/CIDL/LocalExecutorMapping/test-2_exec.idl.orig72
-rw-r--r--CIAO/CCF/Example/CodeGenerationKit/Indentation/IDL/indent_idl.cpp25
-rw-r--r--CIAO/CCF/Example/CodeGenerationKit/Indentation/XML/indent_xml.cpp32
-rw-r--r--CIAO/CCF/Example/ComponentDeploymentDescriptor/SyntaxTree.cpp113
-rw-r--r--CIAO/CCF/Example/ComponentDeploymentDescriptor/SyntaxTree.hpp286
-rw-r--r--CIAO/CCF/Example/ComponentDeploymentDescriptor/Traversal.cpp112
-rw-r--r--CIAO/CCF/Example/ComponentDeploymentDescriptor/Traversal.hpp386
-rw-r--r--CIAO/CCF/Example/ComponentDeploymentDescriptor/cdd.cpp144
-rw-r--r--CIAO/CCF/Example/IDL2/CxxMapping/Generator.cpp32
-rw-r--r--CIAO/CCF/Example/IDL2/CxxMapping/Generator.hpp34
-rw-r--r--CIAO/CCF/Example/IDL2/CxxMapping/GeneratorImpl.hpp533
-rw-r--r--CIAO/CCF/Example/IDL2/CxxMapping/driver.cpp96
-rw-r--r--CIAO/CCF/Example/IDL2/CxxMapping/test.idl12
22 files changed, 4174 insertions, 0 deletions
diff --git a/CIAO/CCF/Example/CIDL/LocalExecutorMapping/ExecutorMappingGenerator.cpp b/CIAO/CCF/Example/CIDL/LocalExecutorMapping/ExecutorMappingGenerator.cpp
new file mode 100644
index 00000000000..a933f2bd6bb
--- /dev/null
+++ b/CIAO/CCF/Example/CIDL/LocalExecutorMapping/ExecutorMappingGenerator.cpp
@@ -0,0 +1,1860 @@
+// file : CCF/Example/CIDL/LocalExecutorMapping/ExecutorMappingGenerator.cpp
+// author : Boris Kolpackov <boris@dre.vanderbilt.edu>
+// cvs-id : $Id$
+
+#include "ExecutorMappingGenerator.hpp"
+
+#include <set>
+#include <ostream>
+#include <fstream>
+
+#include "CCF/CIDL/SemanticGraph.hpp"
+#include "CCF/CIDL/Traversal.hpp"
+
+#include "CCF/CodeGenerationKit/Regex.hpp"
+#include "CCF/CodeGenerationKit/IndentationIDL.hpp"
+#include "CCF/CodeGenerationKit/IndentationImplanter.hpp"
+
+using std::string;
+using std::ostream;
+using std::endl;
+
+using namespace CCF::CIDL;
+using namespace CCF::CIDL::SemanticGraph;
+
+namespace
+{
+ class Context
+ {
+ public:
+ Context (TranslationUnit& tu)
+ : tu_ (tu)
+ {
+ }
+
+ TranslationUnit&
+ tu () const
+ {
+ return tu_;
+ }
+
+ public:
+ bool
+ add (Home& h)
+ {
+ return homes_.insert (&h).second;
+ }
+
+ bool
+ add (Component& c)
+ {
+ return components_.insert (&c).second;
+ }
+
+ bool
+ add (UnconstrainedInterface& i)
+ {
+ return interfaces_.insert (&i).second;
+ }
+
+ bool
+ add (Composition& c)
+ {
+ return compositions_.insert (&c).second;
+ }
+
+ public:
+ bool
+ find (Home& h) const
+ {
+ return homes_.find (&h) != homes_.end ();
+ }
+
+ bool
+ find (Component& c) const
+ {
+ return components_.find (&c) != components_.end ();
+ }
+
+ bool
+ find (UnconstrainedInterface& i) const
+ {
+ return interfaces_.find (&i) != interfaces_.end ();
+ }
+
+ bool
+ find (Composition& c) const
+ {
+ return compositions_.find (&c) != compositions_.end ();
+ }
+
+ private:
+ typedef std::set<Home*> Homes;
+ typedef std::set<Component*> Components;
+ typedef std::set<UnconstrainedInterface*> Interfaces;
+ typedef std::set<Composition*> Compositions;
+
+ TranslationUnit& tu_;
+
+ Homes homes_;
+ Components components_;
+ Interfaces interfaces_;
+ Compositions compositions_;
+ };
+
+ class Traverser
+ {
+ protected:
+ Traverser (Context& c)
+ : ctx (c)
+ {
+ }
+
+ Context& ctx;
+ };
+
+ struct Collector : Traverser
+ {
+ protected:
+ Collector (Context& c)
+ : Traverser (c)
+ {
+ }
+
+ bool
+ exist (ScopedName const& name)
+ {
+ return !ctx.tu ().lookup (name).empty ();
+ }
+ };
+
+ //
+ //
+ //
+ struct ComponentCollector : Traversal::Component, Collector
+ {
+ ComponentCollector (Context& c)
+ : Collector (c)
+ {
+ }
+
+ virtual void
+ traverse (Type& c)
+ {
+ SimpleName name (c.name ());
+ ScopedName scope (c.scoped_name ().scope_name ());
+
+ ScopedName monolith (scope, "CCM_" + name);
+ ScopedName context (scope, "CCM_" + name + "_Context");
+
+ // Check if mapping has already been provided.
+ //
+ if (exist (context) || exist (monolith)) return;
+
+ if(ctx.add (c))
+ {
+ // Collect inherited components and provides interfaces.
+ //
+ Traversal::Component::traverse (c);
+ }
+ }
+ };
+
+
+ //
+ //
+ //
+ struct HomeCollector : Traversal::Home, Collector
+ {
+ HomeCollector (Context& c)
+ : Collector (c)
+ {
+ }
+
+ virtual void
+ traverse (Type& h)
+ {
+ SimpleName name (h.name ());
+ ScopedName scope (h.scoped_name ().scope_name ());
+
+ ScopedName main (scope, "CCM_" + name);
+ ScopedName expl (scope, "CCM_" + name + "Explicit");
+ ScopedName impl (scope, "CCM_" + name + "Implicit");
+
+ // Check if mapping has already been provided.
+ //
+ if (exist (main) || exist (expl) || exist (impl)) return;
+
+ if(ctx.add (h))
+ {
+ // Note that I don't go after components that inherited home manages
+ // because it will be handled by component inheritance tree.
+ //
+ Traversal::Home::traverse (h);
+ }
+ }
+ };
+
+
+ //
+ //
+ //
+ struct InterfaceCollector : Traversal::UnconstrainedInterface, Collector
+ {
+ InterfaceCollector (Context& c)
+ : Collector (c)
+ {
+ }
+
+ virtual void
+ traverse (Type& i)
+ {
+ SimpleName name (i.name ());
+ ScopedName scope (i.scoped_name ().scope_name ());
+
+ ScopedName mapping (scope, "CCM_" + name);
+
+ // Check if mapping has already been provided.
+ //
+ if (exist (mapping)) return;
+
+ // Add to the list if it's not already there.
+ //
+ ctx.add (i);
+ }
+ };
+
+ struct CompositionCollector : Traversal::Composition, Collector
+ {
+ CompositionCollector (Context& c)
+ : Collector (c)
+ {
+ }
+
+ virtual void
+ traverse (Type& c)
+ {
+ // Add to the list if it's not already there.
+ //
+ if (ctx.add (c))
+ {
+ Traversal::Composition::traverse (c);
+ }
+ }
+ };
+
+ struct Emitter : Traverser
+ {
+ protected:
+ Emitter (Context& c, ostream& os_)
+ : Traverser (c), os (os_)
+ {
+ }
+
+ protected:
+ ostream& os;
+ };
+
+
+ //
+ //
+ //
+ struct TypeNameEmitter : Traversal::FundamentalType,
+ Traversal::Type,
+ Emitter
+ {
+ TypeNameEmitter (Context& c, ostream& os)
+ : Emitter (c, os)
+ {
+ }
+
+ virtual void
+ traverse (SemanticGraph::FundamentalType& t)
+ {
+ os << t.name ();
+ }
+
+ virtual void
+ traverse (SemanticGraph::Type& t)
+ {
+ os << t.scoped_name ();
+ }
+ };
+
+
+ struct NameMangler : Traversal::Nameable, Emitter
+ {
+ NameMangler (Context& c,
+ ostream& os,
+ string const& prefix,
+ string const& suffix = "")
+ : Emitter (c, os), prefix_ (prefix), suffix_ (suffix)
+ {
+ }
+
+ virtual void
+ traverse (Type& t)
+ {
+ ScopedName n (t.scoped_name ());
+ os << n.scope_name () << "::" << prefix_ << n.simple_name () << suffix_;
+ }
+
+ private:
+ string prefix_, suffix_;
+ };
+
+
+ //
+ //
+ //
+ struct ComponentEmitter : Traversal::Component, Emitter
+ {
+ protected:
+ ComponentEmitter (Context& c, ostream& os)
+ : Emitter (c, os)
+ {
+ }
+
+ virtual void
+ traverse (Type& c)
+ {
+ if (ctx.find (c))
+ {
+ Component::traverse (c);
+ }
+ }
+ };
+
+ struct AttributeEmitter : Traversal::ReadAttribute,
+ Traversal::ReadWriteAttribute,
+ Emitter
+ {
+ AttributeEmitter (Context& c, ostream& os)
+ : Emitter (c, os)
+ {
+ }
+
+ // ReadAttribute
+ //
+ virtual void
+ pre (SemanticGraph::ReadAttribute& )
+ {
+ os << "readonly attribute ";
+ }
+
+ virtual void
+ name (SemanticGraph::ReadAttribute& a)
+ {
+ os << " " << a.name ();
+ }
+
+ virtual void
+ post (SemanticGraph::ReadAttribute&)
+ {
+ os << ";";
+ }
+
+ // ReadWriteAttribute
+ //
+ virtual void
+ pre (SemanticGraph::ReadWriteAttribute& )
+ {
+ os << "attribute ";
+ }
+
+ virtual void
+ name (SemanticGraph::ReadWriteAttribute& a)
+ {
+ os << " " << a.name ();
+ }
+
+ virtual void
+ post (SemanticGraph::ReadWriteAttribute&)
+ {
+ os << ";";
+ }
+ };
+
+
+ // MonolithEmitter generates what spec calls 'Monolithic Component
+ // Executor'.
+ //
+ struct MonolithEmitter : ComponentEmitter
+ {
+ MonolithEmitter (Context& c, ostream& os)
+ : ComponentEmitter (c, os),
+ monolith_name_emitter (c, os, "CCM_"),
+ attribute (c, os),
+ consumer (c, os),
+ provider (c, os),
+ type_name_emitter (c, os)
+ {
+ edge_traverser (inherits);
+ edge_traverser (defines);
+
+ inherits.node_traverser (monolith_name_emitter);
+
+ defines.node_traverser (attribute);
+ defines.node_traverser (consumer);
+ defines.node_traverser (provider);
+
+ attribute.edge_traverser (belongs);
+ consumer.edge_traverser (belongs);
+ provider.edge_traverser (provider_belongs);
+
+ belongs.node_traverser (type_name_emitter);
+ provider_belongs.node_traverser (monolith_name_emitter);
+ }
+
+ virtual void
+ pre (Type&)
+ {
+ os << "local interface ";
+ }
+
+ virtual void
+ name (Type& c)
+ {
+ os << "CCM_" << c.name ();
+ }
+
+ virtual void
+ inherits_pre (Type&)
+ {
+ os << " : ";
+ }
+
+ virtual void
+ inherits_none (Type&)
+ {
+ os << " : ::Components::EnterpriseComponent";
+ }
+
+ virtual void
+ supports_pre (Type&)
+ {
+ os << ", ";
+ }
+
+ virtual void
+ names_pre (Type&)
+ {
+ os << "{";
+ }
+
+ virtual void
+ names_post (Type&)
+ {
+ os << "}";
+ }
+
+ virtual void
+ post (Type&)
+ {
+ os << ";";
+ }
+
+ virtual void
+ comma (Type&)
+ {
+ os << ", ";
+ }
+
+ private:
+ struct Consumer : Traversal::ConsumerSet, Emitter
+ {
+ Consumer (Context& c, ostream& os)
+ : Emitter (c, os)
+ {
+ }
+
+ virtual void
+ returns (Type&)
+ {
+ os << "void";
+ }
+
+ virtual void
+ name (Type& c)
+ {
+ os << " push_" << c.name ();
+ }
+
+ virtual void
+ receives_pre (Type&)
+ {
+ os << " (in ";
+ }
+
+ virtual void
+ receives_post (Type&)
+ {
+ os << " e)";
+ }
+
+ virtual void
+ post (Type&)
+ {
+ os << ";";
+ }
+ };
+
+
+ struct Provider : Traversal::ProviderGet, Emitter
+ {
+ Provider (Context& c, ostream& os)
+ : Emitter (c, os)
+ {
+ }
+
+ virtual void
+ name (Type& c)
+ {
+ os << " get_" << c.name ();
+ }
+
+ virtual void
+ receives_pre (Type&)
+ {
+ os << " (";
+ }
+
+ virtual void
+ receives_post (Type&)
+ {
+ os << ")";
+ }
+
+ virtual void
+ post (Type&)
+ {
+ os << ";";
+ }
+ };
+
+ Traversal::Inherits inherits;
+ Traversal::Defines defines;
+
+ NameMangler monolith_name_emitter;
+
+ AttributeEmitter attribute;
+ Consumer consumer;
+ Provider provider;
+
+ Traversal::Belongs belongs;
+ Traversal::Belongs provider_belongs;
+
+ TypeNameEmitter type_name_emitter;
+ };
+
+
+ // ContextEmitter generates component context interface.
+ //
+ //
+ struct ContextPortEmitter : Traversal::UserGet,
+ Traversal::PublisherSet,
+ Traversal::EmitterSet,
+ Emitter
+ {
+ ContextPortEmitter (Context& c, ostream& os)
+ : Emitter (c, os)
+ {
+ }
+
+
+ // User.
+ //
+ virtual void
+ name (SemanticGraph::User& u)
+ {
+ os << " get_connection_" << u.name ();
+ }
+
+ virtual void
+ receives_pre (SemanticGraph::User&)
+ {
+ os << " (";
+ }
+
+ virtual void
+ receives_post (SemanticGraph::User&)
+ {
+ os << ")";
+ }
+
+ virtual void
+ post (SemanticGraph::User&)
+ {
+ os << ";";
+ }
+
+
+ // Publisher.
+ //
+ virtual void
+ returns (SemanticGraph::Publisher&)
+ {
+ os << "void";
+ }
+
+ virtual void
+ name (SemanticGraph::Publisher& p)
+ {
+ os << " push_" << p.name ();
+ }
+
+ virtual void
+ receives_pre (SemanticGraph::Publisher&)
+ {
+ os << " (in ";
+ }
+
+ virtual void
+ receives_post (SemanticGraph::Publisher&)
+ {
+ os << " e)";
+ }
+
+ virtual void
+ post (SemanticGraph::Publisher&)
+ {
+ os << ";";
+ }
+
+
+ // Emitter.
+ //
+ virtual void
+ returns (SemanticGraph::Emitter&)
+ {
+ os << "void";
+ }
+
+ virtual void
+ name (SemanticGraph::Emitter& e)
+ {
+ os << " push_" << e.name ();
+ }
+
+ virtual void
+ receives_pre (SemanticGraph::Emitter&)
+ {
+ os << " (in ";
+ }
+
+ virtual void
+ receives_post (SemanticGraph::Emitter&)
+ {
+ os << " e)";
+ }
+
+ virtual void
+ post (SemanticGraph::Emitter&)
+ {
+ os << ";";
+ }
+ };
+
+
+ struct ContextEmitter : ComponentEmitter
+ {
+ ContextEmitter (Context& c, ostream& os)
+ : ComponentEmitter (c, os), name_emitter (c, os, "CCM_", "_Context")
+ {
+ edge_traverser (inherits);
+ inherits.node_traverser (name_emitter);
+ }
+
+ virtual void
+ pre (Type&)
+ {
+ os << "local interface ";
+ }
+
+ virtual void
+ name (Type& c)
+ {
+ os << "CCM_" << c.name () << "_Context";
+ }
+
+ virtual void
+ inherits_pre (Type&)
+ {
+ os << " : ";
+ }
+
+ virtual void
+ inherits_none (Type&)
+ {
+ os << " : ::Components::CCMContext";
+ }
+
+ virtual void
+ names_pre (Type&)
+ {
+ os << "{";
+ }
+
+ virtual void
+ names_post (Type&)
+ {
+ os << "}";
+ }
+
+ virtual void
+ post (Type&)
+ {
+ os << ";";
+ }
+
+ private:
+ Traversal::Inherits inherits;
+ NameMangler name_emitter;
+ };
+
+
+ //
+ //
+ //
+ struct HomeEmitter : Traversal::Home, Emitter
+ {
+ HomeEmitter (Context& c, ostream& os)
+ : Emitter (c, os)
+ {
+ }
+
+ virtual void
+ traverse (Type& h)
+ {
+ if (ctx.find (h))
+ {
+ Home::traverse (h);
+ }
+ }
+ };
+
+
+ // HomeExplicitEmitter generates home explicit interface
+ //
+ //
+ struct ExplicitPortEmitter : AttributeEmitter,
+ Traversal::Operation,
+ Traversal::HomeFactory,
+ Traversal::HomeFinder
+ {
+ ExplicitPortEmitter (Context& c, ostream& os)
+ : AttributeEmitter (c, os)
+ {
+ }
+
+ // Operation.
+ //
+
+ virtual void
+ name (SemanticGraph::Operation& o)
+ {
+ os << " " << o.name ();
+ }
+
+ virtual void
+ receives_pre (SemanticGraph::Operation&)
+ {
+ os << " (";
+ }
+
+ virtual void
+ receives_post (SemanticGraph::Operation&)
+ {
+ os << ")";
+ }
+
+ virtual void
+ raises_pre (SemanticGraph::Operation&)
+ {
+ os << " raises (";
+ }
+
+ virtual void
+ raises_post (SemanticGraph::Operation&)
+ {
+ os << ")";
+ }
+
+ virtual void
+ post (SemanticGraph::Operation&)
+ {
+ os << ";";
+ }
+
+ virtual void
+ comma (SemanticGraph::Operation&)
+ {
+ os << ", ";
+ }
+
+
+ // HomeFactory.
+ //
+
+ virtual void
+ returns (SemanticGraph::HomeFactory&)
+ {
+ os << "::Components::EnterpriseComponent ";
+ }
+
+ virtual void
+ name (SemanticGraph::HomeFactory& hf)
+ {
+ os << " " << hf.name ();
+ }
+
+ virtual void
+ receives_pre (SemanticGraph::HomeFactory&)
+ {
+ os << " (";
+ }
+
+ virtual void
+ receives_post (SemanticGraph::HomeFactory&)
+ {
+ os << ")";
+ }
+
+ virtual void
+ raises_pre (SemanticGraph::HomeFactory&)
+ {
+ os << " raises (";
+ }
+
+ virtual void
+ raises_post (SemanticGraph::HomeFactory&)
+ {
+ os << ")";
+ }
+
+ virtual void
+ post (SemanticGraph::HomeFactory&)
+ {
+ os << ";";
+ }
+
+ virtual void
+ comma (SemanticGraph::HomeFactory&)
+ {
+ os << ", ";
+ }
+
+ // HomeFinder.
+ //
+
+ virtual void
+ returns (SemanticGraph::HomeFinder&)
+ {
+ os << "::Components::EnterpriseComponent ";
+ }
+
+ virtual void
+ name (SemanticGraph::HomeFinder& hf)
+ {
+ os << " " << hf.name ();
+ }
+
+ virtual void
+ receives_pre (SemanticGraph::HomeFinder&)
+ {
+ os << " (";
+ }
+
+ virtual void
+ receives_post (SemanticGraph::HomeFinder&)
+ {
+ os << ")";
+ }
+
+ virtual void
+ raises_pre (SemanticGraph::HomeFinder&)
+ {
+ os << " raises (";
+ }
+
+ virtual void
+ raises_post (SemanticGraph::HomeFinder&)
+ {
+ os << ")";
+ }
+
+ virtual void
+ post (SemanticGraph::HomeFinder&)
+ {
+ os << ";";
+ }
+
+ virtual void
+ comma (SemanticGraph::HomeFinder&)
+ {
+ os << ", ";
+ }
+ };
+
+ struct ParameterEmitter : Traversal::InParameter,
+ Traversal::OutParameter,
+ Traversal::InOutParameter,
+ public Emitter
+ {
+ ParameterEmitter (Context& c, ostream& os)
+ : Emitter (c, os)
+ {
+ }
+
+ virtual void
+ pre (InParameter& p)
+ {
+ os << "in ";
+ }
+
+ virtual void
+ pre (OutParameter& p)
+ {
+ os << "out ";
+ }
+
+ virtual void
+ pre (InOutParameter& p)
+ {
+ os << "inout ";
+ }
+
+ virtual void
+ name (InParameter& p)
+ {
+ os << " " << p.name ();
+ }
+
+ virtual void
+ name (OutParameter& p)
+ {
+ os << " " << p.name ();
+ }
+
+ virtual void
+ name (InOutParameter& p)
+ {
+ os << " " << p.name ();
+ }
+ };
+
+ struct HomeExplicitEmitter : HomeEmitter
+ {
+ HomeExplicitEmitter (Context& c, ostream& os)
+ : HomeEmitter (c, os), name_emitter (c, os, "CCM_", "Explicit")
+ {
+ edge_traverser (inherits);
+ inherits.node_traverser (name_emitter);
+ }
+
+ virtual void
+ pre (Type&)
+ {
+ os << "local interface ";
+ }
+
+ virtual void
+ name (Type& h)
+ {
+ os << "CCM_" << h.name () << "Explicit";
+ }
+
+ virtual void
+ inherits_pre (Type&)
+ {
+ os << " : ";
+ }
+
+ virtual void
+ inherits_none (Type&)
+ {
+ os << " : ::Components::HomeExecutorBase";
+ }
+
+ virtual void
+ supports_pre (Type&)
+ {
+ os << ", ";
+ }
+
+ virtual void
+ names_pre (Type&)
+ {
+ os << "{";
+ }
+
+ virtual void
+ names_post (Type&)
+ {
+ os << "}";
+ }
+
+ virtual void
+ post (Type&)
+ {
+ os << ";";
+ }
+
+ virtual void
+ comma (Type&)
+ {
+ os << ", ";
+ }
+
+ private:
+ Traversal::Inherits inherits;
+ NameMangler name_emitter;
+ };
+
+
+ // HomeImplicitEmitter generates home implicit interface
+ //
+ //
+ struct HomeImplicitEmitter : HomeEmitter
+ {
+ HomeImplicitEmitter (Context& c, ostream& os)
+ : HomeEmitter (c, os)
+ {
+ }
+
+ virtual void
+ pre (Type&)
+ {
+ os << "local interface ";
+ }
+
+ virtual void
+ name (Type& h)
+ {
+ os << "CCM_" << h.name () << "Implicit";
+ }
+
+ virtual void
+ names (Type& h)
+ {
+ os<< "{"
+ << "::Components::EnterpriseComponent "
+ << "create () raises (::Components::CCMException);"
+ << "}";
+ }
+
+ virtual void
+ post (Type&)
+ {
+ os << ";";
+ }
+ };
+
+
+ // HomeMainEmitter generates home main interface
+ //
+ //
+ struct HomeMainEmitter : HomeEmitter
+ {
+ HomeMainEmitter (Context& c, ostream& os)
+ : HomeEmitter (c, os)
+ {
+ }
+
+ virtual void
+ pre (Type&)
+ {
+ os << "local interface ";
+ }
+
+ virtual void
+ name (Type& h)
+ {
+ os << "CCM_" << h.name ();
+ }
+
+ virtual void
+ inherits (Type& h)
+ {
+ os << " : "
+ << "CCM_" << h.name () << "Explicit, "
+ << "CCM_" << h.name () << "Implicit";
+ }
+
+ virtual void
+ names (Type&)
+ {
+ os << "{}";
+ }
+
+ virtual void
+ post (Type&)
+ {
+ os << ";";
+ }
+ };
+
+ //
+ //
+ //
+ struct ModuleEmitter : Traversal::Module, Emitter
+ {
+ ModuleEmitter (Context& c, ostream& os)
+ : Emitter (c, os)
+ {
+ }
+
+ virtual void
+ traverse (Type& m)
+ {
+ if (has_elements (m))
+ {
+ Traversal::Module::traverse (m);
+ }
+ }
+
+ virtual void
+ pre (Type&)
+ {
+ os << "module ";
+ }
+
+ virtual void
+ name (Type& m)
+ {
+ os << m.name ();
+ }
+
+ virtual void
+ names_pre (Type&)
+ {
+ os << "{";
+ }
+
+ virtual void
+ names_post (Type&)
+ {
+ os << "}";
+ }
+
+ virtual void
+ post (Type&)
+ {
+ os << ";";
+ }
+
+ private:
+
+ template <typename T>
+ struct Finder : T, Traverser
+ {
+ Finder (Context& c, bool& r)
+ : Traverser (c), r_ (r)
+ {
+ }
+
+ virtual void
+ traverse (typename T::Type& t)
+ {
+ if (ctx.find (t)) r_ = true;
+ }
+
+ private:
+ bool& r_;
+ };
+
+ bool
+ has_elements (Type& m)
+ {
+ bool r (false);
+
+ Traversal::Module module;
+ Traversal::Defines defines;
+
+ module.edge_traverser (defines);
+
+ //@@ MSVC bug: interface is considered to be an alias for a struct.
+ //
+ Finder<Traversal::Composition> composition (ctx, r);
+ Finder<Traversal::UnconstrainedInterface> interface_ (ctx, r);
+ Finder<Traversal::Component> component (ctx, r);
+ Finder<Traversal::Home> home (ctx, r);
+
+ defines.node_traverser (module);
+ defines.node_traverser (composition);
+ defines.node_traverser (interface_);
+ defines.node_traverser (component);
+ defines.node_traverser (home);
+
+ module.traverse (m);
+
+ return r;
+ }
+ };
+
+ //
+ //
+ //
+ struct InterfaceEmitter : Traversal::UnconstrainedInterface, Emitter
+ {
+ InterfaceEmitter (Context& c, ostream& os)
+ : Emitter (c, os)
+ {
+ }
+
+ virtual void
+ traverse (Type& i)
+ {
+ if (ctx.find (i))
+ {
+ Traversal::UnconstrainedInterface::traverse (i);
+ }
+ }
+
+ virtual void
+ pre (Type&)
+ {
+ os << "local interface ";
+ }
+
+ virtual void
+ name (Type& i)
+ {
+ os << "CCM_" << i.name ();
+ }
+
+ virtual void
+ inherits (Type& i)
+ {
+ os << " : " << i.name ();
+ }
+
+ virtual void
+ names_pre (Type&)
+ {
+ os << "{";
+ }
+
+ virtual void
+ names_post (Type&)
+ {
+ os << "}";
+ }
+
+ virtual void
+ post (Type&)
+ {
+ os << ";";
+ }
+ };
+
+
+ //
+ //
+ //
+ struct CompositionEmitter : Traversal::Composition, Emitter
+ {
+ CompositionEmitter (Context& c, ostream& os)
+ : Emitter (c, os)
+ {
+ }
+
+ virtual void
+ traverse (Type& c)
+ {
+ if (ctx.find (c))
+ {
+ Traversal::Composition::traverse (c);
+ }
+ }
+
+ virtual void
+ pre (Type&)
+ {
+ os << "module ";
+ }
+
+ virtual void
+ name (Type& m)
+ {
+ os << m.name ();
+ }
+
+ virtual void
+ names_pre (Type&)
+ {
+ os << "{";
+ }
+
+ virtual void
+ names_post (Type&)
+ {
+ os << "}";
+ }
+
+ virtual void
+ post (Type&)
+ {
+ os << ";";
+ }
+ };
+
+
+ struct ComponentContextEmitter : Traversal::ComponentExecutor, Emitter
+ {
+ ComponentContextEmitter (Context& c, ostream& os)
+ : Emitter (c, os),
+ name_emitter_ (c, os, "CCM_", "_Context")
+ {
+ implements_traverser_.node_traverser (name_emitter_);
+ }
+
+ virtual void
+ pre (Type&)
+ {
+ os << "local interface ";
+ }
+
+ virtual void
+ name (Type& i)
+ {
+ //@@ need to check if spec prescribes this name.
+ //
+ os << i.name () << "_Context";
+ }
+
+ virtual void
+ implements (Type& i)
+ {
+ os << " : ";
+
+ Traversal::ComponentExecutor::implements (i, implements_traverser_);
+
+ os << ", "
+ << "::Components::SessionContext";
+ }
+
+ virtual void
+ post (Type&)
+ {
+ os << "{};";
+ }
+
+ private:
+ NameMangler name_emitter_;
+ Traversal::Implements implements_traverser_;
+ };
+
+
+ struct ComponentExecutorEmitter : Traversal::ComponentExecutor, Emitter
+ {
+ ComponentExecutorEmitter (Context& c, ostream& os)
+ : Emitter (c, os),
+ name_emitter_ (c, os, "CCM_")
+ {
+ implements_traverser_.node_traverser (name_emitter_);
+ }
+
+ virtual void
+ pre (Type&)
+ {
+ os << "local interface ";
+ }
+
+ virtual void
+ name (Type& i)
+ {
+ os << i.name ();
+ }
+
+ virtual void
+ implements (Type& i)
+ {
+ os << " : ";
+
+ Traversal::ComponentExecutor::implements (i, implements_traverser_);
+
+ os << ", "
+ << "::Components::SessionComponent";
+ }
+
+ virtual void
+ post (Type&)
+ {
+ os << "{};";
+ }
+
+ private:
+ NameMangler name_emitter_;
+ Traversal::Implements implements_traverser_;
+ };
+
+
+ struct HomeExecutorEmitter : Traversal::HomeExecutor, Emitter
+ {
+ HomeExecutorEmitter (Context& c, ostream& os)
+ : Emitter (c, os),
+ name_emitter_ (c, os, "CCM_")
+ {
+ implements_traverser_.node_traverser (name_emitter_);
+ }
+
+ virtual void
+ pre (Type&)
+ {
+ os << "local interface ";
+ }
+
+ virtual void
+ name (Type& i)
+ {
+ os << i.name ();
+ }
+
+ virtual void
+ implements (Type& i)
+ {
+ os << " : ";
+
+ Traversal::HomeExecutor::implements (i, implements_traverser_);
+ }
+
+ virtual void
+ post (Type&)
+ {
+ os << "{};";
+ }
+
+ private:
+ NameMangler name_emitter_;
+ Traversal::Implements implements_traverser_;
+ };
+
+ //
+ //
+ //
+ struct IncludesEmitter : Traversal::QuoteIncludes,
+ Traversal::BracketIncludes,
+ Emitter
+ {
+ IncludesEmitter (Context& c, ostream& os)
+ : Emitter (c, os)
+ {
+ }
+
+ virtual void
+ traverse (SemanticGraph::QuoteIncludes& qi)
+ {
+ os << "#include \"" << qi.file ().string () << "\"" << endl;
+ }
+
+ virtual void
+ traverse (SemanticGraph::BracketIncludes& bi)
+ {
+ os << "#include <" << bi.file ().string () << ">" << endl;
+ }
+ };
+}
+
+void ExecutorMappingGenerator::
+options (CL::Description& d)
+{
+ d.add_option (CL::OptionDescription (
+ "lem-file-suffix",
+ "suffix",
+ "Use provided suffix instead of default \'E\' "
+ "when constructing name of local executor mapping file.",
+ true));
+
+ d.add_option (CL::OptionDescription (
+ "lem-file-regex",
+ "regex",
+ "Use provided regular expression when constructing "
+ "name of local executor mapping file.",
+ true));
+
+ d.add_option (CL::OptionDescription (
+ "lem-force-all",
+ "Force generation of local executor mapping for all IDL "
+ "types including those not used (directly or inderectly) "
+ "by compositions. This option is useful for generating a "
+ "common portion of local executor mapping used by more "
+ "than one component or composition.",
+ true));
+}
+
+
+void ExecutorMappingGenerator::
+generate (CommandLine const& cl,
+ TranslationUnit& tu,
+ fs::path const& file_path)
+{
+ fs::ofstream ofs;
+
+ if (!file_path.empty ())
+ {
+ string file_name (file_path.leaf ());
+
+ string suffix (cl.get_value ("lem-file-suffix", "E.idl"));
+
+ string expr (cl.get_value (
+ "lem-file-regex", "/^(.+?)(\\.(idl|cidl))?$/$1" + suffix + "/"));
+
+ string lem_file_name (regex::perl_s (file_name, expr));
+
+ fs::path lem_file_path (lem_file_name);
+
+ ofs.open (lem_file_path, std::ios_base::out);
+
+ if (!ofs.is_open ())
+ {
+ cerr << lem_file_name << ": error: unable to open in write mode"
+ << endl;
+ return;
+ }
+ }
+
+ ostream& os = ofs.is_open ()
+ ? static_cast<ostream&> (ofs)
+ : static_cast<ostream&> (std::cout);
+
+ // Set auto-indentation for os.
+ //
+ Indentation::Implanter<Indentation::IDL> guard (os);
+
+ Context ctx (tu);
+
+ if (cl.get_value ("lem-force-all", false))
+ {
+ Traversal::TranslationUnit unit;
+
+ // Layer 1
+ //
+ Traversal::ContainsPrincipal contains_principal;
+
+ unit.edge_traverser (contains_principal);
+
+ //--
+ Traversal::TranslationRegion region;
+
+ contains_principal.node_traverser (region);
+
+
+ // Layer 2
+ //
+ Traversal::ContainsRoot contains_root;
+ region.edge_traverser (contains_root);
+
+ //--
+ Traversal::Root root;
+ contains_root.node_traverser (root);
+
+
+ // Layer 3
+ //
+ Traversal::Defines defines;
+ root.edge_traverser (defines);
+
+ //--
+ Traversal::Module module;
+ HomeCollector home (ctx);
+ ComponentCollector component (ctx);
+ InterfaceCollector interface_ (ctx);
+
+ defines.node_traverser (module);
+ defines.node_traverser (home);
+ defines.node_traverser (component);
+ defines.node_traverser (interface_);
+
+ // Layer 4
+ //
+ Traversal::Defines component_defines;
+ Traversal::Inherits component_inherits;
+ Traversal::Inherits home_inherits;
+
+ module.edge_traverser (defines);
+
+ home.edge_traverser (home_inherits);
+ component.edge_traverser (component_defines);
+ component.edge_traverser (component_inherits);
+
+ //--
+
+ Traversal::Provider provider;
+
+ component_defines.node_traverser (provider);
+ component_inherits.node_traverser (component);
+ home_inherits.node_traverser (home);
+
+
+ // Layer 5
+ //
+ Traversal::Belongs provider_belongs;
+ provider.edge_traverser (provider_belongs);
+
+ //
+ provider_belongs.node_traverser (interface_);
+
+ // end
+
+ unit.traverse (tu);
+ }
+ else
+ {
+ Traversal::TranslationUnit unit;
+
+ // Layer 1
+ //
+ Traversal::ContainsPrincipal contains_principal;
+
+ unit.edge_traverser (contains_principal);
+
+ //--
+ Traversal::TranslationRegion region;
+
+ contains_principal.node_traverser (region);
+
+
+ // Layer 2
+ //
+ Traversal::ContainsRoot contains_root;
+ Traversal::Includes includes;
+
+ region.edge_traverser (contains_root);
+ region.edge_traverser (includes);
+
+ //--
+ Traversal::Root root;
+
+ contains_root.node_traverser (root);
+ includes.node_traverser (region);
+
+
+ // Layer 3
+ //
+ Traversal::Defines defines;
+ root.edge_traverser (defines);
+
+ //--
+ Traversal::Module module;
+ CompositionCollector composition (ctx);
+
+ defines.node_traverser (module);
+ defines.node_traverser (composition);
+
+
+ // Layer 4
+ //
+ Traversal::Defines composition_defines;
+
+ module.edge_traverser (defines);
+ composition.edge_traverser (composition_defines);
+
+ //--
+ Traversal::ComponentExecutor component_executor;
+ Traversal::HomeExecutor home_executor;
+
+ composition_defines.node_traverser (component_executor);
+ composition_defines.node_traverser (home_executor);
+
+ // Layer 5
+ //
+ Traversal::Implements component_executor_implements;
+ Traversal::Implements home_executor_implements;
+
+ component_executor.edge_traverser (component_executor_implements);
+ home_executor.edge_traverser (home_executor_implements);
+
+ //--
+ ComponentCollector component (ctx);
+ HomeCollector home (ctx);
+
+ component_executor_implements.node_traverser (component);
+ home_executor_implements.node_traverser (home);
+
+
+ // Layer 6
+ //
+ Traversal::Defines component_defines;
+ Traversal::Inherits component_inherits;
+ Traversal::Inherits home_inherits;
+
+ component.edge_traverser (component_defines);
+ component.edge_traverser (component_inherits);
+ home.edge_traverser (home_inherits);
+
+ //--
+
+ Traversal::Provider provider;
+
+ component_defines.node_traverser (provider);
+ component_inherits.node_traverser (component);
+ home_inherits.node_traverser (home);
+
+
+ // Layer 7
+ //
+ Traversal::Belongs provider_belongs;
+ provider.edge_traverser (provider_belongs);
+
+ //
+ InterfaceCollector interface_ (ctx);
+
+ provider_belongs.node_traverser (interface_);
+
+
+ // end
+
+ unit.traverse (tu);
+ }
+
+ {
+ Traversal::TranslationUnit unit;
+
+ // Layer 1
+ //
+ Traversal::ContainsPrincipal contains_principal;
+
+ unit.edge_traverser (contains_principal);
+
+ //--
+ Traversal::TranslationRegion principal_region;
+
+ contains_principal.node_traverser (principal_region);
+
+
+ // Layer 2
+ //
+ Traversal::TranslationRegion included_region;
+
+ // Inclusion handling is somewhat tricky because we want
+ // to print only top-level #include's.
+ //
+
+ Traversal::ContainsRoot contains_root;
+ Traversal::QuoteIncludes quote_includes;
+ Traversal::BracketIncludes bracket_includes;
+ IncludesEmitter includes_emitter (ctx, os);
+
+
+ principal_region.edge_traverser (includes_emitter);
+ principal_region.edge_traverser (quote_includes);
+ principal_region.edge_traverser (bracket_includes);
+ principal_region.edge_traverser (contains_root);
+
+ included_region.edge_traverser (quote_includes);
+ included_region.edge_traverser (bracket_includes);
+ included_region.edge_traverser (contains_root);
+
+
+ //--
+ Traversal::Root root;
+
+ contains_root.node_traverser (root);
+ quote_includes.node_traverser (included_region);
+ bracket_includes.node_traverser (included_region);
+
+
+ // Layer 3
+ //
+ Traversal::Defines defines;
+ root.edge_traverser (defines);
+
+ //--
+ ModuleEmitter module (ctx, os);
+
+ CompositionEmitter composition (ctx, os);
+
+ InterfaceEmitter interface_ (ctx, os);
+
+ MonolithEmitter component_monolith (ctx, os);
+ ContextEmitter component_context (ctx, os);
+
+ HomeImplicitEmitter home_implicit (ctx, os);
+ HomeExplicitEmitter home_explicit (ctx, os);
+ HomeMainEmitter home_main (ctx, os);
+
+ defines.node_traverser (module);
+
+ defines.node_traverser (composition);
+
+ defines.node_traverser (interface_);
+
+ defines.node_traverser (component_monolith);
+ defines.node_traverser (component_context);
+
+ defines.node_traverser (home_implicit);
+ defines.node_traverser (home_explicit);
+ defines.node_traverser (home_main);
+
+ // Layer 4
+ //
+
+ Traversal::Supports supports;
+
+ Traversal::Defines composition_defines;
+
+ Traversal::Defines component_context_defines;
+
+ Traversal::Defines home_explicit_defines;
+
+ module.edge_traverser (defines);
+
+ composition.edge_traverser (composition_defines);
+
+ component_monolith.edge_traverser (supports);
+ component_context.edge_traverser (component_context_defines);
+
+ home_explicit.edge_traverser (supports);
+ home_explicit.edge_traverser (home_explicit_defines);
+
+ //--
+ TypeNameEmitter type (ctx, os);
+
+ ComponentContextEmitter session_component_context (ctx, os);
+ ComponentExecutorEmitter session_component_executor (ctx, os);
+ HomeExecutorEmitter session_home_executor (ctx, os);
+
+ ContextPortEmitter port_context (ctx, os);
+ ExplicitPortEmitter port_explicit (ctx, os);
+
+ supports.node_traverser (type);
+
+ composition_defines.node_traverser (session_component_context);
+ composition_defines.node_traverser (session_component_executor);
+ composition_defines.node_traverser (session_home_executor);
+
+ component_context_defines.node_traverser (port_context);
+
+ home_explicit_defines.node_traverser (port_explicit);
+
+
+ // Layer 5
+ //
+ Traversal::Belongs belongs;
+ Traversal::Receives receives;
+ Traversal::Raises raises;
+
+ port_context.edge_traverser (belongs);
+ port_explicit.edge_traverser (belongs);
+ port_explicit.edge_traverser (raises);
+
+ port_explicit.edge_traverser (receives);
+
+ //--
+ ParameterEmitter parameter (ctx, os);
+
+ belongs.node_traverser (type);
+ receives.node_traverser (parameter);
+ raises.node_traverser (type);
+
+ // Layer 6
+ //
+ parameter.edge_traverser (belongs);
+
+
+ // end
+
+ unit.traverse (tu);
+ }
+}
diff --git a/CIAO/CCF/Example/CIDL/LocalExecutorMapping/ExecutorMappingGenerator.hpp b/CIAO/CCF/Example/CIDL/LocalExecutorMapping/ExecutorMappingGenerator.hpp
new file mode 100644
index 00000000000..c76f56e84b9
--- /dev/null
+++ b/CIAO/CCF/Example/CIDL/LocalExecutorMapping/ExecutorMappingGenerator.hpp
@@ -0,0 +1,34 @@
+// file : CCF/Example/CIDL/LocalExecutorMapping/ExecutorMappingGenerator.hpp
+// author : Boris Kolpackov <boris@dre.vanderbilt.edu>
+// cvs-id : $Id$
+
+#ifndef EXECUTOR_MAPPING_GENERATOR_HPP
+#define EXECUTOR_MAPPING_GENERATOR_HPP
+
+#include "CCF/CompilerElements/FileSystem.hpp"
+
+#include "CCF/CodeGenerationKit/CommandLine.hpp"
+#include "CCF/CodeGenerationKit/CommandLineDescriptor.hpp"
+
+//@@ SemanticGraphFwd could be useful here.
+//
+#include "CCF/CIDL/SemanticGraph.hpp"
+
+class ExecutorMappingGenerator
+{
+public:
+
+ //@@ should be static?
+ void
+ options (CL::Description& d);
+
+ //@@ maybe I should introduce constant and non-constant
+ // traversal.
+ //
+ void
+ generate (CommandLine const& cl,
+ CCF::CIDL::SemanticGraph::TranslationUnit&,
+ fs::path const& file);
+};
+
+#endif // EXECUTOR_MAPPING_GENERATOR_HPP
diff --git a/CIAO/CCF/Example/CIDL/LocalExecutorMapping/cidlc.cpp b/CIAO/CCF/Example/CIDL/LocalExecutorMapping/cidlc.cpp
new file mode 100644
index 00000000000..633697c0641
--- /dev/null
+++ b/CIAO/CCF/Example/CIDL/LocalExecutorMapping/cidlc.cpp
@@ -0,0 +1,228 @@
+// file : CCF/Example/CIDL/LocalExecutorMapping/cidlc.cpp
+// author : Boris Kolpackov <boris@dre.vanderbilt.edu>
+// cvs-id : $Id$
+
+#include <vector>
+#include <iostream>
+
+#include "CCF/CompilerElements/Context.hpp"
+#include "CCF/CompilerElements/FileSystem.hpp"
+#include "CCF/CompilerElements/Diagnostic.hpp"
+#include "CCF/CompilerElements/TokenStream.hpp"
+#include "CCF/CompilerElements/Preprocessor.hpp"
+
+#include "CCF/CodeGenerationKit/CommandLine.hpp"
+#include "CCF/CodeGenerationKit/CommandLineParser.hpp"
+#include "CCF/CodeGenerationKit/CommandLineDescriptor.hpp"
+
+#include "CCF/CIDL/LexicalAnalyzer.hpp"
+#include "CCF/CIDL/Parser.hpp"
+#include "CCF/CIDL/SemanticGraph.hpp"
+#include "CCF/CIDL/SemanticAction/Impl/Factory.hpp"
+
+#include "ExecutorMappingGenerator.hpp"
+
+using std::cerr;
+using std::endl;
+
+using namespace CCF::CompilerElements;
+using namespace CCF::CIDL;
+using namespace CCF::CIDL::SemanticGraph;
+
+int
+main (int argc, char* argv[])
+{
+ try
+ {
+ // Parsing command line options and arguments
+ //
+ //
+ CommandLine cl;
+
+ if (!parse (argc, argv, cl))
+ {
+ cerr << "command line syntax error" << endl;
+ cerr << "try " << argv[0] << " --help for usage information" << endl;
+ return -1;
+ }
+
+ ExecutorMappingGenerator lem_gen;
+
+ if (cl.get_value ("help", false) || cl.get_value ("help-html", false))
+ {
+ CL::Description d (argv[0]);
+
+ lem_gen.options (d);
+
+ d.add_option (CL::OptionDescription (
+ "trace-semantic-actions",
+ "Turn on semnatic actions tracing facility.",
+ true));
+
+ d.add_option (CL::OptionDescription (
+ "preprocess-only",
+ "Run preprocessor only and output result to stdout.",
+ true));
+
+ d.add_option (CL::OptionDescription (
+ "help",
+ "Display usage information and exit.",
+ true));
+
+ d.add_option (CL::OptionDescription (
+ "help-html",
+ "Dump usage information in html format and exit.",
+ true));
+
+ d.add_argument ("cidl file");
+
+ if (cl.get_value ("help-html", false)) CL::print_html (cerr, d);
+ else CL::print_text (cerr, d);
+
+ return 0;
+ }
+
+ fs::ifstream ifs;
+ ifs.exceptions (ios_base::badbit | ios_base::failbit);
+
+ fs::path file_path;
+
+ CommandLine::ArgumentsIterator i = cl.arguments_begin ();
+
+ if (i != cl.arguments_end ())
+ {
+ try
+ {
+ file_path = fs::path (*i, fs::native);
+ ifs.open (file_path, std::ios_base::in);
+ }
+ catch (fs::filesystem_error const&)
+ {
+ cerr << *i << ": error: unable to open in read mode" << endl;
+ return -1;
+ }
+ catch (std::ios_base::failure const&)
+ {
+ cerr << *i << ": error: unable to open in read mode" << endl;
+ return -1;
+ }
+ }
+
+ //@@ for some reason ifs throws exception if I don't reset it to
+ // original state. It probably has something to do with call to
+ // get after eof.
+ ifs.exceptions (ios_base::iostate (0));
+
+ std::istream& is = ifs.is_open ()
+ ? static_cast<std::istream&> (ifs)
+ : static_cast<std::istream&> (std::cin);
+
+ InputStreamAdapter isa (is);
+ CPP::Preprocessor pp (isa);
+
+ if (cl.get_value ("preprocess-only", false))
+ {
+ while (true)
+ {
+ CPP::Token t (pp.next ());
+
+ if (t == CPP::Token::eos) break;
+
+ std::cout << t;
+ }
+ return 0;
+ }
+
+ //}
+
+ Diagnostic::Stream dout;
+
+ LexicalAnalyzer lexer (pp);
+
+ TokenList token_stream;
+
+ //@@ bad token comparison
+ for (TokenPtr token = lexer.next ();; token = lexer.next ())
+ {
+ //cerr << token << endl;
+ token_stream.push_back (token);
+ if (ReferenceCounting::strict_cast<EndOfStream> (token) != 0) break;
+ }
+
+ if (token_stream.size () < 2)
+ {
+ cerr << "no tokens produced so nothing to parse" << endl;
+ return 0;
+ }
+
+ TranslationUnit tu;
+
+ // Initialize compilation context.
+ //
+ CCF::CompilerElements::Context context;
+ context.set ("file-path", file_path);
+ context.set ("trace-semantic-action",
+ cl.get_value ("trace-semantic-actions", false));
+
+
+ // Extract include search paths.
+ //
+
+ std::vector<fs::path> include_paths;
+
+ for (CommandLine::OptionsIterator
+ i (cl.options_begin ()), e (cl.options_end ()); i != e; ++i)
+ {
+ if (i->name () == "I")
+ {
+ include_paths.push_back (fs::path (i->value (), fs::native));
+ }
+ else if (i->name ()[0] == 'I')
+ {
+ std::string opt (i->name ());
+ std::string path (opt.begin () + 1, opt.end ());
+ include_paths.push_back (fs::path (path, fs::native));
+ }
+ }
+
+ context.set ("include-search-paths", include_paths);
+
+ // Instantiate semantic actions factory.
+ //
+ SemanticAction::Impl::Factory actions (context, dout, tu);
+
+ Parser parser (context, dout, lexer, actions);
+
+ //@@ should be able to use CIDL here. Or better yet get rid of this
+ // function completely.
+ //
+ CCF::IDL2::Parsing::parse (token_stream.begin (),
+ token_stream.end (),
+ parser.start ());
+
+ if (dout.error_count () != 0) return -1;
+
+
+ // Generate executor mapping.
+ //
+ lem_gen.generate (cl, tu, file_path);
+
+ }
+ catch (std::bad_cast const&)
+ {
+ cerr << "bad cast exception" << endl;
+ }
+ catch (InvalidName const&)
+ {
+ cerr << "invalid name exception" << endl;
+ }
+ catch (std::exception const& e)
+ {
+ cerr << "caught standard exception " << e.what () << endl;
+ }
+ catch (...)
+ {
+ cerr << "caught unknown exception" << endl;
+ return -1;
+ }
+}
diff --git a/CIAO/CCF/Example/CIDL/LocalExecutorMapping/test-0.idl b/CIAO/CCF/Example/CIDL/LocalExecutorMapping/test-0.idl
new file mode 100644
index 00000000000..3c50f4acdd2
--- /dev/null
+++ b/CIAO/CCF/Example/CIDL/LocalExecutorMapping/test-0.idl
@@ -0,0 +1,21 @@
+// file : CCF/Example/CIDL/LocalExecutorMapping/test-0.idl
+// author : Boris Kolpackov <boris@dre.vanderbilt.edu>
+// cvs-id : $Id$
+
+module Empty
+{
+ interface I
+ {
+ };
+};
+
+module M
+{
+ interface I {};
+
+ typedef I Internal;
+
+ //local interface CCM_I : I {};
+};
+
+eventtype E {};
diff --git a/CIAO/CCF/Example/CIDL/LocalExecutorMapping/test-0_exec.idl.orig b/CIAO/CCF/Example/CIDL/LocalExecutorMapping/test-0_exec.idl.orig
new file mode 100644
index 00000000000..2fd8758f67e
--- /dev/null
+++ b/CIAO/CCF/Example/CIDL/LocalExecutorMapping/test-0_exec.idl.orig
@@ -0,0 +1,6 @@
+module M
+{
+ local interface CCM_I : I
+ {
+ };
+};
diff --git a/CIAO/CCF/Example/CIDL/LocalExecutorMapping/test-1.idl b/CIAO/CCF/Example/CIDL/LocalExecutorMapping/test-1.idl
new file mode 100644
index 00000000000..0a437cb0320
--- /dev/null
+++ b/CIAO/CCF/Example/CIDL/LocalExecutorMapping/test-1.idl
@@ -0,0 +1,23 @@
+// file : CCF/Example/CIDL/LocalExecutorMapping/test-1.idl
+// author : Boris Kolpackov <boris@dre.vanderbilt.edu>
+// cvs-id : $Id$
+
+#include <Components.idl>
+#include "test-0.idl"
+
+module M1
+{
+ interface Blah;
+ interface Fool {};
+
+ component C1
+ {
+ provides M::I i;
+ readonly attribute long l;
+ };
+
+ home H1 manages C1
+ {
+ attribute M::I i;
+ };
+};
diff --git a/CIAO/CCF/Example/CIDL/LocalExecutorMapping/test-1_exec.idl.orig b/CIAO/CCF/Example/CIDL/LocalExecutorMapping/test-1_exec.idl.orig
new file mode 100644
index 00000000000..e0a244db6eb
--- /dev/null
+++ b/CIAO/CCF/Example/CIDL/LocalExecutorMapping/test-1_exec.idl.orig
@@ -0,0 +1,33 @@
+#include <Components.idl>
+#include "test-0.idl"
+module M
+{
+ local interface CCM_I : I
+ {
+ };
+};
+module M1
+{
+ local interface CCM_Fool : Fool
+ {
+ };
+ local interface CCM_C1 : ::Components::EnterpriseComponent
+ {
+ ::M::CCM_I get_i ();
+ readonly attribute long l;
+ };
+ local interface CCM_C1_Context : ::Components::SessionContext
+ {
+ };
+ local interface CCM_H1Implicit
+ {
+ ::Components::EnterpriseComponent create () raises (::Components::CCMException);
+ };
+ local interface CCM_H1Explicit : ::Components::HomeExecutorBase
+ {
+ attribute ::M::I i;
+ };
+ local interface CCM_H1 : CCM_H1Explicit, CCM_H1Implicit
+ {
+ };
+};
diff --git a/CIAO/CCF/Example/CIDL/LocalExecutorMapping/test-2.cidl b/CIAO/CCF/Example/CIDL/LocalExecutorMapping/test-2.cidl
new file mode 100644
index 00000000000..34e635a9b43
--- /dev/null
+++ b/CIAO/CCF/Example/CIDL/LocalExecutorMapping/test-2.cidl
@@ -0,0 +1,18 @@
+// file : CCF/Example/CIDL/LocalExecutorMapping/test-2.cidl
+// author : Boris Kolpackov <boris@dre.vanderbilt.edu>
+// cvs-id : $Id$
+
+#include "test-2.idl"
+
+module M3
+{
+ composition session Impl
+ {
+ home executor HImpl
+ {
+ implements M2::H2;
+ manages CImpl;
+ };
+ };
+};
+
diff --git a/CIAO/CCF/Example/CIDL/LocalExecutorMapping/test-2.idl b/CIAO/CCF/Example/CIDL/LocalExecutorMapping/test-2.idl
new file mode 100644
index 00000000000..51bf3d88a4b
--- /dev/null
+++ b/CIAO/CCF/Example/CIDL/LocalExecutorMapping/test-2.idl
@@ -0,0 +1,74 @@
+// file : CCF/Example/CIDL/LocalExecutorMapping/test-2.idl
+// author : Boris Kolpackov <boris@dre.vanderbilt.edu>
+// cvs-id : $Id$
+
+#include "test-1.idl"
+
+interface Goof {};
+
+module M2
+{
+
+ interface I {};
+ interface J {};
+
+ eventtype E supports I, J
+ {
+ factory new (in string name);
+ public string name;
+ };
+
+ valuetype V
+ {
+ public long l;
+ };
+
+ component C2 : M1::C1 supports I, J
+ {
+ provides Goof pg;
+ uses Goof ug;
+
+ publishes E pe;
+ emits E me;
+ consumes E ce;
+ };
+
+ typedef sequence<octet> OctetSeq;
+
+ struct S
+ {
+ long l;
+ OctetSeq octet_seq;
+ };
+
+ typedef sequence<S> S_Seq;
+
+ exception Ex1
+ {
+ string descr;
+ };
+
+ exception Ex2
+ {
+ };
+
+ home H2 : M1::H1 supports I, J manages C2
+ {
+ readonly attribute long rl;
+ readonly attribute M::I rai;
+ attribute OctetSeq seq;
+ attribute S_Seq a_s_seq;
+
+ void
+ foo (in long l,
+ inout boolean b,
+ out long ol,
+ in M::I i,
+ out unsigned long long ull,
+ inout S_Seq s_seq,
+ in V v) raises (Ex1, Ex2);
+
+ factory new (in long l, in OctetSeq s) raises (Ex2, Ex1);
+ finder find (in long l, in OctetSeq s) raises (Ex1, Ex2);
+ };
+};
diff --git a/CIAO/CCF/Example/CIDL/LocalExecutorMapping/test-2_exec.idl.orig b/CIAO/CCF/Example/CIDL/LocalExecutorMapping/test-2_exec.idl.orig
new file mode 100644
index 00000000000..3719ecd82d2
--- /dev/null
+++ b/CIAO/CCF/Example/CIDL/LocalExecutorMapping/test-2_exec.idl.orig
@@ -0,0 +1,72 @@
+#include "test-2.idl"
+module M
+{
+ local interface CCM_I : I
+ {
+ };
+};
+module M1
+{
+ local interface CCM_C1 : ::Components::EnterpriseComponent
+ {
+ ::M::CCM_I get_i ();
+ readonly attribute long l;
+ };
+ local interface CCM_C1_Context : ::Components::SessionContext
+ {
+ };
+ local interface CCM_H1Implicit
+ {
+ ::Components::EnterpriseComponent create () raises (::Components::CCMException);
+ };
+ local interface CCM_H1Explicit : ::Components::HomeExecutorBase
+ {
+ attribute ::M::I i;
+ };
+ local interface CCM_H1 : CCM_H1Explicit, CCM_H1Implicit
+ {
+ };
+};
+local interface CCM_Goof : Goof
+{
+};
+module M2
+{
+ local interface CCM_C2 : ::M1::CCM_C1, ::M2::I, ::M2::J
+ {
+ ::CCM_Goof get_pg ();
+ void push_ce (in ::M2::E e);
+ };
+ local interface CCM_C2_Context : ::M1::CCM_C1_Context
+ {
+ ::Goof get_connection_ug ();
+ void push_pe (in ::M2::E e);
+ void push_me (in ::M2::E e);
+ };
+ local interface CCM_H2Implicit
+ {
+ ::Components::EnterpriseComponent create () raises (::Components::CCMException);
+ };
+ local interface CCM_H2Explicit : ::M1::CCM_H1Explicit, ::M2::I, ::M2::J
+ {
+ readonly attribute long rl;
+ readonly attribute ::M::I rai;
+ attribute ::M2::OctetSeq seq;
+ attribute ::M2::S_Seq a_s_seq;
+ void foo (in long l, inout boolean b, out long ol, in ::M::I i, out unsigned long long ull, inout ::M2::S_Seq s_seq, in ::M2::V v) raises (::M2::Ex1, ::M2::Ex2);
+ ::Components::EnterpriseComponent new (in long l, in ::M2::OctetSeq s) raises (::M2::Ex2, ::M2::Ex1);
+ ::Components::EnterpriseComponent find (in long l, in ::M2::OctetSeq s) raises (::M2::Ex1, ::M2::Ex2);
+ };
+ local interface CCM_H2 : CCM_H2Explicit, CCM_H2Implicit
+ {
+ };
+};
+module M3
+{
+ module Impl
+ {
+ local interface CImplContext
+ {
+ };
+ };
+};
diff --git a/CIAO/CCF/Example/CodeGenerationKit/Indentation/IDL/indent_idl.cpp b/CIAO/CCF/Example/CodeGenerationKit/Indentation/IDL/indent_idl.cpp
new file mode 100644
index 00000000000..ce0c5eb103c
--- /dev/null
+++ b/CIAO/CCF/Example/CodeGenerationKit/Indentation/IDL/indent_idl.cpp
@@ -0,0 +1,25 @@
+// file : CCF/Example/CodeGenerationKit/Indentation/IDL/indent_idl.cpp
+// author : Boris Kolpackov <boris@dre.vanderbilt.edu>
+// cvs-id : $Id$
+
+#include "CCF/CodeGenerationKit/IndentationIDL.hpp"
+#include "CCF/CodeGenerationKit/IndentationImplanter.hpp"
+
+#include <iostream>
+
+using std::cout;
+using std::endl;
+
+int
+main ()
+{
+ Indentation::Implanter<Indentation::IDL> guard (cout);
+
+ cout << "const string s = \"Hello \\\"world;\";";
+ cout << "const char c1 = \'\\\'\';";
+ cout << "const char c2 = \';\';";
+
+ cout << "interface I {"
+ << "void foo ();"
+ << "};";
+}
diff --git a/CIAO/CCF/Example/CodeGenerationKit/Indentation/XML/indent_xml.cpp b/CIAO/CCF/Example/CodeGenerationKit/Indentation/XML/indent_xml.cpp
new file mode 100644
index 00000000000..f244249c69b
--- /dev/null
+++ b/CIAO/CCF/Example/CodeGenerationKit/Indentation/XML/indent_xml.cpp
@@ -0,0 +1,32 @@
+// file : CCF/Example/CodeGenerationKit/Indentation/IDL/indent_idl.cpp
+// author : Boris Kolpackov <boris@dre.vanderbilt.edu>
+// cvs-id : $Id$
+
+#include "CCF/CodeGenerationKit/IndentationXML.hpp"
+#include "CCF/CodeGenerationKit/IndentationImplanter.hpp"
+
+#include <iostream>
+
+using std::cout;
+using std::endl;
+
+int
+main ()
+{
+ Indentation::Implanter<Indentation::XML> guard (cout);
+
+ cout << "<?xml version=\"1.0\"?>" << endl;
+ cout << "<!DOCTYPE corbacomponent SYSYEM \"corbacomponent.dtd\">" << endl << endl;
+
+ cout << "<atag>whatever</atag>" << endl;
+
+ cout << "<open>" << endl;
+ cout << "<openother>" << endl;
+ cout << "<openother \nlabel=\"<<<<<<<<<>><>\">" << endl;
+ cout << "text" << endl;
+ cout << "<taginitself/>" << endl;
+ cout << "</openother>" << endl;
+ cout << "</openother>" << endl;
+ cout << "</open>" << endl;
+
+}
diff --git a/CIAO/CCF/Example/ComponentDeploymentDescriptor/SyntaxTree.cpp b/CIAO/CCF/Example/ComponentDeploymentDescriptor/SyntaxTree.cpp
new file mode 100644
index 00000000000..0a7a3ae6bf2
--- /dev/null
+++ b/CIAO/CCF/Example/ComponentDeploymentDescriptor/SyntaxTree.cpp
@@ -0,0 +1,113 @@
+// file : CCF/Example/ComponentDeploymentDescriptor/SyntaxTree.cpp
+// author : Boris Kolpackov <boris@dre.vanderbilt.edu>
+// cvs-id : $Id$
+
+#include "SyntaxTree.hpp"
+
+using namespace Introspection;
+
+namespace CDD
+{
+ namespace SyntaxTree
+ {
+ // Node
+ //
+ //
+ namespace
+ {
+ TypeInfo
+ node_init_ ()
+ {
+ TypeInfo ti (typeid (Node));
+ // I don't really need this information
+ // ti.add_base (Access::PUBLIC, true, Object::static_type_info ());
+ return ti;
+ }
+
+ TypeInfo node_ (node_init_ ());
+ }
+
+ TypeInfo const& Node::
+ static_type_info () { return node_; }
+
+
+ // PortInstance
+ //
+ //
+ namespace
+ {
+ TypeInfo
+ port_instance_init_ ()
+ {
+ TypeInfo ti (typeid (PortInstance));
+ ti.add_base (Access::PUBLIC, true, Node::static_type_info ());
+ return ti;
+ }
+
+ TypeInfo port_instance_ (port_instance_init_ ());
+ }
+
+ TypeInfo const& PortInstance::
+ static_type_info () { return port_instance_; }
+
+
+ // ComponentInstance
+ //
+ //
+ namespace
+ {
+ TypeInfo
+ component_instance_init_ ()
+ {
+ TypeInfo ti (typeid (ComponentInstance));
+ ti.add_base (Access::PUBLIC, true, Node::static_type_info ());
+ return ti;
+ }
+
+ TypeInfo component_instance_ (component_instance_init_ ());
+ }
+
+ TypeInfo const& ComponentInstance::
+ static_type_info () { return component_instance_; }
+
+
+ // Connection
+ //
+ //
+ namespace
+ {
+ TypeInfo
+ connection_init_ ()
+ {
+ TypeInfo ti (typeid (Connection));
+ ti.add_base (Access::PUBLIC, true, Node::static_type_info ());
+ return ti;
+ }
+
+ TypeInfo connection_ (connection_init_ ());
+ }
+
+ TypeInfo const& Connection::
+ static_type_info () { return connection_; }
+
+
+ // Descriptor
+ //
+ //
+ namespace
+ {
+ TypeInfo
+ descriptor_init_ ()
+ {
+ TypeInfo ti (typeid (Descriptor));
+ ti.add_base (Access::PUBLIC, true, Node::static_type_info ());
+ return ti;
+ }
+
+ TypeInfo descriptor_ (descriptor_init_ ());
+ }
+
+ TypeInfo const& Descriptor::
+ static_type_info () { return descriptor_; }
+ }
+}
diff --git a/CIAO/CCF/Example/ComponentDeploymentDescriptor/SyntaxTree.hpp b/CIAO/CCF/Example/ComponentDeploymentDescriptor/SyntaxTree.hpp
new file mode 100644
index 00000000000..3739826b27d
--- /dev/null
+++ b/CIAO/CCF/Example/ComponentDeploymentDescriptor/SyntaxTree.hpp
@@ -0,0 +1,286 @@
+// file : CCF/Example/ComponentDeploymentDescriptor/SyntaxTree.hpp
+// author : Boris Kolpackov <boris@dre.vanderbilt.edu>
+// cvs-id : $Id$
+
+#ifndef CDD_SYNTAX_TREE_HPP
+#define CDD_SYNTAX_TREE_HPP
+
+#include <set>
+#include <vector>
+#include <string>
+
+
+#include "CCF/CompilerElements/ReferenceCounting.hpp"
+#include "CCF/CompilerElements/Introspection.hpp"
+
+namespace CDD
+{
+ namespace SyntaxTree
+ {
+ using ReferenceCounting::StrictPtr;
+
+ //
+ //
+ //
+ class Node;
+
+ typedef
+ StrictPtr<Node>
+ NodePtr;
+
+ class Node : public virtual Introspection::Object,
+ public virtual ReferenceCounting::DefaultImpl <>
+ {
+ protected:
+ virtual
+ ~Node () throw () {}
+
+ Node ()
+ {
+ type_info (static_type_info ());
+ }
+
+ public:
+ template <typename Type>
+ StrictPtr<Type>
+ dynamic_type ()
+ {
+ NodePtr self (ReferenceCounting::add_ref (this));
+ return ReferenceCounting::strict_cast<Type>(self);
+ }
+
+ public:
+ static Introspection::TypeInfo const&
+ static_type_info ();
+ };
+
+ typedef
+ std::vector<NodePtr>
+ NodeList;
+
+
+ //
+ //
+ //
+ class PortInstance : public virtual Node
+ {
+ public:
+
+ virtual
+ ~PortInstance () throw () {}
+
+ PortInstance (std::string name)
+ : name_ (name)
+ {
+ type_info (static_type_info ());
+ }
+
+ public:
+ std::string
+ name () const
+ {
+ return name_;
+ }
+
+ public:
+ static Introspection::TypeInfo const&
+ static_type_info ();
+
+ private:
+ std::string name_;
+ };
+
+ typedef
+ StrictPtr<PortInstance>
+ PortInstancePtr;
+
+ template <typename T>
+ struct NameComparator
+ {
+ bool
+ operator () (T const& x, T const& y) const
+ {
+ return x->name () < y->name ();
+ }
+ };
+
+ typedef
+ std::set<PortInstancePtr, NameComparator<PortInstancePtr> >
+ PortInstanceSet;
+
+
+ //
+ //
+ //
+ class ComponentInstance : public virtual Node
+ {
+ public:
+ typedef
+ PortInstanceSet::const_iterator
+ Iterator;
+
+ public:
+
+ virtual
+ ~ComponentInstance () throw () {}
+
+ ComponentInstance (std::string name,
+ std::string type)
+ : name_ (name),
+ type_ (type)
+ {
+ type_info (static_type_info ());
+ }
+
+ public:
+
+ std::string
+ name () const
+ {
+ return name_;
+ }
+
+ std::string
+ type () const
+ {
+ return type_;
+ }
+
+ public:
+ class AlreadyExist {};
+
+ void
+ insert (PortInstancePtr const& d) throw (AlreadyExist)
+ {
+ if (!ports_.insert (d).second) throw AlreadyExist ();
+ }
+
+ Iterator
+ begin () const
+ {
+ return ports_.begin ();
+ }
+
+
+ Iterator
+ end () const
+ {
+ return ports_.end ();
+ }
+
+ public:
+ static Introspection::TypeInfo const&
+ static_type_info ();
+
+ private:
+ std::string name_;
+ std::string type_;
+
+ PortInstanceSet ports_;
+ };
+
+ typedef
+ StrictPtr<ComponentInstance>
+ ComponentInstancePtr;
+
+
+ //
+ //
+ //
+ class Connection : public virtual Node
+ {
+ public:
+ virtual
+ ~Connection () throw () {}
+
+ Connection (PortInstancePtr const& left,
+ PortInstancePtr const& right)
+ : left_ (left),
+ right_ (right)
+ {
+ type_info (static_type_info ());
+ }
+
+ public:
+
+ PortInstancePtr
+ left () const
+ {
+ return left_;
+ }
+
+ PortInstancePtr
+ right () const
+ {
+ return right_;
+ }
+
+ public:
+ static Introspection::TypeInfo const&
+ static_type_info ();
+
+ private:
+ PortInstancePtr left_;
+ PortInstancePtr right_;
+ };
+
+ typedef
+ StrictPtr<Connection>
+ ConnectionPtr;
+
+
+ //
+ //
+ //
+ class Descriptor : public virtual Node
+ {
+ public:
+ typedef
+ NodeList::const_iterator
+ Iterator;
+
+ public:
+ virtual
+ ~Descriptor () throw () {}
+
+ Descriptor ()
+ {
+ type_info (static_type_info ());
+ }
+
+ public:
+ void
+ insert (NodePtr const& n)
+ {
+ nodes_.push_back (n);
+ }
+
+ Iterator
+ begin () const
+ {
+ return nodes_.begin ();
+ }
+
+
+ Iterator
+ end () const
+ {
+ return nodes_.end ();
+ }
+
+ public:
+ static Introspection::TypeInfo const&
+ static_type_info ();
+
+ private:
+ NodeList nodes_;
+ };
+
+ typedef
+ StrictPtr<Descriptor>
+ DescriptorPtr;
+ }
+}
+
+
+#endif // CDD_SYNTAX_TREE_HPP
diff --git a/CIAO/CCF/Example/ComponentDeploymentDescriptor/Traversal.cpp b/CIAO/CCF/Example/ComponentDeploymentDescriptor/Traversal.cpp
new file mode 100644
index 00000000000..8f6a20649bc
--- /dev/null
+++ b/CIAO/CCF/Example/ComponentDeploymentDescriptor/Traversal.cpp
@@ -0,0 +1,112 @@
+// file : CCF/Example/ComponentDeploymentDescriptor/Traversal.cpp
+// author : Boris Kolpackov <boris@dre.vanderbilt.edu>
+// cvs-id : $Id$
+
+#include "Traversal.hpp"
+
+using namespace Introspection;
+
+namespace CDD
+{
+ 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::NodePtr const& n)
+ {
+ LevelMap levels;
+
+ unsigned long max = compute_levels (n->type_info (), 0, levels);
+
+ //cerr << "starting dispatch process for "
+ // << n->type_info ().type_id () << " with "
+ // << max << " levels" << endl;
+
+ 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.suppressed))
+ {
+ //cerr << "dispatching traverser for "
+ // << n->type_info ().type_id () << " as "
+ // << i->first.type_id () << endl;
+
+ v->second.traverser->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);
+ }
+ }
+ }
+ }
+}
diff --git a/CIAO/CCF/Example/ComponentDeploymentDescriptor/Traversal.hpp b/CIAO/CCF/Example/ComponentDeploymentDescriptor/Traversal.hpp
new file mode 100644
index 00000000000..2b6697abae9
--- /dev/null
+++ b/CIAO/CCF/Example/ComponentDeploymentDescriptor/Traversal.hpp
@@ -0,0 +1,386 @@
+// file : CCF/Example/ComponentDeploymentDescriptor/Traversal.hpp
+// author : Boris Kolpackov <boris@dre.vanderbilt.edu>
+// cvs-id : $Id$
+
+#ifndef CDD_TRAVERSAL_HPP
+#define CDD_TRAVERSAL_HPP
+
+#include <map>
+#include <vector>
+
+#include "CCF/CompilerElements/Introspection.hpp"
+
+#include "SyntaxTree.hpp"
+
+namespace CDD
+{
+ namespace Traversal
+ {
+ //
+ //
+ //
+ class TraverserInterface
+ {
+ protected:
+ virtual
+ ~TraverserInterface ()
+ {
+ }
+
+ virtual void
+ traverse (SyntaxTree::NodePtr const& n) = 0;
+
+ friend class Dispatcher;
+ };
+
+
+ //
+ //
+ //
+ class Dispatcher
+ {
+ public:
+ virtual
+ ~Dispatcher ()
+ {
+ }
+
+ virtual void
+ dispatch (SyntaxTree::NodePtr const& n);
+
+ protected:
+
+ class Ambiguous {};
+
+ void
+ map (Introspection::TypeId id,
+ TraverserInterface* t,
+ bool suppress_ambiguity = false)
+ throw (Ambiguous)
+ {
+ if (!traversal_map_.insert (std::make_pair (id, t)).second)
+ {
+ if (suppress_ambiguity)
+ {
+ traversal_map_[id].suppressed = true;
+ }
+ else
+ {
+ throw Ambiguous ();
+ }
+ }
+ }
+
+ private:
+
+ struct TraverserDescriptor
+ {
+ TraverserDescriptor (TraverserInterface* t = 0)
+ : traverser (t),
+ suppressed (false)
+ {
+ }
+
+ TraverserInterface* traverser;
+ bool suppressed;
+ };
+
+ typedef
+ std::map<Introspection::TypeId, TraverserDescriptor>
+ TraversalMap;
+
+ public:
+ typedef
+ TraversalMap::const_iterator
+ Iterator;
+
+ Iterator
+ begin () const
+ {
+ return traversal_map_.begin ();
+ }
+
+ Iterator
+ end () const
+ {
+ return traversal_map_.end ();
+ }
+
+ private:
+ TraversalMap traversal_map_;
+ };
+
+
+ //
+ //
+ //
+ class Discriminator : public virtual Dispatcher
+ {
+ public:
+ virtual void
+ add (Dispatcher* d) throw (Ambiguous)
+ {
+ for (Iterator i = d->begin (); i != d->end (); i++)
+ {
+ map (i->first, i->second.traverser, true);
+ }
+ }
+ };
+
+
+ //
+ //
+ //
+ class Traverser : public TraverserInterface,
+ public virtual Dispatcher
+ {
+ public:
+ virtual void
+ add_delegate (Dispatcher* d)
+ {
+ delegates_.push_back (d);
+ }
+
+ protected:
+ virtual bool
+ delegate (SyntaxTree::NodePtr const& n) const
+ {
+ if (delegates_.empty ()) return false;
+
+ for (DispatcherList::const_iterator i = delegates_.begin ();
+ i != delegates_.end ();
+ i++)
+ {
+ (*i)->dispatch (n);
+ }
+
+ return true;
+ }
+
+ protected:
+ typedef
+ std::vector<Dispatcher*>
+ DispatcherList;
+
+ DispatcherList delegates_;
+ };
+
+
+ //
+ //
+ //
+ struct PortInstance : Traverser
+ {
+ typedef
+ SyntaxTree::PortInstancePtr
+ NodePtr;
+
+ PortInstance ()
+ {
+ map (typeid (SyntaxTree::PortInstance), this);
+ }
+
+ virtual void
+ traverse (SyntaxTree::NodePtr const& n)
+ {
+ traverse (n->dynamic_type<SyntaxTree::PortInstance> ());
+ }
+
+ virtual void
+ traverse (NodePtr const& n)
+ {
+ delegate (n);
+ }
+ };
+
+
+ //
+ //
+ //
+ struct ComponentInstance : Traverser
+ {
+ public:
+
+ virtual void
+ add_port_delegate (Dispatcher* d)
+ {
+ port_delegates_.push_back (d);
+ }
+
+ public:
+ typedef
+ SyntaxTree::ComponentInstancePtr
+ NodePtr;
+
+ ComponentInstance ()
+ {
+ map (typeid (SyntaxTree::ComponentInstance), this);
+ }
+
+ virtual void
+ traverse (SyntaxTree::NodePtr const& n)
+ {
+ traverse (n->dynamic_type<SyntaxTree::ComponentInstance> ());
+ }
+
+ virtual void
+ traverse (NodePtr const& n)
+ {
+ if (!delegate (n))
+ {
+ pre (n);
+ ports (n);
+ post (n);
+ }
+ }
+
+ virtual void
+ pre (NodePtr const&)
+ {
+ }
+
+ virtual void
+ ports (NodePtr const& n)
+ {
+ delegate_port (n);
+ }
+
+ virtual void
+ post (NodePtr const&)
+ {
+ }
+
+ protected:
+ virtual void
+ delegate_port (NodePtr const& s)
+ {
+ for (SyntaxTree::ComponentInstance::Iterator n = s->begin ();
+ n != s->end ();
+ n++)
+ {
+ dispatch (*n);
+
+ for (DispatcherList::const_iterator i = port_delegates_.begin ();
+ i != port_delegates_.end ();
+ i++)
+ {
+ (*i)->dispatch (*n);
+ }
+ }
+ }
+
+ protected:
+ DispatcherList port_delegates_;
+ };
+
+
+ //
+ //
+ //
+ struct Connection : Traverser
+ {
+ typedef
+ SyntaxTree::ConnectionPtr
+ NodePtr;
+
+ Connection ()
+ {
+ map (typeid (SyntaxTree::Connection), this);
+ }
+
+ virtual void
+ traverse (SyntaxTree::NodePtr const& n)
+ {
+ traverse (n->dynamic_type<SyntaxTree::Connection> ());
+ }
+
+ virtual void
+ traverse (NodePtr const& n)
+ {
+ delegate (n);
+ }
+ };
+
+
+ //
+ //
+ //
+ struct Descriptor : Traverser
+ {
+ public:
+
+ virtual void
+ add_node_delegate (Dispatcher* d)
+ {
+ node_delegates_.push_back (d);
+ }
+
+ public:
+ typedef
+ SyntaxTree::DescriptorPtr
+ NodePtr;
+
+ Descriptor ()
+ {
+ map (typeid (SyntaxTree::Descriptor), this);
+ }
+
+ virtual void
+ traverse (SyntaxTree::NodePtr const& n)
+ {
+ traverse (n->dynamic_type<SyntaxTree::Descriptor> ());
+ }
+
+ virtual void
+ traverse (NodePtr const& n)
+ {
+ if (!delegate (n))
+ {
+ pre (n);
+ ports (n);
+ post (n);
+ }
+ }
+
+ virtual void
+ pre (NodePtr const&)
+ {
+ }
+
+ virtual void
+ ports (NodePtr const& n)
+ {
+ delegate_node (n);
+ }
+
+ virtual void
+ post (NodePtr const&)
+ {
+ }
+
+ protected:
+ virtual void
+ delegate_node (NodePtr const& s)
+ {
+ for (SyntaxTree::Descriptor::Iterator n = s->begin ();
+ n != s->end ();
+ n++)
+ {
+ dispatch (*n);
+
+ for (DispatcherList::const_iterator i = node_delegates_.begin ();
+ i != node_delegates_.end ();
+ i++)
+ {
+ (*i)->dispatch (*n);
+ }
+ }
+ }
+
+ protected:
+ DispatcherList node_delegates_;
+ };
+ }
+}
+
+#endif // CDD_TRAVERSAL_HPP
diff --git a/CIAO/CCF/Example/ComponentDeploymentDescriptor/cdd.cpp b/CIAO/CCF/Example/ComponentDeploymentDescriptor/cdd.cpp
new file mode 100644
index 00000000000..737260014bc
--- /dev/null
+++ b/CIAO/CCF/Example/ComponentDeploymentDescriptor/cdd.cpp
@@ -0,0 +1,144 @@
+// file : CCF/Example/ComponentDeploymentDescriptor/cdd.cpp
+// author : Boris Kolpackov <boris@dre.vanderbilt.edu>
+// cvs-id : $Id$
+
+#include <iostream>
+
+#include "CCF/CodeGenerationKit/IndentationXML.hpp"
+#include "CCF/CodeGenerationKit/IndentationImplanter.hpp"
+
+#include "SyntaxTree.hpp"
+#include "Traversal.hpp"
+
+using std::cout;
+using std::cerr;
+using std::endl;
+
+using namespace CDD;
+
+/*
+struct CI_Emitter : public virtual Traversal::ComponentInstance
+{
+ virtual void
+ pre (NodePtr const& n)
+ {
+ cout << "component instance " << n->name () << " of type "
+ << n->type () << endl << "{" << endl;
+
+ }
+
+ virtual void
+ post (NodePtr const& n)
+ {
+ cout << "}" << endl;
+ }
+
+};
+
+struct PI_Emitter : public virtual Traversal::PortInstance
+{
+ virtual void
+ traverse (NodePtr const& n)
+ {
+ cout << " port " << n->name () << ";" << endl;
+ }
+};
+
+struct C_Emitter : public virtual Traversal::Connection
+{
+ virtual void
+ traverse (NodePtr const& n)
+ {
+ cout << "connection " << n->left ()->name ()
+ << "<--->" << n->right ()->name () << ";" << endl;
+ }
+};
+
+*/
+
+
+struct CI_Emitter : public virtual Traversal::ComponentInstance
+{
+ virtual void
+ pre (NodePtr const& n)
+ {
+ cout << "<ComponentInstance name=\"" << n->name () << "\" type=\""
+ << n->type () << "\" >" << endl;
+
+ }
+
+ virtual void
+ post (NodePtr const& n)
+ {
+ cout << "</ComponentInstance>" << endl << endl;
+ }
+
+};
+
+struct PI_Emitter : public virtual Traversal::PortInstance
+{
+ virtual void
+ traverse (NodePtr const& n)
+ {
+ cout << "<Port name=\"" << n->name () << "\" />" << endl;
+ }
+};
+
+struct C_Emitter : public virtual Traversal::Connection
+{
+ virtual void
+ traverse (NodePtr const& n)
+ {
+ cout << "<Connection left=\"" << n->left ()->name () << "\" "
+ << "right=\"" << n->right ()->name () << "\" />" << endl;
+ }
+};
+
+
+int
+main ()
+{
+ using namespace SyntaxTree;
+
+ try
+ {
+ // Construct tree
+
+ DescriptorPtr d (new Descriptor);
+
+ PortInstancePtr ap (new PortInstance ("ap"));
+ ComponentInstancePtr a (new ComponentInstance ("a", "A"));
+ a->insert (ap);
+ d->insert (a);
+
+ PortInstancePtr bp (new PortInstance ("bp"));
+ ComponentInstancePtr b (new ComponentInstance ("b", "B"));
+ b->insert (bp);
+ d->insert (b);
+
+ ConnectionPtr c (new Connection (ap, bp));
+ d->insert (c);
+
+ // Construct Traverser
+
+ Traversal::Descriptor dt;
+
+ CI_Emitter cie;
+ PI_Emitter pie;
+ cie.add_port_delegate (&pie);
+
+ C_Emitter ce;
+
+ dt.add_node_delegate (&cie);
+ dt.add_node_delegate (&ce);
+
+ // Set auto-indentation for cout
+ Indentation::Implanter<Indentation::XML> guard (cout);
+
+ dt.traverse (d);
+ }
+ catch (...)
+ {
+ cerr << "caught something" << endl;
+ }
+}
diff --git a/CIAO/CCF/Example/IDL2/CxxMapping/Generator.cpp b/CIAO/CCF/Example/IDL2/CxxMapping/Generator.cpp
new file mode 100644
index 00000000000..6645b7f0b67
--- /dev/null
+++ b/CIAO/CCF/Example/IDL2/CxxMapping/Generator.cpp
@@ -0,0 +1,32 @@
+// file : Example/IDL2/CxxMapping/Generator.cpp
+// author : Boris Kolpackov <boris@dre.vanderbilt.edu>
+// cvs-id : $Id$
+
+#include "Generator.hpp"
+#include "GeneratorImpl.hpp"
+
+namespace IDL2
+{
+ Generator::
+ ~Generator ()
+ {
+ }
+
+ Generator::
+ Generator ()
+ : pimpl_ (new GeneratorImpl), impl_ (*pimpl_)
+ {
+ }
+
+ Generator::
+ Generator (GeneratorImpl& gi)
+ : pimpl_ (), impl_ (gi)
+ {
+ }
+
+ void Generator::
+ generate (CCF::IDL2::SemanticGraph::TranslationUnit& tu)
+ {
+ impl_.generate (tu);
+ }
+}
diff --git a/CIAO/CCF/Example/IDL2/CxxMapping/Generator.hpp b/CIAO/CCF/Example/IDL2/CxxMapping/Generator.hpp
new file mode 100644
index 00000000000..4e231267dae
--- /dev/null
+++ b/CIAO/CCF/Example/IDL2/CxxMapping/Generator.hpp
@@ -0,0 +1,34 @@
+// file : Example/IDL2/CxxMapping/Generator.hpp
+// author : Boris Kolpackov <boris@dre.vanderbilt.edu>
+// cvs-id : $Id$
+
+#ifndef EXAMPLE_IDL2_CXX_MAPPING_GENERATOR_HPP
+#define EXAMPLE_IDL2_CXX_MAPPING_GENERATOR_HPP
+
+#include <memory>
+
+#include "CCF/IDL2/SemanticGraph.hpp"
+
+namespace IDL2
+{
+ class GeneratorImpl;
+
+ class Generator
+ {
+ public:
+ ~Generator ();
+ Generator ();
+
+ void
+ generate (CCF::IDL2::SemanticGraph::TranslationUnit& tu);
+
+ protected:
+ Generator (GeneratorImpl&);
+
+ protected:
+ std::auto_ptr<GeneratorImpl> pimpl_;
+ GeneratorImpl& impl_;
+ };
+}
+
+#endif // EXAMPLE_IDL2_CXX_MAPPING_GENERATOR_HPP
diff --git a/CIAO/CCF/Example/IDL2/CxxMapping/GeneratorImpl.hpp b/CIAO/CCF/Example/IDL2/CxxMapping/GeneratorImpl.hpp
new file mode 100644
index 00000000000..f5e6edc3e77
--- /dev/null
+++ b/CIAO/CCF/Example/IDL2/CxxMapping/GeneratorImpl.hpp
@@ -0,0 +1,533 @@
+// file : Example/IDL2/CxxMapping/GeneratorImpl.hpp
+// author : Boris Kolpackov <boris@dre.vanderbilt.edu>
+// cvs-id : $Id$
+
+#ifndef EXAMPLE_IDL2_CXX_MAPPING_GENERATOR_IMPL_HPP
+#define EXAMPLE_IDL2_CXX_MAPPING_GENERATOR_IMPL_HPP
+
+#include <iostream>
+
+#include "CCF/CodeGenerationKit/IndentationCxx.hpp"
+#include "CCF/CodeGenerationKit/IndentationImplanter.hpp"
+
+#include "CCF/IDL2/SemanticGraph.hpp"
+#include "CCF/IDL2/Traversal.hpp"
+
+namespace IDL2
+{
+ using namespace CCF::IDL2;
+
+ using std::cout;
+ using std::endl;
+
+ struct Inhibitor
+ {
+ virtual void
+ operator() () const = 0;
+ };
+
+ template <typename O, typename S, typename T>
+ class InhibitorTemplate : public Inhibitor
+ {
+ public:
+ typedef void (O::*F) (S&, T&);
+
+ InhibitorTemplate (O& o, F f, S& s, T& t)
+ : o_ (o), f_ (f), s_ (s), t_ (t)
+ {
+ }
+
+ virtual void
+ operator() () const
+ {
+ (o_.*f_)(s_, t_);
+ }
+
+ private:
+ O& o_;
+ F f_;
+ S& s_;
+ T& t_;
+ };
+
+ template <typename O,
+ typename S,
+ typename T = Traversal::EdgeDispatcherBase>
+ class Factory
+ {
+ public:
+ typedef void (O::*F) (S&, T&);
+
+ Factory (O& o, F f, T& t)
+ : o_ (o), f_ (f), t_ (t)
+ {
+ }
+
+ InhibitorTemplate<O, S, T>
+ operator() (S& s) const
+ {
+ return InhibitorTemplate<O, S, T> (o_, f_, s, t_);
+ }
+
+ private:
+ O& o_;
+ F f_;
+ T& t_;
+ };
+
+ std::ostream&
+ operator<< (std::ostream& os, Inhibitor const& p)
+ {
+ p ();
+ return os;
+ }
+
+ class GeneratorImpl
+ {
+ protected:
+ // Layer 1
+ //
+
+ // Layer 2
+ //
+
+ //--
+
+ // Layer 3
+ //
+
+ //--
+
+ struct InterfaceHdr : Traversal::UnconstrainedInterface
+ {
+ virtual void
+ pre (Type&)
+ {
+ cout << "class ";
+ }
+
+ virtual void
+ name (Type& i)
+ {
+ cout << i.name ();
+ }
+
+ virtual void
+ inherits_pre (Type&)
+ {
+ cout << " : ";
+ }
+
+ virtual void
+ inherits_none (Type&)
+ {
+ cout << " : public virtual CORBA::Impl::Stub";
+ }
+
+ virtual void
+ names_pre (Type&)
+ {
+ cout << "{"
+ << "public:" << endl;
+ }
+
+ virtual void
+ names_post (Type&)
+ {
+ cout << "}";
+ }
+
+ virtual void
+ post (Type&)
+ {
+ cout << ";";
+ }
+
+ virtual void
+ comma (Type&)
+ {
+ cout << ", ";
+ }
+ };
+
+
+ struct Module : Traversal::Module
+ {
+ virtual void
+ pre (Type& m)
+ {
+ cout << "namespace " << m.name ();
+ }
+
+ virtual void
+ names_pre (Type& m)
+ {
+ cout << "{";
+ }
+
+ virtual void
+ names_post (Type& m)
+ {
+ cout << "}";
+ }
+ };
+
+ struct TypeName : Traversal::Nameable,
+ Traversal::FundamentalType
+ {
+ virtual void
+ traverse (SemanticGraph::Nameable& n)
+ {
+ cout << n.scoped_name ();
+ }
+
+ virtual void
+ traverse (SemanticGraph::FundamentalType& ft)
+ {
+ cout << ft.name ();
+ }
+ };
+
+ // Layer 4
+ //
+
+ //--
+
+
+ struct OperationHdr : Traversal::Operation
+ {
+ virtual void
+ name (Type& o)
+ {
+ cout << " " << o.name ();
+ }
+
+ virtual void
+ receives_pre (Type&)
+ {
+ cout << " (";
+ }
+
+ virtual void
+ receives_post (Type&)
+ {
+ cout << ")";
+ }
+
+ virtual void
+ raises_pre (Type&)
+ {
+ cout << " throw (";
+ }
+
+ virtual void
+ raises_post (Type&)
+ {
+ cout << ")";
+ }
+
+ virtual void
+ post (Type&)
+ {
+ cout << ";";
+ }
+
+ virtual void
+ comma (Type&)
+ {
+ cout << ", ";
+ }
+ };
+
+ struct OperationImpl : Traversal::Operation
+ {
+ OperationImpl ()
+ : marshal (*this, &OperationImpl::receives, marshal_),
+ unmarshal (*this, &OperationImpl::receives, unmarshal_),
+ ret_type (*this, &OperationImpl::returns, ret_type_),
+ cast_type (*this, &OperationImpl::returns, cast_type_)
+ {
+ }
+
+ virtual void
+ name (Type& o)
+ {
+ cout << " "
+ << o.scoped_name ().scope_name ().simple_name ()
+ << "::" << o.name ();
+ }
+
+ virtual void
+ receives_pre (Type&)
+ {
+ cout << " (";
+ }
+
+ virtual void
+ receives_post (Type&)
+ {
+ cout << ")";
+ }
+
+ virtual void
+ raises_pre (Type&)
+ {
+ cout << " throw (";
+ }
+
+ virtual void
+ raises_post (Type&)
+ {
+ cout << ")";
+ }
+
+ virtual void
+ post (Type& o)
+ {
+ cout << "{"
+ << "OCDRStream os;"
+ << "static_cast<void> (os" << marshal (o) << ");"
+ << "ICDRStream is (Stub::make_call (\""
+ << o.name () << "\", os));"
+ << ret_type (o) << " _retval;"
+ << "is >> _retval" << unmarshal (o) << ";"
+ << "return " << "static_cast<" << cast_type (o) << "> (_retval);"
+ << "}";
+ }
+
+ virtual void
+ comma (Type&)
+ {
+ cout << ", ";
+ }
+
+ struct MarshalParameter : Traversal::Receives,
+ Traversal::InParameter,
+ Traversal::InOutParameter
+ {
+ MarshalParameter ()
+ {
+ node_traverser (*this);
+ }
+
+ virtual void
+ traverse (SemanticGraph::InParameter& p)
+ {
+ cout << " << " << p.name ();
+ }
+
+ virtual void
+ traverse (SemanticGraph::InOutParameter& p)
+ {
+ cout << " << " << p.name ();
+ }
+ } marshal_;
+
+ Factory<OperationImpl, Type> marshal;
+
+ struct UnmarshalParameter : Traversal::Receives,
+ Traversal::InOutParameter,
+ Traversal::OutParameter
+ {
+ UnmarshalParameter ()
+ {
+ node_traverser (*this);
+ }
+
+ virtual void
+ traverse (SemanticGraph::InOutParameter& p)
+ {
+ cout << " >> " << p.name ();
+ }
+
+ virtual void
+ traverse (SemanticGraph::OutParameter& p)
+ {
+ cout << " >> " << p.name ();
+ }
+ } unmarshal_;
+
+ Factory<OperationImpl, Type> unmarshal;
+
+
+ struct ReturnType : Traversal::Belongs, Traversal::Void, TypeName
+ {
+ ReturnType ()
+ {
+ node_traverser (*this);
+ }
+
+ virtual void
+ traverse (SemanticGraph::Void&)
+ {
+ // Void is a type for which do-nothing operator>> (ICDRStream&)
+ // is provided. Its main purpose is to make C++ type handling
+ // more regular and thus allow more streamlined code generation.
+ //
+ cout << "Void";
+ }
+ } ret_type_;
+
+ Factory<OperationImpl, Type> ret_type;
+
+ struct CastType : Traversal::Belongs, TypeName
+ {
+ CastType ()
+ {
+ node_traverser (*this);
+ }
+ } cast_type_;
+
+ Factory<OperationImpl, Type> cast_type;
+ };
+
+ // Layer 5
+ //
+
+ //--
+
+ struct Parameter : Traversal::Parameter
+ {
+ virtual void
+ name (Type& p)
+ {
+ cout << " " << p.name ();
+ }
+ };
+
+ public:
+
+ GeneratorImpl ()
+ {
+ // Layer 1
+ //
+ unit.edge_traverser (contains_principal);
+
+ //--
+
+ contains_principal.node_traverser (region);
+
+ // Layer 2
+ //
+ region.edge_traverser (contains_root);
+
+ //--
+
+ contains_root.node_traverser (root);
+
+ // Layer 3
+ //
+ root.edge_traverser (defines);
+
+ //--
+ defines.node_traverser (interface_hdr);
+ defines.node_traverser (interface_impl);
+ defines.node_traverser (module);
+
+ // Layer 4
+ //
+ module.edge_traverser (defines);
+
+ interface_hdr.edge_traverser (inherits);
+ interface_hdr.edge_traverser (interface_hdr_defines);
+
+ interface_impl.edge_traverser (interface_impl_defines);
+
+ //--
+ inherits.node_traverser (type_name);
+
+ interface_hdr_defines.node_traverser (operation_hdr);
+ interface_impl_defines.node_traverser (operation_impl);
+
+ // Layer 5
+ //
+
+ operation_hdr.edge_traverser (receives);
+ operation_hdr.edge_traverser (returns);
+
+ operation_impl.edge_traverser (receives);
+ operation_impl.edge_traverser (returns);
+
+ //--
+
+ receives.node_traverser (parameter);
+ returns.node_traverser (type_name);
+
+ // Layer 6
+ //
+ parameter.edge_traverser (belongs);
+
+ //--
+
+ belongs.node_traverser (type_name);
+
+ }
+
+ protected:
+ Traversal::TranslationUnit unit;
+
+ // Layer 1
+ //
+ Traversal::ContainsPrincipal contains_principal;
+
+ //--
+
+ Traversal::TranslationRegion region;
+
+ // Layer 2
+ //
+ Traversal::ContainsRoot contains_root;
+
+ //--
+
+ Traversal::Root root;
+
+ // Layer 3
+ //
+ Traversal::Defines defines;
+
+ //--
+ InterfaceHdr interface_hdr;
+ Traversal::UnconstrainedInterface interface_impl;
+
+ Module module;
+
+ TypeName type_name;
+
+ // Layer 4
+ //
+ Traversal::Inherits inherits;
+ Traversal::Defines interface_hdr_defines;
+ Traversal::Defines interface_impl_defines;
+
+ //--
+ OperationHdr operation_hdr;
+ OperationImpl operation_impl;
+
+ // Layer 5
+ //
+ Traversal::Receives receives;
+ Traversal::Returns returns;
+
+ //--
+
+ Parameter parameter;
+
+ // Layer 6
+ //
+ Traversal::Belongs belongs;
+
+ public:
+ void
+ generate (CCF::IDL2::SemanticGraph::TranslationUnit& tu)
+ {
+ // Plug automatic IDL indenter.
+ //
+ Indentation::Implanter<Indentation::Cxx> guard (cout);
+
+ unit.traverse (tu);
+ }
+ };
+}
+
+#endif // EXAMPLE_IDL2_CXX_MAPPING_GENERATOR_IMPL_HPP
diff --git a/CIAO/CCF/Example/IDL2/CxxMapping/driver.cpp b/CIAO/CCF/Example/IDL2/CxxMapping/driver.cpp
new file mode 100644
index 00000000000..11c6e895611
--- /dev/null
+++ b/CIAO/CCF/Example/IDL2/CxxMapping/driver.cpp
@@ -0,0 +1,96 @@
+// file : Example/IDL2/CxxMapping/driver.cpp
+// author : Boris Kolpackov <boris@dre.vanderbilt.edu>
+// cvs-id : $Id$
+
+#include <iostream>
+
+#include "CCF/CompilerElements/Context.hpp"
+#include "CCF/CompilerElements/FileSystem.hpp"
+#include "CCF/CompilerElements/Diagnostic.hpp"
+#include "CCF/CompilerElements/TokenStream.hpp"
+#include "CCF/CompilerElements/Preprocessor.hpp"
+
+#include "CCF/IDL2/LexicalAnalyzer.hpp"
+#include "CCF/IDL2/Parser.hpp"
+#include "CCF/IDL2/SemanticGraph.hpp"
+#include "CCF/IDL2/SemanticAction/Impl/Factory.hpp"
+
+#include "Generator.hpp"
+
+using std::cerr;
+using std::cout;
+using std::endl;
+
+using namespace CCF::CompilerElements;
+using namespace CCF::IDL2;
+using namespace CCF::IDL2::SemanticGraph;
+
+//@@ code repetition in driver.
+//
+
+int
+main ()
+{
+ try
+ {
+ Diagnostic::Stream dout;
+
+ fs::path file_path ("stdout");
+
+ InputStreamAdapter isa (std::cin);
+ CPP::Preprocessor pp (isa);
+
+ LexicalAnalyzer lexer (pp);
+
+ TokenList token_stream;
+
+ //@@ bad token comparison
+ for (TokenPtr token = lexer.next ();; token = lexer.next ())
+ {
+ token_stream.push_back (token);
+ if (ReferenceCounting::strict_cast<EndOfStream> (token) != 0) break;
+ }
+
+ if (token_stream.size () < 2)
+ {
+ cerr << "no tokens produced so nothing to parse" << endl;
+ return 0;
+ }
+
+ TranslationUnit tu;
+
+ // Compilation context.
+ //
+ CCF::CompilerElements::Context context;
+ context.set ("file-path", file_path);
+ context.set ("trace-semantic-action", false);
+
+
+ SemanticAction::Impl::Factory actions (context, dout, tu);
+
+ Parser parser (context, dout, lexer, actions);
+
+ Parsing::parse (token_stream.begin (),
+ token_stream.end (),
+ parser.start ());
+
+ if (dout.error_count () != 0) return -1;
+
+ IDL2::Generator g;
+
+ g.generate (tu);
+ }
+ catch (std::bad_cast const&)
+ {
+ cerr << "bad cast exception" << endl;
+ }
+ catch (InvalidName const&)
+ {
+ cerr << "invalid name exception" << endl;
+ }
+ catch (...)
+ {
+ cerr << "caught unknown exception" << endl;
+ return -1;
+ }
+}
diff --git a/CIAO/CCF/Example/IDL2/CxxMapping/test.idl b/CIAO/CCF/Example/IDL2/CxxMapping/test.idl
new file mode 100644
index 00000000000..82e44440c58
--- /dev/null
+++ b/CIAO/CCF/Example/IDL2/CxxMapping/test.idl
@@ -0,0 +1,12 @@
+// file : Example/IDL2/CxxMapping/test.idl
+// author : Boris Kolpackov <boris@dre.vanderbilt.edu>
+// cvs-id : $Id$
+
+module M
+{
+ interface I
+ {
+ long foo (in string s, inout boolean b, out long l);
+ void bar ();
+ };
+};