| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 630 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 641 for (intptr_t i = 0; i < num_type_params; i++) { | 641 for (intptr_t i = 0; i < num_type_params; i++) { |
| 642 type_arg = arguments.TypeAt(offset + i); | 642 type_arg = arguments.TypeAt(offset + i); |
| 643 if (type_arg.IsDynamicType()) { | 643 if (type_arg.IsDynamicType()) { |
| 644 continue; | 644 continue; |
| 645 } | 645 } |
| 646 cls_type_param = cls_type_params.TypeAt(i); | 646 cls_type_param = cls_type_params.TypeAt(i); |
| 647 const TypeParameter& type_param = TypeParameter::Cast(cls_type_param); | 647 const TypeParameter& type_param = TypeParameter::Cast(cls_type_param); |
| 648 ASSERT(type_param.IsFinalized()); | 648 ASSERT(type_param.IsFinalized()); |
| 649 declared_bound = type_param.bound(); | 649 declared_bound = type_param.bound(); |
| 650 if (!declared_bound.IsObjectType() && !declared_bound.IsDynamicType()) { | 650 if (!declared_bound.IsObjectType() && !declared_bound.IsDynamicType()) { |
| 651 if (!declared_bound.IsFinalized() && !declared_bound.IsBeingFinalized()) { |
| 652 declared_bound = FinalizeType(cls, declared_bound, kCanonicalize); |
| 653 type_param.set_bound(declared_bound); |
| 654 } |
| 655 ASSERT(declared_bound.IsFinalized() || declared_bound.IsBeingFinalized()); |
| 651 Error& malformed_error = Error::Handle(); | 656 Error& malformed_error = Error::Handle(); |
| 652 // Note that the bound may be malformed, in which case the bound check | 657 // Note that the bound may be malformed, in which case the bound check |
| 653 // will return an error and the bound check will be postponed to run time. | 658 // will return an error and the bound check will be postponed to run time. |
| 654 // Note also that the bound may still be unfinalized. | |
| 655 if (declared_bound.IsInstantiated()) { | 659 if (declared_bound.IsInstantiated()) { |
| 656 instantiated_bound = declared_bound.raw(); | 660 instantiated_bound = declared_bound.raw(); |
| 657 } else { | 661 } else { |
| 658 instantiated_bound = | 662 instantiated_bound = |
| 659 declared_bound.InstantiateFrom(arguments, &malformed_error); | 663 declared_bound.InstantiateFrom(arguments, &malformed_error); |
| 660 } | 664 } |
| 661 if (!instantiated_bound.IsFinalized()) { | 665 if (!instantiated_bound.IsFinalized()) { |
| 662 // The bound refers to type parameters, creating a cycle; postpone | 666 // The bound refers to type parameters, creating a cycle; postpone |
| 663 // bound check to run time, when the bound will be finalized. | 667 // bound check to run time, when the bound will be finalized. |
| 664 // The bound may not necessarily be 'IsBeingFinalized' yet, as is the | 668 // The bound may not necessarily be 'IsBeingFinalized' yet, as is the |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 814 Error& bound_error = Error::Handle(); | 818 Error& bound_error = Error::Handle(); |
| 815 if (num_type_arguments > 0) { | 819 if (num_type_arguments > 0) { |
| 816 // If no type arguments were parsed and if the super types do not prepend | 820 // If no type arguments were parsed and if the super types do not prepend |
| 817 // type arguments to the vector, we can leave the vector as null. | 821 // type arguments to the vector, we can leave the vector as null. |
| 818 if (!arguments.IsNull() || (num_type_arguments > num_type_parameters)) { | 822 if (!arguments.IsNull() || (num_type_arguments > num_type_parameters)) { |
| 819 full_arguments = TypeArguments::New(num_type_arguments); | 823 full_arguments = TypeArguments::New(num_type_arguments); |
| 820 // Copy the parsed type arguments at the correct offset in the full type | 824 // Copy the parsed type arguments at the correct offset in the full type |
| 821 // argument vector. | 825 // argument vector. |
| 822 const intptr_t offset = num_type_arguments - num_type_parameters; | 826 const intptr_t offset = num_type_arguments - num_type_parameters; |
| 823 AbstractType& type_arg = AbstractType::Handle(Type::DynamicType()); | 827 AbstractType& type_arg = AbstractType::Handle(Type::DynamicType()); |
| 828 for (intptr_t i = 0; i < offset; i++) { |
| 829 // Temporarily set the type arguments of the super classes to dynamic. |
| 830 full_arguments.SetTypeAt(i, type_arg); |
| 831 } |
| 824 for (intptr_t i = 0; i < num_type_parameters; i++) { | 832 for (intptr_t i = 0; i < num_type_parameters; i++) { |
| 825 // If no type parameters were provided, a raw type is desired, so we | 833 // If no type parameters were provided, a raw type is desired, so we |
| 826 // create a vector of DynamicType. | 834 // create a vector of dynamic. |
| 827 if (!arguments.IsNull()) { | 835 if (!arguments.IsNull()) { |
| 828 type_arg = arguments.TypeAt(i); | 836 type_arg = arguments.TypeAt(i); |
| 829 } | 837 } |
| 830 ASSERT(type_arg.IsFinalized()); // Index of type parameter is adjusted. | 838 ASSERT(type_arg.IsFinalized()); // Index of type parameter is adjusted. |
| 831 full_arguments.SetTypeAt(offset + i, type_arg); | 839 full_arguments.SetTypeAt(offset + i, type_arg); |
| 832 } | 840 } |
| 841 // Replace the compile-time argument vector (of length zero or |
| 842 // num_type_parameters) of this type being finalized with the still |
| 843 // unfinalized run-time argument vector (of length num_type_arguments). |
| 844 // This type being finalized may be recursively reached via bounds |
| 845 // checking, in which case type arguments of super classes will be seen |
| 846 // as dynamic. |
| 847 parameterized_type.set_arguments(full_arguments); |
| 833 // If the type class is a signature class, the full argument vector | 848 // If the type class is a signature class, the full argument vector |
| 834 // must include the argument vector of the super type. | 849 // must include the argument vector of the super type. |
| 835 // If the signature class is a function type alias, it is also the owner | 850 // If the signature class is a function type alias, it is also the owner |
| 836 // of its signature function and no super type is involved. | 851 // of its signature function and no super type is involved. |
| 837 // If the signature class is canonical (not an alias), the owner of its | 852 // If the signature class is canonical (not an alias), the owner of its |
| 838 // signature function may either be an alias or the enclosing class of a | 853 // signature function may either be an alias or the enclosing class of a |
| 839 // local function, in which case the super type of the enclosing class is | 854 // local function, in which case the super type of the enclosing class is |
| 840 // also considered when filling up the argument vector. | 855 // also considered when filling up the argument vector. |
| 841 if (type_class.IsSignatureClass()) { | 856 if (type_class.IsSignatureClass()) { |
| 842 const Function& signature_fun = | 857 const Function& signature_fun = |
| (...skipping 1465 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2308 expected_name ^= String::New("_offset"); | 2323 expected_name ^= String::New("_offset"); |
| 2309 ASSERT(String::EqualsIgnoringPrivateKey(name, expected_name)); | 2324 ASSERT(String::EqualsIgnoringPrivateKey(name, expected_name)); |
| 2310 field ^= fields_array.At(2); | 2325 field ^= fields_array.At(2); |
| 2311 ASSERT(field.Offset() == TypedDataView::length_offset()); | 2326 ASSERT(field.Offset() == TypedDataView::length_offset()); |
| 2312 name ^= field.name(); | 2327 name ^= field.name(); |
| 2313 ASSERT(name.Equals("length")); | 2328 ASSERT(name.Equals("length")); |
| 2314 #endif | 2329 #endif |
| 2315 } | 2330 } |
| 2316 | 2331 |
| 2317 } // namespace dart | 2332 } // namespace dart |
| OLD | NEW |