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 9072 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
9083 if ((*reinterpret_cast<RawObject**>(this_addr + offset)) != | 9083 if ((*reinterpret_cast<RawObject**>(this_addr + offset)) != |
9084 (*reinterpret_cast<RawObject**>(other_addr + offset))) { | 9084 (*reinterpret_cast<RawObject**>(other_addr + offset))) { |
9085 return false; | 9085 return false; |
9086 } | 9086 } |
9087 } | 9087 } |
9088 } | 9088 } |
9089 return true; | 9089 return true; |
9090 } | 9090 } |
9091 | 9091 |
9092 | 9092 |
9093 RawInstance* Instance::Canonicalize() const { | 9093 RawInstance* Instance::CheckAndCanonicalize(const char** error_str) const { |
9094 ASSERT(!IsNull()); | 9094 ASSERT(!IsNull()); |
9095 if (this->IsCanonical()) { | 9095 if (this->IsCanonical()) { |
9096 return this->raw(); | 9096 return this->raw(); |
9097 } | 9097 } |
9098 Instance& result = Instance::Handle(); | 9098 Instance& result = Instance::Handle(); |
9099 const Class& cls = Class::Handle(this->clazz()); | 9099 const Class& cls = Class::Handle(this->clazz()); |
9100 if ((cls.id() >= kNumPredefinedCids) || cls.IsArray()) { | |
Ivan Posva
2013/06/12 15:22:15
Why are you checking for kNumPredefinedCids here?
srdjan
2013/06/12 16:04:19
Because I cannot iterate over content of object's
| |
9101 // Iterate over all fields, canonicalize numbers and strings, expect all | |
srdjan
2013/06/12 21:27:28
Added a TODO(srdjan): Check that predefined classe
| |
9102 // other instances to be canonical otherwise report error (return | |
9103 // Instance::null()). | |
9104 Object& obj = Object::Handle(); | |
9105 const intptr_t end_field_offset = cls.instance_size() - kWordSize; | |
9106 for (intptr_t field_offset = 0; | |
9107 field_offset <= end_field_offset; | |
9108 field_offset += kWordSize) { | |
9109 obj = *this->FieldAddrAtOffset(field_offset); | |
9110 if (obj.IsInstance() && !obj.IsSmi() && !obj.IsCanonical()) { | |
9111 if (obj.IsNumber() || obj.IsString()) { | |
9112 obj = Instance::Cast(obj).CheckAndCanonicalize(NULL); | |
9113 ASSERT(!obj.IsNull()); | |
9114 this->SetFieldAtOffset(field_offset, obj); | |
9115 } else { | |
9116 ASSERT(error_str != NULL); | |
9117 const char* kFormat = "field: %s\n"; | |
9118 const intptr_t len = | |
9119 OS::SNPrint(NULL, 0, kFormat, obj.ToCString()) + 1; | |
9120 char* chars = Isolate::Current()->current_zone()->Alloc<char>(len); | |
9121 OS::SNPrint(chars, len, kFormat, obj.ToCString()); | |
9122 *error_str = chars; | |
9123 return Instance::null(); | |
9124 } | |
9125 } | |
9126 } | |
9127 } | |
9100 Array& constants = Array::Handle(cls.constants()); | 9128 Array& constants = Array::Handle(cls.constants()); |
9101 const intptr_t constants_len = constants.Length(); | 9129 const intptr_t constants_len = constants.Length(); |
9102 // Linear search to see whether this value is already present in the | 9130 // Linear search to see whether this value is already present in the |
9103 // list of canonicalized constants. | 9131 // list of canonicalized constants. |
9104 intptr_t index = 0; | 9132 intptr_t index = 0; |
9105 while (index < constants_len) { | 9133 while (index < constants_len) { |
9106 result ^= constants.At(index); | 9134 result ^= constants.At(index); |
9107 if (result.IsNull()) { | 9135 if (result.IsNull()) { |
9108 break; | 9136 break; |
9109 } | 9137 } |
(...skipping 2327 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
11437 intptr_t slen = other.Length(); | 11465 intptr_t slen = other.Length(); |
11438 for (int i = 0; i < slen; i++) { | 11466 for (int i = 0; i < slen; i++) { |
11439 if (this->CharAt(i) != other.CharAt(i)) { | 11467 if (this->CharAt(i) != other.CharAt(i)) { |
11440 return false; | 11468 return false; |
11441 } | 11469 } |
11442 } | 11470 } |
11443 return true; | 11471 return true; |
11444 } | 11472 } |
11445 | 11473 |
11446 | 11474 |
11447 RawInstance* String::Canonicalize() const { | 11475 RawInstance* String::CheckAndCanonicalize(const char** error_str) const { |
11448 if (IsCanonical()) { | 11476 if (IsCanonical()) { |
11449 return this->raw(); | 11477 return this->raw(); |
11450 } | 11478 } |
11451 return Symbols::New(*this); | 11479 return Symbols::New(*this); |
11452 } | 11480 } |
11453 | 11481 |
11454 | 11482 |
11455 RawString* String::New(const char* cstr, Heap::Space space) { | 11483 RawString* String::New(const char* cstr, Heap::Space space) { |
11456 ASSERT(cstr != NULL); | 11484 ASSERT(cstr != NULL); |
11457 intptr_t array_len = strlen(cstr); | 11485 intptr_t array_len = strlen(cstr); |
(...skipping 1939 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
13397 space); | 13425 space); |
13398 return reinterpret_cast<RawWeakProperty*>(raw); | 13426 return reinterpret_cast<RawWeakProperty*>(raw); |
13399 } | 13427 } |
13400 | 13428 |
13401 | 13429 |
13402 const char* WeakProperty::ToCString() const { | 13430 const char* WeakProperty::ToCString() const { |
13403 return "_WeakProperty"; | 13431 return "_WeakProperty"; |
13404 } | 13432 } |
13405 | 13433 |
13406 } // namespace dart | 13434 } // namespace dart |
OLD | NEW |