| OLD | NEW |
| 1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 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 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 58 | 58 |
| 59 protected: | 59 protected: |
| 60 // This is null until the string is internalized. | 60 // This is null until the string is internalized. |
| 61 Handle<String> string_; | 61 Handle<String> string_; |
| 62 }; | 62 }; |
| 63 | 63 |
| 64 | 64 |
| 65 class AstRawString : public AstString { | 65 class AstRawString : public AstString { |
| 66 public: | 66 public: |
| 67 int length() const override { | 67 int length() const override { |
| 68 if (is_one_byte_) | 68 if (is_one_byte_) return literal_bytes_.length(); |
| 69 return literal_bytes_.length(); | |
| 70 return literal_bytes_.length() / 2; | 69 return literal_bytes_.length() / 2; |
| 71 } | 70 } |
| 72 | 71 |
| 73 int byte_length() const { return literal_bytes_.length(); } | 72 int byte_length() const { return literal_bytes_.length(); } |
| 74 | 73 |
| 75 void Internalize(Isolate* isolate) override; | 74 void Internalize(Isolate* isolate) override; |
| 76 | 75 |
| 77 bool AsArrayIndex(uint32_t* index) const; | 76 bool AsArrayIndex(uint32_t* index) const; |
| 78 | 77 |
| 79 // The string is not null-terminated, use length() to find out the length. | 78 // The string is not null-terminated, use length() to find out the length. |
| 80 const unsigned char* raw_data() const { | 79 const unsigned char* raw_data() const { return literal_bytes_.start(); } |
| 81 return literal_bytes_.start(); | |
| 82 } | |
| 83 bool is_one_byte() const { return is_one_byte_; } | 80 bool is_one_byte() const { return is_one_byte_; } |
| 84 bool IsOneByteEqualTo(const char* data) const; | 81 bool IsOneByteEqualTo(const char* data) const; |
| 85 uint16_t FirstCharacter() const { | 82 uint16_t FirstCharacter() const { |
| 86 if (is_one_byte_) | 83 if (is_one_byte_) return literal_bytes_[0]; |
| 87 return literal_bytes_[0]; | |
| 88 const uint16_t* c = | 84 const uint16_t* c = |
| 89 reinterpret_cast<const uint16_t*>(literal_bytes_.start()); | 85 reinterpret_cast<const uint16_t*>(literal_bytes_.start()); |
| 90 return *c; | 86 return *c; |
| 91 } | 87 } |
| 92 | 88 |
| 93 // For storing AstRawStrings in a hash map. | 89 // For storing AstRawStrings in a hash map. |
| 94 uint32_t hash() const { | 90 uint32_t hash() const { return hash_; } |
| 95 return hash_; | |
| 96 } | |
| 97 | 91 |
| 98 private: | 92 private: |
| 99 friend class AstValueFactory; | 93 friend class AstValueFactory; |
| 100 friend class AstRawStringInternalizationKey; | 94 friend class AstRawStringInternalizationKey; |
| 101 | 95 |
| 102 AstRawString(bool is_one_byte, const Vector<const byte>& literal_bytes, | 96 AstRawString(bool is_one_byte, const Vector<const byte>& literal_bytes, |
| 103 uint32_t hash) | 97 uint32_t hash) |
| 104 : is_one_byte_(is_one_byte), literal_bytes_(literal_bytes), hash_(hash) {} | 98 : is_one_byte_(is_one_byte), literal_bytes_(literal_bytes), hash_(hash) {} |
| 105 | 99 |
| 106 AstRawString() | 100 AstRawString() : is_one_byte_(true), hash_(0) {} |
| 107 : is_one_byte_(true), | |
| 108 hash_(0) {} | |
| 109 | 101 |
| 110 bool is_one_byte_; | 102 bool is_one_byte_; |
| 111 | 103 |
| 112 // Points to memory owned by Zone. | 104 // Points to memory owned by Zone. |
| 113 Vector<const byte> literal_bytes_; | 105 Vector<const byte> literal_bytes_; |
| 114 uint32_t hash_; | 106 uint32_t hash_; |
| 115 }; | 107 }; |
| 116 | 108 |
| 117 | 109 |
| 118 class AstConsString : public AstString { | 110 class AstConsString : public AstString { |
| 119 public: | 111 public: |
| 120 AstConsString(const AstString* left, const AstString* right) | 112 AstConsString(const AstString* left, const AstString* right) |
| 121 : left_(left), | 113 : left_(left), right_(right) {} |
| 122 right_(right) {} | |
| 123 | 114 |
| 124 int length() const override { return left_->length() + right_->length(); } | 115 int length() const override { return left_->length() + right_->length(); } |
| 125 | 116 |
| 126 void Internalize(Isolate* isolate) override; | 117 void Internalize(Isolate* isolate) override; |
| 127 | 118 |
| 128 private: | 119 private: |
| 129 friend class AstValueFactory; | 120 friend class AstValueFactory; |
| 130 | 121 |
| 131 const AstString* left_; | 122 const AstString* left_; |
| 132 const AstString* right_; | 123 const AstString* right_; |
| 133 }; | 124 }; |
| 134 | 125 |
| 135 | 126 |
| 136 // AstValue is either a string, a number, a string array, a boolean, or a | 127 // AstValue is either a string, a number, a string array, a boolean, or a |
| 137 // special value (null, undefined, the hole). | 128 // special value (null, undefined, the hole). |
| 138 class AstValue : public ZoneObject { | 129 class AstValue : public ZoneObject { |
| 139 public: | 130 public: |
| 140 bool IsString() const { | 131 bool IsString() const { return type_ == STRING; } |
| 141 return type_ == STRING; | |
| 142 } | |
| 143 | 132 |
| 144 bool IsNumber() const { | 133 bool IsNumber() const { |
| 145 return type_ == NUMBER || type_ == NUMBER_WITH_DOT || type_ == SMI; | 134 return type_ == NUMBER || type_ == NUMBER_WITH_DOT || type_ == SMI; |
| 146 } | 135 } |
| 147 | 136 |
| 148 bool ContainsDot() const { return type_ == NUMBER_WITH_DOT; } | 137 bool ContainsDot() const { return type_ == NUMBER_WITH_DOT; } |
| 149 | 138 |
| 150 const AstRawString* AsString() const { | 139 const AstRawString* AsString() const { |
| 151 if (type_ == STRING) | 140 if (type_ == STRING) return string_; |
| 152 return string_; | |
| 153 UNREACHABLE(); | 141 UNREACHABLE(); |
| 154 return 0; | 142 return 0; |
| 155 } | 143 } |
| 156 | 144 |
| 157 double AsNumber() const { | 145 double AsNumber() const { |
| 158 if (type_ == NUMBER || type_ == NUMBER_WITH_DOT) | 146 if (type_ == NUMBER || type_ == NUMBER_WITH_DOT) return number_; |
| 159 return number_; | 147 if (type_ == SMI) return smi_; |
| 160 if (type_ == SMI) | |
| 161 return smi_; | |
| 162 UNREACHABLE(); | 148 UNREACHABLE(); |
| 163 return 0; | 149 return 0; |
| 164 } | 150 } |
| 165 | 151 |
| 166 bool EqualsString(const AstRawString* string) const { | 152 bool EqualsString(const AstRawString* string) const { |
| 167 return type_ == STRING && string_ == string; | 153 return type_ == STRING && string_ == string; |
| 168 } | 154 } |
| 169 | 155 |
| 170 bool IsPropertyName() const; | 156 bool IsPropertyName() const; |
| 171 | 157 |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 305 reinterpret_cast<const uint8_t*>(string), StrLength(string))); | 291 reinterpret_cast<const uint8_t*>(string), StrLength(string))); |
| 306 } | 292 } |
| 307 const AstRawString* GetTwoByteString(Vector<const uint16_t> literal) { | 293 const AstRawString* GetTwoByteString(Vector<const uint16_t> literal) { |
| 308 return GetTwoByteStringInternal(literal); | 294 return GetTwoByteStringInternal(literal); |
| 309 } | 295 } |
| 310 const AstRawString* GetString(Handle<String> literal); | 296 const AstRawString* GetString(Handle<String> literal); |
| 311 const AstConsString* NewConsString(const AstString* left, | 297 const AstConsString* NewConsString(const AstString* left, |
| 312 const AstString* right); | 298 const AstString* right); |
| 313 | 299 |
| 314 void Internalize(Isolate* isolate); | 300 void Internalize(Isolate* isolate); |
| 315 bool IsInternalized() { | 301 bool IsInternalized() { return isolate_ != NULL; } |
| 316 return isolate_ != NULL; | |
| 317 } | |
| 318 | 302 |
| 319 #define F(name, str) \ | 303 #define F(name, str) \ |
| 320 const AstRawString* name##_string() { \ | 304 const AstRawString* name##_string() { \ |
| 321 if (name##_string_ == NULL) { \ | 305 if (name##_string_ == NULL) { \ |
| 322 const char* data = str; \ | 306 const char* data = str; \ |
| 323 name##_string_ = GetOneByteString( \ | 307 name##_string_ = GetOneByteString( \ |
| 324 Vector<const uint8_t>(reinterpret_cast<const uint8_t*>(data), \ | 308 Vector<const uint8_t>(reinterpret_cast<const uint8_t*>(data), \ |
| 325 static_cast<int>(strlen(data)))); \ | 309 static_cast<int>(strlen(data)))); \ |
| 326 } \ | 310 } \ |
| 327 return name##_string_; \ | 311 return name##_string_; \ |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 367 OTHER_CONSTANTS(F) | 351 OTHER_CONSTANTS(F) |
| 368 #undef F | 352 #undef F |
| 369 }; | 353 }; |
| 370 } // namespace internal | 354 } // namespace internal |
| 371 } // namespace v8 | 355 } // namespace v8 |
| 372 | 356 |
| 373 #undef STRING_CONSTANTS | 357 #undef STRING_CONSTANTS |
| 374 #undef OTHER_CONSTANTS | 358 #undef OTHER_CONSTANTS |
| 375 | 359 |
| 376 #endif // V8_AST_AST_VALUE_FACTORY_H_ | 360 #endif // V8_AST_AST_VALUE_FACTORY_H_ |
| OLD | NEW |