| 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 ResolveType(cls, super_type); |
| 301 if (super_type.IsTypeParameter()) { | |
| 302 String& class_name = String::Handle(cls.Name()); | |
| 303 String& type_parameter_name = String::Handle(super_type.Name()); | |
| 304 ReportError("'%s' cannot extend or implement type parameter '%s'.\n", | |
| 305 class_name.ToCString(), | |
| 306 type_parameter_name.ToCString()); | |
| 307 } | |
| 308 cls.set_super_type(super_type); | |
| 309 const Class& super_class = Class::Handle(super_type.type_class()); | 301 const Class& super_class = Class::Handle(super_type.type_class()); |
| 310 if (cls.is_interface() != super_class.is_interface()) { | 302 if (cls.is_interface() != super_class.is_interface()) { |
| 311 String& class_name = String::Handle(cls.Name()); | 303 String& class_name = String::Handle(cls.Name()); |
| 312 String& super_class_name = String::Handle(super_class.Name()); | 304 String& super_class_name = String::Handle(super_class.Name()); |
| 313 const Script& script = Script::Handle(cls.script()); | 305 const Script& script = Script::Handle(cls.script()); |
| 314 ReportError(script, -1, | 306 ReportError(script, -1, |
| 315 "class '%s' and superclass '%s' are not " | 307 "class '%s' and superclass '%s' are not " |
| 316 "both classes or both interfaces.\n", | 308 "both classes or both interfaces.\n", |
| 317 class_name.ToCString(), | 309 class_name.ToCString(), |
| 318 super_class_name.ToCString()); | 310 super_class_name.ToCString()); |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 434 ReportError(script, unresolved_factory_class.token_index(), | 426 ReportError(script, unresolved_factory_class.token_index(), |
| 435 "mismatch in number or names of type parameters between " | 427 "mismatch in number or names of type parameters between " |
| 436 "factory clause of interface '%s' and actual factory " | 428 "factory clause of interface '%s' and actual factory " |
| 437 "class '%s'.\n", | 429 "class '%s'.\n", |
| 438 interface_name.ToCString(), | 430 interface_name.ToCString(), |
| 439 factory_name.ToCString()); | 431 factory_name.ToCString()); |
| 440 } | 432 } |
| 441 } | 433 } |
| 442 | 434 |
| 443 | 435 |
| 444 // TODO(regis): Now that we do not resolve type parameters anymore, we could | 436 void ClassFinalizer::ResolveType(const Class& cls, const AbstractType& type) { |
| 445 // make this function void and resolve the type in place. | |
| 446 RawAbstractType* ClassFinalizer::ResolveType( | |
| 447 const Class& cls, const AbstractType& type) { | |
| 448 if (type.IsResolved()) { | 437 if (type.IsResolved()) { |
| 449 return type.raw(); | 438 return; |
| 450 } | 439 } |
| 451 if (FLAG_trace_type_finalization) { | 440 if (FLAG_trace_type_finalization) { |
| 452 OS::Print("Resolve type '%s'\n", String::Handle(type.Name()).ToCString()); | 441 OS::Print("Resolve type '%s'\n", String::Handle(type.Name()).ToCString()); |
| 453 } | 442 } |
| 454 | 443 |
| 455 // Resolve the type class. | 444 // Resolve the type class. |
| 456 if (!type.HasResolvedTypeClass()) { | 445 if (!type.HasResolvedTypeClass()) { |
| 457 // Type parameters are always resolved in the parser in the correct | 446 // Type parameters are always resolved in the parser in the correct |
| 458 // non-static scope or factory scope. That resolution scope is unknown here. | 447 // non-static scope or factory scope. That resolution scope is unknown here. |
| 459 // Being able to resolve a type parameter from class cls here would indicate | 448 // Being able to resolve a type parameter from class cls here would indicate |
| (...skipping 13 matching lines...) Expand all Loading... |
| 473 parameterized_type.set_type_class(Object::Handle(type_class.raw())); | 462 parameterized_type.set_type_class(Object::Handle(type_class.raw())); |
| 474 } | 463 } |
| 475 | 464 |
| 476 // Resolve type arguments, if any. | 465 // Resolve type arguments, if any. |
| 477 const TypeArguments& arguments = TypeArguments::Handle(type.arguments()); | 466 const TypeArguments& arguments = TypeArguments::Handle(type.arguments()); |
| 478 if (!arguments.IsNull()) { | 467 if (!arguments.IsNull()) { |
| 479 intptr_t num_arguments = arguments.Length(); | 468 intptr_t num_arguments = arguments.Length(); |
| 480 AbstractType& type_argument = AbstractType::Handle(); | 469 AbstractType& type_argument = AbstractType::Handle(); |
| 481 for (intptr_t i = 0; i < num_arguments; i++) { | 470 for (intptr_t i = 0; i < num_arguments; i++) { |
| 482 type_argument = arguments.TypeAt(i); | 471 type_argument = arguments.TypeAt(i); |
| 483 type_argument = ResolveType(cls, type_argument); | 472 ResolveType(cls, type_argument); |
| 484 arguments.SetTypeAt(i, type_argument); | |
| 485 } | 473 } |
| 486 } | 474 } |
| 487 return type.raw(); | |
| 488 } | 475 } |
| 489 | 476 |
| 490 | 477 |
| 491 // Finalize the type argument vector 'arguments' of the type defined by the | 478 // Finalize the type argument vector 'arguments' of the type defined by the |
| 492 // class 'cls' parameterized with the type arguments 'cls_args'. | 479 // class 'cls' parameterized with the type arguments 'cls_args'. |
| 493 // The vector 'cls_args' is already initialized as a subvector at the correct | 480 // The vector 'cls_args' is already initialized as a subvector at the correct |
| 494 // position in the passed in 'arguments' vector. | 481 // position in the passed in 'arguments' vector. |
| 495 // The subvector 'cls_args' has length cls.NumTypeParameters() and starts at | 482 // The subvector 'cls_args' has length cls.NumTypeParameters() and starts at |
| 496 // offset cls.NumTypeArguments() - cls.NumTypeParameters() of the 'arguments' | 483 // offset cls.NumTypeArguments() - cls.NumTypeParameters() of the 'arguments' |
| 497 // vector. | 484 // vector. |
| 498 // Example: | 485 // Example: |
| 499 // Declared: class C<K, V> extends B<V> { ... } | 486 // Declared: class C<K, V> extends B<V> { ... } |
| 500 // class B<T> extends Array<int> { ... } | 487 // class B<T> extends Array<int> { ... } |
| 501 // Input: C<String, double> expressed as | 488 // Input: C<String, double> expressed as |
| 502 // cls = C, arguments = [null, null, String, double], | 489 // cls = C, arguments = [null, null, String, double], |
| 503 // i.e. cls_args = [String, double], offset = 2, length = 2. | 490 // i.e. cls_args = [String, double], offset = 2, length = 2. |
| 504 // Output: arguments = [int, double, String, double] | 491 // Output: arguments = [int, double, String, double] |
| 505 void ClassFinalizer::FinalizeTypeArguments(const Class& cls, | 492 void ClassFinalizer::FinalizeTypeArguments(const Class& cls, |
| 506 const TypeArguments& arguments) { | 493 const TypeArguments& arguments) { |
| 507 ASSERT(arguments.Length() >= cls.NumTypeArguments()); | 494 ASSERT(arguments.Length() >= cls.NumTypeArguments()); |
| 508 AbstractType& super_type = AbstractType::Handle(cls.super_type()); | 495 Type& super_type = Type::Handle(cls.super_type()); |
| 509 if (!super_type.IsNull()) { | 496 if (!super_type.IsNull()) { |
| 510 super_type = FinalizeType(super_type); | 497 super_type ^= FinalizeType(super_type); |
| 511 cls.set_super_type(super_type); | 498 cls.set_super_type(super_type); |
| 512 const Class& super_class = Class::Handle(super_type.type_class()); | 499 const Class& super_class = Class::Handle(super_type.type_class()); |
| 513 const TypeArguments& super_type_args = | 500 const TypeArguments& super_type_args = |
| 514 TypeArguments::Handle(super_type.arguments()); | 501 TypeArguments::Handle(super_type.arguments()); |
| 515 const intptr_t num_super_type_params = super_class.NumTypeParameters(); | 502 const intptr_t num_super_type_params = super_class.NumTypeParameters(); |
| 516 const intptr_t offset = super_class.NumTypeArguments(); | 503 const intptr_t offset = super_class.NumTypeArguments(); |
| 517 const intptr_t super_offset = offset - num_super_type_params; | 504 const intptr_t super_offset = offset - num_super_type_params; |
| 518 ASSERT(offset == (cls.NumTypeArguments() - cls.NumTypeParameters())); | 505 ASSERT(offset == (cls.NumTypeArguments() - cls.NumTypeParameters())); |
| 519 AbstractType& super_type_arg = AbstractType::Handle(); | 506 AbstractType& super_type_arg = AbstractType::Handle(); |
| 520 for (intptr_t i = 0; i < num_super_type_params; i++) { | 507 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, | 548 ReportError(script, -1, |
| 562 "type argument '%s' of class '%s' " | 549 "type argument '%s' of class '%s' " |
| 563 "does not extend type '%s'\n", | 550 "does not extend type '%s'\n", |
| 564 type_argument_name.ToCString(), | 551 type_argument_name.ToCString(), |
| 565 class_name.ToCString(), | 552 class_name.ToCString(), |
| 566 extends_name.ToCString()); | 553 extends_name.ToCString()); |
| 567 } | 554 } |
| 568 } | 555 } |
| 569 } | 556 } |
| 570 } | 557 } |
| 571 AbstractType& super_type = AbstractType::Handle(cls.super_type()); | 558 const Type& super_type = Type::Handle(cls.super_type()); |
| 572 if (!super_type.IsNull()) { | 559 if (!super_type.IsNull()) { |
| 573 ASSERT(super_type.IsFinalized()); | 560 ASSERT(super_type.IsFinalized()); |
| 574 const Class& super_class = Class::Handle(super_type.type_class()); | 561 const Class& super_class = Class::Handle(super_type.type_class()); |
| 575 VerifyUpperBounds(super_class, arguments); | 562 VerifyUpperBounds(super_class, arguments); |
| 576 } | 563 } |
| 577 } | 564 } |
| 578 | 565 |
| 579 | 566 |
| 580 RawAbstractType* ClassFinalizer::FinalizeType(const AbstractType& type) { | 567 RawAbstractType* ClassFinalizer::FinalizeType(const AbstractType& type) { |
| 581 ASSERT(type.IsResolved()); | 568 ASSERT(type.IsResolved()); |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 681 if (FLAG_enable_type_checks) { | 668 if (FLAG_enable_type_checks) { |
| 682 VerifyUpperBounds(type_class, full_arguments); | 669 VerifyUpperBounds(type_class, full_arguments); |
| 683 } | 670 } |
| 684 } else { | 671 } else { |
| 685 parameterized_type.set_is_finalized(); | 672 parameterized_type.set_is_finalized(); |
| 686 } | 673 } |
| 687 return parameterized_type.Canonicalize(); | 674 return parameterized_type.Canonicalize(); |
| 688 } | 675 } |
| 689 | 676 |
| 690 | 677 |
| 691 RawAbstractType* ClassFinalizer::FinalizeAndCanonicalizeType( | 678 RawType* ClassFinalizer::FinalizeAndCanonicalizeType(const Type& type, |
| 692 const AbstractType& type, String* errmsg) { | 679 String* errmsg) { |
| 693 Isolate* isolate = Isolate::Current(); | 680 Isolate* isolate = Isolate::Current(); |
| 694 ASSERT(isolate != NULL); | 681 ASSERT(isolate != NULL); |
| 695 LongJump* base = isolate->long_jump_base(); | 682 LongJump* base = isolate->long_jump_base(); |
| 696 LongJump jump; | 683 LongJump jump; |
| 697 isolate->set_long_jump_base(&jump); | 684 isolate->set_long_jump_base(&jump); |
| 698 if (setjmp(*jump.Set()) == 0) { | 685 if (setjmp(*jump.Set()) == 0) { |
| 699 const AbstractType& canonical_type = | 686 Type& canonical_type = Type::Handle(); |
| 700 AbstractType::Handle(FinalizeType(type)); | 687 canonical_type ^= FinalizeType(type); |
| 701 isolate->set_long_jump_base(base); | 688 isolate->set_long_jump_base(base); |
| 702 *errmsg = String::null(); | 689 *errmsg = String::null(); |
| 703 return canonical_type.raw(); | 690 return canonical_type.raw(); |
| 704 } else { | 691 } else { |
| 705 // Error occured: Get the error message. | 692 // Error occured: Get the error message. |
| 706 isolate->set_long_jump_base(base); | 693 isolate->set_long_jump_base(base); |
| 707 *errmsg = isolate->object_store()->sticky_error(); | 694 *errmsg = isolate->object_store()->sticky_error(); |
| 708 return type.raw(); | 695 return type.raw(); |
| 709 } | 696 } |
| 710 UNREACHABLE(); | 697 UNREACHABLE(); |
| 711 return NULL; | 698 return NULL; |
| 712 } | 699 } |
| 713 | 700 |
| 714 | 701 |
| 715 void ClassFinalizer::ResolveAndFinalizeSignature(const Class& cls, | 702 void ClassFinalizer::ResolveAndFinalizeSignature(const Class& cls, |
| 716 const Function& function) { | 703 const Function& function) { |
| 717 // Resolve result type. | 704 // Resolve result type. |
| 718 AbstractType& type = AbstractType::Handle(function.result_type()); | 705 AbstractType& type = AbstractType::Handle(function.result_type()); |
| 719 if (!type.IsResolved()) { | 706 if (!type.IsResolved()) { |
| 720 if (function.IsFactory()) { | 707 if (function.IsFactory()) { |
| 721 // The signature class of the factory for a generic class holds the type | 708 // The signature class of the factory for a generic class holds the type |
| 722 // parameters and their upper bounds. Copy the signature class from the | 709 // parameters and their upper bounds. Copy the signature class from the |
| 723 // result before it gets resolved. | 710 // result before it gets resolved. |
| 724 const UnresolvedClass& unresolved_type_class = | 711 const UnresolvedClass& unresolved_type_class = |
| 725 UnresolvedClass::Handle(type.unresolved_class()); | 712 UnresolvedClass::Handle(type.unresolved_class()); |
| 726 const Class& factory_signature_class = | 713 const Class& factory_signature_class = |
| 727 Class::Handle(unresolved_type_class.factory_signature_class()); | 714 Class::Handle(unresolved_type_class.factory_signature_class()); |
| 728 ASSERT(!factory_signature_class.IsNull()); | 715 ASSERT(!factory_signature_class.IsNull()); |
| 729 function.set_signature_class(factory_signature_class); | 716 function.set_signature_class(factory_signature_class); |
| 730 type = ResolveType(cls, type); | 717 ResolveType(cls, type); |
| 731 function.set_result_type(type); | |
| 732 const Class& type_class = Class::Handle(type.type_class()); | 718 const Class& type_class = Class::Handle(type.type_class()); |
| 733 // Verify that the factory signature declares the same number of type | 719 // Verify that the factory signature declares the same number of type |
| 734 // parameters as the return type class or interface. | 720 // parameters as the return type class or interface. |
| 735 ResolveAndFinalizeUpperBounds(factory_signature_class); | 721 ResolveAndFinalizeUpperBounds(factory_signature_class); |
| 736 if (factory_signature_class.NumTypeParameters() != | 722 if (factory_signature_class.NumTypeParameters() != |
| 737 type_class.NumTypeParameters()) { | 723 type_class.NumTypeParameters()) { |
| 738 const String& function_name = String::Handle(function.name()); | 724 const String& function_name = String::Handle(function.name()); |
| 739 if (factory_signature_class.NumTypeParameters() == 0) { | 725 if (factory_signature_class.NumTypeParameters() == 0) { |
| 740 // TODO(regis): For now, and until the core lib is fixed, we accept a | 726 // TODO(regis): For now, and until the core lib is fixed, we accept a |
| 741 // factory method with missing list of type parameters and use the | 727 // factory method with missing list of type parameters and use the |
| (...skipping 12 matching lines...) Expand all Loading... |
| 754 const Class& enclosing_class = Class::Handle(function.owner()); | 740 const Class& enclosing_class = Class::Handle(function.owner()); |
| 755 const Script& script = Script::Handle(enclosing_class.script()); | 741 const Script& script = Script::Handle(enclosing_class.script()); |
| 756 ReportError(script, unresolved_type_class.token_index(), | 742 ReportError(script, unresolved_type_class.token_index(), |
| 757 "factory method '%s' must declare %d type parameter%s.\n", | 743 "factory method '%s' must declare %d type parameter%s.\n", |
| 758 function_name.ToCString(), | 744 function_name.ToCString(), |
| 759 type_class.NumTypeParameters(), | 745 type_class.NumTypeParameters(), |
| 760 type_class.NumTypeParameters() > 1 ? "s" : ""); | 746 type_class.NumTypeParameters() > 1 ? "s" : ""); |
| 761 } | 747 } |
| 762 } | 748 } |
| 763 } else { | 749 } else { |
| 764 type = ResolveType(cls, type); | 750 ResolveType(cls, type); |
| 765 function.set_result_type(type); | |
| 766 } | 751 } |
| 767 } | 752 } |
| 768 type = FinalizeType(type); | 753 type = FinalizeType(type); |
| 769 function.set_result_type(type); | 754 function.set_result_type(type); |
| 770 // Resolve formal parameter types. | 755 // Resolve formal parameter types. |
| 771 const intptr_t num_parameters = function.NumberOfParameters(); | 756 const intptr_t num_parameters = function.NumberOfParameters(); |
| 772 for (intptr_t i = 0; i < num_parameters; i++) { | 757 for (intptr_t i = 0; i < num_parameters; i++) { |
| 773 type = function.ParameterTypeAt(i); | 758 type = function.ParameterTypeAt(i); |
| 774 type = ResolveType(cls, type); | 759 ResolveType(cls, type); |
| 775 function.SetParameterTypeAt(i, type); | |
| 776 type = FinalizeType(type); | 760 type = FinalizeType(type); |
| 777 function.SetParameterTypeAt(i, type); | 761 function.SetParameterTypeAt(i, type); |
| 778 } | 762 } |
| 779 } | 763 } |
| 780 | 764 |
| 781 | 765 |
| 782 static RawClass* FindSuperOwnerOfInstanceMember(const Class& cls, | 766 static RawClass* FindSuperOwnerOfInstanceMember(const Class& cls, |
| 783 const String& name) { | 767 const String& name) { |
| 784 Class& super_class = Class::Handle(); | 768 Class& super_class = Class::Handle(); |
| 785 Function& function = Function::Handle(); | 769 Function& function = Function::Handle(); |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 821 // Resolve and finalize the upper bounds of the type parameters of class cls. | 805 // Resolve and finalize the upper bounds of the type parameters of class cls. |
| 822 void ClassFinalizer::ResolveAndFinalizeUpperBounds(const Class& cls) { | 806 void ClassFinalizer::ResolveAndFinalizeUpperBounds(const Class& cls) { |
| 823 const intptr_t num_type_params = cls.NumTypeParameters(); | 807 const intptr_t num_type_params = cls.NumTypeParameters(); |
| 824 AbstractType& type_extends = AbstractType::Handle(); | 808 AbstractType& type_extends = AbstractType::Handle(); |
| 825 const TypeArguments& extends_array = | 809 const TypeArguments& extends_array = |
| 826 TypeArguments::Handle(cls.type_parameter_extends()); | 810 TypeArguments::Handle(cls.type_parameter_extends()); |
| 827 ASSERT((extends_array.IsNull() && (num_type_params == 0)) || | 811 ASSERT((extends_array.IsNull() && (num_type_params == 0)) || |
| 828 (extends_array.Length() == num_type_params)); | 812 (extends_array.Length() == num_type_params)); |
| 829 for (intptr_t i = 0; i < num_type_params; i++) { | 813 for (intptr_t i = 0; i < num_type_params; i++) { |
| 830 type_extends = extends_array.TypeAt(i); | 814 type_extends = extends_array.TypeAt(i); |
| 831 type_extends = ResolveType(cls, type_extends); | 815 ResolveType(cls, type_extends); |
| 832 extends_array.SetTypeAt(i, type_extends); | |
| 833 type_extends = FinalizeType(type_extends); | 816 type_extends = FinalizeType(type_extends); |
| 834 extends_array.SetTypeAt(i, type_extends); | 817 extends_array.SetTypeAt(i, type_extends); |
| 835 } | 818 } |
| 836 } | 819 } |
| 837 | 820 |
| 838 | 821 |
| 839 void ClassFinalizer::ResolveAndFinalizeMemberTypes(const Class& cls) { | 822 void ClassFinalizer::ResolveAndFinalizeMemberTypes(const Class& cls) { |
| 840 // Note that getters and setters are explicitly listed as such in the list of | 823 // Note that getters and setters are explicitly listed as such in the list of |
| 841 // functions of a class, so we do not need to consider fields as implicitly | 824 // functions of a class, so we do not need to consider fields as implicitly |
| 842 // generating getters and setters. | 825 // generating getters and setters. |
| 843 // The only compile errors we report are therefore: | 826 // The only compile errors we report are therefore: |
| 844 // - a getter having the same name as a method (but not a getter) in a super | 827 // - a getter having the same name as a method (but not a getter) in a super |
| 845 // class or in a subclass. | 828 // class or in a subclass. |
| 846 // - a setter having the same name as a method (but not a setter) in a super | 829 // - a setter having the same name as a method (but not a setter) in a super |
| 847 // class or in a subclass. | 830 // class or in a subclass. |
| 848 // - a static field, instance field, or static method (but not an instance | 831 // - a static field, instance field, or static method (but not an instance |
| 849 // method) having the same name as an instance member in a super class. | 832 // method) having the same name as an instance member in a super class. |
| 850 | 833 |
| 851 // Resolve type of fields and check for conflicts in super classes. | 834 // Resolve type of fields and check for conflicts in super classes. |
| 852 Array& array = Array::Handle(cls.fields()); | 835 Array& array = Array::Handle(cls.fields()); |
| 853 Field& field = Field::Handle(); | 836 Field& field = Field::Handle(); |
| 854 AbstractType& type = AbstractType::Handle(); | 837 AbstractType& type = AbstractType::Handle(); |
| 855 String& name = String::Handle(); | 838 String& name = String::Handle(); |
| 856 Class& super_class = Class::Handle(); | 839 Class& super_class = Class::Handle(); |
| 857 intptr_t num_fields = array.Length(); | 840 intptr_t num_fields = array.Length(); |
| 858 for (intptr_t i = 0; i < num_fields; i++) { | 841 for (intptr_t i = 0; i < num_fields; i++) { |
| 859 field ^= array.At(i); | 842 field ^= array.At(i); |
| 860 type = field.type(); | 843 type = field.type(); |
| 861 type = ResolveType(cls, type); | 844 ResolveType(cls, type); |
| 862 field.set_type(type); | |
| 863 type = FinalizeType(type); | 845 type = FinalizeType(type); |
| 864 field.set_type(type); | 846 field.set_type(type); |
| 865 name = field.name(); | 847 name = field.name(); |
| 866 super_class = FindSuperOwnerOfInstanceMember(cls, name); | 848 super_class = FindSuperOwnerOfInstanceMember(cls, name); |
| 867 if (!super_class.IsNull()) { | 849 if (!super_class.IsNull()) { |
| 868 const String& class_name = String::Handle(cls.Name()); | 850 const String& class_name = String::Handle(cls.Name()); |
| 869 const String& super_class_name = String::Handle(super_class.Name()); | 851 const String& super_class_name = String::Handle(super_class.Name()); |
| 870 const Script& script = Script::Handle(cls.script()); | 852 const Script& script = Script::Handle(cls.script()); |
| 871 ReportError(script, field.token_index(), | 853 ReportError(script, field.token_index(), |
| 872 "field '%s' of class '%s' conflicts with instance " | 854 "field '%s' of class '%s' conflicts with instance " |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 997 ASSERT(!cls.IsSignatureClass()); | 979 ASSERT(!cls.IsSignatureClass()); |
| 998 if (!IsSuperCycleFree(cls)) { | 980 if (!IsSuperCycleFree(cls)) { |
| 999 const String& name = String::Handle(cls.Name()); | 981 const String& name = String::Handle(cls.Name()); |
| 1000 const Script& script = Script::Handle(cls.script()); | 982 const Script& script = Script::Handle(cls.script()); |
| 1001 ReportError(script, -1, | 983 ReportError(script, -1, |
| 1002 "class '%s' has a cycle in its superclass relationship.\n", | 984 "class '%s' has a cycle in its superclass relationship.\n", |
| 1003 name.ToCString()); | 985 name.ToCString()); |
| 1004 } | 986 } |
| 1005 GrowableArray<const Class*> visited; | 987 GrowableArray<const Class*> visited; |
| 1006 ResolveInterfaces(cls, &visited); | 988 ResolveInterfaces(cls, &visited); |
| 1007 AbstractType& super_type = AbstractType::Handle(cls.super_type()); | 989 Type& super_type = Type::Handle(cls.super_type()); |
| 1008 if (!super_type.IsNull()) { | 990 if (!super_type.IsNull()) { |
| 1009 const Class& super_class = Class::Handle(super_type.type_class()); | 991 const Class& super_class = Class::Handle(super_type.type_class()); |
| 1010 // Finalize super class and super type. | 992 // Finalize super class and super type. |
| 1011 FinalizeClass(super_class, generating_snapshot); | 993 FinalizeClass(super_class, generating_snapshot); |
| 1012 super_type = FinalizeType(super_type); | 994 super_type ^= FinalizeType(super_type); |
| 1013 cls.set_super_type(super_type); | 995 cls.set_super_type(super_type); |
| 1014 } | 996 } |
| 1015 if (cls.is_interface()) { | 997 if (cls.is_interface()) { |
| 1016 if (cls.HasFactoryClass()) { | 998 if (cls.HasFactoryClass()) { |
| 1017 const Class& factory_class = Class::Handle(cls.FactoryClass()); | 999 const Class& factory_class = Class::Handle(cls.FactoryClass()); |
| 1018 // Finalize factory class. | 1000 // Finalize factory class. |
| 1019 if (!factory_class.is_finalized()) { | 1001 if (!factory_class.is_finalized()) { |
| 1020 FinalizeClass(factory_class, generating_snapshot); | 1002 FinalizeClass(factory_class, generating_snapshot); |
| 1021 // Finalizing the factory class may indirectly finalize this interface. | 1003 // Finalizing the factory class may indirectly finalize this interface. |
| 1022 if (cls.is_finalized()) { | 1004 if (cls.is_finalized()) { |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1149 // about allowed interfaces are lifted. | 1131 // about allowed interfaces are lifted. |
| 1150 const bool cls_belongs_to_core_lib = | 1132 const bool cls_belongs_to_core_lib = |
| 1151 (cls.library() == Library::CoreLibrary()) || | 1133 (cls.library() == Library::CoreLibrary()) || |
| 1152 (cls.library() == Library::CoreImplLibrary()); | 1134 (cls.library() == Library::CoreImplLibrary()); |
| 1153 | 1135 |
| 1154 // Resolve and check the interfaces of cls. | 1136 // Resolve and check the interfaces of cls. |
| 1155 visited->Add(&cls); | 1137 visited->Add(&cls); |
| 1156 AbstractType& interface = AbstractType::Handle(); | 1138 AbstractType& interface = AbstractType::Handle(); |
| 1157 for (intptr_t i = 0; i < super_interfaces.Length(); i++) { | 1139 for (intptr_t i = 0; i < super_interfaces.Length(); i++) { |
| 1158 interface ^= super_interfaces.At(i); | 1140 interface ^= super_interfaces.At(i); |
| 1159 interface = ResolveType(cls, interface); | 1141 ResolveType(cls, interface); |
| 1160 super_interfaces.SetAt(i, interface); | |
| 1161 if (interface.IsTypeParameter()) { | 1142 if (interface.IsTypeParameter()) { |
| 1162 const Script& script = Script::Handle(cls.script()); | 1143 const Script& script = Script::Handle(cls.script()); |
| 1163 ReportError(script, -1, | 1144 ReportError(script, -1, |
| 1164 "Type parameter '%s' cannot be used as interface\n", | 1145 "Type parameter '%s' cannot be used as interface\n", |
| 1165 String::Handle(interface.Name()).ToCString()); | 1146 String::Handle(interface.Name()).ToCString()); |
| 1166 } | 1147 } |
| 1167 const Class& interface_class = Class::Handle(interface.type_class()); | 1148 const Class& interface_class = Class::Handle(interface.type_class()); |
| 1168 if (!interface_class.is_interface()) { | 1149 if (!interface_class.is_interface()) { |
| 1169 const Script& script = Script::Handle(cls.script()); | 1150 const Script& script = Script::Handle(cls.script()); |
| 1170 ReportError(script, -1, | 1151 ReportError(script, -1, |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1309 va_end(args); | 1290 va_end(args); |
| 1310 if (FLAG_warning_as_error) { | 1291 if (FLAG_warning_as_error) { |
| 1311 Isolate::Current()->long_jump_base()->Jump(1, message_buffer); | 1292 Isolate::Current()->long_jump_base()->Jump(1, message_buffer); |
| 1312 UNREACHABLE(); | 1293 UNREACHABLE(); |
| 1313 } else { | 1294 } else { |
| 1314 OS::Print(message_buffer); | 1295 OS::Print(message_buffer); |
| 1315 } | 1296 } |
| 1316 } | 1297 } |
| 1317 | 1298 |
| 1318 } // namespace dart | 1299 } // namespace dart |
| OLD | NEW |