| 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 #ifndef VM_OBJECT_H_ | 5 #ifndef VM_OBJECT_H_ |
| 6 #define VM_OBJECT_H_ | 6 #define VM_OBJECT_H_ |
| 7 | 7 |
| 8 #include "include/dart_api.h" | 8 #include "include/dart_api.h" |
| 9 #include "platform/assert.h" | 9 #include "platform/assert.h" |
| 10 #include "platform/utils.h" | 10 #include "platform/utils.h" |
| (...skipping 557 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 568 } | 568 } |
| 569 | 569 |
| 570 // Check if this class represents a canonical signature class, i.e. not an | 570 // Check if this class represents a canonical signature class, i.e. not an |
| 571 // alias as defined in a typedef. | 571 // alias as defined in a typedef. |
| 572 bool IsCanonicalSignatureClass() const; | 572 bool IsCanonicalSignatureClass() const; |
| 573 | 573 |
| 574 // Check the "more specific than" relationship. | 574 // Check the "more specific than" relationship. |
| 575 bool IsMoreSpecificThan( | 575 bool IsMoreSpecificThan( |
| 576 const AbstractTypeArguments& type_arguments, | 576 const AbstractTypeArguments& type_arguments, |
| 577 const Class& other, | 577 const Class& other, |
| 578 const AbstractTypeArguments& other_type_arguments) const; | 578 const AbstractTypeArguments& other_type_arguments, |
| 579 Error* malformed_error) const; |
| 579 | 580 |
| 580 // Check the subtype relationship. | 581 // Check the subtype relationship. |
| 581 bool IsSubtypeOf(const AbstractTypeArguments& type_arguments, | 582 bool IsSubtypeOf(const AbstractTypeArguments& type_arguments, |
| 582 const Class& other, | 583 const Class& other, |
| 583 const AbstractTypeArguments& other_type_arguments) const { | 584 const AbstractTypeArguments& other_type_arguments, |
| 585 Error* malformed_error) const { |
| 584 return TestType(kIsSubtypeOf, | 586 return TestType(kIsSubtypeOf, |
| 585 type_arguments, | 587 type_arguments, |
| 586 other, | 588 other, |
| 587 other_type_arguments); | 589 other_type_arguments, |
| 590 malformed_error); |
| 588 } | 591 } |
| 589 | 592 |
| 590 // Check the assignability relationship. | 593 // Check the assignability relationship. |
| 591 bool IsAssignableTo(const AbstractTypeArguments& type_arguments, | 594 bool IsAssignableTo(const AbstractTypeArguments& type_arguments, |
| 592 const Class& dst, | 595 const Class& dst, |
| 593 const AbstractTypeArguments& dst_type_arguments) const { | 596 const AbstractTypeArguments& dst_type_arguments, |
| 597 Error* malformed_error) const { |
| 594 return TestType(kIsAssignableTo, | 598 return TestType(kIsAssignableTo, |
| 595 type_arguments, | 599 type_arguments, |
| 596 dst, | 600 dst, |
| 597 dst_type_arguments); | 601 dst_type_arguments, |
| 602 malformed_error); |
| 598 } | 603 } |
| 599 | 604 |
| 600 // Check if this is the top level class. | 605 // Check if this is the top level class. |
| 601 bool IsTopLevel() const; | 606 bool IsTopLevel() const; |
| 602 | 607 |
| 603 RawArray* fields() const { return raw_ptr()->fields_; } | 608 RawArray* fields() const { return raw_ptr()->fields_; } |
| 604 void SetFields(const Array& value) const; | 609 void SetFields(const Array& value) const; |
| 605 | 610 |
| 606 RawArray* functions() const { return raw_ptr()->functions_; } | 611 RawArray* functions() const { return raw_ptr()->functions_; } |
| 607 void SetFunctions(const Array& value) const; | 612 void SetFunctions(const Array& value) const; |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 710 | 715 |
| 711 void set_canonical_types(const Array& value) const; | 716 void set_canonical_types(const Array& value) const; |
| 712 RawArray* canonical_types() const; | 717 RawArray* canonical_types() const; |
| 713 | 718 |
| 714 void CalculateFieldOffsets() const; | 719 void CalculateFieldOffsets() const; |
| 715 | 720 |
| 716 // Check the subtype or assignability relationship. | 721 // Check the subtype or assignability relationship. |
| 717 bool TestType(TypeTestKind test, | 722 bool TestType(TypeTestKind test, |
| 718 const AbstractTypeArguments& type_arguments, | 723 const AbstractTypeArguments& type_arguments, |
| 719 const Class& other, | 724 const Class& other, |
| 720 const AbstractTypeArguments& other_type_arguments) const; | 725 const AbstractTypeArguments& other_type_arguments, |
| 726 Error* malformed_error) const; |
| 721 | 727 |
| 722 // Assigns empty array to all raw class array fields. | 728 // Assigns empty array to all raw class array fields. |
| 723 void InitEmptyFields(); | 729 void InitEmptyFields(); |
| 724 | 730 |
| 725 RawFunction* LookupAccessorFunction(const char* prefix, | 731 RawFunction* LookupAccessorFunction(const char* prefix, |
| 726 intptr_t prefix_length, | 732 intptr_t prefix_length, |
| 727 const String& name) const; | 733 const String& name) const; |
| 728 | 734 |
| 729 HEAP_OBJECT_IMPLEMENTATION(Class, Object); | 735 HEAP_OBJECT_IMPLEMENTATION(Class, Object); |
| 730 friend class Object; | 736 friend class Object; |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 850 // Check if this type is an interface type. | 856 // Check if this type is an interface type. |
| 851 bool IsInterfaceType() const { | 857 bool IsInterfaceType() const { |
| 852 if (!HasResolvedTypeClass()) { | 858 if (!HasResolvedTypeClass()) { |
| 853 return false; | 859 return false; |
| 854 } | 860 } |
| 855 const Class& cls = Class::Handle(type_class()); | 861 const Class& cls = Class::Handle(type_class()); |
| 856 return !cls.IsNull() && cls.is_interface(); | 862 return !cls.IsNull() && cls.is_interface(); |
| 857 } | 863 } |
| 858 | 864 |
| 859 // Check the "more specific than" relationship. | 865 // Check the "more specific than" relationship. |
| 860 bool IsMoreSpecificThan(const AbstractType& other) const; | 866 bool IsMoreSpecificThan(const AbstractType& other, |
| 867 Error* malformed_error) const; |
| 861 | 868 |
| 862 // Check the subtype relationship. | 869 // Check the subtype relationship. |
| 863 bool IsSubtypeOf(const AbstractType& other) const { | 870 bool IsSubtypeOf(const AbstractType& other, Error* malformed_error) const { |
| 864 return Test(kIsSubtypeOf, other); | 871 return Test(kIsSubtypeOf, other, malformed_error); |
| 865 } | 872 } |
| 866 | 873 |
| 867 // Check the assignability relationship. | 874 // Check the assignability relationship. |
| 868 bool IsAssignableTo(const AbstractType& dst) const { | 875 bool IsAssignableTo(const AbstractType& dst, |
| 869 return Test(kIsAssignableTo, dst); | 876 Error* malformed_error) const { |
| 877 return Test(kIsAssignableTo, dst, malformed_error); |
| 870 } | 878 } |
| 871 | 879 |
| 872 static RawAbstractType* NewTypeParameter(intptr_t index, | 880 static RawAbstractType* NewTypeParameter(intptr_t index, |
| 873 const String& name, | 881 const String& name, |
| 874 intptr_t token_index); | 882 intptr_t token_index); |
| 875 | 883 |
| 876 static RawAbstractType* NewInstantiatedType( | 884 static RawAbstractType* NewInstantiatedType( |
| 877 const AbstractType& uninstantiated_type, | 885 const AbstractType& uninstantiated_type, |
| 878 const AbstractTypeArguments& instantiator_type_arguments); | 886 const AbstractTypeArguments& instantiator_type_arguments); |
| 879 | 887 |
| 880 protected: | 888 protected: |
| 881 // Check the subtype or assignability relationship. | 889 // Check the subtype or assignability relationship. |
| 882 bool Test(TypeTestKind test, const AbstractType& other) const; | 890 bool Test(TypeTestKind test, |
| 891 const AbstractType& other, |
| 892 Error* malformed_error) const; |
| 883 | 893 |
| 884 HEAP_OBJECT_IMPLEMENTATION(AbstractType, Object); | 894 HEAP_OBJECT_IMPLEMENTATION(AbstractType, Object); |
| 885 friend class Class; | 895 friend class Class; |
| 886 }; | 896 }; |
| 887 | 897 |
| 888 | 898 |
| 889 // A Type consists of a class, possibly parameterized with type | 899 // A Type consists of a class, possibly parameterized with type |
| 890 // arguments. Example: C<T1, T2>. | 900 // arguments. Example: C<T1, T2>. |
| 891 // An unresolved class is a String specifying the class name. | 901 // An unresolved class is a String specifying the class name. |
| 892 class Type : public AbstractType { | 902 class Type : public AbstractType { |
| (...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1078 virtual RawAbstractTypeArguments* InstantiateFrom( | 1088 virtual RawAbstractTypeArguments* InstantiateFrom( |
| 1079 const AbstractTypeArguments& instantiator_type_arguments) const; | 1089 const AbstractTypeArguments& instantiator_type_arguments) const; |
| 1080 | 1090 |
| 1081 // Do not canonicalize InstantiatedTypeArguments or NULL objects | 1091 // Do not canonicalize InstantiatedTypeArguments or NULL objects |
| 1082 virtual RawAbstractTypeArguments* Canonicalize() const { return this->raw(); } | 1092 virtual RawAbstractTypeArguments* Canonicalize() const { return this->raw(); } |
| 1083 | 1093 |
| 1084 // Check if this type argument vector consists solely of DynamicType, | 1094 // Check if this type argument vector consists solely of DynamicType, |
| 1085 // considering only a prefix of length 'len'. | 1095 // considering only a prefix of length 'len'. |
| 1086 bool IsDynamicTypes(intptr_t len) const; | 1096 bool IsDynamicTypes(intptr_t len) const; |
| 1087 | 1097 |
| 1098 // Check that this type argument vector is within the declared bounds of the |
| 1099 // given class or interface. If not, set malformed_error (if not yet set). |
| 1100 bool IsWithinBoundsOf(const Class& cls, |
| 1101 const AbstractTypeArguments& bounds_instantiator, |
| 1102 Error* malformed_error) const; |
| 1103 |
| 1088 // Check the "more specific than" relationship, considering only a prefix of | 1104 // Check the "more specific than" relationship, considering only a prefix of |
| 1089 // length 'len'. | 1105 // length 'len'. |
| 1090 bool IsMoreSpecificThan( | 1106 bool IsMoreSpecificThan(const AbstractTypeArguments& other, |
| 1091 const AbstractTypeArguments& other, intptr_t len) const; | 1107 intptr_t len, |
| 1108 Error* malformed_error) const; |
| 1092 | 1109 |
| 1093 bool Equals(const AbstractTypeArguments& other) const; | 1110 bool Equals(const AbstractTypeArguments& other) const; |
| 1094 | 1111 |
| 1095 // UNREACHABLEs as AbstractTypeArguments is an abstract class. | 1112 // UNREACHABLEs as AbstractTypeArguments is an abstract class. |
| 1096 virtual intptr_t Length() const; | 1113 virtual intptr_t Length() const; |
| 1097 virtual RawAbstractType* TypeAt(intptr_t index) const; | 1114 virtual RawAbstractType* TypeAt(intptr_t index) const; |
| 1098 virtual void SetTypeAt(intptr_t index, const AbstractType& value) const; | 1115 virtual void SetTypeAt(intptr_t index, const AbstractType& value) const; |
| 1099 virtual bool IsResolved() const; | 1116 virtual bool IsResolved() const; |
| 1100 virtual bool IsInstantiated() const; | 1117 virtual bool IsInstantiated() const; |
| 1101 virtual bool IsUninstantiatedIdentity() const; | 1118 virtual bool IsUninstantiatedIdentity() const; |
| (...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1386 | 1403 |
| 1387 // Returns true if this function has parameters that are compatible with the | 1404 // Returns true if this function has parameters that are compatible with the |
| 1388 // parameters of the other function in order for this function to override the | 1405 // parameters of the other function in order for this function to override the |
| 1389 // other function. Parameter types are ignored. | 1406 // other function. Parameter types are ignored. |
| 1390 bool HasCompatibleParametersWith(const Function& other) const; | 1407 bool HasCompatibleParametersWith(const Function& other) const; |
| 1391 | 1408 |
| 1392 // Returns true if the type of this function is a subtype of the type of | 1409 // Returns true if the type of this function is a subtype of the type of |
| 1393 // the other function. | 1410 // the other function. |
| 1394 bool IsSubtypeOf(const AbstractTypeArguments& type_arguments, | 1411 bool IsSubtypeOf(const AbstractTypeArguments& type_arguments, |
| 1395 const Function& other, | 1412 const Function& other, |
| 1396 const AbstractTypeArguments& other_type_arguments) const { | 1413 const AbstractTypeArguments& other_type_arguments, |
| 1414 Error* malformed_error) const { |
| 1397 return TestType(kIsSubtypeOf, | 1415 return TestType(kIsSubtypeOf, |
| 1398 type_arguments, | 1416 type_arguments, |
| 1399 other, | 1417 other, |
| 1400 other_type_arguments); | 1418 other_type_arguments, |
| 1419 malformed_error); |
| 1401 } | 1420 } |
| 1402 | 1421 |
| 1403 // Returns true if the type of this function can be assigned to the type of | 1422 // Returns true if the type of this function can be assigned to the type of |
| 1404 // the destination function. | 1423 // the destination function. |
| 1405 bool IsAssignableTo(const AbstractTypeArguments& type_arguments, | 1424 bool IsAssignableTo(const AbstractTypeArguments& type_arguments, |
| 1406 const Function& dst, | 1425 const Function& dst, |
| 1407 const AbstractTypeArguments& dst_type_arguments) const { | 1426 const AbstractTypeArguments& dst_type_arguments, |
| 1427 Error* malformed_error) const { |
| 1408 return TestType(kIsAssignableTo, | 1428 return TestType(kIsAssignableTo, |
| 1409 type_arguments, | 1429 type_arguments, |
| 1410 dst, | 1430 dst, |
| 1411 dst_type_arguments); | 1431 dst_type_arguments, |
| 1432 malformed_error); |
| 1412 } | 1433 } |
| 1413 | 1434 |
| 1414 // Returns true if this function represents a (possibly implicit) closure | 1435 // Returns true if this function represents a (possibly implicit) closure |
| 1415 // function. | 1436 // function. |
| 1416 bool IsClosureFunction() const { | 1437 bool IsClosureFunction() const { |
| 1417 return kind() == RawFunction::kClosureFunction; | 1438 return kind() == RawFunction::kClosureFunction; |
| 1418 } | 1439 } |
| 1419 | 1440 |
| 1420 // Returns true if this function represents an implicit closure function. | 1441 // Returns true if this function represents an implicit closure function. |
| 1421 bool IsImplicitClosureFunction() const; | 1442 bool IsImplicitClosureFunction() const; |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1481 static RawFunction* New(); | 1502 static RawFunction* New(); |
| 1482 | 1503 |
| 1483 RawString* BuildSignature(bool instantiate, | 1504 RawString* BuildSignature(bool instantiate, |
| 1484 const AbstractTypeArguments& instantiator) const; | 1505 const AbstractTypeArguments& instantiator) const; |
| 1485 | 1506 |
| 1486 // Checks the subtype or assignability relationship between the type of this | 1507 // Checks the subtype or assignability relationship between the type of this |
| 1487 // function and the type of the other function. | 1508 // function and the type of the other function. |
| 1488 bool TestType(TypeTestKind test, | 1509 bool TestType(TypeTestKind test, |
| 1489 const AbstractTypeArguments& type_arguments, | 1510 const AbstractTypeArguments& type_arguments, |
| 1490 const Function& other, | 1511 const Function& other, |
| 1491 const AbstractTypeArguments& other_type_arguments) const; | 1512 const AbstractTypeArguments& other_type_arguments, |
| 1513 Error* malformed_error) const; |
| 1492 | 1514 |
| 1493 // Checks the type of the formal parameter at the given position for | 1515 // Checks the type of the formal parameter at the given position for |
| 1494 // assignability relationship between the type of this function and the type | 1516 // assignability relationship between the type of this function and the type |
| 1495 // of the other function. | 1517 // of the other function. |
| 1496 bool TestParameterType( | 1518 bool TestParameterType( |
| 1497 intptr_t parameter_position, | 1519 intptr_t parameter_position, |
| 1498 const AbstractTypeArguments& type_arguments, | 1520 const AbstractTypeArguments& type_arguments, |
| 1499 const Function& other, | 1521 const Function& other, |
| 1500 const AbstractTypeArguments& other_type_arguments) const; | 1522 const AbstractTypeArguments& other_type_arguments, |
| 1523 Error* malformed_error) const; |
| 1501 | 1524 |
| 1502 HEAP_OBJECT_IMPLEMENTATION(Function, Object); | 1525 HEAP_OBJECT_IMPLEMENTATION(Function, Object); |
| 1503 friend class Class; | 1526 friend class Class; |
| 1504 }; | 1527 }; |
| 1505 | 1528 |
| 1506 | 1529 |
| 1507 class Field : public Object { | 1530 class Field : public Object { |
| 1508 public: | 1531 public: |
| 1509 RawString* name() const { return raw_ptr()->name_; } | 1532 RawString* name() const { return raw_ptr()->name_; } |
| 1510 bool is_static() const { return raw_ptr()->is_static_; } | 1533 bool is_static() const { return raw_ptr()->is_static_; } |
| (...skipping 942 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2453 StorePointer(FieldAddr(field), value.raw()); | 2476 StorePointer(FieldAddr(field), value.raw()); |
| 2454 } | 2477 } |
| 2455 | 2478 |
| 2456 RawType* GetType() const; | 2479 RawType* GetType() const; |
| 2457 | 2480 |
| 2458 virtual RawAbstractTypeArguments* GetTypeArguments() const; | 2481 virtual RawAbstractTypeArguments* GetTypeArguments() const; |
| 2459 virtual void SetTypeArguments(const AbstractTypeArguments& value) const; | 2482 virtual void SetTypeArguments(const AbstractTypeArguments& value) const; |
| 2460 | 2483 |
| 2461 // Check if this instance is an instance of the given type. | 2484 // Check if this instance is an instance of the given type. |
| 2462 bool IsInstanceOf(const AbstractType& type, | 2485 bool IsInstanceOf(const AbstractType& type, |
| 2463 const AbstractTypeArguments& type_instantiator) const { | 2486 const AbstractTypeArguments& type_instantiator, |
| 2464 return TestType(kIsSubtypeOf, type, type_instantiator); | 2487 Error* malformed_error) const { |
| 2488 return TestType(kIsSubtypeOf, type, type_instantiator, malformed_error); |
| 2465 } | 2489 } |
| 2466 | 2490 |
| 2467 // Check if this instance is assignable to the given type. | 2491 // Check if this instance is assignable to the given type. |
| 2468 bool IsAssignableTo(const AbstractType& type, | 2492 bool IsAssignableTo(const AbstractType& type, |
| 2469 const AbstractTypeArguments& type_instantiator) const { | 2493 const AbstractTypeArguments& type_instantiator, |
| 2470 return TestType(kIsAssignableTo, type, type_instantiator); | 2494 Error* malformed_error) const { |
| 2495 return TestType(kIsAssignableTo, type, type_instantiator, malformed_error); |
| 2471 } | 2496 } |
| 2472 | 2497 |
| 2473 bool IsValidNativeIndex(int index) const; | 2498 bool IsValidNativeIndex(int index) const; |
| 2474 | 2499 |
| 2475 intptr_t GetNativeField(int index) const { | 2500 intptr_t GetNativeField(int index) const { |
| 2476 return *NativeFieldAddr(index); | 2501 return *NativeFieldAddr(index); |
| 2477 } | 2502 } |
| 2478 | 2503 |
| 2479 void SetNativeField(int index, intptr_t value) const { | 2504 void SetNativeField(int index, intptr_t value) const { |
| 2480 *NativeFieldAddr(index) = value; | 2505 *NativeFieldAddr(index) = value; |
| (...skipping 21 matching lines...) Expand all Loading... |
| 2502 } | 2527 } |
| 2503 void SetFieldAtOffset(intptr_t offset, const Object& value) const { | 2528 void SetFieldAtOffset(intptr_t offset, const Object& value) const { |
| 2504 StorePointer(FieldAddrAtOffset(offset), value.raw()); | 2529 StorePointer(FieldAddrAtOffset(offset), value.raw()); |
| 2505 } | 2530 } |
| 2506 bool IsValidFieldOffset(int offset) const; | 2531 bool IsValidFieldOffset(int offset) const; |
| 2507 | 2532 |
| 2508 // Check the subtype or assignability relationship between the type of this | 2533 // Check the subtype or assignability relationship between the type of this |
| 2509 // instance and the given type. | 2534 // instance and the given type. |
| 2510 bool TestType(TypeTestKind test, | 2535 bool TestType(TypeTestKind test, |
| 2511 const AbstractType& type, | 2536 const AbstractType& type, |
| 2512 const AbstractTypeArguments& type_instantiator) const; | 2537 const AbstractTypeArguments& type_instantiator, |
| 2538 Error* malformed_error) const; |
| 2513 | 2539 |
| 2514 // TODO(iposva): Determine if this gets in the way of Smi. | 2540 // TODO(iposva): Determine if this gets in the way of Smi. |
| 2515 HEAP_OBJECT_IMPLEMENTATION(Instance, Object); | 2541 HEAP_OBJECT_IMPLEMENTATION(Instance, Object); |
| 2516 friend class Class; | 2542 friend class Class; |
| 2517 }; | 2543 }; |
| 2518 | 2544 |
| 2519 | 2545 |
| 2520 class Number : public Instance { | 2546 class Number : public Instance { |
| 2521 public: | 2547 public: |
| 2522 // TODO(iposva): Fill in a useful Number interface. | 2548 // TODO(iposva): Fill in a useful Number interface. |
| (...skipping 1283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3806 } | 3832 } |
| 3807 | 3833 |
| 3808 | 3834 |
| 3809 void Context::SetAt(intptr_t index, const Instance& value) const { | 3835 void Context::SetAt(intptr_t index, const Instance& value) const { |
| 3810 StorePointer(InstanceAddr(index), value.raw()); | 3836 StorePointer(InstanceAddr(index), value.raw()); |
| 3811 } | 3837 } |
| 3812 | 3838 |
| 3813 } // namespace dart | 3839 } // namespace dart |
| 3814 | 3840 |
| 3815 #endif // VM_OBJECT_H_ | 3841 #endif // VM_OBJECT_H_ |
| OLD | NEW |