| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 142 int8_t kind_; | 142 int8_t kind_; |
| 143 }; | 143 }; |
| 144 | 144 |
| 145 | 145 |
| 146 // PropertyDetails captures type and attributes for a property. | 146 // PropertyDetails captures type and attributes for a property. |
| 147 // They are used both in property dictionaries and instance descriptors. | 147 // They are used both in property dictionaries and instance descriptors. |
| 148 class PropertyDetails BASE_EMBEDDED { | 148 class PropertyDetails BASE_EMBEDDED { |
| 149 public: | 149 public: |
| 150 PropertyDetails(PropertyAttributes attributes, | 150 PropertyDetails(PropertyAttributes attributes, |
| 151 PropertyType type, | 151 PropertyType type, |
| 152 Representation representation, | 152 int index) { |
| 153 int index = 0) { | |
| 154 value_ = TypeField::encode(type) | 153 value_ = TypeField::encode(type) |
| 155 | AttributesField::encode(attributes) | 154 | AttributesField::encode(attributes) |
| 156 | RepresentationField::encode(EncodeRepresentation(representation)) | |
| 157 | DictionaryStorageField::encode(index); | 155 | DictionaryStorageField::encode(index); |
| 158 | 156 |
| 159 ASSERT(type == this->type()); | 157 ASSERT(type == this->type()); |
| 160 ASSERT(attributes == this->attributes()); | 158 ASSERT(attributes == this->attributes()); |
| 161 if (representation.IsNone()) { | 159 } |
| 162 ASSERT(index == this->dictionary_index()); | 160 |
| 163 } else { | 161 PropertyDetails(PropertyAttributes attributes, |
| 164 ASSERT(index == this->descriptor_index()); | 162 PropertyType type, |
| 165 } | 163 Representation representation) { |
| 164 value_ = TypeField::encode(type) |
| 165 | AttributesField::encode(attributes) |
| 166 | RepresentationField::encode(EncodeRepresentation(representation)); |
| 166 } | 167 } |
| 167 | 168 |
| 168 int pointer() { return DescriptorPointer::decode(value_); } | 169 int pointer() { return DescriptorPointer::decode(value_); } |
| 169 | 170 |
| 170 PropertyDetails set_pointer(int i) { return PropertyDetails(value_, i); } | 171 PropertyDetails set_pointer(int i) { return PropertyDetails(value_, i); } |
| 171 | 172 |
| 172 PropertyDetails CopyWithRepresentation(Representation representation) { | 173 PropertyDetails CopyWithRepresentation(Representation representation) { |
| 173 return PropertyDetails(value_, representation); | 174 return PropertyDetails(value_, representation); |
| 174 } | 175 } |
| 175 | 176 |
| 176 // Conversion for storing details as Object*. | 177 // Conversion for storing details as Object*. |
| 177 explicit inline PropertyDetails(Smi* smi); | 178 explicit inline PropertyDetails(Smi* smi); |
| 178 inline Smi* AsSmi(); | 179 inline Smi* AsSmi(); |
| 179 | 180 |
| 180 static uint8_t EncodeRepresentation(Representation representation) { | 181 static uint8_t EncodeRepresentation(Representation representation) { |
| 181 ASSERT(representation.kind() <= Representation::kTagged); | 182 return representation.kind(); |
| 182 if (representation.kind() < Representation::kInteger32) { | |
| 183 return representation.kind(); | |
| 184 } else { | |
| 185 return representation.kind() - 1; | |
| 186 } | |
| 187 } | 183 } |
| 188 | 184 |
| 189 static Representation DecodeRepresentation(uint32_t bits) { | 185 static Representation DecodeRepresentation(uint32_t bits) { |
| 190 ASSERT(bits <= Representation::kTagged); | |
| 191 if (bits >= Representation::kInteger32) bits += 1; | |
| 192 return Representation::FromKind(static_cast<Representation::Kind>(bits)); | 186 return Representation::FromKind(static_cast<Representation::Kind>(bits)); |
| 193 } | 187 } |
| 194 | 188 |
| 195 PropertyType type() { return TypeField::decode(value_); } | 189 PropertyType type() { return TypeField::decode(value_); } |
| 196 | 190 |
| 197 PropertyAttributes attributes() const { | 191 PropertyAttributes attributes() const { |
| 198 return AttributesField::decode(value_); | 192 return AttributesField::decode(value_); |
| 199 } | 193 } |
| 200 | 194 |
| 201 int dictionary_index() { | 195 int dictionary_index() { |
| 202 return DictionaryStorageField::decode(value_); | 196 return DictionaryStorageField::decode(value_); |
| 203 } | 197 } |
| 204 | 198 |
| 205 int descriptor_index() { | |
| 206 return DescriptorStorageField::decode(value_); | |
| 207 } | |
| 208 | |
| 209 Representation representation() { | 199 Representation representation() { |
| 210 return DecodeRepresentation(RepresentationField::decode(value_)); | 200 return DecodeRepresentation(RepresentationField::decode(value_)); |
| 211 } | 201 } |
| 212 | 202 |
| 213 inline PropertyDetails AsDeleted(); | 203 inline PropertyDetails AsDeleted(); |
| 214 | 204 |
| 215 static bool IsValidIndex(int index) { | 205 static bool IsValidIndex(int index) { |
| 216 return DictionaryStorageField::is_valid(index); | 206 return DictionaryStorageField::is_valid(index); |
| 217 } | 207 } |
| 218 | 208 |
| 219 bool IsReadOnly() const { return (attributes() & READ_ONLY) != 0; } | 209 bool IsReadOnly() const { return (attributes() & READ_ONLY) != 0; } |
| 220 bool IsDontDelete() const { return (attributes() & DONT_DELETE) != 0; } | 210 bool IsDontDelete() const { return (attributes() & DONT_DELETE) != 0; } |
| 221 bool IsDontEnum() const { return (attributes() & DONT_ENUM) != 0; } | 211 bool IsDontEnum() const { return (attributes() & DONT_ENUM) != 0; } |
| 222 bool IsDeleted() const { return DeletedField::decode(value_) != 0;} | 212 bool IsDeleted() const { return DeletedField::decode(value_) != 0;} |
| 223 | 213 |
| 224 // Bit fields in value_ (type, shift, size). Must be public so the | 214 // Bit fields in value_ (type, shift, size). Must be public so the |
| 225 // constants can be embedded in generated code. | 215 // constants can be embedded in generated code. |
| 226 class TypeField: public BitField<PropertyType, 0, 3> {}; | 216 class TypeField: public BitField<PropertyType, 0, 3> {}; |
| 227 class AttributesField: public BitField<PropertyAttributes, 3, 3> {}; | 217 class AttributesField: public BitField<PropertyAttributes, 3, 3> {}; |
| 228 class DeletedField: public BitField<uint32_t, 6, 1> {}; | 218 class DeletedField: public BitField<uint32_t, 6, 1> {}; |
| 229 class DictionaryStorageField: public BitField<uint32_t, 7, 24> {}; | 219 class DictionaryStorageField: public BitField<uint32_t, 7, 24> {}; |
| 230 class DescriptorStorageField: public BitField<uint32_t, 7, 11> {}; | 220 class DescriptorPointer: public BitField<uint32_t, 7, 11> {}; |
| 231 class DescriptorPointer: public BitField<uint32_t, 18, 11> {}; | 221 class RepresentationField: public BitField<uint32_t, 18, 3> {}; |
| 232 class RepresentationField: public BitField<uint32_t, 29, 2> {}; | |
| 233 | 222 |
| 234 static const int kInitialIndex = 1; | 223 static const int kInitialIndex = 1; |
| 235 | 224 |
| 236 private: | 225 private: |
| 237 PropertyDetails(int value, int pointer) { | 226 PropertyDetails(int value, int pointer) { |
| 238 value_ = DescriptorPointer::update(value, pointer); | 227 value_ = DescriptorPointer::update(value, pointer); |
| 239 } | 228 } |
| 240 PropertyDetails(int value, Representation representation) { | 229 PropertyDetails(int value, Representation representation) { |
| 241 value_ = RepresentationField::update( | 230 value_ = RepresentationField::update( |
| 242 value, EncodeRepresentation(representation)); | 231 value, EncodeRepresentation(representation)); |
| 243 } | 232 } |
| 244 | 233 |
| 245 uint32_t value_; | 234 uint32_t value_; |
| 246 }; | 235 }; |
| 247 | 236 |
| 248 } } // namespace v8::internal | 237 } } // namespace v8::internal |
| 249 | 238 |
| 250 #endif // V8_PROPERTY_DETAILS_H_ | 239 #endif // V8_PROPERTY_DETAILS_H_ |
| OLD | NEW |