From 3b1746fcbe4fdc95aa7f50cfd53cbba535483309 Mon Sep 17 00:00:00 2001 From: fields_t Date: Wed, 15 Jun 2005 20:47:58 +0000 Subject: ChangeLogTag:Wed Jun 15 13:46:48 MST 2005 Trevor Fields --- TAO/ChangeLog | 42 + .../be/be_visitor_array/serializer_op_ch.cpp | 166 +++ .../be/be_visitor_array/serializer_op_cs.cpp | 1225 ++++++++++++++++++ .../be/be_visitor_enum/serializer_op_ch.cpp | 62 + .../be/be_visitor_enum/serializer_op_cs.cpp | 76 ++ .../be/be_visitor_field/serializer_op_ch.cpp | 249 ++++ .../be/be_visitor_field/serializer_op_cs.cpp | 1137 +++++++++++++++++ TAO/TAO_IDL/be/be_visitor_module/serializer_op.cpp | 52 + TAO/TAO_IDL/be/be_visitor_root/serializer_op.cpp | 52 + .../be/be_visitor_sequence/serializer_op_ch.cpp | 117 ++ .../be/be_visitor_sequence/serializer_op_cs.cpp | 1333 ++++++++++++++++++++ .../be/be_visitor_structure/serializer_op_ch.cpp | 140 ++ .../be/be_visitor_structure/serializer_op_cs.cpp | 311 +++++ .../be/be_visitor_typedef/serializer_op_ch.cpp | 294 +++++ .../be/be_visitor_typedef/serializer_op_cs.cpp | 264 ++++ .../be/be_visitor_union/serializer_op_ch.cpp | 92 ++ .../be/be_visitor_union/serializer_op_cs.cpp | 468 +++++++ .../be_visitor_union_branch/serializer_op_ch.cpp | 215 ++++ .../be_visitor_union_branch/serializer_op_cs.cpp | 1319 +++++++++++++++++++ .../be_include/be_visitor_array/serializer_op_ch.h | 55 + .../be_include/be_visitor_array/serializer_op_cs.h | 97 ++ .../be_include/be_visitor_enum/serializer_op_ch.h | 48 + .../be_include/be_visitor_enum/serializer_op_cs.h | 48 + .../be_include/be_visitor_field/serializer_op_ch.h | 66 + .../be_include/be_visitor_field/serializer_op_cs.h | 93 ++ .../be_include/be_visitor_module/serializer_op.h | 50 + .../be_include/be_visitor_root/serializer_op.h | 49 + .../be_visitor_sequence/serializer_op_ch.h | 50 + .../be_visitor_sequence/serializer_op_cs.h | 107 ++ .../be_visitor_structure/serializer_op_ch.h | 49 + .../be_visitor_structure/serializer_op_cs.h | 55 + .../be_visitor_typedef/serializer_op_ch.h | 67 + .../be_visitor_typedef/serializer_op_cs.h | 64 + .../be_include/be_visitor_union/serializer_op_ch.h | 50 + .../be_include/be_visitor_union/serializer_op_cs.h | 52 + .../be_visitor_union_branch/serializer_op_ch.h | 67 + .../be_visitor_union_branch/serializer_op_cs.h | 64 + 37 files changed, 8745 insertions(+) create mode 100644 TAO/TAO_IDL/be/be_visitor_array/serializer_op_ch.cpp create mode 100644 TAO/TAO_IDL/be/be_visitor_array/serializer_op_cs.cpp create mode 100644 TAO/TAO_IDL/be/be_visitor_enum/serializer_op_ch.cpp create mode 100644 TAO/TAO_IDL/be/be_visitor_enum/serializer_op_cs.cpp create mode 100644 TAO/TAO_IDL/be/be_visitor_field/serializer_op_ch.cpp create mode 100644 TAO/TAO_IDL/be/be_visitor_field/serializer_op_cs.cpp create mode 100644 TAO/TAO_IDL/be/be_visitor_module/serializer_op.cpp create mode 100644 TAO/TAO_IDL/be/be_visitor_root/serializer_op.cpp create mode 100644 TAO/TAO_IDL/be/be_visitor_sequence/serializer_op_ch.cpp create mode 100644 TAO/TAO_IDL/be/be_visitor_sequence/serializer_op_cs.cpp create mode 100644 TAO/TAO_IDL/be/be_visitor_structure/serializer_op_ch.cpp create mode 100644 TAO/TAO_IDL/be/be_visitor_structure/serializer_op_cs.cpp create mode 100644 TAO/TAO_IDL/be/be_visitor_typedef/serializer_op_ch.cpp create mode 100644 TAO/TAO_IDL/be/be_visitor_typedef/serializer_op_cs.cpp create mode 100644 TAO/TAO_IDL/be/be_visitor_union/serializer_op_ch.cpp create mode 100644 TAO/TAO_IDL/be/be_visitor_union/serializer_op_cs.cpp create mode 100644 TAO/TAO_IDL/be/be_visitor_union_branch/serializer_op_ch.cpp create mode 100644 TAO/TAO_IDL/be/be_visitor_union_branch/serializer_op_cs.cpp create mode 100644 TAO/TAO_IDL/be_include/be_visitor_array/serializer_op_ch.h create mode 100644 TAO/TAO_IDL/be_include/be_visitor_array/serializer_op_cs.h create mode 100644 TAO/TAO_IDL/be_include/be_visitor_enum/serializer_op_ch.h create mode 100644 TAO/TAO_IDL/be_include/be_visitor_enum/serializer_op_cs.h create mode 100644 TAO/TAO_IDL/be_include/be_visitor_field/serializer_op_ch.h create mode 100644 TAO/TAO_IDL/be_include/be_visitor_field/serializer_op_cs.h create mode 100644 TAO/TAO_IDL/be_include/be_visitor_module/serializer_op.h create mode 100644 TAO/TAO_IDL/be_include/be_visitor_root/serializer_op.h create mode 100644 TAO/TAO_IDL/be_include/be_visitor_sequence/serializer_op_ch.h create mode 100644 TAO/TAO_IDL/be_include/be_visitor_sequence/serializer_op_cs.h create mode 100644 TAO/TAO_IDL/be_include/be_visitor_structure/serializer_op_ch.h create mode 100644 TAO/TAO_IDL/be_include/be_visitor_structure/serializer_op_cs.h create mode 100644 TAO/TAO_IDL/be_include/be_visitor_typedef/serializer_op_ch.h create mode 100644 TAO/TAO_IDL/be_include/be_visitor_typedef/serializer_op_cs.h create mode 100644 TAO/TAO_IDL/be_include/be_visitor_union/serializer_op_ch.h create mode 100644 TAO/TAO_IDL/be_include/be_visitor_union/serializer_op_cs.h create mode 100644 TAO/TAO_IDL/be_include/be_visitor_union_branch/serializer_op_ch.h create mode 100644 TAO/TAO_IDL/be_include/be_visitor_union_branch/serializer_op_cs.h diff --git a/TAO/ChangeLog b/TAO/ChangeLog index ef7a4838314..5fac8627172 100644 --- a/TAO/ChangeLog +++ b/TAO/ChangeLog @@ -1,3 +1,45 @@ +Wed Jun 15 13:46:48 MST 2005 Trevor Fields + + * TAO_IDL/be/be_visitor_array/serializer_op_ch.cpp: + * TAO_IDL/be/be_visitor_array/serializer_op_cs.cpp: + * TAO_IDL/be/be_visitor_enum/serializer_op_ch.cpp: + * TAO_IDL/be/be_visitor_enum/serializer_op_cs.cpp: + * TAO_IDL/be/be_visitor_field/serializer_op_ch.cpp: + * TAO_IDL/be/be_visitor_field/serializer_op_cs.cpp: + * TAO_IDL/be/be_visitor_module/serializer_op.cpp: + * TAO_IDL/be/be_visitor_root/serializer_op.cpp: + * TAO_IDL/be/be_visitor_sequence/serializer_op_ch.cpp: + * TAO_IDL/be/be_visitor_sequence/serializer_op_cs.cpp: + * TAO_IDL/be/be_visitor_structure/serializer_op_ch.cpp: + * TAO_IDL/be/be_visitor_structure/serializer_op_cs.cpp: + * TAO_IDL/be/be_visitor_typedef/serializer_op_ch.cpp: + * TAO_IDL/be/be_visitor_typedef/serializer_op_cs.cpp: + * TAO_IDL/be/be_visitor_union/serializer_op_ch.cpp: + * TAO_IDL/be/be_visitor_union/serializer_op_cs.cpp: + * TAO_IDL/be/be_visitor_union_branch/serializer_op_ch.cpp: + * TAO_IDL/be/be_visitor_union_branch/serializer_op_cs.cpp: + * TAO_IDL/be_include/be_visitor_array/serializer_op_ch.h: + * TAO_IDL/be_include/be_visitor_array/serializer_op_cs.h: + * TAO_IDL/be_include/be_visitor_enum/serializer_op_ch.h: + * TAO_IDL/be_include/be_visitor_enum/serializer_op_cs.h: + * TAO_IDL/be_include/be_visitor_field/serializer_op_ch.h: + * TAO_IDL/be_include/be_visitor_field/serializer_op_cs.h: + * TAO_IDL/be_include/be_visitor_module/serializer_op.h: + * TAO_IDL/be_include/be_visitor_root/serializer_op.h: + * TAO_IDL/be_include/be_visitor_sequence/serializer_op_ch.h: + * TAO_IDL/be_include/be_visitor_sequence/serializer_op_cs.h: + * TAO_IDL/be_include/be_visitor_structure/serializer_op_ch.h: + * TAO_IDL/be_include/be_visitor_structure/serializer_op_cs.h: + * TAO_IDL/be_include/be_visitor_typedef/serializer_op_ch.h: + * TAO_IDL/be_include/be_visitor_typedef/serializer_op_cs.h: + * TAO_IDL/be_include/be_visitor_union/serializer_op_ch.h: + * TAO_IDL/be_include/be_visitor_union/serializer_op_cs.h: + * TAO_IDL/be_include/be_visitor_union_branch/serializer_op_ch.h: + * TAO_IDL/be_include/be_visitor_union_branch/serializer_op_cs.h: + + Addin additional files for providing serialization for sending + in DDS. + Wed Jun 15 12:36:04 MST 2005 Trevor Fields * TAO_IDL/be/be_codegen.cpp: diff --git a/TAO/TAO_IDL/be/be_visitor_array/serializer_op_ch.cpp b/TAO/TAO_IDL/be/be_visitor_array/serializer_op_ch.cpp new file mode 100644 index 00000000000..a2a0ecd5e63 --- /dev/null +++ b/TAO/TAO_IDL/be/be_visitor_array/serializer_op_ch.cpp @@ -0,0 +1,166 @@ +// +// $Id$ +// + +// ============================================================================ +// +// = LIBRARY +// TAO IDL +// +// = FILENAME +// serializer_op_ch.cpp +// +// = DESCRIPTION +// Visitor for code generation of Arrays for the +// TAO::DCPS::Serializer operators in the client header. +// +// = AUTHOR +// Scott Harris based on code by Aniruddha Gokhale +// +// ============================================================================ + +#include "be_visitor_sequence/serializer_op_ch.h" + +ACE_RCSID (be_visitor_array, + serializer_op_ch, + "$Id$") + +// *************************************************************************** +// Array visitor for generating Serializer operator declarations in the client header +// *************************************************************************** + +be_visitor_array_serializer_op_ch::be_visitor_array_serializer_op_ch ( + be_visitor_context *ctx + ) + : be_visitor_decl (ctx) +{ +} + +be_visitor_array_serializer_op_ch::~be_visitor_array_serializer_op_ch (void) +{ +} + + +void +be_visitor_array_serializer_op_ch::gen_arg_ref(be_array *node) +{ + TAO_OutStream *os = this->ctx_->stream (); + + if (!this->ctx_->tdef ()) + { + be_scope* scope = be_scope::narrow_from_scope (node->defined_in ()); + be_decl* parent = scope->decl (); + + *os << parent->full_name () + << "::_" << node->local_name () + << "_forany &);" << be_nl; + } + else + { + *os << node->name () << "_forany &);" << be_nl; + } +} + +int +be_visitor_array_serializer_op_ch::visit_array (be_array *node) +{ + if (node->cli_hdr_serializer_op_gen () || node->imported () || node->is_local ()) + { + return 0; + } + + TAO_OutStream *os = this->ctx_->stream (); + + be_type *bt = be_type::narrow_from_decl (node->base_type ()); + AST_Decl::NodeType nt = bt->node_type (); + + // If the node is an array of anonymous sequence, we need to + // generate the sequence's Serializer operator declaration here. + if (nt == AST_Decl::NT_sequence && bt->anonymous ()) + { + be_visitor_sequence_serializer_op_ch visitor (this->ctx_); + + if (bt->accept (&visitor) == -1) + { + ACE_ERROR_RETURN ((LM_ERROR, + "be_visitor_array_serializer_op_ch::" + "visit_array - " + "accept on anonymous base type failed\n"), + -1); + } + } + + // If the array is an anonymous member and if its element type + // is a declaration (not a reference), we must generate code for + // the declaration. + if (this->ctx_->alias () == 0 // Not a typedef. + && bt->is_child (this->ctx_->scope ())) + { + int status = 0; + be_visitor_context ctx (*this->ctx_); + + switch (nt) + { + case AST_Decl::NT_enum: + { + be_visitor_enum_serializer_op_ch ec_visitor (&ctx); + status = bt->accept (&ec_visitor); + break; + } + case AST_Decl::NT_struct: + { + be_visitor_structure_serializer_op_ch sc_visitor (&ctx); + status = bt->accept (&sc_visitor); + break; + } + case AST_Decl::NT_union: + { + be_visitor_union_serializer_op_ch uc_visitor (&ctx); + status = bt->accept (&uc_visitor); + break; + } + default: + break; + } + + if (status == -1) + { + ACE_ERROR_RETURN ((LM_ERROR, + "(%N:%l) be_visitor_array_ch::" + "visit_array - " + "array base type codegen failed\n"), + -1); + } + } + + *os << be_nl << be_nl << "// TAO_IDL - Generated from" << be_nl + << "// " << __FILE__ << ":" << __LINE__ << be_nl << be_nl; + + // Set the sub state as generating code for the size method + *os << be_global->stub_export_macro () + << " size_t _dcps_max_marshaled_size (" + << "const "; + this->gen_arg_ref(node); + + *os << be_global->stub_export_macro () + << " CORBA::Boolean _tao_is_bounded_size (" + << "const "; + this->gen_arg_ref(node); + + *os << be_global->stub_export_macro () + << " size_t _dcps_find_size (" + << "const "; + this->gen_arg_ref(node); + + // Generate the Serializer << and >> operator declarations. + *os << be_global->stub_export_macro () << " CORBA::Boolean" + << " operator<< (TAO::DCPS::Serializer &, const "; + this->gen_arg_ref(node); + + *os << be_global->stub_export_macro () << " CORBA::Boolean" + << " operator>> (TAO::DCPS::Serializer &, "; + this->gen_arg_ref(node); + + node->cli_hdr_serializer_op_gen (1); + return 0; +} diff --git a/TAO/TAO_IDL/be/be_visitor_array/serializer_op_cs.cpp b/TAO/TAO_IDL/be/be_visitor_array/serializer_op_cs.cpp new file mode 100644 index 00000000000..d484a970a27 --- /dev/null +++ b/TAO/TAO_IDL/be/be_visitor_array/serializer_op_cs.cpp @@ -0,0 +1,1225 @@ +// +// $Id$ +// + +// ============================================================================ +// +// = LIBRARY +// TAO IDL +// +// = FILENAME +// serializer_op_cs.cpp +// +// = DESCRIPTION +// Visitor for code generation of Arrays for the +// TAO::DCPS::Serializer operators in the client stubs. +// +// = AUTHOR +// Scott Harris based on code by +// Jeff Parsons +// +// ============================================================================ + +ACE_RCSID (be_visitor_array, + serializer_op_cs, + "$Id$") + +// *************************************************************************** +// Array visitor for generating Serializer operator declarations in the client +// stubs file +// *************************************************************************** + +be_visitor_array_serializer_op_cs::be_visitor_array_serializer_op_cs ( + be_visitor_context *ctx + ) + : be_visitor_decl (ctx) +{ +} + +be_visitor_array_serializer_op_cs::~be_visitor_array_serializer_op_cs (void) +{ +} + +int +be_visitor_array_serializer_op_cs::visit_array (be_array *node) +{ + if (this->ctx_->alias ()) + { + // We are here because we are visiting base type + // of the array node which is itself an + // array, i.e., this is a case of array of array. + return this->visit_node (node); + } + + if (node->cli_stub_serializer_op_gen () + || node->imported () + || node->is_local ()) + { + return 0; + } + + // Retrieve the base type. + be_type *bt = be_type::narrow_from_decl (node->base_type ()); + AST_Decl::NodeType nt = bt->node_type (); + + if (!bt) + { + ACE_ERROR_RETURN ((LM_ERROR, + "(%N:%l) be_visitor_array_serializer_op_cs::" + "visit_array - " + "Bad base type\n"), + -1); + } + + // If we contain an anonymous sequence, + // generate code for the sequence here. + + if (nt == AST_Decl::NT_sequence) + { + if (this->gen_anonymous_base_type (bt, + TAO_CodeGen::TAO_ROOT_SERIALIZER_OP_CS) + == -1) + { + ACE_ERROR_RETURN ((LM_ERROR, + "(%N:%l) be_visitor_array_serializer_op_cs::" + "visit_array - " + "gen_anonymous_base_type failed\n"), + -1); + } + } + + // If the array is an anonymous member and if its element type + // is a declaration (not a reference), we must generate code for + // the declaration. + if (this->ctx_->alias () == 0 // Not a typedef. + && bt->is_child (this->ctx_->scope ())) + { + int status = 0; + be_visitor_context ctx (*this->ctx_); + + switch (nt) + { + case AST_Decl::NT_enum: + { + be_visitor_enum_serializer_op_cs ec_visitor (&ctx); + status = bt->accept (&ec_visitor); + break; + } + case AST_Decl::NT_struct: + { + be_visitor_structure_serializer_op_cs sc_visitor (&ctx); + status = bt->accept (&sc_visitor); + break; + } + case AST_Decl::NT_union: + { + be_visitor_union_serializer_op_cs uc_visitor (&ctx); + status = bt->accept (&uc_visitor); + break; + } + default: + break; + } + + if (status == -1) + { + ACE_ERROR_RETURN ((LM_ERROR, + "(%N:%l) be_visitor_array_ch::" + "visit_array - " + "array base type codegen failed\n"), + -1); + } + } + + // For anonymous arrays, the type name has a _ prepended. We compute the + // full_name with or without the underscore and use it later on. + char fname [NAMEBUFSIZE]; // to hold the full and + + // Save the node's local name and full name in a buffer for quick use later + // on. + ACE_OS::memset (fname, + '\0', + NAMEBUFSIZE); + + if (this->ctx_->tdef ()) + { + ACE_OS::sprintf (fname, "%s", node->full_name ()); + } + else + { + // For anonymous arrays ... + // We have to generate a name for us that has an underscope prepended + // to our local name. This needs to be inserted after the parents's + // name. + + if (node->is_nested ()) + { + be_decl *parent = + be_scope::narrow_from_scope (node->defined_in ())->decl (); + ACE_OS::sprintf (fname, + "%s::_%s", + parent->full_name (), + node->local_name ()->get_string ()); + } + else + { + ACE_OS::sprintf (fname, + "_%s", + node->full_name ()); + } + } + + // Generate the Serializer << and >> operator defns. + + TAO_OutStream *os = this->ctx_->stream (); + this->ctx_->node (node); + + *os << be_nl << be_nl << "// TAO_IDL - Generated from" << be_nl + << "// " << __FILE__ << ":" << __LINE__ << be_nl << be_nl; + + // Set the sub state as generating code for the size method + this->ctx_->sub_state (TAO_CodeGen::TAO_MAX_MARSHALED_SIZE); + *os << "size_t _dcps_max_marshaled_size (" << be_idt << be_idt_nl + << "const " << fname << "_forany &_tao_array" << be_uidt_nl + <<")" << be_uidt_nl + << "{" << be_idt_nl; + + if (bt->accept (this) == -1) + { + ACE_ERROR_RETURN ((LM_ERROR, + "be_visitor_array_serializer_op_cs::" + "visit_array - " + "Base type codegen failed\n"), + -1); + } + + *os << "}" << be_nl << be_nl; + + // Set the sub state as generating code for the size method + this->ctx_->sub_state (TAO_CodeGen::TAO_IS_BOUNDED_SIZE); + *os << "CORBA::Boolean _tao_is_bounded_size (" << be_idt << be_idt_nl + << "const " << fname << "_forany &_tao_array" << be_uidt_nl + <<")" << be_uidt_nl + << "{" << be_idt_nl; + + if (bt->accept (this) == -1) + { + ACE_ERROR_RETURN ((LM_ERROR, + "be_visitor_array_serializer_op_cs::" + "visit_array - " + "Base type codegen failed\n"), + -1); + } + + *os << "}" << be_nl << be_nl; + + // Set the sub state as generating code for the size method + this->ctx_->sub_state (TAO_CodeGen::TAO_FIND_SIZE); + *os << "size_t _dcps_find_size (" << be_idt << be_idt_nl + << "const " << fname << "_forany &_tao_array" << be_uidt_nl + <<")" << be_uidt_nl + << "{" << be_idt_nl; + + if (bt->accept (this) == -1) + { + ACE_ERROR_RETURN ((LM_ERROR, + "be_visitor_array_serializer_op_cs::" + "visit_array - " + "Base type codegen failed\n"), + -1); + } + + *os << "}" << be_nl << be_nl; + + + // Set the sub state as generating code for the output operator. + this->ctx_->sub_state (TAO_CodeGen::TAO_CDR_OUTPUT); + *os << "CORBA::Boolean operator<< (" << be_idt << be_idt_nl + << "TAO::DCPS::Serializer &strm," << be_nl + << "const " << fname << "_forany &_tao_array" << be_uidt_nl + << ")" << be_uidt_nl + << "{" << be_idt_nl; + + if (bt->accept (this) == -1) + { + ACE_ERROR_RETURN ((LM_ERROR, + "be_visitor_array_serializer_op_cs::" + "visit_array - " + "Base type codegen failed\n"), + -1); + } + + *os << "}" << be_nl << be_nl; + + this->ctx_->sub_state (TAO_CodeGen::TAO_CDR_INPUT); + *os << "CORBA::Boolean operator>> (" << be_idt << be_idt_nl + << "TAO::DCPS::Serializer &strm," << be_nl + << fname << "_forany &_tao_array" << be_uidt_nl + << ")" << be_uidt_nl + << "{" << be_idt_nl; + + if (bt->accept (this) == -1) + { + ACE_ERROR_RETURN ((LM_ERROR, + "be_visitor_array_serializer_op_cs::" + "visit_array - " + "Base type codegen failed\n"), + -1); + } + + *os << "}"; + + node->cli_stub_serializer_op_gen (1); + return 0; +} + +// Handle all the base types. + +int +be_visitor_array_serializer_op_cs::visit_enum (be_enum *node) +{ + TAO_OutStream *os = this->ctx_->stream (); + + unsigned long i; + + // Grab the array node. + be_array *array = this->ctx_->be_node_as_array (); + + if (!node) + { + ACE_ERROR_RETURN ((LM_ERROR, + "(%N:%l) be_visitor_array_serializer_op_cs::" + "visit_predefined_type - " + "bad array node\n"), + -1); + } + + // Check what is the code generation substate. Are we generating + // code for the in/out operators for our parent or for us? + switch (this->ctx_->sub_state ()) + { + case TAO_CodeGen::TAO_IS_BOUNDED_SIZE: + *os << "ACE_UNUSED_ARG(_tao_array);" << be_nl + << "return true; // array of enum" << be_uidt_nl; + break; + case TAO_CodeGen::TAO_FIND_SIZE: + case TAO_CodeGen::TAO_MAX_MARSHALED_SIZE: + { + *os << "ACE_UNUSED_ARG(_tao_array);" << be_nl; + *os << "// array of enum = sizeof(CORBA::ULong) * array size" << be_nl + << "return _dcps_max_marshaled_size_ulong () * "; + + unsigned long ndims = array->n_dims (); + + // Generate a product of all the dimensions. This will be the total length + // of the "unfolded" single dimensional array. + for (i = 0; i < ndims; ++i) + { + // Retrieve the ith dimension value. + AST_Expression *expr = array->dims ()[i]; + + if ((expr == 0) || ((expr != 0) && (expr->ev () == 0))) + { + ACE_ERROR_RETURN ((LM_ERROR, + "(%N:%l) be_visitor_array_serializer_op_cs::" + "visit_predefined_type - " + "bad array dimension\n"), + -1); + } + + if (i != 0) + { + // Do not generate the multiplication operator the first time in. + *os << "*"; + } + + if (expr->ev ()->et == AST_Expression::EV_ulong) + { + // Generate a loop for each dimension. + *os << expr->ev ()->u.ulval; + } + else + { + ACE_ERROR_RETURN ((LM_ERROR, + "(%N:%l) be_visitor_array_serializer_op_cs::" + "visit_predefined_type - " + "bad array dimension value\n"), + -1); + } + } + + *os << ";" << be_uidt_nl; + } + break; + + default: + return this->visit_node (node); + } + return 0; +} + +int +be_visitor_array_serializer_op_cs::visit_interface (be_interface *node) +{ + return this->visit_node (node); +} + +int +be_visitor_array_serializer_op_cs::visit_interface_fwd (be_interface_fwd *node) +{ + return this->visit_node (node); +} + +int +be_visitor_array_serializer_op_cs::visit_valuetype (be_valuetype *node) +{ + return this->visit_node (node); +} + +int +be_visitor_array_serializer_op_cs::visit_valuetype_fwd (be_valuetype_fwd *node) +{ + return this->visit_node (node); +} + +int +be_visitor_array_serializer_op_cs::visit_predefined_type (be_predefined_type *node) +{ + TAO_OutStream *os = this->ctx_->stream (); + + switch (node->pt ()) + { + case AST_PredefinedType::PT_pseudo: + case AST_PredefinedType::PT_object: + case AST_PredefinedType::PT_value: + case AST_PredefinedType::PT_any: + // Let the helper handle this. + return this->visit_node (node); + case AST_PredefinedType::PT_void: + // error + ACE_ERROR_RETURN ((LM_ERROR, + "(%N:%l) be_visitor_array_serializer_op_cs::" + "visit_predefined_type - " + "Bad primitive type\n"), + -1); + default: + // All other primitive types. Handle them as shown below. + break; + }; + + // We get here if the "type" of individual elements of the array is a + // primitive type. In this case, we treat the array as a single dimensional + // array (even though it was multi-dimensional), and pass the total length + // of the array as a cross product of the dimensions. + + unsigned long i; + + // Grab the array node. + be_array *array = this->ctx_->be_node_as_array (); + + if (!node) + { + ACE_ERROR_RETURN ((LM_ERROR, + "(%N:%l) be_visitor_array_serializer_op_cs::" + "visit_predefined_type - " + "bad array node\n"), + -1); + } + + // Check what is the code generation substate. Are we generating + // code for the in/out operators for our parent or for us? + switch (this->ctx_->sub_state ()) + { + case TAO_CodeGen::TAO_IS_BOUNDED_SIZE: + // all predefined types are fixed size hence they are bounded. + *os << "ACE_UNUSED_ARG(_tao_array);" << be_nl; + *os << "return true;" << be_uidt_nl; + return 0; // all done - no need to get the array size + break; + + // all predefined types are fixed size so + // _dcps_find_size() = _dcps_max_marshaled_size + case TAO_CodeGen::TAO_FIND_SIZE: + case TAO_CodeGen::TAO_MAX_MARSHALED_SIZE: + switch (node->pt ()) + { + case AST_PredefinedType::PT_octet: + *os << "ACE_UNUSED_ARG(_tao_array);" << be_nl; + *os << "return (_dcps_max_marshaled_size_octet () *"; + break; + case AST_PredefinedType::PT_char: + *os << "ACE_UNUSED_ARG(_tao_array);" << be_nl; + *os << "return (_dcps_max_marshaled_size_char () *"; + break; + case AST_PredefinedType::PT_wchar: + *os << "ACE_UNUSED_ARG(_tao_array);" << be_nl; + *os << "return (_dcps_max_marshaled_size_wchar () *"; + break; + case AST_PredefinedType::PT_long: + case AST_PredefinedType::PT_ulong: + case AST_PredefinedType::PT_short: + case AST_PredefinedType::PT_ushort: + case AST_PredefinedType::PT_float: + case AST_PredefinedType::PT_double: + case AST_PredefinedType::PT_longlong: + case AST_PredefinedType::PT_ulonglong: + case AST_PredefinedType::PT_longdouble: + // array size = slice type size * length + // note: *(_tao_array.in ()) is the array's slice; hence base type + *os << "return (_dcps_max_marshaled_size (*(_tao_array.in ())) * "; + break; + break; + case AST_PredefinedType::PT_boolean: + *os << "ACE_UNUSED_ARG(_tao_array);" << be_nl; + *os << "return (_dcps_max_marshaled_size_boolean () *"; + break; + default: + ACE_ERROR_RETURN ((LM_ERROR, + "(%N:%l) be_visitor_array_serializer_op_cs::" + "visit_predefined_type - " + "bad primitive type for _dcps_max_marshaled_size code gen\n"), + -1); + } + break; + + case TAO_CodeGen::TAO_CDR_INPUT: + case TAO_CodeGen::TAO_CDR_OUTPUT: + { + // We generate optimized code based on an optimized interface available from + // the Serializer class. These optimizations are applicable only to primitive + // types. + *os << " return strm."; + + // Based on our substate, we may be reading from a stream or writing into a + // stream. + switch (this->ctx_->sub_state ()) + { + case TAO_CodeGen::TAO_CDR_INPUT: + *os << "read_"; + break; + case TAO_CodeGen::TAO_CDR_OUTPUT: + *os << "write_"; + break; + default: + ACE_ERROR_RETURN ((LM_ERROR, + "(%N:%l) be_visitor_array_serializer_op_cs::" + "visit_predefined_type - " + "bad sub state\n"), + -1); + } + + // Determine what kind of array are we reading/writing. + switch (node->pt ()) + { + case AST_PredefinedType::PT_long: + *os << "long_array"; + break; + case AST_PredefinedType::PT_ulong: + *os << "ulong_array"; + break; + case AST_PredefinedType::PT_short: + *os << "short_array"; + break; + case AST_PredefinedType::PT_ushort: + *os << "ushort_array"; + break; + case AST_PredefinedType::PT_octet: + *os << "octet_array"; + break; + case AST_PredefinedType::PT_char: + *os << "char_array"; + break; + case AST_PredefinedType::PT_wchar: + *os << "wchar_array"; + break; + case AST_PredefinedType::PT_float: + *os << "float_array"; + break; + case AST_PredefinedType::PT_double: + *os << "double_array"; + break; + case AST_PredefinedType::PT_longlong: + *os << "longlong_array"; + break; + case AST_PredefinedType::PT_ulonglong: + *os << "ulonglong_array"; + break; + case AST_PredefinedType::PT_longdouble: + *os << "longdouble_array"; + break; + case AST_PredefinedType::PT_boolean: + *os << "boolean_array"; + break; + default: + ACE_ERROR_RETURN ((LM_ERROR, + "(%N:%l) be_visitor_array_serializer_op_cs::" + "visit_predefined_type - " + "bad primitive type for optimized code gen\n"), + -1); + } + + // Handle special case to avoid compiler errors. + switch (this->ctx_->sub_state ()) + { + case TAO_CodeGen::TAO_CDR_INPUT: + *os << " (("; + break; + case TAO_CodeGen::TAO_CDR_OUTPUT: + *os << " ((const "; + break; + default: + ACE_ERROR_RETURN ((LM_ERROR, + "(%N:%l) be_visitor_array_serializer_op_cs::" + "visit_predefined_type - " + "bad substate in context\n"), + -1); + } + + switch (node->pt ()) + { + case AST_PredefinedType::PT_long: + *os << "ACE_CDR::Long *)"; + break; + case AST_PredefinedType::PT_ulong: + *os << "ACE_CDR::ULong *)"; + break; + case AST_PredefinedType::PT_short: + *os << "ACE_CDR::Short *)"; + break; + case AST_PredefinedType::PT_ushort: + *os << "ACE_CDR::UShort *)"; + break; + case AST_PredefinedType::PT_octet: + *os << "ACE_CDR::Octet *)"; + break; + case AST_PredefinedType::PT_char: + *os << "ACE_CDR::Char *)"; + break; + case AST_PredefinedType::PT_wchar: + *os << "ACE_CDR::WChar *)"; + break; + case AST_PredefinedType::PT_float: + *os << "ACE_CDR::Float *)"; + break; + case AST_PredefinedType::PT_double: + *os << "ACE_CDR::Double *)"; + break; + case AST_PredefinedType::PT_longlong: + *os << "ACE_CDR::LongLong *)"; + break; + case AST_PredefinedType::PT_ulonglong: + *os << "ACE_CDR::ULongLong *)"; + break; + case AST_PredefinedType::PT_longdouble: + *os << "ACE_CDR::LongDouble *)"; + break; + case AST_PredefinedType::PT_boolean: + *os << "ACE_CDR::Boolean *)"; + break; + default: + ACE_ERROR_RETURN ((LM_ERROR, + "(%N:%l) be_visitor_array_serializer_op_cs::" + "visit_predefined_type - " + "bad primitive type for optimized code gen\n"), + -1); + } + + // Handle special case to avoid compiler errors. + switch (this->ctx_->sub_state ()) + { + case TAO_CodeGen::TAO_CDR_INPUT: + *os << " _tao_array.out (), "; + break; + case TAO_CodeGen::TAO_CDR_OUTPUT: + *os << "_tao_array.in (), "; + break; + default: + ACE_ERROR_RETURN ((LM_ERROR, + "(%N:%l) be_visitor_array_serializer_op_cs::" + "visit_predefined_type - " + "bad substate in context\n"), + -1); + } + } // end TAO_CDR_INPUT/OUTPUT specific code. + break; + case TAO_CodeGen::TAO_CDR_SCOPE: + // This is done in serializer_op_cs and hacked into *.i. + break; + default: + // Error. + ACE_ERROR_RETURN ((LM_ERROR, + "(%N:%l) be_visitor_array_serializer_op_cs::" + "visit_predefined_type - " + "bad sub state\n"), + -1); + } + + unsigned long ndims = array->n_dims (); + + // Generate a product of all the dimensions. This will be the total length + // of the "unfolded" single dimensional array. + for (i = 0; i < ndims; ++i) + { + // Retrieve the ith dimension value. + AST_Expression *expr = array->dims ()[i]; + + if ((expr == 0) || ((expr != 0) && (expr->ev () == 0))) + { + ACE_ERROR_RETURN ((LM_ERROR, + "(%N:%l) be_visitor_array_serializer_op_cs::" + "visit_predefined_type - " + "bad array dimension\n"), + -1); + } + + if (i != 0) + { + // Do not generate the multiplication operator the first time in. + *os << "*"; + } + + if (expr->ev ()->et == AST_Expression::EV_ulong) + { + // Generate a loop for each dimension. + *os << expr->ev ()->u.ulval; + } + else + { + ACE_ERROR_RETURN ((LM_ERROR, + "(%N:%l) be_visitor_array_serializer_op_cs::" + "visit_predefined_type - " + "bad array dimension value\n"), + -1); + } + } + + *os << ");" << be_uidt_nl; + + return 0; +} + +int +be_visitor_array_serializer_op_cs::visit_sequence (be_sequence *node) +{ + return this->visit_node (node); +} + +int +be_visitor_array_serializer_op_cs::visit_string (be_string *node) +{ + return this->visit_node (node); +} + +int +be_visitor_array_serializer_op_cs::visit_structure (be_structure *node) +{ + return this->visit_node (node); +} + +int +be_visitor_array_serializer_op_cs::visit_union (be_union *node) +{ + return this->visit_node (node); +} + +int +be_visitor_array_serializer_op_cs::visit_typedef (be_typedef *node) +{ + this->ctx_->alias (node); + + // The node to be visited in the base primitve type that gets typedefed. + be_type *bt = node->primitive_base_type (); + + if (!bt || (bt->accept (this) == -1)) + { + ACE_ERROR_RETURN ((LM_ERROR, + "(%N:%l) be_visitor_array_serializer_op_cs::" + "visit_typedef - " + "Bad primitive type\n"), + -1); + } + + this->ctx_->alias (0); + return 0; +} + +// Helper. +int +be_visitor_array_serializer_op_cs::visit_node (be_type *bt) +{ + TAO_OutStream *os = this->ctx_->stream (); + unsigned long i; + be_array *node = this->ctx_->be_node_as_array (); + AST_Decl::NodeType nt = bt->node_type (); + + if (!node) + { + ACE_ERROR_RETURN ((LM_ERROR, + "(%N:%l) be_visitor_array_serializer_op_cs::" + "visit_node - " + "bad array node\n"), + -1); + } + + unsigned long ndims = node->n_dims (); + + AST_Decl::NodeType bnt = bt->node_type (); + + switch (this->ctx_->sub_state ()) + { + case TAO_CodeGen::TAO_IS_BOUNDED_SIZE: + switch (bnt) + { + case AST_Decl::NT_string: + case AST_Decl::NT_wstring: + { + be_string *str = + be_string::narrow_from_decl (bt); + + if (!str) + { + ACE_ERROR_RETURN ((LM_ERROR, + "(%N:%l) be_visitor_array_serializer_op_cs::" + "visit_node - " + "bad string node\n"), + -1); + } + + *os << "ACE_UNUSED_ARG(_tao_array);" << be_nl; + if (0 == str->max_size ()->ev ()->u.ulval) + *os << "return false; // array of unbounded string"; + else + *os << "return true; // array of bounded string "; + } + break; + case AST_Decl::NT_array: + *os << "// use ULong instead of literal to avoid overload ambiguity" + << be_nl << "CORBA::ULong first = 0;" << be_nl + << "// must use forany instead of a slice to avoid overload ambiguity" + << be_nl + << bt->name () << "_var tmp_var (" + << bt->name () << "_dup (_tao_array"; + + for (i = 0; i < ndims; ++i) + { + *os << "[first]"; + } + + *os << "));" << be_nl; + *os << bt->name () << "_forany tmp (tmp_var.inout ());" << be_nl; + *os << "return _tao_is_bounded_size (tmp);"; + break; + default: + *os << "return _tao_is_bounded_size (*(_tao_array.in ()));"; + break; + } + *os << be_uidt_nl; + break; + case TAO_CodeGen::TAO_MAX_MARSHALED_SIZE: + { + switch (bnt) + { + case AST_Decl::NT_string: + case AST_Decl::NT_wstring: + { + be_string *str = + be_string::narrow_from_decl (bt); + + if (!str) + { + ACE_ERROR_RETURN ((LM_ERROR, + "(%N:%l) be_visitor_array_serializer_op_cs::" + "visit_node - " + "bad string node\n"), + -1); + } + *os << "ACE_UNUSED_ARG(_tao_array);" << be_nl; + char buff[15]; + ACE_OS::sprintf(buff, "%d", str->max_size ()->ev ()->u.ulval); + *os << "return _dcps_max_marshaled_size_ulong () + (" << buff; + } + break; + case AST_Decl::NT_array: + *os << "// use ULong instead of literal to avoid overload ambiguity" + << be_nl << "CORBA::ULong first = 0;" << be_nl + << "// must use forany instead of a slice to avoid overload ambiguity" + << be_nl + << bt->name () << "_var tmp_var (" + << bt->name () << "_dup (_tao_array"; + + for (i = 0; i < ndims; ++i) + { + *os << "[first]"; + } + + *os << "));" << be_nl; + *os << bt->name () << "_forany tmp (tmp_var.inout ());" << be_nl; + *os << "return (_dcps_max_marshaled_size (tmp)"; + break; + default: + // array size = slice type size * length + // note: *(_tao_array.in ()) is the array's slice; hence base type + *os << "return (_dcps_max_marshaled_size (*(_tao_array.in ()))"; + break; + } + *os << " * "; + + //SHH - TBD - this array dim size code could be common + // Generate a product of all the dimensions. This will be the total length + // of the "unfolded" single dimensional array. + for (i = 0; i < ndims; ++i) + { + // Retrieve the ith dimension value. + AST_Expression *expr = node->dims ()[i]; + + if ((expr == 0) || ((expr != 0) && (expr->ev () == 0))) + { + ACE_ERROR_RETURN ((LM_ERROR, + "(%N:%l) be_visitor_array_serializer_op_cs::" + "visit_node - " + "bad array dimension\n"), + -1); + } + + if (i != 0) + { + // Do not generate the multiplication operator the first time in. + *os << "*"; + } + + if (expr->ev ()->et == AST_Expression::EV_ulong) + { + // Generate a loop for each dimension. + *os << expr->ev ()->u.ulval; + } + else + { + ACE_ERROR_RETURN ((LM_ERROR, + "(%N:%l) be_visitor_array_serializer_op_cs::" + "visit_node - " + "bad array dimension value\n"), + -1); + } + } + + *os << ");" << be_uidt_nl; + + } + break; + case TAO_CodeGen::TAO_FIND_SIZE: + case TAO_CodeGen::TAO_CDR_INPUT: + case TAO_CodeGen::TAO_CDR_OUTPUT: + { + if (TAO_CodeGen::TAO_FIND_SIZE == this->ctx_->sub_state ()) + { + *os << "//iterate over the array to find the current size" << be_nl + << "size_t the_length = 0;" << be_nl; + } + else + { + // Initialize a boolean variable. + *os << "CORBA::Boolean _tao_marshal_flag = 1;" << be_nl; + } + + unsigned long ndims = node->n_dims (); + + // We get here if the "type" of individual elements of the array is not a + // primitive type. In this case, we are left with no other alternative but to + // encode/decode element by element. + + // generate nested loops for as many dimensions as there are + for (i = 0; i < ndims; ++i) + { + // Retrieve the ith dimension value. + AST_Expression *expr = node->dims ()[i]; + + if ((expr == 0) || ((expr != 0) && (expr->ev () == 0))) + { + ACE_ERROR_RETURN ((LM_ERROR, + "(%N:%l) be_visitor_array_serializer_op_cs::" + "visit_node - " + "bad array dimension\n"), + -1); + } + + if (expr->ev ()->et == AST_Expression::EV_ulong) + { + // Generate a loop for each dimension. + *os << be_nl << "for (CORBA::ULong i" << i + << " = 0; i" << i << " < " + << expr->ev ()->u.ulval; + + if (TAO_CodeGen::TAO_FIND_SIZE != this->ctx_->sub_state ()) + *os << " && _tao_marshal_flag"; + + *os << "; i" << i + << "++)" << be_idt_nl + << "{" << be_idt; + } + else + { + ACE_ERROR_RETURN ((LM_ERROR, + "(%N:%l) be_visitor_array_serializer_op_cs::" + "visit_node - " + "bad array dimension value\n"), + -1); + } + } + + // @@ (JP) Need to factor out some of this into method call(s). + switch (this->ctx_->sub_state ()) + { + case TAO_CodeGen::TAO_FIND_SIZE: + { + *os << be_nl; + if (AST_Decl::NT_array == bnt) + { + *os << bt->name () << "_var tmp_var (" + << bt->name () << "_dup (_tao_array"; + + for (i = 0; i < ndims; ++i) + { + *os << "[i" << i << "]"; + } + + *os << "));" << be_nl; + *os << bt->name () << "_forany tmp (tmp_var.inout ());" << be_nl; + *os << "the_length += _dcps_find_size (tmp);"; + } + else + { + if (AST_Decl::NT_string == bnt || + AST_Decl::NT_wstring == bnt ) + *os << "the_length += _dcps_max_marshaled_size_ulong() + " + << "ACE_OS::strlen(_tao_array"; + else + *os << "the_length += _dcps_find_size (_tao_array"; + + for (i = 0; i < ndims; ++i) + { + *os << "[i" << i << "]"; + } + if (AST_Decl::NT_string == bnt || + AST_Decl::NT_wstring == bnt ) + *os << ".in()"; + + *os << ");"; + } + } + break; + case TAO_CodeGen::TAO_CDR_INPUT: + *os << be_nl; + + // Handle the array of array case, where we need to pass the + // forany type. + if (nt == AST_Decl::NT_array) + { + *os << bt->name () << "_forany tmp (" + << bt->name () << "_alloc ());" << be_nl; + *os << "_tao_marshal_flag = (strm >> tmp);" << be_nl; + *os << bt->name () << "_copy (_tao_array"; + + for (i = 0; i < ndims; ++i) + { + *os << "[i" << i << "]"; + } + + *os << ", tmp.in ());" << be_nl; + *os << bt->name () << "_free (tmp.inout ());"; + } + else + { + *os << "_tao_marshal_flag = (strm >> "; + *os << "_tao_array "; + + for (i = 0; i < ndims; ++i) + { + *os << "[i" << i << "]"; + } + + switch (bt->node_type ()) + { + // The following have a _var type and must be + // handled in a special way. + case AST_Decl::NT_string: + case AST_Decl::NT_wstring: + case AST_Decl::NT_valuetype: + case AST_Decl::NT_valuetype_fwd: + *os << ".out ()"; + break; + case AST_Decl::NT_pre_defined: + { + // We need to separately handle this case of pseudo + // objects because they have a _var type. + be_predefined_type *pt = + be_predefined_type::narrow_from_decl (bt); + + if (!pt) + { + ACE_ERROR_RETURN ((LM_ERROR, + "(%N:%l) be_visitor_array_serializer_op_cs::" + "visit_node - " + "bad predefined type node\n"), + -1); + } + + AST_PredefinedType::PredefinedType pdt = pt->pt (); + + if (pdt == AST_PredefinedType::PT_pseudo + || pdt == AST_PredefinedType::PT_object) + { + *os << ".out ()"; + } + } + default: + break; + } + + *os << ");"; + } + + break; + case TAO_CodeGen::TAO_CDR_OUTPUT: + *os << be_nl; + + // Handle the array of array case, where we need to pass the + // forany type. + if (nt == AST_Decl::NT_array) + { + *os << bt->name () << "_var tmp_var (" + << bt->name () << "_dup (_tao_array"; + + for (i = 0; i < ndims; ++i) + { + *os << "[i" << i << "]"; + } + + *os << "));" << be_nl; + *os << bt->name () << "_forany tmp (tmp_var.inout ());" << be_nl; + *os << "_tao_marshal_flag = (strm << tmp);"; + } + else if (nt == AST_Decl::NT_interface + || nt == AST_Decl::NT_interface_fwd) + { + *os << "_tao_marshal_flag = " << be_idt_nl; + + if (bt->is_defined ()) + { + *os << "_tao_array"; + + for (i = 0; i < ndims; ++i) + { + *os << "[i" << i << "]"; + } + + *os << ".in ()->marshal (strm);" << be_uidt; + } + else + { + + AST_Decl *parent = + ScopeAsDecl (bt->defined_in ()); + + if (parent != 0 && parent->node_type () != AST_Decl::NT_root) + { + *os << parent->name () << "::"; + } + + *os << "TAO::Objref_Traits<" << bt->name () << ">::" + << "tao_marshal (_tao_array"; + + for (i = 0; i < ndims; ++i) + { + *os << "[i" << i << "]"; + } + + *os << ".in (), strm);" << be_uidt; + } + } + else + { + *os << "_tao_marshal_flag = (strm << "; + *os << "_tao_array "; + + for (i = 0; i < ndims; ++i) + { + *os << "[i" << i << "]"; + } + + switch (bt->node_type ()) + { + // The following have a _var type and must be + // handled in a special way. + case AST_Decl::NT_string: + case AST_Decl::NT_wstring: + case AST_Decl::NT_valuetype: + case AST_Decl::NT_valuetype_fwd: + *os << ".in ()"; + break; + case AST_Decl::NT_pre_defined: + { + // We need to separately handle this case of pseudo + // objects because they have a _var type. + be_predefined_type *pt = + be_predefined_type::narrow_from_decl (bt); + + if (!pt) + { + ACE_ERROR_RETURN ((LM_ERROR, + "(%N:%l) be_visitor_array_serializer_op_cs::" + "visit_node - " + "bad predefined type node\n"), + -1); + } + + AST_PredefinedType::PredefinedType pdt = pt->pt (); + + if (pdt == AST_PredefinedType::PT_pseudo + || pdt == AST_PredefinedType::PT_object) + { + *os << ".in ()"; + } + } + default: + break; + } + + *os << ");"; + } + + break; + default: + ACE_ERROR_RETURN ((LM_ERROR, + "(%N:%l) be_visitor_array_serializer_op_cs::" + "visit_node - " + "bad sub state\n"), + -1); + } + + for (i = 0; i < ndims; ++i) + { + // Decrement indentation as many times as the number of dimensions. + *os << be_uidt_nl << "}" << be_uidt; + } + + if (TAO_CodeGen::TAO_FIND_SIZE == this->ctx_->sub_state ()) + { + *os << be_nl << be_nl << "return the_length;" << be_uidt_nl; + } + else + { + *os << be_nl << be_nl << "return _tao_marshal_flag;" << be_uidt_nl; + } + + } // end INPUT/OUTPUT_CDR case + break; + default: + ACE_ERROR_RETURN ((LM_ERROR, + "(%N:%l) be_visitor_array_serializer_op_cs::" + "visit_node outter- " + "bad sub state\n"), + -1); + } // end outer switch + + return 0; +} diff --git a/TAO/TAO_IDL/be/be_visitor_enum/serializer_op_ch.cpp b/TAO/TAO_IDL/be/be_visitor_enum/serializer_op_ch.cpp new file mode 100644 index 00000000000..5211493ca9a --- /dev/null +++ b/TAO/TAO_IDL/be/be_visitor_enum/serializer_op_ch.cpp @@ -0,0 +1,62 @@ +// +// $Id$ +// + +// ============================================================================ +// +// = LIBRARY +// TAO IDL +// +// = FILENAME +// serializer_op_ch.cpp +// +// = DESCRIPTION +// Visitor generating code for Enums for the TAO::DCPS::Serializer operators +// +// = AUTHOR +// Scott Harris based on code by Aniruddha Gokhale +// +// ============================================================================ + +ACE_RCSID (be_visitor_enum, + serializer_op_ch, + "$Id$") + + +// *************************************************************************** +// Enum visitor for generating Serializer operator declarations in the client header +// *************************************************************************** + +be_visitor_enum_serializer_op_ch::be_visitor_enum_serializer_op_ch (be_visitor_context *ctx) + : be_visitor_decl (ctx) +{ +} + +be_visitor_enum_serializer_op_ch::~be_visitor_enum_serializer_op_ch (void) +{ +} + +int +be_visitor_enum_serializer_op_ch::visit_enum (be_enum *node) +{ + if (node->cli_hdr_serializer_op_gen () || node->imported ()) + { + 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 Serializer << and >> operators + *os << be_global->stub_export_macro () << " CORBA::Boolean" + << " operator<< (TAO::DCPS::Serializer &, const " << node->name () + << " &);" << be_nl; + *os << be_global->stub_export_macro () << " CORBA::Boolean" + << " operator>> (TAO::DCPS::Serializer &, " + << node->name () << " &);"; + + node->cli_hdr_serializer_op_gen (1); + return 0; +} diff --git a/TAO/TAO_IDL/be/be_visitor_enum/serializer_op_cs.cpp b/TAO/TAO_IDL/be/be_visitor_enum/serializer_op_cs.cpp new file mode 100644 index 00000000000..f4adf2f1777 --- /dev/null +++ b/TAO/TAO_IDL/be/be_visitor_enum/serializer_op_cs.cpp @@ -0,0 +1,76 @@ +// +// $Id$ +// + +// ============================================================================ +// +// = LIBRARY +// TAO IDL +// +// = FILENAME +// serializer_op_cs.cpp +// +// = DESCRIPTION +// Visitors for generation of code for Enum for the +// TAO::DCPS::Serializer operators +// +// = AUTHOR +// Scott Harris based on code by Aniruddha Gokhale +// +// ============================================================================ + +ACE_RCSID (be_visitor_enum, + serializer_op_cs, + "$Id$") + + +// *************************************************************************** +// Enum visitor for generating Serializer operator declarations in the client +// stubs file. +// *************************************************************************** + +be_visitor_enum_serializer_op_cs::be_visitor_enum_serializer_op_cs (be_visitor_context *ctx) + : be_visitor_decl (ctx) +{ +} + +be_visitor_enum_serializer_op_cs::~be_visitor_enum_serializer_op_cs (void) +{ +} + +int +be_visitor_enum_serializer_op_cs::visit_enum (be_enum *node) +{ + if (node->cli_stub_serializer_op_gen () || node->imported ()) + { + 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; + + *os << "CORBA::Boolean operator<< (TAO::DCPS::Serializer &strm, " + << "const " << node->name () << " &_tao_enumval)" << be_nl + << "{" << be_idt_nl + << "CORBA::ULong _tao_temp = _tao_enumval;" << be_nl + << "return strm << _tao_temp;" << be_uidt_nl + << "}" << be_nl << be_nl; + + *os << "CORBA::Boolean operator>> (TAO::DCPS::Serializer &strm, " + << node->name () << " &_tao_enumval)" << 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 + << "{" << be_idt_nl + << "_tao_enumval = static_cast<" << node->name () + << "> (_tao_temp);" << be_uidt_nl + << "}" << be_uidt_nl << be_nl + << "return _tao_result;" << be_uidt_nl + << "}"; + + node->cli_stub_serializer_op_gen (I_TRUE); + return 0; +} diff --git a/TAO/TAO_IDL/be/be_visitor_field/serializer_op_ch.cpp b/TAO/TAO_IDL/be/be_visitor_field/serializer_op_ch.cpp new file mode 100644 index 00000000000..098301bb4c0 --- /dev/null +++ b/TAO/TAO_IDL/be/be_visitor_field/serializer_op_ch.cpp @@ -0,0 +1,249 @@ +// +// $Id$ +// + +// ============================================================================ +// +// = LIBRARY +// TAO IDL +// +// = FILENAME +// serializer_op_ch.cpp +// +// = DESCRIPTION +// Visitor generating TAO::DCPS::Serializer operator declarator for field +// in the client header +// +// = AUTHOR +// Scott Harris based on code by Aniruddha Gokhale +// +// ============================================================================ + +#include "be_visitor_array/serializer_op_ch.h" +#include "be_visitor_enum/serializer_op_ch.h" +#include "be_visitor_sequence/serializer_op_ch.h" +#include "be_visitor_structure/structure.h" +#include "be_visitor_structure/serializer_op_ch.h" +#include "be_visitor_union/union.h" +#include "be_visitor_union/serializer_op_ch.h" + +ACE_RCSID (be_visitor_field, + serializer_op_ch, + "$Id$") + + +// ********************************************** +// Visitor for field in the client header file. +// ********************************************** + +// Constructor. +be_visitor_field_serializer_op_ch::be_visitor_field_serializer_op_ch (be_visitor_context *ctx) + : be_visitor_decl (ctx) +{ +} + +// Destructor. +be_visitor_field_serializer_op_ch::~be_visitor_field_serializer_op_ch (void) +{ +} + +// Visit the field node. +int +be_visitor_field_serializer_op_ch::visit_field (be_field *node) +{ + be_type *bt = be_type::narrow_from_decl (node->field_type ()); + + if (!bt) + { + ACE_ERROR_RETURN ((LM_ERROR, + "(%N:%l) be_visitor_field_serializer_op_ch::" + "visit_field - " + "Bad field type\n"), + -1); + } + + this->ctx_->node (node); + + if (bt->accept (this) == -1) + { + ACE_ERROR_RETURN ((LM_ERROR, + "(%N:%l) be_visitor_field_serializer_op_ch::" + "visit_field - " + "codegen for field type failed\n"), + -1); + } + + return 0; +} + +// Visit operations on all possible data types that a field can be. + +int +be_visitor_field_serializer_op_ch::visit_array (be_array *node) +{ + // If not a typedef and we are defined in the use scope, we must be defined. + + if (!this->ctx_->alias () + && node->is_child (this->ctx_->scope ())) + { + // This is the case for anonymous arrays. + + // Instantiate a visitor context with a copy of our context. This info + // will be modified based on what type of node we are visiting. + be_visitor_context ctx (*this->ctx_); + ctx.node (node); + + // First generate the array declaration. + be_visitor_array_serializer_op_ch visitor (&ctx); + + if (node->accept (&visitor) == -1) + { + ACE_ERROR_RETURN ((LM_ERROR, + "(%N:%l) be_visitor_field_serializer_op_ch::" + "visit_array - " + "codegen failed\n"), + -1); + } + } + + return 0; +} + +int +be_visitor_field_serializer_op_ch::visit_enum (be_enum *node) +{ + // If not a typedef and we are defined in the use scope, we must be defined + if (!this->ctx_->alias () // not a typedef. + && node->is_child (this->ctx_->scope ())) + { + // Instantiate a visitor context with a copy of our context. This info + // will be modified based on what type of node we are visiting. + be_visitor_context ctx (*this->ctx_); + ctx.node (node); + + // First generate the enum declaration. + be_visitor_enum_serializer_op_ch visitor (&ctx); + + if (node->accept (&visitor) == -1) + { + ACE_ERROR_RETURN ((LM_ERROR, + "(%N:%l) be_visitor_field_serializer_op_ch::" + "visit_enum - " + "codegen failed\n" + ), -1); + } + } + + return 0; +} + +int +be_visitor_field_serializer_op_ch::visit_sequence (be_sequence *node) +{ + // If not a typedef and we are defined in the use scope, we must be defined. + if (!this->ctx_->alias () // not a typedef + && node->is_child (this->ctx_->scope ())) + { + // Instantiate a visitor context with a copy of our context. This info + // will be modified based on what type of node we are visiting. + be_visitor_context ctx (*this->ctx_); + ctx.node (node); + + // First generate the sequence declaration. + be_visitor_sequence_serializer_op_ch visitor (&ctx); + + if (node->accept (&visitor) == -1) + { + ACE_ERROR_RETURN ((LM_ERROR, + "(%N:%l) be_visitor_field_serializer_op_ch::" + "visit_sequence - " + "codegen failed\n" + ), -1); + } + } + + return 0; +} + +int +be_visitor_field_serializer_op_ch::visit_structure (be_structure *node) +{ + // if not a typedef and we are defined in the use scope, we must be defined + + if (!this->ctx_->alias () // not a typedef + && node->is_child (this->ctx_->scope ())) + { + // instantiate a visitor context with a copy of our context. This info + // will be modified based on what type of node we are visiting + be_visitor_context ctx (*this->ctx_); + ctx.node (node); // set the node to be the node being visited. The scope + // is still the same + + // first generate the struct declaration + be_visitor_structure_serializer_op_ch visitor (&ctx); + + if (node->accept (&visitor) == -1) + { + ACE_ERROR_RETURN ((LM_ERROR, + "(%N:%l) be_visitor_field_serializer_op_ch::" + "visit_struct - " + "codegen failed\n" + ), -1); + } + } + + return 0; +} + +int +be_visitor_field_serializer_op_ch::visit_typedef (be_typedef *node) +{ + // Save the node for use in code generation and + // indicate that the field of the field node + // is a typedefed quantity. + this->ctx_->alias (node); + + // Make a decision based on the primitive base type. + be_type *bt = node->primitive_base_type (); + + if (!bt || (bt->accept (this) == -1)) + { + ACE_ERROR_RETURN ((LM_ERROR, + "(%N:%l) be_visitor_field_serializer_op_ch::" + "visit_typedef - " + "Bad primitive type\n" + ), -1); + } + + this->ctx_->alias (0); + return 0; +} + +// visit union type +int +be_visitor_field_serializer_op_ch::visit_union (be_union *node) +{ + // If not a typedef and we are defined in the use scope, we must be defined. + if (!this->ctx_->alias () // not a typedef + && node->is_child (this->ctx_->scope ())) + { + // Instantiate a visitor context with a copy of our context. This info + // will be modified based on what type of node we are visiting. + be_visitor_context ctx (*this->ctx_); + ctx.node (node); + + // First generate the enum declaration. + be_visitor_union_serializer_op_ch visitor (&ctx); + + if (node->accept (&visitor) == -1) + { + ACE_ERROR_RETURN ((LM_ERROR, + "(%N:%l) be_visitor_field_serializer_op_ch::" + "visit_enum - " + "codegen failed\n" + ), -1); + } + } + + return 0; +} diff --git a/TAO/TAO_IDL/be/be_visitor_field/serializer_op_cs.cpp b/TAO/TAO_IDL/be/be_visitor_field/serializer_op_cs.cpp new file mode 100644 index 00000000000..361ce174aa5 --- /dev/null +++ b/TAO/TAO_IDL/be/be_visitor_field/serializer_op_cs.cpp @@ -0,0 +1,1137 @@ +// +// $Id$ +// + +// ============================================================================ +// +// = LIBRARY +// TAO IDL +// +// = FILENAME +// field_serializer_op_cs.cpp +// +// = DESCRIPTION +// Visitor generating TAO::DCPS::Serializer operators code for Field in +// the client stubs file. +// +// = AUTHOR +// Scott Harris based on code by Aniruddha Gokhale +// +// ============================================================================ + +#include "be_visitor_array/serializer_op_cs.h" +#include "be_visitor_sequence/serializer_op_cs.h" +#include "be_visitor_structure/serializer_op_cs.h" +#include "be_visitor_union/serializer_op_cs.h" + +ACE_RCSID (be_visitor_field, + serializer_op_cs, + "$Id$") + + +// ********************************************** +// visitor for field in the client stubs file +// ********************************************** + +be_visitor_field_serializer_op_cs::be_visitor_field_serializer_op_cs ( + be_visitor_context *ctx + ) + : be_visitor_decl (ctx) +{ +} + +be_visitor_field_serializer_op_cs::~be_visitor_field_serializer_op_cs (void) +{ +} + +int +be_visitor_field_serializer_op_cs::visit_field (be_field *node) +{ + be_type *bt = be_type::narrow_from_decl (node->field_type ()); + + if (!bt) + { + ACE_ERROR_RETURN ((LM_ERROR, + "(%N:%l) be_visitor_field_serializer_op_cs::" + "visit_field - " + "Bad field type\n"), + -1); + } + + this->ctx_->node (node); + + if (bt->accept (this) == -1) + { + ACE_ERROR_RETURN ((LM_ERROR, + "(%N:%l) be_visitor_field_serializer_op_cs::" + "visit_field - " + "codegen for field type failed\n"), + -1); + } + + return 0; +} + +int +be_visitor_field_serializer_op_cs::visit_array (be_array *node) +{ + // If the array is defined in this scope, we must generate + // CDR stream operators for the array itself. + if (!this->ctx_->alias () + && node->is_child (this->ctx_->scope ())) + { + be_visitor_context ctx (*this->ctx_); + ctx.node (node); + be_visitor_array_serializer_op_cs visitor (&ctx); + + if (node->accept (&visitor) == -1) + { + ACE_ERROR_RETURN ((LM_ERROR, + "(%N:%l) be_visitor_field_serializer_op_cs::" + "visit_array - " + "codegen failed\n"), + -1); + } + } + + // Now generate the (de)marshaling code for the array as a + // field. + + TAO_OutStream *os = this->ctx_->stream (); + be_field *f = this->ctx_->be_node_as_field (); + + if (f == 0) + { + ACE_ERROR_RETURN ((LM_ERROR, + "(%N:%l) be_visitor_field_serializer_op_cs::" + "visit_array - " + "cannot retrieve field node\n"), + -1); + } + + // For anonymous arrays, the type name has a _ prepended. We compute + // the full_name with or without the underscore and use it later on. + char fname [NAMEBUFSIZE]; + + // Save the node's local name and full name in a buffer for quick + // use later on. + ACE_OS::memset (fname, + '\0', + NAMEBUFSIZE); + + if (this->ctx_->alias () == 0 // Not a typedef. + && node->is_child (this->ctx_->scope ())) + { + // For anonymous arrays ... + // we have to generate a name for us that has an underscore + // prepended to our local name. This needs to be inserted after + // the parents's name. + if (node->is_nested ()) + { + be_decl *parent = + be_scope::narrow_from_scope (node->defined_in ())->decl (); + ACE_OS::sprintf (fname, + "%s::_%s", + parent->full_name (), + node->local_name ()->get_string ()); + } + else + { + ACE_OS::sprintf (fname, + "_%s", + node->full_name ()); + } + } + else + { + // Typedefed node. + ACE_OS::sprintf (fname, + "%s", + node->full_name ()); + } + + // Check what is the code generation substate. Are we generating + // code for the in/out operators for our parent or for us? + switch (this->ctx_->sub_state ()) + { + case TAO_CodeGen::TAO_IS_BOUNDED_SIZE: + *os << "_tao_is_bounded_size (_tao_aggregate_" << f->local_name () + << ")"; + break; + case TAO_CodeGen::TAO_MAX_MARSHALED_SIZE: + // get the size of an array typedef + *os << "_dcps_max_marshaled_size (_tao_aggregate_" << f->local_name () + << ")"; + break; + case TAO_CodeGen::TAO_FIND_SIZE: + // get the size of an array typedef + *os << "_dcps_find_size (_tao_aggregate_" << f->local_name () + << ")"; + break; + case TAO_CodeGen::TAO_CDR_INPUT: + *os << "(strm >> " + << "_tao_aggregate_" << f->local_name () << ")"; + + return 0; + case TAO_CodeGen::TAO_CDR_OUTPUT: + *os << "(strm << " + << "_tao_aggregate_" << f->local_name () << ")"; + + return 0; + case TAO_CodeGen::TAO_CDR_SCOPE: + // This is done in serializer_op_cs and hacked into *.i. + break; + default: + // Error. + ACE_ERROR_RETURN ((LM_ERROR, + "(%N:%l) be_visitor_field_serializer_op_cs::" + "visit_array - " + "bad sub state\n"), + -1); + } + + return 0; +} + +int +be_visitor_field_serializer_op_cs::visit_enum (be_enum *node) +{ + // If we are defined inside this scope, we must generate the + /// Serializer stream operators for us here. + if (node->node_type () != AST_Decl::NT_typedef + && node->is_child (this->ctx_->scope ())) + { + be_visitor_context ctx (*this->ctx_); + ctx.node (node); + be_visitor_enum_serializer_op_cs visitor (&ctx); + + if (node->accept (&visitor) == -1) + { + ACE_ERROR_RETURN ((LM_ERROR, + "(%N:%l) be_visitor_field_serializer_op_cs::" + "visit_enum - " + "codegen failed\n"), + -1); + } + } + + TAO_OutStream *os = this->ctx_->stream (); + + // Retrieve the field node. + be_field *f = this->ctx_->be_node_as_field (); + + if (f == 0) + { + ACE_ERROR_RETURN ((LM_ERROR, + "(%N:%l) be_visitor_field_serializer_op_cs::" + "visit_enum - " + "cannot retrieve field node\n"), + -1); + } + + // Check what is the code generations substate. Are we generating code for + // the in/out operators for our parent or for us? + switch (this->ctx_->sub_state ()) + { + case TAO_CodeGen::TAO_IS_BOUNDED_SIZE: + *os << " true /* enum */"; + break; + case TAO_CodeGen::TAO_FIND_SIZE: + case TAO_CodeGen::TAO_MAX_MARSHALED_SIZE: + // enums are serialized as CORBA::ULong + *os << "_dcps_max_marshaled_size_ulong () /* enum */"; + break; + case TAO_CodeGen::TAO_CDR_INPUT: + *os << "(strm >> _tao_aggregate." << f->local_name () << ")"; + + return 0; + case TAO_CodeGen::TAO_CDR_OUTPUT: + *os << "(strm << _tao_aggregate." << f->local_name () << ")"; + + return 0; + case TAO_CodeGen::TAO_CDR_SCOPE: + // Proceed further. + break; + default: + // Error. + ACE_ERROR_RETURN ((LM_ERROR, + "(%N:%l) be_visitor_field_serializer_op_cs::" + "visit_enum - " + "bad sub state\n"), + -1); + } + + return 0; +} + +int +be_visitor_field_serializer_op_cs::visit_interface (be_interface *node) +{ + TAO_OutStream *os = this->ctx_->stream (); + be_field *f = this->ctx_->be_node_as_field (); + + if (!f) + { + ACE_ERROR_RETURN ((LM_ERROR, + "(%N:%l) be_visitor_field_serializer_op_cs::" + "visit_interface - " + "cannot retrieve field node\n"), + -1); + } + + // Check what is the code generations substate. Are we generating code for + // the in/out operators for our parent or for us? + switch (this->ctx_->sub_state ()) + { + case TAO_CodeGen::TAO_CDR_INPUT: + *os << "(strm >> _tao_aggregate." << f->local_name () << ".out ())"; + + break; + case TAO_CodeGen::TAO_CDR_OUTPUT: + if (node->is_defined ()) + { + if (f->is_abstract ()) + { + *os << "(strm << _tao_aggregate." + << f->local_name () << ".in ())"; + } + else + { + *os << "CORBA::Object::marshal (" << be_idt << be_idt_nl + << "_tao_aggregate." << f->local_name () << ".in ()," << be_nl + << "strm" << be_uidt_nl + << ")" << be_uidt; + } + } + else + { + *os << "TAO::Objref_Traits<" << node->name () << ">::marshal (" + << be_idt << be_idt_nl + << "_tao_aggregate." << f->local_name () << ".in ()," << be_nl + << "strm" << be_uidt_nl + << ")" << be_uidt; + } + + break; + case TAO_CodeGen::TAO_CDR_SCOPE: + // Nothing to be done because an interface cannot be declared inside a + // structure. + break; + default: + // Error. + ACE_ERROR_RETURN ((LM_ERROR, + "(%N:%l) be_visitor_field_serializer_op_cs::" + "visit_interface - " + "bad sub state\n"), + -1); + } + + return 0; +} + +int +be_visitor_field_serializer_op_cs::visit_component (be_component *node) +{ + return this->visit_interface (node); +} + +int +be_visitor_field_serializer_op_cs::visit_interface_fwd (be_interface_fwd *node) +{ + TAO_OutStream *os = this->ctx_->stream (); + + // Retrieve the field node. + be_field *f = this->ctx_->be_node_as_field (); + + if (f == 0) + { + ACE_ERROR_RETURN ((LM_ERROR, + "(%N:%l) be_visitor_field_serializer_op_cs::" + "visit_interface_fwd - " + "cannot retrieve field node\n"), + -1); + } + + // Check what is the code generations substate. Are we generating code for + // the in/out operators for our parent or for us? + switch (this->ctx_->sub_state ()) + { + case TAO_CodeGen::TAO_CDR_INPUT: + *os << "(strm >> _tao_aggregate." << f->local_name () << ".out ())"; + + break; + case TAO_CodeGen::TAO_CDR_OUTPUT: + if (node->is_defined ()) + { + if (f->is_abstract ()) + { + *os << "(strm << _tao_aggregate." + << f->local_name () << ".in ())"; + } + else + { + *os << "CORBA::Object::marshal (" << be_idt << be_idt_nl + << "_tao_aggregate." << f->local_name () << ".in ()," << be_nl + << "strm" << be_uidt_nl + << ")" << be_uidt; + } + } + else + { + AST_Decl *parent = ScopeAsDecl (node->defined_in ()); + + if (parent != 0 && parent->node_type () != AST_Decl::NT_root) + { + *os << parent->name () << "::"; + } + + *os << "TAO::Objref_Traits<" << node->name () << ">::marshal (" + << be_idt << be_idt_nl + << "_tao_aggregate." << f->local_name () << ".in ()," << be_nl + << "strm" << be_uidt_nl + << ")" << be_uidt; + } + + break; + case TAO_CodeGen::TAO_CDR_SCOPE: + // Nothing to be done because an interface cannot be declared inside a + // structure. + break; + default: + // Error. + ACE_ERROR_RETURN ((LM_ERROR, + "(%N:%l) be_visitor_field_serializer_op_cs::" + "visit_interface_fwd - " + "bad sub state\n"), + -1); + } + + return 0; +} + +int +be_visitor_field_serializer_op_cs::visit_component_fwd (be_component_fwd *node) +{ + return this->visit_interface_fwd (node); +} + +int +be_visitor_field_serializer_op_cs::visit_valuetype (be_valuetype *) +{ + TAO_OutStream *os = this->ctx_->stream (); + be_field *f = this->ctx_->be_node_as_field (); + + if (!f) + { + ACE_ERROR_RETURN ((LM_ERROR, + "(%N:%l) be_visitor_field_serializer_op_cs::" + "visit_valuetype - " + "cannot retrieve field node\n"), + -1); + } + + // Check what is the code generations substate. Are we generating code for + // the in/out operators for our parent or for us? + switch (this->ctx_->sub_state ()) + { + case TAO_CodeGen::TAO_CDR_INPUT: + *os << "(strm >> _tao_aggregate." << f->local_name () << ".out ())"; + + break; + case TAO_CodeGen::TAO_CDR_OUTPUT: + *os << "(strm << _tao_aggregate." << f->local_name () << ".in ())"; + + break; + case TAO_CodeGen::TAO_CDR_SCOPE: + // Nothing to be done because a valuetype cannot be declared inside a + // structure. + break; + default: + // Error. + ACE_ERROR_RETURN ((LM_ERROR, + "(%N:%l) be_visitor_field_serializer_op_cs::" + "visit_valuetype - " + "bad sub state\n"), + -1); + } + + return 0; +} + +int +be_visitor_field_serializer_op_cs::visit_eventtype (be_eventtype *node) +{ + return this->visit_valuetype (node); +} + +int +be_visitor_field_serializer_op_cs::visit_valuetype_fwd (be_valuetype_fwd *) +{ + TAO_OutStream *os = this->ctx_->stream (); + + // Retrieve the field node. + be_field *f = this->ctx_->be_node_as_field (); + + if (f == 0) + { + ACE_ERROR_RETURN ((LM_ERROR, + "(%N:%l) be_visitor_field_serializer_op_cs::" + "visit_valuetype_fwd - " + "cannot retrieve field node\n"), + -1); + } + + // Check what is the code generations substate. Are we generating code for + // the in/out operators for our parent or for us? + switch (this->ctx_->sub_state ()) + { + case TAO_CodeGen::TAO_CDR_INPUT: + *os << "(strm >> _tao_aggregate." << f->local_name () << ".out ())"; + + break; + case TAO_CodeGen::TAO_CDR_OUTPUT: + *os << "(strm << _tao_aggregate." << f->local_name () << ".in ())"; + + break; + case TAO_CodeGen::TAO_CDR_SCOPE: + // Nothing to be done because a valuetype cannot be declared inside a + // structure. + break; + default: + // Error. + ACE_ERROR_RETURN ((LM_ERROR, + "(%N:%l) be_visitor_field_serializer_op_cs::" + "visit_valuetype_fwd - " + "bad sub state\n"), + -1); + } + + return 0; +} + +int +be_visitor_field_serializer_op_cs::visit_eventtype_fwd (be_eventtype_fwd *node) +{ + return this->visit_valuetype_fwd (node); +} + +// Visit predefined type. +int +be_visitor_field_serializer_op_cs::visit_predefined_type (be_predefined_type *node) +{ + TAO_OutStream *os = this->ctx_->stream (); + + // Retrieve the field node. + be_field *f = this->ctx_->be_node_as_field (); + + if (f == 0) + { + ACE_ERROR_RETURN ((LM_ERROR, + "(%N:%l) be_visitor_field_serializer_op_cs::" + "visit_predefined_type - " + "cannot retrieve field node\n"), + -1); + } + + AST_PredefinedType::PredefinedType pt = node->pt (); + + // Check what is the code generations substate. Are we generating code for + // the in/out operators for our parent or for us? + switch (this->ctx_->sub_state ()) + { + + case TAO_CodeGen::TAO_IS_BOUNDED_SIZE: + if (pt == AST_PredefinedType::PT_pseudo + || pt == AST_PredefinedType::PT_object) + { + ACE_ERROR_RETURN ((LM_ERROR, + "(%N:%l) be_visitor_field_serializer_op_cs::" + "visit_predefined_type - TAO_IS_BOUNDED_SIZE " + "object and psuedo are not supported by DDS\n"), + -1); + } + + else + { + *os << " true "; // all predefined types are bounded + } + break; + case TAO_CodeGen::TAO_MAX_MARSHALED_SIZE: + case TAO_CodeGen::TAO_FIND_SIZE: // the max and current sizes are the same for predefined types + if (pt == AST_PredefinedType::PT_pseudo + || pt == AST_PredefinedType::PT_object) + { + ACE_ERROR_RETURN ((LM_ERROR, + "(%N:%l) be_visitor_field_serializer_op_cs::" + "visit_predefined_type - TAO_MAX_MARSHALED_SIZE " + "object and psuedo are not supported by DDS\n"), + -1); + } + else if (pt == AST_PredefinedType::PT_char) + { + *os << "_dcps_max_marshaled_size (CORBA::Any::from_char (_tao_aggregate." + << f->local_name () << "))"; + } + else if (pt == AST_PredefinedType::PT_wchar) + { + *os << "_dcps_max_marshaled_size (CORBA::Any::from_wchar (_tao_aggregate." + << f->local_name () << "))"; + } + else if (pt == AST_PredefinedType::PT_octet) + { + *os << "_dcps_max_marshaled_size (CORBA::Any::from_octet (_tao_aggregate." + << f->local_name () << "))"; + } + else if (pt == AST_PredefinedType::PT_boolean) + { + *os << "_dcps_max_marshaled_size (CORBA::Any::from_boolean (_tao_aggregate." + << f->local_name () << "))"; + } + else + { + *os << "_dcps_max_marshaled_size (_tao_aggregate." << f->local_name () << ")"; + } + break; + case TAO_CodeGen::TAO_CDR_INPUT: + if (pt == AST_PredefinedType::PT_pseudo + || pt == AST_PredefinedType::PT_object) + { + *os << "(strm >> _tao_aggregate." << f->local_name () + << ".out ())"; + } + else if (pt == AST_PredefinedType::PT_char) + { + *os << "(strm >> CORBA::Any::to_char (_tao_aggregate." + << f->local_name () << "))"; + } + else if (pt == AST_PredefinedType::PT_wchar) + { + *os << "(strm >> CORBA::Any::to_wchar (_tao_aggregate." + << f->local_name () << "))"; + } + else if (pt == AST_PredefinedType::PT_octet) + { + *os << "(strm >> CORBA::Any::to_octet (_tao_aggregate." + << f->local_name () << "))"; + } + else if (pt == AST_PredefinedType::PT_boolean) + { + *os << "(strm >> CORBA::Any::to_boolean (_tao_aggregate." + << f->local_name () << "))"; + } + else + { + *os << "(strm >> _tao_aggregate." << f->local_name () << ")"; + } + break; + case TAO_CodeGen::TAO_CDR_OUTPUT: + if (pt == AST_PredefinedType::PT_pseudo + || pt == AST_PredefinedType::PT_object) + { + *os << "(strm << _tao_aggregate." << f->local_name () << ".in ())"; + } + else if (pt == AST_PredefinedType::PT_char) + { + *os << "(strm << CORBA::Any::from_char (_tao_aggregate." + << f->local_name () << "))"; + } + else if (pt == AST_PredefinedType::PT_wchar) + { + *os << "(strm << CORBA::Any::from_wchar (_tao_aggregate." + << f->local_name () << "))"; + } + else if (pt == AST_PredefinedType::PT_octet) + { + *os << "(strm << CORBA::Any::from_octet (_tao_aggregate." + << f->local_name () << "))"; + } + else if (pt == AST_PredefinedType::PT_boolean) + { + *os << "(strm << CORBA::Any::from_boolean (_tao_aggregate." + << f->local_name () << "))"; + } + else + { + *os << "(strm << _tao_aggregate." << f->local_name () << ")"; + } + break; + case TAO_CodeGen::TAO_CDR_SCOPE: + // Nothing to be done. + break; + default: + // Error. + ACE_ERROR_RETURN ((LM_ERROR, + "(%N:%l) be_visitor_field_serializer_op_cs::" + "visit_predefined_type - " + "bad sub state\n"), + -1); + } + + return 0; +} + +int +be_visitor_field_serializer_op_cs::visit_sequence (be_sequence *node) +{ + // If the sequence is defined in this scope, generate its + // Serializer stream operators here. + if (node->node_type () != AST_Decl::NT_typedef + && node->is_child (this->ctx_->scope ())) + { + be_visitor_context ctx (*this->ctx_); + ctx.node (node); + be_visitor_sequence_serializer_op_cs visitor (&ctx); + + if (node->accept (&visitor) == -1) + { + ACE_ERROR_RETURN ((LM_ERROR, + "(%N:%l) be_visitor_field_serializer_op_cs::" + "visit_sequence - " + "codegen failed\n"), + -1); + } + } + + // How generate the marshaling code for the sequence as a field. + + TAO_OutStream *os = this->ctx_->stream (); + + // Retrieve the field node. + be_field *f = this->ctx_->be_node_as_field (); + + if (f == 0) + { + ACE_ERROR_RETURN ((LM_ERROR, + "(%N:%l) be_visitor_field_serializer_op_cs::" + "visit_sequence - " + "cannot retrieve field node\n"), + -1); + } + + // Check what is the code generations substate. Are we generating code for + // the in/out operators for our parent or for us? + switch (this->ctx_->sub_state ()) + { + case TAO_CodeGen::TAO_IS_BOUNDED_SIZE: + *os << "_tao_is_bounded_size (_tao_aggregate." << f->local_name () + << ")"; + break; + case TAO_CodeGen::TAO_MAX_MARSHALED_SIZE: + *os << "_dcps_max_marshaled_size (_tao_aggregate." << f->local_name () + << ")"; + break; + case TAO_CodeGen::TAO_FIND_SIZE: + *os << "_dcps_find_size (_tao_aggregate." << f->local_name () + << ")"; + break; + case TAO_CodeGen::TAO_CDR_INPUT: + *os << "(strm >> _tao_aggregate." << f->local_name () << ")"; + + return 0; + case TAO_CodeGen::TAO_CDR_OUTPUT: + *os << "(strm << _tao_aggregate." << f->local_name () << ")"; + + return 0; + case TAO_CodeGen::TAO_CDR_SCOPE: + // Proceed further. + break; + default: + // Error. + ACE_ERROR_RETURN ((LM_ERROR, + "(%N:%l) be_visitor_field_serializer_op_cs::" + "visit_sequence - " + "bad sub state\n"), + -1); + } + + return 0; +} + +int +be_visitor_field_serializer_op_cs::visit_string (be_string *node) +{ + TAO_OutStream *os = this->ctx_->stream (); + + // Retrieve the field node. + be_field *f = this->ctx_->be_node_as_field (); + + if (f == 0) + { + ACE_ERROR_RETURN ((LM_ERROR, + "(%N:%l) be_visitor_field_serializer_op_cs::" + "visit_string - " + "cannot retrieve field node\n"), + -1); + } + + // check what is the code generation's substate. Are we generating code for + // the in/out operators for our parent or for us? + switch (this->ctx_->sub_state ()) + { + case TAO_CodeGen::TAO_IS_BOUNDED_SIZE: + if (0 == node->max_size ()->ev ()->u.ulval) + *os << "false /* unbounded string */"; + else + *os << "true /* bounded string */"; + break; + case TAO_CodeGen::TAO_MAX_MARSHALED_SIZE: + char buff[15]; + ACE_OS::sprintf(buff, "%d", node->max_size ()->ev ()->u.ulval); + *os << "_dcps_max_marshaled_size_ulong () + " << buff; + break; + case TAO_CodeGen::TAO_FIND_SIZE: + *os << "_dcps_max_marshaled_size_ulong() + " + << "ACE_OS::strlen(_tao_aggregate." + << f->local_name () << ".in ())"; + break; + case TAO_CodeGen::TAO_CDR_INPUT: + *os << "(strm >> _tao_aggregate." << f->local_name () << ".out ())"; + + break; + case TAO_CodeGen::TAO_CDR_OUTPUT: + *os << "(strm << _tao_aggregate." << f->local_name () << ".in ())"; + + break; + case TAO_CodeGen::TAO_CDR_SCOPE: + // Nothing to be done. + break; + default: + // Error. + ACE_ERROR_RETURN ((LM_ERROR, + "(%N:%l) be_visitor_field_serializer_op_cs::" + "visit_array - " + "bad substate\n"), + -1); + } + + return 0; +} + +int +be_visitor_field_serializer_op_cs::visit_structure (be_structure *node) +{ + // If the struct is defined in this scope, generate its Serializer stream + // operators here. + if (node->node_type () != AST_Decl::NT_typedef + && node->is_child (this->ctx_->scope ())) + { + be_visitor_context ctx (*this->ctx_); + ctx.node (node); + be_visitor_structure_serializer_op_cs visitor (&ctx); + + if (node->accept (&visitor) == -1) + { + ACE_ERROR_RETURN ((LM_ERROR, + "(%N:%l) be_visitor_field_serializer_op_cs::" + "visit_struct - " + "codegen failed\n"), + -1); + } + } + + // How generate the marshaling code for the struct as a field. + + TAO_OutStream *os = this->ctx_->stream (); + + // retrieve the field node. + be_field *f = this->ctx_->be_node_as_field (); + + if (f == 0) + { + ACE_ERROR_RETURN ((LM_ERROR, + "(%N:%l) be_visitor_field_serializer_op_cs::" + "visit_structure - " + "cannot retrieve field node\n"), + -1); + } + + // Check what is the code generations substate. Are we generating code for + // the in/out operators for our parent or for us? + switch (this->ctx_->sub_state ()) + { + case TAO_CodeGen::TAO_IS_BOUNDED_SIZE: + *os << "_tao_is_bounded_size (_tao_aggregate." << f->local_name () + << ")"; + break; + case TAO_CodeGen::TAO_MAX_MARSHALED_SIZE: + *os << "_dcps_max_marshaled_size (_tao_aggregate." << f->local_name () + << ")"; + break; + case TAO_CodeGen::TAO_FIND_SIZE: + *os << "_dcps_find_size (_tao_aggregate." << f->local_name () + << ")"; + break; + case TAO_CodeGen::TAO_CDR_INPUT: + *os << "(strm >> _tao_aggregate." << f->local_name () << ")"; + + return 0; + case TAO_CodeGen::TAO_CDR_OUTPUT: + *os << "(strm << _tao_aggregate." << f->local_name () << ")"; + + return 0; + case TAO_CodeGen::TAO_CDR_SCOPE: + // Proceed further. + break; + default: + // Error. + ACE_ERROR_RETURN ((LM_ERROR, + "(%N:%l) be_visitor_field_serializer_op_cs::" + "visit_structure - " + "bad sub state\n"), + -1); + } + + return 0; +} + +int +be_visitor_field_serializer_op_cs::visit_typedef (be_typedef *node) +{ + this->ctx_->alias (node); + be_type *bt = node->primitive_base_type (); + + if (!bt || (bt->accept (this) == -1)) + { + ACE_ERROR_RETURN ((LM_ERROR, + "(%N:%l) be_visitor_field_serializer_op_cs::" + "visit_typedef - " + "Bad primitive type\n"), + -1); + } + + this->ctx_->alias (0); + return 0; +} + +int +be_visitor_field_serializer_op_cs::visit_union (be_union *node) +{ + // If the union is defined in this scope, generate its Serializer stream + // operators here. + if (node->node_type () != AST_Decl::NT_typedef + && node->is_child (this->ctx_->scope ())) + { + be_visitor_context ctx (*this->ctx_); + ctx.node (node); + be_visitor_union_serializer_op_cs visitor (&ctx); + + if (node->accept (&visitor) == -1) + { + ACE_ERROR_RETURN ((LM_ERROR, + "(%N:%l) be_visitor_field_serializer_op_cs::" + "visit_union - " + "codegen failed\n"), + -1); + } + } + + // Now generate marshaling code for the union as a field. + + TAO_OutStream *os = this->ctx_->stream (); + + // Retrieve the field node. + be_field *f = this->ctx_->be_node_as_field (); + + if (f == 0) + { + ACE_ERROR_RETURN ((LM_ERROR, + "(%N:%l) be_visitor_field_serializer_op_cs::" + "visit_union - " + "cannot retrieve field node\n"), + -1); + } + + // Check what is the code generations substate. Are we generating code for + // the in/out operators for our parent or for us? + switch (this->ctx_->sub_state ()) + { + case TAO_CodeGen::TAO_IS_BOUNDED_SIZE: + *os << "_tao_is_bounded_size (_tao_aggregate." << f->local_name () + << ")"; + break; + case TAO_CodeGen::TAO_MAX_MARSHALED_SIZE: + *os << "_dcps_max_marshaled_size (_tao_aggregate." << f->local_name () + << ")"; + break; + case TAO_CodeGen::TAO_FIND_SIZE: + *os << "_dcps_find_size (_tao_aggregate." << f->local_name () + << ")"; + break; + case TAO_CodeGen::TAO_CDR_INPUT: + *os << "(strm >> _tao_aggregate." << f->local_name () << ")"; + + return 0; + case TAO_CodeGen::TAO_CDR_OUTPUT: + *os << "(strm << _tao_aggregate." << f->local_name () << ")"; + + return 0; + case TAO_CodeGen::TAO_CDR_SCOPE: + // Proceed further. + break; + default: + // Error. + ACE_ERROR_RETURN ((LM_ERROR, + "(%N:%l) be_visitor_field_serializer_op_cs::" + "visit_union - " + "bad sub state\n"), + -1); + } + + return 0; +} + +// **************************************************************** + +be_visitor_serializer_op_field_decl::be_visitor_serializer_op_field_decl ( + be_visitor_context *ctx + ) + : be_visitor_scope (ctx) +{ +} + +// This is a field, but the action depends on the type of the field, +// use this visitor to detect the type of the field. +// Notice that this is why the parent visitor (who create us) cannot +// do the job, because it may have another purpose for some or all of +// the visit_* methods; in other words, while running a visitor to +// generate TAO::DCPS::Serializer operators for structures we cannot use that one to +// generate the code of each field, because visit_struct already has a +// meaning in that visitor. +int +be_visitor_serializer_op_field_decl::visit_field (be_field *node) +{ + be_type *bt = be_type::narrow_from_decl (node->field_type ()); + + if (bt == 0) + { + ACE_ERROR_RETURN ((LM_ERROR, + "(%N:%l) be_visitor_serializer_op_field_decl::" + "visit_field - " + "Bad field type\n"), + -1); + } + + // @@ Shouldn't this be saved in the visitor and not the context?! + this->ctx_->node (node); + + if (bt->accept (this) == -1) + { + ACE_ERROR_RETURN ((LM_ERROR, + "(%N:%l) be_visitor_serializer_op_field_decl::" + "visit_field - " + "codegen for field type failed\n"), + -1); + } + + return 0; +} + +int +be_visitor_serializer_op_field_decl::visit_array (be_array *node) +{ + TAO_OutStream *os = this->ctx_->stream (); + + // Retrieve the field node. + be_field *f = this->ctx_->be_node_as_field (); + + if (f == 0) + { + ACE_ERROR_RETURN ((LM_ERROR, + "(%N:%l) be_visitor_serializer_op_field_decl::" + "visit_array - " + "cannot retrieve field node\n"), + -1); + } + + // For anonymous arrays, the type name has a _ prepended. We compute + // the full_name with or without the underscore and use it later on. + char fname [NAMEBUFSIZE]; + + ACE_OS::memset (fname, + '\0', + NAMEBUFSIZE); + + if (this->ctx_->alias () == 0 // Not a typedef. + && node->is_child (this->ctx_->scope ())) + { + // For anonymous arrays, + // we have to generate a name for us that has an underscope + // prepended to our local name. This needs to be inserted after + // the parents's name. + + if (node->is_nested ()) + { + be_decl *parent = be_scope::narrow_from_scope (node->defined_in ())->decl (); + ACE_OS::sprintf (fname, + "%s::_%s", + parent->full_name (), + node->local_name ()->get_string ()); + } + else + { + ACE_OS::sprintf (fname, + "_%s", + node->full_name ()); + } + } + else + { + // Typedefed node. + ACE_OS::sprintf (fname, + "%s", + node->full_name ()); + } + + // Check what is the code generation substate. Are we generating code for + // the in/out operators for our parent or for us? + switch (this->ctx_->sub_state ()) + { + case TAO_CodeGen::TAO_IS_BOUNDED_SIZE: + case TAO_CodeGen::TAO_MAX_MARSHALED_SIZE: + case TAO_CodeGen::TAO_FIND_SIZE: + case TAO_CodeGen::TAO_CDR_INPUT: + case TAO_CodeGen::TAO_CDR_OUTPUT: + *os << fname << "_forany " + << "_tao_aggregate_" << f->local_name () << be_idt << be_idt_nl + << "(const_cast<" << be_idt << be_idt_nl + << fname << "_slice*> (" << be_nl + << "_tao_aggregate." << f->local_name () << be_uidt_nl + << ")" << be_uidt << be_uidt_nl + << ");" << be_uidt_nl; + + break; + case TAO_CodeGen::TAO_CDR_SCOPE: + default: + // Error. + ACE_ERROR_RETURN ((LM_ERROR, + "(%N:%l) be_visitor_serializer_op_field_decl::" + "visit_array - " + "bad sub state\n"), + -1); + } + + return 0; +} + + +int +be_visitor_serializer_op_field_decl::visit_typedef (be_typedef *node) +{ + this->ctx_->alias (node); // Save the typedef node for use in code + // generation as we visit the base type. + + // The node to be visited in the base primitve type that gets typedefed. + be_type *bt = node->primitive_base_type (); + + if (bt == 0 || bt->accept (this) == -1) + { + ACE_ERROR_RETURN ((LM_ERROR, + "(%N:%l) be_visitor_serializer_op_field_decl::" + "visit_typedef - " + "Bad primitive type\n"), + -1); + } + + this->ctx_->alias (0); + return 0; +} diff --git a/TAO/TAO_IDL/be/be_visitor_module/serializer_op.cpp b/TAO/TAO_IDL/be/be_visitor_module/serializer_op.cpp new file mode 100644 index 00000000000..46418fd81bb --- /dev/null +++ b/TAO/TAO_IDL/be/be_visitor_module/serializer_op.cpp @@ -0,0 +1,52 @@ +// +// $Id$ +// + +// ============================================================================ +// +// = LIBRARY +// TAO IDL +// +// = FILENAME +// serializer_op.cpp +// +// = DESCRIPTION +// Visitor generating code for the TAO::DCPS::Serializer operators +// for types defined in Module's scope. +// +// = AUTHOR +// Scott Harris based on code by Aniruddha Gokhale +// +// ============================================================================ + +ACE_RCSID (be_visitor_module, + serializer_op, + "$Id: serializer_op.cpp,v 1.2 1999/05/28 02:16:43 coryan Exp ") + +// *************************************************************************** +// Module visitor for generating Serializer operator declarations in the client header +// and stub +// *************************************************************************** + +be_visitor_module_serializer_op::be_visitor_module_serializer_op (be_visitor_context *ctx) + : be_visitor_module (ctx) +{ +} + +be_visitor_module_serializer_op::~be_visitor_module_serializer_op (void) +{ +} + +int +be_visitor_module_serializer_op::visit_module (be_module *node) +{ + if (this->visit_scope (node) == -1) + { + ACE_ERROR_RETURN ((LM_ERROR, + "(%N:%l) be_visitor_module_serializer_op::visit_module - " + "codegen for scope failed\n"), + -1); + } + + return 0; +} diff --git a/TAO/TAO_IDL/be/be_visitor_root/serializer_op.cpp b/TAO/TAO_IDL/be/be_visitor_root/serializer_op.cpp new file mode 100644 index 00000000000..09ee1429df7 --- /dev/null +++ b/TAO/TAO_IDL/be/be_visitor_root/serializer_op.cpp @@ -0,0 +1,52 @@ +// +// $Id$ +// + +// ============================================================================ +// +// = LIBRARY +// TAO IDL +// +// = FILENAME +// serializer_op.cpp +// +// = DESCRIPTION +// Visitor generating code for the TAO::DCPS::Serializer operators +// for types defined in Root's scope. +// +// = AUTHOR +// Scott Harris based on code by Aniruddha Gokhale +// +// ============================================================================ + +ACE_RCSID (be_visitor_root, + serializer_op, + "$Id$") + +// *************************************************************************** +// Root visitor for generating Serializer operator declarations in the client header +// and stub +// *************************************************************************** + +be_visitor_root_serializer_op::be_visitor_root_serializer_op (be_visitor_context *ctx) + : be_visitor_root (ctx) +{ +} + +be_visitor_root_serializer_op::~be_visitor_root_serializer_op (void) +{ +} + +int +be_visitor_root_serializer_op::visit_root (be_root *node) +{ + if (this->visit_scope (node) == -1) + { + ACE_ERROR_RETURN ((LM_ERROR, + "(%N:%l) be_visitor_root_serializer_op::visit_root - " + "codegen for scope failed\n"), + -1); + } + + return 0; +} diff --git a/TAO/TAO_IDL/be/be_visitor_sequence/serializer_op_ch.cpp b/TAO/TAO_IDL/be/be_visitor_sequence/serializer_op_ch.cpp new file mode 100644 index 00000000000..52dd795af45 --- /dev/null +++ b/TAO/TAO_IDL/be/be_visitor_sequence/serializer_op_ch.cpp @@ -0,0 +1,117 @@ +// +// $Id$ +// + +// ============================================================================ +// +// = LIBRARY +// TAO IDL +// +// = FILENAME +// serializer_op_ch.cpp +// +// = DESCRIPTION +// Visitor generating code for TAO::DCPS::Serializer operators for sequences. +// This uses compiled marshaling. +// +// = AUTHOR +// Scott Harris based on code by Aniruddha Gokhale +// +// ============================================================================ + +ACE_RCSID (be_visitor_sequence, + serializer_op_ch, + "$Id$") + +// *************************************************************************** +// Sequence visitor for generating Serializer operator declarations in the client header +// *************************************************************************** + +be_visitor_sequence_serializer_op_ch::be_visitor_sequence_serializer_op_ch ( + be_visitor_context *ctx + ) + : be_visitor_decl (ctx) +{ +} + +be_visitor_sequence_serializer_op_ch::~be_visitor_sequence_serializer_op_ch (void) +{ +} + +int +be_visitor_sequence_serializer_op_ch::visit_sequence (be_sequence *node) +{ + if (node->cli_hdr_serializer_op_gen () + || node->imported () + || node->is_local ()) + { + return 0; + } + + be_type *base_type = be_type::narrow_from_decl (node->base_type ()); + + // If our base type is an anonymous sequence, generate code for it here. + if (base_type->node_type () == AST_Decl::NT_sequence) + { + if (base_type->accept (this) != 0) + { + ACE_ERROR_RETURN ((LM_ERROR, + "be_visitor_sequence_serializer_op_ch::visit_sequence -" + "codegen for nested anonymous sequence failed\n"), + -1); + } + } + + TAO_OutStream *os = this->ctx_->stream (); + + be_type *bt = be_type::narrow_from_decl (node); + be_typedef *tdef = be_typedef::narrow_from_decl (bt); + + *os << be_nl << be_nl << "// TAO_IDL - Generated from" << be_nl + << "// " << __FILE__ << ":" << __LINE__; + + // If we're an anonymous sequence, we must protect against + // being declared more than once. + if (!tdef) + { + *os << "\n\n#if !defined _TAO_SERIALIZER_OP_" + << node->flat_name () << "_H_" + << "\n#define _TAO_SERIALIZER_OP_" << node->flat_name () << "_H_"; + } + + *os << be_nl << be_nl; + + *os << be_global->stub_export_macro () + << " CORBA::Boolean _tao_is_bounded_size (" << be_idt << be_idt_nl + << "const " << node->name () << " &" << be_uidt_nl + << ");" << be_uidt_nl; + *os << be_global->stub_export_macro () + << " size_t _dcps_max_marshaled_size (" << be_idt << be_idt_nl + << "const " << node->name () << " &" << be_uidt_nl + << ");" << be_uidt_nl; + *os << be_global->stub_export_macro () + << " size_t _dcps_find_size (" << be_idt << be_idt_nl + << "const " << node->name () << " &" << be_uidt_nl + << ");" << be_uidt_nl; + + *os << be_nl << be_nl + << be_global->stub_export_macro () << " CORBA::Boolean" + << " operator<< (" << be_idt << be_idt_nl + << "TAO::DCPS::Serializer &," << be_nl + << "const " << node->name () << " &" << be_uidt_nl + << ");" << be_uidt_nl; + *os << be_global->stub_export_macro () << " CORBA::Boolean" + << " operator>> (" << be_idt << be_idt_nl + << "TAO::DCPS::Serializer &," << be_nl + << node->name () << " &" << be_uidt_nl + << ");" << be_uidt; + + if (!tdef) + { + *os << "\n\n#endif /* _TAO_SERIALIZER_OP_" + << node->flat_name () << "_H_ */"; + } + + node->cli_hdr_serializer_op_gen (1); + return 0; +} diff --git a/TAO/TAO_IDL/be/be_visitor_sequence/serializer_op_cs.cpp b/TAO/TAO_IDL/be/be_visitor_sequence/serializer_op_cs.cpp new file mode 100644 index 00000000000..2ca3f3c60e0 --- /dev/null +++ b/TAO/TAO_IDL/be/be_visitor_sequence/serializer_op_cs.cpp @@ -0,0 +1,1333 @@ +// ============================================================================ +// +// = LIBRARY +// TAO IDL +// +// = FILENAME +// serializer_op_cs.cpp +// +// = DESCRIPTION +// Visitor for code generation of Sequences for the +// TAO::DCPS::Serializer operators in the client stubs. +// +// = AUTHOR +// Scott Harris based on code by Aniruddha Gokhale +// +// ============================================================================ + +ACE_RCSID (be_visitor_sequence, + serializer_op_cs, + "$Id$") + +// *************************************************************************** +// Sequence visitor for generating Serializer operator declarations in the client +// stubs file. +// *************************************************************************** + +be_visitor_sequence_serializer_op_cs::be_visitor_sequence_serializer_op_cs ( + be_visitor_context *ctx + ) + : be_visitor_decl (ctx) +{ +} + +be_visitor_sequence_serializer_op_cs::~be_visitor_sequence_serializer_op_cs (void) +{ +} + +int +be_visitor_sequence_serializer_op_cs::visit_sequence (be_sequence *node) +{ + if (this->ctx_->alias ()) + { + // We are here because the base type of the sequence node is + // itself a sequence i.e., this is a case of sequence of + // typedef'd sequence. For the case of sequence of + // anonymous sequence, see comment below. + return this->visit_node (node); + } + + if (node->cli_stub_serializer_op_gen () + || node->imported () + || node->is_local ()) + { + return 0; + } + + TAO_OutStream *os = this->ctx_->stream (); + + be_type *bt = + be_type::narrow_from_decl (node->base_type ()); + + if (!bt) + { + ACE_ERROR_RETURN ((LM_ERROR, + "be_visitor_sequence_serializer_op_cs::" + "visit_sequence - " + "Bad base type\n"), + -1); + } + + // Generate the Serializer << and >> operator defns. + + // Save the sequence node for further use. + this->ctx_->node (node); + + // If our element type is an anonymous sequence, generate code for it here. + if (bt->node_type () == AST_Decl::NT_sequence) + { + int status = + this->gen_anonymous_base_type ( + bt, + TAO_CodeGen::TAO_ROOT_SERIALIZER_OP_CS + ); + + if (status == -1) + { + ACE_ERROR_RETURN ((LM_ERROR, + "(%N:%l) be_visitor_sequence_serializer_op_cs::" + "visit_sequence - " + "gen_anonymous_base_type failed\n"), + -1); + } + } + + *os << be_nl << be_nl << "// TAO_IDL - Generated from" << be_nl + << "// " << __FILE__ << ":" << __LINE__ << be_nl << be_nl; + + *os << "#if !defined _TAO_SERIALIZER_OP_" + << node->flat_name () << "_CPP_" << be_nl + << "#define _TAO_SERIALIZER_OP_" << node->flat_name () << "_CPP_" + << be_nl << be_nl; + + // --- _tao_is_bounded_size --- + this->ctx_->sub_state (TAO_CodeGen::TAO_IS_BOUNDED_SIZE); + + *os << "CORBA::Boolean _tao_is_bounded_size (" << be_idt << be_idt_nl + << "const " << node->name () + << " &_tao_sequence" << be_uidt_nl + << ")" << be_uidt_nl + << "{" << be_idt_nl; + + if (bt->node_type () == AST_Decl::NT_sequence) + { + this->visit_node (node); + } + else + { + if (bt->accept (this) == -1) + { + ACE_ERROR_RETURN ((LM_ERROR, + "be_visitor_sequence_serializer_op_cs::" + "visit_sequence - " + "Base type codegen failed\n"), + -1); + } + } + + *os << be_uidt_nl + << "}" << be_nl << be_nl; + + // --- _dcps_max_marshaled_size --- + + this->ctx_->sub_state (TAO_CodeGen::TAO_MAX_MARSHALED_SIZE); + + *os << "size_t _dcps_max_marshaled_size (" << be_idt << be_idt_nl + << "const " << node->name () + << " &_tao_sequence" << be_uidt_nl + << ")" << be_uidt_nl + << "{" << be_idt_nl; + + if (bt->node_type () == AST_Decl::NT_sequence) + { + this->visit_node (node); + } + else + { + if (bt->accept (this) == -1) + { + ACE_ERROR_RETURN ((LM_ERROR, + "be_visitor_sequence_serializer_op_cs::" + "visit_sequence - " + "Base type codegen failed\n"), + -1); + } + } + + *os << be_uidt_nl + << "}" << be_nl << be_nl; + + // --- _dcps_find_size --- + this->ctx_->sub_state (TAO_CodeGen::TAO_FIND_SIZE); + + *os << "size_t _dcps_find_size (" << be_idt << be_idt_nl + << "const " << node->name () + << " &_tao_sequence" << be_uidt_nl + << ")" << be_uidt_nl + << "{" << be_idt_nl; + + if (bt->node_type () == AST_Decl::NT_sequence) + { + this->visit_node (node); + } + else + { + if (bt->accept (this) == -1) + { + ACE_ERROR_RETURN ((LM_ERROR, + "be_visitor_sequence_serializer_op_cs::" + "visit_sequence - " + "Base type codegen failed\n"), + -1); + } + } + + *os << be_uidt_nl + << "}" << be_nl << be_nl; + + + // --- operator<< --- + + // Set the sub state as generating code for the output operator. + this->ctx_->sub_state (TAO_CodeGen::TAO_CDR_OUTPUT); + + *os << "CORBA::Boolean operator<< (" << be_idt << be_idt_nl + << "TAO::DCPS::Serializer &strm," << be_nl + << "const " << node->name () + << " &_tao_sequence" << be_uidt_nl + << ")" << be_uidt_nl + << "{" << be_idt_nl; + + // First encode the sequence length. + *os << "const CORBA::ULong _tao_seq_len = _tao_sequence.length ();" + << be_nl << be_nl; + *os << "if (strm << _tao_seq_len)" << be_idt_nl + << "{" << be_idt_nl; + + // Now encode the sequence elements. + *os << "// Encode all elements." << be_nl; + + + if (bt->node_type () == AST_Decl::NT_sequence) + { + this->visit_node (node); + } + else + { + if (bt->accept (this) == -1) + { + ACE_ERROR_RETURN ((LM_ERROR, + "be_visitor_sequence_serializer_op_cs::" + "visit_sequence - " + "Base type codegen failed\n"), + -1); + } + } + + *os << "}" << be_uidt_nl << be_nl + << "return 0;" << be_uidt_nl + << "}" << be_nl << be_nl; + + // --- operator>> --- + + // Set the sub state as generating code for the input operator. + this->ctx_->sub_state(TAO_CodeGen::TAO_CDR_INPUT); + + *os << "CORBA::Boolean operator>> (" << be_idt << be_idt_nl + << "TAO::DCPS::Serializer &"; + + if (! bt->is_local ()) + { + *os << "strm"; + } + + *os << "," << be_nl + << node->name () << " &"; + + if (! bt->is_local ()) + { + *os << "_tao_sequence"; + } + + *os << be_uidt_nl + << ")" << be_uidt_nl + << "{" << be_idt_nl; + + if (! bt->is_local ()) + { + // First retrieve the length and adjust the sequence length accordingly. + *os << "CORBA::ULong _tao_seq_len;" << be_nl << be_nl; + *os << "if (strm >> _tao_seq_len)" << be_idt_nl + << "{" << be_idt_nl; + + // Now check if the length does not exceed the maximum. We do this only + // for bounded sequences + AST_Expression *expr = node->max_size (); + + if (expr == 0 || (expr != 0 && expr->ev () == 0)) + { + ACE_ERROR_RETURN ((LM_ERROR, + "(%N:%l) be_visitor_sequence_serializer_op_cs::" + "visit_sequence - " + "bad sequence dimension\n"), + -1); + } + + if (expr->ev ()->et == AST_Expression::EV_ulong) + { + if (expr->ev ()->u.ulval > 0) + { + // We are dealing with a bounded sequence. Check if we are within + // bounds. + *os << "if (_tao_seq_len <= _tao_sequence.maximum ())" << be_idt_nl + << "{" << be_idt_nl; + } + } + else + { + ACE_ERROR_RETURN ((LM_ERROR, + "(%N:%l) be_visitor_sequence_serializer_op_cs::" + "visit_sequence - " + "bad sequence dimension value\n"), + -1); + } + + *os << "// Set the length of the sequence." << be_nl + << "_tao_sequence.length (_tao_seq_len);" << be_nl << be_nl; + + // Now we do a check for the sequence length to be non zero. + // If length is 0 we return true. + *os << "// If length is 0 we return true." << be_nl; + *os << "if (0 >= _tao_seq_len) " << be_idt_nl + << "{" << be_idt_nl; + *os << "return 1;" << be_uidt_nl + << "}" << be_uidt_nl << be_nl; + + *os << "// Retrieve all the elements." << be_nl; + + if (bt->node_type () == AST_Decl::NT_sequence) + { + this->visit_node (node); + } + else + { + if (bt->accept (this) == -1) + { + ACE_ERROR_RETURN ((LM_ERROR, + "be_visitor_sequence_serializer_op_cs::" + "visit_sequence - " + "Base type codegen failed\n"), + -1); + } + } + + if (expr->ev ()->u.ulval > 0) + { + // We are dealing with a bounded sequence. + *os << be_nl << "}" << be_uidt << be_uidt; + } + + *os << be_nl << "}" << be_uidt_nl << be_nl; + } + + *os << "return 0;" << be_uidt_nl + << "}"; + + *os << be_nl << be_nl + << "#endif /* _TAO_SERIALIZER_OP_" + << node->flat_name () << "_CPP_ */"; + + node->cli_stub_serializer_op_gen (1); + return 0; +} + +int +be_visitor_sequence_serializer_op_cs::visit_array (be_array *node) +{ + return this->visit_node (node); +} + +int +be_visitor_sequence_serializer_op_cs::visit_enum (be_enum *node) +{ + TAO_OutStream *os = this->ctx_->stream (); + + // We get here if the "type" of individual elements of the sequence is a + // primitive type. In this case, we treat the sequence as a single + // dimensional sequence (even of it was multi-dimensional), and pass + // the total length of the sequence as a cross product of the + // dimensions. + + be_sequence *sequence = this->ctx_->be_node_as_sequence (); + + if (!sequence) + { + ACE_ERROR_RETURN ((LM_ERROR, + "(%N:%l) be_visitor_sequence_serializer_op_cs::" + "visit_enum - " + "bad sequence node\n"), + -1); + } + + switch (this->ctx_->sub_state ()) + { + case TAO_CodeGen::TAO_IS_BOUNDED_SIZE: + *os << "ACE_UNUSED_ARG(_tao_sequence);" << be_nl; + if (sequence->unbounded ()) + *os << "return false; /* unbounded enum sequence */"; + else + *os << "return true; /* bounded enum sequence */"; + break; + case TAO_CodeGen::TAO_FIND_SIZE: + *os << "//enum types are fixed size so OK to call max_marshaled_size" + << be_nl; + case TAO_CodeGen::TAO_MAX_MARSHALED_SIZE: + *os << "//sequence of enum = ulong for length + ulong for enum * length" + << be_nl; + *os << "return _dcps_max_marshaled_size_ulong () + " + << "_dcps_max_marshaled_size_ulong () * " + << be_idt << be_idt_nl; + switch (this->ctx_->sub_state ()) + { + case TAO_CodeGen::TAO_FIND_SIZE: + *os << "_tao_sequence.length();" << be_uidt << be_uidt; + break; + case TAO_CodeGen::TAO_MAX_MARSHALED_SIZE: + *os << "_tao_sequence.maximum();" << be_uidt << be_uidt; + break; + default: + ACE_ERROR_RETURN ((LM_ERROR, + "(%N:%l) be_visitor_array_serializer_op_cs::" + "visit_enum - " + "bad sub_state for seq length\n"), + -1); + } + break; + default: + return this->visit_node (node); + } + return 0; +} + +int +be_visitor_sequence_serializer_op_cs::visit_interface (be_interface *node) +{ + return this->visit_node (node); +} + +int +be_visitor_sequence_serializer_op_cs::visit_interface_fwd (be_interface_fwd *node) +{ + return this->visit_node (node); +} + +int +be_visitor_sequence_serializer_op_cs::visit_component (be_component *node) +{ + return this->visit_node (node); +} + +int +be_visitor_sequence_serializer_op_cs::visit_component_fwd (be_component_fwd *node) +{ + return this->visit_node (node); +} + +int +be_visitor_sequence_serializer_op_cs::visit_home (be_home *node) +{ + return this->visit_node (node); +} + +int +be_visitor_sequence_serializer_op_cs::visit_valuetype (be_valuetype *node) +{ + return this->visit_node (node); +} + +int +be_visitor_sequence_serializer_op_cs::visit_valuetype_fwd (be_valuetype_fwd *node) +{ + return this->visit_node (node); +} + +int +be_visitor_sequence_serializer_op_cs::visit_eventtype (be_eventtype *node) +{ + return this->visit_node (node); +} + +int +be_visitor_sequence_serializer_op_cs::visit_eventtype_fwd (be_eventtype_fwd *node) +{ + return this->visit_node (node); +} + +int +be_visitor_sequence_serializer_op_cs::visit_predefined_type ( + be_predefined_type *node + ) +{ + TAO_OutStream *os = this->ctx_->stream (); + + switch (node->pt ()) + { + case AST_PredefinedType::PT_object: + case AST_PredefinedType::PT_value: + case AST_PredefinedType::PT_pseudo: + case AST_PredefinedType::PT_any: + return this->visit_node (node); + case AST_PredefinedType::PT_void: + ACE_ERROR_RETURN ((LM_ERROR, + "(%N:%l) be_visitor_sequence_serializer_op_cs::" + "visit_predefined_type - " + "Bad primitive type\n"), + -1); + default: + break; + }; + + // We get here if the "type" of individual elements of the sequence is a + // primitive type. In this case, we treat the sequence as a single + // dimensional sequence (even of it was multi-dimensional), and pass + // the total length of the sequence as a cross product of the + // dimensions. + + be_sequence *sequence = this->ctx_->be_node_as_sequence (); + + if (!sequence) + { + ACE_ERROR_RETURN ((LM_ERROR, + "(%N:%l) be_visitor_sequence_serializer_op_cs::" + "visit_predefined_type - " + "bad sequence node\n"), + -1); + } + + switch (this->ctx_->sub_state ()) + { + case TAO_CodeGen::TAO_IS_BOUNDED_SIZE: + *os << "ACE_UNUSED_ARG(_tao_sequence);" << be_nl; + if (sequence->unbounded ()) + *os << "return false; /* seq */"; + else + *os << "return true; /* seq */"; + break; + case TAO_CodeGen::TAO_FIND_SIZE: + *os << "//primitive types are fixed size so OK to call max_marshaled_size" + << be_nl; + case TAO_CodeGen::TAO_MAX_MARSHALED_SIZE: + switch (node->pt ()) + { + case AST_PredefinedType::PT_octet: + *os << "return _dcps_max_marshaled_size_ulong () + " + << "_dcps_max_marshaled_size_octet ()" + << be_idt << be_idt_nl; + break; + case AST_PredefinedType::PT_char: + *os << "return _dcps_max_marshaled_size_ulong () + " + << "_dcps_max_marshaled_size_char ()" + << be_idt << be_idt_nl; + break; + case AST_PredefinedType::PT_wchar: + *os << "return _dcps_max_marshaled_size_ulong () + " + << "_dcps_max_marshaled_size_wchar ()" + << be_idt << be_idt_nl; + break; + case AST_PredefinedType::PT_long: + case AST_PredefinedType::PT_ulong: + case AST_PredefinedType::PT_short: + case AST_PredefinedType::PT_ushort: + case AST_PredefinedType::PT_float: + case AST_PredefinedType::PT_double: + case AST_PredefinedType::PT_longlong: + case AST_PredefinedType::PT_ulonglong: + case AST_PredefinedType::PT_longdouble: + *os << "//sequence is of a fixed sized predefined type = " + << "sizeof(ULong) + type size * length" << be_nl; + *os << node->name () << " a_base_value;" << be_nl; + *os << "return _dcps_max_marshaled_size_ulong () + " + << "_dcps_max_marshaled_size (a_base_value)" + << be_idt << be_idt_nl; + break; + break; + case AST_PredefinedType::PT_boolean: + *os << "return _dcps_max_marshaled_size_ulong () + " + << "_dcps_max_marshaled_size_boolean ()" + << be_idt << be_idt_nl; + break; + default: + ACE_ERROR_RETURN ((LM_ERROR, + "(%N:%l) be_visitor_array_serializer_op_cs::" + "visit_predefined_type - " + "bad primitive type for _dcps_max_marshaled_size code gen\n"), + -1); + } + + switch (this->ctx_->sub_state ()) + { + case TAO_CodeGen::TAO_FIND_SIZE: + *os << " * _tao_sequence.length();" << be_uidt << be_uidt; + break; + case TAO_CodeGen::TAO_MAX_MARSHALED_SIZE: + *os << " * _tao_sequence.maximum();" << be_uidt << be_uidt; + break; + default: + ACE_ERROR_RETURN ((LM_ERROR, + "(%N:%l) be_visitor_array_serializer_op_cs::" + "visit_predefined_type - " + "bad sub_state for seq length\n"), + -1); + } + break; + case TAO_CodeGen::TAO_CDR_INPUT: + case TAO_CodeGen::TAO_CDR_OUTPUT: + { + /* + * Avoiding the work to make TAO::DCPS::Serializer handle the + * TAO_NO_COPY_OCTET_SEQUENCES optimization. + * TBD - support this optimization -- see corresponding CDR code. + */ + *os << "return strm."; + + // Based on our substate, we may be reading from a stream or writing into a + // stream/ + switch (this->ctx_->sub_state ()) + { + case TAO_CodeGen::TAO_CDR_INPUT: + *os << "read_"; + break; + case TAO_CodeGen::TAO_CDR_OUTPUT: + *os << "write_"; + break; + default: + ACE_ERROR_RETURN ((LM_ERROR, + "(%N:%l) be_visitor_sequence_serializer_op_cs::" + "visit_predefined_type - " + "bad sub state\n"), + -1); + } + + // Determine what kind of sequence are we reading/writing. + switch (node->pt ()) + { + case AST_PredefinedType::PT_long: + *os << "long_array"; + break; + case AST_PredefinedType::PT_ulong: + *os << "ulong_array"; + break; + case AST_PredefinedType::PT_short: + *os << "short_array"; + break; + case AST_PredefinedType::PT_ushort: + *os << "ushort_array"; + break; + case AST_PredefinedType::PT_octet: + *os << "octet_array"; + break; + case AST_PredefinedType::PT_char: + *os << "char_array"; + break; + case AST_PredefinedType::PT_wchar: + *os << "wchar_array"; + break; + case AST_PredefinedType::PT_float: + *os << "float_array"; + break; + case AST_PredefinedType::PT_double: + *os << "double_array"; + break; + case AST_PredefinedType::PT_longlong: + *os << "longlong_array"; + break; + case AST_PredefinedType::PT_ulonglong: + *os << "ulonglong_array"; + break; + case AST_PredefinedType::PT_longdouble: + *os << "longdouble_array"; + break; + case AST_PredefinedType::PT_boolean: + *os << "boolean_array"; + break; + default: + // error + ACE_ERROR_RETURN ((LM_ERROR, + "(%N:%l) be_visitor_sequence_serializer_op_cs::" + "visit_predefined_type - " + "bad primitive type for optimized code gen\n"), + -1); + } + + // Handle special case to avoid compiler errors. + switch (node->pt ()) + { + case AST_PredefinedType::PT_char: + switch (this->ctx_->sub_state ()) + { + case TAO_CodeGen::TAO_CDR_INPUT: + *os << " ((char *)_tao_sequence.get_buffer (), "; + break; + case TAO_CodeGen::TAO_CDR_OUTPUT: + *os << " ((const char *)_tao_sequence.get_buffer (), "; + break; + default: + // error + ACE_ERROR_RETURN ((LM_ERROR, + "(%N:%l) be_visitor_sequence_serializer_op_cs" + "::visit_predefined_type - " + "bad codegen substate\n"), + -1); + } + break; + default: + *os << " (_tao_sequence.get_buffer (), "; + break; + } + + *os << "_tao_sequence.length ());" << be_uidt_nl; + + } // end TAO_CDR_INPUT/OUTPUT case + break; + default: + ACE_ERROR_RETURN ((LM_ERROR, + "(%N:%l) be_visitor_sequence_serializer_op_cs::" + "visit_predefined_type - outter " + "bad sub state\n"), + -1); + } // end outter switch + + return 0; +} + +int +be_visitor_sequence_serializer_op_cs::visit_string (be_string *node) +{ + return this->visit_node (node); +} + +int +be_visitor_sequence_serializer_op_cs::visit_structure (be_structure *node) +{ + return this->visit_node (node); +} + +int +be_visitor_sequence_serializer_op_cs::visit_union (be_union *node) +{ + return this->visit_node (node); +} + +int +be_visitor_sequence_serializer_op_cs::visit_typedef (be_typedef *node) +{ + this->ctx_->alias (node); + be_type *bt = node->primitive_base_type (); + + if (!bt || (bt->accept (this) == -1)) + { + ACE_ERROR_RETURN ((LM_ERROR, + "(%N:%l) be_visitor_sequence_serializer_op_cs::" + "visit_typedef - " + "Bad primitive type\n"), + -1); + } + + this->ctx_->alias (0); + return 0; +} + +int +be_visitor_sequence_serializer_op_cs::visit_node (be_type *bt) +{ + TAO_OutStream *os = this->ctx_->stream (); + be_sequence *node = this->ctx_->be_node_as_sequence (); + + if (!node) + { + ACE_ERROR_RETURN ((LM_ERROR, + "(%N:%l) be_visitor_sequence_serializer_op_cs::" + "visit_node - " + "bad sequence node\n"), + -1); + } + + be_visitor_context ctx (*this->ctx_); + be_visitor_sequence_base visitor (&ctx); + + // We get here if the "type" of individual elements of the sequence is not a + // primitive type. In this case, we are left with no other alternative but + // to encode/decode element by element. + + AST_Expression *expr = node->max_size (); + + if (expr == 0 || (expr != 0 && expr->ev () == 0)) + { + ACE_ERROR_RETURN ((LM_ERROR, + "(%N:%l) be_visitor_sequence_serializer_op_cs::" + "visit_node - " + "bad sequence dimension\n"), + -1); + } + + AST_Decl::NodeType nt = bt->node_type (); + be_typedef *td = 0; + + if (nt == AST_Decl::NT_typedef) + { + td = be_typedef::narrow_from_decl (bt); + nt = td->base_node_type (); + } + + +switch (this->ctx_->sub_state ()) + { + case TAO_CodeGen::TAO_IS_BOUNDED_SIZE: + if (node->unbounded ()) + { + *os << "ACE_UNUSED_ARG(_tao_sequence);" << be_nl; + *os << "return false; /* unbounded sequence */"; + } + else + + switch (nt) + { + case AST_Decl::NT_enum: + *os << "ACE_UNUSED_ARG(_tao_sequence);" << be_nl; + *os << "return true; // bounded seqence of enums"; + break; + case AST_Decl::NT_union: + *os << "ACE_UNUSED_ARG(_tao_sequence);" << be_nl; + *os << "// Always return false for a union because " << be_nl + << "// _dcps_max_marshaled_size may produce an access violation." + << be_nl + << "return false; // seq of union " << bt->name () << be_uidt; + break; + case AST_Decl::NT_sequence: + case AST_Decl::NT_struct: + // its a type that should be defined in the generated code. + *os << "ACE_UNUSED_ARG(_tao_sequence);" << be_nl; + *os << bt->name () << " a_base_value;" << be_nl; + *os << "return _tao_is_bounded_size (a_base_value);"; + break; + case AST_Decl::NT_array: + *os << "ACE_UNUSED_ARG(_tao_sequence);" << be_nl; + *os << bt->name () << " a_base_value;" << be_nl; + *os << bt->name () << "_forany tmp(a_base_value);" << be_nl; + *os << "return _tao_is_bounded_size (tmp);" << be_uidt_nl; + break; + case AST_Decl::NT_string: + case AST_Decl::NT_wstring: + { + be_string *str = + be_string::narrow_from_decl ( + td == 0 ? bt : td->primitive_base_type () + ); + + if (!str) + { + ACE_ERROR_RETURN ((LM_ERROR, + "(%N:%l) be_visitor_sequence_serializer_op_cs::" + "visit_node - " + "bad string node\n"), + -1); + } + + *os << "ACE_UNUSED_ARG(_tao_sequence);" << be_nl; + if (str->max_size ()->ev ()->u.ulval == 0) + { + // Unbounded string + *os << "return false; /* bounded seq of unbounded strings */"; + } + else + { + *os << "return true; /* bounded seq of bounded strings */"; + } + } + break; + default: + ACE_ERROR_RETURN ((LM_ERROR, + "(%N:%l) be_visitor_sequence_serializer_op_cs::" + "visit_node - is_bounded_size - " + "unsupported sequence base type\n"), + -1); + break; + } + break; + case TAO_CodeGen::TAO_MAX_MARSHALED_SIZE: + switch (nt) + { + case AST_Decl::NT_enum: + *os << "// sequence of enums" << be_nl + << "return _dcps_max_marshaled_size_ulong () + " << be_idt_nl + << "_tao_sequence.maximum() * " << be_nl + << "_dcps_max_marshaled_size_ulong ();" << be_uidt; + break; + case AST_Decl::NT_union: + *os << "ACE_UNUSED_ARG(_tao_sequence);" << be_nl; + *os << "// do not try getting the _dcps_max_marshaled_size" << be_nl + << "// doing so may produce an access violation" << be_nl + << "return 100000; // seq of union " << bt->name () << be_uidt; + break; + case AST_Decl::NT_sequence: + case AST_Decl::NT_struct: + // its a type that should be defined in the generated code. + *os << bt->name () << " a_base_value;" << be_nl + << "return _dcps_max_marshaled_size_ulong () + " << be_idt_nl + << "_tao_sequence.maximum() * " << be_nl + << "_dcps_max_marshaled_size (a_base_value);" << be_uidt; + break; + case AST_Decl::NT_array: + *os << bt->name () << " a_base_value;" << be_nl; + *os << bt->name() << "_forany tmp(a_base_value);" << be_nl; + *os << "return _dcps_max_marshaled_size_ulong () + " << be_idt_nl + << "_tao_sequence.maximum() * " << be_nl; + *os << "_dcps_max_marshaled_size (tmp);" << be_uidt_nl; + + break; + case AST_Decl::NT_string: + case AST_Decl::NT_wstring: + { + be_string *str = + be_string::narrow_from_decl ( + td == 0 ? bt : td->primitive_base_type () + ); + + if (!str) + { + ACE_ERROR_RETURN ((LM_ERROR, + "(%N:%l) be_visitor_sequence_serializer_op_cs::" + "visit_node - " + "bad string node\n"), + -1); + } + + u_long max_size = str->max_size ()->ev ()->u.ulval; + if (max_size == 0) + *os << "// bounded seq of unbounded strings" << be_nl; + else + *os << "// bounded seq of bounded strings" << be_nl; + + char buff[15]; + ACE_OS::sprintf(buff, "%d", max_size); + *os << "return _dcps_max_marshaled_size_ulong () + " << be_nl + << " _tao_sequence.maximum() * "; + *os << "(_dcps_max_marshaled_size_ulong () + " << buff << ");"; + + } + break; + case AST_Decl::NT_interface: + *os << "//DCPS - Sequence of interfaces is not supported" << be_nl; + *os << "return 77777;" << be_nl; + break; + default: + ACE_ERROR_RETURN ((LM_ERROR, + "(%N:%l) be_visitor_sequence_serializer_op_cs::" + "visit_node - is_bounded_size - " + "unsupported sequence base type\n"), + -1); + break; + } + break; + case TAO_CodeGen::TAO_FIND_SIZE: + { + *os << "//iterate over the sequence to find the current size" << be_nl + << "size_t the_length = _dcps_max_marshaled_size_ulong ();" << be_nl + << "for (CORBA::ULong i = 0; i < _tao_sequence.length(); " + << "++i)" << be_idt_nl + << "{" << be_idt_nl; + + switch (nt) + { + case AST_Decl::NT_enum: + *os << "the_length += _dcps_max_marshaled_size_ulong (); // enum" << be_uidt_nl; + break; + case AST_Decl::NT_union: + case AST_Decl::NT_sequence: + case AST_Decl::NT_struct: + // its a type that should be defined in the generated code. + *os << "the_length += _dcps_find_size (_tao_sequence[i]);" << be_uidt_nl; + break; + case AST_Decl::NT_array: + if (bt->accept (&visitor) == -1) + { + ACE_ERROR_RETURN ((LM_ERROR, + "(%N:%l) be_visitor_sequence_serializer_op_cs::" + "visit_node - " + "base type visit failed\n"), + -1); + } + + *os << "_var tmp_var (" << be_idt << be_idt_nl; + + if (bt->accept (&visitor) == -1) + { + ACE_ERROR_RETURN ((LM_ERROR, + "(%N:%l) be_visitor_sequence_serializer_op_cs::" + "visit_node - " + "base type visit failed\n"), + -1); + } + + *os << "_dup (_tao_sequence[i])" << be_uidt_nl + << ");" << be_uidt_nl; + + if (bt->accept (&visitor) == -1) + { + ACE_ERROR_RETURN ((LM_ERROR, + "(%N:%l) be_visitor_sequence_serializer_op_cs::" + "visit_node - " + "base type visit failed\n"), + -1); + } + + *os << "_forany tmp (tmp_var.inout ());" << be_nl; + *os << "the_length += _dcps_find_size (tmp);" << be_uidt_nl; + + break; + case AST_Decl::NT_string: + case AST_Decl::NT_wstring: + *os << "the_length += _dcps_max_marshaled_size_ulong () + " + << "ACE_OS::strlen (_tao_sequence[i]);" << be_uidt_nl; + break; + case AST_Decl::NT_interface: + *os << "//DCPS - Sequence of interfaces is not supported" << be_nl; + break; + default: + ACE_ERROR_RETURN ((LM_ERROR, + "(%N:%l) be_visitor_sequence_serializer_op_cs::" + "visit_node - is_bounded_size - " + "unsupported sequence base type\n"), + -1); + break; + } + + + *os << "}" << be_uidt_nl + << "return the_length;"; + } + break; + case TAO_CodeGen::TAO_CDR_INPUT: + case TAO_CodeGen::TAO_CDR_OUTPUT: + { + // Initialize a boolean variable. + *os << "CORBA::Boolean _tao_marshal_flag = 1;" << be_nl << be_nl; + + + if (expr->ev ()->et == AST_Expression::EV_ulong) + { + *os << "for (CORBA::ULong i = 0; i < _tao_seq_len" + << " && _tao_marshal_flag; " + << "++i)" << be_idt_nl + << "{" << be_idt_nl; + } + else + { + ACE_ERROR_RETURN ((LM_ERROR, + "(%N:%l) be_visitor_sequence_serializer_op_cs::" + "visit_node - " + "bad sequence dimension value\n"), + -1); + } + + switch (this->ctx_->sub_state ()) + { + case TAO_CodeGen::TAO_CDR_INPUT: + switch (nt) + { + case AST_Decl::NT_array: + if (bt->accept (&visitor) == -1) + { + ACE_ERROR_RETURN ((LM_ERROR, + "(%N:%l) be_visitor_sequence_serializer_op_cs::" + "visit_node - " + "base type visit failed\n"), + -1); + } + + *os << "_forany tmp ("; + + if (bt->accept (&visitor) == -1) + { + ACE_ERROR_RETURN ((LM_ERROR, + "(%N:%l) be_visitor_sequence_serializer_op_cs::" + "visit_node - " + "base type visit failed\n"), + -1); + } + + *os << "_alloc ());" << be_nl; + *os << "_tao_marshal_flag = (strm >> tmp);" << be_nl; + + if (bt->accept (&visitor) == -1) + { + ACE_ERROR_RETURN ((LM_ERROR, + "(%N:%l) be_visitor_sequence_serializer_op_cs::" + "visit_node - " + "base type visit failed\n"), + -1); + } + + *os << "_copy (_tao_sequence[i], tmp.in ());" << be_nl; + + if (bt->accept (&visitor) == -1) + { + ACE_ERROR_RETURN ((LM_ERROR, + "(%N:%l) be_visitor_sequence_serializer_op_cs::" + "visit_node - " + "base type visit failed\n"), + -1); + } + + *os << "_free (tmp.inout ());" << be_uidt_nl; + + break; + case AST_Decl::NT_string: + case AST_Decl::NT_wstring: + { + be_string *str = + be_string::narrow_from_decl ( + td == 0 ? bt : td->primitive_base_type () + ); + + if (!str) + { + ACE_ERROR_RETURN ((LM_ERROR, + "(%N:%l) be_visitor_sequence_serializer_op_cs::" + "visit_node - " + "bad string node\n"), + -1); + } + + if (str->max_size ()->ev ()->u.ulval == 0) + { + // Unbounded. + *os << "_tao_marshal_flag = (strm >> _tao_sequence[i].out ());" + << be_uidt_nl; + } + else + { + if (str->width () == (long) sizeof (char)) + { + *os << "_tao_marshal_flag = (strm >> " + << "CORBA::Any::to_string (_tao_sequence[i].out (), "; + } + else + { + *os << "_tao_marshal_flag = (strm >> " + << "CORBA::Any::to_wstring (_tao_sequence[i].out (), "; + } + + *os << str->max_size ()->ev ()->u.ulval << "));" + << be_uidt_nl; + } + } + break; + case AST_Decl::NT_interface: + case AST_Decl::NT_interface_fwd: + case AST_Decl::NT_valuetype: + case AST_Decl::NT_valuetype_fwd: + *os << "//DCPS does not support interfaces and value types"; + + break; + case AST_Decl::NT_pre_defined: + { + // We need to separately handle this case of pseudo objects + // because they have a _var type. + be_predefined_type *pt = + be_predefined_type::narrow_from_decl ( + td == 0 ? bt : td->primitive_base_type () + ); + + if (!pt) + { + ACE_ERROR_RETURN ((LM_ERROR, + "(%N:%l) be_visitor_sequence_serializer_op_cs::" + "visit_node - " + "bad predefined type node\n"), + -1); + } + + switch (pt->pt ()) + { + case AST_PredefinedType::PT_pseudo: + case AST_PredefinedType::PT_object: + case AST_PredefinedType::PT_value: + *os << "_tao_marshal_flag = (strm >> _tao_sequence[i].out ());"; + break; + case AST_PredefinedType::PT_char: + *os << "_tao_marshal_flag =" << be_idt_nl + << "(strm >> CORBA::Any::to_char (_tao_sequence[i]));" + << be_uidt; + break; + case AST_PredefinedType::PT_wchar: + *os << "_tao_marshal_flag =" << be_idt_nl + << "(strm >> CORBA::Any::to_wchar (_tao_sequence[i]));" + << be_uidt; + break; + case AST_PredefinedType::PT_boolean: + *os << "_tao_marshal_flag =" << be_idt_nl + << "(strm >> CORBA::Any::to_boolean (_tao_sequence[i]));" + << be_uidt; + break; + case AST_PredefinedType::PT_octet: + *os << "_tao_marshal_flag =" << be_idt_nl + << "(strm >> CORBA::Any::to_octet (_tao_sequence[i]));" + << be_uidt; + break; + default: + *os << "_tao_marshal_flag = (strm >> _tao_sequence[i]);"; + break; + } + } + + break; + default: + *os << "_tao_marshal_flag = (strm >> _tao_sequence[i]);"; + + break; + } + + *os << be_uidt_nl + << "}"; + + break; + case TAO_CodeGen::TAO_CDR_OUTPUT: + switch (nt) + { + case AST_Decl::NT_array: + if (bt->accept (&visitor) == -1) + { + ACE_ERROR_RETURN ((LM_ERROR, + "(%N:%l) be_visitor_sequence_serializer_op_cs::" + "visit_node - " + "base type visit failed\n"), + -1); + } + + *os << "_var tmp_var (" << be_idt << be_idt_nl; + + if (bt->accept (&visitor) == -1) + { + ACE_ERROR_RETURN ((LM_ERROR, + "(%N:%l) be_visitor_sequence_serializer_op_cs::" + "visit_node - " + "base type visit failed\n"), + -1); + } + + *os << "_dup (_tao_sequence[i])" << be_uidt_nl + << ");" << be_uidt_nl; + + if (bt->accept (&visitor) == -1) + { + ACE_ERROR_RETURN ((LM_ERROR, + "(%N:%l) be_visitor_sequence_serializer_op_cs::" + "visit_node - " + "base type visit failed\n"), + -1); + } + + *os << "_forany tmp (tmp_var.inout ());" << be_nl; + *os << "_tao_marshal_flag = (strm << tmp);"; + + break; + case AST_Decl::NT_interface: + case AST_Decl::NT_interface_fwd: + *os << "//DCPS does not support interfaces and value types"; + + break; + case AST_Decl::NT_string: + case AST_Decl::NT_wstring: + case AST_Decl::NT_valuetype: + case AST_Decl::NT_valuetype_fwd: + *os << "_tao_marshal_flag = (strm << _tao_sequence[i].in ());"; + + break; + case AST_Decl::NT_pre_defined: + { + //SHH harris_s@ociweb.com - I am not sure you can every get here + // predefined types are handled by be_visitor_sequence_serializer_op_cs::visit_predefined_type + be_predefined_type *pt = + be_predefined_type::narrow_from_decl ( + td == 0 ? bt : td->primitive_base_type () + ); + + if (!pt) + { + ACE_ERROR_RETURN ((LM_ERROR, + "(%N:%l) be_visitor_sequence_serializer_op_cs::" + "visit_node - " + "bad predefined type node\n"), + -1); + } + + switch (pt->pt ()) + { + case AST_PredefinedType::PT_pseudo: + case AST_PredefinedType::PT_object: + case AST_PredefinedType::PT_value: + *os << "_tao_marshal_flag = (strm << _tao_sequence[i].in ());"; + break; + case AST_PredefinedType::PT_char: + *os << "_tao_marshal_flag =" << be_idt_nl + << "(strm << CORBA::Any::from_char (_tao_sequence[i]));" + << be_uidt; + break; + case AST_PredefinedType::PT_wchar: + *os << "_tao_marshal_flag =" << be_idt_nl + << "(strm << CORBA::Any::from_wchar (_tao_sequence[i]));" + << be_uidt; + break; + case AST_PredefinedType::PT_boolean: + *os << "_tao_marshal_flag =" << be_idt_nl + << "(strm << CORBA::Any::from_boolean (_tao_sequence[i]));" + << be_uidt; + break; + case AST_PredefinedType::PT_octet: + *os << "_tao_marshal_flag =" << be_idt_nl + << "(strm << CORBA::Any::from_octet (_tao_sequence[i]));" + << be_uidt; + break; + default: + *os << "_tao_marshal_flag = (strm << _tao_sequence[i]);"; + break; + } + } + + break; + default: + *os << "_tao_marshal_flag = (strm << _tao_sequence[i]);"; + + break; + } + + *os << be_uidt_nl + << "}"; + + break; + default: + ACE_ERROR_RETURN ((LM_ERROR, + "(%N:%l) be_visitor_sequence_serializer_op_cs::" + "visit_node - " + "bad sub state\n"), + -1); + } + + *os << be_uidt_nl << be_nl; + *os << "return _tao_marshal_flag;" << be_uidt_nl; + } + break; + default: + // Error. + ACE_ERROR_RETURN ((LM_ERROR, + "(%N:%l) be_visitor_sequence_serializer_op_cs::" + "visit_node - " + "bad sub state\n"), + -1); + break; +} //outer switch + + + return 0; +} diff --git a/TAO/TAO_IDL/be/be_visitor_structure/serializer_op_ch.cpp b/TAO/TAO_IDL/be/be_visitor_structure/serializer_op_ch.cpp new file mode 100644 index 00000000000..cda64a00df6 --- /dev/null +++ b/TAO/TAO_IDL/be/be_visitor_structure/serializer_op_ch.cpp @@ -0,0 +1,140 @@ +// +// $Id$ +// + +// ============================================================================ +// +// = LIBRARY +// TAO IDL +// +// = FILENAME +// serializer_op_ch.cpp +// +// = DESCRIPTION +// Visitor generating code for TAO::DCPS::Serializer operators for +// structures. This uses compiled marshaling. +// +// = AUTHOR +// Scott Harris based on code by Aniruddha Gokhale +// +// ============================================================================ + +ACE_RCSID (be_visitor_structure, + serializer_op_ch, + "$Id$") + +#include "global_extern.h" + +// *************************************************************************** +// Structure visitor for generating Serializer operator declarations in the client header +// *************************************************************************** + +be_visitor_structure_serializer_op_ch::be_visitor_structure_serializer_op_ch ( + be_visitor_context *ctx + ) + : be_visitor_structure (ctx) +{ +} + +be_visitor_structure_serializer_op_ch::~be_visitor_structure_serializer_op_ch (void) +{ +} + +int +be_visitor_structure_serializer_op_ch::visit_structure (be_structure *node) +{ + if (node->cli_hdr_serializer_op_gen () + || node->imported () + || node->is_local ()) + { + 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; + + IDL_GlobalData::DCPS_Data_Type_Info* info; + if (0 != (info = idl_global->is_dcps_type(node->name()))) + { + *os << be_global->stub_export_macro () + << " CORBA::Boolean _dcps_has_key(const " + << node->name() << "& val);" << be_nl; + + *os << "// This structure supports use of std::map with a key" << be_nl + << "// defined by one or more #pragma DCPS_DATA_KEY lines." << be_nl + << "struct " << be_global->stub_export_macro () << " " + << node->name()->last_component() << "KeyLessThan " << be_nl + << "{" << be_idt_nl + << "bool operator() (" << be_idt << be_idt_nl + << "const " << node->name() << "& v1," << be_nl + << "const " << node->name() << "& v2) const" << be_uidt << be_uidt_nl + << "{" << be_idt_nl; + + if (info->key_list_.is_empty()) + { + *os << "ACE_UNUSED_ARG(v1);" << be_nl; + *os << "ACE_UNUSED_ARG(v2);" << be_nl; + *os << "// if no DCPS_DATA_KEY values then return false" << be_nl + << "// to allow use of map with just one entry" << be_nl; + *os << "return false;" << be_nl; + } + else + { + *os << "return "; + IDL_GlobalData::DCPS_Data_Type_Info_Iter iter (info->key_list_); + + for (ACE_CString *kp = 0; + iter.next (kp) != 0; + ) + { + *os << "v1." << kp->c_str () << " < " << "v2." << kp->c_str (); + iter.advance (); + if (iter.done ()) + *os << ";" << be_uidt_nl; + else + *os << " || " << be_nl; + } + } + *os << "}" << be_uidt_nl + << "};" << be_nl << be_nl; + } + + //- _dcps_max_marshaled_size(type) method + *os << be_global->stub_export_macro () + << " size_t _dcps_max_marshaled_size (const " + << node->name() << "& _tao_aggregate);" << be_nl; + //- _tao_is_bounded_size(type) method + *os << be_global->stub_export_macro () + << " CORBA::Boolean _tao_is_bounded_size (const " + << node->name() << "& _tao_aggregate);" << be_nl; + //- _dcps_find_size(type) method + *os << be_global->stub_export_macro () + << " size_t _dcps_find_size (const " + << node->name() << "& _tao_aggregate);" << be_nl; + + *os << be_global->stub_export_macro () << " CORBA::Boolean" + << " operator<< (TAO::DCPS::Serializer &, const " << node->name () + << " &);" << be_nl; + *os << be_global->stub_export_macro () << " CORBA::Boolean" + << " operator>> (TAO::DCPS::Serializer &, " + << node->name () << " &);"; + + + // Set the substate as generating code for the types defined in our scope. + this->ctx_->sub_state(TAO_CodeGen::TAO_CDR_SCOPE); + + if (this->visit_scope (node) == -1) + { + ACE_ERROR_RETURN ((LM_ERROR, + "(%N:%l) be_visitor_structure_serializer_op_ch::" + "visit_structure - " + "codegen for scope failed\n"), + -1); + } + + + node->cli_hdr_serializer_op_gen (1); + return 0; +} diff --git a/TAO/TAO_IDL/be/be_visitor_structure/serializer_op_cs.cpp b/TAO/TAO_IDL/be/be_visitor_structure/serializer_op_cs.cpp new file mode 100644 index 00000000000..2b01e0f2b33 --- /dev/null +++ b/TAO/TAO_IDL/be/be_visitor_structure/serializer_op_cs.cpp @@ -0,0 +1,311 @@ +// +// $Id$ +// + +// ============================================================================ +// +// = LIBRARY +// TAO IDL +// +// = FILENAME +// serializer_op_cs.cpp +// +// = DESCRIPTION +// Visitor generating code for TAO::DCPS::Serializer operators for structures +// +// = AUTHOR +// Scott Harris based on code by Aniruddha Gokhale +// +// ============================================================================ + +ACE_RCSID (be_visitor_structure, + serializer_op_cs, + "$Id$") + +be_visitor_structure_serializer_op_cs::be_visitor_structure_serializer_op_cs ( + be_visitor_context *ctx + ) + : be_visitor_structure (ctx) +{ +} + +be_visitor_structure_serializer_op_cs::~be_visitor_structure_serializer_op_cs (void) +{ +} + +int +be_visitor_structure_serializer_op_cs::visit_structure (be_structure *node) +{ + if (node->cli_stub_serializer_op_gen () + || node->imported () + || node->is_local ()) + { + return 0; + } + + // Set the substate as generating code for the types defined in our scope. + this->ctx_->sub_state (TAO_CodeGen::TAO_CDR_SCOPE); + + if (this->visit_scope (node) == -1) + { + ACE_ERROR_RETURN ((LM_ERROR, + "(%N:%l) be_visitor_structure_serializer_op_cs::" + "visit_structure - " + "codegen for scope failed\n"), + -1); + } + + TAO_OutStream *os = this->ctx_->stream (); + + *os << be_nl << be_nl << "// TAO_IDL - Generated from" << be_nl + << "// " << __FILE__ << ":" << __LINE__ << be_nl << be_nl; + + IDL_GlobalData::DCPS_Data_Type_Info* info; + if (0 != (info = idl_global->is_dcps_type(node->name()))) + { + *os << "CORBA::Boolean _dcps_has_key(const " + << node->name() << "& ) { " << be_idt_nl; + if (info->key_list_.is_empty()) + *os << "return false;"; + else + *os << "return true;"; + *os << be_uidt_nl << "}" << be_nl; + } + + //- _dcps_max_marshaled_size(type) method + this->ctx_->sub_state (TAO_CodeGen::TAO_MAX_MARSHALED_SIZE); + *os << "size_t " + << "_dcps_max_marshaled_size(const " + << node->name() << "& _tao_aggregate)" << be_nl + << "{" << be_idt_nl + << "ACE_UNUSED_ARG(_tao_aggregate);" + << " // sometimes not used - avoid warning" << be_nl; + + { + be_visitor_context new_ctx (*this->ctx_); + be_visitor_serializer_op_field_decl field_decl (&new_ctx); + field_decl.visit_scope (node); +#ifdef DCPS_DEBUG_IDL + *os << "size_t result = 0;" << be_nl; +#else + *os << "return " << be_idt_nl; +#endif + + if (this->visit_scope (node) == -1) + { + ACE_ERROR_RETURN ((LM_ERROR, + "(%N:%l) be_visitor_structure_serializer_op_cs::" + "visit_structure - " + "codegen for scope failed\n"), + -1); + } + } + *os << ";" << be_uidt << be_uidt_nl; +#ifdef DCPS_DEBUG_IDL + *os << "return result;" << be_uidt_nl; +#endif + *os << "}" << be_nl << be_nl; + + + //- _tao_is_bounded_size(type) method + this->ctx_->sub_state (TAO_CodeGen::TAO_IS_BOUNDED_SIZE); + *os << "CORBA::Boolean _tao_is_bounded_size(const " + << node->name() << "& _tao_aggregate)" << be_nl + << "{" << be_idt_nl; + + { + be_visitor_context new_ctx (*this->ctx_); + be_visitor_serializer_op_field_decl field_decl (&new_ctx); + field_decl.visit_scope (node); + + *os << "ACE_UNUSED_ARG(_tao_aggregate);" + << " // often not used - avoid warning" << be_nl + << "return" << be_idt_nl; + + if (this->visit_scope (node) == -1) + { + ACE_ERROR_RETURN ((LM_ERROR, + "(%N:%l) be_visitor_structure_serializer_op_cs::" + "visit_structure - " + "codegen for scope failed\n"), + -1); + } + } + *os << ";" << be_uidt << be_uidt_nl + << "}" << be_nl << be_nl; + + //- _dcps_find_size(type) method -- like max_marshaled_size but use len - not max. + this->ctx_->sub_state (TAO_CodeGen::TAO_FIND_SIZE); + *os << "size_t " + << "_dcps_find_size(const " + << node->name() << "& _tao_aggregate)" << be_nl + << "{" << be_idt_nl + << "ACE_UNUSED_ARG(_tao_aggregate);" + << " // sometimes not used - avoid warning" << be_nl; + + { + be_visitor_context new_ctx (*this->ctx_); + be_visitor_serializer_op_field_decl field_decl (&new_ctx); + field_decl.visit_scope (node); +#ifdef DCPS_DEBUG_IDL + *os << "size_t result = 0;" << be_nl; +#else + *os << "return " << be_idt_nl; +#endif + + if (this->visit_scope (node) == -1) + { + ACE_ERROR_RETURN ((LM_ERROR, + "(%N:%l) be_visitor_structure_serializer_op_cs::" + "visit_structure - " + "codegen for scope failed\n"), + -1); + } + } + *os << ";" << be_uidt << be_uidt_nl; +#ifdef DCPS_DEBUG_IDL + *os << "return result;" << be_uidt_nl; +#endif + *os << "}" << be_nl << be_nl; + + + // Set the sub state as generating code for the output operator. + this->ctx_->sub_state (TAO_CodeGen::TAO_CDR_OUTPUT); + + *os << "CORBA::Boolean operator<< (" << be_idt << be_idt_nl + << "TAO::DCPS::Serializer &strm," << be_nl + << "const " << node->name () << " &_tao_aggregate" << be_uidt_nl + << ")" << be_uidt_nl + << "{" << be_idt_nl; + + be_visitor_context new_ctx (*this->ctx_); + be_visitor_serializer_op_field_decl field_decl (&new_ctx); + field_decl.visit_scope (node); + + *os << "return" << be_idt_nl; + + if (this->visit_scope (node) == -1) + { + ACE_ERROR_RETURN ((LM_ERROR, + "(%N:%l) be_visitor_structure_serializer_op_cs::" + "visit_structure - " + "codegen for scope failed\n"), + -1); + } + + *os << ";" << be_uidt << be_uidt_nl + << "}" << be_nl << be_nl; + + // Set the substate as generating code for the input operator. + this->ctx_->sub_state (TAO_CodeGen::TAO_CDR_INPUT); + + *os << "CORBA::Boolean operator>> (" << be_idt << be_idt_nl + << "TAO::DCPS::Serializer &"; + + if (! node->is_local ()) + { + *os << "strm"; + } + + *os << "," << be_nl + << node->name () << " &"; + + if (! node->is_local ()) + { + *os << "_tao_aggregate"; + } + + *os << be_uidt_nl + << ")" << be_uidt_nl + << "{" << be_idt_nl; + + if (node->is_local ()) + { + *os << "return 0;"; + } + else + { + new_ctx.sub_state (TAO_CodeGen::TAO_CDR_INPUT); + field_decl.visit_scope (node); + + *os << "return" << be_idt_nl; + + if (this->visit_scope (node) == -1) + { + ACE_ERROR_RETURN ((LM_ERROR, + "(%N:%l) be_visitor_structure_serializer_op_cs" + "::visit_structure - " + "codegen for scope failed\n"), + -1); + } + + *os << ";" << be_uidt << be_uidt; + } + + *os << be_uidt_nl << "}"; + + node->cli_stub_serializer_op_gen (I_TRUE); + return 0; +} + +int +be_visitor_structure_serializer_op_cs::post_process (be_decl *bd) +{ + TAO_OutStream *os = this->ctx_->stream (); + + switch (this->ctx_->sub_state ()) + { + case TAO_CodeGen::TAO_CDR_OUTPUT: + case TAO_CodeGen::TAO_CDR_INPUT: + case TAO_CodeGen::TAO_IS_BOUNDED_SIZE: + if (!this->last_node (bd)) + { + *os << " &&" << be_nl; + } + break; + case TAO_CodeGen::TAO_MAX_MARSHALED_SIZE: + case TAO_CodeGen::TAO_FIND_SIZE: +#ifdef DCPS_DEBUG_IDL + *os << ";" << be_nl; +#else + if (!this->last_node (bd)) + { + *os << " +" << be_nl; + } +#endif + break; + case TAO_CodeGen::TAO_CDR_SCOPE: + default: + break; + }; + + return 0; +} + +int +be_visitor_structure_serializer_op_cs::pre_process (be_decl *bd) +{ +#ifdef DCPS_DEBUG_IDL + TAO_OutStream *os = this->ctx_->stream (); +#else + ACE_UNUSED_ARG(bd); +#endif + + switch (this->ctx_->sub_state ()) + { + case TAO_CodeGen::TAO_IS_BOUNDED_SIZE: + break; + case TAO_CodeGen::TAO_MAX_MARSHALED_SIZE: + case TAO_CodeGen::TAO_FIND_SIZE: +#ifdef DCPS_DEBUG_IDL + *os << "result += "; +#endif + break; + case TAO_CodeGen::TAO_CDR_OUTPUT: + case TAO_CodeGen::TAO_CDR_INPUT: + case TAO_CodeGen::TAO_CDR_SCOPE: + default: + break; + }; + return 0; +} diff --git a/TAO/TAO_IDL/be/be_visitor_typedef/serializer_op_ch.cpp b/TAO/TAO_IDL/be/be_visitor_typedef/serializer_op_ch.cpp new file mode 100644 index 00000000000..6e74c3d5f19 --- /dev/null +++ b/TAO/TAO_IDL/be/be_visitor_typedef/serializer_op_ch.cpp @@ -0,0 +1,294 @@ +// +// $Id$ +// + +// ============================================================================ +// +// = LIBRARY +// TAO IDL +// +// = FILENAME +// serializer_op_ch.cpp +// +// = DESCRIPTION +// Visitor generating code for TAO::DCPS::Serializer operators +// of a Typedef node +// +// = AUTHOR +// Scott Harris based on code by Aniruddha Gokhale +// +// ============================================================================ + +ACE_RCSID (be_visitor_typedef, + serializer_op_ch, + "$Id$") + +// *************************************************************************** +// Typedef visitor for generating Serializer operator declarations in the client header +// *************************************************************************** + +be_visitor_typedef_serializer_op_ch::be_visitor_typedef_serializer_op_ch ( + be_visitor_context *ctx + ) + : be_visitor_typedef (ctx) +{ +} + +be_visitor_typedef_serializer_op_ch::~be_visitor_typedef_serializer_op_ch (void) +{ +} + +int +be_visitor_typedef_serializer_op_ch::visit_typedef (be_typedef *node) +{ + if (node->cli_hdr_serializer_op_gen () || node->imported ()) + { + return 0; + } + + TAO_OutStream *os = this->ctx_->stream (); + + // Generate the Serializer << and >> operator declarations. + os->indent (); + + // In general, we may have a chain of typedefs. i.e., + // typedef sequence X; + // typedef X Y; + // typedef Y Z; and so on + // The first time we will be in will be for node Z for which the code + // generation has to take place. However, it is not enough to just generate + // code that looks like - + // typedef Y Z; + // For different types (in this case we have a sequence), we will need + // typedefs for the _var and _out types for Z. If it had been an array, we + // will additionally have the _forcdr type as well as inlined *_alloc, _dup, + // and _free methods. + // + // Finally, we need to differentiate between the case where we were + // generating code for + // typedef sequence X; and + // typedef Y Z; where Y was somehow aliased to the sequence. In the former + // case, we will need to generate all the code for sequence or whatever + // the type maybe. In the latter, we just need typedefs for the type and all + // associated _var, _out, and other types. + + be_type *bt; // base type + + if (this->ctx_->tdef ()) + { + // The fact that we are here indicates that we were generating code for a + // typedef node whose base type also happens to be another typedef-ed + // (i.e. an alias) node for another (possibly alias) node. + + this->ctx_->alias (node); // save this alias + + // Grab the most primitive base type in the chain to avoid recusrsively + // going thru this visit method. + bt = node->primitive_base_type (); + + if (!bt) + { + ACE_ERROR_RETURN ((LM_ERROR, + "(%N:%l) be_visitor_typedef_serializer_op_ch::" + "visit_typedef - " + "bad primitive base type\n"), + -1); + } + + // Accept on this base type, but generate code for the typedef node. + if (bt->accept (this) == -1) + { + ACE_ERROR_RETURN ((LM_ERROR, + "(%N:%l) be_visitor_typedef_serializer_op_ch::" + "visit_typedef - " + "failed to accept visitor\n"), + -1); + } + + this->ctx_->alias (0); // reset + } + else + { + // The context has not stored cdr "tdef" node. So we must be in here for + // the first time. + this->ctx_->tdef (node); // save the typedef node + + // Grab the immediate base type node. + bt = be_type::narrow_from_decl (node->base_type ()); + + if (!bt) + { + ACE_ERROR_RETURN ((LM_ERROR, + "(%N:%l) be_visitor_typedef_serializer_op_ch::" + "visit_typedef - " + "bad base type\n"), + -1); + } + + // Accept on this base type, but generate code for the typedef node. + if (bt->accept (this) == -1) + { + ACE_ERROR_RETURN ((LM_ERROR, + "(%N:%l) be_visitor_typedef_serializer_op_ch::" + "visit_typedef - " + "failed to accept visitor\n"), + -1); + } + + this->ctx_->tdef (0); + } + + node->cli_hdr_serializer_op_gen (1); + return 0; +} + +int +be_visitor_typedef_serializer_op_ch::visit_array (be_array *node) +{ + be_type *bt; + + if (this->ctx_->alias ()) + { + bt = this->ctx_->alias (); + } + else + { + bt = node; + } + + if (!bt->imported () + && bt->node_type () == AST_Decl::NT_array) + { + // Let the base class visitor handle this case. + if (this->be_visitor_typedef::visit_array (node) == -1) + { + ACE_ERROR_RETURN ((LM_ERROR, + "(%N:%l) be_visitor_typedef_serializer_op_ch::" + "visit_array - " + "base class visitor failed \n"), + -1); + } + } + + return 0; +} + +int +be_visitor_typedef_serializer_op_ch::visit_enum (be_enum *node) +{ + be_type *bt; + + if (this->ctx_->alias ()) + { + bt = this->ctx_->alias (); + } + else + { + bt = node; + } + + if (bt->node_type () == AST_Decl::NT_enum) + { + // Let the base class visitor handle this case. + if (this->be_visitor_typedef::visit_enum (node) == -1) + { + ACE_ERROR_RETURN ((LM_ERROR, + "(%N:%l) be_visitor_typedef_serializer_op_ch::" + "visit_enum - " + "base class visitor failed \n"), + -1); + } + } + + return 0; +} + +int +be_visitor_typedef_serializer_op_ch::visit_sequence (be_sequence *node) +{ + be_type *bt; + + if (this->ctx_->alias ()) + { + bt = this->ctx_->alias (); + } + else + { + bt = node; + } + + if (bt->node_type () == AST_Decl::NT_sequence) + { + // Let the base class visitor handle this case. + if (this->be_visitor_typedef::visit_sequence (node) == -1) + { + ACE_ERROR_RETURN ((LM_ERROR, + "(%N:%l) be_visitor_typedef_serializer_op_ch::" + "visit_sequence - " + "base class visitor failed \n"), + -1); + } + } + + return 0; +} + +int +be_visitor_typedef_serializer_op_ch::visit_structure (be_structure *node) +{ + be_type *bt; + + if (this->ctx_->alias ()) + { + bt = this->ctx_->alias (); + } + else + { + bt = node; + } + + if (bt->node_type () == AST_Decl::NT_struct) + { + // Let the base class visitor handle this case. + if (this->be_visitor_typedef::visit_structure (node) == -1) + { + ACE_ERROR_RETURN ((LM_ERROR, + "(%N:%l) be_visitor_typedef_serializer_op_ch::" + "visit_structure - " + "base class visitor failed \n"), + -1); + } + } + + return 0; +} + +int +be_visitor_typedef_serializer_op_ch::visit_union (be_union *node) +{ + be_type *bt; + + if (this->ctx_->alias ()) + { + bt = this->ctx_->alias (); + } + else + { + bt = node; + } + + if (bt->node_type () == AST_Decl::NT_union) + { + // Let the base class visitor handle this case. + if (this->be_visitor_typedef::visit_union (node) == -1) + { + ACE_ERROR_RETURN ((LM_ERROR, + "(%N:%l) be_visitor_typedef_op_ch::" + "visit_union - " + "base class visitor failed \n"), + -1); + } + } + + return 0; +} diff --git a/TAO/TAO_IDL/be/be_visitor_typedef/serializer_op_cs.cpp b/TAO/TAO_IDL/be/be_visitor_typedef/serializer_op_cs.cpp new file mode 100644 index 00000000000..345dc70a1f3 --- /dev/null +++ b/TAO/TAO_IDL/be/be_visitor_typedef/serializer_op_cs.cpp @@ -0,0 +1,264 @@ +// +// $Id$ +// + +// ============================================================================ +// +// = LIBRARY +// TAO IDL +// +// = FILENAME +// serializer_op_cs.cpp +// +// = DESCRIPTION +// Visitor generating code for TAO::DCPS::Serializer operators +// in the client stubs +// +// = AUTHOR +// Scott Harris based on code by Aniruddha Gokhale +// +// ============================================================================ + +ACE_RCSID (be_visitor_typedef, + serializer_op_cs, + "$Id$") + +// *************************************************************************** +// Typedef visitor for generating Serializer operator declarations in the client +// stubs file +// *************************************************************************** + +be_visitor_typedef_serializer_op_cs::be_visitor_typedef_serializer_op_cs ( + be_visitor_context *ctx + ) + : be_visitor_typedef (ctx) +{ +} + +be_visitor_typedef_serializer_op_cs::~be_visitor_typedef_serializer_op_cs (void) +{ +} + +int +be_visitor_typedef_serializer_op_cs::visit_typedef (be_typedef *node) +{ + if (node->cli_stub_serializer_op_gen () || node->imported ()) + { + return 0; + } + + // In general, we may have a chain of typedefs. i.e., + // typedef sequence X; + // typedef X Y; + // typedef Y Z; and so on + // The first time we will be in will be for node Z for which the code + // generation has to take place. However, it is not enough to just generate + // code that looks like - + // typedef Y Z; + // For different types (in this case we have a sequence), we will need + // typedefs for the _var and _out types for Z. If it had been an array, we + // will additionally have the _forcdr type as well as inlined *_alloc, _dup, + // and _free methods. + // + // Finally, we need to differentiate between the case where we were + // generating code for + // typedef sequence X; and + // typedef Y Z; where Y was somehow aliased to the sequence. In the former + // case, we will need to generate all the code for sequence or whatever + // the type maybe. In the latter, we just need typedefs for the type and all + // associated _var, _out, and other types. + + be_type *bt; // base type + + if (this->ctx_->tdef ()) + { + // the fact that we are here indicates that we were generating code for a + // typedef node whose base type also happens to be another typedef-ed + // (i.e. an alias) node for another (possibly alias) node + + this->ctx_->alias (node); // save this alias + + // grab the most primitive base type in the chain to avoid recusrsively + // going thru this visit method + bt = node->primitive_base_type (); + + if (!bt) + { + ACE_ERROR_RETURN ((LM_ERROR, + "(%N:%l) be_visitor_typedef_serializer_op_cs::" + "visit_typedef - " + "bad primitive base type\n"), + -1); + } + + // accept on this base type, but generate code for the typedef node + if (bt->accept (this) == -1) + { + ACE_ERROR_RETURN ((LM_ERROR, + "(%N:%l) be_visitor_typedef_serializer_op_cs::" + "visit_typedef - " + "failed to accept visitor\n"), + -1); + } + + this->ctx_->alias (0); // reset + } + else + { + // the context has not stored cdr "tdef" node. So we must be in here for + // the first time + this->ctx_->tdef (node); // save the typedef node + + // grab the immediate base type node + bt = be_type::narrow_from_decl (node->base_type ()); + + if (!bt) + { + ACE_ERROR_RETURN ((LM_ERROR, + "(%N:%l) be_visitor_typedef_serializer_op_cs::" + "visit_typedef - " + "bad base type\n"), + -1); + } + + // accept on this base type, but generate code for the typedef node + if (bt->accept (this) == -1) + { + ACE_ERROR_RETURN ((LM_ERROR, + "(%N:%l) be_visitor_typedef_serializer_op_cs::" + "visit_typedef - " + "failed to accept visitor\n"), + -1); + } + + this->ctx_->tdef (0); // reset + } + + node->cli_stub_serializer_op_gen (1); + return 0; +} + +int +be_visitor_typedef_serializer_op_cs::visit_array (be_array *node) +{ + be_type *bt; + + if (this->ctx_->alias ()) // typedef of a typedef + { + bt = this->ctx_->alias (); + } + else + { + bt = node; + } + + if (!bt->imported () && + bt->node_type () == AST_Decl::NT_array) // direct typedef of a base node + // type + { + // let the base class visitor handle this case + if (this->be_visitor_typedef::visit_array (node) == -1) + { + ACE_ERROR_RETURN ((LM_ERROR, + "(%N:%l) be_visitor_typedef_serializer_op_cs::" + "visit_array - " + "base class visitor failed \n"), + -1); + } + } + + return 0; +} + +int +be_visitor_typedef_serializer_op_cs::visit_sequence (be_sequence *node) +{ + be_type *bt; + + if (this->ctx_->alias ()) // typedef of a typedef + { + bt = this->ctx_->alias (); + } + else + { + bt = node; + } + + if (bt->node_type () == AST_Decl::NT_sequence) // direct typedef of a base node + // type + { + // let the base class visitor handle this case + if (this->be_visitor_typedef::visit_sequence (node) == -1) + { + ACE_ERROR_RETURN ((LM_ERROR, + "(%N:%l) be_visitor_typedef_serializer_op_cs::" + "visit_sequence - " + "base class visitor failed \n"), + -1); + } + } + + return 0; +} + +int +be_visitor_typedef_serializer_op_cs::visit_structure (be_structure *node) +{ + be_type *bt; + + if (this->ctx_->alias ()) // typedef of a typedef + { + bt = this->ctx_->alias (); + } + else + { + bt = node; + } + + if (bt->node_type () == AST_Decl::NT_struct) // direct typedef of a base node + // type + { + // let the base class visitor handle this case + if (this->be_visitor_typedef::visit_structure (node) == -1) + { + ACE_ERROR_RETURN ((LM_ERROR, + "(%N:%l) be_visitor_typedef_serializer_op_cs::" + "visit_structure - " + "base class visitor failed \n"), + -1); + } + } + + return 0; +} + +int +be_visitor_typedef_serializer_op_cs::visit_union (be_union *node) +{ + be_type *bt; + + if (this->ctx_->alias ()) // typedef of a typedef + { + bt = this->ctx_->alias (); + } + else + { + bt = node; + } + + if (bt->node_type () == AST_Decl::NT_union) // direct typedef of a base node + // type + { + // let the base class visitor handle this case + if (this->be_visitor_typedef::visit_union (node) == -1) + { + ACE_ERROR_RETURN ((LM_ERROR, + "(%N:%l) be_visitor_typedef_serializer_op_cs::" + "visit_union - " + "base class visitor failed \n"), + -1); + } + } + + return 0; +} diff --git a/TAO/TAO_IDL/be/be_visitor_union/serializer_op_ch.cpp b/TAO/TAO_IDL/be/be_visitor_union/serializer_op_ch.cpp new file mode 100644 index 00000000000..aaf7e19ae48 --- /dev/null +++ b/TAO/TAO_IDL/be/be_visitor_union/serializer_op_ch.cpp @@ -0,0 +1,92 @@ +// +// $Id$ +// + +// ============================================================================ +// +// = LIBRARY +// TAO IDL +// +// = FILENAME +// serializer_op_ch.cpp +// +// = DESCRIPTION +// Visitor generating code for TAO::DCPS::Serializer operators for unions. +// This uses compiled marshaling. +// +// = AUTHOR +// Scott Harris based on code by Aniruddha Gokhale +// +// ============================================================================ + +ACE_RCSID (be_visitor_union, + serializer_op_ch, + "$Id$") + +// *************************************************************************** +// Union visitor for generating Serializer operator declarations in the client header +// *************************************************************************** + +be_visitor_union_serializer_op_ch::be_visitor_union_serializer_op_ch ( + be_visitor_context *ctx + ) + : be_visitor_union (ctx) +{ +} + +be_visitor_union_serializer_op_ch::~be_visitor_union_serializer_op_ch (void) +{ +} + +int +be_visitor_union_serializer_op_ch::visit_union (be_union *node) +{ + if (node->cli_hdr_serializer_op_gen () + || node->imported () + || node->is_local ()) + { + 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; + + //- _dcps_max_marshaled_size(type) method + *os << be_global->stub_export_macro () + << " size_t _dcps_max_marshaled_size (const " + << node->name() << "& _tao_union);" << be_nl; + //- _tao_is_bounded_size(type) method + *os << be_global->stub_export_macro () + << " CORBA::Boolean _tao_is_bounded_size (const " + << node->name() << "& _tao_union);" << be_nl; + //- _dcps_find_size(type) method + *os << be_global->stub_export_macro () + << " size_t _dcps_find_size (const " + << node->name() << "& _tao_union);" << be_nl; + + + *os << be_global->stub_export_macro () << " CORBA::Boolean" + << " operator<< (TAO::DCPS::Serializer &, const " << node->name () + << " &);" << be_nl; + *os << be_global->stub_export_macro () << " CORBA::Boolean" + << " operator>> (TAO::DCPS::Serializer &, " + << node->name () << " &);"; + + + // Set the substate as generating code for the types defined in our scope. + this->ctx_->sub_state (TAO_CodeGen::TAO_CDR_SCOPE); + + if (this->visit_scope (node) == -1) + { + ACE_ERROR_RETURN ((LM_ERROR, + "(%N:%l) be_visitor_union_serializer_op_ch::" + "visit_union - " + "codegen for scope failed\n"), + -1); + } + + node->cli_hdr_serializer_op_gen (1); + return 0; +} diff --git a/TAO/TAO_IDL/be/be_visitor_union/serializer_op_cs.cpp b/TAO/TAO_IDL/be/be_visitor_union/serializer_op_cs.cpp new file mode 100644 index 00000000000..6fd6c316b41 --- /dev/null +++ b/TAO/TAO_IDL/be/be_visitor_union/serializer_op_cs.cpp @@ -0,0 +1,468 @@ +// +// $Id$ +// + +// ============================================================================ +// +// = LIBRARY +// TAO IDL +// +// = FILENAME +// serializer_op_cs.cpp +// +// = DESCRIPTION +// Visitor generating code for TAO::DCPS::Serializer operators for unions +// +// = AUTHOR +// Scott Harris based on code by Aniruddha Gokhale +// +// ============================================================================ + +ACE_RCSID (be_visitor_union, + serializer_op_cs, + "$Id$") + +// *************************************************************************** +// Union visitor for generating Serializer operator declarations in the client +// stubs file +// *************************************************************************** + +be_visitor_union_serializer_op_cs::be_visitor_union_serializer_op_cs ( + be_visitor_context *ctx + ) + : be_visitor_union (ctx) +{ +} + +be_visitor_union_serializer_op_cs::~be_visitor_union_serializer_op_cs (void) +{ +} + +int +be_visitor_union_serializer_op_cs::visit_union (be_union *node) +{ + // already generated and/or we are imported. Don't do anything. + if (node->cli_stub_serializer_op_gen () + || node->imported () + || node->is_local ()) + { + return 0; + } + + // Set the substate as generating code for the types defined in our scope + this->ctx_->sub_state (TAO_CodeGen::TAO_CDR_SCOPE); + + if (this->visit_scope (node) == -1) + { + ACE_ERROR_RETURN ((LM_ERROR, + "(%N:%l) be_visitor_union_serializer_op_cs" + "::visit_union - " + "codegen for scope failed\n"), + -1); + } + + TAO_OutStream *os = this->ctx_->stream (); + + *os << be_nl << be_nl << "// TAO_IDL - Generated from" << be_nl + << "// " << __FILE__ << ":" << __LINE__ << be_nl << be_nl; + + //--------------------------------------------------------------- + // Set the sub state as generating code for _dcps_max_marshaled_size. + this->ctx_->sub_state(TAO_CodeGen::TAO_MAX_MARSHALED_SIZE); + + *os << "size_t _dcps_max_marshaled_size (" << be_idt << be_idt_nl + << "const " << node->name () << " &" << be_uidt_nl + << ")" << be_uidt_nl + << "{" << be_idt_nl + ; + *os << "// do not try getting the _dcps_max_marshaled_size" << be_nl + << "// doing so may produce an access violation" << be_nl + << "return 100000;" << be_uidt_nl + << "}" << be_nl << be_nl; + +/* + << "size_t max_size = 0;" << be_nl << be_nl; + + *os << "// find the maximum field size." << be_nl; + if (this->visit_scope (node) == -1) + { + ACE_ERROR_RETURN ((LM_ERROR, + "(%N:%l) be_visitor_union_serializer_op_cs::" + "visit_union - " + "codegen for scope failed\n"), + -1); + } + + *os << be_nl << "// now add in the size of the discriminant" << be_nl; + switch (node->udisc_type ()) + { + case AST_Expression::EV_bool: + *os << "max_size += _dcps_max_marshaled_size (" + << "CORBA::Any::from_boolean (_tao_union._d ()));" << be_nl; + break; + case AST_Expression::EV_char: + *os << "max_size += _dcps_max_marshaled_size (" + << "CORBA::Any::from_char (_tao_union._d ()));" << be_nl; + + break; + case AST_Expression::EV_wchar: + *os << "max_size += _dcps_max_marshaled_size (" + << "CORBA::Any::from_wchar (_tao_union._d ()));" << be_nl; + + break; + default: + // no need to cast the other dicriminant types + *os << "max_size += _dcps_max_marshaled_size (" + << "_tao_union._d ());" << be_nl; + + break; + } + + *os << be_nl + << "return max_size;" << be_uidt_nl + << "}" << be_nl << be_nl; +*/ + + //--------------------------------------------------------------- + // Set the sub state as generating code for _tao_is_bounded_size. + this->ctx_->sub_state(TAO_CodeGen::TAO_IS_BOUNDED_SIZE); + *os << "CORBA::Boolean _tao_is_bounded_size (" << be_idt << be_idt_nl + << "const " << node->name () << " &" << be_uidt_nl + << ")" << be_uidt_nl + << "{" << be_idt_nl + ; + *os << "// Always return false for a union because " << be_nl + << "// _dcps_max_marshaled_size may produce an access violation." + << be_nl + << "return false;" << be_uidt_nl + << "}" << be_nl << be_nl; +/* + << "CORBA::Boolean is_bounded = true;" + << " // all discrimenent types are bounded" << be_nl << be_nl; + + *os << "// bounded if all branches are bounded." << be_nl; + if (this->visit_scope (node) == -1) + { + ACE_ERROR_RETURN ((LM_ERROR, + "(%N:%l) be_visitor_union_serializer_op_cs::" + "visit_union - " + "codegen for scope failed\n"), + -1); + } + + *os << be_nl + << "return is_bounded;" << be_uidt_nl + << "}" << be_nl << be_nl; +*/ + + //--------------------------------------------------------------- + // Set the sub state as generating code for _dcps_find_size. + this->ctx_->sub_state(TAO_CodeGen::TAO_FIND_SIZE); + *os << be_global->stub_export_macro () + << " size_t _dcps_find_size (const " + << node->name() << "& _tao_union);" << be_nl; + + *os << "size_t _dcps_find_size (" << be_idt << be_idt_nl + << "const " << node->name () << " &_tao_union" << be_uidt_nl + << ")" << be_uidt_nl + << "{" << be_idt_nl + << "// all union discriminents are fixed size" + << "so OK to use _dcps_max_marshaled_size" << be_nl + << "size_t result = "; + + switch (node->udisc_type ()) + { + case AST_Expression::EV_bool: + *os << "_dcps_max_marshaled_size (CORBA::Any::from_boolean (_tao_union._d ()));" << be_nl; + break; + case AST_Expression::EV_char: + *os << "_dcps_max_marshaled_size (CORBA::Any::from_char (_tao_union._d ()));" << be_nl; + break; + case AST_Expression::EV_wchar: + *os << "_dcps_max_marshaled_size (CORBA::Any::from_wchar (_tao_union._d ()));" << be_nl; + break; + default: + *os << "_dcps_max_marshaled_size (_tao_union._d ());" << be_nl; + break; + } + + *os << be_nl + << "switch (_tao_union._d ())" << be_nl + << "{" << be_idt; + + if (this->visit_scope (node) == -1) + { + ACE_ERROR_RETURN ((LM_ERROR, + "(%N:%l) be_visitor_union_serializer_op_cs::" + "visit_union - " + "codegen for scope failed\n"), + -1); + } + + // If there is no explicit default case, but there + // is an implicit one, and the discriminant is an enum, + // we need this to avert warnings in some compilers that + // not all case values are included. If there is no + // implicit default case, or the discriminator is not + // an enum, this does no harm. + if (node->gen_empty_default_label ()) + { + *os << be_nl << "default:" << be_idt_nl; + *os << "break;"<< be_uidt; + } + + *os << be_uidt << be_uidt_nl << "}" << be_nl << be_nl + << "return result;" << be_uidt_nl + << "}" << be_nl << be_nl; + + //--------------------------------------------------------------- + // Set the sub state as generating code for the output operator. + this->ctx_->sub_state(TAO_CodeGen::TAO_CDR_OUTPUT); + + *os << "CORBA::Boolean operator<< (" << be_idt << be_idt_nl + << "TAO::DCPS::Serializer &strm," << be_nl + << "const " << node->name () << " &_tao_union" << be_uidt_nl + << ")" << be_uidt_nl + << "{" << be_idt_nl; + + switch (node->udisc_type ()) + { + case AST_Expression::EV_bool: + *os << "CORBA::Any::from_boolean tmp (_tao_union._d ());" << be_nl + << "if ( !(strm << tmp) )" << be_idt_nl; + + break; + case AST_Expression::EV_char: + *os << "CORBA::Any::from_char tmp (_tao_union._d ());" << be_nl + << "if ( !(strm << tmp) )" << be_idt_nl; + + break; + case AST_Expression::EV_wchar: + *os << "CORBA::Any::from_wchar tmp (_tao_union._d ());" << be_nl + << "if ( !(strm << tmp) )" << be_idt_nl; + + break; + default: + *os << "if ( !(strm << _tao_union._d ()) )" << be_idt_nl; + + break; + } + + *os << "{" << be_idt_nl + << "return 0;" << be_uidt_nl + << "}" << be_uidt_nl << be_nl + << "CORBA::Boolean result = 1;" << be_nl << be_nl + << "switch (_tao_union._d ())" << be_nl + << "{" << be_idt; + + if (this->visit_scope (node) == -1) + { + ACE_ERROR_RETURN ((LM_ERROR, + "(%N:%l) be_visitor_union_serializer_op_cs::" + "visit_union - " + "codegen for scope failed\n"), + -1); + } + + // If there is no explicit default case, but there + // is an implicit one, and the discriminant is an enum, + // we need this to avert warnings in some compilers that + // not all case values are included. If there is no + // implicit default case, or the discriminator is not + // an enum, this does no harm. + if (node->gen_empty_default_label ()) + { + *os << be_nl << "default:" << be_idt_nl; + *os << "break;"<< be_uidt; + } + + *os << be_uidt_nl << "}" << be_nl << be_nl + << "return result;" << be_uidt_nl + << "}" << be_nl << be_nl; + + //--------------------------------------------------------------- + // Set the substate as generating code for the input operator. + this->ctx_->sub_state(TAO_CodeGen::TAO_CDR_INPUT); + *os << "CORBA::Boolean operator>> (" << be_idt << be_idt_nl + << "TAO::DCPS::Serializer &strm," << be_nl + << node->name () << " &_tao_union" << be_uidt_nl + << ")" << be_uidt_nl + << "{" << be_idt_nl; + + be_type* disc_type = + be_type::narrow_from_decl (node->disc_type ()); + + // Generate a temporary to store the discriminant + *os << disc_type->full_name () + << " " << "_tao_discriminant;" << be_nl; + + switch (node->udisc_type ()) + { + case AST_Expression::EV_bool: + *os << "CORBA::Any::to_boolean tmp (_tao_discriminant);" << be_nl + << "if ( !(strm >> tmp) )" << be_idt_nl; + + break; + case AST_Expression::EV_char: + *os << "CORBA::Any::to_char tmp (_tao_discriminant);" << be_nl + << "if ( !(strm >> tmp) )" << be_idt_nl; + + break; + case AST_Expression::EV_wchar: + *os << "CORBA::Any::to_wchar tmp (_tao_discriminant);" << be_nl + << "if ( !(strm >> tmp) )" << be_idt_nl; + + break; + default: + *os << "if ( !(strm >> _tao_discriminant) )" << be_idt_nl; + + break; + } + + *os << "{" << be_idt_nl + << "return 0;" << be_uidt_nl + << "}" << be_uidt_nl << be_nl + << "CORBA::Boolean result = 1;" << be_nl << be_nl + << "switch (_tao_discriminant)" << be_nl + << "{" << be_idt; + + if (this->visit_scope (node) == -1) + { + ACE_ERROR_RETURN ((LM_ERROR, + "(%N:%l) be_visitor_union_serializer_op_cs::" + "visit_union - " + "codegen for scope failed\n"), + -1); + } + + // If there is no explicit default case, but there + // is an implicit one, and the discriminant is an enum, + // we need this to avert warnings in some compilers that + // not all case values are included. If there is no + // implicit default case, or the discriminator is not + // an enum, this does no harm. + if (node->gen_empty_default_label ()) + { + *os << be_nl; + *os << "default:" << be_idt_nl; + *os << "_tao_union._d (_tao_discriminant);" << be_nl; + *os << "break;" << be_uidt; + } + + *os << be_uidt_nl + << "}" << be_nl << be_nl + << "return result;" << be_uidt_nl + << "}"; + + node->cli_stub_serializer_op_gen (1); + return 0; +} + +int +be_visitor_union_serializer_op_cs::pre_process (be_decl *bd) +{ + switch (this->ctx_->sub_state ()) + { + case TAO_CodeGen::TAO_CDR_SCOPE: + case TAO_CodeGen::TAO_MAX_MARSHALED_SIZE: + case TAO_CodeGen::TAO_IS_BOUNDED_SIZE: + return 0; + break; + + case TAO_CodeGen::TAO_FIND_SIZE: + case TAO_CodeGen::TAO_CDR_OUTPUT: + case TAO_CodeGen::TAO_CDR_INPUT: + { + // Enum val nodes are added just to help check reference + // clashes, since an enum declared in our scope is not itself + // a scope. + if (bd->node_type () == AST_Decl::NT_enum_val) + { + return 0; + } + + TAO_OutStream *os = this->ctx_->stream (); + + be_union_branch* b = + be_union_branch::narrow_from_decl (bd); + + *os << be_nl; + + for (unsigned long i = 0; i < b->label_list_length (); ++i) + { + // check if we are printing the default case + if (b->label (i)->label_kind () == AST_UnionLabel::UL_default) + { + *os << "default:"; + } + else + { + *os << "case "; + + b->gen_label_value (os, i); + + *os << ":"; + } + + if (i == (b->label_list_length () - 1)) + { + *os << be_idt_nl; + } + else + { + *os << be_nl; + } + } + + *os << "{" << be_idt_nl; + } + break; + default: + ACE_ERROR_RETURN ((LM_ERROR, + "(%N:%l) be_visitor_union_serializer_op_cs::" + "pre_process - " + "bad sub_state.\n"), + -1); + } + + return 0; +} + +int +be_visitor_union_serializer_op_cs::post_process (be_decl *bd) +{ + switch (this->ctx_->sub_state ()) + { + case TAO_CodeGen::TAO_CDR_SCOPE: + case TAO_CodeGen::TAO_MAX_MARSHALED_SIZE: + case TAO_CodeGen::TAO_IS_BOUNDED_SIZE: + return 0; + break; + + case TAO_CodeGen::TAO_FIND_SIZE: + case TAO_CodeGen::TAO_CDR_OUTPUT: + case TAO_CodeGen::TAO_CDR_INPUT: + { + + if (bd->node_type () == AST_Decl::NT_enum_val) + { + return 0; + } + + TAO_OutStream *os = this->ctx_->stream (); + + *os << be_uidt_nl << "}" << be_nl + << "break;" << be_uidt; + + } + break; + default: + ACE_ERROR_RETURN ((LM_ERROR, + "(%N:%l) be_visitor_union_serializer_op_cs::" + "pre_process - " + "bad sub_state.\n"), + -1); + } + + return 0; +} diff --git a/TAO/TAO_IDL/be/be_visitor_union_branch/serializer_op_ch.cpp b/TAO/TAO_IDL/be/be_visitor_union_branch/serializer_op_ch.cpp new file mode 100644 index 00000000000..5369b1d1d8a --- /dev/null +++ b/TAO/TAO_IDL/be/be_visitor_union_branch/serializer_op_ch.cpp @@ -0,0 +1,215 @@ + +// +// $Id$ +// + +// ============================================================================ +// +// = LIBRARY +// TAO IDL +// +// = FILENAME +// serializer_op_ch.cpp +// +// = DESCRIPTION +// Visitor generating Serializer operator declarator for union_branch +// in the client header +// +// = AUTHOR +// Scott Harris based on code by Aniruddha Gokhale +// +// ============================================================================ + +ACE_RCSID (be_visitor_union_branch, + serializer_op_ch, + "$Id$") + +// ********************************************** +// Visitor for union_branch in the client header file. +// ********************************************** + +be_visitor_union_branch_serializer_op_ch::be_visitor_union_branch_serializer_op_ch ( + be_visitor_context *ctx + ) + : be_visitor_decl (ctx) +{ +} + +be_visitor_union_branch_serializer_op_ch::~be_visitor_union_branch_serializer_op_ch (void) +{ +} + +int +be_visitor_union_branch_serializer_op_ch::visit_union_branch (be_union_branch *node) +{ + be_type *bt = be_type::narrow_from_decl (node->field_type ()); + + if (!bt) + { + ACE_ERROR_RETURN ((LM_ERROR, + "(%N:%l) be_visitor_union_branch_serializer_op_ch::" + "visit_union_branch - " + "Bad union_branch type\n"), + -1); + } + + this->ctx_->node (node); + + if (bt->accept (this) == -1) + { + ACE_ERROR_RETURN ((LM_ERROR, + "(%N:%l) be_visitor_union_branch_serializer_op_ch::" + "visit_union_branch - " + "codegen for union_branch type failed\n"), + -1); + } + + return 0; +} + +// Visit operations on all possible data types that a union_branch can be. + +int +be_visitor_union_branch_serializer_op_ch::visit_array (be_array *node) +{ + // If not a typedef and we are defined in the use scope, we must be defined. + + if (!this->ctx_->alias () + && node->is_child (this->ctx_->scope ())) + { + // This is the case for anonymous arrays. + + be_visitor_context ctx (*this->ctx_); + ctx.node (node); + + be_visitor_array_serializer_op_ch visitor (&ctx); + + if (node->accept (&visitor) == -1) + { + ACE_ERROR_RETURN ((LM_ERROR, + "(%N:%l) be_visitor_union_branch_serializer_op_ch::" + "visit_array - " + "codegen failed\n"), + -1); + } + } + + return 0; +} + +int +be_visitor_union_branch_serializer_op_ch::visit_enum (be_enum *node) +{ + // If not a typedef and we are defined in the use scope, we must be defined. + if (!this->ctx_->alias () + && node->is_child (this->ctx_->scope ())) + { + be_visitor_context ctx (*this->ctx_); + ctx.node (node); + + be_visitor_enum_serializer_op_ch visitor (&ctx); + + if (node->accept (&visitor) == -1) + { + ACE_ERROR_RETURN ((LM_ERROR, + "(%N:%l) be_visitor_union_branch_serializer_op_ch::" + "visit_enum - " + "codegen failed\n"), + -1); + } + } + + return 0; +} + +int +be_visitor_union_branch_serializer_op_ch::visit_sequence (be_sequence *node) +{ + // If not a typedef and we are defined in the use scope, we must be defined. + if (!this->ctx_->alias () + && node->is_child (this->ctx_->scope ())) + { + be_visitor_context ctx (*this->ctx_); + ctx.node (node); + be_visitor_sequence_serializer_op_ch visitor (&ctx); + + if (node->accept (&visitor) == -1) + { + ACE_ERROR_RETURN ((LM_ERROR, + "(%N:%l) be_visitor_union_branch_serializer_op_ch::" + "visit_sequence - " + "codegen failed\n"), + -1); + } + } + + return 0; +} + +int +be_visitor_union_branch_serializer_op_ch::visit_structure (be_structure *node) +{ + // If not a typedef and we are defined in the use scope, we must be defined. + if (!this->ctx_->alias () + && node->is_child (this->ctx_->scope ())) + { + be_visitor_context ctx (*this->ctx_); + ctx.node (node); + be_visitor_structure_serializer_op_ch visitor (&ctx); + + if (node->accept (&visitor) == -1) + { + ACE_ERROR_RETURN ((LM_ERROR, + "(%N:%l) be_visitor_union_branch_serializer_op_ch::" + "visit_struct - " + "codegen failed\n"), + -1); + } + } + + return 0; +} + +int +be_visitor_union_branch_serializer_op_ch::visit_typedef (be_typedef *node) +{ + this->ctx_->alias (node); + + be_type *bt = node->primitive_base_type (); + + if (!bt || (bt->accept (this) == -1)) + { + ACE_ERROR_RETURN ((LM_ERROR, + "(%N:%l) be_visitor_union_branch_serializer_op_ch::" + "visit_typedef - " + "Bad primitive type\n"), + -1); + } + + this->ctx_->alias (0); + return 0; +} + +int +be_visitor_union_branch_serializer_op_ch::visit_union (be_union *node) +{ + // If not a typedef and we are defined in the use scope, we must be defined. + if (!this->ctx_->alias () + && node->is_child (this->ctx_->scope ())) + { + be_visitor_context ctx (*this->ctx_); + ctx.node (node); + be_visitor_union_serializer_op_ch visitor (&ctx); + + if (node->accept (&visitor) == -1) + { + ACE_ERROR_RETURN ((LM_ERROR, + "(%N:%l) be_visitor_union_branch_serializer_op_ch::" + "visit_enum - " + "codegen failed\n"), + -1); + } + } + + return 0; +} diff --git a/TAO/TAO_IDL/be/be_visitor_union_branch/serializer_op_cs.cpp b/TAO/TAO_IDL/be/be_visitor_union_branch/serializer_op_cs.cpp new file mode 100644 index 00000000000..85f1b9be6b9 --- /dev/null +++ b/TAO/TAO_IDL/be/be_visitor_union_branch/serializer_op_cs.cpp @@ -0,0 +1,1319 @@ +// +// $Id$ +// + +// ============================================================================ +// +// = LIBRARY +// TAO IDL +// +// = FILENAME +// union_branch/serializer_op_cs.cpp +// +// = DESCRIPTION +// Visitor generating code for Union_Branch in the client stubs file. +// +// = AUTHOR +// Scott Harris based on code by Aniruddha Gokhale +// +// ============================================================================ + +ACE_RCSID (be_visitor_union_branch, + serializer_op_cs, + "$Id$") + +// ********************************************** +// Visitor for union_branch in the client stubs file. +// ********************************************** + +be_visitor_union_branch_serializer_op_cs::be_visitor_union_branch_serializer_op_cs ( + be_visitor_context *ctx + ) + : be_visitor_decl (ctx) +{ +} + +be_visitor_union_branch_serializer_op_cs::~be_visitor_union_branch_serializer_op_cs (void) +{ +} + +int +be_visitor_union_branch_serializer_op_cs::visit_union_branch (be_union_branch *node) +{ + be_type *bt = be_type::narrow_from_decl (node->field_type ()); + + if (!bt) + { + ACE_ERROR_RETURN ((LM_ERROR, + "(%N:%l) be_visitor_union_branch_serializer_op_cs::" + "visit_union_branch - " + "Bad union_branch type\n"), + -1); + } + + this->ctx_->node (node); + + if (bt->accept (this) == -1) + { + ACE_ERROR_RETURN ((LM_ERROR, + "(%N:%l) be_visitor_union_branch_serializer_op_cs::" + "visit_union_branch - " + "codegen for union_branch type failed\n"), + -1); + } + + return 0; +} + +int +be_visitor_union_branch_serializer_op_cs::visit_array (be_array *node) +{ + // If not a typedef and we are defined in the use scope, we must be defined. + if (!this->ctx_->alias () + && node->is_child (this->ctx_->scope ())) + { + be_visitor_context ctx (*this->ctx_); + ctx.node (node); + be_visitor_array_serializer_op_cs visitor (&ctx); + + if (node->accept (&visitor) == -1) + { + ACE_ERROR_RETURN ((LM_ERROR, + "(%N:%l) be_visitor_union_branch_serializer_op_cs::" + "visit_array - " + "codegen failed\n"), + -1); + } + } + + TAO_OutStream *os = this->ctx_->stream (); + + // Retrieve the union_branch node. + be_union_branch *f = this->ctx_->be_node_as_union_branch (); + + if (!f) + { + ACE_ERROR_RETURN ((LM_ERROR, + "(%N:%l) be_visitor_union_branch_serializer_op_cs::" + "visit_array - " + "cannot retrieve union_branch node\n"), + -1); + } + + // For anonymous arrays, the type name has a _ prepended. We compute the + // fullname with or without the underscore and use it later on. + char fname [NAMEBUFSIZE]; // to hold the full and + + // Save the node's local name and full name in a buffer for quick + // use later on. + ACE_OS::memset (fname, + '\0', + NAMEBUFSIZE); + + if (!this->ctx_->alias () // not a typedef + && node->is_child (this->ctx_->scope ())) + { + // For anonymous arrays ... + // we have to generate a name for us that has an underscore + // prepended to our local name. This needs to be inserted after + // the parents's name. + if (node->is_nested ()) + { + be_decl *parent = + be_scope::narrow_from_scope (node->defined_in ())->decl (); + ACE_OS::sprintf (fname, + "%s::_%s", + parent->full_name (), + node->local_name ()->get_string ()); + } + else + { + ACE_OS::sprintf (fname, + "_%s", + node->full_name ()); + } + } + else + { + // Typedefed node. + ACE_OS::sprintf (fname, "%s", node->full_name ()); + } + + // Check what is the code generations substate. Are we generating code for + // the in/out operators for our parent or for us? + switch (this->ctx_->sub_state ()) + { + case TAO_CodeGen::TAO_IS_BOUNDED_SIZE: + { + //SHH - TBD - could avoid the counter by enclosing in {} + // But this code is currently dead anyway because + // unions always return false for _dcps_is_bounded and a large + // number for _dcsp_max_marshaled_size. + // This note applies to multiple locations in this file. + static int tmp_counter = 0; + char tmp_val_name[30]; + ACE_OS::sprintf(tmp_val_name, "tmp_array_val%d", tmp_counter++); + *os << fname << "_forany " << tmp_val_name << " (" << be_idt << be_idt_nl + << "_tao_union." + << f->local_name () << " ()" << be_uidt_nl + <<");" << be_uidt_nl; + *os << "is_bounded = is_bounded && " + << "_tao_is_bounded_size (" << tmp_val_name << ");" + << be_nl; + } + break; + case TAO_CodeGen::TAO_MAX_MARSHALED_SIZE: + { + static int tmp_counter = 0; + char tmp_size_name[30]; + char tmp_val_name[30]; + ACE_OS::sprintf(tmp_size_name, "tmp_array_size%d", tmp_counter); + ACE_OS::sprintf(tmp_val_name, "tmp_array_val%d", tmp_counter++); + *os << f->field_type ()->name() << "_forany " << tmp_val_name + << "; // is type of " << f->local_name () << be_nl; + *os << "size_t " << tmp_size_name + << " = _dcps_max_marshaled_size (" << tmp_val_name << ");" << be_nl + << "if (" << tmp_size_name << " > max_size) " << be_idt_nl + << "max_size = " << tmp_size_name << ";" << be_uidt_nl << be_nl; + } + break; + case TAO_CodeGen::TAO_FIND_SIZE: + *os << fname << "_forany _tao_union_tmp (" << be_idt << be_idt_nl + << "_tao_union." + << f->local_name () << " ()" << be_uidt_nl + <<");" << be_uidt_nl; + *os << "result += _dcps_find_size (_tao_union_tmp);"; + break; + case TAO_CodeGen::TAO_CDR_INPUT: + *os << fname << " _tao_union_tmp;" << be_nl + << fname << "_forany _tao_union_helper (" + << be_idt << be_idt_nl + << "_tao_union_tmp" << be_uidt_nl + << ");" << be_uidt_nl + << "result = strm >> _tao_union_helper;" << be_nl << be_nl + << "if (result)" << be_idt_nl + << "{" << be_idt_nl + << "_tao_union." << f->local_name () + << " (_tao_union_tmp);" << be_nl + << "_tao_union._d (_tao_discriminant);" << be_uidt_nl + << "}" << be_uidt; + + return 0; + + case TAO_CodeGen::TAO_CDR_OUTPUT: + *os << fname << "_forany _tao_union_tmp (" << be_idt << be_idt_nl + << "_tao_union." + << f->local_name () << " ()" << be_uidt_nl + <<");" << be_uidt_nl + << "result = strm << _tao_union_tmp;"; + return 0; + + case TAO_CodeGen::TAO_CDR_SCOPE: + // This is done in serializer_op_cs.cpp and hacked into *.i. + break; + default: + // Error. + ACE_ERROR_RETURN ((LM_ERROR, + "(%N:%l) be_visitor_union_branch_serializer_op_cs::" + "visit_array - " + "bad sub state\n"), + -1); + } + + return 0; +} + +int +be_visitor_union_branch_serializer_op_cs::visit_enum (be_enum *node) +{ + TAO_OutStream *os = this->ctx_->stream (); + + // Retrieve the union_branch node + be_union_branch *f = this->ctx_->be_node_as_union_branch (); + + if (!f) + { + ACE_ERROR_RETURN ((LM_ERROR, + "(%N:%l) be_visitor_union_branch_serializer_op_cs::" + "visit_array - " + "cannot retrieve union_branch node\n"), + -1); + } + + switch (this->ctx_->sub_state ()) + { + case TAO_CodeGen::TAO_IS_BOUNDED_SIZE: + *os << "// " << f->local_name () + << " is of an enum type; hence is bounded" << be_nl; + return 0; // all done + break; + case TAO_CodeGen::TAO_FIND_SIZE: + // enums are serialized as CORBA::ULong + *os << "result += _dcps_max_marshaled_size_ulong (); /* enum */" + << be_nl; + return 0; // all done + break; + case TAO_CodeGen::TAO_MAX_MARSHALED_SIZE: + // enums are serialized as CORBA::ULong + *os << "if (_dcps_max_marshaled_size_ulong () > max_size)" << be_idt_nl + << "max_size = _dcps_max_marshaled_size_ulong (); /* enum */" + << be_uidt_nl << be_nl; + return 0; // all done + break; + default: + // do code in the rest of this method. + break; + } + + // Check what is the code generations substate. Are we generating code for + // the in/out operators for our parent or for us? + switch (this->ctx_->sub_state ()) + { + case TAO_CodeGen::TAO_CDR_INPUT: + *os << node->name () << " _tao_union_tmp" + << ";" << be_nl + << "result = strm >> _tao_union_tmp;" << be_nl + << "if (result)" << be_idt_nl + << "{" << be_idt_nl + << "_tao_union." << f->local_name () + << " (_tao_union_tmp);" << be_nl + << "_tao_union._d (_tao_discriminant);" << be_uidt_nl + << "}" << be_uidt; + + return 0; + + case TAO_CodeGen::TAO_CDR_OUTPUT: + *os << "result = strm << _tao_union." << f->local_name () << " ();"; + return 0; + + case TAO_CodeGen::TAO_CDR_SCOPE: + // Proceed further. + break; + default: + // Error. + ACE_ERROR_RETURN ((LM_ERROR, + "(%N:%l) be_visitor_union_branch_serializer_op_cs::" + "visit_enum - " + "bad sub state\n"), + -1); + } + + // Not a typedef and node is defined inside the union. Otherwise the + // Serializer operator is generated elsewhere. + if (node->node_type () != AST_Decl::NT_typedef + && node->is_child (this->ctx_->scope ())) + { + // Instantiate a visitor context with a copy of our context. This info + // will be modified based on what type of node we are visiting. + be_visitor_context ctx (*this->ctx_); + ctx.node (node); + be_visitor_enum_serializer_op_cs visitor (&ctx); + + if (visitor.visit_enum (node) == -1) + { + ACE_ERROR_RETURN ((LM_ERROR, + "(%N:%l) be_visitor_union_branch_serializer_op_cs::" + "visit_enum - " + "codegen failed\n"), + -1); + } + } + + return 0; +} + +int +be_visitor_union_branch_serializer_op_cs::visit_interface (be_interface *node) +{ + TAO_OutStream *os = this->ctx_->stream (); + + // Retrieve the union_branch node. + be_union_branch *f = this->ctx_->be_node_as_union_branch (); + + if (!f) + { + ACE_ERROR_RETURN ((LM_ERROR, + "(%N:%l) be_visitor_union_branch_serializer_op_cs::" + "visit_interface - " + "cannot retrieve union_branch node\n"), + -1); + } + + // Check what is the code generations substate. Are we generating code for + // the in/out operators for our parent or for us? + switch (this->ctx_->sub_state ()) + { + case TAO_CodeGen::TAO_CDR_INPUT: + if (node->is_local ()) + { + *os << "result = 0;"; + } + else + { + *os << node->name () << "_var _tao_union_tmp;" << be_nl + << "result = strm >> _tao_union_tmp.inout ();" << be_nl << be_nl + << "if (result)" << be_idt_nl + << "{" << be_idt_nl + << "_tao_union." + << f->local_name () << " (_tao_union_tmp.in ());" << be_nl + << "_tao_union._d (_tao_discriminant);" << be_uidt_nl + << "}" << be_uidt; + } + + break; + + case TAO_CodeGen::TAO_CDR_OUTPUT: + if (node->is_defined ()) + { + if (f->is_abstract ()) + { + *os << "(strm << _tao_union." + << f->local_name () << " ());"; + } + else + { + *os << "CORBA::Object::marshal (" << be_idt << be_idt_nl + << "_tao_union." << f->local_name () << " ()," << be_nl + << "strm" << be_uidt_nl + << ");" << be_uidt; + } + } + else + { + *os << "result =" << be_idt_nl + << "TAO::Objref_Traits<" << node->name () << ">::marshal (" + << be_idt << be_idt_nl + << "_tao_union." << f->local_name () << " ()," << be_nl + << "strm" << be_uidt_nl + << ");" << be_uidt << be_uidt; + } + + break; + + case TAO_CodeGen::TAO_CDR_SCOPE: + // Nothing to be done because an interface cannot be declared inside a + // union. + break; + + default: + // Error. + ACE_ERROR_RETURN ((LM_ERROR, + "(%N:%l) be_visitor_union_branch_serializer_op_cs::" + "visit_interface - " + "bad sub state\n"), + -1); + } + + return 0; +} + +int +be_visitor_union_branch_serializer_op_cs::visit_interface_fwd (be_interface_fwd *node) +{ + TAO_OutStream *os = this->ctx_->stream (); + + // Retrieve the union_branch node. + be_union_branch *f = this->ctx_->be_node_as_union_branch (); + + if (!f) + { + ACE_ERROR_RETURN ((LM_ERROR, + "(%N:%l) be_visitor_union_branch_serializer_op_cs::" + "visit_interface_fwd - " + "cannot retrieve union_branch node\n"), + -1); + } + + // Check what is the code generations substate. Are we generating code for + // the in/out operators for our parent or for us? + switch (this->ctx_->sub_state ()) + { + case TAO_CodeGen::TAO_CDR_INPUT: + if (node->is_local ()) + { + *os << "result = 0;"; + } + else + { + *os << node->name () << "_var _tao_union_tmp;" << be_nl + << "result = strm >> _tao_union_tmp.inout ();" << be_nl << be_nl + << "if (result)" << be_idt_nl + << "{" << be_idt_nl + << "_tao_union." + << f->local_name () << " (_tao_union_tmp.in ());" << be_nl + << "_tao_union._d (_tao_discriminant);" << be_uidt_nl + << "}" << be_uidt; + } + + break; + + case TAO_CodeGen::TAO_CDR_OUTPUT: + *os << "result = _tao_union." + << f->local_name () << " ()->marshal (strm);"; + break; + + case TAO_CodeGen::TAO_CDR_SCOPE: + // Nothing to be done because an interface cannot be forward declared + // inside a union. + break; + + default: + // Error. + ACE_ERROR_RETURN ((LM_ERROR, + "(%N:%l) be_visitor_union_branch_serializer_op_cs::" + "visit_interface_fwd - " + "bad sub state\n"), + -1); + } + + return 0; +} + +int +be_visitor_union_branch_serializer_op_cs::visit_valuetype (be_valuetype *node) +{ + TAO_OutStream *os = this->ctx_->stream (); + + // Retrieve the union_branch node. + be_union_branch *f = this->ctx_->be_node_as_union_branch (); + + if (!f) + { + ACE_ERROR_RETURN ((LM_ERROR, + "(%N:%l) be_visitor_union_branch_serializer_op_cs::" + "visit_valuetype - " + "cannot retrieve union_branch node\n"), + -1); + } + + // Check what is the code generations substate. Are we generating code for + // the in/out operators for our parent or for us? + switch (this->ctx_->sub_state ()) + { + case TAO_CodeGen::TAO_CDR_INPUT: + *os << node->name () << "_var _tao_union_tmp;" << be_nl + << "result = strm >> _tao_union_tmp.inout ();" << be_nl << be_nl + << "if (result)" << be_idt_nl + << "{" << be_idt_nl + << "_tao_union." + << f->local_name () << " (_tao_union_tmp.in ());" << be_nl + << "_tao_union._d (_tao_discriminant);" << be_uidt_nl + << "}" << be_uidt; + + break; + + case TAO_CodeGen::TAO_CDR_OUTPUT: + *os << "result = strm << _tao_union." + << f->local_name () << " ();"; + break; + + case TAO_CodeGen::TAO_CDR_SCOPE: + // Nothing to be done because an interface cannot be declared inside a + // union. + break; + + default: + // Error. + ACE_ERROR_RETURN ((LM_ERROR, + "(%N:%l) be_visitor_union_branch_serializer_op_cs::" + "visit_valuetype - " + "bad sub state\n"), + -1); + } + + return 0; +} + +int +be_visitor_union_branch_serializer_op_cs::visit_valuetype_fwd (be_valuetype_fwd *node) +{ + TAO_OutStream *os = this->ctx_->stream (); + + // Retrieve the union_branch node. + be_union_branch *f = this->ctx_->be_node_as_union_branch (); + + if (!f) + { + ACE_ERROR_RETURN ((LM_ERROR, + "(%N:%l) be_visitor_union_branch_serializer_op_cs::" + "visit_valuetype_fwd - " + "cannot retrieve union_branch node\n"), + -1); + } + + // Check what is the code generations substate. Are we generating code for + // the in/out operators for our parent or for us? + switch (this->ctx_->sub_state ()) + { + case TAO_CodeGen::TAO_CDR_INPUT: + *os << node->name () << "_var _tao_union_tmp;" << be_nl + << "result = strm >> _tao_union_tmp.inout ();" << be_nl << be_nl + << "if (result)" << be_idt_nl + << "{" << be_idt_nl + << "_tao_union." + << f->local_name () << " (_tao_union_tmp.in ());" << be_nl + << "_tao_union._d (_tao_discriminant);" << be_uidt_nl + << "}" << be_uidt; + + break; + + case TAO_CodeGen::TAO_CDR_OUTPUT: + *os << "result = strm << _tao_union." + << f->local_name () << " ();"; + break; + + case TAO_CodeGen::TAO_CDR_SCOPE: + // Nothing to be done because an interface cannot be forward declared + // inside a union. + break; + + default: + // Error. + ACE_ERROR_RETURN ((LM_ERROR, + "(%N:%l) be_visitor_union_branch_serializer_op_cs::" + "visit_valuetype_fwd - " + "bad sub state\n"), + -1); + } + + return 0; +} + +int +be_visitor_union_branch_serializer_op_cs::visit_predefined_type (be_predefined_type *node) +{ + TAO_OutStream *os = this->ctx_->stream (); + + // Retrieve the union_branch node. + be_union_branch *f = this->ctx_->be_node_as_union_branch (); + + if (!f) + { + ACE_ERROR_RETURN ((LM_ERROR, + "(%N:%l) be_visitor_union_branch_serializer_op_cs::" + "visit_predefined_type - " + "cannot retrieve union_branch node\n"), + -1); + } + + AST_PredefinedType::PredefinedType pt = node->pt (); + + // Check what is the code generations substate. Are we generating code for + // the in/out operators for our parent or for us? + switch (this->ctx_->sub_state ()) + { + case TAO_CodeGen::TAO_MAX_MARSHALED_SIZE: + { + static int tmp_counter = 0; + char tmp_name[10]; + ACE_OS::sprintf(tmp_name, "tmp%d", tmp_counter++); + + if (pt == AST_PredefinedType::PT_pseudo + || pt == AST_PredefinedType::PT_object) + { + *os << "PT_pseudo and PT_object not supported by -Gdcps"; + *os << be_nl << be_nl << "// above error is from " << be_nl + << "// " << __FILE__ << ":" << __LINE__ << be_nl << be_nl; + } + else if (pt == AST_PredefinedType::PT_char) + { + *os << "size_t " << tmp_name << " = _dcps_max_marshaled_size (" + << "CORBA::Any::from_char (_tao_union." + << f->local_name () << " ()));" << be_nl + << "if (" << tmp_name << " > max_size) max_size = " + << tmp_name << ";" << be_nl; + } + else if (pt == AST_PredefinedType::PT_wchar) + { + *os << "size_t " << tmp_name << " = _dcps_max_marshaled_size (" + << "CORBA::Any::from_wchar (_tao_union." + << f->local_name () << " ()));" << be_nl + << "if (" << tmp_name << " > max_size) max_size = " + << tmp_name << ";" << be_nl; + } + else if (pt == AST_PredefinedType::PT_octet) + { + *os << "size_t " << tmp_name << " = _dcps_max_marshaled_size (" + << "CORBA::Any::from_octet (_tao_union." + << f->local_name () << " ()));" << be_nl + << "if (" << tmp_name << " > max_size) max_size = " + << tmp_name << ";" << be_nl; + } + else if (pt == AST_PredefinedType::PT_boolean) + { + *os << "size_t " << tmp_name << " = _dcps_max_marshaled_size (" + << "CORBA::Any::from_boolean (_tao_union." + << f->local_name () << " ()));" << be_nl + << "if (" << tmp_name << " > max_size) max_size = " + << tmp_name << ";" << be_nl; + } + else + { + *os << "size_t " << tmp_name + << " = _dcps_max_marshaled_size (_tao_union." + << f->local_name () << " ());" << be_nl + << "if (" << tmp_name << " > max_size)" << be_idt_nl + << "max_size = "<< tmp_name << ";" << be_uidt_nl << be_nl; + } + } + break; + + case TAO_CodeGen::TAO_IS_BOUNDED_SIZE: + if (pt == AST_PredefinedType::PT_pseudo + || pt == AST_PredefinedType::PT_object) + { + *os << "PT_pseudo and PT_object not supported by -Gdcps"; + *os << be_nl << be_nl << "// above error is from " << be_nl + << "// " << __FILE__ << ":" << __LINE__ << be_nl << be_nl; + } + else + { + *os << "// " << f->local_name () + << " is of a predefined type; hence is bounded" << be_nl; + } + break; + + case TAO_CodeGen::TAO_FIND_SIZE: + + *os << "result += "; + + if (pt == AST_PredefinedType::PT_pseudo + || pt == AST_PredefinedType::PT_object) + { + *os << "PT_pseudo and PT_object not supported by -Gdcps"; + *os << be_nl << be_nl << "// above error is from " << be_nl + << "// " << __FILE__ << ":" << __LINE__ << be_nl << be_nl; + } + else if (pt == AST_PredefinedType::PT_char) + { + *os << "_dcps_max_marshaled_size (CORBA::Any::from_char (_tao_union." + << f->local_name () << " ()));"; + } + else if (pt == AST_PredefinedType::PT_wchar) + { + *os << "_dcps_max_marshaled_size (CORBA::Any::from_wchar (_tao_union." + << f->local_name () << " ()));"; + } + else if (pt == AST_PredefinedType::PT_octet) + { + *os << "_dcps_max_marshaled_size (CORBA::Any::from_octet (_tao_union." + << f->local_name () << " ()));"; + } + else if (pt == AST_PredefinedType::PT_boolean) + { + *os << "_dcps_max_marshaled_size (CORBA::Any::from_boolean (_tao_union." + << f->local_name () << " ()));"; + } + else + { + // is predefined so _find_size = _dcps_max_marshaled_size + *os << "_dcps_max_marshaled_size (_tao_union." << f->local_name () << " ());"; + } + + break; + + case TAO_CodeGen::TAO_CDR_INPUT: + if (pt == AST_PredefinedType::PT_object) + { + *os << "CORBA::Object_var _tao_union_tmp;" << be_nl; + + *os << "result = strm >> _tao_union_tmp.out ();" << be_nl << be_nl + << "if (result)" << be_idt_nl + << "{" << be_idt_nl + << "_tao_union." << f->local_name () << " (_tao_union_tmp.in ());"; + + } + else if (pt == AST_PredefinedType::PT_pseudo) + { + *os << "CORBA::TypeCode_var _tao_union_tmp;" << be_nl + << "result = strm >> _tao_union_tmp.out ();" << be_nl << be_nl + << "if (result)" << be_idt_nl + << "{" << be_idt_nl + << "_tao_union." << f->local_name () << " (_tao_union_tmp.in ());"; + + } + else if (pt == AST_PredefinedType::PT_value) + { + *os << "CORBA::ValueBase * _tao_union_tmp;" << be_nl + << "result = strm >> _tao_union_tmp;" << be_nl << be_nl + << "if (result)" << be_idt_nl + << "{" << be_idt_nl + << "_tao_union." << f->local_name () << " (_tao_union_tmp);"; + + } + else if (pt == AST_PredefinedType::PT_char) + { + *os << "CORBA::Char _tao_union_tmp;" << be_nl + << "CORBA::Any::to_char _tao_union_helper " + << "(_tao_union_tmp);" << be_nl + << "result = strm >> _tao_union_helper;" << be_nl << be_nl + << "if (result)" << be_idt_nl + << "{" << be_idt_nl + << "_tao_union." << f->local_name () + << " (_tao_union_tmp);"; + } + else if (pt == AST_PredefinedType::PT_wchar) + { + *os << "CORBA::WChar _tao_union_tmp;" << be_nl + << "CORBA::Any::to_wchar _tao_union_helper " + << "(_tao_union_tmp);" << be_nl + << "result = strm >> _tao_union_helper;" << be_nl << be_nl + << "if (result)" << be_idt_nl + << "{" << be_idt_nl + << "_tao_union." << f->local_name () + << " (_tao_union_tmp);"; + } + else if (pt == AST_PredefinedType::PT_octet) + { + *os << "CORBA::Octet _tao_union_tmp;" << be_nl + << "CORBA::Any::to_octet _tao_union_helper " + << "(_tao_union_tmp);" << be_nl + << "result = strm >> _tao_union_helper;" << be_nl << be_nl + << "if (result)" << be_idt_nl + << "{" << be_idt_nl + << "_tao_union." << f->local_name () + << " (_tao_union_tmp);"; + } + else if (pt == AST_PredefinedType::PT_boolean) + { + *os << "CORBA::Boolean _tao_union_tmp;" << be_nl + << "CORBA::Any::to_boolean _tao_union_helper " + << "(_tao_union_tmp);" << be_nl + << "result = strm >> _tao_union_helper;" << be_nl << be_nl + << "if (result)" << be_idt_nl + << "{" << be_idt_nl + << "_tao_union." << f->local_name () + << " (_tao_union_tmp);"; + } + else + { + *os << node->name () << " _tao_union_tmp;" << be_nl + << "result = strm >> _tao_union_tmp;" << be_nl << be_nl + << "if (result)" << be_idt_nl + << "{" << be_idt_nl + << "_tao_union." << f->local_name () + << " (_tao_union_tmp);"; + } + + *os << be_nl; + *os << "_tao_union._d (_tao_discriminant);" << be_uidt_nl; + *os << "}" << be_uidt; + + break; + + case TAO_CodeGen::TAO_CDR_OUTPUT: + + *os << "result = "; + + if (pt == AST_PredefinedType::PT_pseudo + || pt == AST_PredefinedType::PT_object) + { + *os << "strm << _tao_union." << f->local_name () << " ();"; + } + else if (pt == AST_PredefinedType::PT_char) + { + *os << "strm << CORBA::Any::from_char (_tao_union." + << f->local_name () << " ());"; + } + else if (pt == AST_PredefinedType::PT_wchar) + { + *os << "strm << CORBA::Any::from_wchar (_tao_union." + << f->local_name () << " ());"; + } + else if (pt == AST_PredefinedType::PT_octet) + { + *os << "strm << CORBA::Any::from_octet (_tao_union." + << f->local_name () << " ());"; + } + else if (pt == AST_PredefinedType::PT_boolean) + { + *os << "strm << CORBA::Any::from_boolean (_tao_union." + << f->local_name () << " ());"; + } + else + { + *os << "strm << _tao_union." << f->local_name () << " ();"; + } + + break; + + case TAO_CodeGen::TAO_CDR_SCOPE: + // Nothing to be done. + break; + default: + // Error. + ACE_ERROR_RETURN ((LM_ERROR, + "(%N:%l) be_visitor_union_branch_serializer_op_cs::" + "visit_array - " + "bad sub state\n"), + -1); + } + + return 0; +} + +int +be_visitor_union_branch_serializer_op_cs::visit_sequence (be_sequence *node) +{ + // If the sequence is defined in this scope, generate its Serializer stream + // operators heree. + if (node->node_type () != AST_Decl::NT_typedef + && node->is_child (this->ctx_->scope ())) + { + // Anonymous sequence + be_visitor_context ctx (*this->ctx_); + ctx.node (node); + be_visitor_sequence_serializer_op_cs visitor (&ctx); + + if (node->accept (&visitor) == -1) + { + ACE_ERROR_RETURN ((LM_ERROR, + "(%N:%l) be_visitor_union_branch_serializer_op_cs::" + "visit_sequence - " + "codegen failed\n"), + -1); + } + } + + // Now generate the Serializer stream operators for the sequence as a + // union branch. + + TAO_OutStream *os = this->ctx_->stream (); + + // Retrieve the union_branch node. + be_union_branch *f = this->ctx_->be_node_as_union_branch (); + if (!f) + { + ACE_ERROR_RETURN ((LM_ERROR, + "(%N:%l) be_visitor_union_branch_serializer_op_cs::" + "visit_sequence - " + "cannot retrieve union_branch node\n" + ), -1); + } + + // Check what is the code generations substate. Are we generating code for + // the in/out operators for our parent or for us? + switch (this->ctx_->sub_state ()) + { + case TAO_CodeGen::TAO_IS_BOUNDED_SIZE: + { + static int tmp_counter = 0; + char tmp_val_name[30]; + ACE_OS::sprintf(tmp_val_name, "tmp_seq_val%d", tmp_counter++); + *os << f->field_type ()->name() << " " << tmp_val_name + << "; // is type of " << f->local_name () << be_nl; + *os << "is_bounded = is_bounded && " + << "_tao_is_bounded_size (" << tmp_val_name << ");" + << be_nl; + } + break; + case TAO_CodeGen::TAO_MAX_MARSHALED_SIZE: + { + static int tmp_counter = 0; + char tmp_size_name[30]; + char tmp_val_name[30]; + ACE_OS::sprintf(tmp_size_name, "tmp_seq_size%d", tmp_counter); + ACE_OS::sprintf(tmp_val_name, "tmp_seq_val%d", tmp_counter++); + *os << f->field_type ()->name() << " " << tmp_val_name + << "; // is type of " << f->local_name () << be_nl; + *os << "size_t " << tmp_size_name + << " = _dcps_max_marshaled_size (" << tmp_val_name << ");" << be_nl + << "if (" << tmp_size_name << " > max_size) " << be_idt_nl + << "max_size = " << tmp_size_name << ";" << be_uidt_nl << be_nl; + } + break; + case TAO_CodeGen::TAO_FIND_SIZE: + //SHH - TBD - make sure this is a shallow copy. + // But this code is currently dead anyway because + // unions always return false for _dcps_is_bounded and a large + // number for _dcsp_max_marshaled_size. + // This note applies to multiple locations in this file. + *os << f->field_type ()->name() << " tmp (_tao_union." + << f->local_name () << " ());" << be_nl; + *os << "result += _dcps_find_size (tmp);" << be_nl; + break; + case TAO_CodeGen::TAO_CDR_INPUT: + { + // If the typedef'd sequence is included from another + // file, node->name() won't work. The following works + // for all typedefs, external or not. + be_typedef *td = this->ctx_->alias (); + + if (td) + { + *os << td->name (); + } + else + { + *os << node->name (); + } + + *os << " _tao_union_tmp;" << be_nl + << "result = strm >> _tao_union_tmp;" << be_nl << be_nl + << "if (result)" << be_idt_nl + << "{" << be_idt_nl + << "_tao_union." + << f->local_name () << " (_tao_union_tmp);" << be_nl + << "_tao_union._d (_tao_discriminant);" << be_uidt_nl + << "}" << be_uidt; + + return 0; + } + + case TAO_CodeGen::TAO_CDR_OUTPUT: + *os << "result = strm << _tao_union." + << f->local_name () << " ();"; + return 0; + + case TAO_CodeGen::TAO_CDR_SCOPE: + // Proceed further. + break; + default: + // Error + ACE_ERROR_RETURN ((LM_ERROR, + "(%N:%l) be_visitor_union_branch_serializer_op_cs::" + "visit_sequence - " + "bad sub state\n"), + -1); + } + + return 0; +} + +int +be_visitor_union_branch_serializer_op_cs::visit_string (be_string *node) +{ + TAO_OutStream *os = this->ctx_->stream (); + + // Retrieve the union_branch node. + be_union_branch *f = this->ctx_->be_node_as_union_branch (); + + if (!f) + { + ACE_ERROR_RETURN ((LM_ERROR, + "(%N:%l) be_visitor_union_branch_serializer_op_cs::" + "visit_string - " + "cannot retrieve union_branch node\n"), + -1); + } + + // Check what is the code generations substate. Are we generating code for + // the in/out operators for our parent or for us? + switch (this->ctx_->sub_state ()) + { + case TAO_CodeGen::TAO_IS_BOUNDED_SIZE: + if (0 == node->max_size ()->ev ()->u.ulval) + *os << "is_bounded = is_bounded && false; /* unbounded string */" + << be_nl; + else + *os << "// bounded string " << f->local_name () + << be_nl; + break; + case TAO_CodeGen::TAO_MAX_MARSHALED_SIZE: + { + static int tmp_counter = 0; + char tmp_size_name[30]; + ACE_OS::sprintf(tmp_size_name, "tmp_string_size%d", tmp_counter++); + + char buff[15]; + ACE_OS::sprintf(buff, "%d", node->max_size ()->ev ()->u.ulval); + *os << "size_t " << tmp_size_name + << " = _dcps_max_marshaled_size_ulong () + " << buff << ";" << be_nl + << "if (" << tmp_size_name << ")" << be_idt_nl + << "max_size = " << tmp_size_name << ";" << be_uidt_nl; + } + break; + case TAO_CodeGen::TAO_FIND_SIZE: + *os << "result += _dcps_max_marshaled_size_ulong() + " << be_idt_nl + << "ACE_OS::strlen(_tao_union." + << f->local_name () << " ());" << be_uidt_nl; + break; + case TAO_CodeGen::TAO_CDR_INPUT: + if (node->width () == (long) sizeof (char)) + { + *os << "CORBA::String_var _tao_union_tmp;" << be_nl; + } + else + { + *os << "CORBA::WString_var _tao_union_tmp;" << be_nl; + } + + *os << "result = strm >> _tao_union_tmp.out ();" << be_nl << be_nl + << "if (result)" << be_idt_nl + << "{" << be_idt_nl + << "_tao_union." + << f->local_name () << " (_tao_union_tmp);" << be_nl + << "_tao_union._d (_tao_discriminant);" << be_uidt_nl + << "}" << be_uidt; + + break; + + case TAO_CodeGen::TAO_CDR_OUTPUT: + *os << "result = strm << _tao_union." + << f->local_name () << " ();"; + break; + + case TAO_CodeGen::TAO_CDR_SCOPE: + // Nothing to be done. + break; + default: + // Error. + ACE_ERROR_RETURN ((LM_ERROR, + "(%N:%l) be_visitor_union_branch_serializer_op_cs::" + "visit_array - " + "bad sub state\n"), + -1); + } + + return 0; +} + +int +be_visitor_union_branch_serializer_op_cs::visit_structure (be_structure *node) +{ + // If the structure is defined in this scope. generate its Serializer + // stream operators here. + if (node->node_type () != AST_Decl::NT_typedef + && node->is_child (this->ctx_->scope ())) + { + be_visitor_context ctx (*this->ctx_); + ctx.node (node); + be_visitor_structure_serializer_op_cs visitor (&ctx); + + if (node->accept (&visitor) == -1) + { + ACE_ERROR_RETURN ((LM_ERROR, + "(%N:%l) be_visitor_union_branch_serializer_op_cs::" + "visit_struct - " + "codegen failed\n"), + -1); + } + } + + // How generate the Serializer stream operators for the structure as + // a union branch. + + TAO_OutStream *os = this->ctx_->stream (); + + // Retrieve the union_branch node. + be_union_branch *f = this->ctx_->be_node_as_union_branch (); + + if (!f) + { + ACE_ERROR_RETURN ((LM_ERROR, + "(%N:%l) be_visitor_union_branch_serializer_op_cs::" + "visit_structure - " + "cannot retrieve union_branch node\n"), + -1); + } + + // Check what is the code generations substate. Are we generating code for + // the in/out operators for our parent or for us? + switch (this->ctx_->sub_state ()) + { + case TAO_CodeGen::TAO_MAX_MARSHALED_SIZE: + { + static int tmp_counter = 0; + char tmp_size_name[30]; + char tmp_val_name[30]; + ACE_OS::sprintf(tmp_size_name, "tmp_struct_size%d", tmp_counter); + ACE_OS::sprintf(tmp_val_name, "tmp_struct_val%d", tmp_counter++); + + *os << f->field_type ()->name() << " " << tmp_val_name + << "; // is type of " << f->local_name () << be_nl; + *os << "size_t " << tmp_size_name + << " = _dcps_max_marshaled_size (" << tmp_val_name << ");" << be_nl + << "if (" << tmp_size_name << " > max_size) " << be_idt_nl + << "max_size = " << tmp_size_name << ";" << be_uidt_nl << be_nl; + } + break; + + case TAO_CodeGen::TAO_IS_BOUNDED_SIZE: + { + static int tmp_counter = 0; + char tmp_size_name[30]; + char tmp_val_name[30]; + ACE_OS::sprintf(tmp_size_name, "tmp_struct_size%d", tmp_counter); + ACE_OS::sprintf(tmp_val_name, "tmp_struct_val%d", tmp_counter++); + + *os << f->field_type ()->name() << " " << tmp_val_name + << "; // is type of " << f->local_name () << be_nl; + *os << "is_bounded = is_bounded && _tao_is_bounded_size (" + << tmp_val_name << ");" << be_nl; + } + break; + + case TAO_CodeGen::TAO_FIND_SIZE: + *os << "result += _dcps_find_size (_tao_union." + << f->local_name () << " ());" << be_nl; + break; + + case TAO_CodeGen::TAO_CDR_INPUT: + *os << node->name () << " _tao_union_tmp;" << be_nl + << "result = strm >> _tao_union_tmp;" << be_nl << be_nl + << "if (result)" << be_idt_nl + << "{" << be_idt_nl + << "_tao_union." << f->local_name () + << " (_tao_union_tmp);" << be_nl + << "_tao_union._d (_tao_discriminant);" << be_uidt_nl + << "}" << be_uidt; + + return 0; + + case TAO_CodeGen::TAO_CDR_OUTPUT: + *os << "result = strm << _tao_union." + << f->local_name () << " ();"; + return 0; + + case TAO_CodeGen::TAO_CDR_SCOPE: + // Proceed further. + break; + default: + // Error. + ACE_ERROR_RETURN ((LM_ERROR, + "(%N:%l) be_visitor_union_branch_serializer_op_cs::" + "visit_structure - " + "bad sub state\n"), + -1); + } + + return 0; +} + +int +be_visitor_union_branch_serializer_op_cs::visit_typedef (be_typedef *node) +{ + this->ctx_->alias (node); + + // The node to be visited in the base primitve type that gets typedefed. + be_type *bt = node->primitive_base_type (); + + if (!bt || (bt->accept (this) == -1)) + { + ACE_ERROR_RETURN ((LM_ERROR, + "(%N:%l) be_visitor_union_branch_public_ci::" + "visit_typedef - " + "Bad primitive type\n"), + -1); + } + + this->ctx_->alias (0); + return 0; +} + +int +be_visitor_union_branch_serializer_op_cs::visit_union (be_union *node) +{ + // If the union is defined in this scope, generate its Serializer + // stream operators here. + if (node->node_type () != AST_Decl::NT_typedef + && node->is_child (this->ctx_->scope ())) + { + be_visitor_context ctx (*this->ctx_); + ctx.node (node); + be_visitor_union_serializer_op_cs visitor (&ctx); + + if (node->accept (&visitor) == -1) + { + ACE_ERROR_RETURN ((LM_ERROR, + "(%N:%l) be_visitor_union_branch_serializer_op_cs::" + "visit_union - " + "codegen failed\n"), + -1); + } + } + + // Now generate the Serializer stream operators for the union as + // a union branch. + + TAO_OutStream *os = this->ctx_->stream (); + + // Retrieve the union_branch node. + be_union_branch *f = this->ctx_->be_node_as_union_branch (); + + if (!f) + { + ACE_ERROR_RETURN ((LM_ERROR, + "(%N:%l) be_visitor_union_branch_serializer_op_cs::" + "visit_union - " + "cannot retrieve union_branch node\n"), + -1); + } + + // Check what is the code generations substate. Are we generating code for + // the in/out operators for our parent or for us? + switch (this->ctx_->sub_state ()) + { + case TAO_CodeGen::TAO_CDR_INPUT: + *os << node->name () << " _tao_union_tmp" + << ";" << be_nl + << "result = strm >> _tao_union_tmp;" << be_nl << be_nl + << "if (result)" << be_idt_nl + << "{" << be_idt_nl + << "_tao_union." << f->local_name () + << " (_tao_union_tmp);" << be_nl + << "_tao_union._d (_tao_discriminant);" << be_uidt_nl + << "}" << be_uidt_nl; + + return 0; + + case TAO_CodeGen::TAO_CDR_OUTPUT: + *os << "result = strm << _tao_union." + << f->local_name () << " ();"; + return 0; + + case TAO_CodeGen::TAO_CDR_SCOPE: + // Proceed further. + break; + default: + // Error. + ACE_ERROR_RETURN ((LM_ERROR, + "(%N:%l) be_visitor_union_branch_serializer_op_cs::" + "visit_union - " + "bad sub state\n"), + -1); + } + + return 0; +} + +int +be_visitor_union_branch_serializer_op_cs::explicit_default (void) +{ + be_union *bu = be_union::narrow_from_decl (this->ctx_->scope ()); + int def_index = bu->default_index (); + + if (def_index != -1) + { + be_union_branch *ub = + be_union_branch::narrow_from_decl (this->ctx_->node ()); + + int i = 0; + + // Instantiate a scope iterator. + for (UTL_ScopeActiveIterator si (bu, UTL_Scope::IK_decls); + !si.is_done (); + si.next ()) + { + be_union_branch *bub = 0; // union branch node + + AST_Decl *d = si.item (); + + if (!d->imported ()) + { + bub = be_union_branch::narrow_from_decl (d); + } + + if (bub == ub) + { + return (i == def_index); + } + else + { + ++i; + } + } + } + + return 0; +} diff --git a/TAO/TAO_IDL/be_include/be_visitor_array/serializer_op_ch.h b/TAO/TAO_IDL/be_include/be_visitor_array/serializer_op_ch.h new file mode 100644 index 00000000000..4ed57472afa --- /dev/null +++ b/TAO/TAO_IDL/be_include/be_visitor_array/serializer_op_ch.h @@ -0,0 +1,55 @@ +// +// $Id$ +// + +// ============================================================================ +// +// = LIBRARY +// TAO IDL +// +// = FILENAME +// serializer_op_ch.h +// +// = DESCRIPTION +// Visitors for generation of TAO::DCPS::Serializer operators code +// for Arrays in client header. This one +// generates the TAO::DCPS::Serializer operators. +// +// = AUTHOR +// Scott Harris based on code by Aniruddha Gokhale +// +// ============================================================================ + +#ifndef _BE_VISITOR_ARRAY_serializer_op_CH_H_ +#define _BE_VISITOR_ARRAY_serializer_op_CH_H_ + +// ************************************************************ +// class be_visitor_array_serializer_op_ch +// ************************************************************ + +class be_visitor_array_serializer_op_ch : public be_visitor_decl +{ + // + // = TITLE + // be_visitor_array_serializer_op_ch + // + // = DESCRIPTION + // This is a concrete visitor for array that generates the Serializer operator + // declarations + // + +public: + be_visitor_array_serializer_op_ch (be_visitor_context *ctx); + // constructor + + ~be_visitor_array_serializer_op_ch (void); + // destructor + + void gen_arg_ref(be_array *node); + // helper - common code + + virtual int visit_array (be_array *node); + // visit array +}; + +#endif /* _BE_VISITOR_ARRAY_serializer_op_CH_H_ */ diff --git a/TAO/TAO_IDL/be_include/be_visitor_array/serializer_op_cs.h b/TAO/TAO_IDL/be_include/be_visitor_array/serializer_op_cs.h new file mode 100644 index 00000000000..f2f55211619 --- /dev/null +++ b/TAO/TAO_IDL/be_include/be_visitor_array/serializer_op_cs.h @@ -0,0 +1,97 @@ +// +// $Id$ +// + +// ============================================================================ +// +// = LIBRARY +// TAO IDL +// +// = FILENAME +// serializer_op_cs.h +// +// = DESCRIPTION +// The array's own TAO::DCPS::Serializer operators are generated in +// the .i file, but if the +// array contains an anonymous sequence, those +// TAO::DCPS::Serializer operators will not +// get generated on their own, and, since the sequence may contain a +// recursive type, they must also be generated in the .cpp file. That is +// the sole purpose of this visitor type. +// +// = AUTHOR +// Scott Harris based on code by +// Jeff Parsons +// +// ============================================================================ + +#ifndef _BE_VISITOR_ARRAY_serializer_op_CS_H_ +#define _BE_VISITOR_ARRAY_serializer_op_CS_H_ + +// ************************************************************ +// class be_visitor_array_serializer_op_cs +// ************************************************************ + +class be_visitor_array_serializer_op_cs : public be_visitor_decl +{ + // + // = TITLE + // be_visitor_array_serializer_op_cs + // + // = DESCRIPTION + // This is a concrete visitor for array that generates the Serializer operator + // implementations for the array's element type, if that type is + // an anonymous sequence. + // + +public: + be_visitor_array_serializer_op_cs (be_visitor_context *ctx); + // constructor + + ~be_visitor_array_serializer_op_cs (void); + // destructor + + virtual int visit_array (be_array *node); + // visit array + + // = Visitor methods on array types + + virtual int visit_enum (be_enum *node); + // visit an enum + + virtual int visit_interface (be_interface *node); + // visit an interface + + virtual int visit_interface_fwd (be_interface_fwd *node); + // visit an interface forward node + + virtual int visit_valuetype (be_valuetype *node); + // visit a valuetype + + virtual int visit_valuetype_fwd (be_valuetype_fwd *node); + // visit a valuetype forward node + + virtual int visit_predefined_type (be_predefined_type *node); + // visit a predefined type node + + virtual int visit_sequence (be_sequence *node); + // visit sequence + + virtual int visit_string (be_string *node); + // visit string + + virtual int visit_structure (be_structure *node); + // visit structure + + virtual int visit_typedef (be_typedef *node); + // visit typedef + + virtual int visit_union (be_union *node); + // visit union + +protected: + int visit_node (be_type *); + // helper that does the common job +}; + +#endif /* _BE_VISITOR_ARRAY_serializer_op_CS_H_ */ diff --git a/TAO/TAO_IDL/be_include/be_visitor_enum/serializer_op_ch.h b/TAO/TAO_IDL/be_include/be_visitor_enum/serializer_op_ch.h new file mode 100644 index 00000000000..6619d36d274 --- /dev/null +++ b/TAO/TAO_IDL/be_include/be_visitor_enum/serializer_op_ch.h @@ -0,0 +1,48 @@ +/* -*- C++ -*- */ +// +// $Id$ +// + +// ============================================================================ +// +// = LIBRARY +// TAO IDL +// +// = FILENAME +// serializer_op_ch.h +// +// = DESCRIPTION +// Concrete visitor for Enums generating code for the +// TAO::DCPS::Serializer operators +// +// = AUTHOR +// Scott Harris based on code by Aniruddha Gokhale +// +// ============================================================================ + +#ifndef _BE_VISITOR_ENUM_serializer_op_CH_H_ +#define _BE_VISITOR_ENUM_serializer_op_CH_H_ + +class be_visitor_enum_serializer_op_ch : public be_visitor_decl +{ + // + // = TITLE + // be_visitor_enum_serializer_op_ch + // + // = DESCRIPTION + // This is a concrete visitor for enum that generates the Serializer operator + // declarations + // + +public: + be_visitor_enum_serializer_op_ch (be_visitor_context *ctx); + // constructor + + ~be_visitor_enum_serializer_op_ch (void); + // destructor + + virtual int visit_enum (be_enum *node); + // visit enum +}; + +#endif /* _BE_VISITOR_ENUM_serializer_op_CH_H_ */ diff --git a/TAO/TAO_IDL/be_include/be_visitor_enum/serializer_op_cs.h b/TAO/TAO_IDL/be_include/be_visitor_enum/serializer_op_cs.h new file mode 100644 index 00000000000..0af226580d4 --- /dev/null +++ b/TAO/TAO_IDL/be_include/be_visitor_enum/serializer_op_cs.h @@ -0,0 +1,48 @@ +/* -*- C++ -*- */ +// +// $Id$ +// + +// ============================================================================ +// +// = LIBRARY +// TAO IDL +// +// = FILENAME +// serializer_op_cs.h +// +// = DESCRIPTION +// Concrete visitor for Enums generating code for the +// TAO::DCPS::Serializer operators +// +// = AUTHOR +// Scott Harris based on code by Aniruddha Gokhale +// +// ============================================================================ + +#ifndef _BE_VISITOR_ENUM_serializer_op_CS_H_ +#define _BE_VISITOR_ENUM_serializer_op_CS_H_ + +class be_visitor_enum_serializer_op_cs : public be_visitor_decl +{ + // + // = TITLE + // be_visitor_enum_serializer_op_cs + // + // = DESCRIPTION + // This is a concrete visitor for enum that generates the Serializer operator + // implementations + // + +public: + be_visitor_enum_serializer_op_cs (be_visitor_context *ctx); + // constructor + + ~be_visitor_enum_serializer_op_cs (void); + // destructor + + virtual int visit_enum (be_enum *node); + // visit enum +}; + +#endif /* _BE_VISITOR_ENUM_serializer_op_CS_H_ */ diff --git a/TAO/TAO_IDL/be_include/be_visitor_field/serializer_op_ch.h b/TAO/TAO_IDL/be_include/be_visitor_field/serializer_op_ch.h new file mode 100644 index 00000000000..ea3092716de --- /dev/null +++ b/TAO/TAO_IDL/be_include/be_visitor_field/serializer_op_ch.h @@ -0,0 +1,66 @@ +// +// $Id$ +// +/* -*- c++ -*- */ +// ============================================================================ +// +// = LIBRARY +// TAO IDL +// +// = FILENAME +// serializer_op_ch.h +// +// = DESCRIPTION +// Concrete visitor for the base "BE_Field" node +// This generates TAO::DCPS::Serializer operators code for structure members +// in the client header. +// +// = AUTHOR +// Scott Harris based on code by Aniruddha Gokhale +// +// ============================================================================ + +#ifndef _BE_VISITOR_FIELD_serializer_op_CH_H_ +#define _BE_VISITOR_FIELD_serializer_op_CH_H_ + +class be_visitor_field_serializer_op_ch : public be_visitor_decl +{ + // + // = TITLE + // be_visitor_serializer_op_ch + // + // = DESCRIPTION + // This is a concrete visitor for the be_field node for the client header. + // +public: + be_visitor_field_serializer_op_ch (be_visitor_context *ctx); + // constructor + + ~be_visitor_field_serializer_op_ch (void); + // destructor + + virtual int visit_field (be_field *node); + // visit the field node + + // =visit operations on all possible data types that a field can be + + virtual int visit_array (be_array *node); + // visit array type + + virtual int visit_enum (be_enum *node); + // visit enum type + + virtual int visit_sequence (be_sequence *node); + // visit sequence type + + virtual int visit_structure (be_structure *node); + // visit structure type + + virtual int visit_typedef (be_typedef *node); + // visit typedefed type + + virtual int visit_union (be_union *node); + // visit union type +}; + +#endif /* _BE_VISITOR_FIELD_serializer_op_CH_H_ */ diff --git a/TAO/TAO_IDL/be_include/be_visitor_field/serializer_op_cs.h b/TAO/TAO_IDL/be_include/be_visitor_field/serializer_op_cs.h new file mode 100644 index 00000000000..79d679cc8e8 --- /dev/null +++ b/TAO/TAO_IDL/be_include/be_visitor_field/serializer_op_cs.h @@ -0,0 +1,93 @@ +// +// $Id$ +// +/* -*- c++ -*- */ +// ============================================================================ +// +// = LIBRARY +// TAO IDL +// +// = FILENAME +// serializer_op_cs.h +// +// = DESCRIPTION +// Concrete visitor for the base "BE_Field" node +// This generates TAO::DCPS::Serializer operators code for structure members +// in the client header. +// +// = AUTHOR +// Scott Harris based on code by Aniruddha Gokhale +// +// ============================================================================ + +#ifndef _BE_VISITOR_FIELD_serializer_op_CS_H_ +#define _BE_VISITOR_FIELD_serializer_op_CS_H_ + +class be_visitor_field_serializer_op_cs : public be_visitor_decl +{ + // + // = TITLE + // be_visitor_field_serializer_op_cs + // + // = DESCRIPTION + // This is a concrete visitor for the be_field node for the client header. + // +public: + be_visitor_field_serializer_op_cs (be_visitor_context *ctx); + // constructor + + ~be_visitor_field_serializer_op_cs (void); + // destructor + + virtual int visit_field (be_field *node); + // visit the field node + + // =visit operations on all possible data types that a field can be + + virtual int visit_array (be_array *node); + virtual int visit_enum (be_enum *node); + virtual int visit_interface (be_interface *node); + virtual int visit_interface_fwd (be_interface_fwd *node); + virtual int visit_component (be_component *node); + virtual int visit_component_fwd (be_component_fwd *node); + virtual int visit_valuetype (be_valuetype *node); + virtual int visit_valuetype_fwd (be_valuetype_fwd *node); + virtual int visit_eventtype (be_eventtype *node); + virtual int visit_eventtype_fwd (be_eventtype_fwd *node); + virtual int visit_predefined_type (be_predefined_type *node); + virtual int visit_sequence (be_sequence *node); + virtual int visit_string (be_string *node); + virtual int visit_structure (be_structure *node); + virtual int visit_typedef (be_typedef *node); + virtual int visit_union (be_union *node); +}; + +class be_visitor_serializer_op_field_decl : public be_visitor_scope +{ + // + // = TITLE + // be_visitor_serializer_op_ci_field_decl + // + // = DESCRIPTION + // When generating TAO::DCPS::Serializer operators for fields of structures and/or + // unions it may be necessary to define some local variables (for + // instance to hold temporary T_forany objects); this visitor + // generates that code. + // +public: + be_visitor_serializer_op_field_decl (be_visitor_context *ctx); + // constructor + + virtual int visit_field (be_field *node); + // visit the field node + + // = visit operations for data types that require a local variable. + + virtual int visit_array (be_array *node); + // visit array type + + virtual int visit_typedef (be_typedef *node); + // visit typedef type +}; + +#endif /* _BE_VISITOR_FIELD_serializer_op_CS_H_ */ diff --git a/TAO/TAO_IDL/be_include/be_visitor_module/serializer_op.h b/TAO/TAO_IDL/be_include/be_visitor_module/serializer_op.h new file mode 100644 index 00000000000..54d83515334 --- /dev/null +++ b/TAO/TAO_IDL/be_include/be_visitor_module/serializer_op.h @@ -0,0 +1,50 @@ +/* -*- c++ -*- */ +// +// $Id$ +// + +// ============================================================================ +// +// = LIBRARY +// TAO IDL +// +// = FILENAME +// serializer_op.h +// +// = DESCRIPTION +// Concrete visitor for the Module class +// This one provides visitors to generate the +// TAO::DCPS::Serializer operators for elements in +// the Module's scope. +// +// = AUTHOR +// Scott Harris based on code by Aniruddha Gokhale +// +// ============================================================================ + +#ifndef _BE_VISITOR_MODULE_serializer_op_H_ +#define _BE_VISITOR_MODULE_serializer_op_H_ + +class be_visitor_module_serializer_op : public be_visitor_module +{ + // + // = TITLE + // be_visitor_module_serializer_op + // + // = DESCRIPTION + // This is a concrete visitor for module that generates the Serializer operator + // declarations and implementations + // + +public: + be_visitor_module_serializer_op (be_visitor_context *ctx); + // constructor + + ~be_visitor_module_serializer_op (void); + // destructor + + virtual int visit_module (be_module *node); + // visit module +}; + +#endif /* _BE_VISITOR_MODULE_serializer_op_H_ */ diff --git a/TAO/TAO_IDL/be_include/be_visitor_root/serializer_op.h b/TAO/TAO_IDL/be_include/be_visitor_root/serializer_op.h new file mode 100644 index 00000000000..d0628c4b249 --- /dev/null +++ b/TAO/TAO_IDL/be_include/be_visitor_root/serializer_op.h @@ -0,0 +1,49 @@ +/* -*- c++ -*- */ +// +// $Id$ +// + +// ============================================================================ +// +// = LIBRARY +// TAO IDL +// +// = FILENAME +// serializer_op.h +// +// = DESCRIPTION +// Concrete visitor for the Root class +// This one provides code generation for the TAO::DCPS::Serializer operators +// for elements of the Root scope. +// +// = AUTHOR +// Scott Harris based on code by Aniruddha Gokhale +// +// ============================================================================ + +#ifndef _BE_VISITOR_ROOT_serializer_op_H_ +#define _BE_VISITOR_ROOT_serializer_op_H_ + +class be_visitor_root_serializer_op : public be_visitor_root +{ + // + // = TITLE + // be_visitor_root_serializer_op + // + // = DESCRIPTION + // This is a concrete visitor for root that generates the Serializer operator + // declarations and implementations + // + +public: + be_visitor_root_serializer_op (be_visitor_context *ctx); + // constructor + + ~be_visitor_root_serializer_op (void); + // destructor + + virtual int visit_root (be_root *node); + // visit root +}; + +#endif /* _BE_VISITOR_ROOT_serializer_op_H_ */ diff --git a/TAO/TAO_IDL/be_include/be_visitor_sequence/serializer_op_ch.h b/TAO/TAO_IDL/be_include/be_visitor_sequence/serializer_op_ch.h new file mode 100644 index 00000000000..d27985b5879 --- /dev/null +++ b/TAO/TAO_IDL/be_include/be_visitor_sequence/serializer_op_ch.h @@ -0,0 +1,50 @@ +/* -*- c++ -*- */ +// +// $Id$ +// + +// ============================================================================ +// +// = LIBRARY +// TAO IDL +// +// = FILENAME +// serializer_op_ch.h +// +// = DESCRIPTION +// Concrete visitor for the Sequence class +// This one provides code generation for the +// TAO::DCPS::Serializer operators for the sequence +// in the client header. +// +// = AUTHOR +// Scott Harris based on code by Aniruddha Gokhale +// +// ============================================================================ + +#ifndef _BE_VISITOR_SEQUENCE_serializer_op_CH_H_ +#define _BE_VISITOR_SEQUENCE_serializer_op_CH_H_ + +class be_visitor_sequence_serializer_op_ch : public be_visitor_decl +{ + // + // = TITLE + // be_visitor_sequence_serializer_op_ch + // + // = DESCRIPTION + // This is a concrete visitor for sequence that generates the Serializer operator + // declarations + // + +public: + be_visitor_sequence_serializer_op_ch (be_visitor_context *ctx); + // constructor + + ~be_visitor_sequence_serializer_op_ch (void); + // destructor + + virtual int visit_sequence (be_sequence *node); + // visit sequence +}; + +#endif /* _BE_VISITOR_SEQUENCE_serializer_op_CH_H_ */ diff --git a/TAO/TAO_IDL/be_include/be_visitor_sequence/serializer_op_cs.h b/TAO/TAO_IDL/be_include/be_visitor_sequence/serializer_op_cs.h new file mode 100644 index 00000000000..5102dd83686 --- /dev/null +++ b/TAO/TAO_IDL/be_include/be_visitor_sequence/serializer_op_cs.h @@ -0,0 +1,107 @@ +// +// $Id$ +// + +// ============================================================================ +// +// = LIBRARY +// TAO IDL +// +// = FILENAME +// serializer_op_cs.h +// +// = DESCRIPTION +// Visitors for generation of code for Sequences in client stubs. This one +// generates the TAO::DCPS::Serializer operators. +// +// = AUTHOR +// Scott Harris based on code by Aniruddha Gokhale +// +// ============================================================================ + +#ifndef _BE_VISITOR_SEQUENCE_serializer_op_CS_H_ +#define _BE_VISITOR_SEQUENCE_serializer_op_CS_H_ + +// ************************************************************ +// class be_visitor_sequence_cs +// ************************************************************ + +class be_visitor_sequence_serializer_op_cs : public be_visitor_decl +{ + // + // = TITLE + // be_visitor_sequence_serializer_op_cs + // + // = DESCRIPTION + // This is a concrete visitor for sequence that generates the Serializer operator + // implementations + // + +public: + be_visitor_sequence_serializer_op_cs (be_visitor_context *ctx); + // constructor + + ~be_visitor_sequence_serializer_op_cs (void); + // destructor + + virtual int visit_sequence (be_sequence *node); + // visit sequence + + // = Visitor methods on sequence types + + virtual int visit_array (be_array *node); + // visit sequence + + virtual int visit_enum (be_enum *node); + // visit an enum + + virtual int visit_interface (be_interface *node); + // visit an interface + + virtual int visit_interface_fwd (be_interface_fwd *node); + // visit an interface forward node + + virtual int visit_component (be_component *node); + // visit a component + + virtual int visit_component_fwd (be_component_fwd *node); + // visit a component forward node + + virtual int visit_home (be_home *node); + // visit a home + + virtual int visit_valuetype (be_valuetype *node); + // visit a valuetype + + virtual int visit_valuetype_fwd (be_valuetype_fwd *node); + // visit a valuetype forward node + + virtual int visit_eventtype (be_eventtype *node); + // visit an eventtype + + virtual int visit_eventtype_fwd (be_eventtype_fwd *node); + // visit an eventtype forward node + + virtual int visit_predefined_type (be_predefined_type *node); + // visit a predefined type node + + virtual int visit_string (be_string *node); + // visit string + + virtual int visit_structure (be_structure *node); + // visit structure + + virtual int visit_typedef (be_typedef *node); + // visit typedef + + virtual int visit_union (be_union *node); + // visit union + +protected: + + int visit_node (be_type *); + // helper that does the common job + +}; + +#endif /* _BE_VISITOR_SEQUENCE_serializer_op_CS_H_ */ diff --git a/TAO/TAO_IDL/be_include/be_visitor_structure/serializer_op_ch.h b/TAO/TAO_IDL/be_include/be_visitor_structure/serializer_op_ch.h new file mode 100644 index 00000000000..d933328a197 --- /dev/null +++ b/TAO/TAO_IDL/be_include/be_visitor_structure/serializer_op_ch.h @@ -0,0 +1,49 @@ +/* -*- c++ -*- */ +// +// $Id$ +// + +// ============================================================================ +// +// = LIBRARY +// TAO IDL +// +// = FILENAME +// serializer_op_ch.h +// +// = DESCRIPTION +// Concrete visitor for the Structure class +// This one provides code generation for the TAO::DCPS::Serializer operators +// for the structure in the client header. +// +// = AUTHOR +// Scott Harris based on code by Aniruddha Gokhale +// +// ============================================================================ + +#ifndef _BE_VISITOR_STRUCTURE_serializer_op_CH_H_ +#define _BE_VISITOR_STRUCTURE_serializer_op_CH_H_ + +class be_visitor_structure_serializer_op_ch : public be_visitor_structure +{ + // + // = TITLE + // be_visitor_structure_serializer_op_ch + // + // = DESCRIPTION + // This is a concrete visitor for structure that generates the Serializer operator + // declarations + // + +public: + be_visitor_structure_serializer_op_ch (be_visitor_context *ctx); + // constructor + + ~be_visitor_structure_serializer_op_ch (void); + // destructor + + virtual int visit_structure (be_structure *node); + // visit structure +}; + +#endif /* _BE_VISITOR_STRUCTURE_serializer_op_CH_H_ */ diff --git a/TAO/TAO_IDL/be_include/be_visitor_structure/serializer_op_cs.h b/TAO/TAO_IDL/be_include/be_visitor_structure/serializer_op_cs.h new file mode 100644 index 00000000000..f4c8292fbf8 --- /dev/null +++ b/TAO/TAO_IDL/be_include/be_visitor_structure/serializer_op_cs.h @@ -0,0 +1,55 @@ +/* -*- c++ -*- */ +// +// $Id$ +// + +// ============================================================================ +// +// = LIBRARY +// TAO IDL +// +// = FILENAME +// serializer_op_ch.h +// +// = DESCRIPTION +// Concrete visitor for the Structure class +// This one provides code generation for the TAO::DCPS::Serializer operators +// for the structure in the client stub. +// +// = AUTHOR +// Scott Harris based on code by Aniruddha Gokhale +// +// ============================================================================ + +#ifndef _BE_VISITOR_STRUCTURE_serializer_op_CS_H_ +#define _BE_VISITOR_STRUCTURE_serializer_op_CS_H_ + +class be_visitor_structure_serializer_op_cs : public be_visitor_structure +{ + // + // = TITLE + // be_visitor_structure_serializer_op_cs + // + // = DESCRIPTION + // This is a concrete visitor for structure that generates the Serializer operator + // implementations + // + +public: + be_visitor_structure_serializer_op_cs (be_visitor_context *ctx); + // constructor + + ~be_visitor_structure_serializer_op_cs (void); + // destructor + + virtual int visit_structure (be_structure *node); + // visit structure + + virtual int post_process (be_decl *); + // any post processing that needs to be done after a field is handled + + virtual int pre_process (be_decl *bd); + // any preprocessing that needs to be done before a field is handled +}; + +#endif /* _BE_VISITOR_STRUCTURE_serializer_op_CS_H_ */ diff --git a/TAO/TAO_IDL/be_include/be_visitor_typedef/serializer_op_ch.h b/TAO/TAO_IDL/be_include/be_visitor_typedef/serializer_op_ch.h new file mode 100644 index 00000000000..8e625e199b1 --- /dev/null +++ b/TAO/TAO_IDL/be_include/be_visitor_typedef/serializer_op_ch.h @@ -0,0 +1,67 @@ +/* -*- c++ -*- */ +// +// $Id$ +// + +// ============================================================================ +// +// = LIBRARY +// TAO IDL +// +// = FILENAME +// serializer_op_ch.h +// +// = DESCRIPTION +// Concrete visitor for the Typedef class +// This provides the code generation for the TAO::DCPS::Serializer operators +// of the Typedef class in the client header. +// +// = AUTHOR +// Scott Harris based on code by Aniruddha Gokhale +// +// ============================================================================ + +#ifndef _BE_VISITOR_TYPEDEF_serializer_op_CH_H_ +#define _BE_VISITOR_TYPEDEF_serializer_op_CH_H_ + +class be_visitor_typedef_serializer_op_ch : public be_visitor_typedef +{ + // + // = TITLE + // be_visitor_typedef_serializer_op_ch + // + // = DESCRIPTION + // This is a concrete visitor for typedef that generates the Serializer operator + // declarations and implementations + // + +public: + be_visitor_typedef_serializer_op_ch (be_visitor_context *ctx); + // constructor + + ~be_visitor_typedef_serializer_op_ch (void); + // destructor + + virtual int visit_typedef (be_typedef *node); + // visit typedef + + // =visit methods on all elements syntactically valid as types that can be + // typedefed. + + virtual int visit_array (be_array *node); + // visit a array + + virtual int visit_enum (be_enum *node); + // visit an enum + + virtual int visit_sequence (be_sequence *node); + // visit a sequence + + virtual int visit_structure (be_structure *node); + // visit a structure + + virtual int visit_union (be_union *node); + // visit a union +}; + +#endif /* _BE_VISITOR_TYPEDEF_serializer_op_CH_H_*/ diff --git a/TAO/TAO_IDL/be_include/be_visitor_typedef/serializer_op_cs.h b/TAO/TAO_IDL/be_include/be_visitor_typedef/serializer_op_cs.h new file mode 100644 index 00000000000..e2ada3ffcb8 --- /dev/null +++ b/TAO/TAO_IDL/be_include/be_visitor_typedef/serializer_op_cs.h @@ -0,0 +1,64 @@ +/* -*- c++ -*- */ +// +// $Id$ +// + +// ============================================================================ +// +// = LIBRARY +// TAO IDL +// +// = FILENAME +// serializer_op_cs.h +// +// = DESCRIPTION +// Concrete visitor for the Typedef class +// This provides the code generation for the TAO::DCPS::Serializer operators +// of the Typedef class in the client stubs. +// +// = AUTHOR +// Scott Harris based on code by Aniruddha Gokhale +// +// ============================================================================ + +#ifndef _BE_VISITOR_TYPEDEF_serializer_op_CS_H_ +#define _BE_VISITOR_TYPEDEF_serializer_op_CS_H_ + +class be_visitor_typedef_serializer_op_cs : public be_visitor_typedef +{ + // + // = TITLE + // be_visitor_typedef_serializer_op_cs + // + // = DESCRIPTION + // This is a concrete visitor for typedef that generates the Serializer operator + // declarations and implementations + // + +public: + be_visitor_typedef_serializer_op_cs (be_visitor_context *ctx); + // constructor + + ~be_visitor_typedef_serializer_op_cs (void); + // destructor + + virtual int visit_typedef (be_typedef *node); + // visit typedef + + // =visit methods on all elements syntactically valid as types that can be + // typedefed. + + virtual int visit_array (be_array *node); + // visit a array + + virtual int visit_sequence (be_sequence *node); + // visit a sequence + + virtual int visit_structure (be_structure *node); + // visit a structure + + virtual int visit_union (be_union *node); + // visit a union +}; + +#endif /* _BE_VISITOR_TYPEDEF_serializer_op_CS_H_*/ diff --git a/TAO/TAO_IDL/be_include/be_visitor_union/serializer_op_ch.h b/TAO/TAO_IDL/be_include/be_visitor_union/serializer_op_ch.h new file mode 100644 index 00000000000..01ff118c903 --- /dev/null +++ b/TAO/TAO_IDL/be_include/be_visitor_union/serializer_op_ch.h @@ -0,0 +1,50 @@ +/* -*- c++ -*- */ +// +// $Id$ +// + +// ============================================================================ +// +// = LIBRARY +// TAO IDL +// +// = FILENAME +// serializer_op_ch.h +// +// = DESCRIPTION +// Concrete visitor for the Union class +// This one provides code generation for the TAO::DCPS::Serializer operators +// for the union in the client header. +// +// = AUTHOR +// Scott Harris based on code by Aniruddha Gokhale +// +// ============================================================================ + +#ifndef _BE_VISITOR_UNION_serializer_op_CH_H_ +#define _BE_VISITOR_UNION_serializer_op_CH_H_ + +class be_visitor_union_serializer_op_ch : public be_visitor_union +{ + // + // = TITLE + // be_visitor_union_serializer_op_ch + // + // = DESCRIPTION + // This is a concrete visitor for union that generates the Serializer operator + // declarations + // + +public: + be_visitor_union_serializer_op_ch (be_visitor_context *ctx); + // constructor + + ~be_visitor_union_serializer_op_ch (void); + // destructor + + virtual int visit_union (be_union *node); + // visit union + +}; + +#endif /* _BE_VISITOR_UNION_serializer_op_CH_H_ */ diff --git a/TAO/TAO_IDL/be_include/be_visitor_union/serializer_op_cs.h b/TAO/TAO_IDL/be_include/be_visitor_union/serializer_op_cs.h new file mode 100644 index 00000000000..f2a19231056 --- /dev/null +++ b/TAO/TAO_IDL/be_include/be_visitor_union/serializer_op_cs.h @@ -0,0 +1,52 @@ +/* -*- c++ -*- */ +// +// $Id$ +// + +// ============================================================================ +// +// = LIBRARY +// TAO IDL +// +// = FILENAME +// serializer_op_ch.h +// +// = DESCRIPTION +// Concrete visitor for the Union class +// This one provides code generation for the TAO::DCPS::Serializer operators +// for the union in the client stub. +// +// = AUTHOR +// Scott Harris based on code by Aniruddha Gokhale +// +// ============================================================================ + +#ifndef _BE_VISITOR_UNION_serializer_op_CS_H_ +#define _BE_VISITOR_UNION_serializer_op_CS_H_ + +class be_visitor_union_serializer_op_cs : public be_visitor_union +{ + // + // = TITLE + // be_visitor_union_serializer_op_cs + // + // = DESCRIPTION + // This is a concrete visitor for union that generates the Serializer operator + // implementations + // + +public: + be_visitor_union_serializer_op_cs (be_visitor_context *ctx); + // constructor + + ~be_visitor_union_serializer_op_cs (void); + // destructor + + virtual int visit_union (be_union *node); + // visit union + + virtual int pre_process (be_decl *); + virtual int post_process (be_decl *); +}; + +#endif /* _BE_VISITOR_UNION_serializer_op_CS_H_ */ diff --git a/TAO/TAO_IDL/be_include/be_visitor_union_branch/serializer_op_ch.h b/TAO/TAO_IDL/be_include/be_visitor_union_branch/serializer_op_ch.h new file mode 100644 index 00000000000..fa3e88b33ae --- /dev/null +++ b/TAO/TAO_IDL/be_include/be_visitor_union_branch/serializer_op_ch.h @@ -0,0 +1,67 @@ +// +// $Id$ +// +/* -*- c++ -*- */ +// ============================================================================ +// +// = LIBRARY +// TAO IDL +// +// = FILENAME +// serializer_op_ch.h +// +// = DESCRIPTION +// Concrete visitor for the base "BE_Union_Branch" node +// This generates TAO::DCPS::Serializer operators code for structure members +// in the client header. +// +// = AUTHOR +// Scott Harris based on code by Aniruddha Gokhale +// +// ============================================================================ + +#ifndef _BE_VISITOR_UNION_BRANCH_serializer_op_CH_H_ +#define _BE_VISITOR_UNION_BRANCH_serializer_op_CH_H_ + +class be_visitor_union_branch_serializer_op_ch : public be_visitor_decl +{ + // + // = TITLE + // be_visitor_serializer_op_ch + // + // = DESCRIPTION + // This is a concrete visitor for the be_union_branch node for the client header. + // +public: + be_visitor_union_branch_serializer_op_ch (be_visitor_context *ctx); + // constructor + + ~be_visitor_union_branch_serializer_op_ch (void); + // destructor + + virtual int visit_union_branch (be_union_branch *node); + // visit the union_branch node + + // =visit operations on all possible data types that a union_branch can be + + virtual int visit_array (be_array *node); + // visit array type + + virtual int visit_enum (be_enum *node); + // visit enum type + + virtual int visit_sequence (be_sequence *node); + // visit sequence type + + virtual int visit_structure (be_structure *node); + // visit structure type + + virtual int visit_typedef (be_typedef *node); + // visit typedefed type + + virtual int visit_union (be_union *node); + // visit union type + +}; + +#endif /* _BE_VISITOR_UNION_BRANCH_serializer_op_CH_H_ */ diff --git a/TAO/TAO_IDL/be_include/be_visitor_union_branch/serializer_op_cs.h b/TAO/TAO_IDL/be_include/be_visitor_union_branch/serializer_op_cs.h new file mode 100644 index 00000000000..d03a521a842 --- /dev/null +++ b/TAO/TAO_IDL/be_include/be_visitor_union_branch/serializer_op_cs.h @@ -0,0 +1,64 @@ +// +// $Id$ +// +/* -*- c++ -*- */ +// ============================================================================ +// +// = LIBRARY +// TAO IDL +// +// = FILENAME +// serializer_op_cs.h +// +// = DESCRIPTION +// Concrete visitor for the base "BE_Union_Branch" node +// This generates TAO::DCPS::Serializer operators code for structure members +// in the client header. +// +// = AUTHOR +// Scott Harris based on code by Aniruddha Gokhale +// +// ============================================================================ + +#ifndef _BE_VISITOR_UNION_BRANCH_serializer_op_CS_H_ +#define _BE_VISITOR_UNION_BRANCH_serializer_op_CS_H_ + +class be_visitor_union_branch_serializer_op_cs : public be_visitor_decl +{ + // + // = TITLE + // be_visitor_union_branch_serializer_op_cs + // + // = DESCRIPTION + // This is a concrete visitor for the be_union_branch node for the client header. + // +public: + be_visitor_union_branch_serializer_op_cs (be_visitor_context *ctx); + // constructor + + ~be_visitor_union_branch_serializer_op_cs (void); + // destructor + + virtual int visit_union_branch (be_union_branch *node); + // visit the union_branch node + + // =visit operations on all possible data types that a union_branch can be + + virtual int visit_array (be_array *node); + virtual int visit_enum (be_enum *node); + virtual int visit_interface (be_interface *node); + virtual int visit_interface_fwd (be_interface_fwd *node); + virtual int visit_valuetype (be_valuetype *node); + virtual int visit_valuetype_fwd (be_valuetype_fwd *node); + virtual int visit_predefined_type (be_predefined_type *node); + virtual int visit_sequence (be_sequence *node); + virtual int visit_string (be_string *node); + virtual int visit_structure (be_structure *node); + virtual int visit_typedef (be_typedef *node); + virtual int visit_union (be_union *node); + + virtual int explicit_default (void); + // extra code generation for an explicit default case +}; + +#endif /* _BE_VISITOR_UNION_BRANCH_serializer_op_CS_H_ */ -- cgit v1.2.1