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 3216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3227 RawObject* Class::canonical_types() const { | 3227 RawObject* Class::canonical_types() const { |
3228 return raw_ptr()->canonical_types_; | 3228 return raw_ptr()->canonical_types_; |
3229 } | 3229 } |
3230 | 3230 |
3231 void Class::set_canonical_types(const Object& value) const { | 3231 void Class::set_canonical_types(const Object& value) const { |
3232 ASSERT(!value.IsNull()); | 3232 ASSERT(!value.IsNull()); |
3233 StorePointer(&raw_ptr()->canonical_types_, value.raw()); | 3233 StorePointer(&raw_ptr()->canonical_types_, value.raw()); |
3234 } | 3234 } |
3235 | 3235 |
3236 | 3236 |
3237 intptr_t Class::NumCanonicalTypes() const { | |
3238 if (CanonicalType() != Type::null()) { | |
3239 return 1; | |
3240 } | |
3241 const Object& types = Object::Handle(canonical_types()); | |
3242 if (types.IsNull() || !types.IsArray()) { | |
3243 return 0; | |
3244 } | |
3245 intptr_t num_types = Array::Cast(types).Length(); | |
3246 while (Array::Cast(types).At(num_types - 1) == Type::null()) { | |
3247 num_types--; | |
3248 } | |
3249 return num_types; | |
3250 } | |
3251 | |
3252 | |
3253 intptr_t Class::FindCanonicalTypeIndex(const Type& needle) const { | |
3254 Isolate* isolate = Isolate::Current(); | |
3255 if (EnsureIsFinalized(isolate) != Error::null()) { | |
3256 return -1; | |
3257 } | |
3258 if (needle.raw() == CanonicalType()) { | |
3259 return 0; | |
3260 } | |
3261 ReusableHandleScope reused_handles(isolate); | |
3262 Object& types = reused_handles.ObjectHandle(); | |
3263 types = canonical_types(); | |
3264 if (types.IsNull() || !types.IsArray()) { | |
3265 return -1; | |
3266 } | |
3267 const intptr_t len = Array::Cast(types).Length(); | |
3268 AbstractType& type = reused_handles.AbstractTypeHandle(); | |
3269 for (intptr_t i = 0; i < len; i++) { | |
3270 type ^= Array::Cast(types).At(i); | |
3271 if (needle.raw() == type.raw()) { | |
3272 return i; | |
3273 } | |
3274 } | |
3275 // No type found. | |
3276 return -1; | |
3277 } | |
3278 | |
3279 | |
3280 RawType* Class::CanonicalTypeFromIndex(intptr_t idx) const { | |
3281 Type& type = Type::Handle(); | |
3282 if (idx == 0) { | |
3283 type = CanonicalType(); | |
3284 if (!type.IsNull()) { | |
3285 return type.raw(); | |
3286 } | |
3287 } | |
3288 Object& types = Object::Handle(canonical_types()); | |
3289 if (types.IsNull() || !types.IsArray()) { | |
3290 types = empty_array().raw(); | |
3291 } | |
3292 if ((idx < 0) || (idx >= Array::Cast(types).Length())) { | |
3293 return Type::null(); | |
3294 } | |
3295 type ^= Array::Cast(types).At(idx); | |
3296 ASSERT(!type.IsNull()); | |
3297 return type.raw(); | |
3298 } | |
3299 | |
3300 | |
3237 void Class::set_allocation_stub(const Code& value) const { | 3301 void Class::set_allocation_stub(const Code& value) const { |
3238 ASSERT(!value.IsNull()); | 3302 ASSERT(!value.IsNull()); |
3239 ASSERT(raw_ptr()->allocation_stub_ == Code::null()); | 3303 ASSERT(raw_ptr()->allocation_stub_ == Code::null()); |
3240 StorePointer(&raw_ptr()->allocation_stub_, value.raw()); | 3304 StorePointer(&raw_ptr()->allocation_stub_, value.raw()); |
3241 } | 3305 } |
3242 | 3306 |
3243 | 3307 |
3244 bool Class::IsFunctionClass() const { | 3308 bool Class::IsFunctionClass() const { |
3245 return raw() == Type::Handle(Type::Function()).type_class(); | 3309 return raw() == Type::Handle(Type::Function()).type_class(); |
3246 } | 3310 } |
(...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3587 Isolate* isolate = Isolate::Current(); | 3651 Isolate* isolate = Isolate::Current(); |
3588 if (EnsureIsFinalized(isolate) != Error::null()) { | 3652 if (EnsureIsFinalized(isolate) != Error::null()) { |
3589 return Function::null(); | 3653 return Function::null(); |
3590 } | 3654 } |
3591 ReusableHandleScope reused_handles(isolate); | 3655 ReusableHandleScope reused_handles(isolate); |
3592 Array& funcs = reused_handles.ArrayHandle(); | 3656 Array& funcs = reused_handles.ArrayHandle(); |
3593 funcs ^= functions(); | 3657 funcs ^= functions(); |
3594 ASSERT(!funcs.IsNull()); | 3658 ASSERT(!funcs.IsNull()); |
3595 Function& function = reused_handles.FunctionHandle(); | 3659 Function& function = reused_handles.FunctionHandle(); |
3596 String& function_name = reused_handles.StringHandle(); | 3660 String& function_name = reused_handles.StringHandle(); |
3597 intptr_t len = funcs.Length(); | 3661 const intptr_t len = funcs.Length(); |
3598 for (intptr_t i = 0; i < len; i++) { | 3662 for (intptr_t i = 0; i < len; i++) { |
3599 function ^= funcs.At(i); | 3663 function ^= funcs.At(i); |
3600 function_name ^= function.name(); | 3664 function_name ^= function.name(); |
3601 if (String::EqualsIgnoringPrivateKey(function_name, name)) { | 3665 if (String::EqualsIgnoringPrivateKey(function_name, name)) { |
3602 return CheckFunctionType(function, type); | 3666 return CheckFunctionType(function, type); |
3603 } | 3667 } |
3604 } | 3668 } |
3605 // No function found. | 3669 // No function found. |
3606 return Function::null(); | 3670 return Function::null(); |
3607 } | 3671 } |
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3782 JSONArray functions_array(&jsobj, "functions"); | 3846 JSONArray functions_array(&jsobj, "functions"); |
3783 const Array& function_array = Array::Handle(functions()); | 3847 const Array& function_array = Array::Handle(functions()); |
3784 Function& function = Function::Handle(); | 3848 Function& function = Function::Handle(); |
3785 if (!function_array.IsNull()) { | 3849 if (!function_array.IsNull()) { |
3786 for (intptr_t i = 0; i < function_array.Length(); i++) { | 3850 for (intptr_t i = 0; i < function_array.Length(); i++) { |
3787 function ^= function_array.At(i); | 3851 function ^= function_array.At(i); |
3788 functions_array.AddValue(function); | 3852 functions_array.AddValue(function); |
3789 } | 3853 } |
3790 } | 3854 } |
3791 } | 3855 } |
3856 jsobj.AddPropertyF("canonicalTypes", "classes/%" Pd "/types", id()); | |
3792 } | 3857 } |
3793 } | 3858 } |
3794 | 3859 |
3795 | 3860 |
3796 void Class::InsertCanonicalConstant(intptr_t index, | 3861 void Class::InsertCanonicalConstant(intptr_t index, |
3797 const Instance& constant) const { | 3862 const Instance& constant) const { |
3798 // The constant needs to be added to the list. Grow the list if it is full. | 3863 // The constant needs to be added to the list. Grow the list if it is full. |
3799 Array& canonical_list = Array::Handle(constants()); | 3864 Array& canonical_list = Array::Handle(constants()); |
3800 const intptr_t list_len = canonical_list.Length(); | 3865 const intptr_t list_len = canonical_list.Length(); |
3801 if (index >= list_len) { | 3866 if (index >= list_len) { |
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3994 if (!type.TypeTest(test_kind, other_type, bound_error)) { | 4059 if (!type.TypeTest(test_kind, other_type, bound_error)) { |
3995 return false; | 4060 return false; |
3996 } | 4061 } |
3997 } | 4062 } |
3998 return true; | 4063 return true; |
3999 } | 4064 } |
4000 | 4065 |
4001 | 4066 |
4002 void TypeArguments::PrintToJSONStream(JSONStream* stream, bool ref) const { | 4067 void TypeArguments::PrintToJSONStream(JSONStream* stream, bool ref) const { |
4003 JSONObject jsobj(stream); | 4068 JSONObject jsobj(stream); |
4069 if (IsNull()) { | |
4070 jsobj.AddProperty("type", ref ? "@Null" : "Null"); | |
4071 jsobj.AddProperty("id", "objects/null"); | |
4072 return; | |
4073 } | |
4074 // The index in the canonical_type_arguments table cannot be used as part of | |
4075 // the object id (as in typearguments/id), because the indices are not | |
4076 // preserved when the table grows and the entries get rehashed. Use the ring. | |
4077 Isolate* isolate = Isolate::Current(); | |
4078 ObjectStore* object_store = isolate->object_store(); | |
4079 const Array& table = Array::Handle(object_store->canonical_type_arguments()); | |
4080 ASSERT(table.Length() > 0); | |
4081 ObjectIdRing* ring = Isolate::Current()->object_id_ring(); | |
4082 const intptr_t id = ring->GetIdForObject(raw()); | |
4083 jsobj.AddProperty("type", JSONType(ref)); | |
4084 jsobj.AddPropertyF("id", "objects/%" Pd "", id); | |
4085 jsobj.AddProperty("name", String::Handle(UserVisibleName()).ToCString()); | |
4086 jsobj.AddProperty("length", Length()); | |
4087 jsobj.AddProperty("num_instantiations", NumInstantiations()); | |
4088 if (ref) { | |
4089 return; | |
4090 } | |
4091 { | |
4092 JSONArray jsarr(&jsobj, "types"); | |
4093 AbstractType& type_arg = AbstractType::Handle(); | |
4094 for (intptr_t i = 0; i < Length(); i++) { | |
4095 type_arg = TypeAt(i); | |
4096 jsarr.AddValue(type_arg); | |
4097 } | |
4098 } | |
4099 if (!IsInstantiated()) { | |
4100 JSONArray jsarr(&jsobj, "instantiations"); | |
4101 Array& prior_instantiations = Array::Handle(instantiations()); | |
4102 ASSERT(prior_instantiations.Length() > 0); // Always at least a sentinel. | |
4103 TypeArguments& type_args = TypeArguments::Handle(); | |
4104 intptr_t i = 0; | |
4105 while (true) { | |
4106 if (prior_instantiations.At(i) == Smi::New(StubCode::kNoInstantiator)) { | |
4107 break; | |
4108 } | |
4109 JSONObject instantiation(&jsarr); | |
4110 type_args ^= prior_instantiations.At(i); | |
4111 instantiation.AddProperty("instantiator", type_args, true); | |
4112 type_args ^= prior_instantiations.At(i + 1); | |
4113 instantiation.AddProperty("instantiated", type_args, true); | |
4114 i += 2; | |
4115 } | |
4116 } | |
4117 } | |
4118 | |
4119 | |
4120 bool TypeArguments::HasInstantiations() const { | |
4121 const Array& prior_instantiations = Array::Handle(instantiations()); | |
4122 ASSERT(prior_instantiations.Length() > 0); // Always at least a sentinel. | |
4123 return prior_instantiations.Length() > 1; | |
4124 } | |
4125 | |
4126 | |
4127 intptr_t TypeArguments::NumInstantiations() const { | |
4128 const Array& prior_instantiations = Array::Handle(instantiations()); | |
4129 ASSERT(prior_instantiations.Length() > 0); // Always at least a sentinel. | |
4130 intptr_t i = 0; | |
4131 while (prior_instantiations.At(i) != Smi::New(StubCode::kNoInstantiator)) { | |
4132 i += 2; | |
4133 } | |
4134 return i/2; | |
4004 } | 4135 } |
4005 | 4136 |
4006 | 4137 |
4007 RawArray* TypeArguments::instantiations() const { | 4138 RawArray* TypeArguments::instantiations() const { |
4008 return raw_ptr()->instantiations_; | 4139 return raw_ptr()->instantiations_; |
4009 } | 4140 } |
4010 | 4141 |
4142 | |
4011 void TypeArguments::set_instantiations(const Array& value) const { | 4143 void TypeArguments::set_instantiations(const Array& value) const { |
4012 ASSERT(!value.IsNull()); | 4144 ASSERT(!value.IsNull()); |
4013 StorePointer(&raw_ptr()->instantiations_, value.raw()); | 4145 StorePointer(&raw_ptr()->instantiations_, value.raw()); |
4014 } | 4146 } |
4015 | 4147 |
4016 | 4148 |
4017 intptr_t TypeArguments::Length() const { | 4149 intptr_t TypeArguments::Length() const { |
4018 ASSERT(!IsNull()); | 4150 ASSERT(!IsNull()); |
4019 return Smi::Value(raw_ptr()->length_); | 4151 return Smi::Value(raw_ptr()->length_); |
4020 } | 4152 } |
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4240 const TypeArguments& instantiator_type_arguments, | 4372 const TypeArguments& instantiator_type_arguments, |
4241 Error* bound_error) const { | 4373 Error* bound_error) const { |
4242 ASSERT(!IsInstantiated()); | 4374 ASSERT(!IsInstantiated()); |
4243 ASSERT(instantiator_type_arguments.IsNull() || | 4375 ASSERT(instantiator_type_arguments.IsNull() || |
4244 instantiator_type_arguments.IsCanonical()); | 4376 instantiator_type_arguments.IsCanonical()); |
4245 // Lookup instantiator and, if found, return paired instantiated result. | 4377 // Lookup instantiator and, if found, return paired instantiated result. |
4246 Array& prior_instantiations = Array::Handle(instantiations()); | 4378 Array& prior_instantiations = Array::Handle(instantiations()); |
4247 ASSERT(!prior_instantiations.IsNull() && prior_instantiations.IsArray()); | 4379 ASSERT(!prior_instantiations.IsNull() && prior_instantiations.IsArray()); |
4248 // The instantiations cache is initialized with Object::zero_array() and is | 4380 // The instantiations cache is initialized with Object::zero_array() and is |
4249 // therefore guaranteed to contain kNoInstantiator. No length check needed. | 4381 // therefore guaranteed to contain kNoInstantiator. No length check needed. |
4250 ASSERT(prior_instantiations.Length() > 0); | 4382 ASSERT(prior_instantiations.Length() > 0); // Always at least a sentinel. |
4251 intptr_t index = 0; | 4383 intptr_t index = 0; |
4252 while (true) { | 4384 while (true) { |
4253 if (prior_instantiations.At(index) == instantiator_type_arguments.raw()) { | 4385 if (prior_instantiations.At(index) == instantiator_type_arguments.raw()) { |
4254 return TypeArguments::RawCast(prior_instantiations.At(index + 1)); | 4386 return TypeArguments::RawCast(prior_instantiations.At(index + 1)); |
4255 } | 4387 } |
4256 if (prior_instantiations.At(index) == Smi::New(StubCode::kNoInstantiator)) { | 4388 if (prior_instantiations.At(index) == Smi::New(StubCode::kNoInstantiator)) { |
4257 break; | 4389 break; |
4258 } | 4390 } |
4259 index += 2; | 4391 index += 2; |
4260 } | 4392 } |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4363 intptr_t index) { | 4495 intptr_t index) { |
4364 arguments.SetCanonical(); // Mark object as being canonical. | 4496 arguments.SetCanonical(); // Mark object as being canonical. |
4365 table.SetAt(index, arguments); // Remember the new element. | 4497 table.SetAt(index, arguments); // Remember the new element. |
4366 // Update used count. | 4498 // Update used count. |
4367 // Last element of the array is the number of used elements. | 4499 // Last element of the array is the number of used elements. |
4368 intptr_t table_size = table.Length() - 1; | 4500 intptr_t table_size = table.Length() - 1; |
4369 intptr_t used_elements = Smi::Value(Smi::RawCast(table.At(table_size))) + 1; | 4501 intptr_t used_elements = Smi::Value(Smi::RawCast(table.At(table_size))) + 1; |
4370 const Smi& used = Smi::Handle(isolate, Smi::New(used_elements)); | 4502 const Smi& used = Smi::Handle(isolate, Smi::New(used_elements)); |
4371 table.SetAt(table_size, used); | 4503 table.SetAt(table_size, used); |
4372 | 4504 |
4505 // TODO(regis): Use a trail to compute hashes of TypeRef, or duplicates will | |
4506 // show up in the table (different hashes but equal). | |
4507 #if 0 // #ifdef DEBUG | |
4508 // Verify that there are no duplicates. | |
4509 // Duplicates could appear if hash values are not kept constant across | |
4510 // snapshots, e.g. if class ids are not preserved by the snapshots. | |
4511 TypeArguments& other = TypeArguments::Handle(); | |
4512 for (intptr_t i = 0; i < table_size; i++) { | |
4513 if ((i != index) && (table.At(i) != TypeArguments::null())) { | |
4514 other ^= table.At(i); | |
4515 ASSERT(!arguments.Equals(other)); | |
4516 } | |
4517 } | |
4518 #endif | |
4519 | |
4373 // Rehash if table is 75% full. | 4520 // Rehash if table is 75% full. |
4374 if (used_elements > ((table_size / 4) * 3)) { | 4521 if (used_elements > ((table_size / 4) * 3)) { |
4375 GrowCanonicalTypeArguments(isolate, table); | 4522 GrowCanonicalTypeArguments(isolate, table); |
4376 } | 4523 } |
4377 } | 4524 } |
4378 | 4525 |
4379 | 4526 |
4380 static intptr_t FindIndexInCanonicalTypeArguments( | 4527 static intptr_t FindIndexInCanonicalTypeArguments( |
4381 Isolate* isolate, | 4528 Isolate* isolate, |
4382 const Array& table, | 4529 const Array& table, |
(...skipping 7742 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
12125 } else if (raw() == Symbols::OptimizedOut().raw()) { | 12272 } else if (raw() == Symbols::OptimizedOut().raw()) { |
12126 // TODO(turnidge): This is a hack. The user could have this | 12273 // TODO(turnidge): This is a hack. The user could have this |
12127 // special string in their program. Fixing this involves updating | 12274 // special string in their program. Fixing this involves updating |
12128 // the debugging api a bit. | 12275 // the debugging api a bit. |
12129 jsobj.AddProperty("type", ref ? "@Null" : "Null"); | 12276 jsobj.AddProperty("type", ref ? "@Null" : "Null"); |
12130 jsobj.AddProperty("id", "objects/optimized-out"); | 12277 jsobj.AddProperty("id", "objects/optimized-out"); |
12131 jsobj.AddProperty("preview", "<optimized out>"); | 12278 jsobj.AddProperty("preview", "<optimized out>"); |
12132 return; | 12279 return; |
12133 } else { | 12280 } else { |
12134 ObjectIdRing* ring = Isolate::Current()->object_id_ring(); | 12281 ObjectIdRing* ring = Isolate::Current()->object_id_ring(); |
12135 intptr_t id = ring->GetIdForObject(raw()); | 12282 const intptr_t id = ring->GetIdForObject(raw()); |
12136 if (IsClosure()) { | 12283 if (IsClosure()) { |
12137 const Function& closureFunc = Function::Handle(Closure::function(*this)); | 12284 const Function& closureFunc = Function::Handle(Closure::function(*this)); |
12138 jsobj.AddProperty("closureFunc", closureFunc); | 12285 jsobj.AddProperty("closureFunc", closureFunc); |
12139 jsobj.AddProperty("type", ref ? "@Closure" : "Closure"); | 12286 jsobj.AddProperty("type", ref ? "@Closure" : "Closure"); |
12140 } else { | 12287 } else { |
12141 jsobj.AddProperty("type", JSONType(ref)); | 12288 jsobj.AddProperty("type", JSONType(ref)); |
12142 } | 12289 } |
12143 jsobj.AddPropertyF("id", "objects/%" Pd "", id); | 12290 jsobj.AddPropertyF("id", "objects/%" Pd "", id); |
12144 jsobj.AddProperty("class", cls); | 12291 jsobj.AddProperty("class", cls); |
12145 } | 12292 } |
(...skipping 416 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
12562 | 12709 |
12563 | 12710 |
12564 const char* AbstractType::ToCString() const { | 12711 const char* AbstractType::ToCString() const { |
12565 // AbstractType is an abstract class. | 12712 // AbstractType is an abstract class. |
12566 UNREACHABLE(); | 12713 UNREACHABLE(); |
12567 return "AbstractType"; | 12714 return "AbstractType"; |
12568 } | 12715 } |
12569 | 12716 |
12570 | 12717 |
12571 void AbstractType::PrintToJSONStream(JSONStream* stream, bool ref) const { | 12718 void AbstractType::PrintToJSONStream(JSONStream* stream, bool ref) const { |
12572 JSONObject jsobj(stream); | 12719 UNREACHABLE(); |
12573 } | 12720 } |
12574 | 12721 |
12575 | 12722 |
12576 RawType* Type::NullType() { | 12723 RawType* Type::NullType() { |
12577 return Isolate::Current()->object_store()->null_type(); | 12724 return Isolate::Current()->object_store()->null_type(); |
12578 } | 12725 } |
12579 | 12726 |
12580 | 12727 |
12581 RawType* Type::DynamicType() { | 12728 RawType* Type::DynamicType() { |
12582 return Object::dynamic_type(); | 12729 return Object::dynamic_type(); |
(...skipping 498 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
13081 OS::SNPrint(chars, len, format, class_name, args_cstr); | 13228 OS::SNPrint(chars, len, format, class_name, args_cstr); |
13082 return chars; | 13229 return chars; |
13083 } | 13230 } |
13084 } else { | 13231 } else { |
13085 return "Unresolved Type"; | 13232 return "Unresolved Type"; |
13086 } | 13233 } |
13087 } | 13234 } |
13088 | 13235 |
13089 | 13236 |
13090 void Type::PrintToJSONStream(JSONStream* stream, bool ref) const { | 13237 void Type::PrintToJSONStream(JSONStream* stream, bool ref) const { |
13238 ASSERT(IsCanonical()); | |
13091 JSONObject jsobj(stream); | 13239 JSONObject jsobj(stream); |
13240 jsobj.AddProperty("type", JSONType(ref)); | |
13241 const Class& type_cls = Class::Handle(type_class()); | |
13242 intptr_t id = type_cls.FindCanonicalTypeIndex(*this); | |
13243 if (id >= 0) { | |
13244 intptr_t cid = type_cls.id(); | |
13245 jsobj.AddPropertyF("id", "classes/%" Pd "/types/%" Pd "", cid, id); | |
13246 } else { | |
13247 ObjectIdRing* ring = Isolate::Current()->object_id_ring(); | |
13248 id = ring->GetIdForObject(raw()); | |
Cutch
2014/03/11 13:50:01
How frequently does this path happen?
regis
2014/03/14 23:52:07
If I call PrintToJSON on all canonicalized type ar
| |
13249 jsobj.AddPropertyF("id", "objects/%" Pd "", id); | |
13250 } | |
13251 const char* type_name = String::Handle(UserVisibleName()).ToCString(); | |
13252 jsobj.AddProperty("name", type_name); | |
13253 if (ref) { | |
13254 return; | |
13255 } | |
13256 jsobj.AddProperty("type_class", type_cls); | |
13257 jsobj.AddProperty("type_arguments", TypeArguments::Handle(arguments())); | |
13092 } | 13258 } |
13093 | 13259 |
13094 | 13260 |
13095 bool TypeRef::IsInstantiated(GrowableObjectArray* trail) const { | 13261 bool TypeRef::IsInstantiated(GrowableObjectArray* trail) const { |
13096 if (TestAndAddToTrail(&trail)) { | 13262 if (TestAndAddToTrail(&trail)) { |
13097 return true; | 13263 return true; |
13098 } | 13264 } |
13099 return AbstractType::Handle(type()).IsInstantiated(trail); | 13265 return AbstractType::Handle(type()).IsInstantiated(trail); |
13100 } | 13266 } |
13101 | 13267 |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
13250 type()).arguments() == TypeArguments::null()) ? "" : "<...>"; | 13416 type()).arguments() == TypeArguments::null()) ? "" : "<...>"; |
13251 intptr_t len = OS::SNPrint(NULL, 0, format, type_cstr, args_cstr) + 1; | 13417 intptr_t len = OS::SNPrint(NULL, 0, format, type_cstr, args_cstr) + 1; |
13252 char* chars = Isolate::Current()->current_zone()->Alloc<char>(len); | 13418 char* chars = Isolate::Current()->current_zone()->Alloc<char>(len); |
13253 OS::SNPrint(chars, len, format, type_cstr, args_cstr); | 13419 OS::SNPrint(chars, len, format, type_cstr, args_cstr); |
13254 return chars; | 13420 return chars; |
13255 } | 13421 } |
13256 | 13422 |
13257 | 13423 |
13258 void TypeRef::PrintToJSONStream(JSONStream* stream, bool ref) const { | 13424 void TypeRef::PrintToJSONStream(JSONStream* stream, bool ref) const { |
13259 JSONObject jsobj(stream); | 13425 JSONObject jsobj(stream); |
13426 ObjectIdRing* ring = Isolate::Current()->object_id_ring(); | |
13427 const intptr_t id = ring->GetIdForObject(raw()); | |
13428 jsobj.AddProperty("type", JSONType(ref)); | |
13429 jsobj.AddPropertyF("id", "objects/%" Pd "", id); | |
13430 const char* type_name = String::Handle(UserVisibleName()).ToCString(); | |
13431 jsobj.AddProperty("name", type_name); | |
13432 if (ref) { | |
13433 return; | |
13434 } | |
13435 jsobj.AddProperty("ref_type", AbstractType::Handle(type())); | |
13260 } | 13436 } |
13261 | 13437 |
13262 | 13438 |
13263 void TypeParameter::set_is_finalized() const { | 13439 void TypeParameter::set_is_finalized() const { |
13264 ASSERT(!IsFinalized()); | 13440 ASSERT(!IsFinalized()); |
13265 set_type_state(RawTypeParameter::kFinalizedUninstantiated); | 13441 set_type_state(RawTypeParameter::kFinalizedUninstantiated); |
13266 } | 13442 } |
13267 | 13443 |
13268 | 13444 |
13269 bool TypeParameter::IsEquivalent(const Instance& other, | 13445 bool TypeParameter::IsEquivalent(const Instance& other, |
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
13454 intptr_t len = OS::SNPrint( | 13630 intptr_t len = OS::SNPrint( |
13455 NULL, 0, format, name_cstr, index(), cls_cstr, bound_cstr) + 1; | 13631 NULL, 0, format, name_cstr, index(), cls_cstr, bound_cstr) + 1; |
13456 char* chars = Isolate::Current()->current_zone()->Alloc<char>(len); | 13632 char* chars = Isolate::Current()->current_zone()->Alloc<char>(len); |
13457 OS::SNPrint(chars, len, format, name_cstr, index(), cls_cstr, bound_cstr); | 13633 OS::SNPrint(chars, len, format, name_cstr, index(), cls_cstr, bound_cstr); |
13458 return chars; | 13634 return chars; |
13459 } | 13635 } |
13460 | 13636 |
13461 | 13637 |
13462 void TypeParameter::PrintToJSONStream(JSONStream* stream, bool ref) const { | 13638 void TypeParameter::PrintToJSONStream(JSONStream* stream, bool ref) const { |
13463 JSONObject jsobj(stream); | 13639 JSONObject jsobj(stream); |
13640 ObjectIdRing* ring = Isolate::Current()->object_id_ring(); | |
13641 const intptr_t id = ring->GetIdForObject(raw()); | |
13642 jsobj.AddProperty("type", JSONType(ref)); | |
13643 jsobj.AddPropertyF("id", "objects/%" Pd "", id); | |
13644 jsobj.AddProperty("name", String::Handle(name()).ToCString()); | |
13645 const Class& cls = Class::Handle(parameterized_class()); | |
13646 jsobj.AddProperty("parameterized_class", cls); | |
13647 if (ref) { | |
13648 return; | |
13649 } | |
13650 jsobj.AddProperty("index", index()); | |
13651 const AbstractType& upper_bound = AbstractType::Handle(bound()); | |
13652 jsobj.AddProperty("upper_bound", upper_bound); | |
13464 } | 13653 } |
13465 | 13654 |
13466 | 13655 |
13467 bool BoundedType::IsMalformed() const { | 13656 bool BoundedType::IsMalformed() const { |
13468 return AbstractType::Handle(type()).IsMalformed(); | 13657 return AbstractType::Handle(type()).IsMalformed(); |
13469 } | 13658 } |
13470 | 13659 |
13471 | 13660 |
13472 bool BoundedType::IsMalbounded() const { | 13661 bool BoundedType::IsMalbounded() const { |
13473 return AbstractType::Handle(type()).IsMalbounded(); | 13662 return AbstractType::Handle(type()).IsMalbounded(); |
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
13635 NULL, 0, format, type_cstr, bound_cstr, type_param_cstr, cls_cstr) + 1; | 13824 NULL, 0, format, type_cstr, bound_cstr, type_param_cstr, cls_cstr) + 1; |
13636 char* chars = Isolate::Current()->current_zone()->Alloc<char>(len); | 13825 char* chars = Isolate::Current()->current_zone()->Alloc<char>(len); |
13637 OS::SNPrint( | 13826 OS::SNPrint( |
13638 chars, len, format, type_cstr, bound_cstr, type_param_cstr, cls_cstr); | 13827 chars, len, format, type_cstr, bound_cstr, type_param_cstr, cls_cstr); |
13639 return chars; | 13828 return chars; |
13640 } | 13829 } |
13641 | 13830 |
13642 | 13831 |
13643 void BoundedType::PrintToJSONStream(JSONStream* stream, bool ref) const { | 13832 void BoundedType::PrintToJSONStream(JSONStream* stream, bool ref) const { |
13644 JSONObject jsobj(stream); | 13833 JSONObject jsobj(stream); |
13834 ObjectIdRing* ring = Isolate::Current()->object_id_ring(); | |
13835 const intptr_t id = ring->GetIdForObject(raw()); | |
13836 jsobj.AddProperty("type", JSONType(ref)); | |
13837 jsobj.AddPropertyF("id", "objects/%" Pd "", id); | |
13838 const char* type_name = String::Handle(UserVisibleName()).ToCString(); | |
13839 jsobj.AddProperty("name", type_name); | |
13840 if (ref) { | |
13841 return; | |
13842 } | |
13843 jsobj.AddProperty("bounded_type", AbstractType::Handle(type())); | |
13844 jsobj.AddProperty("upper_bound", AbstractType::Handle(bound())); | |
13645 } | 13845 } |
13646 | 13846 |
13647 | 13847 |
13648 intptr_t MixinAppType::token_pos() const { | 13848 intptr_t MixinAppType::token_pos() const { |
13649 return AbstractType::Handle(MixinTypeAt(0)).token_pos(); | 13849 return AbstractType::Handle(MixinTypeAt(0)).token_pos(); |
13650 } | 13850 } |
13651 | 13851 |
13652 | 13852 |
13653 intptr_t MixinAppType::Depth() const { | 13853 intptr_t MixinAppType::Depth() const { |
13654 return Array::Handle(mixin_types()).Length(); | 13854 return Array::Handle(mixin_types()).Length(); |
(...skipping 13 matching lines...) Expand all Loading... | |
13668 MixinTypeAt(0)).Name()).ToCString(); | 13868 MixinTypeAt(0)).Name()).ToCString(); |
13669 intptr_t len = OS::SNPrint( | 13869 intptr_t len = OS::SNPrint( |
13670 NULL, 0, format, super_type_cstr, first_mixin_type_cstr) + 1; | 13870 NULL, 0, format, super_type_cstr, first_mixin_type_cstr) + 1; |
13671 char* chars = Isolate::Current()->current_zone()->Alloc<char>(len); | 13871 char* chars = Isolate::Current()->current_zone()->Alloc<char>(len); |
13672 OS::SNPrint(chars, len, format, super_type_cstr, first_mixin_type_cstr); | 13872 OS::SNPrint(chars, len, format, super_type_cstr, first_mixin_type_cstr); |
13673 return chars; | 13873 return chars; |
13674 } | 13874 } |
13675 | 13875 |
13676 | 13876 |
13677 void MixinAppType::PrintToJSONStream(JSONStream* stream, bool ref) const { | 13877 void MixinAppType::PrintToJSONStream(JSONStream* stream, bool ref) const { |
13678 JSONObject jsobj(stream); | 13878 UNREACHABLE(); |
13679 } | 13879 } |
13680 | 13880 |
13681 | 13881 |
13682 RawAbstractType* MixinAppType::MixinTypeAt(intptr_t depth) const { | 13882 RawAbstractType* MixinAppType::MixinTypeAt(intptr_t depth) const { |
13683 return AbstractType::RawCast(Array::Handle(mixin_types()).At(depth)); | 13883 return AbstractType::RawCast(Array::Handle(mixin_types()).At(depth)); |
13684 } | 13884 } |
13685 | 13885 |
13686 | 13886 |
13687 void MixinAppType::set_super_type(const AbstractType& value) const { | 13887 void MixinAppType::set_super_type(const AbstractType& value) const { |
13688 StorePointer(&raw_ptr()->super_type_, value.raw()); | 13888 StorePointer(&raw_ptr()->super_type_, value.raw()); |
(...skipping 2600 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
16289 char* chars = Isolate::Current()->current_zone()->Alloc<char>(len); | 16489 char* chars = Isolate::Current()->current_zone()->Alloc<char>(len); |
16290 OS::SNPrint(chars, len, format, Length()); | 16490 OS::SNPrint(chars, len, format, Length()); |
16291 return chars; | 16491 return chars; |
16292 } | 16492 } |
16293 | 16493 |
16294 | 16494 |
16295 void Array::PrintToJSONStream(JSONStream* stream, bool ref) const { | 16495 void Array::PrintToJSONStream(JSONStream* stream, bool ref) const { |
16296 JSONObject jsobj(stream); | 16496 JSONObject jsobj(stream); |
16297 Class& cls = Class::Handle(this->clazz()); | 16497 Class& cls = Class::Handle(this->clazz()); |
16298 ObjectIdRing* ring = Isolate::Current()->object_id_ring(); | 16498 ObjectIdRing* ring = Isolate::Current()->object_id_ring(); |
16299 intptr_t id = ring->GetIdForObject(raw()); | 16499 const intptr_t id = ring->GetIdForObject(raw()); |
16300 jsobj.AddProperty("type", JSONType(ref)); | 16500 jsobj.AddProperty("type", JSONType(ref)); |
16301 jsobj.AddPropertyF("id", "objects/%" Pd "", id); | 16501 jsobj.AddPropertyF("id", "objects/%" Pd "", id); |
16302 jsobj.AddProperty("class", cls); | 16502 jsobj.AddProperty("class", cls); |
16303 jsobj.AddProperty("length", Length()); | 16503 jsobj.AddProperty("length", Length()); |
16304 if (ref) { | 16504 if (ref) { |
16305 return; | 16505 return; |
16306 } | 16506 } |
16307 { | 16507 { |
16308 JSONArray jsarr(&jsobj, "elements"); | 16508 JSONArray jsarr(&jsobj, "elements"); |
16309 for (intptr_t index = 0; index < Length(); index++) { | 16509 for (intptr_t index = 0; index < Length(); index++) { |
(...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
16629 buffer[pos] = '\0'; | 16829 buffer[pos] = '\0'; |
16630 return buffer; | 16830 return buffer; |
16631 } | 16831 } |
16632 | 16832 |
16633 | 16833 |
16634 void GrowableObjectArray::PrintToJSONStream(JSONStream* stream, | 16834 void GrowableObjectArray::PrintToJSONStream(JSONStream* stream, |
16635 bool ref) const { | 16835 bool ref) const { |
16636 JSONObject jsobj(stream); | 16836 JSONObject jsobj(stream); |
16637 Class& cls = Class::Handle(this->clazz()); | 16837 Class& cls = Class::Handle(this->clazz()); |
16638 ObjectIdRing* ring = Isolate::Current()->object_id_ring(); | 16838 ObjectIdRing* ring = Isolate::Current()->object_id_ring(); |
16639 intptr_t id = ring->GetIdForObject(raw()); | 16839 const intptr_t id = ring->GetIdForObject(raw()); |
16640 jsobj.AddProperty("type", JSONType(ref)); | 16840 jsobj.AddProperty("type", JSONType(ref)); |
16641 jsobj.AddPropertyF("id", "objects/%" Pd "", id); | 16841 jsobj.AddPropertyF("id", "objects/%" Pd "", id); |
16642 jsobj.AddProperty("class", cls); | 16842 jsobj.AddProperty("class", cls); |
16643 jsobj.AddProperty("length", Length()); | 16843 jsobj.AddProperty("length", Length()); |
16644 if (ref) { | 16844 if (ref) { |
16645 return; | 16845 return; |
16646 } | 16846 } |
16647 { | 16847 { |
16648 JSONArray jsarr(&jsobj, "elements"); | 16848 JSONArray jsarr(&jsobj, "elements"); |
16649 for (intptr_t index = 0; index < Length(); index++) { | 16849 for (intptr_t index = 0; index < Length(); index++) { |
(...skipping 857 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
17507 return "_MirrorReference"; | 17707 return "_MirrorReference"; |
17508 } | 17708 } |
17509 | 17709 |
17510 | 17710 |
17511 void MirrorReference::PrintToJSONStream(JSONStream* stream, bool ref) const { | 17711 void MirrorReference::PrintToJSONStream(JSONStream* stream, bool ref) const { |
17512 Instance::PrintToJSONStream(stream, ref); | 17712 Instance::PrintToJSONStream(stream, ref); |
17513 } | 17713 } |
17514 | 17714 |
17515 | 17715 |
17516 } // namespace dart | 17716 } // namespace dart |
OLD | NEW |