Chromium Code Reviews| Index: src/property-details.h |
| diff --git a/src/property-details.h b/src/property-details.h |
| index 2aa6dcfa959421d8c6e285d3b731fccb6dbc4b31..a8c4341dad4153f12a11162acb02ac15ad42f56a 100644 |
| --- a/src/property-details.h |
| +++ b/src/property-details.h |
| @@ -76,26 +76,114 @@ enum PropertyType { |
| }; |
| +class Representation { |
| + public: |
| + enum Kind { |
| + kNone, |
| + kSmi, |
| + kInteger32, |
| + kDouble, |
| + kTagged, |
| + kExternal, |
| + kNumRepresentations |
| + }; |
| + |
| + Representation() : kind_(kNone) { } |
| + |
| + static Representation None() { return Representation(kNone); } |
| + static Representation Tagged() { return Representation(kTagged); } |
| + static Representation Smi() { return Representation(kSmi); } |
| + static Representation Integer32() { return Representation(kInteger32); } |
| + static Representation Double() { return Representation(kDouble); } |
| + static Representation External() { return Representation(kExternal); } |
| + |
| + static Representation FromKind(Kind kind) { return Representation(kind); } |
| + |
| + bool Equals(const Representation& other) { |
| + return kind_ == other.kind_; |
| + } |
| + |
| + bool is_more_general_than(const Representation& other) { |
| + ASSERT(kind_ != kExternal); |
| + ASSERT(other.kind_ != kExternal); |
| + return kind_ > other.kind_; |
| + } |
| + |
| + Representation generalize(Representation other) { |
| + if (is_more_general_than(other)) { |
| + return *this; |
| + } else { |
| + return other; |
| + } |
| + } |
| + |
| + Kind kind() const { return static_cast<Kind>(kind_); } |
| + bool IsNone() const { return kind_ == kNone; } |
| + bool IsTagged() const { return kind_ == kTagged; } |
| + bool IsSmi() const { return kind_ == kSmi; } |
| + bool IsInteger32() const { return kind_ == kInteger32; } |
| + bool IsDouble() const { return kind_ == kDouble; } |
| + bool IsExternal() const { return kind_ == kExternal; } |
| + bool IsSpecialization() const { |
| + return kind_ == kInteger32 || kind_ == kDouble; |
| + } |
| + const char* Mnemonic() const; |
| + |
| + uint8_t DetailsEncoded() { |
|
danno
2013/04/25 13:33:48
Move this encoding to PropertyDetails
Toon Verwaest
2013/04/25 14:49:10
Done.
|
| + ASSERT(kind_ <= kTagged); |
| + if (kind_ < kInteger32) { |
| + return kind_; |
| + } else { |
| + return kind_ - 1; |
| + } |
| + } |
| + |
| + static Representation DecodeDetails(uint32_t bits) { |
| + ASSERT(bits <= kTagged); |
| + if (bits >= kInteger32) bits += 1; |
| + return FromKind(static_cast<Kind>(bits)); |
| + } |
| + |
| + private: |
| + explicit Representation(Kind k) : kind_(k) { } |
| + |
| + // Make sure kind fits in int8. |
| + STATIC_ASSERT(kNumRepresentations <= (1 << kBitsPerByte)); |
| + |
| + int8_t kind_; |
| +}; |
| + |
| + |
| // PropertyDetails captures type and attributes for a property. |
| // They are used both in property dictionaries and instance descriptors. |
| class PropertyDetails BASE_EMBEDDED { |
| public: |
| PropertyDetails(PropertyAttributes attributes, |
| PropertyType type, |
| + Representation representation, |
| int index = 0) { |
| value_ = TypeField::encode(type) |
| | AttributesField::encode(attributes) |
| + | RepresentationField::encode(representation.DetailsEncoded()) |
| | DictionaryStorageField::encode(index); |
| ASSERT(type == this->type()); |
| ASSERT(attributes == this->attributes()); |
| - ASSERT(index == this->dictionary_index()); |
| + if (representation.IsNone()) { |
| + ASSERT(index == this->dictionary_index()); |
| + } else { |
| + ASSERT(index == this->descriptor_index()); |
| + } |
| } |
| int pointer() { return DescriptorPointer::decode(value_); } |
| PropertyDetails set_pointer(int i) { return PropertyDetails(value_, i); } |
| + PropertyDetails set_representation(Representation representation) { |
|
danno
2013/04/25 13:33:48
CopyForRepresentation
Toon Verwaest
2013/04/25 14:49:10
Done.
|
| + return PropertyDetails(value_, representation); |
| + } |
| + |
| // Conversion for storing details as Object*. |
| explicit inline PropertyDetails(Smi* smi); |
| inline Smi* AsSmi(); |
| @@ -114,6 +202,10 @@ class PropertyDetails BASE_EMBEDDED { |
| return DescriptorStorageField::decode(value_); |
| } |
| + Representation representation() { |
| + return Representation::DecodeDetails(RepresentationField::decode(value_)); |
| + } |
| + |
| inline PropertyDetails AsDeleted(); |
| static bool IsValidIndex(int index) { |
| @@ -133,12 +225,17 @@ class PropertyDetails BASE_EMBEDDED { |
| class DictionaryStorageField: public BitField<uint32_t, 7, 24> {}; |
| class DescriptorStorageField: public BitField<uint32_t, 7, 11> {}; |
| class DescriptorPointer: public BitField<uint32_t, 18, 11> {}; |
| + class RepresentationField: public BitField<uint32_t, 29, 2> {}; |
| static const int kInitialIndex = 1; |
| private: |
| PropertyDetails(int value, int pointer) { |
| - value_ = DescriptorPointer::update(value, pointer); |
| + value_ = DescriptorPointer::update(value, pointer); |
| + } |
| + PropertyDetails(int value, Representation representation) { |
| + value_ = RepresentationField::update( |
| + value, representation.DetailsEncoded()); |
| } |
| uint32_t value_; |