| 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 #ifndef VM_OBJECT_H_ | 5 #ifndef VM_OBJECT_H_ |
| 6 #define VM_OBJECT_H_ | 6 #define VM_OBJECT_H_ |
| 7 | 7 |
| 8 #include "vm/assert.h" | 8 #include "vm/assert.h" |
| 9 #include "vm/dart.h" | 9 #include "vm/dart.h" |
| 10 #include "vm/globals.h" | 10 #include "vm/globals.h" |
| (...skipping 687 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 698 virtual bool IsFinalized() const; | 698 virtual bool IsFinalized() const; |
| 699 virtual bool IsBeingFinalized() const; | 699 virtual bool IsBeingFinalized() const; |
| 700 virtual bool IsResolved() const; | 700 virtual bool IsResolved() const; |
| 701 virtual bool HasResolvedTypeClass() const; | 701 virtual bool HasResolvedTypeClass() const; |
| 702 virtual RawClass* type_class() const; | 702 virtual RawClass* type_class() const; |
| 703 virtual RawUnresolvedClass* unresolved_class() const; | 703 virtual RawUnresolvedClass* unresolved_class() const; |
| 704 virtual RawAbstractTypeArguments* arguments() const; | 704 virtual RawAbstractTypeArguments* arguments() const; |
| 705 virtual bool IsInstantiated() const; | 705 virtual bool IsInstantiated() const; |
| 706 virtual bool Equals(const AbstractType& other) const; | 706 virtual bool Equals(const AbstractType& other) const; |
| 707 | 707 |
| 708 // Instantiate this type using the given type argument vector starting at the | 708 // Instantiate this type using the given type argument vector. |
| 709 // given offset. | |
| 710 // Return a new type, or return 'this' if it is already instantiated. | 709 // Return a new type, or return 'this' if it is already instantiated. |
| 711 virtual RawAbstractType* InstantiateFrom( | 710 virtual RawAbstractType* InstantiateFrom( |
| 712 const AbstractTypeArguments& instantiator_type_arguments, | 711 const AbstractTypeArguments& instantiator_type_arguments) const; |
| 713 intptr_t offset) const; | |
| 714 | 712 |
| 715 // Return the canonical version of this type. | 713 // Return the canonical version of this type. |
| 716 virtual RawAbstractType* Canonicalize() const; | 714 virtual RawAbstractType* Canonicalize() const; |
| 717 | 715 |
| 718 // The name of this type, including the names of its type arguments, if any. | 716 // The name of this type, including the names of its type arguments, if any. |
| 719 virtual RawString* Name() const; | 717 virtual RawString* Name() const; |
| 720 | 718 |
| 721 // The index of this type parameter. Fail if not a type parameter. | 719 // The index of this type parameter. Fail if not a type parameter. |
| 722 virtual intptr_t Index() const; | 720 virtual intptr_t Index() const; |
| 723 | 721 |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 814 virtual bool IsResolved() const; // Class and all arguments classes resolved. | 812 virtual bool IsResolved() const; // Class and all arguments classes resolved. |
| 815 virtual bool HasResolvedTypeClass() const; // Own type class resolved. | 813 virtual bool HasResolvedTypeClass() const; // Own type class resolved. |
| 816 virtual RawClass* type_class() const; | 814 virtual RawClass* type_class() const; |
| 817 void set_type_class(const Object& value) const; | 815 void set_type_class(const Object& value) const; |
| 818 virtual RawUnresolvedClass* unresolved_class() const; | 816 virtual RawUnresolvedClass* unresolved_class() const; |
| 819 virtual RawAbstractTypeArguments* arguments() const; | 817 virtual RawAbstractTypeArguments* arguments() const; |
| 820 void set_arguments(const AbstractTypeArguments& value) const; | 818 void set_arguments(const AbstractTypeArguments& value) const; |
| 821 virtual bool IsInstantiated() const; | 819 virtual bool IsInstantiated() const; |
| 822 virtual bool Equals(const AbstractType& other) const; | 820 virtual bool Equals(const AbstractType& other) const; |
| 823 virtual RawAbstractType* InstantiateFrom( | 821 virtual RawAbstractType* InstantiateFrom( |
| 824 const AbstractTypeArguments& instantiator_type_arguments, | 822 const AbstractTypeArguments& instantiator_type_arguments) const; |
| 825 intptr_t offset) const; | |
| 826 virtual RawAbstractType* Canonicalize() const; | 823 virtual RawAbstractType* Canonicalize() const; |
| 827 | 824 |
| 828 static intptr_t InstanceSize() { | 825 static intptr_t InstanceSize() { |
| 829 return RoundedAllocationSize(sizeof(RawType)); | 826 return RoundedAllocationSize(sizeof(RawType)); |
| 830 } | 827 } |
| 831 | 828 |
| 832 // The type of the literal 'null'. | 829 // The type of the literal 'null'. |
| 833 static RawType* NullType(); | 830 static RawType* NullType(); |
| 834 | 831 |
| 835 // The 'Dynamic' type. | 832 // The 'Dynamic' type. |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 884 HEAP_OBJECT_IMPLEMENTATION(Type, AbstractType); | 881 HEAP_OBJECT_IMPLEMENTATION(Type, AbstractType); |
| 885 friend class Class; | 882 friend class Class; |
| 886 }; | 883 }; |
| 887 | 884 |
| 888 | 885 |
| 889 // A TypeParameter, in the context of a parameterized class, references a type | 886 // A TypeParameter, in the context of a parameterized class, references a type |
| 890 // parameter of a class by its index (and by its name for debugging purposes). | 887 // parameter of a class by its index (and by its name for debugging purposes). |
| 891 // For example, the type parameter 'V' is specified as index 1 in the context of | 888 // For example, the type parameter 'V' is specified as index 1 in the context of |
| 892 // the class HashMap<K, V>. At compile time, the TypeParameter is not | 889 // the class HashMap<K, V>. At compile time, the TypeParameter is not |
| 893 // instantiated yet, i.e. it is only a place holder. | 890 // instantiated yet, i.e. it is only a place holder. |
| 891 // Upon finalization, the TypeParameter index is changed to reflect its position |
| 892 // as type argument (rather than type parameter) of the enclosing class. |
| 894 class TypeParameter : public AbstractType { | 893 class TypeParameter : public AbstractType { |
| 895 public: | 894 public: |
| 896 virtual bool IsFinalized() const { return true; } | 895 virtual bool IsFinalized() const { |
| 896 return raw_ptr()->type_state_ == RawTypeParameter::kFinalized; |
| 897 } |
| 898 void set_is_finalized() const; |
| 897 virtual bool IsBeingFinalized() const { return false; } | 899 virtual bool IsBeingFinalized() const { return false; } |
| 898 virtual bool IsResolved() const { return true; } | 900 virtual bool IsResolved() const { return true; } |
| 899 virtual bool HasResolvedTypeClass() const { return false; } | 901 virtual bool HasResolvedTypeClass() const { return false; } |
| 900 virtual RawString* Name() const { return raw_ptr()->name_; } | 902 virtual RawString* Name() const { return raw_ptr()->name_; } |
| 901 virtual intptr_t Index() const { return raw_ptr()->index_; } | 903 virtual intptr_t Index() const { return raw_ptr()->index_; } |
| 904 void set_index(intptr_t value) const; |
| 902 virtual bool IsInstantiated() const { return false; } | 905 virtual bool IsInstantiated() const { return false; } |
| 903 virtual bool Equals(const AbstractType& other) const; | 906 virtual bool Equals(const AbstractType& other) const; |
| 904 virtual RawAbstractType* InstantiateFrom( | 907 virtual RawAbstractType* InstantiateFrom( |
| 905 const AbstractTypeArguments& instantiator_type_arguments, | 908 const AbstractTypeArguments& instantiator_type_arguments) const; |
| 906 intptr_t offset) const; | |
| 907 virtual RawAbstractType* Canonicalize() const { return raw(); } | 909 virtual RawAbstractType* Canonicalize() const { return raw(); } |
| 908 | 910 |
| 909 static intptr_t InstanceSize() { | 911 static intptr_t InstanceSize() { |
| 910 return RoundedAllocationSize(sizeof(RawTypeParameter)); | 912 return RoundedAllocationSize(sizeof(RawTypeParameter)); |
| 911 } | 913 } |
| 912 | 914 |
| 913 static RawTypeParameter* New(intptr_t index, const String& name); | 915 static RawTypeParameter* New(intptr_t index, const String& name); |
| 914 | 916 |
| 915 private: | 917 private: |
| 916 void set_index(intptr_t value) const; | |
| 917 void set_name(const String& value) const; | 918 void set_name(const String& value) const; |
| 919 void set_type_state(int8_t state) const; |
| 918 static RawTypeParameter* New(); | 920 static RawTypeParameter* New(); |
| 919 | 921 |
| 920 HEAP_OBJECT_IMPLEMENTATION(TypeParameter, AbstractType); | 922 HEAP_OBJECT_IMPLEMENTATION(TypeParameter, AbstractType); |
| 921 friend class Class; | 923 friend class Class; |
| 922 }; | 924 }; |
| 923 | 925 |
| 924 | 926 |
| 925 // An instance of InstantiatedType is never encountered at compile time, but | 927 // An instance of InstantiatedType is never encountered at compile time, but |
| 926 // only at run time, when type parameters can be matched to actual types. | 928 // only at run time, when type parameters can be matched to actual types. |
| 927 // An instance of InstantiatedType consists of an uninstantiated AbstractType | 929 // An instance of InstantiatedType consists of an uninstantiated AbstractType |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 970 // AbstractTypeArguments is an abstract superclass. | 972 // AbstractTypeArguments is an abstract superclass. |
| 971 // Subclasses of AbstractTypeArguments are TypeArguments and InstantiatedTypes. | 973 // Subclasses of AbstractTypeArguments are TypeArguments and InstantiatedTypes. |
| 972 class AbstractTypeArguments : public Object { | 974 class AbstractTypeArguments : public Object { |
| 973 public: | 975 public: |
| 974 static bool AreEqual(const AbstractTypeArguments& arguments, | 976 static bool AreEqual(const AbstractTypeArguments& arguments, |
| 975 const AbstractTypeArguments& other_arguments); | 977 const AbstractTypeArguments& other_arguments); |
| 976 | 978 |
| 977 // Return 'this' if this type argument vector is instantiated, i.e. if it does | 979 // Return 'this' if this type argument vector is instantiated, i.e. if it does |
| 978 // not refer to type parameters. Otherwise, return a new type argument vector | 980 // not refer to type parameters. Otherwise, return a new type argument vector |
| 979 // where each reference to a type parameter is replaced with the corresponding | 981 // where each reference to a type parameter is replaced with the corresponding |
| 980 // type of the instantiator type argument vector starting at the given offset. | 982 // type of the instantiator type argument vector. |
| 981 virtual RawAbstractTypeArguments* InstantiateFrom( | 983 virtual RawAbstractTypeArguments* InstantiateFrom( |
| 982 const AbstractTypeArguments& instantiator_type_arguments, | 984 const AbstractTypeArguments& instantiator_type_arguments) const; |
| 983 intptr_t offset) const; | |
| 984 | 985 |
| 985 // Do not canonicalize InstantiatedTypeArguments or NULL objects | 986 // Do not canonicalize InstantiatedTypeArguments or NULL objects |
| 986 virtual RawAbstractTypeArguments* Canonicalize() const { return this->raw(); } | 987 virtual RawAbstractTypeArguments* Canonicalize() const { return this->raw(); } |
| 987 | 988 |
| 988 // Check if this type argument vector consists solely of DynamicType, | 989 // Check if this type argument vector consists solely of DynamicType, |
| 989 // considering only a prefix of length 'len'. | 990 // considering only a prefix of length 'len'. |
| 990 bool IsDynamicTypes(intptr_t len) const; | 991 bool IsDynamicTypes(intptr_t len) const; |
| 991 | 992 |
| 992 // Check the "more specific than" relationship, considering only a prefix of | 993 // Check the "more specific than" relationship, considering only a prefix of |
| 993 // length 'len'. | 994 // length 'len'. |
| (...skipping 22 matching lines...) Expand all Loading... |
| 1016 virtual intptr_t Length() const; | 1017 virtual intptr_t Length() const; |
| 1017 virtual RawAbstractType* TypeAt(intptr_t index) const; | 1018 virtual RawAbstractType* TypeAt(intptr_t index) const; |
| 1018 virtual void SetTypeAt(intptr_t index, const AbstractType& value) const; | 1019 virtual void SetTypeAt(intptr_t index, const AbstractType& value) const; |
| 1019 virtual bool IsResolved() const; | 1020 virtual bool IsResolved() const; |
| 1020 virtual bool IsInstantiated() const; | 1021 virtual bool IsInstantiated() const; |
| 1021 virtual bool IsUninstantiatedIdentity() const; | 1022 virtual bool IsUninstantiatedIdentity() const; |
| 1022 // Canonicalize only if instantiated, otherwise returns 'this'. | 1023 // Canonicalize only if instantiated, otherwise returns 'this'. |
| 1023 virtual RawAbstractTypeArguments* Canonicalize() const; | 1024 virtual RawAbstractTypeArguments* Canonicalize() const; |
| 1024 | 1025 |
| 1025 virtual RawAbstractTypeArguments* InstantiateFrom( | 1026 virtual RawAbstractTypeArguments* InstantiateFrom( |
| 1026 const AbstractTypeArguments& instantiator_type_arguments, | 1027 const AbstractTypeArguments& instantiator_type_arguments) const; |
| 1027 intptr_t offset) const; | |
| 1028 | 1028 |
| 1029 static intptr_t length_offset() { | 1029 static intptr_t length_offset() { |
| 1030 return OFFSET_OF(RawTypeArguments, length_); | 1030 return OFFSET_OF(RawTypeArguments, length_); |
| 1031 } | 1031 } |
| 1032 | 1032 |
| 1033 static intptr_t InstanceSize() { | 1033 static intptr_t InstanceSize() { |
| 1034 ASSERT(sizeof(RawTypeArguments) == OFFSET_OF(RawTypeArguments, types_)); | 1034 ASSERT(sizeof(RawTypeArguments) == OFFSET_OF(RawTypeArguments, types_)); |
| 1035 return 0; | 1035 return 0; |
| 1036 } | 1036 } |
| 1037 | 1037 |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1112 }; | 1112 }; |
| 1113 | 1113 |
| 1114 | 1114 |
| 1115 class Function : public Object { | 1115 class Function : public Object { |
| 1116 public: | 1116 public: |
| 1117 RawString* name() const { return raw_ptr()->name_; } | 1117 RawString* name() const { return raw_ptr()->name_; } |
| 1118 | 1118 |
| 1119 // Build a string of the form '<T, R>(T, [b: B, c: C]) => R' representing the | 1119 // Build a string of the form '<T, R>(T, [b: B, c: C]) => R' representing the |
| 1120 // signature of the given function. | 1120 // signature of the given function. |
| 1121 RawString* Signature() const { | 1121 RawString* Signature() const { |
| 1122 return BuildSignature(false, TypeArguments::Handle(), 0); | 1122 return BuildSignature(false, TypeArguments::Handle()); |
| 1123 } | 1123 } |
| 1124 | 1124 |
| 1125 // Build a string of the form '(A, [b: B, c: C]) => D' representing the | 1125 // Build a string of the form '(A, [b: B, c: C]) => D' representing the |
| 1126 // signature of the given function, where all generic types (e.g. '<T, R>' in | 1126 // signature of the given function, where all generic types (e.g. '<T, R>' in |
| 1127 // '<T, R>(T, [b: B, c: C]) => R') are instantiated using the given | 1127 // '<T, R>(T, [b: B, c: C]) => R') are instantiated using the given |
| 1128 // instantiator type argument vector (e.g. '<A, D>'). | 1128 // instantiator type argument vector (e.g. '<A, D>'). |
| 1129 RawString* InstantiatedSignatureFrom( | 1129 RawString* InstantiatedSignatureFrom( |
| 1130 const AbstractTypeArguments& instantiator, | 1130 const AbstractTypeArguments& instantiator) const { |
| 1131 intptr_t offset) const { | 1131 return BuildSignature(true, instantiator); |
| 1132 return BuildSignature(true, instantiator, offset); | |
| 1133 } | 1132 } |
| 1134 | 1133 |
| 1135 // Returns true if the signature of this function is instantiated, i.e. if it | 1134 // Returns true if the signature of this function is instantiated, i.e. if it |
| 1136 // does not involve generic parameter types or generic result type. | 1135 // does not involve generic parameter types or generic result type. |
| 1137 bool HasInstantiatedSignature() const; | 1136 bool HasInstantiatedSignature() const; |
| 1138 | 1137 |
| 1139 RawClass* owner() const { return raw_ptr()->owner_; } | 1138 RawClass* owner() const { return raw_ptr()->owner_; } |
| 1140 void set_owner(const Class& value) const; | 1139 void set_owner(const Class& value) const; |
| 1141 | 1140 |
| 1142 RawAbstractType* result_type() const { return raw_ptr()->result_type_; } | 1141 RawAbstractType* result_type() const { return raw_ptr()->result_type_; } |
| (...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1333 void set_name(const String& value) const; | 1332 void set_name(const String& value) const; |
| 1334 void set_kind(RawFunction::Kind value) const; | 1333 void set_kind(RawFunction::Kind value) const; |
| 1335 void set_is_static(bool is_static) const; | 1334 void set_is_static(bool is_static) const; |
| 1336 void set_is_const(bool is_const) const; | 1335 void set_is_const(bool is_const) const; |
| 1337 void set_parent_function(const Function& value) const; | 1336 void set_parent_function(const Function& value) const; |
| 1338 void set_token_index(intptr_t value) const; | 1337 void set_token_index(intptr_t value) const; |
| 1339 void set_implicit_closure_function(const Function& value) const; | 1338 void set_implicit_closure_function(const Function& value) const; |
| 1340 static RawFunction* New(); | 1339 static RawFunction* New(); |
| 1341 | 1340 |
| 1342 RawString* BuildSignature(bool instantiate, | 1341 RawString* BuildSignature(bool instantiate, |
| 1343 const AbstractTypeArguments& instantiator, | 1342 const AbstractTypeArguments& instantiator) const; |
| 1344 intptr_t offset) const; | |
| 1345 | 1343 |
| 1346 // Checks the subtype or assignability relationship between the type of this | 1344 // Checks the subtype or assignability relationship between the type of this |
| 1347 // function and the type of the other function. | 1345 // function and the type of the other function. |
| 1348 bool TestType(TypeTestKind test, | 1346 bool TestType(TypeTestKind test, |
| 1349 const AbstractTypeArguments& type_arguments, | 1347 const AbstractTypeArguments& type_arguments, |
| 1350 const Function& other, | 1348 const Function& other, |
| 1351 const AbstractTypeArguments& other_type_arguments) const; | 1349 const AbstractTypeArguments& other_type_arguments) const; |
| 1352 | 1350 |
| 1353 // Checks the type of the formal parameter at the given position for | 1351 // Checks the type of the formal parameter at the given position for |
| 1354 // assignability relationship between the type of this function and the type | 1352 // assignability relationship between the type of this function and the type |
| (...skipping 1919 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3274 } | 3272 } |
| 3275 | 3273 |
| 3276 | 3274 |
| 3277 void Context::SetAt(intptr_t index, const Instance& value) const { | 3275 void Context::SetAt(intptr_t index, const Instance& value) const { |
| 3278 StorePointer(InstanceAddr(index), value.raw()); | 3276 StorePointer(InstanceAddr(index), value.raw()); |
| 3279 } | 3277 } |
| 3280 | 3278 |
| 3281 } // namespace dart | 3279 } // namespace dart |
| 3282 | 3280 |
| 3283 #endif // VM_OBJECT_H_ | 3281 #endif // VM_OBJECT_H_ |
| OLD | NEW |