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

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

Issue 693693003: Resubmit fix for Function::Clone() and Field::Clone() to adjust the class owner (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 if (new_owner.NumTypeParameters() > 0) {
6180 // Adjust uninstantiated types to refer to type parameters of the new owner.
6181 AbstractType& type = AbstractType::Handle(clone.result_type());
6182 type ^= type.CloneUninstantiated(new_owner);
6183 clone.set_result_type(type);
6184 const intptr_t num_params = clone.NumParameters();
6185 Array& array = Array::Handle(clone.parameter_types());
6186 array ^= Object::Clone(array, Heap::kOld);
6187 clone.set_parameter_types(array);
6188 for (intptr_t i = 0; i < num_params; i++) {
6189 type = clone.ParameterTypeAt(i);
6190 type ^= type.CloneUninstantiated(new_owner);
6191 clone.SetParameterTypeAt(i, type);
6192 }
6193 }
6158 return clone.raw(); 6194 return clone.raw();
6159 } 6195 }
6160 6196
6161 6197
6162 RawFunction* Function::NewClosureFunction(const String& name, 6198 RawFunction* Function::NewClosureFunction(const String& name,
6163 const Function& parent, 6199 const Function& parent,
6164 intptr_t token_pos) { 6200 intptr_t token_pos) {
6165 ASSERT(!parent.IsNull()); 6201 ASSERT(!parent.IsNull());
6166 // Use the owner defining the parent function and not the class containing it. 6202 // Use the owner defining the parent function and not the class containing it.
6167 const Object& parent_owner = Object::Handle(parent.raw_ptr()->owner_); 6203 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(); 7056 Field& clone = Field::Handle();
7021 clone ^= Object::Clone(*this, Heap::kOld); 7057 clone ^= Object::Clone(*this, Heap::kOld);
7022 const Class& owner = Class::Handle(this->owner()); 7058 const Class& owner = Class::Handle(this->owner());
7023 const PatchClass& clone_owner = 7059 const PatchClass& clone_owner =
7024 PatchClass::Handle(PatchClass::New(new_owner, owner)); 7060 PatchClass::Handle(PatchClass::New(new_owner, owner));
7025 clone.set_owner(clone_owner); 7061 clone.set_owner(clone_owner);
7026 clone.set_dependent_code(Object::null_array()); 7062 clone.set_dependent_code(Object::null_array());
7027 if (!clone.is_static()) { 7063 if (!clone.is_static()) {
7028 clone.SetOffset(0); 7064 clone.SetOffset(0);
7029 } 7065 }
7066 if (new_owner.NumTypeParameters() > 0) {
7067 // Adjust the field type to refer to type parameters of the new owner.
7068 AbstractType& type = AbstractType::Handle(clone.type());
7069 type ^= type.CloneUninstantiated(new_owner);
7070 clone.set_type(type);
7071 }
7030 return clone.raw(); 7072 return clone.raw();
7031 } 7073 }
7032 7074
7033 7075
7034 RawString* Field::PrettyName() const { 7076 RawString* Field::PrettyName() const {
7035 const String& str = String::Handle(name()); 7077 const String& str = String::Handle(name());
7036 return String::IdentifierPrettyName(str); 7078 return String::IdentifierPrettyName(str);
7037 } 7079 }
7038 7080
7039 7081
(...skipping 6776 matching lines...) Expand 10 before | Expand all | Expand 10 after
13816 } 13858 }
13817 13859
13818 13860
13819 RawAbstractType* AbstractType::CloneUnfinalized() const { 13861 RawAbstractType* AbstractType::CloneUnfinalized() const {
13820 // AbstractType is an abstract class. 13862 // AbstractType is an abstract class.
13821 UNREACHABLE(); 13863 UNREACHABLE();
13822 return NULL; 13864 return NULL;
13823 } 13865 }
13824 13866
13825 13867
13868 RawAbstractType* AbstractType::CloneUninstantiated(
13869 const Class& new_owner) const {
13870 // AbstractType is an abstract class.
13871 UNREACHABLE();
13872 return NULL;
13873 }
13874
13875
13826 RawAbstractType* AbstractType::Canonicalize(GrowableObjectArray* trail) const { 13876 RawAbstractType* AbstractType::Canonicalize(GrowableObjectArray* trail) const {
13827 // AbstractType is an abstract class. 13877 // AbstractType is an abstract class.
13828 UNREACHABLE(); 13878 UNREACHABLE();
13829 return NULL; 13879 return NULL;
13830 } 13880 }
13831 13881
13832 13882
13833 RawObject* AbstractType::OnlyBuddyInTrail(GrowableObjectArray* trail) const { 13883 RawObject* AbstractType::OnlyBuddyInTrail(GrowableObjectArray* trail) const {
13834 if (trail == NULL) { 13884 if (trail == NULL) {
13835 return Object::null(); 13885 return Object::null();
(...skipping 679 matching lines...) Expand 10 before | Expand all | Expand 10 after
14515 RawAbstractType* Type::CloneUnfinalized() const { 14565 RawAbstractType* Type::CloneUnfinalized() const {
14516 ASSERT(IsResolved()); 14566 ASSERT(IsResolved());
14517 if (IsFinalized()) { 14567 if (IsFinalized()) {
14518 return raw(); 14568 return raw();
14519 } 14569 }
14520 ASSERT(!IsMalformed()); // Malformed types are finalized. 14570 ASSERT(!IsMalformed()); // Malformed types are finalized.
14521 ASSERT(!IsBeingFinalized()); // Cloning must occur prior to finalization. 14571 ASSERT(!IsBeingFinalized()); // Cloning must occur prior to finalization.
14522 TypeArguments& type_args = TypeArguments::Handle(arguments()); 14572 TypeArguments& type_args = TypeArguments::Handle(arguments());
14523 type_args = type_args.CloneUnfinalized(); 14573 type_args = type_args.CloneUnfinalized();
14524 const Class& type_cls = Class::Handle(type_class()); 14574 const Class& type_cls = Class::Handle(type_class());
14525 const Type& type = Type::Handle(Type::New(type_cls, type_args, token_pos())); 14575 const Type& clone = Type::Handle(Type::New(type_cls, type_args, token_pos()));
14526 type.set_is_resolved(); 14576 clone.set_is_resolved();
14527 return type.raw(); 14577 return clone.raw();
14578 }
14579
14580
14581 RawAbstractType* Type::CloneUninstantiated(const Class& new_owner) const {
14582 ASSERT(IsFinalized());
14583 ASSERT(!IsMalformed());
14584 if (IsInstantiated()) {
14585 return raw();
14586 }
14587 TypeArguments& type_args = TypeArguments::Handle(arguments());
14588 type_args = type_args.CloneUninstantiated(new_owner);
14589 const Class& type_cls = Class::Handle(type_class());
14590 const Type& clone = Type::Handle(Type::New(type_cls, type_args, token_pos()));
14591 clone.SetIsFinalized();
14592 return clone.raw();
14528 } 14593 }
14529 14594
14530 14595
14531 RawAbstractType* Type::Canonicalize(GrowableObjectArray* trail) const { 14596 RawAbstractType* Type::Canonicalize(GrowableObjectArray* trail) const {
14532 ASSERT(IsFinalized()); 14597 ASSERT(IsFinalized());
14533 if (IsCanonical() || IsMalformed()) { 14598 if (IsCanonical() || IsMalformed()) {
14534 ASSERT(IsMalformed() || TypeArguments::Handle(arguments()).IsOld()); 14599 ASSERT(IsMalformed() || TypeArguments::Handle(arguments()).IsOld());
14535 return this->raw(); 14600 return this->raw();
14536 } 14601 }
14537 Isolate* isolate = Isolate::Current(); 14602 Isolate* isolate = Isolate::Current();
(...skipping 519 matching lines...) Expand 10 before | Expand all | Expand 10 after
15057 } 15122 }
15058 // No need to clone bound, as it is not part of the finalization state. 15123 // No need to clone bound, as it is not part of the finalization state.
15059 return TypeParameter::New(Class::Handle(parameterized_class()), 15124 return TypeParameter::New(Class::Handle(parameterized_class()),
15060 index(), 15125 index(),
15061 String::Handle(name()), 15126 String::Handle(name()),
15062 AbstractType::Handle(bound()), 15127 AbstractType::Handle(bound()),
15063 token_pos()); 15128 token_pos());
15064 } 15129 }
15065 15130
15066 15131
15132 RawAbstractType* TypeParameter::CloneUninstantiated(
15133 const Class& new_owner) const {
15134 ASSERT(IsFinalized());
15135 AbstractType& upper_bound = AbstractType::Handle(bound());
15136 upper_bound = upper_bound.CloneUninstantiated(new_owner);
15137 const Class& old_owner = Class::Handle(parameterized_class());
15138 const intptr_t new_index = index() +
15139 new_owner.NumTypeArguments() - old_owner.NumTypeArguments();
15140 const TypeParameter& clone = TypeParameter::Handle(
15141 TypeParameter::New(new_owner,
15142 new_index,
15143 String::Handle(name()),
15144 upper_bound,
15145 token_pos()));
15146 clone.set_is_finalized();
15147 return clone.raw();
15148 }
15149
15150
15067 intptr_t TypeParameter::Hash() const { 15151 intptr_t TypeParameter::Hash() const {
15068 ASSERT(IsFinalized()); 15152 ASSERT(IsFinalized());
15069 uint32_t result = Class::Handle(parameterized_class()).id(); 15153 uint32_t result = Class::Handle(parameterized_class()).id();
15070 // No need to include the hash of the bound, since the type parameter is fully 15154 // No need to include the hash of the bound, since the type parameter is fully
15071 // identified by its class and index. 15155 // identified by its class and index.
15072 result = CombineHashes(result, index()); 15156 result = CombineHashes(result, index());
15073 return FinalizeHash(result); 15157 return FinalizeHash(result);
15074 } 15158 }
15075 15159
15076 15160
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after
15277 15361
15278 bounded_type = bounded_type.CloneUnfinalized(); 15362 bounded_type = bounded_type.CloneUnfinalized();
15279 // No need to clone bound or type parameter, as they are not part of the 15363 // No need to clone bound or type parameter, as they are not part of the
15280 // finalization state of this bounded type. 15364 // finalization state of this bounded type.
15281 return BoundedType::New(bounded_type, 15365 return BoundedType::New(bounded_type,
15282 AbstractType::Handle(bound()), 15366 AbstractType::Handle(bound()),
15283 TypeParameter::Handle(type_parameter())); 15367 TypeParameter::Handle(type_parameter()));
15284 } 15368 }
15285 15369
15286 15370
15371 RawAbstractType* BoundedType::CloneUninstantiated(
15372 const Class& new_owner) const {
15373 if (IsInstantiated()) {
15374 return raw();
15375 }
15376 AbstractType& bounded_type = AbstractType::Handle(type());
15377 bounded_type = bounded_type.CloneUninstantiated(new_owner);
15378 AbstractType& upper_bound = AbstractType::Handle(bound());
15379 upper_bound = upper_bound.CloneUninstantiated(new_owner);
15380 TypeParameter& type_param = TypeParameter::Handle(type_parameter());
15381 type_param ^= type_param.CloneUninstantiated(new_owner);
15382 return BoundedType::New(bounded_type, upper_bound, type_param);
15383 }
15384
15385
15287 intptr_t BoundedType::Hash() const { 15386 intptr_t BoundedType::Hash() const {
15288 uint32_t result = AbstractType::Handle(type()).Hash(); 15387 uint32_t result = AbstractType::Handle(type()).Hash();
15289 // No need to include the hash of the bound, since the bound is defined by the 15388 // No need to include the hash of the bound, since the bound is defined by the
15290 // type parameter (modulo instantiation state). 15389 // type parameter (modulo instantiation state).
15291 result = CombineHashes(result, 15390 result = CombineHashes(result,
15292 TypeParameter::Handle(type_parameter()).Hash()); 15391 TypeParameter::Handle(type_parameter()).Hash());
15293 return FinalizeHash(result); 15392 return FinalizeHash(result);
15294 } 15393 }
15295 15394
15296 15395
(...skipping 5006 matching lines...) Expand 10 before | Expand all | Expand 10 after
20303 return tag_label.ToCString(); 20402 return tag_label.ToCString();
20304 } 20403 }
20305 20404
20306 20405
20307 void UserTag::PrintJSONImpl(JSONStream* stream, bool ref) const { 20406 void UserTag::PrintJSONImpl(JSONStream* stream, bool ref) const {
20308 Instance::PrintJSONImpl(stream, ref); 20407 Instance::PrintJSONImpl(stream, ref);
20309 } 20408 }
20310 20409
20311 20410
20312 } // namespace dart 20411 } // 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