OLD | NEW |
---|---|
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project 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 #ifndef V8_UTILS_H_ | 5 #ifndef V8_UTILS_H_ |
6 #define V8_UTILS_H_ | 6 #define V8_UTILS_H_ |
7 | 7 |
8 #include <limits.h> | 8 #include <limits.h> |
9 #include <stdlib.h> | 9 #include <stdlib.h> |
10 #include <string.h> | 10 #include <string.h> |
11 | 11 |
12 #include "src/allocation.h" | 12 #include "src/allocation.h" |
13 #include "src/base/macros.h" | 13 #include "src/base/macros.h" |
14 #include "src/checks.h" | 14 #include "src/checks.h" |
15 #include "src/globals.h" | 15 #include "src/globals.h" |
16 #include "src/list.h" | 16 #include "src/list.h" |
17 #include "src/platform.h" | 17 #include "src/platform.h" |
18 #include "src/vector.h" | 18 #include "src/vector.h" |
19 #include "src/base/safe_math.h" | |
19 | 20 |
20 namespace v8 { | 21 namespace v8 { |
21 namespace internal { | 22 namespace internal { |
22 | 23 |
23 // ---------------------------------------------------------------------------- | 24 // ---------------------------------------------------------------------------- |
24 // General helper functions | 25 // General helper functions |
25 | 26 |
26 // Returns true iff x is a power of 2. Cannot be used with the maximally | 27 // Returns true iff x is a power of 2. Cannot be used with the maximally |
27 // negative value of the type T (the -1 overflows). | 28 // negative value of the type T (the -1 overflows). |
28 template <typename T> | 29 template <typename T> |
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
245 template<> struct make_unsigned<int32_t> { | 246 template<> struct make_unsigned<int32_t> { |
246 typedef uint32_t type; | 247 typedef uint32_t type; |
247 }; | 248 }; |
248 | 249 |
249 | 250 |
250 template<> struct make_unsigned<int64_t> { | 251 template<> struct make_unsigned<int64_t> { |
251 typedef uint64_t type; | 252 typedef uint64_t type; |
252 }; | 253 }; |
253 | 254 |
254 | 255 |
256 template<typename T> bool MultiplyOverflows(T x, T y) { | |
danno
2014/06/18 14:55:04
Do you really need these wrappers? It seems that t
| |
257 v8::base::internal::CheckedNumeric<T> checked_result = x; | |
258 checked_result = checked_result * y; | |
259 return !checked_result.IsValid(); | |
260 } | |
261 | |
262 | |
263 template<typename T> bool AdditionOverflows(T x, T y) { | |
264 v8::base::internal::CheckedNumeric<T> checked_result = x; | |
265 checked_result = checked_result + y; | |
266 return !checked_result.IsValid(); | |
267 } | |
268 | |
269 | |
255 // ---------------------------------------------------------------------------- | 270 // ---------------------------------------------------------------------------- |
256 // BitField is a help template for encoding and decode bitfield with | 271 // BitField is a help template for encoding and decode bitfield with |
257 // unsigned content. | 272 // unsigned content. |
258 | 273 |
259 template<class T, int shift, int size, class U> | 274 template<class T, int shift, int size, class U> |
260 class BitFieldBase { | 275 class BitFieldBase { |
261 public: | 276 public: |
262 // A type U mask of bit field. To use all bits of a type U of x bits | 277 // A type U mask of bit field. To use all bits of a type U of x bits |
263 // in a bitfield without compiler warnings we have to compute 2^x | 278 // in a bitfield without compiler warnings we have to compute 2^x |
264 // without using a shift count of x in the computation. | 279 // without using a shift count of x in the computation. |
(...skipping 1309 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1574 // Add formatted contents like printf based on a va_list. | 1589 // Add formatted contents like printf based on a va_list. |
1575 void AddFormattedList(const char* format, va_list list); | 1590 void AddFormattedList(const char* format, va_list list); |
1576 private: | 1591 private: |
1577 DISALLOW_IMPLICIT_CONSTRUCTORS(StringBuilder); | 1592 DISALLOW_IMPLICIT_CONSTRUCTORS(StringBuilder); |
1578 }; | 1593 }; |
1579 | 1594 |
1580 | 1595 |
1581 } } // namespace v8::internal | 1596 } } // namespace v8::internal |
1582 | 1597 |
1583 #endif // V8_UTILS_H_ | 1598 #endif // V8_UTILS_H_ |
OLD | NEW |