Chromium Code Reviews| 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 314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 325 F(false_value) \ | 325 F(false_value) \ |
| 326 F(null_value) \ | 326 F(null_value) \ |
| 327 F(undefined_value) \ | 327 F(undefined_value) \ |
| 328 F(the_hole_value) | 328 F(the_hole_value) |
| 329 | 329 |
| 330 class AstValueFactory { | 330 class AstValueFactory { |
| 331 public: | 331 public: |
| 332 AstValueFactory(Zone* zone, uint32_t hash_seed) | 332 AstValueFactory(Zone* zone, uint32_t hash_seed) |
| 333 : string_table_(AstRawStringCompare), | 333 : string_table_(AstRawStringCompare), |
| 334 values_(nullptr), | 334 values_(nullptr), |
| 335 smis_(), | |
| 335 strings_(nullptr), | 336 strings_(nullptr), |
| 336 strings_end_(&strings_), | 337 strings_end_(&strings_), |
| 337 zone_(zone), | 338 zone_(zone), |
| 338 hash_seed_(hash_seed) { | 339 hash_seed_(hash_seed) { |
| 339 #define F(name, str) name##_string_ = NULL; | 340 #define F(name, str) name##_string_ = NULL; |
| 340 STRING_CONSTANTS(F) | 341 STRING_CONSTANTS(F) |
| 341 #undef F | 342 #undef F |
| 342 #define F(name) name##_ = NULL; | 343 #define F(name) name##_ = NULL; |
| 343 OTHER_CONSTANTS(F) | 344 OTHER_CONSTANTS(F) |
| 344 #undef F | 345 #undef F |
| 346 std::fill(&smis_[0], &smis_[kMaxCachedSmi + 1], nullptr); | |
|
vogelheim
2016/11/09 15:04:10
I'd use std::fill(smis_, smis_ + arraysize(smis_),
| |
| 345 } | 347 } |
| 346 | 348 |
| 347 Zone* zone() const { return zone_; } | 349 Zone* zone() const { return zone_; } |
| 348 | 350 |
| 349 const AstRawString* GetOneByteString(Vector<const uint8_t> literal) { | 351 const AstRawString* GetOneByteString(Vector<const uint8_t> literal) { |
| 350 return GetOneByteStringInternal(literal); | 352 return GetOneByteStringInternal(literal); |
| 351 } | 353 } |
| 352 const AstRawString* GetOneByteString(const char* string) { | 354 const AstRawString* GetOneByteString(const char* string) { |
| 353 return GetOneByteString(Vector<const uint8_t>( | 355 return GetOneByteString(Vector<const uint8_t>( |
| 354 reinterpret_cast<const uint8_t*>(string), StrLength(string))); | 356 reinterpret_cast<const uint8_t*>(string), StrLength(string))); |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 374 } \ | 376 } \ |
| 375 return name##_string_; \ | 377 return name##_string_; \ |
| 376 } | 378 } |
| 377 STRING_CONSTANTS(F) | 379 STRING_CONSTANTS(F) |
| 378 #undef F | 380 #undef F |
| 379 | 381 |
| 380 const AstValue* NewString(const AstRawString* string); | 382 const AstValue* NewString(const AstRawString* string); |
| 381 // A JavaScript symbol (ECMA-262 edition 6). | 383 // A JavaScript symbol (ECMA-262 edition 6). |
| 382 const AstValue* NewSymbol(const char* name); | 384 const AstValue* NewSymbol(const char* name); |
| 383 const AstValue* NewNumber(double number, bool with_dot = false); | 385 const AstValue* NewNumber(double number, bool with_dot = false); |
| 384 const AstValue* NewSmi(int number); | 386 const AstValue* NewSmi(uint32_t number); |
| 385 const AstValue* NewBoolean(bool b); | 387 const AstValue* NewBoolean(bool b); |
| 386 const AstValue* NewStringList(ZoneList<const AstRawString*>* strings); | 388 const AstValue* NewStringList(ZoneList<const AstRawString*>* strings); |
| 387 const AstValue* NewNull(); | 389 const AstValue* NewNull(); |
| 388 const AstValue* NewUndefined(); | 390 const AstValue* NewUndefined(); |
| 389 const AstValue* NewTheHole(); | 391 const AstValue* NewTheHole(); |
| 390 | 392 |
| 391 private: | 393 private: |
| 394 static const uint32_t kMaxCachedSmi = 1 << 10; | |
| 395 | |
| 396 STATIC_ASSERT(kMaxCachedSmi <= Smi::kMaxValue); | |
| 397 | |
| 392 AstValue* AddValue(AstValue* value) { | 398 AstValue* AddValue(AstValue* value) { |
| 393 value->set_next(values_); | 399 value->set_next(values_); |
| 394 values_ = value; | 400 values_ = value; |
| 395 return value; | 401 return value; |
| 396 } | 402 } |
| 397 AstString* AddString(AstString* string) { | 403 AstString* AddString(AstString* string) { |
| 398 *strings_end_ = string; | 404 *strings_end_ = string; |
| 399 strings_end_ = string->next_location(); | 405 strings_end_ = string->next_location(); |
| 400 return string; | 406 return string; |
| 401 } | 407 } |
| 402 void ResetStrings() { | 408 void ResetStrings() { |
| 403 strings_ = nullptr; | 409 strings_ = nullptr; |
| 404 strings_end_ = &strings_; | 410 strings_end_ = &strings_; |
| 405 } | 411 } |
| 406 V8_EXPORT_PRIVATE AstRawString* GetOneByteStringInternal( | 412 V8_EXPORT_PRIVATE AstRawString* GetOneByteStringInternal( |
| 407 Vector<const uint8_t> literal); | 413 Vector<const uint8_t> literal); |
| 408 AstRawString* GetTwoByteStringInternal(Vector<const uint16_t> literal); | 414 AstRawString* GetTwoByteStringInternal(Vector<const uint16_t> literal); |
| 409 AstRawString* GetString(uint32_t hash, bool is_one_byte, | 415 AstRawString* GetString(uint32_t hash, bool is_one_byte, |
| 410 Vector<const byte> literal_bytes); | 416 Vector<const byte> literal_bytes); |
| 411 | 417 |
| 412 static bool AstRawStringCompare(void* a, void* b); | 418 static bool AstRawStringCompare(void* a, void* b); |
| 413 | 419 |
| 414 // All strings are copied here, one after another (no NULLs inbetween). | 420 // All strings are copied here, one after another (no NULLs inbetween). |
| 415 base::CustomMatcherHashMap string_table_; | 421 base::CustomMatcherHashMap string_table_; |
| 416 // For keeping track of all AstValues and AstRawStrings we've created (so that | 422 // For keeping track of all AstValues and AstRawStrings we've created (so that |
| 417 // they can be internalized later). | 423 // they can be internalized later). |
| 418 AstValue* values_; | 424 AstValue* values_; |
| 425 | |
| 426 AstValue* smis_[kMaxCachedSmi + 1]; | |
| 419 // We need to keep track of strings_ in order since cons strings require their | 427 // We need to keep track of strings_ in order since cons strings require their |
| 420 // members to be internalized first. | 428 // members to be internalized first. |
| 421 AstString* strings_; | 429 AstString* strings_; |
| 422 AstString** strings_end_; | 430 AstString** strings_end_; |
| 423 Zone* zone_; | 431 Zone* zone_; |
| 424 | 432 |
| 425 uint32_t hash_seed_; | 433 uint32_t hash_seed_; |
| 426 | 434 |
| 427 #define F(name, str) const AstRawString* name##_string_; | 435 #define F(name, str) const AstRawString* name##_string_; |
| 428 STRING_CONSTANTS(F) | 436 STRING_CONSTANTS(F) |
| 429 #undef F | 437 #undef F |
| 430 | 438 |
| 431 #define F(name) AstValue* name##_; | 439 #define F(name) AstValue* name##_; |
| 432 OTHER_CONSTANTS(F) | 440 OTHER_CONSTANTS(F) |
| 433 #undef F | 441 #undef F |
| 434 }; | 442 }; |
| 435 } // namespace internal | 443 } // namespace internal |
| 436 } // namespace v8 | 444 } // namespace v8 |
| 437 | 445 |
| 438 #undef STRING_CONSTANTS | 446 #undef STRING_CONSTANTS |
| 439 #undef OTHER_CONSTANTS | 447 #undef OTHER_CONSTANTS |
| 440 | 448 |
| 441 #endif // V8_AST_AST_VALUE_FACTORY_H_ | 449 #endif // V8_AST_AST_VALUE_FACTORY_H_ |
| OLD | NEW |