| 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 1282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1293 | 1293 |
| 1294 // Check the 'more specific' relationship, considering only a subvector of | 1294 // Check the 'more specific' relationship, considering only a subvector of |
| 1295 // length 'len' starting at 'from_index'. | 1295 // length 'len' starting at 'from_index'. |
| 1296 bool IsMoreSpecificThan(const TypeArguments& other, | 1296 bool IsMoreSpecificThan(const TypeArguments& other, |
| 1297 intptr_t from_index, | 1297 intptr_t from_index, |
| 1298 intptr_t len, | 1298 intptr_t len, |
| 1299 Error* bound_error) const { | 1299 Error* bound_error) const { |
| 1300 return TypeTest(kIsMoreSpecificThan, other, from_index, len, bound_error); | 1300 return TypeTest(kIsMoreSpecificThan, other, from_index, len, bound_error); |
| 1301 } | 1301 } |
| 1302 | 1302 |
| 1303 // Check if the vectors are equal. | 1303 // Check if the vectors are equal (they may be null). |
| 1304 bool Equals(const TypeArguments& other) const { | 1304 bool Equals(const TypeArguments& other) const { |
| 1305 return IsEquivalent(other); | 1305 return IsSubvectorEquivalent(other, 0, IsNull() ? 0 : Length()); |
| 1306 } | 1306 } |
| 1307 | 1307 |
| 1308 bool IsEquivalent(const TypeArguments& other, | 1308 bool IsEquivalent(const TypeArguments& other, |
| 1309 GrowableObjectArray* trail = NULL) const; | 1309 GrowableObjectArray* trail = NULL) const { |
| 1310 return IsSubvectorEquivalent(other, 0, IsNull() ? 0 : Length(), trail); |
| 1311 } |
| 1312 bool IsSubvectorEquivalent(const TypeArguments& other, |
| 1313 intptr_t from_index, |
| 1314 intptr_t len, |
| 1315 GrowableObjectArray* trail = NULL) const; |
| 1310 | 1316 |
| 1311 bool IsInstantiated(GrowableObjectArray* trail = NULL) const; | 1317 // Check if the vector is instantiated (it must not be null). |
| 1318 bool IsInstantiated(GrowableObjectArray* trail = NULL) const { |
| 1319 return IsSubvectorInstantiated(0, Length(), trail); |
| 1320 } |
| 1321 bool IsSubvectorInstantiated(intptr_t from_index, |
| 1322 intptr_t len, |
| 1323 GrowableObjectArray* trail = NULL) const; |
| 1312 bool IsUninstantiatedIdentity() const; | 1324 bool IsUninstantiatedIdentity() const; |
| 1313 bool CanShareInstantiatorTypeArguments(const Class& instantiator_class) const; | 1325 bool CanShareInstantiatorTypeArguments(const Class& instantiator_class) const; |
| 1314 | 1326 |
| 1315 // Returns true if all types of this vector are respectively, resolved, | 1327 // Return true if all types of this vector are respectively, resolved, |
| 1316 // finalized, or bounded. | 1328 // finalized, or bounded. |
| 1317 bool IsResolved() const; | 1329 bool IsResolved() const; |
| 1318 bool IsFinalized() const; | 1330 bool IsFinalized() const; |
| 1319 bool IsBounded() const; | 1331 bool IsBounded() const; |
| 1320 | 1332 |
| 1333 // Return true if this vector contains a recursive type argument. |
| 1334 bool IsRecursive() const; |
| 1335 |
| 1321 // Clone this type argument vector and clone all unfinalized type arguments. | 1336 // Clone this type argument vector and clone all unfinalized type arguments. |
| 1322 // Finalized type arguments are shared. | 1337 // Finalized type arguments are shared. |
| 1323 RawTypeArguments* CloneUnfinalized() const; | 1338 RawTypeArguments* CloneUnfinalized() const; |
| 1324 | 1339 |
| 1325 // Canonicalize only if instantiated, otherwise returns 'this'. | 1340 // Canonicalize only if instantiated, otherwise returns 'this'. |
| 1326 RawTypeArguments* Canonicalize(GrowableObjectArray* trail = NULL) const; | 1341 RawTypeArguments* Canonicalize(GrowableObjectArray* trail = NULL) const; |
| 1327 | 1342 |
| 1328 // Return 'this' if this type argument vector is instantiated, i.e. if it does | 1343 // Return 'this' if this type argument vector is instantiated, i.e. if it does |
| 1329 // not refer to type parameters. Otherwise, return a new type argument vector | 1344 // not refer to type parameters. Otherwise, return a new type argument vector |
| 1330 // where each reference to a type parameter is replaced with the corresponding | 1345 // where each reference to a type parameter is replaced with the corresponding |
| (...skipping 2794 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4125 virtual RawClass* type_class() const; | 4140 virtual RawClass* type_class() const; |
| 4126 virtual RawUnresolvedClass* unresolved_class() const; | 4141 virtual RawUnresolvedClass* unresolved_class() const; |
| 4127 virtual RawTypeArguments* arguments() const; | 4142 virtual RawTypeArguments* arguments() const; |
| 4128 virtual intptr_t token_pos() const; | 4143 virtual intptr_t token_pos() const; |
| 4129 virtual bool IsInstantiated(GrowableObjectArray* trail = NULL) const; | 4144 virtual bool IsInstantiated(GrowableObjectArray* trail = NULL) const; |
| 4130 virtual bool Equals(const Instance& other) const { | 4145 virtual bool Equals(const Instance& other) const { |
| 4131 return IsEquivalent(other); | 4146 return IsEquivalent(other); |
| 4132 } | 4147 } |
| 4133 virtual bool IsEquivalent(const Instance& other, | 4148 virtual bool IsEquivalent(const Instance& other, |
| 4134 GrowableObjectArray* trail = NULL) const; | 4149 GrowableObjectArray* trail = NULL) const; |
| 4150 virtual bool IsRecursive() const; |
| 4135 | 4151 |
| 4136 // Instantiate this type using the given type argument vector. | 4152 // Instantiate this type using the given type argument vector. |
| 4137 // Return a new type, or return 'this' if it is already instantiated. | 4153 // Return a new type, or return 'this' if it is already instantiated. |
| 4138 // If bound_error is not NULL, it may be set to reflect a bound error. | 4154 // If bound_error is not NULL, it may be set to reflect a bound error. |
| 4139 virtual RawAbstractType* InstantiateFrom( | 4155 virtual RawAbstractType* InstantiateFrom( |
| 4140 const TypeArguments& instantiator_type_arguments, | 4156 const TypeArguments& instantiator_type_arguments, |
| 4141 Error* bound_error, | 4157 Error* bound_error, |
| 4142 GrowableObjectArray* trail = NULL) const; | 4158 GrowableObjectArray* trail = NULL) const; |
| 4143 | 4159 |
| 4144 // Return a clone of this unfinalized type or the type itself if it is | 4160 // Return a clone of this unfinalized type or the type itself if it is |
| 4145 // already finalized. Apply recursively to type arguments, i.e. finalized | 4161 // already finalized. Apply recursively to type arguments, i.e. finalized |
| 4146 // type arguments of an unfinalized type are not cloned, but shared. | 4162 // type arguments of an unfinalized type are not cloned, but shared. |
| 4147 virtual RawAbstractType* CloneUnfinalized() const; | 4163 virtual RawAbstractType* CloneUnfinalized() const; |
| 4148 | 4164 |
| 4149 virtual RawInstance* CheckAndCanonicalize(const char** error_str) const { | 4165 virtual RawInstance* CheckAndCanonicalize(const char** error_str) const { |
| 4150 return Canonicalize(); | 4166 return Canonicalize(); |
| 4151 } | 4167 } |
| 4152 | 4168 |
| 4153 // Return the canonical version of this type. | 4169 // Return the canonical version of this type. |
| 4154 virtual RawAbstractType* Canonicalize( | 4170 virtual RawAbstractType* Canonicalize( |
| 4155 GrowableObjectArray* trail = NULL) const; | 4171 GrowableObjectArray* trail = NULL) const; |
| 4156 | 4172 |
| 4173 // Return the object associated with the receiver in the trail or |
| 4174 // Object::null() if the receiver is not contained in the trail. |
| 4175 RawObject* OnlyBuddyInTrail(GrowableObjectArray* trail) const; |
| 4176 |
| 4177 // If the trail is null, allocate a trail, add the pair <receiver, buddy> to |
| 4178 // the trail. The receiver may only be added once with its only buddy. |
| 4179 void AddOnlyBuddyToTrail(GrowableObjectArray** trail, |
| 4180 const Object& buddy) const; |
| 4181 |
| 4157 // The name of this type, including the names of its type arguments, if any. | 4182 // The name of this type, including the names of its type arguments, if any. |
| 4158 virtual RawString* Name() const { | 4183 virtual RawString* Name() const { |
| 4159 return BuildName(kInternalName); | 4184 return BuildName(kInternalName); |
| 4160 } | 4185 } |
| 4161 | 4186 |
| 4162 // The name of this type, including the names of its type arguments, if any. | 4187 // The name of this type, including the names of its type arguments, if any. |
| 4163 // Names of internal classes are mapped to their public interfaces. | 4188 // Names of internal classes are mapped to their public interfaces. |
| 4164 virtual RawString* UserVisibleName() const { | 4189 virtual RawString* UserVisibleName() const { |
| 4165 return BuildName(kUserVisibleName); | 4190 return BuildName(kUserVisibleName); |
| 4166 } | 4191 } |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4280 virtual bool HasResolvedTypeClass() const; // Own type class resolved. | 4305 virtual bool HasResolvedTypeClass() const; // Own type class resolved. |
| 4281 virtual RawClass* type_class() const; | 4306 virtual RawClass* type_class() const; |
| 4282 void set_type_class(const Object& value) const; | 4307 void set_type_class(const Object& value) const; |
| 4283 virtual RawUnresolvedClass* unresolved_class() const; | 4308 virtual RawUnresolvedClass* unresolved_class() const; |
| 4284 virtual RawTypeArguments* arguments() const; | 4309 virtual RawTypeArguments* arguments() const; |
| 4285 void set_arguments(const TypeArguments& value) const; | 4310 void set_arguments(const TypeArguments& value) const; |
| 4286 virtual intptr_t token_pos() const { return raw_ptr()->token_pos_; } | 4311 virtual intptr_t token_pos() const { return raw_ptr()->token_pos_; } |
| 4287 virtual bool IsInstantiated(GrowableObjectArray* trail = NULL) const; | 4312 virtual bool IsInstantiated(GrowableObjectArray* trail = NULL) const; |
| 4288 virtual bool IsEquivalent(const Instance& other, | 4313 virtual bool IsEquivalent(const Instance& other, |
| 4289 GrowableObjectArray* trail = NULL) const; | 4314 GrowableObjectArray* trail = NULL) const; |
| 4315 virtual bool IsRecursive() const; |
| 4290 virtual RawAbstractType* InstantiateFrom( | 4316 virtual RawAbstractType* InstantiateFrom( |
| 4291 const TypeArguments& instantiator_type_arguments, | 4317 const TypeArguments& instantiator_type_arguments, |
| 4292 Error* malformed_error, | 4318 Error* malformed_error, |
| 4293 GrowableObjectArray* trail = NULL) const; | 4319 GrowableObjectArray* trail = NULL) const; |
| 4294 virtual RawAbstractType* CloneUnfinalized() const; | 4320 virtual RawAbstractType* CloneUnfinalized() const; |
| 4295 virtual RawAbstractType* Canonicalize( | 4321 virtual RawAbstractType* Canonicalize( |
| 4296 GrowableObjectArray* trail = NULL) const; | 4322 GrowableObjectArray* trail = NULL) const; |
| 4297 | 4323 |
| 4298 virtual intptr_t Hash() const; | 4324 virtual intptr_t Hash() const; |
| 4299 | 4325 |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4398 } | 4424 } |
| 4399 virtual RawTypeArguments* arguments() const { | 4425 virtual RawTypeArguments* arguments() const { |
| 4400 return AbstractType::Handle(type()).arguments(); | 4426 return AbstractType::Handle(type()).arguments(); |
| 4401 } | 4427 } |
| 4402 virtual intptr_t token_pos() const { | 4428 virtual intptr_t token_pos() const { |
| 4403 return AbstractType::Handle(type()).token_pos(); | 4429 return AbstractType::Handle(type()).token_pos(); |
| 4404 } | 4430 } |
| 4405 virtual bool IsInstantiated(GrowableObjectArray* trail = NULL) const; | 4431 virtual bool IsInstantiated(GrowableObjectArray* trail = NULL) const; |
| 4406 virtual bool IsEquivalent(const Instance& other, | 4432 virtual bool IsEquivalent(const Instance& other, |
| 4407 GrowableObjectArray* trail = NULL) const; | 4433 GrowableObjectArray* trail = NULL) const; |
| 4434 virtual bool IsRecursive() const { return true; } |
| 4408 virtual RawAbstractType* InstantiateFrom( | 4435 virtual RawAbstractType* InstantiateFrom( |
| 4409 const TypeArguments& instantiator_type_arguments, | 4436 const TypeArguments& instantiator_type_arguments, |
| 4410 Error* bound_error, | 4437 Error* bound_error, |
| 4411 GrowableObjectArray* trail = NULL) const; | 4438 GrowableObjectArray* trail = NULL) const; |
| 4412 virtual RawAbstractType* Canonicalize( | 4439 virtual RawAbstractType* Canonicalize( |
| 4413 GrowableObjectArray* trail = NULL) const; | 4440 GrowableObjectArray* trail = NULL) const; |
| 4414 | 4441 |
| 4415 virtual intptr_t Hash() const; | 4442 virtual intptr_t Hash() const; |
| 4416 | 4443 |
| 4417 // Return true if the receiver is contained in the trail. | 4444 // Return true if the receiver is contained in the trail. |
| 4418 // Otherwise, if the trail is null, allocate a trail, then add the receiver to | 4445 // Otherwise, if the trail is null, allocate a trail, then add the receiver to |
| 4419 // the trail and return false. | 4446 // the trail and return false. |
| 4420 bool TestAndAddToTrail(GrowableObjectArray** trail) const; | 4447 bool TestAndAddToTrail(GrowableObjectArray** trail) const; |
| 4421 | 4448 |
| 4422 // Return true if the pair <receiver, buddy> is contained in the trail. | 4449 // Return true if the pair <receiver, buddy> is contained in the trail. |
| 4423 // Otherwise, if the trail is null, allocate a trail, add the pair <receiver, | 4450 // Otherwise, if the trail is null, allocate a trail, add the pair <receiver, |
| 4424 // buddy> to the trail and return false. | 4451 // buddy> to the trail and return false. |
| 4425 // The receiver may be added several times, each time with a different buddy. | 4452 // The receiver may be added several times, each time with a different buddy. |
| 4426 bool TestAndAddBuddyToTrail(GrowableObjectArray** trail, | 4453 bool TestAndAddBuddyToTrail(GrowableObjectArray** trail, |
| 4427 const Object& buddy) const; | 4454 const Object& buddy) const; |
| 4428 | 4455 |
| 4429 // Return the object associated with the receiver in the trail or | |
| 4430 // Object::null() if the receiver is not contained in the trail. | |
| 4431 RawObject* OnlyBuddyInTrail(GrowableObjectArray* trail) const; | |
| 4432 | |
| 4433 // If the trail is null, allocate a trail, add the pair <receiver, buddy> to | |
| 4434 // the trail. The receiver may only be added once with its only buddy. | |
| 4435 void AddOnlyBuddyToTrail(GrowableObjectArray** trail, | |
| 4436 const Object& buddy) const; | |
| 4437 | |
| 4438 static intptr_t InstanceSize() { | 4456 static intptr_t InstanceSize() { |
| 4439 return RoundedAllocationSize(sizeof(RawTypeRef)); | 4457 return RoundedAllocationSize(sizeof(RawTypeRef)); |
| 4440 } | 4458 } |
| 4441 | 4459 |
| 4442 static RawTypeRef* New(const AbstractType& type); | 4460 static RawTypeRef* New(const AbstractType& type); |
| 4443 | 4461 |
| 4444 private: | 4462 private: |
| 4445 static RawTypeRef* New(); | 4463 static RawTypeRef* New(); |
| 4446 | 4464 |
| 4447 FINAL_HEAP_OBJECT_IMPLEMENTATION(TypeRef, AbstractType); | 4465 FINAL_HEAP_OBJECT_IMPLEMENTATION(TypeRef, AbstractType); |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4486 // bound cannot be checked yet and this is not an error. | 4504 // bound cannot be checked yet and this is not an error. |
| 4487 bool CheckBound(const AbstractType& bounded_type, | 4505 bool CheckBound(const AbstractType& bounded_type, |
| 4488 const AbstractType& upper_bound, | 4506 const AbstractType& upper_bound, |
| 4489 Error* bound_error) const; | 4507 Error* bound_error) const; |
| 4490 virtual intptr_t token_pos() const { return raw_ptr()->token_pos_; } | 4508 virtual intptr_t token_pos() const { return raw_ptr()->token_pos_; } |
| 4491 virtual bool IsInstantiated(GrowableObjectArray* trail = NULL) const { | 4509 virtual bool IsInstantiated(GrowableObjectArray* trail = NULL) const { |
| 4492 return false; | 4510 return false; |
| 4493 } | 4511 } |
| 4494 virtual bool IsEquivalent(const Instance& other, | 4512 virtual bool IsEquivalent(const Instance& other, |
| 4495 GrowableObjectArray* trail = NULL) const; | 4513 GrowableObjectArray* trail = NULL) const; |
| 4514 virtual bool IsRecursive() const { return false; } |
| 4496 virtual RawAbstractType* InstantiateFrom( | 4515 virtual RawAbstractType* InstantiateFrom( |
| 4497 const TypeArguments& instantiator_type_arguments, | 4516 const TypeArguments& instantiator_type_arguments, |
| 4498 Error* bound_error, | 4517 Error* bound_error, |
| 4499 GrowableObjectArray* trail = NULL) const; | 4518 GrowableObjectArray* trail = NULL) const; |
| 4500 virtual RawAbstractType* CloneUnfinalized() const; | 4519 virtual RawAbstractType* CloneUnfinalized() const; |
| 4501 virtual RawAbstractType* Canonicalize( | 4520 virtual RawAbstractType* Canonicalize( |
| 4502 GrowableObjectArray* trail = NULL) const { | 4521 GrowableObjectArray* trail = NULL) const { |
| 4503 return raw(); | 4522 return raw(); |
| 4504 } | 4523 } |
| 4505 | 4524 |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4569 } | 4588 } |
| 4570 virtual bool IsInstantiated(GrowableObjectArray* trail = NULL) const { | 4589 virtual bool IsInstantiated(GrowableObjectArray* trail = NULL) const { |
| 4571 // It is not possible to encounter an instantiated bounded type with an | 4590 // It is not possible to encounter an instantiated bounded type with an |
| 4572 // uninstantiated upper bound. Therefore, we do not need to check if the | 4591 // uninstantiated upper bound. Therefore, we do not need to check if the |
| 4573 // bound is instantiated. Moreover, doing so could lead into cycles, as in | 4592 // bound is instantiated. Moreover, doing so could lead into cycles, as in |
| 4574 // class C<T extends C<C>> { }. | 4593 // class C<T extends C<C>> { }. |
| 4575 return AbstractType::Handle(type()).IsInstantiated(); | 4594 return AbstractType::Handle(type()).IsInstantiated(); |
| 4576 } | 4595 } |
| 4577 virtual bool IsEquivalent(const Instance& other, | 4596 virtual bool IsEquivalent(const Instance& other, |
| 4578 GrowableObjectArray* trail = NULL) const; | 4597 GrowableObjectArray* trail = NULL) const; |
| 4598 virtual bool IsRecursive() const; |
| 4579 virtual RawAbstractType* InstantiateFrom( | 4599 virtual RawAbstractType* InstantiateFrom( |
| 4580 const TypeArguments& instantiator_type_arguments, | 4600 const TypeArguments& instantiator_type_arguments, |
| 4581 Error* bound_error, | 4601 Error* bound_error, |
| 4582 GrowableObjectArray* trail = NULL) const; | 4602 GrowableObjectArray* trail = NULL) const; |
| 4583 virtual RawAbstractType* CloneUnfinalized() const; | 4603 virtual RawAbstractType* CloneUnfinalized() const; |
| 4584 virtual RawAbstractType* Canonicalize( | 4604 virtual RawAbstractType* Canonicalize( |
| 4585 GrowableObjectArray* trail = NULL) const { | 4605 GrowableObjectArray* trail = NULL) const { |
| 4586 return raw(); | 4606 return raw(); |
| 4587 } | 4607 } |
| 4588 | 4608 |
| (...skipping 2170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6759 | 6779 |
| 6760 | 6780 |
| 6761 RawObject* MegamorphicCache::GetTargetFunction(const Array& array, | 6781 RawObject* MegamorphicCache::GetTargetFunction(const Array& array, |
| 6762 intptr_t index) { | 6782 intptr_t index) { |
| 6763 return array.At((index * kEntryLength) + kTargetFunctionIndex); | 6783 return array.At((index * kEntryLength) + kTargetFunctionIndex); |
| 6764 } | 6784 } |
| 6765 | 6785 |
| 6766 } // namespace dart | 6786 } // namespace dart |
| 6767 | 6787 |
| 6768 #endif // VM_OBJECT_H_ | 6788 #endif // VM_OBJECT_H_ |
| OLD | NEW |