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/become.h" | 10 #include "vm/become.h" |
| (...skipping 2465 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2476 | 2476 |
| 2477 | 2477 |
| 2478 void Class::set_super_type(const AbstractType& value) const { | 2478 void Class::set_super_type(const AbstractType& value) const { |
| 2479 ASSERT(value.IsNull() || | 2479 ASSERT(value.IsNull() || |
| 2480 (value.IsType() && !value.IsDynamicType()) || | 2480 (value.IsType() && !value.IsDynamicType()) || |
| 2481 value.IsMixinAppType()); | 2481 value.IsMixinAppType()); |
| 2482 StorePointer(&raw_ptr()->super_type_, value.raw()); | 2482 StorePointer(&raw_ptr()->super_type_, value.raw()); |
| 2483 } | 2483 } |
| 2484 | 2484 |
| 2485 | 2485 |
| 2486 // Return a TypeParameter if the type_name is a type parameter of this class. | |
| 2487 // Return null otherwise. | |
| 2488 RawTypeParameter* Class::LookupTypeParameter(const String& type_name) const { | 2486 RawTypeParameter* Class::LookupTypeParameter(const String& type_name) const { |
| 2489 ASSERT(!type_name.IsNull()); | 2487 ASSERT(!type_name.IsNull()); |
| 2490 Thread* thread = Thread::Current(); | 2488 Thread* thread = Thread::Current(); |
| 2491 REUSABLE_TYPE_ARGUMENTS_HANDLESCOPE(thread); | 2489 REUSABLE_TYPE_ARGUMENTS_HANDLESCOPE(thread); |
| 2492 REUSABLE_TYPE_PARAMETER_HANDLESCOPE(thread); | 2490 REUSABLE_TYPE_PARAMETER_HANDLESCOPE(thread); |
| 2493 REUSABLE_STRING_HANDLESCOPE(thread); | 2491 REUSABLE_STRING_HANDLESCOPE(thread); |
| 2494 TypeArguments& type_params = thread->TypeArgumentsHandle(); | 2492 TypeArguments& type_params = thread->TypeArgumentsHandle(); |
| 2495 TypeParameter& type_param = thread->TypeParameterHandle(); | 2493 TypeParameter& type_param = thread->TypeParameterHandle(); |
| 2496 String& type_param_name = thread->StringHandle(); | 2494 String& type_param_name = thread->StringHandle(); |
| 2497 | 2495 |
| (...skipping 2998 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 5496 return Field::null(); | 5494 return Field::null(); |
| 5497 } | 5495 } |
| 5498 | 5496 |
| 5499 | 5497 |
| 5500 | 5498 |
| 5501 RawFunction* Function::parent_function() const { | 5499 RawFunction* Function::parent_function() const { |
| 5502 if (IsClosureFunction()) { | 5500 if (IsClosureFunction()) { |
| 5503 const Object& obj = Object::Handle(raw_ptr()->data_); | 5501 const Object& obj = Object::Handle(raw_ptr()->data_); |
| 5504 ASSERT(!obj.IsNull()); | 5502 ASSERT(!obj.IsNull()); |
| 5505 return ClosureData::Cast(obj).parent_function(); | 5503 return ClosureData::Cast(obj).parent_function(); |
| 5504 } else if (IsSignatureFunction()) { | |
| 5505 const Object& obj = Object::Handle(raw_ptr()->data_); | |
| 5506 // Parent function may be null or data_ may already be set to function type. | |
| 5507 if (!obj.IsNull() && obj.IsFunction()) { | |
| 5508 return Function::Cast(obj).raw(); | |
| 5509 } | |
| 5506 } | 5510 } |
| 5507 return Function::null(); | 5511 return Function::null(); |
| 5508 } | 5512 } |
| 5509 | 5513 |
| 5510 | 5514 |
| 5511 void Function::set_parent_function(const Function& value) const { | 5515 void Function::set_parent_function(const Function& value) const { |
| 5512 if (IsClosureFunction()) { | 5516 if (IsClosureFunction()) { |
| 5513 const Object& obj = Object::Handle(raw_ptr()->data_); | 5517 const Object& obj = Object::Handle(raw_ptr()->data_); |
| 5514 ASSERT(!obj.IsNull()); | 5518 ASSERT(!obj.IsNull()); |
| 5515 ClosureData::Cast(obj).set_parent_function(value); | 5519 ClosureData::Cast(obj).set_parent_function(value); |
| 5516 return; | 5520 return; |
| 5521 } else if (IsSignatureFunction()) { | |
| 5522 set_data(value); // Temporarily set during parsing only. | |
| 5523 return; | |
| 5517 } | 5524 } |
| 5518 UNREACHABLE(); | 5525 UNREACHABLE(); |
| 5519 } | 5526 } |
| 5520 | 5527 |
| 5521 | 5528 |
| 5522 RawFunction* Function::implicit_closure_function() const { | 5529 RawFunction* Function::implicit_closure_function() const { |
| 5523 if (IsClosureFunction() || | 5530 if (IsClosureFunction() || |
| 5524 IsSignatureFunction() || | 5531 IsSignatureFunction() || |
| 5525 IsFactory()) { | 5532 IsFactory()) { |
| 5526 return Function::null(); | 5533 return Function::null(); |
| (...skipping 327 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 5854 const Array& parameter_names = Array::Handle(raw_ptr()->parameter_names_); | 5861 const Array& parameter_names = Array::Handle(raw_ptr()->parameter_names_); |
| 5855 parameter_names.SetAt(index, value); | 5862 parameter_names.SetAt(index, value); |
| 5856 } | 5863 } |
| 5857 | 5864 |
| 5858 | 5865 |
| 5859 void Function::set_parameter_names(const Array& value) const { | 5866 void Function::set_parameter_names(const Array& value) const { |
| 5860 StorePointer(&raw_ptr()->parameter_names_, value.raw()); | 5867 StorePointer(&raw_ptr()->parameter_names_, value.raw()); |
| 5861 } | 5868 } |
| 5862 | 5869 |
| 5863 | 5870 |
| 5871 void Function::set_type_parameters(const TypeArguments& value) const { | |
| 5872 StorePointer(&raw_ptr()->type_parameters_, value.raw()); | |
| 5873 } | |
| 5874 | |
| 5875 | |
| 5876 intptr_t Function::NumTypeParameters(Thread* thread) const { | |
| 5877 if (type_parameters() == TypeArguments::null()) { | |
| 5878 return 0; | |
| 5879 } | |
| 5880 REUSABLE_TYPE_ARGUMENTS_HANDLESCOPE(thread); | |
| 5881 TypeArguments& type_params = thread->TypeArgumentsHandle(); | |
| 5882 type_params = type_parameters(); | |
| 5883 return type_params.Length(); | |
| 5884 } | |
| 5885 | |
| 5886 | |
| 5887 RawTypeParameter* Function::LookupTypeParameter( | |
| 5888 const String& type_name, intptr_t* function_level) const { | |
| 5889 ASSERT(!type_name.IsNull()); | |
| 5890 Thread* thread = Thread::Current(); | |
| 5891 REUSABLE_TYPE_ARGUMENTS_HANDLESCOPE(thread); | |
| 5892 REUSABLE_TYPE_PARAMETER_HANDLESCOPE(thread); | |
| 5893 REUSABLE_STRING_HANDLESCOPE(thread); | |
| 5894 TypeArguments& type_params = thread->TypeArgumentsHandle(); | |
| 5895 TypeParameter& type_param = thread->TypeParameterHandle(); | |
| 5896 String& type_param_name = thread->StringHandle(); | |
| 5897 Function& function = thread->FunctionHandle(); | |
|
siva
2016/09/19 23:23:46
REUSABLE_FUNCTION_HANDLESCOPE(thread);
needed her
regis
2016/09/23 00:35:23
Done.
| |
| 5898 | |
| 5899 function ^= this->raw(); | |
| 5900 intptr_t parent_level = -1; | |
| 5901 while (!function.IsNull()) { | |
| 5902 type_params ^= function.type_parameters(); | |
| 5903 if (!type_params.IsNull()) { | |
| 5904 parent_level++; | |
| 5905 const intptr_t num_type_params = type_params.Length(); | |
| 5906 for (intptr_t i = 0; i < num_type_params; i++) { | |
| 5907 type_param ^= type_params.TypeAt(i); | |
| 5908 type_param_name = type_param.name(); | |
| 5909 if (type_param_name.Equals(type_name)) { | |
| 5910 if (parent_level > 0) { | |
| 5911 // TODO(regis): Clone type parameter and set parent_level. | |
| 5912 } | |
| 5913 return type_param.raw(); | |
| 5914 } | |
| 5915 } | |
| 5916 } | |
| 5917 function ^= function.parent_function(); | |
| 5918 if (function_level != NULL) { | |
| 5919 (*function_level)--; | |
| 5920 } | |
| 5921 } | |
| 5922 return TypeParameter::null(); | |
| 5923 } | |
| 5924 | |
| 5925 | |
| 5864 void Function::set_kind(RawFunction::Kind value) const { | 5926 void Function::set_kind(RawFunction::Kind value) const { |
| 5865 set_kind_tag(KindBits::update(value, raw_ptr()->kind_tag_)); | 5927 set_kind_tag(KindBits::update(value, raw_ptr()->kind_tag_)); |
| 5866 } | 5928 } |
| 5867 | 5929 |
| 5868 | 5930 |
| 5869 void Function::set_modifier(RawFunction::AsyncModifier value) const { | 5931 void Function::set_modifier(RawFunction::AsyncModifier value) const { |
| 5870 set_kind_tag(ModifierBits::update(value, raw_ptr()->kind_tag_)); | 5932 set_kind_tag(ModifierBits::update(value, raw_ptr()->kind_tag_)); |
| 5871 } | 5933 } |
| 5872 | 5934 |
| 5873 | 5935 |
| (...skipping 11827 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 17701 | 17763 |
| 17702 RawClass* TypeParameter::parameterized_class() const { | 17764 RawClass* TypeParameter::parameterized_class() const { |
| 17703 classid_t cid = parameterized_class_id(); | 17765 classid_t cid = parameterized_class_id(); |
| 17704 if (cid == kIllegalCid) { | 17766 if (cid == kIllegalCid) { |
| 17705 return Class::null(); | 17767 return Class::null(); |
| 17706 } | 17768 } |
| 17707 return Isolate::Current()->class_table()->At(cid); | 17769 return Isolate::Current()->class_table()->At(cid); |
| 17708 } | 17770 } |
| 17709 | 17771 |
| 17710 | 17772 |
| 17773 void TypeParameter::set_parameterized_function(const Function& value) const { | |
| 17774 StorePointer(&raw_ptr()->parameterized_function_, value.raw()); | |
| 17775 } | |
| 17776 | |
| 17777 | |
| 17711 void TypeParameter::set_index(intptr_t value) const { | 17778 void TypeParameter::set_index(intptr_t value) const { |
| 17712 ASSERT(value >= 0); | 17779 ASSERT(value >= 0); |
| 17713 ASSERT(Utils::IsInt(16, value)); | 17780 ASSERT(Utils::IsInt(16, value)); |
| 17714 StoreNonPointer(&raw_ptr()->index_, value); | 17781 StoreNonPointer(&raw_ptr()->index_, value); |
| 17715 } | 17782 } |
| 17716 | 17783 |
| 17717 | 17784 |
| 17718 void TypeParameter::set_name(const String& value) const { | 17785 void TypeParameter::set_name(const String& value) const { |
| 17719 ASSERT(value.IsSymbol()); | 17786 ASSERT(value.IsSymbol()); |
| 17720 StorePointer(&raw_ptr()->name_, value.raw()); | 17787 StorePointer(&raw_ptr()->name_, value.raw()); |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 17811 return false; | 17878 return false; |
| 17812 } | 17879 } |
| 17813 | 17880 |
| 17814 | 17881 |
| 17815 RawAbstractType* TypeParameter::CloneUnfinalized() const { | 17882 RawAbstractType* TypeParameter::CloneUnfinalized() const { |
| 17816 if (IsFinalized()) { | 17883 if (IsFinalized()) { |
| 17817 return raw(); | 17884 return raw(); |
| 17818 } | 17885 } |
| 17819 // No need to clone bound, as it is not part of the finalization state. | 17886 // No need to clone bound, as it is not part of the finalization state. |
| 17820 return TypeParameter::New(Class::Handle(parameterized_class()), | 17887 return TypeParameter::New(Class::Handle(parameterized_class()), |
| 17888 Function::Handle(parameterized_function()), | |
| 17821 index(), | 17889 index(), |
| 17822 String::Handle(name()), | 17890 String::Handle(name()), |
| 17823 AbstractType::Handle(bound()), | 17891 AbstractType::Handle(bound()), |
| 17824 token_pos()); | 17892 token_pos()); |
| 17825 } | 17893 } |
| 17826 | 17894 |
| 17827 | 17895 |
| 17828 RawAbstractType* TypeParameter::CloneUninstantiated( | 17896 RawAbstractType* TypeParameter::CloneUninstantiated( |
| 17829 const Class& new_owner, TrailPtr trail) const { | 17897 const Class& new_owner, TrailPtr trail) const { |
| 17830 ASSERT(IsFinalized()); | 17898 ASSERT(IsFinalized()); |
| 17831 TypeParameter& clone = TypeParameter::Handle(); | 17899 TypeParameter& clone = TypeParameter::Handle(); |
| 17832 clone ^= OnlyBuddyInTrail(trail); | 17900 clone ^= OnlyBuddyInTrail(trail); |
| 17833 if (!clone.IsNull()) { | 17901 if (!clone.IsNull()) { |
| 17834 return clone.raw(); | 17902 return clone.raw(); |
| 17835 } | 17903 } |
| 17836 const Class& old_owner = Class::Handle(parameterized_class()); | 17904 const Class& old_owner = Class::Handle(parameterized_class()); |
| 17837 const intptr_t new_index = index() + | 17905 const intptr_t new_index = index() + |
| 17838 new_owner.NumTypeArguments() - old_owner.NumTypeArguments(); | 17906 new_owner.NumTypeArguments() - old_owner.NumTypeArguments(); |
| 17839 AbstractType& upper_bound = AbstractType::Handle(bound()); | 17907 AbstractType& upper_bound = AbstractType::Handle(bound()); |
| 17908 ASSERT(parameterized_function() == Function::null()); | |
| 17840 clone = TypeParameter::New(new_owner, | 17909 clone = TypeParameter::New(new_owner, |
| 17910 Function::Handle(), | |
| 17841 new_index, | 17911 new_index, |
| 17842 String::Handle(name()), | 17912 String::Handle(name()), |
| 17843 upper_bound, // Not cloned yet. | 17913 upper_bound, // Not cloned yet. |
| 17844 token_pos()); | 17914 token_pos()); |
| 17845 clone.SetIsFinalized(); | 17915 clone.SetIsFinalized(); |
| 17846 AddOnlyBuddyToTrail(&trail, clone); | 17916 AddOnlyBuddyToTrail(&trail, clone); |
| 17847 upper_bound = upper_bound.CloneUninstantiated(new_owner, trail); | 17917 upper_bound = upper_bound.CloneUninstantiated(new_owner, trail); |
| 17848 clone.set_bound(upper_bound); | 17918 clone.set_bound(upper_bound); |
| 17849 return clone.raw(); | 17919 return clone.raw(); |
| 17850 } | 17920 } |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 17881 | 17951 |
| 17882 RawTypeParameter* TypeParameter::New() { | 17952 RawTypeParameter* TypeParameter::New() { |
| 17883 RawObject* raw = Object::Allocate(TypeParameter::kClassId, | 17953 RawObject* raw = Object::Allocate(TypeParameter::kClassId, |
| 17884 TypeParameter::InstanceSize(), | 17954 TypeParameter::InstanceSize(), |
| 17885 Heap::kOld); | 17955 Heap::kOld); |
| 17886 return reinterpret_cast<RawTypeParameter*>(raw); | 17956 return reinterpret_cast<RawTypeParameter*>(raw); |
| 17887 } | 17957 } |
| 17888 | 17958 |
| 17889 | 17959 |
| 17890 RawTypeParameter* TypeParameter::New(const Class& parameterized_class, | 17960 RawTypeParameter* TypeParameter::New(const Class& parameterized_class, |
| 17961 const Function& parameterized_function, | |
| 17891 intptr_t index, | 17962 intptr_t index, |
| 17892 const String& name, | 17963 const String& name, |
| 17893 const AbstractType& bound, | 17964 const AbstractType& bound, |
| 17894 TokenPosition token_pos) { | 17965 TokenPosition token_pos) { |
| 17966 ASSERT(parameterized_class.IsNull() != parameterized_function.IsNull()); | |
| 17895 const TypeParameter& result = TypeParameter::Handle(TypeParameter::New()); | 17967 const TypeParameter& result = TypeParameter::Handle(TypeParameter::New()); |
| 17896 result.set_parameterized_class(parameterized_class); | 17968 result.set_parameterized_class(parameterized_class); |
| 17969 result.set_parameterized_function(parameterized_function); | |
| 17897 result.set_index(index); | 17970 result.set_index(index); |
| 17898 result.set_name(name); | 17971 result.set_name(name); |
| 17899 result.set_bound(bound); | 17972 result.set_bound(bound); |
| 17900 result.SetHash(0); | 17973 result.SetHash(0); |
| 17901 result.set_token_pos(token_pos); | 17974 result.set_token_pos(token_pos); |
| 17902 result.StoreNonPointer(&result.raw_ptr()->type_state_, | 17975 result.StoreNonPointer(&result.raw_ptr()->type_state_, |
| 17903 RawTypeParameter::kAllocated); | 17976 RawTypeParameter::kAllocated); |
| 17904 return result.raw(); | 17977 return result.raw(); |
| 17905 } | 17978 } |
| 17906 | 17979 |
| (...skipping 4972 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 22879 return UserTag::null(); | 22952 return UserTag::null(); |
| 22880 } | 22953 } |
| 22881 | 22954 |
| 22882 | 22955 |
| 22883 const char* UserTag::ToCString() const { | 22956 const char* UserTag::ToCString() const { |
| 22884 const String& tag_label = String::Handle(label()); | 22957 const String& tag_label = String::Handle(label()); |
| 22885 return tag_label.ToCString(); | 22958 return tag_label.ToCString(); |
| 22886 } | 22959 } |
| 22887 | 22960 |
| 22888 } // namespace dart | 22961 } // namespace dart |
| OLD | NEW |