OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // Slightly adapted for inclusion in V8. | 5 // Slightly adapted for inclusion in V8. |
6 // Copyright 2014 the V8 project authors. All rights reserved. | 6 // Copyright 2014 the V8 project authors. All rights reserved. |
7 | 7 |
8 #ifndef V8_BASE_SAFE_CONVERSIONS_IMPL_H_ | 8 #ifndef V8_BASE_SAFE_CONVERSIONS_IMPL_H_ |
9 #define V8_BASE_SAFE_CONVERSIONS_IMPL_H_ | 9 #define V8_BASE_SAFE_CONVERSIONS_IMPL_H_ |
10 | 10 |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
83 | 83 |
84 // Signed to unsigned: Dst cannot be statically determined to contain Src. | 84 // Signed to unsigned: Dst cannot be statically determined to contain Src. |
85 template <typename Dst, typename Src> | 85 template <typename Dst, typename Src> |
86 struct StaticDstRangeRelationToSrcRange<Dst, | 86 struct StaticDstRangeRelationToSrcRange<Dst, |
87 Src, | 87 Src, |
88 INTEGER_REPRESENTATION_UNSIGNED, | 88 INTEGER_REPRESENTATION_UNSIGNED, |
89 INTEGER_REPRESENTATION_SIGNED> { | 89 INTEGER_REPRESENTATION_SIGNED> { |
90 static const NumericRangeRepresentation value = NUMERIC_RANGE_NOT_CONTAINED; | 90 static const NumericRangeRepresentation value = NUMERIC_RANGE_NOT_CONTAINED; |
91 }; | 91 }; |
92 | 92 |
93 enum RangeConstraint { | 93 enum RangeConstraint : unsigned char { |
94 RANGE_VALID = 0x0, // Value can be represented by the destination type. | 94 RANGE_VALID = 0x0, // Value can be represented by the destination type. |
95 RANGE_UNDERFLOW = 0x1, // Value would overflow. | 95 RANGE_UNDERFLOW = 0x1, // Value would overflow. |
96 RANGE_OVERFLOW = 0x2, // Value would underflow. | 96 RANGE_OVERFLOW = 0x2, // Value would underflow. |
97 RANGE_INVALID = RANGE_UNDERFLOW | RANGE_OVERFLOW // Invalid (i.e. NaN). | 97 RANGE_INVALID = RANGE_UNDERFLOW | RANGE_OVERFLOW // Invalid (i.e. NaN). |
98 }; | 98 }; |
99 | 99 |
100 // Helper function for coercing an int back to a RangeContraint. | 100 // Helper function for coercing an int back to a RangeContraint. |
101 inline RangeConstraint GetRangeConstraint(int integer_range_constraint) { | 101 inline RangeConstraint GetRangeConstraint(int integer_range_constraint) { |
102 DCHECK(integer_range_constraint >= RANGE_VALID && | 102 DCHECK(integer_range_constraint >= RANGE_VALID && |
103 integer_range_constraint <= RANGE_INVALID); | 103 integer_range_constraint <= RANGE_INVALID); |
104 return static_cast<RangeConstraint>(integer_range_constraint); | 104 return static_cast<RangeConstraint>(integer_range_constraint); |
105 } | 105 } |
106 | 106 |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
211 STATIC_ASSERT(std::numeric_limits<Src>::is_specialized); | 211 STATIC_ASSERT(std::numeric_limits<Src>::is_specialized); |
212 STATIC_ASSERT(std::numeric_limits<Dst>::is_specialized); | 212 STATIC_ASSERT(std::numeric_limits<Dst>::is_specialized); |
213 return DstRangeRelationToSrcRangeImpl<Dst, Src>::Check(value); | 213 return DstRangeRelationToSrcRangeImpl<Dst, Src>::Check(value); |
214 } | 214 } |
215 | 215 |
216 } // namespace internal | 216 } // namespace internal |
217 } // namespace base | 217 } // namespace base |
218 } // namespace v8 | 218 } // namespace v8 |
219 | 219 |
220 #endif // V8_BASE_SAFE_CONVERSIONS_IMPL_H_ | 220 #endif // V8_BASE_SAFE_CONVERSIONS_IMPL_H_ |
OLD | NEW |