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; }
unsigned long be_enum_val::Value () { AST_Expression * enumExpr; AST_Expression::AST_ExprValue * exprValue; enumExpr = constant_value (); if (enumExpr) { exprValue = enumExpr->eval (AST_Expression::EK_positive_int); if (exprValue) { assert (exprValue->et == AST_Expression::EV_ulong); return exprValue->u.eval; } else { assert(pbfalse); } } else { assert(pbfalse); } return 0; }
int be_union_branch::gen_label_value (TAO_OutStream *os, unsigned long index) { AST_Expression *e = this->label (index)->label_val (); if (e->ec () != AST_Expression::EC_symbol) { // Easy, just a number... *os << e; return 0; } // If the enum is not in the global scope we have to prefix it. be_union *u = be_union::narrow_from_scope (this->defined_in ()); if (u == 0) { return -1; } be_type* dt = be_type::narrow_from_decl (u->disc_type ()); if (dt == 0) { return -1; } // Check if discriminator is a typedef of an integer. If so, and the // first IF block in this function didn't catch it, then we // are a constant of this type. We can't generate the constant's name, // we must generate the underlying integer value for the // label value. if (dt->node_type () == AST_Decl::NT_pre_defined) { *os << e; return 0; } // 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 << e->n (); return 0; } // But if it was generated inside a module or something similar then // we must prefix the enum value with something... be_decl* decl = scope->decl (); *os << decl->full_name () << "::" << e->n ()->last_component (); return 0; }
int ast_visitor_reifying::visit_sequence (AST_Sequence *node) { AST_Type *bt = node->base_type (); if (bt->ast_accept (this) != 0) { ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT ("ast_visitor_reifying::") ACE_TEXT ("visit_sequence - ") ACE_TEXT ("visit of base type failed\n")), -1); } bt = AST_Type::narrow_from_decl (this->reified_node_); AST_Expression *v = node->max_size (); AST_Param_Holder *ph = v->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_sequence - ") ACE_TEXT ("visit_param_holder() ") ACE_TEXT ("failed\n")), -1); } AST_Constant *c = AST_Constant::narrow_from_decl (this->reified_node_); v = c->constant_value (); } AST_Expression *bound = idl_global->gen ()->create_expr (v, AST_Expression::EV_ulong); Identifier id ("sequence"); UTL_ScopedName sn (&id, 0); this->reified_node_ = idl_global->gen ()->create_sequence (bound, bt, &sn, false, false); // No need to add this new node to any scope - it's anonymous // and owned by the node that references it. return 0; }
void eval_binary_exp_exp_test() { AST_Expression_Integer intExp = (AST_Expression_Integer) newAST_Expression_Integer(2); AST_Expression_Integer intExp2 = (AST_Expression_Integer) newAST_Expression_Integer(3); AST_Expression_BinOp binOp = (AST_Expression_BinOp) newAST_Expression_BinOp(intExp, intExp2, BINOPEXP); EvalExp *evalExp = new EvalExp(NULL); AST_Expression result = evalExp->eval(binOp); BOOST_CHECK(result->expressionType() == EXPINTEGER); BOOST_CHECK(result->getAsInteger()->val() == 8); }
// 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; }
void AST_UnionBranch::coerce_labels (AST_Union *u) { for (unsigned long i = 0; i < this->label_list_length (); ++i) { AST_UnionLabel *ul = this->label (i); if (ul->label_kind () == AST_UnionLabel::UL_default) { continue; } AST_Expression *lv = ul->label_val (); lv->set_ev (lv->coerce (u->udisc_type ())); } }
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; }
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; } } }
AST_Real BraceIterator::next() { AST_Expression exp = *_braceExpElementsIter; AST_Real value; switch (exp->expressionType()){ case EXPINTEGER: value = exp->getAsInteger()->val(); break; case EXPREAL: value = (int)exp->getAsReal()->val(); break; default: ERROR("BraceIterator::next():\n" "Incorrect brace expression element's type."); } _braceExpElementsIter++; return value; }
void find_identifiers(AST_Expression &exp, IdMap &idmap) { switch(exp.getType()) { case AST_BEXP: find_identifiers((AST_BinaryExpression&)exp, idmap); break; case AST_UEXP: find_identifiers((AST_UnaryExpression&)exp, idmap); break; case AST_ID: find_identifiers((AST_Identifier&)exp, idmap); break; default: std::cout << "Error?" << std::endl; } }
bool evaluate(AST_Expression &exp, ValueMap &valmap) { switch(exp.getType()) { case AST_BEXP: return evaluate((AST_BinaryExpression&)exp, valmap); case AST_UEXP: return evaluate((AST_UnaryExpression&)exp, valmap); case AST_ID: return evaluate((AST_Identifier&)exp, valmap); default: std::cout << "Error?" << std::endl; } return false; }
void eval_binary_exp_combi_test() { // 24 / ((2 + 1 + (-1)) ^ 3) AST_Expression_Integer intExp = (AST_Expression_Integer) newAST_Expression_Integer(24); AST_Expression_Integer intExp2 = (AST_Expression_Integer) newAST_Expression_Real(2); AST_Expression_Integer intExp3 = (AST_Expression_Integer) newAST_Expression_Integer(1); AST_Expression_Integer intExp4 = (AST_Expression_Integer) newAST_Expression_Integer(1); AST_Expression_Integer intExp5 = (AST_Expression_Integer) newAST_Expression_Integer(3); AST_Expression_BinOp binOp = (AST_Expression_BinOp) newAST_Expression_BinOp(intExp2, intExp3, BINOPADD); AST_Expression_UMinus uMinus = (AST_Expression_UMinus) newAST_Expression_UnaryMinus(intExp4); AST_Expression_BinOp binOp1 = (AST_Expression_BinOp) newAST_Expression_BinOp(binOp, uMinus, BINOPADD); AST_Expression_BinOp binOp2 = (AST_Expression_BinOp) newAST_Expression_BinOp(binOp1, intExp5, BINOPEXP); AST_Expression_BinOp binOp3 = (AST_Expression_BinOp) newAST_Expression_BinOp(intExp, binOp2, BINOPDIV); EvalExp *evalExp = new EvalExp(NULL); AST_Expression result = evalExp->eval(binOp3); BOOST_CHECK(result->expressionType() == EXPREAL); BOOST_CHECK(result->getAsReal()->val() == 3); }
AST_Real RangeIterator::eval(AST_Expression exp, VarSymbolTable symbolTable) { EvalExp evaluator(symbolTable); AST_Expression result = evaluator.eval(exp); ERROR_UNLESS(result->expressionType() == EXPREAL || result->expressionType() == EXPINTEGER, "RangeIterator::getVal:\n" "Expression type should be EXPREAL or EXPINTEGER \n"); if (result->expressionType() == EXPREAL) { return result->getAsReal()->val(); } else { return result->getAsInteger()->val(); } }
AST_Expression MMO_ConvertCondition_::foldTraverseElementUMinus (AST_Expression exp) { return (foldTraverse (exp->getAsUMinus ()->exp ())); }
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; }
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; }
Type TypeCheck_::check_expression(AST_Expression e) { Type ct,t1,t2,t; switch (e->expressionType()) { case EXPBINOP: { AST_Expression_BinOp b = e->getAsBinOp(); return check_binop(b->left() , b->right() , b->binopType()); } case EXPUMINUS: { AST_Expression_UMinus b = e->getAsUMinus(); t = check_expression(b->exp()); if ( check_equal(t , T("Integer")) or check_equal(t , T("Real")) ) return t; throw "Type Error (3)"; } case EXPOUTPUT : { AST_Expression_Output b = e->getAsOutput(); return check_expression(b->expressionList()->front() ); } case EXPIF: { AST_Expression_If b = e->getAsIf(); ct = check_expression(b->condition() ); t1 = check_expression(b->then() ); t2 = check_expression(b->else_exp()); // Falta el elseIF if ( !check_equal(ct, T("Boolean")) ) throw "Type Error (4)"; if ( !check_equal(t1,t2) ) throw "Type Error (5)"; return t1; } case EXPCALL: { // Añadir las funciones en la listaaaa de variables AST_Expression_Call c = e->getAsCall(); if ( toStr(c->name()) == "sample" ) return T("Boolean"); if ( toStr(c->name()) == "pre" ) return check_expression(c->arguments()->front()); return T("Real"); } case EXPCOMPREF: { AST_Expression_ComponentReference b = e->getAsComponentReference(); VarInfo tt = varEnv->lookup( toStr(b->names()->front()) ); if (tt == NULL) { cerr << "Var:" << b->names()->front() << ":"; throw "Variable no existe (8)"; } if (b->indexes()->front()->size() == 0) return tt->type(); else { Type t = tt->type(); AST_ExpressionListIterator exit; foreach(exit , b->indexes()->front() ) if (t->getType() == TYARRAY) t = t->getAsArray()->arrayOf(); else throw "Type Error (7)"; return t; } break; } case EXPDERIVATIVE: return T("Real"); case EXPBOOLEAN: return T("Boolean"); case EXPSTRING: return T("String"); case EXPREAL: return T("Real"); case EXPINTEGER: return T("Integer"); case EXPBOOLEANNOT: { AST_Expression_BooleanNot b = e->getAsBooleanNot(); t = check_expression(b->exp()); if ( !check_equal(t, T("Boolean")) ) throw "Type Error (6)"; return t; } default: throw "No implrementado aun! (check_expression)"; } }
// 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; }
// 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 MMO_EvalInitExp_::foldTraverseElement (AST_Expression exp) { int ret = 0; switch (exp->expressionType ()) { case EXPCOMPREF: { AST_Expression_ComponentReference cr = exp->getAsComponentReference (); VarInfo vi = _vt->lookup (cr->name ()); if (vi == NULL) { Error::getInstance ()->add (exp->lineNum (), EM_IR | EM_VARIABLE_NOT_FOUND, ER_Error, "%s", cr->name ().c_str ()); return (ret); } if (!vi->isConstant ()) { Error::getInstance ()->add ( exp->lineNum (), EM_IR | EM_INIT_EXP, ER_Error, "Only constants allowed inside initial expressions. %s", cr->name ().c_str ()); return (ret); } return (vi->value ()); } case EXPBOOLEAN: { AST_Expression_Boolean eb = exp->getAsBoolean (); if (eb->value ()) { return (1); } else { return (0); } } case EXPBOOLEANNOT: { AST_Expression_BooleanNot ebn = exp->getAsBooleanNot (); int res = foldTraverse (ebn->exp ()); if (res == 0) { return (1); } else { return (0); } } case EXPREAL: Error::getInstance ()->add ( 0, EM_IR | EM_INIT_EXP, ER_Warning, "Implicit conversion from Real to Integer, in initial expression."); return (exp->getAsReal ()->val ()); case EXPINTEGER: return (exp->getAsInteger ()->val ()); default: Error::getInstance ()->add ( 0, EM_IR | EM_INIT_EXP, ER_Warning, "Initial expression not recognized, returning zero as default value."); break; } return (ret); }
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; }
int MMO_EvalInitExp_::foldTraverseElementUMinus (AST_Expression exp) { return (-1 * foldTraverse (exp->getAsUMinus ()->exp ())); }
// Look up a branch in an enum which is the discriminator type for this // union, based on the label value which must be an enumerator in that // enum. AST_UnionBranch * AST_Union::lookup_enum (AST_UnionBranch *b) { AST_UnionLabel *label = b->label(); AST_Expression *lv = label->label_val (); AST_Enum *e = AST_Enum::narrow_from_decl (this->pd_disc_type); AST_Decl *d = 0; AST_UnionBranch *fb = 0; if (e == 0) { return 0; } if (lv == 0) { return b; } // Expecting a symbol label. if (lv->ec () != AST_Expression::EC_symbol) { idl_global->err ()->enum_val_expected (this, label); return b; } // See if the symbol defines a constant in the discriminator enum. UTL_ScopedName *sn = lv->n (); d = e->lookup_by_name (sn, true); if (d == 0 || d->defined_in () != e) { idl_global->err ()->enum_val_lookup_failure (this, e, sn); return b; } // OK, now see if this symbol is already used as the label of // some other branch. 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; }