diff options
Diffstat (limited to 'TAO/TAO_IDL/be/be_visitor_union_branch/private_ch.cpp')
-rw-r--r-- | TAO/TAO_IDL/be/be_visitor_union_branch/private_ch.cpp | 390 |
1 files changed, 390 insertions, 0 deletions
diff --git a/TAO/TAO_IDL/be/be_visitor_union_branch/private_ch.cpp b/TAO/TAO_IDL/be/be_visitor_union_branch/private_ch.cpp new file mode 100644 index 00000000000..d1b481f1aa2 --- /dev/null +++ b/TAO/TAO_IDL/be/be_visitor_union_branch/private_ch.cpp @@ -0,0 +1,390 @@ +// +// $Id$ +// + +// ============================================================================ +// +// = LIBRARY +// TAO IDL +// +// = FILENAME +// private_ch.cpp +// +// = DESCRIPTION +// Visitor generating code for Union branch for the private part of the +// class. +// +// = AUTHOR +// Aniruddha Gokhale +// +// ============================================================================ + +#include "idl.h" +#include "idl_extern.h" +#include "be.h" + +#include "be_visitor_union_branch.h" + + +// ********************************************** +// visitor for union_branch in the client header generating the private information +// ********************************************** + +// constructor +be_visitor_union_branch_private_ch::be_visitor_union_branch_private_ch (be_visitor_context *ctx) + : be_visitor_decl (ctx) +{ +} + +// destructor +be_visitor_union_branch_private_ch::~be_visitor_union_branch_private_ch (void) +{ +} + +// visit the union_branch node +int +be_visitor_union_branch_private_ch::visit_union_branch (be_union_branch *node) +{ + TAO_OutStream *os; + be_type *bt; // union_branch's type + + os = this->ctx_->stream (); + // 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_branch_cs::" + "visit_union_branch - " + "Bad union_branch type\n" + ), -1); + } + + this->ctx_->node (node); // save the node + if (bt->accept (this) == -1) + { + ACE_ERROR_RETURN ((LM_ERROR, + "(%N:%l) be_visitor_union_branch_cs::" + "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_private_ch::visit_array (be_array *node) +{ + TAO_OutStream *os; // output stream + be_decl *ub = this->ctx_->node (); // get union branch + be_decl *bu = this->ctx_->scope (); // 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 (!ub || !bu) + { + ACE_ERROR_RETURN ((LM_ERROR, + "(%N:%l) be_visitor_union_branch_private_ch::" + "visit_array - " + "bad context information\n" + ), -1); + } + + os = this->ctx_->stream (); + + os->indent (); + *os << bt->nested_type_name (bu, "_slice") << " *" << ub->local_name () + << "_;\n"; + return 0; +} + +int +be_visitor_union_branch_private_ch::visit_enum (be_enum *node) +{ + TAO_OutStream *os; // output stream + be_decl *ub = this->ctx_->node (); // get union branch + be_decl *bu = this->ctx_->scope (); // 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 (!ub || !bu) + { + ACE_ERROR_RETURN ((LM_ERROR, + "(%N:%l) be_visitor_union_branch_private_ch::" + "visit_enum - " + "bad context information\n" + ), -1); + } + + os = this->ctx_->stream (); + + os->indent (); // start from current indentation + *os << bt->nested_type_name (bu) << " " << ub->local_name () << "_;\n"; + return 0; +} + +int +be_visitor_union_branch_private_ch::visit_interface (be_interface *node) +{ + TAO_OutStream *os; // output stream + be_decl *ub = this->ctx_->node (); // get union branch + be_decl *bu = this->ctx_->scope (); // 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 (!ub || !bu) + { + ACE_ERROR_RETURN ((LM_ERROR, + "(%N:%l) be_visitor_union_branch_private_ch::" + "visit_interface - " + "bad context information\n" + ), -1); + } + + os = this->ctx_->stream (); + + os->indent (); // start from current indentation + // C++ does not allow an object declaration inside a union. Hence we + // must have a pointer. This changes some of the methods + *os << bt->nested_type_name (bu, "_ptr") << " " << ub->local_name () << + "_;\n"; + return 0; +} + +int +be_visitor_union_branch_private_ch::visit_interface_fwd (be_interface_fwd *node) +{ + TAO_OutStream *os; // output stream + be_decl *ub = this->ctx_->node (); // get union branch + be_decl *bu = this->ctx_->scope (); // 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 (!ub || !bu) + { + ACE_ERROR_RETURN ((LM_ERROR, + "(%N:%l) be_visitor_union_branch_private_ch::" + "visit_interface_fwd - " + "bad context information\n" + ), -1); + } + + os = this->ctx_->stream (); + + os->indent (); // start from current indentation + // C++ does not allow an object declaration inside a union. Hence we + // must have a pointer. This changes some of the methods + *os << bt->nested_type_name (bu, "_ptr") << " " << ub->local_name () << + "_;\n"; + return 0; +} + +int +be_visitor_union_branch_private_ch::visit_predefined_type (be_predefined_type *node) +{ + TAO_OutStream *os; // output stream + be_decl *ub = this->ctx_->node (); // get union branch + be_decl *bu = this->ctx_->scope (); // 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 (!ub || !bu) + { + ACE_ERROR_RETURN ((LM_ERROR, + "(%N:%l) be_visitor_union_branch_private_ch::" + "visit_predefined_type - " + "bad context information\n" + ), -1); + } + + os = this->ctx_->stream (); + + if (node->pt () == AST_PredefinedType::PT_pseudo) + { + // Cannot have an object inside of a union + os->indent (); // start from current indentation + *os << bt->nested_type_name (bu, "_ptr") << " " << ub->local_name () << + "_;\n"; + } + else + { + os->indent (); // start from current indentation + *os << bt->nested_type_name (bu) << " " << ub->local_name () << + "_;\n"; + } + return 0; +} + +int +be_visitor_union_branch_private_ch::visit_sequence (be_sequence *node) +{ + TAO_OutStream *os; // output stream + be_decl *ub = this->ctx_->node (); // get union branch + be_decl *bu = this->ctx_->scope (); // 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 (!ub || !bu) + { + ACE_ERROR_RETURN ((LM_ERROR, + "(%N:%l) be_visitor_union_branch_private_ch::" + "visit_sequence - " + "bad context information\n" + ), -1); + } + + os = this->ctx_->stream (); + + os->indent (); + // C++ doesn't allow object instances inside unions, so we need a + // pointer + *os << bt->nested_type_name (bu) << " *" << ub->local_name () << "_;\n"; + return 0; +} + +int +be_visitor_union_branch_private_ch::visit_string (be_string *node) +{ + TAO_OutStream *os; // output stream + be_decl *ub = this->ctx_->node (); // get union branch + be_decl *bu = this->ctx_->scope (); // 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 (!ub || !bu) + { + ACE_ERROR_RETURN ((LM_ERROR, + "(%N:%l) be_visitor_union_branch_private_ch::" + "visit_string - " + "bad context information\n" + ), -1); + } + + os = this->ctx_->stream (); + + *os << "char *" << ub->local_name () << "_;\n"; + return 0; +} + +int +be_visitor_union_branch_private_ch::visit_structure (be_structure *node) +{ + TAO_OutStream *os; // output stream + be_decl *ub = this->ctx_->node (); // get union branch + be_decl *bu = this->ctx_->scope (); // 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 (!ub || !bu) + { + ACE_ERROR_RETURN ((LM_ERROR, + "(%N:%l) be_visitor_union_branch_private_ch::" + "visit_structure - " + "bad context information\n" + ), -1); + } + + os = this->ctx_->stream (); + + os->indent (); + *os << bt->nested_type_name (bu) << " " << ub->local_name () << "_;\n"; + return 0; +} + +int +be_visitor_union_branch_private_ch::visit_typedef (be_typedef *node) +{ + TAO_OutStream *os; // output stream + + os = this->ctx_->stream (); + 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_branch_private_ch::" + "visit_typedef - " + "Bad primitive type\n" + ), -1); + } + + this->ctx_->alias (0); + return 0; +} + +int +be_visitor_union_branch_private_ch::visit_union (be_union *node) +{ + TAO_OutStream *os; // output stream + be_decl *ub = this->ctx_->node (); // get union branch + be_decl *bu = this->ctx_->scope (); // 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 (!ub || !bu) + { + ACE_ERROR_RETURN ((LM_ERROR, + "(%N:%l) be_visitor_union_branch_private_ch::" + "visit_union - " + "bad context information\n" + ), -1); + } + + os = this->ctx_->stream (); + + os->indent (); + // C++ doesn't allow object instances inside unions, so we need a + // pointer + *os << bt->nested_type_name (bu) << " *" << ub->local_name () << "_;\n"; + return 0; +} |