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 3511 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3522 FINAL_HEAP_OBJECT_IMPLEMENTATION(UnwindError, Error); | 3522 FINAL_HEAP_OBJECT_IMPLEMENTATION(UnwindError, Error); |
3523 friend class Class; | 3523 friend class Class; |
3524 }; | 3524 }; |
3525 | 3525 |
3526 | 3526 |
3527 // Instance is the base class for all instance objects (aka the Object class | 3527 // Instance is the base class for all instance objects (aka the Object class |
3528 // in Dart source code. | 3528 // in Dart source code. |
3529 class Instance : public Object { | 3529 class Instance : public Object { |
3530 public: | 3530 public: |
3531 virtual bool Equals(const Instance& other) const; | 3531 virtual bool Equals(const Instance& other) const; |
3532 virtual RawInstance* Canonicalize() const; | 3532 // Returns Instance::null() if instance cannot be canonicalized. |
| 3533 // Any non-canonical number of string will be canonicalized here. |
| 3534 // An instance cannot be canonicalized if it still contains non-canonical |
| 3535 // instances in its fields. |
| 3536 // Returns error in error_str, pass NULL if an error cannot occur. |
| 3537 virtual RawInstance* CheckAndCanonicalize(const char** error_str) const; |
3533 | 3538 |
3534 RawObject* GetField(const Field& field) const { | 3539 RawObject* GetField(const Field& field) const { |
3535 return *FieldAddr(field); | 3540 return *FieldAddr(field); |
3536 } | 3541 } |
3537 | 3542 |
3538 void SetField(const Field& field, const Object& value) const { | 3543 void SetField(const Field& field, const Object& value) const { |
3539 StorePointer(FieldAddr(field), value.raw()); | 3544 StorePointer(FieldAddr(field), value.raw()); |
3540 } | 3545 } |
3541 | 3546 |
3542 RawType* GetType() const; | 3547 RawType* GetType() const; |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3613 virtual bool IsInstantiated() const; | 3618 virtual bool IsInstantiated() const; |
3614 virtual bool Equals(const Instance& other) const; | 3619 virtual bool Equals(const Instance& other) const; |
3615 | 3620 |
3616 // Instantiate this type using the given type argument vector. | 3621 // Instantiate this type using the given type argument vector. |
3617 // Return a new type, or return 'this' if it is already instantiated. | 3622 // Return a new type, or return 'this' if it is already instantiated. |
3618 // If malformed_error is not NULL, it may be set to reflect a bound error. | 3623 // If malformed_error is not NULL, it may be set to reflect a bound error. |
3619 virtual RawAbstractType* InstantiateFrom( | 3624 virtual RawAbstractType* InstantiateFrom( |
3620 const AbstractTypeArguments& instantiator_type_arguments, | 3625 const AbstractTypeArguments& instantiator_type_arguments, |
3621 Error* malformed_error) const; | 3626 Error* malformed_error) const; |
3622 | 3627 |
| 3628 virtual RawInstance* CheckAndCanonicalize(const char** error_str) const { |
| 3629 return Canonicalize(); |
| 3630 } |
| 3631 |
3623 // Return the canonical version of this type. | 3632 // Return the canonical version of this type. |
3624 virtual RawAbstractType* Canonicalize() const; | 3633 virtual RawAbstractType* Canonicalize() const; |
3625 | 3634 |
3626 // The name of this type, including the names of its type arguments, if any. | 3635 // The name of this type, including the names of its type arguments, if any. |
3627 virtual RawString* Name() const { | 3636 virtual RawString* Name() const { |
3628 return BuildName(kInternalName); | 3637 return BuildName(kInternalName); |
3629 } | 3638 } |
3630 | 3639 |
3631 // The name of this type, including the names of its type arguments, if any. | 3640 // The name of this type, including the names of its type arguments, if any. |
3632 // Names of internal classes are mapped to their public interfaces. | 3641 // Names of internal classes are mapped to their public interfaces. |
(...skipping 433 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4066 static const intptr_t kMinValue = kSmiMin; | 4075 static const intptr_t kMinValue = kSmiMin; |
4067 | 4076 |
4068 intptr_t Value() const { | 4077 intptr_t Value() const { |
4069 return ValueFromRaw(raw_value()); | 4078 return ValueFromRaw(raw_value()); |
4070 } | 4079 } |
4071 | 4080 |
4072 virtual bool Equals(const Instance& other) const; | 4081 virtual bool Equals(const Instance& other) const; |
4073 virtual bool IsZero() const { return Value() == 0; } | 4082 virtual bool IsZero() const { return Value() == 0; } |
4074 virtual bool IsNegative() const { return Value() < 0; } | 4083 virtual bool IsNegative() const { return Value() < 0; } |
4075 // Smi values are implicitly canonicalized. | 4084 // Smi values are implicitly canonicalized. |
4076 virtual RawInstance* Canonicalize() const { | 4085 virtual RawInstance* CheckAndCanonicalize(const char** error_str) const { |
4077 return reinterpret_cast<RawSmi*>(raw_value()); | 4086 return reinterpret_cast<RawSmi*>(raw_value()); |
4078 } | 4087 } |
4079 | 4088 |
4080 virtual double AsDoubleValue() const; | 4089 virtual double AsDoubleValue() const; |
4081 virtual int64_t AsInt64Value() const; | 4090 virtual int64_t AsInt64Value() const; |
4082 | 4091 |
4083 virtual int CompareWith(const Integer& other) const; | 4092 virtual int CompareWith(const Integer& other) const; |
4084 | 4093 |
4085 static intptr_t InstanceSize() { return 0; } | 4094 static intptr_t InstanceSize() { return 0; } |
4086 | 4095 |
(...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4396 | 4405 |
4397 // Compares to an array of UTF-32 encoded characters. | 4406 // Compares to an array of UTF-32 encoded characters. |
4398 bool Equals(const int32_t* characters, intptr_t len) const; | 4407 bool Equals(const int32_t* characters, intptr_t len) const; |
4399 | 4408 |
4400 virtual bool Equals(const Instance& other) const; | 4409 virtual bool Equals(const Instance& other) const; |
4401 | 4410 |
4402 intptr_t CompareTo(const String& other) const; | 4411 intptr_t CompareTo(const String& other) const; |
4403 | 4412 |
4404 bool StartsWith(const String& other) const; | 4413 bool StartsWith(const String& other) const; |
4405 | 4414 |
4406 virtual RawInstance* Canonicalize() const; | 4415 virtual RawInstance* CheckAndCanonicalize(const char** error_str) const; |
4407 | 4416 |
4408 bool IsSymbol() const { return raw()->IsCanonical(); } | 4417 bool IsSymbol() const { return raw()->IsCanonical(); } |
4409 | 4418 |
4410 bool IsOneByteString() const { | 4419 bool IsOneByteString() const { |
4411 return raw()->GetClassId() == kOneByteStringCid; | 4420 return raw()->GetClassId() == kOneByteStringCid; |
4412 } | 4421 } |
4413 | 4422 |
4414 bool IsTwoByteString() const { | 4423 bool IsTwoByteString() const { |
4415 return raw()->GetClassId() == kTwoByteStringCid; | 4424 return raw()->GetClassId() == kTwoByteStringCid; |
4416 } | 4425 } |
(...skipping 689 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5106 // type argument vector may be longer than 1 due to a type optimization | 5115 // type argument vector may be longer than 1 due to a type optimization |
5107 // reusing the type argument vector of the instantiator. | 5116 // reusing the type argument vector of the instantiator. |
5108 ASSERT(value.IsNull() || ((value.Length() >= 1) && value.IsInstantiated())); | 5117 ASSERT(value.IsNull() || ((value.Length() >= 1) && value.IsInstantiated())); |
5109 const Array& contents = Array::Handle(data()); | 5118 const Array& contents = Array::Handle(data()); |
5110 contents.SetTypeArguments(value); | 5119 contents.SetTypeArguments(value); |
5111 StorePointer(&raw_ptr()->type_arguments_, value.raw()); | 5120 StorePointer(&raw_ptr()->type_arguments_, value.raw()); |
5112 } | 5121 } |
5113 | 5122 |
5114 virtual bool Equals(const Instance& other) const; | 5123 virtual bool Equals(const Instance& other) const; |
5115 | 5124 |
| 5125 virtual RawInstance* CheckAndCanonicalize(const char** error_str) const { |
| 5126 UNREACHABLE(); |
| 5127 return Instance::null(); |
| 5128 } |
| 5129 |
5116 static intptr_t type_arguments_offset() { | 5130 static intptr_t type_arguments_offset() { |
5117 return OFFSET_OF(RawGrowableObjectArray, type_arguments_); | 5131 return OFFSET_OF(RawGrowableObjectArray, type_arguments_); |
5118 } | 5132 } |
5119 | 5133 |
5120 static intptr_t length_offset() { | 5134 static intptr_t length_offset() { |
5121 return OFFSET_OF(RawGrowableObjectArray, length_); | 5135 return OFFSET_OF(RawGrowableObjectArray, length_); |
5122 } | 5136 } |
5123 static intptr_t data_offset() { | 5137 static intptr_t data_offset() { |
5124 return OFFSET_OF(RawGrowableObjectArray, data_); | 5138 return OFFSET_OF(RawGrowableObjectArray, data_); |
5125 } | 5139 } |
(...skipping 776 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5902 | 5916 |
5903 | 5917 |
5904 RawObject* MegamorphicCache::GetTargetFunction(const Array& array, | 5918 RawObject* MegamorphicCache::GetTargetFunction(const Array& array, |
5905 intptr_t index) { | 5919 intptr_t index) { |
5906 return array.At((index * kEntryLength) + kTargetFunctionIndex); | 5920 return array.At((index * kEntryLength) + kTargetFunctionIndex); |
5907 } | 5921 } |
5908 | 5922 |
5909 } // namespace dart | 5923 } // namespace dart |
5910 | 5924 |
5911 #endif // VM_OBJECT_H_ | 5925 #endif // VM_OBJECT_H_ |
OLD | NEW |