Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(5)

Side by Side Diff: runtime/vm/object.h

Issue 274333002: Instance equality (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « runtime/vm/exceptions_test.cc ('k') | runtime/vm/object.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 4112 matching lines...) Expand 10 before | Expand all | Expand 10 after
4123 4123
4124 FINAL_HEAP_OBJECT_IMPLEMENTATION(UnwindError, Error); 4124 FINAL_HEAP_OBJECT_IMPLEMENTATION(UnwindError, Error);
4125 friend class Class; 4125 friend class Class;
4126 }; 4126 };
4127 4127
4128 4128
4129 // Instance is the base class for all instance objects (aka the Object class 4129 // Instance is the base class for all instance objects (aka the Object class
4130 // in Dart source code. 4130 // in Dart source code.
4131 class Instance : public Object { 4131 class Instance : public Object {
4132 public: 4132 public:
4133 virtual bool Equals(const Instance& other) const; 4133 // Equality and identity testing.
4134 // 1. OperatorEquals: true iff 'this == other' is true in Dart code.
rmacnak 2014/05/12 17:15:17 Reminds me of Self's equivalent (=), indistinguish
koda 2014/05/12 17:41:43 Maybe we should add SameSameButDifferent :)
4135 // 2. IsIdenticalTo: true iff 'identical(this, other)' is true in Dart code.
4136 // 3. CanonicalizeEquals: used to canonicalize compile-time constants, e.g.,
hausner 2014/05/12 17:09:30 Would it make sense to rename this as BitwiseEqual
koda 2014/05/12 17:41:43 That is almost true, but not technically true for
4137 // using bitwise equality of fields and list elements.
4138 // Subclasses where 1 and 3 coincide may also define a plain Equals, e.g.,
4139 // String and Integer.
4140 virtual bool OperatorEquals(const Instance& other) const;
4141 bool IsIdenticalTo(const Instance& other) const;
4142 virtual bool CanonicalizeEquals(const Instance& other) const;
4143
4134 // Returns Instance::null() if instance cannot be canonicalized. 4144 // Returns Instance::null() if instance cannot be canonicalized.
4135 // Any non-canonical number of string will be canonicalized here. 4145 // Any non-canonical number of string will be canonicalized here.
4136 // An instance cannot be canonicalized if it still contains non-canonical 4146 // An instance cannot be canonicalized if it still contains non-canonical
4137 // instances in its fields. 4147 // instances in its fields.
4138 // Returns error in error_str, pass NULL if an error cannot occur. 4148 // Returns error in error_str, pass NULL if an error cannot occur.
4139 virtual RawInstance* CheckAndCanonicalize(const char** error_str) const; 4149 virtual RawInstance* CheckAndCanonicalize(const char** error_str) const;
4140 4150
4141 // Returns true if all fields are OK for canonicalization. 4151 // Returns true if all fields are OK for canonicalization.
4142 virtual bool CheckAndCanonicalizeFields(const char** error_str) const; 4152 virtual bool CheckAndCanonicalizeFields(const char** error_str) const;
4143 4153
4144 RawObject* GetField(const Field& field) const { 4154 RawObject* GetField(const Field& field) const {
4145 return *FieldAddr(field); 4155 return *FieldAddr(field);
4146 } 4156 }
4147 4157
4148 void SetField(const Field& field, const Object& value) const { 4158 void SetField(const Field& field, const Object& value) const {
4149 field.UpdateGuardedCidAndLength(value); 4159 field.UpdateGuardedCidAndLength(value);
4150 StorePointer(FieldAddr(field), value.raw()); 4160 StorePointer(FieldAddr(field), value.raw());
4151 } 4161 }
4152 4162
4153 RawType* GetType() const; 4163 RawType* GetType() const;
4154 4164
4155 virtual RawTypeArguments* GetTypeArguments() const; 4165 virtual RawTypeArguments* GetTypeArguments() const;
4156 virtual void SetTypeArguments(const TypeArguments& value) const; 4166 virtual void SetTypeArguments(const TypeArguments& value) const;
4157 4167
4158 // Check if the type of this instance is a subtype of the given type. 4168 // Check if the type of this instance is a subtype of the given type.
4159 bool IsInstanceOf(const AbstractType& type, 4169 bool IsInstanceOf(const AbstractType& type,
4160 const TypeArguments& type_instantiator, 4170 const TypeArguments& type_instantiator,
4161 Error* bound_error) const; 4171 Error* bound_error) const;
4162 4172
4163 // Check whether this instance is identical to the argument according to the
4164 // specification of dare:core's identical().
4165 bool IsIdenticalTo(const Instance& other) const;
4166
4167 bool IsValidNativeIndex(int index) const { 4173 bool IsValidNativeIndex(int index) const {
4168 return ((index >= 0) && (index < clazz()->ptr()->num_native_fields_)); 4174 return ((index >= 0) && (index < clazz()->ptr()->num_native_fields_));
4169 } 4175 }
4170 4176
4171 intptr_t* NativeFieldsDataAddr() const; 4177 intptr_t* NativeFieldsDataAddr() const;
4172 inline intptr_t GetNativeField(int index) const; 4178 inline intptr_t GetNativeField(int index) const;
4173 inline void GetNativeFields(uint16_t num_fields, 4179 inline void GetNativeFields(uint16_t num_fields,
4174 intptr_t* field_values) const; 4180 intptr_t* field_values) const;
4175 4181
4176 uint16_t NumNativeFields() const { 4182 uint16_t NumNativeFields() const {
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
4301 virtual bool IsMalformedOrMalbounded() const; 4307 virtual bool IsMalformedOrMalbounded() const;
4302 virtual RawLanguageError* error() const; 4308 virtual RawLanguageError* error() const;
4303 virtual void set_error(const LanguageError& value) const; 4309 virtual void set_error(const LanguageError& value) const;
4304 virtual bool IsResolved() const; 4310 virtual bool IsResolved() const;
4305 virtual bool HasResolvedTypeClass() const; 4311 virtual bool HasResolvedTypeClass() const;
4306 virtual RawClass* type_class() const; 4312 virtual RawClass* type_class() const;
4307 virtual RawUnresolvedClass* unresolved_class() const; 4313 virtual RawUnresolvedClass* unresolved_class() const;
4308 virtual RawTypeArguments* arguments() const; 4314 virtual RawTypeArguments* arguments() const;
4309 virtual intptr_t token_pos() const; 4315 virtual intptr_t token_pos() const;
4310 virtual bool IsInstantiated(GrowableObjectArray* trail = NULL) const; 4316 virtual bool IsInstantiated(GrowableObjectArray* trail = NULL) const;
4317 virtual bool CanonicalizeEquals(const Instance& other) const {
4318 return Equals(other);
4319 }
4311 virtual bool Equals(const Instance& other) const { 4320 virtual bool Equals(const Instance& other) const {
4312 return IsEquivalent(other); 4321 return IsEquivalent(other);
4313 } 4322 }
4314 virtual bool IsEquivalent(const Instance& other, 4323 virtual bool IsEquivalent(const Instance& other,
4315 GrowableObjectArray* trail = NULL) const; 4324 GrowableObjectArray* trail = NULL) const;
4316 virtual bool IsRecursive() const; 4325 virtual bool IsRecursive() const;
4317 4326
4318 // Instantiate this type using the given type argument vector. 4327 // Instantiate this type using the given type argument vector.
4319 // Return a new type, or return 'this' if it is already instantiated. 4328 // Return a new type, or return 'this' if it is already instantiated.
4320 // If bound_error is not NULL, it may be set to reflect a bound error. 4329 // If bound_error is not NULL, it may be set to reflect a bound error.
(...skipping 546 matching lines...) Expand 10 before | Expand all | Expand 10 after
4867 uint64_t value, Heap::Space space = Heap::kNew); 4876 uint64_t value, Heap::Space space = Heap::kNew);
4868 4877
4869 // Returns a canonical Integer object allocated in the old gen space. 4878 // Returns a canonical Integer object allocated in the old gen space.
4870 static RawInteger* NewCanonical(const String& str); 4879 static RawInteger* NewCanonical(const String& str);
4871 4880
4872 // Do not throw JavascriptIntegerOverflow if 'silent' is true. 4881 // Do not throw JavascriptIntegerOverflow if 'silent' is true.
4873 static RawInteger* New(int64_t value, 4882 static RawInteger* New(int64_t value,
4874 Heap::Space space = Heap::kNew, 4883 Heap::Space space = Heap::kNew,
4875 const bool silent = false); 4884 const bool silent = false);
4876 4885
4886 virtual bool OperatorEquals(const Instance& other) const {
4887 return Equals(other);
4888 }
4889 virtual bool CanonicalizeEquals(const Instance& other) const {
4890 return Equals(other);
4891 }
4892 virtual bool Equals(const Instance& other) const {
4893 UNREACHABLE();
4894 return false;
4895 }
4896
4877 // Integer is an abstract class. 4897 // Integer is an abstract class.
4878 virtual bool IsZero() const { 4898 virtual bool IsZero() const {
4879 UNREACHABLE(); 4899 UNREACHABLE();
4880 return false; 4900 return false;
4881 } 4901 }
4882 virtual bool IsNegative() const { 4902 virtual bool IsNegative() const {
4883 // Number is an abstract class. 4903 // Number is an abstract class.
4884 UNREACHABLE(); 4904 UNREACHABLE();
4885 return false; 4905 return false;
4886 } 4906 }
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after
5131 5151
5132 5152
5133 // Class Double represents class Double in corelib_impl, which implements 5153 // Class Double represents class Double in corelib_impl, which implements
5134 // abstract class double in corelib. 5154 // abstract class double in corelib.
5135 class Double : public Number { 5155 class Double : public Number {
5136 public: 5156 public:
5137 double value() const { 5157 double value() const {
5138 return raw_ptr()->value_; 5158 return raw_ptr()->value_;
5139 } 5159 }
5140 5160
5141 bool EqualsToDouble(double value) const; 5161 bool BitwiseEqualsToDouble(double value) const;
5142 virtual bool Equals(const Instance& other) const; 5162 virtual bool OperatorEquals(const Instance& other) const;
5163 virtual bool CanonicalizeEquals(const Instance& other) const;
5143 5164
5144 static RawDouble* New(double d, Heap::Space space = Heap::kNew); 5165 static RawDouble* New(double d, Heap::Space space = Heap::kNew);
5145 5166
5146 static RawDouble* New(const String& str, Heap::Space space = Heap::kNew); 5167 static RawDouble* New(const String& str, Heap::Space space = Heap::kNew);
5147 5168
5148 // Returns a canonical double object allocated in the old gen space. 5169 // Returns a canonical double object allocated in the old gen space.
5149 static RawDouble* NewCanonical(double d); 5170 static RawDouble* NewCanonical(double d);
5150 5171
5151 // Returns a canonical double object (allocated in the old gen space) or 5172 // Returns a canonical double object (allocated in the old gen space) or
5152 // Double::null() if str points to a string that does not convert to a 5173 // Double::null() if str points to a string that does not convert to a
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
5252 5273
5253 // Compares to an array of UTF-8 encoded characters. 5274 // Compares to an array of UTF-8 encoded characters.
5254 bool Equals(const uint8_t* characters, intptr_t len) const; 5275 bool Equals(const uint8_t* characters, intptr_t len) const;
5255 5276
5256 // Compares to an array of UTF-16 encoded characters. 5277 // Compares to an array of UTF-16 encoded characters.
5257 bool Equals(const uint16_t* characters, intptr_t len) const; 5278 bool Equals(const uint16_t* characters, intptr_t len) const;
5258 5279
5259 // Compares to an array of UTF-32 encoded characters. 5280 // Compares to an array of UTF-32 encoded characters.
5260 bool Equals(const int32_t* characters, intptr_t len) const; 5281 bool Equals(const int32_t* characters, intptr_t len) const;
5261 5282
5283 virtual bool OperatorEquals(const Instance& other) const {
5284 return Equals(other);
5285 }
5286 virtual bool CanonicalizeEquals(const Instance& other) const {
5287 return Equals(other);
5288 }
5262 virtual bool Equals(const Instance& other) const; 5289 virtual bool Equals(const Instance& other) const;
5263 5290
5264 intptr_t CompareTo(const String& other) const; 5291 intptr_t CompareTo(const String& other) const;
5265 5292
5266 bool StartsWith(const String& other) const; 5293 bool StartsWith(const String& other) const;
5267 5294
5268 virtual RawInstance* CheckAndCanonicalize(const char** error_str) const; 5295 virtual RawInstance* CheckAndCanonicalize(const char** error_str) const;
5269 5296
5270 bool IsSymbol() const { return raw()->IsCanonical(); } 5297 bool IsSymbol() const { return raw()->IsCanonical(); }
5271 5298
(...skipping 610 matching lines...) Expand 10 before | Expand all | Expand 10 after
5882 return raw_ptr()->type_arguments_; 5909 return raw_ptr()->type_arguments_;
5883 } 5910 }
5884 virtual void SetTypeArguments(const TypeArguments& value) const { 5911 virtual void SetTypeArguments(const TypeArguments& value) const {
5885 // An Array is raw or takes one type argument. However, its type argument 5912 // An Array is raw or takes one type argument. However, its type argument
5886 // vector may be longer than 1 due to a type optimization reusing the type 5913 // vector may be longer than 1 due to a type optimization reusing the type
5887 // argument vector of the instantiator. 5914 // argument vector of the instantiator.
5888 ASSERT(value.IsNull() || ((value.Length() >= 1) && value.IsInstantiated())); 5915 ASSERT(value.IsNull() || ((value.Length() >= 1) && value.IsInstantiated()));
5889 StorePointer(&raw_ptr()->type_arguments_, value.raw()); 5916 StorePointer(&raw_ptr()->type_arguments_, value.raw());
5890 } 5917 }
5891 5918
5892 virtual bool Equals(const Instance& other) const; 5919 virtual bool CanonicalizeEquals(const Instance& other) const;
5893 5920
5894 static const intptr_t kBytesPerElement = kWordSize; 5921 static const intptr_t kBytesPerElement = kWordSize;
5895 static const intptr_t kMaxElements = kSmiMax / kBytesPerElement; 5922 static const intptr_t kMaxElements = kSmiMax / kBytesPerElement;
5896 5923
5897 static intptr_t type_arguments_offset() { 5924 static intptr_t type_arguments_offset() {
5898 return OFFSET_OF(RawArray, type_arguments_); 5925 return OFFSET_OF(RawArray, type_arguments_);
5899 } 5926 }
5900 5927
5901 static intptr_t InstanceSize() { 5928 static intptr_t InstanceSize() {
5902 ASSERT(sizeof(RawArray) == OFFSET_OF_RETURNED_VALUE(RawArray, data)); 5929 ASSERT(sizeof(RawArray) == OFFSET_OF_RETURNED_VALUE(RawArray, data));
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
6042 virtual void SetTypeArguments(const TypeArguments& value) const { 6069 virtual void SetTypeArguments(const TypeArguments& value) const {
6043 // A GrowableObjectArray is raw or takes one type argument. However, its 6070 // A GrowableObjectArray is raw or takes one type argument. However, its
6044 // type argument vector may be longer than 1 due to a type optimization 6071 // type argument vector may be longer than 1 due to a type optimization
6045 // reusing the type argument vector of the instantiator. 6072 // reusing the type argument vector of the instantiator.
6046 ASSERT(value.IsNull() || ((value.Length() >= 1) && value.IsInstantiated())); 6073 ASSERT(value.IsNull() || ((value.Length() >= 1) && value.IsInstantiated()));
6047 const Array& contents = Array::Handle(data()); 6074 const Array& contents = Array::Handle(data());
6048 contents.SetTypeArguments(value); 6075 contents.SetTypeArguments(value);
6049 StorePointer(&raw_ptr()->type_arguments_, value.raw()); 6076 StorePointer(&raw_ptr()->type_arguments_, value.raw());
6050 } 6077 }
6051 6078
6052 virtual bool Equals(const Instance& other) const; 6079 virtual bool CanonicalizeEquals(const Instance& other) const;
6053 6080
6054 virtual RawInstance* CheckAndCanonicalize(const char** error_str) const { 6081 virtual RawInstance* CheckAndCanonicalize(const char** error_str) const {
6055 UNREACHABLE(); 6082 UNREACHABLE();
6056 return Instance::null(); 6083 return Instance::null();
6057 } 6084 }
6058 6085
6059 static intptr_t type_arguments_offset() { 6086 static intptr_t type_arguments_offset() {
6060 return OFFSET_OF(RawGrowableObjectArray, type_arguments_); 6087 return OFFSET_OF(RawGrowableObjectArray, type_arguments_);
6061 } 6088 }
6062 6089
(...skipping 690 matching lines...) Expand 10 before | Expand all | Expand 10 after
6753 void set_is_global() const { raw_ptr()->flags_ |= kGlobal; } 6780 void set_is_global() const { raw_ptr()->flags_ |= kGlobal; }
6754 void set_is_ignore_case() const { raw_ptr()->flags_ |= kIgnoreCase; } 6781 void set_is_ignore_case() const { raw_ptr()->flags_ |= kIgnoreCase; }
6755 void set_is_multi_line() const { raw_ptr()->flags_ |= kMultiLine; } 6782 void set_is_multi_line() const { raw_ptr()->flags_ |= kMultiLine; }
6756 void set_is_simple() const { raw_ptr()->type_ = kSimple; } 6783 void set_is_simple() const { raw_ptr()->type_ = kSimple; }
6757 void set_is_complex() const { raw_ptr()->type_ = kComplex; } 6784 void set_is_complex() const { raw_ptr()->type_ = kComplex; }
6758 6785
6759 void* GetDataStartAddress() const; 6786 void* GetDataStartAddress() const;
6760 static RawJSRegExp* FromDataStartAddress(void* data); 6787 static RawJSRegExp* FromDataStartAddress(void* data);
6761 const char* Flags() const; 6788 const char* Flags() const;
6762 6789
6763 virtual bool Equals(const Instance& other) const; 6790 virtual bool CanonicalizeEquals(const Instance& other) const;
6764 6791
6765 static const intptr_t kBytesPerElement = 1; 6792 static const intptr_t kBytesPerElement = 1;
6766 static const intptr_t kMaxElements = kSmiMax / kBytesPerElement; 6793 static const intptr_t kMaxElements = kSmiMax / kBytesPerElement;
6767 6794
6768 static intptr_t InstanceSize() { 6795 static intptr_t InstanceSize() {
6769 ASSERT(sizeof(RawJSRegExp) == OFFSET_OF(RawJSRegExp, data_)); 6796 ASSERT(sizeof(RawJSRegExp) == OFFSET_OF(RawJSRegExp, data_));
6770 return 0; 6797 return 0;
6771 } 6798 }
6772 6799
6773 static intptr_t InstanceSize(intptr_t len) { 6800 static intptr_t InstanceSize(intptr_t len) {
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after
7036 7063
7037 7064
7038 RawObject* MegamorphicCache::GetTargetFunction(const Array& array, 7065 RawObject* MegamorphicCache::GetTargetFunction(const Array& array,
7039 intptr_t index) { 7066 intptr_t index) {
7040 return array.At((index * kEntryLength) + kTargetFunctionIndex); 7067 return array.At((index * kEntryLength) + kTargetFunctionIndex);
7041 } 7068 }
7042 7069
7043 } // namespace dart 7070 } // namespace dart
7044 7071
7045 #endif // VM_OBJECT_H_ 7072 #endif // VM_OBJECT_H_
OLDNEW
« no previous file with comments | « runtime/vm/exceptions_test.cc ('k') | runtime/vm/object.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698