Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TAO 2] Fix Floating Point Constant Expressions in tao_idl #1717

Merged
merged 6 commits into from
Nov 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions TAO/NEWS
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
USER VISIBLE CHANGES BETWEEN TAO-2.5.15 and TAO-2.5.16
======================================================

. TAO_IDL: Fix bug where floating point constant expressions fail to evaluate.
This bug was introduced in 2.5.14.

USER VISIBLE CHANGES BETWEEN TAO-2.5.14 and TAO-2.5.15
======================================================

Expand Down
215 changes: 126 additions & 89 deletions TAO/TAO_IDL/ast/ast_expression.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ AST_Expression::eval_kind_to_expr_type (AST_Expression::EvalKind eval_kind)
case EK_long:
return EV_long;
case EK_ulong:
case EK_positive_int:
return EV_ulong;
case EK_longlong:
return EV_longlong;
Expand All @@ -113,9 +114,13 @@ AST_Expression::eval_kind_to_expr_type (AST_Expression::EvalKind eval_kind)
return EV_int8;
case EK_uint8:
return EV_uint8;
default:
case EK_const:
idl_global->err ()->misc_error ("eval_kind_to_expr_type can't handle EK_const");
return EV_none;
}

idl_global->err ()->misc_error ("eval_kind_to_expr_type unhandled EvalKind");
return EV_none;
}

// Helper function to fill out the details of where this expression
Expand Down Expand Up @@ -1650,7 +1655,8 @@ eval_kind (AST_Expression::AST_ExprValue *ev, AST_Expression::EvalKind ek)
case AST_Expression::EK_uint8:
retval = coerce_value (newval, AST_Expression::EV_uint8);
break;
default:
case AST_Expression::EK_floating_point:
retval = coerce_value (newval, AST_Expression::EV_double);
break;
}

Expand Down Expand Up @@ -1736,7 +1742,8 @@ AST_Expression::eval_bin_op (AST_Expression::EvalKind ek)
return 0;
}

ExprType const expr_type = eval_kind_to_expr_type (ek);
ExprType const expr_type = ek == EK_const ?
pd_v1->ev ()->et : eval_kind_to_expr_type (ek);
if (expr_type == EV_none) return 0;

ACE_NEW_RETURN (retval,
Expand Down Expand Up @@ -1806,7 +1813,7 @@ AST_Expression::eval_bin_op (AST_Expression::EvalKind ek)
break;

default:
success = true;
break;
}

if (!success)
Expand All @@ -1818,6 +1825,17 @@ AST_Expression::eval_bin_op (AST_Expression::EvalKind ek)
return retval;
}

template <typename Type>
bool
do_eval_mod_op (Type a, Type b, Type &result)
{
if (b == 0) {
return false;
}
result = a % b;
return true;
}

// Apply binary operators to an AST_Expression after evaluating
// its sub-expressions.
// Operations supported: '%'
Expand All @@ -1839,79 +1857,74 @@ AST_Expression::eval_mod_op (AST_Expression::EvalKind ek)
return 0;
}

ExprType const expr_type = ek == EK_const ?
pd_v1->ev ()->et : eval_kind_to_expr_type (ek);
if (expr_type == EV_none) return 0;

ACE_NEW_RETURN (retval,
AST_ExprValue,
0);

if (ek == EK_ulonglong)
pd_v1->set_ev (pd_v1->coerce (expr_type));
pd_v2->set_ev (pd_v2->coerce (expr_type));
retval->et = expr_type;

