| 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/cpu.h" | 10 #include "vm/cpu.h" |
| (...skipping 9191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 9202 if ((*reinterpret_cast<RawObject**>(this_addr + offset)) != | 9202 if ((*reinterpret_cast<RawObject**>(this_addr + offset)) != |
| 9203 (*reinterpret_cast<RawObject**>(other_addr + offset))) { | 9203 (*reinterpret_cast<RawObject**>(other_addr + offset))) { |
| 9204 return false; | 9204 return false; |
| 9205 } | 9205 } |
| 9206 } | 9206 } |
| 9207 } | 9207 } |
| 9208 return true; | 9208 return true; |
| 9209 } | 9209 } |
| 9210 | 9210 |
| 9211 | 9211 |
| 9212 RawInstance* Instance::Canonicalize() const { | 9212 RawInstance* Instance::CheckAndCanonicalize(const char** error_str) const { |
| 9213 ASSERT(!IsNull()); | 9213 ASSERT(!IsNull()); |
| 9214 if (this->IsCanonical()) { | 9214 if (this->IsCanonical()) { |
| 9215 return this->raw(); | 9215 return this->raw(); |
| 9216 } | 9216 } |
| 9217 Instance& result = Instance::Handle(); | 9217 Instance& result = Instance::Handle(); |
| 9218 const Class& cls = Class::Handle(this->clazz()); | 9218 const Class& cls = Class::Handle(this->clazz()); |
| 9219 // TODO(srdjan): Check that predefined classes do not have fields that need |
| 9220 // to be checked/canonicalized as well. |
| 9221 if ((cls.id() >= kNumPredefinedCids) || cls.IsArray()) { |
| 9222 // Iterate over all fields, canonicalize numbers and strings, expect all |
| 9223 // other instances to be canonical otherwise report error (return |
| 9224 // Instance::null()). |
| 9225 Object& obj = Object::Handle(); |
| 9226 const intptr_t end_field_offset = cls.instance_size() - kWordSize; |
| 9227 for (intptr_t field_offset = 0; |
| 9228 field_offset <= end_field_offset; |
| 9229 field_offset += kWordSize) { |
| 9230 obj = *this->FieldAddrAtOffset(field_offset); |
| 9231 if (obj.IsInstance() && !obj.IsSmi() && !obj.IsCanonical()) { |
| 9232 if (obj.IsNumber() || obj.IsString()) { |
| 9233 obj = Instance::Cast(obj).CheckAndCanonicalize(NULL); |
| 9234 ASSERT(!obj.IsNull()); |
| 9235 this->SetFieldAtOffset(field_offset, obj); |
| 9236 } else { |
| 9237 ASSERT(error_str != NULL); |
| 9238 const char* kFormat = "field: %s\n"; |
| 9239 const intptr_t len = |
| 9240 OS::SNPrint(NULL, 0, kFormat, obj.ToCString()) + 1; |
| 9241 char* chars = Isolate::Current()->current_zone()->Alloc<char>(len); |
| 9242 OS::SNPrint(chars, len, kFormat, obj.ToCString()); |
| 9243 *error_str = chars; |
| 9244 return Instance::null(); |
| 9245 } |
| 9246 } |
| 9247 } |
| 9248 } |
| 9219 Array& constants = Array::Handle(cls.constants()); | 9249 Array& constants = Array::Handle(cls.constants()); |
| 9220 const intptr_t constants_len = constants.Length(); | 9250 const intptr_t constants_len = constants.Length(); |
| 9221 // Linear search to see whether this value is already present in the | 9251 // Linear search to see whether this value is already present in the |
| 9222 // list of canonicalized constants. | 9252 // list of canonicalized constants. |
| 9223 intptr_t index = 0; | 9253 intptr_t index = 0; |
| 9224 while (index < constants_len) { | 9254 while (index < constants_len) { |
| 9225 result ^= constants.At(index); | 9255 result ^= constants.At(index); |
| 9226 if (result.IsNull()) { | 9256 if (result.IsNull()) { |
| 9227 break; | 9257 break; |
| 9228 } | 9258 } |
| (...skipping 2327 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 11556 intptr_t slen = other.Length(); | 11586 intptr_t slen = other.Length(); |
| 11557 for (int i = 0; i < slen; i++) { | 11587 for (int i = 0; i < slen; i++) { |
| 11558 if (this->CharAt(i) != other.CharAt(i)) { | 11588 if (this->CharAt(i) != other.CharAt(i)) { |
| 11559 return false; | 11589 return false; |
| 11560 } | 11590 } |
| 11561 } | 11591 } |
| 11562 return true; | 11592 return true; |
| 11563 } | 11593 } |
| 11564 | 11594 |
| 11565 | 11595 |
| 11566 RawInstance* String::Canonicalize() const { | 11596 RawInstance* String::CheckAndCanonicalize(const char** error_str) const { |
| 11567 if (IsCanonical()) { | 11597 if (IsCanonical()) { |
| 11568 return this->raw(); | 11598 return this->raw(); |
| 11569 } | 11599 } |
| 11570 return Symbols::New(*this); | 11600 return Symbols::New(*this); |
| 11571 } | 11601 } |
| 11572 | 11602 |
| 11573 | 11603 |
| 11574 RawString* String::New(const char* cstr, Heap::Space space) { | 11604 RawString* String::New(const char* cstr, Heap::Space space) { |
| 11575 ASSERT(cstr != NULL); | 11605 ASSERT(cstr != NULL); |
| 11576 intptr_t array_len = strlen(cstr); | 11606 intptr_t array_len = strlen(cstr); |
| (...skipping 1939 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 13516 space); | 13546 space); |
| 13517 return reinterpret_cast<RawWeakProperty*>(raw); | 13547 return reinterpret_cast<RawWeakProperty*>(raw); |
| 13518 } | 13548 } |
| 13519 | 13549 |
| 13520 | 13550 |
| 13521 const char* WeakProperty::ToCString() const { | 13551 const char* WeakProperty::ToCString() const { |
| 13522 return "_WeakProperty"; | 13552 return "_WeakProperty"; |
| 13523 } | 13553 } |
| 13524 | 13554 |
| 13525 } // namespace dart | 13555 } // namespace dart |
| OLD | NEW |