| 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 4937 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4948 for (intptr_t i = 0; i < num_types; i++) { | 4948 for (intptr_t i = 0; i < num_types; i++) { |
| 4949 type = TypeAt(i); | 4949 type = TypeAt(i); |
| 4950 type = type.CloneUnfinalized(); | 4950 type = type.CloneUnfinalized(); |
| 4951 clone.SetTypeAt(i, type); | 4951 clone.SetTypeAt(i, type); |
| 4952 } | 4952 } |
| 4953 ASSERT(clone.IsResolved()); | 4953 ASSERT(clone.IsResolved()); |
| 4954 return clone.raw(); | 4954 return clone.raw(); |
| 4955 } | 4955 } |
| 4956 | 4956 |
| 4957 | 4957 |
| 4958 RawTypeArguments* TypeArguments::CloneUninstantiated( | |
| 4959 const Class& new_owner) const { | |
| 4960 ASSERT(!IsNull()); | |
| 4961 ASSERT(IsFinalized()); | |
| 4962 ASSERT(!IsInstantiated()); | |
| 4963 AbstractType& type = AbstractType::Handle(); | |
| 4964 const intptr_t num_types = Length(); | |
| 4965 const TypeArguments& clone = TypeArguments::Handle( | |
| 4966 TypeArguments::New(num_types)); | |
| 4967 for (intptr_t i = 0; i < num_types; i++) { | |
| 4968 type = TypeAt(i); | |
| 4969 if (!type.IsInstantiated()) { | |
| 4970 type = type.CloneUninstantiated(new_owner); | |
| 4971 } | |
| 4972 clone.SetTypeAt(i, type); | |
| 4973 } | |
| 4974 ASSERT(clone.IsFinalized()); | |
| 4975 return clone.raw(); | |
| 4976 } | |
| 4977 | |
| 4978 | |
| 4979 RawTypeArguments* TypeArguments::Canonicalize( | 4958 RawTypeArguments* TypeArguments::Canonicalize( |
| 4980 GrowableObjectArray* trail) const { | 4959 GrowableObjectArray* trail) const { |
| 4981 if (IsNull() || IsCanonical()) { | 4960 if (IsNull() || IsCanonical()) { |
| 4982 ASSERT(IsOld()); | 4961 ASSERT(IsOld()); |
| 4983 return this->raw(); | 4962 return this->raw(); |
| 4984 } | 4963 } |
| 4985 const intptr_t num_types = Length(); | 4964 const intptr_t num_types = Length(); |
| 4986 if (IsRaw(0, num_types)) { | 4965 if (IsRaw(0, num_types)) { |
| 4987 return TypeArguments::null(); | 4966 return TypeArguments::null(); |
| 4988 } | 4967 } |
| (...skipping 1180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6169 const Class& origin = Class::Handle(this->origin()); | 6148 const Class& origin = Class::Handle(this->origin()); |
| 6170 const PatchClass& clone_owner = | 6149 const PatchClass& clone_owner = |
| 6171 PatchClass::Handle(PatchClass::New(new_owner, origin)); | 6150 PatchClass::Handle(PatchClass::New(new_owner, origin)); |
| 6172 clone.set_owner(clone_owner); | 6151 clone.set_owner(clone_owner); |
| 6173 clone.ClearCode(); | 6152 clone.ClearCode(); |
| 6174 clone.set_usage_counter(0); | 6153 clone.set_usage_counter(0); |
| 6175 clone.set_deoptimization_counter(0); | 6154 clone.set_deoptimization_counter(0); |
| 6176 clone.set_optimized_instruction_count(0); | 6155 clone.set_optimized_instruction_count(0); |
| 6177 clone.set_optimized_call_site_count(0); | 6156 clone.set_optimized_call_site_count(0); |
| 6178 clone.set_ic_data_array(Array::Handle()); | 6157 clone.set_ic_data_array(Array::Handle()); |
| 6179 // Adjust uninstantiated types to refer to type parameters of the new owner. | |
| 6180 AbstractType& type = AbstractType::Handle(clone.result_type()); | |
| 6181 type ^= type.CloneUninstantiated(new_owner); | |
| 6182 clone.set_result_type(type); | |
| 6183 const intptr_t num_params = clone.NumParameters(); | |
| 6184 for (intptr_t i = 0; i < num_params; i++) { | |
| 6185 type = clone.ParameterTypeAt(i); | |
| 6186 type ^= type.CloneUninstantiated(new_owner); | |
| 6187 clone.SetParameterTypeAt(i, type); | |
| 6188 } | |
| 6189 return clone.raw(); | 6158 return clone.raw(); |
| 6190 } | 6159 } |
| 6191 | 6160 |
| 6192 | 6161 |
| 6193 RawFunction* Function::NewClosureFunction(const String& name, | 6162 RawFunction* Function::NewClosureFunction(const String& name, |
| 6194 const Function& parent, | 6163 const Function& parent, |
| 6195 intptr_t token_pos) { | 6164 intptr_t token_pos) { |
| 6196 ASSERT(!parent.IsNull()); | 6165 ASSERT(!parent.IsNull()); |
| 6197 // Use the owner defining the parent function and not the class containing it. | 6166 // Use the owner defining the parent function and not the class containing it. |
| 6198 const Object& parent_owner = Object::Handle(parent.raw_ptr()->owner_); | 6167 const Object& parent_owner = Object::Handle(parent.raw_ptr()->owner_); |
| (...skipping 852 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7051 Field& clone = Field::Handle(); | 7020 Field& clone = Field::Handle(); |
| 7052 clone ^= Object::Clone(*this, Heap::kOld); | 7021 clone ^= Object::Clone(*this, Heap::kOld); |
| 7053 const Class& owner = Class::Handle(this->owner()); | 7022 const Class& owner = Class::Handle(this->owner()); |
| 7054 const PatchClass& clone_owner = | 7023 const PatchClass& clone_owner = |
| 7055 PatchClass::Handle(PatchClass::New(new_owner, owner)); | 7024 PatchClass::Handle(PatchClass::New(new_owner, owner)); |
| 7056 clone.set_owner(clone_owner); | 7025 clone.set_owner(clone_owner); |
| 7057 clone.set_dependent_code(Object::null_array()); | 7026 clone.set_dependent_code(Object::null_array()); |
| 7058 if (!clone.is_static()) { | 7027 if (!clone.is_static()) { |
| 7059 clone.SetOffset(0); | 7028 clone.SetOffset(0); |
| 7060 } | 7029 } |
| 7061 // Adjust the field type to refer to type parameters of the new owner. | |
| 7062 AbstractType& type = AbstractType::Handle(clone.type()); | |
| 7063 type ^= type.CloneUninstantiated(new_owner); | |
| 7064 clone.set_type(type); | |
| 7065 return clone.raw(); | 7030 return clone.raw(); |
| 7066 } | 7031 } |
| 7067 | 7032 |
| 7068 | 7033 |
| 7069 RawString* Field::PrettyName() const { | 7034 RawString* Field::PrettyName() const { |
| 7070 const String& str = String::Handle(name()); | 7035 const String& str = String::Handle(name()); |
| 7071 return String::IdentifierPrettyName(str); | 7036 return String::IdentifierPrettyName(str); |
| 7072 } | 7037 } |
| 7073 | 7038 |
| 7074 | 7039 |
| (...skipping 6781 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 13856 } | 13821 } |
| 13857 | 13822 |
| 13858 | 13823 |
| 13859 RawAbstractType* AbstractType::CloneUnfinalized() const { | 13824 RawAbstractType* AbstractType::CloneUnfinalized() const { |
| 13860 // AbstractType is an abstract class. | 13825 // AbstractType is an abstract class. |
| 13861 UNREACHABLE(); | 13826 UNREACHABLE(); |
| 13862 return NULL; | 13827 return NULL; |
| 13863 } | 13828 } |
| 13864 | 13829 |
| 13865 | 13830 |
| 13866 RawAbstractType* AbstractType::CloneUninstantiated( | |
| 13867 const Class& new_owner) const { | |
| 13868 // AbstractType is an abstract class. | |
| 13869 UNREACHABLE(); | |
| 13870 return NULL; | |
| 13871 } | |
| 13872 | |
| 13873 | |
| 13874 RawAbstractType* AbstractType::Canonicalize(GrowableObjectArray* trail) const { | 13831 RawAbstractType* AbstractType::Canonicalize(GrowableObjectArray* trail) const { |
| 13875 // AbstractType is an abstract class. | 13832 // AbstractType is an abstract class. |
| 13876 UNREACHABLE(); | 13833 UNREACHABLE(); |
| 13877 return NULL; | 13834 return NULL; |
| 13878 } | 13835 } |
| 13879 | 13836 |
| 13880 | 13837 |
| 13881 RawObject* AbstractType::OnlyBuddyInTrail(GrowableObjectArray* trail) const { | 13838 RawObject* AbstractType::OnlyBuddyInTrail(GrowableObjectArray* trail) const { |
| 13882 if (trail == NULL) { | 13839 if (trail == NULL) { |
| 13883 return Object::null(); | 13840 return Object::null(); |
| (...skipping 679 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 14563 RawAbstractType* Type::CloneUnfinalized() const { | 14520 RawAbstractType* Type::CloneUnfinalized() const { |
| 14564 ASSERT(IsResolved()); | 14521 ASSERT(IsResolved()); |
| 14565 if (IsFinalized()) { | 14522 if (IsFinalized()) { |
| 14566 return raw(); | 14523 return raw(); |
| 14567 } | 14524 } |
| 14568 ASSERT(!IsMalformed()); // Malformed types are finalized. | 14525 ASSERT(!IsMalformed()); // Malformed types are finalized. |
| 14569 ASSERT(!IsBeingFinalized()); // Cloning must occur prior to finalization. | 14526 ASSERT(!IsBeingFinalized()); // Cloning must occur prior to finalization. |
| 14570 TypeArguments& type_args = TypeArguments::Handle(arguments()); | 14527 TypeArguments& type_args = TypeArguments::Handle(arguments()); |
| 14571 type_args = type_args.CloneUnfinalized(); | 14528 type_args = type_args.CloneUnfinalized(); |
| 14572 const Class& type_cls = Class::Handle(type_class()); | 14529 const Class& type_cls = Class::Handle(type_class()); |
| 14573 const Type& clone = Type::Handle(Type::New(type_cls, type_args, token_pos())); | 14530 const Type& type = Type::Handle(Type::New(type_cls, type_args, token_pos())); |
| 14574 clone.set_is_resolved(); | 14531 type.set_is_resolved(); |
| 14575 return clone.raw(); | 14532 return type.raw(); |
| 14576 } | |
| 14577 | |
| 14578 | |
| 14579 RawAbstractType* Type::CloneUninstantiated(const Class& new_owner) const { | |
| 14580 ASSERT(IsFinalized()); | |
| 14581 ASSERT(!IsMalformed()); | |
| 14582 if (IsInstantiated()) { | |
| 14583 return raw(); | |
| 14584 } | |
| 14585 TypeArguments& type_args = TypeArguments::Handle(arguments()); | |
| 14586 type_args = type_args.CloneUninstantiated(new_owner); | |
| 14587 const Class& type_cls = Class::Handle(type_class()); | |
| 14588 const Type& clone = Type::Handle(Type::New(type_cls, type_args, token_pos())); | |
| 14589 clone.SetIsFinalized(); | |
| 14590 return clone.raw(); | |
| 14591 } | 14533 } |
| 14592 | 14534 |
| 14593 | 14535 |
| 14594 RawAbstractType* Type::Canonicalize(GrowableObjectArray* trail) const { | 14536 RawAbstractType* Type::Canonicalize(GrowableObjectArray* trail) const { |
| 14595 ASSERT(IsFinalized()); | 14537 ASSERT(IsFinalized()); |
| 14596 if (IsCanonical() || IsMalformed()) { | 14538 if (IsCanonical() || IsMalformed()) { |
| 14597 ASSERT(IsMalformed() || TypeArguments::Handle(arguments()).IsOld()); | 14539 ASSERT(IsMalformed() || TypeArguments::Handle(arguments()).IsOld()); |
| 14598 return this->raw(); | 14540 return this->raw(); |
| 14599 } | 14541 } |
| 14600 Isolate* isolate = Isolate::Current(); | 14542 Isolate* isolate = Isolate::Current(); |
| (...skipping 519 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 15120 } | 15062 } |
| 15121 // No need to clone bound, as it is not part of the finalization state. | 15063 // No need to clone bound, as it is not part of the finalization state. |
| 15122 return TypeParameter::New(Class::Handle(parameterized_class()), | 15064 return TypeParameter::New(Class::Handle(parameterized_class()), |
| 15123 index(), | 15065 index(), |
| 15124 String::Handle(name()), | 15066 String::Handle(name()), |
| 15125 AbstractType::Handle(bound()), | 15067 AbstractType::Handle(bound()), |
| 15126 token_pos()); | 15068 token_pos()); |
| 15127 } | 15069 } |
| 15128 | 15070 |
| 15129 | 15071 |
| 15130 RawAbstractType* TypeParameter::CloneUninstantiated( | |
| 15131 const Class& new_owner) const { | |
| 15132 ASSERT(IsFinalized()); | |
| 15133 AbstractType& upper_bound = AbstractType::Handle(bound()); | |
| 15134 upper_bound = upper_bound.CloneUninstantiated(new_owner); | |
| 15135 const Class& old_owner = Class::Handle(parameterized_class()); | |
| 15136 const intptr_t new_index = index() + | |
| 15137 new_owner.NumTypeArguments() - old_owner.NumTypeArguments(); | |
| 15138 const TypeParameter& clone = TypeParameter::Handle( | |
| 15139 TypeParameter::New(new_owner, | |
| 15140 new_index, | |
| 15141 String::Handle(name()), | |
| 15142 upper_bound, | |
| 15143 token_pos())); | |
| 15144 clone.set_is_finalized(); | |
| 15145 return clone.raw(); | |
| 15146 } | |
| 15147 | |
| 15148 | |
| 15149 intptr_t TypeParameter::Hash() const { | 15072 intptr_t TypeParameter::Hash() const { |
| 15150 ASSERT(IsFinalized()); | 15073 ASSERT(IsFinalized()); |
| 15151 uint32_t result = Class::Handle(parameterized_class()).id(); | 15074 uint32_t result = Class::Handle(parameterized_class()).id(); |
| 15152 // No need to include the hash of the bound, since the type parameter is fully | 15075 // No need to include the hash of the bound, since the type parameter is fully |
| 15153 // identified by its class and index. | 15076 // identified by its class and index. |
| 15154 result = CombineHashes(result, index()); | 15077 result = CombineHashes(result, index()); |
| 15155 return FinalizeHash(result); | 15078 return FinalizeHash(result); |
| 15156 } | 15079 } |
| 15157 | 15080 |
| 15158 | 15081 |
| (...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 15359 | 15282 |
| 15360 bounded_type = bounded_type.CloneUnfinalized(); | 15283 bounded_type = bounded_type.CloneUnfinalized(); |
| 15361 // No need to clone bound or type parameter, as they are not part of the | 15284 // No need to clone bound or type parameter, as they are not part of the |
| 15362 // finalization state of this bounded type. | 15285 // finalization state of this bounded type. |
| 15363 return BoundedType::New(bounded_type, | 15286 return BoundedType::New(bounded_type, |
| 15364 AbstractType::Handle(bound()), | 15287 AbstractType::Handle(bound()), |
| 15365 TypeParameter::Handle(type_parameter())); | 15288 TypeParameter::Handle(type_parameter())); |
| 15366 } | 15289 } |
| 15367 | 15290 |
| 15368 | 15291 |
| 15369 RawAbstractType* BoundedType::CloneUninstantiated( | |
| 15370 const Class& new_owner) const { | |
| 15371 if (IsInstantiated()) { | |
| 15372 return raw(); | |
| 15373 } | |
| 15374 AbstractType& bounded_type = AbstractType::Handle(type()); | |
| 15375 bounded_type = bounded_type.CloneUninstantiated(new_owner); | |
| 15376 AbstractType& upper_bound = AbstractType::Handle(bound()); | |
| 15377 upper_bound = upper_bound.CloneUninstantiated(new_owner); | |
| 15378 TypeParameter& type_param = TypeParameter::Handle(type_parameter()); | |
| 15379 type_param ^= type_param.CloneUninstantiated(new_owner); | |
| 15380 return BoundedType::New(bounded_type, upper_bound, type_param); | |
| 15381 } | |
| 15382 | |
| 15383 | |
| 15384 intptr_t BoundedType::Hash() const { | 15292 intptr_t BoundedType::Hash() const { |
| 15385 uint32_t result = AbstractType::Handle(type()).Hash(); | 15293 uint32_t result = AbstractType::Handle(type()).Hash(); |
| 15386 // No need to include the hash of the bound, since the bound is defined by the | 15294 // No need to include the hash of the bound, since the bound is defined by the |
| 15387 // type parameter (modulo instantiation state). | 15295 // type parameter (modulo instantiation state). |
| 15388 result = CombineHashes(result, | 15296 result = CombineHashes(result, |
| 15389 TypeParameter::Handle(type_parameter()).Hash()); | 15297 TypeParameter::Handle(type_parameter()).Hash()); |
| 15390 return FinalizeHash(result); | 15298 return FinalizeHash(result); |
| 15391 } | 15299 } |
| 15392 | 15300 |
| 15393 | 15301 |
| (...skipping 5006 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 20400 return tag_label.ToCString(); | 20308 return tag_label.ToCString(); |
| 20401 } | 20309 } |
| 20402 | 20310 |
| 20403 | 20311 |
| 20404 void UserTag::PrintJSONImpl(JSONStream* stream, bool ref) const { | 20312 void UserTag::PrintJSONImpl(JSONStream* stream, bool ref) const { |
| 20405 Instance::PrintJSONImpl(stream, ref); | 20313 Instance::PrintJSONImpl(stream, ref); |
| 20406 } | 20314 } |
| 20407 | 20315 |
| 20408 | 20316 |
| 20409 } // namespace dart | 20317 } // namespace dart |
| OLD | NEW |