bool success = false;
switch (expr_type)
{
this->pd_v1->set_ev (this->pd_v1->coerce (EV_ulonglong));
this->pd_v2->set_ev (this->pd_v2->coerce (EV_ulonglong));
retval->et = EV_ulonglong;
case EV_int8:
success = do_eval_mod_op<ACE_CDR::Int8> (
pd_v1->ev ()->u.int8val, pd_v2->ev ()->u.int8val, retval->u.int8val);
break;

if (this->pd_v2->ev ()->u.ullval == 0)
{
delete retval;
retval = 0;
return 0;
}
case EV_uint8:
success = do_eval_mod_op<ACE_CDR::UInt8> (
pd_v1->ev ()->u.uint8val, pd_v2->ev ()->u.uint8val, retval->u.uint8val);
break;

retval->u.ullval =
this->pd_v1->ev ()->u.ullval % this->pd_v2->ev ()->u.ullval;
}
else if (ek == EK_longlong)
{
this->pd_v1->set_ev (this->pd_v1->coerce (EV_longlong));
this->pd_v2->set_ev (this->pd_v2->coerce (EV_longlong));
retval->et = EV_longlong;
case EV_short:
success = do_eval_mod_op<ACE_CDR::Short> (
pd_v1->ev ()->u.sval, pd_v2->ev ()->u.sval, retval->u.sval);
break;

if (this->pd_v2->ev ()->u.llval == 0)
{
delete retval;
retval = 0;
return 0;
}
case EV_ushort:
success = do_eval_mod_op<ACE_CDR::UShort> (
pd_v1->ev ()->u.usval, pd_v2->ev ()->u.usval, retval->u.usval);
break;

retval->u.llval =
this->pd_v1->ev ()->u.llval % this->pd_v2->ev ()->u.llval;
}
else if (ek == EK_ulong)
{
this->pd_v1->set_ev (this->pd_v1->coerce (EV_ulong));
this->pd_v2->set_ev (this->pd_v2->coerce (EV_ulong));
retval->et = EV_ulong;
case EV_long:
success = do_eval_mod_op<ACE_CDR::Long> (
pd_v1->ev ()->u.lval, pd_v2->ev ()->u.lval, retval->u.lval);
break;

if (this->pd_v2->ev ()->u.ulval == 0)
{
delete retval;
retval = 0;
return 0;
}
case EV_ulong:
success = do_eval_mod_op<ACE_CDR::ULong> (
pd_v1->ev ()->u.ulval, pd_v2->ev ()->u.ulval, retval->u.ulval);
break;

retval->u.ulval =
this->pd_v1->ev ()->u.ulval % this->pd_v2->ev ()->u.ulval;
}
else if (ek == EK_long)
{
this->pd_v1->set_ev (this->pd_v1->coerce (EV_long));
this->pd_v2->set_ev (this->pd_v2->coerce (EV_long));
retval->et = EV_long;
case EV_longlong:
success = do_eval_mod_op<ACE_CDR::LongLong> (
pd_v1->ev ()->u.llval, pd_v2->ev ()->u.llval, retval->u.llval);
break;

if (this->pd_v2->ev ()->u.lval == 0)
{
delete retval;
retval = 0;
return 0;
}
case EV_ulonglong:
success = do_eval_mod_op<ACE_CDR::ULongLong> (
pd_v1->ev ()->u.ullval, pd_v2->ev ()->u.ullval, retval->u.ullval);
break;

case EV_octet:
success = do_eval_mod_op<ACE_CDR::Octet> (
pd_v1->ev ()->u.oval, pd_v2->ev ()->u.oval, retval->u.oval);
break;

retval->u.lval =
this->pd_v1->ev ()->u.lval % this->pd_v2->ev ()->u.lval;
default:
break;
}
else

if (!success)
{
delete retval;
retval = 0;
return 0;
}

return retval;
Expand Down Expand Up @@ -1991,9 +2004,9 @@ AST_Expression::eval_bit_op (AST_Expression::EvalKind ek)
pd_v2->set_ev (pd_v2->coerce (expr_type));
retval->et = expr_type;

bool success = true;
bool success = false;
switch (expr_type)
{
{
case EV_int8:
success = do_eval_bit_op<ACE_CDR::Int8> (pd_ec,
pd_v1->ev ()->u.int8val, pd_v2->ev ()->u.int8val, retval->u.int8val);
Expand Down Expand Up @@ -2045,8 +2058,8 @@ AST_Expression::eval_bit_op (AST_Expression::EvalKind ek)
break;

default:
success = true;
}
break;
}

