summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFred Hornsey <hornseyf@objectcomputing.com>2021-06-12 22:43:28 -0500
committerFred Hornsey <hornseyf@objectcomputing.com>2021-06-12 22:43:28 -0500
commit56a61b91a637fbb0be576cbc3f7a173e0c63476a (patch)
treea9b1b870c839ecf1feefed10be48a09711320fb1
parenta4c5b22c20a1f1298a23d3ab57571237284b1963 (diff)
downloadATCD-56a61b91a637fbb0be576cbc3f7a173e0c63476a.tar.gz
Fix Issues with explicit_ints Test
- Add uint8 and int8 to ACE and TAO serialization - Refactor parts of AST_Expression to also cover uint8 and int8
-rw-r--r--ACE/ace/CDR_Stream.h12
-rw-r--r--ACE/ace/CDR_Stream.inl86
-rw-r--r--TAO/TAO_IDL/ast/ast_expression.cpp639
-rw-r--r--TAO/TAO_IDL/be/be_helper.cpp11
-rw-r--r--TAO/TAO_IDL/include/ast_expression.h6
-rw-r--r--TAO/tao/CDR.h4
-rw-r--r--TAO/tao/CDR.inl23
-rw-r--r--TAO/tests/IDLv4/explicit_ints/IDLv4_explicit_ints.mpc3
-rw-r--r--TAO/tests/IDLv4/explicit_ints/main.cpp25
-rw-r--r--TAO/tests/IDLv4/explicit_ints/test.idl28
10 files changed, 391 insertions, 446 deletions
diff --git a/ACE/ace/CDR_Stream.h b/ACE/ace/CDR_Stream.h
index 3a16dbeb7bf..b47b8d348c4 100644
--- a/ACE/ace/CDR_Stream.h
+++ b/ACE/ace/CDR_Stream.h
@@ -260,6 +260,8 @@ public:
ACE_CDR::Boolean write_double (const ACE_CDR::Double &x);
ACE_CDR::Boolean write_longdouble (const ACE_CDR::LongDouble &x);
ACE_CDR::Boolean write_fixed (const ACE_CDR::Fixed &x);
+ ACE_CDR::Boolean write_int8 (ACE_CDR::Int8 x);
+ ACE_CDR::Boolean write_uint8 (ACE_CDR::Uint8 x);
/// For string we offer methods that accept a precomputed length.
ACE_CDR::Boolean write_string (const ACE_CDR::Char *x);
@@ -306,6 +308,8 @@ public:
ACE_CDR::ULong length);
ACE_CDR::Boolean write_longdouble_array (const ACE_CDR::LongDouble* x,
ACE_CDR::ULong length);
+ ACE_CDR::Boolean write_int8_array (const ACE_CDR::Int8 *x, ACE_CDR::ULong length);
+ ACE_CDR::Boolean write_uint8_array (const ACE_CDR::Uint8 *x, ACE_CDR::ULong length);
/// Write an octet array contained inside a MB, this can be optimized
/// to minimize copies.
@@ -857,6 +861,8 @@ public:
ACE_CDR::Boolean read_double (ACE_CDR::Double &x);
ACE_CDR::Boolean read_longdouble (ACE_CDR::LongDouble &x);
ACE_CDR::Boolean read_fixed (ACE_CDR::Fixed &x);
+ ACE_CDR::Boolean read_int8 (ACE_CDR::Int8 &x);
+ ACE_CDR::Boolean read_uint8 (ACE_CDR::Uint8 &x);
ACE_CDR::Boolean read_string (ACE_CDR::Char *&x);
ACE_CDR::Boolean read_string (ACE_CString &x);
@@ -899,6 +905,8 @@ public:
ACE_CDR::ULong length);
ACE_CDR::Boolean read_longdouble_array (ACE_CDR::LongDouble* x,
ACE_CDR::ULong length);
+ ACE_CDR::Boolean read_int8_array (ACE_CDR::Int8 *x, ACE_CDR::ULong length);
+ ACE_CDR::Boolean read_uint8_array (ACE_CDR::Uint8 *x, ACE_CDR::ULong length);
//@}
/**
@@ -1384,6 +1392,8 @@ extern ACE_Export ACE_CDR::Boolean operator<< (ACE_OutputCDR &os,
ACE_CDR::Double x);
extern ACE_Export ACE_CDR::Boolean operator<< (ACE_OutputCDR &os,
const ACE_CDR::Fixed &x);
+extern ACE_Export ACE_CDR::Boolean operator<< (ACE_OutputCDR &os, ACE_CDR::Uint8 x);
+extern ACE_Export ACE_CDR::Boolean operator<< (ACE_OutputCDR &os, ACE_CDR::Int8 x);
// CDR output operator from helper classes
@@ -1439,6 +1449,8 @@ extern ACE_Export ACE_CDR::Boolean operator>> (ACE_InputCDR &is,
ACE_CDR::Double &x);
extern ACE_Export ACE_CDR::Boolean operator>> (ACE_InputCDR &is,
ACE_CDR::Fixed &x);
+extern ACE_Export ACE_CDR::Boolean operator>> (ACE_OutputCDR &os, ACE_CDR::Uint8 &x);
+extern ACE_Export ACE_CDR::Boolean operator>> (ACE_OutputCDR &os, ACE_CDR::Int8 &x);
// CDR input operator from helper classes
diff --git a/ACE/ace/CDR_Stream.inl b/ACE/ace/CDR_Stream.inl
index 3ee06d67ef4..76b2c15735a 100644
--- a/ACE/ace/CDR_Stream.inl
+++ b/ACE/ace/CDR_Stream.inl
@@ -356,6 +356,18 @@ ACE_OutputCDR::write_wstring (const std::wstring &x)
#endif
ACE_INLINE ACE_CDR::Boolean
+ACE_OutputCDR::write_int8 (ACE_CDR::Int8 x)
+{
+ return this->write_1 (reinterpret_cast<ACE_CDR::Octet *> (&x));
+}
+
+ACE_INLINE ACE_CDR::Boolean
+ACE_OutputCDR::write_uint8 (ACE_CDR::Uint8 x)
+{
+ return this->write_1 (reinterpret_cast<ACE_CDR::Octet *> (&x));
+}
+
+ACE_INLINE ACE_CDR::Boolean
ACE_OutputCDR::write_char_array (const ACE_CDR::Char *x,
ACE_CDR::ULong length)
{
@@ -491,6 +503,18 @@ ACE_OutputCDR::write_longdouble_array (const ACE_CDR::LongDouble* x,
length);
}
+ACE_INLINE ACE_CDR::Boolean
+ACE_OutputCDR::write_int8_array (const ACE_CDR::Int8 *x, ACE_CDR::ULong length)
+{
+ return write_array (x, ACE_CDR::OCTET_SIZE, ACE_CDR::OCTET_ALIGN, length);
+}
+
+ACE_INLINE ACE_CDR::Boolean
+ACE_OutputCDR::write_uint8_array (const ACE_CDR::Uint8 *x, ACE_CDR::ULong length)
+{
+ return write_array (x, ACE_CDR::OCTET_SIZE, ACE_CDR::OCTET_ALIGN, length);
+}
+
ACE_INLINE bool
ACE_OutputCDR::good_bit () const
{
@@ -791,6 +815,18 @@ ACE_InputCDR::read_fixed (ACE_CDR::Fixed &x)
return false;
}
+ACE_INLINE ACE_CDR::Boolean
+ACE_InputCDR::read_int8 (ACE_CDR::Int8 &x)
+{
+ return read_1 (reinterpret_cast<ACE_CDR::Octet *>(&x));
+}
+
+ACE_INLINE ACE_CDR::Boolean
+ACE_InputCDR::read_uint8 (ACE_CDR::Uint8 &x)
+{
+ return read_1 (reinterpret_cast<ACE_CDR::Octet *>(&x));
+}
+
ACE_INLINE size_t
ACE_InputCDR::length () const
{
@@ -1022,6 +1058,30 @@ ACE_InputCDR::read_longdouble_array (ACE_CDR::LongDouble* x,
}
ACE_INLINE ACE_CDR::Boolean
+ACE_InputCDR::read_int8_array (ACE_CDR::Int8 *x, ACE_CDR::ULong length)
+{
+ if (length * ACE_CDR::OCTET_SIZE > this->length ())
+ {
+ this->good_bit_ = false;
+ return false;
+ }
+
+ return read_array (x, ACE_CDR::OCTET_SIZE, ACE_CDR::OCTET_ALIGN, length);
+}
+
+ACE_INLINE ACE_CDR::Boolean
+ACE_InputCDR::read_uint8_array (ACE_CDR::Uint8 *x, ACE_CDR::ULong length)
+{
+ if (length * ACE_CDR::OCTET_SIZE > this->length ())
+ {
+ this->good_bit_ = false;
+ return false;
+ }
+
+ return read_array (x, ACE_CDR::OCTET_SIZE, ACE_CDR::OCTET_ALIGN, length);
+}
+
+ACE_INLINE ACE_CDR::Boolean
ACE_InputCDR::skip_octet ()
{
ACE_CDR::Octet x;
@@ -1314,6 +1374,20 @@ operator<< (ACE_OutputCDR &os, const std::wstring& x)
}
#endif
+ACE_INLINE ACE_CDR::Boolean
+operator<< (ACE_OutputCDR &os, ACE_CDR::Uint8 x)
+{
+ os.write_uint8 (x);
+ return (ACE_CDR::Boolean) os.good_bit ();
+}
+
+ACE_INLINE ACE_CDR::Boolean
+operator<< (ACE_OutputCDR &os, ACE_CDR::Int8 x)
+{
+ os.write_int8 (x);
+ return (ACE_CDR::Boolean) os.good_bit ();
+}
+
// The following use the helper classes
ACE_INLINE ACE_CDR::Boolean
operator<< (ACE_OutputCDR &os, ACE_OutputCDR::from_boolean x)
@@ -1467,6 +1541,18 @@ operator>> (ACE_InputCDR &is, std::wstring& x)
}
#endif
+ACE_INLINE ACE_CDR::Boolean
+operator>> (ACE_InputCDR &is, ACE_CDR::Uint8 &x)
+{
+ return is.read_uint8 (x) && is.good_bit ();
+}
+
+ACE_INLINE ACE_CDR::Boolean
+operator>> (ACE_InputCDR &is, ACE_CDR::Int8 &x)
+{
+ return is.read_int8 (x) && is.good_bit ();
+}
+
// The following use the helper classes
ACE_INLINE ACE_CDR::Boolean
operator>> (ACE_InputCDR &is, ACE_InputCDR::to_boolean x)
diff --git a/TAO/TAO_IDL/ast/ast_expression.cpp b/TAO/TAO_IDL/ast/ast_expression.cpp
index c1b2c15b903..f653a4c196d 100644
--- a/TAO/TAO_IDL/ast/ast_expression.cpp
+++ b/TAO/TAO_IDL/ast/ast_expression.cpp
@@ -84,6 +84,40 @@ trademarks or registered trademarks of Sun Microsystems, Inc.
// FUZZ: disable check_for_streams_include
#include "ace/streams.h"
+AST_Expression::ExprType
+AST_Expression::eval_kind_to_expr_type (AST_Expression::EvalKind eval_kind)
+{
+ switch (eval_kind)
+ {
+ case EK_bool:
+ return EV_bool;
+ case EK_short:
+ return EV_short;
+ case EK_ushort:
+ return EV_ushort;
+ case EK_long:
+ return EV_long;
+ case EK_ulong:
+ return EV_ulong;
+ case EK_longlong:
+ return EV_longlong;
+ case EK_ulonglong:
+ return EV_ulonglong;
+ case EK_octet:
+ return EV_octet;
+ case EK_floating_point:
+ return EV_double;
+ case EK_fixed_point:
+ return EV_fixed;
+ case EK_int8:
+ return EV_int8;
+ case EK_uint8:
+ return EV_uint8;
+ default:
+ return EV_none;
+ }
+}
+
// Helper function to fill out the details of where this expression
// is defined.
void
@@ -1777,6 +1811,32 @@ eval_kind (AST_Expression::AST_ExprValue *ev, AST_Expression::EvalKind ek)
// Apply binary operators to an AST_Expression after evaluating
// its sub-expressions.
// Operations supported: '+', '-', '*', '/'
+template <typename Type>
+bool
+do_eval_bin_op (AST_Expression::ExprComb op, Type a, Type b, Type &result)
+{
+ switch (op)
+ {
+ case AST_Expression::EC_add:
+ result = a + b;
+ break;
+ case AST_Expression::EC_minus:
+ result = a - b;
+ break;
+ case AST_Expression::EC_mul:
+ result = a * b;
+ break;
+ case AST_Expression::EC_div:
+ if (!b) return true;
+ result = a / b;
+ break;
+ default:
+ return true;
+ }
+
+ return false;
+}
+
AST_Expression::AST_ExprValue *
AST_Expression::eval_bin_op (AST_Expression::EvalKind ek)
{
@@ -1795,161 +1855,88 @@ AST_Expression::eval_bin_op (AST_Expression::EvalKind ek)
return nullptr;
}
+ const ExprType expr_type = eval_kind_to_expr_type (ek);
+ if (expr_type == EV_none) return nullptr;
+
ACE_NEW_RETURN (retval,
AST_ExprValue,
nullptr);
- 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 failed = true;
+ 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:
+ failed = do_eval_bin_op<ACE_CDR::Int8> (pd_ec,
+ pd_v1->ev ()->u.int8val, pd_v2->ev ()->u.int8val, retval->u.int8val);
+ break;
- switch (this->pd_ec)
- {
- case EC_add:
- retval->u.ullval =
- this->pd_v1->ev ()->u.ullval + this->pd_v2->ev ()->u.ullval;
- break;
- case EC_minus:
- retval->u.ullval =
- this->pd_v1->ev ()->u.ullval - this->pd_v2->ev ()->u.ullval;
- break;
- case EC_mul:
- retval->u.ullval =
- this->pd_v1->ev ()->u.ullval * this->pd_v2->ev ()->u.ullval;
- break;
- case EC_div:
- if (this->pd_v2->ev ()->u.ullval == 0)
- {
- delete retval;
- retval = nullptr;
- return nullptr;
- }
+ case EV_uint8:
+ failed = do_eval_bin_op<ACE_CDR::Uint8> (pd_ec,
+ 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;
- break;
- default:
- delete retval;
- retval = nullptr;
- return nullptr;
- }
- }
- 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:
+ failed = do_eval_bin_op<ACE_CDR::Short> (pd_ec,
+ pd_v1->ev ()->u.sval, pd_v2->ev ()->u.sval, retval->u.sval);
+ break;
- switch (this->pd_ec)
- {
- case EC_add:
- retval->u.llval =
- this->pd_v1->ev ()->u.llval + this->pd_v2->ev ()->u.llval;
- break;
- case EC_minus:
- retval->u.llval =
- this->pd_v1->ev ()->u.llval - this->pd_v2->ev ()->u.llval;
- break;
- case EC_mul:
- retval->u.llval =
- this->pd_v1->ev ()->u.llval * this->pd_v2->ev ()->u.llval;
- break;
- case EC_div:
- if (this->pd_v2->ev ()->u.llval == 0)
- {
- delete retval;
- retval = nullptr;
- return nullptr;
- }
+ case EV_ushort:
+ failed = do_eval_bin_op<ACE_CDR::UShort> (pd_ec,
+ 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;
- break;
- default:
- delete retval;
- retval = nullptr;
- return nullptr;
- }
- }
- else if (ek == EK_fixed_point)
- {
- this->pd_v1->set_ev (this->pd_v1->coerce (EV_fixed));
- this->pd_v2->set_ev (this->pd_v2->coerce (EV_fixed));
- retval->et = EV_fixed;
+ case EV_long:
+ failed = do_eval_bin_op<ACE_CDR::Long> (pd_ec,
+ pd_v1->ev ()->u.lval, pd_v2->ev ()->u.lval, retval->u.lval);
+ break;
- switch (this->pd_ec)
- {
- case EC_add:
- retval->u.fixedval =
- this->pd_v1->ev ()->u.fixedval + this->pd_v2->ev ()->u.fixedval;
- break;
- case EC_minus:
- retval->u.fixedval =
- this->pd_v1->ev ()->u.fixedval - this->pd_v2->ev ()->u.fixedval;
- break;
- case EC_mul:
- retval->u.fixedval =
- this->pd_v1->ev ()->u.fixedval * this->pd_v2->ev ()->u.fixedval;
- break;
- case EC_div:
- if (!this->pd_v2->ev ()->u.fixedval)
- {
- delete retval;
- retval = nullptr;
- return nullptr;
- }
+ case EV_ulong:
+ failed = do_eval_bin_op<ACE_CDR::ULong> (pd_ec,
+ pd_v1->ev ()->u.ulval, pd_v2->ev ()->u.ulval, retval->u.ulval);
+ break;
- retval->u.fixedval =
- this->pd_v1->ev ()->u.fixedval / this->pd_v2->ev ()->u.fixedval;
- break;
- default:
- delete retval;
- retval = nullptr;
- return nullptr;
- }
- }
- else
- {
- this->pd_v1->set_ev (this->pd_v1->coerce (EV_double));
- this->pd_v2->set_ev (this->pd_v2->coerce (EV_double));
- retval->et = EV_double;
+ case EV_longlong:
+ failed = do_eval_bin_op<ACE_CDR::LongLong> (pd_ec,
+ pd_v1->ev ()->u.llval, pd_v2->ev ()->u.llval, retval->u.llval);
+ break;
- switch (this->pd_ec)
- {
- case EC_add:
- retval->u.dval =
- this->pd_v1->ev ()->u.dval + this->pd_v2->ev ()->u.dval;
- break;
- case EC_minus:
- retval->u.dval =
- this->pd_v1->ev ()->u.dval - this->pd_v2->ev ()->u.dval;
- break;
- case EC_mul:
- retval->u.dval =
- this->pd_v1->ev ()->u.dval * this->pd_v2->ev ()->u.dval;
- break;
- case EC_div:
- if (ACE::is_equal (this->pd_v2->ev ()->u.dval, 0.0))
- {
- delete retval;
- retval = nullptr;
- return nullptr;
- }
+ case EV_ulonglong:
+ failed = do_eval_bin_op<ACE_CDR::ULongLong> (pd_ec,
+ pd_v1->ev ()->u.ullval, pd_v2->ev ()->u.ullval, retval->u.ullval);
+ break;
- retval->u.dval =
- this->pd_v1->ev ()->u.dval / this->pd_v2->ev ()->u.dval;
- break;
- default:
- delete retval;
- retval = nullptr;
- return nullptr;
- }
+ case EV_octet:
+ failed = do_eval_bin_op<ACE_CDR::Octet> (pd_ec,
+ pd_v1->ev ()->u.oval, pd_v2->ev ()->u.oval, retval->u.oval);
+ break;
+
+ case EV_double:
+ failed = do_eval_bin_op<ACE_CDR::Double> (pd_ec,
+ pd_v1->ev ()->u.dval, pd_v2->ev ()->u.dval, retval->u.dval);
+ break;
+
+ case EV_fixed:
+ failed = do_eval_bin_op<ACE_CDR::Fixed> (pd_ec,
+ pd_v1->ev ()->u.fixedval, pd_v2->ev ()->u.fixedval, retval->u.fixedval);
+ break;
+
+ default:
+ failed = true;
+ }
+
+ if (failed)
+ {
+ delete retval;
+ retval = nullptr;
}
return retval;
}
+
// Apply binary operators to an AST_Expression after evaluating
// its sub-expressions.
// Operations supported: '%'
@@ -2007,8 +1994,7 @@ AST_Expression::eval_mod_op (AST_Expression::EvalKind ek)
retval->u.llval =
this->pd_v1->ev ()->u.llval % this->pd_v2->ev ()->u.llval;
}
- else
- if (ek == EK_ulong)
+ 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));
@@ -2053,6 +2039,34 @@ AST_Expression::eval_mod_op (AST_Expression::EvalKind ek)
// Apply bitwise operations to an AST_Expression after evaluating
// its sub-expressions.
// Operations supported: '%', '|', '&', '^', '<<', '>>'
+template <typename Type>
+bool
+do_eval_bit_op (AST_Expression::ExprComb op, Type a, Type b, Type &result)
+{
+ switch (op)
+ {
+ case AST_Expression::EC_or:
+ result = a | b;
+ break;
+ case AST_Expression::EC_xor:
+ result = a ^ b;
+ break;
+ case AST_Expression::EC_and:
+ result = a & b;
+ break;
+ case AST_Expression::EC_left:
+ result = a << b;
+ break;
+ case AST_Expression::EC_right:
+ result = a >> b;
+ break;
+ default:
+ return true;
+ }
+
+ return false;
+}
+
AST_Expression::AST_ExprValue *
AST_Expression::eval_bit_op (AST_Expression::EvalKind ek)
{
@@ -2071,315 +2085,80 @@ AST_Expression::eval_bit_op (AST_Expression::EvalKind ek)
return nullptr;
}
+ const ExprType expr_type = eval_kind_to_expr_type (ek);
+ if (expr_type == EV_none) return nullptr;
+
ACE_NEW_RETURN (retval,
AST_ExprValue,
nullptr);
- switch (ek)
- {
- case EK_ulonglong:
- {
- 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;
-
- switch (this->pd_ec)
- {
- case EC_or:
- retval->u.ullval =
- this->pd_v1->ev ()->u.ullval | this->pd_v2->ev ()->u.ullval;
- break;
- case EC_xor:
- retval->u.ullval =
- this->pd_v1->ev ()->u.ullval ^ this->pd_v2->ev ()->u.ullval;
- break;
- case EC_and:
- retval->u.ullval =
- this->pd_v1->ev ()->u.ullval & this->pd_v2->ev ()->u.ullval;
- break;
- case EC_left:
- retval->u.ullval =
- this->pd_v1->ev ()->u.ullval << this->pd_v2->ev ()->u.ullval;
- break;
- case EC_right:
- retval->u.ullval =
- this->pd_v1->ev ()->u.ullval >> this->pd_v2->ev ()->u.ullval;
- break;
- default:
- delete retval;
- retval = nullptr;
- return nullptr;
- }
- }
-
- break;
- case 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;
+ pd_v1->set_ev (pd_v1->coerce (expr_type));
+ pd_v2->set_ev (pd_v2->coerce (expr_type));
+ retval->et = expr_type;
- switch (this->pd_ec)
- {
- case EC_or:
- retval->u.llval =
- this->pd_v1->ev ()->u.llval | this->pd_v2->ev ()->u.llval;
- break;
- case EC_xor:
- retval->u.llval =
- this->pd_v1->ev ()->u.llval ^ this->pd_v2->ev ()->u.llval;
- break;
- case EC_and:
- retval->u.llval =
- this->pd_v1->ev ()->u.llval & this->pd_v2->ev ()->u.llval;
- break;
- case EC_left:
- retval->u.llval =
- this->pd_v1->ev ()->u.llval << this->pd_v2->ev ()->u.llval;
- break;
- case EC_right:
- retval->u.llval =
- this->pd_v1->ev ()->u.llval >> this->pd_v2->ev ()->u.llval;
- break;
- default:
- delete retval;
- retval = nullptr;
- return nullptr;
- }
- }
+ bool failed = true;
+ switch (expr_type)
+ {
+ case EV_int8:
+ failed = do_eval_bit_op<ACE_CDR::Int8> (pd_ec,
+ pd_v1->ev ()->u.int8val, pd_v2->ev ()->u.int8val, retval->u.int8val);
+ break;
- break;
- case 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_uint8:
+ failed = do_eval_bit_op<ACE_CDR::Uint8> (pd_ec,
+ pd_v1->ev ()->u.uint8val, pd_v2->ev ()->u.uint8val, retval->u.uint8val);
+ break;
- switch (this->pd_ec)
- {
- case EC_or:
- retval->u.ulval =
- this->pd_v1->ev ()->u.ulval | this->pd_v2->ev ()->u.ulval;
- break;
- case EC_xor:
- retval->u.ulval =
- this->pd_v1->ev ()->u.ulval ^ this->pd_v2->ev ()->u.ulval;
- break;
- case EC_and:
- retval->u.ulval =
- this->pd_v1->ev ()->u.ulval & this->pd_v2->ev ()->u.ulval;
- break;
- case EC_left:
- retval->u.ulval =
- this->pd_v1->ev ()->u.ulval << this->pd_v2->ev ()->u.ulval;
- break;
- case EC_right:
- retval->u.ulval =
- this->pd_v1->ev ()->u.ulval >> this->pd_v2->ev ()->u.ulval;
- break;
- default:
- delete retval;
- retval = nullptr;
- return nullptr;
- }
- }
+ case EV_short:
+ failed = do_eval_bit_op<ACE_CDR::Short> (pd_ec,
+ pd_v1->ev ()->u.sval, pd_v2->ev ()->u.sval, retval->u.sval);
+ break;
- break;
- case 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_ushort:
+ failed = do_eval_bit_op<ACE_CDR::UShort> (pd_ec,
+ pd_v1->ev ()->u.usval, pd_v2->ev ()->u.usval, retval->u.usval);
+ break;
- switch (this->pd_ec)
- {
- case EC_or:
- retval->u.lval =
- this->pd_v1->ev ()->u.lval | this->pd_v2->ev ()->u.lval;
- break;
- case EC_xor:
- retval->u.lval =
- this->pd_v1->ev ()->u.lval ^ this->pd_v2->ev ()->u.lval;
- break;
- case EC_and:
- retval->u.lval =
- this->pd_v1->ev ()->u.lval & this->pd_v2->ev ()->u.lval;
- break;
- case EC_left:
- retval->u.lval =
- this->pd_v1->ev ()->u.lval << this->pd_v2->ev ()->u.lval;
- break;
- case EC_right:
- retval->u.lval =
- this->pd_v1->ev ()->u.lval >> this->pd_v2->ev ()->u.lval;
- break;
- default:
- delete retval;
- retval = nullptr;
- return nullptr;
- }
- }
+ case EV_long:
+ failed = do_eval_bit_op<ACE_CDR::Long> (pd_ec,
+ pd_v1->ev ()->u.lval, pd_v2->ev ()->u.lval, retval->u.lval);
+ break;
- break;
- case EK_ushort:
- {
- this->pd_v1->set_ev (this->pd_v1->coerce (EV_ushort));
- this->pd_v2->set_ev (this->pd_v2->coerce (EV_ushort));
- retval->et = EV_ushort;
+ case EV_ulong:
+ failed = do_eval_bit_op<ACE_CDR::ULong> (pd_ec,
+ pd_v1->ev ()->u.ulval, pd_v2->ev ()->u.ulval, retval->u.ulval);
+ break;
- switch (this->pd_ec)
- {
- case EC_or:
- retval->u.usval =
- this->pd_v1->ev ()->u.usval | this->pd_v2->ev ()->u.usval;
- break;
- case EC_xor:
- retval->u.usval =
- this->pd_v1->ev ()->u.usval ^ this->pd_v2->ev ()->u.usval;
- break;
- case EC_and:
- retval->u.usval =
- this->pd_v1->ev ()->u.usval & this->pd_v2->ev ()->u.usval;
- break;
- case EC_left:
- retval->u.usval =
- this->pd_v1->ev ()->u.usval << this->pd_v2->ev ()->u.usval;
- break;
- case EC_right:
- retval->u.usval =
- this->pd_v1->ev ()->u.usval >> this->pd_v2->ev ()->u.usval;
- break;
- default:
- delete retval;
- retval = nullptr;
- return nullptr;
- }
- }
+ case EV_longlong:
+ failed = do_eval_bit_op<ACE_CDR::LongLong> (pd_ec,
+ pd_v1->ev ()->u.llval, pd_v2->ev ()->u.llval, retval->u.llval);
+ break;
- break;
- case EK_short:
- {
- this->pd_v1->set_ev (this->pd_v1->coerce (EV_short));
- this->pd_v2->set_ev (this->pd_v2->coerce (EV_short));
- retval->et = EV_short;
+ case EV_ulonglong:
+ failed = do_eval_bit_op<ACE_CDR::ULongLong> (pd_ec,
+ pd_v1->ev ()->u.ullval, pd_v2->ev ()->u.ullval, retval->u.ullval);
+ break;
- switch (this->pd_ec)
- {
- case EC_or:
- retval->u.sval =
- this->pd_v1->ev ()->u.sval | this->pd_v2->ev ()->u.sval;
- break;
- case EC_xor:
- retval->u.sval =
- this->pd_v1->ev ()->u.sval ^ this->pd_v2->ev ()->u.sval;
- break;
- case EC_and:
- retval->u.sval =
- this->pd_v1->ev ()->u.sval & this->pd_v2->ev ()->u.sval;
- break;
- case EC_left:
- retval->u.sval =
- this->pd_v1->ev ()->u.sval << this->pd_v2->ev ()->u.sval;
- break;
- case EC_right:
- retval->u.sval =
- this->pd_v1->ev ()->u.sval >> this->pd_v2->ev ()->u.sval;
- break;
- default:
- delete retval;
- retval = nullptr;
- return nullptr;
- }
- }
+ case EV_octet:
+ failed = do_eval_bit_op<ACE_CDR::Octet> (pd_ec,
+ pd_v1->ev ()->u.oval, pd_v2->ev ()->u.oval, retval->u.oval);
+ break;
- break;
- case EK_bool:
- {
- this->pd_v1->set_ev (this->pd_v1->coerce (EV_bool));
- this->pd_v2->set_ev (this->pd_v2->coerce (EV_bool));
- retval->et = EV_bool;
+ case EV_bool:
+ failed = do_eval_bit_op<ACE_CDR::Boolean> (pd_ec,
+ pd_v1->ev ()->u.bval, pd_v2->ev ()->u.bval, retval->u.bval);
+ break;
- switch (this->pd_ec)
- {
- case EC_or:
- retval->u.bval =
- this->pd_v1->ev ()->u.bval | this->pd_v2->ev ()->u.bval;
- break;
- case EC_xor:
- retval->u.bval =
- this->pd_v1->ev ()->u.bval ^ this->pd_v2->ev ()->u.bval;
- break;
- case EC_and:
- retval->u.bval =
- this->pd_v1->ev ()->u.bval & this->pd_v2->ev ()->u.bval;
- break;
- case EC_left:
- retval->u.bval =
- this->pd_v1->ev ()->u.ulval << this->pd_v2->ev ()->u.ulval;
- break;
- case EC_right:
- retval->u.bval =
- this->pd_v1->ev ()->u.ulval >> this->pd_v2->ev ()->u.ulval;
- break;
- default:
- delete retval;
- retval = nullptr;
- return nullptr;
- }
- }
+ default:
+ failed = true;
+ }
- break;
- case EK_octet:
+ if (failed)
{
- this->pd_v1->set_ev (this->pd_v1->coerce (EV_octet));
- this->pd_v2->set_ev (this->pd_v2->coerce (EV_octet));
- retval->et = EV_octet;
-
- switch (this->pd_ec)
- {
- case EC_or:
- retval->u.oval =
- this->pd_v1->ev ()->u.oval | this->pd_v2->ev ()->u.oval;
- break;
- case EC_xor:
- retval->u.oval =
- this->pd_v1->ev ()->u.oval ^ this->pd_v2->ev ()->u.oval;
- break;
- case EC_and:
- retval->u.oval =
- this->pd_v1->ev ()->u.oval & this->pd_v2->ev ()->u.oval;
- break;
- case EC_left:
- {
- // This is the only bitwise operation that can cause overflow
- // even if both operands are in range, so we set the ExprType
- // to a large type and then check for overflow.
- retval->u.ulval =
- this->pd_v1->ev ()->u.ulval << this->pd_v2->ev ()->u.ulval;
- AST_Expression test (retval->u.ulval, EV_ulong);
- AST_ExprValue *ev = test.coerce (EV_octet);
- delete retval;
- retval = ev;
- break;
- }
- case EC_right:
- retval->u.oval =
- this->pd_v1->ev ()->u.oval >> this->pd_v2->ev ()->u.oval;
- break;
- default:
- delete retval;
- retval = nullptr;
- return nullptr;
- }
+ delete retval;
+ retval = nullptr;
}
- break;
- default:
- delete retval;
- retval = nullptr;
- return nullptr;
- }
-
return retval;
}
diff --git a/TAO/TAO_IDL/be/be_helper.cpp b/TAO/TAO_IDL/be/be_helper.cpp
index 218bc0ac534..9a8883e71e6 100644
--- a/TAO/TAO_IDL/be/be_helper.cpp
+++ b/TAO/TAO_IDL/be/be_helper.cpp
@@ -533,13 +533,12 @@ TAO_OutStream::print (AST_Expression *expr)
{
ACE_CDR::LongLong value = ev->u.llval;
/*
- * It seem in C/C++ compilers the minus sign and the bare number are
- * parsed separately for negative integer literals. This can cause
- * compilers to complain when using the minimum value of a signed integer
- * because the number without the minus sign is 1 past the max signed
- * value.
+ * It seems that in C/C++ the minus sign and the bare number are parsed
+ * separately for negative integer literals. This can cause compilers
+ * to complain when using the minimum value of a signed integer because
+ * the number without the minus sign is 1 past the max signed value.
*
- * https://stackoverflow.com/questions/65007935/integer-constant-is-so-large-that-it-is-unsigned-compiler-warning-rational
+ * https://stackoverflow.com/questions/65007935
*
* Apparently the workaround is to write it as `VALUE_PLUS_ONE - 1`.
*/
diff --git a/TAO/TAO_IDL/include/ast_expression.h b/TAO/TAO_IDL/include/ast_expression.h
index 01c666a0717..c005adc37e4 100644
--- a/TAO/TAO_IDL/include/ast_expression.h
+++ b/TAO/TAO_IDL/include/ast_expression.h
@@ -161,6 +161,8 @@ public:
, EV_none // Expression value is missing.
};
+ static ExprType eval_kind_to_expr_type (EvalKind eval_kind);
+
// Structure to describe value of constant expression and its type.
struct AST_ExprValue
{
@@ -184,8 +186,8 @@ public:
char *wstrval; // Contains wide string expr value.
ACE_CDR::ULong eval; // Contains enumeration value.
ACE_CDR::Fixed fixedval; // Contains IDL fixed value.
- ACE_CDR::Char int8val; // Signed Byte Sized Integer
- ACE_CDR::Octet uint8val; // Unsigned Byte Sized Integer
+ ACE_CDR::Int8 int8val; // Signed Byte Sized Integer
+ ACE_CDR::Uint8 uint8val; // Unsigned Byte Sized Integer
} u;
ExprType et;
diff --git a/TAO/tao/CDR.h b/TAO/tao/CDR.h
index 1b1168c5cf2..6b4a769a28b 100644
--- a/TAO/tao/CDR.h
+++ b/TAO/tao/CDR.h
@@ -499,6 +499,8 @@ TAO_Export CORBA::Boolean operator<< (TAO_OutputCDR &os,
TAO_Export CORBA::Boolean operator<< (TAO_OutputCDR &os,
ACE_OutputCDR::from_std_wstring x);
#endif /* ACE_LACKS_STD_WSTRING */
+TAO_Export CORBA::Boolean operator<< (TAO_OutputCDR &os, CORBA::Int8 x);
+TAO_Export CORBA::Boolean operator<< (TAO_OutputCDR &os, CORBA::Uint8 x);
// CDR input operators for CORBA types
@@ -538,6 +540,8 @@ TAO_Export CORBA::Boolean operator>> (TAO_InputCDR &os,
TAO_Export CORBA::Boolean operator>> (TAO_InputCDR &os,
ACE_InputCDR::to_std_wstring x);
#endif /* ACE_LACKS_STD_WSTRING */
+TAO_Export CORBA::Boolean operator>> (TAO_InputCDR &is, CORBA::Int8 &x);
+TAO_Export CORBA::Boolean operator>> (TAO_InputCDR &is, CORBA::Uint8 &x);
TAO_END_VERSIONED_NAMESPACE_DECL
diff --git a/TAO/tao/CDR.inl b/TAO/tao/CDR.inl
index 89958d671dd..02ba3827fb5 100644
--- a/TAO/tao/CDR.inl
+++ b/TAO/tao/CDR.inl
@@ -495,6 +495,19 @@ ACE_INLINE CORBA::Boolean operator<< (TAO_OutputCDR &os,
}
#endif /* ACE_LACKS_STD_WSTRING */
+ACE_INLINE CORBA::Boolean operator<< (TAO_OutputCDR &os, CORBA::Int8 x)
+{
+ return os.fragment_stream (ACE_CDR::OCTET_ALIGN, ACE_CDR::OCTET_SIZE)
+ && static_cast<ACE_OutputCDR &> (os) << x;
+}
+
+ACE_INLINE CORBA::Boolean operator<< (TAO_OutputCDR &os, CORBA::Uint8 x)
+{
+ return
+ os.fragment_stream (ACE_CDR::OCTET_ALIGN, ACE_CDR::OCTET_SIZE)
+ && static_cast<ACE_OutputCDR &> (os) << x;
+}
+
// ****************************************************************
ACE_INLINE CORBA::Boolean operator>> (TAO_InputCDR &is,
@@ -625,4 +638,14 @@ ACE_INLINE CORBA::Boolean operator>> (TAO_InputCDR &is,
}
#endif /* ACE_LACKS_STD_WSTRING */
+ACE_INLINE CORBA::Boolean operator>> (TAO_InputCDR &is, CORBA::Int8 &x)
+{
+ return static_cast<ACE_InputCDR &> (is) >> x;
+}
+
+ACE_INLINE CORBA::Boolean operator>> (TAO_InputCDR &is, CORBA::Uint8 &x)
+{
+ return static_cast<ACE_InputCDR &> (is) >> x;
+}
+
TAO_END_VERSIONED_NAMESPACE_DECL
diff --git a/TAO/tests/IDLv4/explicit_ints/IDLv4_explicit_ints.mpc b/TAO/tests/IDLv4/explicit_ints/IDLv4_explicit_ints.mpc
index 3938803c119..8a3691bfd34 100644
--- a/TAO/tests/IDLv4/explicit_ints/IDLv4_explicit_ints.mpc
+++ b/TAO/tests/IDLv4/explicit_ints/IDLv4_explicit_ints.mpc
@@ -4,4 +4,7 @@ project: taoexe {
IDL_Files {
test.idl
}
+ Source_Files {
+ main.cpp
+ }
}
diff --git a/TAO/tests/IDLv4/explicit_ints/main.cpp b/TAO/tests/IDLv4/explicit_ints/main.cpp
index beb36f2008c..9540764b58c 100644
--- a/TAO/tests/IDLv4/explicit_ints/main.cpp
+++ b/TAO/tests/IDLv4/explicit_ints/main.cpp
@@ -19,8 +19,7 @@ template <typename IntType>
void
expect_equals (bool &any_failed, const char *name, IntType actual, IntType expected)
{
- const bool failed = actual != expected;
- if (failed)
+ if (actual != expected)
{
using stream8::operator<<;
*ACE_DEFAULT_LOG_STREAM
@@ -48,11 +47,33 @@ ACE_TMAIN (int, ACE_TCHAR *[])
expect_equals<CORBA::Int64>(any_failed, "i64_min", i64_min, (-9223372036854775807 - 1));
expect_equals<CORBA::Int64>(any_failed, "i64_max", i64_max, 9223372036854775807);
+ expect_equals<CORBA::Uint8>(any_failed, "u8_min_overflow", u8_min_overflow, u8_max);
+ expect_equals<CORBA::Int8>(any_failed, "i8_min_overflow", i8_min_overflow, i8_max);
expect_equals<CORBA::Uint8>(any_failed, "u8_max_overflow", u8_max_overflow, 0);
expect_equals<CORBA::Int8>(any_failed, "i8_max_overflow", i8_max_overflow, i8_min);
expect_equals<CORBA::Uint8>(any_failed, "u8_max_negate", u8_max_negate, 0);
expect_equals<CORBA::Int8>(any_failed, "i8_max_negate", i8_max_negate, i8_min);
+ expect_equals<CORBA::Uint8>(any_failed, "u8_e1", u8_e1, 2);
+ expect_equals<CORBA::Uint8>(any_failed, "u8_e2", u8_e2, 4);
+ expect_equals<CORBA::Uint8>(any_failed, "u8_e3", u8_e3, 12);
+ expect_equals<CORBA::Uint8>(any_failed, "u8_e4", u8_e4, 3);
+ expect_equals<CORBA::Uint8>(any_failed, "u8_e5", u8_e5, 7);
+ expect_equals<CORBA::Uint8>(any_failed, "u8_e6", u8_e6, 1);
+ expect_equals<CORBA::Uint8>(any_failed, "u8_e7", u8_e7, 1);
+ expect_equals<CORBA::Uint8>(any_failed, "u8_e8", u8_e8, 16);
+ expect_equals<CORBA::Uint8>(any_failed, "u8_e9", u8_e9, 8);
+
+ expect_equals<CORBA::Int8>(any_failed, "i8_e1", i8_e1, -2);
+ expect_equals<CORBA::Int8>(any_failed, "i8_e2", i8_e2, 4);
+ expect_equals<CORBA::Int8>(any_failed, "i8_e3", i8_e3, 12);
+ expect_equals<CORBA::Int8>(any_failed, "i8_e4", i8_e4, 3);
+ expect_equals<CORBA::Int8>(any_failed, "i8_e5", i8_e5, 7);
+ expect_equals<CORBA::Int8>(any_failed, "i8_e6", i8_e6, 1);
+ expect_equals<CORBA::Int8>(any_failed, "i8_e7", i8_e7, 1);
+ expect_equals<CORBA::Int8>(any_failed, "i8_e8", i8_e8, 16);
+ expect_equals<CORBA::Int8>(any_failed, "i8_e9", i8_e9, 8);
+
return any_failed ? 1 : 0;
}
diff --git a/TAO/tests/IDLv4/explicit_ints/test.idl b/TAO/tests/IDLv4/explicit_ints/test.idl
index 03fee4b9bfa..eb1e476a80c 100644
--- a/TAO/tests/IDLv4/explicit_ints/test.idl
+++ b/TAO/tests/IDLv4/explicit_ints/test.idl
@@ -12,15 +12,34 @@ const uint64 u64_max = 18446744073709551615;
const int64 i64_min = -9223372036854775808;
const int64 i64_max = 9223372036854775807;
+const uint8 u8_min_overflow = u8_min - 1; // == u8_max
+const int8 i8_min_overflow = i8_min - 1; // == i8_max
const uint8 u8_max_overflow = u8_max + 1; // == 0
-const int8 i8_max_overflow = i8_max + 1; // == i8_min TODO: value is 0
+const int8 i8_max_overflow = i8_max + 1; // == i8_min
const uint8 u8_max_negate = ~u8_max; // == 0
const int8 i8_max_negate = ~i8_max; // == i8_min
-// TODO: More Expressions
+const uint8 u8_e1 = 2;
+const uint8 u8_e2 = u8_e1 + 2;
+const uint8 u8_e3 = u8_e2 * 3;
+const uint8 u8_e4 = u8_e3 / 4;
+const uint8 u8_e5 = u8_e4 | 5;
+const uint8 u8_e6 = u8_e5 ^ 6;
+const uint8 u8_e7 = u8_e6 & 7;
+const uint8 u8_e8 = u8_e7 << 4;
+const uint8 u8_e9 = u8_e8 >> 1;
+
+const int8 i8_e1 = -2;
+const int8 i8_e2 = i8_e1 - -6;
+const int8 i8_e3 = i8_e2 * 3;
+const int8 i8_e4 = i8_e3 / 4;
+const int8 i8_e5 = i8_e4 | 5;
+const int8 i8_e6 = i8_e5 ^ 6;
+const int8 i8_e7 = i8_e6 & 7;
+const int8 i8_e8 = i8_e7 << 4;
+const int8 i8_e9 = i8_e8 >> 1;
-/* TODO: serialization functions stop these from compiling
struct StructWithInts {
uint8 u8;
int8 i8;
@@ -45,6 +64,3 @@ case 0:
case 1:
int8 i8;
};
-*/
-
-// TODO: More situations?