| 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 RUNTIME_VM_OBJECT_H_ | 5 #ifndef RUNTIME_VM_OBJECT_H_ |
| 6 #define RUNTIME_VM_OBJECT_H_ | 6 #define RUNTIME_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 1530 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1541 void set_ident(const String& ident) const; | 1541 void set_ident(const String& ident) const; |
| 1542 void set_token_pos(TokenPosition token_pos) const; | 1542 void set_token_pos(TokenPosition token_pos) const; |
| 1543 | 1543 |
| 1544 static RawUnresolvedClass* New(); | 1544 static RawUnresolvedClass* New(); |
| 1545 | 1545 |
| 1546 FINAL_HEAP_OBJECT_IMPLEMENTATION(UnresolvedClass, Object); | 1546 FINAL_HEAP_OBJECT_IMPLEMENTATION(UnresolvedClass, Object); |
| 1547 friend class Class; | 1547 friend class Class; |
| 1548 }; | 1548 }; |
| 1549 | 1549 |
| 1550 | 1550 |
| 1551 // Classification of type genericity according to type parameter owners. |
| 1552 enum Genericity { |
| 1553 kAny, // Consider type params of class and functions. |
| 1554 kClass, // Consider type params of class only. |
| 1555 kFunctions, // Consider type params of current and parent functions. |
| 1556 kCurrentFunction, // Consider type params of current function only. |
| 1557 kParentFunctions // Consider type params of parent functions only. |
| 1558 }; |
| 1559 |
| 1560 |
| 1551 // A TypeArguments is an array of AbstractType. | 1561 // A TypeArguments is an array of AbstractType. |
| 1552 class TypeArguments : public Object { | 1562 class TypeArguments : public Object { |
| 1553 public: | 1563 public: |
| 1554 // We use 30 bits for the hash code so hashes in a snapshot taken on a | 1564 // We use 30 bits for the hash code so hashes in a snapshot taken on a |
| 1555 // 64-bit architecture stay in Smi range when loaded on a 32-bit | 1565 // 64-bit architecture stay in Smi range when loaded on a 32-bit |
| 1556 // architecture. | 1566 // architecture. |
| 1557 static const intptr_t kHashBits = 30; | 1567 static const intptr_t kHashBits = 30; |
| 1558 | 1568 |
| 1559 intptr_t Length() const; | 1569 intptr_t Length() const; |
| 1560 RawAbstractType* TypeAt(intptr_t index) const; | 1570 RawAbstractType* TypeAt(intptr_t index) const; |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1618 | 1628 |
| 1619 bool IsEquivalent(const TypeArguments& other, TrailPtr trail = NULL) const { | 1629 bool IsEquivalent(const TypeArguments& other, TrailPtr trail = NULL) const { |
| 1620 return IsSubvectorEquivalent(other, 0, IsNull() ? 0 : Length(), trail); | 1630 return IsSubvectorEquivalent(other, 0, IsNull() ? 0 : Length(), trail); |
| 1621 } | 1631 } |
| 1622 bool IsSubvectorEquivalent(const TypeArguments& other, | 1632 bool IsSubvectorEquivalent(const TypeArguments& other, |
| 1623 intptr_t from_index, | 1633 intptr_t from_index, |
| 1624 intptr_t len, | 1634 intptr_t len, |
| 1625 TrailPtr trail = NULL) const; | 1635 TrailPtr trail = NULL) const; |
| 1626 | 1636 |
| 1627 // Check if the vector is instantiated (it must not be null). | 1637 // Check if the vector is instantiated (it must not be null). |
| 1628 bool IsInstantiated(TrailPtr trail = NULL) const { | 1638 bool IsInstantiated(Genericity genericity = kAny, |
| 1629 return IsSubvectorInstantiated(0, Length(), trail); | 1639 TrailPtr trail = NULL) const { |
| 1640 return IsSubvectorInstantiated(0, Length(), genericity, trail); |
| 1630 } | 1641 } |
| 1631 bool IsSubvectorInstantiated(intptr_t from_index, | 1642 bool IsSubvectorInstantiated(intptr_t from_index, |
| 1632 intptr_t len, | 1643 intptr_t len, |
| 1644 Genericity genericity = kAny, |
| 1633 TrailPtr trail = NULL) const; | 1645 TrailPtr trail = NULL) const; |
| 1634 bool IsUninstantiatedIdentity() const; | 1646 bool IsUninstantiatedIdentity() const; |
| 1635 bool CanShareInstantiatorTypeArguments(const Class& instantiator_class) const; | 1647 bool CanShareInstantiatorTypeArguments(const Class& instantiator_class) const; |
| 1636 | 1648 |
| 1637 // Return true if all types of this vector are respectively, resolved, | 1649 // Return true if all types of this vector are respectively, resolved, |
| 1638 // finalized, or bounded. | 1650 // finalized, or bounded. |
| 1639 bool IsResolved() const; | 1651 bool IsResolved() const; |
| 1640 bool IsFinalized() const; | 1652 bool IsFinalized() const; |
| 1641 bool IsBounded() const; | 1653 bool IsBounded() const; |
| 1642 | 1654 |
| (...skipping 625 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2268 // Return a TypeParameter if the type_name is a type parameter of this | 2280 // Return a TypeParameter if the type_name is a type parameter of this |
| 2269 // function or of one of its parent functions. | 2281 // function or of one of its parent functions. |
| 2270 // Unless NULL, adjust function_level accordingly (in and out parameter). | 2282 // Unless NULL, adjust function_level accordingly (in and out parameter). |
| 2271 // Return null otherwise. | 2283 // Return null otherwise. |
| 2272 RawTypeParameter* LookupTypeParameter(const String& type_name, | 2284 RawTypeParameter* LookupTypeParameter(const String& type_name, |
| 2273 intptr_t* function_level) const; | 2285 intptr_t* function_level) const; |
| 2274 | 2286 |
| 2275 // Return true if this function declares type parameters. | 2287 // Return true if this function declares type parameters. |
| 2276 bool IsGeneric() const { return NumTypeParameters(Thread::Current()) > 0; } | 2288 bool IsGeneric() const { return NumTypeParameters(Thread::Current()) > 0; } |
| 2277 | 2289 |
| 2290 // Return true if any parent function of this function is generic. |
| 2291 bool HasGenericParent() const; |
| 2292 |
| 2278 // Not thread-safe; must be called in the main thread. | 2293 // Not thread-safe; must be called in the main thread. |
| 2279 // Sets function's code and code's function. | 2294 // Sets function's code and code's function. |
| 2280 void InstallOptimizedCode(const Code& code, bool is_osr) const; | 2295 void InstallOptimizedCode(const Code& code, bool is_osr) const; |
| 2281 void AttachCode(const Code& value) const; | 2296 void AttachCode(const Code& value) const; |
| 2282 void SetInstructions(const Code& value) const; | 2297 void SetInstructions(const Code& value) const; |
| 2283 void ClearCode() const; | 2298 void ClearCode() const; |
| 2284 | 2299 |
| 2285 // Disables optimized code and switches to unoptimized code. | 2300 // Disables optimized code and switches to unoptimized code. |
| 2286 void SwitchToUnoptimizedCode() const; | 2301 void SwitchToUnoptimizedCode() const; |
| 2287 | 2302 |
| (...skipping 3383 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5671 virtual void set_error(const LanguageError& value) const; | 5686 virtual void set_error(const LanguageError& value) const; |
| 5672 virtual bool IsResolved() const; | 5687 virtual bool IsResolved() const; |
| 5673 virtual void SetIsResolved() const; | 5688 virtual void SetIsResolved() const; |
| 5674 virtual bool HasResolvedTypeClass() const; | 5689 virtual bool HasResolvedTypeClass() const; |
| 5675 virtual classid_t type_class_id() const; | 5690 virtual classid_t type_class_id() const; |
| 5676 virtual RawClass* type_class() const; | 5691 virtual RawClass* type_class() const; |
| 5677 virtual RawUnresolvedClass* unresolved_class() const; | 5692 virtual RawUnresolvedClass* unresolved_class() const; |
| 5678 virtual RawTypeArguments* arguments() const; | 5693 virtual RawTypeArguments* arguments() const; |
| 5679 virtual void set_arguments(const TypeArguments& value) const; | 5694 virtual void set_arguments(const TypeArguments& value) const; |
| 5680 virtual TokenPosition token_pos() const; | 5695 virtual TokenPosition token_pos() const; |
| 5681 virtual bool IsInstantiated(TrailPtr trail = NULL) const; | 5696 virtual bool IsInstantiated(Genericity genericity = kAny, |
| 5697 TrailPtr trail = NULL) const; |
| 5682 virtual bool CanonicalizeEquals(const Instance& other) const { | 5698 virtual bool CanonicalizeEquals(const Instance& other) const { |
| 5683 return Equals(other); | 5699 return Equals(other); |
| 5684 } | 5700 } |
| 5685 virtual bool Equals(const Instance& other) const { | 5701 virtual bool Equals(const Instance& other) const { |
| 5686 return IsEquivalent(other); | 5702 return IsEquivalent(other); |
| 5687 } | 5703 } |
| 5688 virtual bool IsEquivalent(const Instance& other, TrailPtr trail = NULL) const; | 5704 virtual bool IsEquivalent(const Instance& other, TrailPtr trail = NULL) const; |
| 5689 virtual bool IsRecursive() const; | 5705 virtual bool IsRecursive() const; |
| 5690 | 5706 |
| 5691 // Check if this type represents a function type. | 5707 // Check if this type represents a function type. |
| (...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5886 virtual void SetIsResolved() const; | 5902 virtual void SetIsResolved() const; |
| 5887 virtual bool HasResolvedTypeClass() const; // Own type class resolved. | 5903 virtual bool HasResolvedTypeClass() const; // Own type class resolved. |
| 5888 virtual classid_t type_class_id() const; | 5904 virtual classid_t type_class_id() const; |
| 5889 virtual RawClass* type_class() const; | 5905 virtual RawClass* type_class() const; |
| 5890 void set_type_class(const Class& value) const; | 5906 void set_type_class(const Class& value) const; |
| 5891 void set_unresolved_class(const Object& value) const; | 5907 void set_unresolved_class(const Object& value) const; |
| 5892 virtual RawUnresolvedClass* unresolved_class() const; | 5908 virtual RawUnresolvedClass* unresolved_class() const; |
| 5893 virtual RawTypeArguments* arguments() const { return raw_ptr()->arguments_; } | 5909 virtual RawTypeArguments* arguments() const { return raw_ptr()->arguments_; } |
| 5894 virtual void set_arguments(const TypeArguments& value) const; | 5910 virtual void set_arguments(const TypeArguments& value) const; |
| 5895 virtual TokenPosition token_pos() const { return raw_ptr()->token_pos_; } | 5911 virtual TokenPosition token_pos() const { return raw_ptr()->token_pos_; } |
| 5896 virtual bool IsInstantiated(TrailPtr trail = NULL) const; | 5912 virtual bool IsInstantiated(Genericity genericity = kAny, |
| 5913 TrailPtr trail = NULL) const; |
| 5897 virtual bool IsEquivalent(const Instance& other, TrailPtr trail = NULL) const; | 5914 virtual bool IsEquivalent(const Instance& other, TrailPtr trail = NULL) const; |
| 5898 virtual bool IsRecursive() const; | 5915 virtual bool IsRecursive() const; |
| 5899 // If signature is not null, this type represents a function type. | 5916 // If signature is not null, this type represents a function type. |
| 5900 RawFunction* signature() const; | 5917 RawFunction* signature() const; |
| 5901 void set_signature(const Function& value) const; | 5918 void set_signature(const Function& value) const; |
| 5902 virtual bool IsFunctionType() const { | 5919 virtual bool IsFunctionType() const { |
| 5903 return signature() != Function::null(); | 5920 return signature() != Function::null(); |
| 5904 } | 5921 } |
| 5905 virtual RawAbstractType* InstantiateFrom( | 5922 virtual RawAbstractType* InstantiateFrom( |
| 5906 const TypeArguments& instantiator_type_arguments, | 5923 const TypeArguments& instantiator_type_arguments, |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6024 void set_type(const AbstractType& value) const; | 6041 void set_type(const AbstractType& value) const; |
| 6025 virtual RawClass* type_class() const { | 6042 virtual RawClass* type_class() const { |
| 6026 return AbstractType::Handle(type()).type_class(); | 6043 return AbstractType::Handle(type()).type_class(); |
| 6027 } | 6044 } |
| 6028 virtual RawTypeArguments* arguments() const { | 6045 virtual RawTypeArguments* arguments() const { |
| 6029 return AbstractType::Handle(type()).arguments(); | 6046 return AbstractType::Handle(type()).arguments(); |
| 6030 } | 6047 } |
| 6031 virtual TokenPosition token_pos() const { | 6048 virtual TokenPosition token_pos() const { |
| 6032 return AbstractType::Handle(type()).token_pos(); | 6049 return AbstractType::Handle(type()).token_pos(); |
| 6033 } | 6050 } |
| 6034 virtual bool IsInstantiated(TrailPtr trail = NULL) const; | 6051 virtual bool IsInstantiated(Genericity genericity = kAny, |
| 6052 TrailPtr trail = NULL) const; |
| 6035 virtual bool IsEquivalent(const Instance& other, TrailPtr trail = NULL) const; | 6053 virtual bool IsEquivalent(const Instance& other, TrailPtr trail = NULL) const; |
| 6036 virtual bool IsRecursive() const { return true; } | 6054 virtual bool IsRecursive() const { return true; } |
| 6037 virtual RawTypeRef* InstantiateFrom( | 6055 virtual RawTypeRef* InstantiateFrom( |
| 6038 const TypeArguments& instantiator_type_arguments, | 6056 const TypeArguments& instantiator_type_arguments, |
| 6039 Error* bound_error, | 6057 Error* bound_error, |
| 6040 TrailPtr instantiation_trail, | 6058 TrailPtr instantiation_trail, |
| 6041 TrailPtr bound_trail, | 6059 TrailPtr bound_trail, |
| 6042 Heap::Space space) const; | 6060 Heap::Space space) const; |
| 6043 virtual RawTypeRef* CloneUninstantiated(const Class& new_owner, | 6061 virtual RawTypeRef* CloneUninstantiated(const Class& new_owner, |
| 6044 TrailPtr trail = NULL) const; | 6062 TrailPtr trail = NULL) const; |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6108 // Returns true if bounded_type is below upper_bound, otherwise return false | 6126 // Returns true if bounded_type is below upper_bound, otherwise return false |
| 6109 // and set bound_error if both bounded_type and upper_bound are instantiated. | 6127 // and set bound_error if both bounded_type and upper_bound are instantiated. |
| 6110 // If one or both are not instantiated, returning false only means that the | 6128 // If one or both are not instantiated, returning false only means that the |
| 6111 // bound cannot be checked yet and this is not an error. | 6129 // bound cannot be checked yet and this is not an error. |
| 6112 bool CheckBound(const AbstractType& bounded_type, | 6130 bool CheckBound(const AbstractType& bounded_type, |
| 6113 const AbstractType& upper_bound, | 6131 const AbstractType& upper_bound, |
| 6114 Error* bound_error, | 6132 Error* bound_error, |
| 6115 TrailPtr bound_trail, | 6133 TrailPtr bound_trail, |
| 6116 Heap::Space space) const; | 6134 Heap::Space space) const; |
| 6117 virtual TokenPosition token_pos() const { return raw_ptr()->token_pos_; } | 6135 virtual TokenPosition token_pos() const { return raw_ptr()->token_pos_; } |
| 6118 virtual bool IsInstantiated(TrailPtr trail = NULL) const { return false; } | 6136 virtual bool IsInstantiated(Genericity genericity = kAny, |
| 6137 TrailPtr trail = NULL) const; |
| 6119 virtual bool IsEquivalent(const Instance& other, TrailPtr trail = NULL) const; | 6138 virtual bool IsEquivalent(const Instance& other, TrailPtr trail = NULL) const; |
| 6120 virtual bool IsRecursive() const { return false; } | 6139 virtual bool IsRecursive() const { return false; } |
| 6121 virtual RawAbstractType* InstantiateFrom( | 6140 virtual RawAbstractType* InstantiateFrom( |
| 6122 const TypeArguments& instantiator_type_arguments, | 6141 const TypeArguments& instantiator_type_arguments, |
| 6123 Error* bound_error, | 6142 Error* bound_error, |
| 6124 TrailPtr instantiation_trail, | 6143 TrailPtr instantiation_trail, |
| 6125 TrailPtr bound_trail, | 6144 TrailPtr bound_trail, |
| 6126 Heap::Space space) const; | 6145 Heap::Space space) const; |
| 6127 virtual RawAbstractType* CloneUnfinalized() const; | 6146 virtual RawAbstractType* CloneUnfinalized() const; |
| 6128 virtual RawAbstractType* CloneUninstantiated(const Class& new_owner, | 6147 virtual RawAbstractType* CloneUninstantiated(const Class& new_owner, |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6202 return AbstractType::Handle(type()).arguments(); | 6221 return AbstractType::Handle(type()).arguments(); |
| 6203 } | 6222 } |
| 6204 RawAbstractType* type() const { return raw_ptr()->type_; } | 6223 RawAbstractType* type() const { return raw_ptr()->type_; } |
| 6205 RawAbstractType* bound() const { return raw_ptr()->bound_; } | 6224 RawAbstractType* bound() const { return raw_ptr()->bound_; } |
| 6206 RawTypeParameter* type_parameter() const { | 6225 RawTypeParameter* type_parameter() const { |
| 6207 return raw_ptr()->type_parameter_; | 6226 return raw_ptr()->type_parameter_; |
| 6208 } | 6227 } |
| 6209 virtual TokenPosition token_pos() const { | 6228 virtual TokenPosition token_pos() const { |
| 6210 return AbstractType::Handle(type()).token_pos(); | 6229 return AbstractType::Handle(type()).token_pos(); |
| 6211 } | 6230 } |
| 6212 virtual bool IsInstantiated(TrailPtr trail = NULL) const { | 6231 virtual bool IsInstantiated(Genericity genericity = kAny, |
| 6232 TrailPtr trail = NULL) const { |
| 6213 // It is not possible to encounter an instantiated bounded type with an | 6233 // It is not possible to encounter an instantiated bounded type with an |
| 6214 // uninstantiated upper bound. Therefore, we do not need to check if the | 6234 // uninstantiated upper bound. Therefore, we do not need to check if the |
| 6215 // bound is instantiated. Moreover, doing so could lead into cycles, as in | 6235 // bound is instantiated. Moreover, doing so could lead into cycles, as in |
| 6216 // class C<T extends C<C>> { }. | 6236 // class C<T extends C<C>> { }. |
| 6217 return AbstractType::Handle(type()).IsInstantiated(trail); | 6237 return AbstractType::Handle(type()).IsInstantiated(genericity, trail); |
| 6218 } | 6238 } |
| 6219 virtual bool IsEquivalent(const Instance& other, TrailPtr trail = NULL) const; | 6239 virtual bool IsEquivalent(const Instance& other, TrailPtr trail = NULL) const; |
| 6220 virtual bool IsRecursive() const; | 6240 virtual bool IsRecursive() const; |
| 6221 virtual RawAbstractType* InstantiateFrom( | 6241 virtual RawAbstractType* InstantiateFrom( |
| 6222 const TypeArguments& instantiator_type_arguments, | 6242 const TypeArguments& instantiator_type_arguments, |
| 6223 Error* bound_error, | 6243 Error* bound_error, |
| 6224 TrailPtr instantiation_trail, | 6244 TrailPtr instantiation_trail, |
| 6225 TrailPtr bound_trail, | 6245 TrailPtr bound_trail, |
| 6226 Heap::Space space) const; | 6246 Heap::Space space) const; |
| 6227 virtual RawAbstractType* CloneUnfinalized() const; | 6247 virtual RawAbstractType* CloneUnfinalized() const; |
| (...skipping 2701 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8929 | 8949 |
| 8930 inline void TypeArguments::SetHash(intptr_t value) const { | 8950 inline void TypeArguments::SetHash(intptr_t value) const { |
| 8931 // This is only safe because we create a new Smi, which does not cause | 8951 // This is only safe because we create a new Smi, which does not cause |
| 8932 // heap allocation. | 8952 // heap allocation. |
| 8933 StoreSmi(&raw_ptr()->hash_, Smi::New(value)); | 8953 StoreSmi(&raw_ptr()->hash_, Smi::New(value)); |
| 8934 } | 8954 } |
| 8935 | 8955 |
| 8936 } // namespace dart | 8956 } // namespace dart |
| 8937 | 8957 |
| 8938 #endif // RUNTIME_VM_OBJECT_H_ | 8958 #endif // RUNTIME_VM_OBJECT_H_ |
| OLD | NEW |