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 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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_) |
69 return literal_bytes_.length(); | 69 return literal_bytes_.length(); |
70 return literal_bytes_.length() / 2; | 70 return literal_bytes_.length() / 2; |
71 } | 71 } |
72 | 72 |
| 73 int byte_length() const { return literal_bytes_.length(); } |
| 74 |
73 void Internalize(Isolate* isolate) OVERRIDE; | 75 void Internalize(Isolate* isolate) OVERRIDE; |
74 | 76 |
75 bool AsArrayIndex(uint32_t* index) const; | 77 bool AsArrayIndex(uint32_t* index) const; |
76 | 78 |
77 // The string is not null-terminated, use length() to find out the length. | 79 // The string is not null-terminated, use length() to find out the length. |
78 const unsigned char* raw_data() const { | 80 const unsigned char* raw_data() const { |
79 return literal_bytes_.start(); | 81 return literal_bytes_.start(); |
80 } | 82 } |
81 bool is_one_byte() const { return is_one_byte_; } | 83 bool is_one_byte() const { return is_one_byte_; } |
82 bool IsOneByteEqualTo(const char* data) const; | 84 bool IsOneByteEqualTo(const char* data) const; |
83 uint16_t FirstCharacter() const { | 85 uint16_t FirstCharacter() const { |
84 if (is_one_byte_) | 86 if (is_one_byte_) |
85 return literal_bytes_[0]; | 87 return literal_bytes_[0]; |
86 const uint16_t* c = | 88 const uint16_t* c = |
87 reinterpret_cast<const uint16_t*>(literal_bytes_.start()); | 89 reinterpret_cast<const uint16_t*>(literal_bytes_.start()); |
88 return *c; | 90 return *c; |
89 } | 91 } |
90 | 92 |
91 // For storing AstRawStrings in a hash map. | 93 // For storing AstRawStrings in a hash map. |
92 uint32_t hash() const { | 94 uint32_t hash() const { |
93 return hash_; | 95 return hash_; |
94 } | 96 } |
95 static bool Compare(void* a, void* b); | |
96 | |
97 bool operator==(const AstRawString& rhs) const; | |
98 | 97 |
99 private: | 98 private: |
100 friend class AstValueFactory; | 99 friend class AstValueFactory; |
101 friend class AstRawStringInternalizationKey; | 100 friend class AstRawStringInternalizationKey; |
102 | 101 |
103 AstRawString(bool is_one_byte, const Vector<const byte>& literal_bytes, | 102 AstRawString(bool is_one_byte, const Vector<const byte>& literal_bytes, |
104 uint32_t hash) | 103 uint32_t hash) |
105 : is_one_byte_(is_one_byte), literal_bytes_(literal_bytes), hash_(hash) {} | 104 : is_one_byte_(is_one_byte), literal_bytes_(literal_bytes), hash_(hash) {} |
106 | 105 |
107 AstRawString() | 106 AstRawString() |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
270 #define OTHER_CONSTANTS(F) \ | 269 #define OTHER_CONSTANTS(F) \ |
271 F(true_value) \ | 270 F(true_value) \ |
272 F(false_value) \ | 271 F(false_value) \ |
273 F(null_value) \ | 272 F(null_value) \ |
274 F(undefined_value) \ | 273 F(undefined_value) \ |
275 F(the_hole_value) | 274 F(the_hole_value) |
276 | 275 |
277 class AstValueFactory { | 276 class AstValueFactory { |
278 public: | 277 public: |
279 AstValueFactory(Zone* zone, uint32_t hash_seed) | 278 AstValueFactory(Zone* zone, uint32_t hash_seed) |
280 : string_table_(AstRawString::Compare), | 279 : string_table_(AstRawStringCompare), |
281 zone_(zone), | 280 zone_(zone), |
282 isolate_(NULL), | 281 isolate_(NULL), |
283 hash_seed_(hash_seed) { | 282 hash_seed_(hash_seed) { |
284 #define F(name, str) name##_string_ = NULL; | 283 #define F(name, str) name##_string_ = NULL; |
285 STRING_CONSTANTS(F) | 284 STRING_CONSTANTS(F) |
286 #undef F | 285 #undef F |
287 #define F(name) name##_ = NULL; | 286 #define F(name) name##_ = NULL; |
288 OTHER_CONSTANTS(F) | 287 OTHER_CONSTANTS(F) |
289 #undef F | 288 #undef F |
290 } | 289 } |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
333 const AstValue* NewNull(); | 332 const AstValue* NewNull(); |
334 const AstValue* NewUndefined(); | 333 const AstValue* NewUndefined(); |
335 const AstValue* NewTheHole(); | 334 const AstValue* NewTheHole(); |
336 | 335 |
337 private: | 336 private: |
338 AstRawString* GetOneByteStringInternal(Vector<const uint8_t> literal); | 337 AstRawString* GetOneByteStringInternal(Vector<const uint8_t> literal); |
339 AstRawString* GetTwoByteStringInternal(Vector<const uint16_t> literal); | 338 AstRawString* GetTwoByteStringInternal(Vector<const uint16_t> literal); |
340 AstRawString* GetString(uint32_t hash, bool is_one_byte, | 339 AstRawString* GetString(uint32_t hash, bool is_one_byte, |
341 Vector<const byte> literal_bytes); | 340 Vector<const byte> literal_bytes); |
342 | 341 |
| 342 static bool AstRawStringCompare(void* a, void* b); |
| 343 |
343 // All strings are copied here, one after another (no NULLs inbetween). | 344 // All strings are copied here, one after another (no NULLs inbetween). |
344 HashMap string_table_; | 345 HashMap string_table_; |
345 // For keeping track of all AstValues and AstRawStrings we've created (so that | 346 // For keeping track of all AstValues and AstRawStrings we've created (so that |
346 // they can be internalized later). | 347 // they can be internalized later). |
347 List<AstValue*> values_; | 348 List<AstValue*> values_; |
348 List<AstString*> strings_; | 349 List<AstString*> strings_; |
349 Zone* zone_; | 350 Zone* zone_; |
350 Isolate* isolate_; | 351 Isolate* isolate_; |
351 | 352 |
352 uint32_t hash_seed_; | 353 uint32_t hash_seed_; |
353 | 354 |
354 #define F(name, str) const AstRawString* name##_string_; | 355 #define F(name, str) const AstRawString* name##_string_; |
355 STRING_CONSTANTS(F) | 356 STRING_CONSTANTS(F) |
356 #undef F | 357 #undef F |
357 | 358 |
358 #define F(name) AstValue* name##_; | 359 #define F(name) AstValue* name##_; |
359 OTHER_CONSTANTS(F) | 360 OTHER_CONSTANTS(F) |
360 #undef F | 361 #undef F |
361 }; | 362 }; |
362 } } // namespace v8::internal | 363 } } // namespace v8::internal |
363 | 364 |
364 #undef STRING_CONSTANTS | 365 #undef STRING_CONSTANTS |
365 #undef OTHER_CONSTANTS | 366 #undef OTHER_CONSTANTS |
366 | 367 |
367 #endif // V8_AST_VALUE_FACTORY_H_ | 368 #endif // V8_AST_VALUE_FACTORY_H_ |
OLD | NEW |