Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(42)

Side by Side Diff: runtime/vm/object.cc

Issue 646103005: Fix Function::Clone() and Field::Clone() to adjust the class owner of type (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « runtime/vm/object.h ('k') | tests/language/mixin_type_parameter5_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
4958 RawTypeArguments* TypeArguments::Canonicalize( 4979 RawTypeArguments* TypeArguments::Canonicalize(
4959 GrowableObjectArray* trail) const { 4980 GrowableObjectArray* trail) const {
4960 if (IsNull() || IsCanonical()) { 4981 if (IsNull() || IsCanonical()) {
4961 ASSERT(IsOld()); 4982 ASSERT(IsOld());
4962 return this->raw(); 4983 return this->raw();
4963 } 4984 }
4964 const intptr_t num_types = Length(); 4985 const intptr_t num_types = Length();
4965 if (IsRaw(0, num_types)) { 4986 if (IsRaw(0, num_types)) {
4966 return TypeArguments::null(); 4987 return TypeArguments::null();
4967 } 4988 }
(...skipping 1180 matching lines...) Expand 10 before | Expand all | Expand 10 after
6148 const Class& origin = Class::Handle(this->origin()); 6169 const Class& origin = Class::Handle(this->origin());
6149 const PatchClass& clone_owner = 6170 const PatchClass& clone_owner =
6150 PatchClass::Handle(PatchClass::New(new_owner, origin)); 6171 PatchClass::Handle(PatchClass::New(new_owner, origin));
6151 clone.set_owner(clone_owner); 6172 clone.set_owner(clone_owner);
6152 clone.ClearCode(); 6173 clone.ClearCode();
6153 clone.set_usage_counter(0); 6174 clone.set_usage_counter(0);
6154 clone.set_deoptimization_counter(0); 6175 clone.set_deoptimization_counter(0);
6155 clone.set_optimized_instruction_count(0); 6176 clone.set_optimized_instruction_count(0);
6156 clone.set_optimized_call_site_count(0); 6177 clone.set_optimized_call_site_count(0);
6157 clone.set_ic_data_array(Array::Handle()); 6178 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 }
6158 return clone.raw(); 6189 return clone.raw();
6159 } 6190 }
6160 6191
6161 6192
6162 RawFunction* Function::NewClosureFunction(const String& name, 6193 RawFunction* Function::NewClosureFunction(const String& name,
6163 const Function& parent, 6194 const Function& parent,
6164 intptr_t token_pos) { 6195 intptr_t token_pos) {
6165 ASSERT(!parent.IsNull()); 6196 ASSERT(!parent.IsNull());
6166 // Use the owner defining the parent function and not the class containing it. 6197 // Use the owner defining the parent function and not the class containing it.
6167 const Object& parent_owner = Object::Handle(parent.raw_ptr()->owner_); 6198 const Object& parent_owner = Object::Handle(parent.raw_ptr()->owner_);
(...skipping 852 matching lines...) Expand 10 before | Expand all | Expand 10 after
7020 Field& clone = Field::Handle(); 7051 Field& clone = Field::Handle();
7021 clone ^= Object::Clone(*this, Heap::kOld); 7052 clone ^= Object::Clone(*this, Heap::kOld);
7022 const Class& owner = Class::Handle(this->owner()); 7053 const Class& owner = Class::Handle(this->owner());
7023 const PatchClass& clone_owner = 7054 const PatchClass& clone_owner =
7024 PatchClass::Handle(PatchClass::New(new_owner, owner)); 7055 PatchClass::Handle(PatchClass::New(new_owner, owner));
7025 clone.set_owner(clone_owner); 7056 clone.set_owner(clone_owner);
7026 clone.set_dependent_code(Object::null_array()); 7057 clone.set_dependent_code(Object::null_array());
7027 if (!clone.is_static()) { 7058 if (!clone.is_static()) {
7028 clone.SetOffset(0); 7059 clone.SetOffset(0);
7029 } 7060 }
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);
7030 return clone.raw(); 7065 return clone.raw();
7031 } 7066 }
7032 7067
7033 7068
7034 RawString* Field::PrettyName() const { 7069 RawString* Field::PrettyName() const {
7035 const String& str = String::Handle(name()); 7070 const String& str = String::Handle(name());
7036 return String::IdentifierPrettyName(str); 7071 return String::IdentifierPrettyName(str);
7037 } 7072 }
7038 7073
7039 7074
(...skipping 6781 matching lines...) Expand 10 before | Expand all | Expand 10 after
13821 } 13856 }
13822 13857
13823 13858
13824 RawAbstractType* AbstractType::CloneUnfinalized() const { 13859 RawAbstractType* AbstractType::CloneUnfinalized() const {
13825 // AbstractType is an abstract class. 13860 // AbstractType is an abstract class.
13826 UNREACHABLE(); 13861 UNREACHABLE();
13827 return NULL; 13862 return NULL;
13828 } 13863 }
13829 13864
13830 13865
13866 RawAbstractType* AbstractType::CloneUninstantiated(
13867 const Class& new_owner) const {
13868 // AbstractType is an abstract class.
13869 UNREACHABLE();
13870 return NULL;
13871 }
13872
13873
13831 RawAbstractType* AbstractType::Canonicalize(GrowableObjectArray* trail) const { 13874 RawAbstractType* AbstractType::Canonicalize(GrowableObjectArray* trail) const {
13832 // AbstractType is an abstract class. 13875 // AbstractType is an abstract class.
13833 UNREACHABLE(); 13876 UNREACHABLE();
13834 return NULL; 13877 return NULL;
13835 } 13878 }
13836 13879
13837 13880
13838 RawObject* AbstractType::OnlyBuddyInTrail(GrowableObjectArray* trail) const { 13881 RawObject* AbstractType::OnlyBuddyInTrail(GrowableObjectArray* trail) const {
13839 if (trail == NULL) { 13882 if (trail == NULL) {
13840 return Object::null(); 13883 return Object::null();
(...skipping 679 matching lines...) Expand 10 before | Expand all | Expand 10 after
14520 RawAbstractType* Type::CloneUnfinalized() const { 14563 RawAbstractType* Type::CloneUnfinalized() const {
14521 ASSERT(IsResolved()); 14564 ASSERT(IsResolved());
14522 if (IsFinalized()) { 14565 if (IsFinalized()) {
14523 return raw(); 14566 return raw();
14524 } 14567 }
14525 ASSERT(!IsMalformed()); // Malformed types are finalized. 14568 ASSERT(!IsMalformed()); // Malformed types are finalized.
14526 ASSERT(!IsBeingFinalized()); // Cloning must occur prior to finalization. 14569 ASSERT(!IsBeingFinalized()); // Cloning must occur prior to finalization.
14527 TypeArguments& type_args = TypeArguments::Handle(arguments()); 14570 TypeArguments& type_args = TypeArguments::Handle(arguments());
14528 type_args = type_args.CloneUnfinalized(); 14571 type_args = type_args.CloneUnfinalized();
14529 const Class& type_cls = Class::Handle(type_class()); 14572 const Class& type_cls = Class::Handle(type_class());
14530 const Type& type = Type::Handle(Type::New(type_cls, type_args, token_pos())); 14573 const Type& clone = Type::Handle(Type::New(type_cls, type_args, token_pos()));
14531 type.set_is_resolved(); 14574 clone.set_is_resolved();
14532 return type.raw(); 14575 return clone.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();
14533 } 14591 }
14534 14592
14535 14593
14536 RawAbstractType* Type::Canonicalize(GrowableObjectArray* trail) const { 14594 RawAbstractType* Type::Canonicalize(GrowableObjectArray* trail) const {
14537 ASSERT(IsFinalized()); 14595 ASSERT(IsFinalized());
14538 if (IsCanonical() || IsMalformed()) { 14596 if (IsCanonical() || IsMalformed()) {
14539 ASSERT(IsMalformed() || TypeArguments::Handle(arguments()).IsOld()); 14597 ASSERT(IsMalformed() || TypeArguments::Handle(arguments()).IsOld());
14540 return this->raw(); 14598 return this->raw();
14541 } 14599 }
14542 Isolate* isolate = Isolate::Current(); 14600 Isolate* isolate = Isolate::Current();
(...skipping 519 matching lines...) Expand 10 before | Expand all | Expand 10 after
15062 } 15120 }
15063 // No need to clone bound, as it is not part of the finalization state. 15121 // No need to clone bound, as it is not part of the finalization state.
15064 return TypeParameter::New(Class::Handle(parameterized_class()), 15122 return TypeParameter::New(Class::Handle(parameterized_class()),
15065 index(), 15123 index(),
15066 String::Handle(name()), 15124 String::Handle(name()),
15067 AbstractType::Handle(bound()), 15125 AbstractType::Handle(bound()),
15068 token_pos()); 15126 token_pos());
15069 } 15127 }
15070 15128
15071 15129
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
15072 intptr_t TypeParameter::Hash() const { 15149 intptr_t TypeParameter::Hash() const {
15073 ASSERT(IsFinalized()); 15150 ASSERT(IsFinalized());
15074 uint32_t result = Class::Handle(parameterized_class()).id(); 15151 uint32_t result = Class::Handle(parameterized_class()).id();
15075 // No need to include the hash of the bound, since the type parameter is fully 15152 // No need to include the hash of the bound, since the type parameter is fully
15076 // identified by its class and index. 15153 // identified by its class and index.
15077 result = CombineHashes(result, index()); 15154 result = CombineHashes(result, index());
15078 return FinalizeHash(result); 15155 return FinalizeHash(result);
15079 } 15156 }
15080 15157
15081 15158
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after
15282 15359
15283 bounded_type = bounded_type.CloneUnfinalized(); 15360 bounded_type = bounded_type.CloneUnfinalized();
15284 // No need to clone bound or type parameter, as they are not part of the 15361 // No need to clone bound or type parameter, as they are not part of the
15285 // finalization state of this bounded type. 15362 // finalization state of this bounded type.
15286 return BoundedType::New(bounded_type, 15363 return BoundedType::New(bounded_type,
15287 AbstractType::Handle(bound()), 15364 AbstractType::Handle(bound()),
15288 TypeParameter::Handle(type_parameter())); 15365 TypeParameter::Handle(type_parameter()));
15289 } 15366 }
15290 15367
15291 15368
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
15292 intptr_t BoundedType::Hash() const { 15384 intptr_t BoundedType::Hash() const {
15293 uint32_t result = AbstractType::Handle(type()).Hash(); 15385 uint32_t result = AbstractType::Handle(type()).Hash();
15294 // No need to include the hash of the bound, since the bound is defined by the 15386 // No need to include the hash of the bound, since the bound is defined by the
15295 // type parameter (modulo instantiation state). 15387 // type parameter (modulo instantiation state).
15296 result = CombineHashes(result, 15388 result = CombineHashes(result,
15297 TypeParameter::Handle(type_parameter()).Hash()); 15389 TypeParameter::Handle(type_parameter()).Hash());
15298 return FinalizeHash(result); 15390 return FinalizeHash(result);
15299 } 15391 }
15300 15392
15301 15393
(...skipping 5006 matching lines...) Expand 10 before | Expand all | Expand 10 after
20308 return tag_label.ToCString(); 20400 return tag_label.ToCString();
20309 } 20401 }
20310 20402
20311 20403
20312 void UserTag::PrintJSONImpl(JSONStream* stream, bool ref) const { 20404 void UserTag::PrintJSONImpl(JSONStream* stream, bool ref) const {
20313 Instance::PrintJSONImpl(stream, ref); 20405 Instance::PrintJSONImpl(stream, ref);
20314 } 20406 }
20315 20407
20316 20408
20317 } // namespace dart 20409 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/object.h ('k') | tests/language/mixin_type_parameter5_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698