Merge lp:~paul-lucas/zorba/bug-951016 into lp:zorba

Proposed by Paul J. Lucas
Status: Merged
Approved by: Matthias Brantner
Approved revision: 10777
Merged at revision: 10782
Proposed branch: lp:~paul-lucas/zorba/bug-951016
Merge into: lp:zorba
Diff against target: 301 lines (+180/-12)
4 files modified
src/util/stl_util.h (+75/-0)
src/zorbatypes/decimal.h (+10/-5)
src/zorbatypes/integer.cpp (+34/-2)
src/zorbatypes/integer.h (+61/-5)
To merge this branch: bzr merge lp:~paul-lucas/zorba/bug-951016
Reviewer Review Type Date Requested Status
Matthias Brantner Approve
Paul J. Lucas Approve
Review via email: mp+102707@code.launchpad.net

This proposal supersedes a proposal from 2012-04-18.

Commit message

Added functions to get rid of warnings.
Added is_xs_TTTTTT() functions to Integer.

Description of the change

Added functions to get rid of warnings.
Added is_xs_TTTTTT() functions to Integer.

To post a comment you must log in.
Revision history for this message
Paul J. Lucas (paul-lucas) : Posted in a previous version of this proposal
review: Approve
Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote : Posted in a previous version of this proposal
Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote : Posted in a previous version of this proposal

The attempt to merge lp:~paul-lucas/zorba/bug-951016 into lp:zorba failed. Below is the output from the failed tests.

CMake Error at /home/ceej/zo/testing/zorbatest/tester/TarmacLander.cmake:274 (message):
  Validation queue job bug-951016-2012-04-19T14-05-59.25Z is finished. The
  final status was:

  No tests were run - build or configure step must have failed.

  Not commiting changes.

Error in read script: /home/ceej/zo/testing/zorbatest/tester/TarmacLander.cmake

Revision history for this message
Paul J. Lucas (paul-lucas) :
review: Approve
Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :
Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :

Validation queue job bug-951016-2012-04-19T14-44-58.911Z is finished. The final status was:

All tests succeeded!

Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :

Voting does not meet specified criteria. Required: Approve > 1, Disapprove < 1, Needs Fixing < 1, Pending < 1. Got: 1 Approve, 1 Pending.

Revision history for this message
Matthias Brantner (matthias-brantner) :
review: Approve
Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :
Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :

Validation queue job bug-951016-2012-04-19T16-15-57.634Z is finished. The final status was:

