| 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 386 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 397 return; | 397 return; |
| 398 } | 398 } |
| 399 String& expected_type_name = String::Handle(); | 399 String& expected_type_name = String::Handle(); |
| 400 String& actual_type_name = String::Handle(); | 400 String& actual_type_name = String::Handle(); |
| 401 AbstractType& expected_type_extends = AbstractType::Handle(); | 401 AbstractType& expected_type_extends = AbstractType::Handle(); |
| 402 AbstractType& actual_type_extends = AbstractType::Handle(); | 402 AbstractType& actual_type_extends = AbstractType::Handle(); |
| 403 const Array& expected_type_names = | 403 const Array& expected_type_names = |
| 404 Array::Handle(factory_signature_class.type_parameters()); | 404 Array::Handle(factory_signature_class.type_parameters()); |
| 405 const Array& actual_type_names = | 405 const Array& actual_type_names = |
| 406 Array::Handle(factory_class.type_parameters()); | 406 Array::Handle(factory_class.type_parameters()); |
| 407 const TypeArray& expected_extends_array = | 407 const TypeArguments& expected_extends_array = |
| 408 TypeArray::Handle(factory_signature_class.type_parameter_extends()); | 408 TypeArguments::Handle(factory_signature_class.type_parameter_extends()); |
| 409 const TypeArray& actual_extends_array = | 409 const TypeArguments& actual_extends_array = |
| 410 TypeArray::Handle(factory_class.type_parameter_extends()); | 410 TypeArguments::Handle(factory_class.type_parameter_extends()); |
| 411 for (intptr_t i = 0; !mismatch && (i < num_type_params); i++) { | 411 for (intptr_t i = 0; !mismatch && (i < num_type_params); i++) { |
| 412 expected_type_name ^= expected_type_names.At(i); | 412 expected_type_name ^= expected_type_names.At(i); |
| 413 actual_type_name ^= actual_type_names.At(i); | 413 actual_type_name ^= actual_type_names.At(i); |
| 414 expected_type_extends = expected_extends_array.TypeAt(i); | 414 expected_type_extends = expected_extends_array.TypeAt(i); |
| 415 actual_type_extends = actual_extends_array.TypeAt(i); | 415 actual_type_extends = actual_extends_array.TypeAt(i); |
| 416 if (!expected_type_name.Equals(actual_type_name) || | 416 if (!expected_type_name.Equals(actual_type_name) || |
| 417 !expected_type_extends.Equals(actual_type_extends)) { | 417 !expected_type_extends.Equals(actual_type_extends)) { |
| 418 mismatch = true; | 418 mismatch = true; |
| 419 } | 419 } |
| 420 } | 420 } |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 456 Class::Handle(ResolveClass(cls, unresolved_class)); | 456 Class::Handle(ResolveClass(cls, unresolved_class)); |
| 457 | 457 |
| 458 // Replace unresolved class with resolved type class. | 458 // Replace unresolved class with resolved type class. |
| 459 ASSERT(type.IsType()); | 459 ASSERT(type.IsType()); |
| 460 Type& parameterized_type = Type::Handle(); | 460 Type& parameterized_type = Type::Handle(); |
| 461 parameterized_type ^= type.raw(); | 461 parameterized_type ^= type.raw(); |
| 462 parameterized_type.set_type_class(Object::Handle(type_class.raw())); | 462 parameterized_type.set_type_class(Object::Handle(type_class.raw())); |
| 463 } | 463 } |
| 464 | 464 |
| 465 // Resolve type arguments, if any. | 465 // Resolve type arguments, if any. |
| 466 const TypeArguments& arguments = TypeArguments::Handle(type.arguments()); | 466 const AbstractTypeArguments& arguments = |
| 467 AbstractTypeArguments::Handle(type.arguments()); |
| 467 if (!arguments.IsNull()) { | 468 if (!arguments.IsNull()) { |
| 468 intptr_t num_arguments = arguments.Length(); | 469 intptr_t num_arguments = arguments.Length(); |
| 469 AbstractType& type_argument = AbstractType::Handle(); | 470 AbstractType& type_argument = AbstractType::Handle(); |
| 470 for (intptr_t i = 0; i < num_arguments; i++) { | 471 for (intptr_t i = 0; i < num_arguments; i++) { |
| 471 type_argument = arguments.TypeAt(i); | 472 type_argument = arguments.TypeAt(i); |
| 472 ResolveType(cls, type_argument); | 473 ResolveType(cls, type_argument); |
| 473 } | 474 } |
| 474 } | 475 } |
| 475 } | 476 } |
| 476 | 477 |
| 477 | 478 |
| 478 // 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 |
| 479 // class 'cls' parameterized with the type arguments 'cls_args'. | 480 // class 'cls' parameterized with the type arguments 'cls_args'. |
| 480 // 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 |
| 481 // position in the passed in 'arguments' vector. | 482 // position in the passed in 'arguments' vector. |
| 482 // The subvector 'cls_args' has length cls.NumTypeParameters() and starts at | 483 // The subvector 'cls_args' has length cls.NumTypeParameters() and starts at |
| 483 // offset cls.NumTypeArguments() - cls.NumTypeParameters() of the 'arguments' | 484 // offset cls.NumTypeArguments() - cls.NumTypeParameters() of the 'arguments' |
| 484 // vector. | 485 // vector. |
| 485 // Example: | 486 // Example: |
| 486 // Declared: class C<K, V> extends B<V> { ... } | 487 // Declared: class C<K, V> extends B<V> { ... } |
| 487 // class B<T> extends Array<int> { ... } | 488 // class B<T> extends Array<int> { ... } |
| 488 // Input: C<String, double> expressed as | 489 // Input: C<String, double> expressed as |
| 489 // cls = C, arguments = [null, null, String, double], | 490 // cls = C, arguments = [null, null, String, double], |
| 490 // i.e. cls_args = [String, double], offset = 2, length = 2. | 491 // i.e. cls_args = [String, double], offset = 2, length = 2. |
| 491 // Output: arguments = [int, double, String, double] | 492 // Output: arguments = [int, double, String, double] |
| 492 void ClassFinalizer::FinalizeTypeArguments(const Class& cls, | 493 void ClassFinalizer::FinalizeTypeArguments( |
| 493 const TypeArguments& arguments) { | 494 const Class& cls, const AbstractTypeArguments& arguments) { |
| 494 ASSERT(arguments.Length() >= cls.NumTypeArguments()); | 495 ASSERT(arguments.Length() >= cls.NumTypeArguments()); |
| 495 Type& super_type = Type::Handle(cls.super_type()); | 496 Type& super_type = Type::Handle(cls.super_type()); |
| 496 if (!super_type.IsNull()) { | 497 if (!super_type.IsNull()) { |
| 497 super_type ^= FinalizeType(super_type); | 498 super_type ^= FinalizeType(super_type); |
| 498 cls.set_super_type(super_type); | 499 cls.set_super_type(super_type); |
| 499 const Class& super_class = Class::Handle(super_type.type_class()); | 500 const Class& super_class = Class::Handle(super_type.type_class()); |
| 500 const TypeArguments& super_type_args = | 501 const AbstractTypeArguments& super_type_args = |
| 501 TypeArguments::Handle(super_type.arguments()); | 502 AbstractTypeArguments::Handle(super_type.arguments()); |
| 502 const intptr_t num_super_type_params = super_class.NumTypeParameters(); | 503 const intptr_t num_super_type_params = super_class.NumTypeParameters(); |
| 503 const intptr_t offset = super_class.NumTypeArguments(); | 504 const intptr_t offset = super_class.NumTypeArguments(); |
| 504 const intptr_t super_offset = offset - num_super_type_params; | 505 const intptr_t super_offset = offset - num_super_type_params; |
| 505 ASSERT(offset == (cls.NumTypeArguments() - cls.NumTypeParameters())); | 506 ASSERT(offset == (cls.NumTypeArguments() - cls.NumTypeParameters())); |
| 506 AbstractType& super_type_arg = AbstractType::Handle(); | 507 AbstractType& super_type_arg = AbstractType::Handle(); |
| 507 for (intptr_t i = 0; i < num_super_type_params; i++) { | 508 for (intptr_t i = 0; i < num_super_type_params; i++) { |
| 508 super_type_arg = super_type_args.TypeAt(super_offset + i); | 509 super_type_arg = super_type_args.TypeAt(super_offset + i); |
| 509 if (!super_type_arg.IsInstantiated()) { | 510 if (!super_type_arg.IsInstantiated()) { |
| 510 super_type_arg = super_type_arg.InstantiateFrom(arguments, offset); | 511 super_type_arg = super_type_arg.InstantiateFrom(arguments, offset); |
| 511 } | 512 } |
| 512 super_type_arg = super_type_arg.Canonicalize(); | 513 super_type_arg = super_type_arg.Canonicalize(); |
| 513 arguments.SetTypeAt(super_offset + i, super_type_arg); | 514 arguments.SetTypeAt(super_offset + i, super_type_arg); |
| 514 } | 515 } |
| 515 FinalizeTypeArguments(super_class, arguments); | 516 FinalizeTypeArguments(super_class, arguments); |
| 516 } | 517 } |
| 517 } | 518 } |
| 518 | 519 |
| 519 | 520 |
| 520 // Verify the upper bounds of the type arguments of class cls. | 521 // Verify the upper bounds of the type arguments of class cls. |
| 521 void ClassFinalizer::VerifyUpperBounds(const Class& cls, | 522 void ClassFinalizer::VerifyUpperBounds(const Class& cls, |
| 522 const TypeArguments& arguments) { | 523 const AbstractTypeArguments& arguments) { |
| 523 ASSERT(FLAG_enable_type_checks); | 524 ASSERT(FLAG_enable_type_checks); |
| 524 ASSERT(arguments.Length() >= cls.NumTypeArguments()); | 525 ASSERT(arguments.Length() >= cls.NumTypeArguments()); |
| 525 const intptr_t num_type_params = cls.NumTypeParameters(); | 526 const intptr_t num_type_params = cls.NumTypeParameters(); |
| 526 const intptr_t offset = cls.NumTypeArguments() - num_type_params; | 527 const intptr_t offset = cls.NumTypeArguments() - num_type_params; |
| 527 AbstractType& type = AbstractType::Handle(); | 528 AbstractType& type = AbstractType::Handle(); |
| 528 AbstractType& type_extends = AbstractType::Handle(); | 529 AbstractType& type_extends = AbstractType::Handle(); |
| 529 const TypeArguments& extends_array = | 530 const AbstractTypeArguments& extends_array = |
| 530 TypeArguments::Handle(cls.type_parameter_extends()); | 531 AbstractTypeArguments::Handle(cls.type_parameter_extends()); |
| 531 ASSERT((extends_array.IsNull() && (num_type_params == 0)) || | 532 ASSERT((extends_array.IsNull() && (num_type_params == 0)) || |
| 532 (extends_array.Length() == num_type_params)); | 533 (extends_array.Length() == num_type_params)); |
| 533 for (intptr_t i = 0; i < num_type_params; i++) { | 534 for (intptr_t i = 0; i < num_type_params; i++) { |
| 534 type_extends = extends_array.TypeAt(i); | 535 type_extends = extends_array.TypeAt(i); |
| 535 if (!type_extends.IsDynamicType()) { | 536 if (!type_extends.IsDynamicType()) { |
| 536 type = arguments.TypeAt(offset + i); | 537 type = arguments.TypeAt(offset + i); |
| 537 if (type.IsInstantiated()) { | 538 if (type.IsInstantiated()) { |
| 538 if (!type_extends.IsInstantiated()) { | 539 if (!type_extends.IsInstantiated()) { |
| 539 type_extends = type_extends.InstantiateFrom(arguments, offset); | 540 type_extends = type_extends.InstantiateFrom(arguments, offset); |
| 540 } | 541 } |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 580 if (parameterized_type.IsBeingFinalized()) { | 581 if (parameterized_type.IsBeingFinalized()) { |
| 581 ReportError("type '%s' illegally refers to itself\n", | 582 ReportError("type '%s' illegally refers to itself\n", |
| 582 String::Handle(parameterized_type.Name()).ToCString()); | 583 String::Handle(parameterized_type.Name()).ToCString()); |
| 583 } | 584 } |
| 584 | 585 |
| 585 // Mark type as being finalized in order to detect illegal self reference. | 586 // Mark type as being finalized in order to detect illegal self reference. |
| 586 parameterized_type.set_is_being_finalized(); | 587 parameterized_type.set_is_being_finalized(); |
| 587 | 588 |
| 588 // Finalize the current type arguments of the type, which are still the | 589 // Finalize the current type arguments of the type, which are still the |
| 589 // parsed type arguments. | 590 // parsed type arguments. |
| 590 TypeArguments& arguments = | 591 AbstractTypeArguments& arguments = |
| 591 TypeArguments::Handle(parameterized_type.arguments()); | 592 AbstractTypeArguments::Handle(parameterized_type.arguments()); |
| 592 if (!arguments.IsNull()) { | 593 if (!arguments.IsNull()) { |
| 593 intptr_t num_arguments = arguments.Length(); | 594 intptr_t num_arguments = arguments.Length(); |
| 594 for (intptr_t i = 0; i < num_arguments; i++) { | 595 for (intptr_t i = 0; i < num_arguments; i++) { |
| 595 AbstractType& type_argument = AbstractType::Handle(arguments.TypeAt(i)); | 596 AbstractType& type_argument = AbstractType::Handle(arguments.TypeAt(i)); |
| 596 type_argument = FinalizeType(type_argument); | 597 type_argument = FinalizeType(type_argument); |
| 597 arguments.SetTypeAt(i, type_argument); | 598 arguments.SetTypeAt(i, type_argument); |
| 598 } | 599 } |
| 599 } | 600 } |
| 600 | 601 |
| 601 // The type class does not need to be finalized in order to finalize the type, | 602 // The type class does not need to be finalized in order to finalize the type, |
| (...skipping 27 matching lines...) Expand all Loading... |
| 629 if (!arguments.IsNull() && (arguments.Length() != num_type_parameters)) { | 630 if (!arguments.IsNull() && (arguments.Length() != num_type_parameters)) { |
| 630 // TODO(regis): We need to store the token_index in each type. | 631 // TODO(regis): We need to store the token_index in each type. |
| 631 ReportError("wrong number of type arguments in type '%s'\n", | 632 ReportError("wrong number of type arguments in type '%s'\n", |
| 632 String::Handle(type.Name()).ToCString()); | 633 String::Handle(type.Name()).ToCString()); |
| 633 } | 634 } |
| 634 // The full type argument vector consists of the type arguments of the | 635 // The full type argument vector consists of the type arguments of the |
| 635 // super types of type_class, which may be initialized from the parsed | 636 // super types of type_class, which may be initialized from the parsed |
| 636 // type arguments, followed by the parsed type arguments. | 637 // type arguments, followed by the parsed type arguments. |
| 637 if (num_type_arguments > 0) { | 638 if (num_type_arguments > 0) { |
| 638 const TypeArguments& full_arguments = TypeArguments::Handle( | 639 const TypeArguments& full_arguments = TypeArguments::Handle( |
| 639 TypeArguments::NewTypeArray(num_type_arguments)); | 640 TypeArguments::New(num_type_arguments)); |
| 640 // Copy the parsed type arguments at the correct offset in the full type | 641 // Copy the parsed type arguments at the correct offset in the full type |
| 641 // argument vector. | 642 // argument vector. |
| 642 const intptr_t offset = num_type_arguments - num_type_parameters; | 643 const intptr_t offset = num_type_arguments - num_type_parameters; |
| 643 AbstractType& type = AbstractType::Handle(Type::DynamicType()); | 644 AbstractType& type = AbstractType::Handle(Type::DynamicType()); |
| 644 for (intptr_t i = 0; i < num_type_parameters; i++) { | 645 for (intptr_t i = 0; i < num_type_parameters; i++) { |
| 645 // If no type parameters were provided, a raw type is desired, so we | 646 // If no type parameters were provided, a raw type is desired, so we |
| 646 // create a vector of DynamicType. | 647 // create a vector of DynamicType. |
| 647 if (!arguments.IsNull()) { | 648 if (!arguments.IsNull()) { |
| 648 type = arguments.TypeAt(i); | 649 type = arguments.TypeAt(i); |
| 649 } | 650 } |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 799 super_class = super_class.SuperClass(); | 800 super_class = super_class.SuperClass(); |
| 800 } | 801 } |
| 801 return Class::null(); | 802 return Class::null(); |
| 802 } | 803 } |
| 803 | 804 |
| 804 | 805 |
| 805 // Resolve and finalize the upper bounds of the type parameters of class cls. | 806 // Resolve and finalize the upper bounds of the type parameters of class cls. |
| 806 void ClassFinalizer::ResolveAndFinalizeUpperBounds(const Class& cls) { | 807 void ClassFinalizer::ResolveAndFinalizeUpperBounds(const Class& cls) { |
| 807 const intptr_t num_type_params = cls.NumTypeParameters(); | 808 const intptr_t num_type_params = cls.NumTypeParameters(); |
| 808 AbstractType& type_extends = AbstractType::Handle(); | 809 AbstractType& type_extends = AbstractType::Handle(); |
| 809 const TypeArguments& extends_array = | 810 const AbstractTypeArguments& extends_array = |
| 810 TypeArguments::Handle(cls.type_parameter_extends()); | 811 AbstractTypeArguments::Handle(cls.type_parameter_extends()); |
| 811 ASSERT((extends_array.IsNull() && (num_type_params == 0)) || | 812 ASSERT((extends_array.IsNull() && (num_type_params == 0)) || |
| 812 (extends_array.Length() == num_type_params)); | 813 (extends_array.Length() == num_type_params)); |
| 813 for (intptr_t i = 0; i < num_type_params; i++) { | 814 for (intptr_t i = 0; i < num_type_params; i++) { |
| 814 type_extends = extends_array.TypeAt(i); | 815 type_extends = extends_array.TypeAt(i); |
| 815 ResolveType(cls, type_extends); | 816 ResolveType(cls, type_extends); |
| 816 type_extends = FinalizeType(type_extends); | 817 type_extends = FinalizeType(type_extends); |
| 817 extends_array.SetTypeAt(i, type_extends); | 818 extends_array.SetTypeAt(i, type_extends); |
| 818 } | 819 } |
| 819 } | 820 } |
| 820 | 821 |
| (...skipping 469 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1290 va_end(args); | 1291 va_end(args); |
| 1291 if (FLAG_warning_as_error) { | 1292 if (FLAG_warning_as_error) { |
| 1292 Isolate::Current()->long_jump_base()->Jump(1, message_buffer); | 1293 Isolate::Current()->long_jump_base()->Jump(1, message_buffer); |
| 1293 UNREACHABLE(); | 1294 UNREACHABLE(); |
| 1294 } else { | 1295 } else { |
| 1295 OS::Print(message_buffer); | 1296 OS::Print(message_buffer); |
| 1296 } | 1297 } |
| 1297 } | 1298 } |
| 1298 | 1299 |
| 1299 } // namespace dart | 1300 } // namespace dart |
| OLD | NEW |