if (!success)
{
Expand Down Expand Up @@ -2163,10 +2176,10 @@ AST_Expression::eval_un_op (AST_Expression::EvalKind ek)
case EV_octet:
retval->u.oval = ~this->pd_v1->ev ()->u.oval;
break;
case AST_Expression::EV_int8:
case EV_int8:
retval->u.int8val = ~pd_v1->ev ()->u.int8val;
break;
case AST_Expression::EV_uint8:
case EV_uint8:
retval->u.uint8val = ~pd_v1->ev ()->u.uint8val;
break;
default:
Expand Down Expand Up @@ -2372,8 +2385,21 @@ AST_Expression::coerce (AST_Expression::ExprType t)
case EV_fixed:
tmp = this->eval_internal (EK_fixed_point);
break;
default:
tmp = this->eval_internal (EK_const);
case EV_float:
case EV_double:
case EV_longdouble:
tmp = eval_internal (EK_floating_point);
break;
case EV_char:
case EV_wchar:
case EV_string:
case EV_wstring:
case EV_enum:
case EV_any:
case EV_object:
case EV_void:
tmp = eval_internal (EK_const);
case EV_none:
break;
}

Expand Down Expand Up @@ -2457,7 +2483,8 @@ AST_Expression::coerce (AST_Expression::ExprType t)
case EV_uint8:
copy->u.uint8val = this->pd_ev->u.uint8val;
break;
default:
case EV_any:
case EV_object:
break;
}

Expand Down Expand Up @@ -2677,30 +2704,32 @@ dump_expr_val (ACE_OSTREAM_TYPE &o, AST_Expression::AST_ExprValue *ev)
{
case AST_Expression::EV_short:
o << ev->u.sval;
break;
return;
case AST_Expression::EV_ushort:
o << ev->u.usval;
break;
return;
case AST_Expression::EV_long:
o << ev->u.lval;
break;
return;
case AST_Expression::EV_ulong:
case AST_Expression::EV_enum:
o << ev->u.ulval;
break;
return;
case AST_Expression::EV_float:
o << ev->u.fval;
break;
return;
case AST_Expression::EV_double:
o << ev->u.dval;
break;
return;
case AST_Expression::EV_char:
o << ev->u.cval;
break;
#ifndef ACE_HAS_CPP20
return;
case AST_Expression::EV_wchar:
o << ev->u.wcval;
#ifdef ACE_HAS_CPP20
break;
#else
o << ev->u.wcval;
return;
#endif
case AST_Expression::EV_octet:
{
Expand All @@ -2709,10 +2738,10 @@ dump_expr_val (ACE_OSTREAM_TYPE &o, AST_Expression::AST_ExprValue *ev)
o << "0x" << std::hex << std::setw (2) << std::setfill ('0') << unsigned (ev->u.oval);
o.copyfmt (saved);
}
break;
return;
case AST_Expression::EV_bool:
o << (ev->u.bval == true ? "TRUE" : "FALSE");
break;
return;
case AST_Expression::EV_string:
if (ev->u.strval != 0)
{
Expand All @@ -2722,25 +2751,32 @@ dump_expr_val (ACE_OSTREAM_TYPE &o, AST_Expression::AST_ExprValue *ev)
{
o << "(null string)";
}
break;
return;
case AST_Expression::EV_longlong:
o << ev->u.llval;
break;
return;
case AST_Expression::EV_ulonglong:
o << ev->u.ullval;
break;
return;
case AST_Expression::EV_fixed:
o << ev->u.fixedval;
break;
return;
case AST_Expression::EV_int8:
o << static_cast<short> (ev->u.int8val);
break;
return;
case AST_Expression::EV_uint8:
o << static_cast<unsigned short> (ev->u.uint8val);
return;
case AST_Expression::EV_longdouble:
case AST_Expression::EV_wstring:
case AST_Expression::EV_any:
case AST_Expression::EV_object:
case AST_Expression::EV_void:
case AST_Expression::EV_none:
break;
default:
o << "(Can not dump this type)";
}

o << "(Can not dump type " << AST_Expression::exprtype_to_string (ev->et) << ")";
}

// Dump an AST_Expression node to the ostream o.
Expand Down Expand Up @@ -2842,6 +2878,7 @@ AST_Expression::dump (ACE_OSTREAM_TYPE &o)
o << ACE_TEXT ("(nil symbolic name)");
break;
case EC_none:
o << ACE_TEXT ("(none)");
break;
default:
o << ACE_TEXT ("unsupported dump mode for expression with ec == ")
Expand Down Expand Up @@ -3048,9 +3085,9 @@ AST_Expression::exprtype_to_string (ExprType t)
return "uint8";
case AST_Expression::EV_int8:
return "int8";
default:
return "<UNKNOWN TYPE>";
}

return "<UNKNOWN TYPE>";
}

AST_Enum *
Expand Down
Loading