| 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 6352 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6363 const Class& cls = Class::Handle(owner()); | 6363 const Class& cls = Class::Handle(owner()); |
| 6364 const char* cls_name = String::Handle(cls.Name()).ToCString(); | 6364 const char* cls_name = String::Handle(cls.Name()).ToCString(); |
| 6365 intptr_t len = | 6365 intptr_t len = |
| 6366 OS::SNPrint(NULL, 0, kFormat, cls_name, field_name, kF0, kF1, kF2) + 1; | 6366 OS::SNPrint(NULL, 0, kFormat, cls_name, field_name, kF0, kF1, kF2) + 1; |
| 6367 char* chars = Isolate::Current()->current_zone()->Alloc<char>(len); | 6367 char* chars = Isolate::Current()->current_zone()->Alloc<char>(len); |
| 6368 OS::SNPrint(chars, len, kFormat, cls_name, field_name, kF0, kF1, kF2); | 6368 OS::SNPrint(chars, len, kFormat, cls_name, field_name, kF0, kF1, kF2); |
| 6369 return chars; | 6369 return chars; |
| 6370 } | 6370 } |
| 6371 | 6371 |
| 6372 void Field::PrintToJSONStream(JSONStream* stream, bool ref) const { | 6372 void Field::PrintToJSONStream(JSONStream* stream, bool ref) const { |
| 6373 PrintToJSONStreamWithInstance(stream, Object::null_instance(), ref); | |
| 6374 } | |
| 6375 | |
| 6376 | |
| 6377 void Field::PrintToJSONStreamWithInstance(JSONStream* stream, | |
| 6378 const Instance& instance, | |
| 6379 bool ref) const { | |
| 6380 JSONObject jsobj(stream); | 6373 JSONObject jsobj(stream); |
| 6381 const char* internal_field_name = String::Handle(name()).ToCString(); | 6374 const char* internal_field_name = String::Handle(name()).ToCString(); |
| 6382 const char* field_name = String::Handle(UserVisibleName()).ToCString(); | 6375 const char* field_name = String::Handle(UserVisibleName()).ToCString(); |
| 6383 Class& cls = Class::Handle(owner()); | 6376 Class& cls = Class::Handle(owner()); |
| 6384 intptr_t id = cls.FindFieldIndex(*this); | 6377 intptr_t id = cls.FindFieldIndex(*this); |
| 6385 ASSERT(id >= 0); | 6378 ASSERT(id >= 0); |
| 6386 intptr_t cid = cls.id(); | 6379 intptr_t cid = cls.id(); |
| 6387 jsobj.AddProperty("type", JSONType(ref)); | 6380 jsobj.AddProperty("type", JSONType(ref)); |
| 6388 jsobj.AddPropertyF("id", "classes/%" Pd "/fields/%" Pd "", cid, id); | 6381 jsobj.AddPropertyF("id", "classes/%" Pd "/fields/%" Pd "", cid, id); |
| 6389 jsobj.AddProperty("name", internal_field_name); | 6382 jsobj.AddProperty("name", internal_field_name); |
| 6390 jsobj.AddProperty("user_name", field_name); | 6383 jsobj.AddProperty("user_name", field_name); |
| 6391 if (is_static()) { | 6384 if (is_static()) { |
| 6392 const Object& valueObj = Object::Handle(value()); | 6385 const Instance& valueObj = Instance::Handle(value()); |
| 6393 jsobj.AddProperty("value", valueObj); | |
| 6394 } else if (!instance.IsNull()) { | |
| 6395 const Object& valueObj = Object::Handle(instance.GetField(*this)); | |
| 6396 jsobj.AddProperty("value", valueObj); | 6386 jsobj.AddProperty("value", valueObj); |
| 6397 } | 6387 } |
| 6398 | 6388 |
| 6399 jsobj.AddProperty("owner", cls); | 6389 jsobj.AddProperty("owner", cls); |
| 6400 AbstractType& declared_type = AbstractType::Handle(type()); | 6390 AbstractType& declared_type = AbstractType::Handle(type()); |
| 6401 cls = declared_type.type_class(); | 6391 cls = declared_type.type_class(); |
| 6402 jsobj.AddProperty("declared_type", cls); | 6392 jsobj.AddProperty("declared_type", cls); |
| 6403 jsobj.AddProperty("static", is_static()); | 6393 jsobj.AddProperty("static", is_static()); |
| 6404 jsobj.AddProperty("final", is_final()); | 6394 jsobj.AddProperty("final", is_final()); |
| 6405 jsobj.AddProperty("const", is_const()); | 6395 jsobj.AddProperty("const", is_const()); |
| (...skipping 5661 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 12067 jsobj.AddPropertyF("id", "objects/%" Pd "", id); | 12057 jsobj.AddPropertyF("id", "objects/%" Pd "", id); |
| 12068 jsobj.AddProperty("class", cls); | 12058 jsobj.AddProperty("class", cls); |
| 12069 } | 12059 } |
| 12070 | 12060 |
| 12071 if (ref) { | 12061 if (ref) { |
| 12072 return; | 12062 return; |
| 12073 } | 12063 } |
| 12074 | 12064 |
| 12075 // Walk the superclass chain, adding all instance fields. | 12065 // Walk the superclass chain, adding all instance fields. |
| 12076 { | 12066 { |
| 12067 Instance& fieldValue = Instance::Handle(); |
| 12077 JSONArray jsarr(&jsobj, "fields"); | 12068 JSONArray jsarr(&jsobj, "fields"); |
| 12078 while (!cls.IsNull()) { | 12069 while (!cls.IsNull()) { |
| 12079 const Array& field_array = Array::Handle(cls.fields()); | 12070 const Array& field_array = Array::Handle(cls.fields()); |
| 12080 Field& field = Field::Handle(); | 12071 Field& field = Field::Handle(); |
| 12081 if (!field_array.IsNull()) { | 12072 if (!field_array.IsNull()) { |
| 12082 for (intptr_t i = 0; i < field_array.Length(); i++) { | 12073 for (intptr_t i = 0; i < field_array.Length(); i++) { |
| 12083 field ^= field_array.At(i); | 12074 field ^= field_array.At(i); |
| 12084 if (!field.is_static()) { | 12075 if (!field.is_static()) { |
| 12085 jsarr.AddValue(field, *this); | 12076 fieldValue ^= GetField(field); |
| 12077 JSONObject jsfield(&jsarr); |
| 12078 jsfield.AddProperty("decl", field); |
| 12079 jsfield.AddProperty("value", fieldValue); |
| 12086 } | 12080 } |
| 12087 } | 12081 } |
| 12088 } | 12082 } |
| 12089 cls = cls.SuperClass(); | 12083 cls = cls.SuperClass(); |
| 12090 } | 12084 } |
| 12091 } | 12085 } |
| 12092 } | 12086 } |
| 12093 | 12087 |
| 12094 | 12088 |
| 12095 bool AbstractType::IsResolved() const { | 12089 bool AbstractType::IsResolved() const { |
| (...skipping 4097 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 16193 const char* format = IsImmutable() ? | 16187 const char* format = IsImmutable() ? |
| 16194 "_ImmutableList len:%" Pd : "_List len:%" Pd; | 16188 "_ImmutableList len:%" Pd : "_List len:%" Pd; |
| 16195 intptr_t len = OS::SNPrint(NULL, 0, format, Length()) + 1; | 16189 intptr_t len = OS::SNPrint(NULL, 0, format, Length()) + 1; |
| 16196 char* chars = Isolate::Current()->current_zone()->Alloc<char>(len); | 16190 char* chars = Isolate::Current()->current_zone()->Alloc<char>(len); |
| 16197 OS::SNPrint(chars, len, format, Length()); | 16191 OS::SNPrint(chars, len, format, Length()); |
| 16198 return chars; | 16192 return chars; |
| 16199 } | 16193 } |
| 16200 | 16194 |
| 16201 | 16195 |
| 16202 void Array::PrintToJSONStream(JSONStream* stream, bool ref) const { | 16196 void Array::PrintToJSONStream(JSONStream* stream, bool ref) const { |
| 16203 Instance::PrintToJSONStream(stream, ref); | 16197 JSONObject jsobj(stream); |
| 16198 Class& cls = Class::Handle(this->clazz()); |
| 16199 ObjectIdRing* ring = Isolate::Current()->object_id_ring(); |
| 16200 intptr_t id = ring->GetIdForObject(raw()); |
| 16201 jsobj.AddProperty("type", JSONType(ref)); |
| 16202 jsobj.AddPropertyF("id", "objects/%" Pd "", id); |
| 16203 jsobj.AddProperty("class", cls); |
| 16204 jsobj.AddProperty("length", Length()); |
| 16205 if (ref) { |
| 16206 return; |
| 16207 } |
| 16208 { |
| 16209 JSONArray jsarr(&jsobj, "elements"); |
| 16210 for (intptr_t index = 0; index < Length(); index++) { |
| 16211 JSONObject jselement(&jsarr); |
| 16212 jselement.AddProperty("index", index); |
| 16213 |
| 16214 Instance& instance = Instance::Handle(); |
| 16215 instance ^= At(index); |
| 16216 jselement.AddProperty("value", instance); |
| 16217 } |
| 16218 } |
| 16204 } | 16219 } |
| 16205 | 16220 |
| 16206 | 16221 |
| 16207 RawArray* Array::Grow(const Array& source, int new_length, Heap::Space space) { | 16222 RawArray* Array::Grow(const Array& source, int new_length, Heap::Space space) { |
| 16208 const Array& result = Array::Handle(Array::New(new_length, space)); | 16223 const Array& result = Array::Handle(Array::New(new_length, space)); |
| 16209 intptr_t len = 0; | 16224 intptr_t len = 0; |
| 16210 if (!source.IsNull()) { | 16225 if (!source.IsNull()) { |
| 16211 len = source.Length(); | 16226 len = source.Length(); |
| 16212 result.SetTypeArguments(TypeArguments::Handle(source.GetTypeArguments())); | 16227 result.SetTypeArguments(TypeArguments::Handle(source.GetTypeArguments())); |
| 16213 } | 16228 } |
| (...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 16504 pos += OS::SNPrint((buffer + pos), (max_len + 1 - pos), "%s", trunc_suffix); | 16519 pos += OS::SNPrint((buffer + pos), (max_len + 1 - pos), "%s", trunc_suffix); |
| 16505 } | 16520 } |
| 16506 ASSERT(pos <= max_len); | 16521 ASSERT(pos <= max_len); |
| 16507 buffer[pos] = '\0'; | 16522 buffer[pos] = '\0'; |
| 16508 return buffer; | 16523 return buffer; |
| 16509 } | 16524 } |
| 16510 | 16525 |
| 16511 | 16526 |
| 16512 void GrowableObjectArray::PrintToJSONStream(JSONStream* stream, | 16527 void GrowableObjectArray::PrintToJSONStream(JSONStream* stream, |
| 16513 bool ref) const { | 16528 bool ref) const { |
| 16514 Instance::PrintToJSONStream(stream, ref); | 16529 JSONObject jsobj(stream); |
| 16530 Class& cls = Class::Handle(this->clazz()); |
| 16531 ObjectIdRing* ring = Isolate::Current()->object_id_ring(); |
| 16532 intptr_t id = ring->GetIdForObject(raw()); |
| 16533 jsobj.AddProperty("type", JSONType(ref)); |
| 16534 jsobj.AddPropertyF("id", "objects/%" Pd "", id); |
| 16535 jsobj.AddProperty("class", cls); |
| 16536 jsobj.AddProperty("length", Length()); |
| 16537 if (ref) { |
| 16538 return; |
| 16539 } |
| 16540 { |
| 16541 JSONArray jsarr(&jsobj, "elements"); |
| 16542 for (intptr_t index = 0; index < Length(); index++) { |
| 16543 JSONObject jselement(&jsarr); |
| 16544 jselement.AddProperty("index", index); |
| 16545 |
| 16546 Instance& instance = Instance::Handle(); |
| 16547 instance ^= At(index); |
| 16548 jselement.AddProperty("value", instance); |
| 16549 } |
| 16550 } |
| 16515 } | 16551 } |
| 16516 | 16552 |
| 16517 | 16553 |
| 16518 RawFloat32x4* Float32x4::New(float v0, float v1, float v2, float v3, | 16554 RawFloat32x4* Float32x4::New(float v0, float v1, float v2, float v3, |
| 16519 Heap::Space space) { | 16555 Heap::Space space) { |
| 16520 ASSERT(Isolate::Current()->object_store()->float32x4_class() != | 16556 ASSERT(Isolate::Current()->object_store()->float32x4_class() != |
| 16521 Class::null()); | 16557 Class::null()); |
| 16522 Float32x4& result = Float32x4::Handle(); | 16558 Float32x4& result = Float32x4::Handle(); |
| 16523 { | 16559 { |
| 16524 RawObject* raw = Object::Allocate(Float32x4::kClassId, | 16560 RawObject* raw = Object::Allocate(Float32x4::kClassId, |
| (...skipping 839 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 17364 return "_MirrorReference"; | 17400 return "_MirrorReference"; |
| 17365 } | 17401 } |
| 17366 | 17402 |
| 17367 | 17403 |
| 17368 void MirrorReference::PrintToJSONStream(JSONStream* stream, bool ref) const { | 17404 void MirrorReference::PrintToJSONStream(JSONStream* stream, bool ref) const { |
| 17369 Instance::PrintToJSONStream(stream, ref); | 17405 Instance::PrintToJSONStream(stream, ref); |
| 17370 } | 17406 } |
| 17371 | 17407 |
| 17372 | 17408 |
| 17373 } // namespace dart | 17409 } // namespace dart |
| OLD | NEW |