| OLD | NEW |
| 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/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 321 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 332 super_class_name.ToCString()); | 332 super_class_name.ToCString()); |
| 333 } | 333 } |
| 334 // If cls belongs to core lib or to core lib's implementation, restrictions | 334 // If cls belongs to core lib or to core lib's implementation, restrictions |
| 335 // about allowed interfaces are lifted. | 335 // about allowed interfaces are lifted. |
| 336 if ((cls.library() != Library::CoreLibrary()) && | 336 if ((cls.library() != Library::CoreLibrary()) && |
| 337 (cls.library() != Library::CoreImplLibrary())) { | 337 (cls.library() != Library::CoreImplLibrary())) { |
| 338 // Prevent extending core implementation classes Bool, Double, ObjectArray, | 338 // Prevent extending core implementation classes Bool, Double, ObjectArray, |
| 339 // ImmutableArray, GrowableObjectArray, IntegerImplementation, Smi, Mint, | 339 // ImmutableArray, GrowableObjectArray, IntegerImplementation, Smi, Mint, |
| 340 // BigInt, OneByteString, TwoByteString, FourByteString. | 340 // BigInt, OneByteString, TwoByteString, FourByteString. |
| 341 ObjectStore* object_store = Isolate::Current()->object_store(); | 341 ObjectStore* object_store = Isolate::Current()->object_store(); |
| 342 const Library& core_impl_lib = Library::Handle(Library::CoreImplLibrary()); | |
| 343 const String& integer_implementation_name = | |
| 344 String::Handle(String::NewSymbol("IntegerImplementation")); | |
| 345 const Class& integer_implementation_class = | |
| 346 Class::Handle(core_impl_lib.LookupClass(integer_implementation_name)); | |
| 347 const String& growable_object_array_name = | |
| 348 String::Handle(String::NewSymbol("GrowableObjectArray")); | |
| 349 const Class& growable_object_array_class = | |
| 350 Class::Handle(core_impl_lib.LookupClass(growable_object_array_name)); | |
| 351 if ((super_class.raw() == object_store->bool_class()) || | 342 if ((super_class.raw() == object_store->bool_class()) || |
| 352 (super_class.raw() == object_store->double_class()) || | 343 (super_class.raw() == object_store->double_class()) || |
| 353 (super_class.raw() == object_store->array_class()) || | 344 (super_class.raw() == object_store->array_class()) || |
| 354 (super_class.raw() == object_store->immutable_array_class()) || | 345 (super_class.raw() == object_store->immutable_array_class()) || |
| 355 (super_class.raw() == growable_object_array_class.raw()) || | 346 (super_class.raw() == object_store->growable_object_array_class()) || |
| 356 (super_class.raw() == object_store->int8_array_class()) || | 347 (super_class.raw() == object_store->int8_array_class()) || |
| 357 (super_class.raw() == object_store->uint8_array_class()) || | 348 (super_class.raw() == object_store->uint8_array_class()) || |
| 358 (super_class.raw() == object_store->int16_array_class()) || | 349 (super_class.raw() == object_store->int16_array_class()) || |
| 359 (super_class.raw() == object_store->uint16_array_class()) || | 350 (super_class.raw() == object_store->uint16_array_class()) || |
| 360 (super_class.raw() == object_store->int32_array_class()) || | 351 (super_class.raw() == object_store->int32_array_class()) || |
| 361 (super_class.raw() == object_store->uint32_array_class()) || | 352 (super_class.raw() == object_store->uint32_array_class()) || |
| 362 (super_class.raw() == object_store->int64_array_class()) || | 353 (super_class.raw() == object_store->int64_array_class()) || |
| 363 (super_class.raw() == object_store->uint64_array_class()) || | 354 (super_class.raw() == object_store->uint64_array_class()) || |
| 364 (super_class.raw() == object_store->float32_array_class()) || | 355 (super_class.raw() == object_store->float32_array_class()) || |
| 365 (super_class.raw() == object_store->float64_array_class()) || | 356 (super_class.raw() == object_store->float64_array_class()) || |
| 366 (super_class.raw() == object_store->external_int8_array_class()) || | 357 (super_class.raw() == object_store->external_int8_array_class()) || |
| 367 (super_class.raw() == object_store->external_uint8_array_class()) || | 358 (super_class.raw() == object_store->external_uint8_array_class()) || |
| 368 (super_class.raw() == object_store->external_int16_array_class()) || | 359 (super_class.raw() == object_store->external_int16_array_class()) || |
| 369 (super_class.raw() == object_store->external_uint16_array_class()) || | 360 (super_class.raw() == object_store->external_uint16_array_class()) || |
| 370 (super_class.raw() == object_store->external_int32_array_class()) || | 361 (super_class.raw() == object_store->external_int32_array_class()) || |
| 371 (super_class.raw() == object_store->external_uint32_array_class()) || | 362 (super_class.raw() == object_store->external_uint32_array_class()) || |
| 372 (super_class.raw() == object_store->external_int64_array_class()) || | 363 (super_class.raw() == object_store->external_int64_array_class()) || |
| 373 (super_class.raw() == object_store->external_uint64_array_class()) || | 364 (super_class.raw() == object_store->external_uint64_array_class()) || |
| 374 (super_class.raw() == object_store->external_float32_array_class()) || | 365 (super_class.raw() == object_store->external_float32_array_class()) || |
| 375 (super_class.raw() == object_store->external_float64_array_class()) || | 366 (super_class.raw() == object_store->external_float64_array_class()) || |
| 376 (super_class.raw() == integer_implementation_class.raw()) || | 367 (super_class.raw() == object_store->integer_implementation_class()) || |
| 377 (super_class.raw() == object_store->smi_class()) || | 368 (super_class.raw() == object_store->smi_class()) || |
| 378 (super_class.raw() == object_store->mint_class()) || | 369 (super_class.raw() == object_store->mint_class()) || |
| 379 (super_class.raw() == object_store->bigint_class()) || | 370 (super_class.raw() == object_store->bigint_class()) || |
| 380 (super_class.raw() == object_store->one_byte_string_class()) || | 371 (super_class.raw() == object_store->one_byte_string_class()) || |
| 381 (super_class.raw() == object_store->two_byte_string_class()) || | 372 (super_class.raw() == object_store->two_byte_string_class()) || |
| 382 (super_class.raw() == object_store->four_byte_string_class())) { | 373 (super_class.raw() == object_store->four_byte_string_class())) { |
| 383 const Script& script = Script::Handle(cls.script()); | 374 const Script& script = Script::Handle(cls.script()); |
| 384 ReportError(script, cls.token_pos(), | 375 ReportError(script, cls.token_pos(), |
| 385 "'%s' is not allowed to extend '%s'", | 376 "'%s' is not allowed to extend '%s'", |
| 386 String::Handle(cls.Name()).ToCString(), | 377 String::Handle(cls.Name()).ToCString(), |
| (...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 645 | 636 |
| 646 // At this point, we can only have a parameterized_type. | 637 // At this point, we can only have a parameterized_type. |
| 647 const Type& parameterized_type = Type::Cast(type); | 638 const Type& parameterized_type = Type::Cast(type); |
| 648 | 639 |
| 649 if (parameterized_type.IsBeingFinalized()) { | 640 if (parameterized_type.IsBeingFinalized()) { |
| 650 // Self reference detected. The type is malformed. | 641 // Self reference detected. The type is malformed. |
| 651 FinalizeMalformedType( | 642 FinalizeMalformedType( |
| 652 Error::Handle(), // No previous error. | 643 Error::Handle(), // No previous error. |
| 653 cls, parameterized_type, finalization, | 644 cls, parameterized_type, finalization, |
| 654 "type '%s' illegally refers to itself", | 645 "type '%s' illegally refers to itself", |
| 655 String::Handle(parameterized_type.Name()).ToCString()); | 646 String::Handle(parameterized_type.UserVisibleName()).ToCString()); |
| 656 return parameterized_type.raw(); | 647 return parameterized_type.raw(); |
| 657 } | 648 } |
| 658 | 649 |
| 659 // Mark type as being finalized in order to detect illegal self reference. | 650 // Mark type as being finalized in order to detect illegal self reference. |
| 660 parameterized_type.set_is_being_finalized(); | 651 parameterized_type.set_is_being_finalized(); |
| 661 | 652 |
| 662 // The type class does not need to be finalized in order to finalize the type, | 653 // The type class does not need to be finalized in order to finalize the type, |
| 663 // however, it must at least be resolved (this was done as part of resolving | 654 // however, it must at least be resolved (this was done as part of resolving |
| 664 // the type itself, a precondition to calling FinalizeType). | 655 // the type itself, a precondition to calling FinalizeType). |
| 665 // Also, the interfaces of the type class must be resolved and the type | 656 // Also, the interfaces of the type class must be resolved and the type |
| (...skipping 13 matching lines...) Expand all Loading... |
| 679 intptr_t num_arguments = arguments.Length(); | 670 intptr_t num_arguments = arguments.Length(); |
| 680 AbstractType& type_argument = AbstractType::Handle(); | 671 AbstractType& type_argument = AbstractType::Handle(); |
| 681 for (intptr_t i = 0; i < num_arguments; i++) { | 672 for (intptr_t i = 0; i < num_arguments; i++) { |
| 682 type_argument = arguments.TypeAt(i); | 673 type_argument = arguments.TypeAt(i); |
| 683 type_argument = FinalizeType(cls, type_argument, finalization); | 674 type_argument = FinalizeType(cls, type_argument, finalization); |
| 684 if (type_argument.IsMalformed()) { | 675 if (type_argument.IsMalformed()) { |
| 685 // In production mode, malformed type arguments are mapped to Dynamic. | 676 // In production mode, malformed type arguments are mapped to Dynamic. |
| 686 // In checked mode, a type with malformed type arguments is malformed. | 677 // In checked mode, a type with malformed type arguments is malformed. |
| 687 if (FLAG_enable_type_checks) { | 678 if (FLAG_enable_type_checks) { |
| 688 const Error& error = Error::Handle(type_argument.malformed_error()); | 679 const Error& error = Error::Handle(type_argument.malformed_error()); |
| 689 const String& type_name = String::Handle(parameterized_type.Name()); | 680 const String& type_name = |
| 681 String::Handle(parameterized_type.UserVisibleName()); |
| 690 FinalizeMalformedType(error, cls, parameterized_type, finalization, | 682 FinalizeMalformedType(error, cls, parameterized_type, finalization, |
| 691 "type '%s' has malformed type argument", | 683 "type '%s' has malformed type argument", |
| 692 type_name.ToCString()); | 684 type_name.ToCString()); |
| 693 return parameterized_type.raw(); | 685 return parameterized_type.raw(); |
| 694 } else { | 686 } else { |
| 695 type_argument = Type::DynamicType(); | 687 type_argument = Type::DynamicType(); |
| 696 } | 688 } |
| 697 } | 689 } |
| 698 arguments.SetTypeAt(i, type_argument); | 690 arguments.SetTypeAt(i, type_argument); |
| 699 } | 691 } |
| 700 } | 692 } |
| 701 | 693 |
| 702 // The finalized type argument vector needs num_type_arguments types. | 694 // The finalized type argument vector needs num_type_arguments types. |
| 703 const intptr_t num_type_arguments = type_class.NumTypeArguments(); | 695 const intptr_t num_type_arguments = type_class.NumTypeArguments(); |
| 704 // The type class has num_type_parameters type parameters. | 696 // The type class has num_type_parameters type parameters. |
| 705 const intptr_t num_type_parameters = type_class.NumTypeParameters(); | 697 const intptr_t num_type_parameters = type_class.NumTypeParameters(); |
| 706 | 698 |
| 707 // Initialize the type argument vector. | 699 // Initialize the type argument vector. |
| 708 // Check the number of parsed type arguments, if any. | 700 // Check the number of parsed type arguments, if any. |
| 709 // Specifying no type arguments indicates a raw type, which is not an error. | 701 // Specifying no type arguments indicates a raw type, which is not an error. |
| 710 // However, type parameter bounds are checked below, even for a raw type. | 702 // However, type parameter bounds are checked below, even for a raw type. |
| 711 if (!arguments.IsNull() && (arguments.Length() != num_type_parameters)) { | 703 if (!arguments.IsNull() && (arguments.Length() != num_type_parameters)) { |
| 712 // Wrong number of type arguments. The type is malformed. | 704 // Wrong number of type arguments. The type is malformed. |
| 713 FinalizeMalformedType( | 705 FinalizeMalformedType( |
| 714 Error::Handle(), // No previous error. | 706 Error::Handle(), // No previous error. |
| 715 cls, parameterized_type, finalization, | 707 cls, parameterized_type, finalization, |
| 716 "wrong number of type arguments in type '%s'", | 708 "wrong number of type arguments in type '%s'", |
| 717 String::Handle(parameterized_type.Name()).ToCString()); | 709 String::Handle(parameterized_type.UserVisibleName()).ToCString()); |
| 718 return parameterized_type.raw(); | 710 return parameterized_type.raw(); |
| 719 } | 711 } |
| 720 // The full type argument vector consists of the type arguments of the | 712 // The full type argument vector consists of the type arguments of the |
| 721 // super types of type_class, which may be initialized from the parsed | 713 // super types of type_class, which may be initialized from the parsed |
| 722 // type arguments, followed by the parsed type arguments. | 714 // type arguments, followed by the parsed type arguments. |
| 723 TypeArguments& full_arguments = TypeArguments::Handle(); | 715 TypeArguments& full_arguments = TypeArguments::Handle(); |
| 724 if (num_type_arguments > 0) { | 716 if (num_type_arguments > 0) { |
| 725 // If no type arguments were parsed and if the super types do not prepend | 717 // If no type arguments were parsed and if the super types do not prepend |
| 726 // type arguments to the vector, we can leave the vector as null. | 718 // type arguments to the vector, we can leave the vector as null. |
| 727 if (!arguments.IsNull() || (num_type_arguments > num_type_parameters)) { | 719 if (!arguments.IsNull() || (num_type_arguments > num_type_parameters)) { |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 788 // The type argument vector of the type is not within bounds. The type | 780 // The type argument vector of the type is not within bounds. The type |
| 789 // is malformed. Prepend malformed_error to new malformed type error in | 781 // is malformed. Prepend malformed_error to new malformed type error in |
| 790 // order to report both locations. | 782 // order to report both locations. |
| 791 // Note that malformed bounds never result in a compile time error, even | 783 // Note that malformed bounds never result in a compile time error, even |
| 792 // in checked mode. Therefore, overwrite finalization with kFinalize | 784 // in checked mode. Therefore, overwrite finalization with kFinalize |
| 793 // when finalizing the malformed type. | 785 // when finalizing the malformed type. |
| 794 FinalizeMalformedType( | 786 FinalizeMalformedType( |
| 795 malformed_error, | 787 malformed_error, |
| 796 cls, parameterized_type, kFinalize, | 788 cls, parameterized_type, kFinalize, |
| 797 "type arguments of type '%s' are not within bounds", | 789 "type arguments of type '%s' are not within bounds", |
| 798 String::Handle(parameterized_type.Name()).ToCString()); | 790 String::Handle(parameterized_type.UserVisibleName()).ToCString()); |
| 799 return parameterized_type.raw(); | 791 return parameterized_type.raw(); |
| 800 } | 792 } |
| 801 } | 793 } |
| 802 | 794 |
| 803 // If the type class is a signature class, we are currently finalizing a | 795 // If the type class is a signature class, we are currently finalizing a |
| 804 // signature type, i.e. finalizing the result type and parameter types of the | 796 // signature type, i.e. finalizing the result type and parameter types of the |
| 805 // signature function of this signature type. | 797 // signature function of this signature type. |
| 806 // We do this after marking this type as finalized in order to allow a | 798 // We do this after marking this type as finalized in order to allow a |
| 807 // function type to refer to itself via its parameter types and result type. | 799 // function type to refer to itself via its parameter types and result type. |
| 808 if (type_class.IsSignatureClass()) { | 800 if (type_class.IsSignatureClass()) { |
| (...skipping 696 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1505 void ClassFinalizer::ReportError(const char* format, ...) { | 1497 void ClassFinalizer::ReportError(const char* format, ...) { |
| 1506 va_list args; | 1498 va_list args; |
| 1507 va_start(args, format); | 1499 va_start(args, format); |
| 1508 const Error& error = Error::Handle( | 1500 const Error& error = Error::Handle( |
| 1509 Parser::FormatError(Script::Handle(), -1, "Error", format, args)); | 1501 Parser::FormatError(Script::Handle(), -1, "Error", format, args)); |
| 1510 va_end(args); | 1502 va_end(args); |
| 1511 ReportError(error); | 1503 ReportError(error); |
| 1512 } | 1504 } |
| 1513 | 1505 |
| 1514 } // namespace dart | 1506 } // namespace dart |
| OLD | NEW |