diff options
author | jai <jai@ae88bc3d-4319-0410-8dbf-d08b4c9d3795> | 2007-01-29 21:10:39 +0000 |
---|---|---|
committer | jai <jai@ae88bc3d-4319-0410-8dbf-d08b4c9d3795> | 2007-01-29 21:10:39 +0000 |
commit | e7b830ab561638ed25822054be80ce12e8801d38 (patch) | |
tree | a5b9aa16924c541fcb424ee9460b1ac7f5a89352 /modules/CIAO/CCF/Test/IDL3/Compiler | |
parent | 9b720f395833b3ce2f499463e5fed37a0da926f4 (diff) | |
download | ATCD-DiffServ-Merge.tar.gz |
branching/taggingDiffServ-Merge
Diffstat (limited to 'modules/CIAO/CCF/Test/IDL3/Compiler')
-rw-r--r-- | modules/CIAO/CCF/Test/IDL3/Compiler/Generator.cpp | 32 | ||||
-rw-r--r-- | modules/CIAO/CCF/Test/IDL3/Compiler/Generator.hpp | 34 | ||||
-rw-r--r-- | modules/CIAO/CCF/Test/IDL3/Compiler/GeneratorImpl.hpp | 616 | ||||
-rw-r--r-- | modules/CIAO/CCF/Test/IDL3/Compiler/driver.cpp | 97 | ||||
-rw-r--r-- | modules/CIAO/CCF/Test/IDL3/Compiler/result.idl.orig | 103 | ||||
-rw-r--r-- | modules/CIAO/CCF/Test/IDL3/Compiler/test.idl | 166 |
6 files changed, 1048 insertions, 0 deletions
diff --git a/modules/CIAO/CCF/Test/IDL3/Compiler/Generator.cpp b/modules/CIAO/CCF/Test/IDL3/Compiler/Generator.cpp new file mode 100644 index 00000000000..06310ecd4b8 --- /dev/null +++ b/modules/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/modules/CIAO/CCF/Test/IDL3/Compiler/Generator.hpp b/modules/CIAO/CCF/Test/IDL3/Compiler/Generator.hpp new file mode 100644 index 00000000000..667e1d3c69f --- /dev/null +++ b/modules/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/modules/CIAO/CCF/Test/IDL3/Compiler/GeneratorImpl.hpp b/modules/CIAO/CCF/Test/IDL3/Compiler/GeneratorImpl.hpp new file mode 100644 index 00000000000..91e3ab3cb49 --- /dev/null +++ b/modules/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/modules/CIAO/CCF/Test/IDL3/Compiler/driver.cpp b/modules/CIAO/CCF/Test/IDL3/Compiler/driver.cpp new file mode 100644 index 00000000000..d2f8ff91ba0 --- /dev/null +++ b/modules/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/modules/CIAO/CCF/Test/IDL3/Compiler/result.idl.orig b/modules/CIAO/CCF/Test/IDL3/Compiler/result.idl.orig new file mode 100644 index 00000000000..730e7c103cb --- /dev/null +++ b/modules/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/modules/CIAO/CCF/Test/IDL3/Compiler/test.idl b/modules/CIAO/CCF/Test/IDL3/Compiler/test.idl new file mode 100644 index 00000000000..a7e1cfb1d5a --- /dev/null +++ b/modules/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; + }; +}; |