diff options
Diffstat (limited to 'modules/CIAO/CCF/Test/IDL2')
13 files changed, 1407 insertions, 0 deletions
diff --git a/modules/CIAO/CCF/Test/IDL2/Compiler/driver.cpp b/modules/CIAO/CCF/Test/IDL2/Compiler/driver.cpp new file mode 100644 index 00000000000..71d8dc9b971 --- /dev/null +++ b/modules/CIAO/CCF/Test/IDL2/Compiler/driver.cpp @@ -0,0 +1,94 @@ +// file : Test/IDL2/Compiler/driver.cpp +// author : Boris Kolpackov <boris@dre.vanderbilt.edu> +// cvs-id : $Id$ + +#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 "../Traversal/Recreate/Generator.hpp" + +#include <iostream> + +using std::cerr; +using std::cout; +using std::endl; + +using namespace CCF::CompilerElements; +using namespace CCF::IDL2; +using namespace CCF::IDL2::SemanticGraph; + +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/modules/CIAO/CCF/Test/IDL2/Compiler/result.idl.orig b/modules/CIAO/CCF/Test/IDL2/Compiler/result.idl.orig new file mode 100644 index 00000000000..a29258b9e6f --- /dev/null +++ b/modules/CIAO/CCF/Test/IDL2/Compiler/result.idl.orig @@ -0,0 +1,88 @@ +module AttributeTest +{ + interface I + { + attribute long a; + attribute string foo; + }; +}; +module InterfaceTest +{ + abstract interface AI; + local interface LI; + interface I; + abstract interface AI + { + }; + interface I : ::InterfaceTest::AI + { + }; + local interface LI : ::InterfaceTest::I, ::InterfaceTest::AI + { + }; +}; +module MemberTest +{ + typedef long Id; + struct S + { + long id; + string foo; + string bar; + string baz; + }; +}; +module ModuleTest +{ + module M + { + module N + { + typedef long L; + }; + }; + module M + { + typedef long L; + }; + module N + { + typedef long L; + }; +}; +module OperationTest +{ + interface I + { + long f (in string a, out long b, inout octet c); + }; +}; +module Sequence +{ + typedef sequence<octet> OctetSeq; + typedef sequence<octet> RawSeq; + typedef sequence<string> StringSeq; + typedef sequence<string> StrSeq; +}; +module StructTest +{ + struct S; + struct S + { + long m; + }; +}; +module TypeidTest +{ + interface I; + typeid ::TypeidTest::I "Foo"; + typeprefix ::TypeidTest "Bar"; +}; +module TypedefTest +{ + interface I; + typedef ::TypedefTest::I J; + interface I + { + }; +}; diff --git a/modules/CIAO/CCF/Test/IDL2/Compiler/test.idl b/modules/CIAO/CCF/Test/IDL2/Compiler/test.idl new file mode 100644 index 00000000000..737a729524b --- /dev/null +++ b/modules/CIAO/CCF/Test/IDL2/Compiler/test.idl @@ -0,0 +1,151 @@ +// file : CCF/Test/IDL2/Compiler/test.idl +// author : Boris Kolpackov <boris@dre.vanderbilt.edu> +// cvs-id : $Id$ + +// Attribute +// +// +module AttributeTest +{ + interface I + { + attribute long a; + attribute string foo; + }; +}; + +// Interface +// +// +module InterfaceTest +{ + abstract interface AI; + local interface LI; + interface I; + + abstract interface AI + { + }; + + interface I : AI + { + }; + + local interface LI : I, AI + { + }; +}; + +// Member +// +// +module MemberTest +{ + typedef long Id; + + struct S + { + Id id; + string foo, bar, baz; + }; +}; + +// Module +// +// +module ModuleTest +{ + module M + { + module N + { + typedef long L; + }; + }; + + module M + { + typedef N::L L; + }; + + module N + { + typedef M::N::L L; + }; +}; + + +// Operation +// +// +module OperationTest +{ + interface I + { + long f (in string a, out long b, inout octet c); + }; +}; + + +// Sequence +// +// +module Sequence +{ + typedef sequence<octet> OctetSeq; + + typedef OctetSeq RawSeq; + + typedef sequence<string> StringSeq, StrSeq; +}; + + +// Struct +// +// +module StructTest +{ + struct S; + + struct S + { + long m; // Struct cannot be empty. + }; + +}; + +// Typeid +// +// +module TypeidTest +{ + interface I; + + typeid I "Foo"; + typeprefix TypeidTest "Bar"; +}; + + +// Typedef +// +// + +module TypedefTest +{ + interface I; + + typedef I J; + + interface I + { + /* + struct S + { + long l; + }; + + J::S op (); + */ + }; +}; + diff --git a/modules/CIAO/CCF/Test/IDL2/LexicalAnalyzer/Coverage.idl b/modules/CIAO/CCF/Test/IDL2/LexicalAnalyzer/Coverage.idl new file mode 100644 index 00000000000..a29dde465d2 --- /dev/null +++ b/modules/CIAO/CCF/Test/IDL2/LexicalAnalyzer/Coverage.idl @@ -0,0 +1,25 @@ +// file : CCF/Test/IDL2/LexicalAnalyzer/Coverage.idl +// author : Boris Kolpackov <boris@dre.vanderbilt.edu> +// cvs-id : $Id$ + +// This file is supposed to cover an IDL2 lexical structure and intended +// for IDL2 lexer regression testing. +// + +abstract interface FA; + +abstract interface A +{ + void foo (in long l, out boolean b, inout FA fa); +}; + +module M +{ + interface I + { + }; +}; + +local interface L : ::A, M::I +{ +}; diff --git a/modules/CIAO/CCF/Test/IDL2/Parser/Recovery/interface.idl b/modules/CIAO/CCF/Test/IDL2/Parser/Recovery/interface.idl new file mode 100644 index 00000000000..22a99ffadf2 --- /dev/null +++ b/modules/CIAO/CCF/Test/IDL2/Parser/Recovery/interface.idl @@ -0,0 +1,41 @@ +// file : CCF/Test/IDL2/Parsing/Recovery/interface.idl +// author : Boris Kolpackov <boris@dre.vanderbilt.edu> +// cvs-id : $Id$ + +interface Base {}; + + +// Interface declaration syntax errors +// +// + +local intrrface L; + +// + +abstract interrface A; + +// + +interface ; + +// + +interface I : {}; + +// + +interface I : Base, {}; + +// + +interface I }; + +// + +interface I {; + +// + +interface I {} + diff --git a/modules/CIAO/CCF/Test/IDL2/Parser/Recovery/module.idl b/modules/CIAO/CCF/Test/IDL2/Parser/Recovery/module.idl new file mode 100644 index 00000000000..edfd868809b --- /dev/null +++ b/modules/CIAO/CCF/Test/IDL2/Parser/Recovery/module.idl @@ -0,0 +1,38 @@ +// file : CCF/Test/IDL2/Parsing/Recovery/module.idl +// author : Boris Kolpackov <boris@dre.vanderbilt.edu> +// cvs-id : $Id$ + +// Module declaration syntax errors +// +// + +// + +module; + +// + +module M; + +// + +module M {; + +// + +module M {} + + +// + +module M { + interface I; +; + +// + +module N +{ + interface I; +} + diff --git a/modules/CIAO/CCF/Test/IDL2/SemanticGraph/HandBuilt/Builder.cpp b/modules/CIAO/CCF/Test/IDL2/SemanticGraph/HandBuilt/Builder.cpp new file mode 100644 index 00000000000..764ab3fbc6f --- /dev/null +++ b/modules/CIAO/CCF/Test/IDL2/SemanticGraph/HandBuilt/Builder.cpp @@ -0,0 +1,165 @@ +// file : Test/IDL2/SemanticGraph/HandBuilt/Builder.cpp +// author : Boris Kolpackov <boris@dre.vanderbilt.edu> +// cvs-id : $Id$ + +#include <iostream> + +#include "Builder.hpp" + +using namespace CCF::IDL2::SemanticGraph; + +//@@ tmp +using std::cerr; +using std::endl; + +TranslationUnit* Builder:: +build () +{ + /* + 0 + 1 #include "../foo/quote.idl" + 2 #include <ui/bracket.idl> + 3 + 4 module M + 5 { + 6 + 7 interface I; + 8 + 9 typedef I J; + 10 + 11 interface I + 12 { + 13 void f (in long id, out string name); + 14 + 15 attribute long a; + 16 }; + 17 + 18 interface Q : J {}; + 19 + 20 typeid I "Foo"; + 21 typeprefix M "Bar"; + 22 + 23 struct S + 24 { + 25 long member; + 26 }; + 27 + 28 typedef sequence<long> LongSeq; + 29 + 30 }; + 31 + 32 + */ + + //@@ names can be spcified without explicit construction. + // + + TranslationUnit& tu (*(new TranslationUnit)); + + + // 0: Implied translation region with fundamental types. + // + // + TranslationRegion& fundamental (tu.new_node<TranslationRegion> ()); + tu.new_edge<ContainsImplied> (tu, fundamental, ".fundamental"); + + Root& fundamental_root (tu.new_node<Root> ()); + tu.new_edge<ContainsRoot> (fundamental, fundamental_root); + + Void& void_ (tu.new_node<Void> ()); + tu.new_edge<Defines> (fundamental_root, void_, SimpleName ("void")); + + Long& long_ (tu.new_node<Long> ()); + tu.new_edge<Defines> (fundamental_root, long_, SimpleName ("long")); + + String& string_ (tu.new_node<String> ()); + tu.new_edge<Defines> (fundamental_root, string_, SimpleName ("string")); + + // Principal translation region. + // + TranslationRegion& principal (tu.new_node<TranslationRegion> ()); + tu.new_edge<ContainsPrincipal> (tu, principal); + + // 1: Quote included translation region. + // + TranslationRegion& quote_included (tu.new_node<TranslationRegion> ()); + tu.new_edge<QuoteIncludes> (principal, quote_included, "../foo/quote.idl"); + + // 2: Bracket included translation region. + // + TranslationRegion& braket_included (tu.new_node<TranslationRegion> ()); + tu.new_edge<BracketIncludes> (principal, braket_included, "ui/bracket.idl"); + + Root& root (tu.new_node<Root> ()); + tu.new_edge<ContainsRoot> (principal, root); + + // 4-5: + // + Module& m (tu.new_node<Module> ()); + tu.new_edge<Defines> (root, m, SimpleName ("M")); + + // 7-11: + // + UnconstrainedInterface& i (tu.new_node<UnconstrainedInterface> ()); + tu.new_edge<Mentions> (m, i, SimpleName ("I")); + tu.new_edge<Aliases> (m, i, SimpleName ("J")); + tu.new_edge<Defines> (m, i, SimpleName ("I")); + + // 13: + // + TwoWayOperation& f (tu.new_node<TwoWayOperation> ()); + tu.new_edge<Returns> (f, void_); + + Parameter& id (tu.new_node<InParameter> ("id")); + tu.new_edge<Belongs> (id, long_); + tu.new_edge<Receives> (f, id); + + Parameter& name (tu.new_node<OutParameter> ("name")); + tu.new_edge<Belongs> (name, string_); + tu.new_edge<Receives> (f, name); + + tu.new_edge<Defines> (i, f, SimpleName ("f")); + + // 15: + // + Attribute& a (tu.new_node<Attribute> ()); + tu.new_edge<Belongs> (a, long_); + tu.new_edge<Defines> (i, a, SimpleName ("a")); + + // 18: + // + UnconstrainedInterface& q (tu.new_node<UnconstrainedInterface> ()); + tu.new_edge<Inherits> (q, i); + tu.new_edge<Defines> (m, q, SimpleName ("Q")); + + // 20: + // + TypeId& ti (tu.new_node<TypeId> ( + ScopedName ("::M::I"), StringLiteral ("Foo"))); + tu.new_edge<Defines> (m, ti, SimpleName ("typeid")); + + // 21: + // + TypePrefix& tp (tu.new_node<TypePrefix> ( + ScopedName ("::M"), StringLiteral ("Bar"))); + tu.new_edge<Defines> (m, tp, SimpleName ("typeprefix")); + + // 23-24: + // + Struct& s (tu.new_node<Struct> ()); + tu.new_edge<Defines> (m, s, SimpleName ("S")); + + // 25: + // + Member& member (tu.new_node<Member> ()); + tu.new_edge<Belongs> (member, long_); + tu.new_edge<Defines> (s, member, SimpleName ("member")); + + // 28: + // + UnboundedSequence& long_seq (tu.new_node<UnboundedSequence> ()); + tu.new_edge<Specialized> (long_seq, long_); + tu.new_edge<Aliases> (m, long_seq, SimpleName ("LongSeq")); + + return &tu; +} diff --git a/modules/CIAO/CCF/Test/IDL2/SemanticGraph/HandBuilt/Builder.hpp b/modules/CIAO/CCF/Test/IDL2/SemanticGraph/HandBuilt/Builder.hpp new file mode 100644 index 00000000000..794c56547d2 --- /dev/null +++ b/modules/CIAO/CCF/Test/IDL2/SemanticGraph/HandBuilt/Builder.hpp @@ -0,0 +1,17 @@ +// file : Test/IDL2/SemanticGraph/HandBuilt/Builder.hpp +// author : Boris Kolpackov <boris@dre.vanderbilt.edu> +// cvs-id : $Id$ + +#ifndef TEST_IDL2_SEMANTIC_GRAPH_BUILDER_HPP +#define TEST_IDL2_SEMANTIC_GRAPH_BUILDER_HPP + +#include "CCF/IDL2/SemanticGraph.hpp" + +class Builder +{ +public: + CCF::IDL2::SemanticGraph::TranslationUnit* + build (); +}; + +#endif // TEST_IDL2_SEMANTIC_GRAPH_BUILDER_HPP diff --git a/modules/CIAO/CCF/Test/IDL2/SemanticGraph/HandBuilt/hand_built.cpp b/modules/CIAO/CCF/Test/IDL2/SemanticGraph/HandBuilt/hand_built.cpp new file mode 100644 index 00000000000..3640282cfe3 --- /dev/null +++ b/modules/CIAO/CCF/Test/IDL2/SemanticGraph/HandBuilt/hand_built.cpp @@ -0,0 +1,16 @@ +// file : Test/IDL2/SemanticGraph/HandBuilt/hand_built.cpp +// author : Boris Kolpackov <boris@dre.vanderbilt.edu> +// cvs-id : $Id$ + +#include "Builder.hpp" + +using namespace CCF::IDL2; + +int +main () +{ + Builder b; + SemanticGraph::TranslationUnit& tu (*b.build ()); + + delete &tu; +} diff --git a/modules/CIAO/CCF/Test/IDL2/Traversal/Recreate/Generator.cpp b/modules/CIAO/CCF/Test/IDL2/Traversal/Recreate/Generator.cpp new file mode 100644 index 00000000000..8aa3e895b9d --- /dev/null +++ b/modules/CIAO/CCF/Test/IDL2/Traversal/Recreate/Generator.cpp @@ -0,0 +1,32 @@ +// file : Test/IDL2/Traversal/Recreate/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/modules/CIAO/CCF/Test/IDL2/Traversal/Recreate/Generator.hpp b/modules/CIAO/CCF/Test/IDL2/Traversal/Recreate/Generator.hpp new file mode 100644 index 00000000000..b0387317ad5 --- /dev/null +++ b/modules/CIAO/CCF/Test/IDL2/Traversal/Recreate/Generator.hpp @@ -0,0 +1,34 @@ +// file : Test/IDL2/Traversal/Recreate/Generator.hpp +// author : Boris Kolpackov <boris@dre.vanderbilt.edu> +// cvs-id : $Id$ + +#ifndef TEST_IDL2_TRAVERSAL_RECREATE_GENERATOR_HPP +#define TEST_IDL2_TRAVERSAL_RECREATE_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 // TEST_IDL2_TRAVERSAL_RECREATE_GENERATOR_HPP diff --git a/modules/CIAO/CCF/Test/IDL2/Traversal/Recreate/GeneratorImpl.hpp b/modules/CIAO/CCF/Test/IDL2/Traversal/Recreate/GeneratorImpl.hpp new file mode 100644 index 00000000000..52b89e03e12 --- /dev/null +++ b/modules/CIAO/CCF/Test/IDL2/Traversal/Recreate/GeneratorImpl.hpp @@ -0,0 +1,682 @@ +// file : Test/IDL2/Traversal/Recreate/GeneratorImpl.hpp +// author : Boris Kolpackov <boris@dre.vanderbilt.edu> +// cvs-id : $Id$ + +#ifndef TEST_IDL2_TRAVERSAL_RECREATE_GENERATOR_IMPL_HPP +#define TEST_IDL2_TRAVERSAL_RECREATE_GENERATOR_IMPL_HPP + +#include <iostream> + +#include "CCF/CodeGenerationKit/IndentationIDL.hpp" +#include "CCF/CodeGenerationKit/IndentationImplanter.hpp" + +#include "CCF/IDL2/SemanticGraph.hpp" +#include "CCF/IDL2/Traversal.hpp" + +namespace IDL2 +{ + using namespace CCF::IDL2; + using namespace CCF::IDL2::SemanticGraph; + + using std::cout; + using std::endl; + + class GeneratorImpl + { + protected: + // Layer 1 + // + + // Layer 2 + // + struct BracketIncludes : Traversal::BracketIncludes + { + virtual void + traverse (Type& qi) + { + cout << "include <" << qi.file ().string () << ">" << endl; + } + }; + + struct QuoteIncludes : Traversal::QuoteIncludes + { + virtual void + traverse (Type& qi) + { + cout << "include \"" << qi.file ().string () << "\"" << endl; + } + }; + + //-- + + // Layer 3 + // + + struct Aliases : Traversal::Aliases + { + virtual void + pre (Type&) + { + cout << "typedef "; + } + + virtual void + name (Type& a) + { + cout << " " << a.name (); + } + + virtual void + post (Type&) + { + cout << ";"; + } + }; + + //-- + + struct AbstractInterfaceFwd : Traversal::AbstractInterface + { + virtual void + traverse (Type& i) + { + cout << "abstract interface " << i.name () << ";"; + } + }; + + struct LocalInterfaceFwd : Traversal::LocalInterface + { + virtual void + traverse (Type& i) + { + cout << "local interface " << i.name () << ";"; + } + }; + + struct UnconstrainedInterfaceFwd : Traversal::UnconstrainedInterface + { + virtual void + traverse (Type& i) + { + cout << "interface " << i.name () << ";"; + } + }; + + struct StructFwd : Traversal::Struct + { + virtual void + traverse (Type& i) + { + cout << "struct " << i.name () << ";"; + } + }; + + + struct AbstractInterface : Traversal::AbstractInterface + { + virtual void + pre (Type&) + { + cout << "abstract interface "; + } + + virtual void + name (Type& i) + { + cout << i.name (); + } + + virtual void + inherits_pre (Type&) + { + cout << " : "; + } + + virtual void + names_pre (Type&) + { + cout << "{"; + } + + virtual void + names_post (Type&) + { + cout << "}"; + } + + virtual void + post (Type&) + { + cout << ";"; + } + + virtual void + comma (Type&) + { + cout << ", "; + } + }; + + struct LocalInterface : Traversal::LocalInterface + { + virtual void + pre (Type&) + { + cout << "local interface "; + } + + virtual void + name (Type& i) + { + cout << i.name (); + } + + virtual void + inherits_pre (Type&) + { + cout << " : "; + } + + virtual void + names_pre (Type&) + { + cout << "{"; + } + + virtual void + names_post (Type&) + { + cout << "}"; + } + + virtual void + post (Type&) + { + cout << ";"; + } + + virtual void + comma (Type&) + { + cout << ", "; + } + }; + + struct UnconstrainedInterface : Traversal::UnconstrainedInterface + { + virtual void + pre (Type&) + { + cout << "interface "; + } + + virtual void + name (Type& i) + { + cout << i.name (); + } + + virtual void + inherits_pre (Type&) + { + cout << " : "; + } + + virtual void + names_pre (Type&) + { + cout << "{"; + } + + 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 << "module " << m.name (); + } + + virtual void + names_pre (Type& m) + { + cout << "{"; + } + + virtual void + names_post (Type& m) + { + cout << "}"; + } + + virtual void + post (Type& m) + { + cout << ";"; + } + }; + + struct Struct : Traversal::Struct + { + virtual void + pre (Type&) + { + cout << "struct "; + } + + virtual void + name (Type& s) + { + cout << s.name (); + } + + virtual void + names_pre (Type&) + { + cout << "{"; + } + + virtual void + names_post (Type&) + { + cout << "}"; + } + + virtual void + post (Type&) + { + cout << ";"; + } + }; + + + struct TypeId : Traversal::TypeId + { + virtual void + traverse (Type& ti) + { + cout << "typeid " << ti.declaration () << " " << ti.id () << ";"; + } + }; + + + struct TypePrefix : Traversal::TypePrefix + { + virtual void + traverse (Type& ti) + { + cout << "typeprefix " << ti.declaration () << " " + << ti.prefix () << ";"; + } + }; + + 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 (); + } + }; + + struct UnboundedSequence : Traversal::UnboundedSequence + { + virtual void + pre (Type&) + { + cout << "sequence<"; + } + + virtual void + post (Type&) + { + cout << ">"; + } + }; + + // Layer 4 + // + + //-- + + struct Operation : 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 << " raises ("; + } + + virtual void + raises_post (Type&) + { + cout << ")"; + } + + virtual void + post (Type&) + { + cout << ";"; + } + + virtual void + comma (Type&) + { + cout << ", "; + } + }; + + struct Attribute : Traversal::Attribute + { + virtual void + pre (Type&) + { + cout << "attribute "; + } + + virtual void + name (Type& a) + { + cout << " " << a.name (); + } + + virtual void + post (Type&) + { + cout << ";"; + } + + }; + + struct Member : Traversal::Member + { + virtual void + name (Type& m) + { + cout << " " << m.name (); + } + + virtual void + post (Type&) + { + cout << ";"; + } + }; + + // Layer 5 + // + + //-- + + struct Parameter : Traversal::InParameter, + Traversal::OutParameter, + Traversal::InOutParameter + { + virtual void + pre (InParameter& p) + { + cout << " in "; + } + + virtual void + pre (OutParameter& p) + { + cout << " out "; + } + + virtual void + pre (InOutParameter& p) + { + cout << " inout "; + } + + virtual void + name (InParameter& p) + { + cout << p.name (); + } + + virtual void + name (OutParameter& p) + { + cout << p.name (); + } + + virtual void + name (InOutParameter& p) + { + cout << p.name (); + } + }; + + public: + + GeneratorImpl () + { + // Layer 1 + // + unit.edge_traverser (contains_principal); + + //-- + + contains_principal.node_traverser (region); + + // Layer 2 + // + region.edge_traverser (quote_includes); + region.edge_traverser (bracket_includes); + region.edge_traverser (contains_root); + + //-- + + contains_root.node_traverser (root); + + // Layer 3 + // + root.edge_traverser (mentions); + root.edge_traverser (defines); + root.edge_traverser (aliases); + + //-- + + mentions.node_traverser (abstract_interface_fwd); + mentions.node_traverser (local_interface_fwd); + mentions.node_traverser (unconstrained_interface_fwd); + mentions.node_traverser (struct_fwd); + + defines.node_traverser (abstract_interface); + defines.node_traverser (local_interface); + defines.node_traverser (unconstrained_interface); + defines.node_traverser (module); + defines.node_traverser (struct_); + defines.node_traverser (type_id); + defines.node_traverser (type_prefix); + + aliases.node_traverser (type_name); + aliases.node_traverser (unbounded_sequence); + + // Layer 4 + // + module.edge_traverser (mentions); + module.edge_traverser (defines); + module.edge_traverser (aliases); + + abstract_interface.edge_traverser (inherits); + local_interface.edge_traverser (inherits); + unconstrained_interface.edge_traverser (inherits); + + abstract_interface.edge_traverser (interface_defines); + local_interface.edge_traverser (interface_defines); + unconstrained_interface.edge_traverser (interface_defines); + + struct_.edge_traverser (struct_defines); + + unbounded_sequence.edge_traverser (specialized); + + //-- + + inherits.node_traverser (type_name); + + interface_defines.node_traverser (operation); + interface_defines.node_traverser (attribute); + + struct_defines.node_traverser (member); + + specialized.node_traverser (type_name); + + // Layer 5 + // + + operation.edge_traverser (receives); + operation.edge_traverser (returns); + + attribute.edge_traverser (belongs); + + member.edge_traverser (belongs); + + //-- + + receives.node_traverser (parameter); + returns.node_traverser (type_name); + belongs.node_traverser (type_name); + + // Layer 6 + // + parameter.edge_traverser (belongs); + + } + + protected: + Traversal::TranslationUnit unit; + + // Layer 1 + // + Traversal::ContainsPrincipal contains_principal; + + //-- + + Traversal::TranslationRegion region; + + // Layer 2 + // + BracketIncludes bracket_includes; + QuoteIncludes quote_includes; + Traversal::ContainsRoot contains_root; + + //-- + + Traversal::Root root; + + // Layer 3 + // + Traversal::Mentions mentions; + Traversal::Defines defines; + Aliases aliases; + + //-- + + AbstractInterfaceFwd abstract_interface_fwd; + LocalInterfaceFwd local_interface_fwd; + UnconstrainedInterfaceFwd unconstrained_interface_fwd; + + StructFwd struct_fwd; + + AbstractInterface abstract_interface; + LocalInterface local_interface; + UnconstrainedInterface unconstrained_interface; + + Module module; + + Struct struct_; + + TypeId type_id; + TypePrefix type_prefix; + + TypeName type_name; + + UnboundedSequence unbounded_sequence; + + // Layer 4 + // + Traversal::Inherits inherits; + Traversal::Defines interface_defines; + Traversal::Defines struct_defines; + Traversal::Specialized specialized; + + //-- + + Operation operation; + Attribute attribute; + Member member; + + // Layer 5 + // + Traversal::Receives receives; + Traversal::Returns returns; + Traversal::Belongs belongs; + + //-- + + Parameter parameter; + + // Layer 6 + // + + public: + void + generate (CCF::IDL2::SemanticGraph::TranslationUnit& tu) + { + // Plug automatic IDL indenter. + // + Indentation::Implanter<Indentation::IDL> guard (cout); + + unit.traverse (tu); + } + }; +} + +#endif // TEST_IDL2_TRAVERSAL_RECREATE_GENERATOR_IMPL_HPP diff --git a/modules/CIAO/CCF/Test/IDL2/Traversal/Recreate/recreate.cpp b/modules/CIAO/CCF/Test/IDL2/Traversal/Recreate/recreate.cpp new file mode 100644 index 00000000000..560040bbcb0 --- /dev/null +++ b/modules/CIAO/CCF/Test/IDL2/Traversal/Recreate/recreate.cpp @@ -0,0 +1,24 @@ +// file : Test/IDL2/Traversal/Recreate/recreate.cpp +// author : Boris Kolpackov <boris@dre.vanderbilt.edu> +// cvs-id : $Id$ + +#include <iostream> + +#include "CCF/IDL2/SemanticGraph.hpp" + +#include "../../SemanticGraph/HandBuilt/Builder.hpp" + +#include "Generator.hpp" + +int +main () +{ + Builder b; + CCF::IDL2::SemanticGraph::TranslationUnit& tu (*b.build ()); + + IDL2::Generator g; + + g.generate (tu); + + delete &tu; +} |