diff options
Diffstat (limited to 'TAO/TAO_IDL/be/be_visitor_union')
-rw-r--r-- | TAO/TAO_IDL/be/be_visitor_union/any_op_ch.cpp | 102 | ||||
-rw-r--r-- | TAO/TAO_IDL/be/be_visitor_union/any_op_cs.cpp | 276 | ||||
-rw-r--r-- | TAO/TAO_IDL/be/be_visitor_union/cdr_op_ch.cpp | 75 | ||||
-rw-r--r-- | TAO/TAO_IDL/be/be_visitor_union/cdr_op_ci.cpp | 171 | ||||
-rw-r--r-- | TAO/TAO_IDL/be/be_visitor_union/cdr_op_cs.cpp | 64 | ||||
-rw-r--r-- | TAO/TAO_IDL/be/be_visitor_union/discriminant_ch.cpp | 142 | ||||
-rw-r--r-- | TAO/TAO_IDL/be/be_visitor_union/discriminant_ci.cpp | 215 | ||||
-rw-r--r-- | TAO/TAO_IDL/be/be_visitor_union/discriminant_cs.cpp | 88 | ||||
-rw-r--r-- | TAO/TAO_IDL/be/be_visitor_union/union.cpp | 122 | ||||
-rw-r--r-- | TAO/TAO_IDL/be/be_visitor_union/union_ch.cpp | 238 | ||||
-rw-r--r-- | TAO/TAO_IDL/be/be_visitor_union/union_ci.cpp | 160 | ||||
-rw-r--r-- | TAO/TAO_IDL/be/be_visitor_union/union_cs.cpp | 234 |
12 files changed, 0 insertions, 1887 deletions
diff --git a/TAO/TAO_IDL/be/be_visitor_union/any_op_ch.cpp b/TAO/TAO_IDL/be/be_visitor_union/any_op_ch.cpp deleted file mode 100644 index f743a905db8..00000000000 --- a/TAO/TAO_IDL/be/be_visitor_union/any_op_ch.cpp +++ /dev/null @@ -1,102 +0,0 @@ -// -// $Id$ -// - -// ============================================================================ -// -// = LIBRARY -// TAO IDL -// -// = FILENAME -// any_op_ch.cpp -// -// = DESCRIPTION -// Visitor generating code for Any operators for Union. -// -// = AUTHOR -// Aniruddha Gokhale -// -// ============================================================================ - -#include "idl.h" -#include "idl_extern.h" -#include "be.h" - -#include "be_visitor_union.h" - -ACE_RCSID(be_visitor_union, any_op_ch, "$Id$") - - -// *************************************************************************** -// Union visitor for generating Any operator declarations in the client header -// *************************************************************************** - -be_visitor_union_any_op_ch::be_visitor_union_any_op_ch -(be_visitor_context *ctx) - : be_visitor_union (ctx) -{ -} - -be_visitor_union_any_op_ch::~be_visitor_union_any_op_ch (void) -{ -} - -int -be_visitor_union_any_op_ch::visit_union (be_union *node) -{ - if (node->cli_hdr_any_op_gen () || node->imported ()) - return 0; - - TAO_OutStream *os = this->ctx_->stream (); - - // generate the Any <<= and >>= operator declarations - os->indent (); - *os << "void " << idl_global->export_macro () - << " operator<<= (CORBA::Any &, const " << node->name () - << " &); // copying version" << be_nl; - *os << "void " << idl_global->export_macro () - << " operator<<= (CORBA::Any &, " << node->name () - << "*); // noncopying version" << be_nl; - *os << "CORBA::Boolean " << idl_global->export_macro () - << " operator>>= (const CORBA::Any &, " - << node->name () << " *&);\n"; - - - // all we have to do is to visit the scope and generate code - if (this->visit_scope (node) == -1) - { - ACE_ERROR_RETURN ((LM_ERROR, - "(%N:%l) be_visitor_union::visit_union - " - "codegen for scope failed\n"), -1); - } - - node->cli_hdr_any_op_gen (1); - return 0; -} - -int -be_visitor_union_any_op_ch::visit_union_branch (be_union_branch *node) -{ - be_type *bt; // field's type - - // first generate the type information - bt = be_type::narrow_from_decl (node->field_type ()); - if (!bt) - { - ACE_ERROR_RETURN ((LM_ERROR, - "(%N:%l) be_visitor_union_any_op_ch::" - "visit_union_branch - " - "Bad field type\n" - ), -1); - } - - if (bt->accept (this) == -1) - { - ACE_ERROR_RETURN ((LM_ERROR, - "(%N:%l) be_visitor_union_any_op_ch::" - "visit_field - " - "codegen for field type failed\n" - ), -1); - } - return 0; -} diff --git a/TAO/TAO_IDL/be/be_visitor_union/any_op_cs.cpp b/TAO/TAO_IDL/be/be_visitor_union/any_op_cs.cpp deleted file mode 100644 index 8287b104719..00000000000 --- a/TAO/TAO_IDL/be/be_visitor_union/any_op_cs.cpp +++ /dev/null @@ -1,276 +0,0 @@ -// -// $Id$ -// - -// ============================================================================ -// -// = LIBRARY -// TAO IDL -// -// = FILENAME -// any_op_cs.cpp -// -// = DESCRIPTION -// Visitor generating code for Any operators for Union. -// -// = AUTHOR -// Aniruddha Gokhale -// -// ============================================================================ - -#include "idl.h" -#include "idl_extern.h" -#include "be.h" - -#include "be_visitor_union.h" - -ACE_RCSID(be_visitor_union, any_op_cs, "$Id$") - - -// *************************************************************************** -// Union visitor for generating Any operator declarations in the client -// stubs file -// *************************************************************************** - -be_visitor_union_any_op_cs::be_visitor_union_any_op_cs -(be_visitor_context *ctx) - : be_visitor_union (ctx) -{ -} - -be_visitor_union_any_op_cs::~be_visitor_union_any_op_cs (void) -{ -} - -int -be_visitor_union_any_op_cs::visit_union (be_union *node) -{ - if (node->cli_stub_any_op_gen () || node->imported ()) - return 0; - - TAO_OutStream *os = this->ctx_->stream (); - - // generate the Any <<= and >>= operator declarations - os->indent (); - *os << "void operator<<= (" << be_idt << be_idt_nl - << "CORBA::Any &_tao_any," << be_nl - << "const " << node->name () << " &_tao_elem" << be_uidt_nl - << ")" << be_uidt_nl - << "{" << be_idt_nl - << node->name () << " *_any_val;" << be_nl - << "ACE_NEW (_any_val, " << node->name () << " (_tao_elem));" - << be_nl - << "ACE_TRY_NEW_ENV" << be_nl - << "{" << be_idt_nl; - - if (this->gen_insertion (os, node) != 0) - return -1; - - *os << "}" << be_nl - << "ACE_CATCHANY" << be_nl - << "{" << be_idt_nl - << "delete _any_val;" << be_uidt_nl - << "}" << be_nl - << "ACE_ENDTRY;" << be_uidt_nl - << "}\n" << be_nl; - - *os << "void operator<<= (" << be_idt << be_idt_nl - << "CORBA::Any &_tao_any," << be_nl - << node->name () << " *_tao_elem" << be_uidt_nl - << ")" << be_uidt_nl - << "{" << be_idt_nl - << "ACE_TRY_NEW_ENV" << be_nl - << "{" << be_idt_nl; - - if (this->gen_insertion_nocopy (os, node) != 0) - return -1; - - *os << "}" << be_nl - << "ACE_CATCHANY {}" << be_nl - << "ACE_ENDTRY;" << be_uidt_nl - << "}\n" << be_nl; - - *os << "CORBA::Boolean operator>>= (" << be_idt << be_idt_nl - << "const CORBA::Any &_tao_any," << be_nl - << node->name () << " *&_tao_elem" << be_uidt_nl - << ")" << be_uidt_nl - << "{" << be_idt_nl - << "ACE_TRY_NEW_ENV" << be_nl - << "{" << be_idt_nl - << "CORBA::TypeCode_var type = _tao_any.type ();" << be_nl - << "if (!type->equal (" << node->tc_name () - << ", ACE_TRY_ENV))" << be_idt_nl - << "return 0;" << be_uidt_nl - << "ACE_TRY_CHECK;" << be_nl - << "if (_tao_any.any_owns_data ())" << be_nl - << "{" << be_idt_nl - << "_tao_elem = (" << node->name () << " *)_tao_any.value ();" - << be_nl - << "return 1;" << be_uidt_nl - << "}" << be_nl - << "else" << be_nl // else any does not own the data - << "{" << be_idt_nl - << "ACE_NEW_RETURN (_tao_elem, " << node->name () << ", 0);" - << be_nl - << "TAO_InputCDR stream (_tao_any._tao_get_cdr ());" << be_nl; - - if (this->gen_extraction (os, node) != 0) - return -1; - - *os << be_nl - << "return 1;" << be_uidt_nl - << "}" << be_uidt_nl - << "}" << be_nl - << "ACE_CATCHANY" << be_nl - << "{" << be_idt_nl - << "delete _tao_elem;" << be_uidt_nl - << "}" << be_nl - << "ACE_ENDTRY;" << be_nl - << "return 0;" << be_uidt_nl - << "}\n\n"; - - - // all we have to do is to visit the scope and generate code - if (this->visit_scope (node) == -1) - { - ACE_ERROR_RETURN ((LM_ERROR, - "(%N:%l) be_visitor_union::visit_union - " - "codegen for scope failed\n"), -1); - } - - node->cli_stub_any_op_gen (1); - return 0; -} - -int -be_visitor_union_any_op_cs::visit_union_branch (be_union_branch *node) -{ - be_type *bt; // field's type - - // first generate the type information - bt = be_type::narrow_from_decl (node->field_type ()); - if (!bt) - { - ACE_ERROR_RETURN ((LM_ERROR, - "(%N:%l) be_visitor_union_any_op_cs::" - "visit_union_branch - " - "Bad field type\n" - ), -1); - } - - if (bt->accept (this) == -1) - { - ACE_ERROR_RETURN ((LM_ERROR, - "(%N:%l) be_visitor_union_any_op_cs::" - "visit_union_branch - " - "codegen for field type failed\n" - ), -1); - } - return 0; -} - -// **************************************************************** - -be_visitor_union_any_op_compiled_cs:: -be_visitor_union_any_op_compiled_cs (be_visitor_context *ctx) - : be_visitor_union_any_op_cs (ctx) -{ -} - -int -be_visitor_union_any_op_compiled_cs:: -gen_insertion (TAO_OutStream *os, - be_union *node) -{ - *os << "TAO_OutputCDR stream;" << be_nl - << "stream << *_any_val;" << be_nl - << "_tao_any._tao_replace (" << be_idt << be_idt_nl - << node->tc_name () << "," << be_nl - << "stream.begin ()," << be_nl - << "1," << be_nl - << "_any_val," << be_nl - << "ACE_TRY_ENV" << be_uidt_nl - << ");" << be_uidt_nl - << "ACE_TRY_CHECK;" << be_uidt_nl; - return 0; -} - -int -be_visitor_union_any_op_compiled_cs:: -gen_insertion_nocopy (TAO_OutStream *os, - be_union *node) -{ - *os << "TAO_OutputCDR stream;" << be_nl - << "stream << *_tao_elem;" << be_nl - << "_tao_any._tao_replace (" << be_idt << be_idt_nl - << node->tc_name () << "," << be_nl - << "stream.begin ()," << be_nl - << "1," << be_nl - << "_tao_elem," << be_nl - << "ACE_TRY_ENV" << be_uidt_nl - << ");" << be_uidt_nl - << "ACE_TRY_CHECK;" << be_uidt_nl; - return 0; -} - -int -be_visitor_union_any_op_compiled_cs:: -gen_extraction (TAO_OutStream *os, - be_union *node) -{ - *os << "stream >> *_tao_elem;" << be_nl - << "((CORBA::Any *)&_tao_any)->_tao_replace (" << be_idt << be_idt_nl - << node->tc_name () << "," << be_nl - << "1," << be_nl - << "ACE_reinterpret_cast(void*,_tao_elem)," << be_nl - << "ACE_TRY_ENV" << be_uidt_nl - << ");" << be_uidt_nl - << "ACE_TRY_CHECK;" << be_nl; - return 0; -} - -// **************************************************************** - -be_visitor_union_any_op_interpretive_cs:: -be_visitor_union_any_op_interpretive_cs (be_visitor_context *ctx) - : be_visitor_union_any_op_cs (ctx) -{ -} - -int -be_visitor_union_any_op_interpretive_cs:: -gen_insertion (TAO_OutStream *os, - be_union *node) -{ - *os << "_tao_any.replace (" << node->tc_name () - << ", _any_val, 1, ACE_TRY_ENV);" << " // copy the value" << be_nl - << "ACE_TRY_CHECK;" << be_uidt_nl; - return 0; -} - -int -be_visitor_union_any_op_interpretive_cs:: -gen_insertion_nocopy (TAO_OutStream *os, - be_union *node) -{ - *os << "_tao_any.replace (" << node->tc_name () << ", " - << "_tao_elem, 1, ACE_TRY_ENV); // consume it" << be_nl - << "ACE_TRY_CHECK;" << be_uidt_nl; - return 0; -} - -int -be_visitor_union_any_op_interpretive_cs:: -gen_extraction (TAO_OutStream *os, - be_union *node) -{ - *os << "if (stream.decode (" << node->tc_name () - << ", _tao_elem, 0, ACE_TRY_ENV)" << be_nl - << " == CORBA::TypeCode::TRAVERSE_CONTINUE)" << be_nl - << "{" << be_idt_nl - << "((CORBA::Any *)&_tao_any)->replace (" - << node->tc_name () << ", _tao_elem, 1, ACE_TRY_ENV);" << be_nl - << "ACE_TRY_CHECK;" << be_uidt_nl - << "}"; - return 0; -} diff --git a/TAO/TAO_IDL/be/be_visitor_union/cdr_op_ch.cpp b/TAO/TAO_IDL/be/be_visitor_union/cdr_op_ch.cpp deleted file mode 100644 index 01173b46b6d..00000000000 --- a/TAO/TAO_IDL/be/be_visitor_union/cdr_op_ch.cpp +++ /dev/null @@ -1,75 +0,0 @@ -// -// $Id$ -// - -// ============================================================================ -// -// = LIBRARY -// TAO IDL -// -// = FILENAME -// cdr_op_ch.cpp -// -// = DESCRIPTION -// Visitor generating code for CDR operators for unions. This uses -// compiled marshaling. -// -// = AUTHOR -// Aniruddha Gokhale -// -// ============================================================================ - -#include "idl.h" -#include "idl_extern.h" -#include "be.h" - -#include "be_visitor_union.h" - -ACE_RCSID(be_visitor_union, cdr_op_ch, "$Id$") - -// *************************************************************************** -// Union visitor for generating CDR operator declarations in the client header -// *************************************************************************** - -be_visitor_union_cdr_op_ch::be_visitor_union_cdr_op_ch -(be_visitor_context *ctx) - : be_visitor_union (ctx) -{ -} - -be_visitor_union_cdr_op_ch::~be_visitor_union_cdr_op_ch (void) -{ -} - -int -be_visitor_union_cdr_op_ch::visit_union (be_union *node) -{ - if (node->cli_hdr_cdr_op_gen () || node->imported ()) - return 0; - - TAO_OutStream *os = this->ctx_->stream (); - - // generate the CDR << and >> operator declarations - os->indent (); - *os << "CORBA::Boolean " << idl_global->export_macro () - << " operator<< (TAO_OutputCDR &, const " << node->name () - << " &); // " << be_nl; - *os << "CORBA::Boolean " << idl_global->export_macro () - << " operator>> (TAO_InputCDR &, " - << node->name () << " &);\n"; - - - // set the substate as generating code for the types defined in our scope - this->ctx_->sub_state(TAO_CodeGen::TAO_CDR_SCOPE); - // all we have to do is to visit the scope and generate code - if (this->visit_scope (node) == -1) - { - ACE_ERROR_RETURN ((LM_ERROR, - "(%N:%l) be_visitor_union_cdr_op_ch::" - "visit_union - " - "codegen for scope failed\n"), -1); - } - - node->cli_hdr_cdr_op_gen (1); - return 0; -} diff --git a/TAO/TAO_IDL/be/be_visitor_union/cdr_op_ci.cpp b/TAO/TAO_IDL/be/be_visitor_union/cdr_op_ci.cpp deleted file mode 100644 index 969d4216d9b..00000000000 --- a/TAO/TAO_IDL/be/be_visitor_union/cdr_op_ci.cpp +++ /dev/null @@ -1,171 +0,0 @@ -// -// $Id$ -// - -// ============================================================================ -// -// = LIBRARY -// TAO IDL -// -// = FILENAME -// cdr_op_ci.cpp -// -// = DESCRIPTION -// Visitor generating code for CDR operators for unions -// -// = AUTHOR -// Aniruddha Gokhale -// -// ============================================================================ - -#include "idl.h" -#include "idl_extern.h" -#include "be.h" - -#include "be_visitor_union.h" - -ACE_RCSID(be_visitor_union, cdr_op_ci, "$Id$") - -// *************************************************************************** -// Union visitor for generating CDR operator declarations in the client -// stubs file -// *************************************************************************** - -be_visitor_union_cdr_op_ci::be_visitor_union_cdr_op_ci -(be_visitor_context *ctx) - : be_visitor_union (ctx) -{ -} - -be_visitor_union_cdr_op_ci::~be_visitor_union_cdr_op_ci (void) -{ -} - -int -be_visitor_union_cdr_op_ci::visit_union (be_union *node) -{ - // already generated and/or we are imported. Don't do anything. - if (node->cli_inline_cdr_op_gen () || node->imported ()) - return 0; - - // set the substate as generating code for the types defined in our scope - this->ctx_->sub_state(TAO_CodeGen::TAO_CDR_SCOPE); - // all we have to do is to visit the scope and generate code - if (this->visit_scope (node) == -1) - { - ACE_ERROR_RETURN ((LM_ERROR, - "(%N:%l) be_visitor_union_cdr_op_ci" - "::visit_union - " - "codegen for scope failed\n"), -1); - } - - TAO_OutStream *os = this->ctx_->stream (); - - // set the sub state as generating code for the output operator - this->ctx_->sub_state(TAO_CodeGen::TAO_CDR_OUTPUT); - - *os << "ACE_INLINE CORBA::Boolean operator<< (" << be_idt << be_idt_nl - << "TAO_OutputCDR &strm," << be_nl - << "const " << node->name () << " &_tao_union" << be_uidt_nl - << ")" << be_uidt_nl - << "{" << be_idt_nl - << "if (!(strm << _tao_union._d ()))" << be_idt_nl - << "return 0;" << be_uidt_nl - << "CORBA::Boolean result = 0;" << be_nl - << "switch (_tao_union._d ())" << be_nl - << "{" << be_idt_nl; - - if (this->visit_scope (node) == -1) - { - ACE_ERROR_RETURN ((LM_ERROR, - "(%N:%l) be_visitor_union_cdr_op_ci::" - "visit_union - " - "codegen for scope failed\n"), -1); - } - *os << be_uidt_nl << "}" << be_nl - << "return result;" << be_uidt_nl - << "}\n\n"; - - // set the substate as generating code for the input operator - this->ctx_->sub_state(TAO_CodeGen::TAO_CDR_INPUT); - *os << "ACE_INLINE CORBA::Boolean operator>> (" << be_idt << be_idt_nl - << "TAO_InputCDR &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->fullname () - << " " << "_tao_discriminant;" << be_nl - << "if ( !(strm >> _tao_discriminant) )" << be_idt_nl - << "return 0;" << be_uidt_nl - << "CORBA::Boolean result = 0;" << be_nl - << "switch (_tao_discriminant)" << be_nl - << "{" << be_idt_nl; - - if (this->visit_scope (node) == -1) - { - ACE_ERROR_RETURN ((LM_ERROR, - "(%N:%l) be_visitor_union_cdr_op_ci::" - "visit_union - " - "codegen for scope failed\n"), -1); - } - - *os << be_uidt_nl << "}" << be_nl - << "return result;" << be_uidt_nl - << "}\n\n"; - - node->cli_inline_cdr_op_gen (1); - return 0; -} - -int -be_visitor_union_cdr_op_ci::pre_process (be_decl *bd) -{ - if (this->ctx_->sub_state () == TAO_CodeGen::TAO_CDR_SCOPE) - return 0; - - TAO_OutStream *os = this->ctx_->stream (); - - be_union_branch* b = - be_union_branch::narrow_from_decl (bd); - - 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; - return 0; -} - -int -be_visitor_union_cdr_op_ci::post_process (be_decl *) -{ - if (this->ctx_->sub_state () == TAO_CodeGen::TAO_CDR_SCOPE) - return 0; - - TAO_OutStream *os = this->ctx_->stream (); - - *os << be_uidt_nl << "}" << be_nl - << "break;" << be_uidt_nl; - - return 0; -} diff --git a/TAO/TAO_IDL/be/be_visitor_union/cdr_op_cs.cpp b/TAO/TAO_IDL/be/be_visitor_union/cdr_op_cs.cpp deleted file mode 100644 index f62a2206f04..00000000000 --- a/TAO/TAO_IDL/be/be_visitor_union/cdr_op_cs.cpp +++ /dev/null @@ -1,64 +0,0 @@ -// -// $Id$ -// - -// ============================================================================ -// -// = LIBRARY -// TAO IDL -// -// = FILENAME -// cdr_op_cs.cpp -// -// = DESCRIPTION -// Visitor generating code for CDR operators for unions -// -// = AUTHOR -// Aniruddha Gokhale -// -// ============================================================================ - -#include "idl.h" -#include "idl_extern.h" -#include "be.h" - -#include "be_visitor_union.h" - -ACE_RCSID(be_visitor_union, cdr_op_cs, "$Id$") - -// *************************************************************************** -// Union visitor for generating CDR operator declarations in the client -// stubs file -// *************************************************************************** - -be_visitor_union_cdr_op_cs::be_visitor_union_cdr_op_cs -(be_visitor_context *ctx) - : be_visitor_union (ctx) -{ -} - -be_visitor_union_cdr_op_cs::~be_visitor_union_cdr_op_cs (void) -{ -} - -int -be_visitor_union_cdr_op_cs::visit_union (be_union *node) -{ - // already generated and/or we are imported. Don't do anything. - if (node->cli_stub_cdr_op_gen () || node->imported ()) - return 0; - - // set the substate as generating code for the types defined in our scope - this->ctx_->sub_state(TAO_CodeGen::TAO_CDR_SCOPE); - // all we have to do is to visit the scope and generate code - if (this->visit_scope (node) == -1) - { - ACE_ERROR_RETURN ((LM_ERROR, - "(%N:%l) be_visitor_union_cdr_op_cs" - "::visit_union - " - "codegen for scope failed\n"), -1); - } - - node->cli_stub_cdr_op_gen (1); - return 0; -} diff --git a/TAO/TAO_IDL/be/be_visitor_union/discriminant_ch.cpp b/TAO/TAO_IDL/be/be_visitor_union/discriminant_ch.cpp deleted file mode 100644 index 66c3002b440..00000000000 --- a/TAO/TAO_IDL/be/be_visitor_union/discriminant_ch.cpp +++ /dev/null @@ -1,142 +0,0 @@ -// -// $Id$ -// - -// ============================================================================ -// -// = LIBRARY -// TAO IDL -// -// = FILENAME -// discriminant_ch.cpp -// -// = DESCRIPTION -// Visitor generating code for discriminant of the Union -// -// = AUTHOR -// Aniruddha Gokhale -// -// ============================================================================ - -#include "idl.h" -#include "idl_extern.h" -#include "be.h" - -#include "be_visitor_union.h" - -ACE_RCSID(be_visitor_union, discriminant_ch, "$Id$") - - -// ************************************************************************* -// be_visitor_discriminant_ch - visitor for discriminant in client header file -// ************************************************************************* - -be_visitor_union_discriminant_ch::be_visitor_union_discriminant_ch -(be_visitor_context *ctx) - : be_visitor_decl (ctx) -{ -} - -be_visitor_union_discriminant_ch::~be_visitor_union_discriminant_ch (void) -{ -} - -int -be_visitor_union_discriminant_ch::visit_enum (be_enum *node) -{ - TAO_OutStream *os; // output stream - be_union *bu = - this->ctx_->be_node_as_union (); // get the enclosing union backend - be_type *bt; - - // check if we are visiting this node via a visit to a typedef node - if (this->ctx_->alias ()) - bt = this->ctx_->alias (); - else - bt = node; - - os = this->ctx_->stream (); - - if (bt->node_type () != AST_Decl::NT_typedef // not a typedef - && bt->is_child (bu)) // bt is defined inside the union - { - // 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 enum declaration - ctx.state (TAO_CodeGen::TAO_ENUM_CH); - be_visitor *visitor = tao_cg->make_visitor (&ctx); - if (!visitor) - { - ACE_ERROR_RETURN ((LM_ERROR, - "(%N:%l) be_visitor_union_discriminant_ch::" - "visit_enum - " - "Bad visitor\n" - ), -1); - } - if (node->accept (visitor) == -1) - { - ACE_ERROR_RETURN ((LM_ERROR, - "(%N:%l) be_visitor_union_discriminant_ch::" - "visit_enum - " - "codegen failed\n" - ), -1); - } - delete visitor; - } - - os->indent (); - // the set method - *os << "void _d (" << bt->nested_type_name (bu) << ");" << be_nl; - // the get method - *os << bt->nested_type_name (bu) << " _d (void) const;\n\n"; - return 0; -} - -int -be_visitor_union_discriminant_ch::visit_predefined_type (be_predefined_type - *node) -{ - TAO_OutStream *os; // output stream - be_union *bu = - this->ctx_->be_node_as_union (); // get the enclosing union backend - be_type *bt; - - // check if we are visiting this node via a visit to a typedef node - if (this->ctx_->alias ()) - bt = this->ctx_->alias (); - else - bt = node; - - os = this->ctx_->stream (); - - os->indent (); - // the set method - *os << "void _d (" << bt->nested_type_name (bu) << ");" << be_nl; - // the get method - *os << bt->nested_type_name (bu) << " _d (void) const;\n\n"; - return 0; -} - -int -be_visitor_union_discriminant_ch::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 || (bt->accept (this) == -1)) - { - ACE_ERROR_RETURN ((LM_ERROR, - "(%N:%l) be_visitor_union_discriminant_ch::" - "visit_typedef - " - "Bad primitive type\n" - ), -1); - } - this->ctx_->alias (0); - return 0; -} diff --git a/TAO/TAO_IDL/be/be_visitor_union/discriminant_ci.cpp b/TAO/TAO_IDL/be/be_visitor_union/discriminant_ci.cpp deleted file mode 100644 index 100c54c65c3..00000000000 --- a/TAO/TAO_IDL/be/be_visitor_union/discriminant_ci.cpp +++ /dev/null @@ -1,215 +0,0 @@ -// -// $Id$ -// - -// ============================================================================ -// -// = LIBRARY -// TAO IDL -// -// = FILENAME -// discriminant_ci.cpp -// -// = DESCRIPTION -// Visitor generating code for discriminant of the union. -// -// = AUTHOR -// Aniruddha Gokhale -// -// ============================================================================ - -#include "idl.h" -#include "idl_extern.h" -#include "be.h" - -#include "be_visitor_union.h" - -ACE_RCSID(be_visitor_union, discriminant_ci, "$Id$") - - -// ************************************************************************* -// be_visitor_discriminant_ci - visitor for discriminant in client inline file -// ************************************************************************* - -be_visitor_union_discriminant_ci::be_visitor_union_discriminant_ci -(be_visitor_context *ctx) - : be_visitor_decl (ctx) -{ -} - -be_visitor_union_discriminant_ci::~be_visitor_union_discriminant_ci (void) -{ -} - -int -be_visitor_union_discriminant_ci::visit_enum (be_enum *node) -{ - TAO_OutStream *os; // output stream - be_union *bu = - this->ctx_->be_node_as_union (); // get the enclosing union backend - be_type *bt; - - // check if we are visiting this node via a visit to a typedef node - if (this->ctx_->alias ()) - bt = this->ctx_->alias (); - else - bt = node; - - os = this->ctx_->stream (); - - // now check if we need to generate the _default () method - be_union::DefaultValue dv; - if (bu->default_value (dv) == -1) - { - ACE_ERROR_RETURN ((LM_ERROR, - "(%N:%l) be_visitor_union_discriminant_ci::" - "visit_enum - " - "computing default value failed\n"), - -1); - } - if ((dv.computed_ != 0) && (bu->default_index () == -1)) - { - // only if all cases are not covered AND there is no explicit - // default, we get the _default () method - os->indent (); - *os << "// the implicit _default () method" << be_nl; - *os << "ACE_INLINE void " << be_nl - << bu->name () << "::_default ()" << be_nl - << "{" << be_idt_nl - << "this->disc_ = "; - switch (bu->udisc_type ()) - { - case AST_Expression::EV_short: - *os << dv.u.short_val; - break; - case AST_Expression::EV_ushort: - *os << dv.u.ushort_val; - break; - case AST_Expression::EV_long: - *os << dv.u.long_val; - break; - case AST_Expression::EV_ulong: - *os << dv.u.ulong_val; - break; - case AST_Expression::EV_char: - os->print ("%d", dv.u.char_val); - break; - case AST_Expression::EV_bool: - *os << dv.u.bool_val; - break; - case AST_Expression::EV_any: - // The discriminant is an enum. Some compilers will - // not accept a numeric value assigned to this - // discriminant, so we must generate the string name. - { - be_type* dt = - be_type::narrow_from_decl (bu->disc_type ()); - if (dt == 0) - return -1; - - // Find where was the enum defined, if it was defined in the globa - // scope, then it is easy to generate the enum values.... - be_scope* scope = - be_scope::narrow_from_scope (dt->defined_in ()); - if (scope == 0) - { - *os << node->value_to_name (dv.u.enum_val); - return 0; - } - - // The function value_to_name() takes care of adding - // any necessary scoping to the output. - *os << node->value_to_name (dv.u.enum_val); - break; - } - case AST_Expression::EV_longlong: - case AST_Expression::EV_ulonglong: - // unimplemented - default: - // error caught earlier. - ACE_ERROR_RETURN ((LM_ERROR, - "(%N:%l) be_visitor_union_discriminant_ci::" - "visit_enum - " - "bad or unimplemented discriminant type\n"), - -1); - } - *os << ";" << be_uidt_nl << "}\n\n"; - } - - os->indent (); - // the set method - *os << "// accessor to set the discriminant" << be_nl - << "ACE_INLINE void" << be_nl - << bu->name () << "::_d (" << bt->name () - << " discval)" << be_nl - << "{" << be_idt_nl - << "this->disc_ = discval;" << be_uidt_nl - << "}" << be_nl; - - // the get method - *os << "// accessor to get the discriminant" << be_nl - << "ACE_INLINE " << bt->name () << be_nl - << bu->name () << "::_d (void) const" << be_nl - << "{" << be_idt_nl - << "return this->disc_;" << be_uidt_nl - << "}\n\n"; - return 0; -} - -int -be_visitor_union_discriminant_ci::visit_predefined_type (be_predefined_type - *node) -{ - TAO_OutStream *os; // output stream - be_union *bu = - this->ctx_->be_node_as_union (); // get the enclosing union backend - be_type *bt; - - // check if we are visiting this node via a visit to a typedef node - if (this->ctx_->alias ()) - bt = this->ctx_->alias (); - else - bt = node; - - os = this->ctx_->stream (); - - os->indent (); - // the set method - *os << "// accessor to set the discriminant" << be_nl - << "ACE_INLINE void" << be_nl - << bu->name () << "::_d (" << bt->name () - << " discval)" << be_nl - << "{" << be_idt_nl - << "this->disc_ = discval;" << be_uidt_nl - << "}" << be_nl; - - // the get method - *os << "// accessor to get the discriminant" << be_nl - << "ACE_INLINE " << bt->name () << be_nl - << bu->name () << "::_d (void) const" << be_nl - << "{" << be_idt_nl - << "return this->disc_;" << be_uidt_nl - << "}\n\n"; - return 0; -} - -int -be_visitor_union_discriminant_ci::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 || (bt->accept (this) == -1)) - { - ACE_ERROR_RETURN ((LM_ERROR, - "(%N:%l) be_visitor_union_discriminant_ci::" - "visit_typedef - " - "Bad primitive type\n" - ), -1); - } - this->ctx_->alias (0); - - return 0; -} diff --git a/TAO/TAO_IDL/be/be_visitor_union/discriminant_cs.cpp b/TAO/TAO_IDL/be/be_visitor_union/discriminant_cs.cpp deleted file mode 100644 index 79f75f66a28..00000000000 --- a/TAO/TAO_IDL/be/be_visitor_union/discriminant_cs.cpp +++ /dev/null @@ -1,88 +0,0 @@ -// -// $Id$ -// - -// ============================================================================ -// -// = LIBRARY -// TAO IDL -// -// = FILENAME -// discriminant_cs.cpp -// -// = DESCRIPTION -// Visitor generating code for discriminant of the union -// -// = AUTHOR -// Aniruddha Gokhale -// -// ============================================================================ - -#include "idl.h" -#include "idl_extern.h" -#include "be.h" - -#include "be_visitor_union.h" - -ACE_RCSID(be_visitor_union, discriminant_cs, "$Id$") - - -// ************************************************************************* -// be_visitor_discriminant_cs - visitor for discriminant in client stubs -// ************************************************************************* - -be_visitor_union_discriminant_cs::be_visitor_union_discriminant_cs -(be_visitor_context *ctx) - : be_visitor_decl (ctx) -{ -} - -be_visitor_union_discriminant_cs::~be_visitor_union_discriminant_cs (void) -{ -} - -int -be_visitor_union_discriminant_cs::visit_enum (be_enum *node) -{ - be_union *bu = - this->ctx_->be_node_as_union (); // get the enclosing union backend - be_type *bt; - - // check if we are visiting this node via a visit to a typedef node - if (this->ctx_->alias ()) - bt = this->ctx_->alias (); - else - bt = node; - - if (bt->node_type () != AST_Decl::NT_typedef // not a typedef - && bt->is_child (bu)) // bt is defined inside the union - { - // 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 - - // generate the typecode for the enum - ctx.state (TAO_CodeGen::TAO_ENUM_CS); - be_visitor *visitor = tao_cg->make_visitor (&ctx); - if (!visitor) - { - ACE_ERROR_RETURN ((LM_ERROR, - "(%N:%l) be_visitor_union_discriminant_cs::" - "visit_enum - " - "Bad visitor\n" - ), -1); - } - if (node->accept (visitor) == -1) - { - ACE_ERROR_RETURN ((LM_ERROR, - "(%N:%l) be_visitor_union_discriminant_cs::" - "visit_enum - " - "codegen failed\n" - ), -1); - } - delete visitor; - } - return 0; -} diff --git a/TAO/TAO_IDL/be/be_visitor_union/union.cpp b/TAO/TAO_IDL/be/be_visitor_union/union.cpp deleted file mode 100644 index 2b04aff5d46..00000000000 --- a/TAO/TAO_IDL/be/be_visitor_union/union.cpp +++ /dev/null @@ -1,122 +0,0 @@ -// -// $Id$ -// - -// ============================================================================ -// -// = LIBRARY -// TAO IDL -// -// = FILENAME -// union.cpp -// -// = DESCRIPTION -// Generic visitor generating code for Unions -// -// = AUTHOR -// Aniruddha Gokhale -// -// ============================================================================ - -#include "idl.h" -#include "idl_extern.h" -#include "be.h" - -#include "be_visitor_union.h" - -ACE_RCSID(be_visitor_union, union, "$Id$") - - -// generic struct visitor -be_visitor_union::be_visitor_union (be_visitor_context *ctx) - : be_visitor_scope (ctx) -{ -} - -be_visitor_union::~be_visitor_union (void) -{ -} - -// visit the Union node and its scope -int -be_visitor_union::visit_union (be_union *) -{ - return -1; // must be overriden -} - -int -be_visitor_union::visit_union_branch (be_union_branch *node) -{ - // 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 - - // this switch is acceptable rather than having derived visitors overriding - // this method and differing only in what state they set - - switch (this->ctx_->state ()) - { - case TAO_CodeGen::TAO_UNION_PUBLIC_CH: - ctx.state (TAO_CodeGen::TAO_UNION_PUBLIC_CH); - break; - case TAO_CodeGen::TAO_UNION_PRIVATE_CH: - ctx.state (TAO_CodeGen::TAO_UNION_PRIVATE_CH); - break; - case TAO_CodeGen::TAO_UNION_PUBLIC_CI: - ctx.state (TAO_CodeGen::TAO_UNION_PUBLIC_CI); - break; - case TAO_CodeGen::TAO_UNION_PUBLIC_CS: - ctx.state (TAO_CodeGen::TAO_UNION_PUBLIC_CS); - break; - case TAO_CodeGen::TAO_UNION_PUBLIC_ASSIGN_CS: - ctx.state (TAO_CodeGen::TAO_UNION_PUBLIC_ASSIGN_CS); - break; - case TAO_CodeGen::TAO_UNION_PUBLIC_RESET_CS: - ctx.state (TAO_CodeGen::TAO_UNION_PUBLIC_RESET_CS); - break; - case TAO_CodeGen::TAO_UNION_PUBLIC_ACCESS_CS: - ctx.state (TAO_CodeGen::TAO_UNION_PUBLIC_ACCESS_CS); - break; - case TAO_CodeGen::TAO_UNION_CDR_OP_CH: - ctx.state (TAO_CodeGen::TAO_UNION_BRANCH_CDR_OP_CH); - break; - case TAO_CodeGen::TAO_UNION_CDR_OP_CI: - ctx.state (TAO_CodeGen::TAO_UNION_BRANCH_CDR_OP_CI); - break; - case TAO_CodeGen::TAO_UNION_CDR_OP_CS: - ctx.state (TAO_CodeGen::TAO_UNION_BRANCH_CDR_OP_CS); - break; - default: - { - ACE_ERROR_RETURN ((LM_ERROR, - "(%N:%l) be_visitor_union::" - "visit_union_branch - " - "Bad context state\n" - ), -1); - } - } - - be_visitor *visitor = tao_cg->make_visitor (&ctx); - if (!visitor) - { - ACE_ERROR_RETURN ((LM_ERROR, - "(%N:%l) be_visitor_union::" - "visit_union_branch - " - "NUL visitor\n" - ), -1); - } - - // let the node accept this visitor - if (node->accept (visitor) == -1) - { - ACE_ERROR_RETURN ((LM_ERROR, - "(%N:%l) be_visitor_union::" - "visit_union_branch - " - "failed to accept visitor\n" - ), -1); - } - delete visitor; - return 0; -} diff --git a/TAO/TAO_IDL/be/be_visitor_union/union_ch.cpp b/TAO/TAO_IDL/be/be_visitor_union/union_ch.cpp deleted file mode 100644 index b3d8de89394..00000000000 --- a/TAO/TAO_IDL/be/be_visitor_union/union_ch.cpp +++ /dev/null @@ -1,238 +0,0 @@ -// -// $Id$ -// - -// ============================================================================ -// -// = LIBRARY -// TAO IDL -// -// = FILENAME -// union_ch.cpp -// -// = DESCRIPTION -// Visitor generating code for Unions in the client header -// -// = AUTHOR -// Aniruddha Gokhale -// -// ============================================================================ - -#include "idl.h" -#include "idl_extern.h" -#include "be.h" - -#include "be_visitor_union.h" - -ACE_RCSID(be_visitor_union, union_ch, "$Id$") - - -// ****************************************************** -// for client header -// ****************************************************** - -be_visitor_union_ch::be_visitor_union_ch (be_visitor_context *ctx) - : be_visitor_union (ctx) -{ -} - -be_visitor_union_ch::~be_visitor_union_ch (void) -{ -} - -// visit the Union node and its scope -int be_visitor_union_ch::visit_union (be_union *node) -{ - TAO_OutStream *os; // output stream - be_type *bt; // type node - // 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 - - - if (!node->cli_hdr_gen () && !node->imported ()) // not already generated and - // not imported - { - os = this->ctx_->stream (); - - // generate the ifdefined macro for the union type - os->gen_ifdef_macro (node->flatname ()); - os->indent (); // start with the current indentation level - *os << "class " << idl_global->export_macro () << " " - << node->local_name () << ": public TAO_Base_Union " << be_nl - << "{" << be_nl - << "public:" << be_idt_nl - - // generate default and copy constructors - << node->local_name () << " (void); // default constructor" << be_nl - << node->local_name () << " (const " << node->local_name () - << " &); // copy constructor" << be_nl - // generate destructor - << "~" << node->local_name () << " (void); // destructor" << be_nl - // generate assignment operator - << node->local_name () << " &operator= (const " - << node->local_name () << " &); // copy constructor\n\n"; - - // retrieve the disriminant type - bt = be_type::narrow_from_decl (node->disc_type ()); - if (!bt) - { - ACE_ERROR_RETURN ((LM_ERROR, - "(%N:%l) be_visitor_union_ch::" - "visit_union - " - "bad disciminant type\n"), -1); - } - - // the discriminant type may have to be defined here if it was an enum - // declaration inside of the union statement. - - ctx.state (TAO_CodeGen::TAO_UNION_DISCTYPEDEFN_CH); // set current code - // gen state - be_visitor *visitor = tao_cg->make_visitor (&ctx); - if (!visitor) - { - ACE_ERROR_RETURN ((LM_ERROR, - "(%N:%l) be_visitor_union_ch::" - "visit_union - " - "bad visitor\n"), -1); - } - - if (bt->accept (visitor) == -1) - { - ACE_ERROR_RETURN ((LM_ERROR, - "(%N:%l) be_visitor_union_ch::" - " visit_union - " - "codegen for discriminant failed\n"), -1); - } - delete visitor; - - // now generate the public defn for the union branch members. For this, - // set our state to reflect what we are aiming to do - this->ctx_->state (TAO_CodeGen::TAO_UNION_PUBLIC_CH); // set current code - // gen state - if (this->visit_scope (node) == -1) - { - ACE_ERROR_RETURN ((LM_ERROR, - "(%N:%l) be_visitor_union_ch::" - "visit_union - " - "codegen for public defn of union members\n"), - -1); - } - - // now check if we need to generate the _default () method - be_union::DefaultValue dv; - if (node->default_value (dv) == -1) - { - ACE_ERROR_RETURN ((LM_ERROR, - "(%N:%l) be_visitor_union_ch::" - "visit_union - " - "computing default value failed\n"), - -1); - } - if ((dv.computed_ != 0) && (node->default_index () == -1)) - { - // only if all cases are not covered AND there is no explicit - // default, we get the _default () method - os->indent (); - *os << "void _default ();\n"; - } - - // now generate the private data members of the union - os->decr_indent (); - *os << "private:\n"; - os->incr_indent (); - *os << bt->nested_type_name (node) << " disc_;" << be_nl; // emit the - // ACE_NESTED_CLASS macro - - // the members are inside of a union - *os << "union" << be_nl; - *os << "{\n"; - os->incr_indent (0); - this->ctx_->state (TAO_CodeGen::TAO_UNION_PRIVATE_CH); // set current - // code gen state - if (this->visit_scope (node) == -1) - { - ACE_ERROR_RETURN ((LM_ERROR, - "(%N:%l) be_visitor_union_ch::" - "visit_union - " - "codegen for private members of union\n"), -1); - } - - os->decr_indent (); - *os << "} u_; // end of union" << be_nl; - - // the reset method (TAO extension) - *os << "// TAO extensions" << be_nl; - *os << "void _reset (" << bt->nested_type_name (node) - << ", CORBA::Boolean);" << be_nl; - *os << "// Frees any allocated storage" << be_nl << be_nl; - // the virtual overloaded _discriminant method - *os << "virtual void *_discriminant (void);" << be_nl; - *os << "// returns pointer to the discriminant" << be_nl << be_nl; - // the overloaded virtual reset method - *os << "virtual void _reset (void);" << be_nl; - *os << "// calls the above reset with finalize=1" << be_nl << be_nl; - // the _access method - *os << "virtual void *_access (CORBA::Boolean flag);" << be_nl; - *os << "// accesses the right data member. " - << "Also will allocate on TRUE flag" << be_nl << be_uidt_nl; - *os << "}; // " << node->name () << "\n\n"; - - // by using a visitor to declare and define the TypeCode, we have the - // added advantage to conditionally not generate any code. This will be - // based on the command line options. This is still TO-DO - ctx = *this->ctx_; - ctx.state (TAO_CodeGen::TAO_TYPECODE_DECL); - visitor = tao_cg->make_visitor (&ctx); - if (!visitor || (node->accept (visitor) == -1)) - { - ACE_ERROR_RETURN ((LM_ERROR, - "(%N:%l) be_visitor_union_ch::" - "visit_union - " - "TypeCode declaration failed\n" - ), -1); - } - - - os->gen_endif (); - - // generate the ifdefined macro for the _var type - os->gen_ifdef_macro (node->flatname (), "_var"); - // generate var defn - if (node->gen_var_defn () == -1) - { - ACE_ERROR_RETURN ((LM_ERROR, - "(%N:%l) be_visitor_union_ch::" - "visit_union - " - "codegen for _var\n"), -1); - } - os->gen_endif (); - - // generate the ifdefined macro for the array type - os->gen_ifdef_macro (node->flatname (), "_out"); - // a class is generated for an out defn only for a variable length struct - if (node->size_type () == be_decl::VARIABLE) - { - if (node->gen_out_defn () == -1) - { - ACE_ERROR_RETURN ((LM_ERROR, - "(%N:%l) be_visitor_union_ch::" - "visit_union - " - "codegen for _out\n"), -1); - } - } - else - { - os->indent (); - *os << "typedef " << node->local_name () << " &" << node->local_name - () << "_out;\n\n"; - } - os->gen_endif (); - - node->cli_hdr_gen (I_TRUE); - } - - return 0; -} diff --git a/TAO/TAO_IDL/be/be_visitor_union/union_ci.cpp b/TAO/TAO_IDL/be/be_visitor_union/union_ci.cpp deleted file mode 100644 index 8790e6a339b..00000000000 --- a/TAO/TAO_IDL/be/be_visitor_union/union_ci.cpp +++ /dev/null @@ -1,160 +0,0 @@ -// -// $Id$ -// - -// ============================================================================ -// -// = LIBRARY -// TAO IDL -// -// = FILENAME -// union_ci.cpp -// -// = DESCRIPTION -// Visitor generating code for Union in the client inline file -// -// = AUTHOR -// Aniruddha Gokhale -// -// ============================================================================ - -#include "idl.h" -#include "idl_extern.h" -#include "be.h" - -#include "be_visitor_union.h" - -ACE_RCSID(be_visitor_union, union_ci, "$Id$") - - -// ****************************************************** -// for client inline -// ****************************************************** - -be_visitor_union_ci::be_visitor_union_ci (be_visitor_context *ctx) - : be_visitor_union (ctx) -{ -} - -be_visitor_union_ci::~be_visitor_union_ci (void) -{ -} - -// visit the Union node and its scope -int be_visitor_union_ci::visit_union (be_union *node) -{ - TAO_OutStream *os; // output stream - be_type *bt; // type node - // 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 - - - if (!node->cli_inline_gen () && !node->imported ()) - { - os = this->ctx_->stream (); - - *os << "// *************************************************************" - << be_nl; - *os << "// Inline operations for union " << node->name () << be_nl; - *os << "// *************************************************************\n\n"; - - // generate the default constructor and the destructor here - os->indent (); - *os << "// destructor" << be_nl - << "ACE_INLINE" << be_nl - << node->name () << "::~" << node->local_name () << " (void)" << be_nl - << "{" << be_idt_nl - << "// finalize" << be_nl - << "this->_reset (this->disc_, 1);" << be_uidt_nl - << "}" << be_nl << be_nl; - - // the virtual overloaded _reset method - *os << "// this reset method is used by the decoding engine" << be_nl; - *os << "ACE_INLINE void" << be_nl - << node->name () << "::_reset (void)" << be_nl - << "{" << be_idt_nl - << "this->_reset (this->disc_, 1);" << be_nl - << "ACE_OS::memcpy (&this->u_, 0, sizeof (this->u_));" << be_uidt_nl - << "}" << be_nl << be_nl; - - // the virtual overloaded _discriminant method - *os << "// returns pointer to the discriminant" << be_nl; - *os << "ACE_INLINE void *" << be_nl - << node->name () << "::_discriminant (void)" << be_nl - << "{" << be_idt_nl - << "return &this->disc_;" << be_uidt_nl - << "}\n\n"; - - // the discriminant type may have to be defined here if it was an enum - // declaration inside of the union statement. - - bt = be_type::narrow_from_decl (node->disc_type ()); - if (!bt) - { - ACE_ERROR_RETURN ((LM_ERROR, - "(%N:%l) be_visitor_union_ci::" - "visit_union - " - "bad discriminant type\n"), -1); - } - - ctx.state (TAO_CodeGen::TAO_UNION_DISCTYPEDEFN_CI); // set current code - // gen state - be_visitor *visitor = tao_cg->make_visitor (&ctx); - if (!visitor) - { - ACE_ERROR_RETURN ((LM_ERROR, - "(%N:%l) be_visitor_union_ci::" - "visit_union - " - "bad visitor\n"), -1); - } - // generate code for the discriminant - if (bt->accept (visitor) == -1) - { - ACE_ERROR_RETURN ((LM_ERROR, - "(%N:%l) be_visitor_union_ci::" - "visit union - " - "codegen for discrminant failed\n"), -1); - } - - // now generate the implementation of the access methods for the - // union. For this set our state - this->ctx_->state (TAO_CodeGen::TAO_UNION_PUBLIC_CI); - if (this->visit_scope (node) == -1) - { - ACE_ERROR_RETURN ((LM_ERROR, - "(%N:%l) be_visitor_union_ci::" - "visit_union - " - "codegen for scope failed\n"), -1); - } - - // generate the ifdefined macro for the array type - os->gen_ifdef_macro (node->flatname (), "_var"); - if (node->gen_var_impl () == -1) - { - ACE_ERROR_RETURN ((LM_ERROR, - "(%N:%l) be_visitor_union_ci::" - "visit_union - " - "codegen for _var failed\n"), -1); - } - os->gen_endif (); - - // generate the ifdefined macro for the array type then generate the _out - // impl - os->gen_ifdef_macro (node->flatname (), "_out"); - if (node->size_type () == be_decl::VARIABLE - && node->gen_out_impl () == -1) - { - ACE_ERROR_RETURN ((LM_ERROR, - "(%N:%l) be_visitor_union_ci::" - "visit_union - " - "codegen for _out failed\n"), -1); - } - os->gen_endif (); - - node->cli_inline_gen (I_TRUE); - } - return 0; -} diff --git a/TAO/TAO_IDL/be/be_visitor_union/union_cs.cpp b/TAO/TAO_IDL/be/be_visitor_union/union_cs.cpp deleted file mode 100644 index d739655b4f2..00000000000 --- a/TAO/TAO_IDL/be/be_visitor_union/union_cs.cpp +++ /dev/null @@ -1,234 +0,0 @@ -// -// $Id$ -// - -// ============================================================================ -// -// = LIBRARY -// TAO IDL -// -// = FILENAME -// union_cs.cpp -// -// = DESCRIPTION -// Visitor generating code for Unions in the client stubs -// -// = AUTHOR -// Aniruddha Gokhale -// -// ============================================================================ - -#include "idl.h" -#include "idl_extern.h" -#include "be.h" - -#include "be_visitor_union.h" - -ACE_RCSID(be_visitor_union, union_cs, "$Id$") - - -// ****************************************************** -// for client stubs -// ****************************************************** - -be_visitor_union_cs::be_visitor_union_cs (be_visitor_context *ctx) - : be_visitor_union (ctx) -{ -} - -be_visitor_union_cs::~be_visitor_union_cs (void) -{ -} - -// visit the Union_cs node and its scope -int be_visitor_union_cs::visit_union (be_union *node) -{ - TAO_OutStream *os; // output stream - be_type *bt; // for discriminant type - - if (!node->cli_stub_gen () && !node->imported ()) - { - os = this->ctx_->stream (); - - be_visitor_context ctx (*this->ctx_); - // the discriminant type may have to be defined here if it was an enum - // declaration inside of the union statement. We need to generate its - // typecode - - bt = be_type::narrow_from_decl (node->disc_type ()); - if (!bt) - { - ACE_ERROR_RETURN ((LM_ERROR, - "(%N:%l) be_visitor_union_cs::" - "visit_union - " - "bad discriminant type\n"), -1); - } - - ctx.state (TAO_CodeGen::TAO_UNION_DISCTYPEDEFN_CS); // set current code - // gen state - be_visitor *visitor = tao_cg->make_visitor (&ctx); - if (!visitor) - { - ACE_ERROR_RETURN ((LM_ERROR, - "(%N:%l) be_visitor_union_cs::" - "visit_union - " - "bad visitor\n"), -1); - } - // generate code for the discriminant - if (bt->accept (visitor) == -1) - { - ACE_ERROR_RETURN ((LM_ERROR, - "(%N:%l) be_visitor_union_cs::" - "visit union - " - "codegen for discrminant failed\n"), -1); - } - - // first generate code for any of the members (if required, e.g., - // anonymous sequences, structs, unions, arrays) - this->ctx_->state (TAO_CodeGen::TAO_UNION_PUBLIC_CS); // set current code - // gen state - if (this->visit_scope (node) == -1) - { - ACE_ERROR_RETURN ((LM_ERROR, - "(%N:%l) be_visitor_union_cs" - "visit_union - " - "codegen for scope failed\n"), -1); - } - - // now generate the operations on the union such as the copy constructor - // and the assignment operator - - *os << "// *************************************************************" - << be_nl; - *os << "// Operations for union " << node->name () << be_nl; - *os << "// *************************************************************\n\n"; - - // generate the copy constructor and the assignment operator here - os->indent (); - *os << "// default constructor" << be_nl - << node->name () << "::" << node->local_name () << " (void)" << be_nl - << " : TAO_Base_Union ()" << be_nl - << "{" << be_idt_nl - << "ACE_OS::memset (&this->disc_, 0, sizeof (this->disc_));" << be_nl - << "ACE_OS::memset (&this->u_, 0, sizeof (this->u_));" << be_uidt_nl - << "}" << be_nl << be_nl; - - this->ctx_->state (TAO_CodeGen::TAO_UNION_PUBLIC_ASSIGN_CS); - - *os << "// copy constructor" << be_nl; - *os << node->name () << "::" << node->local_name () - << " (const " << node->name () << " &u)" << be_nl - << " : TAO_Base_Union ()" << be_nl; - *os << "{" << be_idt_nl; - *os << "this->disc_ = u.disc_;" << be_nl; - // now switch based on the disc value - *os << "switch (this->disc_)" << be_nl; - *os << "{\n"; - os->incr_indent (0); - if (this->visit_scope (node) == -1) - { - ACE_ERROR_RETURN ((LM_ERROR, - "(%N:%l) be_visitor_union_cs" - "visit_union - " - "codegen for copy ctor failed\n"), -1); - } - - os->decr_indent (); - *os << "}\n"; - os->decr_indent (); - *os << "}\n\n"; - - this->ctx_->state (TAO_CodeGen::TAO_UNION_PUBLIC_ASSIGN_CS); - - // assignment operator - os->indent (); - *os << "// assignment operator" << be_nl; - *os << node->name () << " &" << be_nl; // return type - *os << node->name () << "::operator= (const " << - node->name () << " &u)" << be_nl; - *os << "{\n"; - os->incr_indent (); - // first reset and set the discriminant - *os << "this->_reset (u.disc_, 0);" << be_nl; - *os << "this->disc_ = u.disc_;" << be_nl; - // now switch based on the disc value - *os << "switch (this->disc_)" << be_nl; - *os << "{\n"; - os->incr_indent (0); - if (this->visit_scope (node) == -1) - { - ACE_ERROR_RETURN ((LM_ERROR, - "(%N:%l) be_visitor_union_cs" - "visit_union - " - "codegen for assign op failed\n"), -1); - } - - os->decr_indent (); - *os << "}" << be_nl; - *os << "return *this;\n"; - os->decr_indent (); - *os << "}\n\n"; - - // the reset method - this->ctx_->state (TAO_CodeGen::TAO_UNION_PUBLIC_RESET_CS); - os->indent (); - *os << "// reset method to reset old values of a union" << be_nl; - *os << "void " << node->name () << "::_reset (" << bt->name () - << ", CORBA::Boolean finalize)" << be_nl; - *os << "{" << be_idt_nl; - *os << "switch (this->disc_)" << be_nl; - *os << "{" << be_idt_nl; - if (this->visit_scope (node) == -1) - { - ACE_ERROR_RETURN ((LM_ERROR, - "(%N:%l) be_visitor_union_cs" - "visit_union - " - "codegen for reset failed\n"), -1); - } - - *os << be_uidt_nl << "}" << be_uidt_nl - << "}\n\n"; - - // the access method - os->indent (); - *os << "// the virtual overloaded access method" << be_nl; - *os << "void *" << node->name () << "::_access (" - << " CORBA::Boolean alloc_flag)" << be_nl; - *os << "{" << be_idt_nl; - *os << "switch (this->disc_)" << be_nl; - *os << "{" << be_idt_nl; - this->ctx_->state (TAO_CodeGen::TAO_UNION_PUBLIC_ACCESS_CS); - if (this->visit_scope (node) == -1) - { - ACE_ERROR_RETURN ((LM_ERROR, - "(%N:%l) be_visitor_union_cs" - "visit_union - " - "codegen for access failed\n"), -1); - } - - *os << be_uidt_nl << "}" << be_nl; - *os << "return 0; // default" << be_uidt_nl - << "}\n\n"; - - - // by using a visitor to declare and define the TypeCode, we have the - // added advantage to conditionally not generate any code. This will be - // based on the command line options. This is still TO-DO - ctx = *this->ctx_; - ctx.state (TAO_CodeGen::TAO_TYPECODE_DEFN); - ctx.sub_state (TAO_CodeGen::TAO_TC_DEFN_TYPECODE); - visitor = tao_cg->make_visitor (&ctx); - if (!visitor || (node->accept (visitor) == -1)) - { - ACE_ERROR_RETURN ((LM_ERROR, - "(%N:%l) be_visitor_union_cs::" - "visit_union - " - "TypeCode definition failed\n" - ), -1); - } - - - node->cli_stub_gen (I_TRUE); - } - return 0; -} |