All tests succeeded!

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/util/stl_util.h'
2--- src/util/stl_util.h 2012-04-16 20:56:43 +0000
3+++ src/util/stl_util.h 2012-04-19 14:22:23 +0000
4@@ -21,6 +21,7 @@
5 #include <cassert>
6 #include <cstring>
7 #include <iterator>
8+#include <limits>
9 #include <set>
10 #include <stack>
11
12@@ -292,6 +293,80 @@
13
14 ///////////////////////////////////////////////////////////////////////////////
15
16+//
17+// These functions are used to test whether a value of numeric type N1 is
18+// within the range of another numeric type N2. It correctly handles the
19+// cases where the "signed-ness" of N1 and N2 differ such that the code is
20+// warning-free.
21+//
22+
23+template<typename N1,typename N2> inline
24+typename std::enable_if<ZORBA_TR1_NS::is_signed<N1>::value
25+ && ZORBA_TR1_NS::is_signed<N2>::value,bool>::type
26+ge_min( N1 n1, N2 ) {
27+ return n1 >= std::numeric_limits<N2>::min();
28+}
29+
30+template<typename N1,typename N2> inline
31+typename std::enable_if<ZORBA_TR1_NS::is_signed<N1>::value
32+ && ZORBA_TR1_NS::is_unsigned<N2>::value,bool>::type
33+ge_min( N1 n1, N2 ) {
34+ return n1 >= 0;
35+}
36+
37+template<typename N1,typename N2> inline
38+typename std::enable_if<ZORBA_TR1_NS::is_unsigned<N1>::value
39+ && ZORBA_TR1_NS::is_signed<N2>::value,bool>::type
40+ge_min( N1, N2 ) {
41+ return true;
42+}
43+
44+template<typename N1,typename N2> inline
45+typename std::enable_if<ZORBA_TR1_NS::is_unsigned<N1>::value
46+ && ZORBA_TR1_NS::is_unsigned<N2>::value,bool>::type
47+ge_min( N1, N2 ) {
48+ return true;
49+}
50+
51+template<typename N1,typename N2> inline
52+typename std::enable_if<ZORBA_TR1_NS::is_signed<N1>::value
53+ && ZORBA_TR1_NS::is_signed<N2>::value,bool>::type
54+le_max( N1 n1, N2 ) {
55+ return n1 <= std::numeric_limits<N2>::max();
56+}
57+
58+template<typename N1,typename N2> inline
59+typename std::enable_if<ZORBA_TR1_NS::is_signed<N1>::value
60+ && ZORBA_TR1_NS::is_unsigned<N2>::value,bool>::type
61+le_max( N1 n1, N2 ) {
62+ return n1 <= 0 || static_cast<N2>( n1 ) <= std::numeric_limits<N2>::max();
63+}
64+
65+template<typename N1,typename N2> inline
66+typename std::enable_if<ZORBA_TR1_NS::is_unsigned<N1>::value
67+ && ZORBA_TR1_NS::is_signed<N2>::value,bool>::type
68+le_max( N1 n1, N2 ) {
69+ return n1 <= static_cast<N1>( std::numeric_limits<N2>::max() );
70+}
71+
72+template<typename N1,typename N2> inline
73+typename std::enable_if<ZORBA_TR1_NS::is_unsigned<N1>::value
74+ && ZORBA_TR1_NS::is_unsigned<N2>::value,bool>::type
75+le_max( N1 n1, N2 ) {
76+ return n1 <= std::numeric_limits<N2>::max();
77+}
78+
79+#define ZORBA_GE_MIN(N,T) \
80+ ::zorba::ztd::ge_min( N, static_cast<T>(0) )
81+
82+#define ZORBA_LE_MAX(N,T) \
83+ ::zorba::ztd::le_max( N, static_cast<T>(0) )
84+
85+#define ZORBA_IN_RANGE(N,T) \
86+ ( ZORBA_GE_MIN(N,T) && ZORBA_LE_MAX(N,T) )
87+
88+///////////////////////////////////////////////////////////////////////////////
89+
90 template<typename T> class stack_generator {
91 std::stack<T> &stk;
92 public:
93
94=== modified file 'src/zorbatypes/decimal.h'
95--- src/zorbatypes/decimal.h 2012-04-17 16:07:10 +0000
96+++ src/zorbatypes/decimal.h 2012-04-19 14:22:23 +0000
97@@ -200,7 +200,9 @@
98
99 ////////// miscellaneous ////////////////////////////////////////////////////
100
101- bool is_integer() const;
102+ bool is_xs_int() const;
103+ bool is_xs_integer() const;
104+ bool is_xs_long() const;
105
106 uint32_t hash() const;
107
108@@ -227,8 +229,6 @@
109
110 static uint32_t hash( value_type const& );
111
112- bool is_xs_long() const;
113-
114 enum parse_options {
115 parse_integer,
116 parse_decimal
117@@ -387,13 +387,18 @@
118 return hash( value_ );
119 }
120
121-inline bool Decimal::is_integer() const {
122+inline bool Decimal::is_xs_int() const {
123+ return value_.is_integer() &&
124+ value_ >= MAPM::getMinInt32() && value_ <= MAPM::getMaxInt32();
125+}
126+
127+inline bool Decimal::is_xs_integer() const {
128 return value_.is_integer() != 0;
129 }
130
131 inline bool Decimal::is_xs_long() const {
132 return value_.is_integer() &&
133- value_ > MAPM::getMinInt64() && value_ < MAPM::getMaxInt64();
134+ value_ >= MAPM::getMinInt64() && value_ <= MAPM::getMaxInt64();
135 }
136
137 inline int Decimal::sign() const {
138
139=== modified file 'src/zorbatypes/integer.cpp'
140--- src/zorbatypes/integer.cpp 2012-04-17 16:07:10 +0000
141+++ src/zorbatypes/integer.cpp 2012-04-19 14:22:23 +0000
142@@ -259,7 +259,7 @@
143
144 TEMPLATE_DECL(T)
145 bool operator==( INTEGER_IMPL(T) const &i, Decimal const &d ) {
146- return d.is_integer() && i.itod() == d.value_;
147+ return d.is_xs_integer() && i.itod() == d.value_;
148 }
149
150 #define ZORBA_INTEGER_OP(OP) \
151@@ -366,7 +366,7 @@
152
153 TEMPLATE_DECL(T)
154 MAPM INTEGER_IMPL(T)::itod() const {
155- if ( is_long() )
156+ if ( is_cxx_long() )
157 return static_cast<long>( value_ );
158 ztd::itoa_buf_type buf;
159 return ztd::itoa( value_, buf );
160@@ -377,6 +377,38 @@
161 uint32_t IntegerImpl::hash() const {
162 return Decimal::hash( value_ );
163 }
164+
165+bool IntegerImpl::is_xs_byte() const {
166+ static MAPM xs_byte_min( "-128" );
167+ static MAPM xs_byte_max( "127" );
168+ return value_ >= xs_byte_min && value_ <= xs_byte_max;
169+}
170+
171+bool IntegerImpl::is_xs_short() const {
172+ static MAPM xs_short_min( "-32768" );
173+ static MAPM xs_short_max( "32767" );
174+ return value_ >= xs_short_min && value_ <= xs_short_max;
175+}
176+
177+bool IntegerImpl::is_xs_unsignedByte() const {
178+ static MAPM xs_unsignedByte_max( "256" );
179+ return value_.sign() >= 0 && value_ <= xs_unsignedByte_max;
180+}
181+
182+bool IntegerImpl::is_xs_unsignedInt() const {
183+ static MAPM xs_unsignedInt_max( "4294967295" );
184+ return value_.sign() >= 0 && value_ <= xs_unsignedInt_max;
185+}
186+
187+bool IntegerImpl::is_xs_unsignedLong() const {
188+ static MAPM xs_unsignedLong_max( "18446744073709551615" );
189+ return value_.sign() >= 0 && value_ <= xs_unsignedLong_max;
190+}
191+
192+bool IntegerImpl::is_xs_unsignedShort() const {
193+ static MAPM xs_unsignedShort_max( "65536" );
194+ return value_.sign() >= 0 && value_ <= xs_unsignedShort_max;
195+}
196 #endif /* ZORBA_WITH_BIG_INTEGER */
197
198 TEMPLATE_DECL(T)
199
200=== modified file 'src/zorbatypes/integer.h'
201--- src/zorbatypes/integer.h 2012-04-17 16:07:10 +0000
202+++ src/zorbatypes/integer.h 2012-04-19 14:22:23 +0000
203@@ -439,6 +439,15 @@
204
205 int compare( IntegerImpl const& ) const;
206 uint32_t hash() const;
207+ bool is_cxx_long() const;
208+ bool is_xs_byte() const;
209+ bool is_xs_int() const;
210+ bool is_xs_long() const;
211+ bool is_xs_short() const;
212+ bool is_xs_unsignedByte() const;
213+ bool is_xs_unsignedInt() const;
214+ bool is_xs_unsignedLong() const;
215+ bool is_xs_unsignedShort() const;
216 int sign() const;
217 zstring toString() const;
218 static IntegerImpl const& one();
219@@ -478,8 +487,8 @@
220 static value_type make_value_type( T n ) {
221 return value_type( static_cast<int_cast_type>( n ) );
222 }
223+
224 #else /* ZORBA_WITH_BIG_INTEGER */
225- bool is_long() const;
226
227 static value_type ftoi( value_type v ) {
228 return v; // intentional no-op
229@@ -1028,11 +1037,19 @@
230 return value_.compare( i.value_ );
231 }
232
233+inline bool IntegerImpl::is_xs_int() const {
234+ return value_ >= MAPM::getMinInt32() && value_ <= MAPM::getMaxInt32();
235+}
236+
237+inline bool IntegerImpl::is_xs_long() const {
238+ return value_ >= MAPM::getMinInt64() && value_ <= MAPM::getMaxInt64();
239+}
240+
241 inline int IntegerImpl::sign() const {
242 return value_.sign();
243 }
244
245-#else
246+#else /* ZORBA_WITH_BIG_INTEGER */
247
248 template<typename I>
249 inline int IntegerImpl<I>::compare( IntegerImpl const &i ) const {
250@@ -1045,9 +1062,48 @@
251 }
252
253 template<typename I>
254-inline bool IntegerImpl<I>::is_long() const {
255- return value_ >= std::numeric_limits<long>::min() &&
256- value_ <= std::numeric_limits<long>::max();
257+inline bool IntegerImpl<I>::is_cxx_long() const {
258+ return ZORBA_IN_RANGE( value_, long );
259+}
260+
261+template<typename I>
262+inline bool IntegerImpl<I>::is_xs_byte() const {
263+ return ZORBA_IN_RANGE( value_, xs_byte );
264+}
265+
266+template<typename I>
267+inline bool IntegerImpl<I>::is_xs_int() const {
268+ return ZORBA_IN_RANGE( value_, xs_int );
269+}
270+
271+template<typename I>
272+inline bool IntegerImpl<I>::is_xs_long() const {
273+ return ZORBA_IN_RANGE( value_, xs_long );
274+}
275+
276+template<typename I>
277+inline bool IntegerImpl<I>::is_xs_short() const {
278+ return ZORBA_IN_RANGE( value_, xs_short );
279+}
280+
281+template<typename I>
282+inline bool IntegerImpl<I>::is_xs_unsignedByte() const {
283+ return ZORBA_IN_RANGE( value_, xs_unsignedByte );
284+}
285+
286+template<typename I>
287+inline bool IntegerImpl<I>::is_xs_unsignedInt() const {
288+ return ZORBA_IN_RANGE( value_, xs_unsignedInt );
289+}
290+
291+template<typename I>
292+inline bool IntegerImpl<I>::is_xs_unsignedLong() const {
293+ return ZORBA_IN_RANGE( value_, xs_unsignedLong );
294+}
295+
296+template<typename I>
297+inline bool IntegerImpl<I>::is_xs_unsignedShort() const {
298+ return ZORBA_IN_RANGE( value_, xs_unsignedShort );
299 }
300
301 template<typename I>

Subscribers

People subscribed via source and target branches