diff options
author | Fred Hornsey <hornseyf@objectcomputing.com> | 2021-07-01 14:41:42 -0500 |
---|---|---|
committer | Fred Hornsey <hornseyf@objectcomputing.com> | 2021-07-01 14:41:42 -0500 |
commit | 0f50d148543e52e8c58005aad78976897bc4bacc (patch) | |
tree | 092aeeb219c3c9368b3462a8b971d2eee50d2860 /TAO/TAO_IDL | |
parent | 354b698dd92c075dc01d36bd01fefd56099ce6a5 (diff) | |
download | ATCD-0f50d148543e52e8c58005aad78976897bc4bacc.tar.gz |
Fix Integer Literals for Windows
Diffstat (limited to 'TAO/TAO_IDL')
-rw-r--r-- | TAO/TAO_IDL/be/be_helper.cpp | 42 | ||||
-rw-r--r-- | TAO/TAO_IDL/be/be_union_branch.cpp | 4 | ||||
-rw-r--r-- | TAO/TAO_IDL/be/be_visitor_union/discriminant_ci.cpp | 4 |
3 files changed, 28 insertions, 22 deletions
diff --git a/TAO/TAO_IDL/be/be_helper.cpp b/TAO/TAO_IDL/be/be_helper.cpp index 09f4943f14c..1f8ca4e0121 100644 --- a/TAO/TAO_IDL/be/be_helper.cpp +++ b/TAO/TAO_IDL/be/be_helper.cpp @@ -499,6 +499,26 @@ TAO_OutStream::print (UTL_IdList *idl) return *this; } +template <typename IntType> +void +signed_int_helper (TAO_OutStream &os, IntType value, IntType min, const char *specifier) +{ + /* + * 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 + * + * Apparently the workaround is to write it as `VALUE_PLUS_ONE - 1`. + */ + const bool min_value = value == min; + if (min_value) ++value; + os.print (specifier, value); + if (min_value) os.print (" - 1"); +} + TAO_OutStream& TAO_OutStream::print (AST_Expression *expr) { @@ -523,30 +543,16 @@ TAO_OutStream::print (AST_Expression *expr) this->TAO_OutStream::print (ACE_INT32_FORMAT_SPECIFIER_ASCII "%c", ev->u.usval, 'U'); break; case AST_Expression::EV_long: - this->TAO_OutStream::print (ACE_INT32_FORMAT_SPECIFIER_ASCII, ev->u.lval); + signed_int_helper<ACE_CDR::Long> ( + *this, ev->u.lval, ACE_INT32_MIN, ACE_INT32_FORMAT_SPECIFIER_ASCII); break; case AST_Expression::EV_ulong: this->TAO_OutStream::print (ACE_UINT32_FORMAT_SPECIFIER_ASCII "%c", ev->u.ulval, 'U'); break; case AST_Expression::EV_longlong: this->TAO_OutStream::print ("ACE_INT64_LITERAL ("); - { - ACE_CDR::LongLong value = ev->u.llval; - /* - * 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 - * - * Apparently the workaround is to write it as `VALUE_PLUS_ONE - 1`. - */ - const bool min_value = value == ACE_INT64_MIN; - if (min_value) ++value; - TAO_OutStream::print (ACE_INT64_FORMAT_SPECIFIER_ASCII, value); - if (min_value) TAO_OutStream::print (" - 1"); - } + signed_int_helper<ACE_CDR::LongLong> ( + *this, ev->u.llval, ACE_INT64_MIN, ACE_INT64_FORMAT_SPECIFIER_ASCII); this->TAO_OutStream::print (")"); break; case AST_Expression::EV_ulonglong: diff --git a/TAO/TAO_IDL/be/be_union_branch.cpp b/TAO/TAO_IDL/be/be_union_branch.cpp index de59bd44cfb..ce9ed6972d8 100644 --- a/TAO/TAO_IDL/be/be_union_branch.cpp +++ b/TAO/TAO_IDL/be/be_union_branch.cpp @@ -118,11 +118,9 @@ be_union_branch::gen_default_label_value (TAO_OutStream *os, switch (bu->udisc_type ()) { case AST_Expression::EV_short: - case AST_Expression::EV_int8: *os << dv.u.short_val; break; case AST_Expression::EV_ushort: - case AST_Expression::EV_uint8: *os << dv.u.ushort_val; break; case AST_Expression::EV_long: @@ -133,6 +131,8 @@ be_union_branch::gen_default_label_value (TAO_OutStream *os, break; case AST_Expression::EV_octet: case AST_Expression::EV_char: + case AST_Expression::EV_int8: + case AST_Expression::EV_uint8: os->print ("'\\%o'", dv.u.char_val); break; case AST_Expression::EV_bool: diff --git a/TAO/TAO_IDL/be/be_visitor_union/discriminant_ci.cpp b/TAO/TAO_IDL/be/be_visitor_union/discriminant_ci.cpp index 639e19918ed..5fe1cfe59a2 100644 --- a/TAO/TAO_IDL/be/be_visitor_union/discriminant_ci.cpp +++ b/TAO/TAO_IDL/be/be_visitor_union/discriminant_ci.cpp @@ -159,11 +159,9 @@ be_visitor_union_discriminant_ci::visit_predefined_type ( switch (bu->udisc_type ()) { case AST_Expression::EV_short: - case AST_Expression::EV_int8: *os << dv.u.short_val; break; case AST_Expression::EV_ushort: - case AST_Expression::EV_uint8: *os << dv.u.ushort_val; break; case AST_Expression::EV_long: @@ -174,6 +172,8 @@ be_visitor_union_discriminant_ci::visit_predefined_type ( break; case AST_Expression::EV_char: case AST_Expression::EV_octet: + case AST_Expression::EV_int8: + case AST_Expression::EV_uint8: os->print ("'\\%o'", dv.u.char_val); break; case AST_Expression::EV_bool: |