diff options
author | parsons <parsons@ae88bc3d-4319-0410-8dbf-d08b4c9d3795> | 2000-11-05 00:14:10 +0000 |
---|---|---|
committer | parsons <parsons@ae88bc3d-4319-0410-8dbf-d08b4c9d3795> | 2000-11-05 00:14:10 +0000 |
commit | 8b87ee4548c4634300afc8a778b658a903640e77 (patch) | |
tree | 59c67c4e2072e2184ed0cfdce1cb4242826cf8fb /TAO/TAO_IDL/be/be_union.cpp | |
parent | 8c21cda3eb73f58d0896ad84dd4b57da7685288e (diff) | |
download | ATCD-8b87ee4548c4634300afc8a778b658a903640e77.tar.gz |
ChangeLogTag: Sat Nov 4 18:04:21 2000 Jeff Parsons <parsons@cs.wustl.edu>
Diffstat (limited to 'TAO/TAO_IDL/be/be_union.cpp')
-rw-r--r-- | TAO/TAO_IDL/be/be_union.cpp | 380 |
1 files changed, 1 insertions, 379 deletions
diff --git a/TAO/TAO_IDL/be/be_union.cpp b/TAO/TAO_IDL/be/be_union.cpp index 46c7830e526..0c136f5b514 100644 --- a/TAO/TAO_IDL/be/be_union.cpp +++ b/TAO/TAO_IDL/be/be_union.cpp @@ -52,11 +52,8 @@ be_union::be_union (AST_ConcreteType *dt, p), UTL_Scope (AST_Decl::NT_union), COMMON_Base (local, - abstract), - default_index_ (-2) + abstract) { - this->default_value_.computed_ = -2; - // Always the case. this->has_constructor (I_TRUE); } @@ -796,381 +793,6 @@ be_union::compute_size_type (void) return 0; } -// Return the default value. -int -be_union::default_value (be_union::DefaultValue &dv) -{ - if (this->default_value_.computed_ == -2) - { - // We need to compute it. - if (this->compute_default_value () == -1) - { - ACE_ERROR_RETURN ((LM_ERROR, - ACE_TEXT ("(%N:%l) be_union::") - ACE_TEXT ("default_value - ") - ACE_TEXT ("Error computing ") - ACE_TEXT ("default value\n")), - -1); - } - } - - dv = this->default_value_; - return 0; -} - -// Determine the implicit default value (if any). -int -be_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. - int total_case_members = 0; - - // Instantiate a scope iterator. - UTL_ScopeActiveIterator *si = 0; - ACE_NEW_RETURN (si, - UTL_ScopeActiveIterator (this, - UTL_Scope::IK_decls), - -1); - - while (!si->is_done ()) - { - // Get the next AST decl node. - be_union_branch *ub = - be_union_branch::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++; - } - } - } - - si->next (); - } - - delete si; - - // 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 + 1) - { - this->default_value_.computed_ = 0; - } - - break; - case AST_Expression::EV_long: - case AST_Expression::EV_ulong: - if ((unsigned int) total_case_members > ACE_UINT32_MAX) - { - this->default_value_.computed_ = 0; - } - - break; - case AST_Expression::EV_longlong: - case AST_Expression::EV_ulonglong: - // Error for now. - this->default_value_.computed_ = -1; - ACE_ERROR_RETURN ((LM_ERROR, - ACE_TEXT ("(%N:%l) be_union::compute_default_value ") - ACE_TEXT ("- unimplemented discriminant type ") - ACE_TEXT ("(longlong or ulonglong)\n")), - -1); - ACE_NOTREACHED (break;) - case AST_Expression::EV_char: - if (total_case_members == ACE_OCTET_MAX + 1) - { - 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; - case AST_Expression::EV_any: - // Has to be enum. - { - be_decl *d = be_decl::narrow_from_decl (this->disc_type ()); - - if (d->node_type () == AST_Decl::NT_typedef) - { - be_typedef *bt = be_typedef::narrow_from_decl (d); - d = bt->primitive_base_type (); - } - - be_enum *en = be_enum::narrow_from_decl (d); - - if (en != 0) - { - if (total_case_members == en->member_count ()) - { - this->default_value_.computed_ = 0; - } - } - else - { - // Error. - this->default_value_.computed_ = -1; - ACE_ERROR_RETURN ((LM_ERROR, - ACE_TEXT ("(%N:%l) be_union::") - ACE_TEXT ("compute_default_value ") - ACE_TEXT ("- disc type not an ENUM\n")), - -1); - } - } - break; - default: - // Error. - this->default_value_.computed_ = -1; - ACE_ERROR_RETURN ((LM_ERROR, - ACE_TEXT ("(%N:%l) be_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 need 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) be_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_any: - this->default_value_.u.enum_val = 0; - break; - case AST_Expression::EV_longlong: - case AST_Expression::EV_ulonglong: - // Unimplemented. - default: - // Error caught earlier. - break; - } - - // Proceed until we have found the appropriate default value. - while (this->default_value_.computed_ == -2) - { - // Instantiate a scope iterator. - ACE_NEW_RETURN (si, - UTL_ScopeActiveIterator (this, - UTL_Scope::IK_decls), - -1); - - int break_loop = 0; - - while (!si->is_done () && break_loop == 0) - { - // Get the next AST decl node - be_union_branch *ub = - be_union_branch::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) be_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++; - break_loop = 1; - } - - break; - case AST_Expression::EV_any: - // 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: - case AST_Expression::EV_ulonglong: - // Unimplemented. right now - flag as error. - default: - // Error. - break; - } // End of switch. - } // if label_Kind == label - } // End of for loop going thru all labels. - } // If valid union branch. - - si->next (); - } // End of while scope iterator loop. - - delete si; - - // 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; -} - idl_bool be_union::has_duplicate_case_labels (void) { |