OLD | NEW |
---|---|
1 // Copyright 2006-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2008 the V8 project authors. All rights reserved. |
Karl Klose
2011/04/12 07:55:40
Please update to 2011.
| |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
11 // with the distribution. | 11 // with the distribution. |
12 // * Neither the name of Google Inc. nor the names of its | 12 // * Neither the name of Google Inc. nor the names of its |
13 // contributors may be used to endorse or promote products derived | 13 // contributors may be used to endorse or promote products derived |
14 // from this software without specific prior written permission. | 14 // from this software without specific prior written permission. |
15 // | 15 // |
16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | 16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | 17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | 18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | 19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
27 | 27 |
28 #ifndef V8_CONVERSIONS_H_ | 28 #ifndef V8_CONVERSIONS_H_ |
29 #define V8_CONVERSIONS_H_ | 29 #define V8_CONVERSIONS_H_ |
30 | 30 |
31 #include "scanner-base.h" | |
32 | |
31 namespace v8 { | 33 namespace v8 { |
32 namespace internal { | 34 namespace internal { |
33 | 35 |
34 | 36 |
35 // The fast double-to-(unsigned-)int conversion routine does not guarantee | 37 // The fast double-to-(unsigned-)int conversion routine does not guarantee |
36 // rounding towards zero. | 38 // rounding towards zero. |
37 // The result is unspecified if x is infinite or NaN, or if the rounded | 39 // The result is unspecified if x is infinite or NaN, or if the rounded |
38 // integer value is outside the range of type int. | 40 // integer value is outside the range of type int. |
39 static inline int FastD2I(double x) { | 41 static inline int FastD2I(double x) { |
40 // The static_cast convertion from double to int used to be slow, but | 42 // The static_cast convertion from double to int used to be slow, but |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
84 ALLOW_TRAILING_JUNK = 4 | 86 ALLOW_TRAILING_JUNK = 4 |
85 }; | 87 }; |
86 | 88 |
87 | 89 |
88 // Convert from Number object to C integer. | 90 // Convert from Number object to C integer. |
89 static inline int32_t NumberToInt32(Object* number); | 91 static inline int32_t NumberToInt32(Object* number); |
90 static inline uint32_t NumberToUint32(Object* number); | 92 static inline uint32_t NumberToUint32(Object* number); |
91 | 93 |
92 | 94 |
93 // Converts a string into a double value according to ECMA-262 9.3.1 | 95 // Converts a string into a double value according to ECMA-262 9.3.1 |
94 double StringToDouble(String* str, int flags, double empty_string_val = 0); | 96 double StringToDouble(UnicodeCache* unicode_cache, |
95 double StringToDouble(Vector<const char> str, | 97 String* str, |
98 int flags, | |
99 double empty_string_val = 0); | |
100 double StringToDouble(UnicodeCache* unicode_cache, | |
101 Vector<const char> str, | |
96 int flags, | 102 int flags, |
97 double empty_string_val = 0); | 103 double empty_string_val = 0); |
98 // This version expects a zero-terminated character array. | 104 // This version expects a zero-terminated character array. |
99 double StringToDouble(const char* str, int flags, double empty_string_val = 0); | 105 double StringToDouble(UnicodeCache* unicode_cache, |
106 const char* str, | |
107 int flags, | |
108 double empty_string_val = 0); | |
100 | 109 |
101 // Converts a string into an integer. | 110 // Converts a string into an integer. |
102 double StringToInt(String* str, int radix); | 111 double StringToInt(UnicodeCache* unicode_cache, String* str, int radix); |
103 | 112 |
104 // Converts a double to a string value according to ECMA-262 9.8.1. | 113 // Converts a double to a string value according to ECMA-262 9.8.1. |
105 // The buffer should be large enough for any floating point number. | 114 // The buffer should be large enough for any floating point number. |
106 // 100 characters is enough. | 115 // 100 characters is enough. |
107 const char* DoubleToCString(double value, Vector<char> buffer); | 116 const char* DoubleToCString(double value, Vector<char> buffer); |
108 | 117 |
109 // Convert an int to a null-terminated string. The returned string is | 118 // Convert an int to a null-terminated string. The returned string is |
110 // located inside the buffer, but not necessarily at the start. | 119 // located inside the buffer, but not necessarily at the start. |
111 const char* IntToCString(int n, Vector<char> buffer); | 120 const char* IntToCString(int n, Vector<char> buffer); |
112 | 121 |
113 // Additional number to string conversions for the number type. | 122 // Additional number to string conversions for the number type. |
114 // The caller is responsible for calling free on the returned pointer. | 123 // The caller is responsible for calling free on the returned pointer. |
115 char* DoubleToFixedCString(double value, int f); | 124 char* DoubleToFixedCString(double value, int f); |
116 char* DoubleToExponentialCString(double value, int f); | 125 char* DoubleToExponentialCString(double value, int f); |
117 char* DoubleToPrecisionCString(double value, int f); | 126 char* DoubleToPrecisionCString(double value, int f); |
118 char* DoubleToRadixCString(double value, int radix); | 127 char* DoubleToRadixCString(double value, int radix); |
119 | 128 |
120 } } // namespace v8::internal | 129 } } // namespace v8::internal |
121 | 130 |
122 #endif // V8_CONVERSIONS_H_ | 131 #endif // V8_CONVERSIONS_H_ |
OLD | NEW |