diff options
Diffstat (limited to 'CIAO/CCF/Test')
26 files changed, 2921 insertions, 0 deletions
diff --git a/CIAO/CCF/Test/CIDL/Compiler/Generator.cpp b/CIAO/CCF/Test/CIDL/Compiler/Generator.cpp new file mode 100644 index 00000000000..278278b3360 --- /dev/null +++ b/CIAO/CCF/Test/CIDL/Compiler/Generator.cpp @@ -0,0 +1,32 @@ +// file : Test/CIDL/Compiler/Generator.cpp +// author : Boris Kolpackov <boris@dre.vanderbilt.edu> +// cvs-id : $Id$ + +#include "Generator.hpp" +#include "GeneratorImpl.hpp" + +namespace CIDL +{ + Generator:: + ~Generator () + { + } + + Generator:: + Generator () + : pimpl_ (new GeneratorImpl), impl_ (*pimpl_) + { + } + + Generator:: + Generator (GeneratorImpl& gi) + : pimpl_ (), impl_ (gi) + { + } + + void Generator:: + generate (CCF::IDL3::SemanticGraph::TranslationUnit& tu) + { + impl_.generate (tu); + } +} diff --git a/CIAO/CCF/Test/CIDL/Compiler/Generator.hpp b/CIAO/CCF/Test/CIDL/Compiler/Generator.hpp new file mode 100644 index 00000000000..3876195469d --- /dev/null +++ b/CIAO/CCF/Test/CIDL/Compiler/Generator.hpp @@ -0,0 +1,34 @@ +// file : Test/CIDL/Compiler/Generator.hpp +// author : Boris Kolpackov <boris@dre.vanderbilt.edu> +// cvs-id : $Id$ + +#ifndef TEST_CIDL_COMPILER_GENERATOR_HPP +#define TEST_CIDL_COMPILER_GENERATOR_HPP + +#include <memory> + +#include "CCF/CIDL/SemanticGraph.hpp" + +namespace CIDL +{ + class GeneratorImpl; + + class Generator + { + public: + ~Generator (); + Generator (); + + void + generate (CCF::CIDL::SemanticGraph::TranslationUnit& tu); + + protected: + Generator (GeneratorImpl&); + + protected: + std::auto_ptr<GeneratorImpl> pimpl_; + GeneratorImpl& impl_; + }; +} + +#endif // TEST_CIDL_COMPILER_GENERATOR_HPP diff --git a/CIAO/CCF/Test/CIDL/Compiler/GeneratorImpl.hpp b/CIAO/CCF/Test/CIDL/Compiler/GeneratorImpl.hpp new file mode 100644 index 00000000000..169fb57ace3 --- /dev/null +++ b/CIAO/CCF/Test/CIDL/Compiler/GeneratorImpl.hpp @@ -0,0 +1,228 @@ +// file : Test/CIDL/Compiler/GeneratorImpl.hpp +// author : Boris Kolpackov <boris@dre.vanderbilt.edu> +// cvs-id : $Id$ + +#ifndef TEST_CIDL_COMPILER_GENERATOR_IMPL_HPP +#define TEST_CIDL_COMPILER_GENERATOR_IMPL_HPP + +#include <iostream> + +#include "CCF/CodeGenerationKit/IndentationIDL.hpp" +#include "CCF/CodeGenerationKit/IndentationImplanter.hpp" + +#include "CCF/CIDL/SemanticGraph.hpp" +#include "CCF/CIDL/Traversal.hpp" + +#include "../../IDL3/Compiler/GeneratorImpl.hpp" + +namespace CIDL +{ + using namespace CCF::CIDL; + + using std::cout; + using std::endl; + + class GeneratorImpl : public IDL3::GeneratorImpl + { + protected: + // Layer 1 + // + + // Layer 2 + // + + // Layer 3 + // + + //-- + + struct Composition : Traversal::Composition + { + virtual void + pre (Type& c) + { + //@@ TODO kind + cout << "composition " << "session" << " "; + } + + virtual void + name (Type& i) + { + cout << i.name (); + } + + virtual void + names_pre (Type&) + { + cout << "{"; + } + + virtual void + names_post (Type&) + { + cout << "}"; + } + + virtual void + post (Type&) + { + cout << ";"; + } + }; + + + struct HomeExecutor : Traversal::HomeExecutor + { + virtual void + pre (Type&) + { + cout << "home executor "; + } + + virtual void + name (Type& he) + { + cout << he.name () << "{"; + } + + virtual void + implements_pre (Type&) + { + cout << "implements "; + } + + virtual void + implements_post (Type&) + { + cout << ";"; + } + + virtual void + manages_pre (Type&) + { + cout << "manages "; + } + + virtual void + manages_post (Type&) + { + cout << ";"; + } + + virtual void + post (Type& he) + { + cout << "};"; + } + }; + + + // Layer 4 + // + + //-- + + // Layer 5 + // + + //-- + + struct SimpleName : Traversal::Nameable + { + virtual void + traverse (Type& n) + { + cout << n.name (); + } + }; + + public: + + GeneratorImpl () + { + // Layer 1 + // + + // Layer 2 + // + + // Layer 3 + // + + //-- + + defines.node_traverser (composition); + + // Layer 4 + // + + composition.edge_traverser (composition_defines); + + //-- + + composition_defines.node_traverser (home_executor); + + // Layer 5 + // + home_executor.edge_traverser (home_executor_implements); + home_executor.edge_traverser (home_executor_manages); + + //-- + + home_executor_implements.node_traverser (type_name); + home_executor_manages.node_traverser (simple_name); + + // Layer 6 + // + + } + + protected: + // Layer 1 + // + + // Layer 2 + // + + // Layer 3 + // + + //-- + + Composition composition; + + // Layer 4 + // + + Traversal::Defines composition_defines; + + //-- + + HomeExecutor home_executor; + + // Layer 5 + // + Traversal::Implements home_executor_implements; + Traversal::Manages home_executor_manages; + + //-- + + SimpleName simple_name; + + // Layer 6 + // + + public: + void + generate (CCF::CIDL::SemanticGraph::TranslationUnit& tu) + { + // Plug automatic IDL indenter. + // + Indentation::Implanter<Indentation::IDL> guard (cout); + + unit.traverse (tu); + } + }; +} + +#endif // TEST_CIDL_COMPILER_GENERATOR_IMPL_HPP diff --git a/CIAO/CCF/Test/CIDL/Compiler/driver.cpp b/CIAO/CCF/Test/CIDL/Compiler/driver.cpp new file mode 100644 index 00000000000..222dd8f851c --- /dev/null +++ b/CIAO/CCF/Test/CIDL/Compiler/driver.cpp @@ -0,0 +1,97 @@ +// file : Test/CIDL/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/CIDL/LexicalAnalyzer.hpp" +#include "CCF/CIDL/Parser.hpp" +#include "CCF/CIDL/SemanticGraph.hpp" +#include "CCF/CIDL/SemanticAction/Impl/Factory.hpp" + +#include "Generator.hpp" + +#include <iostream> + +using std::cerr; +using std::cout; +using std::endl; + +using namespace CCF::CompilerElements; +using namespace CCF::CIDL; +using namespace 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); + + //@@ should be able to use IDL3 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; + + CIDL::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/Test/CIDL/Compiler/result.cidl.orig b/CIAO/CCF/Test/CIDL/Compiler/result.cidl.orig new file mode 100644 index 00000000000..6ba766db738 --- /dev/null +++ b/CIAO/CCF/Test/CIDL/Compiler/result.cidl.orig @@ -0,0 +1,14 @@ +component C +{ +}; +home H manages ::C +{ +}; +composition session SC +{ + home executor H_Exec + { + implements ::H; + manages C_Exec; + }; +}; diff --git a/CIAO/CCF/Test/CIDL/Compiler/test.cidl b/CIAO/CCF/Test/CIDL/Compiler/test.cidl new file mode 100644 index 00000000000..349712a18df --- /dev/null +++ b/CIAO/CCF/Test/CIDL/Compiler/test.cidl @@ -0,0 +1,21 @@ +// file : CCF/Test/CIDL/Compiler/test.cidl +// author : Boris Kolpackov <boris@dre.vanderbilt.edu> +// cvs-id : $Id$ + +component C +{ +}; + +home H manages C +{ +}; + +composition session SC +{ + home executor H_Exec + { + implements H; + manages C_Exec; + }; +}; + diff --git a/CIAO/CCF/Test/CompilerElements/CPP/driver.cpp b/CIAO/CCF/Test/CompilerElements/CPP/driver.cpp new file mode 100644 index 00000000000..de3624d86a7 --- /dev/null +++ b/CIAO/CCF/Test/CompilerElements/CPP/driver.cpp @@ -0,0 +1,40 @@ +// file : CCF/Test/CompilerElements/CPP/driver.cpp +// author : Boris Kolpackov <boris@dre.vanderbilt.edu> +// cvs-id : $Id$ + +#include <iostream> + +#include "CCF/CompilerElements/TokenStream.hpp" +#include "CCF/CompilerElements/Preprocessor.hpp" + +using std::cout; +using std::endl; + +using CCF::CompilerElements::InputStreamAdapter; + +using namespace CCF::CompilerElements::CPP; + +int +main () +{ + InputStreamAdapter isa (std::cin); + Preprocessor pp (isa); + + try + { + for (;;) + { + Token t (pp.next ()); + + if (t == Token::eos) break; + + std::cout << t; + } + } + catch (std::exception const& e) + { + cout << e.what () << endl; + } + + return 0; +} diff --git a/CIAO/CCF/Test/IDL2/Compiler/driver.cpp b/CIAO/CCF/Test/IDL2/Compiler/driver.cpp new file mode 100644 index 00000000000..71d8dc9b971 --- /dev/null +++ b/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/CIAO/CCF/Test/IDL2/Compiler/result.idl.orig b/CIAO/CCF/Test/IDL2/Compiler/result.idl.orig new file mode 100644 index 00000000000..a29258b9e6f --- /dev/null +++ b/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/CIAO/CCF/Test/IDL2/Compiler/test.idl b/CIAO/CCF/Test/IDL2/Compiler/test.idl new file mode 100644 index 00000000000..737a729524b --- /dev/null +++ b/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/CIAO/CCF/Test/IDL2/LexicalAnalyzer/Coverage.idl b/CIAO/CCF/Test/IDL2/LexicalAnalyzer/Coverage.idl new file mode 100644 index 00000000000..a29dde465d2 --- /dev/null +++ b/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/CIAO/CCF/Test/IDL2/Parser/Recovery/interface.idl b/CIAO/CCF/Test/IDL2/Parser/Recovery/interface.idl new file mode 100644 index 00000000000..22a99ffadf2 --- /dev/null +++ b/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/CIAO/CCF/Test/IDL2/Parser/Recovery/module.idl b/CIAO/CCF/Test/IDL2/Parser/Recovery/module.idl new file mode 100644 index 00000000000..edfd868809b --- /dev/null +++ b/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/CIAO/CCF/Test/IDL2/SemanticGraph/HandBuilt/Builder.cpp b/CIAO/CCF/Test/IDL2/SemanticGraph/HandBuilt/Builder.cpp new file mode 100644 index 00000000000..764ab3fbc6f --- /dev/null +++ b/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/CIAO/CCF/Test/IDL2/SemanticGraph/HandBuilt/Builder.hpp b/CIAO/CCF/Test/IDL2/SemanticGraph/HandBuilt/Builder.hpp new file mode 100644 index 00000000000..794c56547d2 --- /dev/null +++ b/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/CIAO/CCF/Test/IDL2/SemanticGraph/HandBuilt/hand_built.cpp b/CIAO/CCF/Test/IDL2/SemanticGraph/HandBuilt/hand_built.cpp new file mode 100644 index 00000000000..3640282cfe3 --- /dev/null +++ b/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/CIAO/CCF/Test/IDL2/Traversal/Recreate/Generator.cpp b/CIAO/CCF/Test/IDL2/Traversal/Recreate/Generator.cpp new file mode 100644 index 00000000000..8aa3e895b9d --- /dev/null +++ b/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/CIAO/CCF/Test/IDL2/Traversal/Recreate/Generator.hpp b/CIAO/CCF/Test/IDL2/Traversal/Recreate/Generator.hpp new file mode 100644 index 00000000000..b0387317ad5 --- /dev/null +++ b/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/CIAO/CCF/Test/IDL2/Traversal/Recreate/GeneratorImpl.hpp b/CIAO/CCF/Test/IDL2/Traversal/Recreate/GeneratorImpl.hpp new file mode 100644 index 00000000000..52b89e03e12 --- /dev/null +++ b/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/CIAO/CCF/Test/IDL2/Traversal/Recreate/recreate.cpp b/CIAO/CCF/Test/IDL2/Traversal/Recreate/recreate.cpp new file mode 100644 index 00000000000..560040bbcb0 --- /dev/null +++ b/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; +} diff --git a/CIAO/CCF/Test/IDL3/Compiler/Generator.cpp b/CIAO/CCF/Test/IDL3/Compiler/Generator.cpp new file mode 100644 index 00000000000..06310ecd4b8 --- /dev/null +++ b/CIAO/CCF/Test/IDL3/Compiler/Generator.cpp @@ -0,0 +1,32 @@ +// file : Test/IDL3/Compiler/Generator.cpp +// author : Boris Kolpackov <boris@dre.vanderbilt.edu> +// cvs-id : $Id$ + +#include "Generator.hpp" +#include "GeneratorImpl.hpp" + +namespace IDL3 +{ + Generator:: + ~Generator () + { + } + + Generator:: + Generator () + : pimpl_ (new GeneratorImpl), impl_ (*pimpl_) + { + } + + Generator:: + Generator (GeneratorImpl& gi) + : pimpl_ (), impl_ (gi) + { + } + + void Generator:: + generate (CCF::IDL3::SemanticGraph::TranslationUnit& tu) + { + impl_.generate (tu); + } +} diff --git a/CIAO/CCF/Test/IDL3/Compiler/Generator.hpp b/CIAO/CCF/Test/IDL3/Compiler/Generator.hpp new file mode 100644 index 00000000000..667e1d3c69f --- /dev/null +++ b/CIAO/CCF/Test/IDL3/Compiler/Generator.hpp @@ -0,0 +1,34 @@ +// file : Test/IDL3/Compiler/Generator.hpp +// author : Boris Kolpackov <boris@dre.vanderbilt.edu> +// cvs-id : $Id$ + +#ifndef TEST_IDL3_COMPILER_GENERATOR_HPP +#define TEST_IDL3_COMPILER_GENERATOR_HPP + +#include <memory> + +#include "CCF/IDL3/SemanticGraph.hpp" + +namespace IDL3 +{ + class GeneratorImpl; + + class Generator + { + public: + ~Generator (); + Generator (); + + void + generate (CCF::IDL3::SemanticGraph::TranslationUnit& tu); + + protected: + Generator (GeneratorImpl&); + + protected: + std::auto_ptr<GeneratorImpl> pimpl_; + GeneratorImpl& impl_; + }; +} + +#endif // TEST_IDL3_COMPILER_GENERATOR_HPP diff --git a/CIAO/CCF/Test/IDL3/Compiler/GeneratorImpl.hpp b/CIAO/CCF/Test/IDL3/Compiler/GeneratorImpl.hpp new file mode 100644 index 00000000000..91e3ab3cb49 --- /dev/null +++ b/CIAO/CCF/Test/IDL3/Compiler/GeneratorImpl.hpp @@ -0,0 +1,616 @@ +// file : Test/IDL3/Compiler/GeneratorImpl.hpp +// author : Boris Kolpackov <boris@dre.vanderbilt.edu> +// cvs-id : $Id$ + +#ifndef TEST_IDL3_COMPILER_GENERATOR_IMPL_HPP +#define TEST_IDL3_COMPILER_GENERATOR_IMPL_HPP + +#include <iostream> + +#include "CCF/CodeGenerationKit/IndentationIDL.hpp" +#include "CCF/CodeGenerationKit/IndentationImplanter.hpp" + +#include "CCF/IDL3/SemanticGraph.hpp" +#include "CCF/IDL3/Traversal.hpp" + +#include "../../IDL2/Traversal/Recreate/GeneratorImpl.hpp" + +namespace IDL3 +{ + using namespace CCF::IDL3; + + using std::cout; + using std::endl; + + class GeneratorImpl : public IDL2::GeneratorImpl + { + protected: + // Layer 1 + // + + // Layer 2 + // + + // Layer 3 + // + + //-- + struct ComponentFwd : Traversal::Component + { + virtual void + traverse (Type& i) + { + cout << "component " << i.name () << ";"; + } + }; + + struct Component : Traversal::Component + { + virtual void + pre (Type&) + { + cout << "component "; + } + + virtual void + name (Type& i) + { + cout << i.name (); + } + + virtual void + inherits_pre (Type&) + { + cout << " : "; + } + + virtual void + supports_pre (Type&) + { + cout << " supports "; + } + + virtual void + names_pre (Type&) + { + cout << "{"; + } + + virtual void + names_post (Type&) + { + cout << "}"; + } + + virtual void + post (Type&) + { + cout << ";"; + } + + virtual void + comma (Type&) + { + cout << ", "; + } + }; + + + struct Home : Traversal::Home + { + virtual void + pre (Type&) + { + cout << "home "; + } + + virtual void + name (Type& i) + { + cout << i.name (); + } + + virtual void + inherits_pre (Type&) + { + cout << " : "; + } + + virtual void + supports_pre (Type&) + { + cout << " supports "; + } + + virtual void + manages_pre (Type&) + { + cout << " manages "; + } + + virtual void + names_pre (Type&) + { + cout << "{"; + } + + virtual void + names_post (Type&) + { + cout << "}"; + } + + virtual void + post (Type&) + { + cout << ";"; + } + + virtual void + comma (Type&) + { + cout << ", "; + } + }; + + struct AbstractEventType : Traversal::AbstractEventType + { + virtual void + pre (Type&) + { + cout << "abstract eventtype "; + } + + virtual void + name (Type& i) + { + cout << i.name (); + } + + virtual void + inherits_pre (Type&) + { + cout << " : "; + } + + virtual void + supports_pre (Type&) + { + cout << " supports "; + } + + virtual void + names_pre (Type&) + { + cout << "{"; + } + + virtual void + names_post (Type&) + { + cout << "}"; + } + + virtual void + post (Type&) + { + cout << ";"; + } + + virtual void + comma (Type&) + { + cout << ", "; + } + }; + + struct ConcreteEventType : Traversal::ConcreteEventType + { + virtual void + pre (Type&) + { + cout << "eventtype "; + } + + virtual void + name (Type& i) + { + cout << i.name (); + } + + virtual void + inherits_pre (Type&) + { + cout << " : "; + } + + virtual void + supports_pre (Type&) + { + cout << " supports "; + } + + virtual void + names_pre (Type&) + { + cout << "{"; + } + + virtual void + names_post (Type&) + { + cout << "}"; + } + + virtual void + post (Type&) + { + cout << ";"; + } + + virtual void + comma (Type&) + { + cout << ", "; + } + }; + + // Layer 4 + // + + struct Provider : Traversal::ProviderData + { + virtual void + pre (Type&) + { + cout << "provides "; + } + + virtual void + name (Type& e) + { + cout << " " << e.name (); + } + + virtual void + post (Type& e) + { + cout << ";"; + } + }; + + struct User : Traversal::UserData + { + virtual void + pre (Type&) + { + cout << "uses "; + } + + virtual void + name (Type& e) + { + cout << " " << e.name (); + } + + virtual void + post (Type& e) + { + cout << ";"; + } + }; + + struct Publisher : Traversal::PublisherData + { + virtual void + pre (Type&) + { + cout << "publishes "; + } + + virtual void + name (Type& e) + { + cout << " " << e.name (); + } + + virtual void + post (Type& e) + { + cout << ";"; + } + }; + + struct Emitter : Traversal::EmitterData + { + virtual void + pre (Type&) + { + cout << "emits "; + } + + virtual void + name (Type& e) + { + cout << " " << e.name (); + } + + virtual void + post (Type& e) + { + cout << ";"; + } + }; + + struct Consumer : Traversal::ConsumerData + { + virtual void + pre (Type&) + { + cout << "consumes "; + } + + virtual void + name (Type& e) + { + cout << " " << e.name (); + } + + virtual void + post (Type& e) + { + cout << ";"; + } + }; + + //-- + + struct HomeFactory : Traversal::HomeFactory + { + virtual void + returns (Type&) + { + cout << "factory "; + } + + virtual void + name (Type& hf) + { + cout << hf.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 HomeFinder : Traversal::HomeFinder + { + virtual void + returns (Type&) + { + cout << "finder "; + } + + virtual void + name (Type& hf) + { + cout << hf.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 << ", "; + } + }; + + // Layer 5 + // + + //-- + + public: + + GeneratorImpl () + { + // Layer 1 + // + + // Layer 2 + // + + // Layer 3 + // + + //-- + + mentions.node_traverser (component_fwd); + + defines.node_traverser (component); + + defines.node_traverser (home); + + defines.node_traverser (abstract_event_type); + defines.node_traverser (concrete_event_type); + + // Layer 4 + // + + component.edge_traverser (inherits); + component.edge_traverser (supports); + component.edge_traverser (component_defines); + + home.edge_traverser (inherits); + home.edge_traverser (supports); + home.edge_traverser (manages); + home.edge_traverser (home_defines); + + //@@ eventtype can define the whole bunch of stuff + // just like valuetype. + // + abstract_event_type.edge_traverser (inherits); + concrete_event_type.edge_traverser (inherits); + + //-- + + supports.node_traverser (type_name); + + component_defines.node_traverser (attribute); + component_defines.node_traverser (provider); + component_defines.node_traverser (user); + component_defines.node_traverser (publisher); + component_defines.node_traverser (emitter); + component_defines.node_traverser (consumer); + + manages.node_traverser (type_name); + + //@@ home can define the whole bunch of stuff just like + // interface & valuetype. + + home_defines.node_traverser (home_factory); + home_defines.node_traverser (home_finder); + + // Layer 5 + // + + provider.edge_traverser (belongs); + user.edge_traverser (belongs); + publisher.edge_traverser (belongs); + emitter.edge_traverser (belongs); + consumer.edge_traverser (belongs); + + home_factory.edge_traverser (receives); + home_finder.edge_traverser (receives); + + //-- + + // Layer 6 + // + + } + + protected: + // Layer 1 + // + + // Layer 2 + // + + // Layer 3 + // + + //-- + + ComponentFwd component_fwd; + + Component component; + + Home home; + + AbstractEventType abstract_event_type; + ConcreteEventType concrete_event_type; + + + // Layer 4 + // + Traversal::Supports supports; + Traversal::Defines component_defines; + + Traversal::Manages manages; + Traversal::Defines home_defines; + + //-- + + Provider provider; + User user; + Publisher publisher; + Emitter emitter; + Consumer consumer; + + HomeFactory home_factory; + HomeFinder home_finder; + + // Layer 5 + // + + // Layer 6 + // + + public: + void + generate (CCF::IDL3::SemanticGraph::TranslationUnit& tu) + { + // Plug automatic IDL indenter. + // + Indentation::Implanter<Indentation::IDL> guard (cout); + + unit.traverse (tu); + } + }; +} + +#endif // TEST_IDL3_COMPILER_GENERATOR_IMPL_HPP diff --git a/CIAO/CCF/Test/IDL3/Compiler/driver.cpp b/CIAO/CCF/Test/IDL3/Compiler/driver.cpp new file mode 100644 index 00000000000..d2f8ff91ba0 --- /dev/null +++ b/CIAO/CCF/Test/IDL3/Compiler/driver.cpp @@ -0,0 +1,97 @@ +// file : Test/IDL3/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/IDL3/LexicalAnalyzer.hpp" +#include "CCF/IDL3/Parser.hpp" +#include "CCF/IDL3/SemanticGraph.hpp" +#include "CCF/IDL3/SemanticAction/Impl/Factory.hpp" + +#include "Generator.hpp" + +#include <iostream> + +using std::cerr; +using std::cout; +using std::endl; + +using namespace CCF::CompilerElements; +using namespace CCF::IDL3; +using namespace 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); + + //@@ should be able to use IDL3 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; + + IDL3::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/Test/IDL3/Compiler/result.idl.orig b/CIAO/CCF/Test/IDL3/Compiler/result.idl.orig new file mode 100644 index 00000000000..730e7c103cb --- /dev/null +++ b/CIAO/CCF/Test/IDL3/Compiler/result.idl.orig @@ -0,0 +1,103 @@ +module ComponentTest +{ + component A; + component B + { + }; + interface I + { + }; + interface J + { + }; + component A : ::ComponentTest::B supports ::ComponentTest::I, ::ComponentTest::J + { + }; +}; +module ConsumesTest +{ + eventtype E + { + }; + component C + { + consumes ::ConsumesTest::E e; + }; +}; +module EmitsTest +{ + eventtype E + { + }; + component C + { + emits ::EmitsTest::E e; + }; +}; +module EventTypeTest +{ + eventtype E + { + }; +}; +module HomeTest +{ + interface I + { + }; + interface J + { + }; + component A + { + }; + home AH manages ::HomeTest::A + { + }; + component B + { + }; + home BH : ::HomeTest::AH supports ::HomeTest::I, ::HomeTest::J manages ::HomeTest::B + { + }; +}; +module HomeFactoryTest +{ + component A + { + }; + home AH manages ::HomeFactoryTest::A + { + factory new (in long size); + }; +}; +module ProvidesTest +{ + interface I + { + }; + component C + { + provides ::ProvidesTest::I i; + }; +}; +module PublishesTest +{ + eventtype E + { + }; + component C + { + publishes ::PublishesTest::E e; + }; +}; +module UsesTest +{ + interface I + { + }; + component C + { + uses ::UsesTest::I i; + }; +}; diff --git a/CIAO/CCF/Test/IDL3/Compiler/test.idl b/CIAO/CCF/Test/IDL3/Compiler/test.idl new file mode 100644 index 00000000000..a7e1cfb1d5a --- /dev/null +++ b/CIAO/CCF/Test/IDL3/Compiler/test.idl @@ -0,0 +1,166 @@ +// file : CCF/Test/IDL3/Compiler/test.idl +// author : Boris Kolpackov <boris@dre.vanderbilt.edu> +// cvs-id : $Id$ + +// Component +// +// + +module ComponentTest +{ + component A; + + component B + { + }; + + interface I + { + }; + + interface J + { + }; + + component A : B supports I, J + { + }; +}; + + +// Consumes +// +// +module ConsumesTest +{ + eventtype E + { + }; + + component C + { + consumes E e; + }; +}; + + +// Emits +// +// +module EmitsTest +{ + eventtype E + { + }; + + component C + { + emits E e; + }; +}; + + +// EventType (incomplete) +// +// +module EventTypeTest +{ + eventtype E + { + }; +}; + + +// Home +// +// +module HomeTest +{ + interface I + { + }; + + interface J + { + }; + + component A + { + }; + + home AH manages A + { + }; + + component B + { + }; + + home BH : AH supports I, J manages B + { + }; +}; + + +// HomeFactory +// +// +module HomeFactoryTest +{ + component A + { + }; + + home AH manages A + { + factory new (in long size); + }; +}; + + +// Provides +// +// +module ProvidesTest +{ + interface I + { + }; + + component C + { + provides I i; + }; +}; + + +// Publishes +// +// +module PublishesTest +{ + eventtype E + { + }; + + component C + { + publishes E e; + }; +}; + + +// Uses +// +// +module UsesTest +{ + interface I + { + }; + + component C + { + uses I i; + }; +}; |