Chromium Code Reviews| 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 2329 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2340 void Class::set_type_parameters(const TypeArguments& value) const { | 2340 void Class::set_type_parameters(const TypeArguments& value) const { |
| 2341 StorePointer(&raw_ptr()->type_parameters_, value.raw()); | 2341 StorePointer(&raw_ptr()->type_parameters_, value.raw()); |
| 2342 } | 2342 } |
| 2343 | 2343 |
| 2344 | 2344 |
| 2345 intptr_t Class::NumTypeParameters(Thread* thread) const { | 2345 intptr_t Class::NumTypeParameters(Thread* thread) const { |
| 2346 if (IsMixinApplication() && !is_mixin_type_applied()) { | 2346 if (IsMixinApplication() && !is_mixin_type_applied()) { |
| 2347 ClassFinalizer::ApplyMixinType(*this); | 2347 ClassFinalizer::ApplyMixinType(*this); |
| 2348 } | 2348 } |
| 2349 if (type_parameters() == TypeArguments::null()) { | 2349 if (type_parameters() == TypeArguments::null()) { |
| 2350 const intptr_t cid = id(); | |
| 2351 if ((cid == kArrayCid) || | |
| 2352 (cid == kImmutableArrayCid) || | |
| 2353 (cid == kGrowableObjectArrayCid)) { | |
| 2354 return 1; // List's type parameter not yet parsed. | |
|
srdjan
2016/01/04 20:15:24
Should the comment say: List's type parameter may
regis
2016/01/05 11:24:51
Done.
| |
| 2355 } | |
| 2350 return 0; | 2356 return 0; |
| 2351 } | 2357 } |
| 2352 REUSABLE_TYPE_ARGUMENTS_HANDLESCOPE(thread); | 2358 REUSABLE_TYPE_ARGUMENTS_HANDLESCOPE(thread); |
| 2353 TypeArguments& type_params = thread->TypeArgumentsHandle(); | 2359 TypeArguments& type_params = thread->TypeArgumentsHandle(); |
| 2354 type_params = type_parameters(); | 2360 type_params = type_parameters(); |
| 2355 return type_params.Length(); | 2361 return type_params.Length(); |
| 2356 } | 2362 } |
| 2357 | 2363 |
| 2358 | 2364 |
| 2359 intptr_t Class::NumOwnTypeArguments() const { | 2365 intptr_t Class::NumOwnTypeArguments() const { |
| (...skipping 1263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3623 } | 3629 } |
| 3624 | 3630 |
| 3625 | 3631 |
| 3626 void Class::set_canonical_types(const Object& value) const { | 3632 void Class::set_canonical_types(const Object& value) const { |
| 3627 ASSERT(!value.IsNull()); | 3633 ASSERT(!value.IsNull()); |
| 3628 StorePointer(&raw_ptr()->canonical_types_, value.raw()); | 3634 StorePointer(&raw_ptr()->canonical_types_, value.raw()); |
| 3629 } | 3635 } |
| 3630 | 3636 |
| 3631 | 3637 |
| 3632 RawType* Class::CanonicalType() const { | 3638 RawType* Class::CanonicalType() const { |
| 3633 if (NumTypeArguments() == 0) { | 3639 if (!IsGeneric()) { |
| 3634 return reinterpret_cast<RawType*>(raw_ptr()->canonical_types_); | 3640 return reinterpret_cast<RawType*>(raw_ptr()->canonical_types_); |
| 3635 } | 3641 } |
| 3636 Array& types = Array::Handle(); | 3642 Array& types = Array::Handle(); |
| 3637 types ^= canonical_types(); | 3643 types ^= canonical_types(); |
| 3638 if (!types.IsNull() && (types.Length() > 0)) { | 3644 if (!types.IsNull() && (types.Length() > 0)) { |
| 3639 return reinterpret_cast<RawType*>(types.At(0)); | 3645 return reinterpret_cast<RawType*>(types.At(0)); |
| 3640 } | 3646 } |
| 3641 return reinterpret_cast<RawType*>(Object::null()); | 3647 return reinterpret_cast<RawType*>(Object::null()); |
| 3642 } | 3648 } |
| 3643 | 3649 |
| 3644 | 3650 |
| 3645 void Class::SetCanonicalType(const Type& type) const { | 3651 void Class::SetCanonicalType(const Type& type) const { |
| 3646 ASSERT(type.IsCanonical()); | 3652 ASSERT(type.IsCanonical()); |
| 3647 if (NumTypeArguments() == 0) { | 3653 if (!IsGeneric()) { |
| 3648 ASSERT((canonical_types() == Object::null()) || | 3654 ASSERT((canonical_types() == Object::null()) || |
| 3649 (canonical_types() == type.raw())); // Set during own finalization. | 3655 (canonical_types() == type.raw())); // Set during own finalization. |
| 3650 set_canonical_types(type); | 3656 set_canonical_types(type); |
| 3651 } else { | 3657 } else { |
| 3652 Array& types = Array::Handle(); | 3658 Array& types = Array::Handle(); |
| 3653 types ^= canonical_types(); | 3659 types ^= canonical_types(); |
| 3654 ASSERT(!types.IsNull() && (types.Length() > 1)); | 3660 ASSERT(!types.IsNull() && (types.Length() > 1)); |
| 3655 ASSERT((types.At(0) == Object::null()) || (types.At(0) == type.raw())); | 3661 ASSERT((types.At(0) == Object::null()) || (types.At(0) == type.raw())); |
| 3656 types.SetAt(0, type); | 3662 types.SetAt(0, type); |
| 3657 } | 3663 } |
| (...skipping 11288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 14946 return result.raw(); | 14952 return result.raw(); |
| 14947 } | 14953 } |
| 14948 | 14954 |
| 14949 | 14955 |
| 14950 RawType* Instance::GetType() const { | 14956 RawType* Instance::GetType() const { |
| 14951 if (IsNull()) { | 14957 if (IsNull()) { |
| 14952 return Type::NullType(); | 14958 return Type::NullType(); |
| 14953 } | 14959 } |
| 14954 const Class& cls = Class::Handle(clazz()); | 14960 const Class& cls = Class::Handle(clazz()); |
| 14955 Type& type = Type::Handle(); | 14961 Type& type = Type::Handle(); |
| 14956 if (cls.NumTypeArguments() == 0) { | 14962 if (!cls.IsGeneric()) { |
| 14957 type = cls.CanonicalType(); | 14963 type = cls.CanonicalType(); |
| 14958 } | 14964 } |
| 14959 if (type.IsNull()) { | 14965 if (type.IsNull()) { |
| 14960 TypeArguments& type_arguments = TypeArguments::Handle(); | 14966 TypeArguments& type_arguments = TypeArguments::Handle(); |
| 14961 if (cls.NumTypeArguments() > 0) { | 14967 if (cls.NumTypeArguments() > 0) { |
| 14962 type_arguments = GetTypeArguments(); | 14968 type_arguments = GetTypeArguments(); |
| 14963 } | 14969 } |
| 14964 type = Type::New(cls, type_arguments, Scanner::kNoSourcePos); | 14970 type = Type::New(cls, type_arguments, Scanner::kNoSourcePos); |
| 14965 type.SetIsFinalized(); | 14971 type.SetIsFinalized(); |
| 14966 type ^= type.Canonicalize(); | 14972 type ^= type.Canonicalize(); |
| (...skipping 897 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 15864 return Isolate::Current()->object_store()->array_type(); | 15870 return Isolate::Current()->object_store()->array_type(); |
| 15865 } | 15871 } |
| 15866 | 15872 |
| 15867 | 15873 |
| 15868 RawType* Type::Function() { | 15874 RawType* Type::Function() { |
| 15869 return Isolate::Current()->object_store()->function_type(); | 15875 return Isolate::Current()->object_store()->function_type(); |
| 15870 } | 15876 } |
| 15871 | 15877 |
| 15872 | 15878 |
| 15873 RawType* Type::NewNonParameterizedType(const Class& type_class) { | 15879 RawType* Type::NewNonParameterizedType(const Class& type_class) { |
| 15874 ASSERT(type_class.NumTypeArguments() == 0); | 15880 ASSERT(!type_class.IsGeneric()); // Super class may have type arguments. |
|
srdjan
2016/01/04 20:15:24
I do not understand this comment.
regis
2016/01/05 11:24:51
I reverted this change. A type may be non-paramete
| |
| 15875 Type& type = Type::Handle(type_class.CanonicalType()); | 15881 Type& type = Type::Handle(type_class.CanonicalType()); |
| 15876 if (type.IsNull()) { | 15882 if (type.IsNull()) { |
| 15877 const TypeArguments& no_type_arguments = TypeArguments::Handle(); | 15883 const TypeArguments& no_type_arguments = TypeArguments::Handle(); |
| 15878 type ^= Type::New(Object::Handle(type_class.raw()), | 15884 type ^= Type::New(Object::Handle(type_class.raw()), |
| 15879 no_type_arguments, | 15885 no_type_arguments, |
| 15880 Scanner::kNoSourcePos); | 15886 Scanner::kNoSourcePos); |
| 15881 type.SetIsFinalized(); | 15887 type.SetIsFinalized(); |
| 15882 type ^= type.Canonicalize(); | 15888 type ^= type.Canonicalize(); |
| 15883 } | 15889 } |
| 15884 ASSERT(type.IsFinalized()); | 15890 ASSERT(type.IsFinalized()); |
| (...skipping 322 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 16207 } | 16213 } |
| 16208 Thread* thread = Thread::Current(); | 16214 Thread* thread = Thread::Current(); |
| 16209 Zone* zone = thread->zone(); | 16215 Zone* zone = thread->zone(); |
| 16210 Isolate* isolate = thread->isolate(); | 16216 Isolate* isolate = thread->isolate(); |
| 16211 Type& type = Type::Handle(zone); | 16217 Type& type = Type::Handle(zone); |
| 16212 const Class& cls = Class::Handle(zone, type_class()); | 16218 const Class& cls = Class::Handle(zone, type_class()); |
| 16213 if (cls.raw() == Object::dynamic_class() && (isolate != Dart::vm_isolate())) { | 16219 if (cls.raw() == Object::dynamic_class() && (isolate != Dart::vm_isolate())) { |
| 16214 return Object::dynamic_type().raw(); | 16220 return Object::dynamic_type().raw(); |
| 16215 } | 16221 } |
| 16216 // Fast canonical lookup/registry for simple types. | 16222 // Fast canonical lookup/registry for simple types. |
| 16217 if (cls.NumTypeArguments() == 0) { | 16223 if (!cls.IsGeneric()) { |
| 16218 type = cls.CanonicalType(); | 16224 type = cls.CanonicalType(); |
| 16219 if (type.IsNull()) { | 16225 if (type.IsNull()) { |
| 16220 ASSERT(!cls.raw()->IsVMHeapObject() || (isolate == Dart::vm_isolate())); | 16226 ASSERT(!cls.raw()->IsVMHeapObject() || (isolate == Dart::vm_isolate())); |
| 16221 cls.set_canonical_types(*this); | 16227 // Canonicalize the type arguments of the supertype, if any. |
| 16222 SetCanonical(); | 16228 TypeArguments& type_args = TypeArguments::Handle(zone, arguments()); |
| 16223 return this->raw(); | 16229 type_args = type_args.Canonicalize(trail); |
| 16230 set_arguments(type_args); | |
| 16231 type = cls.CanonicalType(); // May be set while canonicalizing type args. | |
| 16232 if (type.IsNull()) { | |
| 16233 cls.set_canonical_types(*this); | |
| 16234 SetCanonical(); | |
| 16235 return this->raw(); | |
| 16236 } | |
| 16224 } | 16237 } |
| 16225 ASSERT(this->Equals(type)); | 16238 ASSERT(this->Equals(type)); |
| 16226 ASSERT(type.IsCanonical()); | 16239 ASSERT(type.IsCanonical()); |
| 16227 return type.raw(); | 16240 return type.raw(); |
| 16228 } | 16241 } |
| 16229 | 16242 |
| 16230 Array& canonical_types = Array::Handle(zone); | 16243 Array& canonical_types = Array::Handle(zone); |
| 16231 canonical_types ^= cls.canonical_types(); | 16244 canonical_types ^= cls.canonical_types(); |
| 16232 if (canonical_types.IsNull()) { | 16245 if (canonical_types.IsNull()) { |
| 16233 canonical_types = empty_array().raw(); | 16246 canonical_types = empty_array().raw(); |
| (...skipping 5790 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 22024 return tag_label.ToCString(); | 22037 return tag_label.ToCString(); |
| 22025 } | 22038 } |
| 22026 | 22039 |
| 22027 | 22040 |
| 22028 void UserTag::PrintJSONImpl(JSONStream* stream, bool ref) const { | 22041 void UserTag::PrintJSONImpl(JSONStream* stream, bool ref) const { |
| 22029 Instance::PrintJSONImpl(stream, ref); | 22042 Instance::PrintJSONImpl(stream, ref); |
| 22030 } | 22043 } |
| 22031 | 22044 |
| 22032 | 22045 |
| 22033 } // namespace dart | 22046 } // namespace dart |
| OLD | NEW |