int be_visitor_xplicit_pre_proc::visit_string (be_string *node) { if (this->ref_type_) { this->check_and_store (node); return 0; } AST_Expression *b = node->max_size (); if (b->ev ()->u.ulval == 0) { this->type_holder_ = node; return 0; } AST_Expression *bound = 0; ACE_NEW_RETURN (bound, AST_Expression (b, AST_Expression::EV_ulong), -1); Identifier id ("string"); UTL_ScopedName sn (&id, 0); ACE_NEW_RETURN (this->type_holder_, be_string (AST_Decl::NT_string, &sn, bound, node->width ()), -1); return 0; }
void AST_UnionBranch::add_labels (AST_Union *u) { for (UTL_LabellistActiveIterator i (this->pd_ll); !i.is_done (); i.next ()) { if (AST_UnionLabel::UL_default == i.item ()->label_kind ()) { return; } } const bool enum_labels = (u->udisc_type () == AST_Expression::EV_enum); for (UTL_LabellistActiveIterator i (this->pd_ll); !i.is_done (); i.next ()) { AST_Expression *ex = i.item ()->label_val (); UTL_ScopedName *n = ex->n (); if (n) { u->add_to_name_referenced (n->first_component ()); } // If we have enum val labels, we need to set the type and // evaluate here, so the value will be available when the // default index in calculated. if (enum_labels) { ex->ev ()->et = AST_Expression::EV_enum; AST_Enum *disc = AST_Enum::narrow_from_decl (u->disc_type ()); AST_EnumVal *dval = disc->lookup_by_value (ex); if (dval == 0) { idl_global->err ()->incompatible_disc_error (disc, ex); throw Bailout (); } ex->ev ()->u.eval = dval->constant_value ()->ev ()->u.ulval; } } }
// Look up a branch by label. AST_UnionBranch * AST_Union::lookup_label (AST_UnionBranch *b) { AST_UnionLabel *label = b->label (); AST_Expression *lv = label->label_val (); if (label->label_val () == 0) { return b; } AST_Decl *d = 0; AST_UnionBranch *fb = 0; lv->set_ev (lv->coerce (this->pd_udisc_type)); if (lv->ev () == 0) { idl_global->err ()->eval_error (lv); return b; } for (UTL_ScopeActiveIterator i (this, UTL_Scope::IK_decls); !i.is_done(); i.next ()) { d = i.item (); if (d->node_type () == AST_Decl::NT_union_branch) { fb = AST_UnionBranch::narrow_from_decl (d); if (fb == 0) { continue; } if (fb->label() != 0 && fb->label ()->label_kind () == AST_UnionLabel::UL_label && fb->label ()->label_val ()->compare (lv)) { idl_global->err ()->error2 (UTL_Error::EIDL_MULTIPLE_BRANCH, this, b); return b; } } } return 0; }
int ast_visitor_reifying::visit_string (AST_String *node) { AST_Expression *b = node->max_size (); AST_Param_Holder *ph = b->param_holder (); if (ph != 0) { if (this->visit_param_holder (ph) != 0) { ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT ("ast_visitor_reifying::") ACE_TEXT ("visit_string - ") ACE_TEXT ("visit_param_holder() ") ACE_TEXT ("failed\n")), -1); } AST_Constant *c = AST_Constant::narrow_from_decl (this->reified_node_); b = c->constant_value (); } else if (b->ev ()->u.ulval == 0) { this->reified_node_ = node; return 0; } AST_Expression *bound = 0; ACE_NEW_RETURN (bound, AST_Expression (b, AST_Expression::EV_ulong), -1); Identifier id ("string"); UTL_ScopedName sn (&id, 0); ACE_NEW_RETURN (this->reified_node_, AST_String (AST_Decl::NT_string, &sn, bound, node->width ()), -1); return 0; }
int be_visitor_array_cs::visit_array (be_array *node) { // Nothing to do if we are imported or code is already generated. if (node->imported () || (node->cli_stub_gen ())) { return 0; } TAO_OutStream *os = this->ctx_->stream (); ACE_CDR::ULong i; this->ctx_->node (node); // Retrieve the type. be_type *bt = be_type::narrow_from_decl (node->base_type ()); if (!bt) { ACE_ERROR_RETURN ((LM_ERROR, "be_visitor_array_cs::" "visit_array - " "Bad base type\n"), -1); } // To hold the full and local. char fname [NAMEBUFSIZE]; char lname [NAMEBUFSIZE]; ACE_OS::memset (fname, '\0', NAMEBUFSIZE); ACE_OS::memset (lname, '\0', NAMEBUFSIZE); if (this->ctx_->tdef ()) { // Typedefed node. ACE_OS::sprintf (fname, "%s", node->full_name ()); ACE_OS::sprintf (lname, "%s", node->local_name ()->get_string ()); } 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 ()); ACE_OS::sprintf (lname, "_%s", node->local_name ()->get_string ()); } else { ACE_OS::sprintf (fname, "_%s", node->full_name ()); ACE_OS::sprintf (lname, "_%s", node->local_name ()->get_string ()); } } *os << be_nl_2 << "// TAO_IDL - Generated from" << be_nl << "// " << __FILE__ << ":" << __LINE__ << be_nl_2; // dup method. *os << fname << "_slice *" << be_nl << fname << "_dup (const " << fname << "_slice *_tao_src_array)" << be_nl; *os << "{" << be_idt_nl; *os << fname << "_slice *_tao_dup_array =" << be_idt_nl << fname << "_alloc ();" << be_uidt_nl << be_nl; *os << "if (!_tao_dup_array)" << be_idt_nl << "{" << be_idt_nl << "return static_cast <" << fname << "_slice *> (0);" << be_uidt_nl << "}" << be_uidt_nl << be_nl; *os << fname << "_copy (_tao_dup_array, _tao_src_array);" << be_nl; *os << "return _tao_dup_array;" << be_uidt_nl; *os << "}" << be_nl_2; // alloc method. *os << fname << "_slice *" << be_nl; *os << fname << "_alloc (void)" << be_nl; *os << "{" << be_idt_nl; *os << fname << "_slice *retval = 0;" << be_nl; *os << "ACE_NEW_RETURN (retval, "; if (bt->accept (this) == -1) { ACE_ERROR_RETURN ((LM_ERROR, "be_visitor_array_cs::" "visit_array - " "base type decl failed\n"), -1); } if (node->gen_dimensions (os) == -1) { ACE_ERROR_RETURN ((LM_ERROR, "(%N:%l) be_visitor_array_cs::" "visit_array - " "dimensions codegen failed\n"), -1); } *os << ", 0);" << be_nl; *os << "return retval;" << be_uidt_nl; *os << "}" << be_nl_2; // free method. *os << "void" << be_nl << fname << "_free (" << be_idt << be_idt_nl << fname << "_slice *_tao_slice)" << be_uidt << be_uidt_nl; *os << "{" << be_idt_nl; *os << "delete [] _tao_slice;" << be_uidt_nl; *os << "}" << be_nl_2; // copy method. *os << "void" << be_nl; *os << fname << "_copy (" << be_idt << be_idt_nl << fname << "_slice * _tao_to," << be_nl << "const " << fname << "_slice *_tao_from)" << be_uidt << be_uidt_nl; *os << "{" << be_idt_nl; *os << "// Copy each individual element." << be_nl; ACE_CDR::ULong ndims = node->n_dims (); // 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_cs::" "visit_array - " "bad array dimension\n"), -1); } if (expr->ev ()->et == AST_Expression::EV_ulong) { // Generate a loop for each dimension. *os << "for ( ::CORBA::ULong i" << i << " = 0; i" << i << " < " << expr->ev ()->u.ulval << "; ++i" << i << ")" << be_idt_nl << "{" << be_idt_nl; } else { ACE_ERROR_RETURN ((LM_ERROR, "(%N:%l) be_visitor_array_cs::" "visit_array - " "bad array dimension value\n"), -1); } } // Now generate code such that every element of the array gets assigned // inside the innermost level of the nested loops generated above. be_array *primitive_type = 0; if (bt->node_type () == AST_Decl::NT_typedef) { // Base type of the array node is a typedef. We need to make sure that // this typedef is not to another array type. If it is, then we cannot // assign an array to another. We will have to invoke the underlying // array type's copy method for every array dimension. // There may be more than one level of typedef. be_type *tmp = bt; while (tmp->node_type () == AST_Decl::NT_typedef) { be_typedef *tdef = be_typedef::narrow_from_decl (tmp); tmp = be_type::narrow_from_decl (tdef->base_type ()); } primitive_type = be_array::narrow_from_decl (tmp); } if (primitive_type != 0) { // The base type is a typedef to another array type, so // we use the base type's copy method. *os << "// call the underlying _copy" << be_nl; if (bt->accept (this) == -1) { ACE_ERROR_RETURN ((LM_ERROR, "be_visitor_array_cs::" "visit_array - " "base type decl failed\n"), -1); } *os << "_copy (_tao_to"; for (i = 0; i < ndims; ++i) { *os << "[i" << i << "]"; } *os << ", "; *os << "_tao_from"; for (i = 0; i < ndims; ++i) { *os << "[i" << i << "]"; } *os << ");"; } else { // The base type is not a typedef to possibly another array type. In // such a case, assign each element. *os << "_tao_to"; for (i = 0; i < ndims; ++i) { *os << "[i" << i << "]"; } *os << " = "; *os << "_tao_from"; for (i = 0; i < ndims; ++i) { *os << "[i" << i << "]"; } *os << ";"; } for (i = 0; i < ndims; ++i) { // Add closing braces as many times as the number of dimensions. *os << be_uidt_nl << "}" << be_uidt; } *os << be_uidt_nl << "}"; AST_Decl::NodeType nt = bt->node_type (); // 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_CS) == -1) { ACE_ERROR_RETURN ((LM_ERROR, "(%N:%l) be_visitor_array_cs::" "visit_array - " "gen_anonymous_base_type failed\n"), -1); } } // If the member's 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 ()->decl ())) { int status = 0; be_visitor_context ctx (*this->ctx_); switch (nt) { case AST_Decl::NT_enum: { be_visitor_enum_cs ec_visitor (&ctx); status = bt->accept (&ec_visitor); break; } case AST_Decl::NT_struct: { be_visitor_structure_cs sc_visitor (&ctx); status = bt->accept (&sc_visitor); break; } case AST_Decl::NT_union: { be_visitor_union_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); } } node->cli_stub_gen (true); return 0; }
int be_visitor_array_ci::visit_array (be_array *node) { // Nothing to do if we are imported or code is already generated. if (node->imported () || node->cli_inline_gen ()) { return 0; } this->ctx_->node (node); // save the array node // If we contain an anonymous sequence, generate code for it here. be_type *bt = be_type::narrow_from_decl (node->base_type ()); if (!bt) { ACE_ERROR_RETURN ((LM_ERROR, "(%N:%l) be_visitor_array_ci::" "visit_array - " "bad base type\n"), -1); } AST_Decl::NodeType nt = bt->node_type (); if (nt == AST_Decl::NT_sequence) { if (this->gen_anonymous_base_type (bt, TAO_CodeGen::TAO_ROOT_CI) == -1) { ACE_ERROR_RETURN ((LM_ERROR, "(%N:%l) be_visitor_array_ci::" "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 ()->decl ())) { int status = 0; be_visitor_context ctx (*this->ctx_); switch (nt) { case AST_Decl::NT_struct: { be_visitor_structure_ci sc_visitor (&ctx); status = bt->accept (&sc_visitor); break; } case AST_Decl::NT_union: { be_visitor_union_ci 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); } } // To hold the full and local. char fname [NAMEBUFSIZE]; char lname [NAMEBUFSIZE]; ACE_OS::memset (fname, '\0', NAMEBUFSIZE); ACE_OS::memset (lname, '\0', NAMEBUFSIZE); if (this->ctx_->tdef ()) { // Typedefed node. ACE_OS::sprintf (fname, "%s", node->full_name ()); ACE_OS::sprintf (lname, "%s", node->local_name ()->get_string ()); } 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 ()); ACE_OS::sprintf (lname, "_%s", node->local_name ()->get_string ()); } else { ACE_OS::sprintf (fname, "_%s", node->full_name ()); ACE_OS::sprintf (lname, "_%s", node->local_name ()->get_string ()); } } TAO_OutStream *os = this->ctx_->stream (); *os << be_nl_2 << "// TAO_IDL - Generated from" << be_nl << "// " << __FILE__ << ":" << __LINE__; // Generate the array traits specialization definitions, // guarded by #ifdef on unaliased array element type and length. ACE_CString unique; if (nt == AST_Decl::NT_typedef) { be_typedef *td = be_typedef::narrow_from_decl (bt); unique = td->primitive_base_type ()->flat_name (); } else { unique = bt->flat_name (); } char buf[NAMEBUFSIZE]; ACE_CDR::ULong i; for (i = 0UL; i < node->n_dims (); ++i) { ACE_OS::memset (buf, '\0', NAMEBUFSIZE); ACE_OS::sprintf (buf, "_" ACE_UINT32_FORMAT_SPECIFIER_ASCII, node->dims ()[i]->ev ()->u.ulval); unique += buf; } unique += "_traits"; *os << be_nl_2 << "ACE_INLINE" << be_nl << "void" << be_nl << "TAO::Array_Traits<" << fname << "_forany>::free (" << be_idt << be_idt_nl << fname << "_slice * _tao_slice" << be_uidt_nl << ")" << be_uidt_nl << "{" << be_idt_nl << fname << "_free (_tao_slice);" << be_uidt_nl << "}"; *os << be_nl_2 << "ACE_INLINE" << be_nl << fname << "_slice *" << be_nl << "TAO::Array_Traits<" << fname << "_forany>::dup (" << be_idt << be_idt_nl << "const " << fname << "_slice * _tao_slice" << be_uidt_nl << ")" << be_uidt_nl << "{" << be_idt_nl << "return " << fname << "_dup (_tao_slice);" << be_uidt_nl << "}"; *os << be_nl_2 << "ACE_INLINE" << be_nl << "void" << be_nl << "TAO::Array_Traits<" << fname << "_forany>::copy (" << be_idt << be_idt_nl << fname << "_slice * _tao_to," << be_nl << "const " << fname << "_slice * _tao_from" << be_uidt_nl << ")" << be_uidt_nl << "{" << be_idt_nl << fname << "_copy (_tao_to, _tao_from);" << be_uidt_nl << "}"; *os << be_nl_2 << "ACE_INLINE" << be_nl << "void" << be_nl << "TAO::Array_Traits<" << fname << "_forany>::zero (" << be_idt << be_idt_nl << fname << "_slice * _tao_slice" << be_uidt_nl << ")" << be_uidt_nl << "{" << be_idt_nl; ACE_CDR::ULong ndims = node->n_dims (); be_array *primitive_type = 0; if (bt->node_type () == AST_Decl::NT_typedef) { // Base type of the array node is a typedef. We need to make sure that // this typedef is not to another array type. If it is, then we cannot // assign an array to another. We will have to invoke the underlying // array type's copy method for every array dimension. // There may be more than one level of typedef. be_type *tmp = bt; while (tmp->node_type () == AST_Decl::NT_typedef) { be_typedef *tdef = be_typedef::narrow_from_decl (tmp); tmp = be_type::narrow_from_decl (tdef->base_type ()); } primitive_type = be_array::narrow_from_decl (tmp); } *os << "// Zero each individual element." << be_nl; // 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_cs::" "visit_array - " "bad array dimension\n"), -1); } if (expr->ev ()->et == AST_Expression::EV_ulong) { // Generate a loop for each dimension. *os << "for ( ::CORBA::ULong i" << i << " = 0; i" << i << " < " << expr->ev ()->u.ulval << "; ++i" << i << ")" << be_idt_nl << "{" << be_idt_nl; } else { ACE_ERROR_RETURN ((LM_ERROR, "(%N:%l) be_visitor_array_cs::" "visit_array - " "bad array dimension value\n"), -1); } } if (primitive_type) { // The base type is a typedef to another array type, so // we use the base type's copy method. *os << "// call the underlying _zero" << be_nl; * os << "TAO::Array_Traits< "; if (bt->accept (this) == -1) { ACE_ERROR_RETURN ((LM_ERROR, "be_visitor_array_cs::" "visit_array - " "base type decl failed\n"), -1); } * os << "_forany"; * os << ">::"; *os << "zero (_tao_slice"; for (i = 0; i < ndims; ++i) { *os << "[i" << i << "]"; } *os << ");"; } else { // The base type is not a typedef to possibly another array type. In // such a case, assign each element. *os << "_tao_slice"; for (i = 0; i < ndims; ++i) { *os << "[i" << i << "]"; } *os << " = "; if (bt->accept (this) == -1) { ACE_ERROR_RETURN ((LM_ERROR, "be_visitor_array_ch::" "visit_array - " "base type decl failed\n"), -1); } *os << " ();"; } for (i = 0; i < ndims; ++i) { // Add closing braces as many times as the number of dimensions. *os << be_uidt_nl << "}" << be_uidt; } *os << be_uidt_nl << "}"; *os << be_nl_2 << "ACE_INLINE" << be_nl << fname << "_slice *" << be_nl << "TAO::Array_Traits<" << fname << "_forany>::alloc (void)" << be_idt << be_uidt_nl << "{" << be_idt_nl << "return " << fname << "_alloc ();" << be_uidt_nl << "}"; *os << be_nl; node->cli_inline_gen (true); return 0; }
// Helper. int be_visitor_array_cdr_op_cs::visit_node (be_type *bt) { TAO_OutStream *os = this->ctx_->stream (); ACE_CDR::ULong i; be_array *node = be_array::narrow_from_decl (this->ctx_->node ()); AST_Decl::NodeType nt = bt->node_type (); if (node == 0) { ACE_ERROR_RETURN ((LM_ERROR, "(%N:%l) be_visitor_array_cdr_op_cs::" "visit_node - " "bad array node\n"), -1); } // Initialize a boolean variable. *os << "CORBA::Boolean _tao_marshal_flag = true;" << be_nl; ACE_CDR::ULong 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_cdr_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 << " && _tao_marshal_flag; ++i" << i << ")" << be_idt_nl << "{" << be_idt; } else { ACE_ERROR_RETURN ((LM_ERROR, "(%N:%l) be_visitor_array_cdr_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_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 { be_string *str = 0; if (bt->node_type () == AST_Decl::NT_string || bt->node_type () == AST_Decl::NT_wstring) { str = be_string::narrow_from_decl (bt); if (!str) { ACE_ERROR_RETURN ((LM_ERROR, "(%N:%l) be_visitor_array_cdr_op_cs::" "visit_node - " "bad string node\n"), -1); } } *os << "_tao_marshal_flag = (strm >> "; if (str != 0 && str->max_size ()->ev ()->u.ulval != 0) { if (str->width () == (long) sizeof (char)) { *os << "ACE_InputCDR::to_string (_tao_array "; } else { *os << "ACE_InputCDR::to_wstring (_tao_array "; } } else { *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: if (str->max_size ()->ev ()->u.ulval != 0) { *os << ".out (), " << str->max_size ()->ev ()->u.ulval << ")"; } else { *os << ".out ()"; } break; case AST_Decl::NT_valuetype: case AST_Decl::NT_valuetype_fwd: case AST_Decl::NT_eventtype: case AST_Decl::NT_eventtype_fwd: case AST_Decl::NT_valuebox: *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_cdr_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 << "TAO::Objref_Traits<" << bt->name () << ">::" << "marshal (_tao_array"; for (i = 0; i < ndims; ++i) { *os << "[i" << i << "]"; } *os << ".in (), strm);" << be_uidt; } else { be_string *str = 0; if (bt->node_type () == AST_Decl::NT_string || bt->node_type () == AST_Decl::NT_wstring) { str = be_string::narrow_from_decl (bt); if (!str) { ACE_ERROR_RETURN ((LM_ERROR, "(%N:%l) be_visitor_array_cdr_op_cs::" "visit_node - " "bad string node\n"), -1); } } *os << "_tao_marshal_flag = (strm << "; if (str != 0 && str->max_size ()->ev ()->u.ulval != 0) { if (str->width () == (long) sizeof (char)) { *os << "ACE_OutputCDR::from_string (_tao_array "; } else { *os << "ACE_OutputCDR::from_wstring (_tao_array "; } } else { *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: if (str->max_size ()->ev ()->u.ulval != 0) { *os << ".in (), " << str->max_size ()->ev ()->u.ulval << ")"; } else { *os << ".in ()"; } break; case AST_Decl::NT_valuetype: case AST_Decl::NT_valuetype_fwd: case AST_Decl::NT_eventtype: case AST_Decl::NT_eventtype_fwd: case AST_Decl::NT_valuebox: *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_cdr_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_cdr_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; } *os << be_nl_2 << "return _tao_marshal_flag;" << be_uidt_nl; return 0; }
int be_visitor_array_cdr_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_abstract: 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_cdr_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 = be_array::narrow_from_decl (this->ctx_->node ()); if (array == 0) { ACE_ERROR_RETURN ((LM_ERROR, "(%N:%l) be_visitor_array_cdr_op_cs::" "visit_predefined_type - " "bad array node\n"), -1); } // We generate optimized code based on an optimized interface available from // the CDR class. These optimizations are applicable only to primitive // types. *os << "return" << be_idt_nl << "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_cdr_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_cdr_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 << " (" << be_idt << be_idt_nl << "reinterpret_cast <"; break; case TAO_CodeGen::TAO_CDR_OUTPUT: *os << " (" << be_idt << be_idt_nl << "reinterpret_cast <const "; break; default: ACE_ERROR_RETURN ((LM_ERROR, "(%N:%l) be_visitor_array_cdr_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_cdr_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 ())," << be_nl; break; case TAO_CodeGen::TAO_CDR_OUTPUT: *os << " *> (_tao_array.in ())," << be_nl; break; default: ACE_ERROR_RETURN ((LM_ERROR, "(%N:%l) be_visitor_array_cdr_op_cs::" "visit_predefined_type - " "bad substate in context\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_cdr_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_cdr_op_cs::" "visit_predefined_type - " "bad array dimension value\n"), -1); } } *os << ");" << be_uidt << be_uidt << be_uidt << be_uidt_nl; return 0; }
// Determine the default value (if any). int AST_Union::compute_default_value (void) { // Check if we really need a default value. This will be true if there is an // explicit default case OR if an implicit default exists because not all // values of the discriminant type are covered by the cases. // Compute the total true "case" labels i.e., exclude the "default" case. ACE_UINT64 total_case_members = 0; // In the case of a (unsigned) long long discriminant being fully used // the total case count would actually overflow back to zero. // This is 'end of days' programming but what the heck. We're here now. bool first_case_found = false; // Instantiate a scope iterator. for (UTL_ScopeActiveIterator si (this, UTL_Scope::IK_decls); !si.is_done (); si.next ()) { // Get the next AST decl node. AST_UnionBranch *ub = AST_UnionBranch::narrow_from_decl (si.item ()); if (ub != 0) { // If the label is a case label, increment by 1. for (unsigned long i = 0; i < ub->label_list_length (); ++i) { if (ub->label (i)->label_kind () == AST_UnionLabel::UL_label) { ++total_case_members; first_case_found = true; } } } } // Check if the total_case_members cover the entire // range of values that are permitted by the discriminant type. If they do, // then a default value is not necessary. However, if such an explicit // default case is provided, it must be flagged off as an error. Our // front-end is not able to handle such a case since it is a semantic error // and not a syntax error. Such an error is caught here. switch (this->udisc_type ()) { case AST_Expression::EV_short: case AST_Expression::EV_ushort: if (total_case_members > ACE_UINT16_MAX) { this->default_value_.computed_ = 0; } break; case AST_Expression::EV_long: case AST_Expression::EV_ulong: case AST_Expression::EV_enum: // Enums in CORBA are always 32bits in size, so unless // there are that many enum labels in the set, it is // incomplete (reguardless as to the actual member_count). if (total_case_members > ACE_UINT32_MAX) { this->default_value_.computed_ = 0; } break; case AST_Expression::EV_longlong: case AST_Expression::EV_ulonglong: // We would wrap to 0 here - we are using a 64 bit count if (first_case_found && total_case_members == 0) { // If anyone ever produces a "default clause is invalid here" error // after passing through here I will buy them a a house. this->default_value_.computed_ = 0; } break; case AST_Expression::EV_char: if (total_case_members > ACE_OCTET_MAX) { this->default_value_.computed_ = 0; } break; case AST_Expression::EV_wchar: if (total_case_members == ACE_WCHAR_MAX + 1) { this->default_value_.computed_ = 0; } break; case AST_Expression::EV_bool: if (total_case_members == 2) { this->default_value_.computed_ = 0; } break; default: // Error. this->default_value_.computed_ = -1; ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT ("(%N:%l) AST_Union::compute_default_value") ACE_TEXT (" - Bad discriminant type\n")), -1); ACE_NOTREACHED (break;) } // End of switch // If we have determined that we don't have a default case and even then a // default case was provided, flag this off as error. if ((this->default_value_.computed_ == 0) && (this->default_index () != -1)) { // Error. this->default_value_.computed_ = -1; ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT ("(%N:%l) AST_Union::compute_default_value") ACE_TEXT (" - default clause is invalid here\n")), -1); } // Proceed only if necessary. switch (this->default_value_.computed_) { case -1: // Error. We should never be here because errors // have already been caught // above. return -1; case 0: // Nothing more to do. return 0; default: // Proceed further down. break; } // Initialization of the default value data member. switch (this->udisc_type ()) { case AST_Expression::EV_short: this->default_value_.u.short_val = ACE_INT16_MIN; break; case AST_Expression::EV_ushort: this->default_value_.u.ushort_val = 0; break; case AST_Expression::EV_long: // The +1 is to avert a warning on many compilers. this->default_value_.u.long_val = ACE_INT32_MIN + 1; break; case AST_Expression::EV_ulong: this->default_value_.u.ulong_val = 0; break; case AST_Expression::EV_char: this->default_value_.u.char_val = 0; break; case AST_Expression::EV_wchar: this->default_value_.u.wchar_val = 0; break; case AST_Expression::EV_bool: this->default_value_.u.bool_val = 0; break; case AST_Expression::EV_enum: this->default_value_.u.enum_val = 0; break; case AST_Expression::EV_longlong: this->default_value_.u.longlong_val = 0; break; case AST_Expression::EV_ulonglong: this->default_value_.u.ulonglong_val = 0; break; default: // Error caught earlier. break; } // Proceed until we have found the appropriate default value. while (this->default_value_.computed_ == -2) { int break_loop = 0; // Instantiate a scope iterator. for (UTL_ScopeActiveIterator si (this, UTL_Scope::IK_decls); !si.is_done () && break_loop == 0; si.next ()) { // Get the next AST decl node AST_UnionBranch *ub = AST_UnionBranch::narrow_from_decl (si.item ()); if (ub != 0) { for (unsigned long i = 0; i < ub->label_list_length () && !break_loop; ++i) { if (ub->label (i)->label_kind () == AST_UnionLabel::UL_label) { // Not a default. AST_Expression *expr = ub->label (i)->label_val (); if (expr == 0) { // Error. this->default_value_.computed_ = -1; ACE_ERROR_RETURN (( LM_ERROR, ACE_TEXT ("(%N:%l) AST_Union::") ACE_TEXT ("compute_default_value - ") ACE_TEXT ("Bad case label value\n") ), -1 ); } switch (expr->ev ()->et) { // Check if they match in which case this // cannot be the implicit default value. So // start with a new value and try the whole loop // again because our case labels may not be sorted. case AST_Expression::EV_short: if (this->default_value_.u.short_val == expr->ev ()->u.sval) { this->default_value_.u.short_val++; break_loop = 1; } break; case AST_Expression::EV_ushort: if (this->default_value_.u.ushort_val == expr->ev ()->u.usval) { this->default_value_.u.ushort_val++; break_loop = 1; } break; case AST_Expression::EV_long: if (this->default_value_.u.long_val == expr->ev ()->u.lval) { this->default_value_.u.long_val++; break_loop = 1; } break; case AST_Expression::EV_ulong: if (this->default_value_.u.ulong_val == expr->ev ()->u.ulval) { this->default_value_.u.ulong_val++; break_loop = 1; } break; case AST_Expression::EV_char: if (this->default_value_.u.char_val == expr->ev ()->u.cval) { this->default_value_.u.char_val++; break_loop = 1; } break; case AST_Expression::EV_wchar: if (this->default_value_.u.wchar_val == expr->ev ()->u.wcval) { this->default_value_.u.wchar_val++; break_loop = 1; } break; case AST_Expression::EV_bool: if (this->default_value_.u.bool_val == expr->ev ()->u.bval) { this->default_value_.u.bool_val ^= true; break_loop = 1; } break; case AST_Expression::EV_enum: // this is the case of enums. We maintain // evaluated values which always start with 0 if (this->default_value_.u.enum_val == expr->ev ()->u.eval) { this->default_value_.u.enum_val++; break_loop = 1; } break; case AST_Expression::EV_longlong: if (this->default_value_.u.longlong_val == expr->ev ()->u.llval) { this->default_value_.u.longlong_val++; break_loop = 1; } break; case AST_Expression::EV_ulonglong: if (this->default_value_.u.ulonglong_val == expr->ev ()->u.ullval) { this->default_value_.u.ulonglong_val++; break_loop = 1; } break; default: // Error. break; } // End of switch. } // if label_Kind == label } // End of for loop going thru all labels. } // If valid union branch. } // End of while scope iterator loop. // We have not aborted the inner loops which means we have found the // default value. if (break_loop == 0) { this->default_value_.computed_ = 1; } } // End of outer while (default_value.computed == -2). return 0; }