diff options
author | parsons <parsons@ae88bc3d-4319-0410-8dbf-d08b4c9d3795> | 2003-05-31 00:56:39 +0000 |
---|---|---|
committer | parsons <parsons@ae88bc3d-4319-0410-8dbf-d08b4c9d3795> | 2003-05-31 00:56:39 +0000 |
commit | 0a0416f0d11c724103868c0b091a7138f6999443 (patch) | |
tree | 1585434c354d7ff77b14ded3fd6f8775584781b5 | |
parent | 8ec551a46536d0949f10a9b87f065b8bd74b1ffc (diff) | |
download | ATCD-0a0416f0d11c724103868c0b091a7138f6999443.tar.gz |
ChangeLogTag: Fri May 30 19:33:36 2003 Jeff Parsons <j.parsons@vanderbilt.edu>
162 files changed, 24119 insertions, 0 deletions
diff --git a/TAO/CIAO/CCF/CCF/CCF.sln b/TAO/CIAO/CCF/CCF/CCF.sln new file mode 100644 index 00000000000..2cd44b64537 --- /dev/null +++ b/TAO/CIAO/CCF/CCF/CCF.sln @@ -0,0 +1,45 @@ +Microsoft Visual Studio Solution File, Format Version 8.00 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "IDL2", "IDL2\IDL2.vcproj", "{BC4A74B6-EBE7-486D-A537-B4217AE7304E}" + ProjectSection(ProjectDependencies) = postProject + EndProjectSection +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "IDL3", "IDL3\IDL3.vcproj", "{97D61986-05D8-4B2A-B8B2-5095E58909FE}" + ProjectSection(ProjectDependencies) = postProject + EndProjectSection +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "CIDL", "CIDL\CIDL.vcproj", "{39A4243B-8D97-4C1A-BC6B-C49FE4D48D4D}" + ProjectSection(ProjectDependencies) = postProject + EndProjectSection +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "CodeGenerationKit", "CodeGenerationKit\CodeGenerationKit.vcproj", "{93C22389-AD2D-45CD-98C6-D9C5D6679B09}" + ProjectSection(ProjectDependencies) = postProject + EndProjectSection +EndProject +Global + GlobalSection(SolutionConfiguration) = preSolution + Debug = Debug + Release = Release + EndGlobalSection + GlobalSection(ProjectConfiguration) = postSolution + {BC4A74B6-EBE7-486D-A537-B4217AE7304E}.Debug.ActiveCfg = Debug|Win32 + {BC4A74B6-EBE7-486D-A537-B4217AE7304E}.Debug.Build.0 = Debug|Win32 + {BC4A74B6-EBE7-486D-A537-B4217AE7304E}.Release.ActiveCfg = Release|Win32 + {BC4A74B6-EBE7-486D-A537-B4217AE7304E}.Release.Build.0 = Release|Win32 + {97D61986-05D8-4B2A-B8B2-5095E58909FE}.Debug.ActiveCfg = Debug|Win32 + {97D61986-05D8-4B2A-B8B2-5095E58909FE}.Debug.Build.0 = Debug|Win32 + {97D61986-05D8-4B2A-B8B2-5095E58909FE}.Release.ActiveCfg = Release|Win32 + {97D61986-05D8-4B2A-B8B2-5095E58909FE}.Release.Build.0 = Release|Win32 + {39A4243B-8D97-4C1A-BC6B-C49FE4D48D4D}.Debug.ActiveCfg = Debug|Win32 + {39A4243B-8D97-4C1A-BC6B-C49FE4D48D4D}.Debug.Build.0 = Debug|Win32 + {39A4243B-8D97-4C1A-BC6B-C49FE4D48D4D}.Release.ActiveCfg = Release|Win32 + {39A4243B-8D97-4C1A-BC6B-C49FE4D48D4D}.Release.Build.0 = Release|Win32 + {93C22389-AD2D-45CD-98C6-D9C5D6679B09}.Debug.ActiveCfg = Debug|Win32 + {93C22389-AD2D-45CD-98C6-D9C5D6679B09}.Debug.Build.0 = Debug|Win32 + {93C22389-AD2D-45CD-98C6-D9C5D6679B09}.Release.ActiveCfg = Release|Win32 + {93C22389-AD2D-45CD-98C6-D9C5D6679B09}.Release.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + EndGlobalSection + GlobalSection(ExtensibilityAddIns) = postSolution + EndGlobalSection +EndGlobal diff --git a/TAO/CIAO/CCF/CCF/CIDL/CIDL.cpp b/TAO/CIAO/CCF/CCF/CIDL/CIDL.cpp new file mode 100644 index 00000000000..cfa1da318d3 --- /dev/null +++ b/TAO/CIAO/CCF/CCF/CIDL/CIDL.cpp @@ -0,0 +1 @@ +// $Id$ diff --git a/TAO/CIAO/CCF/CCF/CIDL/CIDL.vcproj b/TAO/CIAO/CCF/CCF/CIDL/CIDL.vcproj new file mode 100644 index 00000000000..f658c5476fc --- /dev/null +++ b/TAO/CIAO/CCF/CCF/CIDL/CIDL.vcproj @@ -0,0 +1,150 @@ +<?xml version="1.0" encoding="Windows-1252"?> +<VisualStudioProject + ProjectType="Visual C++" + Version="7.10" + Name="CIDL" + ProjectGUID="{39A4243B-8D97-4C1A-BC6B-C49FE4D48D4D}" + Keyword="Win32Proj"> + <Platforms> + <Platform + Name="Win32"/> + </Platforms> + <Configurations> + <Configuration + Name="Debug|Win32" + OutputDirectory="$(ProjectDir)" + IntermediateDirectory="Debug" + ConfigurationType="4" + CharacterSet="2"> + <Tool + Name="VCCLCompilerTool" + Optimization="0" + AdditionalIncludeDirectories="../..;../../External/Utility" + PreprocessorDefinitions="WIN32;_DEBUG;_LIB" + MinimalRebuild="TRUE" + BasicRuntimeChecks="3" + RuntimeLibrary="5" + ForceConformanceInForLoopScope="TRUE" + RuntimeTypeInfo="TRUE" + UsePrecompiledHeader="0" + WarningLevel="3" + Detect64BitPortabilityProblems="TRUE" + DebugInformationFormat="4"/> + <Tool + Name="VCCustomBuildTool"/> + <Tool + Name="VCLibrarianTool" + OutputFile="$(OutDir)/CIDL.lib"/> + <Tool + Name="VCMIDLTool"/> + <Tool + Name="VCPostBuildEventTool"/> + <Tool + Name="VCPreBuildEventTool"/> + <Tool + Name="VCPreLinkEventTool"/> + <Tool + Name="VCResourceCompilerTool"/> + <Tool + Name="VCWebServiceProxyGeneratorTool"/> + <Tool + Name="VCXMLDataGeneratorTool"/> + <Tool + Name="VCManagedWrapperGeneratorTool"/> + <Tool + Name="VCAuxiliaryManagedWrapperGeneratorTool"/> + </Configuration> + <Configuration + Name="Release|Win32" + OutputDirectory="Release" + IntermediateDirectory="Release" + ConfigurationType="4" + CharacterSet="2"> + <Tool + Name="VCCLCompilerTool" + PreprocessorDefinitions="WIN32;NDEBUG;_LIB" + RuntimeLibrary="4" + UsePrecompiledHeader="0" + WarningLevel="3" + Detect64BitPortabilityProblems="TRUE" + DebugInformationFormat="3"/> + <Tool + Name="VCCustomBuildTool"/> + <Tool + Name="VCLibrarianTool" + OutputFile="$(OutDir)/CIDL.lib"/> + <Tool + Name="VCMIDLTool"/> + <Tool + Name="VCPostBuildEventTool"/> + <Tool + Name="VCPreBuildEventTool"/> + <Tool + Name="VCPreLinkEventTool"/> + <Tool + Name="VCResourceCompilerTool"/> + <Tool + Name="VCWebServiceProxyGeneratorTool"/> + <Tool + Name="VCXMLDataGeneratorTool"/> + <Tool + Name="VCManagedWrapperGeneratorTool"/> + <Tool + Name="VCAuxiliaryManagedWrapperGeneratorTool"/> + </Configuration> + </Configurations> + <References> + </References> + <Files> + <Filter + Name="Source Files" + Filter="cpp;c;cxx;def;odl;idl;hpj;bat;asm;asmx" + UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"> + <File + RelativePath=".\CIDL_SyntaxTree.cpp"> + </File> + <File + RelativePath=".\CIDL_Traversal.cpp"> + </File> + </Filter> + <Filter + Name="Header Files" + Filter="h;hpp;hxx;hm;inl;inc;xsd" + UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"> + <File + RelativePath=".\CIDL_LexicalAnalyzer.hpp"> + </File> + <File + RelativePath=".\CIDL_Parser.hpp"> + </File> + <File + RelativePath=".\CIDL_SemanticAction.hpp"> + </File> + <File + RelativePath=".\CIDL_SemanticActionImpl.hpp"> + </File> + <File + RelativePath=".\CIDL_SyntaxTree.hpp"> + </File> + <File + RelativePath=".\CIDL_SyntaxTreeFwd.hpp"> + </File> + <File + RelativePath=".\CIDL_Traversal.hpp"> + </File> + <File + RelativePath=".\MSVC_Pragmas.hpp"> + </File> + </Filter> + <Filter + Name="Resource Files" + Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx" + UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}"> + </Filter> + <File + RelativePath=".\ReadMe.txt"> + </File> + </Files> + <Globals> + </Globals> +</VisualStudioProject> diff --git a/TAO/CIAO/CCF/CCF/CIDL/CIDL_LexicalAnalyzer.hpp b/TAO/CIAO/CCF/CCF/CIDL/CIDL_LexicalAnalyzer.hpp new file mode 100644 index 00000000000..9d2570d9c84 --- /dev/null +++ b/TAO/CIAO/CCF/CCF/CIDL/CIDL_LexicalAnalyzer.hpp @@ -0,0 +1,57 @@ +// $Id$ +#ifndef CCF_CIDL_LEXICAL_ANALYZER_HPP +#define CCF_CIDL_LEXICAL_ANALYZER_HPP + +#include "MSVC_Pragmas.hpp" + +#include "CCF/IDL3/IDL3_LexicalAnalyzer.hpp" + +#include <string> + +namespace CIDL +{ + class LexicalAnalyzer : public virtual IDL3::LexicalAnalyzer + { + public: + virtual + ~LexicalAnalyzer () throw () {} + + public: + + // Keywords (alphabetic order). + + KeywordPtr composition; + KeywordPtr entity; + KeywordPtr executor; + KeywordPtr implements; + KeywordPtr process; + KeywordPtr service; + KeywordPtr session; + + + + LexicalAnalyzer (CCF::TokenStream<char>& is) + : IDL2::LexicalAnalyzer (is), + IDL3::LexicalAnalyzer (is), + + composition (new Keyword), + entity (new Keyword), + executor (new Keyword), + implements (new Keyword), + process (new Keyword), + service (new Keyword), + session (new Keyword) + { + + keyword_table_["composition"] = composition; + keyword_table_["entity" ] = entity; + keyword_table_["executor" ] = executor; + keyword_table_["implements" ] = implements; + keyword_table_["process" ] = process; + keyword_table_["service" ] = service; + keyword_table_["session" ] = session; + } + }; +} + +#endif // CCF_CIDL_LEXICAL_ANALYZER_HPP diff --git a/TAO/CIAO/CCF/CCF/CIDL/CIDL_Parser.hpp b/TAO/CIAO/CCF/CCF/CIDL/CIDL_Parser.hpp new file mode 100644 index 00000000000..cd1bee26496 --- /dev/null +++ b/TAO/CIAO/CCF/CCF/CIDL/CIDL_Parser.hpp @@ -0,0 +1,202 @@ +// $Id$ +#ifndef CCF_CIDL_PARSER_HPP +#define CCF_CIDL_PARSER_HPP + +#include "MSVC_Pragmas.hpp" + +#include "CCF/IDL3/IDL3_Parser.hpp" +#include "CCF/CIDL/CIDL_LexicalAnalyzer.hpp" +#include "CCF/CIDL/CIDL_SemanticAction.hpp" + +namespace CIDL +{ + class Parser : public virtual IDL3::Parser + { + public: + virtual + ~Parser () throw () {} + + protected: + + // + // Semanic action types + // + typedef + SemanticAction::Composition + Composition; + + typedef + SemanticAction::HomeExecutor + HomeExecutor; + + protected: + LexicalAnalyzer const& lexer_; + SemanticActionFactory& actions_; + + // + // Primitives (alphabetic order). + // + + KeywordParser COMPOSITION; + KeywordParser ENTITY; + KeywordParser EXECUTOR; + KeywordParser IMPLEMENTS; + KeywordParser PROCESS; + KeywordParser SERVICE; + KeywordParser SESSION; + + // + // Language + // + + Rule extension; + + // Composition + Rule composition_decl; + Rule composition_header; + Rule composition_category; + + // Home executor + Rule home_executor_decl; + Rule home_executor_header; + Rule home_executor_body; + Rule home_executor_home_impl_decl; + Rule home_executor_executor_decl; + + public: + + Parser (LexicalAnalyzer const& l, SemanticActionFactory& f) + : IDL2::Parser (l, f), + IDL3::Parser (l, f), + lexer_ (l), + actions_ (f), + + COMPOSITION (l.composition), + ENTITY (l.entity), + EXECUTOR (l.executor), + IMPLEMENTS (l.implements), + PROCESS (l.process), + SERVICE (l.service), + SESSION (l.session), + + act_composition_begin (this, &Parser::act_composition_begin_core), + act_composition_open_scope (f.composition (), &Scope::open_scope), + act_composition_close_scope (f.composition (), &Scope::close_scope), + act_composition_end (f.composition (), &Composition::end), + + act_home_executor_begin (f.home_executor (), + &HomeExecutor::begin), + act_home_executor_open_scope (f.home_executor (), + &Scope::open_scope), + act_home_executor_implements (f.home_executor (), + &HomeExecutor::implements), + act_home_executor_manages (f.home_executor (), + &HomeExecutor::manages), + act_home_executor_close_scope (f.home_executor (), + &Scope::open_scope), + act_home_executor_end (f.home_executor (), + &HomeExecutor::end) + + { + IDL3::Parser::extension = + composition_decl + | extension + ; + + // + // Composition + // + composition_decl = + composition_header + >> LBRACE[act_composition_open_scope] + >> home_executor_decl + >> RBRACE[act_composition_close_scope] + >> SEMI[act_composition_end] + ; + + composition_header = + COMPOSITION + >> (composition_category >> simple_identifier)[act_composition_begin] + ; + + composition_category = + ENTITY + | PROCESS + | SERVICE + | SESSION + ; + + // + // Home executor + // + home_executor_decl = + home_executor_header + >> LBRACE[act_home_executor_open_scope] + >> home_executor_home_impl_decl + >> home_executor_executor_decl + >> RBRACE[act_home_executor_close_scope] + >> SEMI[act_home_executor_end] + ; + + home_executor_header = + HOME + >> EXECUTOR + >> simple_identifier[act_home_executor_begin] + ; + + home_executor_home_impl_decl = + IMPLEMENTS + >> identifier[act_home_executor_implements] + >> SEMI + ; + + home_executor_executor_decl = + MANAGES + >> simple_identifier[act_home_executor_manages] + >> SEMI + ; + } + + protected: + void + act_composition_begin_core (Iterator begin, Iterator end) const + { + Composition::Category::Value c; + + if(identical (lexer_.entity, *begin)) + { + c = Composition::Category::ENTITY; + } + else if (identical (lexer_.process, *begin)) + { + c = Composition::Category::PROCESS; + } + else if (identical (lexer_.service, *begin)) + { + c = Composition::Category::SERVICE; + } + else + { + c = Composition::Category::SESSION; + } + + begin++; + + actions_.composition ().begin (typical<SimpleIdentifierPtr>(*begin), c); + } + + ActionExecutor<Parser> act_composition_begin; + ScopeAction act_composition_open_scope; + ScopeAction act_composition_close_scope; + NoArgAction<Composition> act_composition_end; + + OneArgAction<SimpleIdentifierPtr, HomeExecutor> act_home_executor_begin; + ScopeAction act_home_executor_open_scope; + OneArgAction<IdentifierPtr, HomeExecutor> act_home_executor_implements; + OneArgAction<SimpleIdentifierPtr, HomeExecutor> act_home_executor_manages; + ScopeAction act_home_executor_close_scope; + NoArgAction<HomeExecutor> act_home_executor_end; + }; +} + +#endif // CCF_CIDL_PARSER_HPP diff --git a/TAO/CIAO/CCF/CCF/CIDL/CIDL_SemanticAction.hpp b/TAO/CIAO/CCF/CCF/CIDL/CIDL_SemanticAction.hpp new file mode 100644 index 00000000000..714a6fa2722 --- /dev/null +++ b/TAO/CIAO/CCF/CCF/CIDL/CIDL_SemanticAction.hpp @@ -0,0 +1,74 @@ +// $Id$ +#ifndef CCF_CIDL_SEMANTIC_ACTION_HPP +#define CCF_CIDL_SEMANTIC_ACTION_HPP + +#include "MSVC_Pragmas.hpp" + +#include "CCF/IDL3/IDL3_SemanticAction.hpp" + +namespace CIDL +{ + namespace SemanticAction + { + using namespace IDL3::SemanticAction; + + class Composition : public virtual Scope + { + public: + struct Category + { + enum Value + { + ENTITY, + PROCESS, + SERVICE, + SESSION + }; + + friend std::ostream& + operator<< (std::ostream& o, Value v) + { + if (v == ENTITY) o << "entity"; + else if (v == PROCESS) o << "process"; + else if (v == SERVICE) o << "service"; + else o << "session"; + return o; + } + }; + + virtual void + begin (SimpleIdentifierPtr const& id, Category::Value category) = 0; + + virtual void + end () = 0; + }; + + class HomeExecutor : public virtual Scope + { + public: + virtual void + begin (SimpleIdentifierPtr const& id) = 0; + + virtual void + implements (IdentifierPtr const& id) = 0; + + virtual void + manages (SimpleIdentifierPtr const& id) = 0; + + virtual void + end () = 0; + }; + } + + class SemanticActionFactory : public virtual IDL3::SemanticActionFactory + { + public: + virtual SemanticAction::Composition& + composition () = 0; + + virtual SemanticAction::HomeExecutor& + home_executor () = 0; + }; +} + +#endif // CCF_CIDL_SEMANTIC_ACTION_HPP diff --git a/TAO/CIAO/CCF/CCF/CIDL/CIDL_SemanticActionImpl.hpp b/TAO/CIAO/CCF/CCF/CIDL/CIDL_SemanticActionImpl.hpp new file mode 100644 index 00000000000..17a809784a7 --- /dev/null +++ b/TAO/CIAO/CCF/CCF/CIDL/CIDL_SemanticActionImpl.hpp @@ -0,0 +1,251 @@ +// $Id$ +#ifndef CCF_CIDL_SEMANTIC_ACTION_IMPL_HPP +#define CCF_CIDL_SEMANTIC_ACTION_IMPL_HPP + +#include "MSVC_Pragmas.hpp" + +#include "CCF/CIDL/CIDL_SyntaxTree.hpp" +#include "CCF/CIDL/CIDL_SemanticAction.hpp" +#include "CCF/IDL3/IDL3_SemanticActionImpl.hpp" + +namespace CIDL +{ + namespace SemanticAction + { + namespace Impl + { + using IDL2::SemanticAction::Impl::ScopeBase; + + class Composition : public virtual SemanticAction::Composition, + public virtual ScopeBase<SyntaxTree::CompositionPtr> + { + public: + virtual + ~Composition () throw () {} + + Composition (SyntaxTree::ScopePtr& scope) + : ScopeBase<SyntaxTree::CompositionPtr> (scope) + { + } + + virtual void + begin (SimpleIdentifierPtr const& id, Category::Value c) + { + cerr << "composition " << c << " " << id << endl; + + SyntaxTree::SimpleName name (id->value ()); + + SyntaxTree::Composition::Category::Value category = + SyntaxTree::Composition::Category::SESSION; + + if (c == Category::ENTITY) + { + category = SyntaxTree::Composition::Category::ENTITY; + } + else if (c == Category::PROCESS) + { + category = SyntaxTree::Composition::Category::PROCESS; + } + else if (c == Category::SERVICE) + { + category = SyntaxTree::Composition::Category::SERVICE; + } + + SyntaxTree::CompositionPtr cp ( + new SyntaxTree::Composition (name, category, scope_)); + + scope_->insert (cp); + push (cp); + } + + virtual void + open_scope () + { + scope_ = top (); + } + + virtual void + close_scope () + { + scope_ = scope_->scope (); + } + + virtual void + end () + { + pop (); + cerr << "end" << endl; + } + }; + + class HomeExecutor : + public virtual SemanticAction::HomeExecutor, + public virtual ScopeBase<SyntaxTree::HomeExecutorPtr> + { + public: + virtual + ~HomeExecutor () throw () {} + + HomeExecutor (SyntaxTree::ScopePtr& scope) + : ScopeBase<SyntaxTree::HomeExecutorPtr> (scope), + name_ (""), + implements_ (""), + manages_ ("") + + { + } + + virtual void + begin (SimpleIdentifierPtr const& id) + { + cerr << "home executor " << id << endl; + name_ = SyntaxTree::SimpleName (id->value ()); + } + + virtual void + open_scope () + { + // Note: nothing is expected to go to home executor scope + // so watch for grammar changes. + } + + virtual void + implements (IdentifierPtr const& id) + { + cerr << "implements " << id << endl; + + using namespace SyntaxTree; + + Name name (id->value ()); + + struct ImplementsPredicate : + public DeclarationTable::ResolvePredicate + { + struct IncompatibleType : + public DeclarationTable::ResolutionFailure + { + IncompatibleType (std::string const& t) : type (t) {} + std::string type; + }; + + virtual bool + test (DeclarationPtr const& d) + throw (IncompatibleType) + { + std::string type = d->declaration_type (); + + if (type != "home") throw IncompatibleType (type); + + return strict_cast<TypeDecl> (d)->defined (); + } + } p; + + try + { + ScopedName sn = scope_->table ().resolve ( + name, + scope_->name (), + scope_->peek_order (), + p); + + implements_ = sn; + } + catch (ImplementsPredicate::IncompatibleType const& e) + { + cerr << "error: invalid implements specification" << endl; + + cerr << "specifying " << e.type << " \'" << name + << "\' in home executor implements clause is illegal" + << endl; + } + catch (DeclarationTable::NameNotFound const&) + { + cerr << "error: invalid implements specification" << endl; + cerr << "no home with name \'" + << name << "\' visible from scope \'" + << scope_->name () << "\'" << endl; + } + catch (DeclarationTable::PredicateNotMet const&) + { + cerr << "error: invalid implements specification" << endl; + cerr << "no defined home with name \'" + << name << "\' visible from scope \'" + << scope_->name () << "\'" << endl; + cerr << "implementing forward-declared home is illegal" + << endl; + } + + } + + virtual void + manages (SimpleIdentifierPtr const& id) + { + cerr << "manages " << id << endl; + manages_ = SyntaxTree::SimpleName (id->value ()); + } + + virtual void + close_scope () + { + // Note: nothing is expected to go to home executor scope + // so watch for grammar changes. + } + + virtual void + end () + { + cerr << "end" << endl; + + using namespace SyntaxTree; + + HomeExecutorPtr he (new SyntaxTree::HomeExecutor ( + name_, + scope_, + implements_, + manages_)); + scope_->insert (he); + } + private: + SyntaxTree::SimpleName name_; + SyntaxTree::ScopedName implements_; + SyntaxTree::SimpleName manages_; + }; + } + } + + //@@ Maybe I should bring this class back in to Impl namespace. + class SemanticActionFactoryImpl : + public virtual CIDL::SemanticActionFactory, + public virtual IDL3::SemanticActionFactoryImpl + { + public: + virtual + ~SemanticActionFactoryImpl () throw () {} + + SemanticActionFactoryImpl (SyntaxTree::TranslationRegionPtr const& r) + : IDL2::SemanticActionFactoryImpl (r), + IDL3::SemanticActionFactoryImpl (r), + composition_ (scope_), + home_executor_ (scope_) + { + } + public: + virtual SemanticAction::Composition& + composition () + { + return composition_; + } + + virtual SemanticAction::HomeExecutor& + home_executor () + { + return home_executor_; + } + + private: + SemanticAction::Impl::Composition composition_; + SemanticAction::Impl::HomeExecutor home_executor_; + }; +} + +#endif // CCF_CIDL_SEMANTIC_ACTION_IMPL_HPP diff --git a/TAO/CIAO/CCF/CCF/CIDL/CIDL_SyntaxTree.cpp b/TAO/CIAO/CCF/CCF/CIDL/CIDL_SyntaxTree.cpp new file mode 100644 index 00000000000..577b426e73c --- /dev/null +++ b/TAO/CIAO/CCF/CCF/CIDL/CIDL_SyntaxTree.cpp @@ -0,0 +1,61 @@ +// $Id$ +#include "CIDL_Traversal.hpp" +#include "CIDL_SyntaxTree.hpp" + +namespace CIDL +{ + namespace SyntaxTree + { + using CCF::Traversal::try_visit; + + namespace + { + //@@ repetition of what's already in IDL2 & IDL3 + bool + try_visit_scope (CCF::Traversal::Visitor* v, + ScopePtr const& node) + { + return try_visit<Traversal::Scope> ( + &Traversal::Scope::visit_scope, + v, + node); + } + } + + // + // Composition + // + + void Composition:: + accept (CCF::Traversal::Visitor* v) + { + CompositionPtr self (ReferenceCounting::add_ref (this)); + + if (!try_visit<Traversal::Composition> ( + &Traversal::Composition::visit_composition, + v, + self)) + { + try_visit_scope (v, self); + } + } + + // + // Home + // + + void HomeExecutor:: + accept (CCF::Traversal::Visitor* v) + { + HomeExecutorPtr self (ReferenceCounting::add_ref (this)); + + if (!try_visit<Traversal::HomeExecutor> ( + &Traversal::HomeExecutor::visit_home_executor, + v, + self)) + { + try_visit_scope (v, self); + } + } + } +} diff --git a/TAO/CIAO/CCF/CCF/CIDL/CIDL_SyntaxTree.hpp b/TAO/CIAO/CCF/CCF/CIDL/CIDL_SyntaxTree.hpp new file mode 100644 index 00000000000..6b1e9df4f66 --- /dev/null +++ b/TAO/CIAO/CCF/CCF/CIDL/CIDL_SyntaxTree.hpp @@ -0,0 +1,141 @@ +// $Id$ +#ifndef CCF_CIDL_SYNTAX_TREE_HPP +#define CCF_CIDL_SYNTAX_TREE_HPP + +#include "MSVC_Pragmas.hpp" + +#include "CCF/IDL3/IDL3_SyntaxTree.hpp" + +namespace CIDL +{ + namespace SyntaxTree + { + + // Import all nodes of IDL3 + using namespace IDL3::SyntaxTree; + + + class Composition : public virtual Scope + { + public: + struct Category + { + enum Value + { + ENTITY, + PROCESS, + SERVICE, + SESSION + }; + + friend std::ostream& + operator<< (std::ostream& o, Value v) + { + if (v == ENTITY) o << "entity"; + else if (v == PROCESS) o << "process"; + else if (v == SERVICE) o << "service"; + else o << "session"; + return o; + } + }; + + public: + virtual + ~Composition () throw () {} + + Composition (SimpleName const& name, + Category::Value category, + ScopePtr const& scope) + : Declaration (name, scope), + Scope (name, scope), + category_ (category) + { + } + + public: + Category::Value + category () const + { + return category_; + } + + // Runtime declaration type information + public: + virtual std::string + declaration_type () + { + return "composition"; + } + + // Traversal + public: + virtual void + accept (CCF::Traversal::Visitor* v); + + private: + Category::Value category_; + }; + + typedef + StrictPtr<Composition> + CompositionPtr; + + typedef + DeclarationOrderComparator<CompositionPtr> + CompositionOrderComparator; + + class HomeExecutor : public virtual Scope + { + public: + virtual + ~HomeExecutor () throw () {} + + HomeExecutor (SimpleName const& name, + ScopePtr const& scope, + ScopedName implements, + SimpleName manages) + : Declaration (name, scope), + Scope (name, scope), + implements_ (scope->table (), implements), + manages_ (manages) + { + } + + public: + HomeDefPtr + implements () const + { + return implements_.resolve (); + } + + SimpleName + manages () const + { + return manages_; + } + + // Runtime declaration type information + public: + virtual std::string + declaration_type () + { + return "home executor"; + } + + // Traversal + public: + virtual void + accept (CCF::Traversal::Visitor* v); + + private: + HomeDefRef implements_; + SimpleName manages_; + }; + + typedef + StrictPtr<HomeExecutor> + HomeExecutorPtr; + } +} + +#endif // CCF_CIDL_SYNTAX_TREE_HPP diff --git a/TAO/CIAO/CCF/CCF/CIDL/CIDL_SyntaxTreeFwd.hpp b/TAO/CIAO/CCF/CCF/CIDL/CIDL_SyntaxTreeFwd.hpp new file mode 100644 index 00000000000..80229bb5722 --- /dev/null +++ b/TAO/CIAO/CCF/CCF/CIDL/CIDL_SyntaxTreeFwd.hpp @@ -0,0 +1,29 @@ +// $Id$ +#ifndef CCF_CIDL_SYNTAX_TREE_FWD_HPP +#define CCF_CIDL_SYNTAX_TREE_FWD_HPP + +#include "MSVC_Pragmas.hpp" + +#include "CCF/IDL3/IDL3_SyntaxTreeFwd.hpp" + +namespace CIDL +{ + namespace SyntaxTree + { + + // Import all nodes of IDL3 + using namespace IDL3::SyntaxTree; + + class Composition; + typedef + StrictPtr<Composition> + CompositionPtr; + + class HomeExecutor; + typedef + StrictPtr<HomeExecutor> + HomeExecutorPtr; + } +} + +#endif // CCF_CIDL_SYNTAX_TREE_FWD_HPP diff --git a/TAO/CIAO/CCF/CCF/CIDL/CIDL_Traversal.cpp b/TAO/CIAO/CCF/CCF/CIDL/CIDL_Traversal.cpp new file mode 100644 index 00000000000..22c635605f0 --- /dev/null +++ b/TAO/CIAO/CCF/CCF/CIDL/CIDL_Traversal.cpp @@ -0,0 +1,79 @@ +// $Id$ +#include "CIDL_Traversal.hpp" +#include "CIDL_SyntaxTree.hpp" + +namespace CIDL +{ + namespace Traversal + { + namespace + { + //@@ code duplication + void + iterate_scope (SyntaxTree::ScopePtr const& s, + CCF::Traversal::Visitor* v) + { + for (SyntaxTree::Scope::Iterator i = s->begin (); i != s->end (); i++) + { + (*i)->accept (v); + } + } + } + + // + // Composition + // + + void Composition:: + visit_composition (NodePtr const& c) + { + visit_composition_pre (c); + visit_composition_scope (c); + visit_composition_post (c); + } + + void Composition:: + visit_composition_pre (NodePtr const&) + { + } + + void Composition:: + visit_composition_scope (NodePtr const& c) + { + iterate_scope (c, this); + } + + void Composition:: + visit_composition_post (NodePtr const&) + { + } + + // + // HomeExecutor + // + + void HomeExecutor:: + visit_home_executor (NodePtr const& he) + { + visit_home_executor_pre (he); + visit_home_executor_scope (he); + visit_home_executor_post (he); + } + + void HomeExecutor:: + visit_home_executor_pre (NodePtr const&) + { + } + + void HomeExecutor:: + visit_home_executor_scope (NodePtr const& he) + { + iterate_scope (he, this); + } + + void HomeExecutor:: + visit_home_executor_post (NodePtr const&) + { + } + } +} diff --git a/TAO/CIAO/CCF/CCF/CIDL/CIDL_Traversal.hpp b/TAO/CIAO/CCF/CCF/CIDL/CIDL_Traversal.hpp new file mode 100644 index 00000000000..c562ecd4d42 --- /dev/null +++ b/TAO/CIAO/CCF/CCF/CIDL/CIDL_Traversal.hpp @@ -0,0 +1,50 @@ +// $Id$ +#ifndef CCF_CIDL_TRAVERSAL_HPP +#define CCF_CIDL_TRAVERSAL_HPP + +#include "MSVC_Pragmas.hpp" + +#include "CCF/IDL3/IDL3_Traversal.hpp" +#include "CCF/CIDL/CIDL_SyntaxTreeFwd.hpp" + +namespace CIDL +{ + namespace Traversal + { + // Import visitors from IDL3 + using namespace IDL3::Traversal; + + // + // Composition + // + struct Composition : virtual CCF::Traversal::Visitor + { + typedef + SyntaxTree::CompositionPtr + NodePtr; + + virtual void visit_composition (NodePtr const& c); + virtual void visit_composition_pre (NodePtr const& c); + virtual void visit_composition_scope (NodePtr const& c); + virtual void visit_composition_post (NodePtr const& c); + }; + + // + // HomeExecutor + // + struct HomeExecutor : virtual CCF::Traversal::Visitor + { + typedef + SyntaxTree::HomeExecutorPtr + NodePtr; + + virtual void visit_home_executor (NodePtr const& he); + virtual void visit_home_executor_pre (NodePtr const& he); + virtual void visit_home_executor_scope (NodePtr const& he); + virtual void visit_home_executor_post (NodePtr const& he); + + }; + } +} + +#endif // CCF_CIDL_TRAVERSAL_HPP diff --git a/TAO/CIAO/CCF/CCF/CIDL/MSVC_Pragmas.hpp b/TAO/CIAO/CCF/CCF/CIDL/MSVC_Pragmas.hpp new file mode 100644 index 00000000000..724b5b52646 --- /dev/null +++ b/TAO/CIAO/CCF/CCF/CIDL/MSVC_Pragmas.hpp @@ -0,0 +1,16 @@ +// $Id$ +#ifndef MSVC_PRAGMAS_HPP +#define MSVC_PRAGMAS_HPP + + +// Various warnings that have to be disabled for MSVC. + +// 'this' : used in base member initializer list +#pragma warning(disable:4355) +// 'class1' : inherits 'class2::member' via dominance +#pragma warning(disable:4250) +// C++ Exception Specification ignored +#pragma warning(disable:4290) + + +#endif /* MSVC_PRAGMAS_HPP */
\ No newline at end of file diff --git a/TAO/CIAO/CCF/CCF/CIDL/Makefile b/TAO/CIAO/CCF/CCF/CIDL/Makefile new file mode 100644 index 00000000000..8df971662da --- /dev/null +++ b/TAO/CIAO/CCF/CCF/CIDL/Makefile @@ -0,0 +1,21 @@ +# File : Makefile +# Author : Boris Kolpackov <boris@kolpackov.net> +# $Id$ + +root = ../../External/Utility + +include $(root)/Config/Archive.pre.rules + +cxx_translation_units := CIDL.cpp \ + CIDL_SyntaxTree.cpp \ + CIDL_Traversal.cpp + +module_base := CIDL +module_prefix := +module_suffix := + +CXX_PREPROCESS_FLAGS += -I../.. \ + -I../../External/Utility \ + -I../../External/boost \ + +include $(root)/Config/Archive.post.rules diff --git a/TAO/CIAO/CCF/CCF/CodeGenerationKit/CodeGenerationKit.cpp b/TAO/CIAO/CCF/CCF/CodeGenerationKit/CodeGenerationKit.cpp new file mode 100644 index 00000000000..cfa1da318d3 --- /dev/null +++ b/TAO/CIAO/CCF/CCF/CodeGenerationKit/CodeGenerationKit.cpp @@ -0,0 +1 @@ +// $Id$ diff --git a/TAO/CIAO/CCF/CCF/CodeGenerationKit/CodeGenerationKit.vcproj b/TAO/CIAO/CCF/CCF/CodeGenerationKit/CodeGenerationKit.vcproj new file mode 100644 index 00000000000..857c5bfd741 --- /dev/null +++ b/TAO/CIAO/CCF/CCF/CodeGenerationKit/CodeGenerationKit.vcproj @@ -0,0 +1,150 @@ +<?xml version="1.0" encoding="Windows-1252"?> +<VisualStudioProject + ProjectType="Visual C++" + Version="7.10" + Name="CodeGenerationKit" + ProjectGUID="{93C22389-AD2D-45CD-98C6-D9C5D6679B09}" + Keyword="Win32Proj"> + <Platforms> + <Platform + Name="Win32"/> + </Platforms> + <Configurations> + <Configuration + Name="Debug|Win32" + OutputDirectory="$(ProjectDir)" + IntermediateDirectory="Debug" + ConfigurationType="4" + CharacterSet="2"> + <Tool + Name="VCCLCompilerTool" + Optimization="0" + AdditionalIncludeDirectories="../..;../../External/Utility" + PreprocessorDefinitions="WIN32;_DEBUG;_LIB" + MinimalRebuild="TRUE" + BasicRuntimeChecks="3" + RuntimeLibrary="5" + ForceConformanceInForLoopScope="TRUE" + RuntimeTypeInfo="TRUE" + UsePrecompiledHeader="0" + WarningLevel="3" + Detect64BitPortabilityProblems="TRUE" + DebugInformationFormat="4"/> + <Tool + Name="VCCustomBuildTool"/> + <Tool + Name="VCLibrarianTool" + OutputFile="$(OutDir)/CodeGenerationKit.lib"/> + <Tool + Name="VCMIDLTool"/> + <Tool + Name="VCPostBuildEventTool"/> + <Tool + Name="VCPreBuildEventTool"/> + <Tool + Name="VCPreLinkEventTool"/> + <Tool + Name="VCResourceCompilerTool"/> + <Tool + Name="VCWebServiceProxyGeneratorTool"/> + <Tool + Name="VCXMLDataGeneratorTool"/> + <Tool + Name="VCManagedWrapperGeneratorTool"/> + <Tool + Name="VCAuxiliaryManagedWrapperGeneratorTool"/> + </Configuration> + <Configuration + Name="Release|Win32" + OutputDirectory="Release" + IntermediateDirectory="Release" + ConfigurationType="4" + CharacterSet="2"> + <Tool + Name="VCCLCompilerTool" + PreprocessorDefinitions="WIN32;NDEBUG;_LIB" + RuntimeLibrary="4" + UsePrecompiledHeader="0" + WarningLevel="3" + Detect64BitPortabilityProblems="TRUE" + DebugInformationFormat="3"/> + <Tool + Name="VCCustomBuildTool"/> + <Tool + Name="VCLibrarianTool" + OutputFile="$(OutDir)/CodeGenerationKit.lib"/> + <Tool + Name="VCMIDLTool"/> + <Tool + Name="VCPostBuildEventTool"/> + <Tool + Name="VCPreBuildEventTool"/> + <Tool + Name="VCPreLinkEventTool"/> + <Tool + Name="VCResourceCompilerTool"/> + <Tool + Name="VCWebServiceProxyGeneratorTool"/> + <Tool + Name="VCXMLDataGeneratorTool"/> + <Tool + Name="VCManagedWrapperGeneratorTool"/> + <Tool + Name="VCAuxiliaryManagedWrapperGeneratorTool"/> + </Configuration> + </Configurations> + <References> + </References> + <Files> + <Filter + Name="Source Files" + Filter="cpp;c;cxx;def;odl;idl;hpj;bat;asm;asmx" + UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"> + <File + RelativePath=".\CommandLine.cpp"> + </File> + <File + RelativePath=".\CommandLineGrammar.cpp"> + </File> + <File + RelativePath=".\CommandLineParser.cpp"> + </File> + </Filter> + <Filter + Name="Header Files" + Filter="h;hpp;hxx;hm;inl;inc;xsd" + UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"> + <File + RelativePath=".\CommandLine.hpp"> + </File> + <File + RelativePath=".\CommandLineDescriptor.hpp"> + </File> + <File + RelativePath=".\CommandLineGrammar.hpp"> + </File> + <File + RelativePath=".\CommandLineParser.hpp"> + </File> + <File + RelativePath=".\IDLStream.hpp"> + </File> + <File + RelativePath=".\MSVC_Pragmas.hpp"> + </File> + <File + RelativePath=".\Regex.hpp"> + </File> + </Filter> + <Filter + Name="Resource Files" + Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx" + UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}"> + </Filter> + <File + RelativePath=".\ReadMe.txt"> + </File> + </Files> + <Globals> + </Globals> +</VisualStudioProject> diff --git a/TAO/CIAO/CCF/CCF/CodeGenerationKit/CommandLine.cpp b/TAO/CIAO/CCF/CCF/CodeGenerationKit/CommandLine.cpp new file mode 100644 index 00000000000..f07dd8c10bc --- /dev/null +++ b/TAO/CIAO/CCF/CCF/CodeGenerationKit/CommandLine.cpp @@ -0,0 +1,5 @@ +// File : CommandLine.cpp +// Author : Boris Kolpackov <boris@dre.vanderbilt.edu> +// $Id$ + +#include "CCF/CodeGenerationKit/CommandLine.hpp" diff --git a/TAO/CIAO/CCF/CCF/CodeGenerationKit/CommandLine.hpp b/TAO/CIAO/CCF/CCF/CodeGenerationKit/CommandLine.hpp new file mode 100644 index 00000000000..94c05320287 --- /dev/null +++ b/TAO/CIAO/CCF/CCF/CodeGenerationKit/CommandLine.hpp @@ -0,0 +1,202 @@ +// File : CommandLine.hpp +// Author : Boris Kolpackov <boris@dre.vanderbilt.edu> +// $Id$ + +#ifndef COMMAND_LINE_H +#define COMMAND_LINE_H + +#include "MSVC_Pragmas.hpp" + +#include <algorithm> +#include <vector> +#include <string> + +using namespace std; + +//@@ this stuff needs proper reimplementation + +class CommandLine +{ +public: + + CommandLine () throw () : separator (false) {} + + + // Option constrain checking +public: + + bool + require (std::string option) const throw () + { + return std::find_if (options.begin (), + options.end (), + OptionNamePredicat (option)) != options.end (); + } + + bool + depends (std::string dependant, + std::string principal) const throw () + { + Options::const_iterator begin = options.begin (); + Options::const_iterator end = options.end (); + + if (std::find_if (begin, end, OptionNamePredicat (dependant)) != end) + { + return std::find_if (begin, end, OptionNamePredicat (principal)) != end; + } + else + { + return true; + } + } + + bool + inconsistent (std::string a, + std::string b) const throw () + { + Options::const_iterator begin = options.begin (); + Options::const_iterator end = options.end (); + + if (std::find_if (begin, end, OptionNamePredicat (a)) != end) + { + return std::find_if (begin, end, OptionNamePredicat (b)) == end; + } + else + { + return true; + } + } + + std::string + get_value (std::string name, std::string const& not_found_value) const + { + Options::const_iterator i = std::find_if ( + options.begin (), + options.end (), + OptionNamePredicat (name)); + + if (i != options.end () && !(i->value_.empty ())) + { + return i->value_; + } + else + { + return not_found_value; + } + } + + std::string + get_value (std::string name, char const* not_found_value) const + { + Options::const_iterator i = std::find_if ( + options.begin (), + options.end (), + OptionNamePredicat (name)); + + if (i != options.end () && !(i->value_.empty ())) + { + return i->value_; + } + else + { + return std::string (not_found_value); + } + } + + bool + get_value (std::string name, bool not_found_value) const + { + Options::const_iterator i = std::find_if ( + options.begin (), + options.end (), + OptionNamePredicat (name)); + + if (i != options.end ()) + { + return true; + } + else + { + return not_found_value; + } + } + + // Arguments + // + // + + typedef + std::vector<std::string> + Arguments; + + typedef + Arguments::const_iterator + ArgumentIterator; + + ArgumentIterator + argument_begin () const + { + return arguments.begin (); + } + + + ArgumentIterator + argument_end () const + { + return arguments.end (); + } + + +public: + + struct Option + { + enum OptionType + { + EQUATIONAL, + COMPOSITE + }; + + Option (OptionType type, + std::string const& name, + std::string const& value) throw () + : type_ (type), + name_ (name), + value_ (value) + { + } + + OptionType type_; + std::string name_; + std::string value_; + }; + + + + struct OptionNamePredicat + { + OptionNamePredicat (std::string const& name) + : name_ (name) + { + } + + bool operator ()(Option const& option) throw () + { + return name_ == option.name_; + } + + private: + std::string const name_; + }; + + typedef std::vector<Option> Options; + typedef std::vector<std::string> Arguments; + + std::string command; + Options options; + Arguments arguments; + + bool separator; +}; + +#endif // COMMAND_LINE_H diff --git a/TAO/CIAO/CCF/CCF/CodeGenerationKit/CommandLineDescriptor.hpp b/TAO/CIAO/CCF/CCF/CodeGenerationKit/CommandLineDescriptor.hpp new file mode 100644 index 00000000000..ac2d3ef6488 --- /dev/null +++ b/TAO/CIAO/CCF/CCF/CodeGenerationKit/CommandLineDescriptor.hpp @@ -0,0 +1,260 @@ +// $Id$ +#ifndef COMMAND_LINE_DESCRIPTOR_H +#define COMMAND_LINE_DESCRIPTOR_H + +#include <string> +#include <vector> +#include <ostream> + +//@@ temporary. should probably be changed to CommandLine +namespace CL +{ + class OptionDescription + { + public: + OptionDescription (std::string name, + std::string description, + bool optional) + : optional_ (optional), + name_ (name), + value_synopsis_ (), + description_ (description) + { + } + + + OptionDescription (std::string name, + std::string value_synopsis, + std::string description, + bool optional) + : optional_ (optional), + name_ (name), + value_synopsis_ (value_synopsis), + description_ (description) + { + } + + public: + bool + optional () const + { + return optional_; + } + + std::string + name () const + { + return name_; + } + + std::string + value_synopsis () const + { + return value_synopsis_; + } + + std::string + description () const + { + return description_; + } + + + private: + bool optional_; + std::string name_; + std::string value_synopsis_; + std::string description_; + }; + + + class Description + { + public: + Description (std::string command) + : command_ (command) + { + } + + private: + typedef + std::vector<OptionDescription> + OptionDescriptionList; + + public: + + std::string + command () const + { + return command_; + } + + + public: + typedef + OptionDescriptionList::const_iterator + OptionIterator; + + OptionIterator + begin_option () const + { + return options_.begin (); + } + + OptionIterator + end_option () const + { + return options_.end (); + } + + void + add_option (OptionDescription const& od) + { + options_.push_back (od); + } + + private: + typedef + std::vector<std::string> + ArgumentDescriptionList; + + public: + typedef + ArgumentDescriptionList::const_iterator + ArgumentIterator; + + ArgumentIterator + begin_argument () const + { + return arguments_.begin (); + } + + ArgumentIterator + end_argument () const + { + return arguments_.end (); + } + + void + add_argument (std::string arg) + { + arguments_.push_back (arg); + } + + private: + + std::string command_; + OptionDescriptionList options_; + ArgumentDescriptionList arguments_; + }; + + inline void + print_text (std::ostream& os, Description const& d) + { + os << d.command (); + + Description::OptionIterator ob = d.begin_option (); + Description::OptionIterator oe = d.end_option (); + + if (ob != oe) + { + os << " { OPTIONS }"; + } + + Description::ArgumentIterator ab = d.begin_argument (); + Description::ArgumentIterator ae = d.end_argument (); + + for (; ab != ae; ab++) + { + os << " <" << *ab << ">"; + } + + os << endl << endl; + + for (; ob != oe; ob++) + { + os << (ob->optional () ? "[--" : "--") + << ob->name () + << (ob->value_synopsis ().empty () ? "" : " ") + << ob->value_synopsis () + << (ob->optional () ? "]" : "") + << endl; + + os << "\t\t" << ob->description () << endl; + } + + } + + + inline void + print_html (std::ostream& os, Description const& d) + { + os << "<html>" << endl + << "<body>" << endl + << "<div align=\"center\">" << endl + << "<table width=\"700\" border=\"0\" cellspacing=\"0\" " + << "cellpadding=\"0\">" << endl + << "<tr>" << endl + << "<td>" << endl; + + os << "<p>" << endl + << "<code>" << endl; + + os << d.command (); + + Description::OptionIterator ob = d.begin_option (); + Description::OptionIterator oe = d.end_option (); + + if (ob != oe) + { + os << " { OPTIONS }"; + } + + Description::ArgumentIterator ab = d.begin_argument (); + Description::ArgumentIterator ae = d.end_argument (); + + for (; ab != ae; ab++) + { + os << " <" << *ab << ">"; + } + + os << endl + << "</code>" << endl + << "</p>" << endl; + + + os << "<dl>" << endl; + + for (; ob != oe; ob++) + { + os << "<dt>" << endl + << "<code>" << endl + << (ob->optional () ? "[--" : "--") + << ob->name () + << (ob->value_synopsis ().empty () ? "" : " ") + << ob->value_synopsis () + << (ob->optional () ? "]" : "") << endl + << "</code>" << endl + << "</dt>" << endl; + + os << "<dd>" << endl + << "<p>" << endl + << ob->description () << endl + << "</p>" << endl + << "</dd>" << endl; + } + + os << "</dl>" << endl; + + os << "</td>" << endl + << "</tr>" << endl + << "</table>" << endl + << "</div>" << endl + << "</body>" << endl + << "</html>" << endl; + + } +} + + +#endif // COMMAND_LINE_DESCRIPTOR_H diff --git a/TAO/CIAO/CCF/CCF/CodeGenerationKit/CommandLineGrammar.cpp b/TAO/CIAO/CCF/CCF/CodeGenerationKit/CommandLineGrammar.cpp new file mode 100644 index 00000000000..b14ef33fb1b --- /dev/null +++ b/TAO/CIAO/CCF/CCF/CodeGenerationKit/CommandLineGrammar.cpp @@ -0,0 +1,5 @@ +// File : CommandLineGrammar.cpp +// Author : Boris Kolpackov <boris@dre.vanderbilt.edu> +// $Id$ + +#include "CCF/CodeGenerationKit/CommandLineGrammar.hpp" diff --git a/TAO/CIAO/CCF/CCF/CodeGenerationKit/CommandLineGrammar.hpp b/TAO/CIAO/CCF/CCF/CodeGenerationKit/CommandLineGrammar.hpp new file mode 100644 index 00000000000..89f1ccb90e2 --- /dev/null +++ b/TAO/CIAO/CCF/CCF/CodeGenerationKit/CommandLineGrammar.hpp @@ -0,0 +1,361 @@ +// File : CommandLineGrammar.hpp +// Author : Boris Kolpackov <boris@dre.vanderbilt.edu> +// $Id$ + +#ifndef COMMAND_LINE_GRAMMAR_H +#define COMMAND_LINE_GRAMMAR_H + +#include "MSVC_Pragmas.hpp" + +#include <vector> +#include <string> + +#include <boost/spirit.hpp> + +#include "CCF/CodeGenerationKit/CommandLine.hpp" + + +using namespace std; +using namespace boost::spirit; + +template <typename S> +struct string_directive : public unary<S, parser<string_directive<S> > > +{ + typedef string_directive self_t; + + string_directive (S const& a) + : unary<S, parser<string_directive<S> > > (a) + { + } + + template <typename ScannerT> + typename parser_result<self_t, ScannerT>::type + parse(ScannerT const& scan) const + { + typedef typename ScannerT::iterator_t Iterator; + typedef typename ScannerT::value_t Value; + typedef typename Value::const_iterator ValueIterator; + + Iterator save = scan.first; + + int len = 0; + + if (!scan.at_end()) + { + // Now go one level deeper + + Value const& v = *scan; + + ValueIterator first = v.begin (); + ValueIterator last = v.end (); + + scanner<ValueIterator, scanner_policies <> > sl_scan(first, last); + + match<nil_t> hit = this->subject ().parse(sl_scan); + + if (hit.length() == v.length ()) + { + ++scan; + + return scan.create_match(1, nil_t(), save, scan.first); + } + else + { + return scan.no_match(); + } + } + else + { + return scan.no_match(); + } + } +}; + + +template <typename S> +string_directive<S> +string_d (parser<S> const& a) +{ + return string_directive<S>(a.derived()); +} + + +struct CLineGrammar : public grammar<CLineGrammar> +{ + CommandLine& cl_; + + CLineGrammar (CommandLine& cl) throw () : cl_(cl) {} + + + template <typename IteratorT, typename CodeT> + struct SemanticAction + { + SemanticAction (CommandLine& cl) : cl_ (cl), code_ () {} + + void operator()(IteratorT first, IteratorT last) const + { + string str (first, last); + code_.execute (cl_, str); + } + + private: + CommandLine& cl_; + CodeT code_; + }; + + + struct SetCommandName + { + void execute (CommandLine& cl, string const& s) const throw () + { + cl.command = s; + } + }; + + + template <typename IteratorT> + struct SetOptionName + { + SetOptionName (CommandLine& cl, + CommandLine::Option::OptionType type) + : cl_ (cl), type_ (type) + { + } + + void operator()(IteratorT first, IteratorT last) const + { + string s (first, last); + cl_.options.push_back (CommandLine::Option(type_, s, "")); + } + + private: + CommandLine& cl_; + CommandLine::Option::OptionType type_; + }; + + + struct SetOptionValue + { + void execute (CommandLine& cl, string const& s) const throw () + { + CommandLine::Options::reverse_iterator r = cl.options.rbegin (); + + if (r != cl.options.rend () && r->value_ == "") + { + r->value_ = s; + } + else + { + //@@ + //throw + } + } + }; + + struct SetArgument + { + void execute (CommandLine& cl, string const& s) const throw () + { + cl.arguments.push_back (s); + } + }; + + struct SetSeparator + { + void execute (CommandLine& cl, string const& s) const throw () + { + cl.separator = true; + } + }; + + + template <typename ScannerT> + struct definition + { + typedef typename ScannerT::value_t::const_iterator SLIterator; + typedef scanner<SLIterator, scanner_policies <> > SLScanner; + + typedef rule<ScannerT> Rule; + typedef rule<SLScanner> SLRule; + + + Rule r_argument; + Rule r_arg_list; + + Rule argument; + Rule arg_list; + + SLRule option_prefix; + SLRule e_name; // equational name, i.e. can meet '=' + SLRule c_name; // composite name, i.e. failes if meets '=' + SLRule e_value; // equational value, i.e. can contain leading '-' + SLRule c_value; // composite value, i.e. cannot contain leading '-' + + Rule composite; + Rule equational; + + Rule option_list; + Rule option; + + SLRule command_name; + + Rule command_line; + + // Semantic actions + + typedef SemanticAction<SLIterator, SetCommandName> CommandNameHandler; + typedef SetOptionName<SLIterator> OptionNameHandler; + typedef SemanticAction<SLIterator, SetOptionValue> OptionValueHandler; + typedef SemanticAction<SLIterator, SetArgument> ArgumentHandler; + typedef SemanticAction<SLIterator, SetSeparator> SeperatorHandler; + + /* + + <epigraph> + + As many people naively believe command line is + not a space separated array of words. + + -- unknown author. + </epigraph> + + + + NOTE: + + (1) This grammar is space-sensitive. + + (2) Anychar is assumend not to clash with <argv-delim>. Instead + <argv-delim> is assumed to be a next-dimension entitiy. + + + <command-line> ::= <command-name> + [ + [ <argv-delim> <option-list>] + [ + <option-prefix> [<argv-delim> <arg-list>] | + <argv-delim> <r-arg-list> + ] + ] + + <command-name> ::= anychar+ + + <option-list> ::= <option> { <argv-delim> <option> }* + <option> ::= <composite> | <equational> + <composite> ::= <option-prefix> <name> [ <argv-delim><c-value> ] + <equational> ::= <option-prefix> <name> '=' <e-value> + <option-prefix> ::= '-' [ '-' ] + <name> ::= {anychar - '='}+ + <c-value> ::= anychar+ - {<option-prefix> anychar*} + <e-valie> ::= anychar+ + + <arg-list> ::= <argument> { <arg-delim> <argument> }* + <r-arg-list> ::= <r-argument> { <arg-delim> <argument> }* + + <argument> ::= anychar+ + <r-argument> ::= anychar+ - {<option-prefix> anychar*} + + + */ + + + definition(CLineGrammar const& self) + { + command_line = + + string_d (command_name) >> + !option_list >> + !( + ( + string_d + ( + option_prefix[ SeperatorHandler (self.cl_) ] + ) >> !arg_list + ) | r_arg_list + ); + + // command name + + command_name = (+anychar_p)[CommandNameHandler (self.cl_)]; + + // options + + option_list = *(option); + + option = composite | equational; + + composite = + + string_d + ( + option_prefix >> c_name + + ) >> !string_d (c_value); + + equational = string_d (option_prefix >> e_name >> '=' >> e_value); + + option_prefix = lexeme_d[ch_p('-') >> !ch_p('-')]; + + e_name = + + lexeme_d + [ + ( + +( + anychar_p - ('=' | space_p) + ) + + )[ OptionNameHandler (self.cl_, CommandLine::Option::EQUATIONAL) ] + ]; + + c_name = + + lexeme_d + [ + ( + +(anychar_p - space_p) - + + ( + *(anychar_p - '=') >> '=' >> *anychar_p + ) + + )[ OptionNameHandler (self.cl_, CommandLine::Option::COMPOSITE) ] + ]; + + e_value = (+anychar_p)[ OptionValueHandler (self.cl_) ]; + + + c_value = + ( + +anychar_p - ( option_prefix >> *anychar_p ) + + )[ OptionValueHandler (self.cl_) ]; + + + + // arguments + + arg_list = *(argument); + r_arg_list = !(r_argument >> *argument); + + argument = string_d ((+anychar_p)[ ArgumentHandler (self.cl_) ]); + + r_argument = string_d + ( + ( + +anychar_p - (option_prefix >> *anychar_p) + + )[ ArgumentHandler (self.cl_) ] + ); + + } + + rule<ScannerT> const& start() const + { + return command_line; + } + }; +}; + + +#endif // COMMAND_LINE_GRAMMAR_H diff --git a/TAO/CIAO/CCF/CCF/CodeGenerationKit/CommandLineParser.cpp b/TAO/CIAO/CCF/CCF/CodeGenerationKit/CommandLineParser.cpp new file mode 100644 index 00000000000..0394f895669 --- /dev/null +++ b/TAO/CIAO/CCF/CCF/CodeGenerationKit/CommandLineParser.cpp @@ -0,0 +1,55 @@ +// File : CommandLineParser.cpp +// Author : Boris Kolpackov <boris@dre.vanderbilt.edu> +// $Id$ + +#include "CCF/CodeGenerationKit/CommandLineParser.hpp" +#include "CCF/CodeGenerationKit/CommandLineGrammar.hpp" + +#include <iostream> + +using std::cerr; +using std::endl; + +bool parse (int argc, char* argv[], CommandLine& cl) throw () +{ + typedef vector<string> Argv; + + Argv v; + + for (int i = 0; i < argc; i++) + { + v.push_back (argv[i]); + } + + Argv::iterator first = v.begin (); + Argv::iterator last = v.end (); + + scanner<Argv::iterator, scanner_policies <> > scan(first, last); + + CLineGrammar g (cl); + + match<nil_t> hit = g.parse(scan); + + bool result = hit.length() == v.size (); + + // some semantic analisys + if (!cl.separator) + { + CommandLine::Options::reverse_iterator r = cl.options.rbegin (); + + if (r != cl.options.rend () && + r->value_ != "" && + r->type_ == CommandLine::Option::COMPOSITE) + { + + cerr << "command line: assuming <" << r->value_ + << "> to be a value of option <" << r->name_ + << "> and not the first argument" << endl; + + cerr << "command line: write ... --" << r->name_ << " -- " + << r->value_ << " ... to indicate otherwise" << endl; + } + } + + return result; +} diff --git a/TAO/CIAO/CCF/CCF/CodeGenerationKit/CommandLineParser.hpp b/TAO/CIAO/CCF/CCF/CodeGenerationKit/CommandLineParser.hpp new file mode 100644 index 00000000000..920722403b3 --- /dev/null +++ b/TAO/CIAO/CCF/CCF/CodeGenerationKit/CommandLineParser.hpp @@ -0,0 +1,14 @@ +// File : CommandLineParser.hpp +// Author : Boris Kolpackov <boris@dre.vanderbilt.edu> +// $Id$ + +#ifndef COMMAND_LINE_PARSER_H +#define COMMAND_LINE_PARSER_H + +#include "MSVC_Pragmas.hpp" + +#include "CCF/CodeGenerationKit/CommandLine.hpp" + +bool parse (int argc, char* argv[], CommandLine& cl) throw (); + +#endif // COMMAND_LINE_PARSER_H diff --git a/TAO/CIAO/CCF/CCF/CodeGenerationKit/IDLStream.hpp b/TAO/CIAO/CCF/CCF/CodeGenerationKit/IDLStream.hpp new file mode 100644 index 00000000000..d5e8d897ded --- /dev/null +++ b/TAO/CIAO/CCF/CCF/CodeGenerationKit/IDLStream.hpp @@ -0,0 +1,126 @@ +// $Id$ + +#include "MSVC_Pragmas.hpp" + +#include <streambuf> +#include <iostream> + +//@@ would be nice to teach this beast to handle double newlines +// the idea is to convert double newline into single newline when +// the next character is '}' + +class IDLFormattingBuffer : public std::streambuf +{ +public: + IDLFormattingBuffer (std::streambuf* next) + : after_nl_ (true), + state_ (DECL_COMPLETE), + indentation_ (0), + next_ (next) + { + setbuf (0, 0); + } + + std::streambuf* + next () const + { + return next_; + } + + + +protected: + + class Full {}; + +protected: + + virtual int_type + overflow (int_type c) + { + int_type result; + + try + { + bool defaulting = false; + switch (c) + { + case '\n': + { + result = write (c); + after_nl_ = true; + break; + } + case '{': + { + output_indentation (); + result = write (c); + indentation_++; + break; + } + case '}': + { + if (indentation_ > 0) indentation_--; + output_indentation (); + result = write (c); + break; + } + default: + { + defaulting = true; + break; + } + } + + if (defaulting) + { + output_indentation (); + result = write (c); + } + + } + catch (Full const&) + { + result = traits_type::eof (); + } + + return result; + } + + void + output_indentation () throw (Full) + { + if (after_nl_) + { + for (unsigned long i = 0; i < indentation_; i++) + { + write (' '); + write (' '); + } + after_nl_ = false; + } + } + + int_type + write (int_type c) throw (Full) + { + int_type result = next_->sputc (c); + + if (result == traits_type::eof ()) throw Full (); + + return result; + } + + +private: + + enum State + { + DECL_COMPLETE, + }; + + bool after_nl_; + State state_; + unsigned long indentation_; + std::streambuf* next_; +}; diff --git a/TAO/CIAO/CCF/CCF/CodeGenerationKit/MSVC_Pragmas.hpp b/TAO/CIAO/CCF/CCF/CodeGenerationKit/MSVC_Pragmas.hpp new file mode 100644 index 00000000000..724b5b52646 --- /dev/null +++ b/TAO/CIAO/CCF/CCF/CodeGenerationKit/MSVC_Pragmas.hpp @@ -0,0 +1,16 @@ +// $Id$ +#ifndef MSVC_PRAGMAS_HPP +#define MSVC_PRAGMAS_HPP + + +// Various warnings that have to be disabled for MSVC. + +// 'this' : used in base member initializer list +#pragma warning(disable:4355) +// 'class1' : inherits 'class2::member' via dominance +#pragma warning(disable:4250) +// C++ Exception Specification ignored +#pragma warning(disable:4290) + + +#endif /* MSVC_PRAGMAS_HPP */
\ No newline at end of file diff --git a/TAO/CIAO/CCF/CCF/CodeGenerationKit/Makefile b/TAO/CIAO/CCF/CCF/CodeGenerationKit/Makefile new file mode 100644 index 00000000000..697130f21e6 --- /dev/null +++ b/TAO/CIAO/CCF/CCF/CodeGenerationKit/Makefile @@ -0,0 +1,22 @@ +# File : Makefile +# Author : Boris Kolpackov <boris@kolpackov.net> +# $Id$ + +root = ../../External/Utility + +include $(root)/Config/Archive.pre.rules + +cxx_translation_units := CodeGenerationKit.cpp \ + CommandLine.cpp \ + CommandLineGrammar.cpp \ + CommandLineParser.cpp + +module_base := CodeGenerationKit +module_prefix := +module_suffix := + +CXX_PREPROCESS_FLAGS += -I../.. \ + -I../../External/Utility \ + -I../../External/boost \ + +include $(root)/Config/Archive.post.rules diff --git a/TAO/CIAO/CCF/CCF/CodeGenerationKit/Regex.hpp b/TAO/CIAO/CCF/CCF/CodeGenerationKit/Regex.hpp new file mode 100644 index 00000000000..f9928441262 --- /dev/null +++ b/TAO/CIAO/CCF/CCF/CodeGenerationKit/Regex.hpp @@ -0,0 +1,42 @@ +// file : CCF/CodeGenerationKit/Regex.hpp +// author : Boris Kolpackov <boris@dre.vanderbilt.edu> +// cvs-id : $Id$ + +#ifndef CCF_RUNTIME_REGEX_HPP +#define CCF_RUNTIME_REGEX_HPP + +#include "MSVC_Pragmas.hpp" + +#include <string> +#include <boost/regex.hpp> + +namespace regex +{ + using boost::regex; + using boost::regex_merge; + + inline std::string + perl_s (std::string src, std::string e) + { + char delimiter = '/'; + + std::string::size_type first = e.find (delimiter); + std::string::size_type middle = e.find (delimiter, first + 1); + std::string::size_type last = e.find (delimiter, middle + 1); + + std::string pattern (e, first + 1, middle - first - 1); + std::string format (e, middle + 1, last - middle - 1); + + //std::cout << pattern << " " << format << std::endl; + + regex expr (pattern); + + return regex_merge ( + src, + expr, + format, + boost::match_default | boost::format_all ); + } +} + +#endif // CCF_RUNTIME_REGEX_HPP diff --git a/TAO/CIAO/CCF/CCF/CompilerElements/DiagnosticStream.cpp b/TAO/CIAO/CCF/CCF/CompilerElements/DiagnosticStream.cpp new file mode 100644 index 00000000000..9150c62350d --- /dev/null +++ b/TAO/CIAO/CCF/CCF/CompilerElements/DiagnosticStream.cpp @@ -0,0 +1,47 @@ +// file : CCF/Runtime/DiagnosticStream.cpp +// author : Boris Kolpackov <boris@dre.vanderbilt.edu> +// cvs-id : $Id$ + +#include "CCF/Runtime/DiagnosticStream.hpp" + +#include <iostream> + +namespace CCF +{ + namespace Runtime + { + namespace Diagnostic + { + Stream dout; + + // + // class Message + // + + Message::~Message () throw () + { + } + + // + // class Stream + // + + Stream::Stream () throw () + { + } + + + Stream::~Stream () throw () + { + } + + Stream& + Stream:: operator << (Message const& msg) + throw (ExH::System::Exception) + { + std::cerr << msg.text () << std::endl; + return *this; + } + } + } +} diff --git a/TAO/CIAO/CCF/CCF/CompilerElements/DiagnosticStream.hpp b/TAO/CIAO/CCF/CCF/CompilerElements/DiagnosticStream.hpp new file mode 100644 index 00000000000..6561095690c --- /dev/null +++ b/TAO/CIAO/CCF/CCF/CompilerElements/DiagnosticStream.hpp @@ -0,0 +1,141 @@ +// file : CCF/Runtime/DiagnosticStream.hpp +// author : Boris Kolpackov <boris@dre.vanderbilt.edu> +// cvs-id : $Id$ + +#ifndef CCF_RUNTIME_DIAGNOSTIC_DIAGNOSTIC_STREAM_H +#define CCF_RUNTIME_DIAGNOSTIC_DIAGNOSTIC_STREAM_H + +#include "MSVC_Pragmas.hpp" + +#include <string> +#include <sstream> + +#include "CCF/CompilerElements/ExH.hpp" + +namespace CCF +{ + namespace Runtime + { + namespace Diagnostic + { + class Message + { + public: + virtual + ~Message () throw (); + + virtual std::string + text () const throw (ExH::System::Exception) = 0; + }; + + class Stream + { + public: + Stream () throw (); + virtual + ~Stream () throw (); + + public: + Stream& operator<< (Message const& msg) + throw (ExH::System::Exception); + + private: + // Copy semanic is not supported. + Stream (Stream const&) throw (); + Stream& operator= (Stream const&) throw (); + }; + + extern Stream dout; + + // + // Concrete Message classes. + // + + template <typename Category> + class MessageImpl : public virtual Message, + public virtual Category + { + public: + MessageImpl (char const* subject, char const* message) + throw (ExH::System::Exception) + : subject_ (subject), message_ (message) {} + + MessageImpl (char const* subject, std::ostringstream const& message) + throw (ExH::System::Exception) + : subject_ (subject), message_ (message.str ()) {} + + virtual + ~MessageImpl () throw () {} + + virtual std::string + text () const throw (ExH::System::Exception) + { + std::string category = Category::name (); + + if (category.empty ()) + { + return subject_ + ": " + message_; + } + else + { + return subject_ + ": " + category + ": " + message_; + } + } + + private: + std::string subject_; + std::string message_; + }; + + // + // Error + // + + struct ErrorCategory + { + virtual ~ErrorCategory () throw () {} + + std::string name () const throw (ExH::System::Exception) + { + return "error"; + } + }; + + typedef MessageImpl<ErrorCategory> Error; + + // + // Warning + // + + struct WarningCategory + { + virtual ~WarningCategory () throw () {} + + std::string name () const throw (ExH::System::Exception) + { + return "warning"; + } + }; + + typedef MessageImpl<WarningCategory> Warning; + + // + // Information + // + + struct InformationCategory + { + virtual ~InformationCategory () throw () {} + + std::string name () const throw (ExH::System::Exception) + { + return ""; + } + }; + + typedef MessageImpl<InformationCategory> Information; + } + } +} + +#endif // CCF_RUNTIME_DIAGNOSTIC_DIAGNOSTIC_STREAM_H diff --git a/TAO/CIAO/CCF/CCF/CompilerElements/ExH.hpp b/TAO/CIAO/CCF/CCF/CompilerElements/ExH.hpp new file mode 100644 index 00000000000..41f05a56f5b --- /dev/null +++ b/TAO/CIAO/CCF/CCF/CompilerElements/ExH.hpp @@ -0,0 +1,14 @@ +// file : CCF/CompilerElements/ExH.hpp +// author : Boris Kolpackov <boris@dre.vanderbilt.edu> +// cvs-id : $Id$ + +#ifndef CCF_RUNTIME_EX_H_H +#define CCF_RUNTIME_EX_H_H + +#include "MSVC_Pragmas.hpp" + +#include "Utility/ExH/ExH.hpp" + +namespace ExH = Utility::ExH; + +#endif // CCF_RUNTIME_EX_H_H diff --git a/TAO/CIAO/CCF/CCF/CompilerElements/FileSystem.hpp b/TAO/CIAO/CCF/CCF/CompilerElements/FileSystem.hpp new file mode 100644 index 00000000000..e42c7a3d213 --- /dev/null +++ b/TAO/CIAO/CCF/CCF/CompilerElements/FileSystem.hpp @@ -0,0 +1,17 @@ +// file : CCF/CompilerElements/FileSystem.hpp +// author : Boris Kolpackov <boris@dre.vanderbilt.edu> +// cvs-id : $Id$ + +#ifndef CCF_RUNTIME_FILE_SYSTEM_HPP +#define CCF_RUNTIME_FILE_SYSTEM_HPP + +#include "MSVC_Pragmas.hpp" + +#include <boost/filesystem/path.hpp> +#include <boost/filesystem/fstream.hpp> +#include <boost/filesystem/exception.hpp> +#include <boost/filesystem/operations.hpp> + +namespace fs = boost::filesystem; + +#endif // CCF_RUNTIME_FILE_SYSTEM_HPP diff --git a/TAO/CIAO/CCF/CCF/CompilerElements/MSVC_Pragmas.hpp b/TAO/CIAO/CCF/CCF/CompilerElements/MSVC_Pragmas.hpp new file mode 100644 index 00000000000..f51b92d747b --- /dev/null +++ b/TAO/CIAO/CCF/CCF/CompilerElements/MSVC_Pragmas.hpp @@ -0,0 +1,15 @@ +#ifndef MSVC_PRAGMAS_HPP +#define MSVC_PRAGMAS_HPP + + +// Various warnings that have to be disabled for MSVC. + +// 'this' : used in base member initializer list +#pragma warning(disable:4355) +// 'class1' : inherits 'class2::member' via dominance +#pragma warning(disable:4250) +// C++ Exception Specification ignored +#pragma warning(disable:4290) + + +#endif /* MSVC_PRAGMAS_HPP */
\ No newline at end of file diff --git a/TAO/CIAO/CCF/CCF/CompilerElements/Parser.hpp b/TAO/CIAO/CCF/CCF/CompilerElements/Parser.hpp new file mode 100644 index 00000000000..dd932937b3d --- /dev/null +++ b/TAO/CIAO/CCF/CCF/CompilerElements/Parser.hpp @@ -0,0 +1,265 @@ +#ifndef PARSER_HPP +#define PARSER_HPP + +#include "MSVC_Pragmas.hpp" + +#include "CCF/CompilerElements/Token.hpp" + +#include <boost/spirit.hpp> + +namespace Details +{ + using namespace boost::spirit; + + typedef + TokenStream::iterator + Iterator; + + typedef + scanner<Iterator, scanner_policies<> > + Scanner; + + typedef + rule<Scanner> + Rule; + + + //------------------------------------------------------------- + + template <typename TypePtr> + struct IdentityParser : public parser <IdentityParser<TypePtr> > + { + typedef + IdentityParser + self_t; + + IdentityParser (TypePtr const& t) + : t_ (t) + { + } + + typename parser_result<self_t, Scanner>::type + parse(Scanner const& scan) const + { + if (!scan.at_end()) + { + TokenPtr t = *scan; + + if(identical (t_, t)) + { + Iterator save(scan.first); + ++scan; + return scan.create_match(1, t, save, scan.first); + } + } + return scan.no_match(); + } + + private: + TypePtr t_; + }; + + typedef + IdentityParser<KeywordPtr> + KeywordParser; + + typedef + IdentityParser<PunctuationPtr> + PunctuationParser; + + //---------------------------------------------------------------- + + template <typename TypePtr> + struct TypeParser : public parser <TypeParser<TypePtr> > + { + typedef + TypeParser + self_t; + + typename parser_result<self_t, Scanner>::type + parse(Scanner const& scan) const + { + if (!scan.at_end()) + { + TokenPtr t = *scan; + + if(typical<TypePtr>(t) != 0) + { + Iterator save(scan.first); + ++scan; + return scan.create_match(1, t, save, scan.first); + } + } + return scan.no_match(); + } + }; + + typedef + TypeParser<IdentifierPtr> + IdentifierParser; + + typedef + TypeParser<SimpleIdentifierPtr> + SimpleIdentifierParser; + + typedef + TypeParser<ScopedIdentifierPtr> + ScopedIdentifierParser; + + typedef + TypeParser<StringLiteralPtr> + StringLiteralParser; + + //--------------------------------------------------------------- + + bool parse (Iterator const& first_, + Iterator const& last, + Rule const& rule) + { + Iterator first = first_; + Scanner scan(first, last); + match<nil_t> hit = rule.parse(scan); + + bool result = parse_info<Iterator>( + first, hit, hit && (first == last), hit.length()).full; + + if (!result) + { + if (first != last) + { + std::cerr << (*first)->line () + << ": error: illegal syntactic construct" << std::endl; + } + else + { + //@@ what are the conditions when this happens? + //@@ is I add EOS token to the grammar then I can avoid this? + std::cerr << "error: illegal syntactic construct" << std::endl; + } + + } + + return result; + } +} + +// Base class for CCF-compliant parser +class Parser +{ +protected: + + typedef + Details::Iterator + Iterator; + +protected: + + template <typename Obj> + class ActionExecutor + { + public: + + typedef + void (Obj::*SemanticAction)(Iterator, Iterator) const; + + ActionExecutor (Obj const* obj, SemanticAction action) + : obj_ (obj), action_ (action) + { + } + + void operator () (Iterator begin, Iterator end) const + { + (obj_->*action_) (begin, end); + } + + private: + Obj const* obj_; + SemanticAction action_; + }; + + template <typename Obj> + class NoArgAction + { + public: + + typedef + void (Obj::*Action)(); + + NoArgAction (Obj& obj, Action action) + : obj_ (obj), action_ (action) + { + } + + void operator () (Iterator, Iterator) const + { + (obj_.*action_) (); + } + + private: + Obj& obj_; + Action action_; + }; + + template <typename TypePtr, typename Obj> + class OneArgAction + { + public: + + typedef + void (Obj::*Action)(TypePtr const&); + + OneArgAction (Obj& obj, Action action) + : obj_ (obj), action_ (action) + { + } + + void operator () (Iterator begin, Iterator end) const + { + if (end - begin != 1 ) + { + //@@ throw + } + + //@@ error handling if typical fails + (obj_.*action_) (typical<TypePtr> (*begin)); + } + + private: + Obj& obj_; + Action action_; + }; + + + template <typename Arg1, typename Arg2, typename Obj> + class TwoArgAction + { + public: + + typedef + void (Obj::*Action)(Arg1 const&, Arg2 const&); + + TwoArgAction (Obj& obj, Action action) + : obj_ (obj), action_ (action) + { + } + + void operator () (Iterator begin, Iterator end) const + { + if (end - begin != 2 ) + { + //@@ throw + } + + //@@ error handling if typical fails + (obj_.*action_) (typical<Arg1> (*begin), + typical<Arg2> (*(begin + 1))); + } + + private: + Obj& obj_; + Action action_; + }; +}; + + +#endif // PARSER_HPP diff --git a/TAO/CIAO/CCF/CCF/CompilerElements/Preprocessor.hpp b/TAO/CIAO/CCF/CCF/CompilerElements/Preprocessor.hpp new file mode 100644 index 00000000000..cefbed2da46 --- /dev/null +++ b/TAO/CIAO/CCF/CCF/CompilerElements/Preprocessor.hpp @@ -0,0 +1,303 @@ +#ifndef CCF_PREPROCESSOR_HPP +#define CCF_PREPROCESSOR_HPP + +#include "CCF/CompilerElements/TokenStream.hpp" + +namespace CCF +{ + //@@ this code is experimental and needs cleaning + class Preprocessor : public TokenStream<char> + { + public: + virtual + ~Preprocessor () {} + + Preprocessor (TokenStream<char>& is) + : state (PREPROCESSING), + loc_ ("C"), + is_ (is) + { + } + + public: + virtual int_type + next () + { + return out_get (); + } + + private: + int_type + underflow () + { + int_type i = in_get (); + + if (eos (i)) + { + return i; + } + + char_type c = to_char_type (i); + + //std::cerr << "next_i: c = " << c << std::endl; + + switch (c) + { + case '\\': return handle_escape (); + case '\"': + { + if (state == STRING_LITERAL) state = PREPROCESSING; + else if (state == PREPROCESSING) state = STRING_LITERAL; + else + { + //@@error + } + break; + } + case '\'': + { + if (state == CHAR_LITERAL) state = PREPROCESSING; + else if (state == PREPROCESSING) state = CHAR_LITERAL; + else + { + //@@error + } + break; + } + case '#': + { + if (state != PREPROCESSING) break; + return handle_preprocessor_token (); + } + } + + return i; + } + + int_type + handle_escape () + { + int_type i = in_get (); + + if (eos (i)) + { + //@@ error + return i; + } + + char_type c = to_char_type (i); + + //@@ '\n' won't work on MShit + switch (c) + { + case '\n': return underflow (); //skip it + default: + { + out_buffer_.push_back (i); + return '\\'; + } + } + } + + void + skip_white_space () + { + while (true) + { + int_type i = in_get (); + if (!eos (i)) + { + char_type c = to_char_type (i); + if (std::isspace (c, loc_) && c != '\n') continue; + } + + in_put (i); + break; + } + } + + int_type + handle_preprocessor_token () + { + //std::cerr << "handle_preprocessor_token" << std::endl; + + skip_white_space (); + + std::string lexeme; + + int_type i; + char_type c; + + while (true) + { + i = in_get (); + + if (eos (i)) + { + //@@ error + return i; + } + + c = to_char_type (i); + + if (std::isalnum (c, loc_)) + { + lexeme += c; + continue; + } + break; + } + + if (lexeme == "include") return handle_preprocessor_include (); + else + { + // skip till newline + while (true) + { + if (c == '\n') break; + + i = in_get (); + + if (eos (i)) + { + //@@ error + return i; + } + + c = to_char_type (i); + } + } + + return underflow (); + } + + + int_type + handle_preprocessor_include () + { + //out_put (std::string ("include")); + + skip_white_space (); + + std::string file; + + int_type i = in_get (); + + if (eos (i)) + { + //@@ error + return i; + } + + char_type c = to_char_type (i); + + char_type finilizer; + + if (c == '\"') finilizer = c; + else if (c == '<') finilizer = '>'; + else + { + //@@error + } + + while (true) + { + i = in_get (); + + if (eos (i)) + { + //@@ error + return i; + } + + c = to_char_type (i); + + if (c == finilizer) break; + + file += c; + } + + //@@ it's probably a good idea to skip until the newline + // and perhaps check that all the rest is whitespace. + + if (finilizer == '>') out_put (std::string("sinclude \"")); + else out_put (std::string("include \"")); + + out_put (file); + out_put ("\";"); + + return out_get (); + } + + + private: + + // Buffer manipulation + + int_type + in_get () + { + if (in_buffer_.empty ()) + { + return is_.next (); + } + else + { + int_type i = in_buffer_.front (); + in_buffer_.pop_front (); + return i; + } + } + + void + in_put (int_type c) + { + in_buffer_.push_back (c); + } + + int_type + out_get () + { + if (out_buffer_.empty ()) + { + return underflow (); + } + else + { + int_type i = out_buffer_.front (); + out_buffer_.pop_front (); + return i; + } + } + + void + out_put (std::string const& str) + { + for (std::string::const_iterator i = str.begin (); i != str.end (); i++) + { + out_buffer_.push_back (*i); + } + } + + void + out_put (int_type c) + { + out_buffer_.push_back (c); + } + + private: + enum State + { + PREPROCESSING, + STRING_LITERAL, + CHAR_LITERAL + } state; + + std::locale loc_; + TokenStream<char>& is_; + std::deque<int_type> in_buffer_; + std::deque<int_type> out_buffer_; + }; +} + +#endif //CCF_PREPROCESSOR_HPP diff --git a/TAO/CIAO/CCF/CCF/CompilerElements/ReferenceCounting.hpp b/TAO/CIAO/CCF/CCF/CompilerElements/ReferenceCounting.hpp new file mode 100644 index 00000000000..231b3b1b51d --- /dev/null +++ b/TAO/CIAO/CCF/CCF/CompilerElements/ReferenceCounting.hpp @@ -0,0 +1,14 @@ +// file : CCF/CompilerElements/ReferenceCounting.hpp +// author : Boris Kolpackov <boris@dre.vanderbilt.edu> +// cvs-id : $Id$ + +#ifndef CCF_RUNTIME_REFERENCE_COUNTING_H +#define CCF_RUNTIME_REFERENCE_COUNTING_H + +#include "MSVC_Pragmas.hpp" + +#include "Utility/ReferenceCounting/ReferenceCounting.hpp" + +namespace ReferenceCounting = Utility::ReferenceCounting; + +#endif // CCF_RUNTIME_REFERENCE_COUNTING_H diff --git a/TAO/CIAO/CCF/CCF/CompilerElements/SemanticAction.hpp b/TAO/CIAO/CCF/CCF/CompilerElements/SemanticAction.hpp new file mode 100644 index 00000000000..23448fe4c2a --- /dev/null +++ b/TAO/CIAO/CCF/CCF/CompilerElements/SemanticAction.hpp @@ -0,0 +1,15 @@ +#ifndef SEMANTIC_ACTION_HPP +#define SEMANTIC_ACTION_HPP + +#include "MSVC_Pragmas.hpp" + +namespace SemanticAction +{ + class Base + { + public: + virtual ~Base () {}; + }; +} + +#endif // SEMANTIC_ACTION_HPP diff --git a/TAO/CIAO/CCF/CCF/CompilerElements/Token.hpp b/TAO/CIAO/CCF/CCF/CompilerElements/Token.hpp new file mode 100644 index 00000000000..cb172c8746b --- /dev/null +++ b/TAO/CIAO/CCF/CCF/CompilerElements/Token.hpp @@ -0,0 +1,255 @@ +#ifndef TOKEN_HPP +#define TOKEN_HPP + +#include "MSVC_Pragmas.hpp" + +#include <vector> +#include <string> +//@@ it's a good idea to include ostream instead of iostream where I only +// use ostreams +#include <ostream> + +#include "CCF/CompilerElements/ReferenceCounting.hpp" + +// +// +// +class Token : public ReferenceCounting::DefaultImpl <> +{ +protected: + Token (unsigned long line) + : line_ (line) + { + } + +public: + virtual ~Token () throw () {} + +public: + unsigned long + line () const + { + return line_; + } + +private: + unsigned long line_; +}; + +typedef +ReferenceCounting::StrictPtr<Token> +TokenPtr; + +typedef +std::vector<TokenPtr> +TokenStream; + +// +// +// +class EndOfStream : public Token +{ +public: + EndOfStream () + : Token (0) + { + } + + virtual ~EndOfStream () throw () {} +}; + +typedef +ReferenceCounting::StrictPtr<EndOfStream> +EndOfStreamPtr; + +// +// +// +class Keyword : public Token +{ +public: + Keyword () + : Token (0) + { + } + + virtual + ~Keyword () throw () {} +}; + +typedef +ReferenceCounting::StrictPtr<Keyword> +KeywordPtr; + + + +// +// +// +class Punctuation : public Token +{ +public: + Punctuation () + : Token (0) + { + } + + virtual + ~Punctuation () throw () {} +}; + +typedef +ReferenceCounting::StrictPtr<Punctuation> +PunctuationPtr; + + +// +// +// +class Identifier : public Token +{ +public: + Identifier (std::string const& value, unsigned long line) + : Token (line), + value_ (value) + { + } + + virtual + ~Identifier () throw () {} + + //@@ this mf should probably be called str () or something like this + std::string + value () const + { + return value_; + } + +protected: + std::string value_; +}; + +typedef +ReferenceCounting::StrictPtr<Identifier> +IdentifierPtr; + +inline std::ostream& +operator<< (std::ostream& o, IdentifierPtr const& id) +{ + if (id != 0) o << id->value (); + return o; +} + +// +// +// +class SimpleIdentifier : public Identifier +{ +public: + SimpleIdentifier (std::string const& value, unsigned long line) + : Identifier (value, line) + { + } + + virtual + ~SimpleIdentifier () throw () {} +}; + +typedef +ReferenceCounting::StrictPtr<SimpleIdentifier> +SimpleIdentifierPtr; + +inline std::ostream& +operator<< (std::ostream& o, SimpleIdentifierPtr const& id) +{ + if (id != 0) o << id->value (); + return o; +} + +// +// +// +class ScopedIdentifier : public Identifier +{ +public: + ScopedIdentifier (std::string const& value, unsigned long line) + : Identifier (value, line) + { + } + + virtual + ~ScopedIdentifier () throw () {} +}; + +typedef +ReferenceCounting::StrictPtr<ScopedIdentifier> +ScopedIdentifierPtr; + +inline std::ostream& +operator<< (std::ostream& o, ScopedIdentifierPtr const& id) +{ + if (id != 0) o << id->value (); + return o; +} + +// +// +// +class StringLiteral : public Token +{ +public: + StringLiteral (std::string const& value, unsigned long line) + : Token (line), + value_ (value) + { + } + + virtual + ~StringLiteral () throw () {} + + std::string + value () const + { + return value_; + } + +protected: + std::string value_; +}; + +typedef +ReferenceCounting::StrictPtr<StringLiteral> +StringLiteralPtr; + +inline std::ostream& +operator<< (std::ostream& o, StringLiteralPtr const& sl) +{ + if (sl != 0) o << sl->value (); + return o; +} + +//@@ this is experimental code +// +// +template <typename TypePtr> +bool identical (TypePtr const& a, TokenPtr const& b) +{ + typedef + typename TypePtr::Type + Type; + + Type* t = dynamic_cast<Type*>(b.in ()); + return (t != 0) && (t == a.in ()); +}; + +template <typename TypePtr> +TypePtr typical (TokenPtr a) +{ + typedef + typename TypePtr::Type + Type; + + return TypePtr(add_ref(dynamic_cast<Type*>(a.in ()))); +}; + +#endif // TOKEN_HPP diff --git a/TAO/CIAO/CCF/CCF/CompilerElements/TokenStream.hpp b/TAO/CIAO/CCF/CCF/CompilerElements/TokenStream.hpp new file mode 100644 index 00000000000..a157cfeb71b --- /dev/null +++ b/TAO/CIAO/CCF/CCF/CompilerElements/TokenStream.hpp @@ -0,0 +1,65 @@ +#ifndef TOKEN_STREAM_HPP +#define TOKEN_STREAM_HPP + +#include <string> +#include <istream> + +namespace CCF +{ + template <typename Token> + class TokenStream + { + public: + virtual Token + next () = 0; + }; + + + template <> + class TokenStream<char> + { + public: + typedef std::char_traits<char> traits; + + typedef traits::int_type int_type; + typedef traits::char_type char_type; + + public: + virtual int_type + next () = 0; + + char_type + to_char_type (int_type i) + { + return traits::to_char_type (i); + } + + bool + eos (int_type i) + { + return i == traits::eof (); + } + }; + + class InputStreamAdapter : public TokenStream<char> + { + public: + InputStreamAdapter (std::istream& is) + : is_ (is) + { + } + + public: + + virtual int_type + next () + { + return is_.get (); + } + + private: + std::istream& is_; + }; +} + +#endif //TOKEN_STREAM_HPP diff --git a/TAO/CIAO/CCF/CCF/CompilerElements/Traversal.hpp b/TAO/CIAO/CCF/CCF/CompilerElements/Traversal.hpp new file mode 100644 index 00000000000..86066ee7a63 --- /dev/null +++ b/TAO/CIAO/CCF/CCF/CompilerElements/Traversal.hpp @@ -0,0 +1,38 @@ +#ifndef TRAVERSAL_HPP +#define TRAVERSAL_HPP + +#include "MSVC_Pragmas.hpp" + +namespace CCF +{ + namespace Traversal + { + struct Visitor + { + virtual + ~Visitor () /*@@= 0*/ {} + }; + + + template <typename VisitorType> + bool + try_visit ( + void (VisitorType::*visit_func)(typename VisitorType::NodePtr const&), + Visitor* v, + typename VisitorType::NodePtr const& n) + { + VisitorType* vt = dynamic_cast<VisitorType*> (v); + if(vt != 0) + { + (vt->*visit_func)(n); + return true; + } + else + { + return false; + } + } + } +} + +#endif // TRAVERSAL_HPP diff --git a/TAO/CIAO/CCF/CCF/IDL2/IDL2.cpp b/TAO/CIAO/CCF/CCF/IDL2/IDL2.cpp new file mode 100644 index 00000000000..cfa1da318d3 --- /dev/null +++ b/TAO/CIAO/CCF/CCF/IDL2/IDL2.cpp @@ -0,0 +1 @@ +// $Id$ diff --git a/TAO/CIAO/CCF/CCF/IDL2/IDL2.vcproj b/TAO/CIAO/CCF/CCF/IDL2/IDL2.vcproj new file mode 100644 index 00000000000..ea6de026267 --- /dev/null +++ b/TAO/CIAO/CCF/CCF/IDL2/IDL2.vcproj @@ -0,0 +1,159 @@ +<?xml version="1.0" encoding="Windows-1252"?> +<VisualStudioProject + ProjectType="Visual C++" + Version="7.10" + Name="IDL2" + ProjectGUID="{BC4A74B6-EBE7-486D-A537-B4217AE7304E}" + Keyword="Win32Proj"> + <Platforms> + <Platform + Name="Win32"/> + </Platforms> + <Configurations> + <Configuration + Name="Debug|Win32" + OutputDirectory="$(ProjectDir)" + IntermediateDirectory="Debug" + ConfigurationType="4" + CharacterSet="2"> + <Tool + Name="VCCLCompilerTool" + Optimization="0" + AdditionalIncludeDirectories="../..;../../External/Utility" + PreprocessorDefinitions="WIN32;_DEBUG;_LIB" + MinimalRebuild="TRUE" + BasicRuntimeChecks="3" + RuntimeLibrary="5" + ForceConformanceInForLoopScope="TRUE" + RuntimeTypeInfo="TRUE" + UsePrecompiledHeader="0" + WarningLevel="3" + Detect64BitPortabilityProblems="TRUE" + DebugInformationFormat="4"/> + <Tool + Name="VCCustomBuildTool"/> + <Tool + Name="VCLibrarianTool" + OutputFile="$(OutDir)/IDL2.lib"/> + <Tool + Name="VCMIDLTool"/> + <Tool + Name="VCPostBuildEventTool"/> + <Tool + Name="VCPreBuildEventTool"/> + <Tool + Name="VCPreLinkEventTool"/> + <Tool + Name="VCResourceCompilerTool"/> + <Tool + Name="VCWebServiceProxyGeneratorTool"/> + <Tool + Name="VCXMLDataGeneratorTool"/> + <Tool + Name="VCManagedWrapperGeneratorTool"/> + <Tool + Name="VCAuxiliaryManagedWrapperGeneratorTool"/> + </Configuration> + <Configuration + Name="Release|Win32" + OutputDirectory="Release" + IntermediateDirectory="Release" + ConfigurationType="4" + CharacterSet="2"> + <Tool + Name="VCCLCompilerTool" + PreprocessorDefinitions="WIN32;NDEBUG;_LIB" + RuntimeLibrary="4" + UsePrecompiledHeader="0" + WarningLevel="3" + Detect64BitPortabilityProblems="TRUE" + DebugInformationFormat="3"/> + <Tool + Name="VCCustomBuildTool"/> + <Tool + Name="VCLibrarianTool" + OutputFile="$(OutDir)/IDL2.lib"/> + <Tool + Name="VCMIDLTool"/> + <Tool + Name="VCPostBuildEventTool"/> + <Tool + Name="VCPreBuildEventTool"/> + <Tool + Name="VCPreLinkEventTool"/> + <Tool + Name="VCResourceCompilerTool"/> + <Tool + Name="VCWebServiceProxyGeneratorTool"/> + <Tool + Name="VCXMLDataGeneratorTool"/> + <Tool + Name="VCManagedWrapperGeneratorTool"/> + <Tool + Name="VCAuxiliaryManagedWrapperGeneratorTool"/> + </Configuration> + </Configurations> + <References> + </References> + <Files> + <Filter + Name="Source Files" + Filter="cpp;c;cxx;def;odl;idl;hpj;bat;asm;asmx" + UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"> + <File + RelativePath=".\IDL2_LexicalAnalyzer.cpp"> + </File> + <File + RelativePath=".\IDL2_SyntaxTree.cpp"> + </File> + <File + RelativePath=".\IDL2_SyntaxTree_BuiltIn.cpp"> + </File> + <File + RelativePath=".\IDL2_Traversal.cpp"> + </File> + </Filter> + <Filter + Name="Header Files" + Filter="h;hpp;hxx;hm;inl;inc;xsd" + UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"> + <File + RelativePath=".\IDL2_LexicalAnalyzer.hpp"> + </File> + <File + RelativePath=".\IDL2_Parser.hpp"> + </File> + <File + RelativePath=".\IDL2_SemanticAction.hpp"> + </File> + <File + RelativePath=".\IDL2_SemanticActionImpl.hpp"> + </File> + <File + RelativePath=".\IDL2_SyntaxTree.hpp"> + </File> + <File + RelativePath=".\IDL2_SyntaxTree_BuiltIn.hpp"> + </File> + <File + RelativePath=".\IDL2_SyntaxTree_Value.hpp"> + </File> + <File + RelativePath=".\IDL2_SyntaxTreeFwd.hpp"> + </File> + <File + RelativePath=".\IDL2_Traversal.hpp"> + </File> + <File + RelativePath=".\MSVC_Pragmas.hpp"> + </File> + </Filter> + <Filter + Name="Resource Files" + Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx" + UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}"> + </Filter> + </Files> + <Globals> + </Globals> +</VisualStudioProject> diff --git a/TAO/CIAO/CCF/CCF/IDL2/IDL2_LexicalAnalyzer.cpp b/TAO/CIAO/CCF/CCF/IDL2/IDL2_LexicalAnalyzer.cpp new file mode 100644 index 00000000000..a3a028d2493 --- /dev/null +++ b/TAO/CIAO/CCF/CCF/IDL2/IDL2_LexicalAnalyzer.cpp @@ -0,0 +1,377 @@ +// $Id$ +#include "IDL2_LexicalAnalyzer.hpp" + +#include <iostream> + +namespace IDL2 +{ + LexicalAnalyzer:: + LexicalAnalyzer (CCF::TokenStream<char>& is) + : loc_ ("C"), + is_ (is), + after_nl (true), + line_ (0), + + eos (new EndOfStream), + + abstract (new Keyword), + attribute (new Keyword), + factory (new Keyword), + in (new Keyword), + include (new Keyword), + inout (new Keyword), + interface (new Keyword), + local (new Keyword), + module (new Keyword), + out (new Keyword), + sinclude (new Keyword), + supports (new Keyword), + + colon (new Punctuation), + comma (new Punctuation), + lbrace (new Punctuation), + rbrace (new Punctuation), + lparen (new Punctuation), + rparen (new Punctuation), + semi (new Punctuation) + { + keyword_table_["abstract" ] = abstract; + keyword_table_["attribute"] = attribute; + keyword_table_["factory" ] = factory; + keyword_table_["in" ] = in; + keyword_table_["include" ] = include; + keyword_table_["inout" ] = inout; + keyword_table_["interface"] = interface; + keyword_table_["local" ] = local; + keyword_table_["module" ] = module; + keyword_table_["out" ] = out; + keyword_table_["sinclude" ] = sinclude; + keyword_table_["supports" ] = supports; + + punctuation_table_[":"] = colon; + punctuation_table_[","] = comma; + punctuation_table_["{"] = lbrace; + punctuation_table_["}"] = rbrace; + punctuation_table_["("] = lparen; + punctuation_table_[")"] = rparen; + punctuation_table_[";"] = semi; + } + + + LexicalAnalyzer::int_type LexicalAnalyzer:: + get () + { + int_type i; + + if (buffer_.empty ()) + { + i = is_.next (); + } + else + { + i = buffer_.front (); + buffer_.pop_front (); + } + + if (after_nl) + { + after_nl = false; + line_++; + } + + if (i == '\n') + { + after_nl = true; + } + + return i; + } + + LexicalAnalyzer::int_type LexicalAnalyzer:: + peek () + { + int_type i; + + if (buffer_.empty ()) + { + i = is_.next (); + buffer_.push_back (i); + } + else + { + i = buffer_.front (); + } + + return i; + } + + LexicalAnalyzer::int_type LexicalAnalyzer:: + peek_more () + { + int_type i; + + if (buffer_.size () < 2) + { + i = is_.next (); + buffer_.push_back (i); + } + else + { + i = buffer_.at (1); + } + + return i; + } + + LexicalAnalyzer::char_type LexicalAnalyzer:: + to_char_type (int_type i) + { + return is_.to_char_type (i); + } + + + TokenPtr LexicalAnalyzer:: + next () + { + while (true) + { + int_type i = get (); + + if (is_.eos(i)) return eos; + + char_type c = to_char_type (i); + + // Handling spaces + if (std::isspace (c, loc_)) continue; + + // Handling C++ comments + if (c == '/' && peek () == '/') + { + cxx_comment (c); + continue; + } + + // Handling C comments + if (c == '/' && peek () == '*') + { + c_comment (c); + continue; + } + + if (std::isalpha (c, loc_) || c == '_' || (c == ':' && peek () == ':')) + { + return identifier (c); + } + + TokenPtr token; + + if (string_literal (c, token)) return token; + + if (punctuation (c, token)) return token; + + + std::cerr << line_ << ": error: unable to derive any token from \'" + << c << "\'" << std::endl; + + //@@ I should return something special here. + return eos; + } + } + + void LexicalAnalyzer:: + cxx_comment (char_type c) + { + while (c != '\n') + { + int_type i = get (); + + if (is_.eos (i)) + { + std::cerr << "warning: no new line at the end of file" << std::endl; + //@@ I wonder if it's ok to call get () again after getting eof. + break; + } + c = to_char_type (i); + } + } + + void LexicalAnalyzer:: + c_comment (char_type c) + { + get (); // get '*' + + do + { + int_type i = get (); + + if (is_.eos (i)) + { + std::cerr << "error: end of file before C-style comment finished" + << std::endl; + return; + + //@@ I wonder if it's ok to call get () again after getting eof. + } + c = to_char_type (i); + + //std::cerr << "lexer: c_comment: read character \'" << c << "\'" + // << std::endl; + } + while (c != '*' || peek () != '/'); + + //std::cerr << "lexer: c_comment: finished C-comment \'" << c + // << "\',\'" << to_char_type (peek ()) + // << "\'" << std::endl; + + get (); // get '/' + } + + TokenPtr LexicalAnalyzer:: + identifier (char_type c) + { + std::string lexeme; + + enum + { + SIMPLE, + SCOPED, + OTHER + } type = SIMPLE; + + if (c == ':') + { + get (); + lexeme = "::"; + type = SCOPED; + } + else + { + lexeme += c; + } + + while (true) + { + int_type i = peek (); + + if (is_.eos (i)) + { + std::cerr << "warning: no new line at the end of file" << std::endl; + break; + } + + c = to_char_type (i); + + //std::cerr << "lexer::identifier: peeking on \'" << c + // << "\'; current lexeme \'" << lexeme << "\'" + // << std::endl; + + if (std::isalnum (c, loc_) || c == '_') + { + get (); + lexeme += c; + continue; + } + + if (c == ':' && peek_more () == ':') + { + get (); + get (); + lexeme += "::"; + if (type == SIMPLE) type = OTHER; + continue; + } + + break; + } + + //std::cerr << "lexer: found identifier with lexeme \'" + // << lexeme << "\'" << std::endl; + + switch (type) + { + case SIMPLE: + { + KeywordTable::const_iterator i = keyword_table_.find (lexeme); + + if (i == keyword_table_.end ()) + { + return TokenPtr (new SimpleIdentifier (lexeme, line_)); + } + else + { + return i->second; + } + } + case SCOPED: + { + return TokenPtr (new ScopedIdentifier (lexeme, line_)); + } + case OTHER: + { + return TokenPtr (new Identifier (lexeme, line_)); + } + //@@ without this line GCC issues warning and MSVC issues error + // Is it required by standard? + default: + { + throw InternalError (); + } + + } + } + + bool LexicalAnalyzer:: + punctuation (char_type c, TokenPtr& token) + { + PunctuationTable::const_iterator i = punctuation_table_.begin (); + + while (true) + { + for (;i != punctuation_table_.end () && i->first[0] != c; i++); + + if (i == punctuation_table_.end ()) return false; + + // if it's a two-character punctuation + if (i->first.size () == 2) + { + if (i->first[1] != peek ()) + { + // move on to the next candidate + i++; + continue; + } + } + + token = i->second; + return true; + } + } + + bool LexicalAnalyzer:: + string_literal (char_type c, TokenPtr& token) + { + if (c != '\"') return false; + + std::string lexeme; + + while (true) + { + int_type i = get (); + + if (is_.eos (i)) + { + std::cerr << "warning: end of file while reading string literal" + << std::endl; + break; + } + + c = to_char_type (i); + + if (c == '\"') break; + else lexeme += c; + } + + token = TokenPtr(new StringLiteral (lexeme, line_)); + return true; + } +} diff --git a/TAO/CIAO/CCF/CCF/IDL2/IDL2_LexicalAnalyzer.hpp b/TAO/CIAO/CCF/CCF/IDL2/IDL2_LexicalAnalyzer.hpp new file mode 100644 index 00000000000..52d3bbfd7a3 --- /dev/null +++ b/TAO/CIAO/CCF/CCF/IDL2/IDL2_LexicalAnalyzer.hpp @@ -0,0 +1,129 @@ +// $Id$ +#ifndef CCF_IDL2_LEXICAL_ANALYZER_HPP +#define CCF_IDL2_LEXICAL_ANALYZER_HPP + +#include "MSVC_Pragmas.hpp" + +#include "CCF/CompilerElements/Token.hpp" +#include "CCF/CompilerElements/TokenStream.hpp" + +#include <map> +#include <deque> +#include <locale> +#include <cctype> +#include <string> +#include <istream> + +namespace IDL2 +{ + //@@ It seems to me that there should be a diagnistic information (file, + // line, start_pos, end_pos) supplied with each token. (Thus lexer + // will have to know about #include business. Or maybe not..?) + // + //@@ Would be nice to have a read-only symbol table (or at least keyword + // table). This way it would be easier to extend language (which from + // lexer's persective would ususally mean to add new keywords). + + class LexicalAnalyzer + { + //@@ fixme (should be at the end of class) + protected: + + typedef CCF::TokenStream<char>::int_type int_type; + typedef CCF::TokenStream<char>::char_type char_type; + typedef CCF::TokenStream<char>::traits traits; + + typedef + std::map<std::string, KeywordPtr> + KeywordTable; + + typedef + std::map<std::string, PunctuationPtr> + PunctuationTable; + + + std::locale loc_; + KeywordTable keyword_table_; + PunctuationTable punctuation_table_; + CCF::TokenStream<char>& is_; + + // look ahead mechanism + std::deque<int_type> buffer_; + + // line numbering mechanism + bool after_nl; + unsigned long line_; + + + public: + virtual + ~LexicalAnalyzer () throw () {} + + public: + class InternalError {}; + + EndOfStreamPtr eos; + + // Keywords (alphabetic order) + + KeywordPtr abstract; + KeywordPtr attribute; + KeywordPtr factory; + KeywordPtr in; + KeywordPtr include; + KeywordPtr inout; + KeywordPtr interface; + KeywordPtr local; + KeywordPtr module; + KeywordPtr out; + KeywordPtr sinclude; + KeywordPtr supports; + + // Punctuations (alphabetic group order) + + PunctuationPtr colon; + PunctuationPtr comma; + PunctuationPtr lbrace; + PunctuationPtr rbrace; + PunctuationPtr lparen; + PunctuationPtr rparen; + PunctuationPtr semi; + + public: + LexicalAnalyzer (CCF::TokenStream<char>& is); + + virtual TokenPtr + next (); + + protected: + + virtual int_type + get (); + + virtual int_type + peek (); + + virtual int_type + peek_more (); + + char_type + to_char_type (int_type i); + + virtual void + cxx_comment (char_type c); + + virtual void + c_comment (char_type c); + + virtual TokenPtr + identifier (char_type c); + + virtual bool + string_literal (char_type c, TokenPtr& token); + + virtual bool + punctuation (char_type c, TokenPtr& token); + }; +} + +#endif // CCF_IDL2_LEXICAL_ANALYZER_HPP diff --git a/TAO/CIAO/CCF/CCF/IDL2/IDL2_Parser.hpp b/TAO/CIAO/CCF/CCF/IDL2/IDL2_Parser.hpp new file mode 100644 index 00000000000..1a258ca732a --- /dev/null +++ b/TAO/CIAO/CCF/CCF/IDL2/IDL2_Parser.hpp @@ -0,0 +1,421 @@ +// $Id$ +#ifndef CCF_IDL2_PARSER_HPP +#define CCF_IDL2_PARSER_HPP + +#include "MSVC_Pragmas.hpp" + +#include "CCF/CompilerElements/Parser.hpp" +#include "CCF/IDL2/IDL2_LexicalAnalyzer.hpp" +#include "CCF/IDL2/IDL2_SemanticAction.hpp" + +//@@ tmp +#include <iostream> +using std::cerr; +using std::endl; + +namespace IDL2 +{ + class Parser : public virtual ::Parser + { + public: + virtual + ~Parser () throw () {} + + protected: + LexicalAnalyzer const& lexer_; + SemanticActionFactory& actions_; + + protected: + + // @@ this stinks + // Semanic action types + // + + typedef + SemanticAction::Include + Include; + + typedef + SemanticAction::Scope + Scope; + + typedef + SemanticAction::Module + Module; + + typedef + SemanticAction::Interface + Interface; + + typedef + SemanticAction::Attribute + Attribute; + + typedef + SemanticAction::Operation + Operation; + + protected: + + // + // Primitives + // + typedef + Details::KeywordParser + KeywordParser; + + typedef + Details::PunctuationParser + PunctuationParser; + + typedef + Details::IdentifierParser + IdentifierParser; + + typedef + Details::SimpleIdentifierParser + SimpleIdentifierParser; + + typedef + Details::StringLiteralParser + StringLiteralParser; + + // Keyword parsers (alphabetic order). + KeywordParser ABSTRACT; + KeywordParser ATTRIBUTE; + KeywordParser FACTORY; + KeywordParser IN; + KeywordParser INCLUDE; + KeywordParser INOUT; + KeywordParser INTERFACE; + KeywordParser LOCAL; + KeywordParser MODULE; + KeywordParser OUT; + KeywordParser SINCLUDE; + KeywordParser SUPPORTS; + + // Punctuation parsers (alphabetic group order). + PunctuationParser COLON; + PunctuationParser COMMA; + PunctuationParser LBRACE; + PunctuationParser RBRACE; + PunctuationParser LPAREN; + PunctuationParser RPAREN; + PunctuationParser SEMI; + + IdentifierParser identifier; + SimpleIdentifierParser simple_identifier; + StringLiteralParser string_literal; + + + // + // Language + // + + typedef + Details::Rule + Rule; + + Rule language; + Rule import; + Rule declaration; + Rule extension; + + Rule include_decl; + Rule system_include_decl; + + Rule module_decl; + + Rule interface_decl; + Rule interface_header; + Rule interface_inheritance_spec; + Rule interface_body; + + Rule attribute_decl; + + Rule direction_specifier; + + Rule operation_decl; + Rule operation_parameter_list; + Rule operation_parameter; + + public: + Parser (LexicalAnalyzer const& l, SemanticActionFactory& f) + : lexer_ (l), + actions_ (f), + + ABSTRACT (l.abstract), + ATTRIBUTE (l.attribute), + FACTORY (l.factory), + IN (l.in), + INCLUDE (l.include), + INOUT (l.inout), + INTERFACE (l.interface), + LOCAL (l.local), + MODULE (l.module), + OUT (l.out), + SINCLUDE (l.sinclude), + SUPPORTS (l.supports), + + COLON (l.colon), + COMMA (l.comma), + LBRACE (l.lbrace), + RBRACE (l.rbrace), + LPAREN (l.lparen), + RPAREN (l.rparen), + SEMI (l.semi), + + act_include_begin (f.include (), &Include::begin), + act_include_end (f.include (), &Include::end), + + act_module_begin (f.module (), &Module::begin), + act_module_open_scope (f.module (), &Scope::open_scope), + act_module_close_scope (f.module (), &Scope::close_scope), + act_module_end (f.module (), &Module::end), + + act_interface_begin (this, &Parser::act_interface_begin_core), + act_interface_inherits (f.interface (), &Interface::inherits), + act_interface_open_scope (f.interface (), &Scope::open_scope), + act_interface_close_scope (f.interface (), &Scope::close_scope), + act_interface_end (f.interface (), &Interface::end), + + act_attribute_type (f.attribute (), &Attribute::type), + act_attribute_name (f.attribute (), &Attribute::name), + + act_operation_begin (f.operation (), &Operation::begin), + act_operation_parameter (this, + &Parser::act_operation_parameter_core), + act_operation_end (f.operation (), &Operation::end) + + { + language = *import >> +declaration + ; + + import = + include_decl + | system_include_decl + ; + + include_decl = + INCLUDE + >> string_literal[act_include_begin] + >> SEMI[act_include_end] + ; + + system_include_decl = + SINCLUDE + >> string_literal + >> SEMI[act_include_end] + ; + + declaration = + interface_decl + | module_decl + | extension + ; + + module_decl = + MODULE + >> simple_identifier[act_module_begin] + >> LBRACE[act_module_open_scope] + >> +declaration + >> RBRACE[act_module_close_scope] + >> SEMI[act_module_end] + ; + + + // + // interface + // + interface_decl = + interface_header + >> + ( + SEMI[act_interface_end] + | + ( + !(COLON >> interface_inheritance_spec) + >> LBRACE[act_interface_open_scope] + >> interface_body + >> RBRACE[act_interface_close_scope] + >> SEMI[act_interface_end] + ) + ) + ; + + interface_header = + ( + !(LOCAL | ABSTRACT) + >> INTERFACE + >> simple_identifier + )[act_interface_begin] + ; + + + interface_inheritance_spec = + identifier[act_interface_inherits] + >> *(COMMA >> identifier[act_interface_inherits]) + ; + + interface_body = + *( + attribute_decl + | operation_decl + ) + ; + + // + // attribute + // + attribute_decl = + ATTRIBUTE + >> identifier[act_attribute_type] + >> simple_identifier[act_attribute_name] + >> SEMI + ; + + + // + // direction specifier + // + direction_specifier = + IN + | OUT + | INOUT + ; + + + // + // operation + // + operation_decl = + (identifier >> simple_identifier)[act_operation_begin] + >> LPAREN + >> operation_parameter_list + >> RPAREN + >> SEMI[act_operation_end] + ; + + operation_parameter_list = + *( + operation_parameter + >> *(COMMA >> operation_parameter) + ) + ; + + operation_parameter = + ( + direction_specifier + >> identifier + >> simple_identifier + )[act_operation_parameter] + ; + } + + virtual Rule const& + start() const + { + return language; + } + + protected: + + // + // Semantic actions + // + + typedef + NoArgAction<Scope> + ScopeAction; + + // + // Include + // + OneArgAction<StringLiteralPtr, Include> act_include_begin; + NoArgAction<Include> act_include_end; + + // + // Module + // + + OneArgAction<SimpleIdentifierPtr, Module> act_module_begin; + ScopeAction act_module_open_scope; + ScopeAction act_module_close_scope; + NoArgAction<Module> act_module_end; + + // + // Interface + // + void + act_interface_begin_core (Iterator begin, Iterator end) const + { + Interface::Qualifier::Value q = Interface::Qualifier::UNCONSTRAINED; + + if(end - begin == 3) + { + if(identical (lexer_.local, *begin)) + { + q = Interface::Qualifier::LOCAL; + } + else + { + q = Interface::Qualifier::ABSTRACT; + } + begin++; + } + + begin++; + + actions_.interface ().begin (q, typical<SimpleIdentifierPtr>(*begin)); + } + ActionExecutor<Parser> act_interface_begin; + + OneArgAction<IdentifierPtr, Interface> act_interface_inherits; + + ScopeAction act_interface_open_scope; + ScopeAction act_interface_close_scope; + + NoArgAction<Interface> act_interface_end; + + // + // Attribute + // + OneArgAction<IdentifierPtr, Attribute> act_attribute_type; + OneArgAction<SimpleIdentifierPtr, Attribute> act_attribute_name; + + // + // Operation + // + TwoArgAction<IdentifierPtr, + SimpleIdentifierPtr, + Operation> act_operation_begin; + + void + act_operation_parameter_core (Iterator begin, Iterator end) const + { + Operation::Direction::Value d = Operation::Direction::INOUT; + + if(identical (lexer_.in, *begin)) + { + d = Operation::Direction::IN; + } + else if(identical (lexer_.out, *begin)) + { + d = Operation::Direction::OUT; + } + begin++; + + actions_.operation ().parameter ( + d, + typical<IdentifierPtr>(*begin), + typical<SimpleIdentifierPtr>(*(begin + 1))); + } + ActionExecutor<Parser> act_operation_parameter; + + NoArgAction<Operation> act_operation_end; + + + }; +} + +#endif // CCF_IDL2_PARSER_HPP diff --git a/TAO/CIAO/CCF/CCF/IDL2/IDL2_SemanticAction.hpp b/TAO/CIAO/CCF/CCF/IDL2/IDL2_SemanticAction.hpp new file mode 100644 index 00000000000..3fb04f4c8dc --- /dev/null +++ b/TAO/CIAO/CCF/CCF/IDL2/IDL2_SemanticAction.hpp @@ -0,0 +1,163 @@ +// $Id$ +#ifndef CCF_IDL2_SEMANTIC_ACTION_HPP +#define CCF_IDL2_SEMANTIC_ACTION_HPP + +#include "MSVC_Pragmas.hpp" + +#include "CCF/CompilerElements/Token.hpp" +#include "CCF/CompilerElements/SemanticAction.hpp" + +namespace IDL2 +{ + namespace SemanticAction + { + using ::SemanticAction::Base; + + class Include : public virtual Base + { + public: + virtual + ~Include () throw () {} + + virtual void + begin (StringLiteralPtr const& sl) = 0; + + virtual void + end () = 0; + }; + + class Scope : public virtual Base + { + public: + virtual + ~Scope () throw () {} + + virtual void + open_scope () = 0; + + virtual void + close_scope () = 0; + }; + + class Module : public virtual Scope + { + public: + virtual + ~Module () throw () {} + + virtual void + begin (SimpleIdentifierPtr const& id) = 0; + + virtual void + end () = 0; + }; + + class Interface : public virtual Scope + { + public: + virtual + ~Interface () throw () {} + + struct Qualifier + { + enum Value + { + LOCAL, + ABSTRACT, + UNCONSTRAINED, + }; + + friend std::ostream& + operator<< (std::ostream& o, Value d) + { + if (d == LOCAL) o << "local"; + else if (d == ABSTRACT) o << "abstract"; + else o << "unconstrained"; + return o; + } + }; + + virtual void + begin (Qualifier::Value qualifier, SimpleIdentifierPtr const& id) = 0; + + virtual void + inherits (IdentifierPtr const& id) = 0; + + virtual void + end () = 0; + }; + + class Attribute + { + public: + virtual + ~Attribute () throw () {} + + virtual void + type (IdentifierPtr const& id) = 0; + + virtual void + name (SimpleIdentifierPtr const& id) = 0; + }; + + class Operation + { + public: + + virtual void + begin (IdentifierPtr const& type_id, + SimpleIdentifierPtr const& name_id) = 0; + + struct Direction + { + enum Value + { + IN, + OUT, + INOUT + }; + + friend std::ostream& + operator<< (std::ostream& o, Value d) + { + if (d == IN) o << "in"; + else if (d == OUT) o << "out"; + else o << "inout"; + return o; + } + }; + + virtual void + parameter (Direction::Value direction, + IdentifierPtr const& type_id, + SimpleIdentifierPtr const& name_id) = 0; + + virtual void + end () = 0; + }; + } + + class SemanticActionFactory + { + public: + virtual + ~SemanticActionFactory () throw () {} + + virtual SemanticAction::Include& + include () = 0; + + virtual SemanticAction::Module& + module () = 0; + + virtual SemanticAction::Interface& + interface () = 0; + + virtual SemanticAction::Attribute& + attribute () = 0; + + virtual SemanticAction::Operation& + operation () = 0; + }; +} + +#endif // CCF_IDL2_SEMANTIC_ACTION_HPP diff --git a/TAO/CIAO/CCF/CCF/IDL2/IDL2_SemanticActionImpl.hpp b/TAO/CIAO/CCF/CCF/IDL2/IDL2_SemanticActionImpl.hpp new file mode 100644 index 00000000000..2169acbcddd --- /dev/null +++ b/TAO/CIAO/CCF/CCF/IDL2/IDL2_SemanticActionImpl.hpp @@ -0,0 +1,742 @@ +// $Id$ +#ifndef CCF_IDL2_SEMANTIC_ACTION_IMPL_HPP +#define CCF_IDL2_SEMANTIC_ACTION_IMPL_HPP + +#include "MSVC_Pragmas.hpp" + +#include "CCF/IDL2/IDL2_SemanticAction.hpp" +#include "CCF/IDL2/IDL2_SyntaxTree.hpp" +#include "CCF/IDL2/IDL2_SyntaxTree_BuiltIn.hpp" + +#include <stack> + +// needed for include handling +#include <fstream> + +//@@tmp +#include <iostream> +using std::cerr; +using std::endl; + +namespace IDL2 +{ + namespace SemanticAction + { + namespace Impl + { + + /* + Design notes: + + (1) I am using stack-based approach to handle cases like this: + + struct A + { + struct B + { + struct C + { + ... + } c; + } b; + }; + + Even though you can't write the same let's say for interface + I am still using stack approach for consistency and possible + meta-coding. + + */ + + using ReferenceCounting::strict_cast; + + // + // + // + template <typename NodeTypePtr> + class ScopeBase : public virtual SemanticAction::Scope + { + protected: + virtual + ~ScopeBase () throw () {} + + ScopeBase (SyntaxTree::ScopePtr& scope) + : scope_ (scope) + { + } + + protected: + void + push (NodeTypePtr const& t) + { + stack_.push (t); + } + + void + pop () + { + stack_.pop (); + } + + NodeTypePtr& + top () + { + return stack_.top (); + } + + protected: + SyntaxTree::ScopePtr& scope_; + std::stack<NodeTypePtr> stack_; + }; + + + // + // + // + class Include : public virtual SemanticAction::Include + { + public: + virtual + ~Include () throw () {} + + Include (SemanticActionFactory& action_factory, + SyntaxTree::TranslationRegionPtr const& region, + SyntaxTree::ScopePtr& scope) + : action_factory_ (action_factory), + scope_ (scope) + { + stack_.push (region); + } + + virtual void + begin (StringLiteralPtr const& sl) + { + cerr << "include \"" << sl << "\"" << endl; + + /* + @@ this code is experimentla and temporarlily disabled + using namespace SyntaxTree; + + std::ifstream ifs (sl->value ().c_str ()); + if (!ifs.is_open ()) + { + cerr << "error: unable to open included file \'" + << sl << "\'" << endl; + } + + TranslationRegionPtr r ( + new TranslationRegion (sl->value (), + stack_.top ()->table (), + stack_.top ()->create_order ())); + + stack_.top ()->insert (r); + stack_.push (r); + + scope_ = stack_.top ()->scope (); + + //@@ this code is highly experimental + IDL2::LexicalAnalyzer lexer (ifs); + + TokenStream token_stream; + + //@@ bad token comparison + for (TokenPtr token = lexer.next (); + token.in () != lexer.eos.in (); + token = lexer.next ()) + { + token_stream.push_back (token); + } + + if (token_stream.size () == 0) + { + // Empty file + return; + } + + IDL2::Parser parser (lexer, action_factory_); + + bool result = Details::parse (token_stream.begin (), + token_stream.end (), + parser.start ()); + */ + } + + virtual void + end () + { + cerr << "end" << endl; + + stack_.pop (); + scope_ = stack_.top ()->scope (); + } + + public: + SemanticActionFactory& action_factory_; + SyntaxTree::ScopePtr& scope_; + std::stack<SyntaxTree::TranslationRegionPtr> stack_; + }; + + // + // + // + class Module : public virtual SemanticAction::Module, + public virtual ScopeBase<SyntaxTree::ModulePtr> + { + public: + virtual + ~Module () throw () {} + + + Module (SyntaxTree::ScopePtr& scope) + : ScopeBase<SyntaxTree::ModulePtr> (scope) + { + } + + virtual void + begin (SimpleIdentifierPtr const& id) + { + cerr << "module " << id << endl; + + using namespace SyntaxTree; + + SimpleName name (id->value ()); + + ModulePtr m (new SyntaxTree::Module (name, scope_)); + + scope_->insert (m); + push (m); + } + + virtual void + open_scope () + { + scope_ = top (); + } + + virtual void + close_scope () + { + scope_ = scope_->scope (); + } + + virtual void + end () + { + pop (); + cerr << "end" << endl; + } + }; + + + // + // + // + class Interface : public virtual SemanticAction::Interface, + public virtual ScopeBase<SyntaxTree::InterfaceDeclPtr> + { + public: + virtual + ~Interface () throw () {} + + Interface (SyntaxTree::ScopePtr& scope) + : ScopeBase<SyntaxTree::InterfaceDeclPtr> (scope), + name_ ("") + { + } + + virtual void + begin (Qualifier::Value qualifier, SimpleIdentifierPtr const& id) + { + cerr << qualifier << " interface " << id << endl; + + qualifier_ = qualifier; + name_ = SyntaxTree::SimpleName (id->value ()); + } + + virtual void + inherits (IdentifierPtr const& id) + { + using namespace SyntaxTree; + + cerr << " inherits: " << id << endl; + + Name name (id->value ()); + + struct InheritancePredicate : + public DeclarationTable::ResolvePredicate + { + InheritancePredicate (Qualifier::Value q) : q_ (q) {} + + struct IncompatibleType : + public DeclarationTable::ResolutionFailure + { + IncompatibleType (std::string const& t) : type (t) {} + std::string type; + }; + + virtual bool + test (DeclarationPtr const& d) throw (IncompatibleType) + { + std::string type = d->declaration_type (); + + bool passed = false; + + switch (q_) + { + case Qualifier::UNCONSTRAINED: + { + if (type == "unconstrained interface" || + type == "abstract interface") passed = true; + break; + } + case Qualifier::LOCAL: + { + if (type == "unconstrained interface" || + type == "abstract interface" || + type == "local interface") passed = true; + break; + } + case Qualifier::ABSTRACT: + { + if (type == "abstract interface") passed = true; + break; + } + } + + if (!passed) throw IncompatibleType (type); + + return strict_cast<TypeDecl> (d)->defined (); + } + + private: + Qualifier::Value q_; + } p (qualifier_); + + try + { + ScopedName sn = scope_->table ().resolve ( + name, + scope_->name (), + scope_->peek_order (), + p); + + if (inherits_.insert (sn).second == false) + { + cerr << "error: invalid inheritance specification" << endl; + cerr << "directly inheriting from interface \'" + << sn << "\' more than once is illegal" << endl; + } + } + catch (InheritancePredicate::IncompatibleType const& e) + { + cerr << "error: invalid inheritance specification" << endl; + + cerr << "inheritance of "; + + switch (qualifier_) + { + case Qualifier::UNCONSTRAINED: + { + cerr << "unconstrained "; + break; + } + case Qualifier::LOCAL: + { + cerr << "local "; + break; + } + case Qualifier::ABSTRACT: + { + cerr << "abstract "; + break; + } + } + + cerr << "interface \'" << name_ <<"\' from " + << e.type << " \'" << name << "\' is illegal" << endl; + } + catch (DeclarationTable::NameNotFound const&) + { + cerr << "error: invalid inheritance specification" << endl; + cerr << "no interface with name \'" + << name << "\' visible from scope \'" + << scope_->name () << "\'" << endl; + } + catch (DeclarationTable::PredicateNotMet const&) + { + cerr << "error: invalid inheritance specification" << endl; + cerr << "no defined interface with name \'" + << name << "\' visible from scope \'" + << scope_->name () << "\'" << endl; + cerr << "inheritance from forward-declared interface is illegal" + << endl; + } + } + + virtual void + open_scope () + { + using namespace SyntaxTree; + + InterfaceDefPtr def; + + switch (qualifier_) + { + case Qualifier::UNCONSTRAINED: + { + def = new UnconstrainedInterfaceDef (name_, scope_, inherits_); + break; + } + case Qualifier::LOCAL: + { + def = new LocalInterfaceDef (name_, scope_, inherits_); + break; + } + case Qualifier::ABSTRACT: + { + def = new AbstractInterfaceDef (name_, scope_, inherits_); + break; + } + } + + scope_->insert (def); + push (def); + scope_ = def; + + name_ = SimpleName (""); //indicate that we are done + inherits_.clear (); + } + + virtual void + close_scope () + { + scope_ = scope_->scope (); + } + + virtual void + end () + { + using namespace SyntaxTree; + + cerr << "end" << endl; + + if (name_ != SimpleName ("")) + { + InterfaceDeclPtr decl; + + switch (qualifier_) + { + case Qualifier::UNCONSTRAINED: + { + decl = new UnconstrainedInterfaceForwardDecl (name_, scope_); + break; + } + case Qualifier::LOCAL: + { + decl = new LocalInterfaceForwardDecl (name_, scope_); + break; + } + case Qualifier::ABSTRACT: + { + decl = new AbstractInterfaceForwardDecl (name_, scope_); + break; + } + } + + scope_->insert (decl); + } + else + { + pop (); + } + } + private: + Qualifier::Value qualifier_; + SyntaxTree::SimpleName name_; + SyntaxTree::ScopedNameSet inherits_; + }; + + + class Attribute : public virtual SemanticAction::Attribute + { + public: + virtual + ~Attribute () throw () {} + + Attribute (SyntaxTree::ScopePtr& current) + : scope_ (current), + type_ ("") + { + } + + public: + virtual void + type (IdentifierPtr const& id) + { + cerr << "attribute " << id; + + using namespace SyntaxTree; + + Name name (id->value ()); + + struct Predicate : public DeclarationTable::ResolvePredicate + { + virtual bool + test (DeclarationPtr const& d) throw () + { + //@@ need extension to declaration type system + // e.g. something like this: + // "long;built-in type def;type def;type decl;declaration" + return strict_cast<TypeDecl> (d) != 0; + } + } p; + + try + { + ScopedName sn = scope_->table ().resolve ( + name, + scope_->name (), + scope_->peek_order (), + p); + + type_ = sn; + } + catch (DeclarationTable::NameNotFound const&) + { + cerr << "error: invalid attribute declaration" << endl; + cerr << "no type with name \'" + << name << "\' visible from scope \'" + << scope_->name () << "\'" << endl; + } + catch (DeclarationTable::PredicateNotMet const&) + { + cerr << "error: invalid attribute declaration" << endl; + cerr << "declaration with name \'" << name + << "\' visible from scope \'" << scope_->name () + << "\' is not a type declaration" << endl; + cerr << "using non-type as an attribute type is illegal" + << endl; + } + + } + + virtual void + name (SimpleIdentifierPtr const& id) + { + cerr << " " << id << endl; + + using namespace SyntaxTree; + SimpleName name (id->value ()); + + AttributeDeclPtr a ( + new SyntaxTree::AttributeDecl (name, type_, scope_)); + + scope_->insert (a); + + type_ = ScopedName (""); + } + + private: + SyntaxTree::ScopePtr& scope_; + SyntaxTree::ScopedName type_; + }; + + + // + // + // + class Operation : public virtual SemanticAction::Operation + { + public: + + virtual + ~Operation () throw () {} + + Operation (SyntaxTree::ScopePtr& current) + : scope_ (current) + { + } + + bool + lookup_type (SyntaxTree::Name const& name, + SyntaxTree::ScopedName& result) + { + using namespace SyntaxTree; + + struct Predicate : public DeclarationTable::ResolvePredicate + { + virtual bool + test (DeclarationPtr const& d) throw () + { + return strict_cast<TypeDecl> (d) != 0; + } + } p; + + try + { + result = scope_->table ().resolve ( + name, + scope_->name (), + scope_->peek_order (), + p); + + return true; + } + catch (DeclarationTable::NameNotFound const&) + { + cerr << "error: invalid operation declaration" << endl; + cerr << "no type with name \'" + << name << "\' visible from scope \'" + << scope_->name () << "\'" << endl; + } + catch (DeclarationTable::PredicateNotMet const&) + { + cerr << "error: invalid operation declaration" << endl; + cerr << "declaration with name \'" << name + << "\' visible from scope \'" << scope_->name () + << "\' is not a type declaration" << endl; + cerr << "using non-type as operation parameter type " + << " or return type is illegal" + << endl; + } + + return false; + } + + + virtual void + begin (IdentifierPtr const& type_id, + SimpleIdentifierPtr const& name_id) + { + cerr << "operation " << type_id << " " << name_id << endl; + + using namespace SyntaxTree; + + //@@ Why don't I have a default c-tor? + ScopedName type_name (""); + + if (lookup_type (Name (type_id->value ()), type_name)) + { + operation_ = OperationDeclPtr ( + new OperationDecl (SimpleName (name_id->value ()), + type_name, + scope_)); + } + } + + + virtual void + parameter (Direction::Value direction, + IdentifierPtr const& type_id, + SimpleIdentifierPtr const& name_id) + { + cerr << "parameter " + << direction << " " << type_id << " " << name_id << endl; + + using namespace SyntaxTree; + + ScopedName type_name (""); + + if (lookup_type (Name (type_id->value ()), type_name) && + operation_ != 0) + { + OperationParameter::Direction::Value d = + OperationParameter::Direction::INOUT; + + if (direction == Direction::IN) + { + d = OperationParameter::Direction::IN; + } + else if (direction == Direction::OUT) + { + d = OperationParameter::Direction::OUT; + } + + OperationParameterPtr p ( + new OperationParameter (d, + type_name, + SimpleName (name_id->value ()), + scope_->table ())); + operation_->insert (p); + } + } + + virtual void + end () + { + cerr << "end" << endl; + if (operation_ != 0) + { + scope_->insert (operation_); + operation_ = SyntaxTree::OperationDeclPtr (); + } + } + private: + SyntaxTree::ScopePtr& scope_; + SyntaxTree::OperationDeclPtr operation_; + }; + } + } + + // + // + // + class SemanticActionFactoryImpl : public virtual SemanticActionFactory + { + public: + virtual + ~SemanticActionFactoryImpl () throw () {} + + SemanticActionFactoryImpl (SyntaxTree::TranslationRegionPtr const& r) + : scope_ (r->scope ()), + + include_ (*this, r, scope_), + module_ (scope_), + interface_ (scope_), + attribute_ (scope_), + operation_ (scope_) + { + } + + virtual SemanticAction::Include& + include () + { + return include_; + } + + virtual SemanticAction::Module& + module () + { + return module_; + } + + virtual SemanticAction::Interface& + interface () + { + return interface_; + } + + virtual SemanticAction::Attribute& + attribute () + { + return attribute_; + } + + virtual SemanticAction::Operation& + operation () + { + return operation_; + } + + protected: + SyntaxTree::ScopePtr scope_; + SyntaxTree::TranslationRegionPtr region_; + + SemanticAction::Impl::Include include_; + SemanticAction::Impl::Module module_; + SemanticAction::Impl::Interface interface_; + SemanticAction::Impl::Attribute attribute_; + SemanticAction::Impl::Operation operation_; + }; +} + +#endif // CCF_IDL2_SEMANTIC_ACTION_IMPL_HPP diff --git a/TAO/CIAO/CCF/CCF/IDL2/IDL2_SyntaxTree.cpp b/TAO/CIAO/CCF/CCF/IDL2/IDL2_SyntaxTree.cpp new file mode 100644 index 00000000000..2292853d7da --- /dev/null +++ b/TAO/CIAO/CCF/CCF/IDL2/IDL2_SyntaxTree.cpp @@ -0,0 +1,773 @@ +// $Id$ +#include "IDL2_Traversal.hpp" +#include "IDL2_SyntaxTree.hpp" + +//@@tmp +#include <iostream> +using std::cerr; +using std::endl; + +namespace IDL2 +{ + namespace SyntaxTree + { + using ReferenceCounting::add_ref; + + using CCF::Traversal::try_visit; + + namespace + { + bool + try_visit_scope (CCF::Traversal::Visitor* v, + ScopePtr const& node) + { + return try_visit<Traversal::Scope> (&Traversal::Scope::visit_scope, v, node); + } + + bool + try_visit_type_decl (CCF::Traversal::Visitor* v, + TypeDeclPtr const& node) + { + return try_visit<Traversal::TypeDecl> (&Traversal::TypeDecl::visit_type_decl, v, node); + } + + bool + try_visit_type_def (CCF::Traversal::Visitor* v, + TypeDefPtr const& node) + { + return try_visit<Traversal::TypeDef> (&Traversal::TypeDef::visit_type_def, v, node); + } + + bool + try_visit_interface_decl (CCF::Traversal::Visitor* v, + InterfaceDeclPtr const& node) + { + return try_visit<Traversal::InterfaceDecl> (&Traversal::InterfaceDecl::visit_interface_decl, + v, + node); + } + + bool + try_visit_interface_def (CCF::Traversal::Visitor* v, + InterfaceDefPtr const& node) + { + return try_visit<Traversal::InterfaceDef> ( + &Traversal::InterfaceDef::visit_interface_def, + v, + node); + } + + bool + try_visit_abstract_interface_decl ( + CCF::Traversal::Visitor* v, + AbstractInterfaceDeclPtr const& node) + { + return try_visit<Traversal::AbstractInterfaceDecl> ( + &Traversal::AbstractInterfaceDecl::visit_abstract_interface_decl, + v, + node); + } + + bool + try_visit_local_interface_decl ( + CCF::Traversal::Visitor* v, + LocalInterfaceDeclPtr const& node) + { + return try_visit<Traversal::LocalInterfaceDecl> ( + &Traversal::LocalInterfaceDecl::visit_local_interface_decl, + v, + node); + } + + bool + try_visit_unconstrained_interface_decl ( + CCF::Traversal::Visitor* v, + UnconstrainedInterfaceDeclPtr const& node) + { + return try_visit<Traversal::UnconstrainedInterfaceDecl> ( + &Traversal::UnconstrainedInterfaceDecl:: + visit_unconstrained_interface_decl, + v, + node); + } + } + + // + // Comma + // + void Comma:: + accept (CCF::Traversal::Visitor* v) + { + CommaPtr self (ReferenceCounting::add_ref (this)); + try_visit<Traversal::Comma> (&Traversal::Comma::visit_comma, v, self); + } + + + // + // Declaration + // + Declaration:: + Declaration (SimpleName const& name, ScopePtr const& scope) + : order_ (scope->create_order ()), + name_ (scope->name (), name), + scope_ (scope->table (), + scope->name (), + scope->order ()) // Hint: scope->scope () may throw + { + } + + Declaration:: + Declaration (ScopedName const& name, + Order const& order, + DeclarationTable const& table) + : order_ (order), + name_ (name), + scope_ (table) // this stuff is faked + { + } + + ScopedName Declaration:: + name () const + { + return name_; + } + + Order Declaration:: + order () const + { + return order_; + } + + ScopePtr Declaration:: + scope () const throw (NotInScope) + { + return scope_.resolve (); + } + + // + // DeclarationTable + // + + void DeclarationTable:: + insert (DeclarationPtr d) throw (InvalidArgument, + AlreadyExist, + TypeMismatch) + { + if (d == 0) throw InvalidArgument (); + + IteratorPair pair = lookup (d->name ()); + + if (pair.first != pair.second) + { + // I have some declarations with this name already + if ((*pair.first)->declaration_type () != d->declaration_type ()) + { + throw TypeMismatch (); + } + } + + std::pair<DeclarationSet::iterator, bool> result = + decl_set_.insert (d); + + if (result.second == false) throw AlreadyExist (); + + try + { + if(name_decl_map_[d->name ()].insert (d).second == false) + { + throw AlreadyExist (); + } + } + catch (...) + { + // Leaving table in consistent state + decl_set_.erase (result.first); + throw; + } + } + + DeclarationTable::IteratorPair DeclarationTable:: + lookup (ScopedName const& n) const + { + NameDeclarationMap::const_iterator i = name_decl_map_.find (n); + if (i == name_decl_map_.end ()) + { + return IteratorPair (decl_set_.end (), decl_set_.end ()); + } + else + { + return IteratorPair (i->second.begin (), i->second.end ()); + } + } + + DeclarationTable::Iterator DeclarationTable:: + begin () const + { + return decl_set_.begin (); + } + + DeclarationTable::Iterator DeclarationTable:: + end () const + { + return decl_set_.end (); + } + + ScopedName DeclarationTable:: + resolve (Name const& name, + ScopedName const& from, + Order const& before, + ResolvePredicate& p) const throw (ResolutionFailure) + { + ScopedName result (""); + + // Check if name is already scoped + try + { + result = ScopedName (name); + } + catch (ScopedName::InvalidArgument const&) + { + //seems not + try + { + for (ScopedName base = from;;base = base.scope ()) + { + result = ScopedName (base, name); + + //cerr << "*** resolve: considering: " << result << endl; + + IteratorPair pair = lookup (result); + + if (pair.first != pair.second) + { + // Found something. Now checking the order. Note that the + // first element has the smallest order so it's sufficient + // to check just the first element for now. + if ((*pair.first)->order () < before) + { + break; + } + std::cerr << std::endl + << "before condition failed : " + << (*pair.first)->order () << " (" + << (*pair.first)->name () + << ") expected to be before " + << before << std::endl; + } + } + } + catch (ScopedName::AtRoot const&) + { + // didn't find anything + throw NameNotFound (); + } + } + + // Now check predicat + IteratorPair pair = lookup (result); + + if (pair.first == pair.second) throw NameNotFound (); + + for (;pair.first != pair.second; pair.first++) + { + // we should stay before + if (!((*pair.first)->order () < before)) break; + + if (p.test (*pair.first)) return result; + } + + throw PredicateNotMet (); + } + + // + // Scope + // + + void Scope:: + insert (DeclarationPtr d) throw (InvalidArgument, AlreadyExist) + { + if (d == 0) throw InvalidArgument (); + + std::pair<DeclarationSet::iterator, bool> result = + content_.insert (d); + + if (result.second == false) throw AlreadyExist (); + + try + { + try + { + table_.insert (d); + } + catch (...) + { + //Keep consistent state + content_.erase (result.first); + throw; + } + } + catch (DeclarationTable::InvalidArgument const&) + { + throw InvalidArgument (); + } + catch (DeclarationTable::AlreadyExist const&) + { + throw AlreadyExist (); + } + } + + Scope::Iterator Scope:: + begin () const + { + return content_.begin (); + } + + Scope::Iterator Scope:: + end () const + { + return content_.end (); + } + + Order Scope:: + create_order () + { + return Order (order (), next_order_++); + } + + Order Scope:: + peek_order () + { + return Order (order (), next_order_); + } + + void Scope:: + accept (CCF::Traversal::Visitor* v) + { + ScopePtr self (ReferenceCounting::add_ref (this)); + try_visit_scope (v, self); + } + + // + // TypeDecl + // + + void TypeDecl:: + accept (CCF::Traversal::Visitor* v) + { + TypeDeclPtr self (ReferenceCounting::add_ref (this)); + try_visit<Traversal::TypeDecl> (&Traversal::TypeDecl::visit_type_decl, v, self); + } + + + // + // TypeDef + // + + void TypeDef:: + accept (CCF::Traversal::Visitor* v) + { + TypeDefPtr self (ReferenceCounting::add_ref (this)); + + if(!try_visit<Traversal::TypeDef> ( + &Traversal::TypeDef::visit_type_def, + v, + self)) + { + TypeDecl::accept (v); + } + } + + // + // InterfaceDecl + // + + void InterfaceDecl:: + accept (CCF::Traversal::Visitor* v) + { + InterfaceDeclPtr self (ReferenceCounting::add_ref (this)); + + if (!try_visit_interface_decl (v, self)) + { + TypeDecl::accept (v); + } + } + + // + // InterfaceDef + // + + void InterfaceDef:: + accept (CCF::Traversal::Visitor* v) + { + InterfaceDefPtr self (ReferenceCounting::add_ref (this)); + + if(!try_visit_interface_def (v, self)) + { + InterfaceDecl::accept (v); + Scope::accept (v); + } + } + + + // + // AbstractInterfaceDecl + // + + void AbstractInterfaceDecl:: + accept (CCF::Traversal::Visitor* v) + { + AbstractInterfaceDeclPtr self (ReferenceCounting::add_ref (this)); + + if (!try_visit_abstract_interface_decl (v, self)) + { + InterfaceDecl::accept (v); + } + } + + // + // AbstractInterfaceDef + // + + void AbstractInterfaceDef:: + accept (CCF::Traversal::Visitor* v) + { + AbstractInterfaceDefPtr self (ReferenceCounting::add_ref (this)); + + if(!try_visit<Traversal::AbstractInterfaceDef> ( + &Traversal::AbstractInterfaceDef::visit_abstract_interface_def, + v, + self)) + { + AbstractInterfaceDecl::accept (v); + InterfaceDef::accept (v); + } + } + + // + // LocalInterfaceDecl + // + + void LocalInterfaceDecl:: + accept (CCF::Traversal::Visitor* v) + { + LocalInterfaceDeclPtr self (ReferenceCounting::add_ref (this)); + + if (!try_visit_local_interface_decl (v, self)) + { + InterfaceDecl::accept (v); + } + } + + + // + // LocalInterfaceDef + // + + void LocalInterfaceDef:: + accept (CCF::Traversal::Visitor* v) + { + LocalInterfaceDefPtr self (ReferenceCounting::add_ref (this)); + + if(!try_visit<Traversal::LocalInterfaceDef> ( + &Traversal::LocalInterfaceDef::visit_local_interface_def, + v, + self)) + { + bool b = try_visit_interface_def (v, self); + bool a = try_visit_local_interface_decl (v, self); + + // if (a && b) || a + if (a) return; + + if (b) + { + try_visit_type_def (v, self); + try_visit_scope (v, self); + } + else + { + try_visit_scope (v, self); + a = try_visit_type_def (v, self); + b = try_visit_interface_decl (v, self); + + if (a || b) return; + + try_visit_type_decl (v, self); + } + } + } + + // + // UnconstrainedInterfaceDecl + // + + void UnconstrainedInterfaceDecl:: + accept (CCF::Traversal::Visitor* v) + { + UnconstrainedInterfaceDeclPtr self (ReferenceCounting::add_ref (this)); + + if (!try_visit_unconstrained_interface_decl (v, self)) + { + InterfaceDecl::accept (v); + } + } + + + // + // UnconstrainedInterfaceDef + // + + void UnconstrainedInterfaceDef:: + accept (CCF::Traversal::Visitor* v) + { + UnconstrainedInterfaceDefPtr self (ReferenceCounting::add_ref (this)); + + if(!try_visit<Traversal::UnconstrainedInterfaceDef> ( + &Traversal::UnconstrainedInterfaceDef:: + visit_unconstrained_interface_def, + v, + self)) + { + bool b = try_visit_interface_def (v, self); + bool a = try_visit_unconstrained_interface_decl (v, self); + + // if (a && b) || a + if (a) return; + + if (b) + { + try_visit_type_def (v, self); + try_visit_scope (v, self); + } + else + { + try_visit_scope (v, self); + a = try_visit_type_def (v, self); + b = try_visit_interface_decl (v, self); + + if (a || b) return; + + try_visit_type_decl (v, self); + } + } + } + + // + // AttributeDecl + // + + void AttributeDecl:: + accept (CCF::Traversal::Visitor* v) + { + AttributeDeclPtr self (ReferenceCounting::add_ref (this)); + try_visit<Traversal::AttributeDecl> ( + &Traversal::AttributeDecl::visit_attribute_decl, + v, + self); + } + + // + // OperationParameter + // + void OperationParameter:: + accept (CCF::Traversal::Visitor* v) + { + OperationParameterPtr self (ReferenceCounting::add_ref (this)); + try_visit<Traversal::OperationParameter> (&Traversal::OperationParameter::visit_operation_parameter, + v, + self); + } + + + // + // OperationDecl + // + void OperationDecl:: + accept (CCF::Traversal::Visitor* v) + { + OperationDeclPtr self (ReferenceCounting::add_ref (this)); + try_visit<Traversal::OperationDecl> ( + &Traversal::OperationDecl::visit_operation_decl, + v, + self); + } + + + // + // Module + // + + void Module:: + accept (CCF::Traversal::Visitor* v) + { + ModulePtr self (ReferenceCounting::add_ref (this)); + + if (!try_visit<Traversal::Module> (&Traversal::Module::visit_module, + v, + self)) + { + Scope::accept (v); + } + } + + // + // FileScope + // + + FileScope:: + FileScope (DeclarationTable& table, Order const& order) + : Declaration (ScopedName (""), order, table), + Scope (table, ScopedName (""), order) + { + } + + void FileScope:: + accept (CCF::Traversal::Visitor* v) + { + FileScopePtr self (ReferenceCounting::add_ref (this)); + + if (!try_visit<Traversal::FileScope> ( + &Traversal::FileScope::visit_file_scope, + v, + self)) + { + Scope::accept (v); + } + } + + // + // TranslationRegion + // + + void TranslationRegion:: + insert (TranslationRegionPtr const& tr) throw (InvalidArgument) + { + if (tr == 0) throw InvalidArgument (); + + region_list_.push_back (tr); + } + + TranslationRegion::Iterator TranslationRegion:: + begin () const + { + return region_list_.begin (); + } + + TranslationRegion::Iterator TranslationRegion:: + end () const + { + return region_list_.end (); + } + + void TranslationRegion:: + accept (CCF::Traversal::Visitor* v) + { + TranslationRegionPtr self (ReferenceCounting::add_ref (this)); + + try_visit<Traversal::TranslationRegion> ( + &Traversal::TranslationRegion::visit_translation_region, + v, + self); + } + + // + // IncludeTranslationRegion + // + + void IncludeTranslationRegion:: + accept (CCF::Traversal::Visitor* v) + { + IncludeTranslationRegionPtr self (ReferenceCounting::add_ref (this)); + + if(!try_visit<Traversal::IncludeTranslationRegion>( + &Traversal::IncludeTranslationRegion:: + visit_include_translation_region, + v, + self)) TranslationRegion::accept (v); + } + + // + // SysIncludeTranslationRegion + // + + void SysIncludeTranslationRegion:: + accept (CCF::Traversal::Visitor* v) + { + SysIncludeTranslationRegionPtr self (ReferenceCounting::add_ref (this)); + + if(!try_visit<Traversal::SysIncludeTranslationRegion>( + &Traversal::SysIncludeTranslationRegion:: + visit_sys_include_translation_region, + v, + self)) TranslationRegion::accept (v); + } + + // + // ImpliedIncludeTranslationRegion + // + + void ImpliedIncludeTranslationRegion:: + accept (CCF::Traversal::Visitor* v) + { + ImpliedIncludeTranslationRegionPtr self ( + ReferenceCounting::add_ref (this)); + + if(!try_visit<Traversal::ImpliedIncludeTranslationRegion>( + &Traversal::ImpliedIncludeTranslationRegion:: + visit_implied_include_translation_region, + v, + self)) TranslationRegion::accept (v); + } + + // + // PrincipalTranslationRegion + // + + void PrincipalTranslationRegion:: + accept (CCF::Traversal::Visitor* v) + { + PrincipalTranslationRegionPtr self (ReferenceCounting::add_ref (this)); + + if(!try_visit<Traversal::PrincipalTranslationRegion>( + &Traversal::PrincipalTranslationRegion:: + visit_principal_translation_region, + v, + self)) TranslationRegion::accept (v); + } + + // + // TranslationUnit + // + + void TranslationUnit:: + insert (TranslationRegionPtr const& tr) throw (InvalidArgument) + { + if (tr == 0) throw InvalidArgument (); + + region_list_.push_back (tr); + } + + TranslationUnit::Iterator TranslationUnit:: + begin () const + { + return region_list_.begin (); + } + + TranslationUnit::Iterator TranslationUnit:: + end () const + { + return region_list_.end (); + } + + void TranslationUnit:: + accept (CCF::Traversal::Visitor* v) + { + TranslationUnitPtr self (ReferenceCounting::add_ref (this)); + + try_visit<Traversal::TranslationUnit> ( + &Traversal::TranslationUnit::visit_translation_unit, + v, + self); + } + } +} diff --git a/TAO/CIAO/CCF/CCF/IDL2/IDL2_SyntaxTree.hpp b/TAO/CIAO/CCF/CCF/IDL2/IDL2_SyntaxTree.hpp new file mode 100644 index 00000000000..e6e656591ce --- /dev/null +++ b/TAO/CIAO/CCF/CCF/IDL2/IDL2_SyntaxTree.hpp @@ -0,0 +1,2059 @@ +// $Id$ +#ifndef CCF_IDL2_SYNTAX_TREE_HPP +#define CCF_IDL2_SYNTAX_TREE_HPP + +#include "MSVC_Pragmas.hpp" + +#include <vector> +#include <map> +#include <set> +#include <string> + +#include <iostream> + +#include "CCF/CompilerElements/FileSystem.hpp" +#include "CCF/CompilerElements/ReferenceCounting.hpp" + +#include "CCF/CompilerElements/Traversal.hpp" + +//@@ It doesn't seem that traversal mechanism has to be embeded +// into SyntaxTree anymore. + +namespace IDL2 +{ + namespace SyntaxTree + { + using ReferenceCounting::StrictPtr; + using ReferenceCounting::strict_cast; + + + // + // Can be scoped or simple. + // + class Name + { + public: + explicit + Name (std::string const& name) + : name_ (name) + { + } + + bool + operator< (Name const& other) const + { + return name_ < other.name_; + } + + bool + operator== (Name const& other) const + { + return name_ == other.name_; + } + + bool + operator!= (Name const& other) const + { + return name_ == other.name_; + } + + + + protected: + std::string name_; + + friend std::ostream& + operator << (std::ostream& o, Name const& name) + { + return o << name.name_; + } + + friend class ScopedName; + }; + + + // + // + // + class SimpleName : public Name + { + public: + explicit + SimpleName (std::string const& name) + : Name (name) + { + //@@ need some checking + } + + bool + operator< (SimpleName const& other) const + { + return name_ < other.name_; + } + + bool + operator== (SimpleName const& other) const + { + return name_ == other.name_; + } + + bool + operator!= (SimpleName const& other) const + { + return name_ != other.name_; + } + + private: + std::string + str () const + { + return name_; + } + + friend SimpleName + operator+ (SimpleName const& s1, std::string const& s2) + { + return SimpleName (s1.str () + s2); + } + + friend SimpleName + operator+ (std::string const& s1, SimpleName const& s2) + { + return SimpleName (s1 + s2.str ()); + } + }; + + // + // + // + class ScopedName : public Name + { + public: + class InconsistentState {}; + class InvalidArgument {}; + + public: + explicit + ScopedName (std::string const& name) throw (InvalidArgument) + : Name (name) + { + try + { + check_state (); + } + catch (InconsistentState const&) + { + throw InvalidArgument (); + } + } + + explicit + ScopedName (Name const& name) throw (InvalidArgument) + : Name (name) + { + try + { + check_state (); + } + catch (InconsistentState const&) + { + throw InvalidArgument (); + } + } + + ScopedName (ScopedName const& scope, Name const& name) + throw (InvalidArgument) + : Name (scope.name_ + "::" + name.name_) + { + try + { + check_state (); + } + catch (InconsistentState const&) + { + throw InvalidArgument (); + } + } + + bool + operator< (ScopedName const& other) const + { + return name_ < other.name_; + } + + bool + operator== (ScopedName const& other) const + { + return name_ == other.name_; + } + + bool + operator!= (ScopedName const& other) const + { + return name_ != other.name_; + } + + public: + SimpleName + simple () const + { + std::string::size_type pos = name_.rfind ("::"); + if (pos == std::string::npos) + { + if (name_.empty ()) return SimpleName(""); //file scope name + else throw InconsistentState (); + } + + return SimpleName(std::string (name_.begin () + pos + 2, + name_.end ())); + } + + class AtRoot {}; + + ScopedName + scope () const throw (AtRoot) + { + std::string::size_type pos = name_.rfind ("::"); + if (pos == std::string::npos) + { + throw AtRoot (); + } + + return ScopedName(std::string (name_.begin (), + name_.begin () + pos)); + } + + Name + in_file_scope () const + { + return Name(std::string (name_.begin () + 2, name_.end ())); + } + + + private: + void + check_state () throw (InconsistentState) + { + if (name_.empty ()) return; + + if (name_.length () < 2) throw InconsistentState (); + + if (name_[0] != ':' || name_[1] != ':') throw InconsistentState (); + + //scan the string + for (std::string::const_iterator i = name_.begin (); + i != name_.end (); + i++) + { + if (*i == ':') + { + if (i + 1 == name_.end () || *(i + 1) != ':') + { + throw InconsistentState (); + } + else + { + i++; //skip "::" + } + } + } + } + + }; + + typedef + std::vector<ScopedName> + ScopedNameList; + + typedef + std::set<ScopedName> + ScopedNameSet; + + // + // + // + class Order + { + public: + Order (Order const& parent, unsigned long index) + : list_ (parent.list_) + { + list_.push_back (index); + } + + explicit + Order (unsigned long index) + : list_ (1, index) + { + } + + public: + bool + operator == (Order const& other) const + { + return list_ == other.list_; + } + + bool + operator != (Order const& other) const + { + return list_ != other.list_; + } + + bool + operator < (Order const& other) const + { + Iterator i = list_.begin (); + Iterator j = other.list_.begin (); + for (; i != list_.end () && j != other.list_.end (); i++, j++) + { + if (*i > *j) + { + return false; + } + else if (*i < *j) + { + return true; + } + } + + if (j != other.list_.end ()) + { + // we are equal so far but other is longer which means it is after + return true; + } + else + { + return false; + } + } + + bool + suborder (Order const& subj) const + { + if (list_.size () >= subj.list_.size ()) return false; + + for (Iterator i = list_.begin (), j = subj.list_.begin (); + i != list_.end (); + i++, j++) + { + if (*i != *j) return false; + } + + return true; + } + + + private: + typedef + std::vector<unsigned long> + OrderList_; + + typedef + OrderList_::const_iterator + Iterator; + + OrderList_ list_; + + friend std::ostream& + operator << (std::ostream& o, Order const& order) + { + for (Order::OrderList_::const_iterator i = order.list_.begin (); + i != order.list_.end (); + i++) + { + if (i != order.list_.begin ()) o << ':'; + o << *i; + } + + return o; + } + }; + + + // + // + // + class Node; + typedef + StrictPtr<Node> + NodePtr; + + class Node : public virtual ReferenceCounting::DefaultImpl <> + { + protected: + virtual + ~Node () throw () {} + + // Dynamic typing + public: + + template <typename Type> + bool + is_a () + { + NodePtr self (ReferenceCounting::add_ref (this)); + return strict_cast<Type>(self) != 0; + } + + template <typename Type> + StrictPtr<Type> + dynamic_type () + { + NodePtr self (ReferenceCounting::add_ref (this)); + return strict_cast<Type>(self); + } + + // Traversal + public: + virtual void + accept (CCF::Traversal::Visitor* v) = 0; + }; + + // + // + // + class Comma : public virtual Node + { + public: + virtual + ~Comma () throw () {} + + // Traversal + public: + virtual void + accept (CCF::Traversal::Visitor* v); + }; + typedef + StrictPtr<Comma> + CommaPtr; + + + // + // Contains scoped name & reference to DeclarationTable. + // Purpose: provides controlled way of cyclic dependencies + // + // Issues: + // + // @@ There is a need for 'uninitialized' state of refernce. + // + + class Declaration; + + typedef + StrictPtr<Declaration> + DeclarationPtr; + + class DeclarationTable; + + //@@ Better name for DeclarationRef: + // - DeclarationLink + // + template <typename T, typename Ptr = StrictPtr<T> > + class DeclarationRef + { + public: + class NotInitialized {}; + class DeclarationNotFound {}; + class TypeMismatch {}; + class TableMismatch {}; + + + public: + + DeclarationRef (DeclarationPtr decl); + DeclarationRef (DeclarationTable const& table, ScopedName const& name); + DeclarationRef (DeclarationTable const& table, + ScopedName const& name, + Order const& order); + + //This c-tor construct an uninitialized reference. + DeclarationRef (DeclarationTable const& table); + + // Note that you can only assign DeclarationRef's associated with + // the same DeclarationTable. + // + DeclarationRef& + operator= (DeclarationRef const& other) throw (TableMismatch) + { + if (&table_ != &(other.table_)) throw TableMismatch (); + + name_ = other.name_; + order_ = other.order_; + initialized_ = other.initialized_; + with_order__ = other.with_order_; + + return *this; + } + + operator bool () const + { + return initialized_; + } + + // Returns first declaration that matches. + Ptr + resolve () const + throw (NotInitialized, DeclarationNotFound, TypeMismatch); + + ScopedName + name () const throw (NotInitialized) + { + if (!initialized_) throw NotInitialized (); + return name_; + } + + private: + DeclarationTable const& table_; + ScopedName name_; + Order order_; + bool initialized_; + bool with_order_; + }; + + + // + // Declaration represents any IDL construct that has a scoped name + // + + class Scope; + + typedef + StrictPtr<Scope> + ScopePtr; + + class Declaration : public virtual Node + { + protected: + //@@ pure virtual d-tor with body doesn't work? + virtual + ~Declaration () throw () {} + + Declaration (SimpleName const& name, ScopePtr const& scope); + + // This c-tor is here for Declarations that are not in scope + // e.g. FileScope + Declaration (ScopedName const& name, + Order const& order, + DeclarationTable const& table); + + public: + + ScopedName + name () const; + + Order + order () const; + + class NotInScope {}; // don't cross the edge! ;-) + + virtual ScopePtr + scope () const throw (NotInScope); + + // Runtime declaration type information. I could have used RTTI but + // I will also need a human-readable representation (e.g. + // "local interface" instead of "IDL2::SyntaxTree::LocalInterface") + // for diagnistic. + public: + virtual std::string + declaration_type () + { + return "declaration"; + } + + private: + Order order_; + ScopedName name_; + DeclarationRef<Scope> scope_; + }; + + typedef + StrictPtr<Declaration> + DeclarationPtr; + + + // + // + // + template <typename T = DeclarationPtr> + struct DeclarationOrderComparator + { + bool operator () (T const& x, T const& y) const + { + return x->order () < y->order (); + } + }; + + template <typename T = DeclarationPtr> + struct DeclarationNameComparator + { + bool operator () (T const& x, T const& y) const + { + return x->name () < y->name (); + } + }; + + + // + // + // + template <typename T = DeclarationRef<Declaration> > + struct DeclarationRefOrderComparator + { + bool operator () (T const& x, T const& y) const + { + return x.resolve ()->order () < y.resolve ()->order (); + } + }; + + template <typename T = DeclarationRef<Declaration> > + struct DeclarationRefNameComparator + { + bool operator () (T const& x, T const& y) const + { + return x.resolve ()->name () < y.resolve ()->name (); + } + }; + + + // + // Mapping of fq-name -> sequence<Declaration> and some other + // useful stuff. + // + class DeclarationTable + { + private: + typedef + std::set<DeclarationPtr, DeclarationOrderComparator<> > + DeclarationSet; + + typedef + std::map<ScopedName, DeclarationSet> + NameDeclarationMap; + + public: + + typedef + DeclarationSet::const_iterator + Iterator; + + typedef + std::pair<Iterator, Iterator> + IteratorPair; + + class InvalidArgument {}; + class AlreadyExist {}; + + class TypeMismatch {}; + + public: + void + insert (DeclarationPtr d) throw (InvalidArgument, + AlreadyExist, + TypeMismatch); + Iterator + begin () const; + + Iterator + end () const; + + // Returns iterator pair. first points to the first element, + // second points to the element after last. + IteratorPair + lookup (ScopedName const& n) const; + + bool + exist (ScopedName const& n) const + { + IteratorPair pair = lookup (n); + return pair.first != pair.second; + } + + + class DeclarationNotFound {}; + + template <typename T> + StrictPtr<T> + lookup (ScopedName const& n) const + throw (DeclarationNotFound, TypeMismatch); + + template <typename T> + StrictPtr<T> + lookup (ScopedName const& n, Order const& o) const + throw (DeclarationNotFound, TypeMismatch); + + class ResolutionFailure {}; + class NameNotFound : public ResolutionFailure {}; + class PredicateNotMet : public ResolutionFailure {}; + + struct ResolvePredicate + { + virtual bool + test (DeclarationPtr const& d) throw (ResolutionFailure) = 0; + }; + + ScopedName + resolve (Name const& name, + ScopedName const& from, + Order const& before, + ResolvePredicate& p) const throw (ResolutionFailure); + + private: + DeclarationSet decl_set_; + NameDeclarationMap name_decl_map_; + }; + + + // @@ scope is not a declaration? + // Scope + // + class Scope : public virtual Declaration + { + private: + //@@ same type as in DeclarationTable + typedef + std::set<DeclarationPtr, DeclarationOrderComparator<> > + DeclarationSet; + + public: + typedef + DeclarationSet::const_iterator + Iterator; + + class InvalidArgument {}; + class AlreadyExist {}; + + + protected: + virtual + ~Scope () throw () {} + + // This c-tor is here for Declarations that are not in scope + // e.g. FileScope. + Scope (DeclarationTable& table, + ScopedName const& name, + Order const& order) + : Declaration (name, order, table), + table_ (table), + next_order_ (0) {} + + Scope (SimpleName const& name, ScopePtr const& scope) + : Declaration (name, scope), + table_ (scope->table ()), + next_order_ (0) + { + } + + public: + + // Inject new Declaration into a scope. Relative position of a new + // entity will be determined based on order (order..! order..!). + void + insert (DeclarationPtr d) throw (InvalidArgument, AlreadyExist); + + Iterator + begin () const; + + Iterator + end () const; + + Order + create_order (); + + // Returns order that would be returned by next call to + // create_order (). + Order + peek_order (); + + + public: + + DeclarationTable const& table () const + { + return table_; + } + + DeclarationTable& table () + { + return table_; + } + + // Runtime declaration type information + public: + virtual std::string + declaration_type () + { + return "scope"; + } + + // Traversal + public: + virtual void + accept (CCF::Traversal::Visitor* v); + + private: + DeclarationSet content_; + DeclarationTable& table_; + unsigned long next_order_; + }; + + + // + // + // + class TypeDecl : public virtual Declaration + { + protected: + virtual + ~TypeDecl () throw () {} + + TypeDecl (SimpleName const& name, + ScopePtr const& scope) + : Declaration (name, scope) + { + } + + // Type completeness + public: + virtual bool + defined () const = 0; + + // Runtime declaration type information + public: + virtual std::string + declaration_type () + { + return "type"; + } + + // Traversal + public: + virtual void + accept (CCF::Traversal::Visitor* v); + }; + + typedef + StrictPtr<TypeDecl> + TypeDeclPtr; + + typedef + DeclarationRef<TypeDecl> + TypeDeclRef; + + // + // + // + class TypeForwardDecl : public virtual TypeDecl + { + protected: + virtual + ~TypeForwardDecl () throw () {} + + TypeForwardDecl (SimpleName const& name, + ScopePtr const& scope) + : Declaration (name, scope), + TypeDecl (name, scope) + { + } + + // Type completeness + public: + virtual bool + defined () const + { + return false; + } + + // Runtime declaration type information + public: + virtual std::string + declaration_type () + { + return "type"; + } + }; + + + // + // + // + class TypeDef : public virtual TypeDecl + { + protected: + virtual + ~TypeDef () throw () {} + + TypeDef (SimpleName const& name, + ScopePtr const& scope) + : Declaration (name, scope), + TypeDecl (name, scope) + { + } + + // Type completeness + public: + virtual bool + defined () const + { + return true; + } + + // Runtime declaration type information + public: + virtual std::string + declaration_type () + { + return "type"; + } + + // Traversal + public: + virtual void + accept (CCF::Traversal::Visitor* v); + }; + + typedef + StrictPtr<TypeDef> + TypeDefPtr; + + typedef + DeclarationRef<TypeDef> + TypeDefRef; + + + /* + // Anonymous type + class Anonymous : public virtual Type + { + }; + + */ + + + // + // + // + class InterfaceDecl : public virtual TypeDecl + { + public: + virtual + ~InterfaceDecl () throw () {} + + InterfaceDecl (SimpleName const& name, + ScopePtr const& scope) + : Declaration (name, scope), + TypeDecl (name, scope) + { + } + + // Runtime declaration type information + public: + virtual std::string + declaration_type () + { + return "interface"; + } + + + // Traversal + public: + virtual void + accept (CCF::Traversal::Visitor* v); + }; + + typedef + StrictPtr<InterfaceDecl> + InterfaceDeclPtr; + + typedef + DeclarationOrderComparator<InterfaceDeclPtr> + InterfaceDeclOrderComparator; + + typedef + std::set<InterfaceDeclPtr, InterfaceDeclOrderComparator> + InterfaceDeclSet; + + typedef + DeclarationRef<InterfaceDecl> + InterfaceDeclRef; + + typedef + DeclarationRefOrderComparator<InterfaceDeclRef> + InterfaceDeclRefOrderComparator; + + typedef + std::set<InterfaceDeclRef, InterfaceDeclRefOrderComparator> + InterfaceDeclRefSet; + + + // + // + // + class InterfaceForwardDecl : public virtual InterfaceDecl, + public virtual TypeForwardDecl + { + public: + virtual + ~InterfaceForwardDecl () throw () {} + + InterfaceForwardDecl (SimpleName const& name, + ScopePtr const& scope) + : Declaration (name, scope), + TypeDecl (name, scope), + InterfaceDecl (name, scope), + TypeForwardDecl (name, scope) + { + } + + // Runtime declaration type information + public: + virtual std::string + declaration_type () + { + return "interface"; + } + }; + + // + // + // + class InterfaceDef; + + typedef + StrictPtr<InterfaceDef> + InterfaceDefPtr; + + typedef + DeclarationRef<InterfaceDef> + InterfaceDefRef; + + typedef + DeclarationRefNameComparator<InterfaceDefRef> + InterfaceDefRefNameComparator; + + typedef + std::set<InterfaceDefRef, InterfaceDefRefNameComparator> + InterfaceDefRefSetName; + + class InterfaceDef : public virtual InterfaceDecl, + public virtual TypeDef, + public virtual Scope + { + public: + virtual + ~InterfaceDef () throw () {} + + class DuplicateName {}; + + InterfaceDef (SimpleName const& name, + ScopePtr const& scope, + ScopedNameSet const& inherits) throw (DuplicateName) + : Declaration (name, scope), + TypeDecl (name, scope), + InterfaceDecl (name, scope), + TypeDef (name, scope), + Scope (name, scope) + { + for (ScopedNameSet::const_iterator i = inherits.begin (); + i != inherits.end (); + i++) + { + if (!inherits_.insert ( + InterfaceDefRef (scope->table (), *i)).second) + { + //@@ this never happens + throw DuplicateName (); + } + } + } + + public: + typedef + InterfaceDefRefSetName::const_iterator + Iterator; + + Iterator + inherits_begin () const + { + return inherits_.begin (); + } + + Iterator + inherits_end () const + { + return inherits_.end (); + } + + // Runtime declaration type information + public: + virtual std::string + declaration_type () + { + return "interface"; + } + + // Traversal + public: + virtual void + accept (CCF::Traversal::Visitor* v); + + private: + InterfaceDefRefSetName inherits_; + }; + + typedef + DeclarationOrderComparator<InterfaceDefPtr> + InterfaceDefOrderComparator; + + typedef + std::set<InterfaceDefPtr, InterfaceDefOrderComparator> + InterfaceDefSet; + + typedef + DeclarationRefOrderComparator<InterfaceDefRef> + InterfaceDefRefOrderComparator; + + typedef + std::set<InterfaceDefRef, InterfaceDefRefOrderComparator> + InterfaceDefRefSet; + + + // + // + // + class AbstractInterfaceDecl : public virtual InterfaceDecl + { + public: + virtual + ~AbstractInterfaceDecl () throw () {} + + // forward-declared unconstrained interface c-tor + AbstractInterfaceDecl (SimpleName const& name, + ScopePtr const& scope) + : Declaration (name, scope), + TypeDecl (name, scope), + InterfaceDecl (name, scope) + { + } + + // Runtime declaration type information + public: + virtual std::string + declaration_type () + { + return "abstract interface"; + } + + // Traversal + public: + virtual void + accept (CCF::Traversal::Visitor* v); + }; + + + // + // + // + class AbstractInterfaceForwardDecl : public virtual InterfaceForwardDecl, + public virtual AbstractInterfaceDecl + { + public: + virtual + ~AbstractInterfaceForwardDecl () throw () {} + + // forward-declared unconstrained interface c-tor + AbstractInterfaceForwardDecl (SimpleName const& name, + ScopePtr const& scope) + : Declaration (name, scope), + TypeDecl (name, scope), + InterfaceDecl (name, scope), + TypeForwardDecl (name, scope), + InterfaceForwardDecl (name, scope), + AbstractInterfaceDecl (name, scope) + { + } + + // Runtime declaration type information + public: + virtual std::string + declaration_type () + { + return "abstract interface"; + } + }; + + + // + // + // + class AbstractInterfaceDef : public virtual AbstractInterfaceDecl, + public virtual InterfaceDef + { + public: + virtual + ~AbstractInterfaceDef () throw () {} + + AbstractInterfaceDef (SimpleName const& name, + ScopePtr const& scope, + ScopedNameSet const& inherits) + : Declaration (name, scope), + TypeDecl (name, scope), + InterfaceDecl (name, scope), + AbstractInterfaceDecl (name, scope), + TypeDef (name, scope), + Scope (name, scope), + InterfaceDef (name, scope, inherits) + { + } + + // Runtime declaration type information + public: + virtual std::string + declaration_type () + { + return "abstract interface"; + } + + // Traversal + public: + virtual void + accept (CCF::Traversal::Visitor* v); + }; + + // + // + // + class LocalInterfaceDecl : public virtual InterfaceDecl + { + public: + virtual + ~LocalInterfaceDecl () throw () {} + + LocalInterfaceDecl (SimpleName const& name, + ScopePtr const& scope) + : Declaration (name, scope), + TypeDecl (name, scope), + InterfaceDecl (name, scope) + { + } + + // Runtime declaration type information + public: + virtual std::string + declaration_type () + { + return "local interface"; + } + + // Traversal + public: + virtual void + accept (CCF::Traversal::Visitor* v); + }; + + + // + // + // + class LocalInterfaceForwardDecl : public virtual InterfaceForwardDecl, + public virtual LocalInterfaceDecl + { + public: + virtual + ~LocalInterfaceForwardDecl () throw () {} + + LocalInterfaceForwardDecl (SimpleName const& name, + ScopePtr const& scope) + : Declaration (name, scope), + TypeDecl (name, scope), + InterfaceDecl (name, scope), + TypeForwardDecl (name, scope), + InterfaceForwardDecl (name, scope), + LocalInterfaceDecl (name, scope) + { + } + + // Runtime declaration type information + public: + virtual std::string + declaration_type () + { + return "local interface"; + } + }; + + + // + // + // + class LocalInterfaceDef : public virtual LocalInterfaceDecl, + public virtual InterfaceDef + { + public: + virtual + ~LocalInterfaceDef () throw () {} + + LocalInterfaceDef (SimpleName const& name, + ScopePtr const& scope, + ScopedNameSet const& inherits) + : Declaration (name, scope), + TypeDecl (name, scope), + InterfaceDecl (name, scope), + LocalInterfaceDecl (name, scope), + TypeDef (name, scope), + Scope (name, scope), + InterfaceDef (name, scope, inherits) + { + } + + // Runtime declaration type information + public: + virtual std::string + declaration_type () + { + return "local interface"; + } + + // Traversal + public: + virtual void + accept (CCF::Traversal::Visitor* v); + }; + + typedef + StrictPtr<LocalInterfaceDef> + LocalInterfaceDefPtr; + + + // + // + // + class UnconstrainedInterfaceDecl : public virtual InterfaceDecl + { + public: + virtual + ~UnconstrainedInterfaceDecl () throw () {} + + UnconstrainedInterfaceDecl (SimpleName const& name, + ScopePtr const& scope) + : Declaration (name, scope), + TypeDecl (name, scope), + InterfaceDecl (name, scope) + { + } + + // Runtime declaration type information + public: + virtual std::string + declaration_type () + { + return "unconstrained interface"; + } + + // Traversal + public: + virtual void + accept (CCF::Traversal::Visitor* v); + }; + + typedef + StrictPtr<UnconstrainedInterfaceDecl> + UnconstrainedInterfaceDeclPtr; + + + typedef + DeclarationOrderComparator<UnconstrainedInterfaceDeclPtr> + UnconstrainedInterfaceDeclOrderComparator; + + typedef + std::set<UnconstrainedInterfaceDeclPtr, + UnconstrainedInterfaceDeclOrderComparator> + UnconstrainedInterfaceDeclSet; + + + // + // + // + class UnconstrainedInterfaceForwardDecl : + public virtual InterfaceForwardDecl, + public virtual UnconstrainedInterfaceDecl + { + public: + virtual + ~UnconstrainedInterfaceForwardDecl () throw () {} + + UnconstrainedInterfaceForwardDecl (SimpleName const& name, + ScopePtr const& scope) + : Declaration (name, scope), + TypeDecl (name, scope), + InterfaceDecl (name, scope), + TypeForwardDecl (name, scope), + InterfaceForwardDecl (name, scope), + UnconstrainedInterfaceDecl (name, scope) + { + } + + // Runtime declaration type information + public: + virtual std::string + declaration_type () + { + return "unconstrained interface"; + } + }; + + // + // + // + class UnconstrainedInterfaceDef : + public virtual UnconstrainedInterfaceDecl, + public virtual InterfaceDef + { + public: + virtual + ~UnconstrainedInterfaceDef () throw () {} + + UnconstrainedInterfaceDef (SimpleName const& name, + ScopePtr const& scope, + ScopedNameSet const& inherits) + : Declaration (name, scope), + TypeDecl (name, scope), + InterfaceDecl (name, scope), + UnconstrainedInterfaceDecl (name, scope), + TypeDef (name, scope), + Scope (name, scope), + InterfaceDef (name, scope, inherits) + { + } + + // Runtime declaration type information + public: + virtual std::string + declaration_type () + { + return "unconstrained interface"; + } + + // Traversal + public: + virtual void + accept (CCF::Traversal::Visitor* v); + }; + + typedef + StrictPtr<UnconstrainedInterfaceDef> + UnconstrainedInterfaceDefPtr; + + + typedef + DeclarationOrderComparator<UnconstrainedInterfaceDefPtr> + UnconstrainedInterfaceDefOrderComparator; + + typedef + std::set<UnconstrainedInterfaceDefPtr, + UnconstrainedInterfaceDefOrderComparator> + UnconstrainedInterfaceDefSet; + + + // + // + // + class AttributeDecl : public virtual Declaration + { + public: + virtual + ~AttributeDecl () throw () {} + + AttributeDecl (SimpleName const& name, + ScopedName const& type, + ScopePtr const& scope) + : Declaration (name, scope), + type_ (scope->table (), type) + + { + } + + public: + TypeDeclPtr + type () + { + return type_.resolve (); + } + + + // Runtime declaration type information + public: + virtual std::string + declaration_type () + { + return "attribute"; + } + + // Traversal + public: + virtual void + accept (CCF::Traversal::Visitor* v); + + private: + TypeDeclRef type_; + }; + + typedef + StrictPtr<AttributeDecl> + AttributeDeclPtr; + + // + // + // + class OperationParameter : public virtual Node + { + public: + virtual + ~OperationParameter () throw () {} + + struct Direction + { + enum Value + { + IN, + OUT, + INOUT + }; + + friend std::ostream& + operator<< (std::ostream& o, Value d) + { + if (d == IN) o << "in"; + else if (d == OUT) o << "out"; + else o << "inout"; + return o; + } + }; + + OperationParameter (Direction::Value direction, + ScopedName type, + SimpleName name, + DeclarationTable const& table) + : direction_ (direction), + type_ (table, type), + name_ (name) + { + } + + public: + Direction::Value + direction () + { + return direction_; + } + + TypeDeclPtr + type () + { + return type_.resolve (); + } + + SimpleName + name () + { + return name_; + } + + // Traversal + public: + virtual void + accept (CCF::Traversal::Visitor* v); + + private: + Direction::Value direction_; + TypeDeclRef type_; + SimpleName name_; + }; + + typedef + StrictPtr<OperationParameter> + OperationParameterPtr; + + //@@ Strip Ptr from *List, *Set, etc? + typedef + std::vector<OperationParameterPtr> + OperationParameterList; + + + // + // + // + class OperationDecl : public virtual Declaration + { + public: + virtual + ~OperationDecl () throw () {} + + OperationDecl (SimpleName const& name, + ScopedName const& type, + ScopePtr const& scope) + : Declaration (name, scope), + type_ (scope->table (), type) + + { + } + + public: + TypeDeclPtr + type () + { + return type_.resolve (); + } + + public: + typedef + OperationParameterList::const_iterator + Iterator; + + void + insert (OperationParameterPtr op) + { + //@@ would be nice to have some checking here + // list should probably be a set(by name) + parameter_list_.push_back (op); + } + + //@@ It's probably a good idea to stript prefixes from + // functions like inherits_begin, etc where there is + // no ambiguity. Ambiguity can come from Scope member function. + Iterator + begin () + { + return parameter_list_.begin (); + } + + Iterator + end () + { + return parameter_list_.end (); + } + + // Runtime declaration type information + public: + virtual std::string + declaration_type () + { + return "operation"; + } + + // Traversal + public: + virtual void + accept (CCF::Traversal::Visitor* v); + + private: + TypeDeclRef type_; + OperationParameterList parameter_list_; + }; + + typedef + StrictPtr<OperationDecl> + OperationDeclPtr; + + + // + // Module + // + class Module : public virtual Scope + { + public: + virtual + ~Module () throw () {} + + Module (SimpleName const& name, ScopePtr const& scope) + : Declaration (name, scope), + Scope (name, scope) + { + } + + // Runtime declaration type information + public: + virtual std::string + declaration_type () + { + return "module"; + } + + // Traversal + public: + virtual void + accept (CCF::Traversal::Visitor* v); + }; + typedef + StrictPtr<Module> + ModulePtr; + + // + // + // + class FileScope : public virtual Scope + { + public: + virtual + ~FileScope () throw () {} + + FileScope (DeclarationTable& table, Order const& order); + + virtual ScopePtr + scope () const throw (NotInScope) + { + throw NotInScope (); + } + + // Runtime declaration type information + public: + virtual std::string + declaration_type () + { + return "file scope"; + } + + // Traversal + public: + virtual void + accept (CCF::Traversal::Visitor* v); + }; + + typedef + StrictPtr<FileScope> + FileScopePtr; + + typedef + DeclarationOrderComparator<FileScopePtr> + FileScopeOrderComparator; + + typedef + std::set<FileScopePtr, FileScopeOrderComparator> + FileScopeSet; + + + // + // + // + class TranslationRegion; + + typedef + StrictPtr<TranslationRegion> + TranslationRegionPtr; + + typedef + std::vector<TranslationRegionPtr> + TranslationRegionList; + + class TranslationRegion : public virtual Node + { + public: + virtual + ~TranslationRegion () throw () {} + + TranslationRegion (DeclarationTable& table, + Order const& order) + : order_ (order), + table_ (table), + next_order_ (0) + { + scope_ = FileScopePtr (new FileScope (table_, Order (order_, 1))); + + //@@ eh! + table.insert (scope_); + } + + public: + DeclarationTable const& + table () const + { + return table_; + } + + DeclarationTable& + table () + { + return table_; + } + + public: + Order + create_order () + { + return Order (Order (order_, 0), next_order_++); + } + + public: + FileScopePtr + scope () + { + return scope_; + } + + public: + class InvalidArgument {}; + + void + insert (TranslationRegionPtr const& tr) throw (InvalidArgument); + + typedef + TranslationRegionList::const_iterator + Iterator; + + Iterator + begin () const; + + Iterator + end () const; + + private: + Order order_; + FileScopePtr scope_; + DeclarationTable& table_; + unsigned long next_order_; + TranslationRegionList region_list_; + + // Traversal + public: + virtual void + accept (CCF::Traversal::Visitor* v); + }; + + + // + // + // + class IncludeTranslationRegion : public virtual TranslationRegion + { + public: + virtual + ~IncludeTranslationRegion () throw () {} + + IncludeTranslationRegion (fs::path const& file_path, + DeclarationTable& table, + Order const& order) + : TranslationRegion (table, order), + file_path_ (file_path) + { + } + + public: + fs::path file_path () const + { + return file_path_; + } + + // Traversal + public: + virtual void + accept (CCF::Traversal::Visitor* v); + + private: + fs::path file_path_; + }; + typedef + StrictPtr<IncludeTranslationRegion> + IncludeTranslationRegionPtr; + + // + // + // + class SysIncludeTranslationRegion : public virtual TranslationRegion + { + public: + virtual + ~SysIncludeTranslationRegion () throw () {} + + SysIncludeTranslationRegion (fs::path const& file_path, + DeclarationTable& table, + Order const& order) + : TranslationRegion (table, order), + file_path_ (file_path) + { + } + + public: + fs::path file_path () const + { + return file_path_; + } + + // Traversal + public: + virtual void + accept (CCF::Traversal::Visitor* v); + + private: + fs::path file_path_; + }; + typedef + StrictPtr<SysIncludeTranslationRegion> + SysIncludeTranslationRegionPtr; + + // + // + // + class ImpliedIncludeTranslationRegion : public virtual TranslationRegion + { + public: + virtual + ~ImpliedIncludeTranslationRegion () throw () {} + + ImpliedIncludeTranslationRegion (fs::path const& file_path, + DeclarationTable& table, + Order const& order) + : TranslationRegion (table, order), + file_path_ (file_path) + { + } + + public: + fs::path file_path () const + { + return file_path_; + } + + // Traversal + public: + virtual void + accept (CCF::Traversal::Visitor* v); + + private: + fs::path file_path_; + }; + typedef + StrictPtr<ImpliedIncludeTranslationRegion> + ImpliedIncludeTranslationRegionPtr; + + + // + // + // + class PrincipalTranslationRegion : public virtual TranslationRegion + { + public: + virtual + ~PrincipalTranslationRegion () throw () {} + + PrincipalTranslationRegion (fs::path const& file_path, + DeclarationTable& table, + Order const& order) + : TranslationRegion (table, order), + file_path_ (file_path) + { + } + + public: + fs::path file_path () const + { + return file_path_; + } + + // Traversal + public: + virtual void + accept (CCF::Traversal::Visitor* v); + + private: + fs::path file_path_; + }; + typedef + StrictPtr<PrincipalTranslationRegion> + PrincipalTranslationRegionPtr; + + + //@@ TranslationUnit should not contain FileScope or should it? + //@@ Seems not + // + // + class TranslationUnit : public virtual Node + { + public: + virtual + ~TranslationUnit () throw () {} + + TranslationUnit () + : order_ (0), + next_order_ (0) + { + } + + public: + + DeclarationTable const& + table () const + { + return table_; + } + + DeclarationTable& + table () + { + return table_; + } + + public: + Order + create_order () + { + return Order (order_, next_order_++); + } + + public: + class InvalidArgument {}; + + void + insert (TranslationRegionPtr const& tr) throw (InvalidArgument); + + typedef + TranslationRegionList::const_iterator + Iterator; + + Iterator + begin () const; + + Iterator + end () const; + + + class NotFound {}; + + PrincipalTranslationRegionPtr + principal_translation_region () const throw (NotFound) + { + for (Iterator i = begin (); i != end (); i++) + { + if ((*i)->is_a<PrincipalTranslationRegion> ()) + { + return (*i)->dynamic_type<PrincipalTranslationRegion> (); + } + } + + throw NotFound (); + } + + private: + Order order_; + DeclarationTable table_; + unsigned long next_order_; + TranslationRegionList region_list_; + + // Traversal + public: + virtual void + accept (CCF::Traversal::Visitor* v); + }; + + typedef + StrictPtr<TranslationUnit> + TranslationUnitPtr; + } +} + +//@@ tmp +#include "CCF/IDL2/IDL2_SyntaxTree_BuiltIn.hpp" +#include "CCF/IDL2/IDL2_SyntaxTree_Value.hpp" + +#include "CCF/IDL2/IDL2_SyntaxTree.tpp" + +#endif // CCF_IDL2_SYNTAX_TREE_HPP diff --git a/TAO/CIAO/CCF/CCF/IDL2/IDL2_SyntaxTree.tpp b/TAO/CIAO/CCF/CCF/IDL2/IDL2_SyntaxTree.tpp new file mode 100644 index 00000000000..1c1953b9649 --- /dev/null +++ b/TAO/CIAO/CCF/CCF/IDL2/IDL2_SyntaxTree.tpp @@ -0,0 +1,126 @@ +namespace IDL2 +{ + namespace SyntaxTree + { + + // + // DeclarationRef + // + template <typename T, typename Ptr> + DeclarationRef<T, Ptr>:: + DeclarationRef (DeclarationTable const& table, ScopedName const& name) + : table_ (table), + name_ (name), + order_ (0), + initialized_ (true), + with_order_ (false) + { + } + + template <typename T, typename Ptr> + DeclarationRef<T, Ptr>:: + DeclarationRef (DeclarationTable const& table, + ScopedName const& name, + Order const& order) + : table_ (table), + name_ (name), + order_ (order), + initialized_ (true), + with_order_ (true) + { + } + + template <typename T, typename Ptr> + DeclarationRef<T, Ptr>:: + DeclarationRef (DeclarationPtr decl) + : table_ (decl->scope ()->table ()), + name_ (decl->name ()), + order_ (decl->order ()), + initialized_ (true), + with_order_ (true) + { + } + + template <typename T, typename Ptr> + DeclarationRef<T, Ptr>:: + DeclarationRef (DeclarationTable const& table) + : table_ (table), + name_ (""), + order_ (0), + initialized_ (false), + with_order_ (false) + { + } + + template <typename T, typename Ptr> + Ptr DeclarationRef<T, Ptr>:: + resolve () const throw (NotInitialized, DeclarationNotFound, TypeMismatch) + { + if (!initialized_) throw NotInitialized (); + + try + { + //@@ gcc bug + return with_order_ + ? table_.template lookup<T> (name_, order_) + : table_.template lookup<T> (name_); + } + catch (DeclarationTable::TypeMismatch const&) + { + throw TypeMismatch (); + } + catch (DeclarationTable::DeclarationNotFound const&) + { + throw DeclarationNotFound (); + } + } + + // + // DeclarationTable + // + template <typename T> + StrictPtr<T> DeclarationTable:: + lookup (ScopedName const& n) const + throw (DeclarationNotFound, TypeMismatch) + { + IteratorPair pair = lookup (n); + + if (pair.first == pair.second) throw DeclarationNotFound (); + + for (; pair.first != pair.second; pair.first++) + { + DeclarationPtr d = (*pair.first); + + //@@ gcc bug + StrictPtr<T> p ((*pair.first)->template dynamic_type<T> ()); + + if (p != 0) return p; + } + + throw TypeMismatch (); + } + + + template <typename T> + StrictPtr<T> DeclarationTable:: + lookup (ScopedName const& n, Order const& o) const + throw (DeclarationNotFound, TypeMismatch) + { + IteratorPair pair = lookup (n); + + for (; pair.first != pair.second; pair.first++) + { + if ((*pair.first)->order () != o) continue; + + //@@ gcc bug + StrictPtr<T> p ((*pair.first)->template dynamic_type<T> ()); + + if (p != 0) return p; + + throw TypeMismatch (); + } + + throw DeclarationNotFound (); + } + } +} diff --git a/TAO/CIAO/CCF/CCF/IDL2/IDL2_SyntaxTreeFwd.hpp b/TAO/CIAO/CCF/CCF/IDL2/IDL2_SyntaxTreeFwd.hpp new file mode 100644 index 00000000000..12b6a183516 --- /dev/null +++ b/TAO/CIAO/CCF/CCF/IDL2/IDL2_SyntaxTreeFwd.hpp @@ -0,0 +1,162 @@ +// $Id$ +#ifndef CCF_IDL2_SYNTAX_TREE_FWD_HPP +#define CCF_IDL2_SYNTAX_TREE_FWD_HPP + +#include "MSVC_Pragmas.hpp" + +#include "CCF/CompilerElements/ReferenceCounting.hpp" + +namespace IDL2 +{ + namespace SyntaxTree + { + using ReferenceCounting::StrictPtr; + + class Comma; + typedef + StrictPtr<Comma> + CommaPtr; + + class Declaration; + typedef + StrictPtr<Declaration> + DeclarationPtr; + + class TypeDecl; + typedef + StrictPtr<TypeDecl> + TypeDeclPtr; + + class TypeDef; + typedef + StrictPtr<TypeDef> + TypeDefPtr; + + class BuiltInTypeDef; + typedef + StrictPtr<BuiltInTypeDef> + BuiltInTypeDefPtr; + + class Void; + typedef + StrictPtr<Void> + VoidPtr; + + class Long; + typedef + StrictPtr<Long> + LongPtr; + + class Boolean; + typedef + StrictPtr<Boolean> + BooleanPtr; + + class String; + typedef + StrictPtr<String> + StringPtr; + + class Scope; + typedef + StrictPtr<Scope> + ScopePtr; + + class Module; + typedef + StrictPtr<Module> + ModulePtr; + + class InterfaceDecl; + typedef + StrictPtr<InterfaceDecl> + InterfaceDeclPtr; + + class InterfaceDef; + typedef + StrictPtr<InterfaceDef> + InterfaceDefPtr; + + class AbstractInterfaceDecl; + typedef + StrictPtr<AbstractInterfaceDecl> + AbstractInterfaceDeclPtr; + + class AbstractInterfaceDef; + typedef + StrictPtr<AbstractInterfaceDef> + AbstractInterfaceDefPtr; + + class LocalInterfaceDecl; + typedef + StrictPtr<LocalInterfaceDecl> + LocalInterfaceDeclPtr; + + class LocalInterfaceDef; + typedef + StrictPtr<LocalInterfaceDef> + LocalInterfaceDefPtr; + + class UnconstrainedInterfaceDecl; + typedef + StrictPtr<UnconstrainedInterfaceDecl> + UnconstrainedInterfaceDeclPtr; + + class UnconstrainedInterfaceDef; + typedef + StrictPtr<UnconstrainedInterfaceDef> + UnconstrainedInterfaceDefPtr; + + class AttributeDecl; + typedef + StrictPtr<AttributeDecl> + AttributeDeclPtr; + + class OperationParameter; + typedef + StrictPtr<OperationParameter> + OperationParameterPtr; + + class OperationDecl; + typedef + StrictPtr<OperationDecl> + OperationDeclPtr; + + class FileScope; + typedef + StrictPtr<FileScope> + FileScopePtr; + + class TranslationRegion; + typedef + StrictPtr<TranslationRegion> + TranslationRegionPtr; + + class IncludeTranslationRegion; + typedef + StrictPtr<IncludeTranslationRegion> + IncludeTranslationRegionPtr; + + class SysIncludeTranslationRegion; + typedef + StrictPtr<SysIncludeTranslationRegion> + SysIncludeTranslationRegionPtr; + + class ImpliedIncludeTranslationRegion; + typedef + StrictPtr<ImpliedIncludeTranslationRegion> + ImpliedIncludeTranslationRegionPtr; + + class PrincipalTranslationRegion; + typedef + StrictPtr<PrincipalTranslationRegion> + PrincipalTranslationRegionPtr; + + class TranslationUnit; + typedef + StrictPtr<TranslationUnit> + TranslationUnitPtr; + } +} + +#endif // CCF_IDL2_SYNTAX_TREE_FWD_HPP diff --git a/TAO/CIAO/CCF/CCF/IDL2/IDL2_SyntaxTree_BuiltIn.cpp b/TAO/CIAO/CCF/CCF/IDL2/IDL2_SyntaxTree_BuiltIn.cpp new file mode 100644 index 00000000000..f1ea69edb59 --- /dev/null +++ b/TAO/CIAO/CCF/CCF/IDL2/IDL2_SyntaxTree_BuiltIn.cpp @@ -0,0 +1,99 @@ +// $Id$ +#include "IDL2_SyntaxTree_BuiltIn.hpp" + +#include "IDL2_Traversal.hpp" + +namespace IDL2 +{ + namespace SyntaxTree + { + using ReferenceCounting::StrictPtr; + using CCF::Traversal::try_visit; + + // + // BuiltInTypeDef + // + + void BuiltInTypeDef:: + accept (CCF::Traversal::Visitor* v) + { + BuiltInTypeDefPtr self (ReferenceCounting::add_ref (this)); + + if(!try_visit<Traversal::BuiltInTypeDef> (&Traversal::BuiltInTypeDef::visit_built_in_type_def, + v, + self)) + { + TypeDef::accept (v); + } + } + + + // + // Void + // + + void Void:: + accept (CCF::Traversal::Visitor* v) + { + VoidPtr self (ReferenceCounting::add_ref (this)); + + if(!try_visit<Traversal::Void> (&Traversal::Void::visit_void, + v, + self)) + { + BuiltInTypeDef::accept (v); + } + } + + // + // Long + // + + void Long:: + accept (CCF::Traversal::Visitor* v) + { + LongPtr self (ReferenceCounting::add_ref (this)); + + if(!try_visit<Traversal::Long> (&Traversal::Long::visit_long, + v, + self)) + { + BuiltInTypeDef::accept (v); + } + } + + // + // Boolean + // + + void Boolean:: + accept (CCF::Traversal::Visitor* v) + { + BooleanPtr self (ReferenceCounting::add_ref (this)); + + if(!try_visit<Traversal::Boolean> (&Traversal::Boolean::visit_boolean, + v, + self)) + { + BuiltInTypeDef::accept (v); + } + } + + // + // String + // + + void String:: + accept (CCF::Traversal::Visitor* v) + { + StringPtr self (ReferenceCounting::add_ref (this)); + + if(!try_visit<Traversal::String> (&Traversal::String::visit_string, + v, + self)) + { + BuiltInTypeDef::accept (v); + } + } + } +} diff --git a/TAO/CIAO/CCF/CCF/IDL2/IDL2_SyntaxTree_BuiltIn.hpp b/TAO/CIAO/CCF/CCF/IDL2/IDL2_SyntaxTree_BuiltIn.hpp new file mode 100644 index 00000000000..63ea6290a78 --- /dev/null +++ b/TAO/CIAO/CCF/CCF/IDL2/IDL2_SyntaxTree_BuiltIn.hpp @@ -0,0 +1,200 @@ +// $Id$ +#ifndef CCF_IDL2_SYNTAX_TREE_BUILT_IN_HPP +#define CCF_IDL2_SYNTAX_TREE_BUILT_IN_HPP + +#include "MSVC_Pragmas.hpp" + +#include "CCF/IDL2/IDL2_SyntaxTree.hpp" + +namespace IDL2 +{ + namespace SyntaxTree + { + + //@@ I have a potential problem with two-word built-in types + // e.g. unsigned long. Though I don't see anything bad in + // allowing (internally) for names to contain spaces e.g. + // '::unsigned long'. I will also have to teach LexicalAnalyzer + // to parse this stuff properly. + // + + // + // + // + class BuiltInTypeDef : public virtual TypeDef + { + protected: + virtual + ~BuiltInTypeDef () throw () {} + + BuiltInTypeDef (SimpleName const& name, + ScopePtr const& scope) + : Declaration (name, scope), + TypeDecl (name, scope), + TypeDef (name, scope) + { + } + + // Runtime declaration type information + public: + virtual std::string + declaration_type () + { + return "built-in type"; + } + + // Traversal + public: + virtual void + accept (CCF::Traversal::Visitor* v); + }; + + typedef + StrictPtr<BuiltInTypeDef> + BuiltInTypeDefPtr; + + + // + // + // + class Void : public virtual BuiltInTypeDef + { + public: + virtual + ~Void () throw () {} + + Void (ScopePtr const& scope) + : Declaration (SimpleName ("void"), scope), + TypeDecl (SimpleName ("void"), scope), + TypeDef (SimpleName ("void"), scope), + BuiltInTypeDef (SimpleName ("void"), scope) + { + } + + // Runtime declaration type information + public: + virtual std::string + declaration_type () + { + return "built-in type void"; + } + + // Traversal + public: + virtual void + accept (CCF::Traversal::Visitor* v); + }; + + typedef + StrictPtr<Void> + VoidPtr; + + // + // + // + class Long : public virtual BuiltInTypeDef + { + public: + virtual + ~Long () throw () {} + + Long (ScopePtr const& scope) + : Declaration (SimpleName ("long"), scope), + TypeDecl (SimpleName ("long"), scope), + TypeDef (SimpleName ("long"), scope), + BuiltInTypeDef (SimpleName ("long"), scope) + { + } + + // Runtime declaration type information + public: + virtual std::string + declaration_type () + { + return "built-in type long"; + } + + // Traversal + public: + virtual void + accept (CCF::Traversal::Visitor* v); + }; + + typedef + StrictPtr<Long> + LongPtr; + + // + // + // + class Boolean : public virtual BuiltInTypeDef + { + public: + virtual + ~Boolean () throw () {} + + Boolean (ScopePtr const& scope) + : Declaration (SimpleName ("boolean"), scope), + TypeDecl (SimpleName ("boolean"), scope), + TypeDef (SimpleName ("boolean"), scope), + BuiltInTypeDef (SimpleName ("boolean"), scope) + { + } + + // Runtime declaration type information + public: + virtual std::string + declaration_type () + { + return "built-in type boolean"; + } + + // Traversal + public: + virtual void + accept (CCF::Traversal::Visitor* v); + }; + + typedef + StrictPtr<Boolean> + BooleanPtr; + + + // + // + // + class String : public virtual BuiltInTypeDef + { + public: + virtual + ~String () throw () {} + + String (ScopePtr const& scope) + : Declaration (SimpleName ("string"), scope), + TypeDecl (SimpleName ("string"), scope), + TypeDef (SimpleName ("string"), scope), + BuiltInTypeDef (SimpleName ("string"), scope) + { + } + + // Runtime declaration type information + public: + virtual std::string + declaration_type () + { + return "built-in type string"; + } + + // Traversal + public: + virtual void + accept (CCF::Traversal::Visitor* v); + }; + + typedef + StrictPtr<String> + StringPtr; + } +} + +#endif // CCF_IDL2_SYNTAX_TREE_BUILT_IN_HPP diff --git a/TAO/CIAO/CCF/CCF/IDL2/IDL2_SyntaxTree_Value.hpp b/TAO/CIAO/CCF/CCF/IDL2/IDL2_SyntaxTree_Value.hpp new file mode 100644 index 00000000000..1b8d4399fcd --- /dev/null +++ b/TAO/CIAO/CCF/CCF/IDL2/IDL2_SyntaxTree_Value.hpp @@ -0,0 +1,190 @@ +// $Id$ +#ifndef CCF_IDL2_SYNTAX_TREE_VALUE_HPP +#define CCF_IDL2_SYNTAX_TREE_VALUE_HPP + +#include "MSVC_Pragmas.hpp" + +#include "CCF/IDL2/IDL2_SyntaxTree.hpp" + +namespace IDL2 +{ + namespace SyntaxTree + { + // + // + // + class ValueDecl : public virtual TypeDecl + { + public: + virtual + ~ValueDecl () throw () {} + + ValueDecl (SimpleName const& name, + ScopePtr const& scope) + : Declaration (name, scope), + TypeDecl (name, scope) + { + } + + // Runtime declaration type information + public: + virtual std::string + declaration_type () + { + return "value"; + } + + + // Traversal + public: + virtual void + accept (CCF::Traversal::Visitor* v) + { + } + + }; + + typedef + StrictPtr<ValueDecl> + ValueDeclPtr; + + typedef + DeclarationOrderComparator<ValueDeclPtr> + ValueDeclOrderComparator; + + typedef + std::set<ValueDeclPtr, ValueDeclOrderComparator> + ValueDeclSet; + + typedef + DeclarationRef<ValueDecl> + ValueDeclRef; + + typedef + DeclarationRefOrderComparator<ValueDeclRef> + ValueDeclRefOrderComparator; + + typedef + std::set<ValueDeclRef, ValueDeclRefOrderComparator> + ValueDeclRefSet; + + + // + // + // + class ValueForwardDecl : public virtual ValueDecl, + public virtual TypeForwardDecl + { + public: + virtual + ~ValueForwardDecl () throw () {} + + ValueForwardDecl (SimpleName const& name, + ScopePtr const& scope) + : Declaration (name, scope), + TypeDecl (name, scope), + ValueDecl (name, scope), + TypeForwardDecl (name, scope) + { + } + + // Runtime declaration type information + public: + virtual std::string + declaration_type () + { + return "value"; + } + }; + + // + // + // + class ValueDef; + + typedef + StrictPtr<ValueDef> + ValueDefPtr; + + typedef + DeclarationRef<ValueDef> + ValueDefRef; + + typedef + DeclarationRefNameComparator<ValueDefRef> + ValueDefRefNameComparator; + + typedef + std::set<ValueDefRef, ValueDefRefNameComparator> + ValueDefRefSetName; + + class ValueDef : public virtual ValueDecl, + public virtual TypeDef, + public virtual Scope + { + public: + virtual + ~ValueDef () throw () {} + + class DuplicateName {}; + + ValueDef (SimpleName const& name, + ScopePtr const& scope, + ScopedNameSet const& inherits) throw (DuplicateName) + : Declaration (name, scope), + TypeDecl (name, scope), + ValueDecl (name, scope), + TypeDef (name, scope), + Scope (name, scope) + { + for (ScopedNameSet::const_iterator i = inherits.begin (); + i != inherits.end (); + i++) + { + if (!inherits_.insert (ValueDefRef (scope->table (), *i)).second) + { + //@@ this never happens + throw DuplicateName (); + } + } + } + + // Runtime declaration type information + public: + virtual std::string + declaration_type () + { + return "value"; + } + + // Traversal + public: + virtual void + accept (CCF::Traversal::Visitor* v) + { + } + + + private: + ValueDefRefSetName inherits_; + }; + + typedef + DeclarationOrderComparator<ValueDefPtr> + ValueDefOrderComparator; + + typedef + std::set<ValueDefPtr, ValueDefOrderComparator> + ValueDefSet; + + typedef + DeclarationRefOrderComparator<ValueDefRef> + ValueDefRefOrderComparator; + + typedef + std::set<ValueDefRef, ValueDefRefOrderComparator> + ValueDefRefSet; + } +} + +#endif // CCF_IDL2_SYNTAX_TREE_VALUE_HPP diff --git a/TAO/CIAO/CCF/CCF/IDL2/IDL2_Traversal.cpp b/TAO/CIAO/CCF/CCF/IDL2/IDL2_Traversal.cpp new file mode 100644 index 00000000000..08bff63ed2d --- /dev/null +++ b/TAO/CIAO/CCF/CCF/IDL2/IDL2_Traversal.cpp @@ -0,0 +1,608 @@ +// $Id$ +#include "IDL2_Traversal.hpp" +#include "IDL2_SyntaxTree.hpp" + +namespace IDL2 +{ + namespace Traversal + { + namespace + { + void + iterate_scope (SyntaxTree::ScopePtr const& s, + CCF::Traversal::Visitor* v) + { + for (SyntaxTree::Scope::Iterator i = s->begin (); i != s->end (); i++) + { + (*i)->accept (v); + } + } + } + + + // + // Scope + // + + void Scope:: + visit_scope (NodePtr const& s) + { + visit_scope_pre (s); + visit_scope_scope (s); + visit_scope_post (s); + } + + void Scope:: + visit_scope_scope (NodePtr const& s) + { + iterate_scope (s, this); + } + + + // + // Module + // + + void Module:: + visit_module (NodePtr const& m) + { + visit_module_pre (m); + visit_module_scope (m); + visit_module_post (m); + } + + void Module:: + visit_module_pre (NodePtr const& m) + { + } + + void Module:: + visit_module_scope (NodePtr const& m) + { + iterate_scope (m, this); + } + + void Module:: + visit_module_post (NodePtr const& m) + { + } + + // + // InterfaceDecl + // + + void InterfaceDecl:: + visit_interface_decl (NodePtr const& i) + { + visit_interface_decl_pre (i); + visit_interface_decl_post (i); + } + + void InterfaceDecl:: + visit_interface_decl_pre (NodePtr const&) + { + } + + void InterfaceDecl:: + visit_interface_decl_post (NodePtr const&) + { + } + + + // + // InterfaceDef + // + + void InterfaceDef:: + visit_interface_def (NodePtr const& i) + { + visit_interface_def_pre (i); + visit_interface_def_scope (i); + visit_interface_def_post (i); + } + + void InterfaceDef:: + visit_interface_def_pre (NodePtr const&) + { + } + + void InterfaceDef:: + visit_interface_def_scope (NodePtr const& i) + { + iterate_scope (i, this); + } + + void InterfaceDef:: + visit_interface_def_post (NodePtr const&) + { + } + + // + // AbstractInterfaceDecl + // + + void AbstractInterfaceDecl:: + visit_abstract_interface_decl (NodePtr const& i) + { + visit_abstract_interface_decl_pre (i); + visit_abstract_interface_decl_post (i); + } + + void AbstractInterfaceDecl:: + visit_abstract_interface_decl_pre (NodePtr const&) + { + } + + void AbstractInterfaceDecl:: + visit_abstract_interface_decl_post (NodePtr const&) + { + } + + + // + // AbstractInterfaceDef + // + + void AbstractInterfaceDef:: + visit_abstract_interface_def (NodePtr const& i) + { + visit_abstract_interface_def_pre (i); + visit_abstract_interface_def_scope (i); + visit_abstract_interface_def_post (i); + } + + void AbstractInterfaceDef:: + visit_abstract_interface_def_pre (NodePtr const&) + { + } + + void AbstractInterfaceDef:: + visit_abstract_interface_def_scope (NodePtr const& i) + { + iterate_scope (i, this); + } + + void AbstractInterfaceDef:: + visit_abstract_interface_def_post (NodePtr const&) + { + } + + // + // LocalInterfaceDecl + // + + void LocalInterfaceDecl:: + visit_local_interface_decl (NodePtr const& i) + { + visit_local_interface_decl_pre (i); + visit_local_interface_decl_post (i); + } + + void LocalInterfaceDecl:: + visit_local_interface_decl_pre (NodePtr const&) + { + } + + void LocalInterfaceDecl:: + visit_local_interface_decl_post (NodePtr const&) + { + } + + + // + // LocalInterfaceDef + // + + void LocalInterfaceDef:: + visit_local_interface_def (NodePtr const& i) + { + visit_local_interface_def_pre (i); + visit_local_interface_def_scope (i); + visit_local_interface_def_post (i); + } + + void LocalInterfaceDef:: + visit_local_interface_def_pre (NodePtr const&) + { + } + + void LocalInterfaceDef:: + visit_local_interface_def_scope (NodePtr const& i) + { + iterate_scope (i, this); + } + + void LocalInterfaceDef:: + visit_local_interface_def_post (NodePtr const&) + { + } + + // + // UnconstrainedInterfaceDecl + // + + void UnconstrainedInterfaceDecl:: + visit_unconstrained_interface_decl (NodePtr const& i) + { + visit_unconstrained_interface_decl_pre (i); + visit_unconstrained_interface_decl_post (i); + } + + void UnconstrainedInterfaceDecl:: + visit_unconstrained_interface_decl_pre (NodePtr const&) + { + } + + void UnconstrainedInterfaceDecl:: + visit_unconstrained_interface_decl_post (NodePtr const&) + { + } + + + // + // UnconstrainedInterfaceDef + // + + void UnconstrainedInterfaceDef:: + visit_unconstrained_interface_def (NodePtr const& i) + { + visit_unconstrained_interface_def_pre (i); + visit_unconstrained_interface_def_scope (i); + visit_unconstrained_interface_def_post (i); + } + + void UnconstrainedInterfaceDef:: + visit_unconstrained_interface_def_pre (NodePtr const&) + { + } + + void UnconstrainedInterfaceDef:: + visit_unconstrained_interface_def_scope (NodePtr const& i) + { + iterate_scope (i, this); + } + + void UnconstrainedInterfaceDef:: + visit_unconstrained_interface_def_post (NodePtr const&) + { + } + + // + // + // + + void AttributeDecl:: + visit_attribute_decl (NodePtr const& n) + { + visit_attribute_pre (n); + + if (type_) n->type ()->accept (type_); + else n->type ()->accept (this); + + visit_attribute_post (n); + } + + + void AttributeDecl:: + visit_attribute_pre (NodePtr const& n) + { + } + + void AttributeDecl:: + visit_attribute_post (NodePtr const& n) + { + } + + + // + // OperationParameter + // + void OperationParameter:: + visit_operation_parameter (NodePtr const& op) + { + visit_operation_parameter_pre (op); + + CCF::Traversal::Visitor* v = this; + + switch (op->direction ()) + { + case SyntaxTree::OperationParameter::Direction::IN: + { + if (in_) v = in_; + break; + } + case SyntaxTree::OperationParameter::Direction::OUT: + { + if (out_) v = out_; + break; + } + case SyntaxTree::OperationParameter::Direction::INOUT: + { + if (inout_) v = inout_; + break; + } + } + + op->type ()->accept (v); + + visit_operation_parameter_post (op); + } + + // + // OperationDecl + // + + void OperationDecl:: + visit_operation_decl (NodePtr const& n) + { + visit_operation_decl_pre (n); + visit_operation_decl_type (n); + visit_operation_decl_name (n); + visit_operation_decl_parameters (n); + visit_operation_decl_post (n); + } + + void OperationDecl:: + visit_operation_decl_pre (NodePtr const& n) + { + } + + void OperationDecl:: + visit_operation_decl_type (NodePtr const& n) + { + if (type_) n->type ()->accept (type_); + else n->type ()->accept (this); + } + + void OperationDecl:: + visit_operation_decl_name (NodePtr const& n) + { + } + + void OperationDecl:: + visit_operation_decl_parameters (NodePtr const& n) + { + for (SyntaxTree::OperationDecl::Iterator i = n->begin (); + i != n->end (); + i++) + { + (*i)->accept (this); + + if (i + 1 != n->end ()) + { + //@@ could be OperationParameterComma + SyntaxTree::CommaPtr c (new SyntaxTree::Comma); + c->accept (this); + } + } + } + + void OperationDecl:: + visit_operation_decl_post (NodePtr const& n) + { + } + + // + // FileScope + // + + void FileScope:: + visit_file_scope (NodePtr const& fs) + { + visit_file_scope_pre (fs); + visit_file_scope_scope (fs); + visit_file_scope_post (fs); + } + + void FileScope:: + visit_file_scope_pre (NodePtr const& fs) + { + } + + void FileScope:: + visit_file_scope_scope (NodePtr const& fs) + { + iterate_scope (fs, this); + } + + void FileScope:: + visit_file_scope_post (NodePtr const& fs) + { + } + + // + // TranslationRegion + // + + namespace + { + void + iterate_translation_region (SyntaxTree::TranslationRegionPtr const& tr, + CCF::Traversal::Visitor* v) + { + // visit nested translation regions + for (SyntaxTree::TranslationRegion::Iterator i = tr->begin (); + i != tr->end (); + i++) + { + (*i)->accept (v); + } + + // visit associated scope + tr->scope ()->accept (v); + } + } + + + void TranslationRegion:: + visit_translation_region (NodePtr const& n) + { + visit_translation_region_pre (n); + visit_translation_region_content (n); + visit_translation_region_post (n); + } + + void TranslationRegion:: + visit_translation_region_pre (NodePtr const& n) + { + iterate_translation_region (n, this); + } + + void TranslationRegion:: + visit_translation_region_content (NodePtr const& n) + { + } + + void TranslationRegion:: + visit_translation_region_post (NodePtr const& n) + { + } + + // + // IncludeTranslationRegion + // + + void IncludeTranslationRegion:: + visit_include_translation_region (NodePtr const& n) + { + visit_include_translation_region_pre (n); + visit_include_translation_region_content (n); + visit_include_translation_region_post (n); + } + + void IncludeTranslationRegion:: + visit_include_translation_region_pre (NodePtr const& n) + { + iterate_translation_region (n, this); + } + + void IncludeTranslationRegion:: + visit_include_translation_region_content (NodePtr const& n) + { + } + + void IncludeTranslationRegion:: + visit_include_translation_region_post (NodePtr const& n) + { + } + + // + // SysIncludeTranslationRegion + // + + void SysIncludeTranslationRegion:: + visit_sys_include_translation_region (NodePtr const& n) + { + visit_sys_include_translation_region_pre (n); + visit_sys_include_translation_region_content (n); + visit_sys_include_translation_region_post (n); + } + + void SysIncludeTranslationRegion:: + visit_sys_include_translation_region_pre (NodePtr const& n) + { + iterate_translation_region (n, this); + } + + void SysIncludeTranslationRegion:: + visit_sys_include_translation_region_content (NodePtr const& n) + { + } + + void SysIncludeTranslationRegion:: + visit_sys_include_translation_region_post (NodePtr const& n) + { + } + + // + // ImpliedIncludeTranslationRegion + // + + void ImpliedIncludeTranslationRegion:: + visit_implied_include_translation_region (NodePtr const& n) + { + visit_implied_include_translation_region_pre (n); + visit_implied_include_translation_region_content (n); + visit_implied_include_translation_region_post (n); + } + + void ImpliedIncludeTranslationRegion:: + visit_implied_include_translation_region_pre (NodePtr const& n) + { + iterate_translation_region (n, this); + } + + void ImpliedIncludeTranslationRegion:: + visit_implied_include_translation_region_content (NodePtr const& n) + { + } + + void ImpliedIncludeTranslationRegion:: + visit_implied_include_translation_region_post (NodePtr const& n) + { + } + + + // + // PrincipalTranslationRegion + // + + void PrincipalTranslationRegion:: + visit_principal_translation_region (NodePtr const& n) + { + visit_principal_translation_region_pre (n); + visit_principal_translation_region_content (n); + visit_principal_translation_region_post (n); + } + + void PrincipalTranslationRegion:: + visit_principal_translation_region_pre (NodePtr const& n) + { + iterate_translation_region (n, this); + } + + void PrincipalTranslationRegion:: + visit_principal_translation_region_content (NodePtr const& n) + { + } + + void PrincipalTranslationRegion:: + visit_principal_translation_region_post (NodePtr const& n) + { + } + + // + // TranslationUnit + // + + void TranslationUnit:: + visit_translation_unit (NodePtr const& tu) + { + visit_translation_unit_pre (tu); + visit_translation_unit_content (tu); + visit_translation_unit_post (tu); + } + + void TranslationUnit:: + visit_translation_unit_pre (NodePtr const& tu) + { + } + + void TranslationUnit:: + visit_translation_unit_content (NodePtr const& tu) + { + // Visit nested translation regions + for (SyntaxTree::TranslationUnit::Iterator i = tu->begin (); + i != tu->end (); + i++) + { + (*i)->accept (this); + } + } + + void TranslationUnit:: + visit_translation_unit_post (NodePtr const& tu) + { + } + } +} diff --git a/TAO/CIAO/CCF/CCF/IDL2/IDL2_Traversal.hpp b/TAO/CIAO/CCF/CCF/IDL2/IDL2_Traversal.hpp new file mode 100644 index 00000000000..741a937a2d3 --- /dev/null +++ b/TAO/CIAO/CCF/CCF/IDL2/IDL2_Traversal.hpp @@ -0,0 +1,519 @@ +// $Id$ +#ifndef CCF_IDL2_TRAVERSAL_HPP +#define CCF_IDL2_TRAVERSAL_HPP + +#include "MSVC_Pragmas.hpp" + +#include "CCF/CompilerElements/Traversal.hpp" +#include "CCF/IDL2/IDL2_SyntaxTreeFwd.hpp" + +namespace IDL2 +{ + namespace Traversal + { + // + // + // + struct Comma : virtual CCF::Traversal::Visitor + { + typedef + SyntaxTree::CommaPtr + NodePtr; + + virtual void visit_comma (NodePtr const& s) + { + } + }; + + // + // + // + struct Declaration : virtual CCF::Traversal::Visitor + { + }; + + // + // + // + struct TypeDecl : virtual CCF::Traversal::Visitor + { + typedef + SyntaxTree::TypeDeclPtr + NodePtr; + + virtual void visit_type_decl (NodePtr const& n) + { + } + }; + + // + // + // + struct TypeDef : virtual CCF::Traversal::Visitor + { + typedef + SyntaxTree::TypeDefPtr + NodePtr; + + virtual void visit_type_def (NodePtr const& n) + { + } + }; + + // + // + // + struct BuiltInTypeDef : virtual CCF::Traversal::Visitor + { + typedef + SyntaxTree::BuiltInTypeDefPtr + NodePtr; + + virtual void visit_built_in_type_def (NodePtr const& n) + { + } + }; + + + // + // + // + struct Void : virtual CCF::Traversal::Visitor + { + typedef + SyntaxTree::VoidPtr + NodePtr; + + virtual void visit_void (NodePtr const& n) + { + } + }; + + // + // + // + struct Long : virtual CCF::Traversal::Visitor + { + typedef + SyntaxTree::LongPtr + NodePtr; + + virtual void visit_long (NodePtr const& n) + { + } + }; + + // + // + // + struct Boolean : virtual CCF::Traversal::Visitor + { + typedef + SyntaxTree::BooleanPtr + NodePtr; + + virtual void visit_boolean (NodePtr const& n) + { + } + }; + + // + // + // + struct String : virtual CCF::Traversal::Visitor + { + typedef + SyntaxTree::StringPtr + NodePtr; + + virtual void visit_string (NodePtr const& n) + { + } + }; + + // + // + // + struct Scope : virtual CCF::Traversal::Visitor + { + typedef + SyntaxTree::ScopePtr + NodePtr; + + // visit_scope () function will never be called because Scope is + // an abstract syntax tree node. It is here for symmetry. + virtual void visit_scope (NodePtr const& s); + virtual void visit_scope_scope (NodePtr const& s); + virtual void visit_scope_pre (NodePtr const& ) {} + virtual void visit_scope_post (NodePtr const& ) {} + }; + + // + // + // + struct Module : virtual CCF::Traversal::Visitor + { + typedef + SyntaxTree::ModulePtr + NodePtr; + + virtual void visit_module (NodePtr const& m); + virtual void visit_module_pre (NodePtr const& m); + virtual void visit_module_scope (NodePtr const& m); + virtual void visit_module_post (NodePtr const& m); + }; + + + // + // + // + struct InterfaceDecl : virtual CCF::Traversal::Visitor + { + typedef + SyntaxTree::InterfaceDeclPtr + NodePtr; + + virtual void visit_interface_decl (NodePtr const& i); + virtual void visit_interface_decl_pre (NodePtr const& i); + virtual void visit_interface_decl_post (NodePtr const& i); + }; + + + // + // + // + struct InterfaceDef : virtual CCF::Traversal::Visitor + { + typedef + SyntaxTree::InterfaceDefPtr + NodePtr; + + virtual void visit_interface_def (NodePtr const& i); + virtual void visit_interface_def_pre (NodePtr const& i); + virtual void visit_interface_def_scope (NodePtr const& i); + virtual void visit_interface_def_post (NodePtr const& i); + }; + + + // + // + // + struct AbstractInterfaceDecl : virtual CCF::Traversal::Visitor + { + typedef + SyntaxTree::AbstractInterfaceDeclPtr + NodePtr; + + virtual void visit_abstract_interface_decl (NodePtr const& i); + virtual void visit_abstract_interface_decl_pre (NodePtr const& i); + virtual void visit_abstract_interface_decl_post (NodePtr const& i); + }; + + + // + // + // + struct AbstractInterfaceDef : virtual CCF::Traversal::Visitor + { + typedef + SyntaxTree::AbstractInterfaceDefPtr + NodePtr; + + virtual void visit_abstract_interface_def (NodePtr const& i); + virtual void visit_abstract_interface_def_pre (NodePtr const& i); + virtual void visit_abstract_interface_def_scope (NodePtr const& i); + virtual void visit_abstract_interface_def_post (NodePtr const& i); + }; + + // + // + // + struct LocalInterfaceDecl : virtual CCF::Traversal::Visitor + { + typedef + SyntaxTree::LocalInterfaceDeclPtr + NodePtr; + + virtual void visit_local_interface_decl (NodePtr const& i); + virtual void visit_local_interface_decl_pre (NodePtr const& i); + virtual void visit_local_interface_decl_post (NodePtr const& i); + }; + + + // + // + // + struct LocalInterfaceDef : virtual CCF::Traversal::Visitor + { + typedef + SyntaxTree::LocalInterfaceDefPtr + NodePtr; + + virtual void visit_local_interface_def (NodePtr const& i); + virtual void visit_local_interface_def_pre (NodePtr const& i); + virtual void visit_local_interface_def_scope (NodePtr const& i); + virtual void visit_local_interface_def_post (NodePtr const& i); + }; + + + // + // + // + struct UnconstrainedInterfaceDecl : virtual CCF::Traversal::Visitor + { + typedef + SyntaxTree::UnconstrainedInterfaceDeclPtr + NodePtr; + + virtual void visit_unconstrained_interface_decl (NodePtr const& i); + virtual void visit_unconstrained_interface_decl_pre (NodePtr const& i); + virtual void visit_unconstrained_interface_decl_post (NodePtr const& i); + }; + + + // + // + // + struct UnconstrainedInterfaceDef : virtual CCF::Traversal::Visitor + { + typedef + SyntaxTree::UnconstrainedInterfaceDefPtr + NodePtr; + + virtual void visit_unconstrained_interface_def (NodePtr const& i); + virtual void visit_unconstrained_interface_def_pre (NodePtr const& i); + virtual void visit_unconstrained_interface_def_scope (NodePtr const& i); + virtual void visit_unconstrained_interface_def_post (NodePtr const& i); + }; + + + // + // + // + struct AttributeDecl : virtual CCF::Traversal::Visitor + { + typedef + SyntaxTree::AttributeDeclPtr + NodePtr; + + AttributeDecl (CCF::Traversal::Visitor* type = 0) + : type_ (type) + { + } + + virtual void visit_attribute_decl (NodePtr const& n); + virtual void visit_attribute_pre (NodePtr const& n); + virtual void visit_attribute_post (NodePtr const& n); + + private: + CCF::Traversal::Visitor* type_; + }; + + // + // + // + struct OperationParameter : virtual CCF::Traversal::Visitor + { + typedef + SyntaxTree::OperationParameterPtr + NodePtr; + + OperationParameter (CCF::Traversal::Visitor* in, + CCF::Traversal::Visitor* out, + CCF::Traversal::Visitor* inout) + : in_ (in), out_ (out), inout_ (inout) + { + } + + OperationParameter () + : in_ (0), out_ (0), inout_ (0) + { + } + + + virtual void visit_operation_parameter (NodePtr const& op); + + virtual void visit_operation_parameter_pre (NodePtr const&) + { + } + + virtual void visit_operation_parameter_post (NodePtr const&) + { + } + + private: + CCF::Traversal::Visitor* in_; + CCF::Traversal::Visitor* out_; + CCF::Traversal::Visitor* inout_; + }; + + // + // + // + struct OperationDecl : virtual CCF::Traversal::Visitor + { + typedef + SyntaxTree::OperationDeclPtr + NodePtr; + + OperationDecl (CCF::Traversal::Visitor* type = 0) + : type_ (type) + { + } + + + virtual void visit_operation_decl (NodePtr const& n); + + virtual void visit_operation_decl_pre (NodePtr const& n); + virtual void visit_operation_decl_type (NodePtr const& n); + virtual void visit_operation_decl_name (NodePtr const& n); + virtual void visit_operation_decl_parameters (NodePtr const& n); + virtual void visit_operation_decl_post (NodePtr const& n); + + private: + CCF::Traversal::Visitor* type_; + }; + + + + // + // + // + struct FileScope : virtual CCF::Traversal::Visitor + { + typedef + SyntaxTree::FileScopePtr + NodePtr; + + virtual void visit_file_scope (NodePtr const& r); + virtual void visit_file_scope_pre (NodePtr const& r); + virtual void visit_file_scope_scope (NodePtr const& r); + virtual void visit_file_scope_post (NodePtr const& r); + }; + + // + // + // + struct TranslationRegion : virtual CCF::Traversal::Visitor + { + typedef + SyntaxTree::TranslationRegionPtr + NodePtr; + + virtual void visit_translation_region (NodePtr const& tr); + virtual void visit_translation_region_pre (NodePtr const& tr); + virtual void visit_translation_region_content (NodePtr const& tr); + virtual void visit_translation_region_post (NodePtr const& tr); + }; + + + // + // + // + struct IncludeTranslationRegion : virtual CCF::Traversal::Visitor + { + typedef + SyntaxTree::IncludeTranslationRegionPtr + NodePtr; + + virtual void + visit_include_translation_region (NodePtr const& n); + + virtual void + visit_include_translation_region_pre (NodePtr const& n); + + virtual void + visit_include_translation_region_content (NodePtr const& n); + + virtual void + visit_include_translation_region_post (NodePtr const& n); + }; + + + // + // + // + struct SysIncludeTranslationRegion : virtual CCF::Traversal::Visitor + { + typedef + SyntaxTree::SysIncludeTranslationRegionPtr + NodePtr; + + virtual void + visit_sys_include_translation_region (NodePtr const& n); + + virtual void + visit_sys_include_translation_region_pre (NodePtr const& n); + + virtual void + visit_sys_include_translation_region_content (NodePtr const& n); + + virtual void + visit_sys_include_translation_region_post (NodePtr const& n); + }; + + + // + // + // + struct ImpliedIncludeTranslationRegion : virtual CCF::Traversal::Visitor + { + typedef + SyntaxTree::ImpliedIncludeTranslationRegionPtr + NodePtr; + + virtual void + visit_implied_include_translation_region (NodePtr const& n); + + virtual void + visit_implied_include_translation_region_pre (NodePtr const& n); + + virtual void + visit_implied_include_translation_region_content (NodePtr const& n); + + virtual void + visit_implied_include_translation_region_post (NodePtr const& n); + }; + + + // + // + // + struct PrincipalTranslationRegion : virtual CCF::Traversal::Visitor + { + typedef + SyntaxTree::PrincipalTranslationRegionPtr + NodePtr; + + virtual void + visit_principal_translation_region (NodePtr const& n); + + virtual void + visit_principal_translation_region_pre (NodePtr const& n); + + virtual void + visit_principal_translation_region_content (NodePtr const& n); + + virtual void + visit_principal_translation_region_post (NodePtr const& n); + }; + + + // + // + // + struct TranslationUnit : virtual CCF::Traversal::Visitor + { + typedef + SyntaxTree::TranslationUnitPtr + NodePtr; + + virtual void visit_translation_unit (NodePtr const& tu); + virtual void visit_translation_unit_pre (NodePtr const& tu); + virtual void visit_translation_unit_content (NodePtr const& tu); + virtual void visit_translation_unit_post (NodePtr const& tu); + }; + } +} + +#endif // CCF_IDL2_TRAVERSAL_HPP diff --git a/TAO/CIAO/CCF/CCF/IDL2/MSVC_Pragmas.hpp b/TAO/CIAO/CCF/CCF/IDL2/MSVC_Pragmas.hpp new file mode 100644 index 00000000000..724b5b52646 --- /dev/null +++ b/TAO/CIAO/CCF/CCF/IDL2/MSVC_Pragmas.hpp @@ -0,0 +1,16 @@ +// $Id$ +#ifndef MSVC_PRAGMAS_HPP +#define MSVC_PRAGMAS_HPP + + +// Various warnings that have to be disabled for MSVC. + +// 'this' : used in base member initializer list +#pragma warning(disable:4355) +// 'class1' : inherits 'class2::member' via dominance +#pragma warning(disable:4250) +// C++ Exception Specification ignored +#pragma warning(disable:4290) + + +#endif /* MSVC_PRAGMAS_HPP */
\ No newline at end of file diff --git a/TAO/CIAO/CCF/CCF/IDL2/Makefile b/TAO/CIAO/CCF/CCF/IDL2/Makefile new file mode 100644 index 00000000000..8783e8af049 --- /dev/null +++ b/TAO/CIAO/CCF/CCF/IDL2/Makefile @@ -0,0 +1,23 @@ +# File : Makefile +# Author : Boris Kolpackov <boris@kolpackov.net> +# $Id$ + +root = ../../External/Utility + +include $(root)/Config/Archive.pre.rules + +cxx_translation_units := IDL2.cpp \ + IDL2_LexicalAnalyzer.cpp \ + IDL2_SyntaxTree.cpp \ + IDL2_SyntaxTree_BuiltIn.cpp \ + IDL2_Traversal.cpp + +module_base := IDL2 +module_prefix := +module_suffix := + +CXX_PREPROCESS_FLAGS += -I../.. \ + -I../../External/Utility \ + -I../../External/boost \ + +include $(root)/Config/Archive.post.rules diff --git a/TAO/CIAO/CCF/CCF/IDL3/IDL3.cpp b/TAO/CIAO/CCF/CCF/IDL3/IDL3.cpp new file mode 100644 index 00000000000..cfa1da318d3 --- /dev/null +++ b/TAO/CIAO/CCF/CCF/IDL3/IDL3.cpp @@ -0,0 +1 @@ +// $Id$ diff --git a/TAO/CIAO/CCF/CCF/IDL3/IDL3.vcproj b/TAO/CIAO/CCF/CCF/IDL3/IDL3.vcproj new file mode 100644 index 00000000000..43895adcdd2 --- /dev/null +++ b/TAO/CIAO/CCF/CCF/IDL3/IDL3.vcproj @@ -0,0 +1,156 @@ +<?xml version="1.0" encoding="Windows-1252"?> +<VisualStudioProject + ProjectType="Visual C++" + Version="7.10" + Name="IDL3" + ProjectGUID="{97D61986-05D8-4B2A-B8B2-5095E58909FE}" + Keyword="Win32Proj"> + <Platforms> + <Platform + Name="Win32"/> + </Platforms> + <Configurations> + <Configuration + Name="Debug|Win32" + OutputDirectory="$(ProjectDir)" + IntermediateDirectory="Debug" + ConfigurationType="4" + CharacterSet="2"> + <Tool + Name="VCCLCompilerTool" + Optimization="0" + AdditionalIncludeDirectories="../..;../../External/Utility" + PreprocessorDefinitions="WIN32;_DEBUG;_LIB" + MinimalRebuild="TRUE" + BasicRuntimeChecks="3" + RuntimeLibrary="5" + ForceConformanceInForLoopScope="TRUE" + RuntimeTypeInfo="TRUE" + UsePrecompiledHeader="0" + WarningLevel="3" + Detect64BitPortabilityProblems="TRUE" + DebugInformationFormat="4"/> + <Tool + Name="VCCustomBuildTool"/> + <Tool + Name="VCLibrarianTool" + OutputFile="$(OutDir)/IDL3.lib"/> + <Tool + Name="VCMIDLTool"/> + <Tool + Name="VCPostBuildEventTool"/> + <Tool + Name="VCPreBuildEventTool"/> + <Tool + Name="VCPreLinkEventTool"/> + <Tool + Name="VCResourceCompilerTool"/> + <Tool + Name="VCWebServiceProxyGeneratorTool"/> + <Tool + Name="VCXMLDataGeneratorTool"/> + <Tool + Name="VCManagedWrapperGeneratorTool"/> + <Tool + Name="VCAuxiliaryManagedWrapperGeneratorTool"/> + </Configuration> + <Configuration + Name="Release|Win32" + OutputDirectory="Release" + IntermediateDirectory="Release" + ConfigurationType="4" + CharacterSet="2"> + <Tool + Name="VCCLCompilerTool" + PreprocessorDefinitions="WIN32;NDEBUG;_LIB" + RuntimeLibrary="4" + UsePrecompiledHeader="0" + WarningLevel="3" + Detect64BitPortabilityProblems="TRUE" + DebugInformationFormat="3"/> + <Tool + Name="VCCustomBuildTool"/> + <Tool + Name="VCLibrarianTool" + OutputFile="$(OutDir)/IDL3.lib"/> + <Tool + Name="VCMIDLTool"/> + <Tool + Name="VCPostBuildEventTool"/> + <Tool + Name="VCPreBuildEventTool"/> + <Tool + Name="VCPreLinkEventTool"/> + <Tool + Name="VCResourceCompilerTool"/> + <Tool + Name="VCWebServiceProxyGeneratorTool"/> + <Tool + Name="VCXMLDataGeneratorTool"/> + <Tool + Name="VCManagedWrapperGeneratorTool"/> + <Tool + Name="VCAuxiliaryManagedWrapperGeneratorTool"/> + </Configuration> + </Configurations> + <References> + </References> + <Files> + <Filter + Name="Source Files" + Filter="cpp;c;cxx;def;odl;idl;hpj;bat;asm;asmx" + UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"> + <File + RelativePath=".\IDL3_SyntaxTree.cpp"> + </File> + <File + RelativePath=".\IDL3_SyntaxTree_EventType.cpp"> + </File> + <File + RelativePath=".\IDL3_Traversal.cpp"> + </File> + </Filter> + <Filter + Name="Header Files" + Filter="h;hpp;hxx;hm;inl;inc;xsd" + UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"> + <File + RelativePath=".\IDL3_LexicalAnalyzer.hpp"> + </File> + <File + RelativePath=".\IDL3_Parser.hpp"> + </File> + <File + RelativePath=".\IDL3_SemanticAction.hpp"> + </File> + <File + RelativePath=".\IDL3_SemanticActionImpl.hpp"> + </File> + <File + RelativePath=".\IDL3_SyntaxTree.hpp"> + </File> + <File + RelativePath=".\IDL3_SyntaxTree_EventType.hpp"> + </File> + <File + RelativePath=".\IDL3_SyntaxTreeFwd.hpp"> + </File> + <File + RelativePath=".\IDL3_Traversal.hpp"> + </File> + <File + RelativePath=".\MSVC_Pragmas.hpp"> + </File> + </Filter> + <Filter + Name="Resource Files" + Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx" + UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}"> + </Filter> + <File + RelativePath=".\ReadMe.txt"> + </File> + </Files> + <Globals> + </Globals> +</VisualStudioProject> diff --git a/TAO/CIAO/CCF/CCF/IDL3/IDL3_LexicalAnalyzer.hpp b/TAO/CIAO/CCF/CCF/IDL3/IDL3_LexicalAnalyzer.hpp new file mode 100644 index 00000000000..610e047f294 --- /dev/null +++ b/TAO/CIAO/CCF/CCF/IDL3/IDL3_LexicalAnalyzer.hpp @@ -0,0 +1,59 @@ +// $Id$ +#ifndef CCF_IDL3_LEXICAL_ANALYZER_HPP +#define CCF_IDL3_LEXICAL_ANALYZER_HPP + +#include "MSVC_Pragmas.hpp" + +#include "CCF/IDL2/IDL2_LexicalAnalyzer.hpp" + +#include <string> + +namespace IDL3 +{ + class LexicalAnalyzer : public virtual IDL2::LexicalAnalyzer + { + public: + virtual + ~LexicalAnalyzer () throw () {} + + public: + + // Keywords (alphabetic order). + + KeywordPtr component; + KeywordPtr consumes; + KeywordPtr emits; + KeywordPtr eventtype; + KeywordPtr home; + KeywordPtr manages; + KeywordPtr provides; + KeywordPtr publishes; + KeywordPtr uses; + + LexicalAnalyzer (CCF::TokenStream<char>& is) + : IDL2::LexicalAnalyzer (is), + + component (new Keyword), + consumes (new Keyword), + emits (new Keyword), + eventtype (new Keyword), + home (new Keyword), + manages (new Keyword), + provides (new Keyword), + publishes (new Keyword), + uses (new Keyword) + { + keyword_table_["component"] = component; + keyword_table_["consumes" ] = consumes; + keyword_table_["emits" ] = emits; + keyword_table_["eventtype"] = eventtype; + keyword_table_["home" ] = home; + keyword_table_["manages" ] = manages; + keyword_table_["provides" ] = provides; + keyword_table_["publishes"] = publishes; + keyword_table_["uses" ] = uses; + } + }; +} + +#endif // CCF_IDL3_LEXICAL_ANALYZER_HPP diff --git a/TAO/CIAO/CCF/CCF/IDL3/IDL3_Parser.hpp b/TAO/CIAO/CCF/CCF/IDL3/IDL3_Parser.hpp new file mode 100644 index 00000000000..97cade9dca1 --- /dev/null +++ b/TAO/CIAO/CCF/CCF/IDL3/IDL3_Parser.hpp @@ -0,0 +1,425 @@ +// $Id$ +#ifndef CCF_IDL3_PARSER_HPP +#define CCF_IDL3_PARSER_HPP + + +#include "MSVC_Pragmas.hpp" + +#include "CCF/CompilerElements/Parser.hpp" +#include "CCF/IDL2/IDL2_Parser.hpp" +#include "CCF/IDL3/IDL3_LexicalAnalyzer.hpp" +#include "CCF/IDL3/IDL3_SemanticAction.hpp" + +namespace IDL3 +{ + class Parser : public virtual IDL2::Parser + { + public: + virtual + ~Parser () throw () {} + + protected: + + // + // Semanic action types + // + typedef + SemanticAction::Component + Component; + + typedef + SemanticAction::Provides + Provides; + + typedef + SemanticAction::Uses + Uses; + + typedef + SemanticAction::Publishes + Publishes; + + typedef + SemanticAction::Emits + Emits; + + typedef + SemanticAction::Consumes + Consumes; + + typedef + SemanticAction::EventType + EventType; + + typedef + SemanticAction::Home + Home; + + typedef + SemanticAction::HomeFactory + HomeFactory; + + // + // Primitives (alphabetic order). + // + KeywordParser COMPONENT; + KeywordParser CONSUMES; + KeywordParser EMITS; + KeywordParser EVENTTYPE; + KeywordParser HOME; + KeywordParser MANAGES; + KeywordParser PROVIDES; + KeywordParser PUBLISHES; + KeywordParser USES; + + + // + // Language + // + + Rule extension; + + // Component + Rule component_decl; + Rule component_header; + Rule component_inheritance_spec; + Rule component_support_spec; + Rule component_body; + + // Component body elements + Rule provides_decl; + Rule uses_decl; + Rule emits_decl; + Rule publishes_decl; + Rule consumes_decl; + + // Eventtype + Rule eventtype_decl; + Rule eventtype_header; + Rule eventtype_inheritance_spec; + Rule eventtype_body; + + // Home + Rule home_decl; + Rule home_header; + Rule home_inheritance_spec; + Rule home_support_spec; + Rule home_manage_spec; + Rule home_body; + + Rule home_factory_decl; + Rule home_factory_parameter_list; + Rule home_factory_parameter; + + + public: + + Parser (LexicalAnalyzer const& l, SemanticActionFactory& f) + : IDL2::Parser (l, f), + + COMPONENT (l.component), + CONSUMES (l.consumes), + EMITS (l.emits), + EVENTTYPE (l.eventtype), + HOME (l.home), + MANAGES (l.manages), + PROVIDES (l.provides), + PUBLISHES (l.publishes), + USES (l.uses), + + act_component_begin (f.component (), &Component::begin), + act_component_inherits (f.component (), &Component::inherits), + act_component_supports (f.component (), &Component::supports), + act_component_open_scope (f.component (), &Component::open_scope), + act_component_close_scope (f.component (), &Component::close_scope), + act_component_end (f.component (), &Component::end), + + act_provides_type (f.provides (), &Provides::type), + act_provides_name (f.provides (), &Provides::name), + + act_uses_type (f.uses (), &Uses::type), + act_uses_name (f.uses (), &Uses::name), + + act_publishes_type (f.publishes (), &Publishes::type), + act_publishes_name (f.publishes (), &Publishes::name), + + act_emits_type (f.emits (), &Emits::type), + act_emits_name (f.emits (), &Emits::name), + + act_consumes_type (f.consumes (), &Consumes::type), + act_consumes_name (f.consumes (), &Consumes::name), + + act_event_type_begin (f.event_type (), &EventType::begin), + act_event_type_inherits (f.event_type (), &EventType::inherits), + act_event_type_open_scope (f.event_type (), &EventType::open_scope), + act_event_type_close_scope (f.event_type (), &EventType::close_scope), + act_event_type_end (f.event_type (), &EventType::end), + + act_home_begin (f.home (), &Home::begin), + act_home_inherits (f.home (), &Home::inherits), + act_home_supports (f.home (), &Home::supports), + act_home_manages (f.home (), &Home::manages), + act_home_open_scope (f.home (), &Home::open_scope), + act_home_close_scope (f.home (), &Home::close_scope), + act_home_end (f.home (), &Home::end), + + act_home_factory_begin (f.home_factory (), &HomeFactory::begin), + act_home_factory_parameter (f.home_factory (), + &HomeFactory::parameter), + act_home_factory_end (f.home_factory (), &HomeFactory::end) + + { + IDL2::Parser::extension = + component_decl + | eventtype_decl + | home_decl + | extension + ; + + // + // Component + // + component_decl = + component_header + >> + ( + SEMI[act_component_end] + | + ( + !(COLON >> component_inheritance_spec) + >> !(SUPPORTS >> component_support_spec) + >> LBRACE[act_component_open_scope] + >> component_body + >> RBRACE[act_component_close_scope] + >> SEMI[act_component_end] + ) + ) + ; + + component_header = + COMPONENT + >> simple_identifier[act_component_begin] + ; + + component_inheritance_spec = identifier[act_component_inherits] + ; + + component_support_spec = + identifier[act_component_supports] + >> *(COMMA >> identifier[act_component_supports]) + ; + + component_body = + *( provides_decl + | uses_decl + | emits_decl + | publishes_decl + | consumes_decl + | attribute_decl + ) + ; + + // + // Component body elements + // + provides_decl = + PROVIDES + >> identifier[act_provides_type] + >> simple_identifier[act_provides_name] + >> SEMI + ; + + uses_decl = + USES + >> identifier[act_uses_type] + >> simple_identifier[act_uses_name] + >> SEMI + ; + + emits_decl = + EMITS + >> identifier[act_emits_type] + >> simple_identifier[act_emits_name] + >> SEMI + ; + + publishes_decl = + PUBLISHES + >> identifier[act_publishes_type] + >> simple_identifier[act_publishes_name] + >> SEMI + ; + + consumes_decl = + CONSUMES + >> identifier[act_consumes_type] + >> simple_identifier[act_consumes_name] + >> SEMI + ; + + // + // Eventtype + // + eventtype_decl = + eventtype_header + >> + ( + SEMI[act_event_type_end] + | + ( + !(COLON >> eventtype_inheritance_spec) + >> LBRACE[act_event_type_open_scope] +// >> eventtype_body + >> RBRACE[act_event_type_close_scope] + >> SEMI[act_event_type_end] + ) + ) + ; + + eventtype_header = + !(ABSTRACT) + >> EVENTTYPE + >> simple_identifier[act_event_type_begin] + ; + + eventtype_inheritance_spec = + identifier[act_event_type_inherits] + >> *(COMMA >> identifier[act_event_type_inherits]) + ; + + // + // Home + // + home_decl = + home_header + >> !(COLON >> home_inheritance_spec) + >> !(SUPPORTS >> home_support_spec) + >> MANAGES >> home_manage_spec + >> LBRACE[act_home_open_scope] + >> home_body + >> RBRACE[act_home_close_scope] + >> SEMI[act_home_end] + ; + + home_header = HOME >> simple_identifier[act_home_begin] + ; + + home_inheritance_spec = identifier[act_home_inherits] + ; + + home_support_spec = + identifier[act_home_supports] + >> *(COMMA >> identifier[act_home_supports]) + ; + + home_manage_spec = identifier[act_home_manages] + ; + + home_body = + *( + attribute_decl + | operation_decl + | home_factory_decl + ) + ; + + // + // Home factory + // + home_factory_decl = + FACTORY + >> simple_identifier[act_home_factory_begin] + >> LPAREN + >> home_factory_parameter_list + >> RPAREN + >> SEMI[act_home_factory_end] + ; + + home_factory_parameter_list = + *( + home_factory_parameter + >> *(COMMA >> home_factory_parameter) + ) + ; + + home_factory_parameter = + IN + >> (identifier >> simple_identifier)[act_home_factory_parameter] + ; + + } + + protected: + // + // + // + OneArgAction<SimpleIdentifierPtr, Component> act_component_begin; + OneArgAction<IdentifierPtr, Component> act_component_inherits; + OneArgAction<IdentifierPtr, Component> act_component_supports; + ScopeAction act_component_open_scope; + ScopeAction act_component_close_scope; + NoArgAction<Component> act_component_end; + + // + // Provides + // + OneArgAction<IdentifierPtr, Provides> act_provides_type; + OneArgAction<SimpleIdentifierPtr, Provides> act_provides_name; + + // + // Uses + // + OneArgAction<IdentifierPtr, Uses> act_uses_type; + OneArgAction<SimpleIdentifierPtr, Uses> act_uses_name; + + // + // Publishes + // + OneArgAction<IdentifierPtr, Publishes> act_publishes_type; + OneArgAction<SimpleIdentifierPtr, Publishes> act_publishes_name; + + // + // Emits + // + OneArgAction<IdentifierPtr, Emits> act_emits_type; + OneArgAction<SimpleIdentifierPtr, Emits> act_emits_name; + + // + // Consumes + // + OneArgAction<IdentifierPtr, Consumes> act_consumes_type; + OneArgAction<SimpleIdentifierPtr, Consumes> act_consumes_name; + + // + // + // + OneArgAction<SimpleIdentifierPtr, EventType> act_event_type_begin; + OneArgAction<IdentifierPtr, EventType> act_event_type_inherits; + ScopeAction act_event_type_open_scope; + ScopeAction act_event_type_close_scope; + NoArgAction<EventType> act_event_type_end; + + // + // + // + OneArgAction<SimpleIdentifierPtr, Home> act_home_begin; + OneArgAction<IdentifierPtr, Home> act_home_inherits; + OneArgAction<IdentifierPtr, Home> act_home_supports; + OneArgAction<IdentifierPtr, Home> act_home_manages; + ScopeAction act_home_open_scope; + ScopeAction act_home_close_scope; + NoArgAction<Home> act_home_end; + + // + // Home + // + OneArgAction<SimpleIdentifierPtr, HomeFactory> act_home_factory_begin; + TwoArgAction<IdentifierPtr, + SimpleIdentifierPtr, + HomeFactory> act_home_factory_parameter; + NoArgAction<HomeFactory> act_home_factory_end; + + }; +} + +#endif // CCF_IDL3_PARSER_HPP diff --git a/TAO/CIAO/CCF/CCF/IDL3/IDL3_SemanticAction.hpp b/TAO/CIAO/CCF/CCF/IDL3/IDL3_SemanticAction.hpp new file mode 100644 index 00000000000..51f21d077e3 --- /dev/null +++ b/TAO/CIAO/CCF/CCF/IDL3/IDL3_SemanticAction.hpp @@ -0,0 +1,179 @@ +// $Id$ +#ifndef CCF_IDL3_SEMANTIC_ACTION_HPP +#define CCF_IDL3_SEMANTIC_ACTION_HPP + +#include "MSVC_Pragmas.hpp" + +#include "CCF/IDL2/IDL2_SemanticAction.hpp" + +namespace IDL3 +{ + namespace SemanticAction + { + using namespace IDL2::SemanticAction; + + class Component : public virtual Scope + { + public: + + virtual void + begin (SimpleIdentifierPtr const& id) = 0; + + virtual void + inherits (IdentifierPtr const& id) = 0; + + virtual void + supports (IdentifierPtr const& id) = 0; + + virtual void + end () = 0; + }; + + class Provides + { + public: + virtual + ~Provides () throw () {} + + virtual void + type (IdentifierPtr const& id) = 0; + + virtual void + name (SimpleIdentifierPtr const& id) = 0; + }; + + class Uses + { + public: + virtual + ~Uses () throw () {} + + virtual void + type (IdentifierPtr const& id) = 0; + + virtual void + name (SimpleIdentifierPtr const& id) = 0; + }; + + class Publishes + { + public: + virtual + ~Publishes () throw () {} + + virtual void + type (IdentifierPtr const& id) = 0; + + virtual void + name (SimpleIdentifierPtr const& id) = 0; + }; + + class Emits + { + public: + virtual + ~Emits () throw () {} + + virtual void + type (IdentifierPtr const& id) = 0; + + virtual void + name (SimpleIdentifierPtr const& id) = 0; + }; + + class Consumes + { + public: + virtual + ~Consumes () throw () {} + + virtual void + type (IdentifierPtr const& id) = 0; + + virtual void + name (SimpleIdentifierPtr const& id) = 0; + }; + + class EventType : public virtual Scope + { + public: + + virtual void + begin (SimpleIdentifierPtr const& id) = 0; + + virtual void + inherits (IdentifierPtr const& id) = 0; + + virtual void + end () = 0; + }; + + class Home : public virtual Scope + { + public: + + virtual void + begin (SimpleIdentifierPtr const& id) = 0; + + virtual void + inherits (IdentifierPtr const& id) = 0; + + virtual void + supports (IdentifierPtr const& id) = 0; + + virtual void + manages (IdentifierPtr const& id) = 0; + + virtual void + end () = 0; + }; + + class HomeFactory + { + public: + + virtual void + begin (SimpleIdentifierPtr const& id) = 0; + + virtual void + parameter (IdentifierPtr const& type, + SimpleIdentifierPtr const& name) = 0; + + virtual void + end () = 0; + }; + } + + class SemanticActionFactory : public virtual IDL2::SemanticActionFactory + { + public: + virtual SemanticAction::Component& + component () = 0; + + virtual SemanticAction::Provides& + provides () = 0; + + virtual SemanticAction::Uses& + uses () = 0; + + virtual SemanticAction::Publishes& + publishes () = 0; + + virtual SemanticAction::Emits& + emits () = 0; + + virtual SemanticAction::Consumes& + consumes () = 0; + + virtual SemanticAction::EventType& + event_type () = 0; + + virtual SemanticAction::Home& + home () = 0; + + virtual SemanticAction::HomeFactory& + home_factory () = 0; + }; +} + +#endif // CCF_IDL3_SEMANTIC_ACTION_HPP diff --git a/TAO/CIAO/CCF/CCF/IDL3/IDL3_SemanticActionImpl.hpp b/TAO/CIAO/CCF/CCF/IDL3/IDL3_SemanticActionImpl.hpp new file mode 100644 index 00000000000..9cbf1c49c9b --- /dev/null +++ b/TAO/CIAO/CCF/CCF/IDL3/IDL3_SemanticActionImpl.hpp @@ -0,0 +1,1365 @@ +// $Id$ +#ifndef CCF_IDL3_SEMANTIC_ACTION_IMPL_HPP +#define CCF_IDL3_SEMANTIC_ACTION_IMPL_HPP + +#include "MSVC_Pragmas.hpp" + +#include "CCF/IDL3/IDL3_SyntaxTree.hpp" +#include "CCF/IDL3/IDL3_SyntaxTree_EventType.hpp" + +#include "CCF/IDL3/IDL3_SemanticAction.hpp" +#include "CCF/IDL2/IDL2_SemanticActionImpl.hpp" + +//@@ needed for include handling +#include "CCF/CompilerElements/TokenStream.hpp" +#include "CCF/CompilerElements/Preprocessor.hpp" + +namespace IDL3 +{ + namespace SemanticAction + { + namespace Impl + { + using IDL2::SemanticAction::Impl::ScopeBase; + + // Note: overriding IDL2 include to allow inclusiion of IDL3 files + // + // + class Include : public virtual SemanticAction::Include + { + public: + virtual + ~Include () throw () {} + + Include (SemanticActionFactory& action_factory, + SyntaxTree::TranslationRegionPtr const& region, + SyntaxTree::ScopePtr& scope) + : action_factory_ (action_factory), + scope_ (scope) + { + stack_.push (region); + } + + virtual void + begin (StringLiteralPtr const& sl) + { + cerr << "include \"" << sl << "\"" << endl; + + using namespace SyntaxTree; + + try + { + fs::path file_path (sl->value ()); + + if(!include_file_set_.insert (file_path).second) + { + cerr << "warning: skipping already included file \'" + << sl << "\'" << endl; + return; + } + + fs::ifstream ifs; + ifs.exceptions (ios_base::badbit | ios_base::failbit); + ifs.open (file_path, std::ios_base::in); + + //@@ for some reason ifs throws exception if I don't reset it to + // original state. It probably has something to do with call to + // get after eof. + ifs.exceptions (ios_base::iostate (0)); + + TranslationRegionPtr r ( + new IncludeTranslationRegion (file_path, + stack_.top ()->table (), + stack_.top ()->create_order ())); + + stack_.top ()->insert (r); + stack_.push (r); + + cerr << "push file scope: old scope " << scope_->order (); + + scope_ = stack_.top ()->scope (); + + cerr << "; new scope " << scope_->order () << endl; + + //@@ this code is highly experimental + CCF::InputStreamAdapter isa (ifs); + CCF::Preprocessor pp (isa); + IDL3::LexicalAnalyzer lexer (pp); + + TokenStream token_stream; + + //@@ bad token comparison + for (TokenPtr token = lexer.next (); + token.in () != lexer.eos.in (); + token = lexer.next ()) + { + token_stream.push_back (token); + } + + if (token_stream.size () != 0) + { + IDL3::Parser parser (lexer, action_factory_); + + /*bool result = */Details::parse (token_stream.begin (), + token_stream.end (), + parser.start ()); + } + + cerr << "pop file scope: old scope " << scope_->order (); + + stack_.pop (); + scope_ = stack_.top ()->scope (); + + cerr << "; new scope " << scope_->order () << endl; + } + catch (fs::filesystem_error const&) + { + cerr << sl << ": error: unable to open in read mode" << endl; + } + catch (ios_base::failure const&) + { + cerr << sl << ": error: unable to open in read mode" << endl; + } + } + + virtual void + end () + { + cerr << "end" << endl; + } + + public: + SemanticActionFactory& action_factory_; + SyntaxTree::ScopePtr& scope_; + std::stack<SyntaxTree::TranslationRegionPtr> stack_; + struct FilePathComparator + { + bool operator () (fs::path const& x, fs::path const& y) const + { + return x.string () < y.string (); + } + }; + + std::set<fs::path, FilePathComparator> include_file_set_; + }; + + + // + // + // + class Component : public virtual SemanticAction::Component, + public virtual ScopeBase<SyntaxTree::ComponentDeclPtr> + { + public: + virtual + ~Component () throw () {} + + + Component (SyntaxTree::ScopePtr& scope) + : ScopeBase<SyntaxTree::ComponentDeclPtr> (scope), + name_ (""), + inherits_ ("") + { + } + + virtual void + begin (SimpleIdentifierPtr const& id) + { + cerr << "component " << id << endl; + + name_ = SyntaxTree::SimpleName (id->value ()); + } + + virtual void + inherits (IdentifierPtr const& id) + { + cerr << "inherits " << id << endl; + + using namespace SyntaxTree; + + Name name (id->value ()); + + struct InheritancePredicate : + public DeclarationTable::ResolvePredicate + { + struct IncompatibleType : + public DeclarationTable::ResolutionFailure + { + IncompatibleType (std::string const& t) : type (t) {} + std::string type; + }; + + virtual bool + test (DeclarationPtr const& d) + throw (IncompatibleType) + { + std::string type = d->declaration_type (); + + if (type != "component") throw IncompatibleType (type); + + return strict_cast<TypeDecl> (d)->defined (); + } + } p; + + try + { + ScopedName sn = scope_->table ().resolve ( + name, + scope_->name (), + scope_->peek_order (), + p); + + inherits_ = sn; + } + catch (InheritancePredicate::IncompatibleType const& e) + { + cerr << "error: invalid inheritance specification" << endl; + + cerr << "inheritance of "; + cerr << "component \'" << name_ <<"\' from " + << e.type << " \'" << name << "\' is illegal" << endl; + } + catch (DeclarationTable::NameNotFound const&) + { + cerr << "error: invalid inheritance specification" << endl; + cerr << "no component with name \'" + << name << "\' visible from scope \'" + << scope_->name () << "\'" << endl; + } + catch (DeclarationTable::PredicateNotMet const&) + { + cerr << "error: invalid inheritance specification" << endl; + cerr << "no defined component with name \'" + << name << "\' visible from scope \'" + << scope_->name () << "\'" << endl; + cerr << "inheritance from forward-declared component is illegal" + << endl; + } + } + + + virtual void + supports (IdentifierPtr const& id) + { + cerr << "supports " << id << endl; + + using namespace SyntaxTree; + + Name name (id->value ()); + + struct SupportsPredicate : + public DeclarationTable::ResolvePredicate + { + struct IncompatibleType : + public DeclarationTable::ResolutionFailure + { + IncompatibleType (std::string const& t) : type (t) {} + std::string type; + }; + + virtual bool + test (DeclarationPtr const& d) + throw (IncompatibleType) + { + std::string type = d->declaration_type (); + + // Spec doesn't say anything about which interfaces + // component can support. + if (type != "unconstrained interface") + throw IncompatibleType (type); + + return strict_cast<TypeDecl> (d)->defined (); + } + } p; + + try + { + ScopedName sn = scope_->table ().resolve ( + name, + scope_->name (), + scope_->peek_order (), + p); + + if (supports_.insert (sn).second == false) + { + cerr << "error: invalid support specification" << endl; + cerr << "directly supporting interface \'" + << sn << "\' more than once is illegal" << endl; + } + } + catch (SupportsPredicate::IncompatibleType const& e) + { + cerr << "error: invalid support specification" << endl; + + cerr << "specifying " << e.type << " \'" << name + << "\' in component\'s support clause is illegal" + << endl; + } + catch (DeclarationTable::NameNotFound const&) + { + cerr << "error: invalid support specification" << endl; + cerr << "no interface with name \'" + << name << "\' visible from scope \'" + << scope_->name () << "\'" << endl; + } + catch (DeclarationTable::PredicateNotMet const&) + { + cerr << "error: invalid support specification" << endl; + cerr << "no defined interface with name \'" + << name << "\' visible from scope \'" + << scope_->name () << "\'" << endl; + cerr << "supporting forward-declared interface is illegal" + << endl; + } + } + + virtual void + open_scope () + { + using namespace SyntaxTree; + + ComponentDefPtr def; + + if (inherits_ == ScopedName ("")) + { + def = ComponentDefPtr (new ComponentDef ( + name_, + scope_, + supports_)); + } + else + { + def = ComponentDefPtr (new ComponentDef ( + name_, + scope_, + inherits_, + supports_)); + } + + scope_->insert (def); + push (def); + scope_ = def; + + name_ = SimpleName (""); //indicate that we are done + inherits_ = ScopedName (""); + supports_.clear (); + } + + virtual void + close_scope () + { + scope_ = scope_->scope (); + } + + virtual void + end () + { + cerr << "end" << endl; + + using namespace SyntaxTree; + + if (name_ != SimpleName ("")) + { + ComponentDeclPtr decl (new ComponentForwardDecl (name_, scope_)); + scope_->insert (decl); + } + else + { + pop (); + } + } + private: + SyntaxTree::SimpleName name_; + SyntaxTree::ScopedName inherits_; + SyntaxTree::ScopedNameSet supports_; + }; + + + class Provides : public virtual SemanticAction::Provides + { + public: + virtual + ~Provides () throw () {} + + Provides (SyntaxTree::ScopePtr& current) + : scope_ (current), + type_ ("") + { + } + + virtual void + type (IdentifierPtr const& id) + { + cerr << "provides " << id; + + using namespace SyntaxTree; + + Name name (id->value ()); + + struct Predicate : public DeclarationTable::ResolvePredicate + { + virtual bool + test (DeclarationPtr const& d) throw () + { + return strict_cast<InterfaceDecl> (d) != 0; + } + } p; + + try + { + ScopedName sn = scope_->table ().resolve ( + name, + scope_->name (), + scope_->peek_order (), + p); + + type_ = sn; + } + catch (DeclarationTable::NameNotFound const&) + { + cerr << "error: invalid provides declaration" << endl; + cerr << "no interface type with name \'" + << name << "\' visible from scope \'" + << scope_->name () << "\'" << endl; + } + catch (DeclarationTable::PredicateNotMet const&) + { + cerr << "error: invalid provides declaration" << endl; + cerr << "declaration with name \'" << name + << "\' visible from scope \'" << scope_->name () + << "\' is not an interface type declaration" << endl; + cerr << "using non-<interface type> in provides " + << "declaration is illegal" << endl; + } + } + + virtual void + name (SimpleIdentifierPtr const& id) + { + cerr << " " << id << endl; + + using namespace SyntaxTree; + + SimpleName name (id->value ()); + + DeclarationPtr d ( + new SyntaxTree::ProvidesDecl (name, type_, scope_)); + + scope_->insert (d); + + type_ = ScopedName (""); + } + + private: + SyntaxTree::ScopePtr& scope_; + SyntaxTree::ScopedName type_; + }; + + class Uses : public virtual SemanticAction::Uses + { + public: + virtual + ~Uses () throw () {} + + Uses (SyntaxTree::ScopePtr& current) + : scope_ (current), + type_ ("") + { + } + + virtual void + type (IdentifierPtr const& id) + { + cerr << "uses " << id; + + using namespace SyntaxTree; + + Name name (id->value ()); + + struct Predicate : public DeclarationTable::ResolvePredicate + { + virtual bool + test (DeclarationPtr const& d) throw () + { + return strict_cast<InterfaceDecl> (d) != 0; + } + } p; + + try + { + ScopedName sn = scope_->table ().resolve ( + name, + scope_->name (), + scope_->peek_order (), + p); + + type_ = sn; + } + catch (DeclarationTable::NameNotFound const&) + { + cerr << "error: invalid uses declaration" << endl; + cerr << "no interface type with name \'" + << name << "\' visible from scope \'" + << scope_->name () << "\'" << endl; + } + catch (DeclarationTable::PredicateNotMet const&) + { + cerr << "error: invalid uses declaration" << endl; + cerr << "declaration with name \'" << name + << "\' visible from scope \'" << scope_->name () + << "\' is not an interface type declaration" << endl; + cerr << "using non-<interface type> in uses " + << "declaration is illegal" << endl; + } + } + + virtual void + name (SimpleIdentifierPtr const& id) + { + cerr << " " << id << endl; + + using namespace SyntaxTree; + + SimpleName name (id->value ()); + + DeclarationPtr d ( + new SyntaxTree::UsesDecl (name, type_, scope_)); + + scope_->insert (d); + + type_ = ScopedName (""); + } + + private: + SyntaxTree::ScopePtr& scope_; + SyntaxTree::ScopedName type_; + }; + + + class Publishes : public virtual SemanticAction::Publishes + { + public: + virtual + ~Publishes () throw () {} + + Publishes (SyntaxTree::ScopePtr& current) + : scope_ (current), + type_ ("") + { + } + + virtual void + type (IdentifierPtr const& id) + { + cerr << "publishes " << id; + + using namespace SyntaxTree; + + Name name (id->value ()); + + struct Predicate : public DeclarationTable::ResolvePredicate + { + virtual bool + test (DeclarationPtr const& d) throw () + { + return strict_cast<EventTypeDef> (d) != 0; + } + } p; + + try + { + ScopedName sn = scope_->table ().resolve ( + name, + scope_->name (), + scope_->peek_order (), + p); + + type_ = sn; + } + catch (DeclarationTable::NameNotFound const&) + { + cerr << "error: invalid publishes declaration" << endl; + cerr << "no event type with name \'" + << name << "\' visible from scope \'" + << scope_->name () << "\'" << endl; + } + catch (DeclarationTable::PredicateNotMet const&) + { + cerr << "error: invalid publishes declaration" << endl; + cerr << "declaration with name \'" << name + << "\' visible from scope \'" << scope_->name () + << "\' is not a defined event type" << endl; + cerr << "using non-<defined event type> in publishes " + << "declaration is illegal" << endl; + } + } + + virtual void + name (SimpleIdentifierPtr const& id) + { + cerr << " " << id << endl; + + using namespace SyntaxTree; + + SimpleName name (id->value ()); + + DeclarationPtr d ( + new SyntaxTree::PublishesDecl (name, type_, scope_)); + + scope_->insert (d); + + type_ = ScopedName (""); + } + + private: + SyntaxTree::ScopePtr& scope_; + SyntaxTree::ScopedName type_; + }; + + class Emits : public virtual SemanticAction::Emits + { + public: + virtual + ~Emits () throw () {} + + Emits (SyntaxTree::ScopePtr& current) + : scope_ (current), + type_ ("") + { + } + + virtual void + type (IdentifierPtr const& id) + { + cerr << "emits " << id; + + using namespace SyntaxTree; + + Name name (id->value ()); + + struct Predicate : public DeclarationTable::ResolvePredicate + { + virtual bool + test (DeclarationPtr const& d) throw () + { + return strict_cast<EventTypeDef> (d) != 0; + } + } p; + + try + { + ScopedName sn = scope_->table ().resolve ( + name, + scope_->name (), + scope_->peek_order (), + p); + + type_ = sn; + } + catch (DeclarationTable::NameNotFound const&) + { + cerr << "error: invalid emits declaration" << endl; + cerr << "no event type with name \'" + << name << "\' visible from scope \'" + << scope_->name () << "\'" << endl; + } + catch (DeclarationTable::PredicateNotMet const&) + { + cerr << "error: invalid emits declaration" << endl; + cerr << "declaration with name \'" << name + << "\' visible from scope \'" << scope_->name () + << "\' is not a defined event type" << endl; + cerr << "using non-<defined event type> in emits " + << "declaration is illegal" << endl; + } + } + + virtual void + name (SimpleIdentifierPtr const& id) + { + cerr << " " << id << endl; + + using namespace SyntaxTree; + + SimpleName name (id->value ()); + + DeclarationPtr d ( + new SyntaxTree::EmitsDecl (name, type_, scope_)); + + scope_->insert (d); + + type_ = ScopedName (""); + } + + private: + SyntaxTree::ScopePtr& scope_; + SyntaxTree::ScopedName type_; + }; + + class Consumes : public virtual SemanticAction::Consumes + { + public: + virtual + ~Consumes () throw () {} + + Consumes (SyntaxTree::ScopePtr& current) + : scope_ (current), + type_ ("") + { + } + + virtual void + type (IdentifierPtr const& id) + { + cerr << "consumes " << id; + + using namespace SyntaxTree; + + Name name (id->value ()); + + struct Predicate : public DeclarationTable::ResolvePredicate + { + virtual bool + test (DeclarationPtr const& d) throw () + { + return strict_cast<EventTypeDef> (d) != 0; + } + } p; + + try + { + ScopedName sn = scope_->table ().resolve ( + name, + scope_->name (), + scope_->peek_order (), + p); + + type_ = sn; + } + catch (DeclarationTable::NameNotFound const&) + { + cerr << "error: invalid consumes declaration" << endl; + cerr << "no event type with name \'" + << name << "\' visible from scope \'" + << scope_->name () << "\'" << endl; + } + catch (DeclarationTable::PredicateNotMet const&) + { + cerr << "error: invalid consumes declaration" << endl; + cerr << "declaration with name \'" << name + << "\' visible from scope \'" << scope_->name () + << "\' is not a defined event type" << endl; + cerr << "using non-<defined event type> in consumes " + << "declaration is illegal" << endl; + } + } + + virtual void + name (SimpleIdentifierPtr const& id) + { + cerr << " " << id << endl; + + using namespace SyntaxTree; + + SimpleName name (id->value ()); + + DeclarationPtr d ( + new SyntaxTree::ConsumesDecl (name, type_, scope_)); + + scope_->insert (d); + + type_ = ScopedName (""); + } + + private: + SyntaxTree::ScopePtr& scope_; + SyntaxTree::ScopedName type_; + }; + + // + // + // + class EventType : public virtual SemanticAction::EventType, + public virtual ScopeBase<SyntaxTree::EventTypeDeclPtr> + { + public: + virtual + ~EventType () throw () {} + + EventType (SyntaxTree::ScopePtr& scope) + : ScopeBase<SyntaxTree::EventTypeDeclPtr> (scope), + name_ ("") + { + } + + public: + + virtual void + begin (SimpleIdentifierPtr const& id) + { + cerr << "eventtype " << id << endl; + name_ = SyntaxTree::SimpleName (id->value ()); + } + + virtual void + inherits (IdentifierPtr const& id) + { + cerr << "inherits " << id << endl; + } + + virtual void + open_scope () + { + using namespace SyntaxTree; + + ConcreteEventTypeDefPtr et( new ConcreteEventTypeDef ( + name_, + scope_, + inherits_)); + scope_->insert (et); + push (et); + scope_ = et; + + name_ = SimpleName (""); //indicate that we are done + inherits_.clear (); + } + + virtual void + close_scope () + { + scope_ = scope_->scope (); + } + + virtual void + end () + { + cerr << "end" << endl; + pop (); + } + + private: + SyntaxTree::SimpleName name_; + SyntaxTree::ScopedNameSet inherits_; + }; + + + // + // + // + class Home : public virtual SemanticAction::Home, + public virtual ScopeBase<SyntaxTree::HomeDefPtr> + { + public: + virtual + ~Home () throw () {} + + Home (SyntaxTree::ScopePtr& scope) + : ScopeBase<SyntaxTree::HomeDefPtr> (scope), + name_ (""), + inherits_ (""), + manages_ ("") + + { + } + + virtual void + begin (SimpleIdentifierPtr const& id) + { + cerr << "home " << id << endl; + name_ = SyntaxTree::SimpleName (id->value ()); + } + + + virtual void + inherits (IdentifierPtr const& id) + { + cerr << "inherits " << id << endl; + + using namespace SyntaxTree; + + Name name (id->value ()); + + struct InheritancePredicate : + public DeclarationTable::ResolvePredicate + { + struct IncompatibleType : + public DeclarationTable::ResolutionFailure + { + IncompatibleType (std::string const& t) : type (t) {} + std::string type; + }; + + virtual bool + test (DeclarationPtr const& d) + throw (IncompatibleType) + { + std::string type = d->declaration_type (); + + if (type != "home") throw IncompatibleType (type); + + // This is not really necessary since home cannot be + // forward-declared (yet ;-). + return strict_cast<TypeDecl> (d)->defined (); + } + } p; + + try + { + ScopedName sn = scope_->table ().resolve ( + name, + scope_->name (), + scope_->peek_order (), + p); + + inherits_ = sn; + } + catch (InheritancePredicate::IncompatibleType const& e) + { + cerr << "error: invalid inheritance specification" << endl; + + cerr << "inheritance of "; + cerr << "home \'" << name_ <<"\' from " + << e.type << " \'" << name << "\' is illegal" << endl; + } + catch (DeclarationTable::NameNotFound const&) + { + cerr << "error: invalid inheritance specification" << endl; + cerr << "no home with name \'" + << name << "\' visible from scope \'" + << scope_->name () << "\'" << endl; + } + catch (DeclarationTable::PredicateNotMet const&) + { + cerr << "error: invalid inheritance specification" << endl; + cerr << "no defined home with name \'" + << name << "\' visible from scope \'" + << scope_->name () << "\'" << endl; + cerr << "inheritance from forward-declared home is illegal" + << endl; + } + } + + + virtual void + supports (IdentifierPtr const& id) + { + cerr << "supports " << id << endl; + + using namespace SyntaxTree; + + Name name (id->value ()); + + struct SupportsPredicate : + public DeclarationTable::ResolvePredicate + { + struct IncompatibleType : + public DeclarationTable::ResolutionFailure + { + IncompatibleType (std::string const& t) : type (t) {} + std::string type; + }; + + virtual bool + test (DeclarationPtr const& d) + throw (IncompatibleType) + { + std::string type = d->declaration_type (); + + // Spec doesn't say anything about which interfaces + // component can support. + if (type != "unconstrained interface") + throw IncompatibleType (type); + + return strict_cast<TypeDecl> (d)->defined (); + } + } p; + + try + { + ScopedName sn = scope_->table ().resolve ( + name, + scope_->name (), + scope_->peek_order (), + p); + + if (supports_.insert (sn).second == false) + { + cerr << "error: invalid support specification" << endl; + cerr << "directly supporting interface \'" + << sn << "\' more than once is illegal" << endl; + } + } + catch (SupportsPredicate::IncompatibleType const& e) + { + cerr << "error: invalid support specification" << endl; + + cerr << "specifying " << e.type << " \'" << name + << "\' in home\'s support clause is illegal" + << endl; + } + catch (DeclarationTable::NameNotFound const&) + { + cerr << "error: invalid support specification" << endl; + cerr << "no interface with name \'" + << name << "\' visible from scope \'" + << scope_->name () << "\'" << endl; + } + catch (DeclarationTable::PredicateNotMet const&) + { + cerr << "error: invalid support specification" << endl; + cerr << "no defined interface with name \'" + << name << "\' visible from scope \'" + << scope_->name () << "\'" << endl; + cerr << "supporting forward-declared interface is illegal" + << endl; + } + } + + + virtual void + manages (IdentifierPtr const& id) + { + cerr << "manages " << id << endl; + + using namespace SyntaxTree; + + Name name (id->value ()); + + struct ManagesPredicate : + public DeclarationTable::ResolvePredicate + { + struct IncompatibleType : + public DeclarationTable::ResolutionFailure + { + IncompatibleType (std::string const& t) : type (t) {} + std::string type; + }; + + virtual bool + test (DeclarationPtr const& d) + throw (IncompatibleType) + { + std::string type = d->declaration_type (); + + if (type != "component") throw IncompatibleType (type); + + return strict_cast<TypeDecl> (d)->defined (); + } + } p; + + try + { + ScopedName sn = scope_->table ().resolve ( + name, + scope_->name (), + scope_->peek_order (), + p); + + manages_ = sn; + } + catch (ManagesPredicate::IncompatibleType const& e) + { + cerr << "error: invalid manages specification" << endl; + + cerr << "specifying " << e.type << " \'" << name + << "\' in home manages clause is illegal" << endl; + } + catch (DeclarationTable::NameNotFound const&) + { + cerr << "error: invalid manages specification" << endl; + cerr << "no component with name \'" + << name << "\' visible from scope \'" + << scope_->name () << "\'" << endl; + } + catch (DeclarationTable::PredicateNotMet const&) + { + cerr << "error: invalid manages specification" << endl; + cerr << "no defined component with name \'" + << name << "\' visible from scope \'" + << scope_->name () << "\'" << endl; + cerr << "managing of forward-declared component is illegal" + << endl; + } + } + + virtual void + open_scope () + { + using namespace SyntaxTree; + + HomeDefPtr def (new HomeDef ( + name_, + scope_, + inherits_, + supports_, + manages_)); + + if (inherits_ == ScopedName ("")) + { + def = HomeDefPtr (new HomeDef ( + name_, + scope_, + supports_, + manages_)); + } + else + { + def = HomeDefPtr (new HomeDef ( + name_, + scope_, + inherits_, + supports_, + manages_)); + } + + + scope_->insert (def); + push (def); + scope_ = def; + + name_ = SimpleName (""); //indicate that we are done + inherits_ = ScopedName (""); + supports_.clear (); + manages_ = ScopedName (""); + } + + virtual void + close_scope () + { + scope_ = scope_->scope (); + } + + virtual void + end () + { + cerr << "end" << endl; + + using namespace SyntaxTree; + + if (name_ != SimpleName ("")) + { + // this is not supported by spec yet + } + else + { + pop (); + } + } + private: + SyntaxTree::SimpleName name_; + SyntaxTree::ScopedName inherits_; + SyntaxTree::ScopedNameSet supports_; + SyntaxTree::ScopedName manages_; + }; + + // + // + // + //@@ Name is inconsistent with HomeFactoryDecl + class HomeFactory : public virtual SemanticAction::HomeFactory + { + public: + virtual + ~HomeFactory () throw () + { + } + + HomeFactory (SyntaxTree::ScopePtr& current) + : scope_ (current) + { + } + + virtual void + begin (SimpleIdentifierPtr const& id) + { + cerr << "home factory " << id << endl; + + using namespace SyntaxTree; + + HomeDefPtr home (scope_->dynamic_type<HomeDef> ()); + + if (home == 0) + { + //@@ internal compiler error + } + + ComponentDefPtr component (home->manages ()); + + home_factory_ = HomeFactoryDeclPtr ( + new HomeFactoryDecl (SimpleName (id->value ()), + component->name (), + scope_)); + } + + virtual void + parameter (IdentifierPtr const& type_id, + SimpleIdentifierPtr const& name_id) + { + cerr << "parameter " << type_id << " " << name_id << endl; + + using namespace IDL3::SyntaxTree; + + Name type_name (type_id->value ()); + + struct Predicate : public DeclarationTable::ResolvePredicate + { + virtual bool + test (DeclarationPtr const& d) throw () + { + return strict_cast<TypeDecl> (d) != 0; + } + } p; + + try + { + ScopedName sn = scope_->table ().resolve ( + type_name, + scope_->name (), + scope_->peek_order (), + p); + + HomeFactoryParameterPtr p ( + new HomeFactoryParameter (sn, + SimpleName (name_id->value ()), + scope_->table ())); + + home_factory_->insert (p); + } + catch (DeclarationTable::NameNotFound const&) + { + cerr << "error: invalid home factory declaration" << endl; + cerr << "no type with name \'" + << type_name << "\' visible from scope \'" + << scope_->name () << "\'" << endl; + } + catch (DeclarationTable::PredicateNotMet const&) + { + cerr << "error: invalid home factory declaration" << endl; + cerr << "declaration with name \'" << type_name + << "\' visible from scope \'" << scope_->name () + << "\' is not a type declaration" << endl; + cerr << "using non-type as home factory parameter type is illegal" + << endl; + } + } + + virtual void + end () + { + cerr << "end" << endl; + scope_->insert (home_factory_); + home_factory_ = SyntaxTree::HomeFactoryDeclPtr (); + } + private: + SyntaxTree::ScopePtr& scope_; + SyntaxTree::HomeFactoryDeclPtr home_factory_; + }; + } + } + + class SemanticActionFactoryImpl : + public virtual IDL3::SemanticActionFactory, + public virtual IDL2::SemanticActionFactoryImpl + { + public: + virtual + ~SemanticActionFactoryImpl () throw () {} + + SemanticActionFactoryImpl (SyntaxTree::TranslationRegionPtr const& r) + : IDL2::SemanticActionFactoryImpl (r), + + include_ (*this, r, scope_), + component_ (scope_), + provides_ (scope_), + uses_ (scope_), + publishes_ (scope_), + emits_ (scope_), + consumes_ (scope_), + event_type_ (scope_), + home_ (scope_), + home_factory_ (scope_) + { + + } + + public: + + virtual SemanticAction::Include& + include () + { + return include_; + } + + virtual SemanticAction::Component& + component () + { + return component_; + } + + virtual SemanticAction::Provides& + provides () + { + return provides_; + } + + virtual SemanticAction::Uses& + uses () + { + return uses_; + } + + virtual SemanticAction::Publishes& + publishes () + { + return publishes_; + } + + virtual SemanticAction::Emits& + emits () + { + return emits_; + } + + virtual SemanticAction::Consumes& + consumes () + { + return consumes_; + } + + + virtual SemanticAction::EventType& + event_type () + { + return event_type_; + } + + virtual SemanticAction::Home& + home () + { + return home_; + } + + virtual SemanticAction::HomeFactory& + home_factory () + { + return home_factory_; + } + + + private: + + SemanticAction::Impl::Include include_; + + SemanticAction::Impl::Component component_; + SemanticAction::Impl::Provides provides_; + SemanticAction::Impl::Uses uses_; + SemanticAction::Impl::Publishes publishes_; + SemanticAction::Impl::Emits emits_; + SemanticAction::Impl::Consumes consumes_; + SemanticAction::Impl::EventType event_type_; + SemanticAction::Impl::Home home_; + SemanticAction::Impl::HomeFactory home_factory_; + }; +} + +#endif // CCF_IDL3_SEMANTIC_ACTION_IMPL_HPP diff --git a/TAO/CIAO/CCF/CCF/IDL3/IDL3_SyntaxTree.cpp b/TAO/CIAO/CCF/CCF/IDL3/IDL3_SyntaxTree.cpp new file mode 100644 index 00000000000..d8afe5f49e4 --- /dev/null +++ b/TAO/CIAO/CCF/CCF/IDL3/IDL3_SyntaxTree.cpp @@ -0,0 +1,186 @@ +// $Id$ +#include "IDL3_Traversal.hpp" +#include "IDL3_SyntaxTree.hpp" + +namespace IDL3 +{ + namespace SyntaxTree + { + using CCF::Traversal::try_visit; + + namespace + { + //@@ repetition of what's already in IDL2 + bool + try_visit_scope (CCF::Traversal::Visitor* v, + ScopePtr const& node) + { + return try_visit<Traversal::Scope> ( + &Traversal::Scope::visit_scope, + v, + node); + } + + bool + try_visit_component_decl (CCF::Traversal::Visitor* v, + ComponentDeclPtr const& node) + { + return try_visit<Traversal::ComponentDecl> ( + &Traversal::ComponentDecl::visit_component_decl, + v, + node); + } + } + + + // + // ComponentDecl + // + + void ComponentDecl:: + accept (CCF::Traversal::Visitor* v) + { + ComponentDeclPtr self (ReferenceCounting::add_ref (this)); + + try_visit_component_decl (v, self); + } + + // + // ComponentForwardDecl + // + + void ComponentForwardDecl:: + accept (CCF::Traversal::Visitor* v) + { + } + + // + // ComponentDef + // + + void ComponentDef:: + accept (CCF::Traversal::Visitor* v) + { + ComponentDefPtr self (ReferenceCounting::add_ref (this)); + + if(!try_visit<Traversal::ComponentDef> ( + &Traversal::ComponentDef::visit_component_def, + v, + self)) + { + try_visit_component_decl (v, self); + try_visit_scope (v, self); + } + } + + // + // ProvidesDecl + // + + void ProvidesDecl:: + accept (CCF::Traversal::Visitor* v) + { + ProvidesDeclPtr self (ReferenceCounting::add_ref (this)); + try_visit<Traversal::ProvidesDecl> ( + &Traversal::ProvidesDecl::visit_provides_decl, + v, + self); + } + + // + // UsesDecl + // + + void UsesDecl:: + accept (CCF::Traversal::Visitor* v) + { + UsesDeclPtr self (ReferenceCounting::add_ref (this)); + try_visit<Traversal::UsesDecl> ( + &Traversal::UsesDecl::visit_uses_decl, + v, + self); + } + + // + // PublishesDecl + // + + void PublishesDecl:: + accept (CCF::Traversal::Visitor* v) + { + PublishesDeclPtr self (ReferenceCounting::add_ref (this)); + try_visit<Traversal::PublishesDecl> ( + &Traversal::PublishesDecl::visit_publishes_decl, + v, + self); + } + + // + // EmitsDecl + // + + void EmitsDecl:: + accept (CCF::Traversal::Visitor* v) + { + EmitsDeclPtr self (ReferenceCounting::add_ref (this)); + try_visit<Traversal::EmitsDecl> ( + &Traversal::EmitsDecl::visit_emits_decl, + v, + self); + } + + // + // ConsumesDecl + // + + void ConsumesDecl:: + accept (CCF::Traversal::Visitor* v) + { + ConsumesDeclPtr self (ReferenceCounting::add_ref (this)); + try_visit<Traversal::ConsumesDecl> ( + &Traversal::ConsumesDecl::visit_consumes_decl, + v, + self); + } + + + // + // HomeDef + // + + void HomeDef:: + accept (CCF::Traversal::Visitor* v) + { + HomeDefPtr self (ReferenceCounting::add_ref (this)); + + if(!try_visit<Traversal::HomeDef> ( + &Traversal::HomeDef::visit_home_def, + v, + self)) + { + try_visit_scope (v, self); + } + } + + // + // HomeFactoryDecl + // + + void HomeFactoryDecl:: + accept (CCF::Traversal::Visitor* v) + { + HomeFactoryDeclPtr self (ReferenceCounting::add_ref (this)); + + if(!try_visit<Traversal::HomeFactoryDecl> ( + &Traversal::HomeFactoryDecl::visit_home_factory_decl, + v, + self)) + { + try_visit<Traversal::OperationDecl> ( + &Traversal::OperationDecl::visit_operation_decl, + v, + self); + } + } + } +} diff --git a/TAO/CIAO/CCF/CCF/IDL3/IDL3_SyntaxTree.hpp b/TAO/CIAO/CCF/CCF/IDL3/IDL3_SyntaxTree.hpp new file mode 100644 index 00000000000..2ea652787c5 --- /dev/null +++ b/TAO/CIAO/CCF/CCF/IDL3/IDL3_SyntaxTree.hpp @@ -0,0 +1,627 @@ +// $Id$ +#ifndef CCF_IDL3_SYNTAX_TREE_HPP +#define CCF_IDL3_SYNTAX_TREE_HPP + +#include "MSVC_Pragmas.hpp" + +#include "CCF/IDL2/IDL2_SyntaxTree.hpp" + +namespace IDL3 +{ + namespace SyntaxTree + { + // Import nodes from IDL2 + using namespace IDL2::SyntaxTree; + + + // + // + // + class ComponentDecl : public virtual TypeDecl + { + public: + virtual + ~ComponentDecl () throw () {} + + ComponentDecl (SimpleName const& name, + ScopePtr const& scope) + : Declaration (name, scope), + TypeDecl (name, scope) + { + } + + // Runtime declaration type information + public: + virtual std::string + declaration_type () + { + return "component"; + } + + + // Traversal + public: + virtual void + accept (CCF::Traversal::Visitor* v); + }; + + typedef + StrictPtr<ComponentDecl> + ComponentDeclPtr; + + typedef + DeclarationRef<ComponentDecl> + ComponentDeclRef; + + + // + // + // + class ComponentForwardDecl : public virtual ComponentDecl, + public virtual TypeForwardDecl + { + public: + virtual + ~ComponentForwardDecl () throw () {} + + ComponentForwardDecl (SimpleName const& name, + ScopePtr const& scope) + : Declaration (name, scope), + TypeDecl (name, scope), + ComponentDecl (name, scope), + TypeForwardDecl (name, scope) + { + } + + // Runtime declaration type information + public: + virtual std::string + declaration_type () + { + return "component"; + } + + + // Traversal + public: + virtual void + accept (CCF::Traversal::Visitor* v); + }; + + + + // + // + // + class ComponentDef; + + typedef + StrictPtr<ComponentDef> + ComponentDefPtr; + + typedef + DeclarationRef<ComponentDef> + ComponentDefRef; + + class ComponentDef : public virtual TypeDef, + public virtual ComponentDecl, + public virtual Scope + { + public: + virtual + ~ComponentDef () throw () {} + + class DuplicateName {}; + + ComponentDef (SimpleName const& name, + ScopePtr const& scope, + ScopedName const& inherits, + ScopedNameSet const& supports) throw (DuplicateName) + : Declaration (name, scope), + TypeDecl (name, scope), + TypeDef (name, scope), + ComponentDecl (name, scope), + Scope (name, scope), + inherits_ (scope->table (), inherits) + { + copy_supports_list (supports); + } + + ComponentDef (SimpleName const& name, + ScopePtr const& scope, + ScopedNameSet const& supports) throw (DuplicateName) + : Declaration (name, scope), + TypeDecl (name, scope), + TypeDef (name, scope), + ComponentDecl (name, scope), + Scope (name, scope), + inherits_ (scope->table ()) + { + copy_supports_list (supports); + } + + private: + void + copy_supports_list (ScopedNameSet const& supports) + { + for (ScopedNameSet::const_iterator i = supports.begin (); + i != supports.end (); + i++) + { + if (!supports_.insert ( + InterfaceDefRef (scope ()->table (), *i)).second) + { + //@@ this never happens + throw DuplicateName (); + } + } + } + + + public: + ComponentDefRef + inherits () + { + return inherits_; + } + + + public: + + typedef + InterfaceDefRefSetName::const_iterator + Iterator; + + Iterator + supports_begin () const + { + return supports_.begin (); + } + + Iterator + supports_end () const + { + return supports_.end (); + } + + // Traversal + public: + virtual void + accept (CCF::Traversal::Visitor* v); + + // Runtime declaration type information + public: + virtual std::string + declaration_type () + { + return "component"; + } + + private: + ComponentDefRef inherits_; + InterfaceDefRefSetName supports_; + }; + + typedef + DeclarationOrderComparator<ComponentDefPtr> + ComponentDefOrderComparator; + + typedef + std::set<ComponentDefPtr, ComponentDefOrderComparator> + ComponentDefSet; + + // + // + // + class ProvidesDecl : public virtual Declaration + { + public: + virtual + ~ProvidesDecl () throw () {} + + ProvidesDecl (SimpleName const& name, + ScopedName const& type, + ScopePtr const& scope) + : Declaration (name, scope), + type_ (scope->table (), type) + { + } + + public: + InterfaceDeclPtr + type () + { + return type_.resolve (); + } + + + // Runtime declaration type information + public: + virtual std::string + declaration_type () + { + return "provides"; + } + + // Traversal + public: + virtual void + accept (CCF::Traversal::Visitor* v); + + private: + InterfaceDeclRef type_; + }; + + + // + // + // + class UsesDecl : public virtual Declaration + { + public: + virtual + ~UsesDecl () throw () {} + + UsesDecl (SimpleName const& name, + ScopedName const& type, + ScopePtr const& scope) + : Declaration (name, scope), + type_ (scope->table (), type) + + { + } + + public: + TypeDeclPtr + type () + { + return type_.resolve (); + } + + + // Runtime declaration type information + public: + virtual std::string + declaration_type () + { + return "uses"; + } + + // Traversal + public: + virtual void + accept (CCF::Traversal::Visitor* v); + + private: + TypeDeclRef type_; + }; + + + // + // + // + class PublishesDecl : public virtual Declaration + { + public: + virtual + ~PublishesDecl () throw () {} + + PublishesDecl (SimpleName const& name, + ScopedName const& type, + ScopePtr const& scope) + : Declaration (name, scope), + type_ (scope->table (), type) + { + } + + public: + TypeDeclPtr + type () + { + return type_.resolve (); + } + + + // Runtime declaration type information + public: + virtual std::string + declaration_type () + { + return "publishes"; + } + + // Traversal + public: + virtual void + accept (CCF::Traversal::Visitor* v); + + private: + TypeDeclRef type_; + }; + + + // + // + // + class EmitsDecl : public virtual Declaration + { + public: + virtual + ~EmitsDecl () throw () {} + + EmitsDecl (SimpleName const& name, + ScopedName const& type, + ScopePtr const& scope) + : Declaration (name, scope), + type_ (scope->table (), type) + { + } + + public: + TypeDeclPtr + type () + { + return type_.resolve (); + } + + + // Runtime declaration type information + public: + virtual std::string + declaration_type () + { + return "emits"; + } + + // Traversal + public: + virtual void + accept (CCF::Traversal::Visitor* v); + + private: + TypeDeclRef type_; + }; + + + // + // + // + class ConsumesDecl : public virtual Declaration + { + public: + virtual + ~ConsumesDecl () throw () {} + + ConsumesDecl (SimpleName const& name, + ScopedName const& type, + ScopePtr const& scope) + : Declaration (name, scope), + type_ (scope->table (), type) + { + } + + public: + TypeDeclPtr + type () + { + return type_.resolve (); + } + + + // Runtime declaration type information + public: + virtual std::string + declaration_type () + { + return "consumes"; + } + + // Traversal + public: + virtual void + accept (CCF::Traversal::Visitor* v); + + private: + TypeDeclRef type_; + }; + + + + // According to the spec Home cannot be forward-declared. Did they + // goof again? - you would probably think... + // + + class HomeDef; + + typedef + StrictPtr<HomeDef> + HomeDefPtr; + + typedef + DeclarationRef<HomeDef> + HomeDefRef; + + class HomeDef : public virtual TypeDef, + public virtual Scope + { + public: + virtual + ~HomeDef () throw () {} + + class DuplicateName {}; + + HomeDef (SimpleName const& name, + ScopePtr const& scope, + ScopedName const& inherits, + ScopedNameSet const& supports, + ScopedName const& manages) throw (DuplicateName) + + : Declaration (name, scope), + TypeDecl (name, scope), + TypeDef (name, scope), + Scope (name, scope), + inherits_ (scope->table (), inherits), + manages_ (scope->table (), manages) + { + copy_supports_list (supports); + } + + HomeDef (SimpleName const& name, + ScopePtr const& scope, + ScopedNameSet const& supports, + ScopedName const& manages) throw (DuplicateName) + + : Declaration (name, scope), + TypeDecl (name, scope), + TypeDef (name, scope), + Scope (name, scope), + inherits_ (scope->table ()), + manages_ (scope->table (), manages) + { + copy_supports_list (supports); + } + + private: + void + copy_supports_list (ScopedNameSet const& supports) + { + for (ScopedNameSet::const_iterator i = supports.begin (); + i != supports.end (); + i++) + { + if (!supports_.insert ( + InterfaceDefRef (scope ()->table (), *i)).second) + { + //@@ this never happens + throw DuplicateName (); + } + } + } + + public: + HomeDefRef + inherits () + { + return inherits_; + } + + public: + typedef + InterfaceDefRefSetName::const_iterator + Iterator; + + Iterator + supports_begin () + { + return supports_.begin (); + } + + Iterator + supports_end () + { + return supports_.end (); + } + + public: + ComponentDefPtr + manages () const + { + return manages_.resolve (); + } + + // Runtime declaration type information + public: + virtual std::string + declaration_type () + { + return "home"; + } + + // Traversal + public: + virtual void + accept (CCF::Traversal::Visitor* v); + + private: + HomeDefRef inherits_; + InterfaceDefRefSetName supports_; + ComponentDefRef manages_; + }; + + typedef + DeclarationOrderComparator<HomeDefPtr> + HomeDefOrderComparator; + + typedef + std::set<HomeDefPtr, HomeDefOrderComparator> + HomeDefSet; + + + // + // + // + class HomeFactoryParameter : public virtual OperationParameter + { + public: + virtual + ~HomeFactoryParameter () throw () + { + } + + HomeFactoryParameter (ScopedName type, + SimpleName name, + DeclarationTable const& table) + : OperationParameter (Direction::IN, type, name, table) + { + } + }; + + typedef + StrictPtr<HomeFactoryParameter> + HomeFactoryParameterPtr; + + // + // + // + class HomeFactoryDecl : public virtual OperationDecl + { + public: + virtual + ~HomeFactoryDecl () throw () {} + + HomeFactoryDecl (SimpleName const& name, + ScopedName const& type, + ScopePtr const& scope) + : Declaration (name, scope), + OperationDecl (name, type, scope) + { + } + + //@@ It would be nice to be able to kind of virtual override + // type () mf from OperationDecl with covariant return type + // technique. + + + // Runtime declaration type information + public: + virtual std::string + declaration_type () + { + return "home factory"; + } + + // Traversal + public: + virtual void + accept (CCF::Traversal::Visitor* v); + }; + typedef + StrictPtr<HomeFactoryDecl> + HomeFactoryDeclPtr; + } +} + +//@@ tmp +#include "CCF/IDL3/IDL3_SyntaxTree_EventType.hpp" + +#endif // CCF_IDL3_SYNTAX_TREE_HPP diff --git a/TAO/CIAO/CCF/CCF/IDL3/IDL3_SyntaxTreeFwd.hpp b/TAO/CIAO/CCF/CCF/IDL3/IDL3_SyntaxTreeFwd.hpp new file mode 100644 index 00000000000..d581ad0daa5 --- /dev/null +++ b/TAO/CIAO/CCF/CCF/IDL3/IDL3_SyntaxTreeFwd.hpp @@ -0,0 +1,69 @@ +// $Id$ +#ifndef CCF_IDL3_SYNTAX_TREE_FWD_HPP +#define CCF_IDL3_SYNTAX_TREE_FWD_HPP + +#include "MSVC_Pragmas.hpp" + +#include "CCF/IDL2/IDL2_SyntaxTreeFwd.hpp" + +namespace IDL3 +{ + namespace SyntaxTree + { + // Import all nodes of IDL2 + using namespace IDL2::SyntaxTree; + + class ComponentDecl; + typedef + StrictPtr<ComponentDecl> + ComponentDeclPtr; + + class ComponentDef; + typedef + StrictPtr<ComponentDef> + ComponentDefPtr; + + class ProvidesDecl; + typedef + StrictPtr<ProvidesDecl> + ProvidesDeclPtr; + + class UsesDecl; + typedef + StrictPtr<UsesDecl> + UsesDeclPtr; + + class PublishesDecl; + typedef + StrictPtr<PublishesDecl> + PublishesDeclPtr; + + class EmitsDecl; + typedef + StrictPtr<EmitsDecl> + EmitsDeclPtr; + + class ConsumesDecl; + typedef + StrictPtr<ConsumesDecl> + ConsumesDeclPtr; + + class HomeDef; + typedef + StrictPtr<HomeDef> + HomeDefPtr; + + class HomeFactoryDecl; + typedef + StrictPtr<HomeFactoryDecl> + HomeFactoryDeclPtr; + + //@@ should it be here or in separate file? + class ConcreteEventTypeDef; + typedef + StrictPtr<ConcreteEventTypeDef> + ConcreteEventTypeDefPtr; + } +} + +#endif // CCF_IDL3_SYNTAX_TREE_FWD_HPP diff --git a/TAO/CIAO/CCF/CCF/IDL3/IDL3_SyntaxTree_EventType.cpp b/TAO/CIAO/CCF/CCF/IDL3/IDL3_SyntaxTree_EventType.cpp new file mode 100644 index 00000000000..bd8ad6e7186 --- /dev/null +++ b/TAO/CIAO/CCF/CCF/IDL3/IDL3_SyntaxTree_EventType.cpp @@ -0,0 +1,22 @@ +// $Id$ +#include "IDL3_Traversal.hpp" +#include "IDL3_SyntaxTree_EventType.hpp" + +namespace IDL3 +{ + namespace SyntaxTree + { + using CCF::Traversal::try_visit; + + void ConcreteEventTypeDef:: + accept (CCF::Traversal::Visitor* v) + { + ConcreteEventTypeDefPtr self (ReferenceCounting::add_ref (this)); + + try_visit<Traversal::ConcreteEventTypeDef> ( + &Traversal::ConcreteEventTypeDef::visit_concrete_event_type_def, + v, + self); + } + } +} diff --git a/TAO/CIAO/CCF/CCF/IDL3/IDL3_SyntaxTree_EventType.hpp b/TAO/CIAO/CCF/CCF/IDL3/IDL3_SyntaxTree_EventType.hpp new file mode 100644 index 00000000000..ff8004c7829 --- /dev/null +++ b/TAO/CIAO/CCF/CCF/IDL3/IDL3_SyntaxTree_EventType.hpp @@ -0,0 +1,215 @@ +// $Id$ +#ifndef CCF_IDL3_SYNTAX_TREE_VALUE_HPP +#define CCF_IDL3_SYNTAX_TREE_VALUE_HPP + +#include "MSVC_Pragmas.hpp" + +#include "CCF/IDL2/IDL2_SyntaxTree_Value.hpp" + +namespace IDL3 +{ + namespace SyntaxTree + { + // Import nodes from IDL2 + using namespace IDL2::SyntaxTree; + + // + // + // + class EventTypeDecl : public virtual ValueDecl + { + public: + virtual + ~EventTypeDecl () throw () {} + + EventTypeDecl (SimpleName const& name, + ScopePtr const& scope) + : Declaration (name, scope), + TypeDecl (name, scope), + ValueDecl (name, scope) + { + } + + // Runtime declaration type information + public: + virtual std::string + declaration_type () + { + return "event type"; + } + + // Traversal + public: + virtual void + accept (CCF::Traversal::Visitor* v) + { + } + + }; + + typedef + StrictPtr<EventTypeDecl> + EventTypeDeclPtr; + + + // + // + // + class EventTypeForwardDecl : public virtual ValueForwardDecl, + public virtual EventTypeDecl + { + public: + virtual + ~EventTypeForwardDecl () throw () {} + + EventTypeForwardDecl (SimpleName const& name, + ScopePtr const& scope) + : Declaration (name, scope), + TypeDecl (name, scope), + ValueDecl (name, scope), + TypeForwardDecl (name, scope), + ValueForwardDecl (name, scope), + EventTypeDecl (name, scope) + { + } + + // Runtime declaration type information + public: + virtual std::string + declaration_type () + { + return "event type"; + } + }; + + // + // + // + class EventTypeDef : public virtual EventTypeDecl, + public virtual ValueDef + { + public: + virtual + ~EventTypeDef () throw () {} + + EventTypeDef (SimpleName const& name, + ScopePtr const& scope, + ScopedNameSet const& inherits) + : Declaration (name, scope), + TypeDecl (name, scope), + ValueDecl (name, scope), + EventTypeDecl (name, scope), + TypeDef (name, scope), + Scope (name, scope), + ValueDef (name, scope, inherits) + { + } + + // Runtime declaration type information + public: + virtual std::string + declaration_type () + { + return "event type"; + } + + // Traversal + public: + virtual void + accept (CCF::Traversal::Visitor* v) + { + } + + }; + + + // + // + // + class ConcreteEventTypeDecl : public virtual EventTypeDecl + { + public: + virtual + ~ConcreteEventTypeDecl () throw () {} + + ConcreteEventTypeDecl (SimpleName const& name, + ScopePtr const& scope) + : Declaration (name, scope), + TypeDecl (name, scope), + ValueDecl (name, scope), + EventTypeDecl (name, scope) + { + } + + // Runtime declaration type information + public: + virtual std::string + declaration_type () + { + return "concrete event type"; + } + + // Traversal + public: + virtual void + accept (CCF::Traversal::Visitor* v) + { + } + + }; + + + // + // + // + class ConcreteEventTypeDef : public virtual ConcreteEventTypeDecl, + public virtual EventTypeDef + { + public: + virtual + ~ConcreteEventTypeDef () throw () {} + + ConcreteEventTypeDef (SimpleName const& name, + ScopePtr const& scope, + ScopedNameSet const& inherits) + : Declaration (name, scope), + TypeDecl (name, scope), + ValueDecl (name, scope), + EventTypeDecl (name, scope), + ConcreteEventTypeDecl (name, scope), + TypeDef (name, scope), + Scope (name, scope), + ValueDef (name, scope, inherits), + EventTypeDef (name, scope, inherits) + { + } + + // Runtime declaration type information + public: + virtual std::string + declaration_type () + { + return "concrete event type"; + } + + // Traversal + public: + virtual void + accept (CCF::Traversal::Visitor* v); + }; + + typedef + StrictPtr<ConcreteEventTypeDef> + ConcreteEventTypeDefPtr; + + typedef + DeclarationOrderComparator<ConcreteEventTypeDefPtr> + ConcreteEventTypeDefOrderComparator; + + typedef + std::set<ConcreteEventTypeDefPtr, ConcreteEventTypeDefOrderComparator> + ConcreteEventTypeDefSet; + } +} + +#endif // CCF_IDL3_SYNTAX_TREE_VALUE_HPP diff --git a/TAO/CIAO/CCF/CCF/IDL3/IDL3_Traversal.cpp b/TAO/CIAO/CCF/CCF/IDL3/IDL3_Traversal.cpp new file mode 100644 index 00000000000..a69e74b54ff --- /dev/null +++ b/TAO/CIAO/CCF/CCF/IDL3/IDL3_Traversal.cpp @@ -0,0 +1,184 @@ +// $Id$ +#include "IDL3_Traversal.hpp" + +#include "IDL3_SyntaxTree.hpp" +#include "IDL3_SyntaxTree_EventType.hpp" + +namespace IDL3 +{ + namespace Traversal + { + namespace + { + //@@ code duplication + void + iterate_scope (SyntaxTree::ScopePtr const& s, + CCF::Traversal::Visitor* v) + { + for (SyntaxTree::Scope::Iterator i = s->begin (); i != s->end (); i++) + { + (*i)->accept (v); + } + } + } + + // + // ComponentDecl + // + + void ComponentDecl:: + visit_component_decl (NodePtr const& c) + { + visit_component_decl_pre (c); + visit_component_decl_post (c); + } + + + void ComponentDecl:: + visit_component_decl_pre (NodePtr const&) + { + } + + void ComponentDecl:: + visit_component_decl_post (NodePtr const&) + { + } + + // + // ComponentDef + // + + void ComponentDef:: + visit_component_def (NodePtr const& c) + { + visit_component_def_pre (c); + visit_component_def_scope (c); + visit_component_def_post (c); + } + + + void ComponentDef:: + visit_component_def_pre (NodePtr const&) + { + } + + void ComponentDef:: + visit_component_def_scope (NodePtr const& c) + { + iterate_scope (c, this); + } + + void ComponentDef:: + visit_component_def_post (NodePtr const&) + { + } + + // + // HomeDef + // + + void HomeDef:: + visit_home_def (NodePtr const& h) + { + visit_home_def_pre (h); + visit_home_def_scope (h); + visit_home_def_post (h); + } + + void HomeDef:: + visit_home_def_pre (NodePtr const&) + { + } + + void HomeDef:: + visit_home_def_scope (NodePtr const& h) + { + iterate_scope (h, this); + } + + void HomeDef:: + visit_home_def_post (NodePtr const&) + { + } + + // + // HomeFactoryDecl + // + void HomeFactoryDecl:: + visit_home_factory_decl (NodePtr const& n) + { + visit_home_factory_decl_pre (n); + visit_home_factory_decl_type (n); + visit_home_factory_decl_name (n); + visit_home_factory_decl_parameters (n); + visit_home_factory_decl_post (n); + } + + void HomeFactoryDecl:: + visit_home_factory_decl_pre (NodePtr const& n) + { + } + + void HomeFactoryDecl:: + visit_home_factory_decl_type (NodePtr const& n) + { + if (type_) n->type ()->accept (type_); + else n->type ()->accept (this); + } + + void HomeFactoryDecl:: + visit_home_factory_decl_name (NodePtr const& n) + { + } + + void HomeFactoryDecl:: + visit_home_factory_decl_parameters (NodePtr const& n) + { + for (SyntaxTree::HomeFactoryDecl::Iterator i = n->begin (); + i != n->end (); + i++) + { + (*i)->accept (this); + + if (i + 1 != n->end ()) + { + //@@ could be HomeFactoryParameterComma + SyntaxTree::CommaPtr c (new SyntaxTree::Comma); + c->accept (this); + } + } + } + + void HomeFactoryDecl:: + visit_home_factory_decl_post (NodePtr const& n) + { + } + + // ConcreteEventTypeDef + // + // + void ConcreteEventTypeDef:: + visit_concrete_event_type_def (NodePtr const& et) + { + visit_concrete_event_type_def_pre (et); + visit_concrete_event_type_def_scope (et); + visit_concrete_event_type_def_post (et); + } + + void ConcreteEventTypeDef:: + visit_concrete_event_type_def_pre (NodePtr const&) + { + } + + void ConcreteEventTypeDef:: + visit_concrete_event_type_def_scope (NodePtr const& et) + { + iterate_scope (et, this); + } + + void ConcreteEventTypeDef:: + visit_concrete_event_type_def_post (NodePtr const&) + { + } + } +} diff --git a/TAO/CIAO/CCF/CCF/IDL3/IDL3_Traversal.hpp b/TAO/CIAO/CCF/CCF/IDL3/IDL3_Traversal.hpp new file mode 100644 index 00000000000..0b4b53c5ed1 --- /dev/null +++ b/TAO/CIAO/CCF/CCF/IDL3/IDL3_Traversal.hpp @@ -0,0 +1,175 @@ +// $Id$ +#ifndef CCF_IDL3_TRAVERSAL_HPP +#define CCF_IDL3_TRAVERSAL_HPP + +#include "MSVC_Pragmas.hpp" + +#include "CCF/IDL2/IDL2_Traversal.hpp" +#include "CCF/IDL3/IDL3_SyntaxTreeFwd.hpp" + +namespace IDL3 +{ + namespace Traversal + { + // Import visitors from IDL2 + using namespace IDL2::Traversal; + + // + // + // + struct ComponentDecl : virtual CCF::Traversal::Visitor + { + typedef + SyntaxTree::ComponentDeclPtr + NodePtr; + + virtual void visit_component_decl (NodePtr const& c); + virtual void visit_component_decl_pre (NodePtr const& c); + virtual void visit_component_decl_post (NodePtr const& c); + }; + + // + // + // + struct ComponentDef : virtual CCF::Traversal::Visitor + { + typedef + SyntaxTree::ComponentDefPtr + NodePtr; + + virtual void visit_component_def (NodePtr const& c); + virtual void visit_component_def_pre (NodePtr const& c); + virtual void visit_component_def_scope (NodePtr const& c); + virtual void visit_component_def_post (NodePtr const& c); + }; + + // + // + // + struct ProvidesDecl : virtual CCF::Traversal::Visitor + { + typedef + SyntaxTree::ProvidesDeclPtr + NodePtr; + + virtual void visit_provides_decl (NodePtr const& c) + { + } + }; + + // + // + // + struct UsesDecl : virtual CCF::Traversal::Visitor + { + typedef + SyntaxTree::UsesDeclPtr + NodePtr; + + virtual void visit_uses_decl (NodePtr const& c) + { + } + }; + + // + // + // + struct PublishesDecl : virtual CCF::Traversal::Visitor + { + typedef + SyntaxTree::PublishesDeclPtr + NodePtr; + + virtual void visit_publishes_decl (NodePtr const& c) + { + } + }; + + // + // + // + struct EmitsDecl : virtual CCF::Traversal::Visitor + { + typedef + SyntaxTree::EmitsDeclPtr + NodePtr; + + virtual void visit_emits_decl (NodePtr const& c) + { + } + }; + + // + // + // + struct ConsumesDecl : virtual CCF::Traversal::Visitor + { + typedef + SyntaxTree::ConsumesDeclPtr + NodePtr; + + virtual void visit_consumes_decl (NodePtr const& c) + { + } + }; + + // + // + // + struct HomeDef : virtual CCF::Traversal::Visitor + { + typedef + SyntaxTree::HomeDefPtr + NodePtr; + + virtual void visit_home_def (NodePtr const& h); + virtual void visit_home_def_pre (NodePtr const& h); + virtual void visit_home_def_scope (NodePtr const& h); + virtual void visit_home_def_post (NodePtr const& h); + + }; + + // + // + // + struct HomeFactoryDecl : virtual CCF::Traversal::Visitor + { + typedef + SyntaxTree::HomeFactoryDeclPtr + NodePtr; + + HomeFactoryDecl (CCF::Traversal::Visitor* type = 0) + : type_ (type) + { + } + + virtual void visit_home_factory_decl (NodePtr const& n); + + virtual void visit_home_factory_decl_pre (NodePtr const& n); + virtual void visit_home_factory_decl_type (NodePtr const& n); + virtual void visit_home_factory_decl_name (NodePtr const& n); + virtual void visit_home_factory_decl_parameters (NodePtr const& n); + virtual void visit_home_factory_decl_post (NodePtr const& n); + + private: + CCF::Traversal::Visitor* type_; + }; + + // + // + // + struct ConcreteEventTypeDef : virtual CCF::Traversal::Visitor + { + typedef + SyntaxTree::ConcreteEventTypeDefPtr + NodePtr; + + virtual void visit_concrete_event_type_def (NodePtr const& et); + virtual void visit_concrete_event_type_def_pre (NodePtr const& et); + virtual void visit_concrete_event_type_def_scope (NodePtr const& et); + virtual void visit_concrete_event_type_def_post (NodePtr const& et); + }; + } +} + +#endif // CCF_IDL3_TRAVERSAL_HPP diff --git a/TAO/CIAO/CCF/CCF/IDL3/MSVC_Pragmas.hpp b/TAO/CIAO/CCF/CCF/IDL3/MSVC_Pragmas.hpp new file mode 100644 index 00000000000..724b5b52646 --- /dev/null +++ b/TAO/CIAO/CCF/CCF/IDL3/MSVC_Pragmas.hpp @@ -0,0 +1,16 @@ +// $Id$ +#ifndef MSVC_PRAGMAS_HPP +#define MSVC_PRAGMAS_HPP + + +// Various warnings that have to be disabled for MSVC. + +// 'this' : used in base member initializer list +#pragma warning(disable:4355) +// 'class1' : inherits 'class2::member' via dominance +#pragma warning(disable:4250) +// C++ Exception Specification ignored +#pragma warning(disable:4290) + + +#endif /* MSVC_PRAGMAS_HPP */
\ No newline at end of file diff --git a/TAO/CIAO/CCF/CCF/IDL3/Makefile b/TAO/CIAO/CCF/CCF/IDL3/Makefile new file mode 100644 index 00000000000..6222a052c9a --- /dev/null +++ b/TAO/CIAO/CCF/CCF/IDL3/Makefile @@ -0,0 +1,22 @@ +# File : Makefile +# Author : Boris Kolpackov <boris@kolpackov.net> +# $Id$ + +root = ../../External/Utility + +include $(root)/Config/Archive.pre.rules + +cxx_translation_units := IDL3.cpp \ + IDL3_SyntaxTree.cpp \ + IDL3_SyntaxTree_EventType.cpp \ + IDL3_Traversal.cpp + +module_base := IDL3 +module_prefix := +module_suffix := + +CXX_PREPROCESS_FLAGS += -I../.. \ + -I../../External/Utility \ + -I../../External/boost \ + +include $(root)/Config/Archive.post.rules diff --git a/TAO/CIAO/CCF/CCF/Makefile b/TAO/CIAO/CCF/CCF/Makefile new file mode 100644 index 00000000000..d2fc5f62489 --- /dev/null +++ b/TAO/CIAO/CCF/CCF/Makefile @@ -0,0 +1,14 @@ +# file : CCF/Makefile +# author : Boris Kolpackov <boris@kolpackov.net> +# copyright : Copyright (c) 2002-2003 Boris Kolpackov +# license : http://kolpackov.net/license.html +# cvs-id : $Id$ + +root := .. + +include $(root)/External/Utility/Config/Recursion.pre.rules + +target_makefile_list := +target_directory_list := IDL2 IDL3 CIDL CodeGenerationKit + +include $(root)/External/Utility/Config/Recursion.post.rules diff --git a/TAO/CIAO/CCF/DesignNotes b/TAO/CIAO/CCF/DesignNotes new file mode 100644 index 00000000000..b01fd452762 --- /dev/null +++ b/TAO/CIAO/CCF/DesignNotes @@ -0,0 +1,457 @@ + +Intention of this file is to capture and document CIDL complier design +ideas/decisions. + +Conceptual parts of CIDL compiler design +---------------------------------------- + +Option Parser Consists of option parser and option + database. + +C Preprocessor Interfacing Represents mechanism of preprocessing + cidl files. + +IDL Compiler Interfacing Represents mechanism of invoking IDL + compiler. + +Scanner Scanner for preprocessed cidl file. + +Parser CIDL grammar parser. Consists of grammar + and semantic rules. + +Syntax Tree Intermediate representation of cidl file. + Consists of syntax tree nodes itself and + perhaps symbol tables. + +Semantic Analyzer Traverses Syntax Tree and performs + semantic analysis as well as some + semantic expansions. + + +Code Generation Stream Stream to output generated code to. Used + by concrete Code Generators + +Code Generators +{ + + Executor Mapping Generator Generator for local executor mapping. + + Executor Implementation Generator Generator for partial implementation + of local executor mapping. + + Skeleton Thunk Generator Generator for skeleton thunks i.e. + code that implements skeleton and + thunks user-defined functions to + executor mapping. +} + +Compiler driver Establishes order of execution of + different components as part of + compilation process. + + +How everything works together +----------------------------- + +(1) Compiler Driver executes Option Parser to populate Option Database + +(2) Compiler Driver executes C Preprocessor on a supplied cidl file + +(3) Compiler Driver executes Parser which uses Scanner to scan preprocessed + cidl file and generates Syntax Tree by means of semantic rules. + +(4) At this point we have Syntax Tree corresponding to the original cidl + file. Compiler Driver executes Executor Mapping Generator, + Executor Implementation Generator and Skeleton Thunk Generator on + Syntax Tree. + + + +General Design Ideas/Decision +------------- + +[IDEA]: There is an effort to use autoconf/automake in ACE/TAO. Maybe it's + a good idea to start using it with CIDLC? There is one side advantage + of this approach: if we decide to embed GCC CPP then we will have to + use configure (or otherwise ACE-ify the code which doesn't sound like + a right solution). + +[IDEA]: CIDLC is a prototype for a new IDLC, PSDLC and IfR model. Here are + basic concepts: + + - use common IDL grammar, semantic rules and syntax tree nodes + for IDLC, CIDLC, PSDLC and IfR. Possibly have several libraries + for example ast_idl-2.so, ast_idl-3.so, scaner_idl-2.so + scaner_idl-3.so, parser_idl-2.so, parser_idl-3.so. Dependency + graph would look like this: + + + ast_idl-2.so scanner_idl-2.so + | | + |---------------------------------| + | | | + | | | + | parser_idl-2.so | + | | | + ast_idl-3.so | scanner_idl-3.so + | | | + | | | + | | | + ---------parser_idl-3.so--------- + + Same idea applies for CIDL and PSDL. + + + - use the same internal representation (syntax tree) in all + compilers and IfR. This way at some stage if we will need + to make one of the compilers IfR-integrated (import keyword?) + then it will be a much easier task than it's now. This internal + representation may also be usable in typecodes + + @@ boris: not clear to me. + + @@ jeff: A typecode is like a piece of the Syntax Tree with these + exceptions - + + (1) There is no typecode for an IDL module. + + (2) Typecodes for interfaces and valuetypes lack some of the + information in the corresponding Syntax Tree nodes. + + With these exceptions in mind, a typecode can be composed and + traversed in the same manner as a Syntax Tree, perhaps with + different classes than used to compose the ST itself. + + @@ boris: Ok, let me see if I got it right. So when typecode + is kept in parsed state (as opposite to binary) (btw, when + does it happen?) it makes sense to apply the same techniques + (if in fact not the same ST nodes and traversal mechs) as + for XIDL compilation. + +[IDEA]: We should be consistent with the way external compilers that we call + report errors. For now those are CPP and IDLC. + +Option Parser +------------- + +[IDEA]: Use Spirit parser framework to generate option parser. + +[IDEA]: Option Database is probably a singleton. + + @@ jeff: This is a good idea, especially when passing some of the + options to a preprocessor or spawned IDL compier. But I think we + will still need 'state' classes for the front and back ends (to + hold values set by command line options and default values) so + we can keep them decoupled). + + + @@ boris: I understand what you mean. Though I think we will be + able to do with one 'runtime database'. Each 'compiler module' + will be able to populate its 'namespace' with (1) default + values, (2) with module-specific options and (3) arbitrary + runtime information. I will present prototopy design shortly. + + +[IDEA]: It seems we will have to execute at least two external programs + as part of CIDLC execution: CPP and IDLC. Why wouldn't we follow + GCC specs model (gcc -dumpspecs). Here are candidates to be put into + specs: + + - default CPP name and options + - default IDLC name and options + - default file extensions and formats for different mappings + - other ideas? + +[IDEA]: Provide short and long option names (e.g. -o and --output-dir) + for every option (maybe except -I, -D, etc). + + +C Preprocessor Interfacing +-------------------------- + +[IDEA]: Embed/require GCC CPP + +[IDEA]: We need a new model of handling includes in CIDLC (as well as IDLC). + Right now I'm mentally testing a new model (thanks to Carlos for the + comments). Soon I will put the description here. + +[IDEA]: We cannot move cidl file being preprocessed to for example /tmp + as it's currently the case with IDLC. + +[IDEA]: Can we use pipes (ACE Pipes) portably to avoid temporary files? + (Kitty, you had some ideas about that?) + + + +IDL Compiler Interfacing +------------------------ + +[IDEA]: Same as for CPP: Can we use pipes? + + @@ jeff: check with Nanbor on this. I think there may be CCM/CIAO + use cases where we need the intermediate IDL file. + +[IDEA]: Will need a mechanism to pass options to IDLC from CIDLC command + line (would be nice to have this ability for CPP as well). + Something like -x in xterm? Better ideas? + + + +Scanner +------ + +[IDEA]: Use Spirit framework to construct scanner. The resulting sequence + can be sequence of objects? BTW, Spirit parser expects a "forward + iterator"-based scanner. So this basically mean that we may have to + keep the whole sequence in memory. BTW, this is another good reason + to have scanner: if we manage to make scanner a predictable parser + (i.e. no backtracking) then we don't have to keep the whole + preprocessed cidl file in memory. + + + +Parser +------ + +[IDEA]: Use Spirit framework to construct parser. + +[IDEA]: Define IDL grammar as a number of grammar capsules. This way it's + much easier to reuse/inherit even dynamically. Need to elaborate + this idea. + +[IDEA]: Use functors as semantic actions. This way we can specify (via + functor's data member) on which Syntax Tree they are working. + Bad side: semantic rules are defined during grammar construction. + However we can use a modification of the factory method pattern. + Better ideas? + + @@ jeff: I think ST node creation with a factory + is a good idea - another ST implementation could be plugged in, + as long as it uses a factory with the same method names. + + @@ boris: Right. In fact it's our 'improved' way of handling 'BE' + usecases. + + + +Syntax Tree +----------- + +[IDEA]: Use interface repository model as a base for Syntax Tree hierarchy. + +[IDEA]: Currently (in IDLC) symbol lookup is accomplished by AST navigation, + and is probably the biggest single bottleneck in performance. Perhaps + a separate symbol table would be preferable. Also, lookups could be + specialized, e.g., for declaration, for references, and perhaps a + third type for argument-related lookups. + +[NOTE]: If we are to implement symbol tables then we need to think how we + are going to inherit (extend) this tables. + +[NOTE]: Inheritance/supports graphs: these graphs need to be traversed at + several points in the back end. Currently they are rebuilt for each + use, using an n-squared algorithm. We could at least build them only + once for each interface/valuetype, perhaps even with a better + algorithm. It could be integrated into inheritance/supports error + checking at node creation time, which also be streamlined. + + @@ boris: Well, I think we should design our Syntax Tree so that + every interface/valuetype has a list (flat?) of interfaces it + inherits from/supports. + +[IDEA]: We will probably want to use factories to instantiate Syntax Tree + Nodes (STN). This will allow a concrete code generators to alter (i.e. + inherit off and extend) vanilla STNs (i.e. alternative to BE nodes + in current IDLC design). + + +Common Syntax Tree traversal Design Ideas/Decision +-------------------------------------------------- + +[IDEA] If we specify Syntax Tree traversal facility then we will be able + to specify (or even plug dynamically) Syntax Tree traversal agents + that may not only generate something but also annotate or modify + Syntax Tree. We are already using this technique for a number of + features (e.g. AMI, IDL3 extension, what else?) but all these agents + are hardwired inside TAO IDLC. If we have this facility then we will + be able to produce modular and highly extensible design. Notes: + + - Some traversal agents can change Syntax Tree so that it will be + unusable by some later traversal agents. So maybe the more + generic approach would be to produce new Syntax Tree? + + @@ jeff: Yes, say for example that we were using a common ST + representation for the IDL compiler and the IFR. We would not + want to send the extra AMI nodes to the IFR so in that case + simple modification of the ST might not be best. + +[IDEA] Need a generic name for "Syntax Tree Traversal Agents". What about + "Syntax Tree Traverser"? + + +Code Generation Stream +---------------------- + +[IDEA] Use language indentation engines for code generation (like a c-mode + in emacs). The idea is that code like this + + out << "long foo (long arg0, " << endl + << " long arg1) " << endl + << "{ " << endl + << " return arg0 + arg1; " << endl + << "} " << endl; + + will result in a generated code like this: + + namespace N + { + ... + + long foo (long arg0, + long arg1) + { + return arg0 + arg1; + } + + ... + } + + Note that no special actions were taken to ensure proper indentation. + Instead the stream's indentation engine is responsible for that. + The same mech can be used for different languages (e.g. XML). + + +Code Generators +--------------- + +[IDEA] It makes sense to establish a general concept of code generators. + "Executor Mapping Generator", "Executor Implementation Generator" + and "Skeleton Thunk Generator" would be a concrete code generators. + +[IDEA] Expression evaluation: currently the result (not the expression) + is generated, which may not always be necessary. + + @@ boris: I would say may not always be correct + + + However, for purposes of type coercion and other checking (such as + for positive integer values in string, array and sequence bounds) + evaluation must be done internally. + + @@ boris: note that evaluation is needed to only verify that things + are correct. You don't have to (shouldn't?) substitute original + (const) expression with what's been evaluated. + + + @@ jeff: it may be necessary in some cases to append 'f' or 'U' to + a generated number to avoid a C++ compiler warning. + + @@ boris: shouldn't this 'f' and 'U' be in IDL as well? + +[IDEA] I wonder if it's a good idea to use a separate pass over syntax tree + for semantic checking (e.g. type coercion, positive values for + sequence bounds). + + @@ jeff: This may hurt performance a little - more lookups - but it + will improve error reporting. + + @@ boris: As we dicussed earlier this pass could be used to do + 'semantic expansions' (e.g. calculate a flat list of interface's + children, etc). Also I don't think we should worry about speed + very much here (of course I don't say we have to be stupid ;-) + In fact if we are trading better design vs faster compilation + at this stage we should always go for better design. + + +Executor Mapping Generator +-------------------------- + + + +Executor Implementation Generator +-------------------------------- + +[IDEA]: Translate CIDL composition to C++ namespace. + + + +Skeleton Thunk Generator +------------------------ + + + + +Compiler driver +--------------- + + + +Vault +----- + +Some thoughts from Jeff that I are not directly related to CIDLC and are +rather current IDLC design defects: + +* AMI/AMH implied IDL: more can be done in the BE preprocessing pass, + hopefully eliminating a big chunk of the huge volume of AMI/AMH visitor + code. The implied IDL generated for CCM types, for example, leaves almost + nothing extra for the visitors to do. + +* Fwd decl redefinition: forward declaration nodes all initially contain a + heap-allocated dummy full-definition member, later replaced by a copy + of the full definition. This needs to be streamlined. + +* Memory leaks: inconsistent copying/passing policies make it almost + impossible to eliminate the huge number of leaks. The front end will be + more and more reused, and it may be desirable to make it executable as a + function call, in which case it will important to eliminate the leaks. + Perhaps copying of AST nodes can be eliminated with reference counting or + just with careful management, similarly for string identifiers and literals. + Destroy() methods have been put in all the node classes, and are called + recursively from the AST root at destruction time, but they are far from + doing a complete job. + +* Visitor instantiation: the huge visitor factory has already been much + reduced, and the huge enum of context state values is being reduced. + However there will still be an abundance of switch statements at nearly + every instance of visitor creation at scope nesting. We could make better + use of polymorphism to get rid of them. + +* Node narrowing: instead of the impenetrable macros we use now, we + could either generate valuetype-like downcast methods for the (C)IDL + types, or we could just use dynamic_cast. + +* Error reporting: making error messages more informative, and error recovery + could both be a lot better, as they are in most other IDL compilers. If a + recursive descent parser is used (such as Spirit), there is a simple + generic algorithm for error recovery. + + +* FE/BE node classes: if BE node classes are implemented at all, there should + be a complete separation of concerns - BE node classes should contain only + info related to code generation, and FE node classes should contain only + info related to the AST representation. As the front end becomes more + modular and reusable, this will become more and more necessary. + + @@ boris: It doesn't seem we will need two separate and parallel hierarhies. + +* Undefined fwd decls: now that we have dropped support for platforms without + namespaces, the code generated for fwd declarations not defined in the same + translation unit can be much improved, most likely by the elimination of + generated flat-name global methods, and perhaps other improvements as well. + +* Strategized code generation: many places now have either lots of + duplication, or an explosion of branching in a single visitor. Adding code + generation for use cases incrementally may give us an opportunity to + refactor and strategize it better. + +* Node generator: this class does nothing more than call 'new' and pass + unchanged the arguments it gets to the appropriate constructor - it can be + eliminated. + +* Virtual methods: there are many member functions in the IDL compiler that + are needlessly virtual. + +* Misc. leveraging: redesign of mechanisms listed above can have an effect + on other mechanisms, such as the handling of pragma prefix, typeprefix, and + reopened modules. diff --git a/TAO/CIAO/CCF/External/Utility/Config/Archive.gcc.post.rules b/TAO/CIAO/CCF/External/Utility/Config/Archive.gcc.post.rules new file mode 100644 index 00000000000..b43e4d01363 --- /dev/null +++ b/TAO/CIAO/CCF/External/Utility/Config/Archive.gcc.post.rules @@ -0,0 +1,45 @@ +# file : Config/Archive.gcc.post.rules +# author : Boris Kolpackov <boris@kolpackov.net> +# copyright : Copyright (c) 2002-2003 Boris Kolpackov +# license : http://kolpackov.net/license.html + + +# +# Note: normally you wouldn't want to change anything below. +# + +FULL_MODULE_PREFIX := $(MODULE_PREFIX)$(module_prefix) +FULL_MODULE_SUFFIX := $(module_suffix)$(MODULE_SUFFIX) +MODULE := $(FULL_MODULE_PREFIX)$(module_base)$(FULL_MODULE_SUFFIX) + +# +# Pattern rules catalog. +# { + +# Defined pattern rule to build .o from .cpp +%.o : %.cpp + $(CXX) $(CXX_PREPROCESS_FLAGS) $(CXX_COMPILE_FLAGS) -MD -MP -MT $(@:.o=.d) -MF $(@:.o=.d) -c $< -o $@ + +# Defines pattern rule to build <module> from <module>.o +$(MODULE_PREFIX)$(module_prefix)%$(module_suffix)$(MODULE_SUFFIX) : %.o + $(AR) $(AR_FLAGS) $@ $^ + +# } + +# Defines the rule to build module from tarnslated c++ translation units. +$(MODULE) : $(cxx_translation_units:.cpp=.o) + +# Defines a phony target to clean all what's been generated +.PHONY : clean +clean : + -rm -f $(cxx_translation_units:.cpp=.o) + -rm -f $(cxx_translation_units:.cpp=.d) + -rm -f $(MODULE) + -rm -f *~ + +# Include dependencies for c++ translation units. +-include $(cxx_translation_units:.cpp=.d) + + +# The following catch-all rule will skip unknown targets +%:: ;@: diff --git a/TAO/CIAO/CCF/External/Utility/Config/Archive.gcc.pre.rules b/TAO/CIAO/CCF/External/Utility/Config/Archive.gcc.pre.rules new file mode 100644 index 00000000000..148f6bfbc8a --- /dev/null +++ b/TAO/CIAO/CCF/External/Utility/Config/Archive.gcc.pre.rules @@ -0,0 +1,27 @@ +# file : Config/Archive.gcc.pre.rules +# author : Boris Kolpackov <boris@kolpackov.net> +# copyright : Copyright (c) 2002-2003 Boris Kolpackov +# license : http://kolpackov.net/license.html + +# Forces make to delete targets whos rebuild commands failed but +# updated the target. +.DELETE_ON_ERROR: + +# Empties the suffix list for which old-fassion implicit rules would +# be used. The net effect is that all predefined implicit rules are +# disabled now. +.SUFFIXES: + +CXX ?= g++ +CXX_DEP ?= $(CXX) -M + +CXX_PREPROCESS_FLAGS := +CXX_COMPILE_FLAGS := -Wall +CXX_LINK_FLAGS := +CXX_LINK_LIBS := + +AR ?= ar +AR_FLAGS := -rc + +MODULE_PREFIX := lib +MODULE_SUFFIX := .a diff --git a/TAO/CIAO/CCF/External/Utility/Config/Archive.post.rules b/TAO/CIAO/CCF/External/Utility/Config/Archive.post.rules new file mode 100644 index 00000000000..59aa7e59e91 --- /dev/null +++ b/TAO/CIAO/CCF/External/Utility/Config/Archive.post.rules @@ -0,0 +1,7 @@ +# file : Config/Archive.post.rules +# author : Boris Kolpackov <boris@kolpackov.net> +# copyright : Copyright (c) 2002-2003 Boris Kolpackov +# license : http://kolpackov.net/license.html + +include $(root)/Config/Archive.gcc.post.rules + diff --git a/TAO/CIAO/CCF/External/Utility/Config/Archive.pre.rules b/TAO/CIAO/CCF/External/Utility/Config/Archive.pre.rules new file mode 100644 index 00000000000..17004f6df75 --- /dev/null +++ b/TAO/CIAO/CCF/External/Utility/Config/Archive.pre.rules @@ -0,0 +1,7 @@ +# file : Config/Archive.pre.rules +# author : Boris Kolpackov <boris@kolpackov.net> +# copyright : Copyright (c) 2002-2003 Boris Kolpackov +# license : http://kolpackov.net/license.html + +include $(root)/Config/Archive.gcc.pre.rules + diff --git a/TAO/CIAO/CCF/External/Utility/Config/Documentation.post.rules b/TAO/CIAO/CCF/External/Utility/Config/Documentation.post.rules new file mode 100644 index 00000000000..a4b69a2debe --- /dev/null +++ b/TAO/CIAO/CCF/External/Utility/Config/Documentation.post.rules @@ -0,0 +1,35 @@ +# file : Config/Documentation.post.rules +# author : Boris Kolpackov <boris@kolpackov.net> +# copyright : Copyright (c) 2002-2003 Boris Kolpackov +# license : http://kolpackov.net/license.html + +# +# Note: normally you wouldn't want to change anything below. +# + +# +# Pattern rules catalog. +# { + +# Defined pattern rule to build .hpp.html from .hpp +%.html : % + $(DOC) $(DOC_FLAGS) -o $@ $< + +# } + +# The following rule will inhibit treatment of documentation as +# default target. +.PHONY : all +all: ;@: + +.PHONY : documentation +documentation : $(patsubst %,%.html,$(doc_translation_units)) + +# Defines a phony target to clean all what's been generated +.PHONY : clean +clean : + -rm -f $(patsubst %,%.html,$(doc_translation_units)) + +# The following catch-all rule will skip unknown targets +%:: ;@: + diff --git a/TAO/CIAO/CCF/External/Utility/Config/Documentation.pre.rules b/TAO/CIAO/CCF/External/Utility/Config/Documentation.pre.rules new file mode 100644 index 00000000000..6d89b37ffda --- /dev/null +++ b/TAO/CIAO/CCF/External/Utility/Config/Documentation.pre.rules @@ -0,0 +1,17 @@ +# file : Config/Documentation.pre.rules +# author : Boris Kolpackov <boris@kolpackov.net> +# copyright : Copyright (c) 2002-2003 Boris Kolpackov +# license : http://kolpackov.net/license.html + +# Forces make to delete targets whos rebuild commands failed but +# updated the target. +.DELETE_ON_ERROR: + +# Empties the suffix list for which old-fassion implicit rules would +# be used. The net effect is that all predefined implicit rules are +# disabled now. +.SUFFIXES: + +DOC ?= cpp_to_html +CXX_FLAGS := + diff --git a/TAO/CIAO/CCF/External/Utility/Config/Executable.gcc.post.rules b/TAO/CIAO/CCF/External/Utility/Config/Executable.gcc.post.rules new file mode 100644 index 00000000000..548b2737661 --- /dev/null +++ b/TAO/CIAO/CCF/External/Utility/Config/Executable.gcc.post.rules @@ -0,0 +1,49 @@ +# file : Config/Executable.gcc.post.rules +# author : Boris Kolpackov <boris@kolpackov.net> +# copyright : Copyright (c) 2002-2003 Boris Kolpackov +# license : http://kolpackov.net/license.html + +# +# Note: normally you wouldn't want to change anything below. +# + +FULL_MODULE_PREFIX := $(MODULE_PREFIX)$(module_prefix) +FULL_MODULE_SUFFIX := $(module_suffix)$(MODULE_SUFFIX) +MODULE := $(FULL_MODULE_PREFIX)$(module_base)$(FULL_MODULE_SUFFIX) + +# +# Pattern rules catalog. +# { + +# Defined pattern rule to build .o from .cpp +%.o : %.cpp + $(CXX) $(CXX_PREPROCESS_FLAGS) $(CXX_COMPILE_FLAGS) -MD -MP -MT $(@:.o=.d) -MF $(@:.o=.d) -c $< -o $@ + +# Defines pattern rule to build <module> from <module>.o +$(MODULE_PREFIX)$(module_prefix)%$(module_suffix)$(MODULE_SUFFIX) : %.o + $(CXX) $(CXX_LINK_FLAGS) -o $@ $^ $(CXX_LINK_LIBS) + +# } + +# Defines the rule to build module from tarnslated c++ translation units. +$(MODULE) : $(cxx_translation_units:.cpp=.o) + +# Defines a phony target to clean all what's been generated +.PHONY : clean +clean : + -rm -f $(cxx_translation_units:.cpp=.o) + -rm -f $(cxx_translation_units:.cpp=.d) + -rm -f $(MODULE) + -rm -f *~ + +# Define a phony target to invoke the test driver. +.PHONY : test +test : $(MODULE) + ./$(MODULE) + +# Include dependencies for c++ translation units. +-include $(cxx_translation_units:.cpp=.d) + +# The following catch-all rule will skip unknown targets +%:: ;@: + diff --git a/TAO/CIAO/CCF/External/Utility/Config/Executable.gcc.pre.rules b/TAO/CIAO/CCF/External/Utility/Config/Executable.gcc.pre.rules new file mode 100644 index 00000000000..770e19f3dc9 --- /dev/null +++ b/TAO/CIAO/CCF/External/Utility/Config/Executable.gcc.pre.rules @@ -0,0 +1,25 @@ +# file : Config/Executable.gcc.pre.rules +# author : Boris Kolpackov <boris@kolpackov.net> +# copyright : Copyright (c) 2002-2003 Boris Kolpackov +# license : http://kolpackov.net/license.html + +# Forces make to delete targets whos rebuild commands failed but +# updated the target. +.DELETE_ON_ERROR: + +# Empties the suffix list for which old-fassion implicit rules would +# be used. The net effect is that all predefined implicit rules are +# disabled now. +.SUFFIXES: + +CXX ?= g++ + +CXX_PREPROCESS_FLAGS := +CXX_COMPILE_FLAGS := -Wall +CXX_LINK_FLAGS := +CXX_LINK_LIBS := + + +MODULE_PREFIX := +MODULE_SUFFIX := + diff --git a/TAO/CIAO/CCF/External/Utility/Config/Executable.generic.post.rules b/TAO/CIAO/CCF/External/Utility/Config/Executable.generic.post.rules new file mode 100644 index 00000000000..b6947246499 --- /dev/null +++ b/TAO/CIAO/CCF/External/Utility/Config/Executable.generic.post.rules @@ -0,0 +1,57 @@ +# file : Config/Executable.generic.post.rules +# author : Boris Kolpackov <boris@kolpackov.net> +# copyright : Copyright (c) 2002-2003 Boris Kolpackov +# license : http://kolpackov.net/license.html + +# +# Note: normally you wouldn't want to change anything below. +# + +FULL_MODULE_PREFIX := $(MODULE_PREFIX)$(module_prefix) +FULL_MODULE_SUFFIX := $(module_suffix)$(MODULE_SUFFIX) +MODULE := $(FULL_MODULE_PREFIX)$(module_base)$(FULL_MODULE_SUFFIX) + +# +# Pattern rules catalog. +# { + +# Defines pattern rule to build .d from .cpp +%.d: %.cpp + set -e; $(CXX_DEP) $(CXX_PREPROCESS_FLAGS) $< \ + | sed 's/\($*\)\.o[ :]*/\1.o $@ : /g' > $@; \ + [ -s $@ ] || rm -f $@ + + + +# Defined pattern rule to build .o from .cpp +%.o : %.cpp + $(CXX) $(CXX_PREPROCESS_FLAGS) $(CXX_COMPILE_FLAGS) -c $< -o $@ + +# Defines pattern rule to build <module> from <module>.o +$(MODULE_PREFIX)$(module_prefix)%$(module_suffix)$(MODULE_SUFFIX) : %.o + $(CXX) $(CXX_LINK_FLAGS) -o $@ $^ $(CXX_LINK_LIBS) + +# } + +# Defines the rule to build module from tarnslated c++ translation units. +$(MODULE) : $(cxx_translation_units:.cpp=.o) + +# Defines a phony target to clean all what's been generated +.PHONY : clean +clean : + -rm -f $(cxx_translation_units:.cpp=.o) + -rm -f $(cxx_translation_units:.cpp=.d) + -rm -f $(MODULE) + -rm -f *~ + +# Define a phony target to invoke the test driver. +.PHONY : test +test : $(MODULE) + ./$(MODULE) + +# Include dependencies for c++ translation units. +# Optimization: if we are cleaning there is no reason to calculate +# dependencies because they will be removed a second later. +ifneq ($(MAKECMDGOALS),clean) + include $(cxx_translation_units:.cpp=.d) +endif diff --git a/TAO/CIAO/CCF/External/Utility/Config/Executable.generic.pre.rules b/TAO/CIAO/CCF/External/Utility/Config/Executable.generic.pre.rules new file mode 100644 index 00000000000..13cb5cdeaf9 --- /dev/null +++ b/TAO/CIAO/CCF/External/Utility/Config/Executable.generic.pre.rules @@ -0,0 +1,25 @@ +# file : Config/Executable.generic.pre.rules +# author : Boris Kolpackov <boris@kolpackov.net> +# copyright : Copyright (c) 2002-2003 Boris Kolpackov +# license : http://kolpackov.net/license.html + +# Forces make to delete targets whos rebuild commands failed but +# updated the target. +.DELETE_ON_ERROR: + +# Empties the suffix list for which old-fassion implicit rules would +# be used. The net effect is that all predefined implicit rules are +# disabled now. +.SUFFIXES: + +CXX ?= g++ +CXX_DEP ?= $(CXX) -M + +CXX_PREPROCESS_FLAGS := +CXX_COMPILE_FLAGS := -Wall +CXX_LINK_FLAGS := +CXX_LINK_LIBS := + + +MODULE_PREFIX := +MODULE_SUFFIX := diff --git a/TAO/CIAO/CCF/External/Utility/Config/Executable.post.rules b/TAO/CIAO/CCF/External/Utility/Config/Executable.post.rules new file mode 100644 index 00000000000..c1850c716ee --- /dev/null +++ b/TAO/CIAO/CCF/External/Utility/Config/Executable.post.rules @@ -0,0 +1,7 @@ +# file : Config/Executable.post.rules +# author : Boris Kolpackov <boris@kolpackov.net> +# copyright : Copyright (c) 2002-2003 Boris Kolpackov +# license : http://kolpackov.net/license.html + +include $(root)/Config/Executable.gcc.post.rules + diff --git a/TAO/CIAO/CCF/External/Utility/Config/Executable.pre.rules b/TAO/CIAO/CCF/External/Utility/Config/Executable.pre.rules new file mode 100644 index 00000000000..999b6d2c26b --- /dev/null +++ b/TAO/CIAO/CCF/External/Utility/Config/Executable.pre.rules @@ -0,0 +1,7 @@ +# file : Config/Executable.pre.rules +# author : Boris Kolpackov <boris@kolpackov.net> +# copyright : Copyright (c) 2002-2003 Boris Kolpackov +# license : http://kolpackov.net/license.html + +include $(root)/Config/Executable.gcc.pre.rules + diff --git a/TAO/CIAO/CCF/External/Utility/Config/Recursion.post.rules b/TAO/CIAO/CCF/External/Utility/Config/Recursion.post.rules new file mode 100644 index 00000000000..866ad7a0b64 --- /dev/null +++ b/TAO/CIAO/CCF/External/Utility/Config/Recursion.post.rules @@ -0,0 +1,29 @@ +# file : Config/Recursion.post.rules +# author : Boris Kolpackov <boris@kolpackov.net> +# copyright : Copyright (c) 2002-2003 Boris Kolpackov +# license : http://kolpackov.net/license.html + +.PHONY: $(target_directory_list) $(target_makefile_list) + +_submodules:: $(target_directory_list) $(target_makefile_list) + +$(target_directory_list): + $(MAKE) -C $@ $(MAKECMDGOALS) + +$(target_makefile_list): + $(MAKE) --no-print-directory -f $@ $(MAKECMDGOALS) + +# These rules keep make from trying to use the match-anything rule below to +# rebuild the makefiles. +# +Makefile : ; +%.mk :: ; +%.rules :: ; + + +# Anything we don't know how to build will use this rule. The command is a +# do-nothing command, but the prerequisites ensure that the appropriate +# recursive invocations of make will occur. +# +% :: $(target_directory_list) $(target_makefile_list) ; + diff --git a/TAO/CIAO/CCF/External/Utility/Config/Recursion.pre.rules b/TAO/CIAO/CCF/External/Utility/Config/Recursion.pre.rules new file mode 100644 index 00000000000..4beffdcb281 --- /dev/null +++ b/TAO/CIAO/CCF/External/Utility/Config/Recursion.pre.rules @@ -0,0 +1,11 @@ +# file : Config/Recursion.pre.rules +# author : Boris Kolpackov <boris@kolpackov.net> +# copyright : Copyright (c) 2002-2003 Boris Kolpackov +# license : http://kolpackov.net/license.html + +.SUFFIXES: + +.PHONY: _submodules + +_submodules:: + diff --git a/TAO/CIAO/CCF/External/Utility/Config/Shared.gcc.post.rules b/TAO/CIAO/CCF/External/Utility/Config/Shared.gcc.post.rules new file mode 100644 index 00000000000..e6a67627768 --- /dev/null +++ b/TAO/CIAO/CCF/External/Utility/Config/Shared.gcc.post.rules @@ -0,0 +1,45 @@ +# file : Config/Shared.gcc.post.rules +# author : Boris Kolpackov <boris@kolpackov.net> +# copyright : Copyright (c) 2002-2003 Boris Kolpackov +# license : http://kolpackov.net/license.html + + +# +# Note: normally you wouldn't want to change anything below. +# + +FULL_MODULE_PREFIX := $(MODULE_PREFIX)$(module_prefix) +FULL_MODULE_SUFFIX := $(module_suffix)$(MODULE_SUFFIX) +MODULE := $(FULL_MODULE_PREFIX)$(module_base)$(FULL_MODULE_SUFFIX) + +# +# Pattern rules catalog. +# { + +# Defined pattern rule to build .o from .cpp +%.o : %.cpp + $(CXX) $(CXX_PREPROCESS_FLAGS) $(CXX_COMPILE_FLAGS) -MD -MP -MT $(@:.o=.d) -MF $(@:.o=.d) -c $< -o $@ + +# Defines pattern rule to build <module> from <module>.o +$(MODULE_PREFIX)$(module_prefix)%$(module_suffix)$(MODULE_SUFFIX) : %.o + $(CXX) $(CXX_LINK_FLAGS) -o $@ $^ $(CXX_LINK_LIBS) + +# } + +# Defines the rule to build module from tarnslated c++ translation units. +$(MODULE) : $(cxx_translation_units:.cpp=.o) + +# Defines a phony target to clean all what's been generated +.PHONY : clean +clean : + -rm -f $(cxx_translation_units:.cpp=.o) + -rm -f $(cxx_translation_units:.cpp=.d) + -rm -f $(MODULE) + -rm -f *~ + +# Include dependencies for c++ translation units. +-include $(cxx_translation_units:.cpp=.d) + + +# The following catch-all rule will skip unknown targets +%:: ;@: diff --git a/TAO/CIAO/CCF/External/Utility/Config/Shared.gcc.pre.rules b/TAO/CIAO/CCF/External/Utility/Config/Shared.gcc.pre.rules new file mode 100644 index 00000000000..b8c83c14c23 --- /dev/null +++ b/TAO/CIAO/CCF/External/Utility/Config/Shared.gcc.pre.rules @@ -0,0 +1,25 @@ +# file : Config/Shared.gcc.pre.rules +# author : Boris Kolpackov <boris@kolpackov.net> +# copyright : Copyright (c) 2002-2003 Boris Kolpackov +# license : http://kolpackov.net/license.html + +# Forces make to delete targets whos rebuild commands failed but +# updated the target. +.DELETE_ON_ERROR: + +# Empties the suffix list for which old-fassion implicit rules would +# be used. The net effect is that all predefined implicit rules are +# disabled now. +.SUFFIXES: + +CXX ?= g++ +CXX_DEP ?= $(CXX) -M + +CXX_PREPROCESS_FLAGS := +CXX_COMPILE_FLAGS := -fPIC -Wall +CXX_LINK_FLAGS := -shared +CXX_LINK_LIBS := + + +MODULE_PREFIX := lib +MODULE_SUFFIX := .so diff --git a/TAO/CIAO/CCF/External/Utility/Config/Shared.generic.post.rules b/TAO/CIAO/CCF/External/Utility/Config/Shared.generic.post.rules new file mode 100644 index 00000000000..d21cd0e5840 --- /dev/null +++ b/TAO/CIAO/CCF/External/Utility/Config/Shared.generic.post.rules @@ -0,0 +1,53 @@ +# file : Config/Shared.generic.post.rules +# author : Boris Kolpackov <boris@kolpackov.net> +# copyright : Copyright (c) 2002-2003 Boris Kolpackov +# license : http://kolpackov.net/license.html + + +# +# Note: normally you wouldn't want to change anything below. +# + +FULL_MODULE_PREFIX := $(MODULE_PREFIX)$(module_prefix) +FULL_MODULE_SUFFIX := $(module_suffix)$(MODULE_SUFFIX) +MODULE := $(FULL_MODULE_PREFIX)$(module_base)$(FULL_MODULE_SUFFIX) + +# +# Pattern rules catalog. +# { + +# Defines pattern rule to build .d from .cpp +%.d: %.cpp + set -e; $(CXX_DEP) $(CXX_PREPROCESS_FLAGS) $< \ + | sed 's/\($*\)\.o[ :]*/\1.o $@ : /g' > $@; \ + [ -s $@ ] || rm -f $@ + + + +# Defined pattern rule to build .o from .cpp +%.o : %.cpp + $(CXX) $(CXX_PREPROCESS_FLAGS) $(CXX_COMPILE_FLAGS) -c $< -o $@ + +# Defines pattern rule to build <module> from <module>.o +$(MODULE_PREFIX)$(module_prefix)%$(module_suffix)$(MODULE_SUFFIX) : %.o + $(CXX) $(CXX_LINK_FLAGS) -o $@ $^ $(CXX_LINK_LIBS) + +# } + +# Defines the rule to build module from tarnslated c++ translation units. +$(MODULE) : $(cxx_translation_units:.cpp=.o) + +# Defines a phony target to clean all what's been generated +.PHONY : clean +clean : + -rm -f $(cxx_translation_units:.cpp=.o) + -rm -f $(cxx_translation_units:.cpp=.d) + -rm -f $(MODULE) + -rm -f *~ + +# Include dependencies for c++ translation units. +# Optimization: if we are cleaning there is no reason to calculate +# dependencies because they will be removed a second later. +ifneq ($(MAKECMDGOALS),clean) + include $(cxx_translation_units:.cpp=.d) +endif diff --git a/TAO/CIAO/CCF/External/Utility/Config/Shared.generic.pre.rules b/TAO/CIAO/CCF/External/Utility/Config/Shared.generic.pre.rules new file mode 100644 index 00000000000..71fe4be0eb4 --- /dev/null +++ b/TAO/CIAO/CCF/External/Utility/Config/Shared.generic.pre.rules @@ -0,0 +1,25 @@ +# file : Config/Shared.generic.pre.rules +# author : Boris Kolpackov <boris@kolpackov.net> +# copyright : Copyright (c) 2002-2003 Boris Kolpackov +# license : http://kolpackov.net/license.html + +# Forces make to delete targets whos rebuild commands failed but +# updated the target. +.DELETE_ON_ERROR: + +# Empties the suffix list for which old-fassion implicit rules would +# be used. The net effect is that all predefined implicit rules are +# disabled now. +.SUFFIXES: + +CXX ?= g++ + +CXX_PREPROCESS_FLAGS := +CXX_COMPILE_FLAGS := -fPIC -Wall +CXX_LINK_FLAGS := -shared +CXX_LINK_LIBS := + + +MODULE_PREFIX := lib +MODULE_SUFFIX := .so + diff --git a/TAO/CIAO/CCF/External/Utility/Config/Shared.post.rules b/TAO/CIAO/CCF/External/Utility/Config/Shared.post.rules new file mode 100644 index 00000000000..0e00b9333a6 --- /dev/null +++ b/TAO/CIAO/CCF/External/Utility/Config/Shared.post.rules @@ -0,0 +1,7 @@ +# file : Config/Shared.post.rules +# author : Boris Kolpackov <boris@kolpackov.net> +# copyright : Copyright (c) 2002-2003 Boris Kolpackov +# license : http://kolpackov.net/license.html + +include $(root)/Config/Shared.gcc.post.rules + diff --git a/TAO/CIAO/CCF/External/Utility/Config/Shared.pre.rules b/TAO/CIAO/CCF/External/Utility/Config/Shared.pre.rules new file mode 100644 index 00000000000..032730f684a --- /dev/null +++ b/TAO/CIAO/CCF/External/Utility/Config/Shared.pre.rules @@ -0,0 +1,7 @@ +# file : Config/Shared.pre.rules +# author : Boris Kolpackov <boris@kolpackov.net> +# copyright : Copyright (c) 2002-2003 Boris Kolpackov +# license : http://kolpackov.net/license.html + +include $(root)/Config/Shared.gcc.pre.rules + diff --git a/TAO/CIAO/CCF/External/Utility/Config/Thoughts b/TAO/CIAO/CCF/External/Utility/Config/Thoughts new file mode 100644 index 00000000000..ffdd383d5fd --- /dev/null +++ b/TAO/CIAO/CCF/External/Utility/Config/Thoughts @@ -0,0 +1,54 @@ + +Makefile variable naming style. + +* Each target is usually invoking one or more commands of the following type: + + (1) translator which translates target's prerequsites to target(s) + + (2) arbitrary command which doesn't create target (aka PHONY targets) + +Examples of type (1) are: + + - translation of c++ source to object code + + - translation of object code to executable/shared + +Examples of type (2) are: + + - test: terget + + - clean: target + + +Some properties of these types of targets: + + (1) - usually implemented as an implicit rule + + - sometimes the same program is used as two separate translators + (e.g. CXX is used as a compiler and as a linker) + + + + (2) - seldom (never?) implemented as an implicit rule + + + +Approach #1 + +For type (1) name is derived from the translator's name e.g. + +CXX_COMPILE_FLAGS +CXX_PREPROCESS_FLAGS +CXX_LINK_FLAGS +CXX_LINK_LIBS + +CC_ +LD_ + + +For type (2) name is derived from the target's name e.g. + +TEST_FLAGS +CLEAN_FLAGS +INSTALL_FLAGS + diff --git a/TAO/CIAO/CCF/External/Utility/Documentation/ExH/Example/Makefile b/TAO/CIAO/CCF/External/Utility/Documentation/ExH/Example/Makefile new file mode 100644 index 00000000000..f76e88812ce --- /dev/null +++ b/TAO/CIAO/CCF/External/Utility/Documentation/ExH/Example/Makefile @@ -0,0 +1,24 @@ +# $Id$ +# file : Documentation/ExH/Example/Makefile +# author : Boris Kolpackov <boris@kolpackov.net> +# copyright : Copyright (c) 2002-2003 Boris Kolpackov +# license : http://kolpackov.net/license.html + +root := ../../.. + +include $(root)/Config/Documentation.pre.rules + +vpath %.cpp $(root)/Example/ExH/BadCast +vpath %.cpp $(root)/Example/ExH/Compound +vpath %.cpp $(root)/Example/ExH/HelloWorld +vpath %.cpp $(root)/Example/ExH/LogicToSystem + +doc_translation_units := bad_cast.cpp \ + compound.cpp \ + hello_world.cpp \ + logic_to_system.cpp + +DOC_FLAGS := -css $(root)/Documentation/Style/CXX.css + +include $(root)/Config/Documentation.post.rules + diff --git a/TAO/CIAO/CCF/External/Utility/Documentation/ExH/Logic/Makefile b/TAO/CIAO/CCF/External/Utility/Documentation/ExH/Logic/Makefile new file mode 100644 index 00000000000..2d7a2213ae4 --- /dev/null +++ b/TAO/CIAO/CCF/External/Utility/Documentation/ExH/Logic/Makefile @@ -0,0 +1,18 @@ +# $Id$ +# file : Documentation/ExH/Logic/Makefile +# author : Boris Kolpackov <boris@kolpackov.net> +# copyright : Copyright (c) 2002-2003 Boris Kolpackov +# license : http://kolpackov.net/license.html + +root := ../../.. + +include $(root)/Config/Documentation.pre.rules + +vpath %.hpp $(root)/Utility/ExH/Logic + +doc_translation_units := Exception.hpp DescriptiveException.hpp + +DOC_FLAGS := --strip-preprocessor -css $(root)/Documentation/Style/CXX.css + +include $(root)/Config/Documentation.post.rules + diff --git a/TAO/CIAO/CCF/External/Utility/Documentation/ExH/Makefile b/TAO/CIAO/CCF/External/Utility/Documentation/ExH/Makefile new file mode 100644 index 00000000000..6d84c4bee2b --- /dev/null +++ b/TAO/CIAO/CCF/External/Utility/Documentation/ExH/Makefile @@ -0,0 +1,14 @@ +# $Id$ +# file : Documentation/ExH/Makefile +# author : Boris Kolpackov <boris@kolpackov.net> +# copyright : Copyright (c) 2002-2003 Boris Kolpackov +# license : http://kolpackov.net/license.html + +root := ../.. + +include $(root)/Config/Recursion.pre.rules + +target_makefile_list := Makefile.documentation +target_directory_list := Logic System Example + +include $(root)/Config/Recursion.post.rules diff --git a/TAO/CIAO/CCF/External/Utility/Documentation/ExH/Makefile.documentation b/TAO/CIAO/CCF/External/Utility/Documentation/ExH/Makefile.documentation new file mode 100644 index 00000000000..b9c4cf8845e --- /dev/null +++ b/TAO/CIAO/CCF/External/Utility/Documentation/ExH/Makefile.documentation @@ -0,0 +1,18 @@ +# $Id$ +# file : Documentation/ExH/Make.doc.mk +# author : Boris Kolpackov <boris@kolpackov.net> +# copyright : Copyright (c) 2002-2003 Boris Kolpackov +# license : http://kolpackov.net/license.html + +root := ../.. + +include $(root)/Config/Documentation.pre.rules + +vpath %.hpp $(root)/Utility/ExH + +doc_translation_units := Compound.hpp + +DOC_FLAGS := --strip-preprocessor -css $(root)/Documentation/Style/CXX.css + +include $(root)/Config/Documentation.post.rules + diff --git a/TAO/CIAO/CCF/External/Utility/Documentation/ExH/News.html b/TAO/CIAO/CCF/External/Utility/Documentation/ExH/News.html new file mode 100644 index 00000000000..c2c6df5519e --- /dev/null +++ b/TAO/CIAO/CCF/External/Utility/Documentation/ExH/News.html @@ -0,0 +1,60 @@ +<!-- +// $Id$ +--> +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" + "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> + +<!-- + +file : Documentation/ExH/News.html +author : Boris Kolpackov <boris@kolpackov.net> +copyright : Copyright (c) 2003 Boris Kolpackov +license : http://kolpackov.net/license.html + +--> + +<html> + +<head> + + <title>ExH library news</title> + + <meta name="author" content="Boris Kolpackov"/> + <meta name="copyright" content="© 2001-2003 Boris Kolpackov"/> + <meta name="keywords" content="news,C++,exception,handling,model"/> + <meta name="description" content="ExH library news"/> + <meta http-equiv="Content-Language" content="en"/> + + <style type="text/css"> + body { + font-family : arial,sans-serif; + font-size : 10pt; + } + + h1 { + font-size : 12pt; + } + + </style> + +</head> + +<body> + +<div align="center"> +<table width="700" border="0" cellspacing="0" cellpadding="0"> +<tr> +<td> + +<h1>1.1.0</h1> +<ul> + <li><p>New and complete test coverage</p></li> +</ul> + + +</td> +</tr> +</table> +</div> +</body> +</html> diff --git a/TAO/CIAO/CCF/External/Utility/Documentation/ExH/System/Makefile b/TAO/CIAO/CCF/External/Utility/Documentation/ExH/System/Makefile new file mode 100644 index 00000000000..0966c220c8f --- /dev/null +++ b/TAO/CIAO/CCF/External/Utility/Documentation/ExH/System/Makefile @@ -0,0 +1,18 @@ +# $Id$ +# file : Documentation/ExH/System/Makefile +# author : Boris Kolpackov <boris@kolpackov.net> +# copyright : Copyright (c) 2002-2003 Boris Kolpackov +# license : http://kolpackov.net/license.html + +root := ../../.. + +include $(root)/Config/Documentation.pre.rules + +vpath %.hpp $(root)/Utility/ExH/System + +doc_translation_units := Exception.hpp DescriptiveException.hpp + +DOC_FLAGS := --strip-preprocessor -css $(root)/Documentation/Style/CXX.css + +include $(root)/Config/Documentation.post.rules + diff --git a/TAO/CIAO/CCF/External/Utility/Documentation/ExH/index.html b/TAO/CIAO/CCF/External/Utility/Documentation/ExH/index.html new file mode 100644 index 00000000000..6ef8e522593 --- /dev/null +++ b/TAO/CIAO/CCF/External/Utility/Documentation/ExH/index.html @@ -0,0 +1,80 @@ +<!-- +// $Id$ +--> +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" + "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> + +<!-- + +file : Documentation/ExH/index.html +author : Boris Kolpackov <boris@kolpackov.net> +copyright : Copyright (c) 2003 Boris Kolpackov +license : http://kolpackov.net/license.html + +--> + +<html> + +<head> + + <title>Utility::ExH</title> + + <meta name="author" content="Boris Kolpackov"/> + <meta name="copyright" content="© 2001-2003 Boris Kolpackov"/> + <meta name="keywords" content="C++,utility,exception,handling,model,ExH"/> + <meta name="description" content="Utility::ExH"/> + <meta http-equiv="Content-Language" content="en"/> + + <style type="text/css"> + body { + font-family : arial,sans-serif; + font-size : 10pt; + } + + h1 { + font-size : 12pt; + } + +</style> + +</head> + +<body> + +<div align="center"> +<table width="700" border="0" cellspacing="0" cellpadding="0"> +<tr> +<td> + + +<H1>Utility::ExH</H1> + +<p> +Exception Handling library was designed to promote consistent usage of +exceptions and exception handling mechanisms throughout the project. +For a quick overview of the basic idea you may want to look at these +examples:</p> + +<blockquote> + <p><a href="Example/bad_cast.cpp.html">bad_cast.cpp</a></p> + <p><a href="Example/compound.cpp.html">compound.cpp</a></p> + <p><a href="Example/hello_world.cpp.html">hello_world.cpp</a></p> + <p><a href="Example/logic_to_system.cpp.html">logic_to_system.cpp</a></p> +</blockquote> + +<p>Here are the definitions of the main blocks of the model:</p> + +<blockquote> + <p><a href="Compound.hpp.html">ExH::Compound</a></p> + <p><a href="System/Exception.hpp.html">ExH::System::Exception</a></p> + <p><a href="System/DescriptiveException.hpp.html">ExH::System::DescriptiveException</a></p> + <p><a href="Logic/Exception.hpp.html">ExH::Logic::Exception</a></p> + <p><a href="Logic/DescriptiveException.hpp.html">ExH::Logic::DescriptiveException</a></p> +</blockquote> + +</td> +</tr> +</table> +</div> +</body> +</html> diff --git a/TAO/CIAO/CCF/External/Utility/Documentation/Makefile b/TAO/CIAO/CCF/External/Utility/Documentation/Makefile new file mode 100644 index 00000000000..f37e9b02bc0 --- /dev/null +++ b/TAO/CIAO/CCF/External/Utility/Documentation/Makefile @@ -0,0 +1,14 @@ +# $Id$ +# file : Documentation/Makefile +# author : Boris Kolpackov <boris@kolpackov.net> +# copyright : Copyright (c) 2002-2003 Boris Kolpackov +# license : http://kolpackov.net/license.html + +root := .. + +include $(root)/Config/Recursion.pre.rules + +target_makefile_list := +target_directory_list := ExH ReferenceCounting Synch + +include $(root)/Config/Recursion.post.rules diff --git a/TAO/CIAO/CCF/External/Utility/Documentation/News.html b/TAO/CIAO/CCF/External/Utility/Documentation/News.html new file mode 100644 index 00000000000..9c6cacdb2ce --- /dev/null +++ b/TAO/CIAO/CCF/External/Utility/Documentation/News.html @@ -0,0 +1,69 @@ +<!-- +// $Id$ +--> +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" + "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> + +<!-- + +file : Documentation/News.html +author : Boris Kolpackov <boris@kolpackov.net> +copyright : Copyright (c) 2003 Boris Kolpackov +license : http://kolpackov.net/license.html + +--> + +<html> + +<head> + + <title>Utility library news</title> + + <meta name="author" content="Boris Kolpackov"/> + <meta name="copyright" content="© 2001-2003 Boris Kolpackov"/> + <meta name="keywords" content="news,C++,utility,exception,handling,model,reference,counting,thread,synchronization"/> + <meta name="description" content="Utility library news"/> + <meta http-equiv="Content-Language" content="en"/> + + <style type="text/css"> + body { + font-family : arial,sans-serif; + font-size : 10pt; + } + + h1 { + font-size : 12pt; + } + + </style> + +</head> + +<body> + +<div align="center"> +<table width="700" border="0" cellspacing="0" cellpadding="0"> +<tr> +<td> + +<p>Sub-library news:</p> + +<blockquote> + <p><a href="ExH/News.html">Exception Handling Library News</a></p> + <p><a href="ReferenceCounting/News.html">Reference Counting Library News</a></p> + <p><a href="Synch/News.html">Synchronization Library News</a></p> +</blockquote> + +<h1>1.1.0</h1> +<ul> + <li><p>New directory structure</p></li> + <li><p>New dependency generation mechanism</p></li> + <li><p>Automatic documentation generation (<code>make documentation</code>)</p></li> +</ul> + +</td> +</tr> +</table> +</div> +</body> +</html> diff --git a/TAO/CIAO/CCF/External/Utility/Documentation/ReferenceCounting/Makefile b/TAO/CIAO/CCF/External/Utility/Documentation/ReferenceCounting/Makefile new file mode 100644 index 00000000000..347833799f5 --- /dev/null +++ b/TAO/CIAO/CCF/External/Utility/Documentation/ReferenceCounting/Makefile @@ -0,0 +1,20 @@ +# $Id$ +# file : Documentation/ReferenceCounting/Make.doc.mk +# author : Boris Kolpackov <boris@kolpackov.net> +# copyright : Copyright (c) 2002-2003 Boris Kolpackov +# license : http://kolpackov.net/license.html + +root := ../.. + +include $(root)/Config/Documentation.pre.rules + +vpath %.hpp $(root)/Utility/ReferenceCounting + +doc_translation_units := DefaultImpl.hpp \ + Interface.hpp \ + SmartPtr.hpp \ + StrictPtr.hpp + +DOC_FLAGS := --strip-preprocessor -css $(root)/Documentation/Style/CXX.css + +include $(root)/Config/Documentation.post.rules diff --git a/TAO/CIAO/CCF/External/Utility/Documentation/ReferenceCounting/News.html b/TAO/CIAO/CCF/External/Utility/Documentation/ReferenceCounting/News.html new file mode 100644 index 00000000000..a4f84d17afb --- /dev/null +++ b/TAO/CIAO/CCF/External/Utility/Documentation/ReferenceCounting/News.html @@ -0,0 +1,108 @@ +<!-- +// $Id$ +--> +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" + "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> + +<!-- + +file : Documentation/ReferenceCounting/News.html +author : Boris Kolpackov <boris@kolpackov.net> +copyright : Copyright (c) 2003 Boris Kolpackov +license : http://kolpackov.net/license.html + +--> + +<html> + +<head> + + <title>ReferenceCounting library news</title> + + <meta name="author" content="Boris Kolpackov"/> + <meta name="copyright" content="© 2001-2003 Boris Kolpackov"/> + <meta name="keywords" content="news,C++,reference,counting,smart,pointer"/> + <meta name="description" content="ReferenceCounting library news"/> + <meta http-equiv="Content-Language" content="en"/> + + <style type="text/css"> + body { + font-family : arial,sans-serif; + font-size : 10pt; + } + + h1 { + font-size : 12pt; + } + + </style> + +</head> + +<body> + +<div align="center"> +<table width="700" border="0" cellspacing="0" cellpadding="0"> +<tr> +<td> + +<h1>1.1.0</h1> +<ul> + <li><p>New and complete test coverage</p></li> + + <li><p> + <code><a href="SmartPtr.hpp.html">Utility::ReferenceCounting::SmartPtr</a></code>: + added + <p><code> + template<typename Other> SmartPtr (SmartPtr<Other> const&) + </code></p> + and + <p><code> + template<typename Other> operator= (SmartPtr<Other> const&) + </code></p> + </p></li> + + <li><p> + <code><a href="SmartPtr.hpp.html">Utility::ReferenceCounting::SmartPtr</a></code>: + added + <p><code> + typedef T Type; + </code></p> + to provide access to underlying type. + </p></li> + + <li><p> + <code><a href="index.html">Utility::ReferenceCounting</a></code>: + added + <p><code> + template <typename D, typename S> + D* smart_cast (SmartPtr<S> const&) + </code></p> + to provide more convenient <code>dynamic_cast</code> functionality. + </p></li> + + <li><p> + <code><a href="index.html">Utility::ReferenceCounting</a></code>: + added + <p><code> + template <typename T> + SmartPtr<T> acquire (T*) + </code></p> + </p></li> + + <li><p> + New + <code><a href="StrictPtr.hpp.html"> + Utility::ReferenceCounting::StrictPtr + </a></code> automatic pointer. + </p></li> + +</ul> + + +</td> +</tr> +</table> +</div> +</body> +</html> diff --git a/TAO/CIAO/CCF/External/Utility/Documentation/ReferenceCounting/index.html b/TAO/CIAO/CCF/External/Utility/Documentation/ReferenceCounting/index.html new file mode 100644 index 00000000000..d2cbbb10dc0 --- /dev/null +++ b/TAO/CIAO/CCF/External/Utility/Documentation/ReferenceCounting/index.html @@ -0,0 +1,82 @@ +<!-- +// $Id$ +--> +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" + "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> + +<!-- + +file : Documentation/ReferenceCounting/index.html +author : Boris Kolpackov <boris@kolpackov.net> +copyright : Copyright (c) 2003 Boris Kolpackov +license : http://kolpackov.net/license.html + +--> + +<html> + +<head> + + <title>Utility::ReferenceCounting</title> + + <meta name="author" content="Boris Kolpackov"/> + <meta name="copyright" content="© 2001-2003 Boris Kolpackov"/> + <meta name="keywords" content="C++,utility,reference,counting"/> + <meta name="description" content="Utility::ReferenceCounting"/> + <meta http-equiv="Content-Language" content="en"/> + + <style type="text/css"> + body { + font-family : arial,sans-serif; + font-size : 10pt; + } + + h1 { + font-size : 12pt; + } + + </style> + +</head> + +<body> + +<div align="center"> +<table width="700" border="0" cellspacing="0" cellpadding="0"> +<tr> +<td> + + +<H1>Utility::ReferenceCounting</H1> + +<p>ReferenceCounting library provides basic building blocks for +reference-countable objects. Implementation is modelled after CORBA +IDL-to-C++ mapping's reference-countable objects and significantly +extended. + +<!-- +For a quick overview of the basic idea you +may want to look at these examples:</p> + +<blockquote> + <p><a href="Test/DefaultImpl/default_impl.cpp.html">default_impl.cpp</a></p> + <p><a href="Test/SmartPtr/smart_ptr.cpp.html">smart_ptr.cpp</a></p> +</blockquote> +--> + +<p>Here are the definitions of the key classes:</p> + +<blockquote> + <p><a href="Interface.hpp.html">ReferenceCounting::Interface</a></p> + <p><a href="DefaultImpl.hpp.html">ReferenceCounting::DefaultImpl</a></p> + <p><a href="SmartPtr.hpp.html">ReferenceCounting::SmartPtr</a></p> + <p><a href="StrictPtr.hpp.html">ReferenceCounting::StrictPtr</a></p> +</blockquote> + +</td> +</tr> +</table> +</div> +</body> +</html> + diff --git a/TAO/CIAO/CCF/External/Utility/Documentation/Style/CXX.css b/TAO/CIAO/CCF/External/Utility/Documentation/Style/CXX.css new file mode 100644 index 00000000000..dc6b4835b64 --- /dev/null +++ b/TAO/CIAO/CCF/External/Utility/Documentation/Style/CXX.css @@ -0,0 +1,8 @@ +pre { BORDER-RIGHT: gray 1pt solid; PADDING-RIGHT: 2pt; BORDER-TOP: gray 1pt solid; DISPLAY: block; PADDING-LEFT: 2pt; PADDING-BOTTOM: 2pt; MARGIN-LEFT: 32pt; BORDER-LEFT: gray 1pt solid; MARGIN-RIGHT: 32pt; PADDING-TOP: 2pt; BORDER-BOTTOM: gray 1pt solid; FONT-FAMILY: "Courier New", Courier, mono; background-color: #EEEEEE; font-size: small} +.keyword { color: #000099} +.identifier { } +.comment { color: #990000} +.special { color: #800040} +.preprocessor { color: #006600} +.string { color: #666666} +.number { color: #666666} diff --git a/TAO/CIAO/CCF/External/Utility/Documentation/Style/CXX_Blue.css b/TAO/CIAO/CCF/External/Utility/Documentation/Style/CXX_Blue.css new file mode 100644 index 00000000000..88dbe046bc7 --- /dev/null +++ b/TAO/CIAO/CCF/External/Utility/Documentation/Style/CXX_Blue.css @@ -0,0 +1,24 @@ +pre { + BORDER-RIGHT: gray 1pt solid; + PADDING-RIGHT: 2pt; + BORDER-TOP: gray 1pt solid; + DISPLAY: block; + PADDING-LEFT: 2pt; + PADDING-BOTTOM: 2pt; + MARGIN-LEFT: 32pt; + BORDER-LEFT: gray 1pt solid; + MARGIN-RIGHT: 32pt; + PADDING-TOP: 2pt; + BORDER-BOTTOM: gray 1pt solid; + FONT-FAMILY: "Courier New", Courier, mono; background-color: #191970; + font-size: small +} + +.keyword { font-weight: bold; color: #afeeee} +.identifier { color: #98fb98 } +.comment { color: #add8e6} +.special { color: #bebebe} +.preprocessor { color: #7fffd4} +.string { color: #87cefa} +.number { color: #bebebe} +.literal { color: #FF0000} diff --git a/TAO/CIAO/CCF/External/Utility/Documentation/Synch/Makefile b/TAO/CIAO/CCF/External/Utility/Documentation/Synch/Makefile new file mode 100644 index 00000000000..63b5c86f113 --- /dev/null +++ b/TAO/CIAO/CCF/External/Utility/Documentation/Synch/Makefile @@ -0,0 +1,14 @@ +# $Id$ +# file : Documentation/Synch/Makefile +# author : Boris Kolpackov <boris@kolpackov.net> +# copyright : Copyright (c) 2002-2003 Boris Kolpackov +# license : http://kolpackov.net/license.html + +root := ../.. + +include $(root)/Config/Recursion.pre.rules + +target_makefile_list := +target_directory_list := Policy + +include $(root)/Config/Recursion.post.rules diff --git a/TAO/CIAO/CCF/External/Utility/Documentation/Synch/News.html b/TAO/CIAO/CCF/External/Utility/Documentation/Synch/News.html new file mode 100644 index 00000000000..7987453a31f --- /dev/null +++ b/TAO/CIAO/CCF/External/Utility/Documentation/Synch/News.html @@ -0,0 +1,60 @@ +<!-- +// $Id$ +--> +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" + "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> + +<!-- + +file : Documentation/Synch/News.html +author : Boris Kolpackov <boris@kolpackov.net> +copyright : Copyright (c) 2003 Boris Kolpackov +license : http://kolpackov.net/license.html + +--> + +<html> + +<head> + + <title>Synchronization library news</title> + + <meta name="author" content="Boris Kolpackov"/> + <meta name="copyright" content="© 2001-2003 Boris Kolpackov"/> + <meta name="keywords" content="news,C++,synchronization,policy,thread"/> + <meta name="description" content="Synchronization library news"/> + <meta http-equiv="Content-Language" content="en"/> + + <style type="text/css"> + body { + font-family : arial,sans-serif; + font-size : 10pt; + } + + h1 { + font-size : 12pt; + } + + </style> + +</head> + +<body> + +<div align="center"> +<table width="700" border="0" cellspacing="0" cellpadding="0"> +<tr> +<td> + +<h1>1.1.0</h1> +<ul> + <li><p>New and complete test coverage</p></li> +</ul> + + +</td> +</tr> +</table> +</div> +</body> +</html> diff --git a/TAO/CIAO/CCF/External/Utility/Documentation/Synch/Policy/Makefile b/TAO/CIAO/CCF/External/Utility/Documentation/Synch/Policy/Makefile new file mode 100644 index 00000000000..419f63364e1 --- /dev/null +++ b/TAO/CIAO/CCF/External/Utility/Documentation/Synch/Policy/Makefile @@ -0,0 +1,18 @@ +# $Id$ +# file : Documentation/Synch/Policy/Makefile +# author : Boris Kolpackov <boris@kolpackov.net> +# copyright : Copyright (c) 2002-2003 Boris Kolpackov +# license : http://kolpackov.net/license.html + +root := ../../.. + +include $(root)/Config/Documentation.pre.rules + +vpath %.hpp $(root)/Utility/Synch/Policy + +doc_translation_units := Null.hpp + +DOC_FLAGS := --strip-preprocessor -css $(root)/Documentation/Style/CXX.css + +include $(root)/Config/Documentation.post.rules + diff --git a/TAO/CIAO/CCF/External/Utility/Documentation/Synch/index.html b/TAO/CIAO/CCF/External/Utility/Documentation/Synch/index.html new file mode 100644 index 00000000000..87a7b9086fa --- /dev/null +++ b/TAO/CIAO/CCF/External/Utility/Documentation/Synch/index.html @@ -0,0 +1,70 @@ +<!-- +// $Id$ +--> +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" + "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> + +<!-- + +file : Documentation/Synch/index.html +author : Boris Kolpackov <boris@kolpackov.net> +copyright : Copyright (c) 2003 Boris Kolpackov +license : http://kolpackov.net/license.html + +--> + +<html> + +<head> + + <title>Utility::Synch</title> + + <meta name="author" content="Boris Kolpackov"/> + <meta name="copyright" content="© 2001-2003 Boris Kolpackov"/> + <meta name="keywords" content="C++,utility,thread,synchronization,policy"/> + <meta name="description" content="Utility::Synch"/> + <meta http-equiv="Content-Language" content="en"/> + + <style type="text/css"> + body { + font-family : arial,sans-serif; + font-size : 10pt; + } + + h1 { + font-size : 12pt; + } + +</style> + +</head> + +<body> + +<div align="center"> +<table width="700" border="0" cellspacing="0" cellpadding="0"> +<tr> +<td> + +<H1>Utility::Synch</H1> + +<p> +Synchronization library provides a compile-time policy-based configurable +facility of selecting synchronization mechanisms. For now there is only +no-op synchronization policy provided which is suitable only for +single-threaded applications. However it shouldn't be difficult to porvide +a wrapper policy for synchronization mechanisms used in a particular project. +</p> + +<p>Here are the definitions of the key classes:</p> + +<blockquote> + <p><a href="Policy/Null.hpp.html">Synch::Policy::Null</a></p> +</blockquote> + +</td> +</tr> +</table> +</div> +</body> +</html> diff --git a/TAO/CIAO/CCF/External/Utility/Documentation/index.html b/TAO/CIAO/CCF/External/Utility/Documentation/index.html new file mode 100644 index 00000000000..be5667c86f8 --- /dev/null +++ b/TAO/CIAO/CCF/External/Utility/Documentation/index.html @@ -0,0 +1,92 @@ +<!-- +// $Id$ +--> +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" + "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> + +<!-- + +file : Documentation/index.html +author : Boris Kolpackov <boris@kolpackov.net> +copyright : Copyright (c) 2003 Boris Kolpackov +license : http://kolpackov.net/license.html + +--> + +<html> + +<head> + + <title>Utility library</title> + + <meta name="author" content="Boris Kolpackov"/> + <meta name="copyright" content="© 2001-2003 Boris Kolpackov"/> + <meta name="keywords" content="C++,utility,exception,handling,model,reference,counting,thread,synchronization"/> + <meta name="description" content="Utility library"/> + <meta http-equiv="Content-Language" content="en"/> + + <style type="text/css"> + body { + font-family : arial,sans-serif; + font-size : 10pt; + } + + h1 { + font-size : 12pt; + } + + </style> + +</head> + +<body> + +<div align="center"> +<table width="700" border="0" cellspacing="0" cellpadding="0"> +<tr> +<td> + +<p> +Utility library is a place for generic C++ facilities that I found useful +in more than one project. + +Here you can download the +<a href="http://kolpackov.net/projects/Utility/Download.html"> +latest version of the library</a>. + +Licensing information is provided as a separate page, +<a href="http://kolpackov.net/license.html">license</a>. + +For updates check out <a href="News.html">news section</a>.</p> + +<H1>Supported Platforms</H1> + +<p> +For the time being I test Utility library with at least GNU G++ on Linux and +Compaq (Digital) C++ (-std strict_ansi) on Tru64 UNIX. It also should compile +and work fine with any decent C++ compiler. Also note that I don't have any +plans to bloat source code in attempt to support broken compilers.</p> + +<H1>How to Build</H1> + +<p> +Utility library itself consists of header and inline files so you don't actually need +to build anything to start using it. In order to build tests or examples +you will need at least GNU make.</p> + +<H1>Content</H1> + +<p>Currently Utility library contains the following sub-libraries:</p> + +<blockquote> + <p><a href="ExH/index.html">Exception Handling Library (Utility::ExH)</a></p> + <p><a href="ReferenceCounting/index.html">Reference Counting Library (Utility::ReferenceCounting)</a></p> + <p><a href="Synch/index.html">Synchronization Library (Utility::Synch)</a></p> +</blockquote> + +</td> +</tr> +</table> +</div> +</body> +</html> diff --git a/TAO/CIAO/CCF/External/Utility/Makefile b/TAO/CIAO/CCF/External/Utility/Makefile new file mode 100644 index 00000000000..1254fd3477f --- /dev/null +++ b/TAO/CIAO/CCF/External/Utility/Makefile @@ -0,0 +1,14 @@ +# $Id$ +# file : Makefile +# author : Boris Kolpackov <boris@kolpackov.net> +# copyright : Copyright (c) 2002-2003 Boris Kolpackov +# license : http://kolpackov.net/license.html + +root := . + +include $(root)/Config/Recursion.pre.rules + +target_makefile_list := +target_directory_list := Test Example Documentation + +include $(root)/Config/Recursion.post.rules diff --git a/TAO/CIAO/CCF/External/Utility/Utility/ExH/Compound.hpp b/TAO/CIAO/CCF/External/Utility/Utility/ExH/Compound.hpp new file mode 100644 index 00000000000..e0c2487274c --- /dev/null +++ b/TAO/CIAO/CCF/External/Utility/Utility/ExH/Compound.hpp @@ -0,0 +1,42 @@ +// file : Utility/ExH/Compound.hpp +// author : Boris Kolpackov <boris@kolpackov.net> +// copyright : Copyright (c) 2002-2003 Boris Kolpackov +// license : http://kolpackov.net/license.html + +#ifndef UTILITY_EX_H_COMPOUND_HPP +#define UTILITY_EX_H_COMPOUND_HPP + +namespace Utility +{ + namespace ExH + { + template <typename Type, typename Base> + class Compound : public virtual Base + { + public: + explicit + Compound (char const* description) throw (); + + template <typename T> + explicit + Compound (T const& description) throw (); + + Compound (Compound const& src) throw (); + + virtual + ~Compound () throw (); + + public: + Compound& + operator= (Compound const& src) throw (); + + protected: + Compound () throw (); + }; + } +} + +#include "Utility/ExH/Compound.tpp" + +#endif // UTILITY_EX_H_COMPOUND_HPP + diff --git a/TAO/CIAO/CCF/External/Utility/Utility/ExH/Compound.tpp b/TAO/CIAO/CCF/External/Utility/Utility/ExH/Compound.tpp new file mode 100644 index 00000000000..54122eba980 --- /dev/null +++ b/TAO/CIAO/CCF/External/Utility/Utility/ExH/Compound.tpp @@ -0,0 +1,57 @@ +// file : Utility/ExH/Compound.tpp +// author : Boris Kolpackov <boris@kolpackov.net> +// copyright : Copyright (c) 2002-2003 Boris Kolpackov +// license : http://kolpackov.net/license.html + +#include "Utility/ExH/Converter.hpp" + +namespace Utility +{ + namespace ExH + { + // c-tor's & d-tor + template <typename Type, typename Base> + Compound<Type, Base>:: + Compound () throw () + { + } + + template <typename Type, typename Base> + Compound<Type, Base>:: + Compound (char const* description) throw () + { + Base::init (description); + } + + template <typename Type, typename Base> + template <typename T> + Compound<Type, Base>:: + Compound (T const& description) throw () + { + Base::init (converter<T> (description)); + } + + template <typename Type, typename Base> + Compound<Type, Base>:: + Compound (Compound const& src) throw () + { + Base::init (src.what ()); + } + + template <typename Type, typename Base> + Compound<Type, Base>:: + ~Compound () throw () + { + } + + // operator= + + template <typename Type, typename Base> + Compound<Type, Base>& Compound<Type, Base>:: + operator= (Compound const& src) throw () + { + Base::init (src.what ()); + return *this; + } + } +} diff --git a/TAO/CIAO/CCF/External/Utility/Utility/ExH/Converter.hpp b/TAO/CIAO/CCF/External/Utility/Utility/ExH/Converter.hpp new file mode 100644 index 00000000000..399c5931fab --- /dev/null +++ b/TAO/CIAO/CCF/External/Utility/Utility/ExH/Converter.hpp @@ -0,0 +1,22 @@ +// file : Utility/ExH/Converter.hpp +// author : Boris Kolpackov <boris@kolpackov.net> +// copyright : Copyright (c) 2002-2003 Boris Kolpackov +// license : http://kolpackov.net/license.html + +#ifndef UTILITY_EX_H_CONVERTER_HPP +#define UTILITY_EX_H_CONVERTER_HPP + +namespace Utility +{ + namespace ExH + { + template <typename T> + char const* + converter (T const& t) throw (); + } +} + +#include "Utility/ExH/Converter.tpp" + +#endif // UTILITY_EX_H_CONVERTER_HPP + diff --git a/TAO/CIAO/CCF/External/Utility/Utility/ExH/Converter.tpp b/TAO/CIAO/CCF/External/Utility/Utility/ExH/Converter.tpp new file mode 100644 index 00000000000..018776cad71 --- /dev/null +++ b/TAO/CIAO/CCF/External/Utility/Utility/ExH/Converter.tpp @@ -0,0 +1,19 @@ +// file : Utility/ExH/Converter.tpp +// author : Boris Kolpackov <boris@kolpackov.net> +// copyright : Copyright (c) 2002-2003 Boris Kolpackov +// license : http://kolpackov.net/license.html + +namespace Utility +{ + namespace ExH + { + template <typename T> + char const* + converter (T const& t) throw () + { + // Default implementation just assumes that implicit converion exist. + return t; + } + } +} + diff --git a/TAO/CIAO/CCF/External/Utility/Utility/ExH/ExH.hpp b/TAO/CIAO/CCF/External/Utility/Utility/ExH/ExH.hpp new file mode 100644 index 00000000000..8e41c822cab --- /dev/null +++ b/TAO/CIAO/CCF/External/Utility/Utility/ExH/ExH.hpp @@ -0,0 +1,22 @@ +// file : Utility/ExH/ExH.hpp +// author : Boris Kolpackov <boris@kolpackov.net> +// copyright : Copyright (c) 2003 Boris Kolpackov +// license : http://kolpackov.net/license.html + +#ifndef UTILITY_EX_H_EX_H_HPP +#define UTILITY_EX_H_EX_H_HPP + +#include "Utility/ExH/System/Exception.hpp" +#include "Utility/ExH/System/DescriptiveException.hpp" + +#include "Utility/ExH/Logic/Exception.hpp" +#include "Utility/ExH/Logic/DescriptiveException.hpp" + +#include "Utility/ExH/Compound.hpp" + +#include "Utility/ExH/Converter.hpp" +#include "Utility/ExH/StringConverter.hpp" +#include "Utility/ExH/StringStreamConverter.hpp" + +#endif // UTILITY_EX_H_EX_H_HPP + diff --git a/TAO/CIAO/CCF/External/Utility/Utility/ExH/Logic/DescriptiveException.hpp b/TAO/CIAO/CCF/External/Utility/Utility/ExH/Logic/DescriptiveException.hpp new file mode 100644 index 00000000000..e7852690ebc --- /dev/null +++ b/TAO/CIAO/CCF/External/Utility/Utility/ExH/Logic/DescriptiveException.hpp @@ -0,0 +1,60 @@ +// file : Utility/ExH/Logic/DescriptiveException.hpp +// author : Boris Kolpackov <boris@kolpackov.net> +// copyright : Copyright (c) 2002-2003 Boris Kolpackov +// license : http://kolpackov.net/license.html + +#ifndef UTILITY_EX_H_LOGIC_DESCRIPTIVE_EXCEPTION_HPP +#define UTILITY_EX_H_LOGIC_DESCRIPTIVE_EXCEPTION_HPP + +#include <memory> +#include <string> + + +#include "Utility/ExH/Logic/Exception.hpp" + +namespace Utility +{ + namespace ExH + { + namespace Logic + { + class DescriptiveException : public virtual Exception + { + public: + explicit + DescriptiveException (char const* description) throw (); + + template <typename T> + explicit + DescriptiveException (T const& description) throw (); + + DescriptiveException (DescriptiveException const& src) throw (); + + virtual + ~DescriptiveException () throw (); + + DescriptiveException& + operator= (DescriptiveException const& src) throw (); + + protected: + DescriptiveException () throw (); + + void + init (char const* description) throw (); + + public: + virtual char const* + what () const throw (); + + private: + std::auto_ptr<std::string> description_; + }; + } + } +} + +#include "Utility/ExH/Logic/DescriptiveException.ipp" + +#endif // UTILITY_EX_H_LOGIC_DESCRIPTIVE_EXCEPTION_HPP + + diff --git a/TAO/CIAO/CCF/External/Utility/Utility/ExH/Logic/DescriptiveException.ipp b/TAO/CIAO/CCF/External/Utility/Utility/ExH/Logic/DescriptiveException.ipp new file mode 100644 index 00000000000..44cce34f59a --- /dev/null +++ b/TAO/CIAO/CCF/External/Utility/Utility/ExH/Logic/DescriptiveException.ipp @@ -0,0 +1,101 @@ +// file : Utility/ExH/Logic/DescriptiveException.ipp +// author : Boris Kolpackov <boris@kolpackov.net> +// copyright : Copyright (c) 2002-2003 Boris Kolpackov +// license : http://kolpackov.net/license.html + +#include "Utility/ExH/Converter.hpp" + +namespace Utility +{ + namespace ExH + { + namespace Logic + { + // c-tor's & d-tor + + inline DescriptiveException:: + DescriptiveException () throw () + { + } + + inline DescriptiveException:: + DescriptiveException (char const* description) throw () + { + init (description); + } + + template <typename T> + DescriptiveException:: + DescriptiveException (T const& description) throw () + { + init (converter<T> (description)); + } + + inline DescriptiveException:: + DescriptiveException (DescriptiveException const& src) throw () + { + init (src.what ()); + } + + inline DescriptiveException:: + ~DescriptiveException () throw () + { + } + + inline DescriptiveException& DescriptiveException:: + operator= (DescriptiveException const& src) throw () + { + init (src.what ()); + return *this; + } + + + // accessors / modifiers + + inline void + DescriptiveException::init (char const* description) throw () + { + try + { + if (description == 0 || description[0] == '\0') + { + description_.reset (0); + } + else + { + if (description_.get () != 0) + { + *description_ = description; + } + else + { + description_.reset (new std::string (description)); + } + } + } + catch (...) + { + description_.reset (0); + } + } + + inline char const* + DescriptiveException::what () const throw () + { + try + { + if (description_.get () != 0) + { + return description_->c_str (); + } + } + catch (...) + { + } + + return Exception::what (); + } + } + } +} + diff --git a/TAO/CIAO/CCF/External/Utility/Utility/ExH/Logic/Exception.hpp b/TAO/CIAO/CCF/External/Utility/Utility/ExH/Logic/Exception.hpp new file mode 100644 index 00000000000..711caea3587 --- /dev/null +++ b/TAO/CIAO/CCF/External/Utility/Utility/ExH/Logic/Exception.hpp @@ -0,0 +1,40 @@ +// file : Utility/ExH/Logic/Exception.hpp +// author : Boris Kolpackov <boris@kolpackov.net> +// copyright : Copyright (c) 2002-2003 Boris Kolpackov +// license : http://kolpackov.net/license.html + +#ifndef UTILITY_EX_H_LOGIC_EXCEPTION_HPP +#define UTILITY_EX_H_LOGIC_EXCEPTION_HPP + +#include "Utility/ExH/System/Exception.hpp" + +namespace Utility +{ + namespace ExH + { + namespace Logic + { + + // Logic::Exception inherits from System::Exception for the + // following reason. Semantically for some part of the + // system particular instance of Logic::Exception may seem as + // opaque System::Exception and the only way to handle it would + // be to propagate it further. In other words Logic::Exception + // can be seemlesly "converted" to System::Exception if there is + // no part of the system interested in handling it. + // + + class Exception : public virtual System::Exception + { + public: + virtual + ~Exception () throw (); + }; + } + } +} + +#include "Utility/ExH/Logic/Exception.ipp" + +#endif // UTILITY_EX_H_LOGIC_EXCEPTION_HPP + diff --git a/TAO/CIAO/CCF/External/Utility/Utility/ExH/Logic/Exception.ipp b/TAO/CIAO/CCF/External/Utility/Utility/ExH/Logic/Exception.ipp new file mode 100644 index 00000000000..84fc99e8d2c --- /dev/null +++ b/TAO/CIAO/CCF/External/Utility/Utility/ExH/Logic/Exception.ipp @@ -0,0 +1,19 @@ +// file : Utility/ExH/Logic/Exception.ipp +// author : Boris Kolpackov <boris@kolpackov.net> +// copyright : Copyright (c) 2002-2003 Boris Kolpackov +// license : http://kolpackov.net/license.html + +namespace Utility +{ + namespace ExH + { + namespace Logic + { + inline Exception:: + ~Exception () throw () + { + } + } + } +} + diff --git a/TAO/CIAO/CCF/External/Utility/Utility/ExH/StringConverter.hpp b/TAO/CIAO/CCF/External/Utility/Utility/ExH/StringConverter.hpp new file mode 100644 index 00000000000..279ccbfaf60 --- /dev/null +++ b/TAO/CIAO/CCF/External/Utility/Utility/ExH/StringConverter.hpp @@ -0,0 +1,26 @@ +// file : Utility/ExH/StringConverter.hpp +// author : Boris Kolpackov <boris@kolpackov.net> +// copyright : Copyright (c) 2002-2003 Boris Kolpackov +// license : http://kolpackov.net/license.html + +#ifndef UTILITY_EX_H_STRING_CONVERTER_HPP +#define UTILITY_EX_H_STRING_CONVERTER_HPP + +#include <string> + +#include "Utility/ExH/Converter.hpp" + +namespace Utility +{ + namespace ExH + { + template <> + char const* + converter (std::string const& t) throw (); + } +} + +#include "Utility/ExH/StringConverter.ipp" + +#endif // UTILITY_EX_H_STRING_CONVERTER_HPP + diff --git a/TAO/CIAO/CCF/External/Utility/Utility/ExH/StringConverter.ipp b/TAO/CIAO/CCF/External/Utility/Utility/ExH/StringConverter.ipp new file mode 100644 index 00000000000..4703d47da17 --- /dev/null +++ b/TAO/CIAO/CCF/External/Utility/Utility/ExH/StringConverter.ipp @@ -0,0 +1,17 @@ +// file : Utility/ExH/StringConverter.ipp +// author : Boris Kolpackov <boris@kolpackov.net> +// copyright : Copyright (c) 2002-2003 Boris Kolpackov +// license : http://kolpackov.net/license.html + +namespace Utility +{ + namespace ExH + { + template <> + inline char const* + converter (std::string const& t) throw () + { + return t.c_str (); + } + } +} diff --git a/TAO/CIAO/CCF/External/Utility/Utility/ExH/StringStreamConverter.hpp b/TAO/CIAO/CCF/External/Utility/Utility/ExH/StringStreamConverter.hpp new file mode 100644 index 00000000000..8882bd69690 --- /dev/null +++ b/TAO/CIAO/CCF/External/Utility/Utility/ExH/StringStreamConverter.hpp @@ -0,0 +1,26 @@ +// file : Utility/ExH/StringStreamConverter.hpp +// author : Boris Kolpackov <boris@kolpackov.net> +// copyright : Copyright (c) 2002-2003 Boris Kolpackov +// license : http://kolpackov.net/license.html + +#ifndef UTILITY_EX_H_STRING_STREAM_CONVERTER_HPP +#define UTILITY_EX_H_STRING_STREAM_CONVERTER_HPP + +#include <sstream> + +#include "Utility/ExH/Converter.hpp" + +namespace Utility +{ + namespace ExH + { + template <> + char const* + converter (std::ostringstream const& t) throw (); + } +} + +#include "Utility/ExH/StringStreamConverter.ipp" + +#endif // UTILITY_EX_H_STRING_STREAM_CONVERTER_HPP + diff --git a/TAO/CIAO/CCF/External/Utility/Utility/ExH/StringStreamConverter.ipp b/TAO/CIAO/CCF/External/Utility/Utility/ExH/StringStreamConverter.ipp new file mode 100644 index 00000000000..9c1e7f14489 --- /dev/null +++ b/TAO/CIAO/CCF/External/Utility/Utility/ExH/StringStreamConverter.ipp @@ -0,0 +1,19 @@ +// file : Utility/ExH/StringStreamConverter.ipp +// author : Boris Kolpackov <boris@kolpackov.net> +// copyright : Copyright (c) 2002-2003 Boris Kolpackov +// license : http://kolpackov.net/license.html + +namespace Utility +{ + namespace ExH + { + template <> + inline char const* + converter (std::ostringstream const& t) throw () + { + return t.str ().c_str (); + } + + } +} + diff --git a/TAO/CIAO/CCF/External/Utility/Utility/ExH/System/DescriptiveException.hpp b/TAO/CIAO/CCF/External/Utility/Utility/ExH/System/DescriptiveException.hpp new file mode 100644 index 00000000000..0f58f10f30e --- /dev/null +++ b/TAO/CIAO/CCF/External/Utility/Utility/ExH/System/DescriptiveException.hpp @@ -0,0 +1,58 @@ +// file : Utility/ExH/System/DescriptiveException.hpp +// author : Boris Kolpackov <boris@kolpackov.net> +// copyright : Copyright (c) 2002-2003 Boris Kolpackov +// license : http://kolpackov.net/license.html + +#ifndef UTILITY_EX_H_SYSTEM_DESCRIPTIVE_EXCEPTION_HPP +#define UTILITY_EX_H_SYSTEM_DESCRIPTIVE_EXCEPTION_HPP + +#include "Utility/ExH/System/Exception.hpp" + +namespace Utility +{ + namespace ExH + { + namespace System + { + class DescriptiveException : public virtual Exception + { + public: + explicit + DescriptiveException (char const* description) throw (); + + template <typename T> + explicit + DescriptiveException (T const& description) throw (); + + DescriptiveException (DescriptiveException const& src) throw (); + + virtual + ~DescriptiveException () throw (); + + DescriptiveException& + operator= (DescriptiveException const& src) throw (); + + protected: + DescriptiveException () throw (); + + void + init (char const* description) throw (); + + public: + virtual char const* + what () const throw (); + + private: + + static unsigned long const DESCRIPTION_SIZE = 256; + + char description_ [DESCRIPTION_SIZE]; + }; + } + } +} + +#include "Utility/ExH/System/DescriptiveException.ipp" + +#endif // UTILITY_EX_H_SYSTEM_DESCRIPTIVE_EXCEPTION_HPP + diff --git a/TAO/CIAO/CCF/External/Utility/Utility/ExH/System/DescriptiveException.ipp b/TAO/CIAO/CCF/External/Utility/Utility/ExH/System/DescriptiveException.ipp new file mode 100644 index 00000000000..e35f5aaa60f --- /dev/null +++ b/TAO/CIAO/CCF/External/Utility/Utility/ExH/System/DescriptiveException.ipp @@ -0,0 +1,87 @@ +// file : Utility/ExH/System/DescriptiveException.ipp +// author : Boris Kolpackov <boris@kolpackov.net> +// copyright : Copyright (c) 2002-2003 Boris Kolpackov +// license : http://kolpackov.net/license.html + +#include <cstring> + +#include "Utility/ExH/Converter.hpp" + +namespace Utility +{ + namespace ExH + { + namespace System + { + // c-tor's & d-tor + + inline DescriptiveException:: + DescriptiveException () throw () + { + description_[0] = '\0'; + } + + inline DescriptiveException:: + DescriptiveException (char const* description) throw () + { + init (description); + } + + template <typename T> + inline DescriptiveException:: + DescriptiveException (T const& description) throw () + { + init (converter<T> (description)); + } + + inline DescriptiveException:: + DescriptiveException (DescriptiveException const& src) throw () + { + init (src.what ()); + } + + inline DescriptiveException:: + ~DescriptiveException () throw () + { + } + + inline DescriptiveException& DescriptiveException:: + operator= (DescriptiveException const& src) throw () + { + init (src.what ()); + return *this; + } + + + // accessors / modifiers + + inline void DescriptiveException:: + init (char const* description) throw () + { + if (description != 0) + { + std::strncpy (description_, description, DESCRIPTION_SIZE - 1); + description_[DESCRIPTION_SIZE - 1] = '\0'; + } + else + { + description_[0] = '\0'; + } + } + + inline char const* DescriptiveException:: + what () const throw () + { + if (description_[0] != '\0') + { + return description_; + } + else + { + return Exception::what (); + } + } + } + } +} + diff --git a/TAO/CIAO/CCF/External/Utility/Utility/ExH/System/Exception.hpp b/TAO/CIAO/CCF/External/Utility/Utility/ExH/System/Exception.hpp new file mode 100644 index 00000000000..4d074b66c23 --- /dev/null +++ b/TAO/CIAO/CCF/External/Utility/Utility/ExH/System/Exception.hpp @@ -0,0 +1,28 @@ +// file : Utility/ExH/System/Exception.hpp +// author : Boris Kolpackov <boris@kolpackov.net> +// copyright : Copyright (c) 2002-2003 Boris Kolpackov +// license : http://kolpackov.net/license.html + +#ifndef UTILITY_EX_H_SYSTEM_EXCEPTION_HPP +#define UTILITY_EX_H_SYSTEM_EXCEPTION_HPP + +#include <exception> + +namespace Utility +{ + namespace ExH + { + namespace System + { + // This is the only way to make predefined exceptions like + // std::bad_alloc, etc to appear in the right place of the hierarchy. + // + + typedef std::exception Exception; + } + } +} + +#endif // UTILITY_EX_H_SYSTEM_EXCEPTION_HPP + + diff --git a/TAO/CIAO/CCF/External/Utility/Utility/ReferenceCounting/DefaultImpl.hpp b/TAO/CIAO/CCF/External/Utility/Utility/ReferenceCounting/DefaultImpl.hpp new file mode 100644 index 00000000000..43277035329 --- /dev/null +++ b/TAO/CIAO/CCF/External/Utility/Utility/ReferenceCounting/DefaultImpl.hpp @@ -0,0 +1,95 @@ +// file : Utility/ReferenceCounting/DefaultImpl.hpp +// author : Boris Kolpackov <boris@kolpackov.net> +// copyright : Copyright (c) 2002-2003 Boris Kolpackov +// license : http://kolpackov.net/license.html + +#ifndef UTILITY_REFERENCE_COUNTING_DEFAULT_IMPL_HPP +#define UTILITY_REFERENCE_COUNTING_DEFAULT_IMPL_HPP + +#include "Utility/ExH/Compound.hpp" +#include "Utility/ExH/Logic/DescriptiveException.hpp" + +#include "Utility/Synch/Policy/Null.hpp" + +#include "Utility/ReferenceCounting/Interface.hpp" + +namespace Utility +{ + namespace ReferenceCounting + { + // Default reference counter implementation with parameterised + // synchronization policy. It is assumed that none of the SynchPolicy + // types throw any logic exceptions. If in fact they do then these + // exceptions won't be handled and will be automatically converted + // to system exceptions. + + template <typename SynchPolicy = Utility::Synch::Policy::Null> + class DefaultImpl : public virtual Interface + { + public: + class InconsistentState_ {}; + typedef + ExH::Compound<InconsistentState_, Exception> + InconsistentState; + + public: + DefaultImpl () throw (SystemException); + + virtual + ~DefaultImpl () throw (); + + public: + virtual void + add_ref () const throw (Exception, SystemException); + + virtual void + remove_ref () const throw (); + + virtual count_t + refcount_value () const throw (Exception, SystemException); + + protected: + virtual void + add_ref_i () const throw (Exception, SystemException); + + virtual bool + remove_ref_i () const throw (Exception, SystemException); + + virtual count_t + refcount_value_i () const throw (Exception, SystemException); + + typename SynchPolicy::Mutex& + lock_i () const throw (); + + protected: + typedef + typename SynchPolicy::Mutex + Mutex_; + + typedef + typename SynchPolicy::ReadGuard + ReadGuard_; + + typedef + typename SynchPolicy::WriteGuard + WriteGuard_; + + protected: + mutable count_t ref_count_; + + private: + mutable Mutex_ lock_; + + private: + // Copy semanic is not supported. + DefaultImpl (DefaultImpl const&) throw (); + DefaultImpl& + operator= (DefaultImpl const&) throw (); + }; + } +} + +#include "Utility/ReferenceCounting/DefaultImpl.ipp" + +#endif // UTILITY_REFERENCE_COUNTING_DEFAULT_IMPL_HPP + diff --git a/TAO/CIAO/CCF/External/Utility/Utility/ReferenceCounting/DefaultImpl.ipp b/TAO/CIAO/CCF/External/Utility/Utility/ReferenceCounting/DefaultImpl.ipp new file mode 100644 index 00000000000..e86fac128a0 --- /dev/null +++ b/TAO/CIAO/CCF/External/Utility/Utility/ReferenceCounting/DefaultImpl.ipp @@ -0,0 +1,104 @@ +// file : Utility/ReferenceCounting/DefaultImpl.ipp +// author : Boris Kolpackov <boris@kolpackov.net> +// copyright : Copyright (c) 2002-2003 Boris Kolpackov +// license : http://kolpackov.net/license.html + +namespace Utility +{ + namespace ReferenceCounting + { + // c-tor & d-tor + + template <typename SynchPolicy> + DefaultImpl<SynchPolicy>:: + DefaultImpl () throw (Interface::SystemException) + : ref_count_ (1), + lock_ () + { + } + + template <typename SynchPolicy> + DefaultImpl<SynchPolicy>:: + ~DefaultImpl () throw () + { + } + + // add_ref, remove_ref and refcount_value member functions + + template <typename SynchPolicy> + void DefaultImpl<SynchPolicy>:: + add_ref () const throw (Exception, SystemException) + { + WriteGuard_ guard (lock_); + add_ref_i (); + } + + template <typename SynchPolicy> + void DefaultImpl<SynchPolicy>:: + remove_ref () const throw () + { + bool destroy (false); + try + { + WriteGuard_ guard (lock_); + destroy = remove_ref_i (); + } + catch (...) + { + // there is nothing we can do + } + + if (destroy) delete this; + } + + template <typename SynchPolicy> + Interface::count_t DefaultImpl<SynchPolicy>:: + refcount_value () const throw (Exception, SystemException) + { + ReadGuard_ guard (lock_); + return refcount_value_i (); + } + + // add_ref_i, remove_ref_i and refcount_value_i member functions + + template <typename SynchPolicy> + void DefaultImpl<SynchPolicy>:: + add_ref_i () const throw (Exception, SystemException) + { + ref_count_++; + } + + template <typename SynchPolicy> + bool DefaultImpl<SynchPolicy>:: + remove_ref_i () const throw (Exception, SystemException) + { + bool destroy (false); + if (ref_count_ > 0) + { + if (--ref_count_ == 0) destroy = true; + } + else + { + throw InconsistentState ( + "Utility::ReferenceCounting::DefaultImpl::_remove_ref_i: " + "reference counter is zero."); + } + return destroy; + + } + + template <typename SynchPolicy> + Interface::count_t DefaultImpl<SynchPolicy>:: + refcount_value_i () const throw (Exception, SystemException) + { + return ref_count_; + } + + template <typename SynchPolicy> + typename SynchPolicy::Mutex& DefaultImpl<SynchPolicy>:: + lock_i() const throw () + { + return lock_; + } + } +} diff --git a/TAO/CIAO/CCF/External/Utility/Utility/ReferenceCounting/ExternalLockImpl.hpp b/TAO/CIAO/CCF/External/Utility/Utility/ReferenceCounting/ExternalLockImpl.hpp new file mode 100644 index 00000000000..ba115aaeec1 --- /dev/null +++ b/TAO/CIAO/CCF/External/Utility/Utility/ReferenceCounting/ExternalLockImpl.hpp @@ -0,0 +1,59 @@ +// file : Utility/ReferenceCounting/ExternalLockImpl.hpp +// author : Boris Kolpackov <boris@kolpackov.net> +// copyright : Copyright (c) 2002-2003 Boris Kolpackov +// license : http://kolpackov.net/license.html + +#ifndef UTILITY_REFERENCE_COUNTING_EXTERNAL_LOCK_IMPL_HPP +#define UTILITY_REFERENCE_COUNTING_EXTERNAL_LOCK_IMPL_HPP + +namespace Utility +{ + namespace ReferenceCounting + { + + /* + + Not ported yet. + + class ExternalLockRefCounter : public virtual Util::RefCountBase + { + public: + ExternalLockRefCounter (ACE_Lock* lock = 0); + virtual ~ExternalLockRefCounter (); + + void init (ACE_Lock* lock); + + public: + + virtual void _add_ref (); + virtual void _remove_ref (); + virtual unsigned long _refcount_value (); + + protected: + + virtual void _add_ref_i (); + virtual bool _remove_ref_i (); + virtual unsigned long _refcount_value_i (); + + ACE_Lock* lock_i (); + + private: + + typedef ACE_Guard <ACE_Lock> Guard_; + + ACE_Lock* lock_; + unsigned long ref_count_; + + private: + ExternalLockRefCounter (const ExternalLockRefCounter& ); + void operator= (const ExternalLockRefCounter& ); + }; + + */ + } +} + +#include "Utility/ReferenceCounting/ExternalLockImpl.ipp" + +#endif // UTILITY_REFERENCE_COUNTING_EXTERNAL_LOCK_IMPL_HPP + diff --git a/TAO/CIAO/CCF/External/Utility/Utility/ReferenceCounting/ExternalLockImpl.ipp b/TAO/CIAO/CCF/External/Utility/Utility/ReferenceCounting/ExternalLockImpl.ipp new file mode 100644 index 00000000000..46fde227919 --- /dev/null +++ b/TAO/CIAO/CCF/External/Utility/Utility/ReferenceCounting/ExternalLockImpl.ipp @@ -0,0 +1,121 @@ +// file : Utility/ReferenceCounting/ExternalLockImpl.ipp +// author : Boris Kolpackov <boris@kolpackov.net> +// copyright : Copyright (c) 2002-2003 Boris Kolpackov +// license : http://kolpackov.net/license.html + +namespace Utility +{ + namespace ReferenceCounting + { + /* + inline + ExternalLockRefCounter::ExternalLockRefCounter (ACE_Lock* lock) + : lock_ (lock), + ref_count_ (1) + { + } + + inline + void + ExternalLockRefCounter::init (ACE_Lock* lock) + { + lock_ = lock; + } + + inline + ExternalLockRefCounter::~ExternalLockRefCounter () + { + } + + inline + ACE_Lock* + ExternalLockRefCounter::lock_i () + { + return lock_; + } + + inline + void + ExternalLockRefCounter::_add_ref () + { + if (lock_) + { + Guard_ guard (*lock_); + _add_ref_i (); + } + else + { + _add_ref_i (); + } + } + + inline + void + ExternalLockRefCounter::_remove_ref () + { + bool destroy = false; + { + if (lock_) + { + Guard_ guard (*lock_); + destroy = _remove_ref_i (); + } + else + { + destroy = _remove_ref_i (); + } + } + if (destroy) delete this; + } + + inline + unsigned long + ExternalLockRefCounter::_refcount_value () + { + if (lock_) + { + Guard_ guard (*lock_); + return _refcount_value_i (); + } + else + { + return _refcount_value_i (); + } + } + + inline + void + ExternalLockRefCounter::_add_ref_i () + { + ref_count_++; + } + + inline + bool + ExternalLockRefCounter::_remove_ref_i () + { + bool destroy = false; + if (ref_count_ > 0) + { + if (--ref_count_ == 0) destroy = true; + } + else + { + ACE_ERROR ((LM_ERROR, + "ExternalLockRefCounter::_remove_ref() " + " _remove_ref() called while ref_coundt == 0\n" + )); + } + return destroy; + } + + inline + unsigned long + ExternalLockRefCounter::_refcount_value_i () + { + return ref_count_; + } + */ + } +} + diff --git a/TAO/CIAO/CCF/External/Utility/Utility/ReferenceCounting/Interface.hpp b/TAO/CIAO/CCF/External/Utility/Utility/ReferenceCounting/Interface.hpp new file mode 100644 index 00000000000..818b5f6413f --- /dev/null +++ b/TAO/CIAO/CCF/External/Utility/Utility/ReferenceCounting/Interface.hpp @@ -0,0 +1,83 @@ +// file : Utility/ReferenceCounting/Interface.hpp +// author : Boris Kolpackov <boris@kolpackov.net> +// copyright : Copyright (c) 2002-2003 Boris Kolpackov +// license : http://kolpackov.net/license.html + +#ifndef UTILITY_REFERENCE_COUNTING_INTERFACE_HPP +#define UTILITY_REFERENCE_COUNTING_INTERFACE_HPP + +#include "Utility/ExH/Compound.hpp" +#include "Utility/ExH/System/Exception.hpp" +#include "Utility/ExH/Logic/Exception.hpp" +#include "Utility/ExH/Logic/DescriptiveException.hpp" + +namespace Utility +{ + namespace ReferenceCounting + { + // Interface to a reference-countable object. Note that _remove_ref () + // member function has a no-throw semantic. Even though it can lead to + // a diagnostic loss it was made no-throw because it has a destructor + // semantic. + + class Interface + { + public: + typedef + unsigned long + count_t; + + typedef + ExH::System::Exception + SystemException; + + class Exception_ {}; + typedef + ExH::Compound<Exception_, ExH::Logic::DescriptiveException> + Exception; + + public: + virtual void + add_ref () const throw (Exception, SystemException) = 0; + + virtual void + remove_ref () const throw () = 0; + + virtual count_t + refcount_value () const throw (Exception, SystemException) = 0; + + protected: + Interface () throw (); + + virtual + ~Interface () throw (); + + protected: + virtual void + add_ref_i () const throw (Exception, SystemException) = 0; + + virtual bool + remove_ref_i () const throw (Exception, SystemException) = 0; + + virtual count_t + refcount_value_i () const throw (Exception, SystemException) = 0; + + private: + // Copy semanic is not supported. + Interface (Interface const&) throw (); + Interface& + operator= (Interface const&) throw (); + }; + + template <typename Type> + Type* + add_ref (Type* ptr) + throw (Interface::Exception, Interface::SystemException); + } +} + +#include "Utility/ReferenceCounting/Interface.tpp" +#include "Utility/ReferenceCounting/Interface.ipp" + +#endif // UTILITY_REFERENCE_COUNTING_INTERFACE_HPP + diff --git a/TAO/CIAO/CCF/External/Utility/Utility/ReferenceCounting/Interface.ipp b/TAO/CIAO/CCF/External/Utility/Utility/ReferenceCounting/Interface.ipp new file mode 100644 index 00000000000..61801d218b6 --- /dev/null +++ b/TAO/CIAO/CCF/External/Utility/Utility/ReferenceCounting/Interface.ipp @@ -0,0 +1,21 @@ +// file : Utility/ReferenceCounting/Interface.ipp +// author : Boris Kolpackov <boris@kolpackov.net> +// copyright : Copyright (c) 2002-2003 Boris Kolpackov +// license : http://kolpackov.net/license.html + +namespace Utility +{ + namespace ReferenceCounting + { + inline Interface:: + ~Interface () throw () + { + } + + inline Interface:: + Interface () throw () + { + } + } +} + diff --git a/TAO/CIAO/CCF/External/Utility/Utility/ReferenceCounting/Interface.tpp b/TAO/CIAO/CCF/External/Utility/Utility/ReferenceCounting/Interface.tpp new file mode 100644 index 00000000000..e4cebab5aa0 --- /dev/null +++ b/TAO/CIAO/CCF/External/Utility/Utility/ReferenceCounting/Interface.tpp @@ -0,0 +1,19 @@ +// file : Utility/ReferenceCounting/Interface.tpp +// author : Boris Kolpackov <boris@kolpackov.net> +// copyright : Copyright (c) 2002-2003 Boris Kolpackov +// license : http://kolpackov.net/license.html + +namespace Utility +{ + namespace ReferenceCounting + { + template <typename Type> + inline Type* + add_ref (Type* ptr) + throw (Interface::Exception, Interface::SystemException) + { + if (ptr != 0) ptr->add_ref (); + return ptr; + } + } +} diff --git a/TAO/CIAO/CCF/External/Utility/Utility/ReferenceCounting/ReferenceCounting.hpp b/TAO/CIAO/CCF/External/Utility/Utility/ReferenceCounting/ReferenceCounting.hpp new file mode 100644 index 00000000000..e3929549768 --- /dev/null +++ b/TAO/CIAO/CCF/External/Utility/Utility/ReferenceCounting/ReferenceCounting.hpp @@ -0,0 +1,15 @@ +// file : Utility/ReferenceCounting/ReferenceCounting.hpp +// author : Boris Kolpackov <boris@kolpackov.net> +// copyright : Copyright (c) 2003 Boris Kolpackov +// license : http://kolpackov.net/license.html + +#ifndef UTILITY_REFERENCE_COUNTING_REFERENCE_COUNTING_HPP +#define UTILITY_REFERENCE_COUNTING_REFERENCE_COUNTING_HPP + +#include "Utility/ReferenceCounting/Interface.hpp" +#include "Utility/ReferenceCounting/DefaultImpl.hpp" +#include "Utility/ReferenceCounting/SmartPtr.hpp" +#include "Utility/ReferenceCounting/StrictPtr.hpp" + +#endif // UTILITY_REFERENCE_COUNTING_REFERENCE_COUNTING_HPP + diff --git a/TAO/CIAO/CCF/External/Utility/Utility/ReferenceCounting/SmartPtr.hpp b/TAO/CIAO/CCF/External/Utility/Utility/ReferenceCounting/SmartPtr.hpp new file mode 100644 index 00000000000..5b0aa13b513 --- /dev/null +++ b/TAO/CIAO/CCF/External/Utility/Utility/ReferenceCounting/SmartPtr.hpp @@ -0,0 +1,102 @@ +// file : Utility/ReferenceCounting/SmartPtr.hpp +// author : Boris Kolpackov <boris@kolpackov.net> +// copyright : Copyright (c) 2002-2003 Boris Kolpackov +// license : http://kolpackov.net/license.html + +#ifndef UTILITY_REFERENCE_COUNTING_SMART_PTR_HPP +#define UTILITY_REFERENCE_COUNTING_SMART_PTR_HPP + +#include "Utility/ExH/Compound.hpp" +#include "Utility/ExH/Logic/DescriptiveException.hpp" + +#include "Utility/ReferenceCounting/Interface.hpp" + +namespace Utility +{ + namespace ReferenceCounting + { + template <typename T> + class SmartPtr + { + public: + typedef + T + Type; + + class NotInitialized_ {}; + typedef + ExH::Compound<NotInitialized_, ExH::Logic::DescriptiveException> + NotInitialized; + + public: + // c-tor's + + SmartPtr () throw (); + SmartPtr (Type* ptr) throw (); + SmartPtr (SmartPtr<Type> const& s_ptr) + throw (Interface::Exception, Interface::SystemException); + + template <typename Other> + SmartPtr (SmartPtr<Other> const& s_ptr) + throw (Interface::Exception, Interface::SystemException); + + // d-tor + + ~SmartPtr () throw (); + + // assignment & copy-assignment operators + + SmartPtr<Type>& + operator= (Type* ptr) throw (); + + SmartPtr<Type>& + operator= (SmartPtr<Type> const& s_ptr) + throw (Interface::Exception, Interface::SystemException); + + template <typename Other> + SmartPtr<Type>& + operator= (SmartPtr<Other> const& s_ptr) + throw (Interface::Exception, Interface::SystemException); + + //conversions + + operator Type* () const throw (); + + // accessors + + Type* + operator-> () const throw (NotInitialized); + + Type* + in () const throw (); + + Type* + retn() throw (); + + private: + Type* ptr_; + }; + + // Specialization of add_ref function for SmartPtr<T> + template <typename T> + T* + add_ref (SmartPtr<T> const& ptr) + throw (Interface::Exception, Interface::SystemException); + + + // Dynamic type conversion function for SmartPtr's + template <typename D, typename S> + D* + smart_cast (SmartPtr<S> const& s) + throw (Interface::Exception, Interface::SystemException); + + // Acquisition function + template <typename T> + SmartPtr<T> + acquire (T* ptr) throw (Interface::Exception, Interface::SystemException); + } +} + +#include "Utility/ReferenceCounting/SmartPtr.tpp" + +#endif // UTILITY_REFERENCE_COUNTING_SMART_PTR_HPP diff --git a/TAO/CIAO/CCF/External/Utility/Utility/ReferenceCounting/SmartPtr.tpp b/TAO/CIAO/CCF/External/Utility/Utility/ReferenceCounting/SmartPtr.tpp new file mode 100644 index 00000000000..405fc1503f4 --- /dev/null +++ b/TAO/CIAO/CCF/External/Utility/Utility/ReferenceCounting/SmartPtr.tpp @@ -0,0 +1,169 @@ +// file : Utility/ReferenceCounting/SmartPtr.tpp +// author : Boris Kolpackov <boris@kolpackov.net> +// copyright : Copyright (c) 2002-2003 Boris Kolpackov +// license : http://kolpackov.net/license.html + +namespace Utility +{ + namespace ReferenceCounting + { + // c-tor's & d-tor + + template <typename T> + SmartPtr<T>:: + SmartPtr () throw () + : ptr_ (0) + { + } + + template <typename T> + SmartPtr<T>:: + SmartPtr (Type* ptr) throw () + : ptr_ (ptr) + { + } + + template <typename T> + SmartPtr<T>:: + SmartPtr (SmartPtr<Type> const& s_ptr) + throw (Interface::Exception, Interface::SystemException) + : ptr_ (add_ref (s_ptr.in ())) + { + } + + template <typename T> + template <typename Other> + SmartPtr<T>:: + SmartPtr (SmartPtr<Other> const& s_ptr) + throw (Interface::Exception, Interface::SystemException) + : ptr_ (add_ref (s_ptr.in ())) + { + } + + + template <typename T> + SmartPtr<T>:: + ~SmartPtr () throw () + { + // This is an additional catch-all layer to protect from + // non-conformant Type. + try + { + if (ptr_ != 0) ptr_->remove_ref (); + } + catch (...) + { + } + } + + // operator= + + template <typename T> + SmartPtr<T>& SmartPtr<T>:: + operator= (Type* ptr) throw () + { + if (ptr_ != 0) ptr_->remove_ref (); + ptr_ = ptr; + return *this; + } + + + template <typename T> + SmartPtr<T>& SmartPtr<T>:: + operator= (SmartPtr<Type> const& s_ptr) + throw (Interface::Exception, Interface::SystemException) + { + Type* old_ptr (ptr_); + Type* new_ptr (add_ref (s_ptr.in ())); // this can throw + if (old_ptr != 0) old_ptr->remove_ref (); + + ptr_ = new_ptr; // commit + + return *this; + } + + + template <typename T> + template <typename Other> + SmartPtr<T>& SmartPtr<T>:: + operator= (SmartPtr<Other> const& s_ptr) + throw (Interface::Exception, Interface::SystemException) + { + Type* old_ptr (ptr_); + Other* new_ptr (add_ref (s_ptr.in ())); // this can throw + if (old_ptr != 0) old_ptr->remove_ref (); + + ptr_ = new_ptr; // commit + + return *this; + } + + // conversions + + template <typename T> + SmartPtr<T>:: + operator T* () const throw () + { + return ptr_; + } + + + // accessors + + template <typename T> + T* SmartPtr<T>:: + operator-> () const throw (NotInitialized) + { + if (ptr_ == 0) + { + throw NotInitialized( + "Utility::ReferenceCounting::SmartPtr::operator-> : " + "unable to dereference NULL pointer."); + } + return ptr_; + } + + template <typename T> + T* SmartPtr<T>:: + in () const throw () + { + return ptr_; + } + + template <typename T> + T* SmartPtr<T>:: + retn() throw () + { + Type* ret (ptr_); + ptr_ = 0; + return ret; + } + + // Specialization of add_ref function for SmartPtr<T> + template <typename T> + T* + add_ref (SmartPtr<T> const& ptr) + throw (Interface::Exception, Interface::SystemException) + { + // delegate to generic implementation + return add_ref (ptr.in ()); + } + + // Dynamic type conversion function for SmartPtr's + template <typename D, typename S> + D* + smart_cast (SmartPtr<S> const& s) + throw (Interface::Exception, Interface::SystemException) + { + return add_ref (dynamic_cast<D*>(s.in ())); + } + + // Acquisition function + template <typename T> + SmartPtr<T> + acquire (T* ptr) throw (Interface::Exception, Interface::SystemException) + { + return SmartPtr<T> (ptr); + } + } +} diff --git a/TAO/CIAO/CCF/External/Utility/Utility/ReferenceCounting/StrictPtr.hpp b/TAO/CIAO/CCF/External/Utility/Utility/ReferenceCounting/StrictPtr.hpp new file mode 100644 index 00000000000..9885e321de9 --- /dev/null +++ b/TAO/CIAO/CCF/External/Utility/Utility/ReferenceCounting/StrictPtr.hpp @@ -0,0 +1,107 @@ +// file : Utility/ReferenceCounting/StrictPtr.hpp +// author : Boris Kolpackov <boris@kolpackov.net> +// copyright : Copyright (c) 2002-2003 Boris Kolpackov +// license : http://kolpackov.net/license.html + +#ifndef UTILITY_REFERENCE_COUNTING_STRICT_PTR_HPP +#define UTILITY_REFERENCE_COUNTING_STRICT_PTR_HPP + +#include "Utility/ExH/Compound.hpp" +#include "Utility/ExH/Logic/DescriptiveException.hpp" + +#include "Utility/ReferenceCounting/Interface.hpp" + +namespace Utility +{ + namespace ReferenceCounting + { + template <typename T> + class StrictPtr + { + public: + typedef + T + Type; + + class NotInitialized_ {}; + typedef + ExH::Compound<NotInitialized_, ExH::Logic::DescriptiveException> + NotInitialized; + + public: + // c-tor's + + StrictPtr () throw (); + + explicit + StrictPtr (Type* ptr) throw (); + + StrictPtr (StrictPtr<Type> const& s_ptr) + throw (Interface::Exception, Interface::SystemException); + + template <typename Other> + StrictPtr (StrictPtr<Other> const& s_ptr) + throw (Interface::Exception, Interface::SystemException); + // d-tor + + ~StrictPtr () throw (); + + // assignment & copy-assignment operators + + StrictPtr<Type>& + operator= (Type* ptr) throw (); + + StrictPtr<Type>& + operator= (StrictPtr<Type> const& s_ptr) + throw (Interface::Exception, Interface::SystemException); + + template <typename Other> + StrictPtr<Type>& + operator= (StrictPtr<Other> const& s_ptr) + throw (Interface::Exception, Interface::SystemException); + + // conversions + + // Note: implicit conversion (operator Type* ()) is not supported. + + // comparison + + bool + operator== (Type* other) const throw (); + + bool + operator!= (Type* other) const throw (); + + // accessors + + Type* + operator-> () const throw (NotInitialized); + + Type* + in () const throw (); + + Type* + retn() throw (); + + private: + Type* ptr_; + }; + + // Specialization of add_ref function for StrictPtr<T> + template <typename T> + T* + add_ref (StrictPtr<T> const& ptr) + throw (Interface::Exception, Interface::SystemException); + + // Dynamic type conversion function for StrictPtr's + template <typename D, typename S> + StrictPtr<D> + strict_cast (StrictPtr<S> const& s) + throw (Interface::Exception, Interface::SystemException); + } +} + +#include "Utility/ReferenceCounting/StrictPtr.tpp" + +#endif // UTILITY_REFERENCE_COUNTING_STRICT_PTR_HPP + diff --git a/TAO/CIAO/CCF/External/Utility/Utility/ReferenceCounting/StrictPtr.tpp b/TAO/CIAO/CCF/External/Utility/Utility/ReferenceCounting/StrictPtr.tpp new file mode 100644 index 00000000000..84d97fb6b30 --- /dev/null +++ b/TAO/CIAO/CCF/External/Utility/Utility/ReferenceCounting/StrictPtr.tpp @@ -0,0 +1,166 @@ +// file : Utility/ReferenceCounting/StrictPtr.tpp +// author : Boris Kolpackov <boris@kolpackov.net> +// copyright : Copyright (c) 2002-2003 Boris Kolpackov +// license : http://kolpackov.net/license.html + +namespace Utility +{ + namespace ReferenceCounting + { + // c-tor's & d-tor + + template <typename T> + StrictPtr<T>:: + StrictPtr () throw () + : ptr_ (0) + { + } + + template <typename T> + StrictPtr<T>:: + StrictPtr (Type* ptr) throw () + : ptr_ (ptr) + { + } + + template <typename T> + StrictPtr<T>:: + StrictPtr (StrictPtr<Type> const& s_ptr) + throw (Interface::Exception, Interface::SystemException) + : ptr_ (add_ref (s_ptr.in ())) + { + } + + template <typename T> + template <typename Other> + StrictPtr<T>:: + StrictPtr (StrictPtr<Other> const& s_ptr) + throw (Interface::Exception, Interface::SystemException) + : ptr_ (add_ref (s_ptr.in ())) + { + } + + + template <typename T> + StrictPtr<T>:: + ~StrictPtr () throw () + { + // This is an additional catch-all layer to protect from + // non-conformant Type. + try + { + if (ptr_ != 0) ptr_->remove_ref (); + } + catch (...) + { + } + } + + // operator= + + template <typename T> + StrictPtr<T>& + StrictPtr<T>::operator= (Type* ptr) throw () + { + if (ptr_ != 0) ptr_->remove_ref (); + ptr_ = ptr; + return *this; + } + + template <typename T> + StrictPtr<T>& StrictPtr<T>:: + operator= (StrictPtr<Type> const& s_ptr) + throw (Interface::Exception, Interface::SystemException) + { + Type* old_ptr (ptr_); + Type* new_ptr (add_ref (s_ptr.in ())); // this can throw + if (old_ptr != 0) old_ptr->remove_ref (); + + ptr_ = new_ptr; // commit + + return *this; + } + + + template <typename T> + template <typename Other> + StrictPtr<T>& StrictPtr<T>:: + operator= (StrictPtr<Other> const& s_ptr) + throw (Interface::Exception, Interface::SystemException) + { + Type* old_ptr (ptr_); + Other* new_ptr (add_ref (s_ptr.in ())); // this can throw + if (old_ptr != 0) old_ptr->remove_ref (); + + ptr_ = new_ptr; // commit + + return *this; + } + + // comparison + + template <typename T> + bool StrictPtr<T>:: + operator== (Type* other) const throw () + { + return ptr_ == other; + } + + template <typename T> + bool StrictPtr<T>:: + operator!= (Type* other) const throw () + { + return ptr_ != other; + } + + // accessors + + template <typename T> + T* StrictPtr<T>:: + operator-> () const throw (NotInitialized) + { + if (ptr_ == 0) + { + throw NotInitialized( + "Utility::ReferenceCounting::StrictPtr::operator-> : " + "unable to dereference NULL pointer."); + } + return ptr_; + } + + template <typename T> + T* StrictPtr<T>:: + in () const throw () + { + return ptr_; + } + + template <typename T> + T* StrictPtr<T>:: + retn() throw () + { + Type* ret (ptr_); + ptr_ = 0; + return ret; + } + + // Specialization of add_ref function for StrictPtr<T> + template <typename T> + T* + add_ref (StrictPtr<T> const& ptr) + throw (Interface::Exception, Interface::SystemException) + { + // delegate to generic implementation + return add_ref (ptr.in ()); + } + + // Dynamic type conversion function for StrictPtr's + template <typename D, typename S> + StrictPtr<D> + strict_cast (StrictPtr<S> const& s) + throw (Interface::Exception, Interface::SystemException) + { + return StrictPtr<D>(add_ref (dynamic_cast<D*>(s.in ()))); + } + } +} diff --git a/TAO/CIAO/CCF/External/Utility/Utility/Synch/Policy/Null.hpp b/TAO/CIAO/CCF/External/Utility/Utility/Synch/Policy/Null.hpp new file mode 100644 index 00000000000..d7a26e81089 --- /dev/null +++ b/TAO/CIAO/CCF/External/Utility/Utility/Synch/Policy/Null.hpp @@ -0,0 +1,53 @@ +// file : Utility/Synch/Policy/Null.hpp +// author : Boris Kolpackov <boris@kolpackov.net> +// copyright : Copyright (c) 2002-2003 Boris Kolpackov +// license : http://kolpackov.net/license.html + +#ifndef UTILITY_SYNCH_POLICY_NULL_HPP +#define UTILITY_SYNCH_POLICY_NULL_HPP + +namespace Utility +{ + namespace Synch + { + namespace Policy + { + + class NullMutex + { + }; + + class NullGuard + { + public: + explicit + NullGuard (NullMutex&) throw (); + + private: + NullGuard (NullGuard const&) throw (); + + NullGuard& + operator= (NullGuard const&) throw (); + }; + + struct Null + { + typedef + NullMutex + Mutex; + + typedef + NullGuard + ReadGuard; + + typedef + NullGuard + WriteGuard; + }; + } + } +} + +#include "Utility/Synch/Policy/Null.ipp" + +#endif // UTILITY_SYNCH_POLICY_NULL_HPP diff --git a/TAO/CIAO/CCF/External/Utility/Utility/Synch/Policy/Null.ipp b/TAO/CIAO/CCF/External/Utility/Utility/Synch/Policy/Null.ipp new file mode 100644 index 00000000000..55c254bafc0 --- /dev/null +++ b/TAO/CIAO/CCF/External/Utility/Utility/Synch/Policy/Null.ipp @@ -0,0 +1,19 @@ +// file : Utility/Synch/Policy/Null.ipp +// author : Boris Kolpackov <boris@kolpackov.net> +// copyright : Copyright (c) 2002-2003 Boris Kolpackov +// license : http://kolpackov.net/license.html + +namespace Utility +{ + namespace Synch + { + namespace Policy + { + inline NullGuard:: + NullGuard (NullMutex&) throw () + { + } + } + } +} + diff --git a/TAO/CIAO/CCF/External/Utility/Version b/TAO/CIAO/CCF/External/Utility/Version new file mode 100644 index 00000000000..9084fa2f716 --- /dev/null +++ b/TAO/CIAO/CCF/External/Utility/Version @@ -0,0 +1 @@ +1.1.0 diff --git a/TAO/CIAO/CCF/Makefile b/TAO/CIAO/CCF/Makefile new file mode 100644 index 00000000000..91de9e1a44b --- /dev/null +++ b/TAO/CIAO/CCF/Makefile @@ -0,0 +1,14 @@ +# file : Makefile +# author : Boris Kolpackov <boris@kolpackov.net> +# copyright : Copyright (c) 2002-2003 Boris Kolpackov +# license : http://kolpackov.net/license.html +# cvs-id : $Id$ + +root := . + +include $(root)/External/Utility/Config/Recursion.pre.rules + +target_makefile_list := +target_directory_list := CCF + +include $(root)/External/Utility/Config/Recursion.post.rules diff --git a/TAO/CIAO/CCF/Version b/TAO/CIAO/CCF/Version new file mode 100644 index 00000000000..7bcd0e3612d --- /dev/null +++ b/TAO/CIAO/CCF/Version @@ -0,0 +1 @@ +0.0.2
\ No newline at end of file diff --git a/TAO/CIAO/CIDLC/CIDLC.sln b/TAO/CIAO/CIDLC/CIDLC.sln new file mode 100644 index 00000000000..24dee7c9742 --- /dev/null +++ b/TAO/CIAO/CIDLC/CIDLC.sln @@ -0,0 +1,21 @@ +Microsoft Visual Studio Solution File, Format Version 8.00 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "CIDLC", "CIDLC.vcproj", "{2AA9F186-AEB2-4B78-9783-322182479BBB}" + ProjectSection(ProjectDependencies) = postProject + EndProjectSection +EndProject +Global + GlobalSection(SolutionConfiguration) = preSolution + Debug = Debug + Release = Release + EndGlobalSection + GlobalSection(ProjectConfiguration) = postSolution + {2AA9F186-AEB2-4B78-9783-322182479BBB}.Debug.ActiveCfg = Debug|Win32 + {2AA9F186-AEB2-4B78-9783-322182479BBB}.Debug.Build.0 = Debug|Win32 + {2AA9F186-AEB2-4B78-9783-322182479BBB}.Release.ActiveCfg = Release|Win32 + {2AA9F186-AEB2-4B78-9783-322182479BBB}.Release.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + EndGlobalSection + GlobalSection(ExtensibilityAddIns) = postSolution + EndGlobalSection +EndGlobal diff --git a/TAO/CIAO/CIDLC/CIDLC.vcproj b/TAO/CIAO/CIDLC/CIDLC.vcproj new file mode 100644 index 00000000000..b9c55d46c5e --- /dev/null +++ b/TAO/CIAO/CIDLC/CIDLC.vcproj @@ -0,0 +1,164 @@ +<?xml version="1.0" encoding="Windows-1252"?> +<VisualStudioProject + ProjectType="Visual C++" + Version="7.10" + Name="CIDLC" + ProjectGUID="{2AA9F186-AEB2-4B78-9783-322182479BBB}" + Keyword="Win32Proj"> + <Platforms> + <Platform + Name="Win32"/> + </Platforms> + <Configurations> + <Configuration + Name="Debug|Win32" + OutputDirectory="$(ProjectDir)" + IntermediateDirectory="Debug" + ConfigurationType="1" + CharacterSet="2"> + <Tool + Name="VCCLCompilerTool" + Optimization="0" + AdditionalIncludeDirectories="../CCF;../CCF/External/Utility" + PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE" + MinimalRebuild="TRUE" + BasicRuntimeChecks="3" + RuntimeLibrary="5" + ForceConformanceInForLoopScope="TRUE" + RuntimeTypeInfo="TRUE" + UsePrecompiledHeader="0" + WarningLevel="3" + Detect64BitPortabilityProblems="TRUE" + DebugInformationFormat="4"/> + <Tool + Name="VCCustomBuildTool"/> + <Tool + Name="VCLinkerTool" + AdditionalDependencies="IDL2.lib IDL3.lib CIDL.lib CodeGenerationKit.lib libboost_regex_debug.lib libboost_filesystem_debug.lib" + OutputFile="$(CIAO_ROOT)\bin\cidlc.exe" + LinkIncremental="2" + AdditionalLibraryDirectories="../CCF/CCF/IDL2;../CCF/CCF/IDL3;../CCF/CCF/CIDL;../CCF/CCF/CodeGenerationKit" + GenerateDebugInformation="TRUE" + ProgramDatabaseFile="$(OutDir)/CIDLC.pdb" + SubSystem="1" + TargetMachine="1"/> + <Tool + Name="VCMIDLTool"/> + <Tool + Name="VCPostBuildEventTool"/> + <Tool + Name="VCPreBuildEventTool"/> + <Tool + Name="VCPreLinkEventTool"/> + <Tool + Name="VCResourceCompilerTool"/> + <Tool + Name="VCWebServiceProxyGeneratorTool"/> + <Tool + Name="VCXMLDataGeneratorTool"/> + <Tool + Name="VCWebDeploymentTool"/> + <Tool + Name="VCManagedWrapperGeneratorTool"/> + <Tool + Name="VCAuxiliaryManagedWrapperGeneratorTool"/> + </Configuration> + <Configuration + Name="Release|Win32" + OutputDirectory="Release" + IntermediateDirectory="Release" + ConfigurationType="1" + CharacterSet="2"> + <Tool + Name="VCCLCompilerTool" + PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE" + RuntimeLibrary="4" + UsePrecompiledHeader="0" + WarningLevel="3" + Detect64BitPortabilityProblems="TRUE" + DebugInformationFormat="3"/> + <Tool + Name="VCCustomBuildTool"/> + <Tool + Name="VCLinkerTool" + OutputFile="$(OutDir)/CIDLC.exe" + LinkIncremental="1" + GenerateDebugInformation="TRUE" + SubSystem="1" + OptimizeReferences="2" + EnableCOMDATFolding="2" + TargetMachine="1"/> + <Tool + Name="VCMIDLTool"/> + <Tool + Name="VCPostBuildEventTool"/> + <Tool + Name="VCPreBuildEventTool"/> + <Tool + Name="VCPreLinkEventTool"/> + <Tool + Name="VCResourceCompilerTool"/> + <Tool + Name="VCWebServiceProxyGeneratorTool"/> + <Tool + Name="VCXMLDataGeneratorTool"/> + <Tool + Name="VCWebDeploymentTool"/> + <Tool + Name="VCManagedWrapperGeneratorTool"/> + <Tool + Name="VCAuxiliaryManagedWrapperGeneratorTool"/> + </Configuration> + </Configurations> + <References> + </References> + <Files> + <Filter + Name="Source Files" + Filter="cpp;c;cxx;def;odl;idl;hpj;bat;asm;asmx" + UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"> + <File + RelativePath=".\cidlc.cpp"> + </File> + <File + RelativePath=".\ExecutorMappingGenerator.cpp"> + </File> + <File + RelativePath=".\ServantGenerator.cpp"> + </File> + <File + RelativePath=".\ServantHeaderGenerator.cpp"> + </File> + <File + RelativePath=".\ServantSourceGenerator.cpp"> + </File> + </Filter> + <Filter + Name="Header Files" + Filter="h;hpp;hxx;hm;inl;inc;xsd" + UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"> + <File + RelativePath=".\ExecutorMappingGenerator.hpp"> + </File> + <File + RelativePath=".\Literals.hpp"> + </File> + <File + RelativePath=".\ServantGenerator.hpp"> + </File> + <File + RelativePath=".\ServantHeaderGenerator.hpp"> + </File> + <File + RelativePath=".\ServantSourceGenerator.hpp"> + </File> + </Filter> + <Filter + Name="Resource Files" + Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx" + UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}"> + </Filter> + </Files> + <Globals> + </Globals> +</VisualStudioProject> diff --git a/TAO/CIAO/CIDLC/ExecutorMappingGenerator.cpp b/TAO/CIAO/CIDLC/ExecutorMappingGenerator.cpp new file mode 100644 index 00000000000..90ca844f722 --- /dev/null +++ b/TAO/CIAO/CIDLC/ExecutorMappingGenerator.cpp @@ -0,0 +1,1066 @@ +// $Id$ +#include "ExecutorMappingGenerator.hpp" + +#include <map> +#include <ostream> +#include <fstream> + +#include "CCF/CIDL/CIDL_SyntaxTree.hpp" +#include "CCF/CIDL/CIDL_Traversal.hpp" + +#include "CCF/CodeGenerationKit/Regex.hpp" +#include "CCF/CodeGenerationKit/IDLStream.hpp" + +using std::cout; +using std::endl; +using std::string; +using std::make_pair; + +using namespace CIDL; +using namespace CIDL::SyntaxTree; + +namespace +{ + typedef + std::map <CompositionPtr, ComponentDefPtr, CompositionOrderComparator> + CompositionMap; + + // ProvidesCollector collects interfaces that appear in provides + // declaration of a component in question. Used as a building block + // by Collector. + // + class ProvidesCollector : public virtual Traversal::ComponentDef, + public virtual Traversal::ProvidesDecl + { + public: + ProvidesCollector(UnconstrainedInterfaceDeclSet& interface_set) + : interface_set_ (interface_set) + { + } + + virtual void + visit_provides_decl (ProvidesDeclPtr const& p) + { + //@@ CCM issue: interface should be defined at this point + // and this should be ensured during semantic + // checking. + + UnconstrainedInterfaceDeclPtr decl ( + p->type ()->dynamic_type<UnconstrainedInterfaceDecl> ()); + + // We are only interested in unconstrained interfaces. + if (decl != 0) + { + ScopedName orig (decl->name ()); + ScopedName mapping (orig.scope (), "CCM_" + orig.simple ()); + + // Check if mapping has already been provided. + //@@ bad code: i->scope ()->table () + if (!decl->scope ()->table ().exist (mapping)) + { + // Add to the list if it's not already there. + interface_set_.insert (decl); + } + } + } + + private: + UnconstrainedInterfaceDeclSet& interface_set_; + }; + + + // Collector populates lists of declarations for which local facet + // executor mapping should be provided. + // + class Collector : public virtual Traversal::TranslationUnit, + public virtual Traversal::PrincipalTranslationRegion, + public virtual Traversal::FileScope, + public virtual Traversal::Module, + public virtual Traversal::Composition, + public virtual Traversal::HomeExecutor, + public virtual Traversal::ConcreteEventTypeDef + { + public: + Collector (UnconstrainedInterfaceDeclSet& interface_set, + ComponentDefSet& component_set, + ConcreteEventTypeDefSet& event_type_set, + HomeDefSet& home_set, + CompositionMap& composition_map) + : home_set_ (home_set), + component_set_ (component_set), + event_type_set_ (event_type_set), + composition_map_ (composition_map), + provides_collector_ (interface_set) + { + } + + virtual void + visit_home_executor (HomeExecutorPtr const& he) + { + CompositionPtr composition ( + he->scope ()->dynamic_type<SyntaxTree::Composition> ()); + + HomeDefPtr home (he->implements ()); + + ComponentDefPtr component (home->manages ()); + + composition_map_.insert (make_pair (composition, component)); + + add_home (home); + add_component (component); + } + + virtual void + visit_concrete_event_type_def (ConcreteEventTypeDefPtr const& et) + { + /* + @@ CCM issue: spec says that I need to ganarate this but nobody + knows why. + event_type_set_.insert (et); + */ + } + + private: + void + add_home (HomeDefPtr const& h) + { + ScopedName n (h->name ()); + + ScopedName main (n.scope (), "CCM_" + n.simple ()); + ScopedName expl (n.scope (), "CCM_" + n.simple () + "Explicit"); + ScopedName impl (n.scope (), "CCM_" + n.simple () + "Implicit"); + + // Check if mapping has already been provided. + if (h->table ().exist (main) || + h->table ().exist (expl) || + h->table ().exist (impl)) return; + + if(home_set_.insert (h).second) + { + // Note that I don't go after components that home manages + // because it will be handled by component inheritance tree. + // + if (h->inherits ()) add_home (h->inherits ().resolve ()); + } + } + + void + add_component (ComponentDefPtr const& component) + { + ScopedName n (component->name ()); + + ScopedName monolith (n.scope (), "CCM_" + n.simple ()); + ScopedName context (n.scope (), "CCM_" + n.simple () + "_Context"); + + // Check if mapping has already been provided. + if (component->table ().exist (context) || + component->table ().exist (monolith)) return; + + if(component_set_.insert (component).second) + { + component->accept (&provides_collector_); + + if (component->inherits ()) + { + add_component (component->inherits ().resolve ()); + } + } + } + + private: + HomeDefSet& home_set_; + ComponentDefSet& component_set_; + ConcreteEventTypeDefSet& event_type_set_; + CompositionMap& composition_map_; + + ProvidesCollector provides_collector_; + }; + + // + // + // + class ForcedCollector : public virtual Traversal::TranslationUnit, + public virtual Traversal::PrincipalTranslationRegion, + public virtual Traversal::FileScope, + public virtual Traversal::Module, + public virtual Traversal::ComponentDef, + public virtual Traversal::HomeDef, + public virtual Traversal::UnconstrainedInterfaceDef + { + public: + ForcedCollector (UnconstrainedInterfaceDeclSet& interface_set, + ComponentDefSet& component_set, + ConcreteEventTypeDefSet& event_type_set, + HomeDefSet& home_set, + CompositionMap& composition_map) + : home_set_ (home_set), + component_set_ (component_set), + event_type_set_ (event_type_set), + composition_map_ (composition_map), + interface_set_ (interface_set) + { + } + + virtual void + visit_component_def (ComponentDefPtr const& c) + { + add_component (c); + } + + virtual void + visit_home_def (HomeDefPtr const& h) + { + add_home (h); + } + + virtual void + visit_unconstrained_interface_def (UnconstrainedInterfaceDefPtr const& i) + { + ScopedName orig (i->name ()); + ScopedName mapping (orig.scope (), "CCM_" + orig.simple ()); + + // Check if mapping has already been provided. + if (i->table ().exist (mapping)) return; + + // Add to the list if it's not already there. + interface_set_.insert (i); + } + + virtual void + visit_concrete_event_type_def (ConcreteEventTypeDefPtr const& et) + { + /* + @@ CCM issue: spec says that I need to ganarate this but nobody + knows why. + event_type_set_.insert (et); + */ + } + + private: + void + add_home (HomeDefPtr const& h) + { + ScopedName n (h->name ()); + + ScopedName main (n.scope (), "CCM_" + n.simple ()); + ScopedName expl (n.scope (), "CCM_" + n.simple () + "Explicit"); + ScopedName impl (n.scope (), "CCM_" + n.simple () + "Implicit"); + + // Check if mapping has already been provided. + if (h->table ().exist (main) || + h->table ().exist (expl) || + h->table ().exist (impl)) return; + + if(home_set_.insert (h).second) + { + // Note that I don't go after components that home manages + // because it will be handled by component inheritance tree. + // + if (h->inherits ()) add_home (h->inherits ().resolve ()); + } + } + + void + add_component (ComponentDefPtr const& component) + { + ScopedName n (component->name ()); + + ScopedName monolith (n.scope (), "CCM_" + n.simple ()); + ScopedName context (n.scope (), "CCM_" + n.simple () + "_Context"); + + // Check if mapping has already been provided. + if (component->table ().exist (context) || + component->table ().exist (monolith)) return; + + if(component_set_.insert (component).second) + { + if (component->inherits ()) + { + add_component (component->inherits ().resolve ()); + } + } + } + + private: + HomeDefSet& home_set_; + ComponentDefSet& component_set_; + ConcreteEventTypeDefSet& event_type_set_; + CompositionMap& composition_map_; + UnconstrainedInterfaceDeclSet& interface_set_; + }; + + + // + // + // + class TypeNameEmitter : public virtual Traversal::BuiltInTypeDef, + public virtual Traversal::TypeDecl + { + public: + TypeNameEmitter (std::ostream& os_) + : os (os_) + { + } + + virtual void + visit_built_in_type_def (BuiltInTypeDefPtr const& t) + { + os << t->name ().simple (); + } + + virtual void + visit_type_decl (TypeDeclPtr const& t) + { + os << t->name (); + } + + private: + std::ostream& os; + }; + + + // MonolithEmitter generates what spec calls 'Monolithic Component + // Executor'. + // + class MonolithEmitter : public virtual Traversal::ComponentDef, + public virtual Traversal::AttributeDecl, + public virtual Traversal::ProvidesDecl, + public virtual Traversal::ConsumesDecl + { + public: + MonolithEmitter (std::ostream& os_, + ComponentDefSet const& component_set, + CCF::Traversal::Visitor* type_name_emitter) + : AttributeDecl (type_name_emitter), + os (os_), + component_set_ (component_set) + { + } + + virtual void + visit_component_def (ComponentDefPtr const& c) + { + if (component_set_.find (c) != component_set_.end ()) + { + Traversal::ComponentDef::visit_component_def (c); + } + } + + virtual void + visit_component_def_pre (ComponentDefPtr const& c) + { + os << "local interface CCM_" << c->name ().simple () << " : "; + + ComponentDefRef cr = c->inherits (); + + if (cr) + { + os << cr.name ().scope () << "::CCM_" << cr.name ().simple (); + } + else + { + os << "::Components::EnterpriseComponent"; + } + + for (SyntaxTree::ComponentDef::Iterator i = c->supports_begin (); + i != c->supports_end (); + i++) + { + os << ", " << i->name (); + } + + os << endl + << "{" << endl; + } + + virtual void + visit_attribute_pre (AttributeDeclPtr const& a) + { + os << "attribute "; + } + + virtual void + visit_attribute_post (AttributeDeclPtr const& a) + { + os << " " << a->name ().simple () << ";" << endl; + } + + virtual void + visit_provides_decl (ProvidesDeclPtr const& p) + { + ScopedName n = p->type ()->name (); + + os << n.scope () << "::CCM_" << n.simple () + << " get_" << p->name ().simple () << " ();" << endl; + } + + virtual void + visit_consumes_decl (ConsumesDeclPtr const& p) + { + os << "void push_" << p->name ().simple () + << " (in " << p->type()->name () << " ev);" << endl; + } + + virtual void + visit_component_def_post (ComponentDefPtr const& c) + { + os << "};" << endl + << endl; + } + + private: + std::ostream& os; + ComponentDefSet const& component_set_; + }; + + // ContextEmitter generates component context interface. + // + // + class ContextEmitter : public virtual Traversal::ComponentDef, + public virtual Traversal::UsesDecl, + public virtual Traversal::PublishesDecl, + public virtual Traversal::EmitsDecl + { + public: + ContextEmitter (std::ostream& os_, + ComponentDefSet const& component_set) + : os (os_), + component_set_ (component_set) + { + } + + virtual void + visit_component_def (ComponentDefPtr const& c) + { + if (component_set_.find (c) != component_set_.end ()) + { + Traversal::ComponentDef::visit_component_def (c); + } + } + + + virtual void + visit_component_def_pre (ComponentDefPtr const& c) + { + os << "local interface " + << "CCM_" << c->name ().simple () << "_Context " + << " : "; + + ComponentDefRef cr = c->inherits (); + + if (cr) + { + ScopedName name (cr.name ()); + os << name.scope () << "::CCM_" << name.simple () << "_Context"; + } + else + { + os << "::Components::SessionContext"; + } + + os << endl + << "{" << endl; + } + + virtual void + visit_uses_decl (UsesDeclPtr const& d) + { + os << d->type ()->name () + << " get_connection_" << d->name ().simple () + << " ();" << endl; + } + + virtual void + visit_publishes_decl (PublishesDeclPtr const& d) + { + os << "void push_" << d->name ().simple () + << " (in " << d->type ()->name () << " ev);" << endl; + } + + virtual void + visit_emits_decl (EmitsDeclPtr const& d) + { + os << "void push_" << d->name ().simple () + << " (in " << d->type ()->name () << " ev);" << endl; + } + + virtual void + visit_component_def_post (ComponentDefPtr const& c) + { + os << "};" << endl + << endl; + } + + private: + std::ostream& os; + ComponentDefSet const& component_set_; + }; + + // HomeExplicitEmitter generates home explicit interface + // + // + class HomeExplicitEmitter : public virtual Traversal::OperationParameter, + public virtual Traversal::Comma, + public virtual Traversal::HomeFactoryDecl, + public virtual Traversal::OperationDecl, + public virtual Traversal::AttributeDecl, + public virtual Traversal::HomeDef + { + public: + HomeExplicitEmitter (std::ostream& os_, + CCF::Traversal::Visitor* type_name_emitter) + : OperationParameter (type_name_emitter, + type_name_emitter, + type_name_emitter), + + OperationDecl (type_name_emitter), + AttributeDecl (type_name_emitter), + os (os_) + { + } + + virtual void + visit_home_def_pre (HomeDefPtr const& h) + { + os << "local interface " + << "CCM_" << h->name ().simple () << "Explicit" + << " : "; + + HomeDefRef hr = h->inherits (); + + if (hr) + { + ScopedName name (hr.name ()); + os << name.scope () << "::CCM_" << name.simple () << "Explicit"; + } + else + { + os << "::Components::HomeExecutorBase"; + } + + for (SyntaxTree::HomeDef::Iterator i = h->supports_begin (); + i != h->supports_end (); + i++) + { + os << ", " << i->name (); + } + + os << endl + << "{" << endl; + + } + + // + // OperationParameter + // + + virtual void + visit_operation_parameter_post (OperationParameterPtr const& op) + { + os << " " << op->name (); + } + + virtual void + visit_comma (CommaPtr const& s) + { + os << ", "; + } + + // + // HomeFactory + // + + virtual void + visit_home_factory_decl_type (HomeFactoryDeclPtr const& d) + { + os << "::Components::EnterpriseComponent "; + } + + virtual void + visit_home_factory_decl_name (HomeFactoryDeclPtr const& d) + { + os << d->name ().simple () << " ("; + } + + virtual void + visit_home_factory_decl_post (HomeFactoryDeclPtr const& d) + { + os << ");" << endl; + } + + // + // Operation + // + + virtual void + visit_operation_decl_name (OperationDeclPtr const& d) + { + os << " " << d->name ().simple () << " ("; + } + + virtual void + visit_operation_parameter_pre (OperationParameterPtr const& op) + { + os << op->direction () << " "; + } + + virtual void + visit_operation_decl_post (OperationDeclPtr const& d) + { + os << ");" << endl; + } + + // + // Attribute + // + + virtual void + visit_attribute_pre (AttributeDeclPtr const& a) + { + os << "attribute "; + } + + virtual void + visit_attribute_post (AttributeDeclPtr const& a) + { + os << " " << a->name ().simple () << ";" << endl; + } + + virtual void + visit_home_def_post (HomeDefPtr const& h) + { + os << "};" << endl + << endl; + } + + private: + std::ostream& os; + }; + + // HomeImplicitEmitter generates home implicit interface + // + // + class HomeImplicitEmitter : public virtual Traversal::HomeDef + { + public: + HomeImplicitEmitter (std::ostream& os_) : os (os_) {} + + virtual void + visit_home_def_pre (HomeDefPtr const& h) + { + os << "local interface " + << "CCM_" << h->name ().simple () << "Implicit" << endl + << "{" << endl + << "::Components::EnterpriseComponent " + << "create () raises (::Components::CCMException);" + << endl; + + } + + virtual void + visit_home_def_post (HomeDefPtr const& h) + { + os << "};" << endl + << endl; + } + + private: + std::ostream& os; + }; + + // HomeMainEmitter generates home main interface + // + // + class HomeMainEmitter : public virtual Traversal::HomeDef + { + public: + HomeMainEmitter (std::ostream& os_) : os (os_) {} + + virtual void + visit_home_def_pre (HomeDefPtr const& h) + { + SimpleName name = h->name ().simple (); + + os << "local interface " + << "CCM_" << name + << " : " + << "CCM_" << name << "Explicit, " + << "CCM_" << name << "Implicit" << endl + << "{" << endl; + } + + virtual void + visit_home_def_post (HomeDefPtr const& h) + { + os << "};" << endl + << endl; + } + + private: + std::ostream& os; + }; + + class IncludeEmitter : + public virtual Traversal::TranslationUnit, + public virtual Traversal::ImpliedIncludeTranslationRegion, + public virtual Traversal::PrincipalTranslationRegion, + public virtual Traversal::IncludeTranslationRegion, + public virtual Traversal::SysIncludeTranslationRegion + { + public: + IncludeEmitter (std::ostream& os_) : os (os_) {} + + virtual void + visit_implied_include_translation_region ( + ImpliedIncludeTranslationRegionPtr const& r) + { + os << "#include <" << r->file_path ().string () << ">" << endl; + } + + virtual void + visit_include_translation_region (IncludeTranslationRegionPtr const& r) + { + os << "#include \"" << r->file_path ().string () << "\"" << endl; + } + + virtual void + visit_sys_include_translation_region ( + SysIncludeTranslationRegionPtr const& r) + { + os << "#include <" << r->file_path ().string () << ">" << endl; + } + private: + std::ostream& os; + }; + + + // Emitter generates local executor mapping for declarations collected + // by Collector. Note that the original structire of modules is preserved. + // + class Emitter : public virtual Traversal::TranslationUnit, + public virtual Traversal::TranslationRegion, + public virtual Traversal::FileScope, + public virtual Traversal::Module, + public virtual Traversal::UnconstrainedInterfaceDecl, + public virtual Traversal::ConcreteEventTypeDef, + public virtual Traversal::ComponentDef, + public virtual Traversal::HomeDef, + public virtual Traversal::Composition + { + public: + Emitter (std::ostream& os_, + UnconstrainedInterfaceDeclSet const& interface_set, + ComponentDefSet const& component_set, + ConcreteEventTypeDefSet const& event_type_set, + HomeDefSet const& home_set, + CompositionMap const& composition_map) + : os(os_), + home_set_ (home_set), + component_set_ (component_set), + event_type_set_ (event_type_set), + interface_set_ (interface_set), + composition_map_ (composition_map), + + type_name_emitter_ (os_), + + context_emitter_ (os, component_set), + include_emitter_ (os), + monolith_emitter_ (os, component_set, &type_name_emitter_), + home_main_emitter_ (os), + home_explicit_emitter_ (os, &type_name_emitter_), + home_implicit_emitter_ (os) + { + } + + bool + contains_element (ModulePtr const& m) const + { + for (UnconstrainedInterfaceDeclSet::const_iterator i = + interface_set_.begin (); + i != interface_set_.end (); + i++) + { + if (m->order ().suborder ((*i)->order ())) return true; + } + + for (ComponentDefSet::const_iterator i = component_set_.begin (); + i != component_set_.end (); + i++) + { + if (m->order ().suborder ((*i)->order ())) return true; + } + + for (ConcreteEventTypeDefSet::const_iterator i = + event_type_set_.begin (); + i != event_type_set_.end (); + i++) + { + if (m->order ().suborder ((*i)->order ())) return true; + } + + for (HomeDefSet::const_iterator i = home_set_.begin (); + i != home_set_.end (); + i++) + { + if (m->order ().suborder ((*i)->order ())) return true; + } + + for (CompositionMap::const_iterator i = composition_map_.begin (); + i != composition_map_.end (); + i++) + { + if (m->order ().suborder (i->first->order ())) return true; + } + + return false; + } + + virtual void + visit_translation_unit_pre (TranslationUnitPtr const& u) + { + u->accept(&include_emitter_); + os << endl; + } + + virtual void + visit_module_pre (ModulePtr const& m) + { + if (contains_element (m)) + { + os << "module " << m->name ().simple () << endl + << "{" << endl; + } + } + + virtual void + visit_module_post (ModulePtr const& m) + { + if (contains_element (m)) + { + os << "};" << endl + << endl; + } + } + + virtual void + visit_unconstrained_interface_decl_pre ( + UnconstrainedInterfaceDeclPtr const& i) + { + if (interface_set_.find (i) != interface_set_.end ()) + { + os << "local interface CCM_" << i->name ().simple () + << " : " << i->name ().simple () << endl + << "{" << endl + << "};" << endl + << endl; + } + } + + virtual void + visit_concrete_event_type_def_pre (ConcreteEventTypeDefPtr const& et) + { + /* + @@ CCM issue: spec says that I need to ganarate this but nobody + knows why. + + os << "local interface " + << "CCM_" << et->name ().simple () << "Consumer" << endl + << "{" << endl + << "void push (in " << et->name ().simple () << " ev);" << endl + << "};" << endl + << endl; + */ + } + + virtual void + visit_component_def (ComponentDefPtr const& c) + { + c->accept (&monolith_emitter_); + c->accept (&context_emitter_); + } + + virtual void + visit_home_def (HomeDefPtr const& h) + { + if (home_set_.find (h) != home_set_.end ()) + { + h->accept (&home_explicit_emitter_); + h->accept (&home_implicit_emitter_); + h->accept (&home_main_emitter_); + } + } + + virtual void + visit_composition (CompositionPtr const& c) + { + if (composition_map_.find (c) != composition_map_.end ()) + { + Traversal::Composition::visit_composition (c); + } + } + + virtual void + visit_composition_pre (CompositionPtr const& c) + { + ComponentDefPtr component (composition_map_.find (c)->second); + SyntaxTree::Composition::Category::Value category = c->category (); + + os << "module " << c->name ().simple () << endl + << "{" << endl; + + os << "local interface _Context : " + << component->name ().scope () << "::CCM_" + << component->name ().simple () << "_Context, "; + + if (category == SyntaxTree::Composition::Category::ENTITY) + { + os << "::Components::EntityContext" << endl; + } + else + { + os << "::Components::SessionContext" << endl; + } + + os << "{" << endl + << "};" << endl + << endl; + } + + + virtual void + visit_composition_post (CompositionPtr const& c) + { + os << "};" << endl + << endl; + } + + + private: + + std::ostream& os; + + HomeDefSet const& home_set_; + ComponentDefSet const& component_set_; + ConcreteEventTypeDefSet const& event_type_set_; + UnconstrainedInterfaceDeclSet const& interface_set_; + CompositionMap const& composition_map_; + + TypeNameEmitter type_name_emitter_; + + ContextEmitter context_emitter_; + IncludeEmitter include_emitter_; + MonolithEmitter monolith_emitter_; + HomeMainEmitter home_main_emitter_; + HomeExplicitEmitter home_explicit_emitter_; + HomeImplicitEmitter home_implicit_emitter_; + }; +} + +void ExecutorMappingGenerator:: +options (CL::Description& d) +{ + d.add_option (CL::OptionDescription ( + "lem-file-suffix", + "suffix", + "Use provided suffix instead of default \'_exec\' " + "when constructing name of local executor mapping file.", + true)); + + d.add_option (CL::OptionDescription ( + "lem-file-regex", + "regex", + "Use provided regular expression when constructing " + "name of local executor mapping file.", + true)); + + d.add_option (CL::OptionDescription ( + "lem-force-all", + "Force generation of local executor mapping for all IDL " + "types including those not used (directly or inderectly) " + "by compositions. This option is useful for generating a " + "common portion of local executor mapping used by more " + "than one component or composition.", + true)); +} + + +void ExecutorMappingGenerator:: +generate (CommandLine const& cl, + TranslationUnitPtr const& u) +{ + fs::path file_path = u->principal_translation_region ()->file_path (); + + fs::ofstream ofs; + + if (!file_path.empty ()) + { + string file_name = file_path.leaf (); + + string suffix = cl.get_value ("lem-file-suffix", "_exec.idl"); + string expr = cl.get_value ( + "lem-file-regex", + "/^(.*?)(\\.(idl|cidl))?$/$1" + suffix + "/"); + + string lem_file_name = regex::perl_s (file_name, expr); + + fs::path lem_file_path (lem_file_name); + + ofs.open (lem_file_path, std::ios_base::out); + + if (!ofs.is_open ()) + { + cerr << lem_file_name << ": error: unable to open in write mode" + << endl; + return; + } + } + + std::ostream& os = + ofs.is_open () + ? static_cast<std::ostream&> (ofs) + : static_cast<std::ostream&> (std::cout); + + //@@ need to apply RAII here + + // Set auto-indentation for os + IDLFormattingBuffer ifb (os.rdbuf ()); + os.rdbuf (&ifb); + + HomeDefSet home_set; + ComponentDefSet component_set; + CompositionMap composition_map; + ConcreteEventTypeDefSet event_type_set; + UnconstrainedInterfaceDeclSet interface_set; + + if (cl.get_value ("lem-force-all", false)) + { + ForcedCollector collector (interface_set, + component_set, + event_type_set, + home_set, + composition_map); + u->accept (&collector); + } + else + { + Collector collector (interface_set, + component_set, + event_type_set, + home_set, + composition_map); + u->accept (&collector); + } + + { + Emitter emitter (os, + interface_set, + component_set, + event_type_set, + home_set, + composition_map); + u->accept (&emitter); + } + + // Reset auto-indentation for os + os.rdbuf (ifb.next ()); +} diff --git a/TAO/CIAO/CIDLC/ExecutorMappingGenerator.hpp b/TAO/CIAO/CIDLC/ExecutorMappingGenerator.hpp new file mode 100644 index 00000000000..61ad1749a29 --- /dev/null +++ b/TAO/CIAO/CIDLC/ExecutorMappingGenerator.hpp @@ -0,0 +1,22 @@ +// $Id$ +#ifndef EXECUTOR_MAPPING_GENERATOR_HPP +#define EXECUTOR_MAPPING_GENERATOR_HPP + +#include "CCF/CodeGenerationKit/CommandLine.hpp" +#include "CCF/CodeGenerationKit/CommandLineDescriptor.hpp" + +#include "CCF/CIDL/CIDL_SyntaxTreeFwd.hpp" + +class ExecutorMappingGenerator +{ +public: + + void + options (CL::Description& d); + + void + generate (CommandLine const& cl, + CIDL::SyntaxTree::TranslationUnitPtr const&); +}; + +#endif // EXECUTOR_MAPPING_GENERATOR_HPP diff --git a/TAO/CIAO/CIDLC/Literals.hpp b/TAO/CIAO/CIDLC/Literals.hpp new file mode 100644 index 00000000000..2e612e6fa0d --- /dev/null +++ b/TAO/CIAO/CIDLC/Literals.hpp @@ -0,0 +1,92 @@ +// $Id$ +namespace StringLiterals +{ + static const char COPYRIGHT[] = + "// $I" "d$\n" + "//\n" + "// **** Code generated by the ****\n" + "// **** Component Integrated ACE ORB (CIAO) CIDL Compiler ****\n" + "// CIAO has been developed by:\n" + "// Center for Distributed Object Computing\n" + "// Washington University\n" + "// St. Louis, MO\n" + "// USA\n" + "// http://www.cs.wustl.edu/~schmidt/doc-center.html\n" + "// CIDL Compiler has been developed by:\n" + "// Institute for Software Integrated Systems\n" + "// Vanderbilt University\n" + "// Nashville, TN\n" + "// USA\n" + "// http://www.isis.vanderbilt.edu/\n" + "//\n" + "// Information about CIAO is available at:\n" + "// http://www.cs.wustl.edu/~nanbor/projects/CIAO-src/docs/index.html"; + + static const char *STRS[] = + { + // ACE Environment portability macros. + "ACE_ENV_ARG_DECL_WITH_DEFAULTS", // ENV_HDR + "ACE_ENV_SINGLE_ARG_DECL_WITH_DEFAULTS", // ENV_SNGL_HDR + "ACE_ENV_ARG_DECL", // ENV_SRC + "ACE_ENV_SINGLE_ARG_DECL", // ENV_SNGL_SRC + "ACE_ENV_ARG_PARAMETER", // ENV_ARG + "ACE_ENV_SINGLE_ARG_PARAMETER", // ENV_SNGL_ARG + + // Common CORBA and all Components exceptions. + "ACE_THROW_SPEC ((CORBA::SystemException))", // EXCP_SNGL + "ACE_THROW_SPEC ((", // EXCP_START + "::CORBA::SystemException", // EXCP_SYS + "::Components::IllegalState", // EXCP_IS + "::Components::AlreadyConnected", // EXCP_AC + "::Components::InvalidConnection", // EXCP_IC + "::Components::NoConnection", // EXCP_NC + "::Components::ExceededConnectionLimit", // EXCP_ECL + "::Components::InvalidName", // EXCP_IN + "::Components::RemoveFailure", // EXCP_RF + "::Components::NoKeyAvailable", // EXCP_NKA + "::Components::InvalidConfiguration", // EXCP_ICF + "::Components::CookieRequired", // EXCP_CR + "::Components::BadEventType", // EXCP_BET + + // Commonly used Components module members. + "::Components::Cookie", // COMP_CK + "::Components::NameList &names", // COMP_NAMES + "::Components::EventConsumerBase", // COMP_ECB + + // This could change - don't want it scattered all over. + "namespace CIAO_GLUE", // GLUE_NS + + // Commonly used base class. + "public virtual PortableServer::RefCountServantBase" // INH_RCSB + }; + + // Index into the strings above. + enum + { + ENV_HDR = 0, + ENV_SNGL_HDR, + ENV_SRC, + ENV_SNGL_SRC, + ENV_ARG, + ENV_SNGL_ARG, + EXCP_SNGL, + EXCP_START, + EXCP_SYS, + EXCP_IS, + EXCP_AC, + EXCP_IC, + EXCP_NC, + EXCP_ECL, + EXCP_IN, + EXCP_RF, + EXCP_NKA, + EXCP_ICF, + EXCP_CR, + EXCP_BET, + COMP_CK, + COMP_NAMES, + COMP_ECB, + GLUE_NS, + INH_RCSB + }; +} diff --git a/TAO/CIAO/CIDLC/Makefile b/TAO/CIAO/CIDLC/Makefile new file mode 100644 index 00000000000..1bcda7c4228 --- /dev/null +++ b/TAO/CIAO/CIDLC/Makefile @@ -0,0 +1,33 @@ +# File : Makefile +# Author : Boris Kolpackov <boris@kolpackov.net> +# $Id$ + +root = CCF/External/Utility + +include $(root)/Config/Executable.pre.rules + +cxx_translation_units := ExecutorMappingGenerator.cpp \ + ServantGenerator.cpp \ + ServantHeaderGenerator.cpp \ + ServantSourceGenerator.cpp \ + cidlc.cpp + +module_base := cidlc +module_prefix := +module_suffix := + +CXX_PREPROCESS_FLAGS += -ICCF -ICCF/External/Utility -ICCF/External/boost + +CXX_LINK_LIBS += -LCCF/CCF/IDL2 \ + -lIDL2 \ + -LCCF/CCF/IDL3 \ + -lIDL3 \ + -LCCF/CCF/CIDL \ + -lCIDL \ + -LCCF/CCF/CodeGenerationKit \ + -lCodeGenerationKit \ + -LCCF/External/boost/lib \ + -lboost_regex \ + -lboost_filesystem + +include $(root)/Config/Executable.post.rules diff --git a/TAO/CIAO/CIDLC/ServantGenerator.cpp b/TAO/CIAO/CIDLC/ServantGenerator.cpp new file mode 100644 index 00000000000..d3660db7385 --- /dev/null +++ b/TAO/CIAO/CIDLC/ServantGenerator.cpp @@ -0,0 +1,205 @@ +// $Id$ +#include "ServantGenerator.hpp" +#include "ServantHeaderGenerator.hpp" +#include "ServantSourceGenerator.hpp" + +#include "CCF/CodeGenerationKit/Regex.hpp" +#include "CCF/CodeGenerationKit/IDLStream.hpp" + +ProvidesCollector::ProvidesCollector ( + UnconstrainedInterfaceDefSet& interface_set) + : interface_set_ (interface_set) +{ +} + +void +ProvidesCollector::visit_provides_decl (ProvidesDeclPtr const& p) +{ + //@@ CCM issue: interface should be defined at this point + UnconstrainedInterfaceDefPtr def ( + p->type ()->dynamic_type<SyntaxTree::UnconstrainedInterfaceDef> ()); + + if (def != 0) + { + // Add to the list if it's not already there. + interface_set_.insert (def); + } +} + +Collector::Collector (UnconstrainedInterfaceDefSet& interface_set, + ComponentDefSet& component_set, + HomeDefSet& home_set) + : component_set_ (component_set), + home_set_ (home_set), + provides_collector_ (interface_set) +{ +} + +void +Collector::visit_home_executor (HomeExecutorPtr const& he) +{ + HomeDefPtr h = he->implements (); + ComponentDefPtr c = h->manages (); + + //@@unsupported: need to handle inherited components as well + component_set_.insert (c); + home_set_.insert (h); + + c->accept (&provides_collector_); +} + +namespace +{ + // On some platforms toupper can be something else than a + // function. + int + upcase (int c) + { + return toupper (c); + } +} + +ServantGenerator::ServantGenerator (CommandLine const& cl) + : cl_ (cl), + file_name_ (""), + export_macro_ ("") +{ +} + +void +ServantGenerator::generate (CIDL::SyntaxTree::TranslationUnitPtr const& u) +{ + ComponentDefSet component_set_; + HomeDefSet home_set_; + UnconstrainedInterfaceDefSet interface_set; + + { + Collector collector (interface_set, + component_set_, + home_set_); + u->accept (&collector); + } + + compute_export_macro (u->principal_translation_region ()->file_path ()); + + { + fs::ofstream hdr_ofs; + ostream& hdr_os = configure_stream ("hdr-file-suffix", + "_svnt.h", + "hdr-file-regex", + hdr_ofs); + + // Set auto-indentation for os + IDLFormattingBuffer ifb (hdr_os.rdbuf ()); + hdr_os.rdbuf (&ifb); + + { + ServantHeaderEmitter hdr_emitter (hdr_os, + cl_, + export_macro_, + interface_set, + component_set_, + home_set_); + u->accept (&hdr_emitter); + } + + { + ServantHeaderFinalizingEmitter hdr_finalizer (hdr_os, + cl_, + export_macro_); + u->accept (&hdr_finalizer); + } + } + + { + fs::ofstream src_ofs; + ostream& src_os = configure_stream ("src-file-suffix", + "_svnt.cpp", + "src-file-regex", + src_ofs); + + // Set auto-indentation for os + IDLFormattingBuffer ifb (src_os.rdbuf ()); + src_os.rdbuf (&ifb); + + { + ServantSourceEmitter src_emitter (src_os, + cl_, + interface_set, + component_set_, + home_set_); + u->accept (&src_emitter); + } + + { + ServantSourceFinalizingEmitter src_finalizer (src_os, + export_macro_); + u->accept (&src_finalizer); + } + } +} + +void +ServantGenerator::compute_export_macro (const fs::path& file_path) +{ + if (!file_path.empty ()) + { + file_name_ = file_path.leaf (); + } + + export_macro_ = cl_.get_value ("export-macro", ""); + + if (export_macro_.empty () && !file_name_.empty ()) + { + // Modify a copy of the filename string. + export_macro_ = file_name_; + + // Convert filename string to upper case. + transform (export_macro_.begin (), + export_macro_.end (), + export_macro_.begin (), + upcase); + + // Replace the suffix. + export_macro_ = + regex::perl_s (export_macro_, + "/^(.*?)(\\.(IDL|CIDL))?$/$1_SVNT_Export/"); + + // Replace any remaining '.' in the string with '_'. + export_macro_ = regex::perl_s (export_macro_, + "/\\./_/"); + } +} + +ostream& +ServantGenerator::configure_stream (string const& suffix_option, + string const& default_suffix, + string const& regex_option, + fs::ofstream& ofs) +{ + if (! file_name_.empty ()) + { + string file_suffix = cl_.get_value (suffix_option, + default_suffix); + string file_expr = + cl_.get_value (regex_option, + "/^(.*?)(\\.(idl|cidl))?$/$1" + file_suffix + "/"); + + string file_name = regex::perl_s (file_name_, file_expr); + + fs::path file_path (file_name); + + ofs.open (file_path, std::ios_base::out); + + if (!ofs.is_open ()) + { + cerr << file_name + << ": error: unable to open file in write mode" + << endl; + } + } + + return ofs.is_open () + ? static_cast<ostream&> (ofs) + : static_cast<ostream&> (cout); +} diff --git a/TAO/CIAO/CIDLC/ServantGenerator.hpp b/TAO/CIAO/CIDLC/ServantGenerator.hpp new file mode 100644 index 00000000000..79ef0a0eab0 --- /dev/null +++ b/TAO/CIAO/CIDLC/ServantGenerator.hpp @@ -0,0 +1,81 @@ +// $Id$ +#ifndef SERVANT_GENERATOR_HPP +#define SERVANT_GENERATOR_HPP + +#include "CCF/CodeGenerationKit/CommandLine.hpp" + +#include "CCF/CIDL/CIDL_SyntaxTree.hpp" +#include "CCF/CIDL/CIDL_Traversal.hpp" + +using namespace std; + +using namespace CIDL; +using namespace CIDL::SyntaxTree; + +// ProvidesCollector collects interfaces that appear in provides +// declaration of a component in question. Used as a building block +// by Collector. +// +class ProvidesCollector : public virtual Traversal::ComponentDef, + public virtual Traversal::ProvidesDecl +{ +public: + ProvidesCollector (UnconstrainedInterfaceDefSet& interface_set); + + virtual void + visit_provides_decl (ProvidesDeclPtr const& p); + +private: + UnconstrainedInterfaceDefSet& interface_set_; +}; + +// Collector populates lists of declarations for which local facet +// executor mapping should be provided. +// +class Collector : public virtual Traversal::TranslationUnit, + public virtual Traversal::TranslationRegion, + public virtual Traversal::FileScope, + public virtual Traversal::Module, + public virtual Traversal::Composition, + public virtual Traversal::HomeExecutor +{ +public: + Collector (UnconstrainedInterfaceDefSet& interface_set, + ComponentDefSet& component_set, + HomeDefSet& home_set); + + virtual void + visit_home_executor (HomeExecutorPtr const& he); + +private: + ComponentDefSet& component_set_; + HomeDefSet& home_set_; + + ProvidesCollector provides_collector_; +}; + +class ServantGenerator +{ +public: + ServantGenerator (CommandLine const& cl); + + void + generate (TranslationUnitPtr const& u); + +private: + void + compute_export_macro (const fs::path& file_path); + + ostream& + configure_stream (string const& suffix_option, + string const& default_suffix, + string const& regex_option, + fs::ofstream& ofs); + +private: + CommandLine const& cl_; + string file_name_; + string export_macro_; +}; + +#endif // SERVANT_GENERATOR_HPP diff --git a/TAO/CIAO/CIDLC/ServantHeaderGenerator.cpp b/TAO/CIAO/CIDLC/ServantHeaderGenerator.cpp new file mode 100644 index 00000000000..f89a85ece29 --- /dev/null +++ b/TAO/CIAO/CIDLC/ServantHeaderGenerator.cpp @@ -0,0 +1,1733 @@ +// $Id$ +#include "ServantHeaderGenerator.hpp" + +#include "Literals.hpp" + +#include "CCF/CodeGenerationKit/Regex.hpp" +#include "CCF/CodeGenerationKit/IDLStream.hpp" + +#include <cctype> +#include <algorithm> +#include <ostream> + +using namespace StringLiterals; + +namespace +{ + // Generates the name of an operation's return type. + // + // + class ReturnTypeNameEmitter : public HeaderEmitterBase, + public virtual Traversal::Void, + public virtual Traversal::Boolean, + public virtual Traversal::Long, + public virtual Traversal::String, + public virtual Traversal::LocalInterfaceDecl + { + public: + ReturnTypeNameEmitter (ostream& os_) + : HeaderEmitterBase (os_) + { + } + + virtual void + visit_void (VoidPtr const&) + { + os << "void"; + } + + virtual void + visit_boolean (BooleanPtr const&) + { + os << "::CORBA::Boolean"; + } + + virtual void + visit_long (LongPtr const&) + { + os << "::CORBA::Long"; + } + + virtual void + visit_string (StringPtr const&) + { + os << "char *"; + } + + virtual void + visit_local_interface_decl (LocalInterfaceDeclPtr const& i) + { + os << i->name () << "_ptr"; + } + }; + + // Generates the typename of an IN argument. + // + // + class INArgTypeNameEmitter : public HeaderEmitterBase, + public virtual Traversal::Boolean, + public virtual Traversal::Long, + public virtual Traversal::String + { + public: + INArgTypeNameEmitter (ostream& os_) + : HeaderEmitterBase (os_) + { + } + + virtual void + visit_boolean (BooleanPtr const&) + { + os << "::CORBA::Boolean"; + } + + virtual void + visit_long (LongPtr const&) + { + os << "::CORBA::Long"; + } + + virtual void + visit_string (StringPtr const&) + { + os << "const char *"; + } + }; + + // Generates the typename of an OUT argument. + // + // + class OUTArgTypeNameEmitter : public HeaderEmitterBase, + public virtual Traversal::Boolean, + public virtual Traversal::Long, + public virtual Traversal::String + { + public: + OUTArgTypeNameEmitter (ostream& os_) + : HeaderEmitterBase (os_) + { + } + + virtual void + visit_boolean (BooleanPtr const&) + { + os << "::CORBA::Boolean_out"; + } + + virtual void + visit_long (LongPtr const&) + { + os << "::CORBA::Long_out"; + } + + virtual void + visit_string (StringPtr const&) + { + os << "::CORBA::String_out"; + } + }; + + // Generates the typename of an INOUT argument. + // + // + class INOUTArgTypeNameEmitter : public HeaderEmitterBase, + public virtual Traversal::Boolean, + public virtual Traversal::Long, + public virtual Traversal::String + { + public: + INOUTArgTypeNameEmitter (ostream& os_) + : HeaderEmitterBase (os_) + { + } + + virtual void + visit_boolean (BooleanPtr const&) + { + os << "::CORBA::Boolean &"; + } + + virtual void + visit_long (LongPtr const&) + { + os << "::CORBA::Long &"; + } + + virtual void + visit_string (StringPtr const&) + { + os << "char *&"; + } + }; + + // Generates parts of the accessor operation for an attribute. + // + // + class GetAttributeEmitter : public HeaderEmitterBase, + public virtual Traversal::AttributeDecl, + public virtual Traversal::ComponentDef + { + public: + GetAttributeEmitter (ostream& os_, + ReturnTypeNameEmitter* return_type_name_emitter) + : HeaderEmitterBase (os_), + AttributeDecl (return_type_name_emitter) + { + } + + virtual void + visit_attribute_pre (AttributeDeclPtr const&) + { + os << "virtual "; + } + + virtual void + visit_attribute_post (AttributeDeclPtr const& a) + { + os << endl + << a->name ().simple () << " (" << endl + << STRS[ENV_SNGL_HDR] << ")" << endl + << STRS[EXCP_SNGL] << ";" << endl << endl; + } + }; + + // Generates parts of the mutator operation for an attribute. + // + // + class SetAttributeEmitter : public HeaderEmitterBase, + public virtual Traversal::AttributeDecl + { + public: + SetAttributeEmitter (ostream& os_, + ReturnTypeNameEmitter* return_type_name_emitter) + : HeaderEmitterBase (os_), + AttributeDecl (return_type_name_emitter) + { + } + + virtual void + visit_attribute_pre (AttributeDeclPtr const& a) + { + os << "virtual void " << endl + << a->name ().simple () << " (" << endl; + } + + virtual void + visit_attribute_post (AttributeDeclPtr const&) + { + os << endl + << STRS[ENV_HDR] << ")" << endl + << STRS[EXCP_SNGL] << ";" << endl << endl; + } + }; + + // + // + // + class OperationEmitter : public HeaderEmitterBase, + public virtual Traversal::OperationParameter, + public virtual Traversal::Comma, + public virtual Traversal::UnconstrainedInterfaceDef, + public virtual Traversal::OperationDecl + { + public: + OperationEmitter (ostream& os_, + ReturnTypeNameEmitter* return_type_name_emitter, + INArgTypeNameEmitter* inarg_type_name_emitter_, + OUTArgTypeNameEmitter* outarg_type_name_emitter_, + INOUTArgTypeNameEmitter* inoutarg_type_name_emitter_) + : HeaderEmitterBase (os_), + OperationParameter (inarg_type_name_emitter_, + outarg_type_name_emitter_, + inoutarg_type_name_emitter_), + OperationDecl (return_type_name_emitter) + { + } + + virtual void + visit_operation_decl_pre (OperationDeclPtr const&) + { + os << "virtual "; + } + + virtual void + visit_operation_decl_name (OperationDeclPtr const& d) + { + os << endl << d->name ().simple () << " ("; + } + + virtual void + visit_operation_parameter_pre (OperationParameterPtr const&) + { + os << endl; + } + + virtual void + visit_operation_parameter_post (OperationParameterPtr const& op) + { + os << " " << op->name (); + } + + virtual void + visit_comma (CommaPtr const&) + { + os << ","; + } + + virtual void + visit_operation_decl_post (OperationDeclPtr const& d) + { + // @@@ (JP) Need to process exception list. + os << endl + << (d->begin () == d->end () ? STRS[ENV_SNGL_HDR] : STRS[ENV_HDR]) + << ")" << endl + << STRS[EXCP_SNGL] << ";" << endl << endl; + } + }; + + // Generates the operation associated with a home factory declaration. + // + // + class FactoryEmitter : public HeaderEmitterBase, + public virtual Traversal::HomeFactoryDecl, + public virtual Traversal::OperationParameter, + public virtual Traversal::Comma + { + public: + FactoryEmitter (ostream& os_, + INArgTypeNameEmitter* inarg_type_name_emitter_) + : HeaderEmitterBase (os_), + OperationParameter (inarg_type_name_emitter_, + inarg_type_name_emitter_, + inarg_type_name_emitter_) + { + } + + virtual void + visit_home_factory_decl_pre (HomeFactoryDeclPtr const&) + { + os << "virtual "; + } + + virtual void + visit_home_factory_decl_type (HomeFactoryDeclPtr const& f) + { + HomeDefPtr def (f->scope ()->dynamic_type<SyntaxTree::HomeDef> ()); + os << def->manages ()->name () << "_ptr"; + } + + virtual void + visit_home_factory_decl_name (HomeFactoryDeclPtr const& f) + { + os << endl + << f->name ().simple () << " ("; + } + + virtual void + visit_operation_parameter_pre (OperationParameterPtr const&) + { + os << endl; + } + + virtual void + visit_operation_parameter_post (OperationParameterPtr const& op) + { + os << " " << op->name (); + } + + virtual void + visit_comma (CommaPtr const&) + { + os << ","; + } + + virtual void + visit_home_factory_decl_post (HomeFactoryDeclPtr const& f) + { + // @@@ (JP) Need to process exception list. + os << (f->begin () == f->end () ? STRS[ENV_SNGL_HDR] : STRS[ENV_HDR]) + << ")" << endl + << STRS[EXCP_SNGL] << ";" << endl << endl; + } + }; + + // + // FacetEmitter generates a facet servant class declaration. + // + class FacetEmitter : public HeaderEmitterBase, + public virtual Traversal::UnconstrainedInterfaceDef, + public virtual Traversal::OperationDecl, + public virtual Traversal::AttributeDecl + { + private: + string export_macro_; + + ReturnTypeNameEmitter return_type_name_emitter_; + INArgTypeNameEmitter inarg_type_name_emitter_; + OUTArgTypeNameEmitter outarg_type_name_emitter_; + INOUTArgTypeNameEmitter inoutarg_type_name_emitter_; + + OperationEmitter operation_emitter_; + + public: + FacetEmitter (ostream& os_, + string export_macro) + : HeaderEmitterBase (os_), + export_macro_ (export_macro), + return_type_name_emitter_ (os_), + inarg_type_name_emitter_ (os_), + outarg_type_name_emitter_ (os_), + inoutarg_type_name_emitter_ (os_), + operation_emitter_ (os_, + &return_type_name_emitter_, + &inarg_type_name_emitter_, + &outarg_type_name_emitter_, + &inoutarg_type_name_emitter_) + { + } + + virtual void + visit_unconstrained_interface_def_pre ( + UnconstrainedInterfaceDefPtr const& i) + { + // If we are at file scope, we create a namespace anyway. + if (i->scope ()->dynamic_type<IDL2::SyntaxTree::FileScope> () != 0) + { + os << STRS[GLUE_NS] << endl + << "{" << endl; + } + + // @@@ (JP) Need export macro and prefixable scoped name. + os << "class " << export_macro_ << " " << i->name ().simple () + << "_Servant" << endl + << ": public virtual POA_" << i->name ().in_file_scope () + << "," << endl + << STRS[INH_RCSB] + << endl + << "{" << endl + << "public:" << endl; + + os << i->name ().simple () << "_Servant (" << endl + << i->name ().scope () << "::CCM_" << i->name ().simple () + << "_ptr executor," << endl + << "::Components::CCMContext_ptr ctx);" << endl << endl; + + os << "virtual ~" << i->name ().simple () << "_Servant (void);" + << endl << endl; + } + + virtual void + visit_operation_decl (OperationDeclPtr const& d) + { + d->accept (&operation_emitter_); + } + + virtual void + visit_attribute_decl (AttributeDeclPtr const&) + { + // TODO + } + + virtual void + visit_unconstrained_interface_def_post ( + UnconstrainedInterfaceDefPtr const& i) + { + os << "// Get component implementation." << endl + << "virtual CORBA::Object_ptr" << endl + << "_get_component (" << endl + << STRS[ENV_SNGL_HDR] << ")" << endl + << STRS[EXCP_SNGL] << ";" + << endl << endl; + + os << "protected:" << endl + << "// Facet executor." << endl + << i->name ().scope () << "::CCM_" << i->name ().simple () + << "_var executor_;" << endl << endl; + + os << "// Context object." << endl + << "::Components::CCMContext_var ctx_;" << endl + << "};" << endl; + + // Close the CIAO_GLUE namespace, if we opened one. + if (i->scope ()->dynamic_type<IDL2::SyntaxTree::FileScope> () != 0) + { + os << "}" << endl; + } + + os << endl; + } + }; + + // + // Generates public part of component context interface declaration. + // + class ContextPublicEmitter : public HeaderEmitterBase, + public virtual Traversal::ComponentDef, + public virtual Traversal::UsesDecl, + public virtual Traversal::PublishesDecl, + public virtual Traversal::EmitsDecl + { + private: + string export_macro_; + + public: + ContextPublicEmitter (ostream& os_, + string export_macro) + : HeaderEmitterBase (os_), + export_macro_ (export_macro) + { + } + + virtual void + visit_component_def_pre (ComponentDefPtr const& c) + { + // If we are at file scope, we create a namespace anyway. + if (c->scope ()->dynamic_type<IDL2::SyntaxTree::FileScope> () != 0) + { + os << STRS[GLUE_NS] << endl + << "{" << endl; + } + + // @@@ (JP) Need export macro. + os << "class " << export_macro_ << " " << c->name ().simple () + << "_Context" << endl + << ": public virtual " << c->name ().scope () << "::CCM_" + << c->name ().simple () << "_Context," + << endl + << "public virtual TAO_Local_RefCounted_Object" + << endl + << "{" << endl + << "public:" << endl; + + os << "// We will allow the servant glue code we generate to " + << "access our state." << endl + << "friend class " << c->name ().simple () << "_Servant;" + << endl << endl; + + os << c->name ().simple () << "_Context (" << endl + << "::Components::CCMHome_ptr home," << endl + << "::CIAO::Session_Container *c," << endl + << c->name ().simple () << "_Servant *sv);" << endl << endl; + + os << "virtual ~" << c->name ().simple () << "_Context (void);" + << endl << endl; + + os << "// Operations from ::Components::CCMContext." << endl << endl; + + os << "virtual ::Components::Principal_ptr" << endl + << "get_caller_principal (" << endl + << STRS[ENV_SNGL_HDR] << ")" << endl + << STRS[EXCP_SNGL] << ";" << endl << endl; + + os << "virtual ::Components::CCMHome_ptr" << endl + << "get_CCM_home (" << endl + << STRS[ENV_SNGL_HDR] << ")" << endl + << STRS[EXCP_SNGL] << ";" << endl << endl; + + os << "virtual CORBA::Boolean" << endl + << "get_rollback_only (" << endl + << STRS[ENV_SNGL_HDR] << ")" << endl + << STRS[EXCP_START] << endl + << STRS[EXCP_SYS] << "," << endl + << STRS[EXCP_IS] << "));" << endl << endl; + + os << "virtual ::Components::Transaction::UserTransaction_ptr" << endl + << "get_user_transaction (" << endl + << STRS[ENV_SNGL_HDR] << ")" << endl + << STRS[EXCP_START] << endl + << STRS[EXCP_SYS] << "," << endl + << STRS[EXCP_IS] << "));" << endl << endl; + + os << "virtual CORBA::Boolean" << endl + << "is_caller_in_role (" << endl + << "const char *role" << endl + << STRS[ENV_HDR] << ")" << endl + << STRS[EXCP_SNGL] << ";" << endl << endl; + + os << "virtual void" << endl + << "set_rollback_only (" << endl + << STRS[ENV_SNGL_HDR] << ")" << endl + << STRS[EXCP_START] << endl + << STRS[EXCP_SYS] << "," << endl + << STRS[EXCP_IS] << "));" << endl << endl; + + os << "// Operations from ::Components::SessionContext interface." + << endl << endl; + + os << "virtual CORBA::Object_ptr" << endl + << "get_CCM_object (" << endl + << STRS[ENV_SNGL_HDR] << ")" << endl + << STRS[EXCP_START] << endl + << STRS[EXCP_SYS] << "," << endl + << STRS[EXCP_IS] << "));" << endl << endl; + + os << "// Operations for " << c->name ().simple () << " receptacles" + << " and event sources," << endl + << "// defined in " << c->name ().scope () << "::CCM_" + << c->name ().simple () << "_Context." + << endl << endl; + } + + virtual void + visit_uses_decl (UsesDeclPtr const& d) + { + // @@@ (JP) Need to handle multiple connections. + os << "virtual " << d->type ()->name () << "_ptr" << endl + << "get_connection_" << d->name ().simple () + << " (" << endl + << STRS[ENV_SNGL_HDR] << ")" << endl + << STRS[EXCP_SNGL] << ";" << endl << endl; + } + + virtual void + visit_publishes_decl (PublishesDeclPtr const& d) + { + os << "virtual void" << endl + << "push_" << d->name ().simple () + << " (" << endl + << d->type ()->name () << " *ev" << endl + << STRS[ENV_HDR] << ")" << endl + << STRS[EXCP_SNGL] << ";" << endl << endl; + } + + virtual void + visit_emits_decl (EmitsDeclPtr const& d) + { + os << "virtual void" << endl + << "push_" << d->name ().simple () + << " (" << endl + << d->type ()->name () << " *ev" << endl + << STRS[ENV_HDR] << ")" << endl + << STRS[EXCP_SNGL] << ";" << endl << endl; + } + }; + + // + // Generates protected methods of component context interface declaration. + // + class ContextProtectedMethodEmitter + : public HeaderEmitterBase, + public virtual Traversal::ComponentDef, + public virtual Traversal::UsesDecl, + public virtual Traversal::PublishesDecl, + public virtual Traversal::EmitsDecl + { + public: + ContextProtectedMethodEmitter (ostream& os_) + : HeaderEmitterBase (os_) + { + } + + virtual void + visit_component_def_pre (ComponentDefPtr const& c) + { + os << "protected:" << endl + << "// Methods that manage this component's connections" + << " and consumers." << endl << endl; + } + + virtual void + visit_uses_decl (UsesDeclPtr const& d) + { + // @@@ (JP) Need to handle multiple connections. + os << "virtual void" << endl + << "connect_" << d->name ().simple () << " (" << endl + << d->type ()->name () << "_ptr" << endl + << STRS[ENV_HDR] << ")" << endl + << STRS[EXCP_START] << endl + << STRS[EXCP_SYS] << "," << endl + << STRS[EXCP_AC] << "," << endl + << STRS[EXCP_IC] << "));" << endl << endl; + + os << "virtual " << d->type ()->name () << "_ptr" << endl + << "disconnect_" << d->name ().simple () << " (" << endl + << STRS[ENV_SNGL_HDR] << ")" << endl + << STRS[EXCP_START] << endl + << STRS[EXCP_SYS] << "," << endl + << STRS[EXCP_NC] << "));" << endl << endl; + } + + virtual void + visit_emits_decl (EmitsDeclPtr const& d) + { + os << "virtual void" << endl + << "connect_" << d->name ().simple () << " (" << endl + << d->type ()->name () << "Consumer_ptr c" << endl + << STRS[ENV_HDR] << ")" << endl + << STRS[EXCP_SNGL] << ";" << endl << endl; + + os << "virtual " << d->type ()->name () << "_ptr" << endl + << "disconnect_" << d->name ().simple () << " (" << endl + << STRS[ENV_SNGL_HDR] << ")" << endl + << STRS[EXCP_START] << endl + << STRS[EXCP_SYS] << "," << endl + << STRS[EXCP_NC] << "));" << endl << endl; + } + + virtual void + visit_publishes_decl (PublishesDeclPtr const& p) + { + os << "virtual " << STRS[COMP_CK] << " *" << endl + << "subscribe_" << p->name ().simple () << " (" << endl + << p->type ()->name () << "Consumer_ptr c" << endl + << STRS[ENV_HDR] << ")" << endl + << STRS[EXCP_START] << endl + << STRS[EXCP_SYS] << "," << endl + << STRS[EXCP_ECL] << "));" << endl << endl; + + os << "virtual " << p->type ()->name () << "Consumer_ptr" << endl + << "unsubscribe_" << p->name ().simple () << " (" << endl + << STRS[COMP_CK] << " *ck" << endl + << STRS[ENV_HDR] << ")" << endl + << STRS[EXCP_START] << endl + << STRS[EXCP_SYS] << "," << endl + << STRS[EXCP_IC] << "));" << endl << endl; + } + }; + + // + // Generates protected members of component context interface declaration. + // + class ContextProtectedMemberEmitter + : public HeaderEmitterBase, + public virtual Traversal::ComponentDef, + public virtual Traversal::UsesDecl, + public virtual Traversal::PublishesDecl, + public virtual Traversal::EmitsDecl + { + public: + ContextProtectedMemberEmitter (ostream& os_) + : HeaderEmitterBase (os_) + { + } + + virtual void + visit_component_def_pre (ComponentDefPtr const& c) + { + os << "protected:" << endl; + } + + virtual void + visit_uses_decl (UsesDeclPtr const& d) + { + // @@@ (JP) Need to handle multiple connections. + os << "// Simplex " << d->name ().simple () << " connection." << endl + << d->type ()->name () << "_var" << endl + << "ciao_uses_" << d->name ().simple () << "_;" << endl << endl; + } + + virtual void + visit_emits_decl (EmitsDeclPtr const& d) + { + os << d->type ()->name () << "Consumer_var" << endl + << "ciao_emits_" << d->name ().simple () << "_consumer_;" + << endl << endl; + } + + virtual void + visit_publishes_decl (PublishesDeclPtr const& p) + { + os << "ACE_Active_Map_Manager<" << endl + << p->type ()->name () << "Consumer_var>" << endl + << "ciao_publishes_" << p->name ().simple () << "_map_;" + << endl << endl; + } + + virtual void + visit_component_def_post (ComponentDefPtr const& c) + { + os << "::Components::CCMHome_var" << endl + << "home_;" << endl << endl; + + os << "::CIAO::Session_Container *" << endl + << "container_;" << endl << endl; + + os << c->name ().simple () << "_Servant *" << endl + << "servant_;" << endl << endl; + + os << c->name () << "_var" << endl + << "component_;" << endl; + + os << "};" << endl; + + // Close the CIAO_GLUE namespace, if we opened one. + if (c->scope ()->dynamic_type<IDL2::SyntaxTree::FileScope> () != 0) + { + os << "}" << endl; + } + + os << endl; + } + }; + + // + // Generates public part of component servant interface declaration. + // + class ServantPublicEmitter : public HeaderEmitterBase, + public virtual Traversal::ComponentDef, + public virtual Traversal::ProvidesDecl, + public virtual Traversal::UsesDecl, + public virtual Traversal::PublishesDecl, + public virtual Traversal::ConsumesDecl, + public virtual Traversal::EmitsDecl, + public virtual Traversal::AttributeDecl + + { + private: + string export_macro_; + + ReturnTypeNameEmitter return_type_name_emitter_; + INArgTypeNameEmitter inarg_type_name_emitter_; + OUTArgTypeNameEmitter outarg_type_name_emitter_; + INOUTArgTypeNameEmitter inoutarg_type_name_emitter_; + + GetAttributeEmitter get_attribute_emitter_; + SetAttributeEmitter set_attribute_emitter_; + OperationEmitter operation_emitter_; + + public: + ServantPublicEmitter (ostream& os_, + string export_macro) + : HeaderEmitterBase (os_), + export_macro_ (export_macro), + return_type_name_emitter_ (os_), + inarg_type_name_emitter_ (os_), + outarg_type_name_emitter_ (os_), + inoutarg_type_name_emitter_ (os_), + get_attribute_emitter_ (os_, + &return_type_name_emitter_), + set_attribute_emitter_ (os_, + &return_type_name_emitter_), + operation_emitter_ (os_, + &return_type_name_emitter_, + &inarg_type_name_emitter_, + &outarg_type_name_emitter_, + &inoutarg_type_name_emitter_) + { + } + + virtual void + visit_component_def_pre (ComponentDefPtr const& c) + { + // If we are at file scope, we create a namespace anyway. + if (c->scope ()->dynamic_type<IDL2::SyntaxTree::FileScope> () != 0) + { + os << STRS[GLUE_NS] << endl + << "{" << endl; + } + + // @@@ (JP) Need export macro and prefixable scoped name. + os << "class " << export_macro_ << " " << c->name ().simple () + << "_Servant" << endl + << ": public virtual POA_" << c->name ().in_file_scope () + << "," << endl + << STRS[INH_RCSB] << endl + << "{" << endl + << "public:" << endl; + + os << c->name ().simple () << "_Servant (" << endl + << c->name ().scope () << "::CCM_" << c->name ().simple () + << "_ptr executor," << endl + << "::Components::CCMHome_ptr home," << endl + << "::CIAO::Session_Container *c);" << endl << endl; + + os << "virtual ~" << c->name ().simple () << "_Servant (void);" + << endl << endl; + + // @@@ (JP) Must include ancestors' supported interfaces as well. + for (SyntaxTree::ComponentDef::Iterator i = c->supports_begin (); + i != c->supports_end (); + i++) + { + i->resolve ()->accept (&operation_emitter_); + } + } + + virtual void + visit_attribute_decl (AttributeDeclPtr const& a) + { + a->accept (&get_attribute_emitter_); + a->accept (&set_attribute_emitter_); + } + + virtual void + visit_provides_decl (ProvidesDeclPtr const& p) + { + os << "virtual " << p->type ()->name () << "_ptr" << endl + << "provide_" << p->name ().simple () << " (" << endl + << STRS[ENV_SNGL_HDR] << ")" << endl + << STRS[EXCP_SNGL] << ";" << endl << endl; + } + + virtual void + visit_uses_decl (UsesDeclPtr const& p) + { + // @@@ (JP) Need to handle multiple connections. + os << "virtual void" << endl + << "connect_" << p->name ().simple () << " (" << endl + << p->type ()->name () << "_ptr c" << endl + << STRS[ENV_HDR] << ")" << endl + << STRS[EXCP_START] << endl + << STRS[EXCP_SYS] << "," << endl + << STRS[EXCP_AC] << "," << endl + << STRS[EXCP_IC] << "));" << endl << endl; + + os << "virtual " << p->type ()->name () << "_ptr" << endl + << "disconnect_" << p->name ().simple () << " (" << endl + << STRS[ENV_SNGL_HDR] << ")" << endl + << STRS[EXCP_SNGL] << ";" << endl << endl; + + os << "virtual " << p->type ()->name () << "_ptr" << endl + << "get_connection_" << p->name ().simple () << " (" << endl + << STRS[ENV_SNGL_HDR] << ")" << endl + << STRS[EXCP_SNGL] << ";" << endl << endl; + } + + virtual void + visit_consumes_decl (ConsumesDeclPtr const& c) + { + // @@@ (JP) Need export macro. + os << "// Servant class for the " << c->name ().simple () + << " consumer." << endl + << "class " << export_macro_ << " " + << c->type ()->name ().simple () << "Consumer_" + << c->name ().simple () << "_Servant" << endl + << ": public virtual POA_" << c->type ()->name ().in_file_scope () + << "Consumer," << endl + << STRS[INH_RCSB] + << endl + << "{" << endl + << "public:" << endl; + + os << c->type ()->name ().simple () << "Consumer_" << c->name ().simple () + << "_Servant (" << endl + << c->scope ()->name ().scope () << "::CCM_" + << c->scope ()->name ().simple () << "_ptr executor," + << endl + << c->scope ()->name ().scope () << "::CCM_" + << c->scope ()->name ().simple () + << "_Context_ptr c);" << endl << endl; + + os << "virtual ~" << c->type ()->name ().simple () << "Consumer_" + << c->name ().simple () << "_Servant (void);" << endl << endl; + + // @@@ (JP) May need to generate this for the eventtype's ancestors + // as well (the spec is vague on this point). If so, we need the + // CIDL compiler to support valuetype/eventtype inheritance. + os << "virtual void" << endl + << "push_" << c->type ()->name ().simple () << " (" << endl + << c->type ()->name () << " *evt" << endl + << STRS[ENV_HDR] << ")" << endl + << STRS[EXCP_SNGL] << ";" << endl << endl; + + os << "// Inherited from " << STRS[COMP_ECB] << "." << endl + << "virtual void" << endl + << "push_event (::Components::EventBase *ev" << endl + << STRS[ENV_HDR] << ")" << endl + << STRS[EXCP_START] << endl + << STRS[EXCP_SYS] << "," << endl + << STRS[EXCP_BET] << "));" << endl << endl; + + os << "// Get component implementation." << endl + << "virtual CORBA::Object_ptr" << endl + << "_get_component (" << endl + << STRS[ENV_SNGL_HDR] << ")" << endl + << STRS[EXCP_SNGL] << ";" << endl << endl; + + os << "protected:" << endl + << c->scope ()->name ().scope () << "::CCM_" + << c->scope ()->name ().simple () + << "_var" << endl + << "executor_;" << endl << endl; + + os << c->scope ()->name ().scope () << "::CCM_" + << c->scope ()->name ().simple () + << "_Context_var" << endl + << "ctx_;" << endl; + + os << "};" << endl << endl; + + os << "virtual " << c->type ()->name () << "Consumer_ptr" << endl + << "get_consumer_" << c->name ().simple () << " (" << endl + << STRS[ENV_SNGL_HDR] << ")" << endl + << STRS[EXCP_SNGL] << ";" << endl << endl; + } + + virtual void + visit_emits_decl (EmitsDeclPtr const& e) + { + os << "virtual void" << endl + << "connect_" << e->name ().simple () << " (" << endl + << e->type ()->name () << "Consumer_ptr c" << endl + << STRS[ENV_HDR] << ")" << endl + << STRS[EXCP_START] << endl + << STRS[EXCP_SYS] << "," << endl + << STRS[EXCP_AC] << "));" << endl << endl; + + os << "virtual " << e->type ()->name () << "Consumer_ptr" << endl + << "disconnect_" << e->name ().simple () << " (" << endl + << STRS[ENV_SNGL_HDR] << ")" << endl + << STRS[EXCP_START] << endl + << STRS[EXCP_SYS] << "," << endl + << STRS[EXCP_NC] << "));" << endl << endl; + } + + virtual void + visit_publishes_decl (PublishesDeclPtr const& p) + { + os << "virtual " << STRS[COMP_CK] << " *" << endl + << "subscribe_" << p->name ().simple () << " (" << endl + << p->type ()->name () << "Consumer_ptr c" << endl + << STRS[ENV_HDR] << ")" << endl + << STRS[EXCP_START] << endl + << STRS[EXCP_SYS] << "," << endl + << STRS[EXCP_ECL] << "));" << endl << endl; + + os << "virtual " << p->type ()->name () << "Consumer_ptr" << endl + << "unsubscribe_" << p->name ().simple () << " (" << endl + << STRS[COMP_CK] << " *ck" << endl + << STRS[ENV_HDR] << ")" << endl + << STRS[EXCP_START] << endl + << STRS[EXCP_SYS] << "," << endl + << STRS[EXCP_IC] << "));" << endl << endl; + } + + virtual void + visit_component_def_post (ComponentDefPtr const& c) + { + os << "// Operations for Navigation interface." << endl << endl; + + os << "virtual CORBA::Object_ptr" << endl + << "provide_facet (" << endl + << "const char *name" << endl + << STRS[ENV_HDR] << ")" << endl + << STRS[EXCP_START] << endl + << STRS[EXCP_SYS] << "," << endl + << STRS[EXCP_IN] << "));" << endl << endl; + + os << "virtual ::Components::FacetDescriptions *" << endl + << "get_all_facets (" << endl + << STRS[ENV_SNGL_HDR] << ")" << endl + << STRS[EXCP_SNGL] << ";" << endl << endl; + + os << "virtual ::Components::FacetDescriptions *" << endl + << "get_named_facets (" << endl + << "const " << STRS[COMP_NAMES] << endl + << STRS[ENV_HDR] << ")" << endl + << STRS[EXCP_START] << endl + << STRS[EXCP_SYS] << "," << endl + << STRS[EXCP_IN] << "));" << endl << endl; + + os << "virtual CORBA::Boolean" << endl + << "same_component (" << endl + << "CORBA::Object_ptr object_ref" << endl + << STRS[ENV_HDR] << ")" << endl + << STRS[EXCP_SNGL] << ";" << endl << endl; + + os << "// Operations for Receptacles interface." << endl << endl; + + os << "virtual " << STRS[COMP_CK] << " *" << endl + << "connect (" << endl + << "const char *name," << endl + << "CORBA::Object_ptr connection" << endl + << STRS[ENV_HDR] << ")" << endl + << STRS[EXCP_START] << endl + << STRS[EXCP_SYS] << "," << endl + << STRS[EXCP_IN] << "," << endl + << STRS[EXCP_IC] << "," << endl + << STRS[EXCP_AC] << "," << endl + << STRS[EXCP_ECL] << "));" << endl << endl; + + os << "virtual CORBA::Object_ptr" << endl + << "disconnect (" << endl + << "const char *name," << endl + << STRS[COMP_CK] << " *ck" << endl + << STRS[ENV_HDR] << ")" << endl + << STRS[EXCP_START] << endl + << STRS[EXCP_SYS] << "," << endl + << STRS[EXCP_IN] << "," << endl + << STRS[EXCP_IC] << "," << endl + << STRS[EXCP_CR] << "," << endl + << STRS[EXCP_NC] << "));" << endl << endl; + + os << "virtual ::Components::ConnectionDescriptions *" << endl + << "get_connections (" << endl + << "const char *name" << endl + << STRS[ENV_HDR] << ")" << endl + << STRS[EXCP_START] << endl + << STRS[EXCP_SYS] << "," << endl + << STRS[EXCP_IN] << "));" << endl << endl; + + os << "virtual ::Components::ReceptacleDescriptions *" << endl + << "get_all_receptacles (" << endl + << STRS[ENV_SNGL_HDR] << ")" << endl + << STRS[EXCP_SNGL] << ";" << endl << endl; + + os << "virtual ::Components::ReceptacleDescriptions *" << endl + << "get_named_receptacles (" << endl + << "const " << STRS[COMP_NAMES] << endl + << STRS[ENV_HDR] << ")" << endl + << STRS[EXCP_START] << endl + << STRS[EXCP_SYS] << "," << endl + << STRS[EXCP_IN] << "));" << endl << endl; + + os << "// Operations for Events interface." << endl << endl; + + os << "virtual " << STRS[COMP_ECB] << "_ptr" << endl + << "get_consumer (" << endl + << "const char *sink_name" << endl + << STRS[ENV_HDR] << ")" << endl + << STRS[EXCP_START] << endl + << STRS[EXCP_SYS] << "," << endl + << STRS[EXCP_IN] << "));" << endl << endl; + + os << "virtual " << STRS[COMP_CK] << " *" << endl + << "subscribe (" << endl + << "const char *publisher_name," << endl + << STRS[COMP_ECB] << "_ptr subscriber" << endl + << STRS[ENV_HDR] << ")" << endl + << STRS[EXCP_START] << endl + << STRS[EXCP_SYS] << "," << endl + << STRS[EXCP_IN] << "," << endl + << STRS[EXCP_IC] << "," << endl + << STRS[EXCP_ECL] << "));" << endl << endl; + + os << "virtual " << STRS[COMP_ECB] << "_ptr" << endl + << "unsubscribe (" << endl + << "const char *publisher_name," << endl + << STRS[COMP_CK] << " *ck" << endl + << STRS[ENV_HDR] << ")" << endl + << STRS[EXCP_START] << endl + << STRS[EXCP_SYS] << "," << endl + << STRS[EXCP_IN] << "," << endl + << STRS[EXCP_IC] << "));" << endl << endl; + + os << "virtual void" << endl + << "connect_consumer (" << endl + << "const char *emitter_name," << endl + << STRS[COMP_ECB] << "_ptr consumer" << endl + << STRS[ENV_HDR] << ")" << endl + << STRS[EXCP_START] << endl + << STRS[EXCP_SYS] << "," << endl + << STRS[EXCP_IN] << "," << endl + << STRS[EXCP_AC] << "," << endl + << STRS[EXCP_IC] << "));" << endl << endl; + + os << "virtual " << STRS[COMP_ECB] << "_ptr" << endl + << "disconnect_consumer (" << endl + << "const char *source_name" << endl + << STRS[ENV_HDR] << ")" << endl + << STRS[EXCP_START] << endl + << STRS[EXCP_SYS] << "," << endl + << STRS[EXCP_IN] << "," << endl + << STRS[EXCP_NC] << "));" << endl << endl; + + os << "virtual ::Components::ConsumerDescriptions *" << endl + << "get_all_consumers (" << endl + << STRS[ENV_SNGL_HDR] << ")" << endl + << STRS[EXCP_SNGL] << ";" << endl << endl; + + os << "virtual ::Components::ConsumerDescriptions *" << endl + << "get_named_consumers (" << endl + << "const " << STRS[COMP_NAMES] << endl + << STRS[ENV_HDR] << ")" << endl + << STRS[EXCP_START] << endl + << STRS[EXCP_SYS] << "," << endl + << STRS[EXCP_IN] << "));" << endl << endl; + + os << "virtual ::Components::EmitterDescriptions *" << endl + << "get_all_emitters (" << endl + << STRS[ENV_SNGL_HDR] << ")" << endl + << STRS[EXCP_SNGL] << ";" << endl << endl; + + os << "virtual ::Components::EmitterDescriptions *" << endl + << "get_named_emitters(" << endl + << "const " << STRS[COMP_NAMES] << endl + << STRS[ENV_HDR] << ")" << endl + << STRS[EXCP_START] << endl + << STRS[EXCP_SYS] << "," << endl + << STRS[EXCP_IN] << "));" << endl << endl; + + os << "virtual ::Components::PublisherDescriptions *" << endl + << "get_all_publishers (" << endl + << STRS[ENV_SNGL_HDR] << ")" << endl + << STRS[EXCP_SNGL] << ";" << endl << endl; + + os << "virtual ::Components::PublisherDescriptions *" << endl + << "get_named_publishers(" << endl + << "const " << STRS[COMP_NAMES] << endl + << STRS[ENV_HDR] << ")" << endl + << STRS[EXCP_START] << endl + << STRS[EXCP_SYS] << "," << endl + << STRS[EXCP_IN] << "));" << endl << endl; + + os << "// Operations for CCMObject interface." << endl << endl; + + os << "virtual CORBA::IRObject_ptr" << endl + << "get_component_def (" << endl + << STRS[ENV_SNGL_HDR] << ")" << endl + << STRS[EXCP_SNGL] << ";" << endl << endl; + + os << "virtual ::Components::CCMHome_ptr" << endl + << "get_ccm_home (" << endl + << STRS[ENV_SNGL_HDR] << ")" << endl + << STRS[EXCP_SNGL] << ";" << endl << endl; + + os << "virtual ::Components::PrimaryKeyBase *" << endl + << "get_primary_key (" << endl + << STRS[ENV_SNGL_HDR] << ")" << endl + << STRS[EXCP_START] << endl + << STRS[EXCP_SYS] << "," << endl + << STRS[EXCP_NKA] << "));" << endl << endl; + + os << "virtual void" << endl + << "configuration_complete (" << endl + << STRS[ENV_SNGL_HDR] << ")" << endl + << STRS[EXCP_START] << endl + << STRS[EXCP_SYS] << "," << endl + << STRS[EXCP_ICF] << "));" << endl << endl; + + os << "virtual void" << endl + << "remove (" << endl + << STRS[ENV_SNGL_HDR] << ")" << endl + << STRS[EXCP_START] << endl + << STRS[EXCP_SYS] << "," << endl + << STRS[EXCP_RF] << "));" << endl << endl; + + os << "virtual ::Components::ComponentPortDescription *" << endl + << "get_all_ports(" << endl + << STRS[ENV_SNGL_HDR] << ")" << endl + << STRS[EXCP_SNGL] << ";" << endl << endl; + + os << "// Get component implementation." << endl + << "virtual CORBA::Object_ptr" << endl + << "_get_component (" << endl + << STRS[ENV_SNGL_HDR] << ")" << endl + << STRS[EXCP_SNGL] << ";" << endl << endl; + + os << "// CIAO-specific operations." << endl << endl; + + os << "void" << endl + << "_ciao_activate (" << endl + << STRS[ENV_SNGL_HDR] << ")" << endl + << STRS[EXCP_SNGL] << ";" << endl << endl; + + os << "void" << endl + << "_ciao_passivate (" << endl + << STRS[ENV_SNGL_HDR] << ")" << endl + << STRS[EXCP_SNGL] << ";" << endl << endl; + } + }; + + // + // Generates public part of component servant interface declaration. + // + class ServantProtectedEmitter : public HeaderEmitterBase, + public virtual Traversal::ComponentDef, + public virtual Traversal::ProvidesDecl, + public virtual Traversal::ConsumesDecl + { + public: + ServantProtectedEmitter (ostream& os_) + : HeaderEmitterBase (os_) + { + } + + virtual void + visit_component_def_pre (ComponentDefPtr const& c) + { + os << "protected:" << endl + << c->name ().scope () << "::CCM_" << c->name ().simple () + << "_var" << endl + << "executor_;" << endl << endl; + + os << c->name ().simple () << "_Context *" << endl + << "context_;" << endl << endl; + + os << "::CIAO::Session_Container *" << endl + << "container_;" << endl << endl; + } + + virtual void + visit_provides_decl (ProvidesDeclPtr const& p) + { + os << p->type ()->name () << "_var" << endl + << "provide_" << p->name ().simple () << "_;" << endl << endl; + } + + virtual void + visit_consumes_decl (ConsumesDeclPtr const& c) + { + os << c->type ()->name () << "Consumer_var" << endl + << "consumes_" << c->name ().simple () << "_;" << endl << endl; + } + + virtual void + visit_component_def_post (ComponentDefPtr const& c) + { + os << "};" << endl; + + // Close the CIAO_GLUE namespace, if we opened one. + if (c->scope ()->dynamic_type<IDL2::SyntaxTree::FileScope> () != 0) + { + os << "}" << endl; + } + + os << endl; + } + }; + + // + // Generates the component home servant interface. + // + class HomeEmitter : public HeaderEmitterBase, + public virtual Traversal::OperationParameter, + public virtual Traversal::Comma, + public virtual Traversal::HomeDef, + public virtual Traversal::OperationDecl, + public virtual Traversal::AttributeDecl, + public virtual Traversal::HomeFactoryDecl + { + private: + string export_macro_; + + ReturnTypeNameEmitter return_type_name_emitter_; + INArgTypeNameEmitter inarg_type_name_emitter_; + OUTArgTypeNameEmitter outarg_type_name_emitter_; + INOUTArgTypeNameEmitter inoutarg_type_name_emitter_; + + OperationEmitter operation_emitter_; + FactoryEmitter factory_emitter_; + + public: + HomeEmitter (ostream& os_, + string export_macro) + : HeaderEmitterBase (os_), + export_macro_ (export_macro), + return_type_name_emitter_ (os_), + inarg_type_name_emitter_ (os_), + outarg_type_name_emitter_ (os_), + inoutarg_type_name_emitter_ (os_), + operation_emitter_ (os_, + &return_type_name_emitter_, + &inarg_type_name_emitter_, + &outarg_type_name_emitter_, + &inoutarg_type_name_emitter_), + factory_emitter_ (os_, + &inarg_type_name_emitter_) + { + } + + virtual void + visit_home_def_pre (HomeDefPtr const& h) + { + // If we are at file scope, we create a namespace anyway. + if (h->scope ()->dynamic_type<IDL2::SyntaxTree::FileScope> () != 0) + { + os << STRS[GLUE_NS] << endl + << "{" << endl; + } + + // @@@ (JP) Need export macro and prefixable scoped name. + os << "class " << export_macro_ << " " << h->name ().simple () + << "_Servant" << endl + << ": public virtual POA_" << h->name ().in_file_scope () + << "," << endl + << STRS[INH_RCSB] << endl + << "{" << endl + << "public:" << endl; + + os << h->name ().simple () << "_Servant (" << endl + << h->name ().scope () << "::CCM_" << h->name ().simple () + << "_ptr exe," << endl + << "::CIAO::Session_Container *c);" << endl << endl; + + os << "virtual ~" << h->name ().simple () << "_Servant (void);" + << endl << endl; + + os << "// Home factory and other operations." << endl << endl; + } + + virtual void + visit_operation_decl (OperationDeclPtr const& d) + { + d->accept (&operation_emitter_); + } + + virtual void + visit_home_factory_decl (HomeFactoryDeclPtr const& f) + { + f->accept (&factory_emitter_); + } + + virtual void + visit_attribute_decl (AttributeDeclPtr const& a) + { + // TODO + } + + virtual void + visit_home_def_post (HomeDefPtr const& h) + { + // @@@ (JP) Need primary key support. + os << "// Operations for keyless home interface." << endl << endl; + + os << "virtual ::Components::CCMObject_ptr" << endl + << "create_component (" << endl + << STRS[ENV_SNGL_HDR] << ")" << endl + << STRS[EXCP_START] << endl + << STRS[EXCP_SYS] << "," << endl + << "::Components::CreateFailure));" << endl << endl; + + os << "// Operations for implicit home interface." << endl << endl; + + os << "virtual " << h->manages ()->name () << "_ptr" << endl + << "create (" << endl + << STRS[ENV_SNGL_HDR] << ")" << endl + << STRS[EXCP_START] << endl + << STRS[EXCP_SYS] << "," << endl + << "::Components::CreateFailure));" << endl << endl; + + os << "// Operations for CCMHome interface." << endl << endl; + + os << "virtual ::CORBA::IRObject_ptr" << endl + << "get_component_def (" << endl + << STRS[ENV_SNGL_HDR] << ")" << endl + << STRS[EXCP_SNGL] << ";" << endl << endl; + + os << "virtual ::CORBA::IRObject_ptr" << endl + << "get_home_def (" << endl + << STRS[ENV_SNGL_HDR] << ")" << endl + << STRS[EXCP_SNGL] << ";" << endl << endl; + + os << "virtual void" << endl + << "remove_component (" << endl + << "::Components::CCMObject_ptr comp" << endl + << STRS[ENV_HDR] << ")" << endl + << STRS[EXCP_START] << endl + << STRS[EXCP_SYS] << "," << endl + << STRS[EXCP_RF] << "));" << endl << endl; + + os << "// Supported operations." << endl << endl; + + // @@@ (JP) Must include ancestors' supported interfaces as well. + for (SyntaxTree::HomeDef::Iterator i = h->supports_begin (); + i != h->supports_end (); + i++) + { + i->resolve ()->accept (&operation_emitter_); + } + + os << "protected:" << endl + << "// CIAO-specific operations." << endl << endl; + + os << h->manages ()->name () << "_ptr" << endl + << "_ciao_activate_component (" << endl + << h->manages ()->name ().scope () << "::CCM_" + << h->manages ()->name ().simple () << "_ptr exe" << endl + << STRS[ENV_HDR] << ")" << endl + << STRS[EXCP_SNGL] << ";" << endl << endl; + + os << "void" << endl + << "_ciao_passivate_component (" << endl + << h->manages ()->name () << "_ptr comp" << endl + << STRS[ENV_SNGL_HDR] << ")" << endl + << STRS[EXCP_SNGL] << ";" << endl << endl; + + os << "protected:" << endl; + + os << h->name ().scope () << "::CCM_" + << h->name ().simple () << "_var" << endl + << "executor_;" << endl << endl; + + os << "::CIAO::Session_Container *" << endl + << "container_;" << endl << endl; + + os << "ACE_Hash_Map_Manager_Ex<" << endl + << "PortableServer::ObjectId," << endl + << h->manages ()->name ().simple () << "_Servant *," << endl + << "TAO_ObjectId_Hash," << endl + << "ACE_Equal_To<PortableServer::ObjectId>," << endl + << "ACE_SYNCH_MUTEX>" << endl + << "component_map_;" << endl; + + os << "};" << endl << endl; + + os << "extern \"C\" " << export_macro_ << " ::PortableServer::Servant" + << endl + << "create" << h->name ().simple () << "_Servant (" << endl + << "::Components::HomeExecutorBase_ptr p," << endl + << "CIAO::Session_Container *c" << endl + << STRS[ENV_HDR] << ");" << endl; + + // Close the CIAO_GLUE namespace, if we opened one. + if (h->scope ()->dynamic_type<IDL2::SyntaxTree::FileScope> () != 0) + { + os << "}" << endl; + } + + os << endl; + } + }; +} + +HeaderEmitterBase::HeaderEmitterBase (ostream& os_) + : os (os_) +{ +} + +// =========================================================== + +ServantHeaderEmitter::ServantHeaderEmitter ( + ostream& os_, + CommandLine const& cl, + string export_macro, + UnconstrainedInterfaceDefSet const& interface_set, + ComponentDefSet const& component_set, + HomeDefSet const& home_set) + : HeaderEmitterBase (os_), + cl_ (cl), + export_macro_ (export_macro), + component_set_ (component_set), + home_set_ (home_set), + interface_set_ (interface_set) + { + } + +bool +ServantHeaderEmitter::contains_element (ModulePtr const& m) const +{ + for (UnconstrainedInterfaceDefSet::const_iterator i = + interface_set_.begin (); + i != interface_set_.end (); + i++) + { + if (m->order ().suborder ((*i)->order ())) return true; + } + + for (ComponentDefSet::const_iterator i = component_set_.begin (); + i != component_set_.end (); + i++) + { + if (m->order ().suborder ((*i)->order ())) return true; + } + + for (HomeDefSet::const_iterator i = home_set_.begin (); + i != home_set_.end (); + i++) + { + if (m->order ().suborder ((*i)->order ())) return true; + } + + return false; +} + +namespace +{ + // On some platforms toupper can be something else than a + // function. + int + upcase (int c) + { + return std::toupper (c); + } +} + +void +ServantHeaderEmitter::visit_translation_unit_pre ( + TranslationUnitPtr const& u) +{ + os << COPYRIGHT << endl << endl; + + fs::path file_path = u->principal_translation_region ()->file_path (); + string file_name (""); + + if (!file_path.empty ()) + { + file_name = file_path.leaf (); + } + + string uc_file_name = file_name; + + std::transform (uc_file_name.begin (), + uc_file_name.end (), + uc_file_name.begin (), + upcase); + + string uc_file_suffix = cl_.get_value ("hdr-file-suffix", + "_svnt.h"); + + std::transform (uc_file_suffix.begin (), + uc_file_suffix.end (), + uc_file_suffix.begin (), + upcase); + + string guard = + "CIAO_GLUE_SESSION_" + + regex::perl_s (uc_file_name, + "/^(.*?)(\\.(IDL|CIDL))?$/$1" + uc_file_suffix + "/"); + + // Replace any remaining '.' with '_'. + guard = regex::perl_s (guard, "/\\./_/"); + + os << "#ifndef " << guard << endl + << "#define " << guard << endl + << "#include \"ace/pre.h\"" << endl << endl; + + string export_include = cl_.get_value ("export-include", ""); + + if (!export_include.empty ()) + { + os << "#include \"" << export_include << "\"" << endl << endl; + } + + // Get the suffix for the executor IDL file and strip off the + // trailing .idl. + // @@@ (JP) I guess it's a safe assumption that the tail of the + // suffix will be .idl. + string suffix = cl_.get_value ("lem-file-suffix", "_exec.idl"); + suffix = regex::perl_s (suffix, + "/^(.*?)(\\.idl)?$/$1/"); + + // @@@ (JP) No way of knowing if the IDL compiler had command line + // option(s) to change C.h and/or S.h. We could add command line options + // to the CIDL compiler for them, but the user will have to make sure + // they are in synch with the IDL compiler's options. + os << "#include \"" + << regex::perl_s (file_name, + "/^(.*?)(\\.(idl|cidl))?$/$1S.h/") + << "\"" + << endl + << "#include \"" + << regex::perl_s (file_name, + "/^(.*?)(\\.(idl|cidl))?$/$1" + suffix + "C.h/") + << "\"" + << endl << endl; + + os << "#include \"ciao/Container_Base.h\"" << endl + << "#include \"tao/LocalObject.h\"" << endl + << "#include \"tao/PortableServer/Key_Adapters.h\"" << endl + << "#include \"ace/Active_Map_Manager_T.h\"" << endl << endl; + + os << "#if !defined (ACE_LACKS_PRAGMA_ONCE)" << endl + << "# pragma once" << endl + << "#endif /* ACE_LACKS_PRAGMA_ONCE */" << endl << endl; +} + +void +ServantHeaderEmitter::visit_module_pre (ModulePtr const& m) +{ + if (contains_element (m)) + { + os << STRS[GLUE_NS] << "_" << m->name ().simple () << endl + << "{" << endl; + } +} + +void +ServantHeaderEmitter::visit_unconstrained_interface_def ( + UnconstrainedInterfaceDefPtr const& i) +{ + if (interface_set_.find (i) != interface_set_.end ()) + { + FacetEmitter facet_emitter (os, export_macro_); + i->accept (&facet_emitter); + } +} + +void +ServantHeaderEmitter::visit_component_def (ComponentDefPtr const& c) +{ + { + ContextPublicEmitter context_public_emitter (os, export_macro_); + c->accept (&context_public_emitter); + } + + { + ContextProtectedMethodEmitter context_protected_method_emitter (os); + c->accept (&context_protected_method_emitter); + } + + { + ContextProtectedMemberEmitter context_protected_member_emitter (os); + c->accept (&context_protected_member_emitter); + } + + { + ServantPublicEmitter servant_public_emitter (os, export_macro_); + c->accept (&servant_public_emitter); + } + + { + ServantProtectedEmitter servant_protected_emitter (os); + c->accept (&servant_protected_emitter); + } +} + +void +ServantHeaderEmitter::visit_home_def (HomeDefPtr const& h) +{ + HomeEmitter home_emitter (os, export_macro_); + h->accept (&home_emitter); +} + +void +ServantHeaderEmitter::visit_module_post (ModulePtr const& m) +{ + if (contains_element (m)) + { + os << "}" << endl << endl; + } +} + +// ============================================================== + +ServantHeaderFinalizingEmitter::ServantHeaderFinalizingEmitter ( + ostream& os_, + CommandLine const& cl, + string export_macro) + : HeaderEmitterBase (os_), + cl_ (cl), + export_macro_ (export_macro) +{ +} + +void +ServantHeaderFinalizingEmitter::visit_home_def (HomeDefPtr const& h) +{ +} + +void +ServantHeaderFinalizingEmitter::visit_translation_unit_post ( + TranslationUnitPtr const& u) +{ + fs::path file_path = u->principal_translation_region ()->file_path (); + + if (file_path.empty ()) return; + + string uc_file_name = file_path.leaf (); + + std::transform (uc_file_name.begin (), + uc_file_name.end (), + uc_file_name.begin (), + upcase); + + string uc_file_suffix = cl_.get_value ("hdr-file-suffix", + "_svnt.h"); + + std::transform (uc_file_suffix.begin (), + uc_file_suffix.end (), + uc_file_suffix.begin (), + upcase); + + string guard = + "CIAO_GLUE_SESSION_" + + regex::perl_s (uc_file_name, + "/^(.*?)(\\.(IDL|CIDL))?$/$1" + uc_file_suffix + "/"); + + guard = regex::perl_s (guard, "/\\./_/"); + + os << "#include \"ace/post.h\"" << endl + << "#endif /* " << guard << " */" + << endl << endl; +} diff --git a/TAO/CIAO/CIDLC/ServantHeaderGenerator.hpp b/TAO/CIAO/CIDLC/ServantHeaderGenerator.hpp new file mode 100644 index 00000000000..7be488ba818 --- /dev/null +++ b/TAO/CIAO/CIDLC/ServantHeaderGenerator.hpp @@ -0,0 +1,104 @@ +// $Id$ +#ifndef SERVANT_HEADER_GENERATOR_HPP +#define SERVANT_HEADER_GENERATOR_HPP + +#include "CCF/CodeGenerationKit/CommandLine.hpp" + + +#include "CCF/CIDL/CIDL_SyntaxTree.hpp" +#include "CCF/CIDL/CIDL_Traversal.hpp" + +using std::ostream; + +using namespace CIDL; +using namespace CIDL::SyntaxTree; + +// HeaderEmitterBase is a base class that holds the ostream member +// common to every other class in this file. +// +class HeaderEmitterBase +{ +protected: + HeaderEmitterBase (ostream&); + + ostream& os; +}; + +// Emitter generates the servant source mapping for declarations collected +// by Collector. Note that the original structure of modules is preserved. +// +class ServantHeaderEmitter + : public HeaderEmitterBase, + public virtual Traversal::TranslationUnit, + public virtual Traversal::TranslationRegion, + public virtual Traversal::FileScope, + public virtual Traversal::Module, + public virtual Traversal::UnconstrainedInterfaceDef, + public virtual Traversal::ConcreteEventTypeDef, + public virtual Traversal::ComponentDef, + public virtual Traversal::HomeDef +{ +public: + ServantHeaderEmitter (ostream& os_, + CommandLine const& cl, + string export_macro, + UnconstrainedInterfaceDefSet const& interface_set, + ComponentDefSet const& component_set, + HomeDefSet const& home_set); + + bool + contains_element (ModulePtr const& m) const; + + virtual void + visit_translation_unit_pre (TranslationUnitPtr const& u); + + virtual void + visit_module_pre (ModulePtr const& m); + + virtual void + visit_unconstrained_interface_def ( + UnconstrainedInterfaceDefPtr const& i); + + virtual void + visit_component_def (ComponentDefPtr const& c); + + virtual void + visit_home_def (HomeDefPtr const& h); + + virtual void + visit_module_post (ModulePtr const& m); + +private: + CommandLine const& cl_; + string export_macro_; + + ComponentDefSet const& component_set_; + HomeDefSet const& home_set_; + UnconstrainedInterfaceDefSet const& interface_set_; +}; + +class ServantHeaderFinalizingEmitter + : public HeaderEmitterBase, + public virtual Traversal::TranslationUnit, + public virtual Traversal::TranslationRegion, + public virtual Traversal::FileScope, + public virtual Traversal::Module, + public virtual Traversal::HomeDef +{ +public: + ServantHeaderFinalizingEmitter (ostream& os_, + CommandLine const& cl, + string export_macro); + + virtual void + visit_home_def (HomeDefPtr const& h); + + virtual void + visit_translation_unit_post (TranslationUnitPtr const& u); + +private: + CommandLine const& cl_; + string export_macro_; +}; + +#endif // SERVANT_HEADER_GENERATOR_HPP diff --git a/TAO/CIAO/CIDLC/ServantSourceGenerator.cpp b/TAO/CIAO/CIDLC/ServantSourceGenerator.cpp new file mode 100644 index 00000000000..04b091a46fd --- /dev/null +++ b/TAO/CIAO/CIDLC/ServantSourceGenerator.cpp @@ -0,0 +1,2525 @@ +// $Id$ +#include "ServantSourceGenerator.hpp" + +#include "CCF/CIDL/CIDL_SyntaxTree.hpp" +#include "CCF/CIDL/CIDL_Traversal.hpp" + +#include "CCF/CodeGenerationKit/Regex.hpp" +#include "CCF/CodeGenerationKit/IDLStream.hpp" + +#include "Literals.hpp" + +#include <ostream> + +using namespace CIDL; +using namespace CIDL::SyntaxTree; +using namespace StringLiterals; + +namespace +{ + // Generates the name of an operation's return type. + // + // + class ReturnTypeNameEmitter : public SourceEmitterBase, + public virtual Traversal::Void, + public virtual Traversal::Boolean, + public virtual Traversal::Long, + public virtual Traversal::String, + public virtual Traversal::LocalInterfaceDecl + { + public: + ReturnTypeNameEmitter (ostream& os_) + : SourceEmitterBase (os_) + { + } + + virtual void + visit_void (VoidPtr const&) + { + os << "void"; + } + + virtual void + visit_boolean (BooleanPtr const&) + { + os << "::CORBA::Boolean"; + } + + virtual void + visit_long (LongPtr const&) + { + os << "::CORBA::Long"; + } + + virtual void + visit_string (StringPtr const&) + { + os << "char *"; + } + + virtual void + visit_local_interface_decl (LocalInterfaceDeclPtr const& i) + { + os << i->name () << "_ptr"; + } + }; + + // Generates the typename of an IN argument. + // + // + class INArgTypeNameEmitter : public SourceEmitterBase, + public virtual Traversal::Boolean, + public virtual Traversal::Long, + public virtual Traversal::String + { + public: + INArgTypeNameEmitter (ostream& os_) + : SourceEmitterBase (os_) + { + } + + virtual void + visit_boolean (BooleanPtr const&) + { + os << "::CORBA::Boolean"; + } + + virtual void + visit_long (LongPtr const&) + { + os << "::CORBA::Long"; + } + + virtual void + visit_string (StringPtr const&) + { + os << "const char *"; + } + }; + + // Generates the typename of an OUT argument. + // + // + class OUTArgTypeNameEmitter : public SourceEmitterBase, + public virtual Traversal::Boolean, + public virtual Traversal::Long, + public virtual Traversal::String + { + public: + OUTArgTypeNameEmitter (ostream& os_) + : SourceEmitterBase (os_) + { + } + + virtual void + visit_boolean (BooleanPtr const&) + { + os << "::CORBA::Boolean_out"; + } + + virtual void + visit_long (LongPtr const&) + { + os << "::CORBA::Long_out"; + } + + virtual void + visit_string (StringPtr const&) + { + os << "::CORBA::String_out"; + } + }; + + // Generates the typename of an INOUT argument. + // + // + class INOUTArgTypeNameEmitter : public SourceEmitterBase, + public virtual Traversal::Boolean, + public virtual Traversal::Long, + public virtual Traversal::String + { + public: + INOUTArgTypeNameEmitter (ostream& os_) + : SourceEmitterBase (os_) + { + } + + virtual void + visit_boolean (BooleanPtr const&) + { + os << "::CORBA::Boolean &"; + } + + virtual void + visit_long (LongPtr const&) + { + os << "::CORBA::Long &"; + } + + virtual void + visit_string (StringPtr const&) + { + os << "char *&"; + } + }; + + // Generates an argument's identifier. + // + // + class ArgNameEmitter : public SourceEmitterBase, + public virtual Traversal::TypeDecl + { + public: + ArgNameEmitter (ostream& os_) + : SourceEmitterBase (os_) + { + } + + virtual void + visit_operation_parameter_pre (OperationParameterPtr const&) + { + os << endl; + } + + virtual void + visit_operation_parameter_post (OperationParameterPtr const& op) + { + os << " " << op->name (); + } + + virtual void + visit_comma (CommaPtr const&) + { + os << ","; + } + }; + + // Generates an attribute's accessor operation. + // + // + class GetAttributeEmitter : public SourceEmitterBase, + public virtual Traversal::AttributeDecl, + public virtual Traversal::ComponentDef + { + public: + GetAttributeEmitter (ostream& os_, + ReturnTypeNameEmitter* return_type_name_emitter) + : SourceEmitterBase (os_), + AttributeDecl (return_type_name_emitter) + { + } + + virtual void + visit_attribute_post (AttributeDeclPtr const& a) + { + os << endl + << a->name ().scope ().simple () + << "_Servant::" << a->name ().simple () << " (" << endl + << STRS[ENV_SNGL_SRC] << ")" << endl + << STRS[EXCP_SNGL] << endl + << "{" << endl + << "return this->executor_->" << a->name ().simple () + << " (" << endl + << STRS[ENV_SNGL_ARG] << ");" << endl + << "}" << endl << endl; + } + }; + + // Generates an attribute's mutator operation. + // + // + class SetAttributeEmitter : public SourceEmitterBase, + public virtual Traversal::AttributeDecl + { + public: + SetAttributeEmitter (ostream& os_, + ReturnTypeNameEmitter* return_type_name_emitter) + : SourceEmitterBase (os_), + AttributeDecl (return_type_name_emitter) + { + } + + virtual void + visit_attribute_pre (AttributeDeclPtr const& a) + { + os << "void " << endl + << a->name ().scope ().simple () + << "_Servant::" << a->name ().simple () << " (" << endl; + } + + virtual void + visit_attribute_post (AttributeDeclPtr const& a) + { + os << " val" << endl + << STRS[ENV_SRC] << ")" << endl + << STRS[EXCP_SNGL] << endl + << "{" << endl + << "this->executor_->" << a->name ().simple () << " (" << endl + << "val" << endl + << STRS[ENV_ARG] << ");" << endl + << "}" << endl << endl; + } + }; + + // Generates the statement that delegates the operation + // to the executor. + // + class OperationExecEmitter : public SourceEmitterBase, + public virtual Traversal::OperationParameter, + public virtual Traversal::Comma, + public virtual Traversal::OperationDecl + { + public: + OperationExecEmitter (ostream& os_, + ArgNameEmitter* arg_name_emitter_) + : SourceEmitterBase (os_), + OperationParameter (arg_name_emitter_, + arg_name_emitter_, + arg_name_emitter_) + { + } + + virtual void + visit_operation_parameter_pre (OperationParameterPtr const&) + { + os << endl; + } + + virtual void + visit_operation_parameter_post (OperationParameterPtr const& op) + { + os << op->name (); + } + + virtual void + visit_comma (CommaPtr const&) + { + os << ","; + } + }; + + // Generates an operation definition. + // + // + class OperationEmitter : public SourceEmitterBase, + public virtual Traversal::OperationParameter, + public virtual Traversal::Comma, + public virtual Traversal::UnconstrainedInterfaceDef, + public virtual Traversal::OperationDecl + { + public: + OperationEmitter (ostream& os_, + ReturnTypeNameEmitter* return_type_name_emitter, + INArgTypeNameEmitter* inarg_type_name_emitter_, + OUTArgTypeNameEmitter* outarg_type_name_emitter_, + INOUTArgTypeNameEmitter* inoutarg_type_name_emitter_) + : SourceEmitterBase (os_), + OperationParameter (inarg_type_name_emitter_, + outarg_type_name_emitter_, + inoutarg_type_name_emitter_), + OperationDecl (return_type_name_emitter) + { + } + + virtual void + visit_operation_decl_name (OperationDeclPtr const& d) + { + os << endl + << d->name ().scope ().simple () << "_Servant::" + << d->name ().simple () << " ("; + } + + virtual void + visit_operation_parameter_pre (OperationParameterPtr const&) + { + os << endl; + } + + virtual void + visit_operation_parameter_post (OperationParameterPtr const& op) + { + os << " " << op->name (); + } + + virtual void + visit_comma (CommaPtr const&) + { + os << ","; + } + + virtual void + visit_operation_decl_post (OperationDeclPtr const& d) + { + bool void_return_type = + (d->type ()->dynamic_type<IDL2::SyntaxTree::Void> () != 0); + + // @@@ (JP) Must add support for user exceptions. + os << endl + << (d->begin () == d->end () ? STRS[ENV_SNGL_SRC] : STRS[ENV_SRC]) + << ")" << endl + << STRS[EXCP_SNGL] << endl + << "{" << endl + << (void_return_type ? "" : "return ") + << "this->executor_->" << d->name ().simple () << " ("; + + ArgNameEmitter arg_name_emitter (os); + OperationExecEmitter operation_exec_emitter (os, + &arg_name_emitter); + d->accept (&operation_exec_emitter); + + os << endl + << (d->begin () == d->end () ? STRS[ENV_SNGL_ARG] : STRS[ENV_ARG]) + << ");" << endl + << "}" << endl << endl; + } + }; + + // Generates the operation associated with a home factory definition. + // + // + class FactoryEmitter : public SourceEmitterBase, + public virtual Traversal::HomeFactoryDecl, + public virtual Traversal::OperationParameter, + public virtual Traversal::Comma + { + public: + FactoryEmitter (ostream& os_, + INArgTypeNameEmitter* inarg_type_name_emitter_) + : SourceEmitterBase (os_), + OperationParameter (inarg_type_name_emitter_, + inarg_type_name_emitter_, + inarg_type_name_emitter_) + { + } + + virtual void + visit_home_factory_decl_type (HomeFactoryDeclPtr const& f) + { + HomeDefPtr def (f->scope ()->dynamic_type<SyntaxTree::HomeDef> ()); + os << def->manages ()->name () << "_ptr"; + } + + virtual void + visit_home_factory_decl_name (HomeFactoryDeclPtr const& f) + { + os << endl + << f->name ().scope ().simple () << "_Servant::" + << f->name ().simple () << " ("; + } + + virtual void + visit_operation_parameter_pre (OperationParameterPtr const&) + { + os << endl; + } + + virtual void + visit_operation_parameter_post (OperationParameterPtr const& op) + { + os << " " << op->name (); + } + + virtual void + visit_comma (CommaPtr const&) + { + os << ","; + } + + virtual void + visit_home_factory_decl_post (HomeFactoryDeclPtr const& f) + { + os << endl + << (f->begin () == f->end () ? STRS[ENV_SNGL_SRC] : STRS[ENV_SRC]) + << ")" << endl + << STRS[EXCP_SNGL] << endl + << "{" << endl + << "::Components::EnterpriseComponent_var _ciao_ec =" << endl + << "this->executor_->" << f->name ().simple () << " ("; + + ArgNameEmitter arg_name_emitter (os); + OperationExecEmitter operation_exec_emitter (os, + &arg_name_emitter); + f->accept (&operation_exec_emitter); + + // If this cast is 0, a syntax error has slipped through. + HomeDefPtr def (f->scope ()->dynamic_type<SyntaxTree::HomeDef> ()); + ScopedName retval = def->manages ()->name (); + + os << endl + << (f->begin () == f->end () ? STRS[ENV_SNGL_ARG] : STRS[ENV_ARG]) + << ");" << endl + << "ACE_CHECK_RETURN (" << retval << "::_nil ());" + << endl << endl + << retval.scope () << "::CCM_" << retval.simple () + << "_var _ciao_comp =" << endl + << retval.scope () << "::CCM_" << retval.simple () + << "::_narrow (" << endl + << "_ciao_ec.in ()" << endl + << STRS[ENV_ARG] << ");" << endl << endl + << "return this->_ciao_activate_component (" << endl + << "_ciao_comp.in ()" << endl + << STRS[ENV_ARG] << ");" << endl + << "}" << endl << endl; + } + }; + + // Generates an operation of a supported interface. + // + // + class SupportedOperationEmitter : public virtual OperationEmitter, + public virtual Traversal::OperationParameter, + public virtual Traversal::OperationDecl + { + private: + SimpleName context_; + + public: + SupportedOperationEmitter (ostream& os_, + ReturnTypeNameEmitter* return_type_name_emitter, + INArgTypeNameEmitter* inarg_type_name_emitter_, + OUTArgTypeNameEmitter* outarg_type_name_emitter_, + INOUTArgTypeNameEmitter* inoutarg_type_name_emitter_, + SimpleName context) + : OperationEmitter (os_, + return_type_name_emitter, + inarg_type_name_emitter_, + outarg_type_name_emitter_, + inoutarg_type_name_emitter_), + OperationParameter (inarg_type_name_emitter_, + outarg_type_name_emitter_, + inoutarg_type_name_emitter_), + OperationDecl (return_type_name_emitter), + context_ (context) + { + } + + virtual void + visit_operation_decl_name (OperationDeclPtr const& d) + { + os << endl + << context_ << "_Servant::" + << d->name ().simple () << " ("; + } + }; + + // Generates an IF statement that compares the publisher name + // argument with an item from an iterator, and calls the + // appropriate subscribe operation upon success. + class SubscribeEmitter : public SourceEmitterBase, + public virtual Traversal::ComponentDef, + public virtual Traversal::PublishesDecl + { + public: + SubscribeEmitter (ostream& os_) + : SourceEmitterBase (os_) + { + } + + virtual void + visit_publishes_decl (PublishesDeclPtr const& p) + { + os << "if (ACE_OS::strcmp (publisher_name, \"" + << p->name ().simple () << "\") == 0)" << endl + << "{" << endl + << p->type ()->name () << "Consumer_var _ciao_consumer =" << endl + << p->type ()->name () << "Consumer::_narrow (" << endl + << "subscribe" << endl + << STRS[ENV_ARG] << ");" << endl + << "ACE_CHECK_RETURN (0);" << endl << endl + << "if (::CORBA::is_nil (_ciao_consumer.in ()))" << endl + << "{" << endl + << "ACE_THROW_RETURN (" << STRS[EXCP_IC] << " (), 0);" + << endl + << "}" << endl << endl + << "return this->subscribe_" << p->name ().simple () + << " (" << endl + << "_ciao_consumer.in ()" << endl + << STRS[ENV_ARG] << ");" << endl + << "}" << endl << endl; + } + }; + + // Generates an IF statement that compares the publisher name + // argument with an item from an iterator, and calls the + // appropriate unsubscribe operation upon success. + class UnsubscribeEmitter : public SourceEmitterBase, + public virtual Traversal::ComponentDef, + public virtual Traversal::PublishesDecl + { + public: + UnsubscribeEmitter (ostream& os_) + : SourceEmitterBase (os_) + { + } + + virtual void + visit_publishes_decl (PublishesDeclPtr const& p) + { + os << "if (ACE_OS::strcmp (publisher_name, \"" + << p->name ().simple () << "\") == 0)" << endl + << "{" << endl + << "return this->unsubscribe_" << p->name ().simple () + << " (" << endl + << "ck" << endl + << STRS[ENV_ARG] << ");" << endl + << "}" << endl << endl; + } + }; + + // Generates an IF statement that compares the receptacle name + // argument with an item from an iterator, and calls the + // appropriate connect operation upon success. + class ConnectEmitter : public SourceEmitterBase, + public virtual Traversal::ComponentDef, + public virtual Traversal::UsesDecl + { + public: + ConnectEmitter (ostream& os_) + : SourceEmitterBase (os_) + { + } + + virtual void + visit_uses_decl (UsesDeclPtr const& u) + { + os << "if (ACE_OS::strcmp (name, \"" + << u->name ().simple () << "\") == 0)" << endl + << "{" << endl + << u->type ()->name () << "_var _ciao_conn =" << endl + << u->type ()->name () << "::_narrow (" << endl + << "connection" << endl + << STRS[ENV_ARG] << ");" << endl + << "ACE_CHECK_RETURN (0);" << endl << endl + << "if (::CORBA::is_nil (_ciao_conn.in ()))" << endl + << "{" << endl + << "ACE_THROW_RETURN (" << STRS[EXCP_IC] << " (), 0);" + << endl + << "}" << endl << endl + << "// Simplex connect." << endl + << "this->connect_" << u->name ().simple () << " (" << endl + << "_ciao_conn.in ()" << endl + << STRS[ENV_ARG] << ");" << endl << endl + << "return 0;" << endl + << "}" << endl << endl; + } + }; + + // Generates an IF statement that compares the receptacle name + // argument with an item from an iterator, and calls the + // appropriate disconnect operation upon success. + class DisconnectEmitter : public SourceEmitterBase, + public virtual Traversal::ComponentDef, + public virtual Traversal::UsesDecl + { + public: + DisconnectEmitter (ostream& os_) + : SourceEmitterBase (os_) + { + } + + virtual void + visit_uses_decl (UsesDeclPtr const& u) + { + os << "if (ACE_OS::strcmp (name, \"" + << u->name ().simple () << "\") == 0)" << endl + << "{" << endl + << "// Simplex disconnect." << endl + << "return this->disconnect_" << u->name ().simple () + << " (" << STRS[ENV_SNGL_ARG] << ");" << endl + << "}" << endl << endl; + } + }; + + // Generates an IF statement that compares the consumer name + // argument with an item from an iterator, and calls the + // appropriate get_consumer operation upon success. + class GetConsumerEmitter : public SourceEmitterBase, + public virtual Traversal::ComponentDef, + public virtual Traversal::ConsumesDecl + { + public: + GetConsumerEmitter (ostream& os_) + : SourceEmitterBase (os_) + { + } + + virtual void + visit_consumes_decl (ConsumesDeclPtr const& c) + { + os << "if (ACE_OS::strcmp (sink_name, \"" + << c->name ().simple () << "\") == 0)" << endl + << "{" << endl + << "return this->get_consumer_" << c->name ().simple () + << " (" << STRS[ENV_SNGL_ARG] << ");" << endl + << "}" << endl << endl; + } + }; + + // Generates an IF statement that compares the facet name + // argument with an item from an iterator, and calls the + // appropriate provide operation upon success. + class ProvidesFacetEmitter : public SourceEmitterBase, + public virtual Traversal::ComponentDef, + public virtual Traversal::ProvidesDecl + { + public: + ProvidesFacetEmitter (ostream& os_) + : SourceEmitterBase (os_) + { + } + + virtual void + visit_provides_decl (ProvidesDeclPtr const& p) + { + os << "if (ACE_OS::strcmp (name, \"" + << p->name ().simple () << "\") == 0)" << endl + << "{" << endl + << "return this->provide_" << p->name ().simple () + << " (" << STRS[ENV_SNGL_ARG] << ");" << endl + << "}" << endl << endl; + } + }; + + // + // FacetEmitter generates facet servant class definitions. + // + class FacetEmitter : public SourceEmitterBase, + public virtual Traversal::UnconstrainedInterfaceDef, + public virtual Traversal::OperationDecl, + public virtual Traversal::AttributeDecl + { + private: + ReturnTypeNameEmitter return_type_name_emitter_; + INArgTypeNameEmitter inarg_type_name_emitter_; + INOUTArgTypeNameEmitter inoutarg_type_name_emitter_; + OUTArgTypeNameEmitter outarg_type_name_emitter_; + + OperationEmitter operation_emitter_; + + public: + FacetEmitter (ostream& os_) + : SourceEmitterBase (os_), + return_type_name_emitter_ (os_), + inarg_type_name_emitter_ (os_), + inoutarg_type_name_emitter_ (os_), + outarg_type_name_emitter_ (os_), + operation_emitter_ (os_, + &return_type_name_emitter_, + &inarg_type_name_emitter_, + &outarg_type_name_emitter_, + &inoutarg_type_name_emitter_) + { + } + + virtual void + visit_unconstrained_interface_def_pre ( + UnconstrainedInterfaceDefPtr const& i) + { + // If we are at file scope, we create a namespace anyway. + if (i->scope ()->dynamic_type<IDL2::SyntaxTree::FileScope> () != 0) + { + os << STRS[GLUE_NS] << endl + << "{" << endl; + } + + os << i->name ().simple () << "_Servant::" << i->name ().simple () + << "_Servant (" << endl + << i->name ().scope () << "::CCM_" << i->name ().simple () + << "_ptr executor," << endl + << "::Components::CCMContext_ptr c)" << endl + << ": executor_ (" << i->name ().scope () << "::CCM_" + << i->name ().simple () << "::_duplicate (executor))," << endl + << "ctx_ (::Components::CCMContext::_duplicate (c))" << endl + << "{" << endl + << "}" << endl << endl; + + os << i->name ().simple () << "_Servant::~" << i->name ().simple () + << "_Servant (void)" << endl + << "{" << endl + << "}" << endl << endl; + } + + virtual void + visit_operation_decl (OperationDeclPtr const& d) + { + d->accept (&operation_emitter_); + } + + virtual void + visit_attribute_decl (AttributeDeclPtr const& a) + { + // TODO + } + + virtual void + visit_unconstrained_interface_def_post ( + UnconstrainedInterfaceDefPtr const& i) + { + os << "CORBA::Object_ptr" << endl + << i->name ().simple () << "_Servant::_get_component (" << endl + << STRS[ENV_SNGL_SRC] << ")" << endl + << "ACE_THROW_SPEC ((CORBA::SystemException))" << endl + << "{" << endl + << "::Components::SessionContext_var sc =" << endl + << "::Components::SessionContext::_narrow (" << endl + << "this->ctx_.in ()" << endl + << STRS[ENV_ARG] << ");" << endl + << "ACE_CHECK_RETURN (CORBA::Object::_nil ());" << endl << endl + << "if (! CORBA::is_nil (sc.in ()))" << endl + << "{" << endl + << "return sc->get_CCM_object (" << endl + << STRS[ENV_SNGL_ARG] << ");" << endl + << "}" << endl << endl + << "::Components::EntityContext_var ec =" << endl + << "::Components::EntityContext::_narrow (" << endl + << "this->ctx_.in ()" << endl + << STRS[ENV_ARG] << ");" << endl + << "ACE_CHECK_RETURN (CORBA::Object::_nil ());" << endl << endl + << "if (! CORBA::is_nil (ec.in ()))" << endl + << "{" << endl + << "return ec->get_CCM_object (" << endl + << STRS[ENV_SNGL_ARG] << ");" << endl + << "}" << endl << endl + << "ACE_THROW_RETURN (CORBA::INTERNAL (), 0);" << endl + << "}" << endl; + + // Close the CIAO_GLUE namespace, if we opened one. + if (i->scope ()->dynamic_type<IDL2::SyntaxTree::FileScope> () != 0) + { + os << "}" << endl; + } + + os << endl; + } + }; + + // + // Generates component context interface definitions. + // + class ContextEmitter : public SourceEmitterBase, + public virtual Traversal::ComponentDef, + public virtual Traversal::UsesDecl, + public virtual Traversal::PublishesDecl, + public virtual Traversal::EmitsDecl + { + public: + ContextEmitter (ostream& os_) + : SourceEmitterBase (os_) + { + } + + virtual void + visit_component_def_pre (ComponentDefPtr const& c) + { + // If we are at file scope, we create a namespace anyway. + if (c->scope ()->dynamic_type<IDL2::SyntaxTree::FileScope> () != 0) + { + os << "namespace CIAO_GLUE" << endl + << "{" << endl; + } + + os << c->name ().simple () << "_Context::" + << c->name ().simple () << "_Context (" << endl + << "::Components::CCMHome_ptr home," << endl + << "::CIAO::Session_Container *c," << endl + << c->name ().simple () << "_Servant *sv)" << endl + << ": home_ (::Components::CCMHome::_duplicate (home))," << endl + << "container_ (c)," << endl + << "servant_ (sv)" << endl + << "{" << endl + << "}" << endl << endl; + + os << c->name ().simple () << "_Context::~" + << c->name ().simple () << "_Context (void)" << endl + << "{" << endl + << "}" << endl << endl; + + os << "// Operations from ::Components::CCMContext." << endl << endl; + + os << "::Components::Principal_ptr" << endl + << c->name ().simple () << "_Context::" + << "get_caller_principal (" << endl + << STRS[ENV_SNGL_SRC] << ")" << endl + << STRS[EXCP_SNGL] << endl + << "{" << endl + << "ACE_THROW_RETURN (" << endl + << "::CORBA::NO_IMPLEMENT ()," << endl + << "::Components::Principal::_nil ());" << endl + << "}" << endl << endl; + + os << "::Components::CCMHome_ptr" << endl + << c->name ().simple () << "_Context::" + << "get_CCM_home (" << endl + << STRS[ENV_SNGL_SRC] << ")" << endl + << STRS[EXCP_SNGL] << endl + << "{" << endl + << "return ::Components::CCMHome::_duplicate (this->home_.in ());" + << endl + << "}" << endl << endl; + + os << "CORBA::Boolean" << endl + << c->name ().simple () << "_Context::" + << "get_rollback_only (" << endl + << STRS[ENV_SNGL_SRC] << ")" << endl + << STRS[EXCP_START] << endl + << STRS[EXCP_SYS] << "," << endl + << STRS[EXCP_IS] << "))" << endl + << "{" << endl + << "ACE_THROW_RETURN (CORBA::NO_IMPLEMENT (), 0);" << endl + << "}" << endl << endl; + + os << "::Components::Transaction::UserTransaction_ptr" << endl + << c->name ().simple () << "_Context::" + << "get_user_transaction (" << endl + << STRS[ENV_SNGL_SRC] << ")" << endl + << STRS[EXCP_START] << endl + << STRS[EXCP_SYS] << "," << endl + << STRS[EXCP_IS] << "))" << endl + << "{" << endl + << "ACE_THROW_RETURN (" << endl + << "::CORBA::NO_IMPLEMENT ()," << endl + << "::Components::Transaction::UserTransaction::_nil ());" << endl + << "}" << endl << endl; + + os << "CORBA::Boolean" << endl + << c->name ().simple () << "_Context::" + << "is_caller_in_role (" << endl + << "const char *role" << endl + << STRS[ENV_SRC] << ")" << endl + << STRS[EXCP_SNGL] << endl + << "{" << endl + << "ACE_UNUSED_ARG (role);" << endl + << "ACE_THROW_RETURN (CORBA::NO_IMPLEMENT (), 0);" << endl + << "}" << endl << endl; + + os << "void" << endl + << c->name ().simple () << "_Context::" + << "set_rollback_only (" << endl + << STRS[ENV_SNGL_SRC] << ")" << endl + << STRS[EXCP_START] << endl + << STRS[EXCP_SYS] << "," << endl + << STRS[EXCP_IS] << "))" << endl + << "{" << endl + << "ACE_THROW (CORBA::NO_IMPLEMENT ());" << endl + << "}" << endl << endl; + + os << "// Operations from ::Components::SessionContext interface." + << endl << endl; + + os << "CORBA::Object_ptr" << endl + << c->name ().simple () << "_Context::" + << "get_CCM_object (" << endl + << STRS[ENV_SNGL_SRC] << ")" << endl + << STRS[EXCP_START] << endl + << STRS[EXCP_SYS] << "," << endl + << STRS[EXCP_IS] << "))" << endl + << "{" << endl + << "if (CORBA::is_nil (this->component_.in ()))" << endl + << "{" << endl + << "CORBA::Object_var obj =" << endl + << "this->container_->get_objref (" << endl + << "this->servant_" << endl + << STRS[ENV_ARG] << ");" << endl + << "ACE_CHECK_RETURN (CORBA::Object::_nil ());" << endl << endl + << "this->component_ =" << endl + << c->name () << "::_narrow (" << endl + << "obj.in ()" << endl + << STRS[ENV_ARG] << ");" << endl + << "ACE_CHECK_RETURN (CORBA::Object::_nil ());" << endl << endl + << "if (CORBA::is_nil (this->component_.in ()))" << endl + << "{" << endl + << "ACE_THROW_RETURN (" << endl + << "::CORBA::INTERNAL ()," << endl + << "::CORBA::Object::_nil ());" << endl + << "}" << endl + << "}" << endl << endl + << "return " << c->name () << "::_duplicate (" << endl + << "this->component_.in ());" << endl + << "}" << endl << endl; + + os << "// Operations for " << c->name ().simple () << " receptacles" + << " and event sources," << endl + << "// defined in " << c->name ().scope () << "::CCM_" + << c->name ().simple () << "_Context." + << endl << endl; + } + + virtual void + visit_uses_decl (UsesDeclPtr const& d) + { + os << d->type ()->name () << "_ptr" << endl + << d->scope ()->name ().simple () << "_Context::get_connection_" + << d->name ().simple () + << " (" << endl + << STRS[ENV_SNGL_SRC] << ")" << endl + << STRS[EXCP_SNGL] << endl + << "{" << endl + << "return " << d->type ()->name () << "::_duplicate (" << endl + << "this->ciao_uses_" << d->name ().simple () + << "_.in ());" << endl + << "}" << endl << endl; + + os << "void" << endl + << d->scope ()->name ().simple () << "_Context::connect_" + << d->name ().simple () << " (" << endl + << d->type ()->name () << "_ptr c" << endl + << STRS[ENV_SRC] << ")" << endl + << STRS[EXCP_START] << endl + << STRS[EXCP_SYS] << "," << endl + << STRS[EXCP_AC] << "," << endl + << STRS[EXCP_IC] << "))" << endl + << "{" << endl + << "if (! CORBA::is_nil (this->ciao_uses_" + << d->name ().simple () << "_.in ()))" << endl + << "{" << endl + << "ACE_THROW (" << STRS[EXCP_AC] << " ());" << endl + << "}" << endl << endl + << "if (CORBA::is_nil (c))" << endl + << "{" << endl + << "ACE_THROW (" << STRS[EXCP_IC] << " ());" << endl + << "}" << endl << endl + << "this->ciao_uses_" << d->name ().simple () << "_ =" << endl + << d->type ()-> name () << "::_duplicate (c);" << endl + << "}" << endl << endl; + + os << d->type ()->name () << "_ptr" << endl + << d->scope ()->name ().simple () << "_Context::disconnect_" + << d->name ().simple () << " (" << endl + << STRS[ENV_SNGL_SRC] << ")" << endl + << STRS[EXCP_START] << endl + << STRS[EXCP_SYS] << "," << endl + << STRS[EXCP_NC] << "))" << endl + << "{" << endl + << "if (CORBA::is_nil (this->ciao_uses_" + << d->name ().simple () << "_.in ()))" << endl + << "{" << endl + << "ACE_THROW_RETURN (" << endl + << STRS[EXCP_NC] << " ()," << endl + << d->type ()->name () << "::_nil ());" << endl + << "}" << endl << endl + << "return this->ciao_uses_" << d->name ().simple () + << "_._retn ();" << endl + << "}" << endl << endl; + } + + virtual void + visit_publishes_decl (PublishesDeclPtr const& d) + { + os << "void" << endl + << d->scope ()->name ().simple () << "_Context::push_" + << d->name ().simple () << " (" << endl + << d->type ()->name () << " *ev" << endl + << STRS[ENV_SRC] << ")" << endl + << STRS[EXCP_SNGL] << endl + << "{" << endl + << "ACE_Active_Map_Manager<" << d->type ()->name () + << "Consumer_var>::iterator end =" << endl + << "this->ciao_publishes_" << d->name ().simple () + << "_map_.end ();" << endl << endl + << "for (ACE_Active_Map_Manager<" << d->type ()->name () + << "Consumer_var>::iterator iter =" << endl + << "this->ciao_publishes_" << d->name ().simple () + << "_map_.begin ();" << endl + << "iter != end;" << endl + << "++iter)" << endl + << "{" << endl + << "ACE_Active_Map_Manager<" << d->type ()->name () + << "Consumer_var>::ENTRY &entry = *iter;" << endl + << d->type ()->name () << "Consumer_var c =" << endl + << d->type ()->name () << "Consumer::_narrow (" << endl + << "entry.int_id_.in ()" << endl + << STRS[ENV_ARG] << ");" << endl + << "ACE_CHECK;" << endl << endl + << "entry.int_id_->push_" << d->type ()->name ().simple () + << " (" << endl + << "ev" << endl + << STRS[ENV_ARG] << ");" << endl + << "ACE_CHECK;" << endl + << "}" << endl + << "}" << endl << endl; + + os << STRS[COMP_CK] << " *" << endl + << d->scope ()->name ().simple () << "_Context::subscribe_" + << d->name ().simple () << " (" << endl + << d->type ()->name () << "Consumer_ptr c" << endl + << STRS[ENV_SRC] << ")" << endl + << STRS[EXCP_START] << endl + << STRS[EXCP_SYS] << "," << endl + << STRS[EXCP_ECL] << "))" << endl + << "{" << endl + << "if (CORBA::is_nil (c))" << endl + << "{" << endl + << "ACE_THROW_RETURN (CORBA::BAD_PARAM (), 0);" << endl + << "}" << endl << endl + << d->type ()->name () << "Consumer_var sub =" << endl + << d->type ()->name () << "Consumer::_duplicate (c);" + << endl << endl + << "ACE_Active_Map_Manager_Key key;" << endl + << "this->ciao_publishes_" << d->name ().simple () + << "_map_.bind (sub.in (), key);" << endl << endl + << "sub._retn ();" << endl << endl + << STRS[COMP_CK] << "_var retv = " + << "new ::CIAO::Map_Key_Cookie (key);" + << endl + << "return retv._retn ();" << endl + << "}" << endl << endl; + + os << d->type ()->name () << "Consumer_ptr" << endl + << d->scope ()->name ().simple () << "_Context::unsubscribe_" + << d->name ().simple () << " (" << endl + << STRS[COMP_CK] << " *ck" << endl + << STRS[ENV_SRC] << ")" << endl + << STRS[EXCP_START] << endl + << STRS[EXCP_SYS] << "," << endl + << STRS[EXCP_IC] << "))" << endl + << "{" << endl + << d->type ()->name () << "Consumer_var retv;" << endl + << "ACE_Active_Map_Manager_Key key;" << endl << endl + << "if (ck == 0 || ::CIAO::Map_Key_Cookie::extract (ck, key) == -1)" + << endl + << "{" << endl + << "ACE_THROW_RETURN (" << endl + << STRS[EXCP_IC] << " ()," << endl + << d->type ()->name () << "Consumer::_nil ());" << endl + << "}" << endl << endl + << "if (this->ciao_publishes_" << d->name ().simple () + << "_map_.unbind (key, retv) != 0)" << endl + << "{" << endl + << "ACE_THROW_RETURN (" << endl + << STRS[EXCP_IC] << " ()," << endl + << d->type ()->name () << "Consumer::_nil ());" << endl + << "}" << endl << endl + << "return retv._retn ();" << endl + << "}" << endl << endl; + } + + virtual void + visit_emits_decl (EmitsDeclPtr const& d) + { + os << "void" << endl + << d->scope ()->name ().simple () << "_Context::push_" + << d->name ().simple () << " (" << endl + << d->type ()->name () << " *ev" << endl + << STRS[ENV_SRC] << ")" << endl + << STRS[EXCP_SNGL] << endl + << "{" << endl + << "this->ciao_emits_" << d->name ().simple () + << "_consumer_->push_" << d->name ().simple () << " (" << endl + << "ev" << endl + << STRS[ENV_ARG] << ");" << endl + << "}" << endl + << "}" << endl << endl; + + os << "void" << endl + << d->scope ()->name ().simple () << "_Context::connect_" + << d->name ().simple () << " (" << endl + << d->type ()-> name () << "Consumer_ptr c" << endl + << STRS[ENV_SRC] << ")" << endl + << STRS[EXCP_START] << endl + << STRS[EXCP_SYS] << "," << endl + << STRS[EXCP_AC] << "))" << endl + << "{" << endl + << "if (CORBA::is_nil (c))" << endl + << "{" << endl + << "ACE_THROW (CORBA::BAD_PARAM ());" << endl + << "}" << endl << endl + << "if (! CORBA::is_nil (this->ciao_emits_" << d->name ().simple () + << "_consumer_.in ()))" << endl + << "{" << endl + << "ACE_THROW (" << STRS[EXCP_AC] << " ());" << endl + << "}" << endl << endl + << "this->ciao_emits_" << d->name ().simple () + << "_consumer_ = c;" << endl + << "}" << endl << endl; + + os << d->type ()->name () << "Consumer_ptr" << endl + << d->scope ()->name ().simple () << "_Context::disconnect_" + << d->name ().simple () << " (" << endl + << STRS[ENV_SNGL_SRC] << ")" << endl + << STRS[EXCP_START] << endl + << STRS[EXCP_SYS] << "," << endl + << STRS[EXCP_NC] << "))" << endl + << "{" << endl + << "if (CORBA::is_nil (this->ciao_emits_" << d->name ().simple () + << "_consumer_.in ()))" << endl + << "{" << endl + << "ACE_THROW_RETURN (" << endl + << STRS[EXCP_NC] << " ()," << endl + << d->type ()->name () << "Consumer::_nil ());" << endl + << "}" << endl << endl + << "return this->ciao_emits_" << d->name ().simple () + << "_consumer_._retn ();" << endl + << "}" << endl << endl; + } + + virtual void + visit_component_def_post (ComponentDefPtr const& c) + { + // Close the CIAO_GLUE namespace, if we opened one. + if (c->scope ()->dynamic_type<IDL2::SyntaxTree::FileScope> () != 0) + { + os << "}" << endl; + } + + os << endl; + } + }; + + // + // Generates component servant interface definitions. + // + class ServantEmitter : public SourceEmitterBase, + public virtual Traversal::ComponentDef, + public virtual Traversal::ProvidesDecl, + public virtual Traversal::UsesDecl, + public virtual Traversal::PublishesDecl, + public virtual Traversal::ConsumesDecl, + public virtual Traversal::EmitsDecl, + public virtual Traversal::AttributeDecl + { + private: + ReturnTypeNameEmitter return_type_name_emitter_; + INArgTypeNameEmitter inarg_type_name_emitter_; + INOUTArgTypeNameEmitter inoutarg_type_name_emitter_; + OUTArgTypeNameEmitter outarg_type_name_emitter_; + + OperationEmitter operation_emitter_; + GetAttributeEmitter get_attribute_emitter_; + SetAttributeEmitter set_attribute_emitter_; + + public: + ServantEmitter (ostream& os_) + : SourceEmitterBase (os_), + return_type_name_emitter_ (os_), + inarg_type_name_emitter_ (os_), + inoutarg_type_name_emitter_ (os_), + outarg_type_name_emitter_ (os_), + operation_emitter_ (os_, + &return_type_name_emitter_, + &inarg_type_name_emitter_, + &outarg_type_name_emitter_, + &inoutarg_type_name_emitter_), + get_attribute_emitter_ (os_, + &return_type_name_emitter_), + set_attribute_emitter_ (os_, + &return_type_name_emitter_) + { + } + + virtual void + visit_component_def_pre (ComponentDefPtr const& c) + { + // If we are at file scope, we create a namespace anyway. + if (c->scope ()->dynamic_type<IDL2::SyntaxTree::FileScope> () != 0) + { + os << "namespace CIAO_GLUE" << endl + << "{" << endl; + } + + os << c->name ().simple () << "_Servant::" + << c->name ().simple () << "_Servant (" << endl + << c->name ().scope () << "::CCM_" << c->name ().simple () + << "_ptr exe," << endl + << "::Components::CCMHome_ptr h," << endl + << "::CIAO::Session_Container *c)" << endl + << ": executor_ (" << c->name ().scope () << "::CCM_" + << c->name ().simple () << "::_duplicate (exe))," << endl + << "container_ (c)" << endl + << "{" << endl + << "this->context_ = " + << "new " << c->name ().simple () << "_Context (h, c, this);" + << endl << endl + << "ACE_TRY_NEW_ENV" << endl + << "{" << endl + << "::Components::SessionComponent_var scom =" << endl + << "::Components::SessionComponent::_narrow (" << endl + << "exe" << endl + << STRS[ENV_ARG] << ");" << endl + << "ACE_TRY_CHECK;" << endl << endl + << "if (! ::CORBA::is_nil (scom.in ()))" << endl + << "{" << endl + << "scom->set_session_context (" << endl + << "this->context_" << endl + << STRS[ENV_ARG] << ");" << endl + << "}" << endl + << "}" << endl + << "ACE_CATCHANY" << endl + << "{" << endl + << "}" << endl + << "ACE_ENDTRY;" << endl + << "}" << endl << endl; + + os << c->name ().simple () << "_Servant::~" + << c->name ().simple () << "_Servant (void)" << endl + << "{" << endl + << "ACE_TRY_NEW_ENV" << endl + << "{" << endl + << "::Components::SessionComponent_var scom =" << endl + << "::Components::SessionComponent::_narrow (" << endl + << "this->executor_.in ()" << endl + << STRS[ENV_ARG] << ");" << endl + << "ACE_TRY_CHECK;" << endl << endl + << "if (! ::CORBA::is_nil (scom.in ()))" << endl + << "{" << endl + << "scom->ccm_remove (" << STRS[ENV_SNGL_ARG] << ");" << endl + << "}" << endl + << "}" << endl + << "ACE_CATCHANY" << endl + << "{" << endl + << "}" << endl + << "ACE_ENDTRY;" << endl << endl + << "this->context_->_remove_ref ();" << endl + << "}" << endl << endl; + } + + virtual void + visit_attribute_decl (AttributeDeclPtr const& a) + { + a->accept (&get_attribute_emitter_); + a->accept (&set_attribute_emitter_); + } + + virtual void + visit_provides_decl (ProvidesDeclPtr const& p) + { + os << p->type ()->name () << "_ptr" << endl + << p->scope ()->name ().simple () + << "_Servant::provide_" << p->name ().simple () << " (" << endl + << STRS[ENV_SNGL_ARG] << ")" << endl + << STRS[EXCP_SNGL] << endl + << "{" << endl + << "if (::CORBA::is_nil (this->provide_" + << p->name ().simple () << "_.in ()))" << endl + << "{" << endl + << p->name ().scope ().scope () << "::CCM_" + << p->type ()->name ().simple () + << "_var fexe =" << endl + << "this->executor_->get_" << p->name ().simple () + << " (" << STRS[ENV_SNGL_ARG] << ");" << endl + << "ACE_CHECK_RETURN (" << p->type ()->name () << "::_nil ());" + << endl << endl + << "if (::CORBA::is_nil (fexe.in ()))" << endl + << "{" << endl + << "ACE_THROW_RETURN (" << endl + << "::CORBA::INTERNAL ()," << endl + << p->type ()->name () << "::_nil ());" << endl + << "}" << endl << endl + << p->type ()->name ().simple () << "_Servant *svt =" << endl + << "new " << p->type ()->name ().simple () << "_Servant (" << endl + << "fexe.in ()," << endl + << "this->context_);" << endl + << "PortableServer::ServantBase_var safe_servant (svt);" + << endl << endl + << "::CORBA::Object_var obj =" << endl + << "this->container_->install_servant (" << endl + << "svt" << endl + << STRS[ENV_ARG] << ");" << endl + << "ACE_CHECK_RETURN (" << p->type ()->name () << "::_nil ());" + << endl << endl + << p->type ()->name () << "_var fo =" << endl + << p->type ()->name () << "::_narrow (" << endl + << "obj.in ()" << endl + << STRS[ENV_ARG] << ");" << endl + << "ACE_CHECK_RETURN (" << p->type ()->name () << "::_nil ());" + << endl << endl + << "this->provide_" << p->name ().simple () << "_ = fo;" << endl + << "}" << endl << endl + << "return " << p->type ()->name () + << "::_duplicate (this->provide_" + << p->name ().simple () << "_.in ());" << endl + << "}" << endl << endl; + } + + virtual void + visit_uses_decl (UsesDeclPtr const& p) + { + os << "void" << endl + << p->scope ()->name ().simple () << "_Servant::connect_" + << p->name ().simple () << " (" << endl + << p->type ()->name () << "_ptr c" << endl + << STRS[ENV_SRC] << ")" << endl + << STRS[EXCP_START] << endl + << STRS[EXCP_SYS] << "," << endl + << STRS[EXCP_AC] << "," << endl + << STRS[EXCP_IC] << "))" << endl + << "{" << endl + << "this->context_->connect_" << p->name ().simple () << " (" + << endl + << "c" << endl + << STRS[ENV_ARG] << ");" << endl + << "}" << endl << endl; + + os << p->type ()->name () << "_ptr" << endl + << p->scope ()->name ().simple () << "_Servant::disconnect_" + << p->name ().simple () << " (" << endl + << STRS[ENV_SNGL_SRC] << ")" << endl + << STRS[EXCP_START] << endl + << STRS[EXCP_SYS] << "," << endl + << STRS[EXCP_NC] << "))" << endl + << "{" << endl + << "return this->context_->disconnect_" << p->name ().simple () + << " (" << endl + << STRS[ENV_SNGL_ARG] << ");" << endl + << "}" << endl << endl; + + os << p->type ()->name () << "_ptr" << endl + << p->scope ()->name ().simple () + << "_Servant::get_connection_" << p->name ().simple () + << " (" << endl + << STRS[ENV_SNGL_SRC] << ")" << endl + << STRS[EXCP_SNGL] << endl + << "{" << endl + << "return this->context_->get_connection_" + << p->name ().simple () << " (" << endl + << STRS[ENV_SNGL_ARG] << ");" << endl + << "}" << endl << endl; + } + + virtual void + visit_consumes_decl (ConsumesDeclPtr const& c) + { + os << c->scope ()-> name ().simple () << "_Servant::" + << c->type ()->name ().simple () + << "Consumer_" << c->name ().simple () + << "_Servant::" << c->type ()->name ().simple () + << "Consumer_" << c->name ().simple () + << "_Servant (" << endl + << c->scope ()->name ().scope () << "::CCM_" + << c->scope ()->name ().simple () << "_ptr executor," + << endl + << c->scope ()->name ().scope () << "::CCM_" + << c->scope ()->name ().simple () + << "_Context_ptr c)" << endl + << ": executor_ (" << c->scope ()->name ().scope () + << "::CCM_" << c->scope ()->name ().simple () + << "::_duplicate (executor))," << endl + << "ctx_ (" << c->scope ()->name ().scope () + << "::CCM_" << c->scope ()->name ().simple () + << "_Context::_duplicate (c))" << endl + << "{" << endl + << "}" << endl << endl; + + os << c->scope ()-> name ().simple () << "_Servant::" + << c->type ()->name ().simple () + << "Consumer_" << c->name ().simple () + << "_Servant::~" << c->type ()->name ().simple () + << "Consumer_" << c->name ().simple () + << "_Servant (void)" << endl + << "{" << endl + << "}" << endl << endl; + + os << "CORBA::Object_ptr" << endl + << c->scope ()-> name ().simple () << "_Servant::" + << c->type ()->name ().simple () + << "Consumer_" << c->name ().simple () + << "_Servant::_get_component (" << endl + << STRS[ENV_SNGL_SRC] << ")" << endl + << STRS[EXCP_SNGL] << endl + << "{" << endl + << "return this->ctx_->get_CCM_object " + << "(" << STRS[ENV_SNGL_ARG] << ");" << endl + << "}" << endl << endl; + + os << "void" << endl + << c->scope ()-> name ().simple () << "_Servant::" + << c->type ()->name ().simple () + << "Consumer_" << c->name ().simple () + << "_Servant::push_" << c->type ()->name ().simple () + << " (" << endl + << c->type ()->name () << " *evt" << endl + << STRS[ENV_SRC] << ")" << endl + << STRS[EXCP_SNGL] << endl + << "{" << endl + << "this->executor_->push_" << c->name ().simple () + << " (" << endl + << "evt" << endl + << STRS[ENV_ARG] << ");" << endl + << "}" << endl << endl; + + os << "// Inherited from " << STRS[COMP_ECB] << "." << endl + << "void" << endl + << c->scope ()-> name ().simple () << "_Servant::" + << c->type ()->name ().simple () + << "Consumer_" << c->name ().simple () + << "_Servant::push_event (" << endl + << "::Components::EventBase *ev" << endl + << STRS[ENV_SRC] << ")" << endl + << STRS[EXCP_START] << endl + << STRS[EXCP_SYS] << "," << endl + << STRS[EXCP_BET] << "))" << endl + << "{" << endl + << c->type ()->name () << "_var ev_type =" << endl + << c->type ()->name () << "::_downcast (ev);" << endl << endl + << "if (ev_type != 0)" << endl + << "{" << endl + << "this->push_" << c->type ()->name ().simple () << " (" << endl + << "ev_type.in ()" << endl + << STRS[ENV_SNGL_ARG] << ");" << endl << endl + << "return;" << endl + << "}" << endl << endl + << "ACE_THROW (" << STRS[EXCP_BET] << " ());" << endl + << "}" << endl << endl; + + os << c->type ()->name () << "Consumer_ptr" << endl + << c->scope ()-> name ().simple () << "_Servant::" + << "get_consumer_" << c->name ().simple () << " (" << endl + << STRS[ENV_SNGL_SRC] << ")" << endl + << STRS[EXCP_SNGL] << endl + << "{" << endl + << "if (CORBA::is_nil (this->consumes_" << c->name ().simple () + << "_.in ()))" << endl + << "{" << endl + << c->scope ()-> name ().simple () << "_Servant::" + << c->type ()->name ().simple () + << "Consumer_" << c->name ().simple () + << "_Servant *svt =" << endl + << "new " << c->scope ()-> name ().simple () << "_Servant::" + << c->type ()->name ().simple () + << "Consumer_" << c->name ().simple () + << "_Servant (" << endl + << "this->executor_.in ()," << endl + << "this->context_);" << endl + << "PortableServer::ServantBase_var safe_servant (svt);" + << endl << endl + << "CORBA::Object_var obj =" << endl + << "this->container_->install_servant (" << endl + << "svt" << endl + << STRS[ENV_ARG] << ");" << endl + << "ACE_CHECK_RETURN (" + << c->type ()->name () << "Consumer::_nil ());" << endl << endl + << c->type ()->name () << "Consumer_var eco =" << endl + << c->type ()->name () << "Consumer::_narrow (" << endl + << "obj.in ()" << endl + << STRS[ENV_ARG] << ");" << endl + << "ACE_CHECK_RETURN (" + << c->type ()->name () << "Consumer::_nil ());" << endl << endl + << "this->consumes_" << c->name ().simple () << "_ = eco;" << endl + << "}" << endl << endl + << "return " << c->type ()->name () + << "Consumer::_duplicate (this->consumes_" << c->name ().simple () + << "_.in ());" << endl + << "}" << endl << endl; + } + + virtual void + visit_emits_decl (EmitsDeclPtr const& e) + { + os << "void" << endl + << e->scope ()->name ().simple () << "_Servant::connect_" + << e->name ().simple () << " (" << endl + << e->type ()->name () << "Consumer_ptr c" << endl + << STRS[ENV_SRC] << ")" << endl + << STRS[EXCP_START] << endl + << STRS[EXCP_SYS] << "," << endl + << STRS[EXCP_AC] << "))" << endl + << "{" << endl + << "this->context_->connect_" << e->name ().simple () + << " (" << endl + << "c" << endl + << STRS[ENV_ARG] << ");" << endl + << "}" << endl << endl; + + os << e->type ()->name () << "Consumer_ptr" << endl + << e->scope ()->name ().simple () << "_Servant::disconnect_" + << e->name ().simple () << " (" << endl + << STRS[ENV_SNGL_SRC] << ")" << endl + << STRS[EXCP_START] << endl + << STRS[EXCP_SYS] << "," << endl + << STRS[EXCP_NC] << "))" << endl + << "{" << endl + << "return this->context_->disconnect_" + << e->name ().simple () << " (" << endl + << STRS[ENV_SNGL_ARG] << ");" << endl + << "}" << endl << endl; + } + + virtual void + visit_publishes_decl (PublishesDeclPtr const& p) + { + os << STRS[COMP_CK] << " *" << endl + << p->scope ()->name ().simple () + << "_Servant::subscribe_" << p->name ().simple () << " (" << endl + << p->type ()->name () << "Consumer_ptr c" << endl + << STRS[ENV_SRC] << ")" << endl + << STRS[EXCP_START] << endl + << STRS[EXCP_SYS] << "," << endl + << STRS[EXCP_ECL] << "))" << endl + << "{" << endl + << "return this->context_->subscribe_" << p->name ().simple () + << " (" << endl + << "c" << endl + << STRS[ENV_ARG] << ");" << endl + << "}" << endl << endl; + + os << p->type ()->name () << "Consumer_ptr" << endl + << p->scope ()->name ().simple () + << "_Servant::unsubscribe_" << p->name ().simple () << " (" << endl + << STRS[COMP_CK] << " *ck" << endl + << STRS[ENV_SRC] << ")" << endl + << STRS[EXCP_START] << endl + << STRS[EXCP_SYS] << "," << endl + << STRS[EXCP_IC] << "))" << endl + << "{" << endl + << "return this->context_->unsubscribe_" + << p->name ().simple () << " (" << endl + << "ck" << endl + << STRS[ENV_ARG] << ");" << endl + << "}" << endl << endl; + } + + virtual void + visit_component_def_post (ComponentDefPtr const& c) + { + os << "// Operations for Navigation interface." << endl << endl; + + os << "CORBA::Object_ptr" << endl + << c->name ().simple () << "_Servant::provide_facet (" << endl + << "const char *name" << endl + << STRS[ENV_SRC] << ")" << endl + << STRS[EXCP_START] << endl + << STRS[EXCP_SYS] << "," << endl + << STRS[EXCP_IN] << "))" << endl + << "{" << endl + << "if (name == 0)" << endl + << "{" << endl + << "ACE_THROW_RETURN (" << endl + << "::CORBA::BAD_PARAM ()," << endl + << "::CORBA::Object::_nil ());" << endl + << "}" << endl << endl; + + ProvidesFacetEmitter provides_facet_emitter (os); + c->accept (&provides_facet_emitter); + + os << "ACE_THROW_RETURN (" << endl + << STRS[EXCP_IN] << " ()," << endl + << "::CORBA::Object::_nil ());" << endl + << "}" << endl << endl; + + os << "::Components::FacetDescriptions *" << endl + << c->name ().simple () << "_Servant::get_all_facets (" << endl + << STRS[ENV_SNGL_SRC] << ")" << endl + << STRS[EXCP_SNGL] << endl + << "{" << endl + << "ACE_THROW_RETURN (::CORBA::NO_IMPLEMENT (), 0);" << endl + << "}" << endl << endl; + + os << "::Components::FacetDescriptions *" << endl + << c->name ().simple () << "_Servant::get_named_facets (" << endl + << "const " << STRS[COMP_NAMES] << endl + << STRS[ENV_SRC] << ")" << endl + << STRS[EXCP_START] << endl + << STRS[EXCP_SYS] << "," << endl + << STRS[EXCP_IN] << "))" << endl + << "{" << endl + << "ACE_THROW_RETURN (::CORBA::NO_IMPLEMENT (), 0);" << endl + << "}" << endl << endl; + + os << "CORBA::Boolean" << endl + << c->name ().simple () << "_Servant::same_component (" << endl + << "CORBA::Object_ptr object_ref" << endl + << STRS[ENV_SRC] << ")" << endl + << STRS[EXCP_SNGL] << endl + << "{" << endl + << "if (::CORBA::is_nil (object_ref))" << endl + << "{" << endl + << "ACE_THROW_RETURN (::CORBA::BAD_PARAM (), 0);" << endl + << "}" << endl << endl + << "::CORBA::Object_var the_other =" << endl + << "object_ref->_get_component (" << STRS[ENV_SNGL_ARG] << ");" + << endl + << "ACE_CHECK_RETURN (0);" << endl << endl + << "::CORBA::Object_var me =" << endl + << "this->context_->get_CCM_object (" << STRS[ENV_SNGL_ARG] << ");" + << endl + << "ACE_CHECK_RETURN (0);" << endl << endl + << "return me->_is_equivalent (" << endl + << "the_other.in ()" << endl + << STRS[ENV_ARG] << ");" << endl + << "}" << endl << endl; + + os << "// Operations for Receptacles interface." << endl << endl; + + os << STRS[COMP_CK] << " *" << endl + << c->name ().simple () << "_Servant::connect (" << endl + << "const char *name," << endl + << "::CORBA::Object_ptr connection" << endl + << STRS[ENV_SRC] << ")" << endl + << STRS[EXCP_START] << endl + << STRS[EXCP_SYS] << "," << endl + << STRS[EXCP_IN] << "," << endl + << STRS[EXCP_IC] << "," << endl + << STRS[EXCP_AC] << "," << endl + << STRS[EXCP_ECL] << "))" << endl + << "{" << endl + << "if (name == 0)" << endl + << "{" << endl + << "ACE_THROW_RETURN (" << STRS[EXCP_IN] << " (), 0);" << endl + << "}" << endl << endl; + + ConnectEmitter connect_emitter (os); + c->accept (&connect_emitter); + + os << "ACE_THROW_RETURN (" << STRS[EXCP_IN] << " (), 0);" << endl + << "}" << endl << endl; + + os << "CORBA::Object_ptr" << endl + << c->name ().simple () << "_Servant::disconnect (" << endl + << "const char *name," << endl + << STRS[COMP_CK] << " *ck" << endl + << STRS[ENV_SRC] << ")" << endl + << STRS[EXCP_START] << endl + << STRS[EXCP_SYS] << "," << endl + << STRS[EXCP_IN] << "," << endl + << STRS[EXCP_IC] << "," << endl + << STRS[EXCP_CR] << "," << endl + << STRS[EXCP_NC] << "))" << endl + << "{" << endl + << "if (name == 0)" << endl + << "{" << endl + << "ACE_THROW_RETURN (" << endl + << STRS[EXCP_IN] << " ()," << endl + << "::CORBA::Object::_nil ());" << endl + << "}" << endl << endl; + + DisconnectEmitter disconnect_emitter (os); + c->accept (&disconnect_emitter); + + os << "ACE_THROW_RETURN (" << endl + << STRS[EXCP_IN] << " ()," << endl + << "::CORBA::Object::_nil ());" << endl + << "}" << endl << endl; + + os << "::Components::ConnectionDescriptions *" << endl + << c->name ().simple () << "_Servant::get_connections (" + << endl + << "const char *name" << endl + << STRS[ENV_SRC] << ")" << endl + << STRS[EXCP_START] << endl + << STRS[EXCP_SYS] << "," << endl + << STRS[EXCP_IN] << "))" << endl + << "{" << endl + << "ACE_THROW_RETURN (::CORBA::NO_IMPLEMENT (), 0);" << endl + << "}" << endl << endl; + + os << "::Components::ReceptacleDescriptions *" << endl + << c->name ().simple () << "_Servant::get_all_receptacles (" + << endl + << STRS[ENV_SNGL_SRC] << ")" << endl + << STRS[EXCP_SNGL] << endl + << "{" << endl + << "ACE_THROW_RETURN (::CORBA::NO_IMPLEMENT (), 0);" << endl + << "}" << endl << endl; + + os << "::Components::ReceptacleDescriptions *" << endl + << c->name ().simple () << "_Servant::get_named_receptacles (" + << endl + << "const " << STRS[COMP_NAMES] << endl + << STRS[ENV_SRC] << ")" << endl + << STRS[EXCP_START] << endl + << STRS[EXCP_SYS] << "," << endl + << STRS[EXCP_IN] << "))" << endl + << "{" << endl + << "ACE_THROW_RETURN (::CORBA::NO_IMPLEMENT (), 0);" << endl + << "}" << endl << endl; + + os << "// Operations for Events interface." << endl << endl; + + os << STRS[COMP_ECB] << "_ptr" << endl + << c->name ().simple () << "_Servant::get_consumer (" << endl + << "const char *sink_name" << endl + << STRS[ENV_SRC] << ")" << endl + << STRS[EXCP_START] << endl + << STRS[EXCP_SYS] << "," << endl + << STRS[EXCP_IN] << "))" << endl + << "{" << endl + << "if (sink_name == 0)" << endl + << "{" << endl + << "ACE_THROW_RETURN (" << endl + << STRS[EXCP_IN] << " ()," << endl + << STRS[COMP_ECB] << "::_nil ());" << endl + << "}" << endl << endl; + + GetConsumerEmitter get_consumer_emitter (os); + c->accept (&get_consumer_emitter); + + os << "ACE_THROW_RETURN (" << endl + << STRS[EXCP_IN] << " ()," << endl + << STRS[COMP_ECB] << "::_nil ());" << endl + << "}" << endl << endl; + + os << STRS[COMP_CK] << " *" << endl + << c->name ().simple () << "_Servant::subscribe (" << endl + << "const char *publisher_name," << endl + << STRS[COMP_ECB] << "_ptr subscribe" << endl + << STRS[ENV_SRC] << ")" << endl + << STRS[EXCP_START] << endl + << STRS[EXCP_SYS] << "," << endl + << STRS[EXCP_IN] << "," << endl + << STRS[EXCP_IC] << "," << endl + << STRS[EXCP_ECL] << "))" << endl + << "{" << endl + << "if (publisher_name == 0)" << endl + << "{" << endl + << "ACE_THROW_RETURN (" << STRS[EXCP_IN] << " (), 0);" + << endl + << "}" << endl << endl; + + SubscribeEmitter subscribe_emitter (os); + c->accept (&subscribe_emitter); + + os << "ACE_THROW_RETURN (" << STRS[EXCP_IN] << " (), 0);" << endl + << "}" << endl << endl; + + os << STRS[COMP_ECB] << "_ptr" << endl + << c->name ().simple () << "_Servant::unsubscribe (" + << endl + << "const char *publisher_name," << endl + << STRS[COMP_CK] << " *ck" << endl + << STRS[ENV_SRC] << ")" << endl + << STRS[EXCP_START] << endl + << STRS[EXCP_SYS] << "," << endl + << STRS[EXCP_IN] << "," << endl + << STRS[EXCP_IC] << "))" << endl + << "{" << endl + << "if (publisher_name == 0)" << endl + << "{" << endl + << "ACE_THROW_RETURN (" << endl + << STRS[EXCP_IN] << " ()," << endl + << STRS[COMP_ECB] << "::_nil ());" << endl + << "}" << endl << endl; + + UnsubscribeEmitter unsubscribe_emitter (os); + c->accept (&unsubscribe_emitter); + + os << "ACE_THROW_RETURN (" << endl + << STRS[EXCP_IN] << " ()," << endl + << STRS[COMP_ECB] << "::_nil ());" << endl + << "}" << endl << endl; + + os << "void" << endl + << c->name ().simple () << "_Servant::connect_consumer (" + << endl + << "const char *emitter_name," << endl + << STRS[COMP_ECB] << "_ptr consumer" << endl + << STRS[ENV_SRC] << ")" << endl + << STRS[EXCP_START] << endl + << STRS[EXCP_SYS] << "," << endl + << STRS[EXCP_IN] << "," << endl + << STRS[EXCP_AC] << "," << endl + << STRS[EXCP_IC] << "))" << endl + << "{" << endl + << "ACE_THROW (::CORBA::NO_IMPLEMENT ());" << endl + << "}" << endl << endl; + + os << STRS[COMP_ECB] << "_ptr" << endl + << c->name ().simple () << "_Servant::disconnect_consumer (" + << endl + << "const char *source_name" << endl + << STRS[ENV_SRC] << ")" << endl + << STRS[EXCP_START] << endl + << STRS[EXCP_SYS] << "," << endl + << STRS[EXCP_IN] << "," << endl + << STRS[EXCP_NC] << "))" << endl + << "{" << endl + << "ACE_THROW_RETURN (::CORBA::NO_IMPLEMENT (), 0);" << endl + << "}" << endl << endl; + + os << "::Components::ConsumerDescriptions *" << endl + << c->name ().simple () << "_Servant::get_all_consumers (" + << endl + << STRS[ENV_SNGL_SRC] << ")" << endl + << STRS[EXCP_SNGL] << endl + << "{" << endl + << "ACE_THROW_RETURN (::CORBA::NO_IMPLEMENT (), 0);" << endl + << "}" << endl << endl; + + os << "::Components::ConsumerDescriptions *" << endl + << c->name ().simple () << "_Servant::get_named_consumers (" + << endl + << "const " << STRS[COMP_NAMES] << endl + << STRS[ENV_SRC] << ")" << endl + << STRS[EXCP_START] << endl + << STRS[EXCP_SYS] << "," << endl + << STRS[EXCP_IN] << "))" << endl + << "{" << endl + << "ACE_THROW_RETURN (::CORBA::NO_IMPLEMENT (), 0);" << endl + << "}" << endl << endl; + + os << "::Components::EmitterDescriptions *" << endl + << c->name ().simple () << "_Servant::get_all_emitters (" + << endl + << STRS[ENV_SNGL_SRC] << ")" << endl + << STRS[EXCP_SNGL] << endl + << "{" << endl + << "ACE_THROW_RETURN (::CORBA::NO_IMPLEMENT (), 0);" << endl + << "}" << endl << endl; + + os << "::Components::EmitterDescriptions *" << endl + << c->name ().simple () << "_Servant::get_named_emitters (" + << endl + << "const " << STRS[COMP_NAMES] << endl + << STRS[ENV_SRC] << ")" << endl + << STRS[EXCP_START] << endl + << STRS[EXCP_SYS] << "," << endl + << STRS[EXCP_IN] << "))" << endl + << "{" << endl + << "ACE_THROW_RETURN (::CORBA::NO_IMPLEMENT (), 0);" << endl + << "}" << endl << endl; + + os << "::Components::PublisherDescriptions *" << endl + << c->name ().simple () << "_Servant::get_all_publishers (" + << endl + << STRS[ENV_SNGL_SRC] << ")" << endl + << STRS[EXCP_SNGL] << endl + << "{" << endl + << "ACE_THROW_RETURN (::CORBA::NO_IMPLEMENT (), 0);" << endl + << "}" << endl << endl; + + os << "::Components::PublisherDescriptions *" << endl + << c->name ().simple () << "_Servant::get_named_publishers (" + << endl + << "const " << STRS[COMP_NAMES] << endl + << STRS[ENV_SRC] << ")" << endl + << STRS[EXCP_START] << endl + << STRS[EXCP_SYS] << "," << endl + << STRS[EXCP_IN] << "))" << endl + << "{" << endl + << "ACE_THROW_RETURN (::CORBA::NO_IMPLEMENT (), 0);" << endl + << "}" << endl << endl; + + os << "// Operations for CCMObject interface." << endl << endl; + + os << "CORBA::IRObject_ptr" << endl + << c->name ().simple () << "_Servant::get_component_def (" << endl + << STRS[ENV_SNGL_SRC] << ")" << endl + << STRS[EXCP_SNGL] << endl + << "{" << endl + << "ACE_THROW_RETURN (" << endl + << "::CORBA::NO_IMPLEMENT ()," << endl + << "::CORBA::IRObject::_nil ());" << endl + << "}" << endl << endl; + + os << "::Components::CCMHome_ptr" << endl + << c->name ().simple () << "_Servant::get_ccm_home (" << endl + << STRS[ENV_SNGL_SRC] << ")" << endl + << STRS[EXCP_SNGL] << endl + << "{" << endl + << "return this->context_->get_CCM_home " + << "(ACE_ENV_SINGLE_ARG_PARAMETER);" << endl + << "}" << endl << endl; + + os << "::Components::PrimaryKeyBase *" << endl + << c->name ().simple () << "_Servant::get_primary_key (" << endl + << STRS[ENV_SNGL_SRC] << ")" << endl + << STRS[EXCP_START] << endl + << STRS[EXCP_SYS] << "," << endl + << STRS[EXCP_NKA] << "))" << endl + << "{" << endl + << "ACE_THROW_RETURN (" << STRS[EXCP_NKA] << " (), 0);" << endl + << "}" << endl << endl; + + os << "void" << endl + << c->name ().simple () + << "_Servant::configuration_complete (" << endl + << STRS[ENV_SNGL_SRC] << ")" << endl + << STRS[EXCP_START] << endl + << STRS[EXCP_SYS] << "," << endl + << STRS[EXCP_ICF] << "))" << endl + << "{" << endl + << "// CIAO to-do" << endl + << "}" << endl << endl; + + os << "void" << endl + << c->name ().simple () << "_Servant::remove (" << endl + << STRS[ENV_SNGL_SRC] << ")" << endl + << STRS[EXCP_START] << endl + << STRS[EXCP_SYS] << "," << endl + << STRS[EXCP_RF] << "))" << endl + << "{" << endl + << "// CIAO to-do" << endl + << "}" << endl << endl; + + os << "::Components::ComponentPortDescription *" << endl + << c->name ().simple () << "_Servant::get_all_ports (" << endl + << STRS[ENV_SNGL_SRC] << ")" << endl + << STRS[EXCP_SNGL] << endl + << "{" << endl + << "::Components::ComponentPortDescription_var retv =" << endl + << "new OBV_Components::ComponentPortDescription;" << endl << endl + << "::Components::FacetDescriptions_var facets_desc =" << endl + << "this->get_all_facets (" << STRS[ENV_SNGL_ARG] << ");" << endl + << "ACE_CHECK_RETURN (0);" << endl << endl + << "::Components::ReceptacleDescriptions_var receptacle_desc =" + << endl + << "this->get_all_receptacles (" << STRS[ENV_SNGL_ARG] << ");" + << endl + << "ACE_CHECK_RETURN (0);" << endl << endl + << "::Components::ConsumerDescriptions_var consumer_desc =" << endl + << "this->get_all_consumers (" << STRS[ENV_SNGL_ARG] << ");" + << endl + << "ACE_CHECK_RETURN (0);" << endl << endl + << "::Components::EmitterDescriptions_var emitter_desc =" << endl + << "this->get_all_emitters (" << STRS[ENV_SNGL_ARG] << ");" << endl + << "ACE_CHECK_RETURN (0);" << endl << endl + << "::Components::PublisherDescriptions_var publisher_desc =" + << endl + << "this->get_all_publishers (" << STRS[ENV_SNGL_ARG] << ");" + << endl + << "ACE_CHECK_RETURN (0);" << endl << endl + << "retv->facets (facets_desc.in ());" << endl + << "retv->receptacles (receptacle_desc.in ());" << endl + << "retv->consumers (consumer_desc.in ());" << endl + << "retv->emitters (emitter_desc.in ());" << endl + << "retv->publishers (publisher_desc.in ());" << endl << endl + << "return retv._retn ();" << endl + << "}" << endl << endl; + + os << "CORBA::Object_ptr" << endl + << c->name ().simple () << "_Servant::_get_component (" << endl + << STRS[ENV_SNGL_SRC] << ")" << endl + << STRS[EXCP_SNGL] << endl + << "{" << endl + << "::Components::SessionContext_var sc =" << endl + << "::Components::SessionContext::_narrow (" << endl + << "this->context_" << endl + << STRS[ENV_ARG] << ");" << endl + << "ACE_CHECK_RETURN (::CORBA::Object::_nil ());" << endl << endl + << "if (! ::CORBA::is_nil (sc.in ()))" << endl + << "{" << endl + << "return sc->get_CCM_object (" << STRS[ENV_SNGL_ARG] << ");" + << endl + << "}" << endl << endl + << "::Components::EntityContext_var ec =" << endl + << "::Components::EntityContext::_narrow (" << endl + << "this->context_" << endl + << STRS[ENV_ARG] << ");" << endl + << "ACE_CHECK_RETURN (::CORBA::Object::_nil ());" << endl << endl + << "if (! ::CORBA::is_nil (ec.in ()))" << endl + << "{" << endl + << "return ec->get_CCM_object (" << STRS[ENV_SNGL_ARG] << ");" + << endl + << "}" << endl << endl + << "ACE_THROW_RETURN (" << endl + << "::CORBA::INTERNAL ()," << endl + << "::CORBA::Object::_nil ());" << endl + << "}" << endl << endl; + + os << "// CIAO-specific operations." << endl << endl; + + os << "void" << endl + << c->name ().simple () << "_Servant::_ciao_activate (" << endl + << STRS[ENV_SNGL_SRC] << ")" << endl + << STRS[EXCP_SNGL] << endl + << "{" << endl + << "::Components::SessionComponent_var temp =" << endl + << "::Components::SessionComponent::_narrow (" << endl + << "this->executor_.in ()" << endl + << STRS[ENV_ARG] << ");" << endl + << "ACE_CHECK;" << endl << endl + << "if (! ::CORBA::is_nil (temp.in ()))" << endl + << "{" << endl + << "temp->ccm_activate (" << STRS[ENV_SNGL_ARG] << ");" << endl + << "}" << endl + << "}" << endl << endl; + + os << "void" << endl + << c->name ().simple () << "_Servant::_ciao_passivate (" << endl + << STRS[ENV_SNGL_SRC] << ")" << endl + << STRS[EXCP_SNGL] << endl + << "{" << endl + << "::Components::SessionComponent_var temp =" << endl + << "::Components::SessionComponent::_narrow (" << endl + << "this->executor_.in ()" << endl + << STRS[ENV_ARG] << ");" << endl + << "ACE_CHECK;" << endl << endl + << "if (! ::CORBA::is_nil (temp.in ()))" << endl + << "{" << endl + << "temp->ccm_passivate (" << STRS[ENV_SNGL_ARG] << ");" << endl + << "}" << endl + << "}" << endl << endl; + + os << "// Supported operations." << endl << endl; + + SupportedOperationEmitter supported_operation_emitter ( + os, + &return_type_name_emitter_, + &inarg_type_name_emitter_, + &outarg_type_name_emitter_, + &inoutarg_type_name_emitter_, + c->name ().simple ()); + + // @@@ (JP) Must include ancestors' supported interfaces as well. + for (SyntaxTree::ComponentDef::Iterator i = c->supports_begin (); + i != c->supports_end (); + i++) + { + i->resolve ()->accept (&supported_operation_emitter); + } + + // Close the CIAO_GLUE namespace, if we opened one. + if (c->scope ()->dynamic_type<IDL2::SyntaxTree::FileScope> () != 0) + { + os << "}" << endl; + } + + os << endl; + } + }; + + // + // Generates the component home servant interface. + // + class HomeEmitter : public SourceEmitterBase, + public virtual Traversal::HomeDef, + public virtual Traversal::OperationDecl, + public virtual Traversal::AttributeDecl, + public virtual Traversal::HomeFactoryDecl + { + private: + ReturnTypeNameEmitter return_type_name_emitter_; + INArgTypeNameEmitter inarg_type_name_emitter_; + INOUTArgTypeNameEmitter inoutarg_type_name_emitter_; + OUTArgTypeNameEmitter outarg_type_name_emitter_; + + OperationEmitter operation_emitter_; + FactoryEmitter factory_emitter_; + + public: + HomeEmitter (ostream& os_) + : SourceEmitterBase (os_), + return_type_name_emitter_ (os_), + inarg_type_name_emitter_ (os_), + inoutarg_type_name_emitter_ (os_), + outarg_type_name_emitter_ (os_), + operation_emitter_ (os_, + &return_type_name_emitter_, + &inarg_type_name_emitter_, + &outarg_type_name_emitter_, + &inoutarg_type_name_emitter_), + factory_emitter_ (os_, + &inarg_type_name_emitter_) + { + } + + virtual void + visit_home_def_pre (HomeDefPtr const& h) + { + // If we are at file scope, we create a namespace anyway. + if (h->scope ()->dynamic_type<IDL2::SyntaxTree::FileScope> () != 0) + { + os << STRS[GLUE_NS] << endl + << "{" << endl; + } + + os << h->name ().simple () << "_Servant::" + << h->name ().simple () << "_Servant (" << endl + << h->name ().scope () << "::CCM_" << h->name ().simple () + << "_ptr exe," << endl + << "::CIAO::Session_Container *c)" << endl + << ": executor_ (" << h->name ().scope () << "::CCM_" + << h->name ().simple () << "::_duplicate (exe))," << endl + << "container_ (c)" << endl + << "{" << endl + << "}" << endl << endl; + + os << h->name ().simple () << "_Servant::~" + << h->name ().simple () << "_Servant (void)" << endl + << "{" << endl + << "}" << endl << endl; + } + + virtual void + visit_operation_decl (OperationDeclPtr const& d) + { + os << "// Home factory and other operations." << endl << endl; + + d->accept (&operation_emitter_); + } + + virtual void + visit_home_factory_decl (HomeFactoryDeclPtr const& f) + { + f->accept (&factory_emitter_); + } + + virtual void + visit_attribute_decl (AttributeDeclPtr const& a) + { + // TODO + } + + virtual void + visit_home_def_post (HomeDefPtr const& h) + { + + os << "// Operations for keyless home interface." << endl << endl; + + os << "::Components::CCMObject_ptr" << endl + << h->name ().simple () << "_Servant::create_component (" << endl + << STRS[ENV_SNGL_SRC] << ")" << endl + << STRS[EXCP_START] << endl + << STRS[EXCP_SYS] << "," << endl + << "::Components::CreateFailure))" << endl + << "{" << endl + << "return this->create (" << STRS[ENV_SNGL_ARG] << ");" << endl + << "}" << endl << endl; + + os << "// Operations for implicit home interface." << endl << endl; + + os << h->manages ()->name () << "_ptr" << endl + << h->name ().simple () << "_Servant::create (" << endl + << STRS[ENV_SNGL_SRC] << ")" << endl + << STRS[EXCP_START] << endl + << STRS[EXCP_SYS] << "," << endl + << "::Components::CreateFailure))" << endl + << "{" << endl + << "if (this->executor_.in () == 0)" << endl + << "{" << endl + << "ACE_THROW_RETURN (" << endl + << "::CORBA::INTERNAL ()," << endl + << h->manages ()->name () << "::_nil ());" << endl + << "}" << endl << endl + << "Components::EnterpriseComponent_var _ciao_ec =" << endl + << "this->executor_->create (" << STRS[ENV_SNGL_ARG] << ");" + << endl + << "ACE_CHECK_RETURN (" << h->manages ()->name () + << "::_nil ());" << endl << endl + << h->manages ()->name ().scope () << "::CCM_" + << h->manages ()->name ().simple () << "_var _ciao_comp =" << endl + << h->manages ()->name ().scope () << "::CCM_" + << h->manages ()->name ().simple () << "::_narrow (" << endl + << "_ciao_ec.in ()" << endl + << STRS[ENV_ARG] << ");" << endl + << "ACE_CHECK_RETURN (" << h->manages ()->name () + << "::_nil ());" << endl << endl + << "return this->_ciao_activate_component (" << endl + << "_ciao_comp.in ()" << endl + << STRS[ENV_ARG] << ");" << endl + << "}" << endl << endl; + + os << "// Operations for CCMHome interface." << endl << endl; + + os << "::CORBA::IRObject_ptr" << endl + << h->name ().simple () << "_Servant::get_component_def (" << endl + << STRS[ENV_SNGL_SRC] << ")" << endl + << STRS[EXCP_SNGL] << endl + << "{" << endl + << "ACE_THROW_RETURN (" << endl + << "::CORBA::NO_IMPLEMENT ()," << endl + << "::CORBA::IRObject::_nil ());" << endl + << "}" << endl << endl; + + os << "::CORBA::IRObject_ptr" << endl + << h->name ().simple () << "_Servant::get_home_def (" << endl + << STRS[ENV_SNGL_SRC] << ")" << endl + << STRS[EXCP_SNGL] << endl + << "{" << endl + << "ACE_THROW_RETURN (" << endl + << "::CORBA::NO_IMPLEMENT ()," << endl + << "::CORBA::IRObject::_nil ());" << endl + << "}" << endl << endl; + + os << "void" << endl + << h->name ().simple () << "_Servant::remove_component (" << endl + << "::Components::CCMObject_ptr comp" << endl + << STRS[ENV_SRC] << ")" << endl + << STRS[EXCP_START] << endl + << STRS[EXCP_SYS] << "," << endl + << STRS[EXCP_RF] << "))" << endl + << "{" << endl + << h->manages ()->name () << "_var _ciao_comp =" << endl + << h->manages ()->name () << "::_narrow (" << endl + << "comp" << endl + << STRS[ENV_ARG] << ");" << endl + << "ACE_CHECK;" << endl << endl + << "if (CORBA::is_nil (_ciao_comp.in ()))" << endl + << "{" << endl + << "ACE_THROW (CORBA::INTERNAL ());" << endl + << "}" << endl << endl + << "_ciao_comp->remove (" << STRS[ENV_ARG] << ");" << endl + << "ACE_CHECK;" << endl << endl + << "this->_ciao_passivate_component (" << endl + << "_ciao_comp.in ()" << endl + << STRS[ENV_ARG] << ");" << endl + << "}" << endl << endl; + + os << "// CIAO-specific operations." << endl << endl; + + os << h->manages ()->name () << "_ptr" << endl + << h->name ().simple () + << "_Servant::_ciao_activate_component (" << endl + << h->manages ()->name ().scope () << "::CCM_" + << h->manages ()->name ().simple () << "_ptr exe" << endl + << STRS[ENV_SRC] << ")" << endl + << STRS[EXCP_SNGL] << endl + << "{" << endl + << "::CORBA::Object_var hobj =" << endl + << "this->container_->get_objref (" << endl + << "this" << endl + << STRS[ENV_ARG] << ");" << endl + << "ACE_CHECK_RETURN (" << h->manages ()->name () << "::_nil ());" + << endl << endl + << "::Components::CCMHome_var home =" << endl + << "::Components::CCMHome::_narrow (" << endl + << "hobj" << endl + << STRS[ENV_ARG] << ");" << endl + << "ACE_CHECK_RETURN (" << h->manages ()->name () << "::_nil ());" + << endl << endl + << h->manages ()->name ().simple () << "_Servant *svt =" << endl + << "new " << h->manages ()->name ().simple () << "_Servant (" + << endl + << "exe," << endl + << "home.in ()," << endl + << "this->container_);" << endl << endl + << "PortableServer::ServantBase_var safe (svt);" << endl + << "PortableServer::ObjectId_var oid;" << endl << endl + << "CORBA::Object_var objref =" << endl + << "this->container_->install_component (" << endl + << "svt," << endl + << "oid.out ()" << endl + << STRS[ENV_ARG] << ");" << endl + << "ACE_CHECK_RETURN (" << h->manages ()->name () << "::_nil ());" + << endl << endl + << "svt->_ciao_activate (" << STRS[ENV_SNGL_ARG] << ");" << endl + << "ACE_CHECK_RETURN (" << h->manages ()->name () << "::_nil ());" + << endl << endl + << h->manages ()->name () << "_var ho =" << endl + << h->manages ()->name () << "::_narrow (" << endl + << "objref.in ()" << endl + << STRS[ENV_ARG] << ");" << endl + << "ACE_CHECK_RETURN (" << h->manages ()->name () << "::_nil ());" + << endl << endl + << "if (this->component_map_.bind (oid.in (), svt) == 0)" << endl + << "{" << endl + << "safe._retn ();" << endl + << "}" << endl << endl + << "return ho._retn ();" << endl + << "}" << endl << endl; + + os << "void" << endl + << h->name ().simple () + << "_Servant::_ciao_passivate_component (" << endl + << h->manages ()->name () << "_ptr comp" << endl + << STRS[ENV_SNGL_SRC] << ")" << endl + << STRS[EXCP_SNGL] << endl + << "{" << endl + << "PortableServer::ObjectId_var oid;" << endl << endl + << "this->container_->uninstall_component (" << endl + << "comp," << endl + << "oid.out ()" << endl + << STRS[ENV_ARG] << ");" << endl + << "ACE_CHECK;" << endl << endl + << h->manages ()->name ().simple () << "_Servant *servant = 0;" + << endl << endl + << "if (this->component_map_.unbind (oid.in (), servant) == 0)" + << endl + << "{" << endl + << "PortableServer::ServantBase_var safe (servant);" << endl + << "servant->_ciao_passivate (" << STRS[ENV_SNGL_ARG] << ");" + << endl + << "ACE_CHECK;" << endl + << "}" << endl + << "}" << endl << endl; + + os << "// Supported operations." << endl << endl; + + SupportedOperationEmitter supported_operation_emitter ( + os, + &return_type_name_emitter_, + &inarg_type_name_emitter_, + &outarg_type_name_emitter_, + &inoutarg_type_name_emitter_, + h->name ().simple ()); + + // @@@ (JP) Must include ancestors' supported interfaces as well. + for (SyntaxTree::HomeDef::Iterator i = h->supports_begin (); + i != h->supports_end (); + i++) + { + i->resolve ()->accept (&supported_operation_emitter); + } + + // Close the CIAO_GLUE namespace, if we opened one. + if (h->scope ()->dynamic_type<IDL2::SyntaxTree::FileScope> () != 0) + { + os << "}" << endl; + } + + os << endl; + } + }; +} + +SourceEmitterBase::SourceEmitterBase (ostream& os_) + : os (os_) +{ +} + +// =========================================================== + +ServantSourceEmitter::ServantSourceEmitter ( + ostream& os_, + CommandLine const& cl, + UnconstrainedInterfaceDefSet const& interface_set, + ComponentDefSet const& component_set, + HomeDefSet const& home_set) + : SourceEmitterBase (os_), + cl_ (cl), + component_set_ (component_set), + home_set_ (home_set), + interface_set_ (interface_set) +{ +} + +bool +ServantSourceEmitter::contains_element (ModulePtr const& m) const +{ + for (UnconstrainedInterfaceDefSet::const_iterator i = + interface_set_.begin (); + i != interface_set_.end (); + i++) + { + if (m->order ().suborder ((*i)->order ())) return true; + } + + for (ComponentDefSet::const_iterator i = component_set_.begin (); + i != component_set_.end (); + i++) + { + if (m->order ().suborder ((*i)->order ())) return true; + } + + for (HomeDefSet::const_iterator i = home_set_.begin (); + i != home_set_.end (); + i++) + { + if (m->order ().suborder ((*i)->order ())) return true; + } + + return false; +} + +void +ServantSourceEmitter::visit_translation_unit_pre (TranslationUnitPtr const& u) +{ + os << COPYRIGHT << endl << endl; + + fs::path file_path = u->principal_translation_region ()->file_path (); + string file_name (""); + + if (! file_path.empty ()) + { + file_name = file_path.leaf (); + } + + string file_suffix = cl_.get_value ("hdr-file-suffix", + "_svnt.h"); + + file_name = regex::perl_s (file_name, + "/^(.*?)(\\.(idl|cidl))?$/$1" + + file_suffix + + "/"); + + os << "#include \"" << file_name << "\"" << endl + << "#include \"Cookies.h\"" << endl << endl; +} + +void +ServantSourceEmitter::visit_module_pre (ModulePtr const& m) +{ + if (contains_element (m)) + { + os << STRS[GLUE_NS] << "_" << m->name ().simple () << endl + << "{" << endl; + } +} + +void +ServantSourceEmitter::visit_unconstrained_interface_def ( + UnconstrainedInterfaceDefPtr const& i) +{ + if (interface_set_.find (i) != interface_set_.end ()) + { + FacetEmitter facet_emitter (os); + i->accept (&facet_emitter); + } +} + +void +ServantSourceEmitter::visit_component_def (ComponentDefPtr const& c) +{ + { + ContextEmitter context_emitter (os); + c->accept (&context_emitter); + } + + { + ServantEmitter servant_emitter (os); + c->accept (&servant_emitter); + } +} + +void +ServantSourceEmitter::visit_home_def (HomeDefPtr const& h) +{ + HomeEmitter home_emitter (os); + h->accept (&home_emitter); +} + +void +ServantSourceEmitter::visit_module_post (ModulePtr const& m) +{ + if (contains_element (m)) + { + os << "}" << endl << endl; + } +} + +// =========================================================== + +ServantSourceFinalizingEmitter::ServantSourceFinalizingEmitter ( + ostream& os_, + string export_macro) + : SourceEmitterBase (os_), + export_macro_ (export_macro) +{ +} + +void +ServantSourceFinalizingEmitter::visit_home_def (HomeDefPtr const& h) +{ + bool global = + (h->scope ()->dynamic_type<IDL2::SyntaxTree::FileScope> () != 0); + + os << "extern \"C\" " << export_macro_ << " ::PortableServer::Servant" + << endl + << "create" << h->name ().simple () << "_Servant (" << endl + << "::Components::HomeExecutorBase_ptr p," << endl + << "CIAO::Session_Container *c" << endl + << STRS[ENV_SRC] << ")" << endl + << "{" << endl + << "if (p == 0)" << endl + << "{" << endl + << "return 0;" << endl + << "}" << endl << endl + << h->name ().scope () << "::CCM_" + << h->name ().simple () << "_var x =" << endl + << h->name ().scope () << "::CCM_" << h->name ().simple () + << "::_narrow (" << endl + << "p" << endl + << STRS[ENV_ARG] << ");" << endl + << "ACE_CHECK_RETURN (0);" << endl << endl + << "if (::CORBA::is_nil (x.in ()))" << endl + << "{" << endl + << "return 0;" << endl + << "}" << endl << endl + << "return new" << endl + << "::CIAO_GLUE"; + + if (!global) os << "_" << h->name ().scope ().simple (); + + os << "::" << h->name ().simple () << "_Servant (" << endl + << "x.in ()," << endl + << "c);" << endl + << "}" << endl << endl; +} diff --git a/TAO/CIAO/CIDLC/ServantSourceGenerator.hpp b/TAO/CIAO/CIDLC/ServantSourceGenerator.hpp new file mode 100644 index 00000000000..6d7635f5594 --- /dev/null +++ b/TAO/CIAO/CIDLC/ServantSourceGenerator.hpp @@ -0,0 +1,96 @@ +// $Id$ +#ifndef SERVANT_SOURCE_GENERATOR_HPP +#define SERVANT_SOURCE_GENERATOR_HPP + +#include "CCF/CodeGenerationKit/CommandLine.hpp" + +#include "CCF/CIDL/CIDL_SyntaxTree.hpp" +#include "CCF/CIDL/CIDL_Traversal.hpp" + +using std::ostream; + +using namespace CIDL; +using namespace CIDL::SyntaxTree; + +// SourceEmitterBase is a base class that holds the ostream member +// common to every other class in this file. +// +class SourceEmitterBase +{ +protected: + SourceEmitterBase (ostream&); + + ostream& os; +}; + +// Emitter generates the servant source mapping for declarations collected +// by Collector. Note that the original structure of modules is preserved. +// +class ServantSourceEmitter + : public SourceEmitterBase, + public virtual Traversal::TranslationUnit, + public virtual Traversal::TranslationRegion, + public virtual Traversal::FileScope, + public virtual Traversal::Module, + public virtual Traversal::UnconstrainedInterfaceDef, + public virtual Traversal::ConcreteEventTypeDef, + public virtual Traversal::ComponentDef, + public virtual Traversal::HomeDef +{ +public: + ServantSourceEmitter (ostream& os_, + CommandLine const& cl, + UnconstrainedInterfaceDefSet const& interface_set, + ComponentDefSet const& component_set, + HomeDefSet const& home_set); + + bool + contains_element (ModulePtr const& m) const; + + virtual void + visit_translation_unit_pre (TranslationUnitPtr const&); + + virtual void + visit_module_pre (ModulePtr const& m); + + virtual void + visit_unconstrained_interface_def ( + UnconstrainedInterfaceDefPtr const& i); + + virtual void + visit_component_def (ComponentDefPtr const& c); + + virtual void + visit_home_def (HomeDefPtr const& h); + + virtual void + visit_module_post (ModulePtr const& m); + +private: + CommandLine const& cl_; + + ComponentDefSet const& component_set_; + HomeDefSet const& home_set_; + UnconstrainedInterfaceDefSet const& interface_set_; +}; + +class ServantSourceFinalizingEmitter + : public SourceEmitterBase, + public virtual Traversal::TranslationUnit, + public virtual Traversal::TranslationRegion, + public virtual Traversal::FileScope, + public virtual Traversal::Module, + public virtual Traversal::HomeDef +{ +public: + ServantSourceFinalizingEmitter (ostream& os_, + string export_macro); + + virtual void + visit_home_def (HomeDefPtr const& h); + +private: + string export_macro_; +}; + +#endif // SERVANT_SOURCE_GENERATOR_HPP diff --git a/TAO/CIAO/CIDLC/Version b/TAO/CIAO/CIDLC/Version new file mode 100644 index 00000000000..99d85ecdbb7 --- /dev/null +++ b/TAO/CIAO/CIDLC/Version @@ -0,0 +1 @@ +0.0.6
\ No newline at end of file diff --git a/TAO/CIAO/CIDLC/cidlc.cpp b/TAO/CIAO/CIDLC/cidlc.cpp new file mode 100644 index 00000000000..a0ca2a61b58 --- /dev/null +++ b/TAO/CIAO/CIDLC/cidlc.cpp @@ -0,0 +1,231 @@ +// $Id$ +#include "CCF/CompilerElements/FileSystem.hpp" + +#include "CCF/CodeGenerationKit/CommandLine.hpp" +#include "CCF/CodeGenerationKit/CommandLineParser.hpp" +#include "CCF/CodeGenerationKit/CommandLineDescriptor.hpp" + +#include "CCF/CIDL/CIDL_LexicalAnalyzer.hpp" +#include "CCF/CIDL/CIDL_Parser.hpp" +#include "CCF/CIDL/CIDL_SyntaxTree.hpp" +#include "CCF/CIDL/CIDL_SemanticActionImpl.hpp" + +#include "ExecutorMappingGenerator.hpp" +#include "ServantGenerator.hpp" + +#include "CCF/CompilerElements/TokenStream.hpp" +#include "CCF/CompilerElements/Preprocessor.hpp" + +#include <iostream> + +using std::cerr; +using std::endl; + +int main (int argc, char* argv[]) +{ + using namespace IDL2::SyntaxTree; + + try + { + // Parsing command line options and arguments + // + // + CommandLine cl; + + if (!parse (argc, argv, cl)) + { + cerr << "command line syntax error" << endl; + cerr << "try " << argv[0] << " --help for usage information" << endl; + return -1; + } + + ExecutorMappingGenerator lem_gen; + + if (cl.get_value ("help", false) || cl.get_value ("help-html", false)) + { + CL::Description d (argv[0]); + + lem_gen.options (d); + + d.add_option (CL::OptionDescription ( + "preprocess-only", + "Run preprocessor only and output result to stdout.", + true)); + + d.add_option (CL::OptionDescription ( + "help", + "Display usage information and exit.", + true)); + + d.add_option (CL::OptionDescription ( + "help-html", + "Dump usage information in html format and exit.", + true)); + + d.add_argument ("cidl file"); + + if (cl.get_value ("help-html", false)) CL::print_html (cerr, d); + else CL::print_text (cerr, d); + + return 0; + } + + + fs::ifstream ifs; + ifs.exceptions (ios_base::badbit | ios_base::failbit); + + fs::path file_path; + + CommandLine::ArgumentIterator i = cl.argument_begin (); + + if (i != cl.argument_end ()) + { + try + { + file_path = fs::path (*i, fs::native); + ifs.open (file_path, std::ios_base::out); + } + catch (fs::filesystem_error const&) + { + cerr << *i << ": error: unable to open in read mode" << endl; + return -1; + } + catch (ios_base::failure const&) + { + cerr << *i << ": error: unable to open in read mode" << endl; + return -1; + } + } + + //@@ for some reason ifs throws exception if I don't reset it to + // original state. It probably has something to do with call to + // get after eof. + ifs.exceptions (ios_base::iostate (0)); + + std::istream& is = ifs.is_open () + ? static_cast<std::istream&> (ifs) + : static_cast<std::istream&> (std::cin); + + CCF::InputStreamAdapter isa (is); + CCF::Preprocessor pp (isa); + + if (cl.get_value ("preprocess-only", false)) + { + while (true) + { + CCF::Preprocessor::int_type i = pp.next (); + + if (pp.eos (i)) break; + + CCF::Preprocessor::char_type c = pp.to_char_type (i); + + std::cout << c ; + } + return 0; + } + + + CIDL::LexicalAnalyzer lexer (pp); + TokenStream token_stream; + + //@@ bad token comparison + for (TokenPtr token = lexer.next (); + token.in () != lexer.eos.in (); + token = lexer.next ()) + { + token_stream.push_back (token); + } + + if (token_stream.size () == 0) + { + cerr << "no tokens produced so nothing to parse" << endl; + return 0; + } + + TranslationUnitPtr unit (new TranslationUnit); + + //----------------------------------------------------------------- + //@@ exeprimental code + + //Create .builtin region + { + TranslationRegionPtr builtin ( + new TranslationRegion (unit->table (), + unit->create_order ())); + unit->insert (builtin); + + // Inject built-in types into the file scope of this + // translation region + + ScopePtr s = builtin->scope (); + + // Note: I know what I am doing here (and if you don't then + // read MExC++#17 again). + + s->insert (BuiltInTypeDefPtr (new Void (s))); + s->insert (BuiltInTypeDefPtr (new Long (s))); + s->insert (BuiltInTypeDefPtr (new Boolean (s))); + s->insert (BuiltInTypeDefPtr (new String (s))); + } + + //@@ This should be in IDL3 or even CIDL part I just need + // a mechanism to create them in proper order. + { + TranslationRegionPtr builtin ( + new ImpliedIncludeTranslationRegion (fs::path ("Components.idl"), + unit->table (), + unit->create_order ())); + unit->insert (builtin); + + ScopePtr fs = builtin->scope (); + ModulePtr m (new SyntaxTree::Module (SimpleName("Components"), fs)); + fs->insert (m); + + LocalInterfaceDefPtr i ( + new LocalInterfaceDef (SimpleName ("EnterpriseComponent"), + m, + ScopedNameSet ())); + + m->insert (i); + } + + TranslationRegionPtr tr ( + new PrincipalTranslationRegion (file_path, + unit->table (), + unit->create_order ())); + unit->insert (tr); + + CIDL::SemanticActionFactoryImpl action_factory (tr); + + //----------------------------------------------------------------- + + CIDL::Parser parser (lexer, action_factory); + + bool result = Details::parse (token_stream.begin (), + token_stream.end (), + parser.start ()); + + if (!result) return -1; + + // Generate executor mapping + + { + lem_gen.generate (cl, unit); + } + + // Generate servant code + { + ServantGenerator gen (cl); + gen.generate (unit); + } + + } + catch (Declaration::NotInScope const&) + { + cerr << "exception: " << "Declaration::NotInScope" << endl; + } + catch (...) + { + cerr << "exception: " << "unknow" << endl; + } +} |