Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 #include "vm/object.h" | 5 #include "vm/object.h" |
| 6 | 6 |
| 7 #include "include/dart_api.h" | 7 #include "include/dart_api.h" |
| 8 #include "platform/assert.h" | 8 #include "platform/assert.h" |
| 9 #include "vm/assembler.h" | 9 #include "vm/assembler.h" |
| 10 #include "vm/become.h" | 10 #include "vm/become.h" |
| (...skipping 19149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 19160 neg = false; | 19160 neg = false; |
| 19161 result.set_digits( | 19161 result.set_digits( |
| 19162 TypedData::Handle(zone, TypedData::EmptyUint32Array(thread))); | 19162 TypedData::Handle(zone, TypedData::EmptyUint32Array(thread))); |
| 19163 } | 19163 } |
| 19164 result.SetNeg(neg); | 19164 result.SetNeg(neg); |
| 19165 result.SetUsed(used); | 19165 result.SetUsed(used); |
| 19166 return result.raw(); | 19166 return result.raw(); |
| 19167 } | 19167 } |
| 19168 | 19168 |
| 19169 | 19169 |
| 19170 RawBigint* Bigint::NewFromInt64(int64_t value, Heap::Space space) { | 19170 RawBigint* Bigint::NewFromInt64(int64_t value, Heap::Space space) { |
|
siva
2017/02/22 01:48:51
This function seems to be used only as a convenien
regis
2017/02/22 17:30:48
Done.
| |
| 19171 if (FLAG_limit_ints_to_64_bits) { | |
| 19172 // The allocated Bigint value is not necessarily out of range, but it may | |
| 19173 // be used as an operand in an operation resulting in a Bigint. | |
| 19174 Exceptions::ThrowRangeErrorMsg( | |
| 19175 "Integer operand requires conversion to Bigint"); | |
| 19176 } | |
| 19171 const TypedData& digits = TypedData::Handle(NewDigits(2, space)); | 19177 const TypedData& digits = TypedData::Handle(NewDigits(2, space)); |
| 19172 bool neg; | 19178 bool neg; |
| 19173 uint64_t abs_value; | 19179 uint64_t abs_value; |
| 19174 if (value < 0) { | 19180 if (value < 0) { |
| 19175 neg = true; | 19181 neg = true; |
| 19176 abs_value = -value; | 19182 abs_value = -value; |
| 19177 } else { | 19183 } else { |
| 19178 neg = false; | 19184 neg = false; |
| 19179 abs_value = value; | 19185 abs_value = value; |
| 19180 } | 19186 } |
| 19181 SetDigitAt(digits, 0, static_cast<uint32_t>(abs_value)); | 19187 SetDigitAt(digits, 0, static_cast<uint32_t>(abs_value)); |
| 19182 SetDigitAt(digits, 1, static_cast<uint32_t>(abs_value >> 32)); | 19188 SetDigitAt(digits, 1, static_cast<uint32_t>(abs_value >> 32)); |
| 19183 return New(neg, 2, digits, space); | 19189 return New(neg, 2, digits, space); |
| 19184 } | 19190 } |
| 19185 | 19191 |
| 19186 | 19192 |
| 19187 RawBigint* Bigint::NewFromUint64(uint64_t value, Heap::Space space) { | 19193 RawBigint* Bigint::NewFromUint64(uint64_t value, Heap::Space space) { |
| 19194 if (FLAG_limit_ints_to_64_bits) { | |
| 19195 // The allocated Bigint value is not necessarily out of range, but it may | |
| 19196 // be used as an operand in an operation resulting in a Bigint. | |
|
siva
2017/02/22 01:48:51
Why do you say the value is not necessarily out of
regis
2017/02/22 17:30:48
You are right. I duplicated the same comment witho
| |
| 19197 Exceptions::ThrowRangeErrorMsg( | |
| 19198 "Integer operand requires conversion to Bigint"); | |
| 19199 } | |
| 19188 const TypedData& digits = TypedData::Handle(NewDigits(2, space)); | 19200 const TypedData& digits = TypedData::Handle(NewDigits(2, space)); |
| 19189 SetDigitAt(digits, 0, static_cast<uint32_t>(value)); | 19201 SetDigitAt(digits, 0, static_cast<uint32_t>(value)); |
| 19190 SetDigitAt(digits, 1, static_cast<uint32_t>(value >> 32)); | 19202 SetDigitAt(digits, 1, static_cast<uint32_t>(value >> 32)); |
| 19191 return New(false, 2, digits, space); | 19203 return New(false, 2, digits, space); |
| 19192 } | 19204 } |
| 19193 | 19205 |
| 19194 | 19206 |
| 19195 RawBigint* Bigint::NewFromShiftedInt64(int64_t value, | 19207 RawBigint* Bigint::NewFromShiftedInt64(int64_t value, |
| 19196 intptr_t shift, | 19208 intptr_t shift, |
| 19197 Heap::Space space) { | 19209 Heap::Space space) { |
| 19210 if (FLAG_limit_ints_to_64_bits) { | |
| 19211 // The allocated Bigint value is not necessarily out of range, but it may | |
| 19212 // be used as an operand in an operation resulting in a Bigint. | |
| 19213 Exceptions::ThrowRangeErrorMsg( | |
| 19214 "Integer operand requires conversion to Bigint"); | |
| 19215 } | |
| 19198 ASSERT(kBitsPerDigit == 32); | 19216 ASSERT(kBitsPerDigit == 32); |
| 19199 ASSERT(shift >= 0); | 19217 ASSERT(shift >= 0); |
| 19200 const intptr_t digit_shift = shift / kBitsPerDigit; | 19218 const intptr_t digit_shift = shift / kBitsPerDigit; |
| 19201 const intptr_t bit_shift = shift % kBitsPerDigit; | 19219 const intptr_t bit_shift = shift % kBitsPerDigit; |
| 19202 const intptr_t used = 3 + digit_shift; | 19220 const intptr_t used = 3 + digit_shift; |
| 19203 const TypedData& digits = TypedData::Handle(NewDigits(used, space)); | 19221 const TypedData& digits = TypedData::Handle(NewDigits(used, space)); |
| 19204 bool neg; | 19222 bool neg; |
| 19205 uint64_t abs_value; | 19223 uint64_t abs_value; |
| 19206 if (value < 0) { | 19224 if (value < 0) { |
| 19207 neg = true; | 19225 neg = true; |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 19218 SetDigitAt(digits, 1 + digit_shift, | 19236 SetDigitAt(digits, 1 + digit_shift, |
| 19219 static_cast<uint32_t>(abs_value >> (32 - bit_shift))); | 19237 static_cast<uint32_t>(abs_value >> (32 - bit_shift))); |
| 19220 SetDigitAt(digits, 2 + digit_shift, | 19238 SetDigitAt(digits, 2 + digit_shift, |
| 19221 (bit_shift == 0) ? 0 : static_cast<uint32_t>(abs_value >> | 19239 (bit_shift == 0) ? 0 : static_cast<uint32_t>(abs_value >> |
| 19222 (64 - bit_shift))); | 19240 (64 - bit_shift))); |
| 19223 return New(neg, used, digits, space); | 19241 return New(neg, used, digits, space); |
| 19224 } | 19242 } |
| 19225 | 19243 |
| 19226 | 19244 |
| 19227 RawBigint* Bigint::NewFromCString(const char* str, Heap::Space space) { | 19245 RawBigint* Bigint::NewFromCString(const char* str, Heap::Space space) { |
| 19246 // Allow parser to scan Bigint literal, even with --limit-ints-to-64-bits. | |
| 19228 ASSERT(str != NULL); | 19247 ASSERT(str != NULL); |
| 19229 bool neg = false; | 19248 bool neg = false; |
| 19230 TypedData& digits = TypedData::Handle(); | 19249 TypedData& digits = TypedData::Handle(); |
| 19231 if (str[0] == '-') { | 19250 if (str[0] == '-') { |
| 19232 ASSERT(str[1] != '-'); | 19251 ASSERT(str[1] != '-'); |
| 19233 neg = true; | 19252 neg = true; |
| 19234 str++; | 19253 str++; |
| 19235 } | 19254 } |
| 19236 intptr_t used; | 19255 intptr_t used; |
| 19237 const intptr_t str_length = strlen(str); | 19256 const intptr_t str_length = strlen(str); |
| 19238 if ((str_length >= 2) && (str[0] == '0') && | 19257 if ((str_length >= 2) && (str[0] == '0') && |
| 19239 ((str[1] == 'x') || (str[1] == 'X'))) { | 19258 ((str[1] == 'x') || (str[1] == 'X'))) { |
| 19240 digits = NewDigitsFromHexCString(&str[2], &used, space); | 19259 digits = NewDigitsFromHexCString(&str[2], &used, space); |
| 19241 } else { | 19260 } else { |
| 19242 digits = NewDigitsFromDecCString(str, &used, space); | 19261 digits = NewDigitsFromDecCString(str, &used, space); |
| 19243 } | 19262 } |
| 19244 return New(neg, used, digits, space); | 19263 return New(neg, used, digits, space); |
| 19245 } | 19264 } |
| 19246 | 19265 |
| 19247 | 19266 |
| 19248 RawBigint* Bigint::NewCanonical(const String& str) { | 19267 RawBigint* Bigint::NewCanonical(const String& str) { |
| 19268 // Allow parser to scan Bigint literal, even with --limit-ints-to-64-bits. | |
| 19249 Thread* thread = Thread::Current(); | 19269 Thread* thread = Thread::Current(); |
| 19250 Zone* zone = thread->zone(); | 19270 Zone* zone = thread->zone(); |
| 19251 Isolate* isolate = thread->isolate(); | 19271 Isolate* isolate = thread->isolate(); |
| 19252 const Bigint& value = | 19272 const Bigint& value = |
| 19253 Bigint::Handle(zone, Bigint::NewFromCString(str.ToCString(), Heap::kOld)); | 19273 Bigint::Handle(zone, Bigint::NewFromCString(str.ToCString(), Heap::kOld)); |
| 19254 const Class& cls = | 19274 const Class& cls = |
| 19255 Class::Handle(zone, isolate->object_store()->bigint_class()); | 19275 Class::Handle(zone, isolate->object_store()->bigint_class()); |
| 19256 intptr_t index = 0; | 19276 intptr_t index = 0; |
| 19257 Bigint& canonical_value = Bigint::Handle(zone); | 19277 Bigint& canonical_value = Bigint::Handle(zone); |
| 19258 canonical_value ^= cls.LookupCanonicalBigint(zone, value, &index); | 19278 canonical_value ^= cls.LookupCanonicalBigint(zone, value, &index); |
| (...skipping 3633 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 22892 return UserTag::null(); | 22912 return UserTag::null(); |
| 22893 } | 22913 } |
| 22894 | 22914 |
| 22895 | 22915 |
| 22896 const char* UserTag::ToCString() const { | 22916 const char* UserTag::ToCString() const { |
| 22897 const String& tag_label = String::Handle(label()); | 22917 const String& tag_label = String::Handle(label()); |
| 22898 return tag_label.ToCString(); | 22918 return tag_label.ToCString(); |
| 22899 } | 22919 } |
| 22900 | 22920 |
| 22901 } // namespace dart | 22921 } // namespace dart |
| OLD | NEW |