summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOssama Othman <ossama-othman@users.noreply.github.com>2005-03-16 22:34:39 +0000
committerOssama Othman <ossama-othman@users.noreply.github.com>2005-03-16 22:34:39 +0000
commitb9c4059a2b5a0f1426160bac985a77468a2770a1 (patch)
tree1ecb7dbf132c6b7159c0e30bc07d78246a852667
parentdaa9b3617579a4b3a7b9d26d94e396ab93ee2441 (diff)
downloadATCD-b9c4059a2b5a0f1426160bac985a77468a2770a1.tar.gz
*** empty log message ***
-rw-r--r--TAO/TAO_IDL/be/be_visitor_typecode/value_typecode.cpp154
-rw-r--r--TAO/TAO_IDL/be_include/be_visitor_typecode/value_typecode.h18
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<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::Value<char const *," << be_nl
- << " TAO::TypeCode::Value_Field<char const *> 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<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 *> 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<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
+ << "_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);
};