| 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/object.h" | 5 #include "vm/object.h" |
| 6 | 6 |
| 7 #include "platform/assert.h" | 7 #include "platform/assert.h" |
| 8 #include "vm/assembler.h" | 8 #include "vm/assembler.h" |
| 9 #include "vm/bigint_operations.h" | 9 #include "vm/bigint_operations.h" |
| 10 #include "vm/bootstrap.h" | 10 #include "vm/bootstrap.h" |
| (...skipping 1395 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1406 | 1406 |
| 1407 bool Class::IsCanonicalSignatureClass() const { | 1407 bool Class::IsCanonicalSignatureClass() const { |
| 1408 const Function& function = Function::Handle(signature_function()); | 1408 const Function& function = Function::Handle(signature_function()); |
| 1409 return (!function.IsNull() && (function.signature_class() == raw())); | 1409 return (!function.IsNull() && (function.signature_class() == raw())); |
| 1410 } | 1410 } |
| 1411 | 1411 |
| 1412 | 1412 |
| 1413 bool Class::IsMoreSpecificThan( | 1413 bool Class::IsMoreSpecificThan( |
| 1414 const AbstractTypeArguments& type_arguments, | 1414 const AbstractTypeArguments& type_arguments, |
| 1415 const Class& other, | 1415 const Class& other, |
| 1416 const AbstractTypeArguments& other_type_arguments) const { | 1416 const AbstractTypeArguments& other_type_arguments, |
| 1417 Error* malformed_error) const { |
| 1417 // Check for DynamicType. | 1418 // Check for DynamicType. |
| 1418 // The DynamicType on the lefthand side is replaced by the bottom type, which | 1419 // The DynamicType on the lefthand side is replaced by the bottom type, which |
| 1419 // is more specific than any type. | 1420 // is more specific than any type. |
| 1420 // Any type is more specific than the DynamicType on the righthand side. | 1421 // Any type is more specific than the DynamicType on the righthand side. |
| 1421 if (IsDynamicClass() || other.IsDynamicClass()) { | 1422 if (IsDynamicClass() || other.IsDynamicClass()) { |
| 1422 return true; | 1423 return true; |
| 1423 } | 1424 } |
| 1424 // Check for reflexivity. | 1425 // Check for reflexivity. |
| 1425 if (raw() == other.raw()) { | 1426 if (raw() == other.raw()) { |
| 1426 const intptr_t len = NumTypeArguments(); | 1427 const intptr_t len = NumTypeArguments(); |
| 1427 if (len == 0) { | 1428 if (len == 0) { |
| 1428 return true; | 1429 return true; |
| 1429 } | 1430 } |
| 1430 // Since we do not truncate the type argument vector of a subclass (see | 1431 // Since we do not truncate the type argument vector of a subclass (see |
| 1431 // below), we only check a prefix of the proper length. | 1432 // below), we only check a prefix of the proper length. |
| 1432 // Check for covariance. | 1433 // Check for covariance. |
| 1433 if (type_arguments.IsNull() || | 1434 if (type_arguments.IsNull() || |
| 1434 other_type_arguments.IsNull() || | 1435 other_type_arguments.IsNull() || |
| 1435 type_arguments.IsDynamicTypes(len) || | 1436 type_arguments.IsDynamicTypes(len) || |
| 1436 other_type_arguments.IsDynamicTypes(len)) { | 1437 other_type_arguments.IsDynamicTypes(len)) { |
| 1437 return true; | 1438 return true; |
| 1438 } | 1439 } |
| 1439 return type_arguments.IsMoreSpecificThan(other_type_arguments, len); | 1440 return type_arguments.IsMoreSpecificThan(other_type_arguments, |
| 1441 len, |
| 1442 malformed_error); |
| 1440 } | 1443 } |
| 1441 // Check for two function types. | 1444 // Check for two function types. |
| 1442 if (IsSignatureClass() && other.IsSignatureClass()) { | 1445 if (IsSignatureClass() && other.IsSignatureClass()) { |
| 1443 const Function& fun = Function::Handle(signature_function()); | 1446 const Function& fun = Function::Handle(signature_function()); |
| 1444 const Function& other_fun = Function::Handle(other.signature_function()); | 1447 const Function& other_fun = Function::Handle(other.signature_function()); |
| 1445 return fun.IsSubtypeOf(type_arguments, | 1448 return fun.IsSubtypeOf(type_arguments, |
| 1446 other_fun, | 1449 other_fun, |
| 1447 other_type_arguments); | 1450 other_type_arguments, |
| 1451 malformed_error); |
| 1448 } | 1452 } |
| 1449 // Check for 'direct super type' in the case of an interface and check for | 1453 // Check for 'direct super type' in the case of an interface and check for |
| 1450 // transitivity at the same time. | 1454 // transitivity at the same time. |
| 1451 if (other.is_interface()) { | 1455 if (other.is_interface()) { |
| 1452 Array& interfaces = Array::Handle(this->interfaces()); | 1456 Array& interfaces = Array::Handle(this->interfaces()); |
| 1453 AbstractType& interface = AbstractType::Handle(); | 1457 AbstractType& interface = AbstractType::Handle(); |
| 1454 Class& interface_class = Class::Handle(); | 1458 Class& interface_class = Class::Handle(); |
| 1455 AbstractTypeArguments& interface_args = AbstractTypeArguments::Handle(); | 1459 AbstractTypeArguments& interface_args = AbstractTypeArguments::Handle(); |
| 1456 for (intptr_t i = 0; i < interfaces.Length(); i++) { | 1460 for (intptr_t i = 0; i < interfaces.Length(); i++) { |
| 1457 interface ^= interfaces.At(i); | 1461 interface ^= interfaces.At(i); |
| 1458 interface_class = interface.type_class(); | 1462 interface_class = interface.type_class(); |
| 1459 interface_args = interface.arguments(); | 1463 interface_args = interface.arguments(); |
| 1460 if (!interface_args.IsNull() && !interface_args.IsInstantiated()) { | 1464 if (!interface_args.IsNull() && !interface_args.IsInstantiated()) { |
| 1461 // This type class implements an interface that is parameterized with | 1465 // This type class implements an interface that is parameterized with |
| 1462 // generic type(s), e.g. it implements List<T>. | 1466 // generic type(s), e.g. it implements List<T>. |
| 1463 // The uninstantiated type T must be instantiated using the type | 1467 // The uninstantiated type T must be instantiated using the type |
| 1464 // parameters of this type before performing the type test. | 1468 // parameters of this type before performing the type test. |
| 1465 // The type arguments of this type that are referred to by the type | 1469 // The type arguments of this type that are referred to by the type |
| 1466 // parameters of the interface are at the end of the type vector, | 1470 // parameters of the interface are at the end of the type vector, |
| 1467 // after the type arguments of the super type of this type. | 1471 // after the type arguments of the super type of this type. |
| 1468 // The index of the type parameters is adjusted upon finalization. | 1472 // The index of the type parameters is adjusted upon finalization. |
| 1469 ASSERT(interface.IsFinalized()); | 1473 ASSERT(interface.IsFinalized()); |
| 1470 interface_args = interface_args.InstantiateFrom(type_arguments); | 1474 interface_args = interface_args.InstantiateFrom(type_arguments); |
| 1471 // In checked mode, verify that the instantiated interface type | 1475 // In checked mode, verify that the instantiated interface type |
| 1472 // arguments are within the bounds specified by the interface class. | 1476 // arguments are within the bounds specified by the interface class. |
| 1473 // Note that the additional bounds check in checked mode may lead to a | 1477 // Note that the additional bounds check in checked mode may lead to a |
| 1474 // dynamic type error, but it will never change the result of the type | 1478 // dynamic type error, but it will never change the result of the type |
| 1475 // check from true in production mode to false in checked mode. | 1479 // check from true in production mode to false in checked mode. |
| 1476 if (FLAG_enable_type_checks && !interface_args.IsNull()) { | 1480 if (FLAG_enable_type_checks && !interface_args.IsNull()) { |
| 1477 AbstractTypeArguments& interface_bounds = | 1481 // Pass type_arguments as bounds instantiator. |
| 1478 AbstractTypeArguments::Handle( | 1482 if (!interface_args.IsWithinBoundsOf(interface_class, |
| 1479 interface_class.type_parameter_bounds()); | 1483 type_arguments, |
| 1480 ASSERT(!interface_bounds.IsNull()); | 1484 malformed_error)) { |
| 1481 if (!interface_bounds.IsInstantiated()) { | |
| 1482 interface_bounds = interface_bounds.InstantiateFrom(type_arguments); | |
| 1483 } | |
| 1484 const intptr_t len = interface_args.Length(); | |
| 1485 if (!interface_args.IsMoreSpecificThan(interface_bounds, len)) { | |
| 1486 // TODO(regis): Handle malformed type error. | |
| 1487 continue; | 1485 continue; |
| 1488 } | 1486 } |
| 1489 } | 1487 } |
| 1490 } | 1488 } |
| 1491 if (interface_class.IsMoreSpecificThan(interface_args, | 1489 if (interface_class.IsMoreSpecificThan(interface_args, |
| 1492 other, | 1490 other, |
| 1493 other_type_arguments)) { | 1491 other_type_arguments, |
| 1492 malformed_error)) { |
| 1494 return true; | 1493 return true; |
| 1495 } | 1494 } |
| 1496 } | 1495 } |
| 1497 } | 1496 } |
| 1498 // Check the interface case. | 1497 // Check the interface case. |
| 1499 if (is_interface()) { | 1498 if (is_interface()) { |
| 1500 // We already checked the case where 'other' is an interface. Now, 'this', | 1499 // We already checked the case where 'other' is an interface. Now, 'this', |
| 1501 // an interface, cannot be more specific than a class, except class Object, | 1500 // an interface, cannot be more specific than a class, except class Object, |
| 1502 // because although Object is not considered an interface by the vm, it is | 1501 // because although Object is not considered an interface by the vm, it is |
| 1503 // one. In other words, all classes implementing this interface also extend | 1502 // one. In other words, all classes implementing this interface also extend |
| 1504 // class Object. An interface is also more specific than the DynamicType. | 1503 // class Object. An interface is also more specific than the DynamicType. |
| 1505 return (other.IsDynamicClass() || other.IsObjectClass()); | 1504 return (other.IsDynamicClass() || other.IsObjectClass()); |
| 1506 } | 1505 } |
| 1507 const Class& super_class = Class::Handle(SuperClass()); | 1506 const Class& super_class = Class::Handle(SuperClass()); |
| 1508 if (super_class.IsNull()) { | 1507 if (super_class.IsNull()) { |
| 1509 return false; | 1508 return false; |
| 1510 } | 1509 } |
| 1511 // Instead of truncating the type argument vector to the length of the super | 1510 // Instead of truncating the type argument vector to the length of the super |
| 1512 // type argument vector, we make sure that the code works with a vector that | 1511 // type argument vector, we make sure that the code works with a vector that |
| 1513 // is longer than necessary. | 1512 // is longer than necessary. |
| 1514 return super_class.IsMoreSpecificThan(type_arguments, | 1513 return super_class.IsMoreSpecificThan(type_arguments, |
| 1515 other, | 1514 other, |
| 1516 other_type_arguments); | 1515 other_type_arguments, |
| 1516 malformed_error); |
| 1517 } | 1517 } |
| 1518 | 1518 |
| 1519 | 1519 |
| 1520 bool Class::IsTopLevel() const { | 1520 bool Class::IsTopLevel() const { |
| 1521 return String::Handle(Name()).Equals("::"); | 1521 return String::Handle(Name()).Equals("::"); |
| 1522 } | 1522 } |
| 1523 | 1523 |
| 1524 | 1524 |
| 1525 bool Class::TestType(TypeTestKind test, | 1525 bool Class::TestType(TypeTestKind test, |
| 1526 const AbstractTypeArguments& type_arguments, | 1526 const AbstractTypeArguments& type_arguments, |
| 1527 const Class& other, | 1527 const Class& other, |
| 1528 const AbstractTypeArguments& other_type_arguments) const { | 1528 const AbstractTypeArguments& other_type_arguments, |
| 1529 Error* malformed_error) const { |
| 1529 ASSERT(is_finalized() || !ClassFinalizer::AllClassesFinalized()); | 1530 ASSERT(is_finalized() || !ClassFinalizer::AllClassesFinalized()); |
| 1530 ASSERT(other.is_finalized() || !ClassFinalizer::AllClassesFinalized()); | 1531 ASSERT(other.is_finalized() || !ClassFinalizer::AllClassesFinalized()); |
| 1531 if (test == kIsAssignableTo) { | 1532 if (test == kIsAssignableTo) { |
| 1532 // The spec states that "a type T is assignable to a type S if T is a | 1533 // The spec states that "a type T is assignable to a type S if T is a |
| 1533 // subtype of S or S is a subtype of T". This is from the perspective of a | 1534 // subtype of S or S is a subtype of T". This is from the perspective of a |
| 1534 // static checker, which does not know the actual type of the assigned | 1535 // static checker, which does not know the actual type of the assigned |
| 1535 // value. However, this type information is available at run time in checked | 1536 // value. However, this type information is available at run time in checked |
| 1536 // mode. We therefore apply a more restrictive subtype check, which prevents | 1537 // mode. We therefore apply a more restrictive subtype check, which prevents |
| 1537 // heap pollution. We only keep the assignability check when assigning | 1538 // heap pollution. We only keep the assignability check when assigning |
| 1538 // values of a function type. | 1539 // values of a function type. |
| 1539 if (IsSignatureClass() && other.IsSignatureClass()) { | 1540 if (IsSignatureClass() && other.IsSignatureClass()) { |
| 1540 const Function& src_fun = Function::Handle(signature_function()); | 1541 const Function& src_fun = Function::Handle(signature_function()); |
| 1541 const Function& dst_fun = Function::Handle(other.signature_function()); | 1542 const Function& dst_fun = Function::Handle(other.signature_function()); |
| 1542 return src_fun.IsAssignableTo(type_arguments, | 1543 return src_fun.IsAssignableTo(type_arguments, |
| 1543 dst_fun, | 1544 dst_fun, |
| 1544 other_type_arguments); | 1545 other_type_arguments, |
| 1546 malformed_error); |
| 1545 } | 1547 } |
| 1546 // Continue with a subtype test. | 1548 // Continue with a subtype test. |
| 1547 test = kIsSubtypeOf; | 1549 test = kIsSubtypeOf; |
| 1548 } | 1550 } |
| 1549 ASSERT(test == kIsSubtypeOf); | 1551 ASSERT(test == kIsSubtypeOf); |
| 1550 | 1552 |
| 1551 // Check for "more specific" relation. | 1553 // Check for "more specific" relation. |
| 1552 return IsMoreSpecificThan(type_arguments, other, other_type_arguments); | 1554 return IsMoreSpecificThan(type_arguments, other, other_type_arguments, |
| 1555 malformed_error); |
| 1553 } | 1556 } |
| 1554 | 1557 |
| 1555 | 1558 |
| 1556 RawFunction* Class::LookupDynamicFunction(const String& name) const { | 1559 RawFunction* Class::LookupDynamicFunction(const String& name) const { |
| 1557 Function& function = Function::Handle(LookupFunction(name)); | 1560 Function& function = Function::Handle(LookupFunction(name)); |
| 1558 if (function.IsNull() || !function.IsDynamicFunction()) { | 1561 if (function.IsNull() || !function.IsDynamicFunction()) { |
| 1559 return Function::null(); | 1562 return Function::null(); |
| 1560 } | 1563 } |
| 1561 return function.raw(); | 1564 return function.raw(); |
| 1562 } | 1565 } |
| (...skipping 536 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2099 (type_class() == Type::Handle(Type::FunctionInterface()).type_class()); | 2102 (type_class() == Type::Handle(Type::FunctionInterface()).type_class()); |
| 2100 } | 2103 } |
| 2101 | 2104 |
| 2102 | 2105 |
| 2103 bool AbstractType::IsListInterface() const { | 2106 bool AbstractType::IsListInterface() const { |
| 2104 return HasResolvedTypeClass() && | 2107 return HasResolvedTypeClass() && |
| 2105 (type_class() == Type::Handle(Type::ListInterface()).type_class()); | 2108 (type_class() == Type::Handle(Type::ListInterface()).type_class()); |
| 2106 } | 2109 } |
| 2107 | 2110 |
| 2108 | 2111 |
| 2109 bool AbstractType::IsMoreSpecificThan(const AbstractType& other) const { | 2112 bool AbstractType::IsMoreSpecificThan(const AbstractType& other, |
| 2113 Error* malformed_error) const { |
| 2110 ASSERT(IsFinalized()); | 2114 ASSERT(IsFinalized()); |
| 2111 ASSERT(other.IsFinalized()); | 2115 ASSERT(other.IsFinalized()); |
| 2112 // AbstractType parameters cannot be handled by Class::IsMoreSpecificThan(). | 2116 // AbstractType parameters cannot be handled by Class::IsMoreSpecificThan(). |
| 2113 if (IsTypeParameter() || other.IsTypeParameter()) { | 2117 if (IsTypeParameter() || other.IsTypeParameter()) { |
| 2114 return IsTypeParameter() && other.IsTypeParameter() && | 2118 return IsTypeParameter() && other.IsTypeParameter() && |
| 2115 (Index() == other.Index()); | 2119 (Index() == other.Index()); |
| 2116 } | 2120 } |
| 2117 const Class& cls = Class::Handle(type_class()); | 2121 const Class& cls = Class::Handle(type_class()); |
| 2118 return cls.IsMoreSpecificThan( | 2122 return cls.IsMoreSpecificThan( |
| 2119 AbstractTypeArguments::Handle(arguments()), | 2123 AbstractTypeArguments::Handle(arguments()), |
| 2120 Class::Handle(other.type_class()), | 2124 Class::Handle(other.type_class()), |
| 2121 AbstractTypeArguments::Handle(other.arguments())); | 2125 AbstractTypeArguments::Handle(other.arguments()), |
| 2126 malformed_error); |
| 2122 } | 2127 } |
| 2123 | 2128 |
| 2124 | 2129 |
| 2125 bool AbstractType::Test(TypeTestKind test, const AbstractType& other) const { | 2130 bool AbstractType::Test(TypeTestKind test, |
| 2131 const AbstractType& other, |
| 2132 Error* malformed_error) const { |
| 2126 ASSERT(IsFinalized()); | 2133 ASSERT(IsFinalized()); |
| 2127 ASSERT(other.IsFinalized()); | 2134 ASSERT(other.IsFinalized()); |
| 2128 // AbstractType parameters cannot be handled by Class::TestType(). | 2135 // AbstractType parameters cannot be handled by Class::TestType(). |
| 2129 if (IsTypeParameter() || other.IsTypeParameter()) { | 2136 if (IsTypeParameter() || other.IsTypeParameter()) { |
| 2130 return IsTypeParameter() && other.IsTypeParameter() && | 2137 return IsTypeParameter() && other.IsTypeParameter() && |
| 2131 (Index() == other.Index()); | 2138 (Index() == other.Index()); |
| 2132 } | 2139 } |
| 2133 const Class& cls = Class::Handle(type_class()); | 2140 const Class& cls = Class::Handle(type_class()); |
| 2134 if (test == kIsSubtypeOf) { | 2141 if (test == kIsSubtypeOf) { |
| 2135 return cls.IsSubtypeOf(AbstractTypeArguments::Handle(arguments()), | 2142 return cls.IsSubtypeOf(AbstractTypeArguments::Handle(arguments()), |
| 2136 Class::Handle(other.type_class()), | 2143 Class::Handle(other.type_class()), |
| 2137 AbstractTypeArguments::Handle(other.arguments())); | 2144 AbstractTypeArguments::Handle(other.arguments()), |
| 2145 malformed_error); |
| 2138 } else { | 2146 } else { |
| 2139 ASSERT(test == kIsAssignableTo); | 2147 ASSERT(test == kIsAssignableTo); |
| 2140 return cls.IsAssignableTo(AbstractTypeArguments::Handle(arguments()), | 2148 return cls.IsAssignableTo(AbstractTypeArguments::Handle(arguments()), |
| 2141 Class::Handle(other.type_class()), | 2149 Class::Handle(other.type_class()), |
| 2142 AbstractTypeArguments::Handle(other.arguments())); | 2150 AbstractTypeArguments::Handle(other.arguments()), |
| 2151 malformed_error); |
| 2143 } | 2152 } |
| 2144 } | 2153 } |
| 2145 | 2154 |
| 2146 RawAbstractType* AbstractType::NewTypeParameter( | 2155 RawAbstractType* AbstractType::NewTypeParameter( |
| 2147 intptr_t index, const String& name, intptr_t token_index) { | 2156 intptr_t index, const String& name, intptr_t token_index) { |
| 2148 return TypeParameter::New(index, name, token_index); | 2157 return TypeParameter::New(index, name, token_index); |
| 2149 } | 2158 } |
| 2150 | 2159 |
| 2151 | 2160 |
| 2152 RawAbstractType* AbstractType::NewInstantiatedType( | 2161 RawAbstractType* AbstractType::NewInstantiatedType( |
| (...skipping 570 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2723 } | 2732 } |
| 2724 type_class = type.type_class(); | 2733 type_class = type.type_class(); |
| 2725 if (!type_class.IsDynamicClass()) { | 2734 if (!type_class.IsDynamicClass()) { |
| 2726 return false; | 2735 return false; |
| 2727 } | 2736 } |
| 2728 } | 2737 } |
| 2729 return true; | 2738 return true; |
| 2730 } | 2739 } |
| 2731 | 2740 |
| 2732 | 2741 |
| 2742 static RawError* FormatError(const Script& script, |
| 2743 intptr_t token_index, |
| 2744 const char* format, ...) { |
| 2745 va_list args; |
| 2746 va_start(args, format); |
| 2747 return Parser::FormatError(script, token_index, "Error", format, args); |
| 2748 } |
| 2749 |
| 2750 |
| 2751 bool AbstractTypeArguments::IsWithinBoundsOf( |
| 2752 const Class& cls, |
| 2753 const AbstractTypeArguments& bounds_instantiator, |
| 2754 Error* malformed_error) const { |
| 2755 ASSERT(FLAG_enable_type_checks); |
| 2756 ASSERT(IsInstantiated()); |
| 2757 ASSERT(Length() >= cls.NumTypeArguments()); |
| 2758 const intptr_t num_type_params = cls.NumTypeParameters(); |
| 2759 const intptr_t offset = cls.NumTypeArguments() - num_type_params; |
| 2760 AbstractType& type = AbstractType::Handle(); |
| 2761 AbstractType& bound = AbstractType::Handle(); |
| 2762 const TypeArguments& bounds = |
| 2763 TypeArguments::Handle(cls.type_parameter_bounds()); |
| 2764 ASSERT((bounds.IsNull() && (num_type_params == 0)) || |
| 2765 (bounds.Length() == num_type_params)); |
| 2766 for (intptr_t i = 0; i < num_type_params; i++) { |
| 2767 bound = bounds.TypeAt(i); |
| 2768 if (!bound.IsDynamicType()) { |
| 2769 type = TypeAt(offset + i); |
| 2770 if (!bound.IsInstantiated()) { |
| 2771 bound = bound.InstantiateFrom(bounds_instantiator); |
| 2772 } |
| 2773 if (!type.IsSubtypeOf(bound, malformed_error)) { |
| 2774 if (malformed_error->IsNull()) { |
| 2775 const String& type_argument_name = String::Handle(type.Name()); |
| 2776 const String& class_name = String::Handle(cls.Name()); |
| 2777 const String& bound_name = String::Handle(bound.Name()); |
| 2778 const Script& script = Script::Handle(cls.script()); |
| 2779 // Since the bound was canonicalized, its token index was lost, |
| 2780 // therefore, use the token index of the corresponding type parameter. |
| 2781 const TypeArguments& type_parameters = |
| 2782 TypeArguments::Handle(cls.type_parameters()); |
| 2783 type = type_parameters.TypeAt(i); |
| 2784 *malformed_error ^= FormatError(script, type.token_index(), |
| 2785 "type argument '%s' does not " |
| 2786 "extend bound '%s' of '%s'\n", |
| 2787 type_argument_name.ToCString(), |
| 2788 bound_name.ToCString(), |
| 2789 class_name.ToCString()); |
| 2790 } |
| 2791 return false; |
| 2792 } |
| 2793 } |
| 2794 } |
| 2795 const Type& super_type = Type::Handle(cls.super_type()); |
| 2796 if (!super_type.IsNull()) { |
| 2797 ASSERT(super_type.IsFinalized()); |
| 2798 const Class& super_class = Class::Handle(super_type.type_class()); |
| 2799 if (!IsWithinBoundsOf(super_class, bounds_instantiator, malformed_error)) { |
| 2800 return false; |
| 2801 } |
| 2802 } |
| 2803 return true; |
| 2804 } |
| 2805 |
| 2806 |
| 2733 bool AbstractTypeArguments::IsMoreSpecificThan( | 2807 bool AbstractTypeArguments::IsMoreSpecificThan( |
| 2734 const AbstractTypeArguments& other, | 2808 const AbstractTypeArguments& other, |
| 2735 intptr_t len) const { | 2809 intptr_t len, |
| 2810 Error* malformed_error) const { |
| 2736 ASSERT(Length() >= len); | 2811 ASSERT(Length() >= len); |
| 2737 ASSERT(!other.IsNull()); | 2812 ASSERT(!other.IsNull()); |
| 2738 ASSERT(other.Length() >= len); | 2813 ASSERT(other.Length() >= len); |
| 2739 AbstractType& type = AbstractType::Handle(); | 2814 AbstractType& type = AbstractType::Handle(); |
| 2740 AbstractType& other_type = AbstractType::Handle(); | 2815 AbstractType& other_type = AbstractType::Handle(); |
| 2741 for (intptr_t i = 0; i < len; i++) { | 2816 for (intptr_t i = 0; i < len; i++) { |
| 2742 type = TypeAt(i); | 2817 type = TypeAt(i); |
| 2743 ASSERT(!type.IsNull()); | 2818 ASSERT(!type.IsNull()); |
| 2744 other_type = other.TypeAt(i); | 2819 other_type = other.TypeAt(i); |
| 2745 ASSERT(!other_type.IsNull()); | 2820 ASSERT(!other_type.IsNull()); |
| 2746 if (!type.IsMoreSpecificThan(other_type)) { | 2821 if (!type.IsMoreSpecificThan(other_type, malformed_error)) { |
| 2747 return false; | 2822 return false; |
| 2748 } | 2823 } |
| 2749 } | 2824 } |
| 2750 return true; | 2825 return true; |
| 2751 } | 2826 } |
| 2752 | 2827 |
| 2753 | 2828 |
| 2754 const char* AbstractTypeArguments::ToCString() const { | 2829 const char* AbstractTypeArguments::ToCString() const { |
| 2755 // AbstractTypeArguments is an abstract class. | 2830 // AbstractTypeArguments is an abstract class. |
| 2756 UNREACHABLE(); | 2831 UNREACHABLE(); |
| (...skipping 529 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3286 } | 3361 } |
| 3287 } | 3362 } |
| 3288 return true; | 3363 return true; |
| 3289 } | 3364 } |
| 3290 | 3365 |
| 3291 | 3366 |
| 3292 bool Function::TestParameterType( | 3367 bool Function::TestParameterType( |
| 3293 intptr_t parameter_position, | 3368 intptr_t parameter_position, |
| 3294 const AbstractTypeArguments& type_arguments, | 3369 const AbstractTypeArguments& type_arguments, |
| 3295 const Function& other, | 3370 const Function& other, |
| 3296 const AbstractTypeArguments& other_type_arguments) const { | 3371 const AbstractTypeArguments& other_type_arguments, |
| 3372 Error* malformed_error) const { |
| 3297 AbstractType& param_type = | 3373 AbstractType& param_type = |
| 3298 AbstractType::Handle(ParameterTypeAt(parameter_position)); | 3374 AbstractType::Handle(ParameterTypeAt(parameter_position)); |
| 3299 if (!param_type.IsInstantiated()) { | 3375 if (!param_type.IsInstantiated()) { |
| 3300 param_type = param_type.InstantiateFrom(type_arguments); | 3376 param_type = param_type.InstantiateFrom(type_arguments); |
| 3301 } | 3377 } |
| 3302 if (param_type.IsDynamicType()) { | 3378 if (param_type.IsDynamicType()) { |
| 3303 return true; | 3379 return true; |
| 3304 } | 3380 } |
| 3305 AbstractType& other_param_type = | 3381 AbstractType& other_param_type = |
| 3306 AbstractType::Handle(other.ParameterTypeAt(parameter_position)); | 3382 AbstractType::Handle(other.ParameterTypeAt(parameter_position)); |
| 3307 if (!other_param_type.IsInstantiated()) { | 3383 if (!other_param_type.IsInstantiated()) { |
| 3308 other_param_type = other_param_type.InstantiateFrom(other_type_arguments); | 3384 other_param_type = other_param_type.InstantiateFrom(other_type_arguments); |
| 3309 } | 3385 } |
| 3310 if (other_param_type.IsDynamicType()) { | 3386 if (other_param_type.IsDynamicType()) { |
| 3311 return true; | 3387 return true; |
| 3312 } | 3388 } |
| 3313 if (!param_type.IsSubtypeOf(other_param_type) && | 3389 if (!param_type.IsSubtypeOf(other_param_type, malformed_error) && |
| 3314 !other_param_type.IsSubtypeOf(param_type)) { | 3390 !other_param_type.IsSubtypeOf(param_type, malformed_error)) { |
| 3315 return false; | 3391 return false; |
| 3316 } | 3392 } |
| 3317 return true; | 3393 return true; |
| 3318 } | 3394 } |
| 3319 | 3395 |
| 3320 | 3396 |
| 3321 bool Function::TestType( | 3397 bool Function::TestType( |
| 3322 TypeTestKind test, | 3398 TypeTestKind test, |
| 3323 const AbstractTypeArguments& type_arguments, | 3399 const AbstractTypeArguments& type_arguments, |
| 3324 const Function& other, | 3400 const Function& other, |
| 3325 const AbstractTypeArguments& other_type_arguments) const { | 3401 const AbstractTypeArguments& other_type_arguments, |
| 3402 Error* malformed_error) const { |
| 3326 const intptr_t num_fixed_params = num_fixed_parameters(); | 3403 const intptr_t num_fixed_params = num_fixed_parameters(); |
| 3327 const intptr_t num_opt_params = num_optional_parameters(); | 3404 const intptr_t num_opt_params = num_optional_parameters(); |
| 3328 const intptr_t other_num_fixed_params = other.num_fixed_parameters(); | 3405 const intptr_t other_num_fixed_params = other.num_fixed_parameters(); |
| 3329 const intptr_t other_num_opt_params = other.num_optional_parameters(); | 3406 const intptr_t other_num_opt_params = other.num_optional_parameters(); |
| 3330 if ((num_fixed_params != other_num_fixed_params) || | 3407 if ((num_fixed_params != other_num_fixed_params) || |
| 3331 ((test == AbstractType::kIsSubtypeOf) && | 3408 ((test == AbstractType::kIsSubtypeOf) && |
| 3332 (num_opt_params < other_num_opt_params))) { | 3409 (num_opt_params < other_num_opt_params))) { |
| 3333 return false; | 3410 return false; |
| 3334 } | 3411 } |
| 3335 // Check the result type. | 3412 // Check the result type. |
| 3336 AbstractType& other_res_type = AbstractType::Handle(other.result_type()); | 3413 AbstractType& other_res_type = AbstractType::Handle(other.result_type()); |
| 3337 if (!other_res_type.IsInstantiated()) { | 3414 if (!other_res_type.IsInstantiated()) { |
| 3338 other_res_type = other_res_type.InstantiateFrom(other_type_arguments); | 3415 other_res_type = other_res_type.InstantiateFrom(other_type_arguments); |
| 3339 } | 3416 } |
| 3340 if (!other_res_type.IsDynamicType() && !other_res_type.IsVoidType()) { | 3417 if (!other_res_type.IsDynamicType() && !other_res_type.IsVoidType()) { |
| 3341 AbstractType& res_type = AbstractType::Handle(result_type()); | 3418 AbstractType& res_type = AbstractType::Handle(result_type()); |
| 3342 if (!res_type.IsInstantiated()) { | 3419 if (!res_type.IsInstantiated()) { |
| 3343 res_type = res_type.InstantiateFrom(type_arguments); | 3420 res_type = res_type.InstantiateFrom(type_arguments); |
| 3344 } | 3421 } |
| 3345 if (!res_type.IsDynamicType() && | 3422 if (!res_type.IsDynamicType() && |
| 3346 (res_type.IsVoidType() || | 3423 (res_type.IsVoidType() || |
| 3347 !(res_type.IsSubtypeOf(other_res_type) || | 3424 !(res_type.IsSubtypeOf(other_res_type, malformed_error) || |
| 3348 other_res_type.IsSubtypeOf(res_type)))) { | 3425 other_res_type.IsSubtypeOf(res_type, malformed_error)))) { |
| 3349 return false; | 3426 return false; |
| 3350 } | 3427 } |
| 3351 } | 3428 } |
| 3352 // Check the types of fixed parameters. | 3429 // Check the types of fixed parameters. |
| 3353 for (intptr_t i = 0; i < num_fixed_params; i++) { | 3430 for (intptr_t i = 0; i < num_fixed_params; i++) { |
| 3354 if (!TestParameterType(i, type_arguments, other, other_type_arguments)) { | 3431 if (!TestParameterType(i, type_arguments, other, other_type_arguments, |
| 3432 malformed_error)) { |
| 3355 return false; | 3433 return false; |
| 3356 } | 3434 } |
| 3357 } | 3435 } |
| 3358 // Check the names and types of optional parameters. | 3436 // Check the names and types of optional parameters. |
| 3359 if (num_opt_params >= other_num_opt_params) { | 3437 if (num_opt_params >= other_num_opt_params) { |
| 3360 // Check that for each optional named parameter of type T of the other | 3438 // Check that for each optional named parameter of type T of the other |
| 3361 // function type, there is a corresponding optional named parameter of this | 3439 // function type, there is a corresponding optional named parameter of this |
| 3362 // function at the same position with an identical name and with a type S | 3440 // function at the same position with an identical name and with a type S |
| 3363 // that is a subtype or supertype of T. | 3441 // that is a subtype or supertype of T. |
| 3364 // Note that SetParameterNameAt() guarantees that names are symbols, so we | 3442 // Note that SetParameterNameAt() guarantees that names are symbols, so we |
| 3365 // can compare their raw pointers. | 3443 // can compare their raw pointers. |
| 3366 const intptr_t other_num_params = | 3444 const intptr_t other_num_params = |
| 3367 other_num_fixed_params + other_num_opt_params; | 3445 other_num_fixed_params + other_num_opt_params; |
| 3368 String& other_param_name = String::Handle(); | 3446 String& other_param_name = String::Handle(); |
| 3369 for (intptr_t i = other_num_fixed_params; i < other_num_params; i++) { | 3447 for (intptr_t i = other_num_fixed_params; i < other_num_params; i++) { |
| 3370 other_param_name = other.ParameterNameAt(i); | 3448 other_param_name = other.ParameterNameAt(i); |
| 3371 if ((ParameterNameAt(i) != other_param_name.raw()) || | 3449 if ((ParameterNameAt(i) != other_param_name.raw()) || |
| 3372 !TestParameterType(i, type_arguments, other, other_type_arguments)) { | 3450 !TestParameterType(i, type_arguments, other, other_type_arguments, |
| 3451 malformed_error)) { |
| 3373 return false; | 3452 return false; |
| 3374 } | 3453 } |
| 3375 } | 3454 } |
| 3376 return true; | 3455 return true; |
| 3377 } | 3456 } |
| 3378 ASSERT((test == AbstractType::kIsAssignableTo) && | 3457 ASSERT((test == AbstractType::kIsAssignableTo) && |
| 3379 (num_opt_params < other_num_opt_params)); | 3458 (num_opt_params < other_num_opt_params)); |
| 3380 // To verify that this function type is assignable to the other function type, | 3459 // To verify that this function type is assignable to the other function type, |
| 3381 // check that for each optional named parameter of type T of this function | 3460 // check that for each optional named parameter of type T of this function |
| 3382 // type, there is a corresponding optional named parameter of the other | 3461 // type, there is a corresponding optional named parameter of the other |
| 3383 // function at the same position with an identical name and with a type S that | 3462 // function at the same position with an identical name and with a type S that |
| 3384 // is a subtype or supertype of T. | 3463 // is a subtype or supertype of T. |
| 3385 // Note that SetParameterNameAt() guarantees that names are symbols, so we | 3464 // Note that SetParameterNameAt() guarantees that names are symbols, so we |
| 3386 // can compare their raw pointers. | 3465 // can compare their raw pointers. |
| 3387 const intptr_t num_params = num_fixed_params + num_opt_params; | 3466 const intptr_t num_params = num_fixed_params + num_opt_params; |
| 3388 String& other_param_name = String::Handle(); | 3467 String& other_param_name = String::Handle(); |
| 3389 for (intptr_t i = num_fixed_params; i < num_params; i++) { | 3468 for (intptr_t i = num_fixed_params; i < num_params; i++) { |
| 3390 other_param_name = other.ParameterNameAt(i); | 3469 other_param_name = other.ParameterNameAt(i); |
| 3391 if ((ParameterNameAt(i) != other_param_name.raw()) || | 3470 if ((ParameterNameAt(i) != other_param_name.raw()) || |
| 3392 !TestParameterType(i, type_arguments, other, other_type_arguments)) { | 3471 !TestParameterType(i, type_arguments, other, other_type_arguments, |
| 3472 malformed_error)) { |
| 3393 return false; | 3473 return false; |
| 3394 } | 3474 } |
| 3395 } | 3475 } |
| 3396 return true; | 3476 return true; |
| 3397 } | 3477 } |
| 3398 | 3478 |
| 3399 | 3479 |
| 3400 bool Function::IsImplicitClosureFunction() const { | 3480 bool Function::IsImplicitClosureFunction() const { |
| 3401 if (!IsClosureFunction()) { | 3481 if (!IsClosureFunction()) { |
| 3402 return false; | 3482 return false; |
| (...skipping 2546 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5949 void Instance::SetTypeArguments(const AbstractTypeArguments& value) const { | 6029 void Instance::SetTypeArguments(const AbstractTypeArguments& value) const { |
| 5950 const Class& cls = Class::Handle(clazz()); | 6030 const Class& cls = Class::Handle(clazz()); |
| 5951 intptr_t field_offset = cls.type_arguments_instance_field_offset(); | 6031 intptr_t field_offset = cls.type_arguments_instance_field_offset(); |
| 5952 ASSERT(field_offset != Class::kNoTypeArguments); | 6032 ASSERT(field_offset != Class::kNoTypeArguments); |
| 5953 *FieldAddrAtOffset(field_offset) = value.Canonicalize(); | 6033 *FieldAddrAtOffset(field_offset) = value.Canonicalize(); |
| 5954 } | 6034 } |
| 5955 | 6035 |
| 5956 | 6036 |
| 5957 bool Instance::TestType(TypeTestKind test, | 6037 bool Instance::TestType(TypeTestKind test, |
| 5958 const AbstractType& other, | 6038 const AbstractType& other, |
| 5959 const AbstractTypeArguments& other_instantiator) const { | 6039 const AbstractTypeArguments& other_instantiator, |
| 6040 Error* malformed_error) const { |
| 5960 ASSERT(other.IsFinalized()); | 6041 ASSERT(other.IsFinalized()); |
| 5961 ASSERT(!other.IsDynamicType()); | 6042 ASSERT(!other.IsDynamicType()); |
| 5962 ASSERT(!other.IsVoidType()); | 6043 ASSERT(!other.IsVoidType()); |
| 5963 if (IsNull()) { | 6044 if (IsNull()) { |
| 5964 if (test == AbstractType::kIsSubtypeOf) { | 6045 if (test == AbstractType::kIsSubtypeOf) { |
| 5965 Class& other_class = Class::Handle(); | 6046 Class& other_class = Class::Handle(); |
| 5966 if (other.IsTypeParameter()) { | 6047 if (other.IsTypeParameter()) { |
| 5967 if (other_instantiator.IsNull()) { | 6048 if (other_instantiator.IsNull()) { |
| 5968 return true; // Other type is uninstantiated, i.e. Dynamic. | 6049 return true; // Other type is uninstantiated, i.e. Dynamic. |
| 5969 } | 6050 } |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6013 other_type_arguments = instantiated_other.arguments(); | 6094 other_type_arguments = instantiated_other.arguments(); |
| 6014 } else { | 6095 } else { |
| 6015 other_class = other.type_class(); | 6096 other_class = other.type_class(); |
| 6016 other_type_arguments = other.arguments(); | 6097 other_type_arguments = other.arguments(); |
| 6017 if (!other_type_arguments.IsNull() && | 6098 if (!other_type_arguments.IsNull() && |
| 6018 !other_type_arguments.IsInstantiated()) { | 6099 !other_type_arguments.IsInstantiated()) { |
| 6019 other_type_arguments = | 6100 other_type_arguments = |
| 6020 other_type_arguments.InstantiateFrom(other_instantiator); | 6101 other_type_arguments.InstantiateFrom(other_instantiator); |
| 6021 } | 6102 } |
| 6022 } | 6103 } |
| 6023 return cls.TestType(test, type_arguments, other_class, other_type_arguments); | 6104 return cls.TestType(test, type_arguments, other_class, other_type_arguments, |
| 6105 malformed_error); |
| 6024 } | 6106 } |
| 6025 | 6107 |
| 6026 | 6108 |
| 6027 bool Instance::IsValidNativeIndex(int index) const { | 6109 bool Instance::IsValidNativeIndex(int index) const { |
| 6028 const Class& cls = Class::Handle(clazz()); | 6110 const Class& cls = Class::Handle(clazz()); |
| 6029 return (index >= 0 && index < cls.num_native_fields()); | 6111 return (index >= 0 && index < cls.num_native_fields()); |
| 6030 } | 6112 } |
| 6031 | 6113 |
| 6032 | 6114 |
| 6033 RawInstance* Instance::New(const Class& cls, Heap::Space space) { | 6115 RawInstance* Instance::New(const Class& cls, Heap::Space space) { |
| (...skipping 2490 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8524 result.set_num_args_tested(num_args_tested); | 8606 result.set_num_args_tested(num_args_tested); |
| 8525 // Number of array elements in one test entry (num_args_tested + 1) | 8607 // Number of array elements in one test entry (num_args_tested + 1) |
| 8526 intptr_t len = result.TestEntryLength(); | 8608 intptr_t len = result.TestEntryLength(); |
| 8527 // IC data array must be null terminated (sentinel entry). | 8609 // IC data array must be null terminated (sentinel entry). |
| 8528 Array& ic_data = Array::Handle(Array::New(len, Heap::kOld)); | 8610 Array& ic_data = Array::Handle(Array::New(len, Heap::kOld)); |
| 8529 result.set_ic_data(ic_data); | 8611 result.set_ic_data(ic_data); |
| 8530 return result.raw(); | 8612 return result.raw(); |
| 8531 } | 8613 } |
| 8532 | 8614 |
| 8533 } // namespace dart | 8615 } // namespace dart |
| OLD | NEW |