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/become.h" | 10 #include "vm/become.h" |
(...skipping 1414 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1425 RegisterPrivateClass(cls, Symbols::_Bigint(), core_lib); | 1425 RegisterPrivateClass(cls, Symbols::_Bigint(), core_lib); |
1426 pending_classes.Add(cls); | 1426 pending_classes.Add(cls); |
1427 | 1427 |
1428 cls = Class::New<Double>(); | 1428 cls = Class::New<Double>(); |
1429 object_store->set_double_class(cls); | 1429 object_store->set_double_class(cls); |
1430 RegisterPrivateClass(cls, Symbols::_Double(), core_lib); | 1430 RegisterPrivateClass(cls, Symbols::_Double(), core_lib); |
1431 pending_classes.Add(cls); | 1431 pending_classes.Add(cls); |
1432 | 1432 |
1433 // Class that represents the Dart class _Closure and C++ class Closure. | 1433 // Class that represents the Dart class _Closure and C++ class Closure. |
1434 cls = Class::New<Closure>(); | 1434 cls = Class::New<Closure>(); |
1435 cls.set_type_arguments_field_offset(Closure::type_arguments_offset()); | 1435 object_store->set_closure_class(cls); |
1436 cls.set_num_type_arguments(0); // Although a closure has type_arguments_. | 1436 cls.ResetFinalization(); // To calculate field offsets from Dart source. |
1437 cls.set_num_own_type_arguments(0); | |
1438 RegisterPrivateClass(cls, Symbols::_Closure(), core_lib); | 1437 RegisterPrivateClass(cls, Symbols::_Closure(), core_lib); |
1439 pending_classes.Add(cls); | 1438 pending_classes.Add(cls); |
1440 object_store->set_closure_class(cls); | |
1441 | 1439 |
1442 cls = Class::New<WeakProperty>(); | 1440 cls = Class::New<WeakProperty>(); |
1443 object_store->set_weak_property_class(cls); | 1441 object_store->set_weak_property_class(cls); |
1444 RegisterPrivateClass(cls, Symbols::_WeakProperty(), core_lib); | 1442 RegisterPrivateClass(cls, Symbols::_WeakProperty(), core_lib); |
1445 | 1443 |
1446 // Pre-register the mirrors library so we can place the vm class | 1444 // Pre-register the mirrors library so we can place the vm class |
1447 // MirrorReference there rather than the core library. | 1445 // MirrorReference there rather than the core library. |
1448 #if !defined(PRODUCT) | 1446 #if !defined(PRODUCT) |
1449 lib = Library::LookupLibrary(thread, Symbols::DartMirrors()); | 1447 lib = Library::LookupLibrary(thread, Symbols::DartMirrors()); |
1450 if (lib.IsNull()) { | 1448 if (lib.IsNull()) { |
(...skipping 1072 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2523 if (type_param_name.Equals(type_name)) { | 2521 if (type_param_name.Equals(type_name)) { |
2524 return type_param.raw(); | 2522 return type_param.raw(); |
2525 } | 2523 } |
2526 } | 2524 } |
2527 } | 2525 } |
2528 return TypeParameter::null(); | 2526 return TypeParameter::null(); |
2529 } | 2527 } |
2530 | 2528 |
2531 | 2529 |
2532 void Class::CalculateFieldOffsets() const { | 2530 void Class::CalculateFieldOffsets() const { |
2533 ASSERT(id() != kClosureCid); // Class _Closure is prefinalized. | |
2534 Array& flds = Array::Handle(fields()); | 2531 Array& flds = Array::Handle(fields()); |
2535 const Class& super = Class::Handle(SuperClass()); | 2532 const Class& super = Class::Handle(SuperClass()); |
2536 intptr_t offset = 0; | 2533 intptr_t offset = 0; |
2537 intptr_t type_args_field_offset = kNoTypeArguments; | 2534 intptr_t type_args_field_offset = kNoTypeArguments; |
2538 if (super.IsNull()) { | 2535 if (super.IsNull()) { |
2539 offset = Instance::NextFieldOffset(); | 2536 offset = Instance::NextFieldOffset(); |
2540 ASSERT(offset > 0); | 2537 ASSERT(offset > 0); |
2541 } else { | 2538 } else { |
2542 ASSERT(super.is_finalized() || super.is_prefinalized()); | 2539 ASSERT(super.is_finalized() || super.is_prefinalized()); |
2543 type_args_field_offset = super.type_arguments_field_offset(); | 2540 type_args_field_offset = super.type_arguments_field_offset(); |
(...skipping 1083 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3627 | 3624 |
3628 void Class::SetRefinalizeAfterPatch() const { | 3625 void Class::SetRefinalizeAfterPatch() const { |
3629 ASSERT(!IsTopLevel()); | 3626 ASSERT(!IsTopLevel()); |
3630 set_state_bits(ClassFinalizedBits::update(RawClass::kRefinalizeAfterPatch, | 3627 set_state_bits(ClassFinalizedBits::update(RawClass::kRefinalizeAfterPatch, |
3631 raw_ptr()->state_bits_)); | 3628 raw_ptr()->state_bits_)); |
3632 set_state_bits(TypeFinalizedBit::update(false, raw_ptr()->state_bits_)); | 3629 set_state_bits(TypeFinalizedBit::update(false, raw_ptr()->state_bits_)); |
3633 } | 3630 } |
3634 | 3631 |
3635 | 3632 |
3636 void Class::ResetFinalization() const { | 3633 void Class::ResetFinalization() const { |
3637 ASSERT(IsTopLevel()); | 3634 ASSERT(IsTopLevel() || IsClosureClass()); |
3638 set_state_bits( | 3635 set_state_bits( |
3639 ClassFinalizedBits::update(RawClass::kAllocated, raw_ptr()->state_bits_)); | 3636 ClassFinalizedBits::update(RawClass::kAllocated, raw_ptr()->state_bits_)); |
3640 set_state_bits(TypeFinalizedBit::update(false, raw_ptr()->state_bits_)); | 3637 set_state_bits(TypeFinalizedBit::update(false, raw_ptr()->state_bits_)); |
3641 } | 3638 } |
3642 | 3639 |
3643 | 3640 |
3644 void Class::set_is_prefinalized() const { | 3641 void Class::set_is_prefinalized() const { |
3645 ASSERT(!is_finalized()); | 3642 ASSERT(!is_finalized()); |
3646 set_state_bits(ClassFinalizedBits::update(RawClass::kPreFinalized, | 3643 set_state_bits(ClassFinalizedBits::update(RawClass::kPreFinalized, |
3647 raw_ptr()->state_bits_)); | 3644 raw_ptr()->state_bits_)); |
(...skipping 11915 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
15563 if (type.type_class() == cls.raw()) { | 15560 if (type.type_class() == cls.raw()) { |
15564 // Type is not parameterized. | 15561 // Type is not parameterized. |
15565 if (!type.IsCanonical()) { | 15562 if (!type.IsCanonical()) { |
15566 type ^= type.Canonicalize(); | 15563 type ^= type.Canonicalize(); |
15567 signature.SetSignatureType(type); | 15564 signature.SetSignatureType(type); |
15568 } | 15565 } |
15569 return type.raw(); | 15566 return type.raw(); |
15570 } | 15567 } |
15571 const Class& scope_cls = Class::Handle(type.type_class()); | 15568 const Class& scope_cls = Class::Handle(type.type_class()); |
15572 ASSERT(scope_cls.NumTypeArguments() > 0); | 15569 ASSERT(scope_cls.NumTypeArguments() > 0); |
15573 TypeArguments& type_arguments = TypeArguments::Handle(GetTypeArguments()); | 15570 TypeArguments& type_arguments = |
| 15571 TypeArguments::Handle(Closure::Cast(*this).instantiator()); |
15574 type = | 15572 type = |
15575 Type::New(scope_cls, type_arguments, TokenPosition::kNoSource, space); | 15573 Type::New(scope_cls, type_arguments, TokenPosition::kNoSource, space); |
15576 type.set_signature(signature); | 15574 type.set_signature(signature); |
15577 type.SetIsFinalized(); | 15575 type.SetIsFinalized(); |
15578 type ^= type.Canonicalize(); | 15576 type ^= type.Canonicalize(); |
15579 return type.raw(); | 15577 return type.raw(); |
15580 } | 15578 } |
15581 Type& type = Type::Handle(); | 15579 Type& type = Type::Handle(); |
15582 if (!cls.IsGeneric()) { | 15580 if (!cls.IsGeneric()) { |
15583 type = cls.CanonicalType(); | 15581 type = cls.CanonicalType(); |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
15659 } else { | 15657 } else { |
15660 if (!other.IsFunctionType()) { | 15658 if (!other.IsFunctionType()) { |
15661 return false; | 15659 return false; |
15662 } | 15660 } |
15663 other_signature = Type::Cast(other).signature(); | 15661 other_signature = Type::Cast(other).signature(); |
15664 other_type_arguments = other.arguments(); | 15662 other_type_arguments = other.arguments(); |
15665 } | 15663 } |
15666 const Function& signature = | 15664 const Function& signature = |
15667 Function::Handle(zone, Closure::Cast(*this).function()); | 15665 Function::Handle(zone, Closure::Cast(*this).function()); |
15668 const TypeArguments& type_arguments = | 15666 const TypeArguments& type_arguments = |
15669 TypeArguments::Handle(zone, GetTypeArguments()); | 15667 TypeArguments::Handle(zone, Closure::Cast(*this).instantiator()); |
15670 // TODO(regis): If signature function is generic, pass its type parameters | 15668 // TODO(regis): If signature function is generic, pass its type parameters |
15671 // as function instantiator, otherwise pass null. | 15669 // as function instantiator, otherwise pass null. |
15672 // Pass the closure context as well to the the IsSubtypeOf call. | 15670 // Pass the closure context as well to the the IsSubtypeOf call. |
15673 return signature.IsSubtypeOf(type_arguments, other_signature, | 15671 return signature.IsSubtypeOf(type_arguments, other_signature, |
15674 other_type_arguments, bound_error, Heap::kOld); | 15672 other_type_arguments, bound_error, Heap::kOld); |
15675 } | 15673 } |
15676 TypeArguments& type_arguments = TypeArguments::Handle(zone); | 15674 TypeArguments& type_arguments = TypeArguments::Handle(zone); |
15677 if (cls.NumTypeArguments() > 0) { | 15675 if (cls.NumTypeArguments() > 0) { |
15678 type_arguments = GetTypeArguments(); | 15676 type_arguments = GetTypeArguments(); |
15679 ASSERT(type_arguments.IsNull() || type_arguments.IsCanonical()); | 15677 ASSERT(type_arguments.IsNull() || type_arguments.IsCanonical()); |
(...skipping 7226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
22906 return UserTag::null(); | 22904 return UserTag::null(); |
22907 } | 22905 } |
22908 | 22906 |
22909 | 22907 |
22910 const char* UserTag::ToCString() const { | 22908 const char* UserTag::ToCString() const { |
22911 const String& tag_label = String::Handle(label()); | 22909 const String& tag_label = String::Handle(label()); |
22912 return tag_label.ToCString(); | 22910 return tag_label.ToCString(); |
22913 } | 22911 } |
22914 | 22912 |
22915 } // namespace dart | 22913 } // namespace dart |
OLD | NEW |