Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(14)

Side by Side Diff: runtime/vm/object.cc

Issue 2982823002: Option to truncate integers to 64 bits, part 2 (Closed)
Patch Set: Reverting a few test changes for now Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 8099 matching lines...) Expand 10 before | Expand all | Expand 10 after
8110 LiteralToken::InstanceSize(), Heap::kOld); 8110 LiteralToken::InstanceSize(), Heap::kOld);
8111 return reinterpret_cast<RawLiteralToken*>(raw); 8111 return reinterpret_cast<RawLiteralToken*>(raw);
8112 } 8112 }
8113 8113
8114 RawLiteralToken* LiteralToken::New(Token::Kind kind, const String& literal) { 8114 RawLiteralToken* LiteralToken::New(Token::Kind kind, const String& literal) {
8115 const LiteralToken& result = LiteralToken::Handle(LiteralToken::New()); 8115 const LiteralToken& result = LiteralToken::Handle(LiteralToken::New());
8116 result.set_kind(kind); 8116 result.set_kind(kind);
8117 result.set_literal(literal); 8117 result.set_literal(literal);
8118 if (kind == Token::kINTEGER) { 8118 if (kind == Token::kINTEGER) {
8119 const Integer& value = Integer::Handle(Integer::NewCanonical(literal)); 8119 const Integer& value = Integer::Handle(Integer::NewCanonical(literal));
8120 if (value.IsNull()) {
8121 // Integer is out of range.
8122 return LiteralToken::null();
8123 }
8120 ASSERT(value.IsSmi() || value.IsOld()); 8124 ASSERT(value.IsSmi() || value.IsOld());
8121 result.set_value(value); 8125 result.set_value(value);
8122 } else if (kind == Token::kDOUBLE) { 8126 } else if (kind == Token::kDOUBLE) {
8123 const Double& value = Double::Handle(Double::NewCanonical(literal)); 8127 const Double& value = Double::Handle(Double::NewCanonical(literal));
8124 result.set_value(value); 8128 result.set_value(value);
8125 } else { 8129 } else {
8126 ASSERT(Token::NeedsLiteralToken(kind)); 8130 ASSERT(Token::NeedsLiteralToken(kind));
8127 result.set_value(literal); 8131 result.set_value(literal);
8128 } 8132 }
8129 return result.raw(); 8133 return result.raw();
(...skipping 361 matching lines...) Expand 10 before | Expand all | Expand 10 after
8491 value_ = tokens_->GetOrNull(descriptor, &is_present); 8495 value_ = tokens_->GetOrNull(descriptor, &is_present);
8492 intptr_t index = -1; 8496 intptr_t index = -1;
8493 if (is_present) { 8497 if (is_present) {
8494 ASSERT(value_.IsSmi()); 8498 ASSERT(value_.IsSmi());
8495 index = Smi::Cast(value_).Value(); 8499 index = Smi::Cast(value_).Value();
8496 } else { 8500 } else {
8497 const intptr_t fresh_index = token_objects_.Length(); 8501 const intptr_t fresh_index = token_objects_.Length();
8498 fresh_index_smi_ = Smi::New(fresh_index); 8502 fresh_index_smi_ = Smi::New(fresh_index);
8499 const LiteralToken& lit = LiteralToken::Handle( 8503 const LiteralToken& lit = LiteralToken::Handle(
8500 LiteralToken::New(descriptor.kind, *descriptor.literal)); 8504 LiteralToken::New(descriptor.kind, *descriptor.literal));
8505 if (lit.IsNull()) {
8506 // Convert token to an error.
8507 if (descriptor.kind == Token::kINTEGER) {
zra 2017/07/14 17:36:30 Maybe ASSERT this instead of if {} else { UNREACHA
alexmarkov 2017/07/14 18:23:45 Done.
8508 ASSERT(FLAG_limit_ints_to_64_bits);
8509 Scanner::TokenDescriptor errorDesc = descriptor;
8510 errorDesc.kind = Token::kERROR;
8511 errorDesc.literal = &String::Handle(Symbols::New(
8512 Thread::Current(), "integer literal is out of range"));
zra 2017/07/14 17:36:30 Can you add the value to the error message from *d
alexmarkov 2017/07/14 18:23:45 Done.
8513 AddLiteralToken(errorDesc);
8514 } else {
8515 UNREACHABLE();
8516 }
8517 return;
8518 }
8501 index = Smi::Value( 8519 index = Smi::Value(
8502 Smi::RawCast(tokens_->InsertOrGetValue(lit, fresh_index_smi_))); 8520 Smi::RawCast(tokens_->InsertOrGetValue(lit, fresh_index_smi_)));
8503 token_objects_.Add(lit); 8521 token_objects_.Add(lit);
8504 if (kPrintTokenObjects) { 8522 if (kPrintTokenObjects) {
8505 int iid = Isolate::Current()->main_port() % 1024; 8523 int iid = Isolate::Current()->main_port() % 1024;
8506 printf("lit %03x %p %p %p <%s>\n", iid, token_objects_.raw(), 8524 printf("lit %03x %p %p %p <%s>\n", iid, token_objects_.raw(),
8507 lit.literal(), lit.value(), 8525 lit.literal(), lit.value(),
8508 String::Handle(lit.literal()).ToCString()); 8526 String::Handle(lit.literal()).ToCString());
8509 } 8527 }
8510 } 8528 }
(...skipping 9309 matching lines...) Expand 10 before | Expand all | Expand 10 after
17820 // Integer is an interface. No instances of Integer should exist except null. 17838 // Integer is an interface. No instances of Integer should exist except null.
17821 ASSERT(IsNull()); 17839 ASSERT(IsNull());
17822 return "NULL Integer"; 17840 return "NULL Integer";
17823 } 17841 }
17824 17842
17825 RawInteger* Integer::New(const String& str, Heap::Space space) { 17843 RawInteger* Integer::New(const String& str, Heap::Space space) {
17826 // We are not supposed to have integers represented as two byte strings. 17844 // We are not supposed to have integers represented as two byte strings.
17827 ASSERT(str.IsOneByteString()); 17845 ASSERT(str.IsOneByteString());
17828 int64_t value; 17846 int64_t value;
17829 if (!OS::StringToInt64(str.ToCString(), &value)) { 17847 if (!OS::StringToInt64(str.ToCString(), &value)) {
17848 if (FLAG_limit_ints_to_64_bits) {
17849 // Out of range.
17850 return Integer::null();
17851 }
17830 const Bigint& big = 17852 const Bigint& big =
17831 Bigint::Handle(Bigint::NewFromCString(str.ToCString(), space)); 17853 Bigint::Handle(Bigint::NewFromCString(str.ToCString(), space));
17832 ASSERT(!big.FitsIntoSmi()); 17854 ASSERT(!big.FitsIntoSmi());
17833 ASSERT(!big.FitsIntoInt64()); 17855 ASSERT(!big.FitsIntoInt64());
17834 if (!FLAG_limit_ints_to_64_bits) { 17856 return big.raw();
17835 return big.raw();
17836 }
17837 // TODO(alexmarkov): Throw error in FLAG_limit_ints_to_64_bits mode.
17838 value = big.AsTruncatedInt64Value();
17839 } 17857 }
17840 return Integer::New(value, space); 17858 return Integer::New(value, space);
17841 } 17859 }
17842 17860
17843 RawInteger* Integer::NewCanonical(const String& str) { 17861 RawInteger* Integer::NewCanonical(const String& str) {
17844 // We are not supposed to have integers represented as two byte strings. 17862 // We are not supposed to have integers represented as two byte strings.
17845 ASSERT(str.IsOneByteString()); 17863 ASSERT(str.IsOneByteString());
17846 int64_t value; 17864 int64_t value;
17847 if (!OS::StringToInt64(str.ToCString(), &value)) { 17865 if (!OS::StringToInt64(str.ToCString(), &value)) {
17866 if (FLAG_limit_ints_to_64_bits) {
17867 // Out of range.
17868 return Integer::null();
17869 }
17848 const Bigint& big = Bigint::Handle(Bigint::NewCanonical(str)); 17870 const Bigint& big = Bigint::Handle(Bigint::NewCanonical(str));
17849 ASSERT(!big.FitsIntoSmi()); 17871 ASSERT(!big.FitsIntoSmi());
17850 ASSERT(!big.FitsIntoInt64()); 17872 ASSERT(!big.FitsIntoInt64());
17851 if (!FLAG_limit_ints_to_64_bits) { 17873 return big.raw();
17852 return big.raw();
17853 }
17854 // TODO(alexmarkov): Throw error in FLAG_limit_ints_to_64_bits mode.
17855 value = big.AsTruncatedInt64Value();
17856 } 17874 }
17857 if (Smi::IsValid(value)) { 17875 if (Smi::IsValid(value)) {
17858 return Smi::New(static_cast<intptr_t>(value)); 17876 return Smi::New(static_cast<intptr_t>(value));
17859 } 17877 }
17860 return Mint::NewCanonical(value); 17878 return Mint::NewCanonical(value);
17861 } 17879 }
17862 17880
17863 RawInteger* Integer::New(int64_t value, Heap::Space space) { 17881 RawInteger* Integer::New(int64_t value, Heap::Space space) {
17864 const bool is_smi = Smi::IsValid(value); 17882 const bool is_smi = Smi::IsValid(value);
17865 if (is_smi) { 17883 if (is_smi) {
17866 return Smi::New(static_cast<intptr_t>(value)); 17884 return Smi::New(static_cast<intptr_t>(value));
17867 } 17885 }
17868 return Mint::New(value, space); 17886 return Mint::New(value, space);
17869 } 17887 }
17870 17888
17871 RawInteger* Integer::NewFromUint64(uint64_t value, Heap::Space space) { 17889 RawInteger* Integer::NewFromUint64(uint64_t value, Heap::Space space) {
17872 if (value > static_cast<uint64_t>(Mint::kMaxValue)) { 17890 if (value > static_cast<uint64_t>(Mint::kMaxValue)) {
17873 if (FLAG_limit_ints_to_64_bits) { 17891 if (FLAG_limit_ints_to_64_bits) {
17874 // TODO(alexmarkov): Throw error in FLAG_limit_ints_to_64_bits mode. 17892 // Out of range.
17875 return Integer::New(static_cast<int64_t>(value), space); 17893 return Integer::null();
17876 } else { 17894 } else {
17877 return Bigint::NewFromUint64(value, space); 17895 return Bigint::NewFromUint64(value, space);
17878 } 17896 }
17879 } else { 17897 } else {
17880 return Integer::New(value, space); 17898 return Integer::New(value, space);
17881 } 17899 }
17882 } 17900 }
17883 17901
17884 bool Integer::Equals(const Instance& other) const { 17902 bool Integer::Equals(const Instance& other) const {
17885 // Integer is an abstract class. 17903 // Integer is an abstract class.
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
18066 } else { 18084 } else {
18067 return Integer::New(remainder + right_value, space); 18085 return Integer::New(remainder + right_value, space);
18068 } 18086 }
18069 } 18087 }
18070 return Integer::New(remainder, space); 18088 return Integer::New(remainder, space);
18071 } 18089 }
18072 default: 18090 default:
18073 UNIMPLEMENTED(); 18091 UNIMPLEMENTED();
18074 } 18092 }
18075 } 18093 }
18076 ASSERT(!FLAG_limit_ints_to_64_bits); 18094 ASSERT(!Bigint::IsDisabled());
18077 return Integer::null(); // Notify caller that a bigint operation is required. 18095 return Integer::null(); // Notify caller that a bigint operation is required.
18078 } 18096 }
18079 18097
18080 static bool Are64bitOperands(const Integer& op1, const Integer& op2) { 18098 static bool Are64bitOperands(const Integer& op1, const Integer& op2) {
18081 return !op1.IsBigint() && !op2.IsBigint(); 18099 return !op1.IsBigint() && !op2.IsBigint();
18082 } 18100 }
18083 18101
18084 RawInteger* Integer::BitOp(Token::Kind kind, 18102 RawInteger* Integer::BitOp(Token::Kind kind,
18085 const Integer& other, 18103 const Integer& other,
18086 Heap::Space space) const { 18104 Heap::Space space) const {
(...skipping 23 matching lines...) Expand all
18110 case Token::kBIT_AND: 18128 case Token::kBIT_AND:
18111 return Integer::New(a & b, space); 18129 return Integer::New(a & b, space);
18112 case Token::kBIT_OR: 18130 case Token::kBIT_OR:
18113 return Integer::New(a | b, space); 18131 return Integer::New(a | b, space);
18114 case Token::kBIT_XOR: 18132 case Token::kBIT_XOR:
18115 return Integer::New(a ^ b, space); 18133 return Integer::New(a ^ b, space);
18116 default: 18134 default:
18117 UNIMPLEMENTED(); 18135 UNIMPLEMENTED();
18118 } 18136 }
18119 } 18137 }
18120 ASSERT(!FLAG_limit_ints_to_64_bits); 18138 ASSERT(!Bigint::IsDisabled());
18121 return Integer::null(); // Notify caller that a bigint operation is required. 18139 return Integer::null(); // Notify caller that a bigint operation is required.
18122 } 18140 }
18123 18141
18124 // TODO(srdjan): Clarify handling of negative right operand in a shift op. 18142 // TODO(srdjan): Clarify handling of negative right operand in a shift op.
18125 RawInteger* Smi::ShiftOp(Token::Kind kind, 18143 RawInteger* Smi::ShiftOp(Token::Kind kind,
18126 const Smi& other, 18144 const Smi& other,
18127 Heap::Space space) const { 18145 Heap::Space space) const {
18128 intptr_t result = 0; 18146 intptr_t result = 0;
18129 const intptr_t left_value = Value(); 18147 const intptr_t left_value = Value();
18130 const intptr_t right_value = other.Value(); 18148 const intptr_t right_value = other.Value();
(...skipping 392 matching lines...) Expand 10 before | Expand all | Expand 10 after
18523 digits_ ^= digits_.CheckAndCanonicalize(thread, NULL); 18541 digits_ ^= digits_.CheckAndCanonicalize(thread, NULL);
18524 ASSERT(!digits_.IsNull()); 18542 ASSERT(!digits_.IsNull());
18525 set_digits(digits_); 18543 set_digits(digits_);
18526 } else { 18544 } else {
18527 ASSERT(digits() == TypedData::EmptyUint32Array(Thread::Current())); 18545 ASSERT(digits() == TypedData::EmptyUint32Array(Thread::Current()));
18528 } 18546 }
18529 return true; 18547 return true;
18530 } 18548 }
18531 18549
18532 RawBigint* Bigint::New(Heap::Space space) { 18550 RawBigint* Bigint::New(Heap::Space space) {
18533 // TODO(alexmarkov): Throw error or assert in --limit-ints-to-64-bits mode. 18551 ASSERT(!Bigint::IsDisabled());
18534 Thread* thread = Thread::Current(); 18552 Thread* thread = Thread::Current();
18535 Zone* zone = thread->zone(); 18553 Zone* zone = thread->zone();
18536 Isolate* isolate = thread->isolate(); 18554 Isolate* isolate = thread->isolate();
18537 ASSERT(isolate->object_store()->bigint_class() != Class::null()); 18555 ASSERT(isolate->object_store()->bigint_class() != Class::null());
18538 Bigint& result = Bigint::Handle(zone); 18556 Bigint& result = Bigint::Handle(zone);
18539 { 18557 {
18540 RawObject* raw = 18558 RawObject* raw =
18541 Object::Allocate(Bigint::kClassId, Bigint::InstanceSize(), space); 18559 Object::Allocate(Bigint::kClassId, Bigint::InstanceSize(), space);
18542 NoSafepointScope no_safepoint; 18560 NoSafepointScope no_safepoint;
18543 result ^= raw; 18561 result ^= raw;
18544 } 18562 }
18545 result.SetNeg(false); 18563 result.SetNeg(false);
18546 result.SetUsed(0); 18564 result.SetUsed(0);
18547 result.set_digits( 18565 result.set_digits(
18548 TypedData::Handle(zone, TypedData::EmptyUint32Array(thread))); 18566 TypedData::Handle(zone, TypedData::EmptyUint32Array(thread)));
18549 return result.raw(); 18567 return result.raw();
18550 } 18568 }
18551 18569
18552 RawBigint* Bigint::New(bool neg, 18570 RawBigint* Bigint::New(bool neg,
18553 intptr_t used, 18571 intptr_t used,
18554 const TypedData& digits, 18572 const TypedData& digits,
18555 Heap::Space space) { 18573 Heap::Space space) {
18556 // TODO(alexmarkov): Throw error or assert in --limit-ints-to-64-bits mode. 18574 ASSERT(!Bigint::IsDisabled());
18557 ASSERT((used == 0) || 18575 ASSERT((used == 0) ||
18558 (!digits.IsNull() && (digits.Length() >= (used + (used & 1))))); 18576 (!digits.IsNull() && (digits.Length() >= (used + (used & 1)))));
18559 Thread* thread = Thread::Current(); 18577 Thread* thread = Thread::Current();
18560 Zone* zone = thread->zone(); 18578 Zone* zone = thread->zone();
18561 Isolate* isolate = thread->isolate(); 18579 Isolate* isolate = thread->isolate();
18562 ASSERT(isolate->object_store()->bigint_class() != Class::null()); 18580 ASSERT(isolate->object_store()->bigint_class() != Class::null());
18563 Bigint& result = Bigint::Handle(zone); 18581 Bigint& result = Bigint::Handle(zone);
18564 { 18582 {
18565 RawObject* raw = 18583 RawObject* raw =
18566 Object::Allocate(Bigint::kClassId, Bigint::InstanceSize(), space); 18584 Object::Allocate(Bigint::kClassId, Bigint::InstanceSize(), space);
(...skipping 16 matching lines...) Expand all
18583 neg = false; 18601 neg = false;
18584 result.set_digits( 18602 result.set_digits(
18585 TypedData::Handle(zone, TypedData::EmptyUint32Array(thread))); 18603 TypedData::Handle(zone, TypedData::EmptyUint32Array(thread)));
18586 } 18604 }
18587 result.SetNeg(neg); 18605 result.SetNeg(neg);
18588 result.SetUsed(used); 18606 result.SetUsed(used);
18589 return result.raw(); 18607 return result.raw();
18590 } 18608 }
18591 18609
18592 RawBigint* Bigint::NewFromInt64(int64_t value, Heap::Space space) { 18610 RawBigint* Bigint::NewFromInt64(int64_t value, Heap::Space space) {
18593 // Currently only used to convert Smi or Mint to hex String, therefore do 18611 ASSERT(!Bigint::IsDisabled());
18594 // not throw RangeError if --limit-ints-to-64-bits.
18595 // TODO(alexmarkov): Throw error or assert in --limit-ints-to-64-bits mode.
18596 const TypedData& digits = TypedData::Handle(NewDigits(2, space)); 18612 const TypedData& digits = TypedData::Handle(NewDigits(2, space));
18597 bool neg; 18613 bool neg;
18598 uint64_t abs_value; 18614 uint64_t abs_value;
18599 if (value < 0) { 18615 if (value < 0) {
18600 neg = true; 18616 neg = true;
18601 abs_value = -value; 18617 abs_value = -value;
18602 } else { 18618 } else {
18603 neg = false; 18619 neg = false;
18604 abs_value = value; 18620 abs_value = value;
18605 } 18621 }
18606 SetDigitAt(digits, 0, static_cast<uint32_t>(abs_value)); 18622 SetDigitAt(digits, 0, static_cast<uint32_t>(abs_value));
18607 SetDigitAt(digits, 1, static_cast<uint32_t>(abs_value >> 32)); 18623 SetDigitAt(digits, 1, static_cast<uint32_t>(abs_value >> 32));
18608 return New(neg, 2, digits, space); 18624 return New(neg, 2, digits, space);
18609 } 18625 }
18610 18626
18611 RawBigint* Bigint::NewFromUint64(uint64_t value, Heap::Space space) { 18627 RawBigint* Bigint::NewFromUint64(uint64_t value, Heap::Space space) {
18612 // TODO(alexmarkov): Revise this assertion if this factory method is used 18628 ASSERT(!Bigint::IsDisabled());
18613 // to explicitly allocate Bigint objects in --limit-ints-to-64-bits mode.
18614 ASSERT(!FLAG_limit_ints_to_64_bits);
18615 const TypedData& digits = TypedData::Handle(NewDigits(2, space)); 18629 const TypedData& digits = TypedData::Handle(NewDigits(2, space));
18616 SetDigitAt(digits, 0, static_cast<uint32_t>(value)); 18630 SetDigitAt(digits, 0, static_cast<uint32_t>(value));
18617 SetDigitAt(digits, 1, static_cast<uint32_t>(value >> 32)); 18631 SetDigitAt(digits, 1, static_cast<uint32_t>(value >> 32));
18618 return New(false, 2, digits, space); 18632 return New(false, 2, digits, space);
18619 } 18633 }
18620 18634
18621 RawBigint* Bigint::NewFromShiftedInt64(int64_t value, 18635 RawBigint* Bigint::NewFromShiftedInt64(int64_t value,
18622 intptr_t shift, 18636 intptr_t shift,
18623 Heap::Space space) { 18637 Heap::Space space) {
18624 // TODO(alexmarkov): Revise this assertion if this factory method is used 18638 ASSERT(!Bigint::IsDisabled());
18625 // to explicitly allocate Bigint objects in --limit-ints-to-64-bits mode.
18626 ASSERT(!FLAG_limit_ints_to_64_bits);
18627 ASSERT(kBitsPerDigit == 32); 18639 ASSERT(kBitsPerDigit == 32);
18628 ASSERT(shift >= 0); 18640 ASSERT(shift >= 0);
18629 const intptr_t digit_shift = shift / kBitsPerDigit; 18641 const intptr_t digit_shift = shift / kBitsPerDigit;
18630 const intptr_t bit_shift = shift % kBitsPerDigit; 18642 const intptr_t bit_shift = shift % kBitsPerDigit;
18631 const intptr_t used = 3 + digit_shift; 18643 const intptr_t used = 3 + digit_shift;
18632 const TypedData& digits = TypedData::Handle(NewDigits(used, space)); 18644 const TypedData& digits = TypedData::Handle(NewDigits(used, space));
18633 bool neg; 18645 bool neg;
18634 uint64_t abs_value; 18646 uint64_t abs_value;
18635 if (value < 0) { 18647 if (value < 0) {
18636 neg = true; 18648 neg = true;
(...skipping 10 matching lines...) Expand all
18647 SetDigitAt(digits, 1 + digit_shift, 18659 SetDigitAt(digits, 1 + digit_shift,
18648 static_cast<uint32_t>(abs_value >> (32 - bit_shift))); 18660 static_cast<uint32_t>(abs_value >> (32 - bit_shift)));
18649 SetDigitAt(digits, 2 + digit_shift, 18661 SetDigitAt(digits, 2 + digit_shift,
18650 (bit_shift == 0) 18662 (bit_shift == 0)
18651 ? 0 18663 ? 0
18652 : static_cast<uint32_t>(abs_value >> (64 - bit_shift))); 18664 : static_cast<uint32_t>(abs_value >> (64 - bit_shift)));
18653 return New(neg, used, digits, space); 18665 return New(neg, used, digits, space);
18654 } 18666 }
18655 18667
18656 RawBigint* Bigint::NewFromCString(const char* str, Heap::Space space) { 18668 RawBigint* Bigint::NewFromCString(const char* str, Heap::Space space) {
18657 // Allow parser to scan Bigint literal, even with --limit-ints-to-64-bits. 18669 ASSERT(!Bigint::IsDisabled());
18658 // TODO(alexmarkov): Throw error or assert in --limit-ints-to-64-bits mode.
18659 ASSERT(str != NULL); 18670 ASSERT(str != NULL);
18660 bool neg = false; 18671 bool neg = false;
18661 TypedData& digits = TypedData::Handle(); 18672 TypedData& digits = TypedData::Handle();
18662 if (str[0] == '-') { 18673 if (str[0] == '-') {
18663 ASSERT(str[1] != '-'); 18674 ASSERT(str[1] != '-');
18664 neg = true; 18675 neg = true;
18665 str++; 18676 str++;
18666 } 18677 }
18667 intptr_t used; 18678 intptr_t used;
18668 const intptr_t str_length = strlen(str); 18679 const intptr_t str_length = strlen(str);
18669 if ((str_length >= 2) && (str[0] == '0') && 18680 if ((str_length >= 2) && (str[0] == '0') &&
18670 ((str[1] == 'x') || (str[1] == 'X'))) { 18681 ((str[1] == 'x') || (str[1] == 'X'))) {
18671 digits = NewDigitsFromHexCString(&str[2], &used, space); 18682 digits = NewDigitsFromHexCString(&str[2], &used, space);
18672 } else { 18683 } else {
18673 digits = NewDigitsFromDecCString(str, &used, space); 18684 digits = NewDigitsFromDecCString(str, &used, space);
18674 } 18685 }
18675 return New(neg, used, digits, space); 18686 return New(neg, used, digits, space);
18676 } 18687 }
18677 18688
18678 RawBigint* Bigint::NewCanonical(const String& str) { 18689 RawBigint* Bigint::NewCanonical(const String& str) {
18679 // Allow parser to scan Bigint literal, even with --limit-ints-to-64-bits. 18690 ASSERT(!Bigint::IsDisabled());
18680 // TODO(alexmarkov): Throw error or assert in --limit-ints-to-64-bits mode.
18681 Thread* thread = Thread::Current(); 18691 Thread* thread = Thread::Current();
18682 Zone* zone = thread->zone(); 18692 Zone* zone = thread->zone();
18683 Isolate* isolate = thread->isolate(); 18693 Isolate* isolate = thread->isolate();
18684 const Bigint& value = 18694 const Bigint& value =
18685 Bigint::Handle(zone, Bigint::NewFromCString(str.ToCString(), Heap::kOld)); 18695 Bigint::Handle(zone, Bigint::NewFromCString(str.ToCString(), Heap::kOld));
18686 const Class& cls = 18696 const Class& cls =
18687 Class::Handle(zone, isolate->object_store()->bigint_class()); 18697 Class::Handle(zone, isolate->object_store()->bigint_class());
18688 intptr_t index = 0; 18698 intptr_t index = 0;
18689 Bigint& canonical_value = Bigint::Handle(zone); 18699 Bigint& canonical_value = Bigint::Handle(zone);
18690 canonical_value ^= cls.LookupCanonicalBigint(zone, value, &index); 18700 canonical_value ^= cls.LookupCanonicalBigint(zone, value, &index);
(...skipping 3533 matching lines...) Expand 10 before | Expand all | Expand 10 after
22224 } 22234 }
22225 return UserTag::null(); 22235 return UserTag::null();
22226 } 22236 }
22227 22237
22228 const char* UserTag::ToCString() const { 22238 const char* UserTag::ToCString() const {
22229 const String& tag_label = String::Handle(label()); 22239 const String& tag_label = String::Handle(label());
22230 return tag_label.ToCString(); 22240 return tag_label.ToCString();
22231 } 22241 }
22232 22242
22233 } // namespace dart 22243 } // namespace dart
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698