From b9c4059a2b5a0f1426160bac985a77468a2770a1 Mon Sep 17 00:00:00 2001 From: Ossama Othman Date: Wed, 16 Mar 2005 22:34:39 +0000 Subject: *** empty log message *** --- .../be/be_visitor_typecode/value_typecode.cpp | 154 +++++++++++++++------ .../be_visitor_typecode/value_typecode.h | 18 +-- 2 files changed, 121 insertions(+), 51 deletions(-) diff --git a/TAO/TAO_IDL/be/be_visitor_typecode/value_typecode.cpp b/TAO/TAO_IDL/be/be_visitor_typecode/value_typecode.cpp index 9bb7f5175db..941dbde2af5 100644 --- a/TAO/TAO_IDL/be/be_visitor_typecode/value_typecode.cpp +++ b/TAO/TAO_IDL/be/be_visitor_typecode/value_typecode.cpp @@ -25,7 +25,7 @@ TAO::be_visitor_value_typecode::be_visitor_value_typecode ( } int -TAO::be_visitor_value_typecode::visit_structure (AST_Structure * node) +TAO::be_visitor_value_typecode::visit_structure (be_valuetype * node) { TAO_OutStream & os = *this->ctx_->stream (); @@ -33,65 +33,141 @@ TAO::be_visitor_value_typecode::visit_structure (AST_Structure * node) << "// TAO_IDL - Generated from" << be_nl << "// " << __FILE__ << ":" << __LINE__ << be_nl << be_nl; + size_t const count = + node->data_members_count (); - std::string const fields_name (std::string ("_tao_fields_") - + node->flat_name ()); - - // Generate array containing struct field characteristics. - os << "static TAO::TypeCode::Value_Field 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::Value const *," << be_nl - << " CORBA::tk_" - << (this->is_exception_ ? "except" : "struct") << "," << 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 - << "_tao_fields_" << node->flat_name () << "," << be_nl - << node->nfields () << ");" << be_uidt_nl - << be_uidt_nl; + 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 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 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::Value const *," << be_nl + << " CORBA::tk_" + << (dynamic_cast (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 + << "_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 (AST_Structure * node) +TAO::be_visitor_value_typecode::visit_members (be_valuetype * node) { - AST_Field ** member_ptr = 0; + TAO_OutStream & os = *this->ctx_->stream (); - size_t const count = node->nfields (); + size_t const count = + node->data_members_count (); - TAO_OutStream & os = *this->ctx_->stream (); + size_t i = 0; - for (size_t i = 0; i < count; ++i) + for (UTL_ScopeActiveIterator si (node, UTL_Scope::IK_decls); + !si.is_done (); + si.next(), ++i) { - node->field (member_ptr, 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 (*member_ptr); + be_decl::narrow_from_decl (field); be_type * const member_type = - be_type::narrow_from_decl ((*member_ptr)->field_type ()); + be_type::narrow_from_decl (field->field_type ()); os << "{ " << "\"" << member_decl->original_local_name () << "\", " - << "&" << member_type->tc_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 << ","; 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 index 8afa9bbc716..b52b14c7562 100644 --- a/TAO/TAO_IDL/be_include/be_visitor_typecode/value_typecode.h +++ b/TAO/TAO_IDL/be_include/be_visitor_typecode/value_typecode.h @@ -21,9 +21,9 @@ namespace TAO { /** - * @class be_visitor_struct_typecode + * @class be_visitor_value_typecode * - * @brief Structure TypeCode generation visitor. + * @brief valuetype TypeCode generation visitor. * * Structure TypeCode generation visitor. */ @@ -33,28 +33,22 @@ namespace TAO public: /// Constructor. - be_visitor_value_typecode (be_visitor_context * ctx, - bool is_exception); + be_visitor_value_typecode (be_visitor_context * ctx); /// Visit a structure. /** - * @todo The legacy method name "@c visit_structure()" is + * @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 (AST_Structure * node); + virtual int visit_valuetype (be_valuetype * 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_; + int visit_members (be_valuetype * node); }; -- cgit v1.2.1