Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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/class_finalizer.h" | 5 #include "vm/class_finalizer.h" |
| 6 | 6 |
| 7 #include "vm/flags.h" | 7 #include "vm/flags.h" |
| 8 #include "vm/heap.h" | 8 #include "vm/heap.h" |
| 9 #include "vm/isolate.h" | 9 #include "vm/isolate.h" |
| 10 #include "vm/longjump.h" | 10 #include "vm/longjump.h" |
| (...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 285 } | 285 } |
| 286 return resolved_class.raw(); | 286 return resolved_class.raw(); |
| 287 } | 287 } |
| 288 | 288 |
| 289 | 289 |
| 290 // Resolve unresolved supertype (String -> Class). | 290 // Resolve unresolved supertype (String -> Class). |
| 291 void ClassFinalizer::ResolveSuperType(const Class& cls) { | 291 void ClassFinalizer::ResolveSuperType(const Class& cls) { |
| 292 if (cls.is_finalized()) { | 292 if (cls.is_finalized()) { |
| 293 return; | 293 return; |
| 294 } | 294 } |
| 295 AbstractType& super_type = AbstractType::Handle(cls.super_type()); | 295 Type& super_type = Type::Handle(cls.super_type()); |
| 296 if (super_type.IsNull()) { | 296 if (super_type.IsNull()) { |
| 297 return; | 297 return; |
| 298 } | 298 } |
| 299 // Resolve failures lead to a longjmp. | 299 // Resolve failures lead to a longjmp. |
| 300 super_type = ResolveType(cls, super_type); | 300 super_type ^= ResolveType(cls, super_type); |
| 301 if (super_type.IsTypeParameter()) { | 301 if (super_type.IsTypeParameter()) { |
|
regis
2011/12/01 19:20:43
Since super_type is now a Type, this test always f
srdjan
2011/12/01 20:04:09
Removed code.
I think it is better if I implement
| |
| 302 String& class_name = String::Handle(cls.Name()); | 302 String& class_name = String::Handle(cls.Name()); |
| 303 String& type_parameter_name = String::Handle(super_type.Name()); | 303 String& type_parameter_name = String::Handle(super_type.Name()); |
| 304 ReportError("'%s' cannot extend or implement type parameter '%s'.\n", | 304 ReportError("'%s' cannot extend or implement type parameter '%s'.\n", |
| 305 class_name.ToCString(), | 305 class_name.ToCString(), |
| 306 type_parameter_name.ToCString()); | 306 type_parameter_name.ToCString()); |
| 307 } | 307 } |
| 308 cls.set_super_type(super_type); | 308 cls.set_super_type(super_type); |
| 309 const Class& super_class = Class::Handle(super_type.type_class()); | 309 const Class& super_class = Class::Handle(super_type.type_class()); |
| 310 if (cls.is_interface() != super_class.is_interface()) { | 310 if (cls.is_interface() != super_class.is_interface()) { |
| 311 String& class_name = String::Handle(cls.Name()); | 311 String& class_name = String::Handle(cls.Name()); |
| (...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 498 // Example: | 498 // Example: |
| 499 // Declared: class C<K, V> extends B<V> { ... } | 499 // Declared: class C<K, V> extends B<V> { ... } |
| 500 // class B<T> extends Array<int> { ... } | 500 // class B<T> extends Array<int> { ... } |
| 501 // Input: C<String, double> expressed as | 501 // Input: C<String, double> expressed as |
| 502 // cls = C, arguments = [null, null, String, double], | 502 // cls = C, arguments = [null, null, String, double], |
| 503 // i.e. cls_args = [String, double], offset = 2, length = 2. | 503 // i.e. cls_args = [String, double], offset = 2, length = 2. |
| 504 // Output: arguments = [int, double, String, double] | 504 // Output: arguments = [int, double, String, double] |
| 505 void ClassFinalizer::FinalizeTypeArguments(const Class& cls, | 505 void ClassFinalizer::FinalizeTypeArguments(const Class& cls, |
| 506 const TypeArguments& arguments) { | 506 const TypeArguments& arguments) { |
| 507 ASSERT(arguments.Length() >= cls.NumTypeArguments()); | 507 ASSERT(arguments.Length() >= cls.NumTypeArguments()); |
| 508 AbstractType& super_type = AbstractType::Handle(cls.super_type()); | 508 Type& super_type = Type::Handle(cls.super_type()); |
| 509 if (!super_type.IsNull()) { | 509 if (!super_type.IsNull()) { |
| 510 super_type = FinalizeType(super_type); | 510 super_type ^= FinalizeType(super_type); |
| 511 cls.set_super_type(super_type); | 511 cls.set_super_type(super_type); |
| 512 const Class& super_class = Class::Handle(super_type.type_class()); | 512 const Class& super_class = Class::Handle(super_type.type_class()); |
| 513 const TypeArguments& super_type_args = | 513 const TypeArguments& super_type_args = |
| 514 TypeArguments::Handle(super_type.arguments()); | 514 TypeArguments::Handle(super_type.arguments()); |
| 515 const intptr_t num_super_type_params = super_class.NumTypeParameters(); | 515 const intptr_t num_super_type_params = super_class.NumTypeParameters(); |
| 516 const intptr_t offset = super_class.NumTypeArguments(); | 516 const intptr_t offset = super_class.NumTypeArguments(); |
| 517 const intptr_t super_offset = offset - num_super_type_params; | 517 const intptr_t super_offset = offset - num_super_type_params; |
| 518 ASSERT(offset == (cls.NumTypeArguments() - cls.NumTypeParameters())); | 518 ASSERT(offset == (cls.NumTypeArguments() - cls.NumTypeParameters())); |
| 519 AbstractType& super_type_arg = AbstractType::Handle(); | 519 AbstractType& super_type_arg = AbstractType::Handle(); |
| 520 for (intptr_t i = 0; i < num_super_type_params; i++) { | 520 for (intptr_t i = 0; i < num_super_type_params; i++) { |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 561 ReportError(script, -1, | 561 ReportError(script, -1, |
| 562 "type argument '%s' of class '%s' " | 562 "type argument '%s' of class '%s' " |
| 563 "does not extend type '%s'\n", | 563 "does not extend type '%s'\n", |
| 564 type_argument_name.ToCString(), | 564 type_argument_name.ToCString(), |
| 565 class_name.ToCString(), | 565 class_name.ToCString(), |
| 566 extends_name.ToCString()); | 566 extends_name.ToCString()); |
| 567 } | 567 } |
| 568 } | 568 } |
| 569 } | 569 } |
| 570 } | 570 } |
| 571 AbstractType& super_type = AbstractType::Handle(cls.super_type()); | 571 const Type& super_type = Type::Handle(cls.super_type()); |
| 572 if (!super_type.IsNull()) { | 572 if (!super_type.IsNull()) { |
| 573 ASSERT(super_type.IsFinalized()); | 573 ASSERT(super_type.IsFinalized()); |
| 574 const Class& super_class = Class::Handle(super_type.type_class()); | 574 const Class& super_class = Class::Handle(super_type.type_class()); |
| 575 VerifyUpperBounds(super_class, arguments); | 575 VerifyUpperBounds(super_class, arguments); |
| 576 } | 576 } |
| 577 } | 577 } |
| 578 | 578 |
| 579 | 579 |
| 580 RawAbstractType* ClassFinalizer::FinalizeType(const AbstractType& type) { | 580 RawAbstractType* ClassFinalizer::FinalizeType(const AbstractType& type) { |
| 581 ASSERT(type.IsResolved()); | 581 ASSERT(type.IsResolved()); |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 681 if (FLAG_enable_type_checks) { | 681 if (FLAG_enable_type_checks) { |
| 682 VerifyUpperBounds(type_class, full_arguments); | 682 VerifyUpperBounds(type_class, full_arguments); |
| 683 } | 683 } |
| 684 } else { | 684 } else { |
| 685 parameterized_type.set_is_finalized(); | 685 parameterized_type.set_is_finalized(); |
| 686 } | 686 } |
| 687 return parameterized_type.Canonicalize(); | 687 return parameterized_type.Canonicalize(); |
| 688 } | 688 } |
| 689 | 689 |
| 690 | 690 |
| 691 RawAbstractType* ClassFinalizer::FinalizeAndCanonicalizeType( | 691 RawAbstractType* ClassFinalizer::FinalizeAndCanonicalizeType( |
|
regis
2011/12/01 19:20:43
I think this should always return a RawType*.
Howe
srdjan
2011/12/01 20:04:09
Done.
| |
| 692 const AbstractType& type, String* errmsg) { | 692 const AbstractType& type, String* errmsg) { |
| 693 Isolate* isolate = Isolate::Current(); | 693 Isolate* isolate = Isolate::Current(); |
| 694 ASSERT(isolate != NULL); | 694 ASSERT(isolate != NULL); |
| 695 LongJump* base = isolate->long_jump_base(); | 695 LongJump* base = isolate->long_jump_base(); |
| 696 LongJump jump; | 696 LongJump jump; |
| 697 isolate->set_long_jump_base(&jump); | 697 isolate->set_long_jump_base(&jump); |
| 698 if (setjmp(*jump.Set()) == 0) { | 698 if (setjmp(*jump.Set()) == 0) { |
| 699 const AbstractType& canonical_type = | 699 const AbstractType& canonical_type = |
| 700 AbstractType::Handle(FinalizeType(type)); | 700 AbstractType::Handle(FinalizeType(type)); |
| 701 isolate->set_long_jump_base(base); | 701 isolate->set_long_jump_base(base); |
| (...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 997 ASSERT(!cls.IsSignatureClass()); | 997 ASSERT(!cls.IsSignatureClass()); |
| 998 if (!IsSuperCycleFree(cls)) { | 998 if (!IsSuperCycleFree(cls)) { |
| 999 const String& name = String::Handle(cls.Name()); | 999 const String& name = String::Handle(cls.Name()); |
| 1000 const Script& script = Script::Handle(cls.script()); | 1000 const Script& script = Script::Handle(cls.script()); |
| 1001 ReportError(script, -1, | 1001 ReportError(script, -1, |
| 1002 "class '%s' has a cycle in its superclass relationship.\n", | 1002 "class '%s' has a cycle in its superclass relationship.\n", |
| 1003 name.ToCString()); | 1003 name.ToCString()); |
| 1004 } | 1004 } |
| 1005 GrowableArray<const Class*> visited; | 1005 GrowableArray<const Class*> visited; |
| 1006 ResolveInterfaces(cls, &visited); | 1006 ResolveInterfaces(cls, &visited); |
| 1007 AbstractType& super_type = AbstractType::Handle(cls.super_type()); | 1007 Type& super_type = Type::Handle(cls.super_type()); |
| 1008 if (!super_type.IsNull()) { | 1008 if (!super_type.IsNull()) { |
| 1009 const Class& super_class = Class::Handle(super_type.type_class()); | 1009 const Class& super_class = Class::Handle(super_type.type_class()); |
| 1010 // Finalize super class and super type. | 1010 // Finalize super class and super type. |
| 1011 FinalizeClass(super_class, generating_snapshot); | 1011 FinalizeClass(super_class, generating_snapshot); |
| 1012 super_type = FinalizeType(super_type); | 1012 super_type ^= FinalizeType(super_type); |
| 1013 cls.set_super_type(super_type); | 1013 cls.set_super_type(super_type); |
| 1014 } | 1014 } |
| 1015 if (cls.is_interface()) { | 1015 if (cls.is_interface()) { |
| 1016 if (cls.HasFactoryClass()) { | 1016 if (cls.HasFactoryClass()) { |
| 1017 const Class& factory_class = Class::Handle(cls.FactoryClass()); | 1017 const Class& factory_class = Class::Handle(cls.FactoryClass()); |
| 1018 // Finalize factory class. | 1018 // Finalize factory class. |
| 1019 if (!factory_class.is_finalized()) { | 1019 if (!factory_class.is_finalized()) { |
| 1020 FinalizeClass(factory_class, generating_snapshot); | 1020 FinalizeClass(factory_class, generating_snapshot); |
| 1021 // Finalizing the factory class may indirectly finalize this interface. | 1021 // Finalizing the factory class may indirectly finalize this interface. |
| 1022 if (cls.is_finalized()) { | 1022 if (cls.is_finalized()) { |
| (...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1309 va_end(args); | 1309 va_end(args); |
| 1310 if (FLAG_warning_as_error) { | 1310 if (FLAG_warning_as_error) { |
| 1311 Isolate::Current()->long_jump_base()->Jump(1, message_buffer); | 1311 Isolate::Current()->long_jump_base()->Jump(1, message_buffer); |
| 1312 UNREACHABLE(); | 1312 UNREACHABLE(); |
| 1313 } else { | 1313 } else { |
| 1314 OS::Print(message_buffer); | 1314 OS::Print(message_buffer); |
| 1315 } | 1315 } |
| 1316 } | 1316 } |
| 1317 | 1317 |
| 1318 } // namespace dart | 1318 } // namespace dart |
| OLD | NEW |