Thrift-1395: Patch to prevent warnings for integer types in some cases
Client: delpi
Patch: Jens Geyer
Constants such as i32 = 0x80000000 produce a Delphi warning. The current code renders such values as positive integer, which needs an explicit typecast to satisfy the Delphi compiler.
git-svn-id: https://svn.apache.org/repos/asf/thrift/trunk@1188494 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/compiler/cpp/src/generate/t_delphi_generator.cc b/compiler/cpp/src/generate/t_delphi_generator.cc
index 8e1ae7b..4798b61 100644
--- a/compiler/cpp/src/generate/t_delphi_generator.cc
+++ b/compiler/cpp/src/generate/t_delphi_generator.cc
@@ -756,10 +756,32 @@
render << ((value->get_integer() > 0) ? "True" : "False");
break;
case t_base_type::TYPE_BYTE:
+ if( 0x7F < value->get_integer()) {
+ render << "ShortInt( " << value->get_integer() << ")";
+ } else {
+ render << value->get_integer();
+ }
+ break;
case t_base_type::TYPE_I16:
+ if( 0x7FFF < value->get_integer()) {
+ render << "SmallInt( " << value->get_integer() << ")";
+ } else {
+ render << value->get_integer();
+ }
+ break;
case t_base_type::TYPE_I32:
+ if( 0x7FFFFFFF < value->get_integer()) {
+ render << "LongInt( " << value->get_integer() << ")";
+ } else {
+ render << value->get_integer();
+ }
+ break;
case t_base_type::TYPE_I64:
- render << value->get_integer();
+ if( 0x7FFFFFFFFFFFFFFF < value->get_integer()) {
+ render << "Int64( " << value->get_integer() << ")";
+ } else {
+ render << value->get_integer();
+ }
break;
case t_base_type::TYPE_DOUBLE:
if (value->get_type() == t_const_value::CV_INTEGER) {