| 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 467 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 478 | 478 |
| 479 // Finalize the type argument vector 'arguments' of the type defined by the | 479 // Finalize the type argument vector 'arguments' of the type defined by the |
| 480 // class 'cls' parameterized with the type arguments 'cls_args'. | 480 // class 'cls' parameterized with the type arguments 'cls_args'. |
| 481 // The vector 'cls_args' is already initialized as a subvector at the correct | 481 // The vector 'cls_args' is already initialized as a subvector at the correct |
| 482 // position in the passed in 'arguments' vector. | 482 // position in the passed in 'arguments' vector. |
| 483 // The subvector 'cls_args' has length cls.NumTypeParameters() and starts at | 483 // The subvector 'cls_args' has length cls.NumTypeParameters() and starts at |
| 484 // offset cls.NumTypeArguments() - cls.NumTypeParameters() of the 'arguments' | 484 // offset cls.NumTypeArguments() - cls.NumTypeParameters() of the 'arguments' |
| 485 // vector. | 485 // vector. |
| 486 // Example: | 486 // Example: |
| 487 // Declared: class C<K, V> extends B<V> { ... } | 487 // Declared: class C<K, V> extends B<V> { ... } |
| 488 // class B<T> extends Array<int> { ... } | 488 // class B<T> extends A<int> { ... } |
| 489 // Input: C<String, double> expressed as | 489 // Input: C<String, double> expressed as |
| 490 // cls = C, arguments = [null, null, String, double], | 490 // cls = C, arguments = [null, null, String, double], |
| 491 // i.e. cls_args = [String, double], offset = 2, length = 2. | 491 // i.e. cls_args = [String, double], offset = 2, length = 2. |
| 492 // Output: arguments = [int, double, String, double] | 492 // Output: arguments = [int, double, String, double] |
| 493 void ClassFinalizer::FinalizeTypeArguments( | 493 void ClassFinalizer::FinalizeTypeArguments( |
| 494 const Class& cls, const AbstractTypeArguments& arguments) { | 494 const Class& cls, const AbstractTypeArguments& arguments) { |
| 495 ASSERT(arguments.Length() >= cls.NumTypeArguments()); | 495 ASSERT(arguments.Length() >= cls.NumTypeArguments()); |
| 496 Type& super_type = Type::Handle(cls.super_type()); | 496 Type& super_type = Type::Handle(cls.super_type()); |
| 497 if (!super_type.IsNull()) { | 497 if (!super_type.IsNull()) { |
| 498 super_type ^= FinalizeType(super_type); | 498 super_type ^= FinalizeType(cls, super_type); |
| 499 cls.set_super_type(super_type); | 499 cls.set_super_type(super_type); |
| 500 const Class& super_class = Class::Handle(super_type.type_class()); | 500 const Class& super_class = Class::Handle(super_type.type_class()); |
| 501 const AbstractTypeArguments& super_type_args = | 501 const AbstractTypeArguments& super_type_args = |
| 502 AbstractTypeArguments::Handle(super_type.arguments()); | 502 AbstractTypeArguments::Handle(super_type.arguments()); |
| 503 const intptr_t num_super_type_params = super_class.NumTypeParameters(); | 503 const intptr_t num_super_type_params = super_class.NumTypeParameters(); |
| 504 const intptr_t offset = super_class.NumTypeArguments(); | 504 const intptr_t offset = super_class.NumTypeArguments(); |
| 505 const intptr_t super_offset = offset - num_super_type_params; | 505 const intptr_t super_offset = offset - num_super_type_params; |
| 506 ASSERT(offset == (cls.NumTypeArguments() - cls.NumTypeParameters())); | 506 ASSERT(offset == (cls.NumTypeArguments() - cls.NumTypeParameters())); |
| 507 AbstractType& super_type_arg = AbstractType::Handle(); | 507 AbstractType& super_type_arg = AbstractType::Handle(); |
| 508 for (intptr_t i = 0; i < num_super_type_params; i++) { | 508 for (intptr_t i = 0; i < num_super_type_params; i++) { |
| 509 super_type_arg = super_type_args.TypeAt(super_offset + i); | 509 super_type_arg = super_type_args.TypeAt(super_offset + i); |
| 510 if (!super_type_arg.IsInstantiated()) { | 510 if (!super_type_arg.IsInstantiated()) { |
| 511 super_type_arg = super_type_arg.InstantiateFrom(arguments, offset); | 511 super_type_arg = super_type_arg.InstantiateFrom(arguments); |
| 512 } | 512 } |
| 513 super_type_arg = super_type_arg.Canonicalize(); | 513 super_type_arg = super_type_arg.Canonicalize(); |
| 514 arguments.SetTypeAt(super_offset + i, super_type_arg); | 514 arguments.SetTypeAt(super_offset + i, super_type_arg); |
| 515 } | 515 } |
| 516 FinalizeTypeArguments(super_class, arguments); | 516 FinalizeTypeArguments(super_class, arguments); |
| 517 } | 517 } |
| 518 } | 518 } |
| 519 | 519 |
| 520 | 520 |
| 521 // Verify the upper bounds of the type arguments of class cls. | 521 // Verify the upper bounds of the type arguments of class cls. |
| 522 void ClassFinalizer::VerifyUpperBounds(const Class& cls, | 522 void ClassFinalizer::VerifyUpperBounds(const Class& cls, |
| 523 const AbstractTypeArguments& arguments) { | 523 const AbstractTypeArguments& arguments) { |
| 524 ASSERT(FLAG_enable_type_checks); | 524 ASSERT(FLAG_enable_type_checks); |
| 525 ASSERT(arguments.Length() >= cls.NumTypeArguments()); | 525 ASSERT(arguments.Length() >= cls.NumTypeArguments()); |
| 526 const intptr_t num_type_params = cls.NumTypeParameters(); | 526 const intptr_t num_type_params = cls.NumTypeParameters(); |
| 527 const intptr_t offset = cls.NumTypeArguments() - num_type_params; | 527 const intptr_t offset = cls.NumTypeArguments() - num_type_params; |
| 528 AbstractType& type = AbstractType::Handle(); | 528 AbstractType& type = AbstractType::Handle(); |
| 529 AbstractType& type_extends = AbstractType::Handle(); | 529 AbstractType& type_extends = AbstractType::Handle(); |
| 530 const AbstractTypeArguments& extends_array = | 530 const AbstractTypeArguments& extends_array = |
| 531 AbstractTypeArguments::Handle(cls.type_parameter_extends()); | 531 AbstractTypeArguments::Handle(cls.type_parameter_extends()); |
| 532 ASSERT((extends_array.IsNull() && (num_type_params == 0)) || | 532 ASSERT((extends_array.IsNull() && (num_type_params == 0)) || |
| 533 (extends_array.Length() == num_type_params)); | 533 (extends_array.Length() == num_type_params)); |
| 534 for (intptr_t i = 0; i < num_type_params; i++) { | 534 for (intptr_t i = 0; i < num_type_params; i++) { |
| 535 type_extends = extends_array.TypeAt(i); | 535 type_extends = extends_array.TypeAt(i); |
| 536 if (!type_extends.IsDynamicType()) { | 536 if (!type_extends.IsDynamicType()) { |
| 537 type = arguments.TypeAt(offset + i); | 537 type = arguments.TypeAt(offset + i); |
| 538 if (type.IsInstantiated()) { | 538 if (type.IsInstantiated()) { |
| 539 if (!type_extends.IsInstantiated()) { | 539 if (!type_extends.IsInstantiated()) { |
| 540 type_extends = type_extends.InstantiateFrom(arguments, offset); | 540 type_extends = type_extends.InstantiateFrom(arguments); |
| 541 } | 541 } |
| 542 // TODO(regis): Where do we check the constraints when the type is | 542 // TODO(regis): Where do we check the constraints when the type is |
| 543 // generic? | 543 // generic? |
| 544 if (!type.IsSubtypeOf(type_extends)) { | 544 if (!type.IsSubtypeOf(type_extends)) { |
| 545 const String& type_argument_name = String::Handle(type.Name()); | 545 const String& type_argument_name = String::Handle(type.Name()); |
| 546 const String& class_name = String::Handle(cls.Name()); | 546 const String& class_name = String::Handle(cls.Name()); |
| 547 const String& extends_name = String::Handle(type_extends.Name()); | 547 const String& extends_name = String::Handle(type_extends.Name()); |
| 548 const Script& script = Script::Handle(cls.script()); | 548 const Script& script = Script::Handle(cls.script()); |
| 549 ReportError(script, -1, | 549 ReportError(script, -1, |
| 550 "type argument '%s' of class '%s' " | 550 "type argument '%s' of class '%s' " |
| 551 "does not extend type '%s'\n", | 551 "does not extend type '%s'\n", |
| 552 type_argument_name.ToCString(), | 552 type_argument_name.ToCString(), |
| 553 class_name.ToCString(), | 553 class_name.ToCString(), |
| 554 extends_name.ToCString()); | 554 extends_name.ToCString()); |
| 555 } | 555 } |
| 556 } | 556 } |
| 557 } | 557 } |
| 558 } | 558 } |
| 559 const Type& super_type = Type::Handle(cls.super_type()); | 559 const Type& super_type = Type::Handle(cls.super_type()); |
| 560 if (!super_type.IsNull()) { | 560 if (!super_type.IsNull()) { |
| 561 ASSERT(super_type.IsFinalized()); | 561 ASSERT(super_type.IsFinalized()); |
| 562 const Class& super_class = Class::Handle(super_type.type_class()); | 562 const Class& super_class = Class::Handle(super_type.type_class()); |
| 563 VerifyUpperBounds(super_class, arguments); | 563 VerifyUpperBounds(super_class, arguments); |
| 564 } | 564 } |
| 565 } | 565 } |
| 566 | 566 |
| 567 | 567 |
| 568 RawAbstractType* ClassFinalizer::FinalizeType(const AbstractType& type) { | 568 RawAbstractType* ClassFinalizer::FinalizeType(const Class& cls, |
| 569 const AbstractType& type) { |
| 569 ASSERT(type.IsResolved()); | 570 ASSERT(type.IsResolved()); |
| 570 if (type.IsFinalized()) { | 571 if (type.IsFinalized()) { |
| 571 return type.raw(); | 572 return type.raw(); |
| 572 } | 573 } |
| 573 if (FLAG_trace_type_finalization) { | 574 if (FLAG_trace_type_finalization) { |
| 574 OS::Print("Finalize type '%s'\n", String::Handle(type.Name()).ToCString()); | 575 OS::Print("Finalize type '%s'\n", String::Handle(type.Name()).ToCString()); |
| 575 } | 576 } |
| 576 | 577 |
| 578 if (type.IsTypeParameter()) { |
| 579 ASSERT(!cls.IsNull()); |
| 580 TypeParameter& type_parameter = TypeParameter::Handle(); |
| 581 type_parameter ^= type.raw(); |
| 582 // The index must reflect the position of this type parameter in the type |
| 583 // arguments vector of the enclosing class. The offset to add is the number |
| 584 // of type arguments in the super type, which is equal to the difference in |
| 585 // number of type arguments and type parameters of the enclosing class. |
| 586 const intptr_t offset = cls.NumTypeArguments() - cls.NumTypeParameters(); |
| 587 type_parameter.set_index(type_parameter.Index() + offset); |
| 588 type_parameter.set_is_finalized(); |
| 589 // We do not canonicalize type parameters. |
| 590 return type_parameter.raw(); |
| 591 } |
| 592 |
| 577 // At this point, we can only have a parameterized_type. | 593 // At this point, we can only have a parameterized_type. |
| 578 Type& parameterized_type = Type::Handle(); | 594 Type& parameterized_type = Type::Handle(); |
| 579 parameterized_type ^= type.raw(); | 595 parameterized_type ^= type.raw(); |
| 580 | 596 |
| 581 if (parameterized_type.IsBeingFinalized()) { | 597 if (parameterized_type.IsBeingFinalized()) { |
| 582 ReportError("type '%s' illegally refers to itself\n", | 598 ReportError("type '%s' illegally refers to itself\n", |
| 583 String::Handle(parameterized_type.Name()).ToCString()); | 599 String::Handle(parameterized_type.Name()).ToCString()); |
| 584 } | 600 } |
| 585 | 601 |
| 586 // Mark type as being finalized in order to detect illegal self reference. | 602 // Mark type as being finalized in order to detect illegal self reference. |
| 587 parameterized_type.set_is_being_finalized(); | 603 parameterized_type.set_is_being_finalized(); |
| 588 | 604 |
| 589 // Finalize the current type arguments of the type, which are still the | 605 // Finalize the current type arguments of the type, which are still the |
| 590 // parsed type arguments. | 606 // parsed type arguments. |
| 591 AbstractTypeArguments& arguments = | 607 AbstractTypeArguments& arguments = |
| 592 AbstractTypeArguments::Handle(parameterized_type.arguments()); | 608 AbstractTypeArguments::Handle(parameterized_type.arguments()); |
| 593 if (!arguments.IsNull()) { | 609 if (!arguments.IsNull()) { |
| 594 intptr_t num_arguments = arguments.Length(); | 610 intptr_t num_arguments = arguments.Length(); |
| 595 for (intptr_t i = 0; i < num_arguments; i++) { | 611 for (intptr_t i = 0; i < num_arguments; i++) { |
| 596 AbstractType& type_argument = AbstractType::Handle(arguments.TypeAt(i)); | 612 AbstractType& type_argument = AbstractType::Handle(arguments.TypeAt(i)); |
| 597 type_argument = FinalizeType(type_argument); | 613 type_argument = FinalizeType(cls, type_argument); |
| 598 arguments.SetTypeAt(i, type_argument); | 614 arguments.SetTypeAt(i, type_argument); |
| 599 } | 615 } |
| 600 } | 616 } |
| 601 | 617 |
| 602 // The type class does not need to be finalized in order to finalize the type, | 618 // The type class does not need to be finalized in order to finalize the type, |
| 603 // however, it must at least be resolved (this was done as part of resolving | 619 // however, it must at least be resolved (this was done as part of resolving |
| 604 // the type itself, a precondition to calling FinalizeType) and the upper | 620 // the type itself, a precondition to calling FinalizeType) and the upper |
| 605 // bounds of its type parameters must be finalized (done here). | 621 // bounds of its type parameters must be finalized (done here). |
| 606 Class& type_class = Class::Handle(parameterized_type.type_class()); | 622 Class& type_class = Class::Handle(parameterized_type.type_class()); |
| 607 | 623 |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 672 if (FLAG_enable_type_checks) { | 688 if (FLAG_enable_type_checks) { |
| 673 VerifyUpperBounds(type_class, full_arguments); | 689 VerifyUpperBounds(type_class, full_arguments); |
| 674 } | 690 } |
| 675 } else { | 691 } else { |
| 676 parameterized_type.set_is_finalized(); | 692 parameterized_type.set_is_finalized(); |
| 677 } | 693 } |
| 678 return parameterized_type.Canonicalize(); | 694 return parameterized_type.Canonicalize(); |
| 679 } | 695 } |
| 680 | 696 |
| 681 | 697 |
| 682 RawType* ClassFinalizer::FinalizeAndCanonicalizeType(const Type& type, | 698 RawAbstractType* ClassFinalizer::FinalizeAndCanonicalizeType( |
| 683 String* errmsg) { | 699 const Class& cls, |
| 700 const AbstractType& type, |
| 701 String* errmsg) { |
| 684 Isolate* isolate = Isolate::Current(); | 702 Isolate* isolate = Isolate::Current(); |
| 685 ASSERT(isolate != NULL); | 703 ASSERT(isolate != NULL); |
| 686 LongJump* base = isolate->long_jump_base(); | 704 LongJump* base = isolate->long_jump_base(); |
| 687 LongJump jump; | 705 LongJump jump; |
| 688 isolate->set_long_jump_base(&jump); | 706 isolate->set_long_jump_base(&jump); |
| 689 if (setjmp(*jump.Set()) == 0) { | 707 if (setjmp(*jump.Set()) == 0) { |
| 690 Type& canonical_type = Type::Handle(); | 708 const AbstractType& finalized_type = |
| 691 canonical_type ^= FinalizeType(type); | 709 AbstractType::Handle(FinalizeType(cls, type)); |
| 692 isolate->set_long_jump_base(base); | 710 isolate->set_long_jump_base(base); |
| 693 *errmsg = String::null(); | 711 *errmsg = String::null(); |
| 694 return canonical_type.raw(); | 712 return finalized_type.raw(); |
| 695 } else { | 713 } else { |
| 696 // Error occured: Get the error message. | 714 // Error occured: Get the error message. |
| 697 isolate->set_long_jump_base(base); | 715 isolate->set_long_jump_base(base); |
| 698 *errmsg = isolate->object_store()->sticky_error(); | 716 *errmsg = isolate->object_store()->sticky_error(); |
| 699 return type.raw(); | 717 return type.raw(); |
| 700 } | 718 } |
| 701 UNREACHABLE(); | 719 UNREACHABLE(); |
| 702 return NULL; | 720 return NULL; |
| 703 } | 721 } |
| 704 | 722 |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 747 "factory method '%s' must declare %d type parameter%s.\n", | 765 "factory method '%s' must declare %d type parameter%s.\n", |
| 748 function_name.ToCString(), | 766 function_name.ToCString(), |
| 749 type_class.NumTypeParameters(), | 767 type_class.NumTypeParameters(), |
| 750 type_class.NumTypeParameters() > 1 ? "s" : ""); | 768 type_class.NumTypeParameters() > 1 ? "s" : ""); |
| 751 } | 769 } |
| 752 } | 770 } |
| 753 } else { | 771 } else { |
| 754 ResolveType(cls, type); | 772 ResolveType(cls, type); |
| 755 } | 773 } |
| 756 } | 774 } |
| 757 type = FinalizeType(type); | 775 type = FinalizeType(cls, type); |
| 758 function.set_result_type(type); | 776 function.set_result_type(type); |
| 759 // Resolve formal parameter types. | 777 // Resolve formal parameter types. |
| 760 const intptr_t num_parameters = function.NumberOfParameters(); | 778 const intptr_t num_parameters = function.NumberOfParameters(); |
| 761 for (intptr_t i = 0; i < num_parameters; i++) { | 779 for (intptr_t i = 0; i < num_parameters; i++) { |
| 762 type = function.ParameterTypeAt(i); | 780 type = function.ParameterTypeAt(i); |
| 763 ResolveType(cls, type); | 781 ResolveType(cls, type); |
| 764 type = FinalizeType(type); | 782 type = FinalizeType(cls, type); |
| 765 function.SetParameterTypeAt(i, type); | 783 function.SetParameterTypeAt(i, type); |
| 766 } | 784 } |
| 767 } | 785 } |
| 768 | 786 |
| 769 | 787 |
| 770 static RawClass* FindSuperOwnerOfInstanceMember(const Class& cls, | 788 static RawClass* FindSuperOwnerOfInstanceMember(const Class& cls, |
| 771 const String& name) { | 789 const String& name) { |
| 772 Class& super_class = Class::Handle(); | 790 Class& super_class = Class::Handle(); |
| 773 Function& function = Function::Handle(); | 791 Function& function = Function::Handle(); |
| 774 Field& field = Field::Handle(); | 792 Field& field = Field::Handle(); |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 810 void ClassFinalizer::ResolveAndFinalizeUpperBounds(const Class& cls) { | 828 void ClassFinalizer::ResolveAndFinalizeUpperBounds(const Class& cls) { |
| 811 const intptr_t num_type_params = cls.NumTypeParameters(); | 829 const intptr_t num_type_params = cls.NumTypeParameters(); |
| 812 AbstractType& type_extends = AbstractType::Handle(); | 830 AbstractType& type_extends = AbstractType::Handle(); |
| 813 const AbstractTypeArguments& extends_array = | 831 const AbstractTypeArguments& extends_array = |
| 814 AbstractTypeArguments::Handle(cls.type_parameter_extends()); | 832 AbstractTypeArguments::Handle(cls.type_parameter_extends()); |
| 815 ASSERT((extends_array.IsNull() && (num_type_params == 0)) || | 833 ASSERT((extends_array.IsNull() && (num_type_params == 0)) || |
| 816 (extends_array.Length() == num_type_params)); | 834 (extends_array.Length() == num_type_params)); |
| 817 for (intptr_t i = 0; i < num_type_params; i++) { | 835 for (intptr_t i = 0; i < num_type_params; i++) { |
| 818 type_extends = extends_array.TypeAt(i); | 836 type_extends = extends_array.TypeAt(i); |
| 819 ResolveType(cls, type_extends); | 837 ResolveType(cls, type_extends); |
| 820 type_extends = FinalizeType(type_extends); | 838 type_extends = FinalizeType(cls, type_extends); |
| 821 extends_array.SetTypeAt(i, type_extends); | 839 extends_array.SetTypeAt(i, type_extends); |
| 822 } | 840 } |
| 823 } | 841 } |
| 824 | 842 |
| 825 | 843 |
| 826 void ClassFinalizer::ResolveAndFinalizeMemberTypes(const Class& cls) { | 844 void ClassFinalizer::ResolveAndFinalizeMemberTypes(const Class& cls) { |
| 827 // Note that getters and setters are explicitly listed as such in the list of | 845 // Note that getters and setters are explicitly listed as such in the list of |
| 828 // functions of a class, so we do not need to consider fields as implicitly | 846 // functions of a class, so we do not need to consider fields as implicitly |
| 829 // generating getters and setters. | 847 // generating getters and setters. |
| 830 // The only compile errors we report are therefore: | 848 // The only compile errors we report are therefore: |
| 831 // - a getter having the same name as a method (but not a getter) in a super | 849 // - a getter having the same name as a method (but not a getter) in a super |
| 832 // class or in a subclass. | 850 // class or in a subclass. |
| 833 // - a setter having the same name as a method (but not a setter) in a super | 851 // - a setter having the same name as a method (but not a setter) in a super |
| 834 // class or in a subclass. | 852 // class or in a subclass. |
| 835 // - a static field, instance field, or static method (but not an instance | 853 // - a static field, instance field, or static method (but not an instance |
| 836 // method) having the same name as an instance member in a super class. | 854 // method) having the same name as an instance member in a super class. |
| 837 | 855 |
| 838 // Resolve type of fields and check for conflicts in super classes. | 856 // Resolve type of fields and check for conflicts in super classes. |
| 839 Array& array = Array::Handle(cls.fields()); | 857 Array& array = Array::Handle(cls.fields()); |
| 840 Field& field = Field::Handle(); | 858 Field& field = Field::Handle(); |
| 841 AbstractType& type = AbstractType::Handle(); | 859 AbstractType& type = AbstractType::Handle(); |
| 842 String& name = String::Handle(); | 860 String& name = String::Handle(); |
| 843 Class& super_class = Class::Handle(); | 861 Class& super_class = Class::Handle(); |
| 844 intptr_t num_fields = array.Length(); | 862 intptr_t num_fields = array.Length(); |
| 845 for (intptr_t i = 0; i < num_fields; i++) { | 863 for (intptr_t i = 0; i < num_fields; i++) { |
| 846 field ^= array.At(i); | 864 field ^= array.At(i); |
| 847 type = field.type(); | 865 type = field.type(); |
| 848 ResolveType(cls, type); | 866 ResolveType(cls, type); |
| 849 type = FinalizeType(type); | 867 type = FinalizeType(cls, type); |
| 850 field.set_type(type); | 868 field.set_type(type); |
| 851 name = field.name(); | 869 name = field.name(); |
| 852 super_class = FindSuperOwnerOfInstanceMember(cls, name); | 870 super_class = FindSuperOwnerOfInstanceMember(cls, name); |
| 853 if (!super_class.IsNull()) { | 871 if (!super_class.IsNull()) { |
| 854 const String& class_name = String::Handle(cls.Name()); | 872 const String& class_name = String::Handle(cls.Name()); |
| 855 const String& super_class_name = String::Handle(super_class.Name()); | 873 const String& super_class_name = String::Handle(super_class.Name()); |
| 856 const Script& script = Script::Handle(cls.script()); | 874 const Script& script = Script::Handle(cls.script()); |
| 857 ReportError(script, field.token_index(), | 875 ReportError(script, field.token_index(), |
| 858 "field '%s' of class '%s' conflicts with instance " | 876 "field '%s' of class '%s' conflicts with instance " |
| 859 "member '%s' of super class '%s'.\n", | 877 "member '%s' of super class '%s'.\n", |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 988 "class '%s' has a cycle in its superclass relationship.\n", | 1006 "class '%s' has a cycle in its superclass relationship.\n", |
| 989 name.ToCString()); | 1007 name.ToCString()); |
| 990 } | 1008 } |
| 991 GrowableArray<const Class*> visited; | 1009 GrowableArray<const Class*> visited; |
| 992 ResolveInterfaces(cls, &visited); | 1010 ResolveInterfaces(cls, &visited); |
| 993 Type& super_type = Type::Handle(cls.super_type()); | 1011 Type& super_type = Type::Handle(cls.super_type()); |
| 994 if (!super_type.IsNull()) { | 1012 if (!super_type.IsNull()) { |
| 995 const Class& super_class = Class::Handle(super_type.type_class()); | 1013 const Class& super_class = Class::Handle(super_type.type_class()); |
| 996 // Finalize super class and super type. | 1014 // Finalize super class and super type. |
| 997 FinalizeClass(super_class, generating_snapshot); | 1015 FinalizeClass(super_class, generating_snapshot); |
| 998 super_type ^= FinalizeType(super_type); | 1016 super_type ^= FinalizeType(cls, super_type); |
| 999 cls.set_super_type(super_type); | 1017 cls.set_super_type(super_type); |
| 1000 } | 1018 } |
| 1001 if (cls.is_interface()) { | 1019 if (cls.is_interface()) { |
| 1002 if (cls.HasFactoryClass()) { | 1020 if (cls.HasFactoryClass()) { |
| 1003 const Class& factory_class = Class::Handle(cls.FactoryClass()); | 1021 const Class& factory_class = Class::Handle(cls.FactoryClass()); |
| 1004 // Finalize factory class. | 1022 // Finalize factory class. |
| 1005 if (!factory_class.is_finalized()) { | 1023 if (!factory_class.is_finalized()) { |
| 1006 FinalizeClass(factory_class, generating_snapshot); | 1024 FinalizeClass(factory_class, generating_snapshot); |
| 1007 // Finalizing the factory class may indirectly finalize this interface. | 1025 // Finalizing the factory class may indirectly finalize this interface. |
| 1008 if (cls.is_finalized()) { | 1026 if (cls.is_finalized()) { |
| 1009 return; | 1027 return; |
| 1010 } | 1028 } |
| 1011 } | 1029 } |
| 1012 } | 1030 } |
| 1013 } | 1031 } |
| 1014 // Finalize interface types (but not necessarily interface classes). | 1032 // Finalize interface types (but not necessarily interface classes). |
| 1015 Array& interface_types = Array::Handle(cls.interfaces()); | 1033 Array& interface_types = Array::Handle(cls.interfaces()); |
| 1016 AbstractType& interface_type = AbstractType::Handle(); | 1034 AbstractType& interface_type = AbstractType::Handle(); |
| 1017 for (intptr_t i = 0; i < interface_types.Length(); i++) { | 1035 for (intptr_t i = 0; i < interface_types.Length(); i++) { |
| 1018 interface_type ^= interface_types.At(i); | 1036 interface_type ^= interface_types.At(i); |
| 1019 interface_type = FinalizeType(interface_type); | 1037 interface_type = FinalizeType(cls, interface_type); |
| 1020 interface_types.SetAt(i, interface_type); | 1038 interface_types.SetAt(i, interface_type); |
| 1021 } | 1039 } |
| 1022 // Mark as finalized before resolving type parameter upper bounds and member | 1040 // Mark as finalized before resolving type parameter upper bounds and member |
| 1023 // types in order to break cycles. | 1041 // types in order to break cycles. |
| 1024 cls.Finalize(); | 1042 cls.Finalize(); |
| 1025 ResolveAndFinalizeUpperBounds(cls); | 1043 ResolveAndFinalizeUpperBounds(cls); |
| 1026 ResolveAndFinalizeMemberTypes(cls); | 1044 ResolveAndFinalizeMemberTypes(cls); |
| 1027 // Run additional checks after all types are finalized. | 1045 // Run additional checks after all types are finalized. |
| 1028 if (cls.is_const()) { | 1046 if (cls.is_const()) { |
| 1029 CheckForLegalConstClass(cls); | 1047 CheckForLegalConstClass(cls); |
| (...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1294 va_end(args); | 1312 va_end(args); |
| 1295 if (FLAG_warning_as_error) { | 1313 if (FLAG_warning_as_error) { |
| 1296 Isolate::Current()->long_jump_base()->Jump(1, message_buffer); | 1314 Isolate::Current()->long_jump_base()->Jump(1, message_buffer); |
| 1297 UNREACHABLE(); | 1315 UNREACHABLE(); |
| 1298 } else { | 1316 } else { |
| 1299 OS::Print(message_buffer); | 1317 OS::Print(message_buffer); |
| 1300 } | 1318 } |
| 1301 } | 1319 } |
| 1302 | 1320 |
| 1303 } // namespace dart | 1321 } // namespace dart |
| OLD | NEW |