diff options
129 files changed, 11978 insertions, 8418 deletions
diff --git a/TAO/TAO_IDL/be/be_codegen.cpp b/TAO/TAO_IDL/be/be_codegen.cpp index 0ac952b9054..6d9c929ce44 100644 --- a/TAO/TAO_IDL/be/be_codegen.cpp +++ b/TAO/TAO_IDL/be/be_codegen.cpp @@ -828,8 +828,8 @@ TAO_CodeGen::start_anyop_source (const char *fname) << be_global->be_get_client_hdr_fname (1) << "\""; - this->gen_standard_include (this->anyop_source_, - "tao/Typecode.h"); + + this->gen_typecode_includes (this->anyop_source_); return 0; } @@ -1420,10 +1420,16 @@ TAO_CodeGen::gen_stub_hdr_includes (void) // If not included here, it will appear in *C.cpp, if TCs not suppressed. this->gen_cond_file_include ( idl_global->typecode_seen_, - "tao/Typecode.h", + "tao/TypeCode.h", this->client_header_ ); + this->gen_cond_file_include ( + idl_global->any_seen_ + | idl_global->typecode_seen_, + "tao/TypeCode_Constants.h", + this->client_header_); + // This is true if we have an 'any' in the IDL file. // If not included here, it will appear in *C.cpp, if Anys not suppressed. this->gen_cond_file_include ( @@ -1555,8 +1561,7 @@ TAO_CodeGen::gen_stub_src_includes (void) || (!idl_global->typecode_seen_ && !be_global->gen_anyop_files ()))) { - this->gen_standard_include (this->client_stubs_, - "tao/Typecode.h"); + this->gen_typecode_includes (this->client_stubs_); } // The UserException::_tao_{en,de}code() methods can throw a @@ -1572,7 +1577,6 @@ TAO_CodeGen::gen_stub_src_includes (void) "tao/SystemException.h"); } - // Includes whatever Any template classes that may be needed. this->gen_any_file_includes (); @@ -1661,7 +1665,7 @@ TAO_CodeGen::gen_skel_src_includes (void) this->gen_standard_include (this->server_skeletons_, "tao/Object_T.h"); this->gen_standard_include (this->server_skeletons_, - "tao/Typecode.h"); + "tao/TypeCode.h"); this->gen_standard_include (this->server_skeletons_, "tao/DynamicC.h"); this->gen_standard_include (this->server_skeletons_, @@ -1982,3 +1986,62 @@ TAO_CodeGen::gen_cond_file_include (bool condition_green, filepath); } } + +void +TAO_CodeGen::gen_typecode_includes (TAO_OutStream * stream) +{ +// this->gen_standard_include (stream, +// "tao/TypeCode.h"); + + + + this->gen_standard_include (stream, + "tao/Null_RefCount_Policy.h"); + + this->gen_standard_include (stream, + "tao/TypeCode_Constants.h"); + + // Just assume we're going to need alias TypeCodes since there is + // currently no alias_seen_ or typedef_seen_ flag in idl_global. + this->gen_standard_include (stream, + "tao/Alias_TypeCode.h"); + + this->gen_cond_file_include (idl_global->enum_seen_, + "tao/TypeCode_Non_Default_Case.h", + stream); + + this->gen_cond_file_include (idl_global->enum_seen_, + "tao/Enum_TypeCode.h", + stream); + + this->gen_cond_file_include (idl_global->interface_seen_, +// idl_global->abstract_iface_seen_ +// | idl_global->non_local_iface_seen_ +// | idl_global->local_iface_seen_ +// | idl_global->base_object_seen_, + "tao/Objref_TypeCode.h", + stream); + + this->gen_cond_file_include (idl_global->seq_seen_, + "tao/Sequence_TypeCode.h", + stream); + + this->gen_cond_file_include (idl_global->string_seen_, + "tao/String_TypeCode.h", + stream); + + this->gen_cond_file_include ( + idl_global->exception_seen_ + | idl_global->fixed_size_arg_seen_ // Could be a struct + | idl_global->var_size_arg_seen_, // Could be a struct + "tao/Struct_TypeCode.h", + stream); + + this->gen_cond_file_include (idl_global->union_seen_, + "tao/Union_TypeCode.h", + stream); + + this->gen_cond_file_include (idl_global->valuetype_seen_, + "tao/Value_TypeCode.h", + stream); +} diff --git a/TAO/TAO_IDL/be/be_sequence.cpp b/TAO/TAO_IDL/be/be_sequence.cpp index 4626a99936f..baa84866259 100644 --- a/TAO/TAO_IDL/be/be_sequence.cpp +++ b/TAO/TAO_IDL/be/be_sequence.cpp @@ -697,6 +697,48 @@ be_sequence::field_node (be_field *node) this->field_node_ = node; } +// Overriden method. +void +be_sequence::compute_tc_name (void) +{ + // Sequence TypeCodes can only be accessed through an alias + // TypeCode. Generate a TypeCode name that is meant for internal + // use alone. + +// Identifier * tao_id = 0; +// ACE_NEW (tao_id, +// Identifier ("TAO")); + + Identifier * tao_id = 0; + ACE_NEW (tao_id, + Identifier ("")); + + ACE_NEW (this->tc_name_, + UTL_ScopedName (tao_id, + 0)); + + char bound[30] = { 0 }; + + ACE_OS::sprintf (bound, + "_%u", + this->max_size ()->ev ()->u.ulval); + + ACE_CString local_tc_name = + ACE_CString (this->flat_name ()) + + ACE_CString (bound); + + Identifier * id = 0; + ACE_NEW (id, + Identifier (local_tc_name.c_str ())); + + UTL_ScopedName * conc_name = 0; + ACE_NEW (conc_name, + UTL_ScopedName (id, + 0)); + + this->tc_name_->nconc (conc_name); +} + const char * be_sequence::smart_fwd_helper_name (AST_Decl *ctx_scope, be_type *elem) diff --git a/TAO/TAO_IDL/be/be_string.cpp b/TAO/TAO_IDL/be/be_string.cpp index c431bb52b1e..84424cdc35e 100644 --- a/TAO/TAO_IDL/be/be_string.cpp +++ b/TAO/TAO_IDL/be/be_string.cpp @@ -42,8 +42,8 @@ be_string::be_string (void) } be_string::be_string (AST_Decl::NodeType nt, - UTL_ScopedName *n, - AST_Expression *v, + UTL_ScopedName * n, + AST_Expression * v, long width) : COMMON_Base (), AST_Decl (nt, @@ -67,18 +67,62 @@ be_string::be_string (AST_Decl::NodeType nt, void be_string::compute_tc_name (void) { - // Start with the head as the CORBA namespace. - Identifier *corba_id = 0; - ACE_NEW (corba_id, - Identifier ("CORBA")); + Identifier * id = 0; - ACE_NEW (this->tc_name_, - UTL_ScopedName (corba_id, - 0)); + AST_Expression zero (static_cast<unsigned long> (0)); + + if (*this->max_size () == &zero) + { + // If the string is unbounded, use the string TypeCode + // constants. + + // Start with the head as the CORBA namespace. + Identifier * corba_id = 0; + ACE_NEW (corba_id, + Identifier ("CORBA")); + + ACE_NEW (this->tc_name_, + UTL_ScopedName (corba_id, + 0)); + + ACE_NEW (id, + Identifier (this->width () == 1 + ? "_tc_string" + : "_tc_wstring")); + } + else + { + // We have a bounded string. Generate a TypeCode name that is + // meant for internal use alone. + +// Identifier * tao_id = 0; +// ACE_NEW (tao_id, +// Identifier ("TAO")); + + Identifier * tao_id = 0; + ACE_NEW (tao_id, + Identifier ("")); + + ACE_NEW (this->tc_name_, + UTL_ScopedName (tao_id, + 0)); + +// char bound[30] = { 0 }; + +// ACE_OS::sprintf (bound, +// "_%u", +// this->max_size ()->ev ()->u.ulval); + +// ACE_CString local_tc_name = +// ACE_CString (this->width () == 1 +// ? "_tc_string" +// : "_tc_wstring") +// + ACE_CString (bound); + + ACE_NEW (id, + Identifier (this->flat_name ())); - Identifier *id = 0; - ACE_NEW (id, - Identifier ("_tc_string")); + } UTL_ScopedName *conc_name = 0; ACE_NEW (conc_name, @@ -89,7 +133,7 @@ be_string::compute_tc_name (void) } int -be_string::accept (be_visitor *visitor) +be_string::accept (be_visitor * visitor) { return visitor->visit_string (this); } diff --git a/TAO/TAO_IDL/be/be_valuetype.cpp b/TAO/TAO_IDL/be/be_valuetype.cpp index 6a60be80ff6..07ecc3c5502 100644 --- a/TAO/TAO_IDL/be/be_valuetype.cpp +++ b/TAO/TAO_IDL/be/be_valuetype.cpp @@ -223,8 +223,8 @@ be_valuetype::determine_factory_style (void) // Initialize an iterator to iterate thru our scope // Continue until each element is visited. for (UTL_ScopeActiveIterator si (this, - UTL_Scope::IK_decls); - !si.is_done (); + UTL_Scope::IK_decls); + !si.is_done (); si.next()) { AST_Decl *d = si.item (); @@ -284,8 +284,8 @@ be_valuetype::have_operation (void) // Initialize an iterator to iterate thru our scope // Continue until each element is checked. for (UTL_ScopeActiveIterator si (this, - UTL_Scope::IK_decls); - !si.is_done (); + UTL_Scope::IK_decls); + !si.is_done (); si.next()) { AST_Decl *d = si.item (); @@ -340,7 +340,7 @@ be_valuetype::have_operation (void) if (intf != 0) { - have_operation = be_valuetype::have_supported_op (intf); + have_operation = be_valuetype::have_supported_op (intf); } } } @@ -352,39 +352,38 @@ idl_bool be_valuetype::have_supported_op (be_interface * node) { - idl_bool have_supported_op = 0; + idl_bool have_supported_op = 0; if (node->nmembers () == 0) { return I_FALSE; } - // Initialize an iterator for supported interface elements - for (UTL_ScopeActiveIterator si (node, UTL_Scope::IK_decls); + // Initialize an iterator for supported interface elements + for (UTL_ScopeActiveIterator si (node, UTL_Scope::IK_decls); si.is_done (); si.next()) - { - AST_Decl *d = si.item (); - - if (!d) - { - ACE_ERROR_RETURN ((LM_ERROR, - "(%N:%l) be_valuetype::" - "have_supported_op" - "bad node in this scope\n"), - 0); + { + AST_Decl *d = si.item (); - } + if (!d) + { + ACE_ERROR_RETURN ((LM_ERROR, + "(%N:%l) be_valuetype::" + "have_supported_op" + "bad node in this scope\n"), + 0); + } - AST_Decl::NodeType nt = d->node_type (); + AST_Decl::NodeType nt = d->node_type (); // Check the type of each element in the supported interface - if (nt == AST_Decl::NT_op || nt == AST_Decl::NT_attr) - { - have_supported_op = 1; - break; - } - } // end for loop + if (nt == AST_Decl::NT_op || nt == AST_Decl::NT_attr) + { + have_supported_op = 1; + break; + } + } // end for loop if (! have_supported_op) { @@ -628,7 +627,7 @@ idl_bool be_valuetype::in_recursion (ACE_Unbounded_Queue<AST_Type *> &list) { list.enqueue_tail (this); - + for (UTL_ScopeActiveIterator si (this, UTL_Scope::IK_decls); !si.is_done (); si.next()) diff --git a/TAO/TAO_IDL/be/be_visitor_enum/cdr_op_ch.cpp b/TAO/TAO_IDL/be/be_visitor_enum/cdr_op_ch.cpp index dd7dc2169d0..1321507ad7c 100644 --- a/TAO/TAO_IDL/be/be_visitor_enum/cdr_op_ch.cpp +++ b/TAO/TAO_IDL/be/be_visitor_enum/cdr_op_ch.cpp @@ -51,11 +51,9 @@ be_visitor_enum_cdr_op_ch::visit_enum (be_enum *node) // generate the CDR << and >> operators *os << be_global->stub_export_macro () << " CORBA::Boolean" - << " operator<< (TAO_OutputCDR &, const " << node->name () - << " &);" << be_nl; + << " operator<< (TAO_OutputCDR &, " << node->name () << ");" << be_nl; *os << be_global->stub_export_macro () << " CORBA::Boolean" - << " operator>> (TAO_InputCDR &, " - << node->name () << " &);"; + << " operator>> (TAO_InputCDR &, " << node->name () << " &);"; node->cli_hdr_cdr_op_gen (1); return 0; diff --git a/TAO/TAO_IDL/be/be_visitor_enum/cdr_op_cs.cpp b/TAO/TAO_IDL/be/be_visitor_enum/cdr_op_cs.cpp index a1c2aab2b3a..744e28ed970 100644 --- a/TAO/TAO_IDL/be/be_visitor_enum/cdr_op_cs.cpp +++ b/TAO/TAO_IDL/be/be_visitor_enum/cdr_op_cs.cpp @@ -50,24 +50,25 @@ be_visitor_enum_cdr_op_cs::visit_enum (be_enum *node) *os << be_nl << be_nl << "// TAO_IDL - Generated from" << be_nl << "// " << __FILE__ << ":" << __LINE__ << be_nl << be_nl; - *os << "CORBA::Boolean operator<< (TAO_OutputCDR &strm, " - << "const " << node->name () << " &_tao_enumval)" << be_nl + *os << "CORBA::Boolean operator<< (TAO_OutputCDR & strm, " + << node->name () << " _tao_enumerator)" << be_nl << "{" << be_idt_nl - << "CORBA::ULong _tao_temp = _tao_enumval;" << be_nl - << "return strm << _tao_temp;" << be_uidt_nl + << "return strm << static_cast<CORBA::ULong> (_tao_enumerator);" + << be_uidt_nl << "}" << be_nl << be_nl; - *os << "CORBA::Boolean operator>> (TAO_InputCDR &strm, " - << node->name () << " &_tao_enumval)" << be_nl + *os << "CORBA::Boolean operator>> (TAO_InputCDR & strm, " + << node->name () << " & _tao_enumerator)" << be_nl << "{" << be_idt_nl << "CORBA::ULong _tao_temp = 0;" << be_nl - << "CORBA::Boolean _tao_result = strm >> _tao_temp;" << be_nl << be_nl - << "if (_tao_result == 1)" << be_idt_nl + << "CORBA::Boolean const _tao_success = strm >> _tao_temp;" << be_nl + << be_nl + << "if (_tao_success)" << be_idt_nl << "{" << be_idt_nl - << "_tao_enumval = static_cast<" << node->name () + << "_tao_enumerator = static_cast<" << node->name () << "> (_tao_temp);" << be_uidt_nl << "}" << be_uidt_nl << be_nl - << "return _tao_result;" << be_uidt_nl + << "return _tao_success;" << be_uidt_nl << "}"; node->cli_stub_cdr_op_gen (I_TRUE); diff --git a/TAO/TAO_IDL/be/be_visitor_enum/enum_cs.cpp b/TAO/TAO_IDL/be/be_visitor_enum/enum_cs.cpp index 0bb8eb73e98..3bd120f3687 100644 --- a/TAO/TAO_IDL/be/be_visitor_enum/enum_cs.cpp +++ b/TAO/TAO_IDL/be/be_visitor_enum/enum_cs.cpp @@ -18,10 +18,10 @@ // // ============================================================================ -#include "be_visitor_typecode/typecode_defn.h" +#include "be_visitor_typecode/enum_typecode.h" -ACE_RCSID (be_visitor_enum, - enum_cs, +ACE_RCSID (be_visitor_enum, + enum_cs, "$Id$") @@ -43,24 +43,24 @@ be_visitor_enum_cs::~be_visitor_enum_cs (void) int be_visitor_enum_cs::visit_enum (be_enum *node) { - if (node->cli_stub_gen () + if (node->cli_stub_gen () || node->imported ()) { - return 0; + return 0; } if (be_global->tc_support ()) { be_visitor_context ctx (*this->ctx_); - ctx.sub_state (TAO_CodeGen::TAO_TC_DEFN_TYPECODE); - be_visitor_typecode_defn visitor (&ctx); + // ctx.sub_state (TAO_CodeGen::TAO_TC_DEFN_TYPECODE); + TAO::be_visitor_enum_typecode visitor (&ctx); - if (node->accept (&visitor) == -1) + if (visitor.visit_enum (node) == -1) { ACE_ERROR_RETURN ((LM_ERROR, "(%N:%l) be_visitor_enum_cs::" "visit_enum - " - "TypeCode definition failed\n"), + "TypeCode definition failed\n"), -1); } } diff --git a/TAO/TAO_IDL/be/be_visitor_exception.cpp b/TAO/TAO_IDL/be/be_visitor_exception.cpp index acbbc850b2e..c02bbbcf791 100644 --- a/TAO/TAO_IDL/be/be_visitor_exception.cpp +++ b/TAO/TAO_IDL/be/be_visitor_exception.cpp @@ -38,6 +38,7 @@ #include "be_visitor_exception.h" #include "be_visitor_context.h" #include "be_visitor_field.h" +#include "be_visitor_typecode.h" #include "ace/Log_Msg.h" #include "be_visitor_exception/exception.cpp" @@ -51,6 +52,6 @@ #include "be_visitor_exception/cdr_op_ch.cpp" #include "be_visitor_exception/cdr_op_cs.cpp" -ACE_RCSID (be, - be_visitor_exception, +ACE_RCSID (be, + be_visitor_exception, "$Id$") diff --git a/TAO/TAO_IDL/be/be_visitor_exception/exception_ch.cpp b/TAO/TAO_IDL/be/be_visitor_exception/exception_ch.cpp index fa4befa74ca..045dfb74283 100644 --- a/TAO/TAO_IDL/be/be_visitor_exception/exception_ch.cpp +++ b/TAO/TAO_IDL/be/be_visitor_exception/exception_ch.cpp @@ -129,7 +129,7 @@ int be_visitor_exception_ch::visit_exception (be_exception *node) if (be_global->tc_support ()) { *os << be_nl << be_nl - << "virtual CORBA::TypeCode_ptr _type (void) const;"; + << "virtual CORBA::TypeCode_ptr _tao_type (void) const;"; } *os << be_uidt_nl << "};"; diff --git a/TAO/TAO_IDL/be/be_visitor_exception/exception_cs.cpp b/TAO/TAO_IDL/be/be_visitor_exception/exception_cs.cpp index 57f95a097d5..f3573348085 100644 --- a/TAO/TAO_IDL/be/be_visitor_exception/exception_cs.cpp +++ b/TAO/TAO_IDL/be/be_visitor_exception/exception_cs.cpp @@ -329,7 +329,7 @@ int be_visitor_exception_cs::visit_exception (be_exception *node) { *os << "// TAO extension - the virtual _type method." << be_nl; *os << "CORBA::TypeCode_ptr " << node->name () - << "::_type (void) const" << be_nl; + << "::_tao_type (void) const" << be_nl; *os << "{" << be_idt_nl; *os << "return ::" << node->tc_name () << ";" << be_uidt_nl; *os << "}"; @@ -338,10 +338,12 @@ int be_visitor_exception_cs::visit_exception (be_exception *node) if (be_global->tc_support ()) { ctx = *this->ctx_; - ctx.sub_state (TAO_CodeGen::TAO_TC_DEFN_TYPECODE); - be_visitor_typecode_defn visitor (&ctx); + // ctx.sub_state (TAO_CodeGen::TAO_TC_DEFN_TYPECODE); + TAO::be_visitor_struct_typecode visitor ( + &ctx, + true /* An exception TypeCode */); - if (node->accept (&visitor) == -1) + if (visitor.visit_structure (node) == -1) { ACE_ERROR_RETURN ((LM_ERROR, "(%N:%l) be_visitor_exception_cs::" diff --git a/TAO/TAO_IDL/be/be_visitor_interface/interface_cs.cpp b/TAO/TAO_IDL/be/be_visitor_interface/interface_cs.cpp index 72a65046da0..4a3c95b8eff 100644 --- a/TAO/TAO_IDL/be/be_visitor_interface/interface_cs.cpp +++ b/TAO/TAO_IDL/be/be_visitor_interface/interface_cs.cpp @@ -491,9 +491,10 @@ be_visitor_interface_cs::visit_interface (be_interface *node) if (be_global->tc_support ()) { + be_visitor_context ctx = *this->ctx_; - ctx.sub_state (TAO_CodeGen::TAO_TC_DEFN_TYPECODE); - be_visitor_typecode_defn tc_visitor (&ctx); + // ctx.sub_state (TAO_CodeGen::TAO_TC_DEFN_TYPECODE); + TAO::be_visitor_objref_typecode tc_visitor (&ctx); if (node->accept (&tc_visitor) == -1) { diff --git a/TAO/TAO_IDL/be/be_visitor_structure/structure_cs.cpp b/TAO/TAO_IDL/be/be_visitor_structure/structure_cs.cpp index 93262de456e..678603637f4 100644 --- a/TAO/TAO_IDL/be/be_visitor_structure/structure_cs.cpp +++ b/TAO/TAO_IDL/be/be_visitor_structure/structure_cs.cpp @@ -46,8 +46,10 @@ be_visitor_structure_cs::visit_structure (be_structure *node) if (be_global->tc_support ()) { be_visitor_context ctx (*this->ctx_); - ctx.sub_state (TAO_CodeGen::TAO_TC_DEFN_TYPECODE); - be_visitor_typecode_defn visitor (&ctx); + // ctx.sub_state (TAO_CodeGen::TAO_TC_DEFN_TYPECODE); + TAO::be_visitor_struct_typecode visitor ( + &ctx, + false /* Not an exception TypeCode */); if (visitor.visit_structure (node) == -1) { diff --git a/TAO/TAO_IDL/be/be_visitor_typecode.cpp b/TAO/TAO_IDL/be/be_visitor_typecode.cpp index 25fef2fdded..f4bf6396eb0 100644 --- a/TAO/TAO_IDL/be/be_visitor_typecode.cpp +++ b/TAO/TAO_IDL/be/be_visitor_typecode.cpp @@ -25,6 +25,7 @@ #include "be_field.h" #include "be_interface.h" #include "be_component.h" +#include "be_home.h" #include "be_module.h" #include "be_predefined_type.h" #include "be_sequence.h" @@ -47,7 +48,14 @@ #include "be_visitor_typecode/typecode_decl.cpp" #include "be_visitor_typecode/typecode_defn.cpp" -ACE_RCSID (be, - be_visitor_typecode, - "$Id$") +#include "be_visitor_typecode/alias_typecode.cpp" +#include "be_visitor_typecode/enum_typecode.cpp" +#include "be_visitor_typecode/objref_typecode.cpp" +#include "be_visitor_typecode/struct_typecode.cpp" +#include "be_visitor_typecode/union_typecode.cpp" +#include "be_visitor_typecode/value_typecode.cpp" + +ACE_RCSID (be, + be_visitor_typecode, + "$Id$") diff --git a/TAO/TAO_IDL/be/be_visitor_typecode/alias_typecode.cpp b/TAO/TAO_IDL/be/be_visitor_typecode/alias_typecode.cpp new file mode 100644 index 00000000000..e6c3ecb3016 --- /dev/null +++ b/TAO/TAO_IDL/be/be_visitor_typecode/alias_typecode.cpp @@ -0,0 +1,62 @@ +// -*- C++ -*- + +//============================================================================= +/** + * @file alias_typecode.cpp + * + * $Id$ + * + * Alias (typedef) TypeCode generation visitor. + * + * @author Ossama Othman <ossama@dre.vanderbilt.edu> + */ +//============================================================================= + + +TAO::be_visitor_alias_typecode::be_visitor_alias_typecode ( + be_visitor_context * ctx) + : be_visitor_typecode_defn (ctx) +{ +} + +int +TAO::be_visitor_alias_typecode::visit_typedef (be_typedef * node) +{ + be_type * const base = be_type::narrow_from_decl (node->base_type ()); + + TAO_OutStream & os = *this->ctx_->stream (); + + os << be_nl << be_nl + << "// TAO_IDL - Generated from" << be_nl + << "// " << __FILE__ << ":" << __LINE__ << be_nl << be_nl; + + // generate typecode for the base type + this->ctx_->sub_state (TAO_CodeGen::TAO_TC_DEFN_TYPECODE_NESTED); + + if (!base || base->accept (this) == -1) + { + ACE_ERROR_RETURN ((LM_ERROR, + ACE_TEXT ("(%N:%l) be_visitor_alias_typecode") + ACE_TEXT ("::visit_typedef) - ") + ACE_TEXT ("failed to generate base typecode\n")), + -1); + } + + // Generate the alias TypeCode instantiation. + os + << "static TAO::TypeCode::Alias<char const *," << be_nl + << " TAO::Null_RefCount_Policy>" + << be_idt_nl + << "_tao_tc_" << node->flat_name () << " (" << be_idt_nl + << "\"" << node->repoID () << "\"," << be_nl + << "\"" << node->original_local_name () << "\"," << be_nl + << "&"; + + int const success = this->gen_base_typecode_name (base); + ACE_ASSERT (success == 0); + + os << ");" << be_uidt_nl + << be_uidt_nl; + + return this->gen_typecode_ptr (node); +} diff --git a/TAO/TAO_IDL/be/be_visitor_typecode/enum_typecode.cpp b/TAO/TAO_IDL/be/be_visitor_typecode/enum_typecode.cpp new file mode 100644 index 00000000000..efec4e5fa9f --- /dev/null +++ b/TAO/TAO_IDL/be/be_visitor_typecode/enum_typecode.cpp @@ -0,0 +1,95 @@ +// -*- C++ -*- + +//============================================================================= +/** + * @file enum_typecode.cpp + * + * $Id$ + * + * Enumeration TypeCode generation visitor. + * + * @author Ossama Othman <ossama@dre.vanderbilt.edu> + */ +//============================================================================= + + +#include "utl_scope.h" + +#include <string> + + +TAO::be_visitor_enum_typecode::be_visitor_enum_typecode ( + be_visitor_context * ctx) + : be_visitor_typecode_defn (ctx) +{ +} + +int +TAO::be_visitor_enum_typecode::visit_enum (be_enum * node) +{ + TAO_OutStream & os = *this->ctx_->stream (); + + os << be_nl << be_nl + << "// TAO_IDL - Generated from" << be_nl + << "// " << __FILE__ << ":" << __LINE__ << be_nl << be_nl; + + + std::string const enumerators_name (std::string ("_tao_enumerators_") + + node->flat_name ()); + + // Generate array containing enum field characteristics. + os << "static TAO::TypeCode::Enumerator<char const *> const " + << enumerators_name.c_str () + << "[] =" << be_idt_nl + << "{" << be_idt_nl; + + if (this->visit_members (node) != 0) + return -1; + + os << be_uidt_nl + << "};" << be_uidt_nl << be_nl; + + // Generate the TypeCode instantiation. + os + << "static TAO::TypeCode::Enum<char const *," << be_nl + << " TAO::TypeCode::Enumerator<char const *> const *," << be_nl + << " TAO::Null_RefCount_Policy>" + << be_idt_nl + << "_tao_tc_" << node->flat_name () << " (" << be_idt_nl + << "\"" << node->repoID () << "\"," << be_nl + << "\"" << node->original_local_name () << "\"," << be_nl + << "_tao_enumerators_" << node->flat_name () << "," << be_nl + << node->member_count () << ");" << be_uidt_nl + << be_uidt_nl; + + return this->gen_typecode_ptr (node); +} + +int +TAO::be_visitor_enum_typecode::visit_members (be_enum * node) +{ + TAO_OutStream & os = *this->ctx_->stream (); + + size_t const count = node->member_count (); + size_t n = 0; + + for (UTL_ScopeActiveIterator i (node, UTL_Scope::IK_decls); + !i.is_done (); + i.next ()) + { + AST_Decl * const d = i.item (); + AST_EnumVal * const item = AST_EnumVal::narrow_from_decl (d); + + // os << item->name (); + os << "\"" << item->original_local_name () << "\""; + + if (n < count - 1) + os << ","; + + os << be_nl; + + ++n; + } + + return 0; +} diff --git a/TAO/TAO_IDL/be/be_visitor_typecode/objref_typecode.cpp b/TAO/TAO_IDL/be/be_visitor_typecode/objref_typecode.cpp new file mode 100644 index 00000000000..4664485f982 --- /dev/null +++ b/TAO/TAO_IDL/be/be_visitor_typecode/objref_typecode.cpp @@ -0,0 +1,87 @@ +// -*- C++ -*- + +//============================================================================= +/** + * @file objref_typecode.cpp + * + * $Id$ + * + * Object reference TypeCode generation visitor. + * + * @author Ossama Othman <ossama@dre.vanderbilt.edu> + */ +//============================================================================= + + +TAO::be_visitor_objref_typecode::be_visitor_objref_typecode ( + be_visitor_context * ctx) + : be_visitor_typecode_defn (ctx) +{ +} + +int +TAO::be_visitor_objref_typecode::visit_interface (be_interface * node) +{ + static char const abstract_interface[] = "abstract_interface"; + static char const component[] = "component"; + static char const home[] = "home"; + static char const local_interface[] = "local_interface"; + static char const objref[] = "objref"; + + char const * kind = 0; + + if (dynamic_cast<be_component *> (node)) + kind = component; + else if (dynamic_cast<be_home *> (node)) + kind = home; + else if (node->is_abstract ()) + kind = abstract_interface; + else if (node->is_local ()) + kind = local_interface; + else + kind = objref; + + return this->visit_i (kind, + node->flat_name (), + node->repoID (), + node->original_local_name ()->get_string (), + node); +} + +int +TAO::be_visitor_objref_typecode::visit_native (be_native * /* node */) +{ + return 0; +// return this->visit_i ("native", +// , +// , +// , +// node); +} + +int +TAO::be_visitor_objref_typecode::visit_i (char const * kind, + char const * flat_name, + char const * repository_id, + char const * original_local_name, + be_type * node) +{ + TAO_OutStream & os = *this->ctx_->stream (); + + os << be_nl << be_nl + << "// TAO_IDL - Generated from" << be_nl + << "// " << __FILE__ << ":" << __LINE__ << be_nl << be_nl; + + // Generate the TypeCode instantiation. + os + << "static TAO::TypeCode::Objref<char const *," << be_nl + << " CORBA::tk_" << kind << "," << be_nl + << " TAO::Null_RefCount_Policy>" + << be_idt_nl + << "_tao_tc_" << flat_name << " (" << be_idt_nl + << "\"" << repository_id << "\"," << be_nl + << "\"" << original_local_name << "\");" << be_uidt_nl + << be_uidt_nl; + + return this->gen_typecode_ptr (node); +} diff --git a/TAO/TAO_IDL/be/be_visitor_typecode/struct_typecode.cpp b/TAO/TAO_IDL/be/be_visitor_typecode/struct_typecode.cpp new file mode 100644 index 00000000000..87da74c4b47 --- /dev/null +++ b/TAO/TAO_IDL/be/be_visitor_typecode/struct_typecode.cpp @@ -0,0 +1,102 @@ +// -*- C++ -*- + +//============================================================================= +/** + * @file struct_typecode.cpp + * + * $Id$ + * + * Structure TypeCode generation visitor. + * + * @author Ossama Othman <ossama@dre.vanderbilt.edu> + */ +//============================================================================= + + +#include <string> + + +TAO::be_visitor_struct_typecode::be_visitor_struct_typecode ( + be_visitor_context * ctx, + bool is_exception) + : be_visitor_typecode_defn (ctx), + is_exception_ (is_exception) +{ +} + +int +TAO::be_visitor_struct_typecode::visit_structure (AST_Structure * node) +{ + TAO_OutStream & os = *this->ctx_->stream (); + + os << be_nl << be_nl + << "// TAO_IDL - Generated from" << be_nl + << "// " << __FILE__ << ":" << __LINE__ << be_nl << be_nl; + + + std::string const fields_name (std::string ("_tao_fields_") + + node->flat_name ()); + + // Generate array containing struct field characteristics. + os << "static TAO::TypeCode::Struct_Field<char const *> const " + << fields_name.c_str () + << "[] =" << be_idt_nl + << "{" << be_idt_nl; + + if (this->visit_members (node) != 0) + return -1; + + os << be_uidt_nl + << "};" << be_uidt_nl << be_nl; + + // Generate the TypeCode instantiation. + os + << "static TAO::TypeCode::Struct<char const *," << be_nl + << " TAO::TypeCode::Struct_Field<char const *> const *," << be_nl + << " CORBA::tk_" + << (this->is_exception_ ? "except" : "struct") << "," << be_nl + << " TAO::Null_RefCount_Policy>" + << be_idt_nl + << "_tao_tc_" << node->flat_name () << " (" << be_idt_nl + << "\"" << node->repoID () << "\"," << be_nl + << "\"" << node->original_local_name () << "\"," << be_nl + << "_tao_fields_" << node->flat_name () << "," << be_nl + << node->nfields () << ");" << be_uidt_nl + << be_uidt_nl; + + return + this->gen_typecode_ptr (be_type::narrow_from_decl (node)); +} + +int +TAO::be_visitor_struct_typecode::visit_members (AST_Structure * node) +{ + AST_Field ** member_ptr = 0; + + size_t const count = node->nfields (); + + TAO_OutStream & os = *this->ctx_->stream (); + + for (size_t i = 0; i < count; ++i) + { + node->field (member_ptr, i); + + be_decl * const member_decl = + be_decl::narrow_from_decl (*member_ptr); + + be_type * const member_type = + be_type::narrow_from_decl ((*member_ptr)->field_type ()); + + os << "{ " + << "\"" << member_decl->original_local_name () << "\", " + << "&" << member_type->tc_name () + << " }"; + + if (i < count - 1) + os << ","; + + os << be_nl; + } + + return 0; +} diff --git a/TAO/TAO_IDL/be/be_visitor_typecode/typecode_decl.cpp b/TAO/TAO_IDL/be/be_visitor_typecode/typecode_decl.cpp index 247095a8c12..9a420740f25 100644 --- a/TAO/TAO_IDL/be/be_visitor_typecode/typecode_decl.cpp +++ b/TAO/TAO_IDL/be/be_visitor_typecode/typecode_decl.cpp @@ -46,9 +46,9 @@ be_visitor_typecode_decl::visit_type (be_type *node) if (node->is_nested ()) { // We have a scoped name. - // Is our enclosing scope a module? We need this check because for - // platforms that support namespaces, the typecode must be declared - // extern. + // Is our enclosing scope a module? We need this check because + // for platforms that support namespaces, the TypeCode must be + // declared extern. if (node->defined_in ()->scope_node_type () == AST_Decl::NT_module) { *os << "TAO_NAMESPACE_STORAGE_CLASS "; diff --git a/TAO/TAO_IDL/be/be_visitor_typecode/typecode_defn.cpp b/TAO/TAO_IDL/be/be_visitor_typecode/typecode_defn.cpp index b43f94e21bf..dca2730b9b5 100644 --- a/TAO/TAO_IDL/be/be_visitor_typecode/typecode_defn.cpp +++ b/TAO/TAO_IDL/be/be_visitor_typecode/typecode_defn.cpp @@ -22,6 +22,7 @@ ACE_RCSID (be_visitor_typecode, typecode_defn, "$Id$") + // This is an implementation of C++ "scoped lock" idiom in order to // avoid repetitive code. class Scoped_Compute_Queue_Guard @@ -61,7 +62,7 @@ Scoped_Compute_Queue_Guard::~Scoped_Compute_Queue_Guard (void) // TypeCode Definitions // ****************************************************** -be_visitor_typecode_defn::be_visitor_typecode_defn (be_visitor_context *ctx) +be_visitor_typecode_defn::be_visitor_typecode_defn (be_visitor_context * ctx) : be_visitor_scope (ctx), computed_tc_size_ (0), computed_encap_len_ (0), @@ -69,6 +70,11 @@ be_visitor_typecode_defn::be_visitor_typecode_defn (be_visitor_context *ctx) tc_offset_ (0), index_ (-1) { + if (be_global->gen_anyop_files ()) + { + // Switch streams. (ctx better be a copy!) + this->ctx_->stream (tao_cg->anyop_source ()); + } } be_visitor_typecode_defn::~be_visitor_typecode_defn (void) @@ -77,141 +83,141 @@ be_visitor_typecode_defn::~be_visitor_typecode_defn (void) this->queue_reset (this->compute_queue_); } -int -be_visitor_typecode_defn::visit_members (AST_Structure *node) -{ - this->elem_number_ = 0; - AST_Field **member_ptr = 0; - size_t count = node->nfields (); - be_decl *enclosing = be_decl::narrow_from_decl (node); - - for (size_t i = 0; i < count; ++i) - { - node->field (member_ptr, i); - - be_decl *bd = be_decl::narrow_from_decl (*member_ptr); - - // Set the node to be visited. - this->ctx_->node (bd); - - // Reset this with every iteration - it might be changed - // when it comes around again. - this->ctx_->scope (enclosing); - - this->elem_number_++; - - // Do any pre processing using the next item info. - if (this->pre_process (bd) == -1) - { - ACE_ERROR_RETURN (( - LM_ERROR, - "(%N:%l) be_visitor_typecode_defn::visit_members - " - "pre processing failed\n" - ), - -1 - ); - } - - // Send the visitor. - if (bd == 0 || bd->accept (this) == -1) - { - ACE_ERROR_RETURN (( - LM_ERROR, - "(%N:%l) be_visitor_typecode_defn::visit_members - " - "codegen for scope failed\n" - ), - -1 - ); - - } - - // Do any post processing using this item info. - if (this->post_process (bd) == -1) - { - ACE_ERROR_RETURN (( - LM_ERROR, - "(%N:%l) be_visitor_typecode_defn::visit_members - " - "post processing failed\n" - ), - -1 - ); - } - } - - return 0; -} - -int -be_visitor_typecode_defn::visit_members (be_valuetype *node) -{ - this->elem_number_ = 0; - - for (UTL_ScopeActiveIterator si (node, UTL_Scope::IK_decls); - !si.is_done (); - si.next()) - { - AST_Decl *d = si.item (); - - if (!d) - { - ACE_ERROR_RETURN ((LM_ERROR, - "(%N:%l) be_visitor_typecode_defn::visit_members - " - "bad node in this scope\n"), - -1); - } - - AST_Field *field = AST_Field::narrow_from_decl (d); - - if (!field) - { - continue; - } - - be_decl *bd = be_decl::narrow_from_decl (d); - - // Set the scope node as "node" in which the code is being - // generated so that elements in the node's scope can use it - // for code generation - this->ctx_->scope (node->decl ()); - - // Set the node to be visited. - this->ctx_->node (bd); - this->elem_number_++; - - // Do any pre processing using the next item info. - if (this->pre_process (bd) == -1) - { - ACE_ERROR_RETURN ((LM_ERROR, - "(%N:%l) be_visitor_typecode_defn::" - "visit_members - " - "pre processing failed\n" - ), - -1); - } - - // Send the visitor. - if (bd == 0 || bd->accept (this) == -1) - { - ACE_ERROR_RETURN ((LM_ERROR, - "(%N:%l) be_visitor_typecode_defn::" - "visit_members - " - "codegen for scope failed\n" - ), -1); - } - - // Do any post processing using this item info. - if (this->post_process (bd) == -1) - { - ACE_ERROR_RETURN ((LM_ERROR, - "(%N:%l) be_visitor_typecode_defn::" - "visit_members - " - "post processing failed\n" - ), -1); - } - } - - return 0; -} +// int +// be_visitor_typecode_defn::visit_members (AST_Structure *node) +// { +// this->elem_number_ = 0; +// AST_Field **member_ptr = 0; +// size_t count = node->nfields (); +// be_decl *enclosing = be_decl::narrow_from_decl (node); + +// for (size_t i = 0; i < count; ++i) +// { +// node->field (member_ptr, i); + +// be_decl *bd = be_decl::narrow_from_decl (*member_ptr); + +// // Set the node to be visited. +// this->ctx_->node (bd); + +// // Reset this with every iteration - it might be changed +// // when it comes around again. +// this->ctx_->scope (enclosing); + +// this->elem_number_++; + +// // Do any pre processing using the next item info. +// if (this->pre_process (bd) == -1) +// { +// ACE_ERROR_RETURN (( +// LM_ERROR, +// "(%N:%l) be_visitor_typecode_defn::visit_members - " +// "pre processing failed\n" +// ), +// -1 +// ); +// } + +// // Send the visitor. +// if (bd == 0 || bd->accept (this) == -1) +// { +// ACE_ERROR_RETURN (( +// LM_ERROR, +// "(%N:%l) be_visitor_typecode_defn::visit_members - " +// "codegen for scope failed\n" +// ), +// -1 +// ); + +// } + +// // Do any post processing using this item info. +// if (this->post_process (bd) == -1) +// { +// ACE_ERROR_RETURN (( +// LM_ERROR, +// "(%N:%l) be_visitor_typecode_defn::visit_members - " +// "post processing failed\n" +// ), +// -1 +// ); +// } +// } + +// return 0; +// } + +// int +// be_visitor_typecode_defn::visit_members (be_valuetype *node) +// { +// this->elem_number_ = 0; + +// for (UTL_ScopeActiveIterator si (node, UTL_Scope::IK_decls); +// !si.is_done (); +// si.next()) +// { +// AST_Decl *d = si.item (); + +// if (!d) +// { +// ACE_ERROR_RETURN ((LM_ERROR, +// "(%N:%l) be_visitor_typecode_defn::visit_members - " +// "bad node in this scope\n"), +// -1); +// } + +// AST_Field *field = AST_Field::narrow_from_decl (d); + +// if (!field) +// { +// continue; +// } + +// be_decl *bd = be_decl::narrow_from_decl (d); + +// // Set the scope node as "node" in which the code is being +// // generated so that elements in the node's scope can use it +// // for code generation +// this->ctx_->scope (node->decl ()); + +// // Set the node to be visited. +// this->ctx_->node (bd); +// this->elem_number_++; + +// // Do any pre processing using the next item info. +// if (this->pre_process (bd) == -1) +// { +// ACE_ERROR_RETURN ((LM_ERROR, +// "(%N:%l) be_visitor_typecode_defn::" +// "visit_members - " +// "pre processing failed\n" +// ), +// -1); +// } + +// // Send the visitor. +// if (bd == 0 || bd->accept (this) == -1) +// { +// ACE_ERROR_RETURN ((LM_ERROR, +// "(%N:%l) be_visitor_typecode_defn::" +// "visit_members - " +// "codegen for scope failed\n" +// ), -1); +// } + +// // Do any post processing using this item info. +// if (this->post_process (bd) == -1) +// { +// ACE_ERROR_RETURN ((LM_ERROR, +// "(%N:%l) be_visitor_typecode_defn::" +// "visit_members - " +// "post processing failed\n" +// ), -1); +// } +// } + +// return 0; +// } // The following needs to be done to deal until the MSVC compiler's broken @@ -253,6 +259,8 @@ be_visitor_typecode_defn::gen_nested_namespace_end (be_module *node) } } + *os << be_nl << be_nl; + return 0; } @@ -262,17 +270,17 @@ be_visitor_typecode_defn::gen_nested_namespace_end (be_module *node) int be_visitor_typecode_defn::visit_type (be_type *node) { - AST_Decl::NodeType nt = node->base_node_type (); +// AST_Decl::NodeType nt = node->base_node_type (); - // Exceptions depend on their typcodes, so if we - // generate the typecode in the *A.cpp file, we also - // pull in the Any operators, which we may not need. - if (be_global->gen_anyop_files () && nt != AST_Decl::NT_except) - { - // Switch streams, ctx will be reassigned when this - // pass is done. - this->ctx_->stream (tao_cg->anyop_source ()); - } +// // Exceptions depend on their typcodes, so if we +// // generate the typecode in the *A.cpp file, we also +// // pull in the Any operators, which we may not need. +// if (be_global->gen_anyop_files () && nt != AST_Decl::NT_except) +// { +// // Switch streams, ctx will be reassigned when this +// // pass is done. +// this->ctx_->stream (tao_cg->anyop_source ()); +// } TAO_OutStream *os = this->ctx_->stream (); @@ -336,36 +344,36 @@ be_visitor_typecode_defn::visit_type (be_type *node) case AST_Decl::NT_array: *os << "CORBA::tk_array"; break; - case AST_Decl::NT_enum: - *os << "CORBA::tk_enum"; - break; - case AST_Decl::NT_except: - *os << "CORBA::tk_except"; - break; - case AST_Decl::NT_interface: - *os << "CORBA::tk_objref"; - break; - case AST_Decl::NT_valuetype: - *os << "CORBA::tk_value"; - break; - case AST_Decl::NT_eventtype: - *os << "CORBA::tk_event"; - break; - case AST_Decl::NT_component: - *os << "CORBA::tk_component"; - break; - case AST_Decl::NT_sequence: - *os << "CORBA::tk_sequence"; - break; - case AST_Decl::NT_struct: - *os << "CORBA::tk_struct"; - break; - case AST_Decl::NT_typedef: - *os << "CORBA::tk_alias"; - break; - case AST_Decl::NT_union: - *os << "CORBA::tk_union"; - break; +// case AST_Decl::NT_enum: +// *os << "CORBA::tk_enum"; +// break; +// case AST_Decl::NT_except: +// *os << "CORBA::tk_except"; +// break; +// case AST_Decl::NT_interface: +// *os << "CORBA::tk_objref"; +// break; +// case AST_Decl::NT_valuetype: +// *os << "CORBA::tk_value"; +// break; +// case AST_Decl::NT_eventtype: +// *os << "CORBA::tk_event"; +// break; +// case AST_Decl::NT_component: +// *os << "CORBA::tk_component"; +// break; +// case AST_Decl::NT_sequence: +// *os << "CORBA::tk_sequence"; +// break; +// case AST_Decl::NT_struct: +// *os << "CORBA::tk_struct"; +// break; +// case AST_Decl::NT_typedef: +// *os << "CORBA::tk_alias"; +// break; +// case AST_Decl::NT_union: +// *os << "CORBA::tk_union"; +// break; default: return -1; // error } @@ -388,28 +396,47 @@ be_visitor_typecode_defn::visit_type (be_type *node) << "0" << be_uidt_nl << ");" << be_uidt_nl << be_nl; + return this->gen_typecode_ptr (node); +} + +int +be_visitor_typecode_defn::gen_typecode_ptr (be_type * node) +{ + TAO_OutStream & os = *this->ctx_->stream (); + + if (node->node_type () == AST_Decl::NT_string + || node->node_type () == AST_Decl::NT_wstring + || node->node_type () == AST_Decl::NT_sequence) + { + // Don't bother generating a TypeCode_ptr for these types. They + // are only accessible through an alias TypeCode. + + return 0; + } + // Is our enclosing scope a module? We need this check because for // platforms that support namespaces, the typecode must be declared // extern. if (node->is_nested () && node->defined_in ()->scope_node_type () == AST_Decl::NT_module) { - be_module *module = be_module::narrow_from_scope (node->defined_in ()); + be_module * const module = + be_module::narrow_from_scope (node->defined_in ()); if (!module || (this->gen_nested_namespace_begin (module) == -1)) { ACE_ERROR_RETURN ((LM_ERROR, - "be_visitor_typecode_defn::visit_type - " + "be_visitor_typecode_defn::gen_typecode_ptr - " "Error parsing nested name\n"), -1); } - *os << "::CORBA::TypeCode_ptr const _tc_" - << node->local_name () - << " =" << be_idt_nl - << "&_tc_TAO_tc_" - << node->flat_name () << ";" - << be_uidt; + os << "::CORBA::TypeCode_ptr const _tc_" + << node->local_name () + << " =" << be_idt_nl + << "&_tao_tc_" + << node->flat_name () << ";" + << be_uidt; if (this->gen_nested_namespace_end (module) == -1) { @@ -422,166 +449,77 @@ be_visitor_typecode_defn::visit_type (be_type *node) else { // outermost scope. - *os << "::CORBA::TypeCode_ptr const "; + os << "::CORBA::TypeCode_ptr const "; // Tc name generation. - *os << node->tc_name (); + os << node->tc_name (); - *os << " =" << be_idt_nl - << "&_tc_TAO_tc_"; + os << " =" << be_idt_nl + << "&_tao_tc_"; // Flat name generation. - *os << node->flat_name (); + os << node->flat_name (); - *os << ";" << be_uidt; + os << ";" << be_uidt; } return 0; } -int -be_visitor_typecode_defn::visit_array (be_array *node) -{ - switch (this->ctx_->sub_state ()) - { - case TAO_CodeGen::TAO_TC_DEFN_TYPECODE: - return this->visit_type (node); - case TAO_CodeGen::TAO_TC_DEFN_TYPECODE_NESTED: - return this->gen_typecode (node); - - case TAO_CodeGen::TAO_TC_DEFN_ENCAPSULATION: - return this->gen_encapsulation (node); - - case TAO_CodeGen::TAO_TC_DEFN_TC_SIZE: - this->computed_tc_size_ = this->compute_tc_size (node); - return ((this->computed_tc_size_ > 0) ? 0 : -1); - case TAO_CodeGen::TAO_TC_DEFN_ENCAP_LEN: - this->computed_encap_len_ = this->compute_encap_length (node); - return ((this->computed_encap_len_ > 0) ? 0 : -1); - default: - // error - break; - } - - ACE_ERROR_RETURN ((LM_ERROR, - ACE_TEXT ("(%N:%l) be_visitor_typecode_defn::") - ACE_TEXT ("visit - bad sub state ") - ACE_TEXT ("in visitor context\n")), - -1); -} int -be_visitor_typecode_defn::visit_enum (be_enum *node) +be_visitor_typecode_defn::gen_base_typecode_name (be_type * base) { - switch (this->ctx_->sub_state ()) + TAO_OutStream & os = *this->ctx_->stream (); + + if (base->is_nested () + && base->defined_in ()->scope_node_type () == AST_Decl::NT_module) { - case TAO_CodeGen::TAO_TC_DEFN_TYPECODE: - return this->visit_type (node); - case TAO_CodeGen::TAO_TC_DEFN_TYPECODE_NESTED: - return this->gen_typecode (node); + if (base->node_type () != AST_Decl::NT_string + && base->node_type () != AST_Decl::NT_wstring + && base->node_type () != AST_Decl::NT_sequence) + { + // Only generate scope names if types other than the ones + // listed above since the corresponding TypeCodes are at the + // file scope. - case TAO_CodeGen::TAO_TC_DEFN_ENCAPSULATION: - return this->gen_encapsulation (node); +// be_module * const module = +// be_module::narrow_from_scope (base->defined_in ()); - case TAO_CodeGen::TAO_TC_DEFN_TC_SIZE: - this->computed_tc_size_ = this->compute_tc_size (node); - return ((this->computed_tc_size_ > 0) ? 0 : -1); - case TAO_CodeGen::TAO_TC_DEFN_ENCAP_LEN: - this->computed_encap_len_ = this->compute_encap_length (node); - return ((this->computed_encap_len_ > 0) ? 0 : -1); - case TAO_CodeGen::TAO_TC_DEFN_SCOPE: - case TAO_CodeGen::TAO_TC_DEFN_SCOPE_LEN: - return this->visit_scope (node); - default: - // error - break; - } +// ACE_ASSERT (module); - ACE_ERROR_RETURN ((LM_ERROR, - ACE_TEXT ("(%N:%l) be_visitor_typecode_defn::") - ACE_TEXT ("visit - bad sub state ") - ACE_TEXT ("in visitor context\n")), - -1); -} +// for (UTL_IdListActiveIterator i (module->name ()); +// !i.is_done (); +// i.next ()) +// { +// char * const module_name = i.item ()->get_string (); -int -be_visitor_typecode_defn::visit_enum_val (be_enum_val *node) -{ - switch (this->ctx_->sub_state ()) - { - case TAO_CodeGen::TAO_TC_DEFN_SCOPE: - return this->gen_encapsulation (node); - case TAO_CodeGen::TAO_TC_DEFN_SCOPE_LEN: - this->computed_encap_len_ = this->compute_encap_length (node); - return ((this->computed_encap_len_ > 0) ? 0 : -1); - default: - // error - break; - } - - ACE_ERROR_RETURN ((LM_ERROR, - ACE_TEXT ("(%N:%l) be_visitor_typecode_defn::") - ACE_TEXT ("visit - bad sub state ") - ACE_TEXT ("in visitor context\n")), - -1); -} +// if (ACE_OS::strcmp (module_name, "") != 0) +// { +// os << "::"; +// } -int -be_visitor_typecode_defn::visit_exception (be_exception *node) -{ - switch (this->ctx_->sub_state ()) - { - case TAO_CodeGen::TAO_TC_DEFN_TYPECODE: - return this->visit_type (node); - case TAO_CodeGen::TAO_TC_DEFN_TYPECODE_NESTED: - return this->gen_typecode (node); - case TAO_CodeGen::TAO_TC_DEFN_ENCAPSULATION: - return this->gen_encapsulation (node); - case TAO_CodeGen::TAO_TC_DEFN_TC_SIZE: - this->computed_tc_size_ = this->compute_tc_size (node); - return ((this->computed_tc_size_ > 0) ? 0 : -1); - case TAO_CodeGen::TAO_TC_DEFN_ENCAP_LEN: - this->computed_encap_len_ = this->compute_encap_length (node); - return ((this->computed_encap_len_ > 0) ? 0 : -1); - case TAO_CodeGen::TAO_TC_DEFN_SCOPE: - case TAO_CodeGen::TAO_TC_DEFN_SCOPE_LEN: - return this->visit_members (node); - default: - // error - break; - } +// os << module_name; +// } - ACE_ERROR_RETURN ((LM_ERROR, - ACE_TEXT ("(%N:%l) be_visitor_typecode_defn::") - ACE_TEXT ("visit - bad sub state ") - ACE_TEXT ("in visitor context\n")), - -1); -} + os << base->tc_name (); + } + else + { + // Internally used TypeCodes. -int -be_visitor_typecode_defn::visit_field (be_field *node) -{ - switch (this->ctx_->sub_state ()) - { - case TAO_CodeGen::TAO_TC_DEFN_SCOPE: - return this->gen_encapsulation (node); - case TAO_CodeGen::TAO_TC_DEFN_SCOPE_LEN: - this->computed_encap_len_ = this->compute_encap_length (node); - return ((this->computed_encap_len_ > 0) ? 0 : -1); - default: - // error - break; + os << "::_tao_tc_" << base->tc_name (); + } } + else + os << "::_tao_tc_" + << base->tc_name (); - ACE_ERROR_RETURN ((LM_ERROR, - ACE_TEXT ("(%N:%l) be_visitor_typecode_defn::") - ACE_TEXT ("visit - bad sub state ") - ACE_TEXT ("in visitor context\n")), - -1); + return 0; } int -be_visitor_typecode_defn::visit_interface (be_interface *node) +be_visitor_typecode_defn::visit_array (be_array *node) { switch (this->ctx_->sub_state ()) { @@ -589,81 +527,10 @@ be_visitor_typecode_defn::visit_interface (be_interface *node) return this->visit_type (node); case TAO_CodeGen::TAO_TC_DEFN_TYPECODE_NESTED: return this->gen_typecode (node); - case TAO_CodeGen::TAO_TC_DEFN_ENCAPSULATION: - return this->gen_encapsulation (node); - case TAO_CodeGen::TAO_TC_DEFN_TC_SIZE: - this->computed_tc_size_ = this->compute_tc_size (node); - return ((this->computed_tc_size_ > 0) ? 0 : -1); - case TAO_CodeGen::TAO_TC_DEFN_ENCAP_LEN: - this->computed_encap_len_ = this->compute_encap_length (node); - return ((this->computed_encap_len_ > 0) ? 0 : -1); - default: - // error - break; - } - ACE_ERROR_RETURN ((LM_ERROR, - ACE_TEXT ("(%N:%l) be_visitor_typecode_defn::") - ACE_TEXT ("visit - bad sub state ") - ACE_TEXT ("in visitor context\n")), - -1); -} - -int -be_visitor_typecode_defn::visit_component (be_component *node) -{ - return this->visit_interface (node); -} - -int -be_visitor_typecode_defn::visit_interface_fwd (be_interface_fwd *) -{ - // nothing to do - return 0; -} - -int -be_visitor_typecode_defn::visit_predefined_type (be_predefined_type *node) -{ - switch (this->ctx_->sub_state ()) - { - case TAO_CodeGen::TAO_TC_DEFN_TYPECODE: - // top level typecodes are defined in the CORBA library. If we show up - // here, then it is an error - break; - case TAO_CodeGen::TAO_TC_DEFN_TYPECODE_NESTED: - return this->gen_typecode (node); case TAO_CodeGen::TAO_TC_DEFN_ENCAPSULATION: return this->gen_encapsulation (node); - case TAO_CodeGen::TAO_TC_DEFN_TC_SIZE: - this->computed_tc_size_ = this->compute_tc_size (node); - return ((this->computed_tc_size_ > 0) ? 0 : -1); - case TAO_CodeGen::TAO_TC_DEFN_ENCAP_LEN: - this->computed_encap_len_ = this->compute_encap_length (node); - return ((this->computed_encap_len_ > 0) ? 0 : -1); - default: - // error - break; - } - - ACE_ERROR_RETURN ((LM_ERROR, - ACE_TEXT ("(%N:%l) be_visitor_typecode_defn::") - ACE_TEXT ("visit - bad sub state ") - ACE_TEXT ("in visitor context\n")), - -1); -} -int -be_visitor_typecode_defn::visit_sequence (be_sequence *node) -{ - switch (this->ctx_->sub_state ()) - { - case TAO_CodeGen::TAO_TC_DEFN_TYPECODE: - return this->visit_type (node); - case TAO_CodeGen::TAO_TC_DEFN_TYPECODE_NESTED: - return this->gen_typecode (node); - case TAO_CodeGen::TAO_TC_DEFN_ENCAPSULATION: - return this->gen_encapsulation (node); case TAO_CodeGen::TAO_TC_DEFN_TC_SIZE: this->computed_tc_size_ = this->compute_tc_size (node); return ((this->computed_tc_size_ > 0) ? 0 : -1); @@ -682,189 +549,413 @@ be_visitor_typecode_defn::visit_sequence (be_sequence *node) -1); } -int -be_visitor_typecode_defn::visit_string (be_string *node) -{ - switch (this->ctx_->sub_state ()) - { - case TAO_CodeGen::TAO_TC_DEFN_TYPECODE: - // top level typecode for string is not permitted. It has to be a - // typedefed string - break; - case TAO_CodeGen::TAO_TC_DEFN_TYPECODE_NESTED: - return this->gen_typecode (node); - case TAO_CodeGen::TAO_TC_DEFN_ENCAPSULATION: - return this->gen_encapsulation (node); - case TAO_CodeGen::TAO_TC_DEFN_TC_SIZE: - this->computed_tc_size_ = this->compute_tc_size (node); - return ((this->computed_tc_size_ > 0) ? 0 : -1); - case TAO_CodeGen::TAO_TC_DEFN_ENCAP_LEN: - this->computed_encap_len_ = this->compute_encap_length (node); - return ((this->computed_encap_len_ > 0) ? 0 : -1); - default: - // error - break; - } - - ACE_ERROR_RETURN ((LM_ERROR, - ACE_TEXT ("(%N:%l) be_visitor_typecode_defn::") - ACE_TEXT ("visit - bad sub state ") - ACE_TEXT ("in visitor context\n")), - -1); -} +// int +// be_visitor_typecode_defn::visit_enum (be_enum *node) +// { +// switch (this->ctx_->sub_state ()) +// { +// case TAO_CodeGen::TAO_TC_DEFN_TYPECODE: +// return this->visit_type (node); +// case TAO_CodeGen::TAO_TC_DEFN_TYPECODE_NESTED: +// return this->gen_typecode (node); + +// case TAO_CodeGen::TAO_TC_DEFN_ENCAPSULATION: +// return this->gen_encapsulation (node); + +// case TAO_CodeGen::TAO_TC_DEFN_TC_SIZE: +// this->computed_tc_size_ = this->compute_tc_size (node); +// return ((this->computed_tc_size_ > 0) ? 0 : -1); +// case TAO_CodeGen::TAO_TC_DEFN_ENCAP_LEN: +// this->computed_encap_len_ = this->compute_encap_length (node); +// return ((this->computed_encap_len_ > 0) ? 0 : -1); +// case TAO_CodeGen::TAO_TC_DEFN_SCOPE: +// case TAO_CodeGen::TAO_TC_DEFN_SCOPE_LEN: +// return this->visit_scope (node); +// default: +// // error +// break; +// } + +// ACE_ERROR_RETURN ((LM_ERROR, +// ACE_TEXT ("(%N:%l) be_visitor_typecode_defn::") +// ACE_TEXT ("visit - bad sub state ") +// ACE_TEXT ("in visitor context\n")), +// -1); +// } + +// int +// be_visitor_typecode_defn::visit_enum_val (be_enum_val *node) +// { +// switch (this->ctx_->sub_state ()) +// { +// case TAO_CodeGen::TAO_TC_DEFN_SCOPE: +// return this->gen_encapsulation (node); +// case TAO_CodeGen::TAO_TC_DEFN_SCOPE_LEN: +// this->computed_encap_len_ = this->compute_encap_length (node); +// return ((this->computed_encap_len_ > 0) ? 0 : -1); +// default: +// // error +// break; +// } + +// ACE_ERROR_RETURN ((LM_ERROR, +// ACE_TEXT ("(%N:%l) be_visitor_typecode_defn::") +// ACE_TEXT ("visit - bad sub state ") +// ACE_TEXT ("in visitor context\n")), +// -1); +// } + +// int +// be_visitor_typecode_defn::visit_exception (be_exception *node) +// { +// switch (this->ctx_->sub_state ()) +// { +// case TAO_CodeGen::TAO_TC_DEFN_TYPECODE: +// return this->visit_type (node); +// case TAO_CodeGen::TAO_TC_DEFN_TYPECODE_NESTED: +// return this->gen_typecode (node); +// case TAO_CodeGen::TAO_TC_DEFN_ENCAPSULATION: +// return this->gen_encapsulation (node); +// case TAO_CodeGen::TAO_TC_DEFN_TC_SIZE: +// this->computed_tc_size_ = this->compute_tc_size (node); +// return ((this->computed_tc_size_ > 0) ? 0 : -1); +// case TAO_CodeGen::TAO_TC_DEFN_ENCAP_LEN: +// this->computed_encap_len_ = this->compute_encap_length (node); +// return ((this->computed_encap_len_ > 0) ? 0 : -1); +// case TAO_CodeGen::TAO_TC_DEFN_SCOPE: +// case TAO_CodeGen::TAO_TC_DEFN_SCOPE_LEN: +// // return this->visit_members (node); +// default: +// // error +// break; +// } + +// ACE_ERROR_RETURN ((LM_ERROR, +// ACE_TEXT ("(%N:%l) be_visitor_typecode_defn::") +// ACE_TEXT ("visit - bad sub state ") +// ACE_TEXT ("in visitor context\n")), +// -1); +// } + +// int +// be_visitor_typecode_defn::visit_field (be_field *node) +// { +// switch (this->ctx_->sub_state ()) +// { +// case TAO_CodeGen::TAO_TC_DEFN_SCOPE: +// return this->gen_encapsulation (node); +// case TAO_CodeGen::TAO_TC_DEFN_SCOPE_LEN: +// this->computed_encap_len_ = this->compute_encap_length (node); +// return ((this->computed_encap_len_ > 0) ? 0 : -1); +// default: +// // error +// break; +// } + +// ACE_ERROR_RETURN ((LM_ERROR, +// ACE_TEXT ("(%N:%l) be_visitor_typecode_defn::") +// ACE_TEXT ("visit - bad sub state ") +// ACE_TEXT ("in visitor context\n")), +// -1); +// } + +// int +// be_visitor_typecode_defn::visit_interface (be_interface *node) +// { +// switch (this->ctx_->sub_state ()) +// { +// case TAO_CodeGen::TAO_TC_DEFN_TYPECODE: +// return this->visit_type (node); +// case TAO_CodeGen::TAO_TC_DEFN_TYPECODE_NESTED: +// return this->gen_typecode (node); +// case TAO_CodeGen::TAO_TC_DEFN_ENCAPSULATION: +// return this->gen_encapsulation (node); +// case TAO_CodeGen::TAO_TC_DEFN_TC_SIZE: +// this->computed_tc_size_ = this->compute_tc_size (node); +// return ((this->computed_tc_size_ > 0) ? 0 : -1); +// case TAO_CodeGen::TAO_TC_DEFN_ENCAP_LEN: +// this->computed_encap_len_ = this->compute_encap_length (node); +// return ((this->computed_encap_len_ > 0) ? 0 : -1); +// default: +// // error +// break; +// } + +// ACE_ERROR_RETURN ((LM_ERROR, +// ACE_TEXT ("(%N:%l) be_visitor_typecode_defn::") +// ACE_TEXT ("visit - bad sub state ") +// ACE_TEXT ("in visitor context\n")), +// -1); +// } + +// int +// be_visitor_typecode_defn::visit_component (be_component *node) +// { +// return this->visit_interface (node); +// } + +// int +// be_visitor_typecode_defn::visit_interface_fwd (be_interface_fwd *) +// { +// // nothing to do +// return 0; +// } + +// int +// be_visitor_typecode_defn::visit_predefined_type (be_predefined_type *node) +// { +// switch (this->ctx_->sub_state ()) +// { +// case TAO_CodeGen::TAO_TC_DEFN_TYPECODE: +// // top level typecodes are defined in the CORBA library. If we show up +// // here, then it is an error +// break; +// case TAO_CodeGen::TAO_TC_DEFN_TYPECODE_NESTED: +// return this->gen_typecode (node); +// case TAO_CodeGen::TAO_TC_DEFN_ENCAPSULATION: +// return this->gen_encapsulation (node); +// case TAO_CodeGen::TAO_TC_DEFN_TC_SIZE: +// this->computed_tc_size_ = this->compute_tc_size (node); +// return ((this->computed_tc_size_ > 0) ? 0 : -1); +// case TAO_CodeGen::TAO_TC_DEFN_ENCAP_LEN: +// this->computed_encap_len_ = this->compute_encap_length (node); +// return ((this->computed_encap_len_ > 0) ? 0 : -1); +// default: +// // error +// break; +// } + +// ACE_ERROR_RETURN ((LM_ERROR, +// ACE_TEXT ("(%N:%l) be_visitor_typecode_defn::") +// ACE_TEXT ("visit - bad sub state ") +// ACE_TEXT ("in visitor context\n")), +// -1); +// } int -be_visitor_typecode_defn::visit_structure (be_structure *node) +be_visitor_typecode_defn::visit_sequence (be_sequence * node) { - switch (this->ctx_->sub_state ()) - { - case TAO_CodeGen::TAO_TC_DEFN_TYPECODE: - return this->visit_type (node); - case TAO_CodeGen::TAO_TC_DEFN_TYPECODE_NESTED: - return this->gen_typecode (node); - case TAO_CodeGen::TAO_TC_DEFN_ENCAPSULATION: - return this->gen_encapsulation (node); - case TAO_CodeGen::TAO_TC_DEFN_TC_SIZE: - this->computed_tc_size_ = this->compute_tc_size (node); - return ((this->computed_tc_size_ > 0) ? 0 : -1); - case TAO_CodeGen::TAO_TC_DEFN_ENCAP_LEN: - this->computed_encap_len_ = this->compute_encap_length (node); - return ((this->computed_encap_len_ > 0) ? 0 : -1); - case TAO_CodeGen::TAO_TC_DEFN_SCOPE: - case TAO_CodeGen::TAO_TC_DEFN_SCOPE_LEN: - return this->visit_members (node); - default: - // error - break; - } + be_type * const base = be_type::narrow_from_decl (node->base_type ()); - ACE_ERROR_RETURN ((LM_ERROR, - ACE_TEXT ("(%N:%l) be_visitor_typecode_defn::") - ACE_TEXT ("visit - bad sub state ") - ACE_TEXT ("in visitor context\n")), - -1); -} + TAO_OutStream & os = *this->ctx_->stream (); -int -be_visitor_typecode_defn::visit_typedef (be_typedef *node) -{ - switch (this->ctx_->sub_state ()) - { - case TAO_CodeGen::TAO_TC_DEFN_TYPECODE: - return this->visit_type (node); - case TAO_CodeGen::TAO_TC_DEFN_TYPECODE_NESTED: - return this->gen_typecode (node); - case TAO_CodeGen::TAO_TC_DEFN_ENCAPSULATION: - return this->gen_encapsulation (node); - case TAO_CodeGen::TAO_TC_DEFN_TC_SIZE: - this->computed_tc_size_ = this->compute_tc_size (node); - return ((this->computed_tc_size_ > 0) ? 0 : -1); - case TAO_CodeGen::TAO_TC_DEFN_ENCAP_LEN: - this->computed_encap_len_ = this->compute_encap_length (node); - return ((this->computed_encap_len_ > 0) ? 0 : -1); - default: - // error - break; - } + os << be_nl << be_nl + << "// TAO_IDL - Generated from" << be_nl + << "// " << __FILE__ << ":" << __LINE__ << be_nl << be_nl; - ACE_ERROR_RETURN ((LM_ERROR, - ACE_TEXT ("(%N:%l) be_visitor_typecode_defn::") - ACE_TEXT ("visit - bad sub state ") - ACE_TEXT ("in visitor context\n")), - -1); -} + // generate typecode for the base type + this->ctx_->sub_state (TAO_CodeGen::TAO_TC_DEFN_TYPECODE_NESTED); -int -be_visitor_typecode_defn::visit_union (be_union *node) -{ - switch (this->ctx_->sub_state ()) + if (!base || base->accept (this) == -1) { - case TAO_CodeGen::TAO_TC_DEFN_TYPECODE: - return this->visit_type (node); - case TAO_CodeGen::TAO_TC_DEFN_TYPECODE_NESTED: - return this->gen_typecode (node); - case TAO_CodeGen::TAO_TC_DEFN_ENCAPSULATION: - return this->gen_encapsulation (node); - case TAO_CodeGen::TAO_TC_DEFN_TC_SIZE: - this->computed_tc_size_ = this->compute_tc_size (node); - return ((this->computed_tc_size_ > 0) ? 0 : -1); - case TAO_CodeGen::TAO_TC_DEFN_ENCAP_LEN: - this->computed_encap_len_ = this->compute_encap_length (node); - return ((this->computed_encap_len_ > 0) ? 0 : -1); - case TAO_CodeGen::TAO_TC_DEFN_SCOPE: - case TAO_CodeGen::TAO_TC_DEFN_SCOPE_LEN: - return this->visit_members (node); - default: - // error - break; + ACE_ERROR_RETURN ((LM_ERROR, + ACE_TEXT ("(%N:%l) be_visitor_typecode_defn") + ACE_TEXT ("::visit_sequence) - ") + ACE_TEXT ("failed to generate base typecode\n")), + -1); } - ACE_ERROR_RETURN ((LM_ERROR, - ACE_TEXT ("(%N:%l) be_visitor_typecode_defn::") - ACE_TEXT ("visit - bad sub state ") - ACE_TEXT ("in visitor context\n")), - -1); -} + // Generate the TypeCode instantiation. + os << "static TAO::TypeCode::Sequence<TAO::Null_RefCount_Policy>" + << be_idt_nl + << "_tao_tc_" +// << node->flat_name () << "_" << node->max_size() + << node->tc_name () + << " (" << be_idt_nl + << "CORBA::tk_sequence," << be_nl + << "&"; -int -be_visitor_typecode_defn::visit_valuetype (be_valuetype *node) -{ - switch (this->ctx_->sub_state ()) - { - case TAO_CodeGen::TAO_TC_DEFN_TYPECODE: - return this->visit_type (node); - case TAO_CodeGen::TAO_TC_DEFN_TYPECODE_NESTED: - return this->gen_typecode (node); - case TAO_CodeGen::TAO_TC_DEFN_ENCAPSULATION: - return this->gen_encapsulation (node); - case TAO_CodeGen::TAO_TC_DEFN_TC_SIZE: - this->computed_tc_size_ = this->compute_tc_size (node); - return ((this->computed_tc_size_ > 0) ? 0 : -1); - case TAO_CodeGen::TAO_TC_DEFN_ENCAP_LEN: - this->computed_encap_len_ = this->compute_encap_length (node); - return ((this->computed_encap_len_ > 0) ? 0 : -1); - case TAO_CodeGen::TAO_TC_DEFN_SCOPE: - case TAO_CodeGen::TAO_TC_DEFN_SCOPE_LEN: - return this->visit_members (node); - default: - // error - break; - } + int const success = this->gen_base_typecode_name (base); + ACE_ASSERT (success == 0); - ACE_ERROR_RETURN ((LM_ERROR, - ACE_TEXT ("(%N:%l) be_visitor_typecode_defn::") - ACE_TEXT ("visit - bad sub state ") - ACE_TEXT ("in visitor context\n")), - -1); -} + os << "," << be_nl + << node->max_size () << ");" << be_uidt_nl + << be_uidt_nl; -int -be_visitor_typecode_defn::visit_eventtype (be_eventtype *node) -{ - return this->visit_valuetype (node); + return this->gen_typecode_ptr (node); } int -be_visitor_typecode_defn::visit_union_branch (be_union_branch *node) -{ - switch (this->ctx_->sub_state ()) - { - case TAO_CodeGen::TAO_TC_DEFN_SCOPE: - return this->gen_encapsulation (node); - case TAO_CodeGen::TAO_TC_DEFN_SCOPE_LEN: - this->computed_encap_len_ = this->compute_encap_length (node); - return ((this->computed_encap_len_ > 0) ? 0 : -1); - default: - // error - break; - } - - ACE_ERROR_RETURN ((LM_ERROR, - ACE_TEXT ("(%N:%l) be_visitor_typecode_defn::") - ACE_TEXT ("visit - bad sub state ") - ACE_TEXT ("in visitor context\n")), - -1); -} +be_visitor_typecode_defn::visit_string (be_string * node) +{ + if (node->max_size ()->ev()->u.ulval == 0) + { + // No need to generate a TypeCode for unbounded strings. Just + // use the {w}string TypeCode constant. + return 0; + } + + TAO_OutStream & os = *this->ctx_->stream (); + + os << be_nl << be_nl + << "// TAO_IDL - Generated from" << be_nl + << "// " << __FILE__ << ":" << __LINE__ << be_nl << be_nl; + + // Generate the TypeCode instantiation. + os + << "static TAO::TypeCode::String<TAO::Null_RefCount_Policy>" + << be_idt_nl + << "_tao_tc_" << node->flat_name () << " (" << be_idt_nl + << "CORBA::tk_" << (node->width () == 1 ? "string" : "wstring") << "," + << be_nl + << node->max_size () << ");" << be_uidt_nl + << be_uidt_nl; + + return this->gen_typecode_ptr (node); +} + +// int +// be_visitor_typecode_defn::visit_structure (be_structure *node) +// { +// switch (this->ctx_->sub_state ()) +// { +// case TAO_CodeGen::TAO_TC_DEFN_TYPECODE: +// return this->visit_type (node); +// case TAO_CodeGen::TAO_TC_DEFN_TYPECODE_NESTED: +// return this->gen_typecode (node); +// case TAO_CodeGen::TAO_TC_DEFN_ENCAPSULATION: +// return this->gen_encapsulation (node); +// case TAO_CodeGen::TAO_TC_DEFN_TC_SIZE: +// this->computed_tc_size_ = this->compute_tc_size (node); +// return ((this->computed_tc_size_ > 0) ? 0 : -1); +// case TAO_CodeGen::TAO_TC_DEFN_ENCAP_LEN: +// this->computed_encap_len_ = this->compute_encap_length (node); +// return ((this->computed_encap_len_ > 0) ? 0 : -1); +// case TAO_CodeGen::TAO_TC_DEFN_SCOPE: +// case TAO_CodeGen::TAO_TC_DEFN_SCOPE_LEN: +// // return this->visit_members (node); +// default: +// // error +// break; +// } + +// ACE_ERROR_RETURN ((LM_ERROR, +// ACE_TEXT ("(%N:%l) be_visitor_typecode_defn::") +// ACE_TEXT ("visit - bad sub state ") +// ACE_TEXT ("in visitor context\n")), +// -1); +// } + +// int +// be_visitor_typecode_defn::visit_typedef (be_typedef *node) +// { +// switch (this->ctx_->sub_state ()) +// { +// case TAO_CodeGen::TAO_TC_DEFN_TYPECODE: +// return this->visit_type (node); +// case TAO_CodeGen::TAO_TC_DEFN_TYPECODE_NESTED: +// return this->gen_typecode (node); +// case TAO_CodeGen::TAO_TC_DEFN_ENCAPSULATION: +// return this->gen_encapsulation (node); +// case TAO_CodeGen::TAO_TC_DEFN_TC_SIZE: +// this->computed_tc_size_ = this->compute_tc_size (node); +// return ((this->computed_tc_size_ > 0) ? 0 : -1); +// case TAO_CodeGen::TAO_TC_DEFN_ENCAP_LEN: +// this->computed_encap_len_ = this->compute_encap_length (node); +// return ((this->computed_encap_len_ > 0) ? 0 : -1); +// default: +// // error +// break; +// } + +// ACE_ERROR_RETURN ((LM_ERROR, +// ACE_TEXT ("(%N:%l) be_visitor_typecode_defn::") +// ACE_TEXT ("visit - bad sub state ") +// ACE_TEXT ("in visitor context\n")), +// -1); +// } + +// int +// be_visitor_typecode_defn::visit_union (be_union *node) +// { +// switch (this->ctx_->sub_state ()) +// { +// case TAO_CodeGen::TAO_TC_DEFN_TYPECODE: +// return this->visit_type (node); +// case TAO_CodeGen::TAO_TC_DEFN_TYPECODE_NESTED: +// return this->gen_typecode (node); +// case TAO_CodeGen::TAO_TC_DEFN_ENCAPSULATION: +// return this->gen_encapsulation (node); +// case TAO_CodeGen::TAO_TC_DEFN_TC_SIZE: +// this->computed_tc_size_ = this->compute_tc_size (node); +// return ((this->computed_tc_size_ > 0) ? 0 : -1); +// case TAO_CodeGen::TAO_TC_DEFN_ENCAP_LEN: +// this->computed_encap_len_ = this->compute_encap_length (node); +// return ((this->computed_encap_len_ > 0) ? 0 : -1); +// case TAO_CodeGen::TAO_TC_DEFN_SCOPE: +// case TAO_CodeGen::TAO_TC_DEFN_SCOPE_LEN: +// // return this->visit_members (node); +// default: +// // error +// break; +// } + +// ACE_ERROR_RETURN ((LM_ERROR, +// ACE_TEXT ("(%N:%l) be_visitor_typecode_defn::") +// ACE_TEXT ("visit - bad sub state ") +// ACE_TEXT ("in visitor context\n")), +// -1); +// } + +// int +// be_visitor_typecode_defn::visit_valuetype (be_valuetype *node) +// { +// switch (this->ctx_->sub_state ()) +// { +// case TAO_CodeGen::TAO_TC_DEFN_TYPECODE: +// return this->visit_type (node); +// case TAO_CodeGen::TAO_TC_DEFN_TYPECODE_NESTED: +// return this->gen_typecode (node); +// case TAO_CodeGen::TAO_TC_DEFN_ENCAPSULATION: +// return this->gen_encapsulation (node); +// case TAO_CodeGen::TAO_TC_DEFN_TC_SIZE: +// this->computed_tc_size_ = this->compute_tc_size (node); +// return ((this->computed_tc_size_ > 0) ? 0 : -1); +// case TAO_CodeGen::TAO_TC_DEFN_ENCAP_LEN: +// this->computed_encap_len_ = this->compute_encap_length (node); +// return ((this->computed_encap_len_ > 0) ? 0 : -1); +// case TAO_CodeGen::TAO_TC_DEFN_SCOPE: +// case TAO_CodeGen::TAO_TC_DEFN_SCOPE_LEN: +// return this->visit_members (node); +// default: +// // error +// break; +// } + +// ACE_ERROR_RETURN ((LM_ERROR, +// ACE_TEXT ("(%N:%l) be_visitor_typecode_defn::") +// ACE_TEXT ("visit - bad sub state ") +// ACE_TEXT ("in visitor context\n")), +// -1); +// } + +// int +// be_visitor_typecode_defn::visit_eventtype (be_eventtype *node) +// { +// return this->visit_valuetype (node); +// } + +// int +// be_visitor_typecode_defn::visit_union_branch (be_union_branch *node) +// { +// switch (this->ctx_->sub_state ()) +// { +// case TAO_CodeGen::TAO_TC_DEFN_SCOPE: +// return this->gen_encapsulation (node); +// case TAO_CodeGen::TAO_TC_DEFN_SCOPE_LEN: +// this->computed_encap_len_ = this->compute_encap_length (node); +// return ((this->computed_encap_len_ > 0) ? 0 : -1); +// default: +// // error +// break; +// } + +// ACE_ERROR_RETURN ((LM_ERROR, +// ACE_TEXT ("(%N:%l) be_visitor_typecode_defn::") +// ACE_TEXT ("visit - bad sub state ") +// ACE_TEXT ("in visitor context\n")), +// -1); +// } // methods that actually produce the typecode and the encapsulations @@ -933,7 +1024,7 @@ be_visitor_typecode_defn::gen_encapsulation (be_array *node) if (!bt) { ACE_ERROR_RETURN ((LM_ERROR, - "(%N:%l) be_array::gen_encapsulation - " + "(%N:%l) be_visitor_typecode_defn::gen_encapsulation - " "bad base type\n"), -1); } @@ -1006,1415 +1097,1415 @@ be_visitor_typecode_defn::gen_encapsulation (be_array *node) return 0; } -int -be_visitor_typecode_defn::gen_typecode (be_enum *node) -{ - TAO_OutStream *os = this->ctx_->stream (); - - os->indent (); - - // Check if we are repeated. - const be_visitor_typecode_defn::QNode *qnode = - this->queue_lookup (this->tc_queue_, node); - - if (qnode && be_global->opt_tc ())// encapsulation length) - { - // We are repeated, so we must generate an indirection here. - *os << "0xffffffff, // indirection" << be_nl; - this->tc_offset_ += sizeof (ACE_CDR::ULong); - - // The offset must point to the tc_kind value of the first occurrence of - // this type. - os->print ("0x%x, // negative offset (%d)\n", - (qnode->offset - this->tc_offset_), - (qnode->offset - this->tc_offset_)); - this->tc_offset_ += sizeof (ACE_CDR::ULong); - } - else - { - if (this->queue_insert (this->tc_queue_, node, this->tc_offset_) == 0) - { - ACE_ERROR_RETURN ((LM_ERROR, - "(%N:%l) be_visitor_typecode_defn::" - "visit_type - " - "queue insert failed\n"), - -1); - } - - *os << "CORBA::tk_enum, // typecode kind" << be_nl; - - // Size of the enum. - this->tc_offset_ += sizeof (ACE_CDR::ULong); - - { - Scoped_Compute_Queue_Guard guard (this); - - // Emit the encapsulation length. - this->ctx_->sub_state (TAO_CodeGen::TAO_TC_DEFN_ENCAP_LEN); - - if (node->accept (this) == -1) - { - ACE_ERROR_RETURN ((LM_ERROR, - ACE_TEXT ("(%N:%l) - be_visitor_typecode_defn") - ACE_TEXT ("gen_typecode (enum) - ") - ACE_TEXT ("Failed to get encap length\n")), - -1); - } - } - - *os << this->computed_encap_len_ << ", // encapsulation length" - << be_idt << "\n"; - - // Size of the encap length. - this->tc_offset_ += sizeof (ACE_CDR::ULong); - - // Now emit the encapsulation. - this->ctx_->sub_state (TAO_CodeGen::TAO_TC_DEFN_ENCAPSULATION); - - if (node->accept (this) == -1) - { - ACE_ERROR_RETURN ((LM_ERROR, - ACE_TEXT ("(%N:%l) be_visitor_typecode_defn") - ACE_TEXT ("::gen_typecode (enum) - ") - ACE_TEXT ("failed to generate encapsulation\n")), - -1); - } - - *os << be_uidt << "\n"; - } - - return 0; -} - -int -be_visitor_typecode_defn::gen_encapsulation (be_enum *node) -{ - TAO_OutStream *os = this->ctx_->stream (); // output stream - - *os << "TAO_ENCAP_BYTE_ORDER, // byte order" << be_nl; - // size of the encapsulation byte order flag. Although it is 1 byte, the - // aligned size is 4 bytes - this->tc_offset_ += sizeof (ACE_CDR::ULong); - - // generate repoID - this->gen_repoID (node); - - // generate name - this->gen_name (node); - - // generate the member count - *os << node->member_count () << ", // member count" << be_nl; - // size of the member length - this->tc_offset_ += sizeof (ACE_CDR::ULong); - - // hand over to the scope to generate the typecode for elements - this->ctx_->sub_state (TAO_CodeGen::TAO_TC_DEFN_SCOPE); - - if (node->accept (this) == -1) - { - ACE_ERROR_RETURN ((LM_ERROR, - ACE_TEXT ("(%N:%l) be_visitor_typecode_defn") - ACE_TEXT ("::gen_encapsulation (enum) - ") - ACE_TEXT ("cannot generate typecode for members\n")), - -1); - } - - return 0; -} - -int -be_visitor_typecode_defn::gen_encapsulation (be_enum_val *node) -{ - // generate name - this->gen_name (node); - - return 0; -} - -int -be_visitor_typecode_defn::gen_typecode (be_exception *node) -{ - TAO_OutStream *os = this->ctx_->stream (); // output stream - - // check if we are repeated - const be_visitor_typecode_defn::QNode *qnode = - this->queue_lookup (this->tc_queue_, node); - - if (qnode && be_global->opt_tc ()) - { - // we are repeated, so we must generate an indirection here - *os << "0xffffffff, // indirection" << be_nl; - this->tc_offset_ += sizeof (ACE_CDR::ULong); - // the offset must point to the tc_kind value of the first occurrence of - // this type - os->print ("0x%x, // negative offset (%d)\n", - (qnode->offset - this->tc_offset_), - (qnode->offset - this->tc_offset_)); - this->tc_offset_ += sizeof (ACE_CDR::ULong); - } - else - { - // Insert node into tc_queue_ in case the node is involved in - // some form of recursion. - if (this->queue_insert (this->tc_queue_, node, this->tc_offset_) == 0) - { - ACE_ERROR_RETURN ((LM_ERROR, - "(%N:%l) be_visitor_typecode_defn::" - "visit_type - " - "queue insert failed\n"), - -1); - } - - *os << "CORBA::tk_except, // typecode kind" << be_nl; - // size of the enum - this->tc_offset_ += sizeof (ACE_CDR::ULong); - - { - Scoped_Compute_Queue_Guard guard (this); - - // emit the encapsulation length - this->ctx_->sub_state (TAO_CodeGen::TAO_TC_DEFN_ENCAP_LEN); - if (node->accept (this) == -1) - { - ACE_ERROR_RETURN ((LM_ERROR, - ACE_TEXT ("(%N:%l) - be_visitor_typecode_defn") - ACE_TEXT ("gen_typecode (exception) - ") - ACE_TEXT ("Failed to get encap length\n")), - -1); - } - } - - *os << this->computed_encap_len_ << ", // encapsulation length" - << be_idt << "\n"; - // size of the encap length - this->tc_offset_ += sizeof (ACE_CDR::ULong); - - // now emit the encapsulation - this->ctx_->sub_state (TAO_CodeGen::TAO_TC_DEFN_ENCAPSULATION); - - if (node->accept (this) == -1) - { - ACE_ERROR_RETURN ((LM_ERROR, - ACE_TEXT ("(%N:%l) be_visitor_typecode_defn") - ACE_TEXT ("::gen_typecode (exception) - ") - ACE_TEXT ("failed to generate encapsulation\n")), - -1); - } - - *os << be_uidt << "\n"; - } - return 0; -} - -int -be_visitor_typecode_defn::gen_encapsulation (be_exception *node) -{ - TAO_OutStream *os = this->ctx_->stream (); // output stream - - os->indent (); // start from whatever indentation level we were at - - *os << "TAO_ENCAP_BYTE_ORDER, // byte order" << be_nl; - // size of the encapsulation byte order flag. Although it is 1 byte, the - // aligned size is 4 bytes - this->tc_offset_ += sizeof (ACE_CDR::ULong); - - // generate repoID - this->gen_repoID (node); - - // generate name - os->indent (); - this->gen_name (node); - - // generate the member count - *os << node->nfields () << ", // member count" << be_nl; - // size of the member count - this->tc_offset_ += sizeof (ACE_CDR::ULong); - - // hand over to the scope to generate the typecode for elements - this->ctx_->sub_state (TAO_CodeGen::TAO_TC_DEFN_SCOPE); - - // Set the scope node as "node" in which the code is being - // generated so that elements in the node's scope can use it - // for code generation. - this->ctx_->scope (node); - - if (node->accept (this) == -1) - { - ACE_ERROR_RETURN ((LM_ERROR, - ACE_TEXT ("(%N:%l) be_visitor_typecode_defn") - ACE_TEXT ("::gen_encapsulation (exception) - ") - ACE_TEXT ("cannot generate typecode for members\n")), - -1); - } - - return 0; -} - -int -be_visitor_typecode_defn::gen_encapsulation (be_field *node) -{ - TAO_OutStream *os = this->ctx_->stream (); // output stream - be_type *bt; // our type node - - os->indent (); // start from whatever indentation level we were at - - // generate name - this->gen_name (node); - - // hand over code generation to our type node - bt = be_type::narrow_from_decl (node->field_type ()); - this->ctx_->sub_state (TAO_CodeGen::TAO_TC_DEFN_TYPECODE_NESTED); - if (!bt || bt->accept (this) == -1) - { - ACE_ERROR_RETURN ((LM_ERROR, - ACE_TEXT ("(%N:%l) be_visitor_typecode_defn") - ACE_TEXT ("::gen_encapsulation (field) - ") - ACE_TEXT ("failed to generate typecode\n")), - -1); - } - // revert the state to what it was before because we may be dealing with - // subsequent fields for which we have to be in the "gen scope" - // substate - this->ctx_->sub_state (TAO_CodeGen::TAO_TC_DEFN_SCOPE); - - if (node->visibility() != AST_Field::vis_NA) - { - // generate visibility marker - - // Even though visibility marker is UShort it seems that - // it would always be aligned on ULong boundary. - ACE_CDR::ULong visibility = - node->visibility() == AST_Field::vis_PRIVATE ? 0 : 1; - - os->indent (); // start from current indentation level - *os << visibility << ", // data member visibility marker" - << "\n\n"; - - this->tc_offset_ += sizeof (ACE_CDR::ULong); - } - - return 0; -} - -int -be_visitor_typecode_defn::gen_typecode (be_interface *node) -{ - TAO_OutStream *os = this->ctx_->stream (); // output stream +// int +// be_visitor_typecode_defn::gen_typecode (be_enum *node) +// { +// TAO_OutStream *os = this->ctx_->stream (); + +// os->indent (); + +// // Check if we are repeated. +// const be_visitor_typecode_defn::QNode *qnode = +// this->queue_lookup (this->tc_queue_, node); + +// if (qnode && be_global->opt_tc ())// encapsulation length) +// { +// // We are repeated, so we must generate an indirection here. +// *os << "0xffffffff, // indirection" << be_nl; +// this->tc_offset_ += sizeof (ACE_CDR::ULong); + +// // The offset must point to the tc_kind value of the first occurrence of +// // this type. +// os->print ("0x%x, // negative offset (%ld)\n", +// (qnode->offset - this->tc_offset_), +// (qnode->offset - this->tc_offset_)); +// this->tc_offset_ += sizeof (ACE_CDR::ULong); +// } +// else +// { +// if (this->queue_insert (this->tc_queue_, node, this->tc_offset_) == 0) +// { +// ACE_ERROR_RETURN ((LM_ERROR, +// "(%N:%l) be_visitor_typecode_defn::" +// "visit_type - " +// "queue insert failed\n"), +// -1); +// } + +// *os << "CORBA::tk_enum, // typecode kind" << be_nl; + +// // Size of the enum. +// this->tc_offset_ += sizeof (ACE_CDR::ULong); + +// { +// Scoped_Compute_Queue_Guard guard (this); + +// // Emit the encapsulation length. +// this->ctx_->sub_state (TAO_CodeGen::TAO_TC_DEFN_ENCAP_LEN); + +// if (node->accept (this) == -1) +// { +// ACE_ERROR_RETURN ((LM_ERROR, +// ACE_TEXT ("(%N:%l) - be_visitor_typecode_defn") +// ACE_TEXT ("gen_typecode (enum) - ") +// ACE_TEXT ("Failed to get encap length\n")), +// -1); +// } +// } + +// *os << this->computed_encap_len_ << ", // encapsulation length" +// << be_idt << "\n"; + +// // Size of the encap length. +// this->tc_offset_ += sizeof (ACE_CDR::ULong); + +// // Now emit the encapsulation. +// this->ctx_->sub_state (TAO_CodeGen::TAO_TC_DEFN_ENCAPSULATION); + +// if (node->accept (this) == -1) +// { +// ACE_ERROR_RETURN ((LM_ERROR, +// ACE_TEXT ("(%N:%l) be_visitor_typecode_defn") +// ACE_TEXT ("::gen_typecode (enum) - ") +// ACE_TEXT ("failed to generate encapsulation\n")), +// -1); +// } + +// *os << be_uidt << "\n"; +// } + +// return 0; +// } + +// int +// be_visitor_typecode_defn::gen_encapsulation (be_enum *node) +// { +// TAO_OutStream *os = this->ctx_->stream (); // output stream + +// *os << "TAO_ENCAP_BYTE_ORDER, // byte order" << be_nl; +// // size of the encapsulation byte order flag. Although it is 1 byte, the +// // aligned size is 4 bytes +// this->tc_offset_ += sizeof (ACE_CDR::ULong); + +// // generate repoID +// this->gen_repoID (node); + +// // generate name +// this->gen_name (node); + +// // generate the member count +// *os << node->member_count () << ", // member count" << be_nl; +// // size of the member length +// this->tc_offset_ += sizeof (ACE_CDR::ULong); + +// // hand over to the scope to generate the typecode for elements +// this->ctx_->sub_state (TAO_CodeGen::TAO_TC_DEFN_SCOPE); + +// if (node->accept (this) == -1) +// { +// ACE_ERROR_RETURN ((LM_ERROR, +// ACE_TEXT ("(%N:%l) be_visitor_typecode_defn") +// ACE_TEXT ("::gen_encapsulation (enum) - ") +// ACE_TEXT ("cannot generate typecode for members\n")), +// -1); +// } + +// return 0; +// } + +// int +// be_visitor_typecode_defn::gen_encapsulation (be_enum_val *node) +// { +// // generate name +// this->gen_name (node); + +// return 0; +// } + +// int +// be_visitor_typecode_defn::gen_typecode (be_exception *node) +// { +// TAO_OutStream *os = this->ctx_->stream (); // output stream + +// // check if we are repeated +// const be_visitor_typecode_defn::QNode *qnode = +// this->queue_lookup (this->tc_queue_, node); + +// if (qnode && be_global->opt_tc ()) +// { +// // we are repeated, so we must generate an indirection here +// *os << "0xffffffff, // indirection" << be_nl; +// this->tc_offset_ += sizeof (ACE_CDR::ULong); +// // the offset must point to the tc_kind value of the first occurrence of +// // this type +// os->print ("0x%x, // negative offset (%ld)\n", +// (qnode->offset - this->tc_offset_), +// (qnode->offset - this->tc_offset_)); +// this->tc_offset_ += sizeof (ACE_CDR::ULong); +// } +// else +// { +// // Insert node into tc_queue_ in case the node is involved in +// // some form of recursion. +// if (this->queue_insert (this->tc_queue_, node, this->tc_offset_) == 0) +// { +// ACE_ERROR_RETURN ((LM_ERROR, +// "(%N:%l) be_visitor_typecode_defn::" +// "visit_type - " +// "queue insert failed\n"), +// -1); +// } + +// *os << "CORBA::tk_except, // typecode kind" << be_nl; +// // size of the enum +// this->tc_offset_ += sizeof (ACE_CDR::ULong); + +// { +// Scoped_Compute_Queue_Guard guard (this); + +// // emit the encapsulation length +// this->ctx_->sub_state (TAO_CodeGen::TAO_TC_DEFN_ENCAP_LEN); +// if (node->accept (this) == -1) +// { +// ACE_ERROR_RETURN ((LM_ERROR, +// ACE_TEXT ("(%N:%l) - be_visitor_typecode_defn") +// ACE_TEXT ("gen_typecode (exception) - ") +// ACE_TEXT ("Failed to get encap length\n")), +// -1); +// } +// } + +// *os << this->computed_encap_len_ << ", // encapsulation length" +// << be_idt << "\n"; +// // size of the encap length +// this->tc_offset_ += sizeof (ACE_CDR::ULong); + +// // now emit the encapsulation +// this->ctx_->sub_state (TAO_CodeGen::TAO_TC_DEFN_ENCAPSULATION); + +// if (node->accept (this) == -1) +// { +// ACE_ERROR_RETURN ((LM_ERROR, +// ACE_TEXT ("(%N:%l) be_visitor_typecode_defn") +// ACE_TEXT ("::gen_typecode (exception) - ") +// ACE_TEXT ("failed to generate encapsulation\n")), +// -1); +// } + +// *os << be_uidt << "\n"; +// } +// return 0; +// } + +// int +// be_visitor_typecode_defn::gen_encapsulation (be_exception *node) +// { +// TAO_OutStream *os = this->ctx_->stream (); // output stream + +// os->indent (); // start from whatever indentation level we were at + +// *os << "TAO_ENCAP_BYTE_ORDER, // byte order" << be_nl; +// // size of the encapsulation byte order flag. Although it is 1 byte, the +// // aligned size is 4 bytes +// this->tc_offset_ += sizeof (ACE_CDR::ULong); + +// // generate repoID +// this->gen_repoID (node); + +// // generate name +// os->indent (); +// this->gen_name (node); + +// // generate the member count +// *os << node->nfields () << ", // member count" << be_nl; +// // size of the member count +// this->tc_offset_ += sizeof (ACE_CDR::ULong); + +// // hand over to the scope to generate the typecode for elements +// this->ctx_->sub_state (TAO_CodeGen::TAO_TC_DEFN_SCOPE); + +// // Set the scope node as "node" in which the code is being +// // generated so that elements in the node's scope can use it +// // for code generation. +// this->ctx_->scope (node); + +// if (node->accept (this) == -1) +// { +// ACE_ERROR_RETURN ((LM_ERROR, +// ACE_TEXT ("(%N:%l) be_visitor_typecode_defn") +// ACE_TEXT ("::gen_encapsulation (exception) - ") +// ACE_TEXT ("cannot generate typecode for members\n")), +// -1); +// } + +// return 0; +// } + +// int +// be_visitor_typecode_defn::gen_encapsulation (be_field *node) +// { +// TAO_OutStream *os = this->ctx_->stream (); // output stream +// be_type *bt; // our type node + +// os->indent (); // start from whatever indentation level we were at + +// // generate name +// this->gen_name (node); + +// // hand over code generation to our type node +// bt = be_type::narrow_from_decl (node->field_type ()); +// this->ctx_->sub_state (TAO_CodeGen::TAO_TC_DEFN_TYPECODE_NESTED); +// if (!bt || bt->accept (this) == -1) +// { +// ACE_ERROR_RETURN ((LM_ERROR, +// ACE_TEXT ("(%N:%l) be_visitor_typecode_defn") +// ACE_TEXT ("::gen_encapsulation (field) - ") +// ACE_TEXT ("failed to generate typecode\n")), +// -1); +// } +// // revert the state to what it was before because we may be dealing with +// // subsequent fields for which we have to be in the "gen scope" +// // substate +// this->ctx_->sub_state (TAO_CodeGen::TAO_TC_DEFN_SCOPE); + +// if (node->visibility() != AST_Field::vis_NA) +// { +// // generate visibility marker + +// // Even though visibility marker is UShort it seems that +// // it would always be aligned on ULong boundary. +// ACE_CDR::ULong visibility = +// node->visibility() == AST_Field::vis_PRIVATE ? 0 : 1; + +// os->indent (); // start from current indentation level +// *os << visibility << ", // data member visibility marker" +// << "\n\n"; + +// this->tc_offset_ += sizeof (ACE_CDR::ULong); +// } + +// return 0; +// } + +// int +// be_visitor_typecode_defn::gen_typecode (be_interface *node) +// { +// TAO_OutStream *os = this->ctx_->stream (); // output stream + +// os->indent (); // start from whatever indentation level we were at + +// // check if we are repeated +// const be_visitor_typecode_defn::QNode *qnode = +// this->queue_lookup (this->tc_queue_, node); + +// if (qnode && be_global->opt_tc ()) +// { +// // we are repeated, so we must generate an indirection here +// *os << "0xffffffff, // indirection" << be_nl; +// this->tc_offset_ += sizeof (ACE_CDR::ULong); +// // the offset must point to the tc_kind value of the first occurrence of +// // this type +// os->print ("0x%x, // negative offset (%ld)\n", +// (qnode->offset - this->tc_offset_), +// (qnode->offset - this->tc_offset_)); +// this->tc_offset_ += sizeof (ACE_CDR::ULong); +// } +// else +// { +// if (this->queue_insert (this->tc_queue_, node, this->tc_offset_) == 0) +// { +// ACE_ERROR_RETURN ((LM_ERROR, +// "(%N:%l) be_visitor_typecode_defn::" +// "visit_type - " +// "queue insert failed\n"), +// -1); +// } + +// *os << "CORBA::tk_objref, // typecode kind" << be_nl; +// // size of the enum +// this->tc_offset_ += sizeof (ACE_CDR::ULong); + +// { +// Scoped_Compute_Queue_Guard guard (this); + +// // emit the encapsulation length +// this->ctx_->sub_state (TAO_CodeGen::TAO_TC_DEFN_ENCAP_LEN); +// if (node->accept (this) == -1) +// { +// ACE_ERROR_RETURN ((LM_ERROR, +// ACE_TEXT ("(%N:%l) - be_visitor_typecode_defn") +// ACE_TEXT ("gen_typecode (interface) - ") +// ACE_TEXT ("Failed to get encap length\n")), +// -1); +// } +// } + +// *os << this->computed_encap_len_ << ", // encapsulation length" +// << be_idt << "\n"; +// // size of the encap length +// this->tc_offset_ += sizeof (ACE_CDR::ULong); + +// // now emit the encapsulation +// this->ctx_->sub_state (TAO_CodeGen::TAO_TC_DEFN_ENCAPSULATION); +// if (node->accept (this) == -1) +// { +// ACE_ERROR_RETURN ((LM_ERROR, +// ACE_TEXT ("(%N:%l) be_visitor_typecode_defn") +// ACE_TEXT ("::gen_typecode (interface) - ") +// ACE_TEXT ("failed to generate encapsulation\n")), +// -1); +// } +// *os << be_uidt << "\n"; +// } +// return 0; +// } + +// int +// be_visitor_typecode_defn::gen_encapsulation (be_interface *node) +// { +// TAO_OutStream *os = this->ctx_->stream (); // output stream + +// os->indent (); // start from whatever indentation level we were at + +// *os << "TAO_ENCAP_BYTE_ORDER, // byte order" << be_nl; +// // size of the encapsulation byte order flag. Although it is 1 byte, the +// // aligned size is 4 bytes +// this->tc_offset_ += sizeof (ACE_CDR::ULong); + +// // generate repoID. +// this->gen_repoID (node); + +// // generate name. +// os->indent (); +// this->gen_name (node); + +// return 0; +// } + +// int +// be_visitor_typecode_defn::gen_typecode (be_interface_fwd *) +// { +// // nothing to do here +// return 0; +// } + +// int +// be_visitor_typecode_defn::gen_encapsulation (be_interface_fwd *) +// { +// // nothing to be done +// return 0; +// } + +// int +// be_visitor_typecode_defn::gen_typecode (be_predefined_type *node) +// { +// TAO_OutStream *os = this->ctx_->stream (); // output stream + +// os->indent (); // start from the current indentation level + +// // size of the enum +// this->tc_offset_ += sizeof (ACE_CDR::ULong); +// switch (node->pt ()) +// { +// case AST_PredefinedType::PT_void: +// *os << "CORBA::tk_void,\n\n"; +// break; +// case AST_PredefinedType::PT_short: +// *os << "CORBA::tk_short,\n\n"; +// break; +// case AST_PredefinedType::PT_ushort: +// *os << "CORBA::tk_ushort,\n\n"; +// break; +// case AST_PredefinedType::PT_long: +// *os << "CORBA::tk_long,\n\n"; +// break; +// case AST_PredefinedType::PT_ulong: +// *os << "CORBA::tk_ulong,\n\n"; +// break; +// case AST_PredefinedType::PT_longlong: +// *os << "CORBA::tk_longlong,\n\n"; +// break; +// case AST_PredefinedType::PT_ulonglong: +// *os << "CORBA::tk_ulonglong,\n\n"; +// break; +// case AST_PredefinedType::PT_float: +// *os << "CORBA::tk_float,\n\n"; +// break; +// case AST_PredefinedType::PT_double: +// *os << "CORBA::tk_double,\n\n"; +// break; +// case AST_PredefinedType::PT_longdouble: +// *os << "CORBA::tk_longdouble,\n\n"; +// break; +// case AST_PredefinedType::PT_boolean: +// *os << "CORBA::tk_boolean,\n\n"; +// break; +// case AST_PredefinedType::PT_char: +// *os << "CORBA::tk_char,\n\n"; +// break; +// case AST_PredefinedType::PT_octet: +// *os << "CORBA::tk_octet,\n\n"; +// break; +// case AST_PredefinedType::PT_any: +// *os << "CORBA::tk_any,\n\n"; +// break; +// case AST_PredefinedType::PT_wchar: +// *os << "CORBA::tk_wchar,\n\n"; +// break; +// case AST_PredefinedType::PT_object: +// { +// // Check if we are repeated. +// const be_visitor_typecode_defn::QNode *qnode = +// this->queue_lookup (this->tc_queue_, node); + +// if (qnode) +// { +// // we are repeated, so we must generate an indirection here +// *os << "0xffffffff, // indirection" << be_nl; +// this->tc_offset_ += sizeof (ACE_CDR::ULong); +// // the offset must point to the tc_kind value of the first occurrence of +// // this type +// os->print ("0x%x, // negative offset (%ld)\n", +// (qnode->offset - this->tc_offset_), +// (qnode->offset - this->tc_offset_)); +// this->tc_offset_ += sizeof (ACE_CDR::ULong); +// } +// else +// { +// // Insert node into tc_queue_ in case the node is involved in +// // some form of recursion. +// if (this->queue_insert (this->tc_queue_, +// node, +// this->tc_offset_) == 0) +// { +// ACE_ERROR_RETURN ((LM_ERROR, +// "(%N:%l) be_visitor_typecode_defn::" +// "visit_type - " +// "queue insert failed\n"), +// -1); +// } + +// *os << "CORBA::tk_objref," << be_nl; + +// { +// Scoped_Compute_Queue_Guard guard (this); + +// // emit the encapsulation length +// this->ctx_->sub_state (TAO_CodeGen::TAO_TC_DEFN_ENCAP_LEN); +// if (node->accept (this) == -1) +// { +// ACE_ERROR_RETURN (( +// LM_ERROR, +// ACE_TEXT ("(%N:%l) - be_visitor_typecode_defn") +// ACE_TEXT ("gen_typecode (predefined) - ") +// ACE_TEXT ("Failed to get encap length\n")), -1); +// } +// } + +// *os << this->computed_encap_len_ +// << ", // encapsulation length" << be_idt << "\n"; +// // size of the encap length +// this->tc_offset_ += sizeof (ACE_CDR::ULong); + +// // now emit the encapsulation +// this->ctx_->sub_state (TAO_CodeGen::TAO_TC_DEFN_ENCAPSULATION); +// if (node->accept (this) == -1) +// { +// ACE_ERROR_RETURN ((LM_ERROR, +// ACE_TEXT ("(%N:%l) be_visitor_typecode_defn") +// ACE_TEXT ("::gen_typecode (predefined objref)") +// ACE_TEXT (" - failed to generate ") +// ACE_TEXT ("encapsulation\n")), +// -1); +// } + +// *os << be_uidt << "\n"; +// } + +// break; +// } +// case AST_PredefinedType::PT_pseudo: +// *os << "CORBA::tk_TypeCode,\n\n"; +// break; +// default: +// break; +// } + +// return 0; +// } + +// int +// be_visitor_typecode_defn::gen_encapsulation (be_predefined_type *node) +// { +// // this one is valid only for "Object" +// if (!ACE_OS::strcmp (node->local_name ()->get_string (), "Object")) +// { +// TAO_OutStream *os = this->ctx_->stream (); // output stream + +// os->indent (); // start from whatever indentation level we were at + +// *os << "TAO_ENCAP_BYTE_ORDER, // byte order" << be_nl; +// // size of the encapsulation byte order flag. Although it is 1 byte, the +// // aligned size is 4 bytes +// this->tc_offset_ += sizeof (ACE_CDR::ULong); + +// // generate repoID +// this->gen_repoID (node); + +// // generate name +// os->indent (); +// this->gen_name (node); +// } +// return 0; +// } + +// int +// be_visitor_typecode_defn::gen_typecode (be_sequence *node) +// { +// TAO_OutStream *os = this->ctx_->stream (); // output stream + +// os->indent (); // start from whatever indentation level we were at + +// // no typecode optimization for anonymous sequences + +// *os << "CORBA::tk_sequence, // typecode kind" << be_nl; +// // size of the enum +// this->tc_offset_ += sizeof (ACE_CDR::ULong); + +// { +// Scoped_Compute_Queue_Guard guard (this); + +// // emit the encapsulation length +// this->ctx_->sub_state (TAO_CodeGen::TAO_TC_DEFN_ENCAP_LEN); + +// if (node->accept (this) == -1) +// { +// ACE_ERROR_RETURN ((LM_ERROR, +// ACE_TEXT ("(%N:%l) - be_visitor_typecode_defn") +// ACE_TEXT ("gen_typecode (sequence) - ") +// ACE_TEXT ("Failed to get encap length\n")), +// -1); +// } +// } + +// *os << this->computed_encap_len_ << ", // encapsulation length" +// << be_idt << "\n"; +// // size of the encap length +// this->tc_offset_ += sizeof (ACE_CDR::ULong); + +// // now emit the encapsulation +// this->ctx_->sub_state (TAO_CodeGen::TAO_TC_DEFN_ENCAPSULATION); + +// if (node->accept (this) == -1) +// { +// ACE_ERROR_RETURN ((LM_ERROR, +// ACE_TEXT ("(%N:%l) be_visitor_typecode_defn") +// ACE_TEXT ("::gen_typecode (sequence) - ") +// ACE_TEXT ("failed to generate encapsulation\n")), +// -1); +// } + +// *os << be_uidt << "\n"; + +// return 0; +// } + +// int +// be_visitor_typecode_defn::gen_encapsulation (be_sequence *node) +// { +// TAO_OutStream *os = this->ctx_->stream (); // output stream +// be_type *bt; // base type + +// os->indent (); +// *os << "TAO_ENCAP_BYTE_ORDER, // byte order\n"; +// // size of the encapsulation byte order flag. Although it is 1 byte, the +// // aligned size is 4 bytes +// this->tc_offset_ += sizeof (ACE_CDR::ULong); + +// // emit typecode of element type +// bt = be_type::narrow_from_decl (node->base_type ()); +// this->ctx_->sub_state (TAO_CodeGen::TAO_TC_DEFN_TYPECODE_NESTED); + +// if (!bt || bt->accept (this) == -1) +// { +// ACE_ERROR_RETURN ((LM_ERROR, +// ACE_TEXT ("(%N:%l) be_visitor_typecode_defn") +// ACE_TEXT ("::gen_encapsulation (sequence) - ") +// ACE_TEXT ("failed to generate typecode\n")), +// -1); +// } + +// // emit the sequence bounds (0 if unbounded) +// os->indent (); +// *os << node->max_size () << ",\n"; +// // size of the bound length +// this->tc_offset_ += sizeof (ACE_CDR::ULong); +// return 0; +// } + +// int +// be_visitor_typecode_defn::gen_typecode (be_string *node) +// { +// TAO_OutStream *os = this->ctx_->stream (); // output stream + +// // no typecode optimizations for anonymous strings + +// os->indent (); // start from the current indentation level + +// // emit the enumeration +// if (node->width () == (long) sizeof (char)) +// { +// *os << "CORBA::tk_string, " << be_nl; +// } +// else +// { +// *os << "CORBA::tk_wstring, " << be_nl; +// } + +// // size of the enum +// this->tc_offset_ += sizeof (ACE_CDR::ULong); + +// // emit the string bounds (0 if unbounded) +// *os << node->max_size () << ", // string length\n"; +// // size of the bounds +// this->tc_offset_ += sizeof (ACE_CDR::ULong); + +// return 0; +// } + +// int +// be_visitor_typecode_defn::gen_encapsulation (be_string *) +// { +// // nothing to be done here +// return 0; +// } + +// int +// be_visitor_typecode_defn::gen_typecode (be_structure *node) +// { +// TAO_OutStream *os = this->ctx_->stream (); // output stream + +// os->indent (); // start from whatever indentation level we were at + +// // check if we are repeated +// const be_visitor_typecode_defn::QNode *qnode = +// this->queue_lookup (this->tc_queue_, node); + +// ACE_Unbounded_Queue<AST_Type *> list; + +// if (qnode && (be_global->opt_tc () || node->in_recursion (list))) +// { +// // we are repeated, so we must generate an indirection here +// *os << "0xffffffff, // indirection" << be_nl; +// this->tc_offset_ += sizeof (ACE_CDR::ULong); +// // the offset must point to the tc_kind value of the first occurrence of +// // this type +// os->print ("0x%x, // negative offset (%ld)\n", +// (qnode->offset - this->tc_offset_), +// (qnode->offset - this->tc_offset_)); +// this->tc_offset_ += sizeof (ACE_CDR::ULong); +// } +// else +// { +// // Insert node into tc_queue_ in case the node is involved in +// // some form of recursion. +// if (this->queue_insert (this->tc_queue_, node, this->tc_offset_) == 0) +// { +// ACE_ERROR_RETURN ((LM_ERROR, +// "(%N:%l) be_visitor_typecode_defn::" +// "visit_type - " +// "queue insert failed\n"), +// -1); +// } + +// *os << "CORBA::tk_struct, // typecode kind" << be_nl; +// // size of the enum +// this->tc_offset_ += sizeof (ACE_CDR::ULong); + +// { +// Scoped_Compute_Queue_Guard guard (this); + +// // emit the encapsulation length +// this->ctx_->sub_state (TAO_CodeGen::TAO_TC_DEFN_ENCAP_LEN); +// if (node->accept (this) == -1) +// { +// ACE_ERROR_RETURN ((LM_ERROR, +// ACE_TEXT ("(%N:%l) - be_visitor_typecode_defn") +// ACE_TEXT ("gen_typecode (struct) - ") +// ACE_TEXT ("Failed to get encap length\n")), +// -1); +// } +// } + +// *os << this->computed_encap_len_ << ", // encapsulation length" +// << be_idt << "\n"; +// // size of the encap length +// this->tc_offset_ += sizeof (ACE_CDR::ULong); + +// // now emit the encapsulation +// this->ctx_->sub_state (TAO_CodeGen::TAO_TC_DEFN_ENCAPSULATION); +// if (node->accept (this) == -1) +// { +// ACE_ERROR_RETURN ((LM_ERROR, +// ACE_TEXT ("(%N:%l) be_visitor_typecode_defn") +// ACE_TEXT ("::gen_typecode (structure) - ") +// ACE_TEXT ("failed to generate encapsulation\n")), +// -1); +// } +// *os << be_uidt << "\n"; +// } +// return 0; +// } + +// int +// be_visitor_typecode_defn::gen_encapsulation (be_structure *node) +// { +// TAO_OutStream *os = this->ctx_->stream (); // output stream + +// os->indent (); // start from whatever indentation level we were at + +// *os << "TAO_ENCAP_BYTE_ORDER, // byte order" << be_nl; +// // size of the encapsulation byte order flag. Although it is 1 byte, the +// // aligned size is 4 bytes +// this->tc_offset_ += sizeof (ACE_CDR::ULong); + +// // generate repoID +// this->gen_repoID (node); + +// // generate name +// os->indent (); +// this->gen_name (node); + +// // generate the member count +// *os << node->nfields () << ", // member count" << be_nl; +// // size of the member count +// this->tc_offset_ += sizeof (ACE_CDR::ULong); + +// // hand over to the scope to generate the typecode for elements +// this->ctx_->sub_state (TAO_CodeGen::TAO_TC_DEFN_SCOPE); + +// if (node->accept (this) == -1) +// { +// ACE_ERROR ((LM_ERROR, "be_structure: cannot generate typecode for members\n")); +// return -1; +// } + +// return 0; +// } + +// int +// be_visitor_typecode_defn::gen_typecode (be_typedef *node) +// { +// TAO_OutStream *os = this->ctx_->stream (); // output stream + +// os->indent (); // start from whatever indentation level we were at + +// // check if we are repeated +// const be_visitor_typecode_defn::QNode *qnode = +// this->queue_lookup (this->tc_queue_, node); + +// if (qnode && be_global->opt_tc ()) +// { +// // we are repeated, so we must generate an indirection here +// *os << "0xffffffff, // indirection" << be_nl; +// this->tc_offset_ += sizeof (ACE_CDR::ULong); +// // the offset must point to the tc_kind value of the first occurrence of +// // this type +// os->print ("0x%x, // negative offset (%ld)\n", +// (qnode->offset - this->tc_offset_), +// (qnode->offset - this->tc_offset_)); +// this->tc_offset_ += sizeof (ACE_CDR::ULong); +// } +// else +// { +// // Insert node into tc_queue_ in case the node is involved in +// // some form of recursion. +// if (this->queue_insert (this->tc_queue_, node, this->tc_offset_) == 0) +// { +// ACE_ERROR_RETURN ((LM_ERROR, +// "(%N:%l) be_visitor_typecode_defn::" +// "visit_type - " +// "queue insert failed\n"), +// -1); +// } + +// *os << "CORBA::tk_alias, // typecode kind for typedefs" << be_nl; +// // size of the enum +// this->tc_offset_ += sizeof (ACE_CDR::ULong); + +// { +// Scoped_Compute_Queue_Guard guard (this); + +// // emit the encapsulation length +// this->ctx_->sub_state (TAO_CodeGen::TAO_TC_DEFN_ENCAP_LEN); + +// if (node->accept (this) == -1) +// { +// ACE_ERROR_RETURN ((LM_ERROR, +// ACE_TEXT ("(%N:%l) - be_visitor_typecode_defn") +// ACE_TEXT ("gen_typecode (typedef) - ") +// ACE_TEXT ("Failed to get encap length\n")), +// -1); +// } +// } + +// *os << this->computed_encap_len_ << ", // encapsulation length" +// << be_idt << "\n"; +// // size of the encap length +// this->tc_offset_ += sizeof (ACE_CDR::ULong); + +// // now emit the encapsulation +// this->ctx_->sub_state (TAO_CodeGen::TAO_TC_DEFN_ENCAPSULATION); + +// if (node->accept (this) == -1) +// { +// ACE_ERROR_RETURN ((LM_ERROR, +// ACE_TEXT ("(%N:%l) be_visitor_typecode_defn") +// ACE_TEXT ("::gen_typecode (typedef) - ") +// ACE_TEXT ("failed to generate encapsulation\n")), +// -1); +// } + +// *os << be_uidt << "\n"; +// } +// return 0; +// } + +// int +// be_visitor_typecode_defn::gen_encapsulation (be_typedef *node) +// { +// TAO_OutStream *os = this->ctx_->stream (); // output stream +// be_type *bt; // base type + +// os->indent (); // start from whatever indentation level we were at + +// *os << "TAO_ENCAP_BYTE_ORDER, // byte order" << be_nl; +// // size of the encapsulation byte order flag. Although it is 1 byte, the +// // aligned size is 4 bytes +// this->tc_offset_ += sizeof (ACE_CDR::ULong); + +// // generate repoID +// this->gen_repoID (node); + +// // generate name +// os->indent (); +// this->gen_name (node); + +// // generate typecode for the base type +// bt = be_type::narrow_from_decl (node->base_type ()); +// this->ctx_->sub_state (TAO_CodeGen::TAO_TC_DEFN_TYPECODE_NESTED); + +// if (!bt || bt->accept (this) == -1) +// { +// ACE_ERROR_RETURN ((LM_ERROR, +// ACE_TEXT ("(%N:%l) be_visitor_typecode_defn") +// ACE_TEXT ("::gen_encapsulation (typedef) - ") +// ACE_TEXT ("failed to generate typecode\n")), +// -1); +// } + +// return 0; +// } + +// int +// be_visitor_typecode_defn::gen_typecode (be_union *node) +// { +// TAO_OutStream *os = this->ctx_->stream (); // output stream + +// os->indent (); // start from whatever indentation level we were at + +// // check if we are repeated +// const be_visitor_typecode_defn::QNode *qnode = +// this->queue_lookup (this->tc_queue_, node); + +// ACE_Unbounded_Queue<AST_Type *> list; + +// if (qnode && (be_global->opt_tc () || node->in_recursion (list))) +// { +// // we are repeated, so we must generate an indirection here +// *os << "0xffffffff, // indirection" << be_nl; +// this->tc_offset_ += sizeof (ACE_CDR::ULong); +// // the offset must point to the tc_kind value of the first occurrence of +// // this type +// os->print ("0x%x, // negative offset (%d)\n", +// (qnode->offset - this->tc_offset_), +// (qnode->offset - this->tc_offset_)); +// this->tc_offset_ += sizeof (ACE_CDR::ULong); +// } +// else +// { +// // Insert node into tc_queue_ in case the node is involved in +// // some form of recursion. +// if (this->queue_insert (this->tc_queue_, node, this->tc_offset_) == 0) +// { +// ACE_ERROR_RETURN ((LM_ERROR, +// "(%N:%l) be_visitor_typecode_defn::" +// "visit_type - " +// "queue insert failed\n"), +// -1); +// } + +// *os << "CORBA::tk_union, // typecode kind" << be_nl; +// // size of the enum +// this->tc_offset_ += sizeof (ACE_CDR::ULong); + +// { +// Scoped_Compute_Queue_Guard guard (this); + +// // emit the encapsulation length +// this->ctx_->sub_state (TAO_CodeGen::TAO_TC_DEFN_ENCAP_LEN); + +// if (node->accept (this) == -1) +// { +// ACE_ERROR_RETURN ((LM_ERROR, +// ACE_TEXT ("(%N:%l) - be_visitor_typecode_defn") +// ACE_TEXT ("gen_typecode (union) - ") +// ACE_TEXT ("Failed to get encap length\n")), +// -1); +// } +// } + +// *os << this->computed_encap_len_ << ", // encapsulation length" +// << be_idt << "\n"; +// // size of the encap length +// this->tc_offset_ += sizeof (ACE_CDR::ULong); + +// // now emit the encapsulation +// this->ctx_->sub_state (TAO_CodeGen::TAO_TC_DEFN_ENCAPSULATION); + +// if (node->accept (this) == -1) +// { +// ACE_ERROR_RETURN ((LM_ERROR, +// ACE_TEXT ("(%N:%l) be_visitor_typecode_defn") +// ACE_TEXT ("::gen_typecode (union) - ") +// ACE_TEXT ("failed to generate encapsulation\n")), +// -1); +// } + +// *os << be_uidt << "\n"; +// } +// return 0; +// } + +// int +// be_visitor_typecode_defn::gen_encapsulation (be_union *node) +// { +// TAO_OutStream *os = this->ctx_->stream (); // output stream +// be_type *discrim; + +// os->indent (); // start from whatever indentation level we were at + +// *os << "TAO_ENCAP_BYTE_ORDER, // byte order" << be_nl; +// // size of the encapsulation byte order flag. Although it is 1 byte, the +// // aligned size is 4 bytes +// this->tc_offset_ += sizeof (ACE_CDR::ULong); + +// // generate repoID +// this->gen_repoID (node); + +// // generate name +// this->gen_name (node); + +// // generate typecode for discriminant +// discrim = be_type::narrow_from_decl (node->disc_type ()); +// this->ctx_->sub_state (TAO_CodeGen::TAO_TC_DEFN_TYPECODE_NESTED); + +// if (discrim->accept (this) == -1) +// { +// ACE_ERROR ((LM_ERROR, "be_union: cannot generate typecode for discriminant\n")); +// return -1; +// } + +// // generate the default used flag +// *os << node->default_index () << ", // default used index" << be_nl; +// // size of the default index used +// this->tc_offset_ += sizeof (ACE_CDR::ULong); + +// // generate the member count +// *os << node->nfields () << ", // member count" << be_nl; +// // size of the member count +// this->tc_offset_ += sizeof (ACE_CDR::ULong); + +// // hand over to the scope to generate the typecode for elements +// this->ctx_->sub_state (TAO_CodeGen::TAO_TC_DEFN_SCOPE); + +// // Set the scope node as "node" in which the code is being +// // generated so that elements in the node's scope can use it +// // for code generation. +// this->ctx_->scope (node); + +// if (node->accept (this) == -1) +// { +// ACE_ERROR ((LM_ERROR, "be_union: cannot generate code for members\n")); +// return -1; +// } + +// return 0; +// } + +// int +// be_visitor_typecode_defn::gen_encapsulation (be_union_branch *node) +// { +// TAO_OutStream *os = this->ctx_->stream (); // output stream +// be_type *bt; // our type node + +// be_union *ub = this->ctx_->be_scope_as_union (); + +// ACE_UINT32 buf[1]; +// ACE_OS::memset (buf, 0, sizeof (buf)); + +// os->indent (); + +// // Emit the case label value. We use only the first value in the +// // label list even if there are multiple case labels for this node. +// // The TypeCode class does not have any way of dealing with +// // any count but member count. We make sure in the generation of +// // the union's _discriminant(0 function (called by (de)marshaling +// // code) that the same value is returned that is generated here. +// if (node->label (0)->label_kind () == AST_UnionLabel::UL_label) +// { +// AST_Expression *expression = node->label (0)->label_val (); +// AST_Expression::AST_ExprValue *ev = expression->ev (); + +// switch (ub->udisc_type ()) +// { +// case AST_Expression::EV_char: +// os->print ("ACE_IDL_NCTOHL (0x%02.2x)", +// (unsigned char)ev->u.cval); +// // size of char aligned to 4 bytes +// this->tc_offset_ += sizeof (ACE_CDR::ULong); +// break; + +// case AST_Expression::EV_bool: +// os->print ("ACE_IDL_NCTOHL (0x%02.2x)", +// (unsigned char)ev->u.bval); +// // size of bool aligned to 4 bytes +// this->tc_offset_ += sizeof (ACE_CDR::ULong); +// break; + +// case AST_Expression::EV_wchar: +// case AST_Expression::EV_short: +// os->print ("ACE_IDL_NSTOHL (0x%04.4x)", +// (unsigned short)ev->u.sval); +// // size of short/wchar aligned to 4 bytes +// this->tc_offset_ += sizeof (ACE_CDR::ULong); +// break; + +// case AST_Expression::EV_ushort: +// os->print ("ACE_IDL_NSTOHL (0x%04.4x)", +// (unsigned short)ev->u.usval); +// // size of unsigned short aligned to 4 bytes +// this->tc_offset_ += sizeof (ACE_CDR::ULong); +// break; + +// case AST_Expression::EV_long: +// os->print ("0x%08.8x", (unsigned long)ev->u.lval); +// // size of long aligned to 4 bytes +// this->tc_offset_ += sizeof (ACE_CDR::ULong); +// break; + +// case AST_Expression::EV_ulong: +// os->print ("0x%08.8x", ev->u.ulval); +// // size of unsigned long aligned to 4 bytes +// this->tc_offset_ += sizeof (ACE_CDR::ULong); +// break; + +// case AST_Expression::EV_enum: +// // enum +// os->print ("0x%08.8x", (unsigned long)ev->u.eval); +// // size of any aligned to 4 bytes +// this->tc_offset_ += sizeof (ACE_CDR::ULong); +// break; + +// case AST_Expression::EV_ulonglong: +// case AST_Expression::EV_longlong: +// // unimplemented yet + +// default: +// ACE_ERROR_RETURN ((LM_DEBUG, +// "be_union_branch: (%N:%l) Label value " +// "type (%d) is invalid\n", ev->et), -1); +// ACE_NOTREACHED (break;) +// } + +// *os << ", // union case label (evaluated value)" << be_nl; +// } +// else +// { +// // default case +// be_union::DefaultValue dv; + +// if (ub->default_value (dv) == -1) +// { +// ACE_ERROR_RETURN ((LM_ERROR, +// "(%N:%l) be_visitor_typecode::" +// "gen_encapsulation (union_branch) - " +// "computing default value failed\n"), +// -1); +// } + +// switch (ub->udisc_type ()) +// { +// case AST_Expression::EV_char: +// os->print ("ACE_IDL_NCTOHL (0x%02.2x)", +// (unsigned char)dv.u.char_val); +// // size of bool/char aligned to 4 bytes +// this->tc_offset_ += sizeof (ACE_CDR::ULong); +// break; + +// case AST_Expression::EV_bool: +// os->print ("ACE_IDL_NCTOHL (0x%02.2x)", +// (unsigned char)dv.u.bool_val); +// // size of bool/char aligned to 4 bytes +// this->tc_offset_ += sizeof (ACE_CDR::ULong); +// break; + +// case AST_Expression::EV_wchar: +// os->print ("ACE_IDL_NSTOHL (0x%04.4x)", +// (unsigned short)dv.u.wchar_val); +// // size of short/wchar aligned to 4 bytes +// this->tc_offset_ += sizeof (ACE_CDR::ULong); +// break; + +// case AST_Expression::EV_short: +// os->print ("ACE_IDL_NSTOHL (0x%04.4x)", +// (unsigned short)dv.u.short_val); +// // size of short/wchar aligned to 4 bytes +// this->tc_offset_ += sizeof (ACE_CDR::ULong); +// break; + +// case AST_Expression::EV_ushort: +// os->print ("ACE_IDL_NSTOHL (0x%04.4x)", +// (unsigned short)dv.u.ushort_val); +// // size of short/wchar aligned to 4 bytes +// this->tc_offset_ += sizeof (ACE_CDR::ULong); +// break; + +// case AST_Expression::EV_long: +// os->print ("0x%08.8x", (unsigned long)dv.u.long_val); +// // size of short/wchar aligned to 4 bytes +// this->tc_offset_ += sizeof (ACE_CDR::ULong); +// break; + +// case AST_Expression::EV_ulong: +// os->print ("0x%08.8x", (unsigned long)dv.u.ulong_val); +// // size of short/wchar aligned to 4 bytes +// this->tc_offset_ += sizeof (ACE_CDR::ULong); +// break; + +// case AST_Expression::EV_enum: +// // enum +// os->print ("0x%08.8x", (unsigned long)dv.u.enum_val); +// // size of short/wchar aligned to 4 bytes +// this->tc_offset_ += sizeof (ACE_CDR::ULong); +// break; + +// case AST_Expression::EV_ulonglong: +// case AST_Expression::EV_longlong: +// // unimplemented yet + +// default: +// ACE_ERROR_RETURN ((LM_DEBUG, +// "be_union_branch: (%N:%l) Label value " +// "type (%d) is invalid\n", +// ub->udisc_type ()), +// -1); +// ACE_NOTREACHED (break;) +// } + +// *os << ", // union default label (evaluated value)" << be_nl; +// } + +// // emit name +// this->gen_name (node); + +// // hand over code generation to our type node +// bt = be_type::narrow_from_decl (node->field_type ()); +// this->ctx_->sub_state (TAO_CodeGen::TAO_TC_DEFN_TYPECODE_NESTED); + +// if (!bt || bt->accept (this) == -1) +// { +// ACE_ERROR_RETURN ((LM_ERROR, +// ACE_TEXT ("(%N:%l) be_visitor_typecode_defn") +// ACE_TEXT ("::gen_encapsulation (union_branch) - ") +// ACE_TEXT ("failed to generate typecode\n") +// ), +// -1); +// } + +// // revert the state +// this->ctx_->sub_state (TAO_CodeGen::TAO_TC_DEFN_SCOPE); +// return 0; +// } + +// int +// be_visitor_typecode_defn::gen_typecode (be_valuetype *node) +// { +// TAO_OutStream *os = this->ctx_->stream (); // output stream + +// os->indent (); // start from whatever indentation level we were at + +// // check if we are repeated +// const be_visitor_typecode_defn::QNode *qnode = +// this->queue_lookup (this->tc_queue_, node); + +// ACE_Unbounded_Queue<AST_Type *> list; + +// if (qnode && (be_global->opt_tc () || node->in_recursion (list))) +// { +// // we are repeated, so we must generate an indirection here +// *os << "0xffffffff, // indirection" << be_nl; +// this->tc_offset_ += sizeof (ACE_CDR::ULong); +// // the offset must point to the tc_kind value of the first occurrence of +// // this type +// os->print ("0x%x, // negative offset (%ld)\n", +// (qnode->offset - this->tc_offset_), +// (qnode->offset - this->tc_offset_)); +// this->tc_offset_ += sizeof (ACE_CDR::ULong); +// } +// else +// { +// // Insert node into tc_queue_ in case the node is involved in +// // some form of recursion. +// if (this->queue_insert (this->tc_queue_, +// node, +// this->tc_offset_) == 0) +// { +// ACE_ERROR_RETURN ((LM_ERROR, +// "(%N:%l) be_visitor_typecode_defn::" +// "visit_type - " +// "queue insert failed\n"), +// -1); +// } + +// *os << "CORBA::tk_value, // typecode kind" << be_nl; +// // size of the enum +// this->tc_offset_ += sizeof (ACE_CDR::ULong); + +// { +// Scoped_Compute_Queue_Guard guard (this); + +// // emit the encapsulation length +// this->ctx_->sub_state (TAO_CodeGen::TAO_TC_DEFN_ENCAP_LEN); + +// if (node->accept (this) == -1) +// { +// ACE_ERROR_RETURN ((LM_ERROR, +// ACE_TEXT ("(%N:%l) - be_visitor_typecode_defn") +// ACE_TEXT ("gen_typecode (valuetype) - ") +// ACE_TEXT ("Failed to get encap length\n")), +// -1); +// } +// } + +// *os << this->computed_encap_len_ << ", // encapsulation length" +// << be_idt << "\n"; +// // size of the encap length +// this->tc_offset_ += sizeof (ACE_CDR::ULong); + +// // now emit the encapsulation +// this->ctx_->sub_state (TAO_CodeGen::TAO_TC_DEFN_ENCAPSULATION); + +// if (node->accept (this) == -1) +// { +// ACE_ERROR_RETURN ((LM_ERROR, +// ACE_TEXT ("(%N:%l) be_visitor_typecode_defn") +// ACE_TEXT ("::gen_typecode (valuetype) - ") +// ACE_TEXT ("failed to generate encapsulation\n")), +// -1); +// } + +// *os << be_uidt << "\n"; +// } + +// return 0; +// } + +// int +// be_visitor_typecode_defn::gen_encapsulation (be_valuetype *node) +// { +// TAO_OutStream *os = this->ctx_->stream (); // output stream + +// os->indent (); // start from whatever indentation level we were at + +// *os << "TAO_ENCAP_BYTE_ORDER, // byte order" << be_nl; +// // size of the encapsulation byte order flag. Although it is 1 byte, the +// // aligned size is 4 bytes +// this->tc_offset_ += sizeof (ACE_CDR::ULong); + +// // STEP 1: generate repoID +// this->gen_repoID (node); + +// // STEP 2: generate name +// os->indent (); +// this->gen_name (node); + +// // STEP 3: generate ValueModifier + +// // By spec ValueModifier is UShort but aligned size +// // seems always to be 4. +// os->indent (); + +// // TAO doesn't support neither CUSTOM nor TRUNCATABLE +// // valuetypes. So basically need to choose between +// // VM_NONE = 0 and VM_ABSTRACT = 2 +// ACE_CDR::ULong value_modifier = node->is_abstract () ? 2 : 0; + +// *os << value_modifier << ", // value modifier" << "\n"; + +// this->tc_offset_ += sizeof (ACE_CDR::ULong); + +// //STEP 4: generate TypeCode of concrete base + +// AST_ValueType *concrete_inherited = node->inherits_concrete (); + +// if (concrete_inherited != 0) +// { +// // Got non-abstract base valuetype. Now emit its typecode +// be_valuetype *vt = be_valuetype::narrow_from_decl(concrete_inherited); +// this->ctx_->sub_state (TAO_CodeGen::TAO_TC_DEFN_TYPECODE_NESTED); + +// if (!vt || vt->accept (this) == -1) +// { +// ACE_ERROR_RETURN ((LM_ERROR, +// ACE_TEXT ("(%N:%l) be_visitor_typecode_defn") +// ACE_TEXT ("::gen_encapsulation (valuetype) - ") +// ACE_TEXT ("failed to generate typecode\n")), +// -1); +// } + +// // revert the state to what it was before +// this->ctx_->sub_state (TAO_CodeGen::TAO_TC_DEFN_SCOPE); +// } +// else +// { +// // emit tk_null +// os->indent (); +// *os << "CORBA::tk_null, // no stateful base valuetype" +// << "\n\n"; + +// // size of the enum +// this->tc_offset_ += sizeof (ACE_CDR::ULong); +// } + +// // STEP 5: generate the member count +// *os << node->data_members_count () << ", // member count" << be_nl; + +// // Size of the member count. +// this->tc_offset_ += sizeof (ACE_CDR::ULong); - os->indent (); // start from whatever indentation level we were at +// // STEP 6: hand over to the scope to generate the typecode for elements +// this->ctx_->sub_state (TAO_CodeGen::TAO_TC_DEFN_SCOPE); - // check if we are repeated - const be_visitor_typecode_defn::QNode *qnode = - this->queue_lookup (this->tc_queue_, node); +// if (node->accept (this) == -1) +// { +// ACE_ERROR_RETURN(( +// LM_ERROR, +// "be_valuetype: cannot generate typecode for members\n"), -1); +// } - if (qnode && be_global->opt_tc ()) - { - // we are repeated, so we must generate an indirection here - *os << "0xffffffff, // indirection" << be_nl; - this->tc_offset_ += sizeof (ACE_CDR::ULong); - // the offset must point to the tc_kind value of the first occurrence of - // this type - os->print ("0x%x, // negative offset (%d)\n", - (qnode->offset - this->tc_offset_), - (qnode->offset - this->tc_offset_)); - this->tc_offset_ += sizeof (ACE_CDR::ULong); - } - else - { - if (this->queue_insert (this->tc_queue_, node, this->tc_offset_) == 0) - { - ACE_ERROR_RETURN ((LM_ERROR, - "(%N:%l) be_visitor_typecode_defn::" - "visit_type - " - "queue insert failed\n"), - -1); - } - - *os << "CORBA::tk_objref, // typecode kind" << be_nl; - // size of the enum - this->tc_offset_ += sizeof (ACE_CDR::ULong); - - { - Scoped_Compute_Queue_Guard guard (this); - - // emit the encapsulation length - this->ctx_->sub_state (TAO_CodeGen::TAO_TC_DEFN_ENCAP_LEN); - if (node->accept (this) == -1) - { - ACE_ERROR_RETURN ((LM_ERROR, - ACE_TEXT ("(%N:%l) - be_visitor_typecode_defn") - ACE_TEXT ("gen_typecode (interface) - ") - ACE_TEXT ("Failed to get encap length\n")), - -1); - } - } - - *os << this->computed_encap_len_ << ", // encapsulation length" - << be_idt << "\n"; - // size of the encap length - this->tc_offset_ += sizeof (ACE_CDR::ULong); - - // now emit the encapsulation - this->ctx_->sub_state (TAO_CodeGen::TAO_TC_DEFN_ENCAPSULATION); - if (node->accept (this) == -1) - { - ACE_ERROR_RETURN ((LM_ERROR, - ACE_TEXT ("(%N:%l) be_visitor_typecode_defn") - ACE_TEXT ("::gen_typecode (interface) - ") - ACE_TEXT ("failed to generate encapsulation\n")), - -1); - } - *os << be_uidt << "\n"; - } - return 0; -} - -int -be_visitor_typecode_defn::gen_encapsulation (be_interface *node) -{ - TAO_OutStream *os = this->ctx_->stream (); // output stream - - os->indent (); // start from whatever indentation level we were at - - *os << "TAO_ENCAP_BYTE_ORDER, // byte order" << be_nl; - // size of the encapsulation byte order flag. Although it is 1 byte, the - // aligned size is 4 bytes - this->tc_offset_ += sizeof (ACE_CDR::ULong); - - // generate repoID. - this->gen_repoID (node); - - // generate name. - os->indent (); - this->gen_name (node); - - return 0; -} - -int -be_visitor_typecode_defn::gen_typecode (be_interface_fwd *) -{ - // nothing to do here - return 0; -} - -int -be_visitor_typecode_defn::gen_encapsulation (be_interface_fwd *) -{ - // nothing to be done - return 0; -} - -int -be_visitor_typecode_defn::gen_typecode (be_predefined_type *node) -{ - TAO_OutStream *os = this->ctx_->stream (); // output stream - - os->indent (); // start from the current indentation level - - // size of the enum - this->tc_offset_ += sizeof (ACE_CDR::ULong); - switch (node->pt ()) - { - case AST_PredefinedType::PT_void: - *os << "CORBA::tk_void,\n\n"; - break; - case AST_PredefinedType::PT_short: - *os << "CORBA::tk_short,\n\n"; - break; - case AST_PredefinedType::PT_ushort: - *os << "CORBA::tk_ushort,\n\n"; - break; - case AST_PredefinedType::PT_long: - *os << "CORBA::tk_long,\n\n"; - break; - case AST_PredefinedType::PT_ulong: - *os << "CORBA::tk_ulong,\n\n"; - break; - case AST_PredefinedType::PT_longlong: - *os << "CORBA::tk_longlong,\n\n"; - break; - case AST_PredefinedType::PT_ulonglong: - *os << "CORBA::tk_ulonglong,\n\n"; - break; - case AST_PredefinedType::PT_float: - *os << "CORBA::tk_float,\n\n"; - break; - case AST_PredefinedType::PT_double: - *os << "CORBA::tk_double,\n\n"; - break; - case AST_PredefinedType::PT_longdouble: - *os << "CORBA::tk_longdouble,\n\n"; - break; - case AST_PredefinedType::PT_boolean: - *os << "CORBA::tk_boolean,\n\n"; - break; - case AST_PredefinedType::PT_char: - *os << "CORBA::tk_char,\n\n"; - break; - case AST_PredefinedType::PT_octet: - *os << "CORBA::tk_octet,\n\n"; - break; - case AST_PredefinedType::PT_any: - *os << "CORBA::tk_any,\n\n"; - break; - case AST_PredefinedType::PT_wchar: - *os << "CORBA::tk_wchar,\n\n"; - break; - case AST_PredefinedType::PT_object: - { - // Check if we are repeated. - const be_visitor_typecode_defn::QNode *qnode = - this->queue_lookup (this->tc_queue_, node); - - if (qnode) - { - // we are repeated, so we must generate an indirection here - *os << "0xffffffff, // indirection" << be_nl; - this->tc_offset_ += sizeof (ACE_CDR::ULong); - // the offset must point to the tc_kind value of the first occurrence of - // this type - os->print ("0x%x, // negative offset (%d)\n", - (qnode->offset - this->tc_offset_), - (qnode->offset - this->tc_offset_)); - this->tc_offset_ += sizeof (ACE_CDR::ULong); - } - else - { - // Insert node into tc_queue_ in case the node is involved in - // some form of recursion. - if (this->queue_insert (this->tc_queue_, - node, - this->tc_offset_) == 0) - { - ACE_ERROR_RETURN ((LM_ERROR, - "(%N:%l) be_visitor_typecode_defn::" - "visit_type - " - "queue insert failed\n"), - -1); - } - - *os << "CORBA::tk_objref," << be_nl; - - { - Scoped_Compute_Queue_Guard guard (this); - - // emit the encapsulation length - this->ctx_->sub_state (TAO_CodeGen::TAO_TC_DEFN_ENCAP_LEN); - if (node->accept (this) == -1) - { - ACE_ERROR_RETURN (( - LM_ERROR, - ACE_TEXT ("(%N:%l) - be_visitor_typecode_defn") - ACE_TEXT ("gen_typecode (predefined) - ") - ACE_TEXT ("Failed to get encap length\n")), -1); - } - } - - *os << this->computed_encap_len_ - << ", // encapsulation length" << be_idt << "\n"; - // size of the encap length - this->tc_offset_ += sizeof (ACE_CDR::ULong); - - // now emit the encapsulation - this->ctx_->sub_state (TAO_CodeGen::TAO_TC_DEFN_ENCAPSULATION); - if (node->accept (this) == -1) - { - ACE_ERROR_RETURN ((LM_ERROR, - ACE_TEXT ("(%N:%l) be_visitor_typecode_defn") - ACE_TEXT ("::gen_typecode (predefined objref)") - ACE_TEXT (" - failed to generate ") - ACE_TEXT ("encapsulation\n")), - -1); - } - - *os << be_uidt << "\n"; - } - - break; - } - case AST_PredefinedType::PT_pseudo: - *os << "CORBA::tk_TypeCode,\n\n"; - break; - default: - break; - } - - return 0; -} - -int -be_visitor_typecode_defn::gen_encapsulation (be_predefined_type *node) -{ - // this one is valid only for "Object" - if (!ACE_OS::strcmp (node->local_name ()->get_string (), "Object")) - { - TAO_OutStream *os = this->ctx_->stream (); // output stream - - os->indent (); // start from whatever indentation level we were at - - *os << "TAO_ENCAP_BYTE_ORDER, // byte order" << be_nl; - // size of the encapsulation byte order flag. Although it is 1 byte, the - // aligned size is 4 bytes - this->tc_offset_ += sizeof (ACE_CDR::ULong); - - // generate repoID - this->gen_repoID (node); - - // generate name - os->indent (); - this->gen_name (node); - } - return 0; -} - -int -be_visitor_typecode_defn::gen_typecode (be_sequence *node) -{ - TAO_OutStream *os = this->ctx_->stream (); // output stream - - os->indent (); // start from whatever indentation level we were at - - // no typecode optimization for anonymous sequences - - *os << "CORBA::tk_sequence, // typecode kind" << be_nl; - // size of the enum - this->tc_offset_ += sizeof (ACE_CDR::ULong); - - { - Scoped_Compute_Queue_Guard guard (this); - - // emit the encapsulation length - this->ctx_->sub_state (TAO_CodeGen::TAO_TC_DEFN_ENCAP_LEN); - - if (node->accept (this) == -1) - { - ACE_ERROR_RETURN ((LM_ERROR, - ACE_TEXT ("(%N:%l) - be_visitor_typecode_defn") - ACE_TEXT ("gen_typecode (sequence) - ") - ACE_TEXT ("Failed to get encap length\n")), - -1); - } - } - - *os << this->computed_encap_len_ << ", // encapsulation length" - << be_idt << "\n"; - // size of the encap length - this->tc_offset_ += sizeof (ACE_CDR::ULong); - - // now emit the encapsulation - this->ctx_->sub_state (TAO_CodeGen::TAO_TC_DEFN_ENCAPSULATION); - - if (node->accept (this) == -1) - { - ACE_ERROR_RETURN ((LM_ERROR, - ACE_TEXT ("(%N:%l) be_visitor_typecode_defn") - ACE_TEXT ("::gen_typecode (sequence) - ") - ACE_TEXT ("failed to generate encapsulation\n")), - -1); - } - - *os << be_uidt << "\n"; - - return 0; -} - -int -be_visitor_typecode_defn::gen_encapsulation (be_sequence *node) -{ - TAO_OutStream *os = this->ctx_->stream (); // output stream - be_type *bt; // base type - - os->indent (); - *os << "TAO_ENCAP_BYTE_ORDER, // byte order\n"; - // size of the encapsulation byte order flag. Although it is 1 byte, the - // aligned size is 4 bytes - this->tc_offset_ += sizeof (ACE_CDR::ULong); - - // emit typecode of element type - bt = be_type::narrow_from_decl (node->base_type ()); - this->ctx_->sub_state (TAO_CodeGen::TAO_TC_DEFN_TYPECODE_NESTED); - - if (!bt || bt->accept (this) == -1) - { - ACE_ERROR_RETURN ((LM_ERROR, - ACE_TEXT ("(%N:%l) be_visitor_typecode_defn") - ACE_TEXT ("::gen_encapsulation (sequence) - ") - ACE_TEXT ("failed to generate typecode\n")), - -1); - } - - // emit the sequence bounds (0 if unbounded) - os->indent (); - *os << node->max_size () << ",\n"; - // size of the bound length - this->tc_offset_ += sizeof (ACE_CDR::ULong); - return 0; -} - -int -be_visitor_typecode_defn::gen_typecode (be_string *node) -{ - TAO_OutStream *os = this->ctx_->stream (); // output stream - - // no typecode optimizations for anonymous strings - - os->indent (); // start from the current indentation level - - // emit the enumeration - if (node->width () == (long) sizeof (char)) - { - *os << "CORBA::tk_string, " << be_nl; - } - else - { - *os << "CORBA::tk_wstring, " << be_nl; - } - - // size of the enum - this->tc_offset_ += sizeof (ACE_CDR::ULong); - - // emit the string bounds (0 if unbounded) - *os << node->max_size () << ", // string length\n"; - // size of the bounds - this->tc_offset_ += sizeof (ACE_CDR::ULong); - - return 0; -} - -int -be_visitor_typecode_defn::gen_encapsulation (be_string *) -{ - // nothing to be done here - return 0; -} - -int -be_visitor_typecode_defn::gen_typecode (be_structure *node) -{ - TAO_OutStream *os = this->ctx_->stream (); // output stream - - os->indent (); // start from whatever indentation level we were at - - // check if we are repeated - const be_visitor_typecode_defn::QNode *qnode = - this->queue_lookup (this->tc_queue_, node); - - ACE_Unbounded_Queue<AST_Type *> list; - - if (qnode && (be_global->opt_tc () || node->in_recursion (list))) - { - // we are repeated, so we must generate an indirection here - *os << "0xffffffff, // indirection" << be_nl; - this->tc_offset_ += sizeof (ACE_CDR::ULong); - // the offset must point to the tc_kind value of the first occurrence of - // this type - os->print ("0x%x, // negative offset (%d)\n", - (qnode->offset - this->tc_offset_), - (qnode->offset - this->tc_offset_)); - this->tc_offset_ += sizeof (ACE_CDR::ULong); - } - else - { - // Insert node into tc_queue_ in case the node is involved in - // some form of recursion. - if (this->queue_insert (this->tc_queue_, node, this->tc_offset_) == 0) - { - ACE_ERROR_RETURN ((LM_ERROR, - "(%N:%l) be_visitor_typecode_defn::" - "visit_type - " - "queue insert failed\n"), - -1); - } - - *os << "CORBA::tk_struct, // typecode kind" << be_nl; - // size of the enum - this->tc_offset_ += sizeof (ACE_CDR::ULong); - - { - Scoped_Compute_Queue_Guard guard (this); - - // emit the encapsulation length - this->ctx_->sub_state (TAO_CodeGen::TAO_TC_DEFN_ENCAP_LEN); - if (node->accept (this) == -1) - { - ACE_ERROR_RETURN ((LM_ERROR, - ACE_TEXT ("(%N:%l) - be_visitor_typecode_defn") - ACE_TEXT ("gen_typecode (struct) - ") - ACE_TEXT ("Failed to get encap length\n")), - -1); - } - } - - *os << this->computed_encap_len_ << ", // encapsulation length" - << be_idt << "\n"; - // size of the encap length - this->tc_offset_ += sizeof (ACE_CDR::ULong); - - // now emit the encapsulation - this->ctx_->sub_state (TAO_CodeGen::TAO_TC_DEFN_ENCAPSULATION); - if (node->accept (this) == -1) - { - ACE_ERROR_RETURN ((LM_ERROR, - ACE_TEXT ("(%N:%l) be_visitor_typecode_defn") - ACE_TEXT ("::gen_typecode (structure) - ") - ACE_TEXT ("failed to generate encapsulation\n")), - -1); - } - *os << be_uidt << "\n"; - } - return 0; -} - -int -be_visitor_typecode_defn::gen_encapsulation (be_structure *node) -{ - TAO_OutStream *os = this->ctx_->stream (); // output stream - - os->indent (); // start from whatever indentation level we were at - - *os << "TAO_ENCAP_BYTE_ORDER, // byte order" << be_nl; - // size of the encapsulation byte order flag. Although it is 1 byte, the - // aligned size is 4 bytes - this->tc_offset_ += sizeof (ACE_CDR::ULong); - - // generate repoID - this->gen_repoID (node); - - // generate name - os->indent (); - this->gen_name (node); - - // generate the member count - *os << node->nfields () << ", // member count" << be_nl; - // size of the member count - this->tc_offset_ += sizeof (ACE_CDR::ULong); - - // hand over to the scope to generate the typecode for elements - this->ctx_->sub_state (TAO_CodeGen::TAO_TC_DEFN_SCOPE); - - if (node->accept (this) == -1) - { - ACE_ERROR ((LM_ERROR, "be_structure: cannot generate typecode for members\n")); - return -1; - } - - return 0; -} - -int -be_visitor_typecode_defn::gen_typecode (be_typedef *node) -{ - TAO_OutStream *os = this->ctx_->stream (); // output stream - - os->indent (); // start from whatever indentation level we were at - - // check if we are repeated - const be_visitor_typecode_defn::QNode *qnode = - this->queue_lookup (this->tc_queue_, node); - - if (qnode && be_global->opt_tc ()) - { - // we are repeated, so we must generate an indirection here - *os << "0xffffffff, // indirection" << be_nl; - this->tc_offset_ += sizeof (ACE_CDR::ULong); - // the offset must point to the tc_kind value of the first occurrence of - // this type - os->print ("0x%x, // negative offset (%d)\n", - (qnode->offset - this->tc_offset_), - (qnode->offset - this->tc_offset_)); - this->tc_offset_ += sizeof (ACE_CDR::ULong); - } - else - { - // Insert node into tc_queue_ in case the node is involved in - // some form of recursion. - if (this->queue_insert (this->tc_queue_, node, this->tc_offset_) == 0) - { - ACE_ERROR_RETURN ((LM_ERROR, - "(%N:%l) be_visitor_typecode_defn::" - "visit_type - " - "queue insert failed\n"), - -1); - } - - *os << "CORBA::tk_alias, // typecode kind for typedefs" << be_nl; - // size of the enum - this->tc_offset_ += sizeof (ACE_CDR::ULong); - - { - Scoped_Compute_Queue_Guard guard (this); - - // emit the encapsulation length - this->ctx_->sub_state (TAO_CodeGen::TAO_TC_DEFN_ENCAP_LEN); - - if (node->accept (this) == -1) - { - ACE_ERROR_RETURN ((LM_ERROR, - ACE_TEXT ("(%N:%l) - be_visitor_typecode_defn") - ACE_TEXT ("gen_typecode (typedef) - ") - ACE_TEXT ("Failed to get encap length\n")), - -1); - } - } - - *os << this->computed_encap_len_ << ", // encapsulation length" - << be_idt << "\n"; - // size of the encap length - this->tc_offset_ += sizeof (ACE_CDR::ULong); - - // now emit the encapsulation - this->ctx_->sub_state (TAO_CodeGen::TAO_TC_DEFN_ENCAPSULATION); - - if (node->accept (this) == -1) - { - ACE_ERROR_RETURN ((LM_ERROR, - ACE_TEXT ("(%N:%l) be_visitor_typecode_defn") - ACE_TEXT ("::gen_typecode (typedef) - ") - ACE_TEXT ("failed to generate encapsulation\n")), - -1); - } - - *os << be_uidt << "\n"; - } - return 0; -} - -int -be_visitor_typecode_defn::gen_encapsulation (be_typedef *node) -{ - TAO_OutStream *os = this->ctx_->stream (); // output stream - be_type *bt; // base type - - os->indent (); // start from whatever indentation level we were at - - *os << "TAO_ENCAP_BYTE_ORDER, // byte order" << be_nl; - // size of the encapsulation byte order flag. Although it is 1 byte, the - // aligned size is 4 bytes - this->tc_offset_ += sizeof (ACE_CDR::ULong); - - // generate repoID - this->gen_repoID (node); - - // generate name - os->indent (); - this->gen_name (node); - - // generate typecode for the base type - bt = be_type::narrow_from_decl (node->base_type ()); - this->ctx_->sub_state (TAO_CodeGen::TAO_TC_DEFN_TYPECODE_NESTED); - - if (!bt || bt->accept (this) == -1) - { - ACE_ERROR_RETURN ((LM_ERROR, - ACE_TEXT ("(%N:%l) be_visitor_typecode_defn") - ACE_TEXT ("::gen_encapsulation (typedef) - ") - ACE_TEXT ("failed to generate typecode\n")), - -1); - } - - return 0; -} - -int -be_visitor_typecode_defn::gen_typecode (be_union *node) -{ - TAO_OutStream *os = this->ctx_->stream (); // output stream - - os->indent (); // start from whatever indentation level we were at - - // check if we are repeated - const be_visitor_typecode_defn::QNode *qnode = - this->queue_lookup (this->tc_queue_, node); - - ACE_Unbounded_Queue<AST_Type *> list; - - if (qnode && (be_global->opt_tc () || node->in_recursion (list))) - { - // we are repeated, so we must generate an indirection here - *os << "0xffffffff, // indirection" << be_nl; - this->tc_offset_ += sizeof (ACE_CDR::ULong); - // the offset must point to the tc_kind value of the first occurrence of - // this type - os->print ("0x%x, // negative offset (%d)\n", - (qnode->offset - this->tc_offset_), - (qnode->offset - this->tc_offset_)); - this->tc_offset_ += sizeof (ACE_CDR::ULong); - } - else - { - // Insert node into tc_queue_ in case the node is involved in - // some form of recursion. - if (this->queue_insert (this->tc_queue_, node, this->tc_offset_) == 0) - { - ACE_ERROR_RETURN ((LM_ERROR, - "(%N:%l) be_visitor_typecode_defn::" - "visit_type - " - "queue insert failed\n"), - -1); - } - - *os << "CORBA::tk_union, // typecode kind" << be_nl; - // size of the enum - this->tc_offset_ += sizeof (ACE_CDR::ULong); - - { - Scoped_Compute_Queue_Guard guard (this); - - // emit the encapsulation length - this->ctx_->sub_state (TAO_CodeGen::TAO_TC_DEFN_ENCAP_LEN); - - if (node->accept (this) == -1) - { - ACE_ERROR_RETURN ((LM_ERROR, - ACE_TEXT ("(%N:%l) - be_visitor_typecode_defn") - ACE_TEXT ("gen_typecode (union) - ") - ACE_TEXT ("Failed to get encap length\n")), - -1); - } - } - - *os << this->computed_encap_len_ << ", // encapsulation length" - << be_idt << "\n"; - // size of the encap length - this->tc_offset_ += sizeof (ACE_CDR::ULong); - - // now emit the encapsulation - this->ctx_->sub_state (TAO_CodeGen::TAO_TC_DEFN_ENCAPSULATION); - - if (node->accept (this) == -1) - { - ACE_ERROR_RETURN ((LM_ERROR, - ACE_TEXT ("(%N:%l) be_visitor_typecode_defn") - ACE_TEXT ("::gen_typecode (union) - ") - ACE_TEXT ("failed to generate encapsulation\n")), - -1); - } - - *os << be_uidt << "\n"; - } - return 0; -} - -int -be_visitor_typecode_defn::gen_encapsulation (be_union *node) -{ - TAO_OutStream *os = this->ctx_->stream (); // output stream - be_type *discrim; - - os->indent (); // start from whatever indentation level we were at - - *os << "TAO_ENCAP_BYTE_ORDER, // byte order" << be_nl; - // size of the encapsulation byte order flag. Although it is 1 byte, the - // aligned size is 4 bytes - this->tc_offset_ += sizeof (ACE_CDR::ULong); - - // generate repoID - this->gen_repoID (node); - - // generate name - this->gen_name (node); - - // generate typecode for discriminant - discrim = be_type::narrow_from_decl (node->disc_type ()); - this->ctx_->sub_state (TAO_CodeGen::TAO_TC_DEFN_TYPECODE_NESTED); - - if (discrim->accept (this) == -1) - { - ACE_ERROR ((LM_ERROR, "be_union: cannot generate typecode for discriminant\n")); - return -1; - } - - // generate the default used flag - *os << node->default_index () << ", // default used index" << be_nl; - // size of the default index used - this->tc_offset_ += sizeof (ACE_CDR::ULong); - - // generate the member count - *os << node->nfields () << ", // member count" << be_nl; - // size of the member count - this->tc_offset_ += sizeof (ACE_CDR::ULong); - - // hand over to the scope to generate the typecode for elements - this->ctx_->sub_state (TAO_CodeGen::TAO_TC_DEFN_SCOPE); - - // Set the scope node as "node" in which the code is being - // generated so that elements in the node's scope can use it - // for code generation. - this->ctx_->scope (node); - - if (node->accept (this) == -1) - { - ACE_ERROR ((LM_ERROR, "be_union: cannot generate code for members\n")); - return -1; - } - - return 0; -} - -int -be_visitor_typecode_defn::gen_encapsulation (be_union_branch *node) -{ - TAO_OutStream *os = this->ctx_->stream (); // output stream - be_type *bt; // our type node - - be_union *ub = this->ctx_->be_scope_as_union (); - - ACE_UINT32 buf[1]; - ACE_OS::memset (buf, 0, sizeof (buf)); - - os->indent (); - - // Emit the case label value. We use only the first value in the - // label list even if there are multiple case labels for this node. - // The TypeCode class does not have any way of dealing with - // any count but member count. We make sure in the generation of - // the union's _discriminant(0 function (called by (de)marshaling - // code) that the same value is returned that is generated here. - if (node->label (0)->label_kind () == AST_UnionLabel::UL_label) - { - AST_Expression *expression = node->label (0)->label_val (); - AST_Expression::AST_ExprValue *ev = expression->ev (); - - switch (ub->udisc_type ()) - { - case AST_Expression::EV_char: - os->print ("ACE_IDL_NCTOHL (0x%02.2x)", - (unsigned char)ev->u.cval); - // size of char aligned to 4 bytes - this->tc_offset_ += sizeof (ACE_CDR::ULong); - break; - - case AST_Expression::EV_bool: - os->print ("ACE_IDL_NCTOHL (0x%02.2x)", - (unsigned char)ev->u.bval); - // size of bool aligned to 4 bytes - this->tc_offset_ += sizeof (ACE_CDR::ULong); - break; - - case AST_Expression::EV_wchar: - case AST_Expression::EV_short: - os->print ("ACE_IDL_NSTOHL (0x%04.4x)", - (unsigned short)ev->u.sval); - // size of short/wchar aligned to 4 bytes - this->tc_offset_ += sizeof (ACE_CDR::ULong); - break; - - case AST_Expression::EV_ushort: - os->print ("ACE_IDL_NSTOHL (0x%04.4x)", - (unsigned short)ev->u.usval); - // size of unsigned short aligned to 4 bytes - this->tc_offset_ += sizeof (ACE_CDR::ULong); - break; - - case AST_Expression::EV_long: - os->print ("0x%08.8x", (unsigned long)ev->u.lval); - // size of long aligned to 4 bytes - this->tc_offset_ += sizeof (ACE_CDR::ULong); - break; - - case AST_Expression::EV_ulong: - os->print ("0x%08.8x", ev->u.ulval); - // size of unsigned long aligned to 4 bytes - this->tc_offset_ += sizeof (ACE_CDR::ULong); - break; - - case AST_Expression::EV_enum: - // enum - os->print ("0x%08.8x", (unsigned long)ev->u.eval); - // size of any aligned to 4 bytes - this->tc_offset_ += sizeof (ACE_CDR::ULong); - break; - - case AST_Expression::EV_ulonglong: - case AST_Expression::EV_longlong: - // unimplemented yet - - default: - ACE_ERROR_RETURN ((LM_DEBUG, - "be_union_branch: (%N:%l) Label value " - "type (%d) is invalid\n", ev->et), -1); - ACE_NOTREACHED (break;) - } - - *os << ", // union case label (evaluated value)" << be_nl; - } - else - { - // default case - be_union::DefaultValue dv; - - if (ub->default_value (dv) == -1) - { - ACE_ERROR_RETURN ((LM_ERROR, - "(%N:%l) be_visitor_typecode::" - "gen_encapsulation (union_branch) - " - "computing default value failed\n"), - -1); - } - - switch (ub->udisc_type ()) - { - case AST_Expression::EV_char: - os->print ("ACE_IDL_NCTOHL (0x%02.2x)", - (unsigned char)dv.u.char_val); - // size of bool/char aligned to 4 bytes - this->tc_offset_ += sizeof (ACE_CDR::ULong); - break; - - case AST_Expression::EV_bool: - os->print ("ACE_IDL_NCTOHL (0x%02.2x)", - (unsigned char)dv.u.bool_val); - // size of bool/char aligned to 4 bytes - this->tc_offset_ += sizeof (ACE_CDR::ULong); - break; - - case AST_Expression::EV_wchar: - os->print ("ACE_IDL_NSTOHL (0x%04.4x)", - (unsigned short)dv.u.wchar_val); - // size of short/wchar aligned to 4 bytes - this->tc_offset_ += sizeof (ACE_CDR::ULong); - break; - - case AST_Expression::EV_short: - os->print ("ACE_IDL_NSTOHL (0x%04.4x)", - (unsigned short)dv.u.short_val); - // size of short/wchar aligned to 4 bytes - this->tc_offset_ += sizeof (ACE_CDR::ULong); - break; - - case AST_Expression::EV_ushort: - os->print ("ACE_IDL_NSTOHL (0x%04.4x)", - (unsigned short)dv.u.ushort_val); - // size of short/wchar aligned to 4 bytes - this->tc_offset_ += sizeof (ACE_CDR::ULong); - break; - - case AST_Expression::EV_long: - os->print ("0x%08.8x", (unsigned long)dv.u.long_val); - // size of short/wchar aligned to 4 bytes - this->tc_offset_ += sizeof (ACE_CDR::ULong); - break; - - case AST_Expression::EV_ulong: - os->print ("0x%08.8x", (unsigned long)dv.u.ulong_val); - // size of short/wchar aligned to 4 bytes - this->tc_offset_ += sizeof (ACE_CDR::ULong); - break; - - case AST_Expression::EV_enum: - // enum - os->print ("0x%08.8x", (unsigned long)dv.u.enum_val); - // size of short/wchar aligned to 4 bytes - this->tc_offset_ += sizeof (ACE_CDR::ULong); - break; - - case AST_Expression::EV_ulonglong: - case AST_Expression::EV_longlong: - // unimplemented yet - - default: - ACE_ERROR_RETURN ((LM_DEBUG, - "be_union_branch: (%N:%l) Label value " - "type (%d) is invalid\n", - ub->udisc_type ()), - -1); - ACE_NOTREACHED (break;) - } - - *os << ", // union default label (evaluated value)" << be_nl; - } - - // emit name - this->gen_name (node); - - // hand over code generation to our type node - bt = be_type::narrow_from_decl (node->field_type ()); - this->ctx_->sub_state (TAO_CodeGen::TAO_TC_DEFN_TYPECODE_NESTED); - - if (!bt || bt->accept (this) == -1) - { - ACE_ERROR_RETURN ((LM_ERROR, - ACE_TEXT ("(%N:%l) be_visitor_typecode_defn") - ACE_TEXT ("::gen_encapsulation (union_branch) - ") - ACE_TEXT ("failed to generate typecode\n") - ), - -1); - } - - // revert the state - this->ctx_->sub_state (TAO_CodeGen::TAO_TC_DEFN_SCOPE); - return 0; -} - -int -be_visitor_typecode_defn::gen_typecode (be_valuetype *node) -{ - TAO_OutStream *os = this->ctx_->stream (); // output stream - - os->indent (); // start from whatever indentation level we were at - - // check if we are repeated - const be_visitor_typecode_defn::QNode *qnode = - this->queue_lookup (this->tc_queue_, node); - - ACE_Unbounded_Queue<AST_Type *> list; - - if (qnode && (be_global->opt_tc () || node->in_recursion (list))) - { - // we are repeated, so we must generate an indirection here - *os << "0xffffffff, // indirection" << be_nl; - this->tc_offset_ += sizeof (ACE_CDR::ULong); - // the offset must point to the tc_kind value of the first occurrence of - // this type - os->print ("0x%x, // negative offset (%d)\n", - (qnode->offset - this->tc_offset_), - (qnode->offset - this->tc_offset_)); - this->tc_offset_ += sizeof (ACE_CDR::ULong); - } - else - { - // Insert node into tc_queue_ in case the node is involved in - // some form of recursion. - if (this->queue_insert (this->tc_queue_, - node, - this->tc_offset_) == 0) - { - ACE_ERROR_RETURN ((LM_ERROR, - "(%N:%l) be_visitor_typecode_defn::" - "visit_type - " - "queue insert failed\n"), - -1); - } - - *os << "CORBA::tk_value, // typecode kind" << be_nl; - // size of the enum - this->tc_offset_ += sizeof (ACE_CDR::ULong); - - { - Scoped_Compute_Queue_Guard guard (this); - - // emit the encapsulation length - this->ctx_->sub_state (TAO_CodeGen::TAO_TC_DEFN_ENCAP_LEN); - - if (node->accept (this) == -1) - { - ACE_ERROR_RETURN ((LM_ERROR, - ACE_TEXT ("(%N:%l) - be_visitor_typecode_defn") - ACE_TEXT ("gen_typecode (valuetype) - ") - ACE_TEXT ("Failed to get encap length\n")), - -1); - } - } - - *os << this->computed_encap_len_ << ", // encapsulation length" - << be_idt << "\n"; - // size of the encap length - this->tc_offset_ += sizeof (ACE_CDR::ULong); - - // now emit the encapsulation - this->ctx_->sub_state (TAO_CodeGen::TAO_TC_DEFN_ENCAPSULATION); - - if (node->accept (this) == -1) - { - ACE_ERROR_RETURN ((LM_ERROR, - ACE_TEXT ("(%N:%l) be_visitor_typecode_defn") - ACE_TEXT ("::gen_typecode (valuetype) - ") - ACE_TEXT ("failed to generate encapsulation\n")), - -1); - } - - *os << be_uidt << "\n"; - } - - return 0; -} - -int -be_visitor_typecode_defn::gen_encapsulation (be_valuetype *node) -{ - TAO_OutStream *os = this->ctx_->stream (); // output stream - - os->indent (); // start from whatever indentation level we were at - - *os << "TAO_ENCAP_BYTE_ORDER, // byte order" << be_nl; - // size of the encapsulation byte order flag. Although it is 1 byte, the - // aligned size is 4 bytes - this->tc_offset_ += sizeof (ACE_CDR::ULong); - - // STEP 1: generate repoID - this->gen_repoID (node); - - // STEP 2: generate name - os->indent (); - this->gen_name (node); - - // STEP 3: generate ValueModifier - - // By spec ValueModifier is UShort but aligned size - // seems always to be 4. - os->indent (); - - // TAO doesn't support neither CUSTOM nor TRUNCATABLE - // valuetypes. So basically need to choose between - // VM_NONE = 0 and VM_ABSTRACT = 2 - ACE_CDR::ULong value_modifier = node->is_abstract () ? 2 : 0; - - *os << value_modifier << ", // value modifier" << "\n"; - - this->tc_offset_ += sizeof (ACE_CDR::ULong); - - //STEP 4: generate TypeCode of concrete base - - AST_ValueType *concrete_inherited = node->inherits_concrete (); - - if (concrete_inherited != 0) - { - // Got non-abstract base valuetype. Now emit its typecode - be_valuetype *vt = be_valuetype::narrow_from_decl(concrete_inherited); - this->ctx_->sub_state (TAO_CodeGen::TAO_TC_DEFN_TYPECODE_NESTED); - - if (!vt || vt->accept (this) == -1) - { - ACE_ERROR_RETURN ((LM_ERROR, - ACE_TEXT ("(%N:%l) be_visitor_typecode_defn") - ACE_TEXT ("::gen_encapsulation (valuetype) - ") - ACE_TEXT ("failed to generate typecode\n")), - -1); - } - - // revert the state to what it was before - this->ctx_->sub_state (TAO_CodeGen::TAO_TC_DEFN_SCOPE); - } - else - { - // emit tk_null - os->indent (); - *os << "CORBA::tk_null, // no stateful base valuetype" - << "\n\n"; - - // size of the enum - this->tc_offset_ += sizeof (ACE_CDR::ULong); - } - - // STEP 5: generate the member count - *os << node->data_members_count () << ", // member count" << be_nl; - - // Size of the member count. - this->tc_offset_ += sizeof (ACE_CDR::ULong); - - // STEP 6: hand over to the scope to generate the typecode for elements - this->ctx_->sub_state (TAO_CodeGen::TAO_TC_DEFN_SCOPE); - - if (node->accept (this) == -1) - { - ACE_ERROR_RETURN(( - LM_ERROR, - "be_valuetype: cannot generate typecode for members\n"), -1); - } - - return 0; -} +// return 0; +// } // = methods for computing typecode and encapsulation sizes @@ -2476,964 +2567,964 @@ be_visitor_typecode_defn::compute_encap_length (be_array *node) return this->computed_encap_len_; } -ACE_CDR::Long -be_visitor_typecode_defn::compute_tc_size (be_enum *node) -{ - // while computing the encapsulation length we must keep in mind the typecode - // that has gotten generated until this point. Hence, we must first check the - // "tc_queue" to ensure if are already there somewhere in a previous - // encapsulation in which case we must count only the bytes for the - // indirection. If we are not already generated, we must then check if we - // have already been counted in the current computation or not by checking - // for our presence in the compute queue. In both cases, we only include the - // 8 bytes in the computation - if (be_global->opt_tc () - && (this->queue_lookup (this->tc_queue_, node) - || this->queue_lookup (this->compute_queue_, node))) - { - this->computed_tc_size_ = 4 + 4; - } - else - { - // Insert node into tc_queue_ in case the node is involved in - // some form of recursion. - if (this->queue_insert (this->compute_queue_, - node, - this->tc_offset_) - == 0) - { - ACE_ERROR_RETURN ((LM_ERROR, - "(%N:%l) be_visitor_typecode_defn::" - "compute_tc_size (enum) - " - "queue insert failed\n"), - -1); - } - - // 4 bytes for enumeration, 4 bytes for storing encap length val, followed by the - // actual encapsulation - - this->ctx_->sub_state (TAO_CodeGen::TAO_TC_DEFN_ENCAP_LEN); - - if (node->accept (this) == -1) - { - ACE_ERROR_RETURN ((LM_ERROR, - ACE_TEXT ("(%N:%l) be_visitor_typecode_defn") - ACE_TEXT ("::compute_tc_size (enum) - ") - ACE_TEXT ("cannot compute encap len\n")), - -1); - } - - this->computed_tc_size_ = 4 + 4 + this->computed_encap_len_; - } - return this->computed_tc_size_; -} - -ACE_CDR::Long -be_visitor_typecode_defn::compute_encap_length (be_enum *node) -{ - ACE_CDR::Long encap_len; - encap_len = 4; // holds the byte order flag - - encap_len += - this->repoID_encap_len (node); // repoID storage - - // do the same thing for the local name - encap_len += this->name_encap_len (node); - - encap_len += 4; // to hold the member count - - // save the current value of scope len and start with a fresh one for our - // scope length computation - if (this->push (this->computed_scope_encap_len_) == -1) - { - ACE_ERROR_RETURN ((LM_ERROR, - ACE_TEXT ("(%N:%l) be_visitor_typecode_defn") - ACE_TEXT ("::compute_encap_len (enum) - ") - ACE_TEXT ("push failed\n")), - -1); - } - - this->computed_scope_encap_len_ = 0; - - // compute encap length for members - this->ctx_->sub_state (TAO_CodeGen::TAO_TC_DEFN_SCOPE_LEN); - - if (node->accept (this) == -1) - { - ACE_ERROR_RETURN ((LM_ERROR, - ACE_TEXT ("(%N:%l) be_visitor_typecode_defn") - ACE_TEXT ("::compute_encap_len (enum) - ") - ACE_TEXT ("cannot compute scope tc size\n")), - -1); - } - - this->computed_encap_len_ = encap_len + this->computed_scope_encap_len_; - - // pop off the previous value of computed_scope_len_ - if (this->pop (this->computed_scope_encap_len_) == -1) - { - ACE_ERROR_RETURN ((LM_ERROR, - ACE_TEXT ("(%N:%l) be_visitor_typecode_defn") - ACE_TEXT ("::compute_encap_len (enum) - ") - ACE_TEXT ("pop failed\n")), - -1); - } - - return this->computed_encap_len_; -} - - -ACE_CDR::Long -be_visitor_typecode_defn::compute_encap_length (be_enum_val *node) -{ - this->computed_encap_len_ = this->name_encap_len (node); - return this->computed_encap_len_; -} - - -ACE_CDR::Long -be_visitor_typecode_defn::compute_tc_size (be_exception *node) -{ - // while computing the encapsulation length we must keep in mind the typecode - // that has gotten generated until this point. Hence, we must first check the - // "tc_queue" to ensure if are already there somewhere in a previous - // encapsulation in which case we must count only the bytes for the - // indirection. If we are not already generated, we must then check if we - // have already been counted in the current computation or not by checking - // for our presence in the compute queue. In both cases, we only include the - // 8 bytes in the computation - if (be_global->opt_tc () - && (this->queue_lookup (this->tc_queue_, node) - || this->queue_lookup (this->compute_queue_, node))) - { - this->computed_tc_size_ = 4 + 4; - } - else - { - // Insert node into tc_queue_ in case the node is involved in - // some form of recursion. - if (this->queue_insert (this->compute_queue_, - node, - this->tc_offset_) - == 0) - { - ACE_ERROR_RETURN ((LM_ERROR, - "(%N:%l) be_visitor_typecode_defn::" - "compute_tc_size (exception) - " - "queue insert failed\n"), - -1); - } - - this->ctx_->sub_state (TAO_CodeGen::TAO_TC_DEFN_ENCAP_LEN); - - if (node->accept (this) == -1) - { - ACE_ERROR_RETURN ((LM_ERROR, - ACE_TEXT ("(%N:%l) be_visitor_typecode_defn") - ACE_TEXT ("::compute_tc_size (array) - ") - ACE_TEXT ("cannot compute encap len\n")), - -1); - } - - this->computed_tc_size_ = 4 + 4 + this->computed_encap_len_; - } - - return this->computed_tc_size_; -} - -ACE_CDR::Long -be_visitor_typecode_defn::compute_encap_length (be_exception *node) -{ - ACE_CDR::Long encap_len; - encap_len = 4; // holds the byte order flag - - encap_len += this->repoID_encap_len (node); // repoID - - // do the same thing for the local name - encap_len += this->name_encap_len (node); - - encap_len += 4; // to hold the member count - - // save the current value of scope len and start with a fresh one for our - // scope length computation - if (this->push (this->computed_scope_encap_len_) == -1) - { - ACE_ERROR_RETURN ((LM_ERROR, - ACE_TEXT ("(%N:%l) be_visitor_typecode_defn") - ACE_TEXT ("::compute_encap_len (exception) - ") - ACE_TEXT ("push failed\n")), - -1); - } - - this->computed_scope_encap_len_ = 0; - - // compute encap length for members - this->ctx_->sub_state (TAO_CodeGen::TAO_TC_DEFN_SCOPE_LEN); - - if (node->accept (this) == -1) - { - ACE_ERROR_RETURN ((LM_ERROR, - ACE_TEXT ("(%N:%l) be_visitor_typecode_defn") - ACE_TEXT ("::compute_encap_len (exception) - ") - ACE_TEXT ("cannot compute scope tc size\n")), - -1); - } - - this->computed_encap_len_ = encap_len + this->computed_scope_encap_len_; - - // pop off the previous value of computed_scope_len_ - if (this->pop (this->computed_scope_encap_len_) == -1) - { - ACE_ERROR_RETURN ((LM_ERROR, - ACE_TEXT ("(%N:%l) be_visitor_typecode_defn") - ACE_TEXT ("::compute_encap_len (exception) - ") - ACE_TEXT ("pop failed\n")), - -1); - } - - return this->computed_encap_len_; -} - -ACE_CDR::Long -be_visitor_typecode_defn::compute_encap_length (be_field *node) -{ - be_type *bt; - - // struct member is represented as the "name" followed by the typecode - - ACE_CDR::Long encap_len = - this->name_encap_len (node); // for name - - // add to this, the size of our typecode - bt = be_type::narrow_from_decl (node->field_type ()); - this->ctx_->sub_state (TAO_CodeGen::TAO_TC_DEFN_TC_SIZE); - - if (!bt || bt->accept (this) == -1) - { - ACE_ERROR_RETURN ((LM_ERROR, - ACE_TEXT ("(%N:%l) be_visitor_typecode_defn") - ACE_TEXT ("::compute_encap_len (array) - ") - ACE_TEXT ("cannot compute tc size\n")), - -1); - } - - // note that we must add typecode size of base type - this->computed_encap_len_ = encap_len + this->computed_tc_size_; - - // revert the sub state - this->ctx_->sub_state (TAO_CodeGen::TAO_TC_DEFN_SCOPE_LEN); - - if (node->visibility() != AST_Field::vis_NA) - { - // count visibility marker - - // Even though visibility marker is UShort it seems that - // it would always be aligned on ULong boundary. - this->computed_encap_len_ += 4; - } - - return this->computed_encap_len_; -} - -ACE_CDR::Long -be_visitor_typecode_defn::compute_tc_size (be_interface *node) -{ - // while computing the encapsulation length we must keep in mind the typecode - // that has gotten generated until this point. Hence, we must first check the - // "tc_queue" to ensure if are already there somewhere in a previous - // encapsulation in which case we must count only the bytes for the - // indirection. If we are not already generated, we must then check if we - // have already been counted in the current computation or not by checking - // for our presence in the compute queue. In both cases, we only include the - // 8 bytes in the computation - if (be_global->opt_tc () - && (this->queue_lookup (this->tc_queue_, node) - || this->queue_lookup (this->compute_queue_, node))) - { - this->computed_tc_size_ = 4 + 4; - } - else - { - // Insert node into tc_queue_ in case the node is involved in - // some form of recursion. - if (this->queue_insert (this->compute_queue_, - node, - this->tc_offset_) - == 0) - { - ACE_ERROR_RETURN ((LM_ERROR, - "(%N:%l) be_visitor_typecode_defn::" - "compute_tc_size (interface) - " - "queue insert failed\n"), - -1); - } - - this->ctx_->sub_state (TAO_CodeGen::TAO_TC_DEFN_ENCAP_LEN); - - if (node->accept (this) == -1) - { - ACE_ERROR_RETURN ((LM_ERROR, - ACE_TEXT ("(%N:%l) be_visitor_typecode_defn") - ACE_TEXT ("::compute_tc_size (interface) - ") - ACE_TEXT ("cannot compute encap len\n")), - -1); - } - - this->computed_tc_size_ = 4 + 4 + this->computed_encap_len_; - } - - return this->computed_tc_size_; -} - -ACE_CDR::Long -be_visitor_typecode_defn::compute_encap_length (be_interface *node) -{ - this->computed_encap_len_ = 4; // holds the byte order flag - - this->computed_encap_len_ += - this->repoID_encap_len (node); // for repoID - - // do the same thing for the local name - this->computed_encap_len_ += - this->name_encap_len (node); - - return this->computed_encap_len_; -} - - -ACE_CDR::Long -be_visitor_typecode_defn::compute_tc_size (be_interface_fwd *) -{ - return 0; -} - -ACE_CDR::Long -be_visitor_typecode_defn::compute_encap_length (be_interface_fwd *) -{ - return 0; -} - - -ACE_CDR::Long -be_visitor_typecode_defn::compute_tc_size (be_predefined_type *node) -{ - if (!ACE_OS::strcmp (node->local_name ()->get_string (), - "Object")) // not same - { - // while computing the encapsulation length we must keep in mind the typecode - // that has gotten generated until this point. Hence, we must first check the - // "tc_queue" to ensure if are already there somewhere in a previous - // encapsulation in which case we must count only the bytes for the - // indirection. If we are not already generated, we must then check if we - // have already been counted in the current computation or not by checking - // for our presence in the compute queue. In both cases, we only include the - // 8 bytes in the computation - if (be_global->opt_tc () - && (this->queue_lookup (this->tc_queue_, node) - || this->queue_lookup (this->compute_queue_, node))) - { - this->computed_tc_size_ = 4 + 4; - } - else - { - // Insert node into tc_queue_ in case the node is involved in - // some form of recursion. - if (this->queue_insert (this->compute_queue_, - node, - this->tc_offset_) - == 0) - { - ACE_ERROR_RETURN ((LM_ERROR, - "(%N:%l) be_visitor_typecode_defn::" - "compute_tc_size (predefined type) - " - "queue insert failed\n"), - -1); - } - - this->ctx_->sub_state (TAO_CodeGen::TAO_TC_DEFN_ENCAP_LEN); - - if (node->accept (this) == -1) - { - ACE_ERROR_RETURN ((LM_ERROR, - ACE_TEXT ("(%N:%l) be_visitor_typecode_defn") - ACE_TEXT ("::compute_tc_size (predefined objref) - ") - ACE_TEXT ("cannot compute encap len\n")), - -1); - } - - this->computed_tc_size_ = 4 + 4 + this->computed_encap_len_; - } - } - else - { - this->computed_tc_size_ = 4; - } - - return this->computed_tc_size_; -} - - -ACE_CDR::Long -be_visitor_typecode_defn::compute_encap_length (be_predefined_type *node) -{ - if (!ACE_OS::strcmp (node->local_name ()->get_string (), - "Object")) // not same - { - this->computed_encap_len_ = 4; // holds the byte order flag - - this->computed_encap_len_ += - this->repoID_encap_len (node); // for repoID - - // do the same thing for the local name - this->computed_encap_len_ += - this->name_encap_len (node); - } - else - { - this->computed_encap_len_ = 0; - } - - return this->computed_encap_len_; -} - -ACE_CDR::Long -be_visitor_typecode_defn::compute_tc_size (be_sequence *node) -{ - this->ctx_->sub_state (TAO_CodeGen::TAO_TC_DEFN_ENCAP_LEN); - - if (node->accept (this) == -1) - { - ACE_ERROR_RETURN ((LM_ERROR, - ACE_TEXT ("(%N:%l) be_visitor_typecode_defn") - ACE_TEXT ("::compute_tc_size (sequence) - ") - ACE_TEXT ("cannot compute encap len\n")), - -1); - } - - this->computed_tc_size_ = 4 + 4 + this->computed_encap_len_; - return this->computed_tc_size_; -} - - -ACE_CDR::Long -be_visitor_typecode_defn::compute_encap_length (be_sequence *node) -{ - be_type *bt; // base type - - ACE_CDR::Long encap_len = 4; // holds the byte order flag - - // add the encapsulation length of our base type - bt = be_type::narrow_from_decl (node->base_type ()); - this->ctx_->sub_state (TAO_CodeGen::TAO_TC_DEFN_TC_SIZE); - - if (!bt || bt->accept (this) == -1) - { - ACE_ERROR_RETURN ((LM_ERROR, - ACE_TEXT ("(%N:%l) be_visitor_typecode_defn") - ACE_TEXT ("::compute_encap_len (sequence) - ") - ACE_TEXT ("cannot compute tc size\n")), - -1); - } - - this->computed_encap_len_ = encap_len + this->computed_tc_size_; - this->computed_encap_len_ += 4; // to hold the max size - - return this->computed_encap_len_; -} - - -ACE_CDR::Long -be_visitor_typecode_defn::compute_tc_size (be_string *) -{ - this->computed_tc_size_ = 4 + 4; - return this->computed_tc_size_; -} - - -ACE_CDR::Long -be_visitor_typecode_defn::compute_encap_length (be_string *) -{ - this->computed_encap_len_ = 0; - return this->computed_encap_len_; -} - - -ACE_CDR::Long -be_visitor_typecode_defn::compute_tc_size (be_structure *node) -{ - // while computing the encapsulation length we must keep in mind the typecode - // that has gotten generated until this point. Hence, we must first check the - // "tc_queue" to ensure if are already there somewhere in a previous - // encapsulation in which case we must count only the bytes for the - // indirection. If we are not already generated, we must then check if we - // have already been counted in the current computation or not by checking - // for our presence in the compute queue. In both cases, we only include the - // 8 bytes in the computation - ACE_Unbounded_Queue<AST_Type *> list; - - if ((be_global->opt_tc () || node->in_recursion (list)) - && (this->queue_lookup (this->tc_queue_, node) - || this->queue_lookup (this->compute_queue_, node))) - { - this->computed_tc_size_ = 4 + 4; - } - else - { - if (this->queue_insert (this->compute_queue_, - node, - this->tc_offset_) - == 0) - { - ACE_ERROR_RETURN ((LM_ERROR, - "(%N:%l) be_visitor_typecode_defn::" - "compute_tc_size (structure) - " - "queue insert failed\n"), - -1); - } - - this->ctx_->sub_state (TAO_CodeGen::TAO_TC_DEFN_ENCAP_LEN); - - if (node->accept (this) == -1) - { - ACE_ERROR_RETURN ((LM_ERROR, - ACE_TEXT ("(%N:%l) be_visitor_typecode_defn") - ACE_TEXT ("::compute_tc_size (structure) - ") - ACE_TEXT ("cannot compute encap len\n")), - -1); - } - - this->computed_tc_size_ = 4 + 4 + this->computed_encap_len_; - } - - return this->computed_tc_size_; -} - - -ACE_CDR::Long -be_visitor_typecode_defn::compute_encap_length (be_structure *node) -{ - ACE_CDR::Long encap_len = 4; // holds the byte order flag - - encap_len += this->repoID_encap_len (node); // repoID - - // do the same thing for the local name - encap_len += this->name_encap_len (node); - - encap_len += 4; // to hold the member count - - // save the current value of scope len and start with a fresh one for our - // scope length computation - if (this->push (this->computed_scope_encap_len_) == -1) - { - ACE_ERROR_RETURN ((LM_ERROR, - ACE_TEXT ("(%N:%l) be_visitor_typecode_defn") - ACE_TEXT ("::compute_encap_len (struct) - ") - ACE_TEXT ("push failed\n")), - -1); - } - - this->computed_scope_encap_len_ = 0; - - // compute encap length for members - this->ctx_->sub_state (TAO_CodeGen::TAO_TC_DEFN_SCOPE_LEN); - - if (node->accept (this) == -1) - { - ACE_ERROR_RETURN ((LM_ERROR, - ACE_TEXT ("(%N:%l) be_visitor_typecode_defn") - ACE_TEXT ("::compute_encap_len (structure) - ") - ACE_TEXT ("cannot compute scope tc size\n")), - -1); - } - - this->computed_encap_len_ = encap_len + this->computed_scope_encap_len_; - - // pop off the previous value of computed_scope_len_ - if (this->pop (this->computed_scope_encap_len_) == -1) - { - ACE_ERROR_RETURN ((LM_ERROR, - ACE_TEXT ("(%N:%l) be_visitor_typecode_defn") - ACE_TEXT ("::compute_encap_len (struct) - ") - ACE_TEXT ("pop failed\n")), - -1); - } - - return this->computed_encap_len_; -} - - -ACE_CDR::Long -be_visitor_typecode_defn::compute_tc_size (be_typedef *node) -{ - // while computing the encapsulation length we must keep in mind the typecode - // that has gotten generated until this point. Hence, we must first check the - // "tc_queue" to ensure if are already there somewhere in a previous - // encapsulation in which case we must count only the bytes for the - // indirection. If we are not already generated, we must then check if we - // have already been counted in the current computation or not by checking - // for our presence in the compute queue. In both cases, we only include the - // 8 bytes in the computation - if (be_global->opt_tc () - && (this->queue_lookup (this->tc_queue_, node) - || this->queue_lookup (this->compute_queue_, node))) - { - this->computed_tc_size_ = 4 + 4; - } - else - { - if (this->queue_insert (this->compute_queue_, - node, - this->tc_offset_) - == 0) - { - ACE_ERROR_RETURN ((LM_ERROR, - "(%N:%l) be_visitor_typecode_defn::" - "compute_tc_size (typedef) - " - "queue insert failed\n"), - -1); - } - - this->ctx_->sub_state (TAO_CodeGen::TAO_TC_DEFN_ENCAP_LEN); - - if (node->accept (this) == -1) - { - ACE_ERROR_RETURN ((LM_ERROR, - ACE_TEXT ("(%N:%l) be_visitor_typecode_defn") - ACE_TEXT ("::compute_tc_size (array) - ") - ACE_TEXT ("cannot compute encap len\n")), - -1); - } - - this->computed_tc_size_ = 4 + 4 + this->computed_encap_len_; - } - - return this->computed_tc_size_; -} - - -ACE_CDR::Long -be_visitor_typecode_defn::compute_encap_length (be_typedef *node) -{ - be_type *bt; // base type - ACE_CDR::Long encap_len = 4; // holds the byte order flag - - encap_len += - this->repoID_encap_len (node); // repoID - - // do the same thing for the local name - encap_len += - this->name_encap_len (node); - - // add the encapsulation length of our base type - bt = be_type::narrow_from_decl (node->base_type ()); - this->ctx_->sub_state (TAO_CodeGen::TAO_TC_DEFN_TC_SIZE); - if (!bt || bt->accept (this) == -1) - - { - ACE_ERROR_RETURN ((LM_ERROR, - ACE_TEXT ("(%N:%l) be_visitor_typecode_defn") - ACE_TEXT ("::compute_encap_len (typedef) - ") - ACE_TEXT ("cannot compute tc size\n")), - -1); - } - - this->computed_encap_len_ = encap_len + this->computed_tc_size_; - return this->computed_encap_len_; -} - - -ACE_CDR::Long -be_visitor_typecode_defn::compute_tc_size (be_union *node) -{ - // while computing the encapsulation length we must keep in mind the typecode - // that has gotten generated until this point. Hence, we must first check the - // "tc_queue" to ensure if are already there somewhere in a previous - // encapsulation in which case we must count only the bytes for the - // indirection. If we are not already generated, we must then check if we - // have already been counted in the current computation or not by checking - // for our presence in the compute queue. In both cases, we only include the - // 8 bytes in the computation - ACE_Unbounded_Queue<AST_Type *> list; - - if ((be_global->opt_tc () || node->in_recursion (list)) - && (this->queue_lookup (this->tc_queue_, node) - || this->queue_lookup (this->compute_queue_, node))) - { - this->computed_tc_size_ = 4 + 4; - } - else - { - // Insert node into tc_queue_ in case the node is involved in - // some form of recursion. - if (this->queue_insert (this->compute_queue_, - node, - this->tc_offset_) - == 0) - { - ACE_ERROR_RETURN ((LM_ERROR, - "(%N:%l) be_visitor_typecode_defn::" - "compute_tc_size (union) - " - "queue insert failed\n"), - -1); - } - - this->ctx_->sub_state (TAO_CodeGen::TAO_TC_DEFN_ENCAP_LEN); - - if (node->accept (this) == -1) - { - ACE_ERROR_RETURN ((LM_ERROR, - ACE_TEXT ("(%N:%l) be_visitor_typecode_defn") - ACE_TEXT ("::compute_tc_size (union) - ") - ACE_TEXT ("cannot compute encap len\n")), - -1); - } - - this->computed_tc_size_ = 4 + 4 + this->computed_encap_len_; - } - - return this->computed_tc_size_; -} - - -ACE_CDR::Long -be_visitor_typecode_defn::compute_encap_length (be_union *node) -{ - be_type *discrim; - - ACE_CDR::Long encap_len = 4; // holds the byte order flag - - encap_len += this->repoID_encap_len (node); // for repoID - - // do the same thing for the local name - encap_len += this->name_encap_len (node); // for name - - // add encapsulation size of discriminant typecode - discrim = be_type::narrow_from_decl (node->disc_type ()); - this->ctx_->sub_state (TAO_CodeGen::TAO_TC_DEFN_TC_SIZE); - - if (!discrim || discrim->accept (this) == -1) - { - ACE_ERROR_RETURN ((LM_ERROR, - ACE_TEXT ("(%N:%l) be_visitor_typecode_defn") - ACE_TEXT ("::compute_encap_len (union) - ") - ACE_TEXT ("cannot compute tc size\n")), - -1); - } - - encap_len += this->computed_tc_size_; - - encap_len += 4; // to hold the "default used" flag - encap_len += 4; // to hold the member count - - // save the current value of scope len and start with a fresh one for our - // scope length computation - if (this->push (this->computed_scope_encap_len_) == -1) - { - ACE_ERROR_RETURN ((LM_ERROR, - ACE_TEXT ("(%N:%l) be_visitor_typecode_defn") - ACE_TEXT ("::compute_encap_len (union) - ") - ACE_TEXT ("push failed\n")), - -1); - } - this->computed_scope_encap_len_ = 0; - - // compute encap length for members - this->ctx_->sub_state (TAO_CodeGen::TAO_TC_DEFN_SCOPE_LEN); - - if (node->accept (this) == -1) - { - ACE_ERROR_RETURN ((LM_ERROR, - ACE_TEXT ("(%N:%l) be_visitor_typecode_defn") - ACE_TEXT ("::compute_encap_len (union) - ") - ACE_TEXT ("cannot compute scope tc size\n")), - -1); - } - - this->computed_encap_len_ = encap_len + this->computed_scope_encap_len_; - - // pop off the previous value of computed_scope_len_ - if (this->pop (this->computed_scope_encap_len_) == -1) - { - ACE_ERROR_RETURN ((LM_ERROR, - ACE_TEXT ("(%N:%l) be_visitor_typecode_defn") - ACE_TEXT ("::compute_encap_len (union) - ") - ACE_TEXT ("pop failed\n")), - -1); - } - - return this->computed_encap_len_; -} - - -ACE_CDR::Long -be_visitor_typecode_defn::compute_encap_length (be_union_branch *node) -{ - be_type *bt; - - ACE_CDR::Long encap_len = 0; - - encap_len += 4; // case label; - encap_len += this->name_encap_len (node); // for name - - bt = be_type::narrow_from_decl (node->field_type ()); - this->ctx_->sub_state (TAO_CodeGen::TAO_TC_DEFN_TC_SIZE); - - if (!bt || bt->accept (this) == -1) - { - ACE_ERROR_RETURN ((LM_ERROR, - ACE_TEXT ("(%N:%l) be_visitor_typecode_defn") - ACE_TEXT ("::compute_encap_len (union branch) - ") - ACE_TEXT ("cannot compute tc size\n")), - -1); - } - - encap_len += this->computed_tc_size_; - - this->computed_encap_len_ = encap_len; - - this->ctx_->sub_state (TAO_CodeGen::TAO_TC_DEFN_SCOPE_LEN); - return this->computed_encap_len_; -} - -ACE_CDR::Long -be_visitor_typecode_defn::compute_tc_size (be_valuetype *node) -{ - // while computing the encapsulation length we must keep in mind the typecode - // that has gotten generated until this point. Hence, we must first check the - // "tc_queue" to ensure if are already there somewhere in a previous - // encapsulation in which case we must count only the bytes for the - // indirection. If we are not already generated, we must then check if we - // have already been counted in the current computation or not by checking - // for our presence in the compute queue. In both cases, we only include the - // 8 bytes in the computation - ACE_Unbounded_Queue<AST_Type *> list; - - if ((be_global->opt_tc () || node->in_recursion (list)) - && (this->queue_lookup (this->tc_queue_, node) - || this->queue_lookup (this->compute_queue_, node))) - { - this->computed_tc_size_ = 4 + 4; - } - else - { - // Insert node into tc_queue_ in case the node is involved in - // some form of recursion. - if (this->queue_insert (this->compute_queue_, - node, - this->tc_offset_) - == 0) - { - ACE_ERROR_RETURN ((LM_ERROR, - "(%N:%l) be_visitor_typecode_defn::" - "compute_tc_size (valuetype) - " - "queue insert failed\n"), - -1); - } - - this->ctx_->sub_state (TAO_CodeGen::TAO_TC_DEFN_ENCAP_LEN); - - if (node->accept (this) == -1) - { - ACE_ERROR_RETURN ((LM_ERROR, - ACE_TEXT ("(%N:%l) be_visitor_typecode_defn") - ACE_TEXT ("::compute_tc_size (valuetype) - ") - ACE_TEXT ("cannot compute encap len\n")), - -1); - } - - this->computed_tc_size_ = 4 + 4 + this->computed_encap_len_; - } - - return this->computed_tc_size_; -} - -ACE_CDR::Long -be_visitor_typecode_defn::compute_encap_length (be_valuetype *node) -{ - // STEP 1: - ACE_CDR::Long encap_len = 4; // holds the byte order flag - - // STEP 2: - encap_len += this->repoID_encap_len (node); // repoID - - //STEP 3: do the same thing for the local name - encap_len += this->name_encap_len (node); - - // STEP 4: - encap_len += 4; // to hold the ValueModifier - - - // STEP 5: get encapsulation length for concrete base valuetype - AST_ValueType *concrete_inherited = node->inherits_concrete (); - - if (concrete_inherited != 0) - { - // Got non-abstract base valuetype. - - this->computed_tc_size_ = 0; - - be_valuetype *vt = be_valuetype::narrow_from_decl (concrete_inherited); - this->ctx_->sub_state (TAO_CodeGen::TAO_TC_DEFN_TC_SIZE); - - if (!vt || vt->accept (this) == -1) - { - ACE_ERROR_RETURN ((LM_ERROR, - ACE_TEXT ("(%N:%l) be_visitor_typecode_defn") - ACE_TEXT ("::compute_encap_len (valuetype) - ") - ACE_TEXT ("failed to compute len\n")), - -1); - } - // revert the state to what it was before - this->ctx_->sub_state (TAO_CodeGen::TAO_TC_DEFN_ENCAP_LEN); - - encap_len += this->computed_tc_size_; - } - else - { - encap_len += 4; // to hold the CORBA::tk_null - } - - //STEP 6: - encap_len += 4; // to hold the member count - - // save the current value of scope len and start with a fresh one for our - // scope length computation - if (this->push (this->computed_scope_encap_len_) == -1) - { - ACE_ERROR_RETURN ((LM_ERROR, - ACE_TEXT ("(%N:%l) be_visitor_typecode_defn") - ACE_TEXT ("::compute_encap_len (struct) - ") - ACE_TEXT ("push failed\n")), - -1); - } - this->computed_scope_encap_len_ = 0; - - // compute encap length for members - this->ctx_->sub_state (TAO_CodeGen::TAO_TC_DEFN_SCOPE_LEN); - - if (node->accept (this) == -1) - { - ACE_ERROR_RETURN ((LM_ERROR, - ACE_TEXT ("(%N:%l) be_visitor_typecode_defn") - ACE_TEXT ("::compute_encap_len (valuetype) - ") - ACE_TEXT ("cannot compute scope tc size\n")), - -1); - } - - this->computed_encap_len_ = encap_len + this->computed_scope_encap_len_; - - // pop off the previous value of computed_scope_len_ - if (this->pop (this->computed_scope_encap_len_) == -1) - { - ACE_ERROR_RETURN ((LM_ERROR, - ACE_TEXT ("(%N:%l) be_visitor_typecode_defn") - ACE_TEXT ("::compute_encap_len (valuetype) - ") - ACE_TEXT ("pop failed\n")), - -1); - } - - return this->computed_encap_len_; -} +// ACE_CDR::Long +// be_visitor_typecode_defn::compute_tc_size (be_enum *node) +// { +// // while computing the encapsulation length we must keep in mind the typecode +// // that has gotten generated until this point. Hence, we must first check the +// // "tc_queue" to ensure if are already there somewhere in a previous +// // encapsulation in which case we must count only the bytes for the +// // indirection. If we are not already generated, we must then check if we +// // have already been counted in the current computation or not by checking +// // for our presence in the compute queue. In both cases, we only include the +// // 8 bytes in the computation +// if (be_global->opt_tc () +// && (this->queue_lookup (this->tc_queue_, node) +// || this->queue_lookup (this->compute_queue_, node))) +// { +// this->computed_tc_size_ = 4 + 4; +// } +// else +// { +// // Insert node into tc_queue_ in case the node is involved in +// // some form of recursion. +// if (this->queue_insert (this->compute_queue_, +// node, +// this->tc_offset_) +// == 0) +// { +// ACE_ERROR_RETURN ((LM_ERROR, +// "(%N:%l) be_visitor_typecode_defn::" +// "compute_tc_size (enum) - " +// "queue insert failed\n"), +// -1); +// } + +// // 4 bytes for enumeration, 4 bytes for storing encap length val, followed by the +// // actual encapsulation + +// this->ctx_->sub_state (TAO_CodeGen::TAO_TC_DEFN_ENCAP_LEN); + +// if (node->accept (this) == -1) +// { +// ACE_ERROR_RETURN ((LM_ERROR, +// ACE_TEXT ("(%N:%l) be_visitor_typecode_defn") +// ACE_TEXT ("::compute_tc_size (enum) - ") +// ACE_TEXT ("cannot compute encap len\n")), +// -1); +// } + +// this->computed_tc_size_ = 4 + 4 + this->computed_encap_len_; +// } +// return this->computed_tc_size_; +// } + +// ACE_CDR::Long +// be_visitor_typecode_defn::compute_encap_length (be_enum *node) +// { +// ACE_CDR::Long encap_len; +// encap_len = 4; // holds the byte order flag + +// encap_len += +// this->repoID_encap_len (node); // repoID storage + +// // do the same thing for the local name +// encap_len += this->name_encap_len (node); + +// encap_len += 4; // to hold the member count + +// // save the current value of scope len and start with a fresh one for our +// // scope length computation +// if (this->push (this->computed_scope_encap_len_) == -1) +// { +// ACE_ERROR_RETURN ((LM_ERROR, +// ACE_TEXT ("(%N:%l) be_visitor_typecode_defn") +// ACE_TEXT ("::compute_encap_len (enum) - ") +// ACE_TEXT ("push failed\n")), +// -1); +// } + +// this->computed_scope_encap_len_ = 0; + +// // compute encap length for members +// this->ctx_->sub_state (TAO_CodeGen::TAO_TC_DEFN_SCOPE_LEN); + +// if (node->accept (this) == -1) +// { +// ACE_ERROR_RETURN ((LM_ERROR, +// ACE_TEXT ("(%N:%l) be_visitor_typecode_defn") +// ACE_TEXT ("::compute_encap_len (enum) - ") +// ACE_TEXT ("cannot compute scope tc size\n")), +// -1); +// } + +// this->computed_encap_len_ = encap_len + this->computed_scope_encap_len_; + +// // pop off the previous value of computed_scope_len_ +// if (this->pop (this->computed_scope_encap_len_) == -1) +// { +// ACE_ERROR_RETURN ((LM_ERROR, +// ACE_TEXT ("(%N:%l) be_visitor_typecode_defn") +// ACE_TEXT ("::compute_encap_len (enum) - ") +// ACE_TEXT ("pop failed\n")), +// -1); +// } + +// return this->computed_encap_len_; +// } + + +// ACE_CDR::Long +// be_visitor_typecode_defn::compute_encap_length (be_enum_val *node) +// { +// this->computed_encap_len_ = this->name_encap_len (node); +// return this->computed_encap_len_; +// } + + +// ACE_CDR::Long +// be_visitor_typecode_defn::compute_tc_size (be_exception *node) +// { +// // while computing the encapsulation length we must keep in mind the typecode +// // that has gotten generated until this point. Hence, we must first check the +// // "tc_queue" to ensure if are already there somewhere in a previous +// // encapsulation in which case we must count only the bytes for the +// // indirection. If we are not already generated, we must then check if we +// // have already been counted in the current computation or not by checking +// // for our presence in the compute queue. In both cases, we only include the +// // 8 bytes in the computation +// if (be_global->opt_tc () +// && (this->queue_lookup (this->tc_queue_, node) +// || this->queue_lookup (this->compute_queue_, node))) +// { +// this->computed_tc_size_ = 4 + 4; +// } +// else +// { +// // Insert node into tc_queue_ in case the node is involved in +// // some form of recursion. +// if (this->queue_insert (this->compute_queue_, +// node, +// this->tc_offset_) +// == 0) +// { +// ACE_ERROR_RETURN ((LM_ERROR, +// "(%N:%l) be_visitor_typecode_defn::" +// "compute_tc_size (exception) - " +// "queue insert failed\n"), +// -1); +// } + +// this->ctx_->sub_state (TAO_CodeGen::TAO_TC_DEFN_ENCAP_LEN); + +// if (node->accept (this) == -1) +// { +// ACE_ERROR_RETURN ((LM_ERROR, +// ACE_TEXT ("(%N:%l) be_visitor_typecode_defn") +// ACE_TEXT ("::compute_tc_size (array) - ") +// ACE_TEXT ("cannot compute encap len\n")), +// -1); +// } + +// this->computed_tc_size_ = 4 + 4 + this->computed_encap_len_; +// } + +// return this->computed_tc_size_; +// } + +// ACE_CDR::Long +// be_visitor_typecode_defn::compute_encap_length (be_exception *node) +// { +// ACE_CDR::Long encap_len; +// encap_len = 4; // holds the byte order flag + +// encap_len += this->repoID_encap_len (node); // repoID + +// // do the same thing for the local name +// encap_len += this->name_encap_len (node); + +// encap_len += 4; // to hold the member count + +// // save the current value of scope len and start with a fresh one for our +// // scope length computation +// if (this->push (this->computed_scope_encap_len_) == -1) +// { +// ACE_ERROR_RETURN ((LM_ERROR, +// ACE_TEXT ("(%N:%l) be_visitor_typecode_defn") +// ACE_TEXT ("::compute_encap_len (exception) - ") +// ACE_TEXT ("push failed\n")), +// -1); +// } + +// this->computed_scope_encap_len_ = 0; + +// // compute encap length for members +// this->ctx_->sub_state (TAO_CodeGen::TAO_TC_DEFN_SCOPE_LEN); + +// if (node->accept (this) == -1) +// { +// ACE_ERROR_RETURN ((LM_ERROR, +// ACE_TEXT ("(%N:%l) be_visitor_typecode_defn") +// ACE_TEXT ("::compute_encap_len (exception) - ") +// ACE_TEXT ("cannot compute scope tc size\n")), +// -1); +// } + +// this->computed_encap_len_ = encap_len + this->computed_scope_encap_len_; + +// // pop off the previous value of computed_scope_len_ +// if (this->pop (this->computed_scope_encap_len_) == -1) +// { +// ACE_ERROR_RETURN ((LM_ERROR, +// ACE_TEXT ("(%N:%l) be_visitor_typecode_defn") +// ACE_TEXT ("::compute_encap_len (exception) - ") +// ACE_TEXT ("pop failed\n")), +// -1); +// } + +// return this->computed_encap_len_; +// } + +// ACE_CDR::Long +// be_visitor_typecode_defn::compute_encap_length (be_field *node) +// { +// be_type *bt; + +// // struct member is represented as the "name" followed by the typecode + +// ACE_CDR::Long encap_len = +// this->name_encap_len (node); // for name + +// // add to this, the size of our typecode +// bt = be_type::narrow_from_decl (node->field_type ()); +// this->ctx_->sub_state (TAO_CodeGen::TAO_TC_DEFN_TC_SIZE); + +// if (!bt || bt->accept (this) == -1) +// { +// ACE_ERROR_RETURN ((LM_ERROR, +// ACE_TEXT ("(%N:%l) be_visitor_typecode_defn") +// ACE_TEXT ("::compute_encap_len (array) - ") +// ACE_TEXT ("cannot compute tc size\n")), +// -1); +// } + +// // note that we must add typecode size of base type +// this->computed_encap_len_ = encap_len + this->computed_tc_size_; + +// // revert the sub state +// this->ctx_->sub_state (TAO_CodeGen::TAO_TC_DEFN_SCOPE_LEN); + +// if (node->visibility() != AST_Field::vis_NA) +// { +// // count visibility marker + +// // Even though visibility marker is UShort it seems that +// // it would always be aligned on ULong boundary. +// this->computed_encap_len_ += 4; +// } + +// return this->computed_encap_len_; +// } + +// ACE_CDR::Long +// be_visitor_typecode_defn::compute_tc_size (be_interface *node) +// { +// // while computing the encapsulation length we must keep in mind the typecode +// // that has gotten generated until this point. Hence, we must first check the +// // "tc_queue" to ensure if are already there somewhere in a previous +// // encapsulation in which case we must count only the bytes for the +// // indirection. If we are not already generated, we must then check if we +// // have already been counted in the current computation or not by checking +// // for our presence in the compute queue. In both cases, we only include the +// // 8 bytes in the computation +// if (be_global->opt_tc () +// && (this->queue_lookup (this->tc_queue_, node) +// || this->queue_lookup (this->compute_queue_, node))) +// { +// this->computed_tc_size_ = 4 + 4; +// } +// else +// { +// // Insert node into tc_queue_ in case the node is involved in +// // some form of recursion. +// if (this->queue_insert (this->compute_queue_, +// node, +// this->tc_offset_) +// == 0) +// { +// ACE_ERROR_RETURN ((LM_ERROR, +// "(%N:%l) be_visitor_typecode_defn::" +// "compute_tc_size (interface) - " +// "queue insert failed\n"), +// -1); +// } + +// this->ctx_->sub_state (TAO_CodeGen::TAO_TC_DEFN_ENCAP_LEN); + +// if (node->accept (this) == -1) +// { +// ACE_ERROR_RETURN ((LM_ERROR, +// ACE_TEXT ("(%N:%l) be_visitor_typecode_defn") +// ACE_TEXT ("::compute_tc_size (interface) - ") +// ACE_TEXT ("cannot compute encap len\n")), +// -1); +// } + +// this->computed_tc_size_ = 4 + 4 + this->computed_encap_len_; +// } + +// return this->computed_tc_size_; +// } + +// ACE_CDR::Long +// be_visitor_typecode_defn::compute_encap_length (be_interface *node) +// { +// this->computed_encap_len_ = 4; // holds the byte order flag + +// this->computed_encap_len_ += +// this->repoID_encap_len (node); // for repoID + +// // do the same thing for the local name +// this->computed_encap_len_ += +// this->name_encap_len (node); + +// return this->computed_encap_len_; +// } + + +// ACE_CDR::Long +// be_visitor_typecode_defn::compute_tc_size (be_interface_fwd *) +// { +// return 0; +// } + +// ACE_CDR::Long +// be_visitor_typecode_defn::compute_encap_length (be_interface_fwd *) +// { +// return 0; +// } + + +// ACE_CDR::Long +// be_visitor_typecode_defn::compute_tc_size (be_predefined_type *node) +// { +// if (!ACE_OS::strcmp (node->local_name ()->get_string (), +// "Object")) // not same +// { +// // while computing the encapsulation length we must keep in mind the typecode +// // that has gotten generated until this point. Hence, we must first check the +// // "tc_queue" to ensure if are already there somewhere in a previous +// // encapsulation in which case we must count only the bytes for the +// // indirection. If we are not already generated, we must then check if we +// // have already been counted in the current computation or not by checking +// // for our presence in the compute queue. In both cases, we only include the +// // 8 bytes in the computation +// if (be_global->opt_tc () +// && (this->queue_lookup (this->tc_queue_, node) +// || this->queue_lookup (this->compute_queue_, node))) +// { +// this->computed_tc_size_ = 4 + 4; +// } +// else +// { +// // Insert node into tc_queue_ in case the node is involved in +// // some form of recursion. +// if (this->queue_insert (this->compute_queue_, +// node, +// this->tc_offset_) +// == 0) +// { +// ACE_ERROR_RETURN ((LM_ERROR, +// "(%N:%l) be_visitor_typecode_defn::" +// "compute_tc_size (predefined type) - " +// "queue insert failed\n"), +// -1); +// } + +// this->ctx_->sub_state (TAO_CodeGen::TAO_TC_DEFN_ENCAP_LEN); + +// if (node->accept (this) == -1) +// { +// ACE_ERROR_RETURN ((LM_ERROR, +// ACE_TEXT ("(%N:%l) be_visitor_typecode_defn") +// ACE_TEXT ("::compute_tc_size (predefined objref) - ") +// ACE_TEXT ("cannot compute encap len\n")), +// -1); +// } + +// this->computed_tc_size_ = 4 + 4 + this->computed_encap_len_; +// } +// } +// else +// { +// this->computed_tc_size_ = 4; +// } + +// return this->computed_tc_size_; +// } + + +// ACE_CDR::Long +// be_visitor_typecode_defn::compute_encap_length (be_predefined_type *node) +// { +// if (!ACE_OS::strcmp (node->local_name ()->get_string (), +// "Object")) // not same +// { +// this->computed_encap_len_ = 4; // holds the byte order flag + +// this->computed_encap_len_ += +// this->repoID_encap_len (node); // for repoID + +// // do the same thing for the local name +// this->computed_encap_len_ += +// this->name_encap_len (node); +// } +// else +// { +// this->computed_encap_len_ = 0; +// } + +// return this->computed_encap_len_; +// } + +// ACE_CDR::Long +// be_visitor_typecode_defn::compute_tc_size (be_sequence *node) +// { +// this->ctx_->sub_state (TAO_CodeGen::TAO_TC_DEFN_ENCAP_LEN); + +// if (node->accept (this) == -1) +// { +// ACE_ERROR_RETURN ((LM_ERROR, +// ACE_TEXT ("(%N:%l) be_visitor_typecode_defn") +// ACE_TEXT ("::compute_tc_size (sequence) - ") +// ACE_TEXT ("cannot compute encap len\n")), +// -1); +// } + +// this->computed_tc_size_ = 4 + 4 + this->computed_encap_len_; +// return this->computed_tc_size_; +// } + + +// ACE_CDR::Long +// be_visitor_typecode_defn::compute_encap_length (be_sequence *node) +// { +// be_type *bt; // base type + +// ACE_CDR::Long encap_len = 4; // holds the byte order flag + +// // add the encapsulation length of our base type +// bt = be_type::narrow_from_decl (node->base_type ()); +// this->ctx_->sub_state (TAO_CodeGen::TAO_TC_DEFN_TC_SIZE); + +// if (!bt || bt->accept (this) == -1) +// { +// ACE_ERROR_RETURN ((LM_ERROR, +// ACE_TEXT ("(%N:%l) be_visitor_typecode_defn") +// ACE_TEXT ("::compute_encap_len (sequence) - ") +// ACE_TEXT ("cannot compute tc size\n")), +// -1); +// } + +// this->computed_encap_len_ = encap_len + this->computed_tc_size_; +// this->computed_encap_len_ += 4; // to hold the max size + +// return this->computed_encap_len_; +// } + + +// ACE_CDR::Long +// be_visitor_typecode_defn::compute_tc_size (be_string *) +// { +// this->computed_tc_size_ = 4 + 4; +// return this->computed_tc_size_; +// } + + +// ACE_CDR::Long +// be_visitor_typecode_defn::compute_encap_length (be_string *) +// { +// this->computed_encap_len_ = 0; +// return this->computed_encap_len_; +// } + + +// ACE_CDR::Long +// be_visitor_typecode_defn::compute_tc_size (be_structure *node) +// { +// // while computing the encapsulation length we must keep in mind the typecode +// // that has gotten generated until this point. Hence, we must first check the +// // "tc_queue" to ensure if are already there somewhere in a previous +// // encapsulation in which case we must count only the bytes for the +// // indirection. If we are not already generated, we must then check if we +// // have already been counted in the current computation or not by checking +// // for our presence in the compute queue. In both cases, we only include the +// // 8 bytes in the computation +// ACE_Unbounded_Queue<AST_Type *> list; + +// if ((be_global->opt_tc () || node->in_recursion (list)) +// && (this->queue_lookup (this->tc_queue_, node) +// || this->queue_lookup (this->compute_queue_, node))) +// { +// this->computed_tc_size_ = 4 + 4; +// } +// else +// { +// if (this->queue_insert (this->compute_queue_, +// node, +// this->tc_offset_) +// == 0) +// { +// ACE_ERROR_RETURN ((LM_ERROR, +// "(%N:%l) be_visitor_typecode_defn::" +// "compute_tc_size (structure) - " +// "queue insert failed\n"), +// -1); +// } + +// this->ctx_->sub_state (TAO_CodeGen::TAO_TC_DEFN_ENCAP_LEN); + +// if (node->accept (this) == -1) +// { +// ACE_ERROR_RETURN ((LM_ERROR, +// ACE_TEXT ("(%N:%l) be_visitor_typecode_defn") +// ACE_TEXT ("::compute_tc_size (structure) - ") +// ACE_TEXT ("cannot compute encap len\n")), +// -1); +// } + +// this->computed_tc_size_ = 4 + 4 + this->computed_encap_len_; +// } + +// return this->computed_tc_size_; +// } + + +// ACE_CDR::Long +// be_visitor_typecode_defn::compute_encap_length (be_structure *node) +// { +// ACE_CDR::Long encap_len = 4; // holds the byte order flag + +// encap_len += this->repoID_encap_len (node); // repoID + +// // do the same thing for the local name +// encap_len += this->name_encap_len (node); + +// encap_len += 4; // to hold the member count + +// // save the current value of scope len and start with a fresh one for our +// // scope length computation +// if (this->push (this->computed_scope_encap_len_) == -1) +// { +// ACE_ERROR_RETURN ((LM_ERROR, +// ACE_TEXT ("(%N:%l) be_visitor_typecode_defn") +// ACE_TEXT ("::compute_encap_len (struct) - ") +// ACE_TEXT ("push failed\n")), +// -1); +// } + +// this->computed_scope_encap_len_ = 0; + +// // compute encap length for members +// this->ctx_->sub_state (TAO_CodeGen::TAO_TC_DEFN_SCOPE_LEN); + +// if (node->accept (this) == -1) +// { +// ACE_ERROR_RETURN ((LM_ERROR, +// ACE_TEXT ("(%N:%l) be_visitor_typecode_defn") +// ACE_TEXT ("::compute_encap_len (structure) - ") +// ACE_TEXT ("cannot compute scope tc size\n")), +// -1); +// } + +// this->computed_encap_len_ = encap_len + this->computed_scope_encap_len_; + +// // pop off the previous value of computed_scope_len_ +// if (this->pop (this->computed_scope_encap_len_) == -1) +// { +// ACE_ERROR_RETURN ((LM_ERROR, +// ACE_TEXT ("(%N:%l) be_visitor_typecode_defn") +// ACE_TEXT ("::compute_encap_len (struct) - ") +// ACE_TEXT ("pop failed\n")), +// -1); +// } + +// return this->computed_encap_len_; +// } + + +// ACE_CDR::Long +// be_visitor_typecode_defn::compute_tc_size (be_typedef *node) +// { +// // while computing the encapsulation length we must keep in mind the typecode +// // that has gotten generated until this point. Hence, we must first check the +// // "tc_queue" to ensure if are already there somewhere in a previous +// // encapsulation in which case we must count only the bytes for the +// // indirection. If we are not already generated, we must then check if we +// // have already been counted in the current computation or not by checking +// // for our presence in the compute queue. In both cases, we only include the +// // 8 bytes in the computation +// if (be_global->opt_tc () +// && (this->queue_lookup (this->tc_queue_, node) +// || this->queue_lookup (this->compute_queue_, node))) +// { +// this->computed_tc_size_ = 4 + 4; +// } +// else +// { +// if (this->queue_insert (this->compute_queue_, +// node, +// this->tc_offset_) +// == 0) +// { +// ACE_ERROR_RETURN ((LM_ERROR, +// "(%N:%l) be_visitor_typecode_defn::" +// "compute_tc_size (typedef) - " +// "queue insert failed\n"), +// -1); +// } + +// this->ctx_->sub_state (TAO_CodeGen::TAO_TC_DEFN_ENCAP_LEN); + +// if (node->accept (this) == -1) +// { +// ACE_ERROR_RETURN ((LM_ERROR, +// ACE_TEXT ("(%N:%l) be_visitor_typecode_defn") +// ACE_TEXT ("::compute_tc_size (array) - ") +// ACE_TEXT ("cannot compute encap len\n")), +// -1); +// } + +// this->computed_tc_size_ = 4 + 4 + this->computed_encap_len_; +// } + +// return this->computed_tc_size_; +// } + + +// ACE_CDR::Long +// be_visitor_typecode_defn::compute_encap_length (be_typedef *node) +// { +// be_type *bt; // base type +// ACE_CDR::Long encap_len = 4; // holds the byte order flag + +// encap_len += +// this->repoID_encap_len (node); // repoID + +// // do the same thing for the local name +// encap_len += +// this->name_encap_len (node); + +// // add the encapsulation length of our base type +// bt = be_type::narrow_from_decl (node->base_type ()); +// this->ctx_->sub_state (TAO_CodeGen::TAO_TC_DEFN_TC_SIZE); +// if (!bt || bt->accept (this) == -1) + +// { +// ACE_ERROR_RETURN ((LM_ERROR, +// ACE_TEXT ("(%N:%l) be_visitor_typecode_defn") +// ACE_TEXT ("::compute_encap_len (typedef) - ") +// ACE_TEXT ("cannot compute tc size\n")), +// -1); +// } + +// this->computed_encap_len_ = encap_len + this->computed_tc_size_; +// return this->computed_encap_len_; +// } + + +// ACE_CDR::Long +// be_visitor_typecode_defn::compute_tc_size (be_union *node) +// { +// // while computing the encapsulation length we must keep in mind the typecode +// // that has gotten generated until this point. Hence, we must first check the +// // "tc_queue" to ensure if are already there somewhere in a previous +// // encapsulation in which case we must count only the bytes for the +// // indirection. If we are not already generated, we must then check if we +// // have already been counted in the current computation or not by checking +// // for our presence in the compute queue. In both cases, we only include the +// // 8 bytes in the computation +// ACE_Unbounded_Queue<AST_Type *> list; + +// if ((be_global->opt_tc () || node->in_recursion (list)) +// && (this->queue_lookup (this->tc_queue_, node) +// || this->queue_lookup (this->compute_queue_, node))) +// { +// this->computed_tc_size_ = 4 + 4; +// } +// else +// { +// // Insert node into tc_queue_ in case the node is involved in +// // some form of recursion. +// if (this->queue_insert (this->compute_queue_, +// node, +// this->tc_offset_) +// == 0) +// { +// ACE_ERROR_RETURN ((LM_ERROR, +// "(%N:%l) be_visitor_typecode_defn::" +// "compute_tc_size (union) - " +// "queue insert failed\n"), +// -1); +// } + +// this->ctx_->sub_state (TAO_CodeGen::TAO_TC_DEFN_ENCAP_LEN); + +// if (node->accept (this) == -1) +// { +// ACE_ERROR_RETURN ((LM_ERROR, +// ACE_TEXT ("(%N:%l) be_visitor_typecode_defn") +// ACE_TEXT ("::compute_tc_size (union) - ") +// ACE_TEXT ("cannot compute encap len\n")), +// -1); +// } + +// this->computed_tc_size_ = 4 + 4 + this->computed_encap_len_; +// } + +// return this->computed_tc_size_; +// } + + +// ACE_CDR::Long +// be_visitor_typecode_defn::compute_encap_length (be_union *node) +// { +// be_type *discrim; + +// ACE_CDR::Long encap_len = 4; // holds the byte order flag + +// encap_len += this->repoID_encap_len (node); // for repoID + +// // do the same thing for the local name +// encap_len += this->name_encap_len (node); // for name + +// // add encapsulation size of discriminant typecode +// discrim = be_type::narrow_from_decl (node->disc_type ()); +// this->ctx_->sub_state (TAO_CodeGen::TAO_TC_DEFN_TC_SIZE); + +// if (!discrim || discrim->accept (this) == -1) +// { +// ACE_ERROR_RETURN ((LM_ERROR, +// ACE_TEXT ("(%N:%l) be_visitor_typecode_defn") +// ACE_TEXT ("::compute_encap_len (union) - ") +// ACE_TEXT ("cannot compute tc size\n")), +// -1); +// } + +// encap_len += this->computed_tc_size_; + +// encap_len += 4; // to hold the "default used" flag +// encap_len += 4; // to hold the member count + +// // save the current value of scope len and start with a fresh one for our +// // scope length computation +// if (this->push (this->computed_scope_encap_len_) == -1) +// { +// ACE_ERROR_RETURN ((LM_ERROR, +// ACE_TEXT ("(%N:%l) be_visitor_typecode_defn") +// ACE_TEXT ("::compute_encap_len (union) - ") +// ACE_TEXT ("push failed\n")), +// -1); +// } +// this->computed_scope_encap_len_ = 0; + +// // compute encap length for members +// this->ctx_->sub_state (TAO_CodeGen::TAO_TC_DEFN_SCOPE_LEN); + +// if (node->accept (this) == -1) +// { +// ACE_ERROR_RETURN ((LM_ERROR, +// ACE_TEXT ("(%N:%l) be_visitor_typecode_defn") +// ACE_TEXT ("::compute_encap_len (union) - ") +// ACE_TEXT ("cannot compute scope tc size\n")), +// -1); +// } + +// this->computed_encap_len_ = encap_len + this->computed_scope_encap_len_; + +// // pop off the previous value of computed_scope_len_ +// if (this->pop (this->computed_scope_encap_len_) == -1) +// { +// ACE_ERROR_RETURN ((LM_ERROR, +// ACE_TEXT ("(%N:%l) be_visitor_typecode_defn") +// ACE_TEXT ("::compute_encap_len (union) - ") +// ACE_TEXT ("pop failed\n")), +// -1); +// } + +// return this->computed_encap_len_; +// } + + +// ACE_CDR::Long +// be_visitor_typecode_defn::compute_encap_length (be_union_branch *node) +// { +// be_type *bt; + +// ACE_CDR::Long encap_len = 0; + +// encap_len += 4; // case label; +// encap_len += this->name_encap_len (node); // for name + +// bt = be_type::narrow_from_decl (node->field_type ()); +// this->ctx_->sub_state (TAO_CodeGen::TAO_TC_DEFN_TC_SIZE); + +// if (!bt || bt->accept (this) == -1) +// { +// ACE_ERROR_RETURN ((LM_ERROR, +// ACE_TEXT ("(%N:%l) be_visitor_typecode_defn") +// ACE_TEXT ("::compute_encap_len (union branch) - ") +// ACE_TEXT ("cannot compute tc size\n")), +// -1); +// } + +// encap_len += this->computed_tc_size_; + +// this->computed_encap_len_ = encap_len; + +// this->ctx_->sub_state (TAO_CodeGen::TAO_TC_DEFN_SCOPE_LEN); +// return this->computed_encap_len_; +// } + +// ACE_CDR::Long +// be_visitor_typecode_defn::compute_tc_size (be_valuetype *node) +// { +// // while computing the encapsulation length we must keep in mind the typecode +// // that has gotten generated until this point. Hence, we must first check the +// // "tc_queue" to ensure if are already there somewhere in a previous +// // encapsulation in which case we must count only the bytes for the +// // indirection. If we are not already generated, we must then check if we +// // have already been counted in the current computation or not by checking +// // for our presence in the compute queue. In both cases, we only include the +// // 8 bytes in the computation +// ACE_Unbounded_Queue<AST_Type *> list; + +// if ((be_global->opt_tc () || node->in_recursion (list)) +// && (this->queue_lookup (this->tc_queue_, node) +// || this->queue_lookup (this->compute_queue_, node))) +// { +// this->computed_tc_size_ = 4 + 4; +// } +// else +// { +// // Insert node into tc_queue_ in case the node is involved in +// // some form of recursion. +// if (this->queue_insert (this->compute_queue_, +// node, +// this->tc_offset_) +// == 0) +// { +// ACE_ERROR_RETURN ((LM_ERROR, +// "(%N:%l) be_visitor_typecode_defn::" +// "compute_tc_size (valuetype) - " +// "queue insert failed\n"), +// -1); +// } + +// this->ctx_->sub_state (TAO_CodeGen::TAO_TC_DEFN_ENCAP_LEN); + +// if (node->accept (this) == -1) +// { +// ACE_ERROR_RETURN ((LM_ERROR, +// ACE_TEXT ("(%N:%l) be_visitor_typecode_defn") +// ACE_TEXT ("::compute_tc_size (valuetype) - ") +// ACE_TEXT ("cannot compute encap len\n")), +// -1); +// } + +// this->computed_tc_size_ = 4 + 4 + this->computed_encap_len_; +// } + +// return this->computed_tc_size_; +// } + +// ACE_CDR::Long +// be_visitor_typecode_defn::compute_encap_length (be_valuetype *node) +// { +// // STEP 1: +// ACE_CDR::Long encap_len = 4; // holds the byte order flag + +// // STEP 2: +// encap_len += this->repoID_encap_len (node); // repoID + +// //STEP 3: do the same thing for the local name +// encap_len += this->name_encap_len (node); + +// // STEP 4: +// encap_len += 4; // to hold the ValueModifier + + +// // STEP 5: get encapsulation length for concrete base valuetype +// AST_ValueType *concrete_inherited = node->inherits_concrete (); + +// if (concrete_inherited != 0) +// { +// // Got non-abstract base valuetype. + +// this->computed_tc_size_ = 0; + +// be_valuetype *vt = be_valuetype::narrow_from_decl (concrete_inherited); +// this->ctx_->sub_state (TAO_CodeGen::TAO_TC_DEFN_TC_SIZE); + +// if (!vt || vt->accept (this) == -1) +// { +// ACE_ERROR_RETURN ((LM_ERROR, +// ACE_TEXT ("(%N:%l) be_visitor_typecode_defn") +// ACE_TEXT ("::compute_encap_len (valuetype) - ") +// ACE_TEXT ("failed to compute len\n")), +// -1); +// } +// // revert the state to what it was before +// this->ctx_->sub_state (TAO_CodeGen::TAO_TC_DEFN_ENCAP_LEN); + +// encap_len += this->computed_tc_size_; +// } +// else +// { +// encap_len += 4; // to hold the CORBA::tk_null +// } + +// //STEP 6: +// encap_len += 4; // to hold the member count + +// // save the current value of scope len and start with a fresh one for our +// // scope length computation +// if (this->push (this->computed_scope_encap_len_) == -1) +// { +// ACE_ERROR_RETURN ((LM_ERROR, +// ACE_TEXT ("(%N:%l) be_visitor_typecode_defn") +// ACE_TEXT ("::compute_encap_len (struct) - ") +// ACE_TEXT ("push failed\n")), +// -1); +// } +// this->computed_scope_encap_len_ = 0; + +// // compute encap length for members +// this->ctx_->sub_state (TAO_CodeGen::TAO_TC_DEFN_SCOPE_LEN); + +// if (node->accept (this) == -1) +// { +// ACE_ERROR_RETURN ((LM_ERROR, +// ACE_TEXT ("(%N:%l) be_visitor_typecode_defn") +// ACE_TEXT ("::compute_encap_len (valuetype) - ") +// ACE_TEXT ("cannot compute scope tc size\n")), +// -1); +// } + +// this->computed_encap_len_ = encap_len + this->computed_scope_encap_len_; + +// // pop off the previous value of computed_scope_len_ +// if (this->pop (this->computed_scope_encap_len_) == -1) +// { +// ACE_ERROR_RETURN ((LM_ERROR, +// ACE_TEXT ("(%N:%l) be_visitor_typecode_defn") +// ACE_TEXT ("::compute_encap_len (valuetype) - ") +// ACE_TEXT ("pop failed\n")), +// -1); +// } + +// return this->computed_encap_len_; +// } // helpers that accomplish a common task - that of generating the repository diff --git a/TAO/TAO_IDL/be/be_visitor_typecode/union_typecode.cpp b/TAO/TAO_IDL/be/be_visitor_typecode/union_typecode.cpp new file mode 100644 index 00000000000..bdf4a72a0b2 --- /dev/null +++ b/TAO/TAO_IDL/be/be_visitor_typecode/union_typecode.cpp @@ -0,0 +1,158 @@ +// -*- C++ -*- + +//============================================================================= +/** + * @file union_typecode.cpp + * + * $Id$ + * + * Union TypeCode generation visitor. + * + * @author Ossama Othman <ossama@dre.vanderbilt.edu> + */ +//============================================================================= + + +#include <string> +#include <iostream> + + +TAO::be_visitor_union_typecode::be_visitor_union_typecode ( + be_visitor_context * ctx) + : be_visitor_typecode_defn (ctx) +{ +} + +int +TAO::be_visitor_union_typecode::visit_union (be_union * node) +{ + TAO_OutStream & os = *this->ctx_->stream (); + + os << be_nl << be_nl + << "// TAO_IDL - Generated from" << be_nl + << "// " << __FILE__ << ":" << __LINE__ << be_nl << be_nl; + + + std::string const fields_name (std::string ("_tao_cases_") + + node->flat_name ()); + + + be_type * const discriminant_type = + be_type::narrow_from_decl (node->disc_type ()); + + ACE_ASSERT (discriminant_type != 0); + + std::string const case_array_type ( + std::string ("TAO::TypeCode::Non_Default_Case<") + + std::string (discriminant_type->full_name ()) + + std::string (", char const *>")); + + // Generate array containing union non-default case + // characteristics. + os << "static " << case_array_type.c_str () << " const " + << fields_name.c_str () + << "[] =" << be_idt_nl + << "{" << be_idt_nl; + + be_union_branch * default_case = 0; + if (this->visit_cases (node, default_case) != 0) + return -1; + + os << be_uidt_nl + << "};" << be_uidt_nl << be_nl; + + // Generate the TypeCode instantiation. + os + << "static TAO::TypeCode::Union<char const *," << be_nl + << " " << case_array_type.c_str () + << " const *," << be_nl + << " TAO::Null_RefCount_Policy>" + << be_idt_nl + << "_tao_tc_" << node->flat_name () << " (" << be_idt_nl + << "\"" << node->repoID () << "\"," << be_nl + << "\"" << node->original_local_name () << "\"," << be_nl + << "&" << discriminant_type->tc_name () << "," << be_nl + << "_tao_cases_" << node->flat_name () << "," << be_nl + << node->nfields () << "," + << node->default_index () << "," << be_nl; + + if (default_case) + { + be_type * const type = + be_type::narrow_from_decl (default_case->field_type ()); + + os << "\"" << default_case->original_local_name () << "\", " + << "&" << type->tc_name (); + } + else + { + os << "0, 0"; // No default_case. + } + + os << ");" << be_uidt_nl + << be_uidt_nl; + + return + this->gen_typecode_ptr (be_type::narrow_from_decl (node)); +} + +int +TAO::be_visitor_union_typecode::visit_cases (be_union * node, + be_union_branch *& default_case) +{ + AST_Field ** member_ptr = 0; + + size_t const count = node->nfields (); + + TAO_OutStream & os = *this->ctx_->stream (); + + default_case = 0; + + be_type * const discriminant_type = + be_type::narrow_from_decl (node->disc_type ()); + + for (size_t i = 0; i < count; ++i) + { + node->field (member_ptr, i); + + be_union_branch * const branch = + be_union_branch::narrow_from_decl (*member_ptr); + + ACE_ASSERT (branch != 0); + + if (branch->label ()->label_kind () == AST_UnionLabel::UL_label) + { + // Only deal with non-default cases. The default case has + // special handling in the union TypeCode implementation. + + os << "TAO::TypeCode::Non_Default_Case<" + << discriminant_type->full_name () << ", " + << "char const *> ("; + + // Generate the label value. Only the first label value is + // used in the case where multiple labels are used for the + // same union branch/case. + branch->gen_label_value (&os, 0); + + os << ", "; + + be_type * const type = + be_type::narrow_from_decl ((*member_ptr)->field_type ()); + + os << "\"" << branch->original_local_name () << "\", " + << "&" << type->tc_name () + << ")"; + + if (i < count - (node->default_index () != -1 ? 2 : 1)) + os << ","; + + os << be_nl; + } + else + { + default_case = branch; + } + } + + return 0; +} diff --git a/TAO/TAO_IDL/be/be_visitor_typecode/value_typecode.cpp b/TAO/TAO_IDL/be/be_visitor_typecode/value_typecode.cpp new file mode 100644 index 00000000000..39a56a07cac --- /dev/null +++ b/TAO/TAO_IDL/be/be_visitor_typecode/value_typecode.cpp @@ -0,0 +1,213 @@ +// -*- C++ -*- + +//============================================================================= +/** + * @file value_typecode.cpp + * + * $Id$ + * + * Structure TypeCode generation visitor. + * + * @author Ossama Othman <ossama@dre.vanderbilt.edu> + */ +//============================================================================= + + +#include <string> + + +TAO::be_visitor_value_typecode::be_visitor_value_typecode ( + be_visitor_context * ctx) + : be_visitor_typecode_defn (ctx) +{ +} + +int +TAO::be_visitor_value_typecode::visit_valuetype (be_valuetype * node) +{ + TAO_OutStream & os = *this->ctx_->stream (); + + os << be_nl << be_nl + << "// TAO_IDL - Generated from" << be_nl + << "// " << __FILE__ << ":" << __LINE__ << be_nl << be_nl; + + size_t const count = + node->data_members_count (); + + /* + if (count == 1 && + count == node->nmembers () // Verify no operations. + && node->n_inherits () == 0) + { + // Generate a value box TypeCode. It is more compact than a + // valuetype TypeCode. + + UTL_ScopeActiveIterator si (node, UTL_Scope::IK_decls); + + AST_Decl * const d = si.item (); + + ACE_ASSERT (d); + + AST_Field * const field = AST_Field::narrow_from_decl (d); + + ACE_ASSERT (field); + + be_type * const member_type = + be_type::narrow_from_decl (field->field_type ()); + + // Generate the TypeCode instantiation. + os + << "static TAO::TypeCode::Value_Box<char const *," << be_nl + << " TAO::Null_RefCount_Policy> const" + << be_idt_nl + << "_tao_tc_" << node->flat_name () << " (" << be_idt_nl + << "\"" << node->repoID () << "\"," << be_nl + << "\"" << node->original_local_name () << "\"," << be_nl + << "&" << member_type->tc_name () << ");" << be_uidt_nl + << be_uidt_nl; + } + else + */ + { + std::string const fields_name (std::string ("_tao_fields_") + + node->flat_name ()); + + // Generate array containing struct field characteristics. + os << "static TAO::TypeCode::Value_Field<char const *> " + << fields_name.c_str (); + + if (count == 0) + { + os << " * const = 0;" << be_nl; + } + else + { + os << "[] =" << be_idt_nl + << "{" << be_idt_nl; + + if (this->visit_members (node) != 0) + return -1; + + os << be_uidt_nl + << "};" << be_uidt_nl; + } + + // Generate the TypeCode instantiation. + + os << be_nl + << "static TAO::TypeCode::Value<char const *," << be_nl + << " TAO::TypeCode::Value_Field<char const *> const *," << be_nl + << " CORBA::tk_" + << (dynamic_cast<be_eventtype *> (node) ? "event" : "value") << "," << be_nl + << " TAO::Null_RefCount_Policy> const" + << be_idt_nl + << "_tao_tc_" << node->flat_name () << " (" << be_idt_nl + << "\"" << node->repoID () << "\"," << be_nl + << "\"" << node->original_local_name () << "\"," << be_nl; + + // ValueModifier + // + // TAO doesn't support CUSTOM or TRUNCATABLE valuetypes. Go + // with VM_NONE or VM_ABSTRACT. + os << "CORBA::" + << (node->is_abstract () ? "VM_ABSTRACT" : "VM_NONE") << "," << be_nl; + + // Concrete base type. + AST_ValueType * const concrete_base = + node->inherits_concrete (); + + if (concrete_base) + { + be_type * const base_type = + be_type::narrow_from_decl (concrete_base); + + ACE_ASSERT (base_type); + + os << "&" << base_type->tc_name () << "," << be_nl; + } + else + { + // No concrete base. + os << "&CORBA::tk_null," << be_nl; + } + + // Fields + os << "_tao_fields_" << node->flat_name () << "," << be_nl + << count << ");" << be_uidt_nl + << be_uidt_nl; + } + + return + this->gen_typecode_ptr (be_type::narrow_from_decl (node)); +} + +int +TAO::be_visitor_value_typecode::visit_members (be_valuetype * node) +{ + TAO_OutStream & os = *this->ctx_->stream (); + + size_t const count = + node->data_members_count (); + + size_t i = 0; + + for (UTL_ScopeActiveIterator si (node, UTL_Scope::IK_decls); + !si.is_done (); + si.next(), ++i) + { + AST_Decl * const d = si.item (); + + if (!d) + { + ACE_ERROR_RETURN ((LM_ERROR, + "(%N:%l) be_visitor_value_typecode::visit_members - " + "bad node in this scope\n"), 0); + } + + AST_Field * const field = AST_Field::narrow_from_decl (d); + + if (!field) + { + continue; + } + + be_decl * const member_decl = + be_decl::narrow_from_decl (field); + + be_type * const member_type = + be_type::narrow_from_decl (field->field_type ()); + + os << "{ " + << "\"" << member_decl->original_local_name () << "\", " + << "&" << member_type->tc_name () << ", "; + + AST_Field::Visibility const vis = field->visibility (); + + switch (vis) + { + case AST_Field::vis_PUBLIC: + os << "CORBA::PUBLIC_MEMBER"; + break; + + case AST_Field::vis_PRIVATE: + os << "CORBA::PRIVATE_MEMBER"; + break; + + default: + ACE_ERROR_RETURN ((LM_ERROR, + "(%N:%l) be_visitor_value_typecode::visit_members - " + "Unknown valuetype member visibility.\n"), + -1); + }; + + os << " }"; + + + if (i < count - 1) + os << ","; + + os << be_nl; + } + + return 0; +} diff --git a/TAO/TAO_IDL/be/be_visitor_typedef/typedef_cs.cpp b/TAO/TAO_IDL/be/be_visitor_typedef/typedef_cs.cpp index 5e1cef76908..647a18ab3c1 100644 --- a/TAO/TAO_IDL/be/be_visitor_typedef/typedef_cs.cpp +++ b/TAO/TAO_IDL/be/be_visitor_typedef/typedef_cs.cpp @@ -125,8 +125,8 @@ be_visitor_typedef_cs::visit_typedef (be_typedef *node) if (!node->imported () && be_global->tc_support ()) { be_visitor_context ctx (*this->ctx_); - ctx.sub_state (TAO_CodeGen::TAO_TC_DEFN_TYPECODE); - be_visitor_typecode_defn visitor (&ctx); + // ctx.sub_state (TAO_CodeGen::TAO_TC_DEFN_TYPECODE); + TAO::be_visitor_alias_typecode visitor (&ctx); if (node->accept (&visitor) == -1) { diff --git a/TAO/TAO_IDL/be/be_visitor_union/union_cs.cpp b/TAO/TAO_IDL/be/be_visitor_union/union_cs.cpp index c7257392ecc..fa072653473 100644 --- a/TAO/TAO_IDL/be/be_visitor_union/union_cs.cpp +++ b/TAO/TAO_IDL/be/be_visitor_union/union_cs.cpp @@ -285,9 +285,8 @@ int be_visitor_union_cs::visit_union (be_union *node) if (be_global->tc_support ()) { ctx = *this->ctx_; - ctx.sub_state (TAO_CodeGen::TAO_TC_DEFN_TYPECODE); - - be_visitor_typecode_defn tc_visitor (&ctx); + // ctx.sub_state (TAO_CodeGen::TAO_TC_DEFN_TYPECODE); + TAO::be_visitor_union_typecode tc_visitor (&ctx); if (tc_visitor.visit_union (node) == -1) { diff --git a/TAO/TAO_IDL/be/be_visitor_valuetype/valuetype_cs.cpp b/TAO/TAO_IDL/be/be_visitor_valuetype/valuetype_cs.cpp index af3c2afbe50..3924af75dbc 100644 --- a/TAO/TAO_IDL/be/be_visitor_valuetype/valuetype_cs.cpp +++ b/TAO/TAO_IDL/be/be_visitor_valuetype/valuetype_cs.cpp @@ -47,10 +47,10 @@ be_visitor_valuetype_cs::visit_valuetype (be_valuetype *node) if (be_global->tc_support ()) { be_visitor_context ctx (*this->ctx_); - ctx.sub_state (TAO_CodeGen::TAO_TC_DEFN_TYPECODE); - be_visitor_typecode_defn tc_visitor (&ctx); + // ctx.sub_state (TAO_CodeGen::TAO_TC_DEFN_TYPECODE); + TAO::be_visitor_value_typecode tc_visitor (&ctx); - if (node->accept (&tc_visitor) == -1) + if (tc_visitor.visit_valuetype (node) == -1) { ACE_ERROR_RETURN ((LM_ERROR, "(%N:%l) be_visitor_valuetype_cs::" diff --git a/TAO/TAO_IDL/be_include/be_codegen.h b/TAO/TAO_IDL/be_include/be_codegen.h index 843b27beff7..b1c0fe974f2 100644 --- a/TAO/TAO_IDL/be_include/be_codegen.h +++ b/TAO/TAO_IDL/be_include/be_codegen.h @@ -384,6 +384,7 @@ private: void gen_cond_file_include (bool condition_green, const char *filepath, TAO_OutStream *stream); + void gen_typecode_includes (TAO_OutStream * stream); private: TAO_OutStream *client_header_; diff --git a/TAO/TAO_IDL/be_include/be_sequence.h b/TAO/TAO_IDL/be_include/be_sequence.h index 7e3fb06f448..f6ae364d559 100644 --- a/TAO/TAO_IDL/be_include/be_sequence.h +++ b/TAO/TAO_IDL/be_include/be_sequence.h @@ -1,3 +1,5 @@ +// -*- C++ -*- + // $Id$ // ============================================================================ @@ -102,6 +104,11 @@ public: virtual char *gen_name (void); // Helper to create_name, also used by the traits visitor. +protected: + + virtual void compute_tc_name (void); + // Computes the fully scoped typecode name. + private: const char *smart_fwd_helper_name (AST_Decl *elem_scope, be_type *elem); diff --git a/TAO/TAO_IDL/be_include/be_visitor_typecode.h b/TAO/TAO_IDL/be_include/be_visitor_typecode.h index 1942889a4c8..ae49fe87a1f 100644 --- a/TAO/TAO_IDL/be_include/be_visitor_typecode.h +++ b/TAO/TAO_IDL/be_include/be_visitor_typecode.h @@ -28,5 +28,12 @@ #include "be_visitor_typecode/typecode_decl.h" #include "be_visitor_typecode/typecode_defn.h" +#include "be_visitor_typecode/alias_typecode.h" +#include "be_visitor_typecode/enum_typecode.h" +#include "be_visitor_typecode/objref_typecode.h" +#include "be_visitor_typecode/struct_typecode.h" +#include "be_visitor_typecode/union_typecode.h" +#include "be_visitor_typecode/value_typecode.h" + #endif /* TAO_BE_VISITOR_TYPECODE_H */ diff --git a/TAO/TAO_IDL/be_include/be_visitor_typecode/alias_typecode.h b/TAO/TAO_IDL/be_include/be_visitor_typecode/alias_typecode.h new file mode 100644 index 00000000000..66d182d648a --- /dev/null +++ b/TAO/TAO_IDL/be_include/be_visitor_typecode/alias_typecode.h @@ -0,0 +1,54 @@ +// -*- C++ -*- + +//============================================================================= +/** + * @file alias_typecode.h + * + * $Id$ + * + * Alias (typedef) TypeCode generation visitor. + * + * @author Ossama Othman <ossama@dre.vanderbilt.edu> + */ +//============================================================================= + +#ifndef TAO_BE_VISITOR_ALIAS_TYPECODE_H +#define TAO_BE_VISITOR_ALIAS_TYPECODE_H + +#include "ace/pre.h" + +namespace TAO +{ + + /** + * @class be_visitor_alias_typecode + * + * @brief Alias (typedef) TypeCode generation visitor. + * + * Alias (typedef) TypeCode generation visitor. + */ + class be_visitor_alias_typecode + : public be_visitor_typecode_defn + { + public: + + /// Constructor. + be_visitor_alias_typecode (be_visitor_context * ctx); + + /// Visit a typedef. + /** + * @todo The legacy method name "@c visit_typedef()" is redundant + * since it is obvious from the argument what kind of + * TypeCode is being visited. It will be changed once the + * rest of the legacy method names and their call sites are + * updated accordingly. + */ + virtual int visit_typedef (be_typedef * node); + + }; + +} + +#include "ace/post.h" + +#endif /* TAO_BE_VISITOR_ALIAS_TYPECODE_H */ diff --git a/TAO/TAO_IDL/be_include/be_visitor_typecode/enum_typecode.h b/TAO/TAO_IDL/be_include/be_visitor_typecode/enum_typecode.h new file mode 100644 index 00000000000..2f59ba11665 --- /dev/null +++ b/TAO/TAO_IDL/be_include/be_visitor_typecode/enum_typecode.h @@ -0,0 +1,61 @@ +// -*- C++ -*- + +//============================================================================= +/** + * @file enum_typecode.h + * + * $Id$ + * + * Enumeration TypeCode generation visitor. + * + * @author Ossama Othman <ossama@dre.vanderbilt.edu> + */ +//============================================================================= + +#ifndef TAO_BE_VISITOR_ENUM_TYPECODE_H +#define TAO_BE_VISITOR_ENUM_TYPECODE_H + +#include "ace/pre.h" + +#include "typecode_defn.h" + +namespace TAO +{ + + /** + * @class be_visitor_enum_typecode + * + * @brief Enumeration TypeCode generation visitor. + * + * Enumeration TypeCode generation visitor. + */ + class be_visitor_enum_typecode + : public be_visitor_typecode_defn + { + public: + + /// Constructor. + be_visitor_enum_typecode (be_visitor_context * ctx); + + /// Visit an enumeration. + /** + * @todo The legacy method name "@c visit_enum()" is + * redundant since it is obvious from the argument what kind + * of TypeCode is being visited. It will be changed once + * the rest of the legacy method names and their call sites + * are updated accordingly. + */ + virtual int visit_enum (be_enum * node); + + private: + + /// Generate structure field related TypeCode code. + int visit_members (be_enum * node); + + }; + +} + +#include "ace/post.h" + +#endif /* TAO_BE_VISITOR_ENUM_TYPECODE_H */ diff --git a/TAO/TAO_IDL/be_include/be_visitor_typecode/objref_typecode.h b/TAO/TAO_IDL/be_include/be_visitor_typecode/objref_typecode.h new file mode 100644 index 00000000000..b783395080a --- /dev/null +++ b/TAO/TAO_IDL/be_include/be_visitor_typecode/objref_typecode.h @@ -0,0 +1,72 @@ +// -*- C++ -*- + +//============================================================================= +/** + * @file objref_typecode.h + * + * $Id$ + * + * Object reference TypeCode generation visitor. + * + * @author Ossama Othman <ossama@dre.vanderbilt.edu> + */ +//============================================================================= + +#ifndef TAO_BE_VISITOR_OBJREF_TYPECODE_H +#define TAO_BE_VISITOR_OBJREF_TYPECODE_H + +#include "ace/pre.h" + +namespace TAO +{ + + /** + * @class be_visitor_objref_typecode + * + * @brief TypeCode generation visitor for types with a TypeCode + * format similar to an object reference / interface + * TypeCode. + * + * TypeCode generation visitor for types with a TypeCode format + * similar to an object reference / interface TypeCode. + */ + class be_visitor_objref_typecode + : public be_visitor_typecode_defn + { + public: + + /// Constructor. + be_visitor_objref_typecode (be_visitor_context * ctx); + + /// Visit an object reference / interface. + /** + * @todo The legacy method name "@c visit_interface()" is redundant + * since it is obvious from the argument what kind of + * TypeCode is being visited. It will be changed once the + * rest of the legacy method names and their call sites are + * updated accordingly. + */ + virtual int visit_interface (be_interface * node); + + /// Visit a native. + /** + * @see visit_interface + */ + virtual int visit_native (be_native * node); + + private: + + /// Generate TypeCode instance. + int visit_i (char const * kind, + char const * flat_name, + char const * repository_id, + char const * original_local_name, + be_type * node); + + }; + +} + +#include "ace/post.h" + +#endif /* TAO_BE_VISITOR_OBJREF_TYPECODE_H */ diff --git a/TAO/TAO_IDL/be_include/be_visitor_typecode/struct_typecode.h b/TAO/TAO_IDL/be_include/be_visitor_typecode/struct_typecode.h new file mode 100644 index 00000000000..a58fa8fd932 --- /dev/null +++ b/TAO/TAO_IDL/be_include/be_visitor_typecode/struct_typecode.h @@ -0,0 +1,65 @@ +// -*- C++ -*- + +//============================================================================= +/** + * @file struct_typecode.h + * + * $Id$ + * + * Structure TypeCode generation visitor. + * + * @author Ossama Othman <ossama@dre.vanderbilt.edu> + */ +//============================================================================= + +#ifndef TAO_BE_VISITOR_STRUCT_TYPECODE_H +#define TAO_BE_VISITOR_STRUCT_TYPECODE_H + +#include "ace/pre.h" + +namespace TAO +{ + + /** + * @class be_visitor_struct_typecode + * + * @brief Structure TypeCode generation visitor. + * + * Structure TypeCode generation visitor. + */ + class be_visitor_struct_typecode + : public be_visitor_typecode_defn + { + public: + + /// Constructor. + be_visitor_struct_typecode (be_visitor_context * ctx, + bool is_exception); + + /// Visit a structure. + /** + * @todo The legacy method name "@c visit_structure()" is + * redundant since it is obvious from the argument what kind + * of TypeCode is being visited. It will be changed once + * the rest of the legacy method names and their call sites + * are updated accordingly. + */ + virtual int visit_structure (AST_Structure * node); + + private: + + /// Generate structure field related TypeCode code. + int visit_members (AST_Structure * node); + + private: + + /// Does the TypeCode refer to a CORBA exception? + bool const is_exception_; + + }; + +} + +#include "ace/post.h" + +#endif /* TAO_BE_VISITOR_STRUCT_TYPECODE_H */ diff --git a/TAO/TAO_IDL/be_include/be_visitor_typecode/typecode_defn.h b/TAO/TAO_IDL/be_include/be_visitor_typecode/typecode_defn.h index 31557af93d0..04d8fc3a5db 100644 --- a/TAO/TAO_IDL/be_include/be_visitor_typecode/typecode_defn.h +++ b/TAO/TAO_IDL/be_include/be_visitor_typecode/typecode_defn.h @@ -1,7 +1,6 @@ -/* -*- c++ -*- */ +// -*- C++ -*- // // $Id$ -// // ============================================================================ // @@ -49,10 +48,10 @@ public: ~be_visitor_typecode_defn (void); // destructor - virtual int visit_members (AST_Structure *node); + //virtual int visit_members (AST_Structure *node); // for use with structs, exceptions, and unions. - virtual int visit_members (be_valuetype *node); +// virtual int visit_members (be_valuetype *node); // for use with valuetypes. virtual int visit_type (be_type *node); @@ -63,22 +62,22 @@ public: virtual int visit_array (be_array *node); // visit a array - virtual int visit_enum (be_enum *node); +// virtual int visit_enum (be_enum *node); // visit an enum - virtual int visit_exception (be_exception *node); - // visit an enum +// virtual int visit_exception (be_exception *node); + // visit an exception - virtual int visit_interface (be_interface *node); +// virtual int visit_interface (be_interface *node); // visit interface - virtual int visit_interface_fwd (be_interface_fwd *node); +// virtual int visit_interface_fwd (be_interface_fwd *node); // visit interface - virtual int visit_component (be_component *node); +// virtual int visit_component (be_component *node); // visit component - virtual int visit_predefined_type (be_predefined_type *node); +// virtual int visit_predefined_type (be_predefined_type *node); // visit predefined types virtual int visit_sequence (be_sequence *node); @@ -87,31 +86,28 @@ public: virtual int visit_string (be_string *node); // visit a structure - virtual int visit_structure (be_structure *node); +// virtual int visit_structure (be_structure *node); // visit a structure - virtual int visit_typedef (be_typedef *node); - // visit a typedef - - virtual int visit_union (be_union *node); +// virtual int visit_union (be_union *node); // visit a union - virtual int visit_valuetype (be_valuetype *node); - // visit a valuetype - - virtual int visit_eventtype (be_eventtype *node); - // visit a valuetype +// virtual int visit_valuetype (be_valuetype *node); +// // visit a valuetype + +// virtual int visit_eventtype (be_eventtype *node); +// // visit a valuetype // = visit methods for the scope elements - virtual int visit_enum_val (be_enum_val *node); - // visit the enumeration values +// virtual int visit_enum_val (be_enum_val *node); +// // visit the enumeration values - virtual int visit_field (be_field *node); +// virtual int visit_field (be_field *node); // visit the field (struct and exception member) - virtual int visit_union_branch (be_union_branch *node); +// virtual int visit_union_branch (be_union_branch *node); // visit the union member // = special methods @@ -126,117 +122,117 @@ public: int gen_typecode (be_array *node); - int gen_typecode (be_enum *node); +// int gen_typecode (be_enum *node); - int gen_typecode (be_exception *node); +// int gen_typecode (be_exception *node); - int gen_typecode (be_interface *node); +// int gen_typecode (be_interface *node); - int gen_typecode (be_interface_fwd *node); +// int gen_typecode (be_interface_fwd *node); - int gen_typecode (be_predefined_type *node); +// int gen_typecode (be_predefined_type *node); - int gen_typecode (be_sequence *node); +// int gen_typecode (be_sequence *node); - int gen_typecode (be_string *node); +// int gen_typecode (be_string *node); - int gen_typecode (be_structure *node); +// int gen_typecode (be_structure *node); - int gen_typecode (be_typedef *node); +// int gen_typecode (be_typedef *node); - int gen_typecode (be_union *node); +// int gen_typecode (be_union *node); - int gen_typecode (be_valuetype *node); +// int gen_typecode (be_valuetype *node); // = methods to generate encapsulations for typecodes int gen_encapsulation (be_array *node); - int gen_encapsulation (be_enum *node); +// int gen_encapsulation (be_enum *node); - int gen_encapsulation (be_enum_val *node); +// int gen_encapsulation (be_enum_val *node); - int gen_encapsulation (be_exception *node); +// int gen_encapsulation (be_exception *node); - int gen_encapsulation (be_field *node); +// int gen_encapsulation (be_field *node); - int gen_encapsulation (be_interface *node); +// int gen_encapsulation (be_interface *node); - int gen_encapsulation (be_interface_fwd *node); +// int gen_encapsulation (be_interface_fwd *node); - int gen_encapsulation (be_predefined_type *node); +// int gen_encapsulation (be_predefined_type *node); - int gen_encapsulation (be_sequence *node); +// int gen_encapsulation (be_sequence *node); - int gen_encapsulation (be_string *node); +// int gen_encapsulation (be_string *node); - int gen_encapsulation (be_structure *node); +// int gen_encapsulation (be_structure *node); - int gen_encapsulation (be_typedef *node); +// int gen_encapsulation (be_typedef *node); - int gen_encapsulation (be_union *node); +// int gen_encapsulation (be_union *node); - int gen_encapsulation (be_union_branch *node); +// int gen_encapsulation (be_union_branch *node); - int gen_encapsulation (be_valuetype *node); +// int gen_encapsulation (be_valuetype *node); // = methods for computing typecode sizes ACE_CDR::Long compute_tc_size (be_array *node); - ACE_CDR::Long compute_tc_size (be_enum *node); +// ACE_CDR::Long compute_tc_size (be_enum *node); - ACE_CDR::Long compute_tc_size (be_exception *node); +// ACE_CDR::Long compute_tc_size (be_exception *node); - ACE_CDR::Long compute_tc_size (be_interface *node); +// ACE_CDR::Long compute_tc_size (be_interface *node); - ACE_CDR::Long compute_tc_size (be_interface_fwd *node); +// ACE_CDR::Long compute_tc_size (be_interface_fwd *node); - ACE_CDR::Long compute_tc_size (be_predefined_type *node); +// ACE_CDR::Long compute_tc_size (be_predefined_type *node); - ACE_CDR::Long compute_tc_size (be_sequence *node); +// ACE_CDR::Long compute_tc_size (be_sequence *node); - ACE_CDR::Long compute_tc_size (be_string *node); +// ACE_CDR::Long compute_tc_size (be_string *node); - ACE_CDR::Long compute_tc_size (be_structure *node); +// ACE_CDR::Long compute_tc_size (be_structure *node); - ACE_CDR::Long compute_tc_size (be_typedef *node); +// ACE_CDR::Long compute_tc_size (be_typedef *node); - ACE_CDR::Long compute_tc_size (be_union *node); +// ACE_CDR::Long compute_tc_size (be_union *node); - ACE_CDR::Long compute_tc_size (be_valuetype *node); +// ACE_CDR::Long compute_tc_size (be_valuetype *node); // methods for computing the encapsulation length ACE_CDR::Long compute_encap_length (be_array *node); - ACE_CDR::Long compute_encap_length (be_enum *node); +// ACE_CDR::Long compute_encap_length (be_enum *node); - ACE_CDR::Long compute_encap_length (be_enum_val *node); +// ACE_CDR::Long compute_encap_length (be_enum_val *node); - ACE_CDR::Long compute_encap_length (be_exception *node); +// ACE_CDR::Long compute_encap_length (be_exception *node); - ACE_CDR::Long compute_encap_length (be_field *node); +// ACE_CDR::Long compute_encap_length (be_field *node); - ACE_CDR::Long compute_encap_length (be_interface *node); +// ACE_CDR::Long compute_encap_length (be_interface *node); - ACE_CDR::Long compute_encap_length (be_interface_fwd *node); +// ACE_CDR::Long compute_encap_length (be_interface_fwd *node); - ACE_CDR::Long compute_encap_length (be_predefined_type *node); +// ACE_CDR::Long compute_encap_length (be_predefined_type *node); - ACE_CDR::Long compute_encap_length (be_sequence *node); +// ACE_CDR::Long compute_encap_length (be_sequence *node); - ACE_CDR::Long compute_encap_length (be_string *node); +// ACE_CDR::Long compute_encap_length (be_string *node); - ACE_CDR::Long compute_encap_length (be_structure *node); +// ACE_CDR::Long compute_encap_length (be_structure *node); - ACE_CDR::Long compute_encap_length (be_typedef *node); +// ACE_CDR::Long compute_encap_length (be_typedef *node); - ACE_CDR::Long compute_encap_length (be_union *node); +// ACE_CDR::Long compute_encap_length (be_union *node); - ACE_CDR::Long compute_encap_length (be_union_branch *node); +// ACE_CDR::Long compute_encap_length (be_union_branch *node); - ACE_CDR::Long compute_encap_length (be_valuetype *node); +// ACE_CDR::Long compute_encap_length (be_valuetype *node); // helpers to generate the repoID and name @@ -270,6 +266,23 @@ public: ACE_CDR::Long offset; }; +protected: + + /// Generate the TypeCode_ptr. + /** + * Generate actual TypeCode instance/definition, not the supporting + * code, e.g. "static CORBA::TypeCode_ptr const Foo_ptr = ...". + */ + int gen_typecode_ptr (be_type * node); + + /// Generate the base type TypeCode name. + /** + * Generate the fully qualified base TypeCode name. Predominantly + * useful for TypeCodes that contain base/content TypeCodes + * (e.g. alias, sequence, etc). + */ + int gen_base_typecode_name (be_type * base); + private: // diff --git a/TAO/TAO_IDL/be_include/be_visitor_typecode/union_typecode.h b/TAO/TAO_IDL/be_include/be_visitor_typecode/union_typecode.h new file mode 100644 index 00000000000..d6318da9dc4 --- /dev/null +++ b/TAO/TAO_IDL/be_include/be_visitor_typecode/union_typecode.h @@ -0,0 +1,59 @@ +// -*- C++ -*- + +//============================================================================= +/** + * @file union_typecode.h + * + * $Id$ + * + * Union TypeCode generation visitor. + * + * @author Ossama Othman <ossama@dre.vanderbilt.edu> + */ +//============================================================================= + +#ifndef TAO_BE_VISITOR_UNION_TYPECODE_H +#define TAO_BE_VISITOR_UNION_TYPECODE_H + +#include "ace/pre.h" + +namespace TAO +{ + + /** + * @class be_visitor_union_typecode + * + * @brief Union TypeCode generation visitor. + * + * Union TypeCode generation visitor. + */ + class be_visitor_union_typecode + : public be_visitor_typecode_defn + { + public: + + /// Constructor. + be_visitor_union_typecode (be_visitor_context * ctx); + + /// Visit a union. + /** + * @todo The legacy method name "@c visit_union()" is + * redundant since it is obvious from the argument what kind + * of TypeCode is being visited. It will be changed once + * the rest of the legacy method names and their call sites + * are updated accordingly. + */ + virtual int visit_union (be_union * node); + + private: + + /// Generate union branch related TypeCode code. + int visit_cases (be_union * node, be_union_branch *& default_case); + + }; + +} + +#include "ace/post.h" + +#endif /* TAO_BE_VISITOR_UNION_TYPECODE_H */ diff --git a/TAO/TAO_IDL/be_include/be_visitor_typecode/value_typecode.h b/TAO/TAO_IDL/be_include/be_visitor_typecode/value_typecode.h new file mode 100644 index 00000000000..b52b14c7562 --- /dev/null +++ b/TAO/TAO_IDL/be_include/be_visitor_typecode/value_typecode.h @@ -0,0 +1,59 @@ +// -*- C++ -*- + +//============================================================================= +/** + * @file value_typecode.h + * + * $Id$ + * + * Structure TypeCode generation visitor. + * + * @author Ossama Othman <ossama@dre.vanderbilt.edu> + */ +//============================================================================= + +#ifndef TAO_BE_VISITOR_VALUE_TYPECODE_H +#define TAO_BE_VISITOR_VALUE_TYPECODE_H + +#include "ace/pre.h" + +namespace TAO +{ + + /** + * @class be_visitor_value_typecode + * + * @brief valuetype TypeCode generation visitor. + * + * Structure TypeCode generation visitor. + */ + class be_visitor_value_typecode + : public be_visitor_typecode_defn + { + public: + + /// Constructor. + be_visitor_value_typecode (be_visitor_context * ctx); + + /// Visit a structure. + /** + * @todo The legacy method name "@c visit_valuetype()" is + * redundant since it is obvious from the argument what kind + * of TypeCode is being visited. It will be changed once + * the rest of the legacy method names and their call sites + * are updated accordingly. + */ + virtual int visit_valuetype (be_valuetype * node); + + private: + + /// Generate structure field related TypeCode code. + int visit_members (be_valuetype * node); + + }; + +} + +#include "ace/post.h" + +#endif /* TAO_BE_VISITOR_VALUE_TYPECODE_H */ diff --git a/TAO/tao/Alias_TypeCode.cpp b/TAO/tao/Alias_TypeCode.cpp new file mode 100644 index 00000000000..89ccc9a47da --- /dev/null +++ b/TAO/tao/Alias_TypeCode.cpp @@ -0,0 +1,179 @@ +// $Id$ + +#ifndef TAO_ALIAS_TYPECODE_CPP +#define TAO_ALIAS_TYPECODE_CPP + +#include "tao/Alias_TypeCode.h" + +#ifndef __ACE_INLINE__ +# include "tao/Alias_TypeCode.inl" +#endif /* !__ACE_INLINE__ */ + +#include "tao/TypeCodeFactory_Adapter.h" +#include "tao/ORB_Core.h" +#include "ace/Dynamic_Service.h" + + +template <typename StringType, class RefCountPolicy> +TAO::TypeCode::Alias<StringType, RefCountPolicy>::~Alias (void) +{ + if (this->content_type_) + CORBA::release (*this->content_type_); +} + +template <typename StringType, class RefCountPolicy> +bool +TAO::TypeCode::Alias<StringType, RefCountPolicy>::tao_marshal ( + TAO_OutputCDR & cdr) const +{ + // A tk_alias TypeCode has a "complex" parameter list type (see + // Table 15-2 in Section 15.3.5.1 "TypeCode" in the CDR section of + // the CORBA specification), meaning that it must be marshaled into + // a CDR encapsulation. + + // Create a CDR encapsulation. + return + (cdr << TAO_OutputCDR::from_boolean (TAO_ENCAP_BYTE_ORDER)) + && (cdr << this->attributes_.id ()) + && (cdr << this->attributes_.name ()) + && (cdr << *(this->content_type_.in ())); +} + +template <typename StringType, class RefCountPolicy> +void +TAO::TypeCode::Alias<StringType, RefCountPolicy>::tao_duplicate (void) +{ + this->RefCountPolicy::add_ref (); +} + +template <typename StringType, class RefCountPolicy> +void +TAO::TypeCode::Alias<StringType, RefCountPolicy>::tao_release (void) +{ + this->RefCountPolicy::remove_ref (); +} + +template <typename StringType, class RefCountPolicy> +CORBA::Boolean +TAO::TypeCode::Alias<StringType, RefCountPolicy>::equal_i ( + CORBA::TypeCode_ptr tc + ACE_ENV_ARG_DECL_NOT_USED) const +{ + // The CORBA::TypeCode base class already verified equality of the + // base attributes (id and name). Perform an equality comparison of + // the members. + + CORBA::TypeCode_var rhs_content_type = + tc->content_type (ACE_ENV_SINGLE_ARG_PARAMETER); + ACE_CHECK_RETURN (0); + + return this->content_type_->equal (rhs_content_type.in () + ACE_ENV_ARG_PARAMETER); +} + +template <typename StringType, class RefCountPolicy> +CORBA::Boolean +TAO::TypeCode::Alias<StringType, RefCountPolicy>::equivalent_i ( + CORBA::TypeCode_ptr tc + ACE_ENV_ARG_DECL) const +{ + // We could refactor this code to the CORBA::TypeCode::equivalent() + // method but doing so would force us to determine the unaliased + // kind of this TypeCode. Since we already know the unaliased kind + // of this TypeCode, choose to optimize away the additional kind + // unaliasing operation rather than save space. + + CORBA::TCKind const tc_kind = + TAO::unaliased_kind (tc + ACE_ENV_ARG_PARAMETER); + ACE_CHECK_RETURN (0); + + if (tc_kind != CORBA::tk_alias) + return (0); + + char const * const this_id = this->attributes_.id (); + char const * const tc_id = tc->id (ACE_ENV_SINGLE_ARG_PARAMETER); + ACE_CHECK_RETURN (0); + + if (ACE_OS::strlen (this_id) == 0 + || ACE_OS::strlen (tc_id) == 0) + { + CORBA::TypeCode_var rhs_content_type = + tc->content_type (ACE_ENV_SINGLE_ARG_PARAMETER); + ACE_CHECK_RETURN (0); + + return *(this->content_type_)->equivalent (rhs_content_type.in () + ACE_ENV_ARG_PARAMETER); + } + else if (ACE_OS::strcmp (this_id, tc_id) != 0) + { + return 0; + } + + return 1; +} + +template <typename StringType, class RefCountPolicy> +CORBA::TCKind +TAO::TypeCode::Alias<StringType, RefCountPolicy>::kind_i ( + ACE_ENV_SINGLE_ARG_DECL_NOT_USED) const +{ + return CORBA::tk_alias; +} + +template <typename StringType, class RefCountPolicy> +CORBA::TypeCode_ptr +TAO::TypeCode::Alias<StringType, RefCountPolicy>::get_compact_typecode_i ( + ACE_ENV_SINGLE_ARG_DECL) const +{ + TAO_TypeCodeFactory_Adapter * const adapter = + ACE_Dynamic_Service<TAO_TypeCodeFactory_Adapter>::instance ( + TAO_ORB_Core::typecodefactory_adapter_name () + ); + + if (adapter == 0) + { + ACE_THROW_RETURN (CORBA::INTERNAL (), + CORBA::TypeCode::_nil ()); + } + + CORBA::TypeCode_var compact_content_type = + *(this->content_type_)->get_compact_typecode ( + ACE_ENV_SINGLE_ARG_PARAMETER); + ACE_CHECK_RETURN (CORBA::TypeCode::_nil ()); + + return adapter->create_alias_tc (this->attributes_.id (), + "", /* empty name */ + compact_content_type.in () + ACE_ENV_ARG_PARAMETER); +} + +template <typename StringType, class RefCountPolicy> +char const * +TAO::TypeCode::Alias<StringType, RefCountPolicy>::id_i ( + ACE_ENV_SINGLE_ARG_DECL_NOT_USED) const +{ + // Ownership is retained by the TypeCode, as required by the C++ + // mapping. + return this->attributes_.id (); +} + +template <typename StringType, class RefCountPolicy> +char const * +TAO::TypeCode::Alias<StringType, RefCountPolicy>::name_i ( + ACE_ENV_SINGLE_ARG_DECL_NOT_USED) const +{ + // Ownership is retained by the TypeCode, as required by the C++ + // mapping. + return this->attributes_.name (); +} + +template <typename StringType, class RefCountPolicy> +CORBA::TypeCode_ptr +TAO::TypeCode::Alias<StringType, RefCountPolicy>::content_type_i ( + ACE_ENV_SINGLE_ARG_DECL_NOT_USED) const +{ + return CORBA::TypeCode::_duplicate (*this->content_type_); +} + +#endif /* TAO_ALIAS_TYPECODE_CPP */ diff --git a/TAO/tao/Alias_TypeCode.h b/TAO/tao/Alias_TypeCode.h new file mode 100644 index 00000000000..4d4357541b0 --- /dev/null +++ b/TAO/tao/Alias_TypeCode.h @@ -0,0 +1,133 @@ +// -*- C++ -*- + +//============================================================================= +/** + * @file Alias_TypeCode.h + * + * $Id$ + * + * Header file for a @c tk_alias CORBA::TypeCode. + * + * @author Ossama Othman <ossama@dre.vanderbilt.edu> + */ +//============================================================================= + +#ifndef TAO_ALIAS_TYPECODE_H +#define TAO_ALIAS_TYPECODE_H + +#include /**/ "ace/pre.h" + +#include "tao/TypeCode.h" + +#if !defined (ACE_LACKS_PRAGMA_ONCE) +# pragma once +#endif /* ACE_LACKS_PRAGMA_ONCE */ + +#include "tao/TypeCode_Base_Attributes.h" + + +namespace TAO +{ + namespace TypeCode + { + + /** + * @class Alias + * + * @brief @c CORBA::TypeCode implementation for an OMG IDL + * @c typedef. + * + * This class implements a @c CORBA::TypeCode for an OMG IDL + * @c typedef. + */ + template <typename StringType, class RefCountPolicy> + class Alias + : public CORBA::TypeCode, + private RefCountPolicy + { + public: + + /// Constructor. + Alias (char const * id, + char const * name, + CORBA::TypeCode_ptr const * tc); + + /// Destructor. + ~Alias (void); + + /** + * @name TAO-specific @c CORBA::TypeCode Methods + * + * Methods required by TAO's implementation of the + * @c CORBA::TypeCode class. + * + * @see @c CORBA::TypeCode + */ + //@{ + virtual bool tao_marshal (TAO_OutputCDR & cdr) const; + virtual void tao_duplicate (void); + virtual void tao_release (void); + //@} + + protected: + + /** + * @name @c TAO CORBA::TypeCode Template Methods + * + * @c tk_alias @c CORBA::TypeCode -specific template methods. + * + * @see @c CORBA::TypeCode + */ + //@{ + virtual CORBA::Boolean equal_i (CORBA::TypeCode_ptr tc + ACE_ENV_ARG_DECL) const; + virtual CORBA::Boolean equivalent_i (CORBA::TypeCode_ptr tc + ACE_ENV_ARG_DECL) const; + virtual CORBA::TCKind kind_i (ACE_ENV_SINGLE_ARG_DECL) const; + virtual CORBA::TypeCode_ptr get_compact_typecode_i ( + ACE_ENV_SINGLE_ARG_DECL) const; + virtual char const * id_i (ACE_ENV_SINGLE_ARG_DECL) const; + virtual char const * name_i (ACE_ENV_SINGLE_ARG_DECL) const; + virtual CORBA::TypeCode_ptr content_type_i (ACE_ENV_SINGLE_ARG_DECL) const; + + private: + + /// Base attributes for this @c TypeCode containing the + /// repository ID and name of the @c typedef. + Base_Attributes<StringType> attributes_; + + /// The @c TypeCode corresponding to the original type upon + /// which the IDL @c typedef was made. + /** + * A pointer to the @c CORBA::TypeCode_ptr rather than the + * @c CORBA::TypeCode_ptr itself is stored since that address is + * well-defined. We may not know the value of the @c + * CORBA::TypeCode_ptr when creating this @c Field statically at + * compile-time, hence the indirection. + * + * @note This @c TypeCode is released upon destruction of this + * @c TypeCode::Alias. + */ + CORBA::TypeCode_ptr const * content_type_; + + }; + + } // End namespace TypeCode +} // End namespace TAO + + +#ifdef __ACE_INLINE__ +# include "tao/Alias_TypeCode.inl" +#endif /* __ACE_INLINE__ */ + +#ifdef ACE_TEMPLATES_REQUIRE_SOURCE +# include "tao/Alias_TypeCode.cpp" +#endif /* ACE_TEMPLATES_REQUIRE_SOURCE */ + +#ifdef ACE_TEMPLATES_REQUIRE_PRAGMA +# pragma implementation ("Alias_TypeCode.cpp") +#endif /* ACE_TEMPLATES_REQUIRE_PRAGMA */ + +#include /**/ "ace/post.h" + +#endif /* TAO_ALIAS_TYPECODE_H */ diff --git a/TAO/tao/Alias_TypeCode.inl b/TAO/tao/Alias_TypeCode.inl new file mode 100644 index 00000000000..0b6805d57a5 --- /dev/null +++ b/TAO/tao/Alias_TypeCode.inl @@ -0,0 +1,16 @@ +// -*- C++ -*- +// +// $Id$ + + +template <typename StringType, class RefCountPolicy> +ACE_INLINE +TAO::TypeCode::Alias<StringType, RefCountPolicy>::Alias ( + char const * id, + char const * name, + CORBA::TypeCode_ptr const * tc) + : RefCountPolicy (), + attributes_ (id, name), + content_type_ (tc) +{ +} diff --git a/TAO/tao/Any.cpp b/TAO/tao/Any.cpp index c688e1b4cb6..e881c609647 100644 --- a/TAO/tao/Any.cpp +++ b/TAO/tao/Any.cpp @@ -7,7 +7,8 @@ #include "tao/Any_Dual_Impl_T.h" #include "tao/Any_Unknown_IDL_Type.h" #include "tao/Object.h" -#include "tao/Typecode.h" +#include "tao/TypeCode.h" +#include "tao/TypeCode_Constants.h" #include "tao/SystemException.h" #include "tao/CDR.h" diff --git a/TAO/tao/Any_Basic_Impl.cpp b/TAO/tao/Any_Basic_Impl.cpp index 9afe23ce010..67d925024a7 100644 --- a/TAO/tao/Any_Basic_Impl.cpp +++ b/TAO/tao/Any_Basic_Impl.cpp @@ -1,8 +1,9 @@ // $Id$ #include "tao/Any_Basic_Impl.h" -#include "tao/Typecode.h" #include "tao/Any_Unknown_IDL_Type.h" +#include "tao/Any.h" +#include "tao/TypeCode.h" #include "tao/CDR.h" #include "tao/SystemException.h" @@ -18,8 +19,15 @@ namespace TAO Any_Basic_Impl::Any_Basic_Impl (CORBA::TypeCode_ptr tc, void *value) : Any_Impl (0, tc), - kind_ (tc ? tc->kind_ : CORBA::tk_null) + kind_ (CORBA::tk_null) { + if (!CORBA::is_nil (tc)) + { + ACE_DECLARE_NEW_CORBA_ENV; + this->kind_ = tc->kind (ACE_ENV_SINGLE_ARG_PARAMETER); + ACE_CHECK; + } + CORBA::TCKind const tckind = static_cast<CORBA::TCKind> (this->kind_); switch (tckind) @@ -137,7 +145,7 @@ namespace TAO // Get the kind of the type where we are extracting in ie. the // aliased type if there are any. Passing the aliased kind // will not help. - CORBA::TCKind tck = tc->kind (); + CORBA::TCKind const tck = tc->kind (); // We don't want the rd_ptr of unk to move, in case it is // shared by another Any. This copies the state, not the buffer. @@ -151,7 +159,7 @@ namespace TAO { Any_Basic_Impl::assign_value (_tao_elem, replacement, - tck); + tck); const_cast<CORBA::Any &> (any).replace (replacement); replacement_safety.release (); return 1; @@ -268,7 +276,10 @@ namespace TAO Any_Basic_Impl * Any_Basic_Impl::create_empty (CORBA::TypeCode_ptr tc) { - CORBA::TCKind const kind = static_cast<CORBA::TCKind> (tc->kind_); + ACE_DECLARE_NEW_CORBA_ENV; + CORBA::TCKind const kind = tc->kind (ACE_ENV_SINGLE_ARG_PARAMETER); + ACE_CHECK_RETURN (0); + TAO::Any_Basic_Impl * retval = 0; switch (kind) diff --git a/TAO/tao/Any_Dual_Impl_T.cpp b/TAO/tao/Any_Dual_Impl_T.cpp index be0ac30c674..30bc144035c 100644 --- a/TAO/tao/Any_Dual_Impl_T.cpp +++ b/TAO/tao/Any_Dual_Impl_T.cpp @@ -1,16 +1,17 @@ // $Id$ -#ifndef TAO_ANY_DUAL_IMPL_T_C -#define TAO_ANY_DUAL_IMPL_T_C +#ifndef TAO_ANY_DUAL_IMPL_T_CPP +#define TAO_ANY_DUAL_IMPL_T_CPP #include "tao/Any_Dual_Impl_T.h" +#include "tao/Any.h" #include "tao/Any_Unknown_IDL_Type.h" #include "tao/Marshal.h" #include "tao/CORBA_String.h" #include "tao/Environment.h" #include "tao/SystemException.h" #include "tao/CDR.h" -#include "tao/Typecode.h" +#include "tao/TypeCode.h" #include "ace/CORBA_macros.h" #include "ace/Auto_Ptr.h" @@ -198,4 +199,4 @@ TAO::Any_Dual_Impl_T<T>::_tao_decode (TAO_InputCDR &cdr } } -#endif /* TAO_ANY_DUAL_IMPL_T_C */ +#endif /* TAO_ANY_DUAL_IMPL_T_CPP */ diff --git a/TAO/tao/Any_Impl.cpp b/TAO/tao/Any_Impl.cpp index 8a81a18a9df..90315638c32 100644 --- a/TAO/tao/Any_Impl.cpp +++ b/TAO/tao/Any_Impl.cpp @@ -4,7 +4,7 @@ #include "Marshal.h" #include "CORBA_String.h" #include "SystemException.h" -#include "Typecode.h" +#include "TypeCode.h" #include "ace/Guard_T.h" diff --git a/TAO/tao/Any_Impl_T.cpp b/TAO/tao/Any_Impl_T.cpp index dce88148265..5a06163cfa5 100644 --- a/TAO/tao/Any_Impl_T.cpp +++ b/TAO/tao/Any_Impl_T.cpp @@ -9,7 +9,7 @@ #include "tao/CDR.h" #include "tao/Environment.h" #include "tao/SystemException.h" -#include "tao/Typecode.h" +#include "tao/TypeCode.h" #include "ace/CORBA_macros.h" #include "ace/Auto_Ptr.h" diff --git a/TAO/tao/Any_Special_Impl_T.cpp b/TAO/tao/Any_Special_Impl_T.cpp index 00d2766e517..e9745d7eb26 100644 --- a/TAO/tao/Any_Special_Impl_T.cpp +++ b/TAO/tao/Any_Special_Impl_T.cpp @@ -7,7 +7,7 @@ #include "tao/Any_Unknown_IDL_Type.h" #include "tao/Marshal.h" #include "tao/Environment.h" -#include "tao/Typecode.h" +#include "tao/TypeCode.h" #include "ace/CORBA_macros.h" @@ -47,36 +47,36 @@ TAO::Any_Special_Impl_T<T, from_T, to_T>::insert (CORBA::Any & any, CORBA::ULong bound ) { - CORBA::TypeCode_ptr bounded_tc = CORBA::TypeCode::_nil (); - - if (bound > 0) - { - CORBA::TCKind kind = static_cast<CORBA::TCKind> (tc->kind_); - CORBA::Long _oc_buffer [] = - { - TAO_ENCAP_BYTE_ORDER, - static_cast<CORBA::Long> (bound) - }; - - ACE_NEW (bounded_tc, - CORBA::TypeCode (kind, - sizeof _oc_buffer, - (char *) &_oc_buffer, - 1, - 0)); - } - else - { - bounded_tc = CORBA::TypeCode::_duplicate (tc); - } - - Any_Special_Impl_T<T, from_T, to_T> *new_impl = 0; +// CORBA::TypeCode_ptr bounded_tc = CORBA::TypeCode::_nil (); + +// if (bound > 0) +// { +// CORBA::TCKind kind = static_cast<CORBA::TCKind> (tc->kind_); +// static CORBA::Long _oc_buffer [] = +// { +// TAO_ENCAP_BYTE_ORDER, +// static_cast<CORBA::Long> (bound) +// }; + +// ACE_NEW (bounded_tc, +// CORBA::TypeCode (kind, +// sizeof _oc_buffer, +// (char *) &_oc_buffer, +// 1, +// 0)); +// } +// else +// { +// bounded_tc = CORBA::TypeCode::_duplicate (tc); +// } + + Any_Special_Impl_T<T, from_T, to_T> * new_impl = 0; ACE_NEW (new_impl, Any_Special_Impl_T (destructor, - bounded_tc, + /* bounded_ */ tc, value, bound)); - CORBA::release (bounded_tc); +// CORBA::release (bounded_tc); any.replace (new_impl); } @@ -95,7 +95,8 @@ TAO::Any_Special_Impl_T<T, from_T, to_T>::extract (const CORBA::Any & any, { CORBA::TypeCode_ptr any_type = any._tao_get_typecode (); CORBA::TypeCode_var unaliased_any_type = - any_type->unalias (ACE_ENV_SINGLE_ARG_PARAMETER); + TAO::unaliased_typecode (any_type + ACE_ENV_ARG_PARAMETER); ACE_TRY_CHECK; CORBA::TCKind any_kind = diff --git a/TAO/tao/Any_SystemException.cpp b/TAO/tao/Any_SystemException.cpp index ea168a4f405..84d3444f252 100644 --- a/TAO/tao/Any_SystemException.cpp +++ b/TAO/tao/Any_SystemException.cpp @@ -1,6 +1,7 @@ // $Id$ #include "Any_SystemException.h" +#include "Any.h" #include "Any_Unknown_IDL_Type.h" #include "CDR.h" #include "Exception.h" @@ -8,7 +9,7 @@ #include "Marshal.h" #include "CORBA_String.h" #include "SystemException.h" -#include "Typecode.h" +#include "TypeCode.h" #include "ace/Auto_Ptr.h" #include "ace/CORBA_macros.h" diff --git a/TAO/tao/Any_Unknown_IDL_Type.cpp b/TAO/tao/Any_Unknown_IDL_Type.cpp index 1154674fe69..1f80c2fc3b3 100644 --- a/TAO/tao/Any_Unknown_IDL_Type.cpp +++ b/TAO/tao/Any_Unknown_IDL_Type.cpp @@ -5,15 +5,18 @@ #include "tao/ORB_Core.h" #include "tao/SystemException.h" #include "tao/Marshal.h" -#include "tao/Typecode.h" +#include "tao/TypeCode.h" +#include "tao/CDR.h" #include "ace/Dynamic_Service.h" #include "ace/OS_NS_string.h" + ACE_RCSID (tao, Any_Unknown_IDL_Type, "$Id$") + TAO::Unknown_IDL_Type::Unknown_IDL_Type ( CORBA::TypeCode_ptr tc, TAO_InputCDR &cdr diff --git a/TAO/tao/CDR_Encaps_Codec.cpp b/TAO/tao/CDR_Encaps_Codec.cpp index a01f912d1b2..b732af6cf21 100644 --- a/TAO/tao/CDR_Encaps_Codec.cpp +++ b/TAO/tao/CDR_Encaps_Codec.cpp @@ -8,11 +8,12 @@ #include "OctetSeqC.h" #include "Any.h" #include "Any_Impl.h" -#include "Typecode.h" +#include "TypeCode.h" #include "Marshal.h" #include "Any_Unknown_IDL_Type.h" #include "SystemException.h" #include "ORB_Constants.h" +#include "TypeCode_Constants.h" #include "ace/Auto_Ptr.h" #include "ace/OS_NS_string.h" diff --git a/TAO/tao/DynamicC.h b/TAO/tao/DynamicC.h index d533cfccfa0..74726075f0d 100644 --- a/TAO/tao/DynamicC.h +++ b/TAO/tao/DynamicC.h @@ -43,7 +43,7 @@ #include "tao/TAO_Export.h" #include "tao/ORB.h" #include "tao/Environment.h" -#include "tao/Typecode.h" +#include "tao/TypeCode.h" #include "tao/Sequence_T.h" #include "tao/Seq_Var_T.h" #include "tao/Seq_Out_T.h" diff --git a/TAO/tao/Empty_Param_TypeCode.cpp b/TAO/tao/Empty_Param_TypeCode.cpp new file mode 100644 index 00000000000..cf5980194a2 --- /dev/null +++ b/TAO/tao/Empty_Param_TypeCode.cpp @@ -0,0 +1,88 @@ +// $Id$ + +#include "Empty_Param_TypeCode.h" + +#ifndef __ACE_INLINE__ +# include "Empty_Param_TypeCode.inl" +#endif /* !__ACE_INLINE__ */ + + +ACE_RCSID (tao, + Empty_Param_TypeCode, + "$Id$") + + +bool +TAO::TypeCode::Empty_Param::tao_marshal (TAO_OutputCDR &) const +{ + // Empty parameter list. Nothing to marshal. + + return true; +} + +void +TAO::TypeCode::Empty_Param::tao_duplicate (void) +{ + // No-op since empty parameter TypeCodes are never created + // dynamically, meaning there is no need to implement reference + // counting. +} + +void +TAO::TypeCode::Empty_Param::tao_release (void) +{ + // No-op since empty parameter TypeCodes are never created + // dynamically, meaning there is no need to implement reference + // counting. +} + +CORBA::Boolean +TAO::TypeCode::Empty_Param::equal_i (CORBA::TypeCode_ptr + ACE_ENV_ARG_DECL_NOT_USED) const +{ + // Equality has already been established in the + // CORBA::TypeCode base class. + + return 1; +} + +CORBA::Boolean +TAO::TypeCode::Empty_Param::equivalent_i (CORBA::TypeCode_ptr tc + ACE_ENV_ARG_DECL) const +{ + // We could refactor this code to the CORBA::TypeCode::equivalent() + // method but doing so would force us to determine the unaliased + // kind of this TypeCode. Since we already know the unaliased kind + // of this TypeCode, choose to optimize away the additional kind + // unaliasing operation rather than save space. + + CORBA::TCKind const tc_kind = + TAO::unaliased_kind (tc + ACE_ENV_ARG_PARAMETER); + ACE_CHECK_RETURN (0); + + if (tc_kind != this->kind_) + return 0; + + return 1; +} + +CORBA::TCKind +TAO::TypeCode::Empty_Param::kind_i (ACE_ENV_SINGLE_ARG_DECL_NOT_USED) const +{ + return this->kind_; +} + +CORBA::TypeCode_ptr +TAO::TypeCode::Empty_Param::get_compact_typecode_i ( + ACE_ENV_SINGLE_ARG_DECL_NOT_USED) const +{ + // Already compact since parameter list is empty. + + // Since empty parameter TypeCodes are never created + // dynamically, there is no need to manipulate a reference count. + + static TAO::TypeCode::Empty_Param compact_typecode (this->kind_); + + return &compact_typecode; +} diff --git a/TAO/tao/Empty_Param_TypeCode.h b/TAO/tao/Empty_Param_TypeCode.h new file mode 100644 index 00000000000..7416d9d6161 --- /dev/null +++ b/TAO/tao/Empty_Param_TypeCode.h @@ -0,0 +1,103 @@ +// -*- C++ -*- + +//============================================================================= +/** + * @file Empty_Param_TypeCode.h + * + * $Id$ + * + * Header file for @c CORBA::TypeCodes with empty parameter lists. + * + * @author Ossama Othman <ossama@dre.vanderbilt.edu> + */ +//============================================================================= + +#ifndef TAO_EMPTY_PARAM_TYPECODE_H +#define TAO_EMPTY_PARAM_TYPECODE_H + +#include /**/ "ace/pre.h" + +#include "tao/TypeCode.h" + +#if !defined (ACE_LACKS_PRAGMA_ONCE) +# pragma once +#endif /* ACE_LACKS_PRAGMA_ONCE */ + +namespace TAO +{ + namespace TypeCode + { + + /** + * @class Empty_Param + * + * @brief @c CORBA::TypeCode implementation for OMG IDL types with + * empty parameter lists. + * + * This class implements a @c CORBA::TypeCode for OMG IDL types + * with empty parameter lists. + * + * @note @c Empty_Param @c TypeCodes are not reference counted in + * TAO since they are static, exist as constants for the + * length of a given OS process, and cannot be created + * through the @c CORBA::ORB or @c CORBA::TypeCodeFactory + * interfaces. + */ + class Empty_Param : public CORBA::TypeCode + { + public: + + /// Constructor. + Empty_Param (CORBA::TCKind k); + + /** + * @name TAO-specific @c CORBA::TypeCode Methods + * + * Methods required by TAO's implementation of the + * @c CORBA::TypeCode class. + * + * @see @c CORBA::TypeCode + */ + //@{ + virtual bool tao_marshal (TAO_OutputCDR & cdr) const; + virtual void tao_duplicate (void); + virtual void tao_release (void); + //@} + + protected: + + /** + * @name @c TAO CORBA::TypeCode Template Methods + * + * @c CORBA::TypeCode template methods specific to @c TypeCodes + * with empty parameter lists. + * + * @see @c CORBA::TypeCode + */ + //@{ + virtual CORBA::Boolean equal_i (CORBA::TypeCode_ptr tc + ACE_ENV_ARG_DECL) const; + virtual CORBA::Boolean equivalent_i (CORBA::TypeCode_ptr tc + ACE_ENV_ARG_DECL) const; + virtual CORBA::TCKind kind_i (ACE_ENV_SINGLE_ARG_DECL) const; + virtual CORBA::TypeCode_ptr get_compact_typecode_i ( + ACE_ENV_SINGLE_ARG_DECL) const; + + private: + + /// Kind of this @c TypeCode. + CORBA::TCKind const kind_; + + }; + + } // End namespace TypeCode +} // End namespace TAO + + +#ifdef __ACE_INLINE__ +# include "tao/Empty_Param_TypeCode.inl" +#endif /* __ACE_INLINE__ */ + +#include /**/ "ace/post.h" + +#endif /* TAO_EMPTY_PARAM_TYPECODE_H */ diff --git a/TAO/tao/Empty_Param_TypeCode.inl b/TAO/tao/Empty_Param_TypeCode.inl new file mode 100644 index 00000000000..81a5d13e0d1 --- /dev/null +++ b/TAO/tao/Empty_Param_TypeCode.inl @@ -0,0 +1,10 @@ +// -*- C++ -*- +// +// $Id$ + + +ACE_INLINE +TAO::TypeCode::Empty_Param::Empty_Param (CORBA::TCKind k) + : kind_ (k) +{ +} diff --git a/TAO/tao/Enum_TypeCode.cpp b/TAO/tao/Enum_TypeCode.cpp new file mode 100644 index 00000000000..6ddd437c689 --- /dev/null +++ b/TAO/tao/Enum_TypeCode.cpp @@ -0,0 +1,273 @@ +// $Id$ + +#ifndef TAO_ENUM_TYPECODE_CPP +#define TAO_ENUM_TYPECODE_CPP + +#include "tao/Enum_TypeCode.h" +#include "tao/TypeCode_Enumerator.h" + +#ifndef __ACE_INLINE__ +# include "tao/Enum_TypeCode.inl" +#endif /* !__ACE_INLINE__ */ + + +template <typename StringType, class EnumeratorArrayType, class RefCountPolicy> +bool +TAO::TypeCode::Enum<StringType, + EnumeratorArrayType, + RefCountPolicy>::tao_marshal ( + TAO_OutputCDR & cdr) const +{ + // A tk_enum TypeCode has a "complex" parameter list type (see + // Table 15-2 in Section 15.3.5.1 "TypeCode" in the CDR section of + // the CORBA specification), meaning that it must be marshaled into + // a CDR encapsulation. + + // Create a CDR encapsulation. + bool const success = + (cdr << TAO_OutputCDR::from_boolean (TAO_ENCAP_BYTE_ORDER)) + && (cdr << this->base_attributes_.id ()) + && (cdr << this->base_attributes_.name ()) + && (cdr << this->nenumerators_); + + if (!success) + return false; + + Enumerator<StringType> const * const begin = this->enumerators (); + Enumerator<StringType> const * const end = begin + this->nenumerators_; + + for (Enumerator<StringType> const * i = begin; i != end; ++i) + { + Enumerator<StringType> const & enumerator = *i; + + if (!(cdr << enumerator.get_name ())) + return false; + } + + return true; +} + +template <typename StringType, class EnumeratorArrayType, class RefCountPolicy> +void +TAO::TypeCode::Enum<StringType, + EnumeratorArrayType, + RefCountPolicy>::tao_duplicate (void) +{ + this->RefCountPolicy::add_ref (); +} + +template <typename StringType, class EnumeratorArrayType, class RefCountPolicy> +void +TAO::TypeCode::Enum<StringType, + EnumeratorArrayType, + RefCountPolicy>::tao_release (void) +{ + this->RefCountPolicy::remove_ref (); +} + +template <typename StringType, class EnumeratorArrayType, class RefCountPolicy> +CORBA::Boolean +TAO::TypeCode::Enum<StringType, + EnumeratorArrayType, + RefCountPolicy>::equal_i ( + CORBA::TypeCode_ptr tc + ACE_ENV_ARG_DECL) const +{ + // This call shouldn't throw since CORBA::TypeCode::equal() verified + // that the TCKind is the same as our's prior to invoking this + // method, meaning that member_count() is supported. + + CORBA::ULong const tc_nenumerators = + tc->member_count (ACE_ENV_SINGLE_ARG_PARAMETER); + ACE_CHECK_RETURN (0); + + if (tc_nenumerators != this->nenumerators_) + return 0; + + for (CORBA::ULong i = 0; i < this->nenumerators_; ++i) + { + Enumerator<StringType> const & lhs_enumerator = this->enumerators_[i]; + + char const * const lhs_name = lhs_enumerator.get_name (); + char const * const rhs_name = tc->member_name (i + ACE_ENV_ARG_PARAMETER); + ACE_CHECK_RETURN (0); + + if (ACE_OS::strcmp (lhs_name, rhs_name) != 0) + return 0; + } + + return 1; +} + +template <typename StringType, class EnumeratorArrayType, class RefCountPolicy> +CORBA::Boolean +TAO::TypeCode::Enum<StringType, + EnumeratorArrayType, + RefCountPolicy>::equivalent_i ( + CORBA::TypeCode_ptr tc + ACE_ENV_ARG_DECL) const +{ + // We could refactor this code to the CORBA::TypeCode::equivalent() + // method but doing so would force us to determine the unaliased + // kind of this TypeCode. Since we already know the unaliased kind + // of this TypeCode, choose to optimize away the additional kind + // unaliasing operation rather than save space. + + CORBA::TCKind const tc_kind = + TAO::unaliased_kind (tc + ACE_ENV_ARG_PARAMETER); + ACE_CHECK_RETURN (0); + + // Call kind_i() instead of using CORBA::tk_enum directly since a + // subclass, such as Except_TypeCode, can use this equivalent_i() + // implementation. + CORBA::TCKind const this_kind = + this->kind_i (ACE_ENV_SINGLE_ARG_PARAMETER); + ACE_CHECK_RETURN (0); + + if (tc_kind != this_kind) + return 0; + + char const * const this_id = this->base_attributes_.id (); + char const * const tc_id = tc->id (ACE_ENV_SINGLE_ARG_PARAMETER); + ACE_CHECK_RETURN (0); + + if (ACE_OS::strlen (this_id) == 0 + || ACE_OS::strlen (tc_id) == 0) + { + // Perform a enumural comparison, excluding the name() and + // member_name() operations. + + CORBA::ULong const tc_nenumerators = + tc->member_count (ACE_ENV_SINGLE_ARG_PARAMETER); + ACE_CHECK_RETURN (0); + + if (tc_nenumerators != this->nenumerators_) + return 0; + } + else if (ACE_OS::strcmp (this_id, tc_id) != 0) + { + return 0; + } + + return 1; +} + +template <typename StringType, class EnumeratorArrayType, class RefCountPolicy> +CORBA::TCKind +TAO::TypeCode::Enum<StringType, EnumeratorArrayType, RefCountPolicy>::kind_i ( + ACE_ENV_SINGLE_ARG_DECL_NOT_USED) const +{ + return CORBA::tk_enum; +} + +template <typename StringType, class EnumeratorArrayType, class RefCountPolicy> +CORBA::TypeCode_ptr +TAO::TypeCode::Enum<StringType, + EnumeratorArrayType, + RefCountPolicy>::get_compact_typecode_i ( + ACE_ENV_SINGLE_ARG_DECL) const +{ + Enumerator<StringType> * tc_enumerators = 0; + + ACE_Auto_Array_Ptr<Enumerator<StringType> > safe_enumerators; + + if (this->nenumerators_ > 0) + { + // Dynamically construct a new array of enumerators stripped of + // member names. + + ACE_NEW_THROW_EX (tc_enumerators, + Enumerator<StringType> [this->nenumerators_], + CORBA::NO_MEMORY ()); + ACE_CHECK_RETURN (CORBA::TypeCode::_nil ()); + + safe_enumerators.reset (enumerators); + + static char const * empty_name = ""; + + for (CORBA::ULong i = 0; i < this->nenumerators_; ++i) + { + // Member names will be stripped, i.e. not embedded within + // the compact TypeCode. + + tc_enumerators[i].name = empty_name; + } + } + + TAO_TypeCodeFactory_Adapter * adapter = + ACE_Dynamic_Service<TAO_TypeCodeFactory_Adapter>::instance ( + TAO_ORB_Core::typecodefactory_adapter_name ()); + + if (adapter == 0) + { + ACE_THROW_RETURN (CORBA::INTERNAL (), + CORBA::TypeCode::_nil ()); + } + + CORBA::TCKind const this_kind = + this->kind_i (ACE_ENV_SINGLE_ARG_PARAMETER); + ACE_CHECK_RETURN (CORBA::TypeCode::_nil ()); + + CORBA::TypeCode_var tc = + adapter->_tao_create_enum_tc (this_kind, + this->base_attributes_.id (), + "" /* empty name */, + tc_enumerators, + this->nenumerators_ + ACE_ENV_ARG_PARAMETER); + ACE_CHECK_RETURN (CORBA::TypeCode::_nil ()); + + (void) safe_enumerators.release (); + + return tc._retn (); +} + +template <typename StringType, class EnumeratorArrayType, class RefCountPolicy> +char const * +TAO::TypeCode::Enum<StringType, EnumeratorArrayType, RefCountPolicy>::id_i ( + ACE_ENV_SINGLE_ARG_DECL_NOT_USED) const +{ + // Ownership is retained by the TypeCode, as required by the C++ + // mapping. + return this->base_attributes_.id (); +} + +template <typename StringType, class EnumeratorArrayType, class RefCountPolicy> +char const * +TAO::TypeCode::Enum<StringType, EnumeratorArrayType, RefCountPolicy>::name_i ( + ACE_ENV_SINGLE_ARG_DECL_NOT_USED) const +{ + // Ownership is retained by the TypeCode, as required by the C++ + // mapping. + return this->base_attributes_.name (); +} + +template <typename StringType, class EnumeratorArrayType, class RefCountPolicy> +CORBA::ULong +TAO::TypeCode::Enum<StringType, + EnumeratorArrayType, + RefCountPolicy>::member_count_i ( + ACE_ENV_SINGLE_ARG_DECL_NOT_USED) const +{ + return this->nenumerators_; +} + +template <typename StringType, class EnumeratorArrayType, class RefCountPolicy> +char const * +TAO::TypeCode::Enum<StringType, + EnumeratorArrayType, + RefCountPolicy>::member_name_i ( + CORBA::ULong index + ACE_ENV_ARG_DECL) const +{ + // Ownership is retained by the TypeCode, as required by the C++ + // mapping. + if (index >= this->nenumerators_) + ACE_THROW_RETURN (CORBA::TypeCode::Bounds (), 0); + + return this->enumerators_[index].get_name (); +} + +#endif /* TAO_ENUM_TYPECODE_CPP */ diff --git a/TAO/tao/Enum_TypeCode.h b/TAO/tao/Enum_TypeCode.h new file mode 100644 index 00000000000..402b5c67b56 --- /dev/null +++ b/TAO/tao/Enum_TypeCode.h @@ -0,0 +1,148 @@ +// -*- C++ -*- + +//============================================================================= +/** + * @file Enum_TypeCode.h + * + * $Id$ + * + * Header file for a @c tk_enum CORBA::TypeCode. + * + * @author Ossama Othman <ossama@dre.vanderbilt.edu> + */ +//============================================================================= + +#ifndef TAO_ENUM_TYPECODE_H +#define TAO_ENUM_TYPECODE_H + +#include /**/ "ace/pre.h" + +#include "tao/TypeCode.h" + +#if !defined (ACE_LACKS_PRAGMA_ONCE) +# pragma once +#endif /* ACE_LACKS_PRAGMA_ONCE */ + +#include "tao/TypeCode_Base_Attributes.h" + + +namespace TAO +{ + namespace TypeCode + { + template<typename StringType> class Enumerator; + + /** + * @class Enum + * + * @brief @c CORBA::TypeCode implementation for an OMG IDL + * @c enum. + * + * This class implements a @c CORBA::TypeCode for an OMG IDL + * @c enum. + */ + template <typename StringType, + class EnumeratorArrayType, + class RefCountPolicy> + class Enum + : public CORBA::TypeCode, + private RefCountPolicy + { + public: + + /// Conenumor. + Enum (char const * id, + char const * name, + Enumerator<StringType> const * enumerators, + CORBA::ULong nenumerators); + + /** + * @name TAO-specific @c CORBA::TypeCode Methods + * + * Methods required by TAO's implementation of the + * @c CORBA::TypeCode class. + * + * @see @c CORBA::TypeCode + */ + //@{ + virtual bool tao_marshal (TAO_OutputCDR & cdr) const; + virtual void tao_duplicate (void); + virtual void tao_release (void); + //@} + + protected: + + /** + * @name @c TAO CORBA::TypeCode Template Methods + * + * @c tk_enum @c CORBA::TypeCode -specific template methods. + * + * @see @c CORBA::TypeCode + */ + //@{ + virtual CORBA::Boolean equal_i (CORBA::TypeCode_ptr tc + ACE_ENV_ARG_DECL) const; + virtual CORBA::Boolean equivalent_i (CORBA::TypeCode_ptr tc + ACE_ENV_ARG_DECL) const; + virtual CORBA::TCKind kind_i (ACE_ENV_SINGLE_ARG_DECL) const; + virtual CORBA::TypeCode_ptr get_compact_typecode_i ( + ACE_ENV_SINGLE_ARG_DECL) const; + virtual char const * id_i (ACE_ENV_SINGLE_ARG_DECL) const; + virtual char const * name_i (ACE_ENV_SINGLE_ARG_DECL) const; + virtual CORBA::ULong member_count_i (ACE_ENV_SINGLE_ARG_DECL) const; + virtual char const * member_name_i (CORBA::ULong index + ACE_ENV_ARG_DECL) const; + //@} + + private: + + /// Get pointer to the underlying @c Enumerator array. + Enumerator<StringType> const * enumerators (void) const; + + private: + + /** + * @c Enum Attributes + * + * Attributes representing the structure of an OMG IDL + * @c enum. + * + * @note These attributes are declared in the order in which + * they are marshaled into a CDR stream in order to + * increase cache hits by improving spatial locality. + */ + //@{ + + /// Base attributes containing repository ID and name of + /// structure type. + Base_Attributes<StringType> base_attributes_; + + /// The number of enumerators in the OMG IDL enumeration. + CORBA::ULong const nenumerators_; + + /// Array of @c TAO::TypeCode enumerators representing + /// enumerators in the OMG IDL defined @c enum. + EnumeratorArrayType const enumerators_; + + }; + + } // End namespace TypeCode +} // End namespace TAO + + +#ifdef __ACE_INLINE__ +# include "tao/Enum_TypeCode.inl" +#endif /* __ACE_INLINE__ */ + +#ifdef ACE_TEMPLATES_REQUIRE_SOURCE +# include "tao/Enum_TypeCode.cpp" +#endif /* ACE_TEMPLATES_REQUIRE_SOURCE */ + +#ifdef ACE_TEMPLATES_REQUIRE_PRAGMA +# pragma implementation ("Enum_TypeCode.cpp") +#endif /* ACE_TEMPLATES_REQUIRE_PRAGMA */ + + +#include /**/ "ace/post.h" + +#endif /* TAO_ENUM_TYPECODE_H */ diff --git a/TAO/tao/Enum_TypeCode.inl b/TAO/tao/Enum_TypeCode.inl new file mode 100644 index 00000000000..a55f91dbada --- /dev/null +++ b/TAO/tao/Enum_TypeCode.inl @@ -0,0 +1,16 @@ +// -*- C++ -*- +// +// $Id$ + +template <typename StringType, class AttrType, class RefCountPolicy> +ACE_INLINE +TAO::TypeCode::Enum<StringType, AttrType, RefCountPolicy>::Enum ( + char const * id, + char const * name, + Enumerator<StringType> const * enumerators, + CORBA::ULong nenumerators) + : base_attributes_ (id, name) + , nenumerators_ (nenumerators) + , enumerators_ (enumerators) +{ +} diff --git a/TAO/tao/Exception.cpp b/TAO/tao/Exception.cpp index e8711f28f66..92e4d7df62e 100644 --- a/TAO/tao/Exception.cpp +++ b/TAO/tao/Exception.cpp @@ -5,9 +5,9 @@ #include "Environment.h" #include "Any_SystemException.h" #include "Any_Dual_Impl_T.h" -#include "Typecode.h" +#include "TypeCode.h" #include "ORB_Constants.h" -#include "TC_Constants_Forward.h" +#include "TypeCode_Constants.h" #include "CORBA_String.h" #include "CDR.h" #include "debug.h" diff --git a/TAO/tao/Fixed_TypeCode.cpp b/TAO/tao/Fixed_TypeCode.cpp new file mode 100644 index 00000000000..177b7602d0f --- /dev/null +++ b/TAO/tao/Fixed_TypeCode.cpp @@ -0,0 +1,127 @@ +// $Id$ + +#ifndef TAO_FIXED_TYPECODE_CPP +#define TAO_FIXED_TYPECODE_CPP + +#include "Fixed_TypeCode.h" + +#ifndef __ACE_INLINE__ +# include "tao/Fixed_TypeCode.inl" +#endif /* !__ACE_INLINE__ */ + + +template <class RefCountPolicy> +bool +TAO::TypeCode::Fixed<RefCountPolicy>::tao_marshal (TAO_OutputCDR & cdr) const +{ + // A tk_fixed TypeCode has a "simple" parameter list type (see + // Table 15-2 in Section 15.3.5.1 "TypeCode" in the CDR section of + // the CORBA specification), meaning that its parameter(s) must be + // marshaled immediately following the TCKind. No CDR encapsulation + // is to be created. + + return (cdr << this->digits_) && (cdr << this->scale_); +} + +template <class RefCountPolicy> +void +TAO::TypeCode::Fixed<RefCountPolicy>::tao_duplicate (void) +{ + this->RefCountPolicy::add_ref (); +} + +template <class RefCountPolicy> +void +TAO::TypeCode::Fixed<RefCountPolicy>::tao_release (void) +{ + this->RefCountPolicy::remove_ref (); +} + +template <class RefCountPolicy> +CORBA::Boolean +TAO::TypeCode::Fixed<RefCountPolicy>::equal_i (CORBA::TypeCode_ptr tc + ACE_ENV_ARG_DECL) const +{ + // The following call won't throw since CORBA::TypeCode::equal() has + // already established the kind of tc is the same as our kind. + CORBA::UShort const tc_digits = + tc->fixed_digits (ACE_ENV_SINGLE_ARG_PARAMETER); + ACE_CHECK_RETURN (0); + + CORBA::UShort const tc_scale = + tc->fixed_scale (ACE_ENV_SINGLE_ARG_PARAMETER); + ACE_CHECK_RETURN (0); + + return (this->digits_ == tc_digits + && this->scale_ == tc_scale); +} + +template <class RefCountPolicy> +CORBA::Boolean +TAO::TypeCode::Fixed<RefCountPolicy>::equivalent_i (CORBA::TypeCode_ptr tc + ACE_ENV_ARG_DECL) const +{ + // We could refactor this code to the CORBA::TypeCode::equivalent() + // method but doing so would force us to determine the unaliased + // kind of this TypeCode. Since we already know the unaliased kind + // of this TypeCode, choose to optimize away the additional kind + // unaliasing operation rather than save space. + + CORBA::TCKind const tc_kind = + TAO::unaliased_kind (tc + ACE_ENV_ARG_PARAMETER); + ACE_CHECK_RETURN (0); + + // Call kind_i() instead of using CORBA::tk_fixed directly since a + // subclass, such as WFixed_TypeCode, can use this equivalent_i() + // implementation. + CORBA::TCKind const this_kind = + this->kind_i (ACE_ENV_SINGLE_ARG_PARAMETER); + ACE_CHECK_RETURN (0); + + if (tc_kind != this_kind) + return 0; + + // Since TCKind comparisons must be performed before equal_i() is + // called, we can also call it to determine equivalence of + // tk_fixed TypeCodes. + return this->equal_i (ACE_ENV_SINGLE_ARG_PARAMETER); +} + +template <class RefCountPolicy> +CORBA::TCKind +TAO::TypeCode::Fixed<RefCountPolicy>::kind_i ( + ACE_ENV_SINGLE_ARG_DECL_NOT_USED) const +{ + return CORBA::tk_fixed; +} + +template <class RefCountPolicy> +CORBA::TypeCode_ptr +TAO::TypeCode::Fixed<RefCountPolicy>::get_compact_typecode_i ( + ACE_ENV_SINGLE_ARG_DECL_NOT_USED) const +{ + // Already compact since tk_fixed TypeCodes have no name or member + // names, meaning that we can simply call _duplicate() on this + // TypeCode. + return CORBA::TypeCode::_duplicate (this); +} + +template <class RefCountPolicy> +CORBA::UShort +TAO::TypeCode::Fixed<RefCountPolicy>::fixed_digits_i ( + ACE_ENV_SINGLE_ARG_DECL_NOT_USED) const +{ + return this->digits_; +} + +template <class RefCountPolicy> +CORBA::UShort +TAO::TypeCode::Fixed<RefCountPolicy>::fixed_scale_i ( + ACE_ENV_SINGLE_ARG_DECL_NOT_USED) const +{ + return this->scale_; +} + + +#endif /* TAO_FIXED_TYPECODE_CPP */ diff --git a/TAO/tao/Fixed_TypeCode.h b/TAO/tao/Fixed_TypeCode.h new file mode 100644 index 00000000000..aff9cc46dba --- /dev/null +++ b/TAO/tao/Fixed_TypeCode.h @@ -0,0 +1,104 @@ +// -*- C++ -*- + +//============================================================================= +/** + * @file Fixed_TypeCode.h + * + * $Id$ + * + * Header file for @c CORBA::tk_fixed @c CORBA::TypeCodes. + * + * @author Ossama Othman <ossama@dre.vanderbilt.edu> + */ +//============================================================================= + +#ifndef TAO_FIXED_TYPECODE_H +#define TAO_FIXED_TYPECODE_H + +#include /**/ "ace/pre.h" + +#include "tao/TypeCode.h" + +#if !defined (ACE_LACKS_PRAGMA_ONCE) +# pragma once +#endif /* ACE_LACKS_PRAGMA_ONCE */ + +namespace TAO +{ + namespace TypeCode + { + + /** + * @class Fixed + * + * @brief @c CORBA::TypeCode implementation for the OMG IDL @fixed + * types. + * + * This class implements a @c CORBA::TypeCode for the OMG IDL @c + * fixed types. + */ + template <class RefCountPolicy> + class Fixed : public CORBA::TypeCode + : private RefCountPolicy + { + public: + + /// Constructor. + Fixed (CORBA::UShort digits, CORBA::UShort scale); + + /** + * @name TAO-specific @c CORBA::TypeCode Methods + * + * Methods required by TAO's implementation of the + * @c CORBA::TypeCode class. + * + * @see @c CORBA::TypeCode + */ + //@{ + virtual bool tao_marshal (TAO_OutputCDR & cdr) const; + virtual void tao_duplicate (void); + virtual void tao_release (void); + //@} + + protected: + + /** + * @name @c TAO CORBA::TypeCode Template Methods + * + * @c CORBA::TypeCode template methods specific to @c tk_fixed + * @c TypeCodes. + * + * @see @c CORBA::TypeCode + */ + //@{ + virtual CORBA::Boolean equal_i (CORBA::TypeCode_ptr tc + ACE_ENV_ARG_DECL) const; + virtual CORBA::Boolean equivalent_i (CORBA::TypeCode_ptr tc + ACE_ENV_ARG_DECL) const; + virtual CORBA::TCKind kind_i (ACE_ENV_SINGLE_ARG_DECL) const; + virtual CORBA::TypeCode_ptr get_compact_typecode_i ( + ACE_ENV_SINGLE_ARG_DECL) const; + virtual UShort fixed_digits_i (ACE_ENV_SINGLE_ARG_DECL) const; + virtual UShort fixed_scale_i (ACE_ENV_SINGLE_ARG_DECL) const; + + private: + + /// The number of significant digits. + CORBA::UShort const digits_; + + /// The scale factor. + CORBA::UShort const scale_; + + }; + + } // End namespace TypeCode +} // End namespace TAO + + +#ifdef __ACE_INLINE__ +# include "tao/Fixed_TypeCode.inl" +#endif /* __ACE_INLINE__ */ + +#include /**/ "ace/post.h" + +#endif /* TAO_FIXED_TYPECODE_H */ diff --git a/TAO/tao/Fixed_TypeCode.inl b/TAO/tao/Fixed_TypeCode.inl new file mode 100644 index 00000000000..16217258126 --- /dev/null +++ b/TAO/tao/Fixed_TypeCode.inl @@ -0,0 +1,12 @@ +// -*- C++ -*- +// +// $Id$ + +template <class RefCountPolicy> +ACE_INLINE +TAO::TypeCode::Fixed<RefCountPolicy::Fixed (CORBA::UShort digits, + CORBA::UShort scale) + : digits_ (digits), + scale_ (scale) +{ +} diff --git a/TAO/tao/IOP_CodecC.h b/TAO/tao/IOP_CodecC.h index 518720d63e7..e896c1dc77d 100644 --- a/TAO/tao/IOP_CodecC.h +++ b/TAO/tao/IOP_CodecC.h @@ -45,7 +45,7 @@ #include "tao/SystemException.h" #include "tao/Environment.h" #include "tao/Object.h" -#include "tao/Typecode.h" +#include "tao/TypeCode.h" #include "tao/Any.h" #include "tao/Objref_VarOut_T.h" #include "tao/VarOut_T.h" diff --git a/TAO/tao/Invocation_Base.cpp b/TAO/tao/Invocation_Base.cpp index 08b0253c9fe..46caafc77e9 100644 --- a/TAO/tao/Invocation_Base.cpp +++ b/TAO/tao/Invocation_Base.cpp @@ -2,7 +2,7 @@ #include "Stub.h" #include "operation_details.h" #include "ORB_Core.h" -#include "Typecode.h" +#include "TypeCode.h" #include "DynamicC.h" #include "SystemException.h" diff --git a/TAO/tao/Marshal.cpp b/TAO/tao/Marshal.cpp index 16826a284ca..b63181880a5 100644 --- a/TAO/tao/Marshal.cpp +++ b/TAO/tao/Marshal.cpp @@ -22,7 +22,7 @@ // ============================================================================ #include "tao/Marshal.h" -#include "tao/Typecode.h" +#include "tao/TypeCode.h" #if !defined (__ACE_INLINE__) # include "tao/Marshal.i" diff --git a/TAO/tao/NVList.cpp b/TAO/tao/NVList.cpp index fdfb2213e16..9049d4434b0 100644 --- a/TAO/tao/NVList.cpp +++ b/TAO/tao/NVList.cpp @@ -7,7 +7,7 @@ #include "tao/SystemException.h" #include "tao/BoundsC.h" -#include "tao/Typecode.h" +#include "tao/TypeCode.h" #include "tao/Marshal.h" #include "tao/CORBA_String.h" #include "tao/Any_Impl.h" diff --git a/TAO/tao/Null_RefCount_Policy.h b/TAO/tao/Null_RefCount_Policy.h new file mode 100644 index 00000000000..fd4ea8e2f57 --- /dev/null +++ b/TAO/tao/Null_RefCount_Policy.h @@ -0,0 +1,77 @@ +// -*- C++ -*- + +//============================================================================= +/** + * @file Null_RefCount_Policy.h + * + * $Id$ + * + * Header file for TAO's reference count policy (unrelated to CORBA + * policies). + * + * @author Ossama Othman <ossama@dre.vanderbilt.edu> + */ +//============================================================================= + +#ifndef TAO_NULL_REFCOUNT_POLICY_H +#define TAO_NULL_REFCOUNT_POLICY_H + +#include /**/ "ace/pre.h" + +#include "tao/TAO_Export.h" + +#if !defined (ACE_LACKS_PRAGMA_ONCE) +# pragma once +#endif /* ACE_LACKS_PRAGMA_ONCE */ + +namespace TAO +{ + /** + * @class Null_RefCount_Policy + * + * @brief No-op reference counting policy. + * + * This class is intended to be used as a "policy" argument to a + * host class template that implements no-op reference counting. + * That class would then inherit privately from it like so: + * + * @code + * template <class RefCountPolicy> + * class MyHostClass : private RefCountPolicy + * { + * public: + * void my_add_ref (void) { this->RefCountPolicy::add_ref (); } + * void my_remove_ref (void) { this->RefCountPolicy::remove_ref (); } + * }; + * @endcode + * + * and use it like so: + * + * @code + * typedef MyHostClass<TAO::Null_RefCount_Policy> MyNonRefCountedClass; + * MyNonRefCountedClass m; + * ... + * @endcode + * + * @note In order to incur no size overhead on the host class due to + * virtual tables, no base class defining an interface is + * defined. This allows C++ compilers to apply the Empty Base + * Class Optimization. + */ + class TAO_Export Null_RefCount_Policy + { + public: + + /// No-op reference increment. + void add_ref (void) { } + + /// No-op reference decrement. + void remove_ref (void) { } + + }; + +} // End namespace TAO + +#include /**/ "ace/post.h" + +#endif /* TAO_NULL_REFCOUNT_POLICY_H */ diff --git a/TAO/tao/ORB.cpp b/TAO/tao/ORB.cpp index 4a726b06e0f..52adbb18774 100644 --- a/TAO/tao/ORB.cpp +++ b/TAO/tao/ORB.cpp @@ -9,7 +9,6 @@ ACE_RCSID (tao, #include "ORB_Table.h" #include "Connector_Registry.h" #include "IOR_Parser.h" -#include "Typecode_Constants.h" #include "Stub.h" #include "ORB_Core.h" #include "TAO_Internal.h" @@ -1304,7 +1303,7 @@ TAO::ORB::init_orb_globals (ACE_ENV_SINGLE_ARG_DECL) } // initialize the system TypeCodes - TAO::TypeCode_Constants::init (); +// TAO::TypeCode_Constants::init (); // initialize the system exceptions TAO_Exceptions::init (ACE_ENV_SINGLE_ARG_PARAMETER); diff --git a/TAO/tao/ORB.h b/TAO/tao/ORB.h index 7bd410a275d..dcdea3771f3 100644 --- a/TAO/tao/ORB.h +++ b/TAO/tao/ORB.h @@ -8,8 +8,9 @@ * * Header file for CORBA's ORB type. * - * @author Copyright 1994-1995 by Sun Microsystems Inc. - * @author Douglas C. Schmidt <schmidt@dre.vanderbilt.edu.edu> + * @author DOC Center - Washington University at St. Louis + * @author DOC Group - Vanderbilt University + * @author DOC Laboratory - University of California at Irvine */ //============================================================================= @@ -154,22 +155,22 @@ namespace CORBA virtual void _raise (void) const; virtual void _tao_encode (TAO_OutputCDR & - ACE_ENV_ARG_DECL_NOT_USED) const; + ACE_ENV_ARG_DECL) const; virtual void _tao_decode (TAO_InputCDR & - ACE_ENV_ARG_DECL_NOT_USED); + ACE_ENV_ARG_DECL); }; typedef char *ObjectId; typedef CORBA::String_var ObjectId_var; typedef CORBA::String_out ObjectId_out; - static CORBA::TypeCode_ptr _tc_ObjectId; + static CORBA::TypeCode_ptr const _tc_ObjectId; typedef CORBA::ORB_ObjectIdList ObjectIdList; typedef CORBA::ORB_ObjectIdList_var ObjectIdList_var; typedef CORBA::ORB_ObjectIdList_out ObjectIdList_out; typedef CORBA::ORB_ObjectIdList *ObjectIdList_ptr; - static CORBA::TypeCode_ptr _tc_ObjectIdList; + static CORBA::TypeCode_ptr const _tc_ObjectIdList; /// Return a duplicate of @c orb. /** @@ -377,7 +378,7 @@ namespace CORBA CORBA::TypeCode_ptr create_local_interface_tc ( const char *id, - const char *ame + const char *name ACE_ENV_ARG_DECL_WITH_DEFAULTS); CORBA::TypeCode_ptr create_component_tc ( @@ -581,7 +582,8 @@ namespace CORBA ACE_Time_Value *get_timeout (void); protected: - // We must be created via the @c ORB_init() call. + + // We must be created via the @c CORBA::ORB_init() function. ORB (TAO_ORB_Core *orb_core); /// Destructor @@ -596,12 +598,12 @@ namespace CORBA /// Resolve the Policy Manager for this ORB. CORBA::Object_ptr resolve_policy_manager ( - ACE_ENV_SINGLE_ARG_DECL_NOT_USED + ACE_ENV_SINGLE_ARG_DECL ); /// Resolve the Policy Current for this thread. CORBA::Object_ptr resolve_policy_current ( - ACE_ENV_SINGLE_ARG_DECL_NOT_USED + ACE_ENV_SINGLE_ARG_DECL ); private: @@ -623,7 +625,7 @@ namespace CORBA void check_shutdown (ACE_ENV_SINGLE_ARG_DECL); /// Set the timeout value - void set_timeout (ACE_Time_Value *timeout); + void set_timeout (ACE_Time_Value * timeout); private: @@ -645,7 +647,7 @@ namespace CORBA ORB &operator= (const ORB &); /// Timeout value - ACE_Time_Value *timeout_; + ACE_Time_Value * timeout_; }; } // End namespace CORBA diff --git a/TAO/tao/Objref_TypeCode.cpp b/TAO/tao/Objref_TypeCode.cpp new file mode 100644 index 00000000000..26a5b7bcd25 --- /dev/null +++ b/TAO/tao/Objref_TypeCode.cpp @@ -0,0 +1,146 @@ +// $Id$ + +#ifndef TAO_OBJREF_TYPECODE_CPP +#define TAO_OBJREF_TYPECODE_CPP + +#include "tao/Objref_TypeCode.h" + +#ifndef __ACE_INLINE__ +# include "tao/Objref_TypeCode.inl" +#endif /* !__ACE_INLINE__ */ + +#include "tao/ORB_Core.h" +#include "tao/CDR.h" + +#include "ace/Dynamic_Service.h" + + +template <typename StringType, CORBA::TCKind Kind, class RefCountPolicy> +bool +TAO::TypeCode::Objref<StringType, + Kind, + RefCountPolicy>::tao_marshal (TAO_OutputCDR & cdr) const +{ + // A tk_objref TypeCode has a "complex" parameter list type (see + // Table 15-2 in Section 15.3.5.1 "TypeCode" in the CDR section of + // the CORBA specification), meaning that it must be marshaled into + // a CDR encapsulation. + + // Create a CDR encapsulation. + return + (cdr << TAO_OutputCDR::from_boolean (TAO_ENCAP_BYTE_ORDER)) + && (cdr << TAO_OutputCDR::from_string (this->attributes_.id (), 0)) + && (cdr << TAO_OutputCDR::from_string (this->attributes_.name (), 0)); +} + +template <typename StringType, CORBA::TCKind Kind, class RefCountPolicy> +void +TAO::TypeCode::Objref<StringType, Kind, RefCountPolicy>::tao_duplicate (void) +{ + this->RefCountPolicy::add_ref (); +} + +template <typename StringType, CORBA::TCKind Kind, class RefCountPolicy> +void +TAO::TypeCode::Objref<StringType, Kind, RefCountPolicy>::tao_release (void) +{ + this->RefCountPolicy::remove_ref (); +} + +template <typename StringType, CORBA::TCKind Kind, class RefCountPolicy> +CORBA::Boolean +TAO::TypeCode::Objref<StringType, Kind, RefCountPolicy>::equal_i ( + CORBA::TypeCode_ptr /* tc */ + ACE_ENV_ARG_DECL_NOT_USED) const +{ + // Equality has already been established in the + // CORBA::TypeCode base class. + + return 1; +} + +template <typename StringType, CORBA::TCKind Kind, class RefCountPolicy> +CORBA::Boolean +TAO::TypeCode::Objref<StringType, Kind, RefCountPolicy>::equivalent_i ( + CORBA::TypeCode_ptr tc + ACE_ENV_ARG_DECL) const +{ + // We could refactor this code to the CORBA::TypeCode::equivalent() + // method but doing so would force us to determine the unaliased + // kind of this TypeCode. Since we already know the unaliased kind + // of this TypeCode, choose to optimize away the additional kind + // unaliasing operation rather than save space. + + CORBA::TCKind const tc_kind = + TAO::unaliased_kind (tc + ACE_ENV_ARG_PARAMETER); + ACE_CHECK_RETURN (0); + + if (tc_kind != Kind) + return 0; + + char const * const this_id = this->attributes_.id (); + char const * const tc_id = tc->id (ACE_ENV_SINGLE_ARG_PARAMETER); + ACE_CHECK_RETURN (0); + + if (ACE_OS::strcmp (this_id, tc_id) != 0) + return 0; + + return 1; +} + +template <typename StringType, CORBA::TCKind Kind, class RefCountPolicy> +CORBA::TCKind +TAO::TypeCode::Objref<StringType, Kind, RefCountPolicy>::kind_i ( + ACE_ENV_SINGLE_ARG_DECL_NOT_USED) const +{ + return Kind; +} + +template <typename StringType, CORBA::TCKind Kind, class RefCountPolicy> +CORBA::TypeCode_ptr +TAO::TypeCode::Objref<StringType, + Kind, + RefCountPolicy>::get_compact_typecode_i ( + ACE_ENV_SINGLE_ARG_DECL) const +{ + TAO_TypeCodeFactory_Adapter * const adapter = + ACE_Dynamic_Service<TAO_TypeCodeFactory_Adapter>::instance ( + TAO_ORB_Core::typecodefactory_adapter_name () + ); + + if (adapter == 0) + { + ACE_THROW_RETURN (CORBA::INTERNAL (), + CORBA::TypeCode::_nil ()); + } + + return + Objref_Traits<Kind>::create_compact_typecode (adapter, + this->attributes_.id () + ACE_ENV_ARG_PARAMETER); +} + + +template <typename StringType, CORBA::TCKind Kind, class RefCountPolicy> +char const * +TAO::TypeCode::Objref<StringType, Kind, RefCountPolicy>::id_i ( + ACE_ENV_SINGLE_ARG_DECL_NOT_USED) const +{ + // Ownership is retained by the TypeCode, as required by the C++ + // mapping. + return this->attributes_.id (); +} + +template <typename StringType, CORBA::TCKind Kind, class RefCountPolicy> +char const * +TAO::TypeCode::Objref<StringType, Kind, RefCountPolicy>::name_i ( + ACE_ENV_SINGLE_ARG_DECL_NOT_USED) const +{ + // Ownership is retained by the TypeCode, as required by the C++ + // mapping. + return this->attributes_.name (); +} + + +#endif /* TAO_OBJREF_TYPECODE_CPP */ diff --git a/TAO/tao/Objref_TypeCode.h b/TAO/tao/Objref_TypeCode.h new file mode 100644 index 00000000000..e0129b23f93 --- /dev/null +++ b/TAO/tao/Objref_TypeCode.h @@ -0,0 +1,214 @@ +// -*- C++ -*- + +//============================================================================= +/** + * @file Objref_TypeCode.h + * + * $Id$ + * + * Header file for + * @c tk_abstract_interface, + * @c tk_component, + * @c tk_local_interface, + * @c tk_native and + * @c tk_objref + * @c CORBA::TypeCodes. + * + * @author Ossama Othman <ossama@dre.vanderbilt.edu> + */ +//============================================================================= + +#ifndef TAO_OBJREF_TYPECODE_H +#define TAO_OBJREF_TYPECODE_H + +#include /**/ "ace/pre.h" + +#include "tao/TypeCode.h" + +#if !defined (ACE_LACKS_PRAGMA_ONCE) +# pragma once +#endif /* ACE_LACKS_PRAGMA_ONCE */ + +#include "tao/TypeCodeFactory_Adapter.h" + +#include "tao/TypeCode_Base_Attributes.h" + +namespace TAO +{ + namespace TypeCode + { + template <CORBA::TCKind KIND> struct Objref_Traits; + + template <> + struct Objref_Traits<CORBA::tk_abstract_interface> + { + static + CORBA::TypeCode_ptr + create_compact_typecode (TAO_TypeCodeFactory_Adapter * factory, + char const * id + ACE_ENV_ARG_DECL) + { + return factory->create_abstract_interface_tc (id, + "" /* empty name */ + ACE_ENV_ARG_PARAMETER); + } + }; + + template <> + struct Objref_Traits<CORBA::tk_component> + { + static + CORBA::TypeCode_ptr + create_compact_typecode (TAO_TypeCodeFactory_Adapter * factory, + char const * id + ACE_ENV_ARG_DECL) + { + return factory->create_component_tc (id, + "" /* empty name */ + ACE_ENV_ARG_PARAMETER); + } + }; + + + template <> + struct Objref_Traits<CORBA::tk_home> + { + static + CORBA::TypeCode_ptr + create_compact_typecode (TAO_TypeCodeFactory_Adapter * factory, + char const * id + ACE_ENV_ARG_DECL) + { + return factory->create_home_tc (id, + "" /* empty name */ + ACE_ENV_ARG_PARAMETER); + } + }; + + template <> + struct Objref_Traits<CORBA::tk_local_interface> + { + static + CORBA::TypeCode_ptr + create_compact_typecode (TAO_TypeCodeFactory_Adapter * factory, + char const * id + ACE_ENV_ARG_DECL) + { + return factory->create_local_interface_tc (id, + "" /* empty name */ + ACE_ENV_ARG_PARAMETER); + } + }; + + template <> + struct Objref_Traits<CORBA::tk_native> + { + static CORBA::TypeCode_ptr + create_compact_typecode (TAO_TypeCodeFactory_Adapter * factory, + char const * id + ACE_ENV_ARG_DECL) + { + return factory->create_native_tc (id, + "" /* empty name */ + ACE_ENV_ARG_PARAMETER); + } + }; + + template <> + struct Objref_Traits<CORBA::tk_objref> + { + static + CORBA::TypeCode_ptr + create_compact_typecode (TAO_TypeCodeFactory_Adapter * factory, + char const * id + ACE_ENV_ARG_DECL) + { + return factory->create_interface_tc (id, + "" /* empty name */ + ACE_ENV_ARG_PARAMETER); + } + }; + + /** + * @class Objref + * + * @brief @c CORBA::TypeCode implementation for an OMG IDL + * @c object and object-like types + * + * This class implements a @c CORBA::TypeCode for an OMG IDL + * @c object (interface) and object-like types (abstract + * interface, component, local interface and native). + */ + template <typename StringType, CORBA::TCKind Kind, class RefCountPolicy> + class Objref + : public CORBA::TypeCode, + private RefCountPolicy + { + public: + + /// Constructor. + Objref (char const * id, + char const * name); + + /** + * @name TAO-specific @c CORBA::TypeCode Methods + * + * Methods required by TAO's implementation of the + * @c CORBA::TypeCode class. + * + * @see @c CORBA::TypeCode + */ + //@{ + virtual bool tao_marshal (TAO_OutputCDR & cdr) const; + virtual void tao_duplicate (void); + virtual void tao_release (void); + //@} + + protected: + + /** + * @name @c TAO CORBA::TypeCode Template Methods + * + * @c tk_abstract_interface, @c tk_component, @c + * tk_local_interface, @c tk_native and @c tk_objref + * @c CORBA::TypeCode -specific template methods. + * + * @see @c CORBA::TypeCode + */ + //@{ + virtual CORBA::Boolean equal_i (CORBA::TypeCode_ptr tc + ACE_ENV_ARG_DECL) const; + virtual CORBA::Boolean equivalent_i (CORBA::TypeCode_ptr tc + ACE_ENV_ARG_DECL) const; + virtual CORBA::TCKind kind_i (ACE_ENV_SINGLE_ARG_DECL) const; + virtual CORBA::TypeCode_ptr get_compact_typecode_i ( + ACE_ENV_SINGLE_ARG_DECL) const; + virtual char const * id_i (ACE_ENV_SINGLE_ARG_DECL) const; + virtual char const * name_i (ACE_ENV_SINGLE_ARG_DECL) const; + + private: + + /// Base attributes (@c id and @c name). + Base_Attributes<StringType> attributes_; + + }; + + } // End namespace TypeCode +} // End namespace TAO + + +#ifdef __ACE_INLINE__ +# include "tao/Objref_TypeCode.inl" +#endif /* __ACE_INLINE__ */ + +#ifdef ACE_TEMPLATES_REQUIRE_SOURCE +# include "tao/Objref_TypeCode.cpp" +#endif /* ACE_TEMPLATES_REQUIRE_SOURCE */ + +#ifdef ACE_TEMPLATES_REQUIRE_PRAGMA +# pragma implementation ("Objref_TypeCode.cpp") +#endif /* ACE_TEMPLATES_REQUIRE_PRAGMA */ + +#include /**/ "ace/post.h" + +#endif /* TAO_OBJREF_TYPECODE_H */ diff --git a/TAO/tao/Objref_TypeCode.inl b/TAO/tao/Objref_TypeCode.inl new file mode 100644 index 00000000000..3a1e735c3f0 --- /dev/null +++ b/TAO/tao/Objref_TypeCode.inl @@ -0,0 +1,15 @@ +// -*- C++ -*- +// +// $Id$ + + +template <typename StringType, CORBA::TCKind Kind, class RefCountPolicy> +ACE_INLINE +TAO::TypeCode::Objref<StringType, + Kind, + RefCountPolicy>::Objref (char const * id, + char const * name) + : RefCountPolicy (), + attributes_ (id, name) +{ +} diff --git a/TAO/tao/PredefinedType_Seq_Tmplinst.cpp b/TAO/tao/PredefinedType_Seq_Tmplinst.cpp index c50c111c7a2..d9a421dc56f 100644 --- a/TAO/tao/PredefinedType_Seq_Tmplinst.cpp +++ b/TAO/tao/PredefinedType_Seq_Tmplinst.cpp @@ -29,7 +29,7 @@ ACE_RCSID (tao, # include "Sequence_T.h" # include "Any.h" # include "Object.h" -# include "Typecode.h" +# include "TypeCode.h" #endif /* ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION || ACE_HAS_TEMPLATE_INSTANTIATION_PRAGM */ diff --git a/TAO/tao/RequestInfo_Util.cpp b/TAO/tao/RequestInfo_Util.cpp index 7db5fe67980..f4ba3e2fedc 100644 --- a/TAO/tao/RequestInfo_Util.cpp +++ b/TAO/tao/RequestInfo_Util.cpp @@ -3,7 +3,7 @@ // $Id$ #include "RequestInfo_Util.h" -#include "Typecode.h" +#include "TypeCode.h" #include "ORB_Constants.h" #include "StringSeqC.h" #include "DynamicC.h" diff --git a/TAO/tao/Sequence_TypeCode.cpp b/TAO/tao/Sequence_TypeCode.cpp new file mode 100644 index 00000000000..93362f34243 --- /dev/null +++ b/TAO/tao/Sequence_TypeCode.cpp @@ -0,0 +1,126 @@ +// $Id$ + +#ifndef TAO_SEQUENCE_TYPECODE_CPP +#define TAO_SEQUENCE_TYPECODE_CPP + +#include "Sequence_TypeCode.h" + +#ifndef __ACE_INLINE__ +# include "tao/Sequence_TypeCode.inl" +#endif /* !__ACE_INLINE__ */ + +template <class RefCountPolicy> +TAO::TypeCode::Sequence<RefCountPolicy>::~Sequence (void) +{ + if (this->content_type_) + CORBA::release (*this->content_type_); +} + +template <class RefCountPolicy> +bool +TAO::TypeCode::Sequence<RefCountPolicy>::tao_marshal ( + TAO_OutputCDR & cdr) const +{ + // A tk_array or tk_sequence TypeCode has a "complex" parameter list + // type (see Table 15-2 in Section 15.3.5.1 "TypeCode" in the CDR + // section of the CORBA specification), meaning that it must be + // marshaled into a CDR encapsulation. + + // Create a CDR encapsulation. + return + (cdr << TAO_OutputCDR::from_boolean (TAO_ENCAP_BYTE_ORDER)) + && (cdr << *(this->content_type_)) + && (cdr << this->length_); +} + +template <class RefCountPolicy> +void +TAO::TypeCode::Sequence<RefCountPolicy>::tao_duplicate (void) +{ + this->RefCountPolicy::add_ref (); +} + +template <class RefCountPolicy> +void +TAO::TypeCode::Sequence<RefCountPolicy>::tao_release (void) +{ + this->RefCountPolicy::remove_ref (); +} + +template <class RefCountPolicy> +CORBA::Boolean +TAO::TypeCode::Sequence<RefCountPolicy>::equal_i (CORBA::TypeCode_ptr tc + ACE_ENV_ARG_DECL) const +{ + // The following calls won't throw since CORBA::TypeCode::equal() + // has already established the kind of tc is the same as our kind. + CORBA::ULong const tc_length = tc->length (ACE_ENV_SINGLE_ARG_PARAMETER); + ACE_CHECK_RETURN (0); + + if (this->length_ != tc_length) + return 0; + + CORBA::TypeCode_var rhs_content_type = + tc->content_type (ACE_ENV_SINGLE_ARG_PARAMETER); + ACE_CHECK_RETURN (0); + + return *(this->content_type_)->equal (rhs_content_type.in () + ACE_ENV_ARG_PARAMETER); +} + +template <class RefCountPolicy> +CORBA::Boolean +TAO::TypeCode::Sequence<RefCountPolicy>::equivalent_i (CORBA::TypeCode_ptr tc + ACE_ENV_ARG_DECL) const +{ + // We could refactor this code to the CORBA::TypeCode::equivalent() + // method but doing so would force us to determine the unaliased + // kind of this TypeCode. Since we already know the unaliased kind + // of this TypeCode, choose to optimize away the additional kind + // unaliasing operation rather than save space. + + CORBA::TCKind const tc_kind = + TAO::unaliased_kind (tc + ACE_ENV_ARG_PARAMETER); + ACE_CHECK_RETURN (0); + + if (tc_kind != this->kind_) + return 0; + + CORBA::TypeCode_var rhs_content_type = + tc->content_type (ACE_ENV_SINGLE_ARG_PARAMETER); + ACE_CHECK_RETURN (0); + + return *(this->content_type_)->equivalent (rhs_content_type.in () + ACE_ENV_ARG_PARAMETER); +} + +template <class RefCountPolicy> +CORBA::TCKind +TAO::TypeCode::Sequence<RefCountPolicy>::kind_i ( + ACE_ENV_SINGLE_ARG_DECL_NOT_USED) const +{ + return this->kind_; +} + +template <class RefCountPolicy> +CORBA::TypeCode_ptr +TAO::TypeCode::Sequence<RefCountPolicy>::get_compact_typecode_i ( + ACE_ENV_SINGLE_ARG_DECL_NOT_USED) const +{ + // Already compact since tk_sequence and tk_array TypeCodes have no + // name or member names, meaning that we can simply call + // _duplicate() on this TypeCode. + return CORBA::TypeCode::_duplicate (this); +} + +template <class RefCountPolicy> +CORBA::TypeCode_ptr +TAO::TypeCode::Sequence<RefCountPolicy>::length_i ( + ACE_ENV_SINGLE_ARG_DECL_NOT_USED) const +{ + return this->length_; +} + + +#endif /* TAO_SEQUENCE_TYPECODE_CPP */ diff --git a/TAO/tao/Sequence_TypeCode.h b/TAO/tao/Sequence_TypeCode.h new file mode 100644 index 00000000000..5aecaf1e06e --- /dev/null +++ b/TAO/tao/Sequence_TypeCode.h @@ -0,0 +1,128 @@ +// -*- C++ -*- + +//============================================================================= +/** + * @file Sequence_TypeCode.h + * + * $Id$ + * + * Header file for @c tk_sequence and @c tk_array @c CORBA::TypeCodes. + * + * @author Ossama Othman <ossama@dre.vanderbilt.edu> + */ +//============================================================================= + +#ifndef TAO_SEQUENCE_TYPECODE_H +#define TAO_SEQUENCE_TYPECODE_H + +#include /**/ "ace/pre.h" + +#include "tao/TypeCode.h" + +#if !defined (ACE_LACKS_PRAGMA_ONCE) +# pragma once +#endif /* ACE_LACKS_PRAGMA_ONCE */ + +namespace TAO +{ + namespace TypeCode + { + + /** + * @class Sequence + * + * @brief @c CORBA::TypeCode implementation for OMG IDL + * @c sequence and @c array types. + * + * This class implements a @c CORBA::TypeCode for OMG IDL + * @c sequence and array types. + */ + template <class RefCountPolicy> + class Sequence + : public CORBA::TypeCode + , private RefCountPolicy + { + public: + + /// Constructor. + Sequence (CORBA::TCKind kind, + CORBA::TypeCode_ptr * content_type, + CORBA::ULong length); + + /// Destructor. + ~Sequence (void); + + /** + * @name TAO-specific @c CORBA::TypeCode Methods + * + * Methods required by TAO's implementation of the + * @c CORBA::TypeCode class. + * + * @see @c CORBA::TypeCode + */ + //@{ + virtual bool tao_marshal (TAO_OutputCDR & cdr) const; + virtual void tao_duplicate (void); + virtual void tao_release (void); + //@} + + protected: + + /** + * @name @c TAO CORBA::TypeCode Template Methods + * + * @c CORBA::TypeCode template methods specific to @c tk_sequence + * @c TypeCodes. + * + * @see @c CORBA::TypeCode + */ + //@{ + virtual CORBA::Boolean equal_i (CORBA::TypeCode_ptr tc + ACE_ENV_ARG_DECL) const; + virtual CORBA::Boolean equivalent_i (CORBA::TypeCode_ptr tc + ACE_ENV_ARG_DECL) const; + virtual CORBA::TCKind kind_i (ACE_ENV_SINGLE_ARG_DECL) const; + virtual CORBA::TypeCode_ptr get_compact_typecode_i ( + ACE_ENV_SINGLE_ARG_DECL) const; + virtual CORBA::ULong length_i (ACE_ENV_SINGLE_ARG_DECL) const; + virtual CORBA::TypeCode_ptr content_type (ACE_ENV_SINGLE_ARG_DECL) const; + + private: + + /// The kind of this @c TypeCode. + /** + * @c kind_ is either @c CORBA::tk_sequence or + * @c CORBA::tk_array. + */ + CORBA::TCKind const kind_; + + /// Element type of the sequence. + /** + * A pointer to the @c CORBA::TypeCode_ptr rather than the + * @c CORBA::TypeCode_ptr itself is stored since that address is + * well-defined. We may not know the value of the @c + * CORBA::TypeCode_ptr when creating this @c Field statically at + * compile-time, hence the indirection. + * + * @note This @c TypeCode is released upon destruction of this + * @c TypeCode::Sequence. + */ + CORBA::TypeCode_ptr * content_type_; + + /// Length of the @c sequence or array. A length of zero + /// indicates an unbounded @c sequence. + CORBA::ULong const length_; + + }; + + } // End namespace TypeCode +} // End namespace TAO + + +#ifdef __ACE_INLINE__ +# include "tao/Sequence_TypeCode.inl" +#endif /* __ACE_INLINE__ */ + +#include /**/ "ace/post.h" + +#endif /* TAO_SEQUENCE_TYPECODE_H */ diff --git a/TAO/tao/Sequence_TypeCode.inl b/TAO/tao/Sequence_TypeCode.inl new file mode 100644 index 00000000000..2c0edb2e190 --- /dev/null +++ b/TAO/tao/Sequence_TypeCode.inl @@ -0,0 +1,16 @@ +// -*- C++ -*- +// +// $Id$ + +template <class RefCountPolicy> +ACE_INLINE +TAO::TypeCode::Sequence<RefCountPolicy>::Sequence ( + CORBA::TCKind kind, + CORBA::TypeCode_ptr * content_type, + CORBA::ULong length) + : kind_ (kind) + , content_type_ (content_type) + , length_ (length) +{ + // ACE_ASSERT (kind == CORBA::tk_array || kind == CORBA::tk_sequence); +} diff --git a/TAO/tao/String_TypeCode.cpp b/TAO/tao/String_TypeCode.cpp new file mode 100644 index 00000000000..c74a102d463 --- /dev/null +++ b/TAO/tao/String_TypeCode.cpp @@ -0,0 +1,113 @@ +// $Id$ + +#ifndef TAO_STRING_TYPECODE_CPP +#define TAO_STRING_TYPECODE_CPP + +#include "String_TypeCode.h" + +#ifndef __ACE_INLINE__ +# include "tao/String_TypeCode.inl" +#endif /* !__ACE_INLINE__ */ + + +template <class RefCountPolicy> +bool +TAO::TypeCode::String<RefCountPolicy>::tao_marshal (TAO_OutputCDR & cdr) const +{ + // A tk_string TypeCode has a "simple" parameter list type (see + // Table 15-2 in Section 15.3.5.1 "TypeCode" in the CDR section of + // the CORBA specification), meaning that its parameter(s) must be + // marshaled immediately following the TCKind. No CDR encapsulation + // is to be created. + + return (cdr << this->length_); +} + +template <class RefCountPolicy> +void +TAO::TypeCode::String<RefCountPolicy>::tao_duplicate (void) +{ + this->RefCountPolicy::add_ref (); +} + +template <class RefCountPolicy> +void +TAO::TypeCode::String<RefCountPolicy>::tao_release (void) +{ + this->RefCountPolicy::remove_ref (); +} + +template <class RefCountPolicy> +CORBA::Boolean +TAO::TypeCode::String<RefCountPolicy>::equal_i (CORBA::TypeCode_ptr tc + ACE_ENV_ARG_DECL) const +{ + // The following call won't throw since CORBA::TypeCode::equal() has + // already established the kind of tc is the same as our kind. + CORBA::ULong const tc_length = tc->length (ACE_ENV_SINGLE_ARG_PARAMETER); + ACE_CHECK_RETURN (0); + + return (this->length_ == tc_length); +} + +template <class RefCountPolicy> +CORBA::Boolean +TAO::TypeCode::String<RefCountPolicy>::equivalent_i (CORBA::TypeCode_ptr tc + ACE_ENV_ARG_DECL) const +{ + // We could refactor this code to the CORBA::TypeCode::equivalent() + // method but doing so would force us to determine the unaliased + // kind of this TypeCode. Since we already know the unaliased kind + // of this TypeCode, choose to optimize away the additional kind + // unaliasing operation rather than save space. + + CORBA::TCKind const tc_kind = + TAO::unaliased_kind (tc + ACE_ENV_ARG_PARAMETER); + ACE_CHECK_RETURN (0); + + // Call kind_i() instead of using CORBA::tk_string directly since a + // subclass, such as WString_TypeCode, can use this equivalent_i() + // implementation. + CORBA::TCKind const this_kind = + this->kind_i (ACE_ENV_SINGLE_ARG_PARAMETER); + ACE_CHECK_RETURN (0); + + if (tc_kind != this_kind) + return 0; + + // Since TCKind comparisons must be performed before equal_i() is + // called, we can also call it to determine equivalence of + // tk_string-based TypeCodes. + return this->equal_i (ACE_ENV_SINGLE_ARG_PARAMETER); +} + +template <class RefCountPolicy> +CORBA::TCKind +TAO::TypeCode::String<RefCountPolicy>::kind_i ( + ACE_ENV_SINGLE_ARG_DECL_NOT_USED) const +{ + return this->kind_; +} + +template <class RefCountPolicy> +CORBA::TypeCode_ptr +TAO::TypeCode::String<RefCountPolicy>::get_compact_typecode_i ( + ACE_ENV_SINGLE_ARG_DECL_NOT_USED) const +{ + // Already compact since tk_string TypeCodes have no name or member + // names, meaning that we can simply call _duplicate() on this + // TypeCode. + return CORBA::TypeCode::_duplicate (this); +} + +template <class RefCountPolicy> +CORBA::ULong +TAO::TypeCode::String<RefCountPolicy>::length_i ( + ACE_ENV_SINGLE_ARG_DECL_NOT_USED) const +{ + return this->length_; +} + + +#endif /* TAO_STRING_TYPECODE_CPP */ diff --git a/TAO/tao/String_TypeCode.h b/TAO/tao/String_TypeCode.h new file mode 100644 index 00000000000..0a95958921a --- /dev/null +++ b/TAO/tao/String_TypeCode.h @@ -0,0 +1,110 @@ +// -*- C++ -*- + +//============================================================================= +/** + * @file String_TypeCode.h + * + * $Id$ + * + * Header file for @c CORBA::tk_string or @c CORBA::tk_wstring + * @c CORBA::TypeCodes. + * + * @author Ossama Othman <ossama@dre.vanderbilt.edu> + */ +//============================================================================= + +#ifndef TAO_STRING_TYPECODE_H +#define TAO_STRING_TYPECODE_H + +#include /**/ "ace/pre.h" + +#include "tao/TypeCode.h" + +#if !defined (ACE_LACKS_PRAGMA_ONCE) +# pragma once +#endif /* ACE_LACKS_PRAGMA_ONCE */ + +namespace TAO +{ + namespace TypeCode + { + + /** + * @class String + * + * @brief @c CORBA::TypeCode implementation for OMG IDL string + * types. + * + * This class implements a @c CORBA::TypeCode for OMG IDL string + * types, including @c wstring. + */ + template <class RefCountPolicy> + class String + : public CORBA::TypeCode, + private RefCountPolicy + { + public: + + /// Constructor. + String (CORBA::TCKind kind, CORBA::ULong length); + + /** + * @name TAO-specific @c CORBA::TypeCode Methods + * + * Methods required by TAO's implementation of the + * @c CORBA::TypeCode class. + * + * @see @c CORBA::TypeCode + */ + //@{ + virtual bool tao_marshal (TAO_OutputCDR & cdr) const; + virtual void tao_duplicate (void); + virtual void tao_release (void); + //@} + + protected: + + /** + * @name @c TAO CORBA::TypeCode Template Methods + * + * @c CORBA::TypeCode template methods specific to @c tk_string + * @c TypeCodes. + * + * @see @c CORBA::TypeCode + */ + //@{ + virtual CORBA::Boolean equal_i (CORBA::TypeCode_ptr tc + ACE_ENV_ARG_DECL) const; + virtual CORBA::Boolean equivalent_i (CORBA::TypeCode_ptr tc + ACE_ENV_ARG_DECL) const; + virtual CORBA::TCKind kind_i (ACE_ENV_SINGLE_ARG_DECL) const; + virtual CORBA::TypeCode_ptr get_compact_typecode_i ( + ACE_ENV_SINGLE_ARG_DECL) const; + virtual CORBA::ULong length_i (ACE_ENV_SINGLE_ARG_DECL) const; + + private: + + /// The kind of this @c TypeCode. + /** + * @c kind_ is either @c CORBA::tk_string or + * @c CORBA::tk_wstring. + */ + CORBA::TCKind const kind_; + + /// Length of the @c string. A length of zero indicates an + /// unbounded @c string. + CORBA::ULong const length_; + + }; + + } // End namespace TypeCode +} // End namespace TAO + + +#ifdef __ACE_INLINE__ +# include "tao/String_TypeCode.inl" +#endif /* __ACE_INLINE__ */ + +#include /**/ "ace/post.h" + +#endif /* TAO_STRING_TYPECODE_H */ diff --git a/TAO/tao/String_TypeCode.inl b/TAO/tao/String_TypeCode.inl new file mode 100644 index 00000000000..781f9f30061 --- /dev/null +++ b/TAO/tao/String_TypeCode.inl @@ -0,0 +1,13 @@ +// -*- C++ -*- +// +// $Id$ + +template <class RefCountPolicy> +ACE_INLINE +TAO::TypeCode::String<RefCountPolicy>::String (CORBA::TCKind kind, + CORBA::ULong length) + : kind_ (kind), + length_ (length) +{ + // ACE_ASSERT (kind == CORBA::tk_string || kind == CORBA::tk_wstring); +} diff --git a/TAO/tao/Struct_TypeCode.cpp b/TAO/tao/Struct_TypeCode.cpp new file mode 100644 index 00000000000..5008b0abc69 --- /dev/null +++ b/TAO/tao/Struct_TypeCode.cpp @@ -0,0 +1,371 @@ +// $Id$ + +#ifndef TAO_STRUCT_TYPECODE_CPP +#define TAO_STRUCT_TYPECODE_CPP + +#include "tao/Struct_TypeCode.h" +#include "tao/TypeCode_Struct_Field.h" +#include "tao/ORB_Core.h" +#include "tao/TypeCodeFactory_Adapter.h" + + +#ifndef __ACE_INLINE__ +# include "tao/Struct_TypeCode.inl" +#endif /* !__ACE_INLINE__ */ + +#include "ace/Dynamic_Service.h" + + +template <typename StringType, + class FieldArrayType, + CORBA::TCKind Kind, + class RefCountPolicy> +bool +TAO::TypeCode::Struct<StringType, + FieldArrayType, + Kind, + RefCountPolicy>::tao_marshal (TAO_OutputCDR & cdr) const +{ + // A tk_struct TypeCode has a "complex" parameter list type (see + // Table 15-2 in Section 15.3.5.1 "TypeCode" in the CDR section of + // the CORBA specification), meaning that it must be marshaled into + // a CDR encapsulation. + + // Create a CDR encapsulation. + bool const success = + (cdr << TAO_OutputCDR::from_boolean (TAO_ENCAP_BYTE_ORDER)) + && (cdr << this->base_attributes_.id ()) + && (cdr << this->base_attributes_.name ()) + && (cdr << this->nfields_); + + if (!success) + return false; + + Struct_Field<StringType> const * const begin = this->fields (); + Struct_Field<StringType> const * const end = begin + this->nfields_; + + for (Struct_Field<StringType> const * i = begin; i != end; ++i) + { + Struct_Field<StringType> const & field = *i; + + if (!(cdr << field.get_name ()) + || !(cdr << *(field.type))) + return false; + } + + return true; +} + +template <typename StringType, + class FieldArrayType, + CORBA::TCKind Kind, + class RefCountPolicy> +void +TAO::TypeCode::Struct<StringType, + FieldArrayType, + Kind, + RefCountPolicy>::tao_duplicate (void) +{ + this->RefCountPolicy::add_ref (); +} + +template <typename StringType, + class FieldArrayType, + CORBA::TCKind Kind, + class RefCountPolicy> +void +TAO::TypeCode::Struct<StringType, + FieldArrayType, + Kind, + RefCountPolicy>::tao_release (void) +{ + this->RefCountPolicy::remove_ref (); +} + +template <typename StringType, + class FieldArrayType, + CORBA::TCKind Kind, + class RefCountPolicy> +CORBA::Boolean +TAO::TypeCode::Struct<StringType, + FieldArrayType, + Kind, + RefCountPolicy>::equal_i ( + CORBA::TypeCode_ptr tc + ACE_ENV_ARG_DECL) const +{ + // This call shouldn't throw since CORBA::TypeCode::equal() verified + // that the TCKind is the same as our's prior to invoking this + // method, meaning that member_count() is supported. + + CORBA::ULong const tc_nfields = + tc->member_count (ACE_ENV_SINGLE_ARG_PARAMETER); + ACE_CHECK_RETURN (0); + + if (tc_nfields != this->nfields_) + return 0; + + for (CORBA::ULong i = 0; i < this->nfields_; ++i) + { + Struct_Field<StringType> const & lhs_field = this->fields_[i]; + + char const * const lhs_name = lhs_field.get_name (); + char const * const rhs_name = tc->member_name (i + ACE_ENV_ARG_PARAMETER); + ACE_CHECK_RETURN (0); + + if (ACE_OS::strcmp (lhs_name, rhs_name) != 0) + return 0; + + CORBA::TypeCode_ptr const lhs_tc = *(lhs_field.type); + CORBA::TypeCode_var const rhs_tc = + tc->member_type (i + ACE_ENV_ARG_PARAMETER); + ACE_CHECK_RETURN (0); + + CORBA::Boolean const equal_members = + lhs_tc->equal (rhs_tc.in () + ACE_ENV_ARG_PARAMETER); + ACE_CHECK_RETURN (0); + + if (!equal_members) + return 0; + } + + return 1; +} + +template <typename StringType, + class FieldArrayType, + CORBA::TCKind Kind, + class RefCountPolicy> +CORBA::Boolean +TAO::TypeCode::Struct<StringType, + FieldArrayType, + Kind, + RefCountPolicy>::equivalent_i ( + CORBA::TypeCode_ptr tc + ACE_ENV_ARG_DECL) const +{ + // We could refactor this code to the CORBA::TypeCode::equivalent() + // method but doing so would force us to determine the unaliased + // kind of this TypeCode. Since we already know the unaliased kind + // of this TypeCode, choose to optimize away the additional kind + // unaliasing operation rather than save space. + + CORBA::TCKind const tc_kind = + TAO::unaliased_kind (tc + ACE_ENV_ARG_PARAMETER); + ACE_CHECK_RETURN (0); + + if (tc_kind != Kind) + return 0; + + char const * const this_id = this->base_attributes_.id (); + char const * const tc_id = tc->id (ACE_ENV_SINGLE_ARG_PARAMETER); + ACE_CHECK_RETURN (0); + + if (ACE_OS::strlen (this_id) == 0 + || ACE_OS::strlen (tc_id) == 0) + { + // Perform a structural comparison, excluding the name() and + // member_name() operations. + + CORBA::ULong const tc_nfields = + tc->member_count (ACE_ENV_SINGLE_ARG_PARAMETER); + ACE_CHECK_RETURN (0); + + if (tc_nfields != this->nfields_) + return 0; + + for (CORBA::ULong i = 0; i < this->nfields_; ++i) + { + CORBA::TypeCode_ptr const lhs = *(this->fields_[i].type); + CORBA::TypeCode_var const rhs = + tc->member_type (i + ACE_ENV_ARG_PARAMETER); + ACE_CHECK_RETURN (0); + + CORBA::Boolean const equiv_members = + lhs->equivalent (rhs.in () + ACE_ENV_ARG_PARAMETER); + ACE_CHECK_RETURN (0); + + if (!equiv_members) + return 0; + } + } + else if (ACE_OS::strcmp (this_id, tc_id) != 0) + { + return 0; + } + + return 1; +} + +template <typename StringType, + class FieldArrayType, + CORBA::TCKind Kind, + class RefCountPolicy> +CORBA::TCKind +TAO::TypeCode::Struct<StringType, + FieldArrayType, + Kind, + RefCountPolicy>::kind_i ( + ACE_ENV_SINGLE_ARG_DECL_NOT_USED) const +{ + return Kind; +} + +template <typename StringType, + class FieldArrayType, + CORBA::TCKind Kind, + class RefCountPolicy> +CORBA::TypeCode_ptr +TAO::TypeCode::Struct<StringType, + FieldArrayType, + Kind, + RefCountPolicy>::get_compact_typecode_i ( + ACE_ENV_SINGLE_ARG_DECL) const +{ + Struct_Field<StringType> * tc_fields = 0; + + ACE_Auto_Array_Ptr<Struct_Field<StringType> > safe_fields; + + if (this->nfields_ > 0) + { + // Dynamically construct a new array of fields stripped of + // member names. + + ACE_NEW_THROW_EX (tc_fields, + Struct_Field<StringType> [this->nfields_], + CORBA::NO_MEMORY ()); + ACE_CHECK_RETURN (CORBA::TypeCode::_nil ()); + + safe_fields.reset (tc_fields); + + static char const empty_name[] = ""; + + for (CORBA::ULong i = 0; i < this->nfields_; ++i) + { + // Member names will be stripped, i.e. not embedded within + // the compact TypeCode. + + tc_fields[i].name = empty_name; + tc_fields[i].type = 0; // FIX ME! +// &(*this->fields_[i].type)->get_compact_typecode ( +// ACE_ENV_SINGLE_ARG_PARAMETER); + ACE_CHECK_RETURN (CORBA::TypeCode::_nil ()); + } + } + + TAO_TypeCodeFactory_Adapter * const adapter = + ACE_Dynamic_Service<TAO_TypeCodeFactory_Adapter>::instance ( + TAO_ORB_Core::typecodefactory_adapter_name ()); + + if (adapter == 0) + { + ACE_THROW_RETURN (CORBA::INTERNAL (), + CORBA::TypeCode::_nil ()); + } + + CORBA::TypeCode_var tc = + adapter->_tao_create_struct_except_tc (Kind, + this->base_attributes_.id (), + "" /* empty name */, + tc_fields, + this->nfields_ + ACE_ENV_ARG_PARAMETER); + ACE_CHECK_RETURN (CORBA::TypeCode::_nil ()); + + (void) safe_fields.release (); + + return tc._retn (); +} + +template <typename StringType, + class FieldArrayType, + CORBA::TCKind Kind, + class RefCountPolicy> +char const * +TAO::TypeCode::Struct<StringType, + FieldArrayType, + Kind, + RefCountPolicy>::id_i ( + ACE_ENV_SINGLE_ARG_DECL_NOT_USED) const +{ + // Ownership is retained by the TypeCode, as required by the C++ + // mapping. + return this->base_attributes_.id (); +} + +template <typename StringType, + class FieldArrayType, + CORBA::TCKind Kind, + class RefCountPolicy> +char const * +TAO::TypeCode::Struct<StringType, + FieldArrayType, + Kind, + RefCountPolicy>::name_i ( + ACE_ENV_SINGLE_ARG_DECL_NOT_USED) const +{ + // Ownership is retained by the TypeCode, as required by the C++ + // mapping. + return this->base_attributes_.name (); +} + +template <typename StringType, + class FieldArrayType, + CORBA::TCKind Kind, + class RefCountPolicy> +CORBA::ULong +TAO::TypeCode::Struct<StringType, + FieldArrayType, + Kind, + RefCountPolicy>::member_count_i ( + ACE_ENV_SINGLE_ARG_DECL_NOT_USED) const +{ + return this->nfields_; +} + +template <typename StringType, + class FieldArrayType, + CORBA::TCKind Kind, + class RefCountPolicy> +char const * +TAO::TypeCode::Struct<StringType, + FieldArrayType, + Kind, + RefCountPolicy>::member_name_i ( + CORBA::ULong index + ACE_ENV_ARG_DECL) const +{ + // Ownership is retained by the TypeCode, as required by the C++ + // mapping. + if (index >= this->nfields_) + ACE_THROW_RETURN (CORBA::TypeCode::Bounds (), 0); + + return this->fields_[index].get_name (); +} + +template <typename StringType, + class FieldArrayType, + CORBA::TCKind Kind, + class RefCountPolicy> +CORBA::TypeCode_ptr +TAO::TypeCode::Struct<StringType, + FieldArrayType, + Kind, + RefCountPolicy>::member_type_i ( + CORBA::ULong index + ACE_ENV_ARG_DECL) const +{ + if (index >= this->nfields_) + ACE_THROW_RETURN (CORBA::TypeCode::Bounds (), + CORBA::TypeCode::_nil ()); + + return CORBA::TypeCode::_duplicate (*(this->fields_[index].type)); +} + +#endif /* TAO_STRUCT_TYPECODE_CPP */ diff --git a/TAO/tao/Struct_TypeCode.h b/TAO/tao/Struct_TypeCode.h new file mode 100644 index 00000000000..9951b3babec --- /dev/null +++ b/TAO/tao/Struct_TypeCode.h @@ -0,0 +1,156 @@ +// -*- C++ -*- + +//============================================================================= +/** + * @file Struct_TypeCode.h + * + * $Id$ + * + * Header file for a @c tk_struct and @c tk_except + * @c CORBA::TypeCodes. + * + * @author Ossama Othman <ossama@dre.vanderbilt.edu> + * @author Carlos O'Ryan + */ +//============================================================================= + +#ifndef TAO_STRUCT_TYPECODE_H +#define TAO_STRUCT_TYPECODE_H + +#include /**/ "ace/pre.h" + +#include "tao/TypeCode.h" + +#if !defined (ACE_LACKS_PRAGMA_ONCE) +# pragma once +#endif /* ACE_LACKS_PRAGMA_ONCE */ + +#include "tao/TypeCode_Base_Attributes.h" + + +namespace TAO +{ + namespace TypeCode + { + template<typename StringType> struct Struct_Field; + + /** + * @class Struct + * + * @brief @c CORBA::TypeCode implementation for an OMG IDL + * @c struct or @c exception. + * + * This class implements a @c CORBA::TypeCode for an OMG IDL + * @c struct or @c exception. + */ + template <typename StringType, + class FieldArrayType, + CORBA::TCKind Kind, + class RefCountPolicy> + class Struct + : public CORBA::TypeCode, + private RefCountPolicy + { + public: + + /// Constructor. + Struct (char const * id, + char const * name, + Struct_Field<StringType> const * fields, + CORBA::ULong nfields); + + /** + * @name TAO-specific @c CORBA::TypeCode Methods + * + * Methods required by TAO's implementation of the + * @c CORBA::TypeCode class. + * + * @see @c CORBA::TypeCode + */ + //@{ + virtual bool tao_marshal (TAO_OutputCDR & cdr) const; + virtual void tao_duplicate (void); + virtual void tao_release (void); + //@} + + protected: + + /** + * @name @c TAO CORBA::TypeCode Template Methods + * + * @c tk_struct or @c tk_except @c CORBA::TypeCode -specific + * template methods. + * + * @see @c CORBA::TypeCode + */ + //@{ + virtual CORBA::Boolean equal_i (CORBA::TypeCode_ptr tc + ACE_ENV_ARG_DECL) const; + virtual CORBA::Boolean equivalent_i (CORBA::TypeCode_ptr tc + ACE_ENV_ARG_DECL) const; + virtual CORBA::TCKind kind_i (ACE_ENV_SINGLE_ARG_DECL) const; + virtual CORBA::TypeCode_ptr get_compact_typecode_i ( + ACE_ENV_SINGLE_ARG_DECL) const; + virtual char const * id_i (ACE_ENV_SINGLE_ARG_DECL) const; + virtual char const * name_i (ACE_ENV_SINGLE_ARG_DECL) const; + virtual CORBA::ULong member_count_i (ACE_ENV_SINGLE_ARG_DECL) const; + virtual char const * member_name_i (CORBA::ULong index + ACE_ENV_ARG_DECL) const; + virtual CORBA::TypeCode_ptr member_type_i (CORBA::ULong index + ACE_ENV_ARG_DECL) const; + //@} + + private: + + /// Get pointer to the underlying @c Field array. + Struct_Field<StringType> const * fields (void) const; + + private: + + /** + * @c Struct Attributes + * + * Attributes representing the structure of an OMG IDL + * @c struct or @c exception. + * + * @note These attributes are declared in the order in which + * they are marshaled into a CDR stream in order to + * increase cache hits by improving spatial locality. + */ + //@{ + + /// Base attributes containing repository ID and name of + /// structure type. + Base_Attributes<StringType> const base_attributes_; + + /// The number of fields in the OMG IDL structure. + CORBA::ULong const nfields_; + + /// Array of @c TAO::TypeCode fields representing structure of the + /// OMG IDL defined @c struct. + FieldArrayType const fields_; + + //@} + + }; + + } // End namespace TypeCode +} // End namespace TAO + + +#ifdef __ACE_INLINE__ +# include "tao/Struct_TypeCode.inl" +#endif /* __ACE_INLINE__ */ + +#ifdef ACE_TEMPLATES_REQUIRE_SOURCE +# include "tao/Struct_TypeCode.cpp" +#endif /* ACE_TEMPLATES_REQUIRE_SOURCE */ + +#ifdef ACE_TEMPLATES_REQUIRE_PRAGMA +# pragma implementation ("Struct_TypeCode.cpp") +#endif /* ACE_TEMPLATES_REQUIRE_PRAGMA */ + + +#include /**/ "ace/post.h" + +#endif /* TAO_STRUCT_TYPECODE_H */ diff --git a/TAO/tao/Struct_TypeCode.inl b/TAO/tao/Struct_TypeCode.inl new file mode 100644 index 00000000000..63825f49350 --- /dev/null +++ b/TAO/tao/Struct_TypeCode.inl @@ -0,0 +1,65 @@ +// -*- C++ -*- +// +// $Id$ + +#include "tao/TypeCode_Struct_Field.h" +#include "tao/True_RefCount_Policy.h" + +#include "ace/Auto_Ptr.h" + + +template <typename StringType, + class FieldArrayType, + CORBA::TCKind Kind, + class RefCountPolicy> +ACE_INLINE +TAO::TypeCode::Struct<StringType, + FieldArrayType, + Kind, + RefCountPolicy>::Struct ( + char const * id, + char const * name, + Struct_Field<StringType> const * fields, + CORBA::ULong nfields) + : base_attributes_ (id, name) + , nfields_ (nfields) + , fields_ (fields) +{ +} + +template <typename StringType, + class FieldArrayType, + CORBA::TCKind Kind, + class RefCountPolicy> +ACE_INLINE TAO::TypeCode::Struct_Field<StringType> const * +TAO::TypeCode::Struct<StringType, + FieldArrayType, + Kind, + RefCountPolicy>::fields (void) const +{ + return this->fields_; +} + +// ------------------------------------------------------------- +// Member specializations +// ------------------------------------------------------------- + +ACE_INLINE TAO::TypeCode::Struct_Field<CORBA::String_var> const * +TAO::TypeCode::Struct< + CORBA::String_var, + ACE_Auto_Array_Ptr<TAO::TypeCode::Struct_Field<CORBA::String_var> const>, + CORBA::tk_struct, + TAO::True_RefCount_Policy>::fields (void) const +{ + return this->fields_.get (); +} + +ACE_INLINE TAO::TypeCode::Struct_Field<CORBA::String_var> const * +TAO::TypeCode::Struct< + CORBA::String_var, + ACE_Auto_Array_Ptr<TAO::TypeCode::Struct_Field<CORBA::String_var> const>, + CORBA::tk_except, + TAO::True_RefCount_Policy>::fields (void) const +{ + return this->fields_.get (); +} diff --git a/TAO/tao/SystemException.cpp b/TAO/tao/SystemException.cpp index 85ee1231b57..44cb9836e29 100644 --- a/TAO/tao/SystemException.cpp +++ b/TAO/tao/SystemException.cpp @@ -4,9 +4,9 @@ #include "Environment.h" #include "Any_SystemException.h" #include "Any_Dual_Impl_T.h" -#include "Typecode.h" +#include "TypeCode.h" #include "ORB_Constants.h" -#include "TC_Constants_Forward.h" +#include "TypeCode_Constants.h" #include "CORBA_String.h" #include "CDR.h" #include "debug.h" @@ -1145,10 +1145,9 @@ STANDARD_EXCEPTION_LIST #define TAO_SYSTEM_EXCEPTION(name) \ void \ -CORBA::name ::_tao_any_destructor (void *x) \ +CORBA::name ::_tao_any_destructor (void * x) \ { \ - CORBA::name *tmp = static_cast<CORBA::name *> (x); \ - delete tmp; \ + delete static_cast<CORBA::name *> (x); \ } STANDARD_EXCEPTION_LIST @@ -1158,7 +1157,7 @@ STANDARD_EXCEPTION_LIST CORBA::Exception * \ CORBA::name ::_tao_duplicate (void) const \ { \ - CORBA::Exception *result; \ + CORBA::Exception * result; \ ACE_NEW_RETURN (result, CORBA::name (*this), 0); \ return result; \ } diff --git a/TAO/tao/TC_Constants_Forward.h b/TAO/tao/TC_Constants_Forward.h index 93df81213df..72c27451a1c 100644 --- a/TAO/tao/TC_Constants_Forward.h +++ b/TAO/tao/TC_Constants_Forward.h @@ -27,27 +27,27 @@ namespace CORBA * All the TypeCode constants */ //@{ - extern TAO_Export TypeCode_ptr _tc_null; - extern TAO_Export TypeCode_ptr _tc_void; - extern TAO_Export TypeCode_ptr _tc_short; - extern TAO_Export TypeCode_ptr _tc_long; - extern TAO_Export TypeCode_ptr _tc_ushort; - extern TAO_Export TypeCode_ptr _tc_ulong; - extern TAO_Export TypeCode_ptr _tc_float; - extern TAO_Export TypeCode_ptr _tc_double; - extern TAO_Export TypeCode_ptr _tc_boolean; - extern TAO_Export TypeCode_ptr _tc_char; - extern TAO_Export TypeCode_ptr _tc_octet; - extern TAO_Export TypeCode_ptr _tc_any; - extern TAO_Export TypeCode_ptr _tc_TypeCode; - extern TAO_Export TypeCode_ptr _tc_Principal; - extern TAO_Export TypeCode_ptr _tc_Object; - extern TAO_Export TypeCode_ptr _tc_string; - extern TAO_Export TypeCode_ptr _tc_longlong; - extern TAO_Export TypeCode_ptr _tc_ulonglong; - extern TAO_Export TypeCode_ptr _tc_longdouble; - extern TAO_Export TypeCode_ptr _tc_wchar; - extern TAO_Export TypeCode_ptr _tc_wstring; + extern TAO_Export TypeCode_ptr const _tc_null; + extern TAO_Export TypeCode_ptr const _tc_void; + extern TAO_Export TypeCode_ptr const _tc_short; + extern TAO_Export TypeCode_ptr const _tc_long; + extern TAO_Export TypeCode_ptr const _tc_ushort; + extern TAO_Export TypeCode_ptr const _tc_ulong; + extern TAO_Export TypeCode_ptr const _tc_float; + extern TAO_Export TypeCode_ptr const _tc_double; + extern TAO_Export TypeCode_ptr const _tc_boolean; + extern TAO_Export TypeCode_ptr const _tc_char; + extern TAO_Export TypeCode_ptr const _tc_octet; + extern TAO_Export TypeCode_ptr const _tc_any; + extern TAO_Export TypeCode_ptr const _tc_TypeCode; + extern TAO_Export TypeCode_ptr const _tc_Principal; + extern TAO_Export TypeCode_ptr const _tc_Object; + extern TAO_Export TypeCode_ptr const _tc_string; + extern TAO_Export TypeCode_ptr const _tc_longlong; + extern TAO_Export TypeCode_ptr const _tc_ulonglong; + extern TAO_Export TypeCode_ptr const _tc_longdouble; + extern TAO_Export TypeCode_ptr const _tc_wchar; + extern TAO_Export TypeCode_ptr const _tc_wstring; #define TAO_SYSTEM_EXCEPTION_LIST \ TAO_SYSTEM_EXCEPTION(UNKNOWN); \ @@ -93,16 +93,16 @@ namespace CORBA // = Typecode constants for system exceptions. #define TAO_SYSTEM_EXCEPTION(name) \ - extern TAO_Export TypeCode_ptr _tc_ ## name + extern TAO_Export TypeCode_ptr const _tc_ ## name TAO_SYSTEM_EXCEPTION_LIST #undef TAO_SYSTEM_EXCEPTION //@} - extern TAO_Export TypeCode_ptr _tc_UnknownUserException; + extern TAO_Export TypeCode_ptr const _tc_UnknownUserException; extern TAO_Export TypeCode_ptr const _tc_Current; - extern TAO_Export TypeCode_ptr _tc_NamedValue; + extern TAO_Export TypeCode_ptr const _tc_NamedValue; } #include /**/ "ace/post.h" diff --git a/TAO/tao/True_RefCount_Policy.cpp b/TAO/tao/True_RefCount_Policy.cpp new file mode 100644 index 00000000000..3b5b3fab354 --- /dev/null +++ b/TAO/tao/True_RefCount_Policy.cpp @@ -0,0 +1,17 @@ +// $Id$ + +#include "True_RefCount_Policy.h" + +#ifndef __ACE_INLINE__ +# include "True_RefCount_Policy.inl" +#endif /* !__ACE_INLINE__ */ + + +ACE_RCSID (tao, + True_RefCount_Policy, + "$Id$") + + +TAO::True_RefCount_Policy::~True_RefCount_Policy (void) +{ +} diff --git a/TAO/tao/True_RefCount_Policy.h b/TAO/tao/True_RefCount_Policy.h new file mode 100644 index 00000000000..64efa5220f5 --- /dev/null +++ b/TAO/tao/True_RefCount_Policy.h @@ -0,0 +1,121 @@ +// -*- C++ -*- + +//============================================================================= +/** + * @file True_RefCount_Policy.h + * + * $Id$ + * + * Header file for TAO's true reference count policy (unrelated to + * CORBA policies). + * + * @author Ossama Othman <ossama@dre.vanderbilt.edu> + */ +//============================================================================= + +#ifndef TAO_TRUE_REFCOUNT_POLICY_H +#define TAO_TRUE_REFCOUNT_POLICY_H + +#include /**/ "ace/pre.h" + +#include "tao/TAO_Export.h" + +#if !defined (ACE_LACKS_PRAGMA_ONCE) +# pragma once +#endif /* ACE_LACKS_PRAGMA_ONCE */ + +#include "tao/orbconf.h" + +#include "ace/Thread_Mutex.h" + + +namespace TAO +{ + /** + * @class True_RefCount_Policy + * + * @brief True reference counting policy. + * + * This class is intended to be used as a "policy" argument to a + * host class template that requires true/functional reference + * counting. That class would then inherit privately from it like + * so: + * + * @code + * template <class RefCountPolicy> + * class MyHostClass : private RefCountPolicy + * { + * public: + * void my_add_ref (void) { this->RefCountPolicy::add_ref (); } + * void my_remove_ref (void) { this->RefCountPolicy::remove_ref (); } + * }; + * @endcode + * + * and use it like so: + * + * @code + * typedef MyHostClass<TAO::True_RefCount_Policy> MyRefCountedClass; + * MyRefCountedClass * p = new MyRefCountedClass; + * ... + * p->my_remove_ref (); + * @endcode + * + * @note Ideally, the host class should declare a protected + * destructor to enforce proper memory management through the + * reference counting mechanism, i.e. to prevent clients from + * calling @c operator @c delete() directly on the host class + * object. + */ + class TAO_Export True_RefCount_Policy + { + public: + + /// Increase the reference count on this object. + void add_ref (void); + + /// Decrease the reference count on this object. + /** + * Decrease the reference count on this object. Once the + * reference count drops to zero, call @c operator @c delete() + * on this object. + */ + void remove_ref (void); + + protected: + + /// Constructor. + /** + * @note This constructor is protected since it not meant to be + * instantiated/used as a standalone object. + */ + True_RefCount_Policy (void); + + /// Destructor. + /** + * @note The destructor must be virtual to ensure that subclass + * destructors are called when the reference count drops to + * zero, i.e. when @c remove_ref() calls @c operator + * @c delete @c this. + */ + virtual ~True_RefCount_Policy (void); + + private: + + /// Lock used to synchronize reference count. + TAO_SYNCH_MUTEX lock_; + + /// Reference count. + unsigned int refcount_; + + }; + +} // End namespace TAO + + +#ifdef __ACE_INLINE__ +# include "tao/True_RefCount_Policy.inl" +#endif /* __ACE_INLINE__ */ + +#include /**/ "ace/post.h" + +#endif /* TAO_TRUE_REFCOUNT_POLICY_H */ diff --git a/TAO/tao/True_RefCount_Policy.inl b/TAO/tao/True_RefCount_Policy.inl new file mode 100644 index 00000000000..a6db939e129 --- /dev/null +++ b/TAO/tao/True_RefCount_Policy.inl @@ -0,0 +1,37 @@ +// -*- C++ -*- +// +// $Id$ + + +#include "ace/Guard_T.h" + + +ACE_INLINE +TAO::True_RefCount_Policy::True_RefCount_Policy (void) + : lock_ (), + refcount_ (1) +{ +} + +ACE_INLINE void +TAO::True_RefCount_Policy::add_ref (void) +{ + ACE_GUARD (TAO_SYNCH_MUTEX, monitor, this->lock_); + + ++this->refcount_; +} + +ACE_INLINE void +TAO::True_RefCount_Policy::remove_ref (void) +{ + { + ACE_GUARD (TAO_SYNCH_MUTEX, monitor, this->lock_); + + --this->refcount_; + + if (this->refcount_ != 0) + return; + } + + delete this; +} diff --git a/TAO/tao/TypeCode.cpp b/TAO/tao/TypeCode.cpp new file mode 100644 index 00000000000..41ec1062484 --- /dev/null +++ b/TAO/tao/TypeCode.cpp @@ -0,0 +1,302 @@ +// $Id$ + +#include "TypeCode.h" + + +ACE_RCSID (tao, + TypeCode, + "$Id$") + + +#if !defined (__ACE_INLINE__) +# include "TypeCode.inl" +#endif /* ! __ACE_INLINE__ */ + +#include "SystemException.h" +#include "CDR.h" +#include "ORB_Constants.h" +#include "Struct_TypeCode.h" +#include "Null_RefCount_Policy.h" + +#include "ace/OS_NS_string.h" + + +CORBA::Boolean +CORBA::TypeCode::equal (TypeCode_ptr tc + ACE_ENV_ARG_DECL) const +{ + if (this == tc) + return 1; + + CORBA::TCKind const tc_kind = tc->kind (ACE_ENV_SINGLE_ARG_PARAMETER); + ACE_CHECK_RETURN (0); + + CORBA::TCKind const this_kind = this->kind (ACE_ENV_SINGLE_ARG_PARAMETER); + ACE_CHECK_RETURN (0); + + if (tc_kind != this_kind) + return 0; + + ACE_TRY + { + char const * const tc_id = tc->id (ACE_ENV_SINGLE_ARG_PARAMETER); + ACE_TRY_CHECK; + + char const * const this_id = this->id (ACE_ENV_SINGLE_ARG_PARAMETER); + ACE_TRY_CHECK; + + if (ACE_OS::strcmp (this_id, tc_id) != 0) + return 0; + + char const * const tc_name = tc->name (ACE_ENV_SINGLE_ARG_PARAMETER); + ACE_TRY_CHECK; + + char const * const this_name = this->name (ACE_ENV_SINGLE_ARG_PARAMETER); + ACE_TRY_CHECK; + + if (ACE_OS::strcmp (this_name, tc_name) != 0) + return 0; + } + ACE_CATCH (CORBA::TypeCode::BadKind, ex) + { + // Some TypeCodes do not support the id() and name() + // operations. Ignore the failure, and continue equality + // verification using TypeCode subclass-specific techniques + // below. + } + ACE_ENDTRY; + ACE_CHECK_RETURN (0); + + return this->equal_i (tc + ACE_ENV_ARG_PARAMETER); +} + + +char const * +CORBA::TypeCode::id_i (ACE_ENV_SINGLE_ARG_DECL) const +{ + ACE_THROW_RETURN (CORBA::TypeCode::BadKind (), 0); +} + +char const * +CORBA::TypeCode::name_i (ACE_ENV_SINGLE_ARG_DECL) const +{ + ACE_THROW_RETURN (CORBA::TypeCode::BadKind (), 0); +} + +CORBA::ULong +CORBA::TypeCode::member_count_i (ACE_ENV_SINGLE_ARG_DECL) const +{ + ACE_THROW_RETURN (CORBA::TypeCode::BadKind (), 0); +} + +char const * +CORBA::TypeCode::member_name_i (CORBA::ULong /* index */ + ACE_ENV_ARG_DECL) const +{ + ACE_THROW_RETURN (CORBA::TypeCode::BadKind (), 0); +} + +CORBA::TypeCode_ptr +CORBA::TypeCode::member_type_i (CORBA::ULong /* index */ + ACE_ENV_ARG_DECL) const +{ + ACE_THROW_RETURN (CORBA::TypeCode::BadKind (), + CORBA::TypeCode::_nil ()); +} + +CORBA::Any * +CORBA::TypeCode::member_label_i (CORBA::ULong /* index */ + ACE_ENV_ARG_DECL) const +{ + ACE_THROW_RETURN (CORBA::TypeCode::BadKind (), 0); +} + +CORBA::TypeCode_ptr +CORBA::TypeCode::discriminator_type_i (ACE_ENV_SINGLE_ARG_DECL) const +{ + ACE_THROW_RETURN (CORBA::TypeCode::BadKind (), + CORBA::TypeCode::_nil ()); +} + +CORBA::Long +CORBA::TypeCode::default_index_i (ACE_ENV_SINGLE_ARG_DECL) const +{ + ACE_THROW_RETURN (CORBA::TypeCode::BadKind (), 0); +} + +CORBA::ULong +CORBA::TypeCode::length_i (ACE_ENV_SINGLE_ARG_DECL) const +{ + ACE_THROW_RETURN (CORBA::TypeCode::BadKind (), 0); +} + +CORBA::TypeCode_ptr +CORBA::TypeCode::content_type_i (ACE_ENV_SINGLE_ARG_DECL) const +{ + ACE_THROW_RETURN (CORBA::TypeCode::BadKind (), + CORBA::TypeCode::_nil ()); +} + +CORBA::UShort +CORBA::TypeCode::fixed_digits_i (ACE_ENV_SINGLE_ARG_DECL) const +{ + ACE_THROW_RETURN (CORBA::TypeCode::BadKind (), 0); +} + +CORBA::UShort +CORBA::TypeCode::fixed_scale_i (ACE_ENV_SINGLE_ARG_DECL) const +{ + ACE_THROW_RETURN (CORBA::TypeCode::BadKind (), 0); +} + +CORBA::Visibility +CORBA::TypeCode::member_visibility_i (CORBA::ULong /* index */ + ACE_ENV_ARG_DECL) const +{ + ACE_THROW_RETURN (CORBA::TypeCode::BadKind (), + CORBA::PRIVATE_MEMBER); +} + +CORBA::ValueModifier +CORBA::TypeCode::type_modifier_i (ACE_ENV_SINGLE_ARG_DECL) const +{ + ACE_THROW_RETURN (CORBA::TypeCode::BadKind (), + CORBA::VM_NONE); +} + +CORBA::TypeCode_ptr +CORBA::TypeCode::concrete_base_type_i (ACE_ENV_SINGLE_ARG_DECL) const +{ + ACE_THROW_RETURN (CORBA::TypeCode::BadKind (), + CORBA::TypeCode::_nil ()); +} + +// --------------------------------------------------------------- + +bool +operator<< (TAO_OutputCDR & cdr, + CORBA::TypeCode_ptr tc) +{ + ACE_DECLARE_NEW_CORBA_ENV; + + if (tc == 0) + { + ACE_THROW_RETURN (CORBA::MARSHAL (0, + CORBA::COMPLETED_MAYBE), + false); + } + + CORBA::ULong const kind = + static_cast<CORBA::ULong> (tc->kind (ACE_ENV_SINGLE_ARG_PARAMETER)); + ACE_CHECK_RETURN (false); + + return (cdr << kind) && tc->tao_marshal (cdr); +} + +bool +operator>> (TAO_InputCDR & cdr, + CORBA::TypeCode_ptr & tc) +{ + ACE_DECLARE_NEW_CORBA_ENV; + + TAO_TypeCodeFactory_Adapter * const adapter = + ACE_Dynamic_Service<TAO_TypeCodeFactory_Adapter>::instance ( + TAO_ORB_Core::typecodefactory_adapter_name () + ); + + if (adapter == 0) + { + ACE_THROW_RETURN (CORBA::INTERNAL (), + false); + } + + return adapter->_tao_make_typecode (cdr, tc); + +} + + + +CORBA::TypeCode_ptr +TAO::unaliased_typecode (CORBA::TypeCode_ptr tc + ACE_ENV_ARG_DECL) +{ + if (CORBA::is_nil (tc)) + { + ACE_THROW_RETURN (CORBA::BAD_PARAM (CORBA::OMGVMCID | 13, + CORBA::COMPLETED_NO), + tc); + } + + CORBA::TCKind tc_kind = tc->kind (ACE_ENV_SINGLE_ARG_PARAMETER); + ACE_CHECK_RETURN (tc); + + if (tc_kind == CORBA::tk_alias) + { + CORBA::TypeCode_var tc_content; + + // Iterate until we get to the actual unaliased type. + do + { + tc_content = + tc_content->content_type (ACE_ENV_SINGLE_ARG_PARAMETER); + ACE_CHECK_RETURN (tc); + + tc_kind = tc_content->kind (ACE_ENV_SINGLE_ARG_PARAMETER); + ACE_CHECK_RETURN (tc); + } + while (tc_kind == CORBA::tk_alias); + + return tc_content._retn (); + } + + return CORBA::TypeCode::_duplicate (tc); +} + +// -------------------------------------------------------------- + +namespace TAO +{ + namespace TypeCode + { + // Notice that these are all statically instantiated and not + // exported. + + char const tc_bounds_id[] = "IDL:omg.org/CORBA/TypeCode/Bounds:1.0"; + char const tc_bounds_name[] = "Bounds"; + Struct<char const *, + Struct_Field<char const *> const *, + CORBA::tk_except, + TAO::Null_RefCount_Policy> tc_Bounds (tc_bounds_id, + tc_bounds_name, + 0, + 0); + + char const tc_bad_kind_id[] = "IDL:omg.org/CORBA/TypeCode/BadKind:1.0"; + char const tc_bad_kind_name[] = "BadKind"; + Struct<char const *, + Struct_Field<char const *> const *, + CORBA::tk_except, + TAO::Null_RefCount_Policy> tc_BadKind (tc_bad_kind_id, + tc_bad_kind_name, + 0, + 0); + } +} + + +// ------------------------------------------------------------------ +// OMG defined TypeCode constants +// ------------------------------------------------------------------ + +namespace CORBA +{ + + // Notice that these are constant TypeCode references/pointers, not + // constant TypeCodes. TypeCodes are effectively read-only since + // all non-static TypeCode operations are const. + + TypeCode_ptr const TypeCode::_tc_Bounds = &TAO::TypeCode::tc_Bounds; + TypeCode_ptr const TypeCode::_tc_BadKind = &TAO::TypeCode::tc_BadKind; + +} diff --git a/TAO/tao/TypeCode.h b/TAO/tao/TypeCode.h new file mode 100644 index 00000000000..ac18e76352c --- /dev/null +++ b/TAO/tao/TypeCode.h @@ -0,0 +1,512 @@ +// -*- C++ -*- + +//============================================================================= +/** + * @file TypeCode.h + * + * $Id$ + * + * Header file the @c CORBA::TypeCode class. + * + * @author Ossama Othman <ossama@dre.vanderbilt.edu> + * @author DOC group at Vanderbilt University, Washington University + * and the University of California at Irvine. + */ +//============================================================================= + +#ifndef TAO_TYPECODE_H +#define TAO_TYPECODE_H + +#include /**/ "ace/pre.h" + +#include "tao/TAO_Export.h" + +#if !defined (ACE_LACKS_PRAGMA_ONCE) +# pragma once +#endif /* ACE_LACKS_PRAGMA_ONCE */ + +#include "tao/UserException.h" +#include "tao/Basic_Types.h" +#include "tao/ValueModifierC.h" +#include "tao/VisibilityC.h" +#include "tao/Typecode_typesC.h" +#include "tao/CORBA_methods.h" +#include "tao/Pseudo_VarOut_T.h" + +namespace CORBA +{ + typedef TAO_Pseudo_Var_T<TypeCode> TypeCode_var; + typedef TAO_Pseudo_Out_T<TypeCode, TypeCode_var> TypeCode_out; + + /** + * @class TypeCode + * + * @brief A representation of the structure of a given OMG + * IDL-declared type. + * + * @c TypeCodes are primarily used by @c CORBA::Anys, the CORBA + * Interface Repository and the CORBA Dynamic Invocation Interface. + */ + class TAO_Export TypeCode + { + public: + + /** + * @class Bounds + * + * @brief Out-of-bounds member index exception. + * + * Exception thrown when attempting to pass an out-of-bounds index + * value to a @c TypeCode operation that accepts a member index + * argument. + */ + class TAO_Export Bounds : public UserException + { + public: + + /// Constructor. + Bounds (void); + + static Bounds * _downcast (CORBA::Exception * ex); + static CORBA::Exception * _alloc (void); + + virtual CORBA::Exception * _tao_duplicate (void) const; + + virtual void _raise (void) const; + + virtual void _tao_encode (TAO_OutputCDR & cdr + ACE_ENV_ARG_DECL) const; + virtual void _tao_decode (TAO_InputCDR & cdr + ACE_ENV_ARG_DECL); + + }; + + /** + * @class BadKind + * + * @brief Invalid @c TypeCode operation exception. + * + * Exception thrown when attempting to invoke a @c TypeCode + * operation that is not valid for the type represented by the + * @c TypeCode. + */ + class TAO_Export BadKind : public CORBA::UserException + { + public: + + BadKind (void); + + static BadKind * _downcast (CORBA::Exception * ex); + static CORBA::Exception * _alloc (void); + + virtual CORBA::Exception * _tao_duplicate (void) const; + + virtual void _raise (void) const; + + virtual void _tao_encode (TAO_OutputCDR & cdr + ACE_ENV_ARG_DECL) const; + virtual void _tao_decode (TAO_InputCDR & cdr + ACE_ENV_ARG_DECL); + + }; + + static CORBA::TypeCode_ptr const _tc_Bounds; + static CORBA::TypeCode_ptr const _tc_BadKind; + + /// Duplicate this @c TypeCode. + /** + * Statically instantiated @c TypeCodes incur no reference count + * manipulation, i.e. reference counting is a no-op. + * + * Dynamically instantiated @c TypeCodes will have their reference + * count incremented by one each time this function is called. + */ + static CORBA::TypeCode_ptr _duplicate (CORBA::TypeCode_ptr tc); + + /// Returns a NULL typecode. + static CORBA::TypeCode_ptr _nil (void); + + /** + * @name @c CORBA::TypeCode Methods + * + * These methods are part of the public interface of @c + * CORBA::TypeCode class, as defined by the OMG CORBA + * specification and C++ mapping. + * + * The C++ mapping does not declare the methods in the public + * @c CORBA::TypeCode API as @c virtual, so work around that by + * making these methods inlined to forward all calls to the + * corresponding protected template method (i.e. the design + * pattern, not the C++ feature) listed below in the @c protected + * block. + */ + //@{ + /// Equality of two @c TypeCodes. + /** + * @return @c true if and only if the set of legal operations is + * the same and invoking any operation on the this + * @c TypeCode and @a tc returns identical results. + */ + Boolean equal (TypeCode_ptr tc + ACE_ENV_ARG_DECL) const; + + /// Equivalence of two @c TypeCodes. + /** + * Equivalence of two @c TypeCodes satisfies a subset of the + * requirements necessary for equality. + * + * @see equal + */ + Boolean equivalent (TypeCode_ptr tc + ACE_ENV_ARG_DECL) const; + + /// The kind of @c TypeCode. + TCKind kind (ACE_ENV_SINGLE_ARG_DECL) const; + + /// Return @c TypeCode stripped of optional @c name and + /// @c member_name fields. + /** + * @note Calling this method will incur additional run-time memory + * consumption since TAO's implementation relies on the + * TypeCodeFactory to dynamically create a compact @c + * TypeCode; the exception being @c TypeCodes with empty + * parameter lists. Those @c TypeCodes are already compact, + * meaning that call this method on such @c TypeCodes incurs + * no additional run-time memory requirements. + * + * Unless you need to send compact @c TypeCodes + * "over-the-wire" or your @c TypeCode corresponds to a + * type with a large number of members, try to stick with + * the existing potentially non-compact @c TypeCode. + * + * @note Compact @c TypeCodes may also be generated statically by + * the TAO_IDL compiler by invoking it with its "-Gt" + * (i.e. enable optimized TypeCodes) command line option. + */ + TypeCode_ptr get_compact_typecode (ACE_ENV_SINGLE_ARG_DECL) const; + + /// The @c RepositoryId globally identifying the type. + /** + * This method is valid for the following kinds of @c TypeCodes: + * + * @li @c tk_objref + * @li @c tk_struct + * @li @c tk_union + * @li @c tk_enum + * @li @c tk_alias + * @li @c tk_value + * @li @c tk_value_box + * @li @c tk_native + * @li @c tk_abstract_interface + * @li @c tk_local_interface + * @li @c tk_except + * @li @c tk_component + * @li @c tk_home + * @li @c tk_event + * + * @note CORBA::TypeCode::id() does not follow the usual parameter + * passing rules defined by the C++ mapping. This behavior + * is required by the C++ mapping. In particular, ownership + * is maintained by the @c TypeCode. + */ + char const * id (ACE_ENV_SINGLE_ARG_DECL) const; + + /// The simple name identifying the type within its enclosing + /// scope. + /** + * This method is valid for the following kinds of @c TypeCodes: + * + * @li @c tk_objref + * @li @c tk_struct + * @li @c tk_union + * @li @c tk_enum + * @li @c tk_alias + * @li @c tk_value + * @li @c tk_value_box + * @li @c tk_native + * @li @c tk_abstract_interface + * @li @c tk_local_interface + * @li @c tk_except + * @li @c tk_component + * @li @c tk_home + * @li @c tk_event + * + * @note CORBA::TypeCode::name() does not follow the usual + * parameter passing rules defined by the C++ mapping. This + * behavior is required by the C++ mapping. In particular, + * ownership is maintained by the @c TypeCode. + */ + char const * name (ACE_ENV_SINGLE_ARG_DECL) const; + + /// The type member count. + /** + * This method is valid for the following kinds of @c TypeCodes: + * + * @li @c tk_struct + * @li @c tk_union + * @li @c tk_enum + * @li @c tk_value + * @li @c tk_except + * @li @c tk_event + */ + ULong member_count (ACE_ENV_SINGLE_ARG_DECL) const; + + /// The type member name. + /** + * This method is valid for the following kinds of @c TypeCodes: + * + * @li @c tk_struct + * @li @c tk_union + * @li @c tk_enum + * @li @c tk_value + * @li @c tk_except + * @li @c tk_event + * + * @note CORBA::TypeCode::member_name() does not follow the usual + * parameter passing rules defined by the C++ mapping. This + * behavior is required by the C++ mapping. In particular, + * ownership is maintained by the @c TypeCode. + */ + char const * member_name (ULong index + ACE_ENV_ARG_DECL) const; + + /// The type member @c TypeCode. + /** + * This method is valid for the following kinds of @c TypeCodes: + * + * @li @c tk_struct + * @li @c tk_union + * @li @c tk_value + * @li @c tk_except + * @li @c tk_event + */ + TypeCode_ptr member_type (ULong index + ACE_ENV_ARG_DECL) const; + + /// The union member label. + /** + * This method is valid for the following kinds of @c TypeCodes: + * + * @li @c tk_union + */ + Any * member_label (ULong index + ACE_ENV_ARG_DECL) const; + + /// The type of all non-default union member labels. + /** + * This method is valid for the following kinds of @c TypeCodes: + * + * @li @c tk_union + */ + TypeCode_ptr discriminator_type (ACE_ENV_SINGLE_ARG_DECL) const; + + /// The index of the default union member. + /** + * This method is valid for the following kinds of @c TypeCodes: + * + * @li @c tk_union + */ + Long default_index (ACE_ENV_SINGLE_ARG_DECL) const; + + /// The length of the type. + /** + * This method is valid for the following kinds of @c TypeCodes: + * + * @li @c tk_string + * @li @c tk_wstring + * @li @c tk_sequence + * @li @c tk_array + */ + ULong length (ACE_ENV_SINGLE_ARG_DECL) const; + + /// The underlying content type. + /** + * This method is valid for the following kinds of @c TypeCodes: + * + * @li @c tk_sequence + * @li @c tk_array + * @li @c tk_value_box + * @li @c tk_alias + */ + TypeCode_ptr content_type (ACE_ENV_SINGLE_ARG_DECL) const; + + /// The number of significant digits. + /** + * This method is valid for the following kinds of @c TypeCodes: + * + * @li @c tk_fixed + */ + UShort fixed_digits (ACE_ENV_SINGLE_ARG_DECL) const; + + /// The scale factor. + /** + * This method is valid for the following kinds of @c TypeCodes: + * + * @li @c tk_fixed + */ + UShort fixed_scale (ACE_ENV_SINGLE_ARG_DECL) const; + + /// The @c Visibility of the @c valuetype or @c eventtype member + /// corresponding to index @a index. + /** + * This method is valid for the following kinds of @c TypeCodes: + * + * @li @c tk_value + * @li @c tk_event + */ + Visibility member_visibility (ULong index + ACE_ENV_ARG_DECL) const; + + /// The @c ValueModifier of the @c valuetype of @c eventtype + /// represented by this @c TypeCode. + /** + * This method is valid for the following kinds of @c TypeCodes: + * + * @li @c tk_value + * @li @c tk_event + */ + ValueModifier type_modifier (ACE_ENV_SINGLE_ARG_DECL) const; + + /// The @c TypeCode corresponding to the concrete base + /// @c valuetype or @c eventtype. + /** + * This method is valid for the following kinds of @c TypeCodes: + * + * @li @c tk_value + * @li @c tk_event + * + * @return @c TypeCode corresponding to the concrete base + * @c valuetype or @c eventtype. + * @c CORBA::TypeCode::_nil() if no concrete base exists. + */ + TypeCode_ptr concrete_base_type (ACE_ENV_SINGLE_ARG_DECL) const; + //@} + + /// Marshal this @c TypeCode into a CDR output stream. + /** + * Marshal this @c TypeCode into the @a cdr output CDR stream, + * excluding the @c TypeCode kind. Existing @a cdr contents will + * not be altered. The marshaled @c TypeCode will be appended to + * the given @a cdr CDR output stream. + * + * @return @c true if marshaling was successful. + * + * @note This is a TAO-specific method that is not part of the + * standard @c CORBA::TypeCode interface. + * + * @note If this method returns @false, the contents of the @a cdr + * output CDR stream are undefined. + */ + virtual bool tao_marshal (TAO_OutputCDR & cdr) const = 0; + + /// Increase the reference count on this @c TypeCode. + virtual void tao_duplicate (void) = 0; + + /// Decrease the reference count on this object. + virtual void tao_release (void) = 0; + + /// Destruction callback for Anys. + static void CORBA::TypeCode::_tao_any_destructor (void * x); + + protected: + + /// Constructor. + TypeCode (void); + + /// Destructor. + /** + * Protected destructor to enforce proper memory management + * through the reference counting mechanism. + */ + virtual ~TypeCode (void); + + /** + * @name @c TypeCode Template Methods + * + * Methods that must be implemented by @c CORBA::TypeCode + * subclasses if valid for those subclasses. + * + * The default implementations of the non-pure virtual methods + * throw the @c CORBA::TypeCode::BadKind exception since many of + * these methods are @c TypeCode type-specific. This reduces code + * duplication and bloat. + * + * The @c TypeCode @c equal(), @c equivalent(), @c kind() and + * @c get_compact_typecode() methods are valid for all + * @c TypeCodes which is why their template method "@c _i" + * counterparts are pure virtual. + */ + //@{ + virtual Boolean equal_i (TypeCode_ptr tc + ACE_ENV_ARG_DECL) const = 0; + virtual Boolean equivalent_i (TypeCode_ptr tc + ACE_ENV_ARG_DECL) const = 0; + virtual TCKind kind_i (ACE_ENV_SINGLE_ARG_DECL) const = 0; + virtual TypeCode_ptr get_compact_typecode_i ( + ACE_ENV_SINGLE_ARG_DECL) const = 0; + + virtual char const * id_i (ACE_ENV_SINGLE_ARG_DECL) const; + virtual char const * name_i (ACE_ENV_SINGLE_ARG_DECL) const; + virtual ULong member_count_i (ACE_ENV_SINGLE_ARG_DECL) const; + virtual char const * member_name_i (ULong index + ACE_ENV_ARG_DECL) const; + virtual TypeCode_ptr member_type_i (ULong index + ACE_ENV_ARG_DECL) const; + virtual Any * member_label_i (ULong index + ACE_ENV_ARG_DECL) const; + virtual TypeCode_ptr discriminator_type_i ( + ACE_ENV_SINGLE_ARG_DECL) const; + virtual Long default_index_i (ACE_ENV_SINGLE_ARG_DECL) const; + virtual ULong length_i (ACE_ENV_SINGLE_ARG_DECL) const; + virtual TypeCode_ptr content_type_i (ACE_ENV_SINGLE_ARG_DECL) const; + virtual UShort fixed_digits_i (ACE_ENV_SINGLE_ARG_DECL) const; + virtual UShort fixed_scale_i (ACE_ENV_SINGLE_ARG_DECL) const; + virtual Visibility member_visibility_i (ULong index + ACE_ENV_ARG_DECL) const; + virtual ValueModifier type_modifier_i (ACE_ENV_SINGLE_ARG_DECL) const; + virtual TypeCode_ptr concrete_base_type_i ( + ACE_ENV_SINGLE_ARG_DECL) const; + //@} + + private: + + // Prevent copying and assignment. + TypeCode (TypeCode const &); + void operator= (TypeCode const &); + + }; + +} // End namespace CORBA + + +TAO_Export bool operator<< (TAO_OutputCDR & cdr, + CORBA::TypeCode_ptr tc); +TAO_Export bool operator>> (TAO_InputCDR & cdr, + CORBA::TypeCode_ptr & tc); + +namespace TAO +{ + /// Return the unaliased content @c TypeCode of the given + /// @c TypeCode. + CORBA::TypeCode_ptr unaliased_typecode (CORBA::TypeCode_ptr tc + ACE_ENV_ARG_DECL); + + /// Return the unaliased @c TCKind of the given @c TypeCode. + /** + * @note This is a convenience function that simply calls @c kind() + * on the unaliased @c TypeCode returned from + * @c unaliased_typecode(). + */ + CORBA::TCKind unaliased_kind (CORBA::TypeCode_ptr tc + ACE_ENV_ARG_DECL); + +} + + +#if defined (__ACE_INLINE__) +# include "tao/TypeCode.inl" +#endif /* __ACE_INLINE__ */ + +#include /**/ "ace/post.h" + +#endif /* TAO_TYPECODE_H */ diff --git a/TAO/tao/TypeCode.inl b/TAO/tao/TypeCode.inl new file mode 100644 index 00000000000..273b02f76cd --- /dev/null +++ b/TAO/tao/TypeCode.inl @@ -0,0 +1,189 @@ +// -*- C++ -*- +// +// $Id$ + + +#include "tao/CORBA_methods.h" +#include "tao/Environment.h" + + +ACE_INLINE CORBA::Boolean +CORBA::is_nil (CORBA::TypeCode_ptr obj) +{ + return obj == 0; +} + +ACE_INLINE void +CORBA::release (CORBA::TypeCode_ptr obj) +{ + if (obj) + obj->tao_release (); +} + +// -------------------------------------------------------------- + +ACE_INLINE +CORBA::TypeCode::TypeCode (void) +{ +} + +ACE_INLINE +CORBA::TypeCode::~TypeCode (void) +{ +} + +ACE_INLINE CORBA::TypeCode_ptr +CORBA::TypeCode::_duplicate (CORBA::TypeCode_ptr tc) +{ + if (!CORBA::is_nil (tc)) + tc->tao_duplicate (); + + return tc; +} + +ACE_INLINE CORBA::TypeCode_ptr +CORBA::TypeCode::_nil (void) +{ + return static_cast<CORBA::TypeCode_ptr> (0); +} + +ACE_INLINE CORBA::Boolean +CORBA::TypeCode::equivalent (TypeCode_ptr tc + ACE_ENV_ARG_DECL) const +{ + if (this == tc) + return 1; + else + return this->equivalent_i (tc + ACE_ENV_ARG_PARAMETER); +} + +ACE_INLINE CORBA::TCKind +CORBA::TypeCode::kind (ACE_ENV_SINGLE_ARG_DECL) const +{ + return this->kind_i (ACE_ENV_SINGLE_ARG_PARAMETER); +} + +ACE_INLINE CORBA::TypeCode_ptr +CORBA::TypeCode::get_compact_typecode (ACE_ENV_SINGLE_ARG_DECL) const +{ + return this->get_compact_typecode_i (ACE_ENV_SINGLE_ARG_PARAMETER); +} + +ACE_INLINE char const * +CORBA::TypeCode::id (ACE_ENV_SINGLE_ARG_DECL) const +{ + return this->id_i (ACE_ENV_SINGLE_ARG_PARAMETER); +} + +ACE_INLINE char const * +CORBA::TypeCode::name (ACE_ENV_SINGLE_ARG_DECL) const +{ + return this->name_i (ACE_ENV_SINGLE_ARG_PARAMETER); +} + +ACE_INLINE CORBA::ULong +CORBA::TypeCode::member_count (ACE_ENV_SINGLE_ARG_DECL) const +{ + return this->member_count_i (ACE_ENV_SINGLE_ARG_PARAMETER); +} + +ACE_INLINE char const * +CORBA::TypeCode::member_name (ULong index + ACE_ENV_ARG_DECL) const +{ + return this->member_name_i (index + ACE_ENV_ARG_PARAMETER); +} + +ACE_INLINE CORBA::TypeCode_ptr +CORBA::TypeCode::member_type (ULong index + ACE_ENV_ARG_DECL) const +{ + return this->member_type_i (index + ACE_ENV_ARG_PARAMETER); +} + +ACE_INLINE CORBA::Any * +CORBA::TypeCode::member_label (ULong index + ACE_ENV_ARG_DECL) const +{ + return this->member_label_i (index + ACE_ENV_ARG_PARAMETER); +} + +ACE_INLINE CORBA::TypeCode_ptr +CORBA::TypeCode::discriminator_type (ACE_ENV_SINGLE_ARG_DECL) const +{ + return this->discriminator_type_i (ACE_ENV_SINGLE_ARG_PARAMETER); +} + +ACE_INLINE CORBA::Long +CORBA::TypeCode::default_index (ACE_ENV_SINGLE_ARG_DECL) const +{ + return this->default_index_i (ACE_ENV_SINGLE_ARG_PARAMETER); +} + +ACE_INLINE CORBA::ULong +CORBA::TypeCode::length (ACE_ENV_SINGLE_ARG_DECL) const +{ + return this->length_i (ACE_ENV_SINGLE_ARG_PARAMETER); +} + +ACE_INLINE CORBA::TypeCode_ptr +CORBA::TypeCode::content_type (ACE_ENV_SINGLE_ARG_DECL) const +{ + return this->content_type_i (ACE_ENV_SINGLE_ARG_PARAMETER); +} + +ACE_INLINE CORBA::UShort +CORBA::TypeCode::fixed_digits (ACE_ENV_SINGLE_ARG_DECL) const +{ + return this->fixed_digits_i (ACE_ENV_SINGLE_ARG_PARAMETER); +} + +ACE_INLINE CORBA::UShort +CORBA::TypeCode::fixed_scale (ACE_ENV_SINGLE_ARG_DECL) const +{ + return this->fixed_scale_i (ACE_ENV_SINGLE_ARG_PARAMETER); +} + +ACE_INLINE CORBA::Visibility +CORBA::TypeCode::member_visibility (ULong index + ACE_ENV_ARG_DECL) const +{ + return this->member_visibility_i (index + ACE_ENV_ARG_PARAMETER); +} + +ACE_INLINE CORBA::ValueModifier +CORBA::TypeCode::type_modifier (ACE_ENV_SINGLE_ARG_DECL) const +{ + return this->type_modifier_i (ACE_ENV_SINGLE_ARG_PARAMETER); +} + +ACE_INLINE CORBA::TypeCode_ptr +CORBA::TypeCode::concrete_base_type (ACE_ENV_SINGLE_ARG_DECL) const +{ + return this->concrete_base_type_i (ACE_ENV_SINGLE_ARG_PARAMETER); +} + +ACE_INLINE void +CORBA::TypeCode::_tao_any_destructor (void * x) +{ + CORBA::release (static_cast <CORBA::TypeCode_ptr> (x)); +} + +// -------------------------------------------------------------- + +ACE_INLINE CORBA::TCKind +TAO::unaliased_kind (CORBA::TypeCode_ptr tc + ACE_ENV_ARG_DECL) +{ + CORBA::TypeCode_var unaliased_tc = + TAO::unaliased_typecode (tc + ACE_ENV_ARG_PARAMETER); + ACE_CHECK_RETURN (CORBA::TAO_TC_KIND_COUNT); + + return unaliased_tc->kind (ACE_ENV_SINGLE_ARG_PARAMETER); +} diff --git a/TAO/tao/TypeCodeFactory_Adapter.h b/TAO/tao/TypeCodeFactory_Adapter.h index 776521743d9..8dea5e4c5c4 100644 --- a/TAO/tao/TypeCodeFactory_Adapter.h +++ b/TAO/tao/TypeCodeFactory_Adapter.h @@ -1,4 +1,4 @@ -// This may look like C, but it's really -*- C++ -*- +// -*- C++ -*- //============================================================================= /** @@ -32,6 +32,18 @@ namespace CORBA class ValueMemberSeq; } +namespace TAO +{ + namespace TypeCode + { + template<typename STRING_TYPE> class Case; + template<typename STRING_TYPE> class Enumerator; + template<typename STRING_TYPE> class Struct_Field; + template<typename STRING_TYPE> class Value_Field; + } +} + + /** * @class TAO_TypeCodeFactory_Adapter * @@ -195,6 +207,52 @@ public: ACE_ENV_ARG_DECL_WITH_DEFAULTS ) ACE_THROW_SPEC ((CORBA::SystemException)) = 0; + + // -- + + // Factory methods that has no corresponding TypeCodeFactory IDL, + // i.e. it is TAO-specific. + + virtual bool _tao_make_typecode (TAO_InputCDR & cdr, + CORBA::TypeCode *& tc); + + virtual CORBA::TypeCode_ptr _tao_create_enum_tc ( + CORBA::TCKind, + char const * id, + char const * name, + TAO::TypeCode::Enumerator<char const *> const *, + CORBA::ULong ncases + ACE_ENV_ARG_DECL) = 0; + + virtual CORBA::TypeCode_ptr _tao_create_struct_except_tc ( + CORBA::TCKind, + char const * id, + char const * name, + TAO::TypeCode::Struct_Field<char const *> const * fields, + CORBA::ULong nfields + ACE_ENV_ARG_DECL) = 0; + + virtual CORBA::TypeCode_ptr _tao_create_union_tc ( + char const * id, + char const * name, + CORBA::TypeCode_ptr * discriminant_type, + TAO::TypeCode::Case<char const *> const *, + CORBA::ULong ncases, + CORBA::Long default_index, + char const * default_case_name, + CORBA::TypeCode_ptr * default_case_type + ACE_ENV_ARG_DECL) = 0; + + virtual CORBA::TypeCode_ptr _tao_create_value_event_tc ( + CORBA::TCKind, + char const * id, + char const * name, + CORBA::ValueModifier modifier, + CORBA::TypeCode_ptr const * concrete_base, + TAO::TypeCode::Value_Field<char const *> const * fields, + CORBA::ULong nfields + ACE_ENV_ARG_DECL) = 0; + }; #include /**/ "ace/post.h" diff --git a/TAO/tao/TypeCode_Base_Attributes.cpp b/TAO/tao/TypeCode_Base_Attributes.cpp new file mode 100644 index 00000000000..b73f35b914a --- /dev/null +++ b/TAO/tao/TypeCode_Base_Attributes.cpp @@ -0,0 +1,10 @@ +// $Id$ + +#ifndef TAO_TYPECODE_BASE_ATTRIBUTES_CPP +#define TAO_TYPECODE_BASE_ATTRIBUTES_CPP + +#ifndef __ACE_INLINE__ +# include "tao/TypeCode_Base_Attributes.inl" +#endif /* !__ACE_INLINE__ */ + +#endif /* TAO_TYPECODE_BASE_ATTRIBUTES_CPP */ diff --git a/TAO/tao/TypeCode_Base_Attributes.h b/TAO/tao/TypeCode_Base_Attributes.h new file mode 100644 index 00000000000..3f475334d6d --- /dev/null +++ b/TAO/tao/TypeCode_Base_Attributes.h @@ -0,0 +1,85 @@ +// -*- C++ -*- + +//============================================================================= +/** + * @file TypeCode_Base_Attributes.h + * + * $Id$ + * + * @author Ossama Othman <ossama@dre.vanderbilt.edu> + */ +//============================================================================= + +#ifndef TAO_TYPECODE_BASE_ATTRIBUTES_H +#define TAO_TYPECODE_BASE_ATTRIBUTES_H + +#include /**/ "ace/pre.h" + +#include "tao/CORBA_String.h" + +#if !defined (ACE_LACKS_PRAGMA_ONCE) +# pragma once +#endif /* ACE_LACKS_PRAGMA_ONCE */ + +namespace TAO +{ + namespace TypeCode + { + + /** + * @class Base_Attributes + * + * @brief Attributes contained by most @c TypeCodes with complex + * parameter lists. + * + * Most @c TypeCodes with complex parameter lists (see Section + * 15.3.5.1 "TypeCode" in the CORBA specification) contain these + * attributes, namely a repository ID and a name. + */ + template <typename STRING_TYPE> + class Base_Attributes + { + public: + + /// Constructor. + Base_Attributes (char const * id, + char const * name); + + /// Get the @c RepositoryId globally identifying the type. + char const * id (void) const; + + /// Get the simple name identifying the type within its + /// enclosing scope. + char const * name (void) const; + + private: + + /// The @c RepositoryId globally identifying the type. + STRING_TYPE const id_; + + /// The simple name identifying the type within its enclosing + /// scope. + STRING_TYPE const name_; + + }; + + } // End namespace TypeCode +} // End namespace TAO + + +#ifdef __ACE_INLINE__ +# include "tao/TypeCode_Base_Attributes.inl" +#endif /* __ACE_INLINE__ */ + +#ifdef ACE_TEMPLATES_REQUIRE_SOURCE +# include "tao/TypeCode_Base_Attributes.cpp" +#endif /* ACE_TEMPLATES_REQUIRE_SOURCE */ + +#ifdef ACE_TEMPLATES_REQUIRE_PRAGMA +# pragma implementation ("TypeCode_Base_Attributes.cpp") +#endif /* ACE_TEMPLATES_REQUIRE_PRAGMA */ + + +#include /**/ "ace/post.h" + +#endif /* TAO_TYPECODE_BASE_ATTRIBUTES_H */ diff --git a/TAO/tao/TypeCode_Base_Attributes.inl b/TAO/tao/TypeCode_Base_Attributes.inl new file mode 100644 index 00000000000..55e6dd94cb4 --- /dev/null +++ b/TAO/tao/TypeCode_Base_Attributes.inl @@ -0,0 +1,46 @@ +// -*- C++ -*- +// +// $Id$ + +template <typename STRING_TYPE> +ACE_INLINE +TAO::TypeCode::Base_Attributes<STRING_TYPE>::Base_Attributes ( + char const * id, + char const * name) + : id_ (id), + name_ (name) +{ +} + +template <typename STRING_TYPE> +ACE_INLINE char const * +TAO::TypeCode::Base_Attributes<STRING_TYPE>::id (void) const +{ + return this->id_; +} + +template <typename STRING_TYPE> +ACE_INLINE char const * +TAO::TypeCode::Base_Attributes<STRING_TYPE>::name (void) const +{ + return this->name_; +} + +// ----------------------------------------------------------------- +// Some compilers exhibit warnings about better conversion sequence +// from a CORBA::String_var to a char const *. These member +// specializations work around them by performing explicit +// conversions. +// ----------------------------------------------------------------- + +ACE_INLINE char const * +TAO::TypeCode::Base_Attributes<CORBA::String_var>::id (void) const +{ + return this->id_.in (); +} + +ACE_INLINE char const * +TAO::TypeCode::Base_Attributes<CORBA::String_var>::name (void) const +{ + return this->name_.in (); +} diff --git a/TAO/tao/TypeCode_Case.cpp b/TAO/tao/TypeCode_Case.cpp new file mode 100644 index 00000000000..b257c910aa3 --- /dev/null +++ b/TAO/tao/TypeCode_Case.cpp @@ -0,0 +1,86 @@ +// $Id$ + +#ifndef TAO_TYPECODE_CASE_CPP +#define TAO_TYPECODE_CASE_CPP + +#include "TypeCode_Case.h" + +#ifndef __ACE_INLINE__ +# include "tao/TypeCode_Case.inl" +#endif /* __ACE_INLINE__ */ + + +template <typename STRING_TYPE> +TAO::TypeCode::Case<STRING_TYPE>::~Case (void) +{ + if (this->type_) + CORBA::release (*(this->type_)); +} + +template <typename STRING_TYPE> +bool +TAO::TypeCode::Case<STRING_TYPE>::equal (CORBA::ULong index, + CORBA::TypeCode_ptr tc + ACE_ENV_ARG_DECL) const +{ + // Check case names. + char const * const lhs_name = this->name (); + char const * const rhs_name = tc->member_name (index + ACE_ENV_ARG_PARAMETER); + ACE_CHECK_RETURN (0); + + if (ACE_OS::strcmp (lhs_name, rhs_name) != 0) + return 0; + + // Check case TypeCodes. + CORBA::TypeCode_ptr const lhs_tc = this->type (); + CORBA::TypeCode_var const rhs_tc = + tc->member_type (index + ACE_ENV_ARG_PARAMETER); + ACE_CHECK_RETURN (0); + + CORBA::Boolean const equal_members = + lhs_tc->equal (rhs_tc.in () + ACE_ENV_ARG_PARAMETER); + ACE_CHECK_RETURN (0); + + if (!equal_members) + return 0; + + // Check case labels. + return this->equal_labels (index, + tc + ACE_ENV_ARG_PARAMETER); +} + +template <typename STRING_TYPE> +bool +TAO::TypeCode::Case<STRING_TYPE>::equivalent (CORBA::ULong index, + CORBA::TypeCode_ptr tc + ACE_ENV_ARG_DECL) const +{ + // Member names are ignore when determining equivalence. + + // Check case TypeCodes. + CORBA::TypeCode_ptr const lhs_tc = this->type (); + CORBA::TypeCode_var const rhs_tc = + tc->member_type (index + ACE_ENV_ARG_PARAMETER); + ACE_CHECK_RETURN (0); + + CORBA::Boolean const equivalent_members = + lhs_tc->equivalent (rhs_tc.in () + ACE_ENV_ARG_PARAMETER); + ACE_CHECK_RETURN (0); + + if (!equivalent_members) + return 0; + + // Check case labels. + // The labels must be equal when determining equivalence, too. + return this->equal_labels (index, + tc + ACE_ENV_ARG_PARAMETER); +} + +#endif /* TAO_TYPECODE_CASE_CPP */ diff --git a/TAO/tao/TypeCode_Case.h b/TAO/tao/TypeCode_Case.h new file mode 100644 index 00000000000..52a1a35af5b --- /dev/null +++ b/TAO/tao/TypeCode_Case.h @@ -0,0 +1,160 @@ +// -*- C++ -*- + +//============================================================================= +/** + * @file TypeCode_Case.h + * + * $Id$ + * + * Header file for @c TAO::TypeCode::Case type. + * + * @author Ossama Othman + */ +//============================================================================= + +#ifndef TAO_TYPECODE_CASE_H +#define TAO_TYPECODE_CASE_H + +#include /**/ "ace/pre.h" + +#include "ace/config.h" + +#if !defined (ACE_LACKS_PRAGMA_ONCE) +# pragma once +#endif /* ACE_LACKS_PRAGMA_ONCE */ + + +namespace CORBA +{ + class TypeCode; + typedef TypeCode* TypeCode_ptr; + + class Any; +} + +namespace TAO +{ + namespace TypeCode + { + + /** + * @class Case + * + * @brief Abstract base class for that represents an IDL @c union + * case/member. + * + * This class hides the actual IDL @c union member label value + * from the @c TAO::TypeCode::Union class by relying on a + * CORBA::Any return value that corresponds to the @c + * CORBA::TypeCode::member_label() return type. It also allows + * the @c TAO::TypeCode::Union class to marshal the member label + * values into a CDR stream without knowledge of the underlying + * member label values. + */ + template <typename STRING_TYPE> + class Case + { + public: + + /// Constructor. + Case (char const * name, + CORBA::TypeCode_ptr const * tc); + + /// Destructor. + virtual ~Case (void); + + /// Return the IDL @c union case label value embedded within a + /// @c CORBA::Any. + virtual CORBA::Any * label (ACE_ENV_SINGLE_ARG_DECL) const = 0; + + /// Get the name of the @c union case/member. + char const * name (void) const; + + /// Get the @c CORBA::TypeCode of the @c union case/member. + /** + * @note The reference count is not manipulated by this method, + * i.e., ownership is retained by this class. + */ + CORBA::TypeCode_ptr type (void) const; + + /// Marshal this IDL @c union member into the given output CDR + /// stream. + bool marshal (TAO_OutputCDR & cdr) const; + + /// Check for equality of the @c case attributes contained by this + /// class and the corresponding member attributes at index "@a + /// index" in the given @c TypeCode @a tc. + bool equal (CORBA::ULong index, + CORBA::TypeCode_ptr tc + ACE_ENV_ARG_DECL) const; + + /// Check for equivalence of the @c case attributes contained by + /// this class and the corresponding member attributes at index + /// "@a index" in the given @c TypeCode @a tc. + bool equivalent (CORBA::ULong index, + CORBA::TypeCode_ptr tc + ACE_ENV_ARG_DECL) const; + + protected: + + /// Marshal the IDL @c union @c case label value into the given + /// output CDR stream. + virtual bool marshal_label (TAO_OutputCDR & cdr) const = 0; + + /// Verify equality of member labels. + /** + * Performing member label equality comparisons in the @c Case + * subclass allows us to avoid performing interpretive + * extraction of the value from the @c Any returned from the + * "right hand side" operand @c TypeCode since the @c Case + * subclass already knows what type and value should be + * extracted from the @c Any. + * + * @param index Member index of given @c TypeCode @a tc being + * tested. + * @param tc The @c TypeCode whose member "@a index" label is + * being tested. + */ + virtual bool equal_label (CORBA::ULong index, + CORBA::TypeCode_ptr tc + ACE_ENV_ARG_DECL) const = 0; + + private: + + /// The name of the case. + STRING_TYPE const name_; + + /// Pointer to the @c CORBA::TypeCode of the case. + /** + * A pointer to the @c CORBA::TypeCode_ptr rather than the + * @c CORBA::TypeCode_ptr itself is stored since that address is + * well-defined. We may not know the value of the @c + * CORBA::TypeCode_ptr when creating this @c Case statically at + * compile-time, hence the indirection. + * + * @note This @c TypeCode is released upon destruction of this + * @c Case. + */ + CORBA::TypeCode_ptr const * const type_; + + }; + + } // End namespace TypeCode +} // End namespace TAO + + +#ifdef __ACE_INLINE__ +# include "tao/TypeCode_Case.inl" +#endif /* __ACE_INLINE__ */ + +#ifdef ACE_TEMPLATES_REQUIRE_SOURCE +# include "tao/TypeCode_Case.cpp" +#endif /* ACE_TEMPLATES_REQUIRE_SOURCE */ + +#ifdef ACE_TEMPLATES_REQUIRE_PRAGMA +# pragma implementation ("TypeCode_Case.cpp") +#endif /* ACE_TEMPLATES_REQUIRE_PRAGMA */ + +#include /**/ "ace/post.h" + +#endif /* TAO_TYPECODE_CASE_H */ diff --git a/TAO/tao/TypeCode_Case.inl b/TAO/tao/TypeCode_Case.inl new file mode 100644 index 00000000000..b97d1e718be --- /dev/null +++ b/TAO/tao/TypeCode_Case.inl @@ -0,0 +1,55 @@ +// -*- C++ -*- +// +// $Id$ + +#include "tao/CDR.h" + + +template <typename STRING_TYPE> +ACE_INLINE +TAO::TypeCode::Case<STRING_TYPE>::Case ( + char const * member_name, + CORBA::TypeCode_ptr const * member_type) + : name_ (member_name) + , type_ (member_type) +{ +} + +template <typename STRING_TYPE> +ACE_INLINE char const * +TAO::TypeCode::Case<STRING_TYPE>::name (void) const +{ + return this->name_; +} + +template <typename STRING_TYPE> +ACE_INLINE CORBA::TypeCode_ptr +TAO::TypeCode::Case<STRING_TYPE>::type (void) const +{ + return *this->type_; +} + +template <typename STRING_TYPE> +ACE_INLINE bool +TAO::TypeCode::Case<STRING_TYPE>::marshal ( + TAO_OutputCDR & cdr) const +{ + return + this->marshal_label () + && (cdr << this->name ()) + && (cdr << this->type ()); +} + + +// ----------------------------------------------------------------- +// Some compilers exhibit warnings about better conversion sequence +// from a CORBA::String_var to a char const *. This member +// specialization works around them by performing explicit +// conversions. +// ----------------------------------------------------------------- + +ACE_INLINE char const * +TAO::TypeCode::Case<CORBA::String_var>::name (void) const +{ + return this->name_.in (); +} diff --git a/TAO/tao/TypeCode_Constants.cpp b/TAO/tao/TypeCode_Constants.cpp new file mode 100644 index 00000000000..69771b39f6c --- /dev/null +++ b/TAO/tao/TypeCode_Constants.cpp @@ -0,0 +1,140 @@ +// $Id$ + + +#include "TypeCode_Constants.h" + + +ACE_RCSID (tao, + TypeCode_Constants, + "$Id$") + + +#include "Null_RefCount_Policy.h" +#include "Empty_Param_TypeCode.h" +#include "Objref_TypeCode.h" +#include "String_TypeCode.h" +#include "Value_TypeCode.h" + + +namespace TAO +{ + namespace TypeCode + { + // Notice that these are all statically instantiated and not + // exported. There CORBA::TypeCode_ptr counterparts are, however, + // exported. + + Empty_Param tc_null (CORBA::tk_null); + Empty_Param tc_void (CORBA::tk_void); + Empty_Param tc_boolean (CORBA::tk_boolean); + Empty_Param tc_char (CORBA::tk_char); + Empty_Param tc_wchar (CORBA::tk_wchar); + Empty_Param tc_short (CORBA::tk_short); + Empty_Param tc_ushort (CORBA::tk_ushort); + Empty_Param tc_long (CORBA::tk_long); + Empty_Param tc_ulong (CORBA::tk_ulong); + Empty_Param tc_longlong (CORBA::tk_longlong); + Empty_Param tc_ulonglong (CORBA::tk_ulonglong); + Empty_Param tc_float (CORBA::tk_float); + Empty_Param tc_double (CORBA::tk_double); + Empty_Param tc_longdouble (CORBA::tk_longdouble); + Empty_Param tc_octet (CORBA::tk_octet); + Empty_Param tc_any (CORBA::tk_any); + Empty_Param tc_TypeCode (CORBA::tk_TypeCode); + Empty_Param tc_Principal (CORBA::tk_Principal); + + // -------------- + + String<TAO::Null_RefCount_Policy> tc_string (CORBA::tk_string, 0); + String<TAO::Null_RefCount_Policy> tc_wstring (CORBA::tk_wstring, 0); + + // -------------- + + char const tc_object_id[] = "IDL:omg.org/CORBA/Object:1.0"; + char const tc_object_name[] = "Object"; + Objref<char const *, + CORBA::tk_objref, + TAO::Null_RefCount_Policy> tc_Object (tc_object_id, tc_object_name); + + char const tc_component_id[] = "IDL:omg.org/CORBA/CCMObject:1.0"; + char const tc_component_name[] = "CCMObject"; + Objref<char const *, + CORBA::tk_component, + TAO::Null_RefCount_Policy> tc_Component (tc_component_id, + tc_component_name); + + char const tc_home_id[] = "IDL:omg.org/CORBA/CCMHome:1.0"; + char const tc_home_name[] = "CCMHome"; + Objref<char const *, + CORBA::tk_home, + TAO::Null_RefCount_Policy> tc_Home (tc_home_id, tc_home_name); + + // -------------- + + char const tc_value_base_id[] = "IDL:omg.org/CORBA/ValueBase:1.0"; + char const tc_value_base_name[] = "ValueBase"; + Value<char const *, + Value_Field<char const *> const *, + CORBA::tk_value, + TAO::Null_RefCount_Policy> tc_ValueBase (tc_value_base_id, + tc_value_base_name, + CORBA::VM_NONE, + 0, // Nil TypeCode + 0, // Field array + 0); // Field count + + char const tc_event_base_id[] = "IDL:omg.org/CORBA/EventBase:1.0"; + char const tc_event_base_name[] = "EventBase"; + Value<char const *, + Value_Field<char const *> const *, + CORBA::tk_event, + TAO::Null_RefCount_Policy> tc_EventBase (tc_event_base_id, + tc_event_base_name, + CORBA::VM_NONE, + 0, // Nil TypeCode + 0, // Field array + 0); // Field count + + } // End TypeCode namespace +} // End TAO namespace + +// ------------------------------------------------------------------ +// OMG defined TypeCode constants +// ------------------------------------------------------------------ + +namespace CORBA +{ + // Notice that these are constant TypeCode references/pointers, not + // constant TypeCodes. TypeCodes are effectively read-only since + // all non-static TypeCode operations are const. + + TypeCode_ptr const _tc_null = &TAO::TypeCode::tc_null; + TypeCode_ptr const _tc_void = &TAO::TypeCode::tc_void; + TypeCode_ptr const _tc_boolean = &TAO::TypeCode::tc_boolean; + TypeCode_ptr const _tc_char = &TAO::TypeCode::tc_char; + TypeCode_ptr const _tc_wchar = &TAO::TypeCode::tc_wchar; + TypeCode_ptr const _tc_short = &TAO::TypeCode::tc_short; + TypeCode_ptr const _tc_ushort = &TAO::TypeCode::tc_ushort; + TypeCode_ptr const _tc_long = &TAO::TypeCode::tc_long; + TypeCode_ptr const _tc_ulong = &TAO::TypeCode::tc_ulong; + TypeCode_ptr const _tc_longlong = &TAO::TypeCode::tc_longlong; + TypeCode_ptr const _tc_ulonglong = &TAO::TypeCode::tc_ulonglong; + TypeCode_ptr const _tc_float = &TAO::TypeCode::tc_float; + TypeCode_ptr const _tc_double = &TAO::TypeCode::tc_double; + TypeCode_ptr const _tc_longdouble = &TAO::TypeCode::tc_longdouble; + TypeCode_ptr const _tc_octet = &TAO::TypeCode::tc_octet; + TypeCode_ptr const _tc_any = &TAO::TypeCode::tc_any; + TypeCode_ptr const _tc_TypeCode = &TAO::TypeCode::tc_TypeCode; + TypeCode_ptr const _tc_Principal = &TAO::TypeCode::tc_Principal; + + TypeCode_ptr const _tc_string = &TAO::TypeCode::tc_string; + TypeCode_ptr const _tc_wstring = &TAO::TypeCode::tc_wstring; + + TypeCode_ptr const _tc_Object = &TAO::TypeCode::tc_Object; + TypeCode_ptr const _tc_Component = &TAO::TypeCode::tc_Component; + TypeCode_ptr const _tc_Home = &TAO::TypeCode::tc_Home; + + TypeCode_ptr const _tc_ValueBase = &TAO::TypeCode::tc_ValueBase; + TypeCode_ptr const _tc_EventBase = &TAO::TypeCode::tc_EventBase; + +} diff --git a/TAO/tao/TypeCode_Constants.h b/TAO/tao/TypeCode_Constants.h new file mode 100644 index 00000000000..f3302e9071b --- /dev/null +++ b/TAO/tao/TypeCode_Constants.h @@ -0,0 +1,115 @@ +// -*- C++ -*- + +//============================================================================= +/** + * @file TypeCode_Constants.h + * + * $Id$ + * + * Declare the @c TypeCode constants available to the ORB and user + * applications. + * + * @author Jeff Parsons + * @author Ossama Othman + */ +//============================================================================= + +#ifndef TAO_TYPECODE_CONSTANTS_FORWARD_H +#define TAO_TYPECODE_CONSTANTS_FORWARD_H + +#include /**/ "ace/pre.h" + +#include "tao/TAO_Export.h" + +namespace CORBA +{ + class TypeCode; + typedef TypeCode * TypeCode_ptr; + + /** + * @name TypeCode Constants + * + * All the TypeCode constants + */ + //@{ + extern TAO_Export TypeCode_ptr const _tc_null; + extern TAO_Export TypeCode_ptr const _tc_void; + extern TAO_Export TypeCode_ptr const _tc_short; + extern TAO_Export TypeCode_ptr const _tc_long; + extern TAO_Export TypeCode_ptr const _tc_ushort; + extern TAO_Export TypeCode_ptr const _tc_ulong; + extern TAO_Export TypeCode_ptr const _tc_float; + extern TAO_Export TypeCode_ptr const _tc_double; + extern TAO_Export TypeCode_ptr const _tc_boolean; + extern TAO_Export TypeCode_ptr const _tc_char; + extern TAO_Export TypeCode_ptr const _tc_octet; + extern TAO_Export TypeCode_ptr const _tc_any; + extern TAO_Export TypeCode_ptr const _tc_TypeCode; + extern TAO_Export TypeCode_ptr const _tc_Principal; + extern TAO_Export TypeCode_ptr const _tc_Object; + extern TAO_Export TypeCode_ptr const _tc_string; + extern TAO_Export TypeCode_ptr const _tc_longlong; + extern TAO_Export TypeCode_ptr const _tc_ulonglong; + extern TAO_Export TypeCode_ptr const _tc_longdouble; + extern TAO_Export TypeCode_ptr const _tc_wchar; + extern TAO_Export TypeCode_ptr const _tc_wstring; + +#define TAO_SYSTEM_EXCEPTION_LIST \ + TAO_SYSTEM_EXCEPTION(UNKNOWN); \ + TAO_SYSTEM_EXCEPTION(BAD_PARAM); \ + TAO_SYSTEM_EXCEPTION(NO_MEMORY); \ + TAO_SYSTEM_EXCEPTION(IMP_LIMIT); \ + TAO_SYSTEM_EXCEPTION(COMM_FAILURE); \ + TAO_SYSTEM_EXCEPTION(INV_OBJREF); \ + TAO_SYSTEM_EXCEPTION(OBJECT_NOT_EXIST); \ + TAO_SYSTEM_EXCEPTION(NO_PERMISSION); \ + TAO_SYSTEM_EXCEPTION(INTERNAL); \ + TAO_SYSTEM_EXCEPTION(MARSHAL); \ + TAO_SYSTEM_EXCEPTION(INITIALIZE); \ + TAO_SYSTEM_EXCEPTION(NO_IMPLEMENT); \ + TAO_SYSTEM_EXCEPTION(BAD_TYPECODE); \ + TAO_SYSTEM_EXCEPTION(BAD_OPERATION); \ + TAO_SYSTEM_EXCEPTION(NO_RESOURCES); \ + TAO_SYSTEM_EXCEPTION(NO_RESPONSE); \ + TAO_SYSTEM_EXCEPTION(PERSIST_STORE); \ + TAO_SYSTEM_EXCEPTION(BAD_INV_ORDER); \ + TAO_SYSTEM_EXCEPTION(TRANSIENT); \ + TAO_SYSTEM_EXCEPTION(FREE_MEM); \ + TAO_SYSTEM_EXCEPTION(INV_IDENT); \ + TAO_SYSTEM_EXCEPTION(INV_FLAG); \ + TAO_SYSTEM_EXCEPTION(INTF_REPOS); \ + TAO_SYSTEM_EXCEPTION(BAD_CONTEXT); \ + TAO_SYSTEM_EXCEPTION(OBJ_ADAPTER); \ + TAO_SYSTEM_EXCEPTION(DATA_CONVERSION); \ + TAO_SYSTEM_EXCEPTION(INV_POLICY); \ + TAO_SYSTEM_EXCEPTION(REBIND); \ + TAO_SYSTEM_EXCEPTION(TIMEOUT); \ + TAO_SYSTEM_EXCEPTION(TRANSACTION_UNAVAILABLE); \ + TAO_SYSTEM_EXCEPTION(TRANSACTION_MODE); \ + TAO_SYSTEM_EXCEPTION(TRANSACTION_REQUIRED); \ + TAO_SYSTEM_EXCEPTION(TRANSACTION_ROLLEDBACK); \ + TAO_SYSTEM_EXCEPTION(INVALID_TRANSACTION); \ + TAO_SYSTEM_EXCEPTION(CODESET_INCOMPATIBLE); \ + TAO_SYSTEM_EXCEPTION(BAD_QOS); \ + TAO_SYSTEM_EXCEPTION(INVALID_ACTIVITY); \ + TAO_SYSTEM_EXCEPTION(ACTIVITY_COMPLETED); \ + TAO_SYSTEM_EXCEPTION(ACTIVITY_REQUIRED); \ + TAO_SYSTEM_EXCEPTION(THREAD_CANCELLED); + + // = Typecode constants for system exceptions. +#define TAO_SYSTEM_EXCEPTION(name) \ + extern TAO_Export TypeCode_ptr const _tc_ ## name + TAO_SYSTEM_EXCEPTION_LIST +#undef TAO_SYSTEM_EXCEPTION + //@} + + extern TAO_Export TypeCode_ptr const _tc_UnknownUserException; + + extern TAO_Export TypeCode_ptr const _tc_Current; + + extern TAO_Export TypeCode_ptr const _tc_NamedValue; +} + +#include /**/ "ace/post.h" + +#endif /* TAO_TYPECODE_CONSTANTS_H */ diff --git a/TAO/tao/TypeCode_Default_Case.cpp b/TAO/tao/TypeCode_Default_Case.cpp new file mode 100644 index 00000000000..8a7449b51b2 --- /dev/null +++ b/TAO/tao/TypeCode_Default_Case.cpp @@ -0,0 +1,83 @@ +// $Id$ + +#ifndef TAO_TYPECODE_DEFAULT_CASE_CPP +#define TAO_TYPECODE_DEFAULT_CASE_CPP + +#include "TypeCode_Default_Case.h" + +#include "tao/CDR.h" +#include "tao/Any.h" + +#ifndef __ACE_INLINE__ +# include "tao/TypeCode_Default_Case.inl" +#endif /* __ACE_INLINE__ */ + + +namespace TAO +{ + namespace TypeCode + { + + // Default case's label is a zero octet. + static TAO_OutputCDR::from_octet const zero_octet (0); + + } // Namespace TypeCode +} // Namespace TAO + +// ------------------------------------------------------------ + +template <typename STRING_TYPE> +bool +TAO::TypeCode::Default_Case<STRING_TYPE>::marshal_label ( + TAO_OutputCDR & cdr) const +{ + // Default case's label is a zero octet. + return (cdr << TAO::TypeCode::zero_octet); +} + +template <typename STRING_TYPE> +bool +TAO::TypeCode::Default_Case<STRING_TYPE>::equal_label (CORBA::ULong index, + CORBA::TypeCode_ptr tc + ACE_ENV_ARG_DECL) const +{ + CORBA::Any_var const any = tc->member_label (index + ACE_ENV_ARG_PARAMETER); + ACE_CHECK_RETURN (false); + + + // Label for default case is always zero octet. + static CORBA::Octet const this_label = 0; + + CORBA::Octet tc_label; + if ((any.in () >>= CORBA::Any::to_octet (tc_label)) + && this_label == tc_label) + { + return true; + } + + return false; +} + +template <typename STRING_TYPE> +CORBA::Any * +TAO::TypeCode::Default_Case<STRING_TYPE>::label ( + ACE_ENV_SINGLE_ARG_DECL) const +{ + CORBA::Any * value; + + ACE_NEW_THROW_EX (value, + CORBA::Any, + CORBA::NO_MEMORY ()); + ACE_CHECK_RETURN (0); + + CORBA::Any_var safe_value (value); + + *value <<= TAO::TypeCode::zero_octet; + + return safe_value._retn (); +} + + + +#endif /* TAO_TYPECODE_DEFAULT_CASE_CPP */ diff --git a/TAO/tao/TypeCode_Default_Case.h b/TAO/tao/TypeCode_Default_Case.h new file mode 100644 index 00000000000..1b9528fcc62 --- /dev/null +++ b/TAO/tao/TypeCode_Default_Case.h @@ -0,0 +1,86 @@ +// -*- C++ -*- + +//============================================================================= +/** + * @file TypeCode_Default_Case.h + * + * $Id$ + * + * Header file for @c TAO::TypeCode::Default_Case type. + * + * @author Ossama Othman + */ +//============================================================================= + +#ifndef TAO_TYPECODE_DEFAULT_CASE_H +#define TAO_TYPECODE_DEFAULT_CASE_H + +#include /**/ "ace/pre.h" + +#include "ace/config.h" + +#if !defined (ACE_LACKS_PRAGMA_ONCE) +# pragma once +#endif /* ACE_LACKS_PRAGMA_ONCE */ + +#include "tao/TypeCode_Case.h" + + +namespace TAO +{ + namespace TypeCode + { + + /** + * @class Default_Case + * + * @brief Representation of an OMG IDL defined @c union @c default + * @c case. + * + */ + template <typename STRING_TYPE> + class Default_Case : public Case<STRING_TYPE> + { + public: + + /// Constructor. + Default_Case (char const * member_name, + CORBA::TypeCode_ptr const * member_type); + + /** + * @name @c TAO::TypeCode::Case Methods + * + * Methods required by the @c TAO::TypeCode::Case abstract base + * class. + * + * @see @c TAO::TypeCode::Case + */ + //@{ + virtual CORBA::Any * label (ACE_ENV_SINGLE_ARG_DECL) const; + virtual bool marshal_label (TAO_OutputCDR & cdr) const; + virtual bool equal_label (CORBA::ULong index, + CORBA::TypeCode_ptr tc + ACE_ENV_ARG_DECL) const; + //@} + + }; + + } // End namespace TypeCode +} // End namespace TAO + + +#ifdef __ACE_INLINE__ +# include "tao/TypeCode_Default_Case.inl" +#endif /* __ACE_INLINE__ */ + +#ifdef ACE_TEMPLATES_REQUIRE_SOURCE +# include "tao/TypeCode_Default_Case.cpp" +#endif /* ACE_TEMPLATES_REQUIRE_SOURCE */ + +#ifdef ACE_TEMPLATES_REQUIRE_PRAGMA +# pragma implementation ("TypeCode_Default_Case.cpp") +#endif /* ACE_TEMPLATES_REQUIRE_PRAGMA */ + +#include /**/ "ace/post.h" + +#endif /* TAO_TYPECODE_DEFAULT_CASE_H */ diff --git a/TAO/tao/TypeCode_Default_Case.inl b/TAO/tao/TypeCode_Default_Case.inl new file mode 100644 index 00000000000..8b4df509191 --- /dev/null +++ b/TAO/tao/TypeCode_Default_Case.inl @@ -0,0 +1,11 @@ +// -*- C++ -*- +// +// $Id$ + +template <typename STRING_TYPE> +TAO::TypeCode::Default_Case<STRING_TYPE>::Default_Case ( + char const * member_name, + CORBA::TypeCode_ptr const * member_type) + : Case<STRING_TYPE> (member_name, member_type) +{ +} diff --git a/TAO/tao/TypeCode_Enumerator.cpp b/TAO/tao/TypeCode_Enumerator.cpp new file mode 100644 index 00000000000..a17468c4d01 --- /dev/null +++ b/TAO/tao/TypeCode_Enumerator.cpp @@ -0,0 +1,12 @@ +// $Id$ + +#ifndef TAO_TYPECODE_ENUMERATOR_CPP +#define TAO_TYPECODE_ENUMERATOR_CPP + +#include "TypeCode_Enumerator.h" + +#ifndef __ACE_INLINE__ +# include "tao/TypeCode_Enumerator.inl" +#endif /* __ACE_INLINE__ */ + +#endif /* TAO_TYPECODE_ENUMERATOR_CPP */ diff --git a/TAO/tao/TypeCode_Enumerator.h b/TAO/tao/TypeCode_Enumerator.h new file mode 100644 index 00000000000..9e75532ecfc --- /dev/null +++ b/TAO/tao/TypeCode_Enumerator.h @@ -0,0 +1,109 @@ +// -*- C++ -*- + +//============================================================================= +/** + * @file TypeCode_Enumerator.h + * + * $Id$ + * + * Header file for @c TAO::TypeCode::Enumerator type. + * + * @author Ossama Othman <ossama@dre.vanderbilt.edu> + */ +//============================================================================= + +#ifndef TAO_TYPECODE_ENUMERATOR_H +#define TAO_TYPECODE_ENUMERATOR_H + +#include /**/ "ace/pre.h" + +#include "tao/TAO_Export.h" + +#if !defined (ACE_LACKS_PRAGMA_ONCE) +# pragma once +#endif /* ACE_LACKS_PRAGMA_ONCE */ + +#include "tao/orbconf.h" + +namespace CORBA +{ + class TypeCode; + typedef TypeCode* TypeCode_ptr; +} + +namespace TAO +{ + namespace TypeCode + { + /** + * @struct Enumerator + * + * @brief Enumerator of an OMG IDL defined enumeration (@c enum). + * + * An @c Enumerator contains the name for a given OMG IDL defined + * enumeration. For example, the enumerators in following OMG IDL + * enumeration: + * + * \code + * enum Color + * { + * RED; + * BLUE; + * }; + * \endcode + * + * would be represented using the following @c + * TAO::TypeCode::Enumerator array: + * + * \code + * TAO::TypeCode::Enumerator _tao_enumerators_Color[] = + * { + * "RED", + * "BLUE", + * }; + * \endcode + */ + template <typename STRING_TYPE> + struct Enumerator + { + + /// Return the name of the @c Enumerator. + /** + * @note This method unfortunately exists so that we can + * retrieve the underlying string when the @a STRING_TYPE + * is @c CORBA::String_var rather than the + * @c CORBA::String_var itself. This is necessary to + * silence a warning about better conversion sequences + * exhibited by some C++ compilers. + */ + char const * get_name (void) const; + + /// The name of the enumerator. + STRING_TYPE name; + + }; + + } // End namespace TypeCode +} // End namespace TAO + + +// If we didn't have to worry about better conversion sequence +// warnings, and drop the Enumerator<>::get_name() method, we could +// drop the below #include directives and remove the files contained +// within them altogether. + +#ifdef __ACE_INLINE__ +# include "tao/TypeCode_Enumerator.inl" +#endif /* __ACE_INLINE__ */ + +#ifdef ACE_TEMPLATES_REQUIRE_SOURCE +# include "tao/TypeCode_Enumerator.cpp" +#endif /* ACE_TEMPLATES_REQUIRE_SOURCE */ + +#ifdef ACE_TEMPLATES_REQUIRE_PRAGMA +# pragma implementation ("TypeCode_Enumerator.cpp") +#endif /* ACE_TEMPLATES_REQUIRE_PRAGMA */ + +#include /**/ "ace/post.h" + +#endif /* TAO_TYPECODE_ENUMERATOR_H */ diff --git a/TAO/tao/TypeCode_Enumerator.inl b/TAO/tao/TypeCode_Enumerator.inl new file mode 100644 index 00000000000..6f3ea4eb33e --- /dev/null +++ b/TAO/tao/TypeCode_Enumerator.inl @@ -0,0 +1,23 @@ +// -*- C++ -*- +// +// $Id$ + +template <typename STRING_TYPE> +ACE_INLINE char const * +TAO::TypeCode::Enumerator<STRING_TYPE>::get_name (void) const +{ + return this->name; +} + +// ----------------------------------------------------------------- +// Some compilers exhibit warnings about better conversion sequence +// from a CORBA::String_var to a char const *. This member +// specialization works around them by performing explicit +// conversions. +// ----------------------------------------------------------------- + +ACE_INLINE char const * +TAO::TypeCode::Enumerator<CORBA::String_var>::get_name (void) const +{ + return this->name.in (); +} diff --git a/TAO/tao/TypeCode_Non_Default_Case.cpp b/TAO/tao/TypeCode_Non_Default_Case.cpp new file mode 100644 index 00000000000..8b04c406048 --- /dev/null +++ b/TAO/tao/TypeCode_Non_Default_Case.cpp @@ -0,0 +1,143 @@ +// $Id$ + +#ifndef TAO_TYPECODE_NON_DEFAULT_CASE_CPP +#define TAO_TYPECODE_NON_DEFAULT_CASE_CPP + +#include "TypeCode_Non_Default_Case.h" + +#include "tao/CDR.h" +#include "tao/Any.h" + +#ifndef __ACE_INLINE__ +# include "tao/TypeCode_Non_Default_Case.inl" +#endif /* __ACE_INLINE__ */ + +namespace TAO +{ + namespace TypeCode + { + template <typename T> + struct Case_Traits + { + inline static T any_from (T v) + { + return v; + } + + inline static T any_to (T & v) + { + return v; + } + }; + + // Specializations for types that require wrapper for Any + // insertion. Note that we only define specializations for types + // that can be used in an IDL union discriminator. + + template <> + struct Case_Traits<CORBA::Boolean> + { + inline static CORBA::Any::from_boolean any_from (CORBA::Boolean v) + { + return CORBA::Any::from_boolean (v); + } + + inline static CORBA::Any::to_boolean any_to (CORBA::Boolean & v) + { + return CORBA::Any::to_boolean (v); + } + }; + + template <> + struct Case_Traits<CORBA::Char> + { + inline static CORBA::Any::from_char any_from (CORBA::Char v) + { + return CORBA::Any::from_char (v); + } + + inline static CORBA::Any::to_char any_to (CORBA::Char & v) + { + return CORBA::Any::to_char (v); + } + }; + + template <> + struct Case_Traits<CORBA::WChar> + { + inline static CORBA::Any::from_wchar any_from (CORBA::WChar v) + { + return CORBA::Any::from_wchar (v); + } + + inline static CORBA::Any::to_wchar any_to (CORBA::WChar & v) + { + return CORBA::Any::to_wchar (v); + } + }; + + } // End TypeCode namespace +} // End TAO namespace + +// ---------------------------------------------------------------- + +template <typename DISCRIMINATOR_TYPE, typename STRING_TYPE> +bool +TAO::TypeCode::Non_Default_Case<DISCRIMINATOR_TYPE, + STRING_TYPE>::marshal_label ( + TAO_OutputCDR & cdr) const +{ + return (cdr << this->label_); +} + +template <typename DISCRIMINATOR_TYPE, typename STRING_TYPE> +bool +TAO::TypeCode::Non_Default_Case<DISCRIMINATOR_TYPE, + STRING_TYPE>::equal_label ( + CORBA::ULong index, + CORBA::TypeCode_ptr tc + ACE_ENV_ARG_DECL) const +{ + CORBA::Any_var const any = tc->member_label (index + ACE_ENV_ARG_PARAMETER); + ACE_CHECK_RETURN (false); + + // The equality operator==() below is guaranteed to be defined for + // the discriminator type since an IDL union discriminator type must + // be any of the following: (1) an integer, (2) a character, (3) a + // boolean, or (4) an enumeration. + + DISCRIMINATOR_TYPE tc_label; + if (any.in () + >>= TAO::TypeCode::Case_Traits<DISCRIMINATOR_TYPE>::any_to (tc_label) + && this->label_ == tc_label) + { + return true; + } + + return false; +} + +template <typename DISCRIMINATOR_TYPE, typename STRING_TYPE> +CORBA::Any * +TAO::TypeCode::Non_Default_Case<DISCRIMINATOR_TYPE, STRING_TYPE>::label ( + ACE_ENV_SINGLE_ARG_DECL) const +{ + CORBA::Any * value; + + ACE_NEW_THROW_EX (value, + CORBA::Any, + CORBA::NO_MEMORY ()); + ACE_CHECK_RETURN (0); + + CORBA::Any_var safe_value (value); + + *value <<= + TAO::TypeCode::Case_Traits<DISCRIMINATOR_TYPE>::any_from (this->label_); + + return safe_value._retn (); +} + + + +#endif /* TAO_TYPECODE_NON_DEFAULT_CASE_CPP */ diff --git a/TAO/tao/TypeCode_Non_Default_Case.h b/TAO/tao/TypeCode_Non_Default_Case.h new file mode 100644 index 00000000000..f37dbaeff86 --- /dev/null +++ b/TAO/tao/TypeCode_Non_Default_Case.h @@ -0,0 +1,136 @@ +// -*- C++ -*- + +//============================================================================= +/** + * @file TypeCode_Non_Default_Case.h + * + * $Id$ + * + * Header file for @c TAO::TypeCode::Non_Default_Case type. + * + * @author Ossama Othman + */ +//============================================================================= + +#ifndef TAO_TYPECODE_NON_DEFAULT_CASE_H +#define TAO_TYPECODE_NON_DEFAULT_CASE_H + +#include /**/ "ace/pre.h" + +#include "ace/config.h" + +#if !defined (ACE_LACKS_PRAGMA_ONCE) +# pragma once +#endif /* ACE_LACKS_PRAGMA_ONCE */ + +#include "tao/TypeCode_Case.h" + + +namespace TAO +{ + namespace TypeCode + { + + /** + * @class Non_Default_Case + * + * @brief Representation of an OMG IDL defined @c union @c case. + * + * A @c Non_Default_Case contains the corresponding case label value, name and + * pointer to the @c CORBA::TypeCode for a given OMG IDL @c union + * @c case. For + * example, the cases in following OMG IDL @c union: + * + * \code + * union Foo switch (short) + * { + * case 0: + * case 1: short a; + * case 2: long b; + * default: octet c; + * }; + * \endcode + * + * would be represented using the following statically instantiated + * @c TAO::TypeCode::Non_Default_Case array: + * + * \code + * typedef TAO::TypeCode::Non_Default_Case<CORBA::Short, + char const *> Foo_Case; + * Foo_Case _tao_cases_Foo[] = + * { + * Foo_Case (0, "a", &CORBA::_tc_short), + * Foo_Case (1, "b", &CORBA::_tc_short), + * Foo_Case (2, "c", &CORBA::_tc_long) + * }; + * \endcode + * + * The @c default case is passed directly to the + * @c TAO::TypeCode::Union constructor. + * + * The template parameter @a DISCRIMINATOR_TYPE is the + * corresponding C++ type for the IDL defined @c union + * discriminator type. For example, a @c union with an IDL @c + * short discriminator will have a corresponding @c CORBA::Short + * C++ type. This template parameter is necessary to allow the + * actual @c case label value to be stored as its actual type, + * which is particularly important when marshaling that value into + * a CDR stream. + * + * The template parameter @a STRING_TYPE is either @c char @c + * const @c * or @c CORBA::String_var. The latter is only used + * when creating @c CORBA::tk_union @c TypeCode dynamically, such + * as through the TypeCodeFactory. + */ + template <typename DISCRIMINATOR_TYPE, typename STRING_TYPE> + class Non_Default_Case : public Case<STRING_TYPE> + { + public: + + /// Constructor. + Non_Default_Case (DISCRIMINATOR_TYPE member_label, + char const * member_name, + CORBA::TypeCode_ptr const * member_type); + + /** + * @name @c TAO::TypeCode::Case Methods + * + * Methods required by the @c TAO::TypeCode::Case abstract base + * class. + * + * @see @c TAO::TypeCode::Case + */ + //@{ + virtual CORBA::Any * label (ACE_ENV_SINGLE_ARG_DECL) const; + virtual bool marshal_label (TAO_OutputCDR & cdr) const; + virtual bool equal_label (CORBA::ULong index, + CORBA::TypeCode_ptr tc + ACE_ENV_ARG_DECL) const; + //@} + + private: + + /// IDL @c union case/member label value. + DISCRIMINATOR_TYPE const label_; + + }; + + } // End namespace TypeCode +} // End namespace TAO + + +#ifdef __ACE_INLINE__ +# include "tao/TypeCode_Non_Default_Case.inl" +#endif /* __ACE_INLINE__ */ + +#ifdef ACE_TEMPLATES_REQUIRE_SOURCE +# include "tao/TypeCode_Non_Default_Case.cpp" +#endif /* ACE_TEMPLATES_REQUIRE_SOURCE */ + +#ifdef ACE_TEMPLATES_REQUIRE_PRAGMA +# pragma implementation ("TypeCode_Non_Default_Case.cpp") +#endif /* ACE_TEMPLATES_REQUIRE_PRAGMA */ + +#include /**/ "ace/post.h" + +#endif /* TAO_TYPECODE_NON_DEFAULT_CASE_H */ diff --git a/TAO/tao/TypeCode_Non_Default_Case.inl b/TAO/tao/TypeCode_Non_Default_Case.inl new file mode 100644 index 00000000000..5f47d0fddcc --- /dev/null +++ b/TAO/tao/TypeCode_Non_Default_Case.inl @@ -0,0 +1,14 @@ +// -*- C++ -*- +// +// $Id$ + +template <typename DISCRIMINATOR_TYPE, typename STRING_TYPE> +TAO::TypeCode::Non_Default_Case<DISCRIMINATOR_TYPE, + STRING_TYPE>::Non_Default_Case ( + DISCRIMINATOR_TYPE member_label, + char const * member_name, + CORBA::TypeCode_ptr const * member_type) + : Case<STRING_TYPE> (member_name, member_type) + , label_ (member_label) +{ +} diff --git a/TAO/tao/TypeCode_Struct_Field.cpp b/TAO/tao/TypeCode_Struct_Field.cpp new file mode 100644 index 00000000000..009ab6d1c4d --- /dev/null +++ b/TAO/tao/TypeCode_Struct_Field.cpp @@ -0,0 +1,20 @@ +// $Id$ + +#ifndef TAO_TYPECODE_STRUCT_FIELD_CPP +#define TAO_TYPECODE_STRUCT_FIELD_CPP + +#include "TypeCode_Struct_Field.h" + +#ifndef __ACE_INLINE__ +# include "tao/TypeCode_Struct_Field.inl" +#endif /* __ACE_INLINE__ */ + + +template <typename STRING_TYPE> +TAO::TypeCode::Struct_Field<STRING_TYPE>::~Struct_Field (void) +{ + if (this->type) + CORBA::release (*type); +} + +#endif /* TAO_TYPECODE_STRUCT_FIELD_CPP */ diff --git a/TAO/tao/TypeCode_Struct_Field.h b/TAO/tao/TypeCode_Struct_Field.h new file mode 100644 index 00000000000..2e6a5e157e7 --- /dev/null +++ b/TAO/tao/TypeCode_Struct_Field.h @@ -0,0 +1,129 @@ +// -*- C++ -*- + +//============================================================================= +/** + * @file TypeCode_Struct_Field.h + * + * $Id$ + * + * Header file for @c TAO::TypeCode::Struct_Field type. + * + * @author Ossama Othman <ossama@dre.vanderbilt.edu> + * @author Carlos O'Ryan + */ +//============================================================================= + +#ifndef TAO_TYPECODE_STRUCT_FIELD_H +#define TAO_TYPECODE_STRUCT_FIELD_H + +#include /**/ "ace/pre.h" + +#include "ace/config.h" + +#if !defined (ACE_LACKS_PRAGMA_ONCE) +# pragma once +#endif /* ACE_LACKS_PRAGMA_ONCE */ + + +namespace CORBA +{ + class TypeCode; + typedef TypeCode* TypeCode_ptr; +} + +namespace TAO +{ + namespace TypeCode + { + /** + * @struct Struct_Field + * + * @brief Name/type pair for fields of an OMG IDL defined + * structure or exception. + * + * A @c Struct_Field contains the corresponding name and pointer + * to the @c CORBA::TypeCode for a given OMG IDL defined type. + * For example, the fields in following OMG IDL structure: + * + * \code + * struct Foo + * { + * long the_number; + * string the_string; + * }; + * \endcode + * + * would be represented using the following statically instantiated + * @c TAO::TypeCode::Struct_Field array: + * + * \code + * TAO::TypeCode::Struct_Field<char const *> _tao_fields_Foo[] = + * { + * { "the_number", &CORBA::_tc_long }, + * { "the_string", &CORBA::_tc_string }, + * }; + * \endcode + * + * The template parameter @a STRING_TYPE is either @c char + * @c const @c * or @c CORBA::String_var. The latter is only used + * when creating @c CORBA::tk_struct or @c CORBA::tk_except + * @c TypeCodes dynamically, such as through the TypeCodeFactory. + */ + template <typename STRING_TYPE> + struct Struct_Field + { + /// Destructor. + ~Struct_Field (void); + + /// Return the name of the @c Struct_Field. + /** + * @note This method unfortunately exists so that we can + * retrieve the underlying string when the @a STRING_TYPE + * is @c CORBA::String_var rather than the + * @c CORBA::String_var itself. This is necessary to + * silence a warning about better conversion sequences + * exhibited by some C++ compilers. + */ + char const * get_name (void) const; + + /// The name of the field. + STRING_TYPE name; + + /// Pointer to the @c CORBA::TypeCode of the field. + /** + * A pointer to the @c CORBA::TypeCode_ptr rather than the + * @c CORBA::TypeCode_ptr itself is stored since that address is + * well-defined. We may not know the value of the @c + * CORBA::TypeCode_ptr when creating this @c Struct_Field + * statically at compile-time, hence the indirection. + * + * @note This @c TypeCode is released upon destruction of this + * @c Struct_Field. + */ + CORBA::TypeCode_ptr const * type; + + }; + + } // End namespace TypeCode +} // End namespace TAO + +// If we didn't have to worry about better conversion sequence +// warnings, and drop the Struct_Field<>::get_name() method, we could +// drop the below #include directives and remove the files contained +// within them altogether. + +#ifdef __ACE_INLINE__ +# include "tao/TypeCode_Struct_Field.inl" +#endif /* __ACE_INLINE__ */ + +#ifdef ACE_TEMPLATES_REQUIRE_SOURCE +# include "tao/TypeCode_Struct_Field.cpp" +#endif /* ACE_TEMPLATES_REQUIRE_SOURCE */ + +#ifdef ACE_TEMPLATES_REQUIRE_PRAGMA +# pragma implementation ("TypeCode_Struct_Field.cpp") +#endif /* ACE_TEMPLATES_REQUIRE_PRAGMA */ + +#include /**/ "ace/post.h" + +#endif /* TAO_TYPECODE_STRUCT_FIELD_H */ diff --git a/TAO/tao/TypeCode_Struct_Field.inl b/TAO/tao/TypeCode_Struct_Field.inl new file mode 100644 index 00000000000..70e5bafdef6 --- /dev/null +++ b/TAO/tao/TypeCode_Struct_Field.inl @@ -0,0 +1,23 @@ +// -*- C++ -*- +// +// $Id$ + +template <typename STRING_TYPE> +ACE_INLINE char const * +TAO::TypeCode::Struct_Field<STRING_TYPE>::get_name (void) const +{ + return this->name; +} + +// ----------------------------------------------------------------- +// Some compilers exhibit warnings about better conversion sequence +// from a CORBA::String_var to a char const *. This member +// specialization works around them by performing explicit +// conversions. +// ----------------------------------------------------------------- + +ACE_INLINE char const * +TAO::TypeCode::Struct_Field<CORBA::String_var>::get_name (void) const +{ + return this->name.in (); +} diff --git a/TAO/tao/TypeCode_Value_Field.cpp b/TAO/tao/TypeCode_Value_Field.cpp new file mode 100644 index 00000000000..df8eb7720a7 --- /dev/null +++ b/TAO/tao/TypeCode_Value_Field.cpp @@ -0,0 +1,20 @@ +// $Id$ + +#ifndef TAO_TYPECODE_VALUE_FIELD_CPP +#define TAO_TYPECODE_VALUE_FIELD_CPP + +#include "TypeCode_Value_Field.h" + +#ifndef __ACE_INLINE__ +# include "tao/TypeCode_Value_Field.inl" +#endif /* __ACE_INLINE__ */ + + +template <typename STRING_TYPE> +TAO::TypeCode::Value_Field<STRING_TYPE>::~Value_Field (void) +{ + if (this->type) + CORBA::release (*type); +} + +#endif /* TAO_TYPECODE_VALUE_FIELD_CPP */ diff --git a/TAO/tao/TypeCode_Value_Field.h b/TAO/tao/TypeCode_Value_Field.h new file mode 100644 index 00000000000..74019af73c9 --- /dev/null +++ b/TAO/tao/TypeCode_Value_Field.h @@ -0,0 +1,131 @@ +// -*- C++ -*- + +//============================================================================= +/** + * @file TypeCode_Value_Field.h + * + * $Id$ + * + * Header file for @c TAO::TypeCode::Value_Field type. + * + * @author Ossama Othman <ossama@dre.vanderbilt.edu> + */ +//============================================================================= + +#ifndef TAO_TYPECODE_VALUE_FIELD_H +#define TAO_TYPECODE_VALUE_FIELD_H + +#include /**/ "ace/pre.h" + +#include "ace/config.h" + +#if !defined (ACE_LACKS_PRAGMA_ONCE) +# pragma once +#endif /* ACE_LACKS_PRAGMA_ONCE */ + + +namespace CORBA +{ + class TypeCode; + typedef TypeCode* TypeCode_ptr; +} + +namespace TAO +{ + namespace TypeCode + { + /** + * @struct Value_Field + * + * @brief Name/type/visibility tuple fields of an OMG IDL defined + * @c valuetype or @c eventtype. + * + * A @c Value_Field contains the corresponding name and pointer to the + * @c CORBA::TypeCode for a given OMG IDL defined type. For + * example, the fields in following OMG IDL structure: + * + * \code + * struct Foo + * { + * long the_number; + * string the_string; + * }; + * \endcode + * + * would be represented using the following statically instantiated + * @c TAO::TypeCode::Value_Field array: + * + * \code + * TAO::TypeCode::Value_Field<char const *> _tao_fields_Foo[] = + * { + * { "the_number", &CORBA::_tc_long }, + * { "the_string", &CORBA::_tc_string }, + * }; + * \endcode + * + * The template parameter @a STRING_TYPE is either @c char + * @c const @c * or @c CORBA::String_var. The latter is only used + * when creating @c CORBA::tk_value or @c CORBA::tk_event + * @c TypeCodes dynamically, such as through the TypeCodeFactory. + */ + template <typename STRING_TYPE> + struct Value_Field + { + /// Destructor. + ~Value_Field (void); + + /// Return the name of the @c Value_Field. + /** + * @note This method unfortunately exists so that we can + * retrieve the underlying string when the @a STRING_TYPE + * is @c CORBA::String_var rather than the + * @c CORBA::String_var itself. This is necessary to + * silence a warning about better conversion sequences + * exhibited by some C++ compilers. + */ + char const * get_name (void) const; + + /// The name of the field. + STRING_TYPE name; + + /// Pointer to the @c CORBA::TypeCode of the field. + /** + * A pointer to the @c CORBA::TypeCode_ptr rather than the + * @c CORBA::TypeCode_ptr itself is stored since that address is + * well-defined. We may not know the value of the + * @c CORBA::TypeCode_ptr when creating this @c Value_Field + * statically at compile-time, hence the indirection. + * + * @note This @c TypeCode is released upon destruction of this + * @c Value_Field. + */ + CORBA::TypeCode_ptr * type; + + /// The visibility of the field. + CORBA::Visibility visibility; + + }; + + } // End namespace TypeCode +} // End namespace TAO + +// If we didn't have to worry about better conversion sequence +// warnings, and drop the Value_Field<>::get_name() method, we could +// drop the below #include directives and remove the files contained +// within them altogether. + +#ifdef __ACE_INLINE__ +# include "tao/TypeCode_Value_Field.inl" +#endif /* __ACE_INLINE__ */ + +#ifdef ACE_TEMPLATES_REQUIRE_SOURCE +# include "tao/TypeCode_Value_Field.cpp" +#endif /* ACE_TEMPLATES_REQUIRE_SOURCE */ + +#ifdef ACE_TEMPLATES_REQUIRE_PRAGMA +# pragma implementation ("TypeCode_Value_Field.cpp") +#endif /* ACE_TEMPLATES_REQUIRE_PRAGMA */ + +#include /**/ "ace/post.h" + +#endif /* TAO_TYPECODE_VALUE_FIELD_H */ diff --git a/TAO/tao/TypeCode_Value_Field.inl b/TAO/tao/TypeCode_Value_Field.inl new file mode 100644 index 00000000000..852273c2d83 --- /dev/null +++ b/TAO/tao/TypeCode_Value_Field.inl @@ -0,0 +1,23 @@ +// -*- C++ -*- +// +// $Id$ + +template <typename STRING_TYPE> +ACE_INLINE char const * +TAO::TypeCode::Value_Field<STRING_TYPE>::get_name (void) const +{ + return this->name; +} + +// ----------------------------------------------------------------- +// Some compilers exhibit warnings about better conversion sequence +// from a CORBA::String_var to a char const *. This member +// specialization works around them by performing explicit +// conversions. +// ----------------------------------------------------------------- + +ACE_INLINE char const * +TAO::TypeCode::Value_Field<CORBA::String_var>::get_name (void) const +{ + return this->name.in (); +} diff --git a/TAO/tao/Typecode.cpp b/TAO/tao/Typecode.cpp deleted file mode 100644 index 86bd9cc8dae..00000000000 --- a/TAO/tao/Typecode.cpp +++ /dev/null @@ -1,3932 +0,0 @@ -// $Id$ - -// Typecodes essentially consist of just the CDR octets that get -// marshaled and unmarshaled, and this code knows how to parse those -// octets and answer questions CORBA's TypeCode APIs require. -// -// NOTE: This isn't well tuned performance-wise. Given how much is -// variable (byte order, alignment) it's clear tuning has its limits -// with respect to CDR bytecode interpretation. -// -// THREADING NOTE: Typecodes are readonly data structures, and the -// only mutual exclusion relates to reference counting and -// construction. - -#include "Typecode.h" -#include "Any.h" -#include "Marshal.h" -#include "CORBA_String.h" -#include "CDR.h" -#include "debug.h" -#include "Any_Unknown_IDL_Type.h" -#include "ORB_Constants.h" -#include "SystemException.h" -#include "orb_typesC.h" -#include "ValueModifierC.h" - -#if defined (ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION) \ - || defined (ACE_HAS_TEMPLATE_INSTANTIATION_PRAGMA) -# include "tao/Sequence_T.h" -#endif /* ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION */ - -#include "ace/Guard_T.h" -#include "ace/Malloc_Base.h" -#include "ace/Null_Mutex.h" -#include "ace/OS_NS_string.h" - -#if !defined (__ACE_INLINE__) -# include "tao/Typecode.i" -#endif /* ! __ACE_INLINE__ */ - - -ACE_RCSID (tao, - Typecode, - "$Id$") - -// Typecodes essentially consist of just the CDR octets that get -// marshaled and unmarshaled, and this code knows how to parse those -// octets and answer questions CORBA's TypeCode APIs require. - -CORBA::TypeCode::Bounds::Bounds (void) - : CORBA::UserException ("IDL:omg.org/CORBA/TypeCode/Bounds:1.0", - "Bounds") -{ -} - -CORBA::TypeCode::Bounds* -CORBA::TypeCode::Bounds::_downcast (CORBA::Exception *ex) -{ - return dynamic_cast <CORBA::TypeCode::Bounds*> (ex); -} - -CORBA::Exception * -CORBA::TypeCode::Bounds::_alloc (void) -{ - CORBA::Exception *retval = 0; - ACE_NEW_RETURN (retval, ::CORBA::TypeCode::Bounds, 0); - return retval; -} - -CORBA::Exception * -CORBA::TypeCode::Bounds::_tao_duplicate (void) const -{ - CORBA::Exception *result; - ACE_NEW_RETURN (result, - CORBA::TypeCode::Bounds (*this), - 0); - return result; -} - -void -CORBA::TypeCode::Bounds::_raise (void) const -{ - TAO_RAISE(*this); -} - -void -CORBA::TypeCode::Bounds::_tao_encode (TAO_OutputCDR &cdr - ACE_ENV_ARG_DECL) const -{ - if (cdr << this->_rep_id ()) - { - return; - } - - ACE_THROW (CORBA::MARSHAL ()); -} - -void -CORBA::TypeCode::Bounds::_tao_decode (TAO_InputCDR & - ACE_ENV_ARG_DECL_NOT_USED) -{ -} - -// **************************************************************** - -CORBA::TypeCode::BadKind::BadKind (void) - : CORBA::UserException ("IDL:omg.org/CORBA/TypeCode/BadKind:1.0", - "BadKind") -{ -} - -CORBA::TypeCode::BadKind* -CORBA::TypeCode::BadKind::_downcast (CORBA::Exception *ex) -{ - return dynamic_cast <CORBA::TypeCode::BadKind*> (ex); -} - -CORBA::Exception * -CORBA::TypeCode::BadKind::_tao_duplicate (void) const -{ - CORBA::Exception *result; - ACE_NEW_RETURN (result, - CORBA::TypeCode::BadKind (*this), - 0); - return result; -} - -void -CORBA::TypeCode::BadKind::_raise (void) const -{ - TAO_RAISE(*this); -} - -void -CORBA::TypeCode::BadKind::_tao_encode (TAO_OutputCDR &cdr - ACE_ENV_ARG_DECL) const -{ - if (cdr << this->_rep_id ()) - { - return; - } - - ACE_THROW (CORBA::MARSHAL ()); -} - -void -CORBA::TypeCode::BadKind::_tao_decode (TAO_InputCDR & - ACE_ENV_ARG_DECL_NOT_USED) -{ -} - -// **************************************************************** - -// Constructor for CONSTANT typecodes with empty parameter lists. -// These are only created once, and those constants are shared. - -CORBA::TypeCode::TypeCode (CORBA::TCKind kind) - : length_ (0), - buffer_ (0), - byte_order_ (ACE_CDR_BYTE_ORDER), - kind_ (kind), - parent_ (0), - tc_base_ (0), - root_tc_base_ (0), - refcount_ (1), - orb_owns_ (1), - private_state_ (new TAO::TC_Private_State (kind)), - non_aligned_buffer_ (0), - offset_map_ (0) -{ -} - -CORBA::TypeCode::TypeCode (CORBA::TCKind kind, - size_t length, - const char *buffer, - CORBA::Boolean orb_owns_tc, - CORBA::ULong /* size */, - CORBA::TypeCode_ptr parent) - : length_ (length), - kind_ (kind), - parent_ (parent), - refcount_ (1), - orb_owns_ (orb_owns_tc), - private_state_ (new TAO::TC_Private_State (kind)), - non_aligned_buffer_ (0), - offset_map_ (0) -{ - // The CDR code used to interpret TypeCodes requires in-memory - // alignments to match the "on-the-wire" alignments, simplifying - // algorithms used to marshal/unmarshal. - // - // However, it's often hard to get compilers (in particular) to - // generate data that's so aligned, since C++ doesn't provide - // primitives giving control at that low a level. Although there - // are ways to get that alignment which work in almost all cases, we - // need to ensure adequate alignment in _all_ cases. - // - // This code exists to ensure such alignment; since the constructor - // is intended only for use by an IDL compiler or ORB code, it's not - // currently a priority to ensure the allocated code is freed. - - // TAO comments: - - // For free standing typecodes, we choose to always make a copy of - // the buffer passed in. That way, our destructor doesn't have to - // deal with the case where the buffer was either allocated in which - // case it must be freed or the case where our buffer just points to - // the buffer passed in. - - if (this->parent_ == 0) - { - // Allocate a buffer to hold the encapsulated stream. We - // allocate extra space since we need a buffer that is aligned - // on a 4 byte word boundary. As a result, it is quite possible - // that we may start accessing the buffer from a position - // shifted to the right in the allocated buffer. As a result, - // during destruction, we do not want part of the allocated heap - // to remain dangling. Hence we save a handle to the original - // allocated buffer. - - // *NOTE* that the buffer parameter is simply our encapsulation. It - // does not contain our TypeCode::kind () and the length. These are - // passed as separate parameters. However, in case of indirected - // offset value for the indirection will effectively point to the - // typecodes, the tk_kind field in our CDR representation. Hence, - // we introduce a new field called tc_base_ which represents the - // start of our CDR representation. The buffer_ data member will - // point to our encapsulation. - - // @@ The typecode buffer contain the encapsulation byte order - // in the first byte... - const CORBA::Octet *ptr = - reinterpret_cast <const CORBA::Octet *> (buffer); - this->byte_order_ = *ptr; - - // allocate a buffer which will accomodate our entire encapsulation - // plus 4 bytes for our tk_kind value and 4 bytes for our encapsulation - // length. The extra MAX_ALIGNMENT bytes are necessary to ensure - // that we will get a properly aligned buffer. - - static const size_t lsize = sizeof (CORBA::ULong); - ACE_NEW (this->non_aligned_buffer_, - char [this->length_ + lsize + lsize + ACE_CDR::MAX_ALIGNMENT]); - - char* start = ACE_ptr_align_binary (this->non_aligned_buffer_, - ACE_CDR::MAX_ALIGNMENT); - - // length_ is of size_t which, on 64-bit platforms, is 64 bits. - // The value to be copied is expected to be 32-bit. We will cast - // the value down to a CORBA::ULong and copy that. - CORBA::ULong length = static_cast <CORBA::ULong> (this->length_); - - (void) ACE_OS::memcpy (start, &this->kind_, lsize); - (void) ACE_OS::memcpy (start + lsize, &length, lsize); - (void) ACE_OS::memcpy (start + lsize + lsize, buffer, this->length_); - // we are the topmost level typecode and hence our typecode base is - // the start whereas the buffer_ which represents the encapsulation - // is 8 bytes ahead of the typecode base - this->tc_base_ = start; - // since we do not have any parents, we are the root - this->root_tc_base_ = start; - this->buffer_ = start + lsize + lsize; - } - else - { - // We are a child. We do not allocate a new buffer, but share it - // with our parent. We know that our parent's buffer was - // properly aligned. - const CORBA::Octet *ptr = - reinterpret_cast <const CORBA::Octet *> (buffer); - this->byte_order_ = *ptr; - - this->buffer_ = buffer; - // our typecode base is 8 bytes prior to our encapsulation and our - // root base is the same as that of our parent's - this->tc_base_ = this->buffer_ - 8; - this->root_tc_base_ = parent->root_tc_base_; - } -} - -// Destructor. For "indirected" typecodes and children, the typecode -// reuses the buffer owned by its parent. - -CORBA::TypeCode::~TypeCode (void) -{ - // Delete the original, possibly nonaligned, buffer. - delete [] this->non_aligned_buffer_; - this->non_aligned_buffer_ = 0; - - this->buffer_ = 0; - - // Free up our private state. - delete this->private_state_; - this->private_state_ = 0; - - if (this->offset_map_ != 0) - { - OFFSET_MAP_ENTRY *entry = 0; - - for (CORBA::TypeCode::OFFSET_MAP_ITERATOR iter (*this->offset_map_); - iter.next (entry) != 0; - iter.advance ()) - { - CORBA::string_free ((char*)entry->ext_id_); - delete entry->int_id_; - } - } - - delete this->offset_map_; - this->offset_map_ = 0; -} - - -// Return the i-th member typecode if it exists, else raise an -// exception. Possible exceptions are BadKind and Bounds. -// -// Applicable only to struct, union, and except - -CORBA::TypeCode_ptr -CORBA::TypeCode::member_type (CORBA::ULong slot - ACE_ENV_ARG_DECL) const -{ - if (this->private_state_->tc_member_count_known_ - && this->private_state_->tc_member_type_list_known_) - { - if (slot < this->private_state_->tc_member_count_) - { - return - CORBA::TypeCode::_duplicate ( - this->private_state_->tc_member_type_list_[slot]); - } - else - { - ACE_THROW_RETURN (CORBA::TypeCode::Bounds (), - CORBA::TypeCode::_nil ()); - } - } - else - { - return - CORBA::TypeCode::_duplicate ( - this->private_member_type (slot - ACE_ENV_ARG_PARAMETER)); - } -} - -// Applicable only to struct, union, and except - -const char * -CORBA::TypeCode::member_name (CORBA::ULong slot - ACE_ENV_ARG_DECL) const -{ - if (this->private_state_->tc_member_count_known_ - && this->private_state_->tc_member_name_list_known_) - { - if (slot < this->private_state_->tc_member_count_) - { - return this->private_state_->tc_member_name_list_[slot]; - } - else - { - ACE_THROW_RETURN (CORBA::TypeCode::Bounds (), - 0); - } - } - else - { - return this->private_member_name (slot - ACE_ENV_ARG_PARAMETER); - } -} - -// Return the label of the i-th member. Applicable only to CORBA::tk_union -CORBA::Any_ptr -CORBA::TypeCode::member_label (CORBA::ULong slot - ACE_ENV_ARG_DECL) const -{ - CORBA::Any_ptr retval = 0; - - if (this->private_state_->tc_member_count_known_ - && this->private_state_->tc_member_label_list_known_) - { - if (slot < this->private_state_->tc_member_count_) - { - ACE_NEW_RETURN ( - retval, - CORBA::Any (*this->private_state_->tc_member_label_list_[slot]), - 0 - ); - } - else - { - ACE_THROW_RETURN (CORBA::TypeCode::Bounds (), - 0); - } - } - else - { - CORBA::Any_ptr label = - this->private_member_label (slot - ACE_ENV_ARG_PARAMETER); - ACE_CHECK_RETURN (0); - - ACE_NEW_RETURN (retval, - CORBA::Any (*label), - 0); - } - - return retval; -} - -// only applicable to CORBA::tk_unions -CORBA::TypeCode_ptr -CORBA::TypeCode::discriminator_type (ACE_ENV_SINGLE_ARG_DECL) const -{ - if (this->kind_ != CORBA::tk_union) - ACE_THROW_RETURN (CORBA::TypeCode::BadKind (), - CORBA::TypeCode::_nil ()); - - if (this->private_state_->tc_discriminator_type_known_) - return - CORBA::TypeCode::_duplicate ( - this->private_state_->tc_discriminator_type_); - - CORBA::TypeCode_ptr type = - this->private_discriminator_type (ACE_ENV_SINGLE_ARG_PARAMETER); - ACE_CHECK_RETURN (CORBA::TypeCode::_nil ()); - - return CORBA::TypeCode::_duplicate (type); -} - -// only applicable to CORBA::tk_unions -CORBA::Long -CORBA::TypeCode::default_index (ACE_ENV_SINGLE_ARG_DECL) const -{ - if (this->kind_ != CORBA::tk_union) - ACE_THROW_RETURN (CORBA::TypeCode::BadKind (), 0); - - if (this->private_state_->tc_default_index_used_known_) - return this->private_state_->tc_default_index_used_; - else - return this->private_default_index (ACE_ENV_SINGLE_ARG_PARAMETER); -} - -// returns the length. Applicable only to string, sequence, and arrays -CORBA::ULong -CORBA::TypeCode::length (ACE_ENV_SINGLE_ARG_DECL) const -{ - // a switch stmt, unfortunately, doesn't get inlined - if (this->kind_ == CORBA::tk_sequence - || this->kind_ == CORBA::tk_array - || this->kind_ == CORBA::tk_string - || this->kind_ == CORBA::tk_wstring) - { - if (this->private_state_->tc_length_known_) - return this->private_state_->tc_length_; - else - return this->private_length (ACE_ENV_SINGLE_ARG_PARAMETER); - } - else - ACE_THROW_RETURN (CORBA::TypeCode::BadKind (), 0); -} - -// returns the typecode. Applicable only to string, sequence, and arrays -CORBA::TypeCode_ptr -CORBA::TypeCode::content_type (ACE_ENV_SINGLE_ARG_DECL) const -{ - if (this->kind_ == CORBA::tk_sequence - || this->kind_ == CORBA::tk_array - || this->kind_ == CORBA::tk_alias) - { - if (this->private_state_->tc_content_type_known_) - return CORBA::TypeCode::_duplicate ( - this->private_state_->tc_content_type_ - ); - else - { - CORBA::TypeCode_ptr tmp = - this->private_content_type (ACE_ENV_SINGLE_ARG_PARAMETER); - ACE_CHECK_RETURN (CORBA::TypeCode::_nil ()); - - return CORBA::TypeCode::_duplicate (tmp); - } - } - else - { - ACE_THROW_RETURN (CORBA::TypeCode::BadKind (), - 0); - } - -} - -CORBA::UShort -CORBA::TypeCode::fixed_digits (ACE_ENV_SINGLE_ARG_DECL) const -{ - ACE_THROW_RETURN (CORBA::NO_IMPLEMENT (), 0); -} - -CORBA::Short -CORBA::TypeCode::fixed_scale (ACE_ENV_SINGLE_ARG_DECL) const -{ - ACE_THROW_RETURN (CORBA::NO_IMPLEMENT (), 0); -} - -CORBA::Visibility -CORBA::TypeCode::member_visibility (CORBA::ULong slot - ACE_ENV_ARG_DECL) const -{ - if (this->private_state_->tc_member_count_known_ - && this->private_state_->tc_member_visibility_list_known_) - { - if (slot < this->private_state_->tc_member_count_) - { - return this->private_state_->tc_member_visibility_list_[slot]; - } - else - { - ACE_THROW_RETURN (CORBA::TypeCode::Bounds (), - 0); - } - } - else - { - CORBA::Visibility v = - this->private_member_visibility (slot - ACE_ENV_ARG_PARAMETER); - ACE_CHECK_RETURN (CORBA::PRIVATE_MEMBER); - - return v; - } -} - -CORBA::ValueModifier -CORBA::TypeCode::type_modifier (ACE_ENV_SINGLE_ARG_DECL) const -{ - if (this->private_state_->tc_type_modifier_known_) - { - return this->private_state_->tc_type_modifier_; - } - else - { - CORBA::ValueModifier vm = - this->private_type_modifier (ACE_ENV_SINGLE_ARG_PARAMETER); - ACE_CHECK_RETURN (CORBA::VM_NONE); - - return vm; - } -} - -CORBA::TypeCode_ptr -CORBA::TypeCode::concrete_base_type (ACE_ENV_SINGLE_ARG_DECL) const -{ - if (this->private_state_->tc_concrete_base_type_known_) - { - return CORBA::TypeCode::_duplicate ( - this->private_state_->tc_concrete_base_type_ - ); - } - else - { - CORBA::TypeCode_ptr tmp = - this->private_concrete_base_type (ACE_ENV_SINGLE_ARG_PARAMETER); - ACE_CHECK_RETURN (CORBA::TypeCode::_nil ()); - - return CORBA::TypeCode::_duplicate (tmp); - } -} - -// skip a typecode encoding in a given CDR stream -// This is just a helper function -CORBA::Boolean -CORBA::TypeCode::skip_typecode (TAO_InputCDR &stream) -{ - CORBA::ULong kind; - CORBA::ULong temp; - - if (stream.read_ulong (kind) - && (kind < CORBA::TC_KIND_COUNT || kind == ~0u)) - { - - switch (kind) - { - // Most TypeCodes have empty parameter lists, nothing to skip - default: - break; - - // Some have single integer parameters, easy to skip. Some have - // preallocated constants that could be used. - case CORBA::tk_string: - case CORBA::tk_wstring: - case ~0u: - return (stream.read_ulong (temp) != 0); - - // The rest have "complex" parameter lists that are - // encoded as bulk octets ... just skip them. - case CORBA::tk_objref: - case CORBA::tk_struct: - case CORBA::tk_union: - case CORBA::tk_enum: - case CORBA::tk_sequence: - case CORBA::tk_array: - case CORBA::tk_alias: - case CORBA::tk_except: - case CORBA::tk_value: - return (stream.read_ulong (temp) != 0 - && stream.skip_bytes (temp) != 0); - } - - return 1; - } - else - return 0; -} - -// constructor for the private state -TAO::TC_Private_State::TC_Private_State (CORBA::TCKind kind) - : tc_kind_ (kind), - tc_id_known_ (0), - tc_name_known_ (0), - tc_member_count_known_ (0), - tc_member_type_list_known_ (0), - tc_member_name_list_known_ (0), - tc_member_label_list_known_ (0), - tc_discriminator_type_known_ (0), - tc_default_index_used_known_ (0), - tc_length_known_ (0), - tc_content_type_known_ (0), - tc_discrim_pad_size_known_ (0), - tc_member_visibility_list_known_ (0), - tc_type_modifier_known_ (0), - tc_concrete_base_type_known_ (0), - tc_id_ (0), - tc_name_ (0), - tc_member_count_ (0), - tc_member_type_list_ (0), - tc_member_name_list_ (0), - tc_member_label_list_ (0), - tc_discriminator_type_ (0), - tc_default_index_used_ (0), - tc_length_ (0), - tc_content_type_ (0), - tc_member_visibility_list_ (0), - tc_type_modifier_ (0), - tc_concrete_base_type_ (0) -{ -} - -// Destructor for the private state. In effect, this cleans up all the -// children and the subtree we hold. -TAO::TC_Private_State::~TC_Private_State (void) -{ - // The following just point into the buffer. So we just make it - // point to 0. - this->tc_id_ = 0; - - if (this->tc_name_ != 0) - { - CORBA::string_free (this->tc_name_); - this->tc_name_ = 0; - } - - // Determine what kind of children we may have and free the space - // accordingly. - switch (this->tc_kind_) - { - case CORBA::tk_enum: - - // free up the member name list - if (this->tc_member_name_list_known_) - { - for (CORBA::ULong i = 0; i < this->tc_member_count_; ++i) - { - CORBA::string_free (this->tc_member_name_list_ [i]); - this->tc_member_name_list_ [i] = 0; - } - - delete [] this->tc_member_name_list_; - this->tc_member_name_list_ = 0; - } - - break; - - case CORBA::tk_struct: - case CORBA::tk_except: - - // Free up the member name list - if (this->tc_member_name_list_known_) - { - for (CORBA::ULong i = 0; i < this->tc_member_count_; ++i) - { - CORBA::string_free (this->tc_member_name_list_ [i]); - this->tc_member_name_list_ [i] = 0; - } - - delete [] this->tc_member_name_list_; - this->tc_member_name_list_ = 0; - } - - // Free up member type list - if (this->tc_member_type_list_known_) - { - for (CORBA::ULong i = 0; i < this->tc_member_count_; ++i) - { - CORBA::release (this->tc_member_type_list_[i]); - } - - // Now free up the array. - delete [] this->tc_member_type_list_; - this->tc_member_type_list_ = 0; - } - - this->tc_member_count_ = 0; - - break; - - case CORBA::tk_sequence: - case CORBA::tk_array: - case CORBA::tk_alias: - // Delete the content type only if it has a parent i.e., if it - // is not acquired from the pool of constant or predefined - // TypeCodes. - if (this->tc_content_type_known_ && this->tc_content_type_ != 0) - { - CORBA::release (this->tc_content_type_); - this->tc_content_type_ = 0; - } - - break; - - case CORBA::tk_union: - { - // Free up the member name list. - if (this->tc_member_name_list_known_) - { - for (CORBA::ULong i = 0; i < this->tc_member_count_; ++i) - { - CORBA::string_free (this->tc_member_name_list_ [i]); - this->tc_member_name_list_ [i] = 0; - } - - delete [] this->tc_member_name_list_; - } - - // Free up type list, label list, and finally the - // discriminator. - if (this->tc_member_type_list_known_) - { - for (CORBA::ULong i = 0; i < this->tc_member_count_; ++i) - { - CORBA::release (this->tc_member_type_list_[i]); - } - - // Now free up the array. - delete [] this->tc_member_type_list_; - this->tc_member_type_list_ = 0; - } - - if (this->tc_member_label_list_known_) - { - for (CORBA::ULong i = 0; i < this->tc_member_count_; ++i) - // Free up the label (Any_ptr). - delete this->tc_member_label_list_[i]; - - delete [] this->tc_member_label_list_; - this->tc_member_label_list_ = 0; - } - - this->tc_member_count_ = 0; - - // Discriminator must come last b/c it will be inside the Any - // in each element of the label list. - CORBA::release (this->tc_discriminator_type_); - this->tc_discriminator_type_ = 0; - } - - break; - - case CORBA::tk_value: - // Free up the member name list. - if (this->tc_member_name_list_known_) - { - for (CORBA::ULong i = 0; i < this->tc_member_count_; ++i) - { - CORBA::string_free (this->tc_member_name_list_ [i]); - this->tc_member_name_list_ [i] = 0; - } - - delete [] this->tc_member_name_list_; - this->tc_member_name_list_ = 0; - } - - // Free up member type list. - if (this->tc_member_type_list_known_) - { - for (CORBA::ULong i = 0; i < this->tc_member_count_; ++i) - { - CORBA::release (this->tc_member_type_list_[i]); - } - - // Now free up the array. - delete [] this->tc_member_type_list_; - this->tc_member_type_list_ = 0; - } - - this->tc_member_count_ = 0; - - // Free up the member visibility list. - if (this->tc_member_visibility_list_known_) - { - delete [] this->tc_member_visibility_list_; - this->tc_member_visibility_list_ = 0; - } - - // Free up concrete base value typecode. - if (this->tc_concrete_base_type_known_) - { - CORBA::release (this->tc_concrete_base_type_); - this->tc_concrete_base_type_ = 0; - } - - break; - - default: - break; - } -} - -// Point of recursion for equal() and equivalent(). -CORBA::Boolean -CORBA::TypeCode::equ_common (CORBA::TypeCode_ptr tc, - CORBA::Boolean equiv_only - ACE_ENV_ARG_DECL) const -{ - // This will catch applications that haven't initialized an ORB. - if (CORBA::is_nil (tc)) - { - return 0; - } - - // Are the two pointers the same? - if (this == tc) - { - return 1; - } - - if (equiv_only) - { - CORBA::TypeCode_var rcvr = - CORBA::TypeCode::_duplicate (const_cast <CORBA::TypeCode *> (this)); - - CORBA::Boolean status = (this->kind_ == CORBA::tk_alias); - - while (status) - { - rcvr = rcvr->content_type (ACE_ENV_SINGLE_ARG_PARAMETER); - ACE_CHECK_RETURN (0); - - status = - (rcvr->kind (ACE_ENV_SINGLE_ARG_PARAMETER) == CORBA::tk_alias); - ACE_CHECK_RETURN (0); - } - - CORBA::TCKind kind = tc->kind (ACE_ENV_SINGLE_ARG_PARAMETER); - ACE_CHECK_RETURN (0); - status = (kind == CORBA::tk_alias); - - // Added by Bala to check for leaks as content_type duplicates the - // pointers - CORBA::TypeCode_var tcvar = - CORBA::TypeCode::_duplicate (const_cast <CORBA::TypeCode *> (tc)); - - while (status) - { - tcvar = tcvar->content_type (ACE_ENV_SINGLE_ARG_PARAMETER); - ACE_CHECK_RETURN (0); - - kind = tcvar->kind (ACE_ENV_SINGLE_ARG_PARAMETER); - ACE_CHECK_RETURN (0); - status = (kind == CORBA::tk_alias); - } - - kind = rcvr->kind (ACE_ENV_SINGLE_ARG_PARAMETER); - ACE_CHECK_RETURN (0); - CORBA::TCKind other_kind = tcvar->kind (ACE_ENV_SINGLE_ARG_PARAMETER); - ACE_CHECK_RETURN (0); - - if (kind != other_kind) - { - return 0; - } - - // Typecode kinds are same. - return rcvr->private_equal (tcvar.in (), - equiv_only - ACE_ENV_ARG_PARAMETER); - } - - CORBA::TCKind kind = tc->kind (ACE_ENV_SINGLE_ARG_PARAMETER); - ACE_CHECK_RETURN (0); - - if (this->kind_ != kind) - { - return 0; - } - - // typecode kinds are same - return this->private_equal (tc, - equiv_only - ACE_ENV_ARG_PARAMETER); -} - -// check if typecodes are equal. Equality is based on a mix of structural -// and name equivalence i.e., if names are provided, we also check for name -// equivalence, else resort simply to structural equivalence. -CORBA::Boolean -CORBA::TypeCode::private_equal (CORBA::TypeCode_ptr tc, - CORBA::Boolean equiv_only - ACE_ENV_ARG_DECL) const -{ - // We come in here only if the typecode kinds of both are same - // Handle each complex typecode separately. - switch (this->kind_) - { - case CORBA::tk_null: - case CORBA::tk_void: - case CORBA::tk_short: - case CORBA::tk_ushort: - case CORBA::tk_long: - case CORBA::tk_ulong: - case CORBA::tk_float: - case CORBA::tk_double: - case CORBA::tk_longlong: - case CORBA::tk_ulonglong: - case CORBA::tk_longdouble: - case CORBA::tk_boolean: - case CORBA::tk_octet: - case CORBA::tk_char: - case CORBA::tk_wchar: - case CORBA::tk_TypeCode: - case CORBA::tk_Principal: - case CORBA::tk_any: - // all these are simple typecodes and the comparison is based - // solely on the kind_ field - return 1; - case CORBA::tk_component: - case CORBA::tk_home: - case CORBA::tk_objref: - case CORBA::tk_abstract_interface: - case CORBA::tk_local_interface: - return this->private_equal_objref (tc, - equiv_only - ACE_ENV_ARG_PARAMETER); - case CORBA::tk_struct: - return this->private_equal_struct (tc, - equiv_only - ACE_ENV_ARG_PARAMETER); - case CORBA::tk_union: - return this->private_equal_union (tc, - equiv_only - ACE_ENV_ARG_PARAMETER); - case CORBA::tk_enum: - return this->private_equal_enum (tc, - equiv_only - ACE_ENV_ARG_PARAMETER); - case CORBA::tk_string: - case CORBA::tk_wstring: - return this->private_equal_string (tc, - equiv_only - ACE_ENV_ARG_PARAMETER); - case CORBA::tk_sequence: - return this->private_equal_sequence (tc, - equiv_only - ACE_ENV_ARG_PARAMETER); - case CORBA::tk_array: - return this->private_equal_array (tc, - equiv_only - ACE_ENV_ARG_PARAMETER); - case CORBA::tk_value_box: - case CORBA::tk_alias: - return this->private_equal_alias (tc, - equiv_only - ACE_ENV_ARG_PARAMETER); - case CORBA::tk_except: - return this->private_equal_except (tc, - equiv_only - ACE_ENV_ARG_PARAMETER); - case CORBA::tk_value: - case CORBA::tk_event: - return this->private_equal_valuetype (tc, - equiv_only - ACE_ENV_ARG_PARAMETER); - case ~0u: // indirection - { - // indirection offset must be same - return 1; - } - ACE_NOTREACHED (break); - default: - return 0; - } -} - -CORBA::Boolean -CORBA::TypeCode::private_equal_objref ( - CORBA::TypeCode_ptr tc, - CORBA::Boolean equiv_only - ACE_ENV_ARG_DECL - ) const -{ - // Compare the repoID and name, of which the name is optional as per GIOP - // spec. However, the repoID is mandatory. - const char *my_id = this->id (ACE_ENV_SINGLE_ARG_PARAMETER); - ACE_CHECK_RETURN (0); - - const char *tc_id = tc->id (ACE_ENV_SINGLE_ARG_PARAMETER); - ACE_CHECK_RETURN (0); - - if (ACE_OS::strcmp (my_id, tc_id) == 0) - { - // Equality of repoIDs is sufficient for equivalence. - if (equiv_only) - { - return 1; - } - // Name check is skipped by equivalent(). - else - { - // same repository IDs. Now check their names - const char *myname = this->name (ACE_ENV_SINGLE_ARG_PARAMETER); - ACE_CHECK_RETURN (0); - - const char *tcname = tc->name (ACE_ENV_SINGLE_ARG_PARAMETER); - ACE_CHECK_RETURN (0); - - if ((ACE_OS::strlen (myname) > 1) - && (ACE_OS::strlen (tcname) > 1)) - { - // Both of them specify names, compare them - if (ACE_OS::strcmp (myname, tcname) == 0) - { - return 1; // success - } - else - { - return 0; // failed - } - } - - return 1; // success - } - } - - return 0; // failed -} - -CORBA::Boolean -CORBA::TypeCode::private_equal_struct ( - CORBA::TypeCode_ptr tc, - CORBA::Boolean equiv_only - ACE_ENV_ARG_DECL - ) const -{ - // For structs the repoID and names are optional. However, if provided, - // we must compare them - const char *my_id = this->id (ACE_ENV_SINGLE_ARG_PARAMETER); - ACE_CHECK_RETURN (0); - - const char *tc_id = tc->id (ACE_ENV_SINGLE_ARG_PARAMETER); - ACE_CHECK_RETURN (0); - - // compare repoIDs if they exist - if (ACE_OS::strlen (my_id) > 1 && ACE_OS::strlen (tc_id) > 1) - { - if (ACE_OS::strcmp (my_id, tc_id)) // not same - { - return 0; - } - else - { - // Equality of repoIDs is sufficient for equivalence. - if (equiv_only) - { - return 1; - } - } - } - - // Skipped by equivalent(). - if (!equiv_only) - { - const char *my_name = this->name (ACE_ENV_SINGLE_ARG_PARAMETER); - ACE_CHECK_RETURN (0); - - const char *tc_name = tc->name (ACE_ENV_SINGLE_ARG_PARAMETER); - ACE_CHECK_RETURN (0); - - // Compare names if they exist. - if (ACE_OS::strlen (my_name) > 1 - && ACE_OS::strlen (tc_name) > 1 - && ACE_OS::strcmp (my_name, tc_name) != 0) // not same - { - return 0; - } - } - - // Check if the member count is same. - CORBA::ULong my_count = this->member_count (ACE_ENV_SINGLE_ARG_PARAMETER); - ACE_CHECK_RETURN (0); - - CORBA::ULong tc_count = tc->member_count (ACE_ENV_SINGLE_ARG_PARAMETER); - ACE_CHECK_RETURN (0); - - if (my_count != tc_count) - { - return 0; // number of members don't match - } - - // The checks below tell if we have a recursive struct. - CORBA::TypeCode_ptr par = this->parent_; - - if (par != 0) - { - if (this->tc_base_ == this->root_tc_base_) - { - return 1; - } - - CORBA::TypeCode_ptr tc_par = tc->parent_; - - if (tc_par) - { - CORBA::TypeCode_ptr gpar = par->parent_; - CORBA::TypeCode_ptr tc_gpar = tc_par->parent_; - - if (gpar != 0 - && tc_gpar != 0 - && this->tc_base_ == gpar->tc_base_ - && tc->tc_base_ == tc_gpar->tc_base_) - { - return 1; - } - } - } - - for (CORBA::ULong i = 0; i < my_count; ++i) - { - // Skipped by equivalent(). - if (!equiv_only) - { - const char *my_member_name = - this->member_name (i ACE_ENV_ARG_PARAMETER); - ACE_CHECK_RETURN (0); - - const char *tc_member_name = - tc->member_name (i ACE_ENV_ARG_PARAMETER); - ACE_CHECK_RETURN (0); - - if (ACE_OS::strlen (my_member_name) > 1 - && ACE_OS::strlen (tc_member_name) > 1 - && ACE_OS::strcmp (my_member_name, tc_member_name) != 0) - { - return 0; - } - } - - // now compare the typecodes of the members - CORBA::TypeCode_var my_member_tc = - this->member_type (i - ACE_ENV_ARG_PARAMETER); - ACE_CHECK_RETURN (0); - - CORBA::TypeCode_var tc_member_tc = - tc->member_type (i - ACE_ENV_ARG_PARAMETER); - ACE_CHECK_RETURN (0); - - // One of our members may be recursive, but not through us. - if (my_member_tc->parent_ != 0 - && my_member_tc->parent_ == tc_member_tc->parent_ - && my_member_tc->tc_base_ == tc_member_tc->tc_base_ - && my_member_tc->root_tc_base_ == tc_member_tc->root_tc_base_) - { - continue; - } - - CORBA::Boolean flag = - my_member_tc->equ_common (tc_member_tc.in (), - equiv_only - ACE_ENV_ARG_PARAMETER); - ACE_CHECK_RETURN (0); - - if (!flag) - { - return 0; - } - } - - return 1; // success -} - -CORBA::Boolean -CORBA::TypeCode::private_equal_union (CORBA::TypeCode_ptr tc, - CORBA::Boolean equiv_only - ACE_ENV_ARG_DECL) const -{ - // For unions the repoID and names are optional. However, if provided, we - // must compare them - const char *my_id = this->id (ACE_ENV_SINGLE_ARG_PARAMETER); - ACE_CHECK_RETURN (0); - - const char *tc_id = tc->id (ACE_ENV_SINGLE_ARG_PARAMETER); - ACE_CHECK_RETURN (0); - - // compare repoIDs if they exist - if (ACE_OS::strlen (my_id) > 1 && ACE_OS::strlen (tc_id) > 1) - { - if (ACE_OS::strcmp (my_id, tc_id)) // not same - { - return 0; - } - else - { - // Equality of repoIDs is sufficient for equivalence. - if (equiv_only) - { - return 1; - } - } - } - - // Skipped by equivalent(). - if (!equiv_only) - { - const char *my_name = this->name (ACE_ENV_SINGLE_ARG_PARAMETER); - ACE_CHECK_RETURN (0); - - const char *tc_name = tc->name (ACE_ENV_SINGLE_ARG_PARAMETER); - ACE_CHECK_RETURN (0); - - // Compare names if they exist. - if (ACE_OS::strlen (my_name) > 1 - && ACE_OS::strlen (tc_name) > 1 - && ACE_OS::strcmp (my_name, tc_name) != 0) // not same - { - return 0; - } - } - - // check if the discriminant type is same - CORBA::TypeCode_var my_discrim = - this->discriminator_type (ACE_ENV_SINGLE_ARG_PARAMETER); - ACE_CHECK_RETURN (0); - - CORBA::TypeCode_var tc_discrim = - tc->discriminator_type (ACE_ENV_SINGLE_ARG_PARAMETER); - ACE_CHECK_RETURN (0); - - CORBA::Boolean status = my_discrim->equ_common (tc_discrim.in (), - equiv_only - ACE_ENV_ARG_PARAMETER); - ACE_CHECK_RETURN (0); - - if (status == 0) - { - return 0; - } - - // Check the default used. - CORBA::Long my_default = this->default_index (ACE_ENV_SINGLE_ARG_PARAMETER); - ACE_CHECK_RETURN (0); - - CORBA::Long tc_default = tc->default_index (ACE_ENV_SINGLE_ARG_PARAMETER); - ACE_CHECK_RETURN (0); - - if (my_default != tc_default) - { - return 0; - } - - // check if the member count is same - CORBA::ULong my_count = this->member_count (ACE_ENV_SINGLE_ARG_PARAMETER); - ACE_CHECK_RETURN (0); - - CORBA::ULong tc_count = tc->member_count (ACE_ENV_SINGLE_ARG_PARAMETER); - ACE_CHECK_RETURN (0); - - if (my_count != tc_count) - { - return 0; - } - - // The checks below indicate that we have a recursive union. - CORBA::TypeCode_ptr par = this->parent_; - - if (par != 0) - { - if (this->tc_base_ == this->root_tc_base_) - { - return 1; - } - - CORBA::TypeCode_ptr tc_par = tc->parent_; - - if (tc_par) - { - CORBA::TypeCode_ptr gpar = par->parent_; - CORBA::TypeCode_ptr tc_gpar = tc_par->parent_; - - if (gpar != 0 - && tc_gpar != 0 - && this->tc_base_ == gpar->tc_base_ - && tc->tc_base_ == tc_gpar->tc_base_) - { - return 1; - } - } - } - - for (CORBA::ULong i = 0; i < my_count; ++i) - { - // First check if labels are same. - - // Check if member names are same - skipped by equivalent(). - if (!equiv_only) - { - const char *my_member_name = - this->member_name (i - ACE_ENV_ARG_PARAMETER); - ACE_CHECK_RETURN (0); - - const char *tc_member_name = - tc->member_name (i - ACE_ENV_ARG_PARAMETER); - ACE_CHECK_RETURN (0); - - if (ACE_OS::strlen (my_member_name) > 1 - && ACE_OS::strlen (tc_member_name) > 1 - && ACE_OS::strcmp (my_member_name, - tc_member_name)) // not same - { - return 0; - } - } - - // now compare the typecodes of the members - CORBA::TypeCode_var my_member_tc = - this->member_type (i - ACE_ENV_ARG_PARAMETER); - ACE_CHECK_RETURN (0); - - CORBA::TypeCode_var tc_member_tc = - tc->member_type (i - ACE_ENV_ARG_PARAMETER); - ACE_CHECK_RETURN (0); - - // One of our members may be recursive, but not through us. - if (my_member_tc->parent_ != 0 - && my_member_tc->parent_ == tc_member_tc->parent_ - && my_member_tc->tc_base_ == tc_member_tc->tc_base_ - && my_member_tc->root_tc_base_ == tc_member_tc->root_tc_base_) - { - continue; - } - - CORBA::Boolean flag = my_member_tc->equ_common (tc_member_tc.in (), - equiv_only - ACE_ENV_ARG_PARAMETER); - ACE_CHECK_RETURN (0); - - if (flag == 0) - { - return 0; - } - } - - return 1; // success -} - -CORBA::Boolean -CORBA::TypeCode::private_equal_enum (CORBA::TypeCode_ptr tc, - CORBA::Boolean equiv_only - ACE_ENV_ARG_DECL) const -{ - // For enums the repoID and names are optional. However, if - // provided, we must compare them. - const char *my_id = this->id (ACE_ENV_SINGLE_ARG_PARAMETER); - ACE_CHECK_RETURN (0); - - const char *tc_id = tc->id (ACE_ENV_SINGLE_ARG_PARAMETER); - ACE_CHECK_RETURN (0); - - // compare repoIDs if they exist - if (ACE_OS::strlen (my_id) > 1 && ACE_OS::strlen (tc_id) > 1) - { - if (ACE_OS::strcmp (my_id, tc_id)) // not same - { - return 0; - } - else - { - // Equality of repoIDs is sufficient for equivalence. - if (equiv_only) - { - return 1; - } - } - } - - // Skipped by equivalent(). - if (!equiv_only) - { - const char *my_name = this->name (ACE_ENV_SINGLE_ARG_PARAMETER); - ACE_CHECK_RETURN (0); - - const char *tc_name = tc->name (ACE_ENV_SINGLE_ARG_PARAMETER); - ACE_CHECK_RETURN (0); - - // Compare names if they exist. - if (ACE_OS::strlen (my_name) > 1 - && ACE_OS::strlen (tc_name) > 1 - && ACE_OS::strcmp (my_name, tc_name)) // not same - { - return 0; - } - } - - // Check if the member count is same. - CORBA::ULong my_count = this->member_count (ACE_ENV_SINGLE_ARG_PARAMETER); - ACE_CHECK_RETURN (0); - - CORBA::ULong tc_count = tc->member_count (ACE_ENV_SINGLE_ARG_PARAMETER); - ACE_CHECK_RETURN (0); - - if (my_count != tc_count) - { - return 0; - } - - for (CORBA::ULong i=0; i < my_count; ++i) - { - // Check if member names are same - skipped by equivalent(). - if (!equiv_only) - { - const char *my_member_name = - this->member_name (i - ACE_ENV_ARG_PARAMETER); - ACE_CHECK_RETURN (0); - - const char *tc_member_name = - tc->member_name (i - ACE_ENV_ARG_PARAMETER); - ACE_CHECK_RETURN (0); - - if (ACE_OS::strlen (my_member_name) > 1 - && ACE_OS::strlen (tc_member_name) > 1 - && ACE_OS::strcmp (my_member_name, tc_member_name) != 0) - { - return 0; - } - } - } - - return 1; // success -} - -CORBA::Boolean -CORBA::TypeCode::private_equal_string ( - CORBA::TypeCode_ptr tc, - CORBA::Boolean /* equiv_only */ - ACE_ENV_ARG_DECL - ) const -{ - // compare the lengths - CORBA::ULong my_len = this->length (ACE_ENV_SINGLE_ARG_PARAMETER); - ACE_CHECK_RETURN (0); - - CORBA::ULong tc_len = tc->length (ACE_ENV_SINGLE_ARG_PARAMETER); - ACE_CHECK_RETURN (0); - - return (my_len == tc_len); -} - -CORBA::Boolean -CORBA::TypeCode::private_equal_wstring ( - CORBA::TypeCode_ptr tc, - CORBA::Boolean /* equiv_only */ - ACE_ENV_ARG_DECL - ) const -{ - // compare the lengths - CORBA::ULong my_len = this->length (ACE_ENV_SINGLE_ARG_PARAMETER); - ACE_CHECK_RETURN (0); - - CORBA::ULong tc_len = tc->length (ACE_ENV_SINGLE_ARG_PARAMETER); - ACE_CHECK_RETURN (0); - - return (my_len == tc_len); -} - -CORBA::Boolean -CORBA::TypeCode::private_equal_sequence ( - CORBA::TypeCode_ptr tc, - CORBA::Boolean equiv_only - ACE_ENV_ARG_DECL - ) const -{ - // this involves comparing the typecodes of the element type as well - // as the bounds - CORBA::TypeCode_var my_elem = - this->content_type (ACE_ENV_SINGLE_ARG_PARAMETER); - ACE_CHECK_RETURN (0); - - CORBA::TypeCode_var tc_elem = - tc->content_type (ACE_ENV_SINGLE_ARG_PARAMETER); - ACE_CHECK_RETURN (0); - - CORBA::Boolean status = my_elem->equ_common (tc_elem.in (), - equiv_only - ACE_ENV_ARG_PARAMETER); - ACE_CHECK_RETURN (0); - - if (status == 0) - { - return 0; - } - - // Now check if bounds are same. - CORBA::ULong my_len = this->length (ACE_ENV_SINGLE_ARG_PARAMETER); - ACE_CHECK_RETURN (0); - - CORBA::ULong tc_len = tc->length (ACE_ENV_SINGLE_ARG_PARAMETER); - ACE_CHECK_RETURN (0); - - return (my_len == tc_len); -} - -CORBA::Boolean -CORBA::TypeCode::private_equal_array (CORBA::TypeCode_ptr tc, - CORBA::Boolean equiv_only - ACE_ENV_ARG_DECL) const -{ - // Exactly like sequence - return this->private_equal_sequence (tc, - equiv_only - ACE_ENV_ARG_PARAMETER); -} - -CORBA::Boolean -CORBA::TypeCode::private_equal_alias (CORBA::TypeCode_ptr tc, - CORBA::Boolean equiv_only - ACE_ENV_ARG_DECL) const -{ - // For structs the repoID and names are optional. However, if - // provided, we must compare them. - const char *my_id = this->id (ACE_ENV_SINGLE_ARG_PARAMETER); - ACE_CHECK_RETURN (0); - - const char *tc_id = tc->id (ACE_ENV_SINGLE_ARG_PARAMETER); - ACE_CHECK_RETURN (0); - - const char *my_name = this->name (ACE_ENV_SINGLE_ARG_PARAMETER); - ACE_CHECK_RETURN (0); - - const char *tc_name = tc->name (ACE_ENV_SINGLE_ARG_PARAMETER); - ACE_CHECK_RETURN (0); - - // Compare repository IDs if they exist. - if (ACE_OS::strlen (my_id) > 1 && ACE_OS::strlen (tc_id) > 1) - { - if (ACE_OS::strcmp (my_id, tc_id) != 0) // not same - { - return 0; - } - } - - // Compare names if they exist. - if (ACE_OS::strlen (my_name) > 1 && ACE_OS::strlen (tc_name) > 1) - { - if (ACE_OS::strcmp (my_name, tc_name) != 0) // not same - { - return 0; - } - } - - // Now compare element TypeCodes. - CORBA::TypeCode_var my_elem = - this->content_type (ACE_ENV_SINGLE_ARG_PARAMETER); - ACE_CHECK_RETURN (0); - - CORBA::TypeCode_var tc_elem = - tc->content_type (ACE_ENV_SINGLE_ARG_PARAMETER); - ACE_CHECK_RETURN (0); - - return my_elem->equ_common (tc_elem.in (), - equiv_only - ACE_ENV_ARG_PARAMETER); -} - -CORBA::Boolean -CORBA::TypeCode::private_equal_except (CORBA::TypeCode_ptr tc, - CORBA::Boolean equiv_only - ACE_ENV_ARG_DECL) const -{ - // Exactly similar to structs, except that the repository ID is - // mandatory. - - const char *my_id = this->id (ACE_ENV_SINGLE_ARG_PARAMETER); - ACE_CHECK_RETURN (0); - - const char *tc_id = tc->id (ACE_ENV_SINGLE_ARG_PARAMETER); - ACE_CHECK_RETURN (0); - - if (ACE_OS::strcmp (my_id, tc_id) != 0) - { - return 0; // failed - } - else - { - // Equality of repoIDs is sufficient for equivalence. - if (equiv_only) - { - return 1; - } - } - - // Now compare names. They may be optional. - const char *my_name = this->name (ACE_ENV_SINGLE_ARG_PARAMETER); - ACE_CHECK_RETURN (0); - - const char *tc_name = tc->name (ACE_ENV_SINGLE_ARG_PARAMETER); - ACE_CHECK_RETURN (0); - - // Compare names if they exist. - if (ACE_OS::strlen (my_name) > 1 - && ACE_OS::strlen (tc_name) > 1 - && ACE_OS::strcmp (my_name, tc_name) != 0) // not same - { - return 0; - } - - // Check if the member count is same. - CORBA::ULong my_count = this->member_count (ACE_ENV_SINGLE_ARG_PARAMETER); - ACE_CHECK_RETURN (0); - - CORBA::ULong tc_count = tc->member_count (ACE_ENV_SINGLE_ARG_PARAMETER); - ACE_CHECK_RETURN (0); - - if (my_count != tc_count) - { - return 0; // number of members don't match - } - - for (CORBA::ULong i = 0; i < my_count; ++i) - { - // Check if member names are same. - const char *my_member_name = - this->member_name (i - ACE_ENV_ARG_PARAMETER); - ACE_CHECK_RETURN (0); - - const char *tc_member_name = - tc->member_name (i - ACE_ENV_ARG_PARAMETER); - ACE_CHECK_RETURN (0); - - if (ACE_OS::strlen (my_member_name) > 1 - && ACE_OS::strlen (tc_member_name) > 1 - && ACE_OS::strcmp (my_member_name, tc_member_name) != 0) - { - return 0; - } - - // Now compare the typecodes of the members. - CORBA::TypeCode_var my_member_tc = - this->member_type (i ACE_ENV_ARG_PARAMETER); - ACE_CHECK_RETURN (0); - - CORBA::TypeCode_var tc_member_tc = - tc->member_type (i ACE_ENV_ARG_PARAMETER); - ACE_CHECK_RETURN (0); - - CORBA::Boolean flag = my_member_tc->equ_common (tc_member_tc.in (), - equiv_only - ACE_ENV_ARG_PARAMETER); - ACE_CHECK_RETURN (0); - - if (flag == 0) - { - return 0; - } - } - - return 1; // success -} - -//@@ boris: This version is incomplete... -CORBA::Boolean -CORBA::TypeCode::private_equal_valuetype ( - CORBA::TypeCode_ptr tc, - CORBA::Boolean equiv_only - ACE_ENV_ARG_DECL - ) const -{ - // Compare the repoID and name, of which the name is optional as per GIOP - // spec. However, the repoID is mandatory. - const char *my_id = this->id (ACE_ENV_SINGLE_ARG_PARAMETER); - ACE_CHECK_RETURN (0); - - const char *tc_id = tc->id (ACE_ENV_SINGLE_ARG_PARAMETER); - ACE_CHECK_RETURN (0); - - if (ACE_OS::strcmp (my_id, tc_id) != 0) - { - return 0; - } - else - { - // Equality of repoIDs is sufficient for equivalence. - if (equiv_only) - { - return 1; - } - } - - // Now check their names. - const char *myname = this->name (ACE_ENV_SINGLE_ARG_PARAMETER); - ACE_CHECK_RETURN (0); - - const char *tcname = tc->name (ACE_ENV_SINGLE_ARG_PARAMETER); - ACE_CHECK_RETURN (0); - - if (ACE_OS::strlen (myname) > 1 - && ACE_OS::strlen (tcname) > 1 - && ACE_OS::strcmp (myname, tcname) != 0) - { - return 0; // failed - } - - // Compare value modifiers. - CORBA::ValueModifier my_vm = - this->type_modifier (ACE_ENV_SINGLE_ARG_PARAMETER); - ACE_CHECK_RETURN (0); - - CORBA::ValueModifier tc_vm = - tc->type_modifier (ACE_ENV_SINGLE_ARG_PARAMETER); - ACE_CHECK_RETURN (0); - - if (my_vm != tc_vm) - { - return 0; - } - - // Check if the member count is same. - CORBA::ULong my_count = this->member_count (ACE_ENV_SINGLE_ARG_PARAMETER); - ACE_CHECK_RETURN (0); - - CORBA::ULong tc_count = tc->member_count (ACE_ENV_SINGLE_ARG_PARAMETER); - ACE_CHECK_RETURN (0); - - if (my_count != tc_count) - { - return 0; // number of members don't match - } - - // The checks below indicate that we have a recursive union. - CORBA::TypeCode_ptr par = this->parent_; - - if (par != 0) - { - if (this->tc_base_ == this->root_tc_base_) - { - return 1; - } - - CORBA::TypeCode_ptr tc_par = tc->parent_; - - if (tc_par) - { - CORBA::TypeCode_ptr gpar = par->parent_; - CORBA::TypeCode_ptr tc_gpar = tc_par->parent_; - - if (gpar != 0 - && tc_gpar != 0 - && this->tc_base_ == gpar->tc_base_ - && tc->tc_base_ == tc_gpar->tc_base_) - { - return 1; - } - } - } - - for (CORBA::ULong i = 0; i < my_count; ++i) - { - // Check if the member visibilities are the same. - CORBA::Visibility my_vs = - this->member_visibility (i - ACE_ENV_ARG_PARAMETER); - ACE_CHECK_RETURN (0); - - CORBA::Visibility tc_vs = - tc->member_visibility (i - ACE_ENV_ARG_PARAMETER); - ACE_CHECK_RETURN (0); - - if (my_vs != tc_vs) - { - return 0; - } - - // Check if the (optional) member names are same. - const char *my_member_name = - this->member_name (i - ACE_ENV_ARG_PARAMETER); - ACE_CHECK_RETURN (0); - - const char *tc_member_name = - tc->member_name (i - ACE_ENV_ARG_PARAMETER); - ACE_CHECK_RETURN (0); - - if (ACE_OS::strlen (my_member_name) > 1 - && ACE_OS::strlen (tc_member_name) > 1 - && ACE_OS::strcmp (my_member_name, tc_member_name) != 0) - { - return 0; - } - - // Now compare the typecodes of the members. - CORBA::TypeCode_var my_member_tc = - this->member_type (i - ACE_ENV_ARG_PARAMETER); - ACE_CHECK_RETURN (0); - - CORBA::TypeCode_var tc_member_tc = - tc->member_type (i - ACE_ENV_ARG_PARAMETER); - ACE_CHECK_RETURN (0); - - CORBA::Boolean flag = my_member_tc->equ_common (tc_member_tc.in (), - equiv_only - ACE_ENV_ARG_PARAMETER); - ACE_CHECK_RETURN (0); - - if (flag == 0) - { - return 0; - } - } - - return 1; -} - - -// Return the type ID (RepositoryId) for the TypeCode; it may be empty. -// -// NOTE the string returned here is owned by the typecode!! -// -// Valid only for objref, struct, union, enum, alias, and except. Raises -// BadKind exception for the rest of the cases. -const char * -CORBA::TypeCode::private_id (ACE_ENV_SINGLE_ARG_DECL) const -{ - switch (this->kind_) - { - // These are all complex typecodes, which have as their first - // parameter (number zero) a repository/type ID string encoded - // per CDR rules. That means we can just return a pointer to - // that string directly! - - case CORBA::tk_objref: - case CORBA::tk_struct: - case CORBA::tk_union: - case CORBA::tk_enum: - case CORBA::tk_alias: - case CORBA::tk_except: - case CORBA::tk_value: - case CORBA::tk_component: - case CORBA::tk_home: - case CORBA::tk_event: - { - // Double checked locking... - ACE_GUARD_RETURN (TAO_SYNCH_MUTEX, - guard, - this->private_state_->mutex_, - 0); - - if (this->private_state_->tc_id_known_) - { - return this->private_state_->tc_id_; - } - - this->private_state_->tc_id_known_ = 1; - this->private_state_->tc_id_ = (const_cast <char *> (buffer_) - + 4 // skip byte order - // flag and padding - + 4); // skip (strlen + 1) - return this->private_state_->tc_id_; // this is OK because - // strings in the CDR stream - // are NULL terminated - } - // No other typecodes ever have type IDs - default: - ACE_THROW_RETURN (CORBA::TypeCode::BadKind (), - 0); - } -} - -// return the name. The string is owned by the typecode -const char * -CORBA::TypeCode::private_name (ACE_ENV_SINGLE_ARG_DECL) const -{ - switch (this->kind_) - { - // These are all complex typecodes, which have as their second - // parameter (number one) a name string encoded per CDR rules. - // That means we can just return a pointer to that string - // directly! - - case CORBA::tk_objref: - case CORBA::tk_struct: - case CORBA::tk_union: - case CORBA::tk_enum: - case CORBA::tk_alias: - case CORBA::tk_except: - case CORBA::tk_value: - case CORBA::tk_component: - case CORBA::tk_home: - case CORBA::tk_event: - { - // Double checked locking... - ACE_GUARD_RETURN (TAO_SYNCH_MUTEX, - guard, - this->private_state_->mutex_, - 0); - - if (this->private_state_->tc_name_known_) - { - return this->private_state_->tc_name_; - } - - // setup an encapsulation. - TAO_InputCDR stream (this->buffer_ + 4, - this->length_ - 4, - this->byte_order_); - - // skip the typecode ID - if (stream.skip_string ()) // ID - { - this->private_state_->tc_name_known_ = 1; - - // "Read" the string without copying. - stream.read_string (this->private_state_->tc_name_); - - return this->private_state_->tc_name_; - } - else - { - ACE_THROW_RETURN (CORBA::INTERNAL (), - 0); - } - } - // No other typecodes ever have type IDs. - default: - ACE_THROW_RETURN (CORBA::TypeCode::BadKind (), - 0); - } -} - -// Return the number of members defined by this typecode -// -// Applicable to struct, union, enum, alias, and except -// For the rest of the cases, raises the BadKind exception. - -CORBA::ULong -CORBA::TypeCode::private_member_count (ACE_ENV_SINGLE_ARG_DECL) const -{ - // Double checked locking... - ACE_GUARD_RETURN (TAO_SYNCH_MUTEX, - guard, - this->private_state_->mutex_, - 0); - - CORBA::ULong members; - // setup an encapsulation - TAO_InputCDR stream (this->buffer_+4, - this->length_-4, - this->byte_order_); - - switch (kind_) - { - case CORBA::tk_alias: - case CORBA::tk_value_box: - return 1; - case CORBA::tk_enum: - case CORBA::tk_except: - case CORBA::tk_struct: - { - if (this->private_state_->tc_member_count_known_) - { - return this->private_state_->tc_member_count_; - } - - // Skip rest of header (type ID and name) and collect the - // number of struct members. - if (!stream.skip_string () // ID - || !stream.skip_string () // struct name - || !stream.read_ulong (members)) - { - ACE_THROW_RETURN (CORBA::BAD_TYPECODE (), - 0); - } - - this->private_state_->tc_member_count_known_ = 1; - this->private_state_->tc_member_count_ = members; - return this->private_state_->tc_member_count_; - } - case CORBA::tk_union: - { - if (this->private_state_->tc_member_count_known_) - { - return this->private_state_->tc_member_count_; - } - - // Skip rest of header (type ID, name, etc...) and collect the - // number of struct members. - if (!stream.skip_string () // ID - || !stream.skip_string () // struct name - || !this->skip_typecode (stream) // discriminant TC - || !stream.read_ulong (members) // default used - || !stream.read_ulong (members)) // real member count - { - ACE_THROW_RETURN (CORBA::BAD_TYPECODE (), - 0); - } - - this->private_state_->tc_member_count_known_ = 1; - this->private_state_->tc_member_count_ = members; - return this->private_state_->tc_member_count_; - } - case CORBA::tk_value: - case CORBA::tk_event: - { - if (this->private_state_->tc_member_count_known_) - { - return this->private_state_->tc_member_count_; - } - - // skip rest of header (type ID, name, etc) and collect the - // number of value members - CORBA::ULong tc_kind_holder; - CORBA::TCKind tc_kind; - - if (!stream.skip_string () // ID - || !stream.skip_string () // Name - || !stream.skip_ulong () // ValueModifier - || !stream.read_ulong (tc_kind_holder)) // Base's TCKind - { - ACE_THROW_RETURN (CORBA::BAD_TYPECODE (), - 0); - } - - tc_kind = static_cast <CORBA::TCKind> (tc_kind_holder); - - // The tc_kind can be either tk_null or tk_value. - // In the latter case we should skip encapsulation or - // indirection - whatever comes in. - CORBA::ULong encap_length; - - if (tc_kind != CORBA::tk_null) - { - if (!stream.read_ulong (encap_length)) - { - ACE_THROW_RETURN (CORBA::BAD_TYPECODE (), - 0); - } - - if (tc_kind_holder != 0xffffffff) // check for indirection - { - if (!stream.skip_bytes (encap_length)) - { - ACE_THROW_RETURN (CORBA::BAD_TYPECODE (), - 0); - } - } - } - - // Now read member count. - if (!stream.read_ulong (members)) - { - ACE_THROW_RETURN (CORBA::BAD_TYPECODE (), - 0); - } - - this->private_state_->tc_member_count_known_ = 1; - this->private_state_->tc_member_count_ = members; - return this->private_state_->tc_member_count_; - } - default: - ACE_THROW_RETURN (CORBA::BAD_TYPECODE (), - 0); - } -} - -// -// Applicable only to struct, union, except, value and event. -// - -CORBA::TypeCode_ptr -CORBA::TypeCode::private_member_type (CORBA::ULong slot - ACE_ENV_ARG_DECL) const -{ - CORBA::ULong temp = 0; - CORBA::ULong i = 0; - CORBA::ULong mcount = this->member_count (ACE_ENV_SINGLE_ARG_PARAMETER); - ACE_CHECK_RETURN (CORBA::TypeCode::_nil ()); - - // Build the de-encapsulating CDR stream, bypassing the stringent - // alignment tests (we're a bit looser in what we need here, and we - // _know_ we're OK). Then skip the byte order code. - TAO_InputCDR stream (this->buffer_+4, - this->length_-4, - this->byte_order_); - CORBA::TypeCode_var tc; - CORBA::TypeCode_ptr disc_tc = CORBA::TypeCode::_nil (); - - // Double checked locking... - ACE_GUARD_RETURN (TAO_SYNCH_MUTEX, - guard, - this->private_state_->mutex_, - CORBA::TypeCode::_nil ()); - - switch (kind_) - { - case CORBA::tk_except: - case CORBA::tk_struct: - if (this->private_state_->tc_member_type_list_known_) - { - if (slot < mcount) - { - return this->private_state_->tc_member_type_list_[slot]; - } - else - { - ACE_THROW_RETURN (CORBA::TypeCode::Bounds (), - CORBA::TypeCode::_nil ()); - } - } - - // the first time in. Precompute and store types of all members - - // Allocate a list to hold the member typecodes - ACE_NEW_THROW_EX (this->private_state_->tc_member_type_list_, - CORBA::TypeCode_ptr[mcount], - CORBA::NO_MEMORY ()); - ACE_CHECK_RETURN (CORBA::TypeCode::_nil ()); - - // skip the id, name, and member_count part - if (!stream.skip_string () // type ID, hidden - || !stream.skip_string () // typedef name - || !stream.read_ulong (temp)) // member count - { - ACE_THROW_RETURN (CORBA::BAD_TYPECODE (), - CORBA::TypeCode::_nil ()); - } - - // compute the typecodes for all the members and - // return the required one. - for (i = 0; i < mcount; ++i) - // the ith entry will have the typecode of the ith guy - { - if (!stream.skip_string ()) // skip the name - { - ACE_THROW_RETURN (CORBA::BAD_TYPECODE (), - CORBA::TypeCode::_nil ()); - } - - CORBA::TypeCode_ptr& member_type = - this->private_state_->tc_member_type_list_[i]; - CORBA::TypeCode::_tao_decode (this, - stream, - member_type - ACE_ENV_ARG_PARAMETER); - ACE_CHECK_RETURN (CORBA::TypeCode::_nil ()); - } - - this->private_state_->tc_member_type_list_known_ = 1; - - if (slot < mcount) - { - return this->private_state_->tc_member_type_list_[slot]; - } - else - { - ACE_THROW_RETURN (CORBA::TypeCode::Bounds (), - CORBA::TypeCode::_nil ()); - } - case CORBA::tk_union: - if (this->private_state_->tc_member_type_list_known_) - { - if (slot < mcount) - { - return this->private_state_->tc_member_type_list_[slot]; - } - else - { - ACE_THROW_RETURN (CORBA::TypeCode::Bounds (), - CORBA::TypeCode::_nil ()); - } - } - - // the first time in. Precompute and store types of all members - ACE_NEW_THROW_EX (this->private_state_->tc_member_type_list_, - CORBA::TypeCode_ptr[mcount], - CORBA::NO_MEMORY ()); - ACE_CHECK_RETURN (CORBA::TypeCode::_nil ()); - - // skip the id, name, and discrimant type part - if (!stream.skip_string () // type ID, hidden - || !stream.skip_string () // typedef name - || !this->skip_typecode (stream)) // skip discriminant typecode - { - ACE_THROW_RETURN (CORBA::BAD_TYPECODE (), - CORBA::TypeCode::_nil ()); - } - else if (!stream.read_ulong (temp) // default used - || !stream.read_ulong (temp)) // member count - { - ACE_THROW_RETURN (CORBA::BAD_TYPECODE (), - CORBA::TypeCode::_nil ()); - } - - // Get the typecode for the discriminator. - disc_tc = - this->private_discriminator_type_i (ACE_ENV_SINGLE_ARG_PARAMETER); - // Compute the typecodes for all the members and return the - // required one. - ACE_CHECK_RETURN (CORBA::TypeCode::_nil ()); - - for (i = 0; i < mcount; ++i) - // The ith entry will have the typecode of the ith guy. - { - // Skip member label. - TAO::traverse_status status = - TAO_Marshal_Object::perform_skip (disc_tc, - &stream - ACE_ENV_ARG_PARAMETER); - ACE_CHECK_RETURN (CORBA::TypeCode::_nil ()); - - if (status != TAO::TRAVERSE_CONTINUE - || !stream.skip_string ()) // skip the name - { - ACE_THROW_RETURN (CORBA::BAD_TYPECODE (), - CORBA::TypeCode::_nil ()); - } - - CORBA::TypeCode_ptr& member_type = - this->private_state_->tc_member_type_list_[i]; - CORBA::TypeCode::_tao_decode (this, - stream, - member_type - ACE_ENV_ARG_PARAMETER); - ACE_CHECK_RETURN (CORBA::TypeCode::_nil ()); - } - - this->private_state_->tc_member_type_list_known_ = 1; - - if (slot < mcount) - { - return this->private_state_->tc_member_type_list_[slot]; - } - else - { - ACE_THROW_RETURN (CORBA::TypeCode::Bounds (), - CORBA::TypeCode::_nil ()); - } - case CORBA::tk_value: - case CORBA::tk_event: - if (this->private_state_->tc_member_type_list_known_) - { - if (slot < mcount) - { - return this->private_state_->tc_member_type_list_[slot]; - } - else - { - ACE_THROW_RETURN (CORBA::TypeCode::Bounds (), - CORBA::TypeCode::_nil ()); - } - } - - // the first time in. Precompute and store types of all members - - // Allocate a list to hold the member typecodes - ACE_NEW_THROW_EX (this->private_state_->tc_member_type_list_, - CORBA::TypeCode_ptr [mcount], - CORBA::NO_MEMORY ()); - ACE_CHECK_RETURN (CORBA::TypeCode::_nil ()); - - // skip rest of header (type ID, name, etc) and collect the - // number of value members - CORBA::ULong tc_kind_holder; - CORBA::TCKind tc_kind; - - if (!stream.skip_string () // ID - || !stream.skip_string () // Name - || !stream.skip_ulong () // ValueModifier - || !stream.read_ulong (tc_kind_holder)) // Base's TCKind - { - ACE_THROW_RETURN (CORBA::BAD_TYPECODE (), - CORBA::TypeCode::_nil ()); - } - - tc_kind = static_cast <CORBA::TCKind> (tc_kind_holder); - - // The tc_kind can be either tk_null or tk_value. - // In the latter case we should skip encapsulation or - // indirection - whatever comes in. - CORBA::ULong encap_length; - - if (tc_kind != CORBA::tk_null) - { - if (!stream.read_ulong (encap_length)) - { - ACE_THROW_RETURN (CORBA::BAD_TYPECODE (), - CORBA::TypeCode::_nil ()); - } - - if (tc_kind_holder != 0xffffffff) // check for indirection - { - if (!stream.skip_bytes (encap_length)) - { - ACE_THROW_RETURN (CORBA::BAD_TYPECODE (), - CORBA::TypeCode::_nil ()); - } - } - } - - // Now skip member count. - if (!stream.skip_ulong ()) - { - ACE_THROW_RETURN (CORBA::BAD_TYPECODE (), - CORBA::TypeCode::_nil ()); - } - - // Compute the typecodes for all the members and - // return the required one. - for (i = 0; i < mcount; ++i) - // The ith entry will have the typecode of the ith guy. - { - if (!stream.skip_string ()) // skip the name - { - ACE_THROW_RETURN (CORBA::BAD_TYPECODE (), - CORBA::TypeCode::_nil ()); - } - - CORBA::TypeCode_ptr& member_type = - this->private_state_->tc_member_type_list_[i]; - CORBA::TypeCode::_tao_decode (this, - stream, - member_type - ACE_ENV_ARG_PARAMETER); - ACE_CHECK_RETURN (CORBA::TypeCode::_nil ()); - - if (!stream.skip_ulong ()) // skip member visibility - { - ACE_THROW_RETURN (CORBA::BAD_TYPECODE (), - CORBA::TypeCode::_nil ()); - } - } - - this->private_state_->tc_member_type_list_known_ = 1; - - if (slot < mcount) - { - return this->private_state_->tc_member_type_list_[slot]; - } - else - { - ACE_THROW_RETURN (CORBA::TypeCode::Bounds (), - CORBA::TypeCode::_nil ()); - } - default: - // Bad kind. - ACE_THROW_RETURN (CORBA::TypeCode::BadKind (), - CORBA::TypeCode::_nil ()); - } -} - -// Return the name for the nth member -// Applicable only to CORBA::tk_struct, CORBA::tk_union, CORBA::tk_enum, -// CORBA::tk_except, tk_value and tk_event. -const char * -CORBA::TypeCode::private_member_name (CORBA::ULong slot - ACE_ENV_ARG_DECL) const -{ - CORBA::ULong temp, mcount; - - // Build the de-encapsulating CDR stream, bypassing the stringent - // alignment tests (we're a bit looser in what we need here, and we - // _know_ we're OK). Then skip the byte order code. - TAO_InputCDR stream (this->buffer_+4, - this->length_-4, - this->byte_order_); - - mcount = this->member_count (ACE_ENV_SINGLE_ARG_PARAMETER); - // out of bounds - ACE_CHECK_RETURN (0); - - // Double checked locking... - ACE_GUARD_RETURN (TAO_SYNCH_MUTEX, - guard, - this->private_state_->mutex_, - 0); - - if (this->private_state_->tc_member_name_list_known_) - { - if (slot < mcount) - { - return this->private_state_->tc_member_name_list_[slot]; - } - else - { - ACE_THROW_RETURN (CORBA::TypeCode::Bounds (), - 0); - } - } - - // the first time in. Precompute and store names of all members - // Allocate a list to hold the member names - ACE_NEW_THROW_EX (this->private_state_->tc_member_name_list_, - char* [mcount], - CORBA::NO_MEMORY ()); - ACE_CHECK_RETURN (0); - - switch (kind_) - { - case CORBA::tk_enum: - { - // skip the id, name, and member_count part - if (!stream.skip_string () // type ID, hidden - || !stream.skip_string () // enum name - || !stream.read_ulong (temp)) // member count - { - ACE_THROW_RETURN (CORBA::BAD_TYPECODE (), - 0); - } - - // compute the typecodes for all the members and - // return the required one. - for (CORBA::ULong i = 0; i < mcount; ++i) - { - // Now read this name. - if (!stream.read_string ( - this->private_state_->tc_member_name_list_ [i] - )) - { - ACE_THROW_RETURN (CORBA::BAD_TYPECODE (), - 0); - } - } - - this->private_state_->tc_member_name_list_known_ = 1; - - if (slot < mcount) - { - return this->private_state_->tc_member_name_list_[slot]; - } - else - { - ACE_THROW_RETURN (CORBA::TypeCode::Bounds (), - 0); - } - } - case CORBA::tk_except: - case CORBA::tk_struct: - { - // Skip the id, name, and member_count part. - if (!stream.skip_string () // type ID, hidden - || !stream.skip_string () // struct/except name - || !stream.read_ulong (temp)) // member count - { - ACE_THROW_RETURN (CORBA::BAD_TYPECODE (), - 0); - } - - // Computes the typecodes for all the members and - // return the required one. - for (CORBA::ULong i = 0; i < mcount; ++i) - { - if (!stream.read_string ( - this->private_state_->tc_member_name_list_[i] - ) - || !this->skip_typecode (stream)) - { - ACE_THROW_RETURN (CORBA::BAD_TYPECODE (), - 0); - } - } - - this->private_state_->tc_member_name_list_known_ = 1; - - if (slot < mcount) - { - return this->private_state_->tc_member_name_list_[slot]; - } - else - { - ACE_THROW_RETURN (CORBA::TypeCode::Bounds (), - 0); - } - - } - case CORBA::tk_union: // index from 0 - { - // skip the id, name, and discrimant type part - if (!stream.skip_string () // type ID, hidden - || !stream.skip_string () // typedef name - || !this->skip_typecode (stream)) // skip discriminant typecode - ACE_THROW_RETURN (CORBA::BAD_TYPECODE (), (char *)0); - else if (!stream.read_ulong (temp) // default used - || !stream.read_ulong (temp)) // member count - ACE_THROW_RETURN (CORBA::BAD_TYPECODE (), 0); - else - { - // get the typecode for the discriminator - CORBA::TypeCode_ptr disc_tc = - this->private_discriminator_type_i ( - ACE_ENV_SINGLE_ARG_PARAMETER); - // Compute the name for all the members and return the - // required one. - ACE_CHECK_RETURN (0); - - for (CORBA::ULong i = 0; i < mcount; ++i) - { - // The ith entry will have the name of the ith member. - TAO::traverse_status status = - TAO_Marshal_Object::perform_skip (disc_tc, - &stream - ACE_ENV_ARG_PARAMETER); - ACE_CHECK_RETURN (0); - - if (status != TAO::TRAVERSE_CONTINUE) - ACE_THROW_RETURN (CORBA::BAD_TYPECODE (), 0); - - // skip typecode for member - if (!stream.read_string ( - this->private_state_->tc_member_name_list_ [i] - ) - || (!this->skip_typecode (stream))) // skip typecode - ACE_THROW_RETURN ( CORBA::BAD_TYPECODE (), 0); - } - - this->private_state_->tc_member_name_list_known_ = 1; - - if (slot < mcount) - { - return this->private_state_->tc_member_name_list_[slot]; - } - else - { - ACE_THROW_RETURN (CORBA::TypeCode::Bounds (), - 0); - } - } - } - case CORBA::tk_value: - case CORBA::tk_event: - { - // Skip rest of header (type ID, name, etc) and skip the - // number of value members. - CORBA::ULong tc_kind_holder; - CORBA::TCKind tc_kind; - - if (!stream.skip_string () // ID - || !stream.skip_string () // Name - || !stream.skip_ulong () // ValueModifier - || !stream.read_ulong (tc_kind_holder)) // Base's TCKind - { - ACE_THROW_RETURN (CORBA::BAD_TYPECODE (), - 0); - } - - tc_kind = static_cast <CORBA::TCKind> (tc_kind_holder); - - // The tc_kind can be either tk_null or tk_value. - // In the latter case we should skip encapsulation or - // indirection - whatever comes in. - CORBA::ULong encap_length; - - if (tc_kind != CORBA::tk_null) - { - if (!stream.read_ulong (encap_length)) - { - ACE_THROW_RETURN (CORBA::BAD_TYPECODE (), - 0); - } - - if (tc_kind_holder != 0xffffffff) // check for indirection - { - if (!stream.skip_bytes (encap_length)) - { - ACE_THROW_RETURN (CORBA::BAD_TYPECODE (), - 0); - } - } - } - - // Now skip member count. - if (!stream.skip_ulong ()) - { - ACE_THROW_RETURN (CORBA::BAD_TYPECODE (), - 0); - } - - // Compute the names for all the members, skip the other - // member parameters and return the required name. - for (CORBA::ULong i = 0; i < mcount; ++i) - { - if (!stream.read_string ( - this->private_state_->tc_member_name_list_[i] - ) - || !this->skip_typecode (stream) // member typecode - || !stream.skip_ulong ()) // member visibility - { - ACE_THROW_RETURN (CORBA::BAD_TYPECODE (), - 0); - } - } - - this->private_state_->tc_member_name_list_known_ = 1; - - if (slot < mcount) - { - return this->private_state_->tc_member_name_list_[slot]; - } - else - { - ACE_THROW_RETURN (CORBA::TypeCode::Bounds (), - 0); - } - } - default: - // Bad kind. - ACE_THROW_RETURN (CORBA::TypeCode::BadKind (), - 0); - } -} - -// Return member labels for CORBA::tk_union typecodes. -CORBA::Any_ptr -CORBA::TypeCode::private_member_label (CORBA::ULong n - ACE_ENV_ARG_DECL) const -{ - // this function is only applicable to the CORBA::tk_union TC - if (this->kind_ != CORBA::tk_union) - { - ACE_THROW_RETURN (CORBA::TypeCode::BadKind (), - 0); - } - - TAO_InputCDR stream (this->buffer_+4, - this->length_-4, - this->byte_order_); - - // skip ID and name - if (!stream.skip_string () // type ID, hidden - || !stream.skip_string () // typedef name - || !this->skip_typecode (stream)) // skip discriminant typecode - { - ACE_THROW_RETURN (CORBA::TypeCode::BadKind (), - 0); - } - - // skip default used, and get member count - CORBA::ULong member_count; - - if (!stream.read_ulong (member_count) // default used - || !stream.read_ulong (member_count)) // member count - { - ACE_DEBUG ((LM_DEBUG, - ACE_TEXT ("TypeCode::private_member_label -- ") - ACE_TEXT ("error reading from stream\n"))); - ACE_THROW_RETURN (CORBA::BAD_TYPECODE (), - 0); - } - - // Double checked locking... - ACE_GUARD_RETURN (TAO_SYNCH_MUTEX, - guard, - this->private_state_->mutex_, - 0); - - if (this->private_state_->tc_member_label_list_known_) - { - if (n < member_count) - { - return this->private_state_->tc_member_label_list_[n]; - } - else - { - ACE_THROW_RETURN (CORBA::TypeCode::Bounds (), - 0); - } - } - - // MJember labels are of type Any. However, the actual types are - // restricted to simple types - - // @@EXC@@ We should use Auto_Ptr_Array to make this exception - // safe. - CORBA::Any_ptr* label_list; - ACE_NEW_THROW_EX (label_list, - CORBA::Any_ptr [member_count], - CORBA::NO_MEMORY ()); - ACE_CHECK_RETURN (0); - - // get the discriminant TC - CORBA::TypeCode_ptr disc_tc = - this->private_discriminator_type_i (ACE_ENV_SINGLE_ARG_PARAMETER); - ACE_CHECK_RETURN (0); - - for (CORBA::ULong i = 0; i < member_count; ++i) - { - // Create an any from the portion of the CDR stream created - // above..... - - // @@ This code assumes that the stream is a single message - // block, this is perfectly OK [the stream is created from a - // single buffer], but we may need to change this if the - // stream creation changes. [Carlos] - TAO_InputCDR temp (stream); - - char *begin = stream.rd_ptr (); - int retval = - TAO_Marshal_Object::perform_skip (disc_tc, - &temp - ACE_ENV_ARG_PARAMETER); - ACE_CHECK_RETURN (0); - - if (retval != TAO::TRAVERSE_CONTINUE) - { - return 0; - } - - char* end = temp.rd_ptr (); - - // We need to allocate more memory than in the original - // stream, first to guarantee that the buffer is aligned in - // memory and next because the realignment may introduce - // extra padding. 2*MAX_ALIGNMENT should be enough. - // @@EXC@@ This doesn't seem to be exception safe. - TAO_OutputCDR out (end - begin + 2 * ACE_CDR::MAX_ALIGNMENT, - ACE_CDR_BYTE_ORDER, - ACE_Allocator::instance (), - ACE_Allocator::instance (), - ACE_Allocator::instance ()); - - CORBA::TypeCode_ptr label_tc; - - const CORBA::ULong slot = - static_cast <CORBA::ULong> - (this->private_default_index_i (ACE_ENV_SINGLE_ARG_PARAMETER)); - ACE_CHECK_RETURN (0); - - // If we are computing the label for the default index, - // the label must contain an octet value of 0. - if (i == slot) - { - label_tc = CORBA::_tc_octet; - - if (out.write_octet (static_cast <CORBA::Octet> (0)) == 0) - { - return 0; - } - - retval = - TAO_Marshal_Object::perform_skip (disc_tc, - &stream - ACE_ENV_ARG_PARAMETER); - ACE_CHECK_RETURN (0); - - if (retval != TAO::TRAVERSE_CONTINUE) - { - return 0; - } - } - else - { - label_tc = disc_tc; - - retval = - TAO_Marshal_Object::perform_append (label_tc, - &stream, - &out - ACE_ENV_ARG_PARAMETER); - ACE_CHECK_RETURN (0); - - if (retval != TAO::TRAVERSE_CONTINUE) - { - return 0; - } - } - - TAO::Unknown_IDL_Type *impl = 0; - TAO_InputCDR in (out); - ACE_NEW_THROW_EX (impl, - TAO::Unknown_IDL_Type (label_tc, - in), - CORBA::NO_MEMORY ()); - ACE_CHECK_RETURN (0); - - ACE_NEW_THROW_EX (label_list[i], - CORBA::Any, - CORBA::NO_MEMORY ()); - ACE_CHECK_RETURN (0); - - label_list[i]->replace (impl); - - if (stream.skip_string () == 0 - || this->skip_typecode (stream) == 0) - { - if (TAO_debug_level > 0) - { - ACE_ERROR ((LM_ERROR, - ACE_TEXT ("TypeCode::private_member_label ") - ACE_TEXT ("error getting typecode for member %d\n"), - i)); - } - ACE_THROW_RETURN (CORBA::BAD_TYPECODE (), - 0); - } - } - - this->private_state_->tc_member_label_list_ = label_list; - this->private_state_->tc_member_label_list_known_ = 1; - - // If caller asked for the label for a nonexistent member, they get - // an error report! - if (n >= member_count) - { - ACE_THROW_RETURN (CORBA::TypeCode::Bounds (), - 0); - } - - return this->private_state_->tc_member_label_list_[n]; -} - -CORBA::TypeCode_ptr -CORBA::TypeCode::private_discriminator_type ( - ACE_ENV_SINGLE_ARG_DECL - ) const -{ - // Double checked locking... - ACE_GUARD_RETURN (TAO_SYNCH_MUTEX, - guard, - this->private_state_->mutex_, - 0); - - return this->private_discriminator_type_i (ACE_ENV_SINGLE_ARG_PARAMETER); -} - -CORBA::TypeCode_ptr -CORBA::TypeCode::private_discriminator_type_i ( - ACE_ENV_SINGLE_ARG_DECL - ) const -{ - if (this->private_state_->tc_discriminator_type_known_) - { - return this->private_state_->tc_discriminator_type_; - } - - TAO_InputCDR stream (this->buffer_+4, - this->length_-4, - this->byte_order_); - - // skip ID and name, and then get the discriminant TC - - if (!stream.skip_string () // type ID, hidden - || !stream.skip_string ()) // typedef name - { - ACE_THROW_RETURN (CORBA::BAD_TYPECODE (), - 0); - } - - CORBA::TypeCode::_tao_decode (this, - stream, - this->private_state_->tc_discriminator_type_ - ACE_ENV_ARG_PARAMETER); - ACE_CHECK_RETURN (0); - - this->private_state_->tc_discriminator_type_known_ = 1; - return this->private_state_->tc_discriminator_type_; -} - -CORBA::Long -CORBA::TypeCode::private_default_index ( - ACE_ENV_SINGLE_ARG_DECL - ) const -{ - // Double checked locking... - ACE_GUARD_RETURN (TAO_SYNCH_MUTEX, - guard, - this->private_state_->mutex_, - 0); - - return this->private_default_index_i (ACE_ENV_SINGLE_ARG_PARAMETER); -} - -CORBA::Long -CORBA::TypeCode::private_default_index_i ( - ACE_ENV_SINGLE_ARG_DECL - ) const -{ - if (this->private_state_->tc_default_index_used_known_) - { - return this->private_state_->tc_default_index_used_; - } - - TAO_InputCDR stream (this->buffer_+4, - this->length_-4, - this->byte_order_); - - // skip ID and name, and then get the discriminant TC - - if (!stream.skip_string () // type ID, hidden - || !stream.skip_string () // typedef name - || !this->skip_typecode (stream) // skip discriminant - || !stream.read_long (this->private_state_->tc_default_index_used_)) - { - ACE_THROW_RETURN (CORBA::BAD_TYPECODE (), - 0); - } - - this->private_state_->tc_default_index_used_known_ = 1; - return this->private_state_->tc_default_index_used_; -} - -CORBA::Long -CORBA::TypeCode::private_length (ACE_ENV_SINGLE_ARG_DECL) const -{ - TAO_InputCDR stream (this->buffer_+4, - this->length_-4, - this->byte_order_); - switch (this->kind_) - { - case CORBA::tk_sequence: - case CORBA::tk_array: - { - // Double checked locking... - ACE_GUARD_RETURN (TAO_SYNCH_MUTEX, - guard, - this->private_state_->mutex_, - 0); - - if (this->private_state_->tc_length_known_) - { - return this->private_state_->tc_length_; - } - - // Skip the typecode of the element and get the bounds - if (!this->skip_typecode (stream) // skip typecode - || !stream.read_ulong (this->private_state_->tc_length_)) - { - ACE_THROW_RETURN (CORBA::BAD_PARAM (), - 0); - } - else - { - this->private_state_->tc_length_known_ = 1; - return this->private_state_->tc_length_; - } - } - case CORBA::tk_string: - case CORBA::tk_wstring: - { - // Double checked locking... - ACE_GUARD_RETURN (TAO_SYNCH_MUTEX, - guard, - this->private_state_->mutex_, - 0); - - if (this->private_state_->tc_length_known_) - { - return this->private_state_->tc_length_; - } - - if (stream.read_ulong (this->private_state_->tc_length_)) - { - this->private_state_->tc_length_known_ = 1; - return this->private_state_->tc_length_; - } - else - { - ACE_THROW_RETURN (CORBA::BAD_PARAM (), - 0); - } - } - default: - ACE_THROW_RETURN (CORBA::TypeCode::BadKind (), - 0); - } -} - -CORBA::TypeCode_ptr -CORBA::TypeCode::private_content_type (ACE_ENV_SINGLE_ARG_DECL) const -{ - TAO_InputCDR stream (this->buffer_+4, - this->length_-4, - this->byte_order_); - switch (kind_) - { - case CORBA::tk_sequence: - case CORBA::tk_array: - { - // Double checked locking... - ACE_GUARD_RETURN (TAO_SYNCH_MUTEX, - guard, - this->private_state_->mutex_, - 0); - - if (this->private_state_->tc_content_type_known_) - { - return this->private_state_->tc_content_type_; - } - - // retrieve the content type - CORBA::TypeCode::_tao_decode (this, - stream, - this->private_state_->tc_content_type_ - ACE_ENV_ARG_PARAMETER); - ACE_CHECK_RETURN (0); - - this->private_state_->tc_content_type_known_ = 1; - return this->private_state_->tc_content_type_; - } - case CORBA::tk_alias: - case CORBA::tk_value_box: - { - // Double checked locking... - ACE_GUARD_RETURN (TAO_SYNCH_MUTEX, - guard, - this->private_state_->mutex_, - 0); - - if (this->private_state_->tc_content_type_known_) - { - return this->private_state_->tc_content_type_; - } - - if (!stream.skip_string () // typeID - || !stream.skip_string ()) // name - { - ACE_THROW_RETURN (CORBA::BAD_PARAM (), - 0); - } - - CORBA::TypeCode::_tao_decode (this, - stream, - this->private_state_->tc_content_type_ - ACE_ENV_ARG_PARAMETER); - ACE_CHECK_RETURN (0); - - this->private_state_->tc_content_type_known_ = 1; - return this->private_state_->tc_content_type_; - } - default: - ACE_THROW_RETURN (CORBA::TypeCode::BadKind (), - 0); - } -} - -CORBA::Visibility -CORBA::TypeCode::private_member_visibility (CORBA::ULong slot - ACE_ENV_ARG_DECL) const -{ - if (this->kind_ != CORBA::tk_value - && this->kind_ != CORBA::tk_event) - { - ACE_THROW_RETURN (CORBA::TypeCode::BadKind (), - CORBA::PRIVATE_MEMBER); - } - - CORBA::ULong mcount = this->member_count (ACE_ENV_SINGLE_ARG_PARAMETER); - ACE_CHECK_RETURN (CORBA::PRIVATE_MEMBER); - - if (slot >= mcount) - { - ACE_THROW_RETURN (CORBA::TypeCode::Bounds (), - CORBA::PRIVATE_MEMBER); - } - - // Double checked locking... - ACE_GUARD_RETURN (TAO_SYNCH_MUTEX, - guard, - this->private_state_->mutex_, - 0); - - if (this->private_state_->tc_member_visibility_list_known_) - { - return this->private_state_->tc_member_visibility_list_[slot]; - } - - // Set up an encapsulation. - TAO_InputCDR stream (this->buffer_+4, - this->length_-4, - this->byte_order_); - - // Skip rest of header (type ID, name, etc) and collect the - // number of value members. - if (!stream.skip_string () // ID - || !stream.skip_string () // Name - || !stream.skip_ulong () // ValueModifier - || !this->skip_typecode (stream) // Concrete base typecode - || !stream.skip_ulong ()) // Member count - { - ACE_THROW_RETURN (CORBA::BAD_TYPECODE (), - 0); - } - - ACE_NEW_THROW_EX (this->private_state_->tc_member_visibility_list_, - CORBA::Visibility[mcount], - CORBA::NO_MEMORY ()); - ACE_CHECK_RETURN (CORBA::PRIVATE_MEMBER); - - CORBA::Visibility tmp = CORBA::PRIVATE_MEMBER; - - for (CORBA::ULong i = 0; i < mcount; ++i) - { - if (!stream.skip_string () // Member name - || !this->skip_typecode (stream) // Member TypeCode - || !stream.read_short (tmp)) // Read the member visibility - { - ACE_THROW_RETURN (CORBA::BAD_TYPECODE (), - 0); - } - - this->private_state_->tc_member_visibility_list_[i] = tmp; - } - - this->private_state_->tc_member_visibility_list_known_ = 1; - return this->private_state_->tc_member_visibility_list_[slot]; -} - -CORBA::ValueModifier -CORBA::TypeCode::private_type_modifier (ACE_ENV_SINGLE_ARG_DECL) const -{ - if (this->kind_ != CORBA::tk_value - && this->kind_ != CORBA::tk_event) - { - ACE_THROW_RETURN (CORBA::TypeCode::BadKind (), - 0); - } - - // Double checked locking... - ACE_GUARD_RETURN (TAO_SYNCH_MUTEX, - guard, - this->private_state_->mutex_, - 0); - - if (this->private_state_->tc_type_modifier_known_) - { - return this->private_state_->tc_type_modifier_; - } - - // Set up an encapsulation. - TAO_InputCDR stream (this->buffer_+4, - this->length_-4, - this->byte_order_); - - // Skip rest of header (type ID, name, etc) and collect the - // number of value members. - if (!stream.skip_string () // ID - || !stream.skip_string ()) // Name - { - ACE_THROW_RETURN (CORBA::BAD_TYPECODE (), - 0); - } - - if (!stream.read_short (this->private_state_->tc_type_modifier_)) - { - ACE_THROW_RETURN (CORBA::BAD_TYPECODE (), - 0); - } - - this->private_state_->tc_type_modifier_known_ = 1; - return this->private_state_->tc_type_modifier_; -} - -CORBA::TypeCode_ptr -CORBA::TypeCode::private_concrete_base_type (ACE_ENV_SINGLE_ARG_DECL) const -{ - if (this->kind_ != CORBA::tk_value - && this->kind_ != CORBA::tk_event) - { - ACE_THROW_RETURN (CORBA::TypeCode::BadKind (), - CORBA::TypeCode::_nil ()); - } - - // Double checked locking... - ACE_GUARD_RETURN (TAO_SYNCH_MUTEX, - guard, - this->private_state_->mutex_, - CORBA::TypeCode::_nil ()); - - if (this->private_state_->tc_concrete_base_type_known_) - { - return this->private_state_->tc_concrete_base_type_; - } - - // Set up an encapsulation. - TAO_InputCDR stream (this->buffer_+4, - this->length_-4, - this->byte_order_); - - // Skip rest of header (type ID, name, etc) and collect the - // number of value members. - if (!stream.skip_string () // ID - || !stream.skip_string () // Name - || !stream.skip_ulong ()) // ValueModifier - { - ACE_THROW_RETURN (CORBA::BAD_TYPECODE (), - CORBA::TypeCode::_nil ()); - } - - // Retrieve the concrete base typecode. - CORBA::TypeCode::_tao_decode (this, - stream, - this->private_state_->tc_concrete_base_type_ - ACE_ENV_ARG_PARAMETER); - ACE_CHECK_RETURN (CORBA::TypeCode::_nil ()); - - this->private_state_->tc_concrete_base_type_known_ = 1; - return this->private_state_->tc_concrete_base_type_; -} - -// **************************************************************** - -void -CORBA::TypeCode::_tao_decode (const CORBA::TypeCode *parent, - TAO_InputCDR &cdr, - CORBA::TypeCode *&x - ACE_ENV_ARG_DECL) -{ - x = 0; - CORBA::ULong kind; - - if (!cdr.read_ulong (kind)) - { - ACE_THROW (CORBA::BAD_TYPECODE ()); - } - - static CORBA::TypeCode_ptr tc_consts [CORBA::TC_KIND_COUNT] = - { - CORBA::_tc_null, - CORBA::_tc_void, - CORBA::_tc_short, - CORBA::_tc_long, - CORBA::_tc_ushort, - - CORBA::_tc_ulong, - CORBA::_tc_float, - CORBA::_tc_double, - CORBA::_tc_boolean, - CORBA::_tc_char, - - CORBA::_tc_octet, - CORBA::_tc_any, - CORBA::_tc_TypeCode, - CORBA::_tc_Principal, - - 0, // CORBA::_tc_Object ... type ID is CORBA::Object - 0, // CORBA::tk_struct - 0, // CORBA::tk_union - 0, // CORBA::tk_enum - 0, // CORBA::_tc_string ... unbounded - 0, // CORBA::tk_sequence - 0, // CORBA::tk_array - 0, // CORBA::tk_alias - 0, // CORBA::tk_except - - CORBA::_tc_longlong, - CORBA::_tc_ulonglong, - CORBA::_tc_longdouble, - CORBA::_tc_wchar, - - 0, // CORBA::_tc_wstring ... unbounded - 0, // CORBA::tk_fixed - 0, // CORBA::tk_value - 0, // CORBA::tk_value_box: - 0, // CORBA::tk_native: - 0, // CORBA::tk_abstract_interface: - 0, // CORBA::tk_local_interface: - 0, // CORBA::tk_component: - 0, // CORBA::tk_home: - 0 // CORBA::tk_event: - }; - - if (kind < CORBA::TC_KIND_COUNT && tc_consts [kind] != 0) - { - // Easy case, the CDR contains no more data, and we can simply - // duplicate one of the TypeCode constants... - x = CORBA::TypeCode::_duplicate (tc_consts [kind]); - return; - } - - if (kind != ~0u && kind >= CORBA::TC_KIND_COUNT) - { - // Invalid kind.... cannot even determine what portion of the - // CDR corresponds to the typecode.... - ACE_THROW (CORBA::BAD_TYPECODE ()); - } - - if (kind == ~0u) - { - // Get the long indicating the encapsulation offset, - // then set up indirection stream that's like "stream" - // but has space enough only for the typecode and the - // length for the encapsulated parameters. - // - // The offset must be negative - CORBA::Long offset; - - if (!cdr.read_long (offset) || offset >= 0) - { - // Since indirected typecodes cannot occur at the - // topmost level, they can occur starting only at the - // second and subsequent levels. This means that a - // normal encoding of that typecode occurred somewhere - // before in the stream. As a result the offset field - // must always be negative. See the CORBA spec for details. - ACE_THROW (CORBA::BAD_TYPECODE ()); - } - - // Slava Galperin <galperin@teknowledge.com> clarifies - // this: - // CORBA Spec says: - // - // The encoding of such an indirection is as a - // TypeCode with a TCKind value that has the special - // value 2^32 -1 (0xffffffff, all ones). Such - // typecodes have a single (simple) parameter, which - // is the long offset (in units of octets) from the - // simple parameter. (This means that an offset of - // negative four (-4) is illegal because it will be - // self-indirecting.) - // (CORBA V2.2 CDR Transfer Syntax February 1998 page 13-17) - // - // This apparently assumes offset from the <em> - // beginning </em> of the simple parameter. - // [Right, because otherwise the value -8 would be - // illegal] - // Because at this point stream is positioned after - // the parameter, we need to account for that when - // constructing indir_stream by subtracting 4 (length - // of the offset parameter itself). - - // TAO_InputCDR indir_stream (*stream, 8, offset - // - 4); - ACE_Message_Block *mb = (ACE_Message_Block *)cdr.start (); - TAO_InputCDR indir_stream (mb->rd_ptr () + offset - 4, - -1 * (offset - 4), - cdr.byte_order ()); - - if (!indir_stream.good_bit ()) - { - ACE_THROW (CORBA::BAD_TYPECODE ()); - } - - // Get "kind" and length of target typecode - // - // XXX this currently assumes the TCKind to which we - // indirect is the same byte order as the "parent" - // typecode -- not the right assumption; see how the - // TypeCode interpreter does it. - - CORBA::ULong indir_kind = 0; - CORBA::ULong indir_len = 0; - - if (!indir_stream.read_ulong (indir_kind) - || indir_kind >= CORBA::TC_KIND_COUNT // no double indirections - || !indir_stream.read_ulong (indir_len)) - { - ACE_THROW (CORBA::BAD_TYPECODE ()); - } - - // Now construct indirected typecode. This shares the - // typecode octets with the "parent" typecode, - // increasing the amount of memory sharing and - // reducing the cost of getting typecodes. - ACE_NEW (x, - CORBA::TypeCode ((CORBA::TCKind) indir_kind, - indir_len, - indir_stream.rd_ptr(), - 0, - 0, - // @@ TODO - // Here we lose the parent - // typecode... - const_cast <CORBA::TypeCode*> (parent))); - return; - } - - // The other cases.... - switch (kind) - { - default: - ACE_THROW (CORBA::INTERNAL ()); - - // Some have "simple" parameter lists ... some of these - // also have preallocated constants that could be used. - case CORBA::tk_string: - case CORBA::tk_wstring: - { - CORBA::ULong bound; - - if (!cdr.read_ulong (bound)) - { - ACE_THROW (CORBA::BAD_TYPECODE ()); - } - - if (bound == 0) - { - // unbounded string. Let us reuse the ORB owned - // _tc_string or _tc_wstring - if (kind == CORBA::tk_string) - { - x = CORBA::TypeCode::_duplicate (CORBA::_tc_string); - } - else - { - x = CORBA::TypeCode::_duplicate (CORBA::_tc_wstring); - } - } - else - { - // bounded string. Create a TypeCode. If it is does not - // have a parent, then the application must free it. - - // allocate a new TypeCode - - // This may produce a memory leak, because - // callers are sloppy about removing these - // objects. - CORBA::Long _oc_bounded_string [] = - {TAO_ENCAP_BYTE_ORDER, 0}; - // Bounded string. Save the bounds - _oc_bounded_string [1] = static_cast <CORBA::Long> (bound); - ACE_NEW (x, - CORBA::TypeCode ( - static_cast <CORBA::TCKind> (kind), - 8, - reinterpret_cast <char*> (_oc_bounded_string), - 0, - sizeof (CORBA::String_var), - 0 - )); - } - } - break; - - // The rest have "complex" parameter lists that are - // encoded as bulk octets ... - case CORBA::tk_objref: - case CORBA::tk_struct: - case CORBA::tk_union: - case CORBA::tk_enum: - case CORBA::tk_sequence: - case CORBA::tk_array: - case CORBA::tk_alias: - case CORBA::tk_except: - case CORBA::tk_value: - case CORBA::tk_value_box: - case CORBA::tk_native: - case CORBA::tk_abstract_interface: - case CORBA::tk_local_interface: - case CORBA::tk_component: - case CORBA::tk_home: - case CORBA::tk_event: - { - CORBA::ULong length; - - // get the encapsulation length - if (!cdr.read_ulong (length)) - { - ACE_THROW (CORBA::BAD_TYPECODE ()); - } - - // If the length is greater that the containing CDR stream - // that is an error... - if (length > cdr.length ()) - { - ACE_THROW (CORBA::BAD_TYPECODE ()); - } - - // create a new typecode - ACE_NEW (x, - CORBA::TypeCode ((CORBA::TCKind) kind, - length, - cdr.rd_ptr (), - 0, - 0, - const_cast <CORBA::TypeCode*> (parent))); - // skip length number of bytes in the stream, otherwise we may - // leave the stream in an undefined state - (void) cdr.skip_bytes (length); - } - break; - } // end of switch -} - -// **************************************************************** - -CORBA::TypeCode_ptr -CORBA::TypeCode::unalias (ACE_ENV_SINGLE_ARG_DECL) -{ - CORBA::TCKind kind = this->kind (ACE_ENV_SINGLE_ARG_PARAMETER); - ACE_CHECK_RETURN (CORBA::TypeCode::_nil ()); - - CORBA::TypeCode_var tmp = CORBA::TypeCode::_duplicate (this); - - while (kind == CORBA::tk_alias) - { - tmp = tmp->content_type (ACE_ENV_SINGLE_ARG_PARAMETER); - ACE_CHECK_RETURN (CORBA::TypeCode::_nil ()); - - kind = tmp->kind (ACE_ENV_SINGLE_ARG_PARAMETER); - ACE_CHECK_RETURN (CORBA::TypeCode::_nil ()); - } - - return tmp._retn (); -} - -// **************************************************************** - -void -CORBA::TypeCode::_tao_any_destructor (void *x) -{ - CORBA::TypeCode_ptr tmp = static_cast <CORBA::TypeCode_ptr> (x); - CORBA::release (tmp); -} - -// ************ The following are deprecated **************** - -// say how many parameters this typecode has; normally a fixed number, -// some are variable length. -// -// NOTE: This refers to "real" parameters, not what shows up in the -// IFR spec !! That is, "hidden" parameters are counted here, this -// doesn't strictly comply with what CORBA says "param_count" -// provides. - -CORBA::ULong -CORBA::TypeCode::param_count (ACE_ENV_SINGLE_ARG_DECL) const -{ - switch (this->kind_) - { - default: - return 0; - case CORBA::tk_string: - case CORBA::tk_wstring: - return 1; - case CORBA::tk_objref: - case CORBA::tk_sequence: - case CORBA::tk_array: - return 2; - case CORBA::tk_alias: - return 3; - case CORBA::tk_except: - case CORBA::tk_struct: - { - CORBA::ULong members; - TAO_InputCDR stream (this->buffer_+4, - this->length_-4, - this->byte_order_); - - // skip rest of header (type ID and name) and collect the - // number of struct members - if (!stream.skip_string () // ID - || !stream.skip_string () // struct name - || !stream.read_ulong (members)) - { - ACE_THROW_RETURN (CORBA::BAD_TYPECODE (), - 0); - } - - return 3 + 2 * members; - } - case CORBA::tk_enum: - { - CORBA::ULong members; - TAO_InputCDR stream (this->buffer_+4, - this->length_-4, - this->byte_order_); - - // skip rest of header (type ID and name) and collect the - // number of struct members - if (!stream.skip_string () // ID - || !stream.skip_string () // typedef name - || !stream.read_ulong (members)) - { - ACE_THROW_RETURN (CORBA::BAD_TYPECODE (), - 0); - } - - return 3 + members; - } - case CORBA::tk_union: - { - CORBA::ULong members; - TAO_InputCDR stream (this->buffer_+4, - this->length_-4, - this->byte_order_); - - // skip rest of header (type ID, name, etc...) and collect the - // number of struct members - if (!stream.skip_string () // ID - || !stream.skip_string () // struct name - || !this->skip_typecode (stream) // discriminant TC - || !stream.read_ulong (members) // default used - || !stream.read_ulong (members)) // real member count - { - ACE_THROW_RETURN (CORBA::BAD_TYPECODE (), - 0); - } - - return 5 + 3 * members; - } - } -} - -CORBA::Any_ptr -CORBA::TypeCode::parameter (const CORBA::Long /* slot */ - ACE_ENV_ARG_DECL) -{ - ACE_THROW_RETURN (CORBA::NO_IMPLEMENT (0, - CORBA::COMPLETED_NO), - 0); -} - -// ========================================================= -// Traits specializations for CORBA::TypeCode. -namespace TAO -{ - CORBA::TypeCode_ptr - Objref_Traits<CORBA::TypeCode>::duplicate (CORBA::TypeCode_ptr p) - { - return CORBA::TypeCode::_duplicate (p); - } - - void - Objref_Traits<CORBA::TypeCode>::release (CORBA::TypeCode_ptr p) - { - CORBA::release (p); - } - - CORBA::TypeCode_ptr - Objref_Traits<CORBA::TypeCode>::nil (void) - { - return CORBA::TypeCode::_nil (); - } - - CORBA::Boolean - Objref_Traits<CORBA::TypeCode>::marshal (CORBA::TypeCode_ptr p, - TAO_OutputCDR & cdr) - { - return cdr << p; - } -} - -// **************************************************************** - -CORBA::Boolean -operator<< (TAO_OutputCDR& cdr, const CORBA::TypeCode *x) -{ - if (x == 0) - { - ACE_DECLARE_NEW_CORBA_ENV; - ACE_THROW_RETURN (CORBA::MARSHAL (0, - CORBA::COMPLETED_MAYBE), - 0); - } - - CORBA::ULong kind = - x->kind_; - - if (!cdr.write_ulong (kind)) - { - return 0; - } - - switch (kind) - { - default: - break; - - // Indirected typecodes can occur at "top level" like - // this only when constructing a recursive typecode in the - // TypeCodeFactory. The check for non-null offset map suffices. - case ~0u: - if (x->offset_map () == 0) - { - return 0; - } - - if (!cdr.write_octet_array ((CORBA::Octet*)x->buffer_, - 4)) - { - return 0; - } - - break; - - // A few have "simple" parameter lists - case CORBA::tk_string: - case CORBA::tk_wstring: - { - ACE_TRY_NEW_ENV - { - CORBA::ULong length = - x->length (ACE_ENV_SINGLE_ARG_PARAMETER); - ACE_TRY_CHECK; - - if (!cdr.write_ulong (length)) - { - return 0; - } - } - ACE_CATCHANY - { - return 0; - } - ACE_ENDTRY; - } - break; - - // The rest have "complex" parameter lists that are - // already encoded as bulk octets ... put length, then - // octets. - case CORBA::tk_objref: - case CORBA::tk_struct: - case CORBA::tk_union: - case CORBA::tk_enum: - case CORBA::tk_sequence: - case CORBA::tk_array: - case CORBA::tk_alias: - case CORBA::tk_except: - case CORBA::tk_value: - case CORBA::tk_value_box: - case CORBA::tk_native: - case CORBA::tk_abstract_interface: - case CORBA::tk_local_interface: - case CORBA::tk_component: - case CORBA::tk_home: - case CORBA::tk_event: - { - CORBA::ULong xlen = static_cast <CORBA::ULong> (x->length_); - if (!cdr.write_ulong (xlen) - || !cdr.write_octet_array ((CORBA::Octet*) x->buffer_, - xlen)) - { - return 0; - } - } - break; - } - - return 1; -} - -CORBA::Boolean -operator>> (TAO_InputCDR& cdr, CORBA::TypeCode *&x) -{ - ACE_TRY_NEW_ENV - { - CORBA::TypeCode::_tao_decode (0, - cdr, - x - ACE_ENV_ARG_PARAMETER); - ACE_TRY_CHECK; - } - ACE_CATCHANY - { - return 0; - } - ACE_ENDTRY; - return 1; -} - -#if defined (ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION) - -template class ACE_Hash_Map_Entry<const char *, - ACE_Unbounded_Queue<CORBA::Long> *>; -template class ACE_Hash_Map_Manager_Ex<const char *, - ACE_Unbounded_Queue<CORBA::Long> *, - ACE_Hash<const char *>, - ACE_Equal_To<const char *>, - ACE_Null_Mutex>; -template class - ACE_Hash_Map_Iterator_Base_Ex<const char *, - ACE_Unbounded_Queue<CORBA::Long> *, - ACE_Hash<const char *>, - ACE_Equal_To<const char *>, - ACE_Null_Mutex>; -template class - ACE_Hash_Map_Reverse_Iterator_Ex<const char *, - ACE_Unbounded_Queue<CORBA::Long> *, - ACE_Hash<const char *>, - ACE_Equal_To<const char *>, - ACE_Null_Mutex>; -template class ACE_Hash_Map_Iterator_Ex<const char *, - ACE_Unbounded_Queue<CORBA::Long> *, - ACE_Hash<const char *>, - ACE_Equal_To<const char *>, - ACE_Null_Mutex>; - -template class TAO_Pseudo_Var_T<CORBA::TypeCode>; -template class TAO_Pseudo_Out_T<CORBA::TypeCode, CORBA::TypeCode_var>; - -template class TAO::Objref_Traits<CORBA::TypeCode>; - -template class TAO::Arg_Traits<CORBA::TypeCode>; -template class TAO::Object_Arg_Traits_T<CORBA::TypeCode_ptr, - CORBA::TypeCode_var, - CORBA::TypeCode_out, - TAO::Objref_Traits<CORBA::TypeCode> >; - -template class TAO::Ret_Object_Argument_T<CORBA::TypeCode*, - TAO_Pseudo_Var_T<CORBA::TypeCode> >; - -template class TAO::In_Object_Argument_T<CORBA::TypeCode*>; - -template class - TAO::Inout_Object_Argument_T<CORBA::TypeCode*, - TAO::Objref_Traits<CORBA::TypeCode> >; - -template class - TAO::Out_Object_Argument_T< - CORBA::TypeCode*, - TAO_Pseudo_Out_T<CORBA::TypeCode, - TAO_Pseudo_Var_T<CORBA::TypeCode> - > >; - -#if 0 -template class TAO::SArg_Traits<CORBA::TypeCode>; -template class TAO::Object_SArg_Traits_T<CORBA::TypeCode_ptr, - CORBA::TypeCode_var, - CORBA::TypeCode_out>; -template class TAO::In_Object_SArgument_T<CORBA::TypeCode_ptr, - CORBA::TypeCode_var>; -template class TAO::Inout_Object_SArgument_T<CORBA::TypeCode_ptr, - CORBA::TypeCode_var>; -template class TAO::Out_Object_SArgument_T<CORBA::TypeCode_ptr, - CORBA::TypeCode_var, - CORBA::TypeCode_out>; -template class TAO::Ret_Object_SArgument_T<CORBA::TypeCode_ptr, - CORBA::TypeCode_var>; -#endif /*if 0*/ -#elif defined (ACE_HAS_TEMPLATE_INSTANTIATION_PRAGMA) - -#pragma instantiate ACE_Hash_Map_Entry<const char *, \ - ACE_Unbounded_Queue<CORBA::Long> *> -#pragma instantiate \ - ACE_Hash_Map_Manager_Ex<const char *, \ - ACE_Unbounded_Queue<CORBA::Long> *, \ - ACE_Hash<const char *>, \ - ACE_Equal_To<const char *>, \ - ACE_Null_Mutex> -#pragma instantiate \ - ACE_Hash_Map_Iterator_Base_Ex<const char *, \ - ACE_Unbounded_Queue<CORBA::Long> *, \ - ACE_Hash<const char *>, \ - ACE_Equal_To<const char *>, \ - ACE_Nullv_Mutex> -#pragma instantiate \ - ACE_Hash_Map_Reverse_Iterator_Ex<const char *, \ - ACE_Unbounded_Queue<CORBA::Long> *, \ - ACE_Hash<const char *>, \ - ACE_Equal_To<const char *>, \ - ACE_Null_Mutex> -#pragma instantiate \ - ACE_Hash_Map_Iterator_Ex<const char *, \ - ACE_Unbounded_Queue<CORBA::Long> *, \ - ACE_Hash<const char *>, \ - ACE_Equal_To<const char *>, \ - ACE_Null_Mutex> - -#pragma instantiate TAO_Pseudo_Var_T<CORBA::TypeCode> -#pragma instantiate TAO_Pseudo_Out_T<CORBA::TypeCode, CORBA::TypeCode_var> - -#pragma instantiate TAO::Objref_Traits<CORBA::TypeCode> -#pragma instantiate TAO::Arg_Traits<CORBA::TypeCode> -#pragma instantiate \ - TAO::Object_Arg_Traits_T<CORBA::TypeCode_ptr, \ - CORBA::TypeCode_var, \ - CORBA::TypeCode_out, \ - TAO::Objref_Traits<CORBA::TypeCode> > -#pragma instantiate TAO::In_Object_Argument_T<CORBA::TypeCode_ptr> -#pragma instantiate \ - TAO::Inout_Object_Argument_T<CORBA::TypeCode_ptr, \ - TAO::Objref_Traits<CORBA::TypeCode> > -#pragma instantiate TAO::Out_Object_Argument_T<CORBA::TypeCode_ptr, \ - CORBA::TypeCode_out> -#pragma instantiate TAO::Ret_Object_Argument_T<CORBA::TypeCode_ptr, \ - CORBA::TypeCode_var> - -#pragma instantiate TAO::SArg_Traits<CORBA::TypeCode> -#pragma instantiate TAO::Object_SArg_Traits_T<CORBA::TypeCode_ptr, \ - CORBA::TypeCode_var, \ - CORBA::TypeCode_out> -#pragma instantiate TAO::In_Object_SArgument_T<CORBA::TypeCode_ptr, \ - CORBA::TypeCode_var> -#pragma instantiate TAO::Inout_Object_SArgument_T<CORBA::TypeCode_ptr, \ - CORBA::TypeCode_var> -#pragma instantiate TAO::Out_Object_SArgument_T<CORBA::TypeCode_ptr, \ - CORBA::TypeCode_var, \ - CORBA::TypeCode_out> -#pragma instantiate TAO::Ret_Object_SArgument_T<CORBA::TypeCode_ptr, \ - CORBA::TypeCode_var> - -#pragma instantiate TAO::Ret_Object_Argument_T<CORBA::TypeCode*, - TAO_Pseudo_Var_T<CORBA::TypeCode> > - -#pragma instantiate TAO::In_Object_Argument_T<CORBA::TypeCode*> - -#pragma instantiate TAO::Inout_Object_Argument_T<CORBA::TypeCode*, - TAO::Objref_Traits<CORBA::TypeCode> > - -#pragma instantiate TAO::Out_Object_Argument_T<CORBA::TypeCode*, - TAO_Pseudo_Out_T<CORBA::TypeCode, - TAO_Pseudo_Var_T<CORBA::TypeCode> > > - -#endif /* ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION */ diff --git a/TAO/tao/Typecode.h b/TAO/tao/Typecode.h deleted file mode 100644 index 2742445fa66..00000000000 --- a/TAO/tao/Typecode.h +++ /dev/null @@ -1,661 +0,0 @@ -// This may look like C, but it's really -*- C++ -*- - -//============================================================================= -/** - * @file Typecode.h - * - * $Id$ - * - * Header file CORBA's "TypeCode" type. - * - * @author Copyright 1994-1995 by Sun Microsystems, Inc. - * @author DOC group at Wash U, UCI and Vanderbilt U. - */ -//============================================================================= - -#ifndef TAO_TYPECODE_H -#define TAO_TYPECODE_H - -#include /**/ "ace/pre.h" - -#include "ace/Thread_Mutex.h" - -#if !defined (ACE_LACKS_PRAGMA_ONCE) -# pragma once -#endif /* ACE_LACKS_PRAGMA_ONCE */ - -#include "ace/Hash_Map_Manager_T.h" -#include "ace/Unbounded_Queue.h" - -#include "tao/UserException.h" -#include "tao/Environment.h" -#include "tao/Pseudo_VarOut_T.h" -#include "tao/Objref_VarOut_T.h" -#include "tao/Object_Argument_T.h" -#include "tao/Arg_Traits_T.h" -#include "tao/TC_Constants_Forward.h" -#include "tao/VisibilityC.h" -#include "tao/CORBA_methods.h" -#include "tao/Sequence_T.h" -#include "tao/Typecode_typesC.h" -#include "tao/TAO_Export.h" - -// Forward declarations. -class TAO_InputCDR; -class TAO_OutputCDR; - -namespace TAO -{ - class TC_Private_State; -} - -namespace CORBA -{ - class TypeCode; - typedef TypeCode *TypeCode_ptr; - - typedef TAO_Pseudo_Var_T<TypeCode> TypeCode_var; - typedef TAO_Pseudo_Out_T<TypeCode, TypeCode_var> TypeCode_out; - - /** - * @class TypeCode - * - * @brief The CORBA TypeCode class. It maintains the in-memory - * representation of any OMG CORBA IDL data type. - * - * Implements the CORBA::TypeCode interface specified by CORBA 2.0 - * spec. Typecodes essentially consist of just the CDR octets - * that get marshaled and unmarshaled, and this code knows how to - * parse those octets and answer questions CORBA's TypeCode APIs - * require. - * @par - * A TypeCode describes data. This one's as thin a wrapper around - * CDR octet sequences as is practical. There are guesses here - * about how the OMG C++ mapping and CORBA 2.0 IfR specification - * will interact. - * - * @note Use TypeCode_ptr, except in code (e.g. output of and - * OMG-IDL / compiler) that needs to create typecodes from - * their octet-sequence encodings. - * - * @note This isn't well tuned performance-wise. Given how much is - * variable (byte order, alignment) it's clear tuning has its - * limits with respect to CDR bytecode interpretation. - * - * - * @note (THREADING) Typecodes are readonly data structures, and the - * only mutual exclusion relates to reference counting and - * construction. - */ - class TAO_Export TypeCode - { - public: - - // Two "user exceptions" are defined for manipulating TypeCodes. These - // two classes are defined inside the TypeCode class. - class TAO_Export Bounds : public CORBA::UserException - { - public: - Bounds (void); - - static Bounds* _downcast (CORBA::Exception *ex); - static CORBA::Exception *_alloc (void); - - virtual CORBA::Exception *_tao_duplicate (void) const; - - virtual void _raise (void) const; - - virtual void _tao_encode (TAO_OutputCDR &cdr - ACE_ENV_ARG_DECL_NOT_USED) const; - virtual void _tao_decode (TAO_InputCDR &cdr - ACE_ENV_ARG_DECL_NOT_USED); - }; - - class TAO_Export BadKind : public CORBA::UserException - { - public: - BadKind (void); - - static BadKind* _downcast (CORBA::Exception *ex); - static CORBA::Exception *_alloc (void); - - virtual CORBA::Exception *_tao_duplicate (void) const; - - virtual void _raise (void) const; - - virtual void _tao_encode (TAO_OutputCDR &cdr - ACE_ENV_ARG_DECL_NOT_USED) const; - virtual void _tao_decode (TAO_InputCDR &cdr - ACE_ENV_ARG_DECL_NOT_USED); - }; - - static CORBA::TypeCode_ptr _tc_Bounds; - static CORBA::TypeCode_ptr _tc_BadKind; - - /// Duplicates i.e., increments ref count. - static CORBA::TypeCode_ptr _duplicate (CORBA::TypeCode_ptr tc); - - /// Returns a NULL typecode. - static CORBA::TypeCode_ptr _nil (void); - - /// Compares two typecodes. Must be identical in every respect. - CORBA::Boolean equal (CORBA::TypeCode_ptr - ACE_ENV_ARG_DECL_WITH_DEFAULTS) const; - - /// Conforms to CORBA 2.3.1 (99-10-07). - CORBA::Boolean equivalent (CORBA::TypeCode_ptr - ACE_ENV_ARG_DECL_WITH_DEFAULTS) const; - - /// For all TypeCode kinds, returns the "kind" of the typecode. - CORBA::TCKind kind (ACE_ENV_SINGLE_ARG_DECL_WITH_DEFAULTS) const; - - /// For tk_{objref,struct,union,enum,alias,except}. Returns the - /// repository ID, raises BadKind. - const char *id (ACE_ENV_SINGLE_ARG_DECL_WITH_DEFAULTS) const; - - /// Returns name (), raises (BadKind). - const char *name (ACE_ENV_SINGLE_ARG_DECL_WITH_DEFAULTS) const; - - /// Returns member_count (), raises (BadKind). Useful for tk_struct, - /// tk_union, tk_enum, tk_alias, and tk_except. - CORBA::ULong member_count (ACE_ENV_SINGLE_ARG_DECL_WITH_DEFAULTS) const; - - /// Returns member_name (...), raises (BadKind, Bounds); Useful for - /// tk_struct, tk_union, tk_enum, tk_alias, and tk_except. - const char *member_name (CORBA::ULong slot - ACE_ENV_ARG_DECL_WITH_DEFAULTS) const; - - /// Returns member_type (...), raises (BadKind, Bounds); Useful for - /// tk_struct, tk_union, and tk_except. - CORBA::TypeCode_ptr member_type (CORBA::ULong slot - ACE_ENV_ARG_DECL_WITH_DEFAULTS) const; - - /// For tk_union. Returns the label. Raises BadKind, Bounds. - CORBA::Any_ptr member_label (CORBA::ULong n - ACE_ENV_ARG_DECL_WITH_DEFAULTS) const; - - /// Returns the discriminator type for tk_union. raises (BadKind). - CORBA::TypeCode_ptr discriminator_type ( - ACE_ENV_SINGLE_ARG_DECL_WITH_DEFAULTS) const; - - /// Returns the default slot for the tk_union. Raises (BadKind). - CORBA::Long default_index (ACE_ENV_SINGLE_ARG_DECL_WITH_DEFAULTS) const; - - /// Returns length, raises (BadKind). Used for tk_string, - /// tk_sequence, and tk_array. - CORBA::ULong length (ACE_ENV_SINGLE_ARG_DECL_WITH_DEFAULTS) const; - - /// Returns the content type (element type). Raises (BadKind); Useful - /// for tk_sequence, tk_array, and tk_alias. - CORBA::TypeCode_ptr content_type ( - ACE_ENV_SINGLE_ARG_DECL_WITH_DEFAULTS) const; - - /// These just throw CORBA::NO_IMPLEMENT. - CORBA::UShort fixed_digits (ACE_ENV_SINGLE_ARG_DECL_WITH_DEFAULTS) const; - CORBA::Short fixed_scale (ACE_ENV_SINGLE_ARG_DECL_WITH_DEFAULTS) const; - - /// Returns the visibility (public/private) of the member at index - /// 'slot'. Raises (BadKind, Bounds). Useful for tk_value only. - CORBA::Visibility member_visibility (CORBA::ULong slot - ACE_ENV_ARG_DECL_WITH_DEFAULTS) const; - - /// Returns the value modifier. Raises (BadKind). Useful for tk_value only. - CORBA::ValueModifier type_modifier ( - ACE_ENV_SINGLE_ARG_DECL_WITH_DEFAULTS) const; - - /// Returns the concrete base type. Raises (BadKind); Useful - /// for tk_value only. - CORBA::TypeCode_ptr concrete_base_type ( - ACE_ENV_SINGLE_ARG_DECL_WITH_DEFAULTS) const; - - // = Creation/refcounting - - // These aren't really public APIs, but an IDL compiler will need to - // be able to create TypeCodes as part of creating stubs. - - /// This constructor is used only for built-in TypeCode constants, - /// with no parameters. - TypeCode (CORBA::TCKind kind); - - /** - * This constructor is used both for typecode constants and for - * heap-allocated TypeCodes. The two are distinguished by the - * orb_owns_tc flag passed in by the creator. - * - * For simple param lists with a single numeric parameter, only - * 'length' matters. - * - * For complex param lists, or simple param lists for which the - * parameter is a string or typecode, length _and_ buffer matter. - * - * For typecodes that are precomputed from the encapsulation stream - * of the parent, even the "parent" argument matters because this - * implies that all children will share the octet buffers of its - * parent - */ - TypeCode (CORBA::TCKind kind, - size_t length, - const char *buffer, - CORBA::Boolean orb_owns_tc, - CORBA::ULong size, - CORBA::TypeCode_ptr parent = 0); - - /// destructor - ~TypeCode (void); - - /// These are used to indicate the status of marshaling. - // Reference counting operations. - CORBA::ULong _incr_refcnt (void); - CORBA::ULong _decr_refcnt (void); - - // = Following three are deprecated - - // The following are deprecated in the CORBA 2.2 spec and are - // missing altogether from 2.3a (98-12-04), but they are included - // here as no-ops so legacy apps won't completely break. They - // throw CORBA::NO_IMPLEMENT. - - /// Deprecated in the CORBA 2.2 spec and - /// missing altogether from 2.3a (98-12-04), - CORBA::Any_ptr parameter (const CORBA::Long slot - ACE_ENV_ARG_DECL_WITH_DEFAULTS); - - /// Deprecated, CORBA 1.2, not fully usable. Returns the number of - /// parameters that the typecode takes. - CORBA::ULong param_count (ACE_ENV_SINGLE_ARG_DECL_WITH_DEFAULTS) const; - - /// CDR decoding: the >> operator is not enough because we must also - /// respect the parent/child relationship among TypeCodes. - static void _tao_decode (const TypeCode *parent, - TAO_InputCDR &cdr, - TypeCode *&child - ACE_ENV_ARG_DECL); - - /// Strip away all typedefs, if any. - TypeCode_ptr unalias (ACE_ENV_SINGLE_ARG_DECL); - - // private: - // - // = The guts of the typecode implementation class - - // This is implemented as a counted set of bytes, in marshaled CDR - // format. - - /// length of the encapsulated stream - size_t length_; - - /// the encapsulated stream - const char* buffer_; - - /// The byte order in the encapsulated stream. - CORBA::Long byte_order_; - - /// the TypeCode kind - CORBA::Long kind_; - - /** - * Indirected typecodes share "buffer" with a parent, and hold a - * reference to that parent to ensure its memory is not freed - * inappropriately. - */ - CORBA::TypeCode_ptr parent_; - - /** - * my typecode base. Notice that the buffer_ member points to my - * encapsulation. However, for indirected typecodes, the offsets - * will point to my tk_kind field which should be pointed to be - * tc_base_. - */ - const char *tc_base_; - - /** - * base of the topmost level typecode. Applicable only if I have - * any parents, else it is the same as tc_base. This helps in case - * we have indirections and we need to traverse beyond - * encapsulation boundaries. - */ - const char *root_tc_base_; - - /// Used in our destruction when we are in an Any. - static void _tao_any_destructor (void *); - - /// skip a typecode encoding in a given CDR stream. This is just a - /// helper function. - static CORBA::Boolean skip_typecode (TAO_InputCDR &stream); - - typedef ACE_Unbounded_Queue<CORBA::Long> OFFSET_LIST; - typedef ACE_Unbounded_Queue_Iterator<CORBA::Long> OFFSET_LIST_ITERATOR; - typedef ACE_Hash_Map_Entry<const char *, OFFSET_LIST *> OFFSET_MAP_ENTRY; - typedef ACE_Hash_Map_Manager_Ex<const char *, - OFFSET_LIST *, - ACE_Hash<const char *>, - ACE_Equal_To<const char *>, - ACE_Null_Mutex> - OFFSET_MAP; - - typedef ACE_Hash_Map_Iterator_Ex<const char *, - OFFSET_LIST *, - ACE_Hash<const char *>, - ACE_Equal_To<const char *>, - ACE_Null_Mutex> - OFFSET_MAP_ITERATOR; - - OFFSET_MAP *offset_map (void) const; - void offset_map (OFFSET_MAP *new_map); - - typedef CORBA::TypeCode_ptr _ptr_type; - typedef CORBA::TypeCode_var _var_type; - // Useful for template programming. - - private: - // = All the private/helper methods - - /** - * equal() and equivalent() must both recurse, but their - * behavior is somewhat different (as defined in CORBA 2.3). - * This function allows us to reuse the same code by acting - * as the point of recursion and by adding the equiv_only - * flag, to differentiate the behavior where necessary. - */ - CORBA::Boolean equ_common (CORBA::TypeCode_ptr tc, - CORBA::Boolean equiv_only - ACE_ENV_ARG_DECL) const; - - /// Compares the typecodes. - CORBA::Boolean private_equal (CORBA::TypeCode_ptr tc, - CORBA::Boolean equiv_only - ACE_ENV_ARG_DECL) const; - - /// For tk_{objref,struct,union,enum,alias,except}. Returns the - /// repository ID, raises BadKind. - const char *private_id (ACE_ENV_SINGLE_ARG_DECL) const; - - /// returns name (), raises (BadKind) - const char *private_name (ACE_ENV_SINGLE_ARG_DECL) const; - - /// returns member_count (), raises (BadKind). Useful for tk_struct, - /// tk_union, tk_enum, tk_alias, and tk_except. - CORBA::ULong private_member_count ( - ACE_ENV_SINGLE_ARG_DECL) const; - - /// returns member_type (...), raises (BadKind, Bounds); Useful for - /// tk_struct, tk_union, and tk_except - CORBA::TypeCode_ptr private_member_type ( - CORBA::ULong slot - ACE_ENV_ARG_DECL - ) const; - - /// returns member_name (...), raises (BadKind, Bounds); Useful for - /// tk_union, tk_struct, tk_except, and tk_enum - const char *private_member_name (CORBA::ULong slot - ACE_ENV_ARG_DECL) const; - - /// For tk_union. Returns the label. Raises BadKind, Bounds. - CORBA::Any_ptr private_member_label (CORBA::ULong n - ACE_ENV_ARG_DECL) const; - - /// returns the discriminator type for tk_union, and acquires the lock - /// for the wrapped function below. raises (BadKind) - CORBA::TypeCode_ptr private_discriminator_type ( - ACE_ENV_SINGLE_ARG_DECL - ) const; - - /// Acquires no lock so it can be called internally from blocks - /// which have a lock. - CORBA::TypeCode_ptr private_discriminator_type_i ( - ACE_ENV_SINGLE_ARG_DECL - ) const; - - /// returns the default slot for the tk_union. Raises (BadKind); - CORBA::Long private_default_index ( - ACE_ENV_SINGLE_ARG_DECL) const; - - /// Acquires no lock so it can be called internally from blocks - /// which have a lock. - CORBA::Long private_default_index_i ( - ACE_ENV_SINGLE_ARG_DECL) const; - - /// Returns length, raises (BadKind). Used for tk_string, - /// tk_sequence, and tk_array. - CORBA::Long private_length (ACE_ENV_SINGLE_ARG_DECL) const; - - /// Returns the content type (element type). Raises (BadKind); Useful - /// for tk_sequence, tk_array, and tk_alias. - CORBA::TypeCode_ptr private_content_type ( - ACE_ENV_SINGLE_ARG_DECL - ) const; - - /// Returns the visibility (public/private) of the member at index - /// 'slot'. Raises (BadKind, Bounds). Useful for tk_value only. - CORBA::Visibility private_member_visibility (CORBA::ULong slot - ACE_ENV_ARG_DECL) const; - - /// Returns the value modifier. Raises (BadKind). Useful for - /// tk_value only. - CORBA::ValueModifier private_type_modifier ( - ACE_ENV_SINGLE_ARG_DECL - ) const; - - /// Returns the concrete base type. Raises (BadKind). Useful for - /// tk_value only. - CORBA::TypeCode_ptr private_concrete_base_type ( - ACE_ENV_SINGLE_ARG_DECL - ) const; - - // = All the private helpers testing for equality of typecodes - - /// test equality for typecodes of objrefs - CORBA::Boolean private_equal_objref (CORBA::TypeCode_ptr tc, - CORBA::Boolean equiv_only - ACE_ENV_ARG_DECL) const; - - /// test equality for typecodes of structs - CORBA::Boolean private_equal_struct (CORBA::TypeCode_ptr tc, - CORBA::Boolean equiv_only - ACE_ENV_ARG_DECL) const; - - /// test equality for typecodes of unions - CORBA::Boolean private_equal_union (CORBA::TypeCode_ptr tc, - CORBA::Boolean equiv_only - ACE_ENV_ARG_DECL) const; - - /// test equality for typecodes of enums - CORBA::Boolean private_equal_enum (CORBA::TypeCode_ptr tc, - CORBA::Boolean equiv_only - ACE_ENV_ARG_DECL) const; - - /// test equality for typecodes of strings - CORBA::Boolean private_equal_string (CORBA::TypeCode_ptr tc, - CORBA::Boolean equiv_only - ACE_ENV_ARG_DECL) const; - - /// test equality for typecodes of wide strings - CORBA::Boolean private_equal_wstring (CORBA::TypeCode_ptr tc, - CORBA::Boolean equiv_only - ACE_ENV_ARG_DECL) const; - - /// test equality for typecodes of sequences - CORBA::Boolean private_equal_sequence (CORBA::TypeCode_ptr tc, - CORBA::Boolean equiv_only - ACE_ENV_ARG_DECL) const; - - /// test equality for typecodes of array - CORBA::Boolean private_equal_array (CORBA::TypeCode_ptr tc, - CORBA::Boolean equiv_only - ACE_ENV_ARG_DECL) const; - - /// test equality for typecodes of typedefs - CORBA::Boolean private_equal_alias (CORBA::TypeCode_ptr tc, - CORBA::Boolean equiv_only - ACE_ENV_ARG_DECL) const; - - /// test equality for typecodes of exceptions - CORBA::Boolean private_equal_except (CORBA::TypeCode_ptr tc, - CORBA::Boolean equiv_only - ACE_ENV_ARG_DECL) const; - - /// test equality for typecodes of exceptions - CORBA::Boolean private_equal_valuetype (CORBA::TypeCode_ptr tc, - CORBA::Boolean equiv_only - ACE_ENV_ARG_DECL) const; - - private: - - // = No copy constructor or assignment operator supported; - - // Use TypeCode_ptr values, duplicate (), release (). - TypeCode (const CORBA::TypeCode &src); - TypeCode &operator = (const CORBA::TypeCode &src); - - private: - - /// if refcount reaches 0, free this typecode - CORBA::ULong refcount_; - - /// Protect the reference count, this is OK because we do no - /// duplicates or releases on the critical path. - TAO_SYNCH_MUTEX refcount_lock_; - - /// TAO's approach differs from the SunSoft IIOP. Constant - /// TypeCodes are owned by the ORB and get freed only when the ORB - /// dies. - /** - * If "orb_owns" is false, the value is a not a constant typecode - * with both the typecode and the buffer allocated (typically, - * this will be created by the IDL compiler generated code) - */ - CORBA::Boolean orb_owns_; - - /** - * maintains precomputed state. We need a separate class that - * maintains the precomputed state since most of the TypeCode class - * operations keep the state of the object constant. However, for - * the purpose of precomputation, we need to update the state. We - * cannot update state directly in the TypeCode class as that - * defeats the constness. However, we can keep an object in our - * typecode class that remains constant, but we can update its - * state. - */ - TAO::TC_Private_State *private_state_; - - /** - * Original buffer that may possibly be non-aligned. We still need a - * handle to the allocated memory so that all of it can be freed by - * the destructor. - */ - char *non_aligned_buffer_; - - OFFSET_MAP *offset_map_; - }; -} // End CORBA namespace - -// -------------------------------------------------------------- - -namespace TAO -{ - /// Used in generated code if CORBA::TypeCode is an argument or return type. - ACE_TEMPLATE_SPECIALIZATION - class TAO_Export Arg_Traits<CORBA::TypeCode> - : public Object_Arg_Traits_T<CORBA::TypeCode_ptr, - CORBA::TypeCode_var, - CORBA::TypeCode_out, - TAO::Objref_Traits<CORBA::TypeCode> > - { - }; - - ACE_TEMPLATE_SPECIALIZATION - struct TAO_Export Objref_Traits< ::CORBA::TypeCode> - { - static ::CORBA::TypeCode_ptr duplicate ( - ::CORBA::TypeCode_ptr - ); - static void release ( - ::CORBA::TypeCode_ptr - ); - static ::CORBA::TypeCode_ptr nil (void); - static CORBA::Boolean marshal ( - ::CORBA::TypeCode_ptr p, - TAO_OutputCDR & cdr - ); - }; - - /** - * @class TC_Private_State - * - * @brief Private state of the TypeCode. - * - * Used to store precomputed values - */ - class TC_Private_State - { - public: - /// Constructor. - TC_Private_State (CORBA::TCKind kind); - - /// Destructor. - ~TC_Private_State (void); - - public: - - TAO_SYNCH_MUTEX mutex_; - - /// Our kind that will determine what kind of children we may have - CORBA::TCKind tc_kind_; - - // Data members that indicate if the desired quantity - // was precomputed or not. - CORBA::Boolean tc_id_known_; - CORBA::Boolean tc_name_known_; - CORBA::Boolean tc_member_count_known_; - CORBA::Boolean tc_member_type_list_known_; - CORBA::Boolean tc_member_name_list_known_; - CORBA::Boolean tc_member_label_list_known_; - CORBA::Boolean tc_discriminator_type_known_; - CORBA::Boolean tc_default_index_used_known_; - CORBA::Boolean tc_length_known_; - CORBA::Boolean tc_content_type_known_; - CORBA::Boolean tc_discrim_pad_size_known_; - CORBA::Boolean tc_member_visibility_list_known_; - CORBA::Boolean tc_type_modifier_known_; - CORBA::Boolean tc_concrete_base_type_known_; - - // These data members store the precomputed values. - char *tc_id_; - char *tc_name_; - CORBA::ULong tc_member_count_; - CORBA::TypeCode_ptr *tc_member_type_list_; - char **tc_member_name_list_; - CORBA::Any_ptr *tc_member_label_list_; - CORBA::TypeCode_ptr tc_discriminator_type_; - CORBA::Long tc_default_index_used_; - CORBA::ULong tc_length_; - CORBA::TypeCode_ptr tc_content_type_; - CORBA::Visibility *tc_member_visibility_list_; - CORBA::ValueModifier tc_type_modifier_; - CORBA::TypeCode_ptr tc_concrete_base_type_; - }; -} // End TAO namespace - -// Workaround for a Visual Studio .NET bug where this class is not -// properly imported by an application if typedef'd or subclassed, -// resulting in 'multiply defined' link errors. The export macro -// here forces an explicit import by the application. Please see -// http://support.microsoft.com/default.aspx?scid=kb;en-us;309801 -#if defined ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION_EXPORT - template class TAO_Export TAO_Unbounded_Pseudo_Sequence<CORBA::TypeCode>; -#endif /* ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION_EXPORT */ - -// -------------------------------------------------------------- - -TAO_Export CORBA::Boolean operator<< (TAO_OutputCDR& cdr, - const CORBA::TypeCode *x); -TAO_Export CORBA::Boolean operator>> (TAO_InputCDR& cdr, - CORBA::TypeCode *&x); - -#if defined (__ACE_INLINE__) -# include "tao/Typecode.i" -#endif /* __ACE_INLINE__ */ - -#include /**/ "ace/post.h" - -#endif /* TAO_TYPECODE_H */ diff --git a/TAO/tao/Typecode.i b/TAO/tao/Typecode.i deleted file mode 100644 index 6c6f85e2fd2..00000000000 --- a/TAO/tao/Typecode.i +++ /dev/null @@ -1,133 +0,0 @@ -// -*- C++ -*- -// -// $Id$ - -ACE_INLINE CORBA::ULong -CORBA::TypeCode::_incr_refcnt (void) -{ - ACE_GUARD_RETURN (TAO_SYNCH_MUTEX, guard, this->refcount_lock_, 0); - return this->refcount_++; -} - -ACE_INLINE CORBA::ULong -CORBA::TypeCode::_decr_refcnt (void) -{ - { - ACE_GUARD_RETURN (TAO_SYNCH_MUTEX, guard, this->refcount_lock_, 0); - this->refcount_--; - if (this->refcount_ != 0) - return this->refcount_; - } - delete this; - return 0; -} - -ACE_INLINE CORBA::TypeCode_ptr -CORBA::TypeCode::_duplicate (CORBA::TypeCode_ptr tc) -{ - if (tc) - tc->_incr_refcnt (); - return tc; -} - -ACE_INLINE CORBA::TypeCode_ptr -CORBA::TypeCode::_nil (void) -{ - return (CORBA::TypeCode_ptr)0; -} - -ACE_INLINE CORBA::TCKind -CORBA::TypeCode::kind (ACE_ENV_SINGLE_ARG_DECL_NOT_USED) const -{ - return (CORBA::TCKind) this->kind_; -} - -// Returns true if the two typecodes are equivalent. -ACE_INLINE CORBA::Boolean -CORBA::TypeCode::equivalent (CORBA::TypeCode_ptr tc - ACE_ENV_ARG_DECL) const -{ - return this->equ_common (tc, - 1 - ACE_ENV_ARG_PARAMETER); -} - -// Returns true if the two typecodes are identical. -ACE_INLINE CORBA::Boolean -CORBA::TypeCode::equal (CORBA::TypeCode_ptr tc - ACE_ENV_ARG_DECL) const -{ - return this->equ_common (tc, - 0 - ACE_ENV_ARG_PARAMETER); -} - -// returns the Repository ID -ACE_INLINE const char * -CORBA::TypeCode::id (ACE_ENV_SINGLE_ARG_DECL) const -{ - // if already precomputed - if (this->private_state_->tc_id_known_) - return this->private_state_->tc_id_; - else - return this->private_id (ACE_ENV_SINGLE_ARG_PARAMETER); -} - -// returns the string name -ACE_INLINE const char * -CORBA::TypeCode::name (ACE_ENV_SINGLE_ARG_DECL) const -{ - // if already precomputed - if (this->private_state_->tc_name_known_) - return this->private_state_->tc_name_; - else - return this->private_name (ACE_ENV_SINGLE_ARG_PARAMETER); -} - -// Return the number of members defined by this typecode -// -// Applicable to struct, union, enum, alias, and except -// For the rest of the cases, raises the BadKind exception. - -ACE_INLINE CORBA::ULong -CORBA::TypeCode::member_count (ACE_ENV_SINGLE_ARG_DECL) const -{ - // if already precomputed... - if (this->private_state_->tc_member_count_known_) - { - return this->private_state_->tc_member_count_; - } - else - { - return this->private_member_count (ACE_ENV_SINGLE_ARG_PARAMETER); - } -} - -ACE_INLINE CORBA::TypeCode::OFFSET_MAP * -CORBA::TypeCode::offset_map (void) const -{ - return this->offset_map_; -} - -ACE_INLINE void -CORBA::TypeCode::offset_map (CORBA::TypeCode::OFFSET_MAP *new_map) -{ - this->offset_map_ = new_map; -} - -// ************************************************************ -// These are in CORBA namespace - -ACE_INLINE CORBA::Boolean -CORBA::is_nil (CORBA::TypeCode_ptr obj) -{ - return obj == 0; -} - -ACE_INLINE void -CORBA::release (CORBA::TypeCode_ptr obj) -{ - if (obj) - obj->_decr_refcnt (); -} - diff --git a/TAO/tao/Typecode_Constants.cpp b/TAO/tao/Typecode_Constants.cpp deleted file mode 100644 index 57d20d38389..00000000000 --- a/TAO/tao/Typecode_Constants.cpp +++ /dev/null @@ -1,480 +0,0 @@ -// $Id$ - -// ============================================================================ -// -// = LIBRARY -// TAO -// -// = FILENAME -// Typecode_Constants.cpp -// -// = DESCRIPTION -// All the CORBA-specified typecode constants. -// -// NOTE: IFR TypeCode constants aren't here; they're left for an IDL -// compiler to generate from the appropriate IDL source. -// -// NOTE: it'd be nice to have these not use init sections. Most can easily -// be in readonly data (e.g. text segment, ROM) rather than writable data; -// that speeds program startup and page sharing in shared libraries. -// -// THREADING NOTE: no issues, these are immutable constants -// -// = AUTHOR -// Copyright 1994-1995 by Sun Microsystems Inc. -// and Aniruddha Gokhale -// -// ============================================================================ - -#include "tao/Typecode_Constants.h" -#include "tao/Typecode.h" -#include "tao/NVList.h" -#include "tao/ORB.h" -#include "tao/Object.h" -#include "tao/SystemException.h" - -#if defined (TAO_HAS_AMI_POLLER) && (TAO_HAS_AMI_POLLER == 1) -#include "tao/PollableC.h" -#endif /* TAO_HAS_AMI_POLLER == 1 */ - -ACE_RCSID (tao, - Typecode_Constants, - "$Id$") - -// Declare all the standard typecodes owned by the ORB - -// Null and void -namespace CORBA -{ - TypeCode_ptr _tc_null = 0; - TypeCode_ptr _tc_void = 0; - - // Basic numeric types: short, long, longlong, and unsigned - // variants - - TypeCode_ptr _tc_short = 0; - TypeCode_ptr _tc_long = 0; - TypeCode_ptr _tc_longlong = 0; - TypeCode_ptr _tc_ushort = 0; - TypeCode_ptr _tc_ulong = 0; - TypeCode_ptr _tc_ulonglong = 0; - - // Floating point types: single, double, quad precision - TypeCode_ptr _tc_float = 0; - TypeCode_ptr _tc_double = 0; - TypeCode_ptr _tc_longdouble = 0; - - // Various simple quantities. - TypeCode_ptr _tc_boolean = 0; - TypeCode_ptr _tc_octet = 0; - - // Internationalization-related data types: ISO Latin/1 and "wide" - // characters, and strings of each. "wchar" is probably Unicode 1.1, - // "wstring" being null-terminated sets thereof. - TypeCode_ptr _tc_char = 0; - TypeCode_ptr _tc_wchar = 0; - - // a string/wstring have a simple parameter list that indicates the - // length - TypeCode_ptr _tc_string = 0; - TypeCode_ptr _tc_wstring = 0; - - // - // Various things that can be passed as "general" parameters: - // Any, TypeCode_ptr Principal_ptr, Object_ptr - // - TypeCode_ptr _tc_any = 0; - TypeCode_ptr _tc_TypeCode = 0; - TypeCode_ptr _tc_Principal = 0; - TypeCode_ptr _tc_Object = 0; - - // Two typecodes for exceptions - TypeCode_ptr CORBA::TypeCode::_tc_Bounds = 0; - TypeCode_ptr CORBA::TypeCode::_tc_BadKind = 0; - TypeCode_ptr _tc_exception_type = 0; - -#if (TAO_HAS_MINIMUM_CORBA == 0) - TypeCode_ptr _tc_NamedValue = 0; -#endif /* TAO_HAS_MINIMUM_CORBA */ -} // End namespace CORBA - -namespace TAO -{ - // Internal to TAO ORB - CORBA::TypeCode_ptr TC_opaque = 0; - CORBA::TypeCode_ptr TC_completion_status = 0; - - // Flag that denotes that the TAO TypeCode constants have been - // initialized. - int TypeCode_Constants::initialized_ = 0; - - // Initialize all the ORB owned TypeCode constants. This routine will - // be invoked by the ORB_init method. - void - TypeCode_Constants::init (void) - { - // Initialize all the standard typecodes owned by the ORB - - // Not thread safe. Caller must provide synchronization. - - // Do not execute code after this point more than once. - if (initialized_ != 0) - { - return; - } - - initialized_ = 1; - - // Null and void. - ACE_NEW (CORBA::_tc_null, - CORBA::TypeCode (CORBA::tk_null)); - - ACE_NEW (CORBA::_tc_void, - CORBA::TypeCode (CORBA::tk_void)); - - // Basic numeric types: short, long, longlong, and unsigned variants. - ACE_NEW (CORBA::_tc_short, - CORBA::TypeCode (CORBA::tk_short)); - - ACE_NEW (CORBA::_tc_long, - CORBA::TypeCode (CORBA::tk_long)); - - ACE_NEW (CORBA::_tc_longlong, - CORBA::TypeCode (CORBA::tk_longlong)); - - ACE_NEW (CORBA::_tc_ushort, - CORBA::TypeCode (CORBA::tk_ushort)); - - ACE_NEW (CORBA::_tc_ulong, - CORBA::TypeCode (CORBA::tk_ulong)); - - ACE_NEW (CORBA::_tc_ulonglong, - CORBA::TypeCode (CORBA::tk_ulonglong)); - - // Floating point types: single, double, quad precision. - ACE_NEW (CORBA::_tc_float, - CORBA::TypeCode (CORBA::tk_float)); - - ACE_NEW (CORBA::_tc_double, - CORBA::TypeCode (CORBA::tk_double)); - - ACE_NEW (CORBA::_tc_longdouble, - CORBA::TypeCode (CORBA::tk_longdouble)); - - // Various simple quantities. - ACE_NEW (CORBA::_tc_boolean, - CORBA::TypeCode (CORBA::tk_boolean)); - - ACE_NEW (CORBA::_tc_octet, - CORBA::TypeCode (CORBA::tk_octet)); - - // Internationalization-related data types: ISO Latin/1 and "wide" - // characters, and strings of each. "wchar" is probably Unicode 1.1, - // "wstring" being null-terminated sets thereof. - ACE_NEW (CORBA::_tc_char, - CORBA::TypeCode (CORBA::tk_char)); - - ACE_NEW (CORBA::_tc_wchar, - CORBA::TypeCode (CORBA::tk_wchar)); - - // A string/wstring have a simple parameter list that - // indicates the length. - static const CORBA::Long _oc_string [] = - { - // CDR typecode octets - TAO_ENCAP_BYTE_ORDER, // native endian + padding; "tricky" - 0 // ... unbounded string - }; - - ACE_NEW (CORBA::_tc_string, - CORBA::TypeCode (CORBA::tk_string, - sizeof _oc_string, - (char*)&_oc_string, - 1, - sizeof (CORBA::String_var))); - - static const CORBA::Long _oc_wstring [] = - { - // CDR typecode octets - TAO_ENCAP_BYTE_ORDER, // native endian + padding; "tricky" - 0 // ... unbounded string - }; - - ACE_NEW (CORBA::_tc_wstring, - CORBA::TypeCode (CORBA::tk_wstring, - sizeof _oc_wstring, - (char *) &_oc_wstring, - 1, - sizeof (CORBA::WChar*))); - - // - // Various things that can be passed as "general" parameters: - // Any, TypeCode_ptr, Principal_ptr, Object_ptr - // - ACE_NEW (CORBA::_tc_any, - CORBA::TypeCode (CORBA::tk_any)); - - ACE_NEW (CORBA::_tc_TypeCode, - CORBA::TypeCode (CORBA::tk_TypeCode)); - - ACE_NEW (CORBA::_tc_Principal, - CORBA::TypeCode (CORBA::tk_Principal)); - - // typecode for objref is complex, has two string parameters - // - // NOTE: Must be four-byte aligned - - static const CORBA::Long _oc_CORBA_Object[] = - { - TAO_ENCAP_BYTE_ORDER, // byte order - 29, - ACE_NTOHL (0x49444c3a), - ACE_NTOHL (0x6f6d672e), - ACE_NTOHL (0x6f72672f), - ACE_NTOHL (0x434f5242), - ACE_NTOHL (0x412f4f62), - ACE_NTOHL (0x6a656374), - ACE_NTOHL (0x3a312e30), - ACE_NTOHL (0x0), // repository ID = IDL:omg.org/CORBA/Object:1.0 - 7, - ACE_NTOHL (0x4f626a65), - ACE_NTOHL (0x63740000), // name = Object - }; - - ACE_NEW (CORBA::_tc_Object, - CORBA::TypeCode (CORBA::tk_objref, - sizeof (_oc_CORBA_Object), - (char *) &_oc_CORBA_Object, - 1, - sizeof (CORBA::Object))); - - // Static initialization of the two user-defined exceptions that - // are part of the ORB. - - static const CORBA::Long _oc_CORBA_TypeCode_Bounds[] = - { - TAO_ENCAP_BYTE_ORDER, // byte order - 38, - ACE_NTOHL (0x49444c3a), - ACE_NTOHL (0x6f6d672e), - ACE_NTOHL (0x6f72672f), - ACE_NTOHL (0x434f5242), - ACE_NTOHL (0x412f5479), - ACE_NTOHL (0x7065436f), - ACE_NTOHL (0x64652f42), - ACE_NTOHL (0x6f756e64), - ACE_NTOHL (0x733a312e), - ACE_NTOHL (0x30000000), // repository ID = IDL:omg.org/CORBA/TypeCode/Bounds:1.0 - 7, - ACE_NTOHL (0x426f756e), - ACE_NTOHL (0x64730000), // name = Bounds - 0, // member count - }; - - ACE_NEW (CORBA::TypeCode::_tc_Bounds, - CORBA::TypeCode (CORBA::tk_except, - sizeof (_oc_CORBA_TypeCode_Bounds), - (char*) &_oc_CORBA_TypeCode_Bounds, - 1, - sizeof (CORBA::TypeCode::Bounds))); - - - static const CORBA::Long _oc_CORBA_TypeCode_BadKind[] = - { - TAO_ENCAP_BYTE_ORDER, // byte order - 39, - ACE_NTOHL (0x49444c3a), - ACE_NTOHL (0x6f6d672e), - ACE_NTOHL (0x6f72672f), - ACE_NTOHL (0x434f5242), - ACE_NTOHL (0x412f5479), - ACE_NTOHL (0x7065436f), - ACE_NTOHL (0x64652f42), - ACE_NTOHL (0x61644b69), - ACE_NTOHL (0x6e643a31), - ACE_NTOHL (0x2e300000), // repository ID = IDL:omg.org/CORBA/TypeCode/BadKind:1.0 - 8, - ACE_NTOHL (0x4261644b), - ACE_NTOHL (0x696e6400), // name = BadKind - 0, // member count - }; - - ACE_NEW (CORBA::TypeCode::_tc_BadKind, - CORBA::TypeCode (CORBA::tk_except, - sizeof (_oc_CORBA_TypeCode_BadKind), - (char*) &_oc_CORBA_TypeCode_BadKind, - 1, - sizeof (CORBA::TypeCode::BadKind))); - - #if (TAO_HAS_MINIMUM_CORBA == 0) - - static const CORBA::Long _oc_corba_NamedValue[] = - { - TAO_ENCAP_BYTE_ORDER, // byte order - 33, - ACE_NTOHL (0x49444c3a), - ACE_NTOHL (0x6f6d672e), - ACE_NTOHL (0x6f72672f), - ACE_NTOHL (0x636f7262), - ACE_NTOHL (0x612f4e61), - ACE_NTOHL (0x6d656456), - ACE_NTOHL (0x616c7565), - ACE_NTOHL (0x3a312e30), - ACE_NTOHL (0x0), // repository ID = - // IDL:omg.org/corba/NamedValue:1.0 - 11, - ACE_NTOHL (0x4e616d65), - ACE_NTOHL (0x6456616c), - ACE_NTOHL (0x75650000), // name = NamedValue, - }; - - ACE_NEW (CORBA::_tc_NamedValue, - CORBA::TypeCode (CORBA::tk_objref, - sizeof (_oc_corba_NamedValue), - (char *) &_oc_corba_NamedValue, - 0, - sizeof (CORBA::NamedValue))); - - #endif /* TAO_HAS_MINIMUM_CORBA */ - - // **************************************************************** - - // The following are internal to the TAO ORB - - // Octet codes for the parameters of the "Opaque" (sequence of octet) - // data type used various places internally ... a CDR encapsulation - // holding two parameters (like all sequence TypeCodes). - // - // NOTE: this **MUST** be longword aligned, which is why it's coded as - // a longword array not an octet array. Just sticking a long in for - // padding won't work with compilers that optimize unused data out of - // existence. - - // CDR typecode octets. - - typedef TAO_Unbounded_Sequence<CORBA::Octet> TAO_opaque; - - static const CORBA::Long _oc_opaque [] = - { - - TAO_ENCAP_BYTE_ORDER, // native endian + padding; "tricky" - 10, // ... (sequence of) octets - 0 // ... unbounded - }; - - ACE_NEW (TC_opaque, - CORBA::TypeCode (CORBA::tk_sequence, - sizeof _oc_opaque, - (char *) &_oc_opaque, - 1, - sizeof (TAO_opaque))); - - // Octet codes for the parameters of the ServiceContextList TypeCode - // ... this is a CDR encapsulation holding two parameters (like all - // sequences): a TypeCode, and the bounds of the sequence (zero in - // this case). - // - // This is complicated since the Typecode for the data type for the - // sequence members is complex, a structure that nests two further - // typecodes (one is a sequence). - // - // NOTE: this must be longword aligned! - - static const CORBA::ULong oc_completion_status [] = - { - TAO_ENCAP_BYTE_ORDER, // byte order flag, tricky - 0, 0, // type ID omitted - 3, // three members - 0, 0, // ... whose names are all omitted - 0, 0, - 0, 0 - }; - - ACE_NEW (TC_completion_status, - CORBA::TypeCode (CORBA::tk_enum, - sizeof oc_completion_status, - (char *) &oc_completion_status, - 1, - sizeof (CORBA::CompletionStatus))); - } - - // Destroy all the typecodes owned by the ORB. - void - TypeCode_Constants::fini (void) - { - // Release all the standard typecodes owned by the ORB. - - // Null and void. - CORBA::release (CORBA::_tc_null); - - CORBA::release (CORBA::_tc_void); - - // Basic numeric types: short, long, longlong, and unsigned variants - CORBA::release (CORBA::_tc_short); - - CORBA::release (CORBA::_tc_long); - - CORBA::release (CORBA::_tc_longlong); - - CORBA::release (CORBA::_tc_ushort); - - CORBA::release (CORBA::_tc_ulong); - - CORBA::release (CORBA::_tc_ulonglong); - - // Floating point types: single, double, quad precision - CORBA::release (CORBA::_tc_float); - - CORBA::release (CORBA::_tc_double); - - CORBA::release (CORBA::_tc_longdouble); - - // Various simple quantities. - CORBA::release (CORBA::_tc_boolean); - - CORBA::release (CORBA::_tc_octet); - - // Internationalization-related data types: ISO Latin/1 and "wide" - // characters, and strings of each. "wchar" is probably Unicode 1.1, - // "wstring" being null-terminated sets thereof. - CORBA::release (CORBA::_tc_char); - - CORBA::release (CORBA::_tc_wchar); - - // A string/wstring have a simple parameter list that - // indicates the length. - CORBA::release (CORBA::_tc_string); - - CORBA::release (CORBA::_tc_wstring); - - // - // Various things that can be passed as "general" parameters: - // Any, TypeCode_ptr, Principal_ptr, Object_ptr - // - CORBA::release (CORBA::_tc_any); - - CORBA::release (CORBA::_tc_TypeCode); - - CORBA::release (CORBA::_tc_Principal); - - // typecode for objref is complex, has two string parameters - // - CORBA::release (CORBA::_tc_Object); - - // other ORB owned typecodes - CORBA::release (CORBA::TypeCode::_tc_Bounds); - - CORBA::release (CORBA::TypeCode::_tc_BadKind); - - #if (TAO_HAS_MINIMUM_CORBA == 0) - - CORBA::release (CORBA::_tc_NamedValue); - - #endif /* TAO_HAS_MINIMUM_CORBA */ - - // TAO specific - CORBA::release (TC_opaque); - - CORBA::release (TC_completion_status); - } -} // end namespace TAO diff --git a/TAO/tao/Typecode_typesC.h b/TAO/tao/Typecode_typesC.h index 6fa50f8c3ff..9bacd563cbe 100644 --- a/TAO/tao/Typecode_typesC.h +++ b/TAO/tao/Typecode_typesC.h @@ -121,7 +121,7 @@ namespace CORBA // This symbol is not defined by CORBA 3.0. It's used to speed up // dispatch based on TCKind values, and lets many important ones // just be table lookups. It must always be the last enum value!! - , TC_KIND_COUNT + , TAO_TC_KIND_COUNT }; typedef TCKind &TCKind_out; diff --git a/TAO/tao/Union_TypeCode.cpp b/TAO/tao/Union_TypeCode.cpp new file mode 100644 index 00000000000..d8e546af3e0 --- /dev/null +++ b/TAO/tao/Union_TypeCode.cpp @@ -0,0 +1,388 @@ +// $Id$ + +#ifndef TAO_UNION_TYPECODE_CPP +#define TAO_UNION_TYPECODE_CPP + +#include "tao/Union_TypeCode.h" +#include "tao/TypeCode_Case.h" + +#ifndef __ACE_INLINE__ +# include "tao/Union_TypeCode.inl" +#endif /* !__ACE_INLINE__ */ + + +template <typename StringType, class CaseArrayType, class RefCountPolicy> +bool +TAO::TypeCode::Union<StringType, + CaseArrayType, + RefCountPolicy>::tao_marshal ( + TAO_OutputCDR & cdr) const +{ + // A tk_union TypeCode has a "complex" parameter list type (see + // Table 15-2 in Section 15.3.5.1 "TypeCode" in the CDR section of + // the CORBA specification), meaning that it must be marshaled into + // a CDR encapsulation. + + CORBA::ULong const count = this->case_count (); + + // Create a CDR encapsulation. + bool const success = + (cdr << TAO_OutputCDR::from_boolean (TAO_ENCAP_BYTE_ORDER)) + && (cdr << this->base_attributes_.id ()) + && (cdr << this->base_attributes_.name ()) + && (cdr << *(this->discriminant_type_)) + && (cdr << this->default_index_) + && (cdr << count); + + if (!success) + return false; + + // Note that we handle the default case below, too. The default + // case handling is hidden behind the case_count() and case() + // methods. + + for (unsigned int i = 0; i < count; ++i) + { + case_type const & c = this->the_case (i); + + if (!c.marshal (cdr)) + return false; + } + + return true; +} + +template <typename StringType, class CaseArrayType, class RefCountPolicy> +void +TAO::TypeCode::Union<StringType, + CaseArrayType, + RefCountPolicy>::tao_duplicate (void) +{ + this->RefCountPolicy::add_ref (); +} + +template <typename StringType, class CaseArrayType, class RefCountPolicy> +void +TAO::TypeCode::Union<StringType, + CaseArrayType, + RefCountPolicy>::tao_release (void) +{ + this->RefCountPolicy::remove_ref (); +} + +template <typename StringType, class CaseArrayType, class RefCountPolicy> +CORBA::Boolean +TAO::TypeCode::Union<StringType, + CaseArrayType, + RefCountPolicy>::equal_i ( + CORBA::TypeCode_ptr tc + ACE_ENV_ARG_DECL) const +{ + // These calls shouldn't throw since CORBA::TypeCode::equal() + // verified that the TCKind is the same as our's prior to invoking + // this method, meaning that the CORBA::tk_union TypeCode methods + // are supported. + + CORBA::ULong const tc_count = + tc->member_count (ACE_ENV_SINGLE_ARG_PARAMETER); + ACE_CHECK_RETURN (0); + + CORBA::Long tc_def = tc->default_index (ACE_ENV_ARG_PARAMETER); + ACE_CHECK_RETURN (0); + + CORBA::ULong const this_count = this->case_count (); + + if (tc_count != this_count + || tc_def != this->default_index_) + return 0; + + // Check the discriminator type. + CORBA::TypeCode_var tc_discriminator = + tc->discriminator_type (ACE_ENV_ARG_PARAMETER); + ACE_CHECK_RETURN (0); + + CORBA::Boolean const equal_discriminators = + (*this->discriminator_type_)->equal (tc_discriminator.in () + ACE_ENV_ARG_PARAMETER); + ACE_CHECK_RETURN (0); + + if (!equal_discriminators) + return 0; + + for (CORBA::ULong i = 0; i < this_count; ++i) + { + case_type const & lhs_case = this->the_case (i); + + bool const equal_case = + lhs_case.equal (i, + tc + ACE_ENV_ARG_PARAMETER); + ACE_CHECK_RETURN (0); + + if (!equal_case) + return 0; + } + + return 1; +} + +template <typename StringType, class CaseArrayType, class RefCountPolicy> +CORBA::Boolean +TAO::TypeCode::Union<StringType, + CaseArrayType, + RefCountPolicy>::equivalent_i ( + CORBA::TypeCode_ptr tc + ACE_ENV_ARG_DECL) const +{ + // We could refactor this code to the CORBA::TypeCode::equivalent() + // method but doing so would force us to determine the unaliased + // kind of this TypeCode. Since we already know the unaliased kind + // of this TypeCode, choose to optimize away the additional kind + // unaliasing operation rather than save space. + + CORBA::TCKind const tc_kind = + TAO::unaliased_kind (tc + ACE_ENV_ARG_PARAMETER); + ACE_CHECK_RETURN (0); + + // Call kind_i() instead of using CORBA::tk_union directly since a + // subclass, such as Except_TypeCode, can use this equivalent_i() + // implementation. + CORBA::TCKind const this_kind = + this->kind_i (ACE_ENV_SINGLE_ARG_PARAMETER); + ACE_CHECK_RETURN (0); + + if (tc_kind != this_kind) + return 0; + + char const * const this_id = this->base_attributes_.id (); + char const * const tc_id = tc->id (ACE_ENV_SINGLE_ARG_PARAMETER); + ACE_CHECK_RETURN (0); + + if (ACE_OS::strlen (this_id) == 0 + || ACE_OS::strlen (tc_id) == 0) + { + // Perform a structural comparison, excluding the name() and + // member_name() operations. + + CORBA::ULong const tc_count = + tc->member_count (ACE_ENV_SINGLE_ARG_PARAMETER); + ACE_CHECK_RETURN (0); + + CORBA::Long tc_def = tc->default_index (ACE_ENV_ARG_PARAMETER); + ACE_CHECK_RETURN (0); + + CORBA::ULong const this_count = this->case_count (); + + if (tc_count != this_count + || tc_def != this->default_index_) + return 0; + + CORBA::TypeCode_var tc_discriminator = + tc->discriminator_type (ACE_ENV_ARG_PARAMETER); + ACE_CHECK_RETURN (0); + + CORBA::Boolean const equiv_discriminators = + (*this->discriminator_type_)->equivalent (tc_discriminator.in () + ACE_ENV_ARG_PARAMETER); + ACE_CHECK_RETURN (0); + + if (!equiv_discriminators) + return 0; + + for (CORBA::ULong i = 0; i < this_count; ++i) + { + case_type const & lhs_case = this->the_case (i); + + bool const equivalent_case = + lhs_case.equivalent (i, + tc + ACE_ENV_ARG_PARAMETER); + ACE_CHECK_RETURN (0); + + if (!equivalent_case) + return 0; + } + } + else if (ACE_OS::strcmp (this_id, tc_id) != 0) + { + return 0; + } + + return 1; +} + +template <typename StringType, class CaseArrayType, class RefCountPolicy> +CORBA::TCKind +TAO::TypeCode::Union<StringType, CaseArrayType, RefCountPolicy>::kind_i ( + ACE_ENV_SINGLE_ARG_DECL_NOT_USED) const +{ + return CORBA::tk_union; +} + +template <typename StringType, class CaseArrayType, class RefCountPolicy> +CORBA::TypeCode_ptr +TAO::TypeCode::Union<StringType, + CaseArrayType, + RefCountPolicy>::get_compact_typecode_i ( + ACE_ENV_SINGLE_ARG_DECL) const +{ + case_type * tc_cases = 0; + + ACE_Auto_Array_Ptr<Case<CORBA::String_var> > safe_cases; + + if (this->ncases_ > 0) + { + // Dynamically construct a new array of cases stripped of + // member names. + + ACE_NEW_THROW_EX (tc_cases, + case_type[this->ncases_], + CORBA::NO_MEMORY ()); + ACE_CHECK_RETURN (CORBA::TypeCode::_nil ()); + + safe_cases.reset (tc_cases); + + static char const * empty_name = ""; + + for (CORBA::ULong i = 0; i < this->ncases_; ++i) + { + // Member names will be stripped, i.e. not embedded within + // the compact TypeCode. + tc_cases[i].name = empty_name; + tc_cases[i].type = + &(this->the_case (i).type ()->get_compact_typecode ( + ACE_ENV_ARG_PARAMETER)); + ACE_CHECK_RETURN (CORBA::TypeCode::_nil ()); + } + } + + // Create the compact union TypeCode. + TAO_TypeCodeFactory_Adapter * adapter = + ACE_Dynamic_Service<TAO_TypeCodeFactory_Adapter>::instance ( + TAO_ORB_Core::typecodefactory_adapter_name ()); + + if (adapter == 0) + { + ACE_THROW_RETURN (CORBA::INTERNAL (), + CORBA::TypeCode::_nil ()); + } + + CORBA::TCKind const this_kind = + this->kind_i (ACE_ENV_SINGLE_ARG_PARAMETER); + ACE_CHECK_RETURN (CORBA::TypeCode::_nil ()); + + CORBA::TypeCode_var tc = + adapter->_tao_create_union_tc (this->base_attributes_.id (), + "", /* empty name */ + this->discriminant_type_, + tc_cases, + this->ncases_, + this->default_index_, + "", + this->default_case_.type () + ACE_ENV_ARG_PARAMETER); + ACE_CHECK_RETURN (CORBA::TypeCode::_nil ()); + + (void) safe_cases.release (); + + return tc._retn (); +} + +template <typename StringType, class CaseArrayType, class RefCountPolicy> +char const * +TAO::TypeCode::Union<StringType, CaseArrayType, RefCountPolicy>::id_i ( + ACE_ENV_SINGLE_ARG_DECL_NOT_USED) const +{ + // Ownership is retained by the TypeCode, as required by the C++ + // mapping. + return this->base_attributes_.id (); +} + +template <typename StringType, class CaseArrayType, class RefCountPolicy> +char const * +TAO::TypeCode::Union<StringType, CaseArrayType, RefCountPolicy>::name_i ( + ACE_ENV_SINGLE_ARG_DECL_NOT_USED) const +{ + // Ownership is retained by the TypeCode, as required by the C++ + // mapping. + return this->base_attributes_.name (); +} + +template <typename StringType, class CaseArrayType, class RefCountPolicy> +CORBA::ULong +TAO::TypeCode::Union<StringType, + CaseArrayType, + RefCountPolicy>::member_count_i ( + ACE_ENV_SINGLE_ARG_DECL_NOT_USED) const +{ + return this->case_count (); +} + +template <typename StringType, class CaseArrayType, class RefCountPolicy> +char const * +TAO::TypeCode::Union<StringType, + CaseArrayType, + RefCountPolicy>::member_name_i ( + CORBA::ULong index + ACE_ENV_ARG_DECL) const +{ + // Ownership is retained by the TypeCode, as required by the C++ + // mapping. + if (index >= this->case_count ()) + ACE_THROW_RETURN (CORBA::TypeCode::Bounds (), 0); + + return this->the_case (index).name (); +} + +template <typename StringType, class CaseArrayType, class RefCountPolicy> +CORBA::TypeCode_ptr +TAO::TypeCode::Union<StringType, + CaseArrayType, + RefCountPolicy>::member_type_i ( + CORBA::ULong index + ACE_ENV_ARG_DECL) const +{ + if (index >= this->case_count ()) + ACE_THROW_RETURN (CORBA::TypeCode::Bounds (), + CORBA::TypeCode::_nil ()); + + return CORBA::TypeCode::_duplicate (this->the_case (index).type ()); +} + +template <typename StringType, class CaseArrayType, class RefCountPolicy> +CORBA::Any * +TAO::TypeCode::Union<StringType, + CaseArrayType, + RefCountPolicy>::member_label_i (CORBA::ULong index + ACE_ENV_ARG_DECL) const +{ + if (index >= this->case_count ()) + ACE_THROW_RETURN (CORBA::TypeCode::Bounds (), + 0); + + return this->the_case (index).label (ACE_ENV_ARG_PARAMETER); +} + +template <typename StringType, class CaseArrayType, class RefCountPolicy> +CORBA::TypeCode_ptr +TAO::TypeCode::Union<StringType, + CaseArrayType, + RefCountPolicy>::discriminator_type_i ( + ACE_ENV_SINGLE_ARG_DECL) const +{ + return CORBA::TypeCode::_duplicate (*this->discriminator_type_); +} + +template <typename StringType, class CaseArrayType, class RefCountPolicy> +CORBA::Long +TAO::TypeCode::Union<StringType, + CaseArrayType, + RefCountPolicy>::default_index_i ( + ACE_ENV_SINGLE_ARG_DECL_NOT_USED) const +{ + return this->default_index_; +} + + +#endif /* TAO_UNION_TYPECODE_CPP */ diff --git a/TAO/tao/Union_TypeCode.h b/TAO/tao/Union_TypeCode.h new file mode 100644 index 00000000000..50d369e5739 --- /dev/null +++ b/TAO/tao/Union_TypeCode.h @@ -0,0 +1,198 @@ +// -*- C++ -*- + +//============================================================================= +/** + * @file Union_TypeCode.h + * + * $Id$ + * + * Header file for a @c tk_union CORBA::TypeCode. + * + * @author Ossama Othman + */ +//============================================================================= + +#ifndef TAO_UNION_TYPECODE_H +#define TAO_UNION_TYPECODE_H + +#include /**/ "ace/pre.h" + +#include "tao/TypeCode.h" + +#if !defined (ACE_LACKS_PRAGMA_ONCE) +# pragma once +#endif /* ACE_LACKS_PRAGMA_ONCE */ + +#include "tao/TypeCode_Base_Attributes.h" +#include "tao/TypeCode_Default_Case.h" + +namespace TAO +{ + namespace TypeCode + { + + /** + * @class Union + * + * @brief @c CORBA::TypeCode implementation for an OMG IDL + * @c union. + * + * This class implements a @c CORBA::TypeCode for an OMG IDL + * @c union. + */ + template <typename StringType, class CaseArrayType, class RefCountPolicy> + class Union + : public CORBA::TypeCode, + private RefCountPolicy + { + public: + + typedef TAO::TypeCode::Case<StringType> case_type; + + /// Constructor. + Union (char const * id, + char const * name, + CORBA::TypeCode_ptr const * discriminant_type, + case_type const * cases, + CORBA::ULong ncases, + CORBA::Long default_index, + char const * default_member_name, + CORBA::TypeCode_ptr const * default_member_type); + + /** + * @name TAO-specific @c CORBA::TypeCode Methods + * + * Methods required by TAO's implementation of the + * @c CORBA::TypeCode class. + * + * @see @c CORBA::TypeCode + */ + //@{ + virtual bool tao_marshal (TAO_OutputCDR & cdr) const; + virtual void tao_duplicate (void); + virtual void tao_release (void); + //@} + + protected: + + /** + * @name @c TAO CORBA::TypeCode Template Methods + * + * @c tk_union @c CORBA::TypeCode -specific template methods. + * + * @see @c CORBA::TypeCode + */ + //@{ + virtual CORBA::Boolean equal_i (CORBA::TypeCode_ptr tc + ACE_ENV_ARG_DECL) const; + virtual CORBA::Boolean equivalent_i (CORBA::TypeCode_ptr tc + ACE_ENV_ARG_DECL) const; + virtual CORBA::TCKind kind_i (ACE_ENV_SINGLE_ARG_DECL) const; + virtual CORBA::TypeCode_ptr get_compact_typecode_i ( + ACE_ENV_SINGLE_ARG_DECL) const; + virtual char const * id_i (ACE_ENV_SINGLE_ARG_DECL) const; + virtual char const * name_i (ACE_ENV_SINGLE_ARG_DECL) const; + virtual CORBA::ULong member_count_i (ACE_ENV_SINGLE_ARG_DECL) const; + virtual char const * member_name_i (CORBA::ULong index + ACE_ENV_ARG_DECL) const; + virtual CORBA::TypeCode_ptr member_type_i (CORBA::ULong index + ACE_ENV_ARG_DECL) const; + virtual CORBA::Any * member_label_i (CORBA::ULong index + ACE_ENV_ARG_DECL) const; + virtual CORBA::TypeCode_ptr discriminator_type_i ( + ACE_ENV_SINGLE_ARG_DECL) const; + virtual CORBA::Long default_index_i (ACE_ENV_SINGLE_ARG_DECL) const; + //@} + + private: + + /// Get pointer to the underlying @c Case array. +// case_type const * cases (void) const; + + /// Return the number of cases in the IDL @c union, including + /// the @c default case. + CORBA::ULong case_count (void) const; + + /// Return @c union case corresponding to given member (not + /// @c case_type array) index. + /** + * @param index The zero-based index of the @c union member, + * including the @c default case. For example, if + * the @c default case is the second @union + * case/member, the @a index would be @c 1. + * + * @return Reference to @c union case/member corresponding to + * the given member zero-based @a index value. + * + * @note This method handles the @c default case. Do not + * attempt to perform special handling for the @c default + * case by shifting the index value by one, for example. + */ + case_type const & the_case (CORBA::ULong index) const; + + private: + + /** + * @c Union Attributes + * + * Attributes representing the structure of an OMG IDL + * @c union. + * + * @note These attributes are declared in the order in which + * they are marshaled into a CDR stream in order to + * increase cache hits by improving spatial locality. + */ + //@{ + + /// Base attributes containing repository ID and name of + /// union type. + Base_Attributes<StringType> const base_attributes_; + + /// Type of IDL @c union discriminant. + CORBA::TypeCode_ptr * const discriminant_type_; + + /// Index of the default union case. + /** + * This value will be -1 if no default case is found in the + * union. + */ + CORBA::Long const default_index_; + + /// The number of cases in the OMG IDL union, excluding the + /// @c default case. + CORBA::ULong const ncases_; + + /// Array of @c TAO::TypeCode::Case representing structure of + /// the OMG IDL defined @c union. + CaseArrayType const cases_; + + /// IDL @c union @c default case. + /** + * @note Only valid if @c this->default_index_ @c >= @c 0. + */ + Default_Case<StringType> const default_case_; + + //@} + + }; + + } // End namespace TypeCode +} // End namespace TAO + + +#ifdef __ACE_INLINE__ +# include "tao/Union_TypeCode.inl" +#endif /* __ACE_INLINE__ */ + +#ifdef ACE_TEMPLATES_REQUIRE_SOURCE +# include "tao/Union_TypeCode.cpp" +#endif /* ACE_TEMPLATES_REQUIRE_SOURCE */ + +#ifdef ACE_TEMPLATES_REQUIRE_PRAGMA +# pragma implementation ("Union_TypeCode.cpp") +#endif /* ACE_TEMPLATES_REQUIRE_PRAGMA */ + + +#include /**/ "ace/post.h" + +#endif /* TAO_UNION_TYPECODE_H */ diff --git a/TAO/tao/Union_TypeCode.inl b/TAO/tao/Union_TypeCode.inl new file mode 100644 index 00000000000..3f431d53a5f --- /dev/null +++ b/TAO/tao/Union_TypeCode.inl @@ -0,0 +1,76 @@ +// -*- C++ -*- +// +// $Id$ + +#include "ace/Auto_Ptr.h" + + +template <typename StringType, class CaseArrayType, class RefCountPolicy> +ACE_INLINE +TAO::TypeCode::Union<StringType, CaseArrayType, RefCountPolicy>::Union ( + char const * id, + char const * name, + CORBA::TypeCode_ptr const * discriminant_type, + case_type const * cases, + CORBA::ULong ncases, + CORBA::Long default_index, + char const * default_member_name, + CORBA::TypeCode_ptr const * default_member_type) + : base_attributes_ (id, name) + , discriminant_type_ (discriminant_type) + , default_index_ (default_index) + , ncases_ (ncases) + , cases_ (cases) + , default_case_ (default_member_name, + default_member_type) +{ +} + +template <typename StringType, typename CaseArrayType, class RefCountPolicy> +ACE_INLINE CORBA::ULong +TAO::TypeCode::Union<StringType, + CaseArrayType, + RefCountPolicy>::case_count (void) const +{ + return (this->default_index_ < 0 ? this->ncases_ : this->ncases_ + 1); +} + +template <typename StringType, typename CaseArrayType, class RefCountPolicy> +ACE_INLINE TAO::TypeCode::Union<StringType, + CaseArrayType, + RefCountPolicy>::case_type const & +TAO::TypeCode::Union<StringType, + CaseArrayType, + RefCountPolicy>::the_case (CORBA::ULong index) const +{ + if (default_index_ >= 0) + { + if (index == static_cast<CORBA::ULong> (this->default_index_)) + return this->default_case_; + + // Shift by one if default case was declared prior to + // non-default cases. + else if (index > static_cast<CORBA::ULong> (this->default_index_)) + return this->cases_[index - 1]; + + // Remaining (index < this->default_index_) case is handled + // below. + } + + return this->cases_[index]; +} + + +// ------------------------------------------------------------- +// Member specializations +// ------------------------------------------------------------- + +// ACE_INLINE TAO::TypeCode::Union<CORBA::String_var, +// ACE_Auto_Ptr_Array<Case const>, +// TAO::True_RefCount_Policy>::case_type const * +// TAO::TypeCode::Union<CORBA::String_var, +// ACE_Auto_Ptr_Array<Case const>, +// TAO::True_RefCount_Policy>::cases (void) const +// { +// return this->cases_.get (); +// } diff --git a/TAO/tao/Value_Box_TypeCode.cpp b/TAO/tao/Value_Box_TypeCode.cpp new file mode 100644 index 00000000000..bd579b9a693 --- /dev/null +++ b/TAO/tao/Value_Box_TypeCode.cpp @@ -0,0 +1,175 @@ +// $Id$ + +#ifndef TAO_VALUE_BOX_TYPECODE_CPP +#define TAO_VALUE_BOX_TYPECODE_CPP + +#include "tao/Value_Box_TypeCode.h" + +#ifndef __ACE_INLINE__ +# include "tao/Value_Box_TypeCode.inl" +#endif /* !__ACE_INLINE__ */ + + +template <typename StringType, class RefCountPolicy> +TAO::TypeCode::Value_Box<StringType, RefCountPolicy>::~Value_Box (void) +{ + if (this->content_type_) + CORBA::release (*this->content_type_); +} + +template <typename StringType, class RefCountPolicy> +bool +TAO::TypeCode::Value_Box<StringType, RefCountPolicy>::tao_marshal ( + TAO_OutputCDR &) const +{ + // A tk_value_box TypeCode has a "complex" parameter list type (see + // Table 15-2 in Section 15.3.5.1 "TypeCode" in the CDR section of + // the CORBA specification), meaning that it must be marshaled into + // a CDR encapsulation. + + // Create a CDR encapsulation. + return + (cdr << TAO_OutputCDR::from_boolean (TAO_ENCAP_BYTE_ORDER)) + && (cdr << this->attributes_.id ()) + && (cdr << this->attributes_.name ()) + && (cdr << *(this->content_type_.in ())); +} + +template <typename StringType, class RefCountPolicy> +void +TAO::TypeCode::Value_Box<StringType, RefCountPolicy>::tao_duplicate (void) +{ + this->RefCountPolicy::add_ref (); +} + +template <typename StringType, class RefCountPolicy> +void +TAO::TypeCode::Value_Box<StringType, RefCountPolicy>::tao_release (void) +{ + this->RefCountPolicy::remove_ref (); +} + +template <typename StringType, class RefCountPolicy> +CORBA::Boolean +TAO::TypeCode::Value_Box<StringType, RefCountPolicy>::equal_i ( + CORBA::TypeCode_ptr tc + ACE_ENV_ARG_DECL_NOT_USED) const +{ + // The CORBA::TypeCode base class already verified equality of the + // base attributes (id and name). Perform an equality comparison of + // the members. + + CORBA::TypeCode_var rhs_content_type = + tc->content_type (ACE_ENV_SINGLE_ARG_PARAMETER); + ACE_CHECK_RETURN (0); + + return this->content_type_->equal (rhs_content_type.in () + ACE_ENV_ARG_PARAMETER); +} + +template <typename StringType, class RefCountPolicy> +CORBA::Boolean +TAO::TypeCode::Value_Box<StringType, RefCountPolicy>::equivalent_i ( + CORBA::TypeCode_ptr tc + ACE_ENV_ARG_DECL) const +{ + // We could refactor this code to the CORBA::TypeCode::equivalent() + // method but doing so would force us to determine the unaliased + // kind of this TypeCode. Since we already know the unaliased kind + // of this TypeCode, choose to optimize away the additional kind + // unaliasing operation rather than save space. + + CORBA::TCKind const tc_kind = + TAO::unaliased_kind (tc + ACE_ENV_ARG_PARAMETER); + ACE_CHECK_RETURN (0); + + if (tc_kind != CORBA::tk_value_box) + return (0); + + char const * const this_id = this->attributes_.id (); + char const * const tc_id = tc->id (ACE_ENV_SINGLE_ARG_PARAMETER); + ACE_CHECK_RETURN (0); + + if (ACE_OS::strlen (this_id) == 0 + || ACE_OS::strlen (tc_id) == 0) + { + CORBA::TypeCode_var rhs_content_type = + tc->content_type (ACE_ENV_SINGLE_ARG_PARAMETER); + ACE_CHECK_RETURN (0); + + return *(this->content_type_)->equivalent (rhs_content_type.in () + ACE_ENV_ARG_PARAMETER); + } + else if (ACE_OS::strcmp (this_id, tc_id) != 0) + { + return 0; + } + + return 1; +} + +template <typename StringType, class RefCountPolicy> +CORBA::TCKind +TAO::TypeCode::Value_Box<StringType, RefCountPolicy>::kind_i ( + ACE_ENV_SINGLE_ARG_DECL_NOT_USED) const +{ + return CORBA::tk_value_box; +} + +template <typename StringType, class RefCountPolicy> +CORBA::TypeCode_ptr +TAO::TypeCode::Value_Box<StringType, RefCountPolicy>::get_compact_typecode_i ( + ACE_ENV_SINGLE_ARG_DECL) const +{ + TAO_TypeCodeFactory_Adapter * adapter = + ACE_Dynamic_Service<TAO_TypeCodeFactory_Adapter>::instance ( + TAO_ORB_Core::typecodefactory_adapter_name () + ); + + if (adapter == 0) + { + ACE_THROW_RETURN (CORBA::INTERNAL (), + CORBA::TypeCode::_nil ()); + } + + CORBA::TypeCode_var compact_content_type = + *(this->content_type_)->get_compact_typecode ( + ACE_ENV_SINGLE_ARG_PARAMETER); + ACE_CHECK_RETURN (CORBA::TypeCode::_nil ()); + + return adapter->create_value_box_tc (this->attributes_.id (), + "" /* empty name */ + compact_content_type.in () + ACE_ENV_ARG_PARAMETER); +} + +template <typename StringType, class RefCountPolicy> +char const * +TAO::TypeCode::Value_Box<StringType, RefCountPolicy>::id_i ( + ACE_ENV_SINGLE_ARG_DECL_NOT_USED) const +{ + // Ownership is retained by the TypeCode, as required by the C++ + // mapping. + return this->attributes_.id (); +} + +template <typename StringType, class RefCountPolicy> +char const * +TAO::TypeCode::Value_Box<StringType, RefCountPolicy>::name_i ( + ACE_ENV_SINGLE_ARG_DECL_NOT_USED) const +{ + // Ownership is retained by the TypeCode, as required by the C++ + // mapping. + return this->attributes_.name (); +} + +template <typename StringType, class RefCountPolicy> +CORBA::TypeCode_ptr +TAO::TypeCode::Value_Box<StringType, RefCountPolicy>::content_type_i ( + ACE_ENV_SINGLE_ARG_DECL_NOT_USED) const +{ + return CORBA::TypeCode::_duplicate (*this->content_type_); +} + +#endif /* TAO_VALUE_BOX_TYPECODE_CPP */ diff --git a/TAO/tao/Value_Box_TypeCode.h b/TAO/tao/Value_Box_TypeCode.h new file mode 100644 index 00000000000..fb359bf63e0 --- /dev/null +++ b/TAO/tao/Value_Box_TypeCode.h @@ -0,0 +1,130 @@ +// -*- C++ -*- + +//============================================================================= +/** + * @file Value_Box_TypeCode.h + * + * $Id$ + * + * Header file for a @c tk_value_box CORBA::TypeCode. + * + * @author Ossama Othman <ossama@dre.vanderbilt.edu> + */ +//============================================================================= + +#ifndef TAO_VALUE_BOX_TYPECODE_H +#define TAO_VALUE_BOX_TYPECODE_H + +#include /**/ "ace/pre.h" + +#include "tao/TypeCode.h" + +#if !defined (ACE_LACKS_PRAGMA_ONCE) +# pragma once +#endif /* ACE_LACKS_PRAGMA_ONCE */ + +namespace TAO +{ + namespace TypeCode + { + + /** + * @class Value_Box + * + * @brief @c CORBA::TypeCode implementation for an OMG IDL + * boxed @c valuetype. + * + * This class implements a @c CORBA::TypeCode for an OMG IDL + * boxed @c valuetype. + */ + template <typename StringType, class RefCountPolicy> + class Value_Box + : public CORBA::TypeCode, + private RefCountPolicy + { + public: + + /// Constructor. + Value_Box (char const * id, + char const * name, + CORBA::TypeCode_ptr * tc); + + /// Destructor. + ~Value_Box (void); + + /** + * @name TAO-specific @c CORBA::TypeCode Methods + * + * Methods required by TAO's implementation of the + * @c CORBA::TypeCode class. + * + * @see @c CORBA::TypeCode + */ + //@{ + virtual bool tao_marshal (TAO_OutputCDR & cdr) const; + virtual void tao_duplicate (void); + virtual void tao_release (void); + //@} + + protected: + + /** + * @name @c TAO CORBA::TypeCode Template Methods + * + * @c tk_value_box @c CORBA::TypeCode -specific template methods. + * + * @see @c CORBA::TypeCode + */ + //@{ + virtual CORBA::Boolean equal_i (CORBA::TypeCode_ptr tc + ACE_ENV_ARG_DECL) const; + virtual CORBA::Boolean equivalent_i (CORBA::TypeCode_ptr tc + ACE_ENV_ARG_DECL) const; + virtual CORBA::TCKind kind_i (ACE_ENV_SINGLE_ARG_DECL) const; + virtual CORBA::TypeCode_ptr get_compact_typecode_i ( + ACE_ENV_SINGLE_ARG_DECL) const; + virtual char const * id_i (ACE_ENV_SINGLE_ARG_DECL) const; + virtual char const * name_i (ACE_ENV_SINGLE_ARG_DECL) const; + virtual TypeCode_ptr content_type_i (ACE_ENV_SINGLE_ARG_DECL) const; + + private: + + /// Base attributes for this @c TypeCode containing the + /// repository ID and name of the boxed @c valuetype. + Base_Attributes<StringType> attributes_; + + /// The @c TypeCode corresponding to the original type upon + /// which the IDL boxed @c valuetype was made. + /** + * A pointer to the @c CORBA::TypeCode_ptr rather than the + * @c CORBA::TypeCode_ptr itself is stored since that address is + * well-defined. We may not know the value of the @c + * CORBA::TypeCode_ptr when creating this @c Field statically at + * compile-time, hence the indirection. + * + * @note This @c TypeCode is released upon destruction of this + * @c TypeCode::Value_Box. + */ + CORBA::TypeCode_ptr * content_type_; + + }; + + } // End namespace TypeCode +} // End namespace TAO + + +#ifdef __ACE_INLINE__ +# include "tao/Value_Box_TypeCode.inl" +#endif /* __ACE_INLINE__ */ + +#ifdef ACE_TEMPLATES_REQUIRE_SOURCE +# include "tao/Value_Box_TypeCode.cpp" +#endif /* ACE_TEMPLATES_REQUIRE_SOURCE */ + +#ifdef ACE_TEMPLATES_REQUIRE_PRAGMA +# pragma implementation ("Value_Box_TypeCode.cpp") +#endif /* ACE_TEMPLATES_REQUIRE_PRAGMA */ + +#include /**/ "ace/post.h" + +#endif /* TAO_VALUE_BOX_TYPECODE_H */ diff --git a/TAO/tao/Value_TypeCode.cpp b/TAO/tao/Value_TypeCode.cpp new file mode 100644 index 00000000000..a7c331b9ee5 --- /dev/null +++ b/TAO/tao/Value_TypeCode.cpp @@ -0,0 +1,483 @@ +// $Id$ + +#ifndef TAO_VALUE_TYPECODE_CPP +#define TAO_VALUE_TYPECODE_CPP + +#include "tao/Value_TypeCode.h" +#include "tao/TypeCode_Value_Field.h" + +#ifndef __ACE_INLINE__ +# include "tao/Value_TypeCode.inl" +#endif /* !__ACE_INLINE__ */ + + +template <typename StringType, + class FieldArrayType, + CORBA::TCKind Kind, + class RefCountPolicy> +bool +TAO::TypeCode::Value<StringType, + FieldArrayType, + Kind, + RefCountPolicy>::tao_marshal ( + TAO_OutputCDR & cdr) const +{ + // A tk_value TypeCode has a "complex" parameter list type (see + // Table 15-2 in Section 15.3.5.1 "TypeCode" in the CDR section of + // the CORBA specification), meaning that it must be marshaled into + // a CDR encapsulation. + + // Create a CDR encapsulation. + bool const success = + (cdr << TAO_OutputCDR::from_boolean (TAO_ENCAP_BYTE_ORDER)) + && (cdr << this->base_attributes_.id ()) + && (cdr << this->base_attributes_.name ()) + && (cdr << this->type_modifier_) + && (cdr << *this->concrete_base_) + && (cdr << this->nfields_); + + if (!success) + return false; + + Value_Field<StringType> const * const begin = this->fields (); + Value_Field<StringType> const * const end = begin + this->nfields_; + + for (Value_Field<StringType> const * i = begin; i != end; ++i) + { + Value_Field<StringType> const & field = *i; + + if (!(cdr << field.get_name ()) + || !(cdr << *(field.type)) + || !(cdr << field.visibility)) + return false; + } + + return true; +} + +template <typename StringType, + class FieldArrayType, + CORBA::TCKind Kind, + class RefCountPolicy> +void +TAO::TypeCode::Value<StringType, + FieldArrayType, + Kind, + RefCountPolicy>::tao_duplicate (void) +{ + this->RefCountPolicy::add_ref (); +} + +template <typename StringType, + class FieldArrayType, + CORBA::TCKind Kind, + class RefCountPolicy> +void +TAO::TypeCode::Value<StringType, + FieldArrayType, + Kind, + RefCountPolicy>::tao_release (void) +{ + this->RefCountPolicy::remove_ref (); +} + +template <typename StringType, + class FieldArrayType, + CORBA::TCKind Kind, + class RefCountPolicy> +CORBA::Boolean +TAO::TypeCode::Value<StringType, + FieldArrayType, + Kind, + RefCountPolicy>::equal_i ( + CORBA::TypeCode_ptr tc + ACE_ENV_ARG_DECL) const +{ + // None of these calls should throw since CORBA::TypeCode::equal() + // verified that the TCKind is the same as our's prior to invoking + // this method. + + CORBA::ValueModifier const tc_type_modifier = + tc->type_modifier (ACE_ENV_SINGLE_ARG_PARAMETER); + ACE_CHECK_RETURN (0); + + if (tc_type_modifier != this->type_modifier_) + return 0; + + CORBA::TypeCode_var rhs_concrete_base_type = + tc->concrete_base_type (ACE_ENV_SINGLE_ARG_PARAMETER); + ACE_CHECK_RETURN (0); + + CORBA::Boolean const equal_concrete_base_types = + this->equal (rhs_concrete_base_type.in () + ACE_ENV_ARG_PARAMETER); + ACE_CHECK_RETURN (0); + + if (!equal_concrete_base_types) + return 0; + + CORBA::ULong const tc_nfields = + tc->member_count (ACE_ENV_SINGLE_ARG_PARAMETER); + ACE_CHECK_RETURN (0); + + if (tc_nfields != this->nfields_) + return 0; + + for (CORBA::ULong i = 0; i < this->nfields_; ++i) + { + Value_Field<StringType> const & lhs_field = this->fields_[i]; + + CORBA::Visibility const lhs_visibility = lhs_field.visibility; + CORBA::Visibility const rhs_visibility = + tc->member_visibility (i + ACE_ENV_ARG_PARAMETER); + ACE_CHECK_RETURN (0); + + if (lhs_visibility != rhs_visibility) + return 0; + + char const * const lhs_name = lhs_field.get_name (); + char const * const rhs_name = tc->member_name (i + ACE_ENV_ARG_PARAMETER); + ACE_CHECK_RETURN (0); + + if (ACE_OS::strcmp (lhs_name, rhs_name) != 0) + return 0; + + CORBA::TypeCode_ptr const lhs_tc = *(lhs_field.type); + CORBA::TypeCode_var const rhs_tc = + tc->member_type (i + ACE_ENV_ARG_PARAMETER); + ACE_CHECK_RETURN (0); + + CORBA::Boolean const equal_members = + lhs_tc->equal (rhs_tc.in () + ACE_ENV_ARG_PARAMETER); + ACE_CHECK_RETURN (0); + + if (!equal_members) + return 0; + } + + return 1; +} + +template <typename StringType, + class FieldArrayType, + CORBA::TCKind Kind, + class RefCountPolicy> +CORBA::Boolean +TAO::TypeCode::Value<StringType, + FieldArrayType, + Kind, + RefCountPolicy>::equivalent_i ( + CORBA::TypeCode_ptr tc + ACE_ENV_ARG_DECL) const +{ + // We could refactor this code to the CORBA::TypeCode::equivalent() + // method but doing so would force us to determine the unaliased + // kind of this TypeCode. Since we already know the unaliased kind + // of this TypeCode, choose to optimize away the additional kind + // unaliasing operation rather than save space. + + CORBA::TCKind const tc_kind = + TAO::unaliased_kind (tc + ACE_ENV_ARG_PARAMETER); + ACE_CHECK_RETURN (0); + + if (tc_kind != Kind) + return 0; + + char const * const this_id = this->base_attributes_.id (); + char const * const tc_id = tc->id (ACE_ENV_SINGLE_ARG_PARAMETER); + ACE_CHECK_RETURN (0); + + if (ACE_OS::strlen (this_id) == 0 + || ACE_OS::strlen (tc_id) == 0) + { + CORBA::ValueModifier const tc_type_modifier = + tc->type_modifier (ACE_ENV_SINGLE_ARG_PARAMETER); + ACE_CHECK_RETURN (0); + + if (tc_type_modifier != this->type_modifier_) + return 0; + + CORBA::TypeCode_var rhs_concrete_base_type = + tc->concrete_base_type (ACE_ENV_SINGLE_ARG_PARAMETER); + ACE_CHECK_RETURN (0); + + CORBA::Boolean const equivalent_concrete_base_types = + this->equivalent (rhs_concrete_base_type.in () + ACE_ENV_ARG_PARAMETER); + ACE_CHECK_RETURN (0); + + if (!equivalent_concrete_base_types) + return 0; + + // Perform a structural comparison, excluding the name() and + // member_name() operations. + + CORBA::ULong const tc_nfields = + tc->member_count (ACE_ENV_SINGLE_ARG_PARAMETER); + ACE_CHECK_RETURN (0); + + if (tc_nfields != this->nfields_) + return 0; + + for (CORBA::ULong i = 0; i < this->nfields_; ++i) + { + Value_Field<StringType> const & lhs_field = this->fields_[i]; + + CORBA::Visibility const lhs_visibility = + lhs_field.visibility; + CORBA::Visibility const rhs_visibility = + tc->member_visibility (i + ACE_ENV_ARG_PARAMETER); + ACE_CHECK_RETURN (0); + + if (lhs_visibility != rhs_visibility) + return 0; + + CORBA::TypeCode_ptr const lhs_tc = *(lhs_field.type); + CORBA::TypeCode_var const rhs_tc = + tc->member_type (i + ACE_ENV_ARG_PARAMETER); + ACE_CHECK_RETURN (0); + + CORBA::Boolean const equiv_types = + lhs_tc->equivalent (rhs_tc.in () + ACE_ENV_ARG_PARAMETER); + ACE_CHECK_RETURN (0); + + if (!equiv_types) + return 0; + } + } + else if (ACE_OS::strcmp (this_id, tc_id) != 0) + { + return 0; + } + + return 1; +} + +template <typename StringType, + class FieldArrayType, + CORBA::TCKind Kind, + class RefCountPolicy> +CORBA::TCKind +TAO::TypeCode::Value<StringType, + FieldArrayType, + Kind, + RefCountPolicy>::kind_i ( + ACE_ENV_SINGLE_ARG_DECL_NOT_USED) const +{ + return Kind; +} + +template <typename StringType, + class FieldArrayType, + CORBA::TCKind Kind, + class RefCountPolicy> +CORBA::TypeCode_ptr +TAO::TypeCode::Value<StringType, + FieldArrayType, + Kind, + RefCountPolicy>::get_compact_typecode_i ( + ACE_ENV_SINGLE_ARG_DECL) const +{ + Value_Field<StringType> * tc_fields = 0; + + ACE_Auto_Array_Ptr<Value_Field<StringType> > safe_fields; + + if (this->nfields_ > 0) + { + // Dynamically construct a new array of fields stripped of + // member names. + + ACE_NEW_THROW_EX (tc_fields, + Value_Field<StringType> [this->nfields_], + CORBA::NO_MEMORY ()); + ACE_CHECK_RETURN (CORBA::TypeCode::_nil ()); + + safe_fields.reset (tc_fields); + + static char const empty_name[] = ""; + + for (CORBA::ULong i = 0; i < this->nfields_; ++i) + { + // Member names will be stripped, i.e. not embedded within + // the compact TypeCode. + + tc_fields[i].name = empty_name; + tc_fields[i].type = 0; // FIX ME!!!!! +// &(*(this->fields_[i].type))->get_compact_typecode ( +// ACE_ENV_SINGLE_ARG_PARAMETER); +// ACE_CHECK_RETURN (CORBA::TypeCode::_nil ()); + tc_fields[i].visibility = this->fields_[i].visibility; + } + } + + TAO_TypeCodeFactory_Adapter * const adapter = + ACE_Dynamic_Service<TAO_TypeCodeFactory_Adapter>::instance ( + TAO_ORB_Core::typecodefactory_adapter_name ()); + + if (adapter == 0) + { + ACE_THROW_RETURN (CORBA::INTERNAL (), + CORBA::TypeCode::_nil ()); + } + + CORBA::TypeCode_var tc = + adapter->_tao_create_value_event_tc (Kind, + this->base_attributes_.id (), + "", // empty name + this->type_modifier_, + this->concrete_base_, + tc_fields, + this->nfields_ + ACE_ENV_ARG_PARAMETER); + ACE_CHECK_RETURN (CORBA::TypeCode::_nil ()); + + (void) safe_fields.release (); + + return tc._retn (); +} + +template <typename StringType, + class FieldArrayType, + CORBA::TCKind Kind, + class RefCountPolicy> +char const * +TAO::TypeCode::Value<StringType, + FieldArrayType, + Kind, + RefCountPolicy>::id_i ( + ACE_ENV_SINGLE_ARG_DECL_NOT_USED) const +{ + // Ownership is retained by the TypeCode, as required by the C++ + // mapping. + return this->base_attributes_.id (); +} + +template <typename StringType, + class FieldArrayType, + CORBA::TCKind Kind, + class RefCountPolicy> +char const * +TAO::TypeCode::Value<StringType, + FieldArrayType, + Kind, + RefCountPolicy>::name_i ( + ACE_ENV_SINGLE_ARG_DECL_NOT_USED) const +{ + // Ownership is retained by the TypeCode, as required by the C++ + // mapping. + return this->base_attributes_.name (); +} + +template <typename StringType, + class FieldArrayType, + CORBA::TCKind Kind, + class RefCountPolicy> +CORBA::ULong +TAO::TypeCode::Value<StringType, + FieldArrayType, + Kind, + RefCountPolicy>::member_count_i ( + ACE_ENV_SINGLE_ARG_DECL_NOT_USED) const +{ + return this->nfields_; +} + +template <typename StringType, + class FieldArrayType, + CORBA::TCKind Kind, + class RefCountPolicy> +char const * +TAO::TypeCode::Value<StringType, + FieldArrayType, + Kind, + RefCountPolicy>::member_name_i ( + CORBA::ULong index + ACE_ENV_ARG_DECL) const +{ + // Ownership is retained by the TypeCode, as required by the C++ + // mapping. + if (index >= this->nfields_) + ACE_THROW_RETURN (CORBA::TypeCode::Bounds (), 0); + + return this->fields_[index].get_name (); +} + +template <typename StringType, + class FieldArrayType, + CORBA::TCKind Kind, + class RefCountPolicy> +CORBA::TypeCode_ptr +TAO::TypeCode::Value<StringType, + FieldArrayType, + Kind, + RefCountPolicy>::member_type_i ( + CORBA::ULong index + ACE_ENV_ARG_DECL) const +{ + if (index >= this->nfields_) + ACE_THROW_RETURN (CORBA::TypeCode::Bounds (), + CORBA::TypeCode::_nil ()); + + return CORBA::TypeCode::_duplicate (*(this->fields_[index].type)); +} + +template <typename StringType, + class FieldArrayType, + CORBA::TCKind Kind, + class RefCountPolicy> +CORBA::Visibility +TAO::TypeCode::Value<StringType, + FieldArrayType, + Kind, + RefCountPolicy>::member_visibility_i ( + CORBA::ULong index + ACE_ENV_ARG_DECL) const +{ + if (index >= this->nfields_) + ACE_THROW_RETURN (CORBA::TypeCode::Bounds (), + CORBA::PRIVATE_MEMBER); + + return this->fields_[index].visibility; +} + +template <typename StringType, + class FieldArrayType, + CORBA::TCKind Kind, + class RefCountPolicy> +CORBA::ValueModifier +TAO::TypeCode::Value<StringType, + FieldArrayType, + Kind, + RefCountPolicy>::type_modifier ( + ACE_ENV_SINGLE_ARG_DECL_NOT_USED) const +{ + return this->type_modifier_; +} + +template <typename StringType, + class FieldArrayType, + CORBA::TCKind Kind, + class RefCountPolicy> +CORBA::TypeCode_ptr +TAO::TypeCode::Value<StringType, + FieldArrayType, + Kind, + RefCountPolicy>::concrete_base_type ( + ACE_ENV_SINGLE_ARG_DECL_NOT_USED) const +{ + return + this->concrete_base_ == 0 + ? CORBA::TypeCode::_nil () + : CORBA::TypeCode::_duplicate (*(this->concrete_base_)); +} + + +#endif /* TAO_VALUE_TYPECODE_CPP */ diff --git a/TAO/tao/Value_TypeCode.h b/TAO/tao/Value_TypeCode.h new file mode 100644 index 00000000000..5e981127a66 --- /dev/null +++ b/TAO/tao/Value_TypeCode.h @@ -0,0 +1,172 @@ +// -*- C++ -*- + +//============================================================================= +/** + * @file Value_TypeCode.h + * + * $Id$ + * + * Header file for a @c tk_value and @c tk_event + * @c CORBA::TypeCodes. + * + * @author Ossama Othman <ossama@dre.vanderbilt.edu> + */ +//============================================================================= + +#ifndef TAO_VALUE_TYPECODE_H +#define TAO_VALUE_TYPECODE_H + +#include /**/ "ace/pre.h" + +#include "tao/TypeCode.h" + +#if !defined (ACE_LACKS_PRAGMA_ONCE) +# pragma once +#endif /* ACE_LACKS_PRAGMA_ONCE */ + +#include "tao/TypeCode_Base_Attributes.h" +#include "tao/OBV_Constants.h" + + +namespace TAO +{ + namespace TypeCode + { + template<typename StringType> struct Value_Field; + + /** + * @class Value + * + * @brief @c CORBA::TypeCode implementation for an OMG IDL + * @c valuetype or @c event. + * + * This class implements a @c CORBA::TypeCode for an OMG IDL + * @c valuetype or @c event. + */ + template <typename StringType, + class FieldArrayType, + CORBA::TCKind Kind, + class RefCountPolicy> + class Value + : public CORBA::TypeCode, + private RefCountPolicy + { + public: + + /// Constructor. + Value (char const * id, + char const * name, + CORBA::ValueModifier modifier, + CORBA::TypeCode_ptr * concrete_base, + Value_Field<StringType> const * fields, + CORBA::ULong nfields); + + /** + * @name TAO-specific @c CORBA::TypeCode Methods + * + * Methods required by TAO's implementation of the + * @c CORBA::TypeCode class. + * + * @see @c CORBA::TypeCode + */ + //@{ + virtual bool tao_marshal (TAO_OutputCDR & cdr) const; + virtual void tao_duplicate (void); + virtual void tao_release (void); + //@} + + protected: + + /** + * @name @c TAO CORBA::TypeCode Template Methods + * + * @c tk_value or @c tk_event @c CORBA::TypeCode -specific + * template methods. + * + * @see @c CORBA::TypeCode + */ + //@{ + virtual CORBA::Boolean equal_i (CORBA::TypeCode_ptr tc + ACE_ENV_ARG_DECL) const; + virtual CORBA::Boolean equivalent_i (CORBA::TypeCode_ptr tc + ACE_ENV_ARG_DECL) const; + virtual CORBA::TCKind kind_i (ACE_ENV_SINGLE_ARG_DECL) const; + virtual CORBA::TypeCode_ptr get_compact_typecode_i ( + ACE_ENV_SINGLE_ARG_DECL) const; + virtual char const * id_i (ACE_ENV_SINGLE_ARG_DECL) const; + virtual char const * name_i (ACE_ENV_SINGLE_ARG_DECL) const; + virtual CORBA::ULong member_count_i (ACE_ENV_SINGLE_ARG_DECL) const; + virtual char const * member_name_i (CORBA::ULong index + ACE_ENV_ARG_DECL) const; + virtual CORBA::TypeCode_ptr member_type_i (CORBA::ULong index + ACE_ENV_ARG_DECL) const; + virtual CORBA::Visibility member_visibility_i (CORBA::ULong index + ACE_ENV_ARG_DECL) const; + virtual CORBA::ValueModifier type_modifier ( + ACE_ENV_SINGLE_ARG_DECL) const; + virtual CORBA::TypeCode_ptr concrete_base_type ( + ACE_ENV_SINGLE_ARG_DECL) const; + //@} + + private: + + /// Get pointer to the underlying @c Value_Field array. + Value_Field<StringType> const * fields (void) const; + + private: + + /** + * @c Valuetype Attributes + * + * Attributes representing the structure of an OMG IDL + * @c valuetype or @c event. + * + * @note These attributes are declared in the order in which + * they are marshaled into a CDR stream in order to + * increase cache hits by improving spatial locality. + */ + //@{ + + /// Base attributes containing repository ID and name of + /// @c valuetype. + Base_Attributes<StringType> const base_attributes_; + + /// The @c ValueModifier of the @c valuetype of @c eventtype + /// represented by this @c TypeCode. + CORBA::ValueModifier const type_modifier_; + + /// The @c TypeCode corresponding to the concrete base + /// @c valuetype or @c eventtype. + CORBA::TypeCode_ptr * const concrete_base_; + + /// The number of fields in the OMG IDL value. + CORBA::ULong const nfields_; + + /// Array of @c TAO::TypeCode fields representing structure of the + /// OMG IDL defined @c value. + FieldArrayType const fields_; + + //@} + + }; + + } // End namespace TypeCode +} // End namespace TAO + + +#ifdef __ACE_INLINE__ +# include "tao/Value_TypeCode.inl" +#endif /* __ACE_INLINE__ */ + +#ifdef ACE_TEMPLATES_REQUIRE_SOURCE +# include "tao/Value_TypeCode.cpp" +#endif /* ACE_TEMPLATES_REQUIRE_SOURCE */ + +#ifdef ACE_TEMPLATES_REQUIRE_PRAGMA +# pragma implementation ("Value_TypeCode.cpp") +#endif /* ACE_TEMPLATES_REQUIRE_PRAGMA */ + + +#include /**/ "ace/post.h" + +#endif /* TAO_VALUE_TYPECODE_H */ diff --git a/TAO/tao/Value_TypeCode.inl b/TAO/tao/Value_TypeCode.inl new file mode 100644 index 00000000000..e54295cc7e8 --- /dev/null +++ b/TAO/tao/Value_TypeCode.inl @@ -0,0 +1,66 @@ +// -*- C++ -*- +// +// $Id$ + +#include "tao/TypeCode_Value_Field.h" +#include "tao/True_RefCount_Policy.h" + +#include "ace/Auto_Ptr.h" + + +template <typename StringType, + class FieldArrayType, + CORBA::TCKind Kind, + class RefCountPolicy> +ACE_INLINE +TAO::TypeCode::Value<StringType, FieldArrayType, Kind, RefCountPolicy>::Value ( + char const * id, + char const * name, + CORBA::ValueModifier modifier, + CORBA::TypeCode_ptr * concrete_base, + Value_Field<StringType> const * fields, + CORBA::ULong nfields) + : base_attributes_ (id, name) + , type_modifier_ (modifier) + , concrete_base_ (concrete_base) + , nfields_ (nfields) + , fields_ (fields) +{ +} + +template <typename StringType, + class FieldArrayType, + CORBA::TCKind Kind, + class RefCountPolicy> +ACE_INLINE TAO::TypeCode::Value_Field<StringType> const * +TAO::TypeCode::Value<StringType, + FieldArrayType, + Kind, + RefCountPolicy>::fields (void) const +{ + return this->fields_; +} + +// ------------------------------------------------------------- +// Member specializations +// ------------------------------------------------------------- + +ACE_INLINE TAO::TypeCode::Value_Field<CORBA::String_var> const * +TAO::TypeCode::Value< + CORBA::String_var, + ACE_Auto_Array_Ptr<TAO::TypeCode::Value_Field<CORBA::String_var> const>, + CORBA::tk_value, + TAO::True_RefCount_Policy>::fields (void) const +{ + return this->fields_.get (); +} + +ACE_INLINE TAO::TypeCode::Value_Field<CORBA::String_var> const * +TAO::TypeCode::Value< + CORBA::String_var, + ACE_Auto_Array_Ptr<TAO::TypeCode::Value_Field<CORBA::String_var> const>, + CORBA::tk_event, + TAO::True_RefCount_Policy>::fields (void) const +{ + return this->fields_.get (); +} diff --git a/TAO/tao/append.cpp b/TAO/tao/append.cpp index 9f90343bd48..585a517aa95 100644 --- a/TAO/tao/append.cpp +++ b/TAO/tao/append.cpp @@ -23,11 +23,12 @@ #include "tao/debug.h" #include "tao/Valuetype_Adapter.h" #include "tao/ORB_Core.h" -#include "tao/Typecode.h" +#include "tao/TypeCode.h" #include "tao/Marshal.h" #include "tao/Any_Unknown_IDL_Type.h" #include "tao/CDR.h" #include "tao/SystemException.h" +#include "tao/TypeCode_Constants.h" #include "ace/Dynamic_Service.h" @@ -51,7 +52,10 @@ TAO_Marshal_Primitive::append (CORBA::TypeCode_ptr tc, TAO::traverse_status retval = TAO::TRAVERSE_CONTINUE; // status of encode operation - switch (tc->kind_) + CORBA::TCKind const k = tc->kind (ACE_ENV_SINGLE_ARG_PARAMETER); + ACE_CHECK_RETURN (TAO::TRAVERSE_STOP) + + switch (k) { case CORBA::tk_null: case CORBA::tk_void: @@ -128,7 +132,7 @@ TAO_Marshal_Any::append (CORBA::TypeCode_ptr, TAO_Marshal_Object::perform_append (elem_tc.in (), src, dest - ACE_ENV_ARG_PARAMETER); + ACE_ENV_ARG_PARAMETER); ACE_CHECK_RETURN (TAO::TRAVERSE_STOP); if (retval != TAO::TRAVERSE_CONTINUE) @@ -167,7 +171,7 @@ TAO_Marshal_TypeCode::append (CORBA::TypeCode_ptr, // Typecodes with empty parameter lists all have preallocated // constants. We use those to reduce memory consumption and // heap access ... also, to speed things up! - if ((kind < CORBA::TC_KIND_COUNT) + if ((kind < CORBA::TAO_TC_KIND_COUNT) || (kind == ~0u)) { // Either a non-constant typecode or an indirected typecode. @@ -186,7 +190,7 @@ TAO_Marshal_TypeCode::append (CORBA::TypeCode_ptr, TAO_Marshal_Object::perform_append (CORBA::_tc_long, src, dest - ACE_ENV_ARG_PARAMETER); + ACE_ENV_ARG_PARAMETER); ACE_CHECK_RETURN (TAO::TRAVERSE_STOP); } break; @@ -199,7 +203,7 @@ TAO_Marshal_TypeCode::append (CORBA::TypeCode_ptr, TAO_Marshal_Object::perform_append (CORBA::_tc_long, src, dest - ACE_ENV_ARG_PARAMETER); + ACE_ENV_ARG_PARAMETER); ACE_CHECK_RETURN (TAO::TRAVERSE_STOP); } break; @@ -273,7 +277,7 @@ TAO_Marshal_Principal::append (CORBA::TypeCode_ptr, return TAO_Marshal_Object::perform_append (TAO::TC_opaque, src, dest - ACE_ENV_ARG_PARAMETER); + ACE_ENV_ARG_PARAMETER); } TAO::traverse_status @@ -563,8 +567,8 @@ TAO_Marshal_Union::append (CORBA::TypeCode_ptr tc, { TAO::Unknown_IDL_Type *unk = dynamic_cast<TAO::Unknown_IDL_Type *> (impl); - - // We don't want unk's rd_ptr to move, in case + + // We don't want unk's rd_ptr to move, in case // we are shared by another Any, so we use this // to copy the state, not the buffer. TAO_InputCDR for_reading (unk->_tao_get_cdr ()); @@ -628,7 +632,7 @@ TAO_Marshal_Union::append (CORBA::TypeCode_ptr tc, return TAO_Marshal_Object::perform_append (member_tc.in (), src, dest - ACE_ENV_ARG_PARAMETER); + ACE_ENV_ARG_PARAMETER); } // If we're here, we have an implicit default case, and we @@ -644,7 +648,7 @@ TAO_Marshal_Union::append (CORBA::TypeCode_ptr tc, return TAO_Marshal_Object::perform_append (member_tc.in (), src, dest - ACE_ENV_ARG_PARAMETER); + ACE_ENV_ARG_PARAMETER); } TAO::traverse_status @@ -1067,7 +1071,7 @@ TAO_Marshal_Array::append (CORBA::TypeCode_ptr tc, retval = TAO_Marshal_Object::perform_append (tc2.in (), src, dest - ACE_ENV_ARG_PARAMETER); + ACE_ENV_ARG_PARAMETER); ACE_CHECK_RETURN (TAO::TRAVERSE_STOP); } break; @@ -1105,7 +1109,7 @@ TAO_Marshal_Alias::append (CORBA::TypeCode_ptr tc, retval = TAO_Marshal_Object::perform_append (tc2.in (), src, dest - ACE_ENV_ARG_PARAMETER); + ACE_ENV_ARG_PARAMETER); ACE_CHECK_RETURN (TAO::TRAVERSE_STOP); if (retval == TAO::TRAVERSE_CONTINUE diff --git a/TAO/tao/corba.h b/TAO/tao/corba.h index 822d5499ad2..5b52282e16d 100644 --- a/TAO/tao/corba.h +++ b/TAO/tao/corba.h @@ -34,7 +34,7 @@ // The definitions are included in the same order as they are declared // in corbafwd.h -#include "tao/Typecode.h" +#include "tao/TypeCode.h" #include "tao/Environment.h" #include "tao/SystemException.h" diff --git a/TAO/tao/diffs/Typecode_types.diff b/TAO/tao/diffs/Typecode_types.diff index 4ff1392d63f..46dd87ebbf9 100644 --- a/TAO/tao/diffs/Typecode_types.diff +++ b/TAO/tao/diffs/Typecode_types.diff @@ -43,7 +43,7 @@ + // This symbol is not defined by CORBA 3.0. It's used to speed up + // dispatch based on TCKind values, and lets many important ones + // just be table lookups. It must always be the last enum value!! -+ , TC_KIND_COUNT ++ , TAO_TC_KIND_COUNT }; typedef TCKind &TCKind_out; diff --git a/TAO/tao/operation_details.cpp b/TAO/tao/operation_details.cpp index d8d2e27a3e3..24436535e49 100644 --- a/TAO/tao/operation_details.cpp +++ b/TAO/tao/operation_details.cpp @@ -1,7 +1,7 @@ //$Id$ #include "operation_details.h" #include "Stub.h" -#include "Typecode.h" +#include "TypeCode.h" #include "ORB_Constants.h" #include "DynamicC.h" #include "Exception_Data.h" diff --git a/TAO/tao/skip.cpp b/TAO/tao/skip.cpp index bf9ed47dac2..5e8742763cb 100644 --- a/TAO/tao/skip.cpp +++ b/TAO/tao/skip.cpp @@ -23,7 +23,7 @@ #include "debug.h" #include "Valuetype_Adapter.h" #include "ORB_Core.h" -#include "Typecode.h" +#include "TypeCode.h" #include "Any_Unknown_IDL_Type.h" #include "tao/CDR.h" #include "SystemException.h" @@ -44,7 +44,10 @@ TAO_Marshal_Primitive::skip (CORBA::TypeCode_ptr tc, // Status of skip operation. TAO::traverse_status retval = TAO::TRAVERSE_CONTINUE; - switch (tc->kind_) + CORBA::TCKind const k = tc->kind (ACE_ENV_SINGLE_ARG_PARAMETER); + ACE_CHECK_RETURN (TAO::TRAVERSE_STOP) + + switch (k) { case CORBA::tk_null: case CORBA::tk_void: @@ -132,7 +135,7 @@ TAO_Marshal_TypeCode::skip (CORBA::TypeCode_ptr, // Typecodes with empty parameter lists all have preallocated // constants. We use those to reduce memory consumption and // heap access ... also, to speed things up! - if ((kind < CORBA::TC_KIND_COUNT) || + if ((kind < CORBA::TAO_TC_KIND_COUNT) || (kind == ~0u)) { // Either a non-constant typecode or an indirected typecode. @@ -507,8 +510,8 @@ TAO_Marshal_Union::skip (CORBA::TypeCode_ptr tc, { TAO::Unknown_IDL_Type *unk = dynamic_cast<TAO::Unknown_IDL_Type *> (impl); - - // We don't want unk's rd_ptr to move, in case + + // We don't want unk's rd_ptr to move, in case // we are shared by another Any, so we use this // to copy the state, not the buffer. TAO_InputCDR for_reading (unk->_tao_get_cdr ()); diff --git a/TAO/tao/tao.mpc b/TAO/tao/tao.mpc index ce8d2cdfad5..82099dd702a 100644 --- a/TAO/tao/tao.mpc +++ b/TAO/tao/tao.mpc @@ -80,6 +80,7 @@ project(TAO) : acelib, core, tao_output, taodefaults, pidl, extra_core { Dynamic_ParameterC.cpp DynamicA.cpp DynamicC.cpp + Empty_Param_TypeCode.cpp Encodable.cpp Endpoint.cpp Endpoint_Selector_Factory.cpp @@ -256,7 +257,7 @@ project(TAO) : acelib, core, tao_output, taodefaults, pidl, extra_core { Transport_Mux_Strategy.cpp Transport_Timer.cpp TSS_Resources.cpp - Typecode.cpp + TypeCode.cpp Typecode_typesC.cpp Typecode_Constants.cpp TypeCodeFactory_Adapter.cpp @@ -294,6 +295,7 @@ project(TAO) : acelib, core, tao_output, taodefaults, pidl, extra_core { Adapter_Factory.h Adapter.h Adapter_Registry.h + Alias_TypeCode.h Allocator.h Any_Arg_Traits.h Any_Array_Impl_T.h @@ -393,6 +395,7 @@ project(TAO) : acelib, core, tao_output, taodefaults, pidl, extra_core { FILE_Parser.h Fixed_Array_Argument_T.h Fixed_Size_Argument_T.h + Fixed_TypeCode.h FloatSeqC.h FloatSeqS.h Flushing_Strategy.h @@ -479,6 +482,7 @@ project(TAO) : acelib, core, tao_output, taodefaults, pidl, extra_core { Object_Proxy_Impl.h Object_Ref_Table.h Object_T.h + Objref_TypeCode.h Objref_VarOut_T.h OctetSeqC.h OctetSeqS.h @@ -537,6 +541,7 @@ project(TAO) : acelib, core, tao_output, taodefaults, pidl, extra_core { Seq_Out_T.h Sequence.h Sequence_T.h + Sequence_TypeCode.h Seq_Var_T.h Server_Strategy_Factory.h Service_Callbacks.h @@ -551,6 +556,7 @@ project(TAO) : acelib, core, tao_output, taodefaults, pidl, extra_core { Special_Basic_Argument_T.h StringSeqC.h StringSeqS.h + Struct_TypeCode.h Stub_Factory.h Stub.h Synch_Invocation.h @@ -586,9 +592,15 @@ project(TAO) : acelib, core, tao_output, taodefaults, pidl, extra_core { Transport_Mux_Strategy.h Transport_Timer.h TSS_Resources.h - Typecode_Constants.h + TypeCode_Constants.h + TypeCode_Case.h + TypeCode_Default_Case.h + TypeCode_Enumerator.h + TypeCode_Non_Default_Case.h + TypeCode_Struct_Field.h + TypeCode_Value_Field.h + TypeCode.h TypeCodeFactory_Adapter.h - Typecode.h Typecode_typesC.h Typecode_typesS.h UB_String_Arguments.h @@ -597,11 +609,14 @@ project(TAO) : acelib, core, tao_output, taodefaults, pidl, extra_core { ULongLongSeqS.h ULongSeqC.h ULongSeqS.h + Union_TypeCode.h UserException.h UShortSeqC.h UShortSeqS.h UTF16_BOM_Factory.h UTF16_BOM_Translator.h + Value_Box_TypeCode.h + Value_TypeCode.h Valuetype_Adapter.h Var_Array_Argument_T.h varbase.h @@ -630,9 +645,25 @@ project(TAO) : acelib, core, tao_output, taodefaults, pidl, extra_core { Template_Files { *_T.cpp Acceptor_Impl.cpp + Alias_TypeCode.cpp Condition.cpp Connector_Impl.cpp + Fixed_TypeCode.cpp + Objref_TypeCode.cpp + Sequence_TypeCode.cpp + String_TypeCode.cpp + Struct_TypeCode.cpp TAO_Singleton.cpp + TypeCode_Base_Attributes.cpp + TypeCode_Case.cpp + TypeCode_Default_Case.cpp + TypeCode_Enumerator.cpp + TypeCode_Non_Default_Case.cpp + TypeCode_Struct_Field.cpp + TypeCode_Value_Field.cpp + Union_TypeCode.cpp + Value_Box_TypeCode.cpp + Value_TypeCode.cpp orb.idl } |