Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(4)

Side by Side Diff: src/ast/ast-value-factory.h

Issue 2328593002: [Parser] Don't internalize on-the-fly. (Closed)
Patch Set: Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | src/ast/ast-value-factory.cc » ('j') | src/parsing/rewriter.cc » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 309 matching lines...) Expand 10 before | Expand all | Expand 10 after
320 F(undefined_value) \ 320 F(undefined_value) \
321 F(the_hole_value) 321 F(the_hole_value)
322 322
323 class AstValueFactory { 323 class AstValueFactory {
324 public: 324 public:
325 AstValueFactory(Zone* zone, uint32_t hash_seed) 325 AstValueFactory(Zone* zone, uint32_t hash_seed)
326 : string_table_(AstRawStringCompare), 326 : string_table_(AstRawStringCompare),
327 values_(nullptr), 327 values_(nullptr),
328 strings_end_(&strings_), 328 strings_end_(&strings_),
329 zone_(zone), 329 zone_(zone),
330 isolate_(NULL),
331 hash_seed_(hash_seed) { 330 hash_seed_(hash_seed) {
332 ResetStrings(); 331 ResetStrings();
333 #define F(name, str) name##_string_ = NULL; 332 #define F(name, str) name##_string_ = NULL;
334 STRING_CONSTANTS(F) 333 STRING_CONSTANTS(F)
335 #undef F 334 #undef F
336 #define F(name) name##_ = NULL; 335 #define F(name) name##_ = NULL;
337 OTHER_CONSTANTS(F) 336 OTHER_CONSTANTS(F)
338 #undef F 337 #undef F
339 } 338 }
340 339
341 Zone* zone() const { return zone_; } 340 Zone* zone() const { return zone_; }
342 341
343 const AstRawString* GetOneByteString(Vector<const uint8_t> literal) { 342 const AstRawString* GetOneByteString(Vector<const uint8_t> literal) {
344 return GetOneByteStringInternal(literal); 343 return GetOneByteStringInternal(literal);
345 } 344 }
346 const AstRawString* GetOneByteString(const char* string) { 345 const AstRawString* GetOneByteString(const char* string) {
347 return GetOneByteString(Vector<const uint8_t>( 346 return GetOneByteString(Vector<const uint8_t>(
348 reinterpret_cast<const uint8_t*>(string), StrLength(string))); 347 reinterpret_cast<const uint8_t*>(string), StrLength(string)));
349 } 348 }
350 const AstRawString* GetTwoByteString(Vector<const uint16_t> literal) { 349 const AstRawString* GetTwoByteString(Vector<const uint16_t> literal) {
351 return GetTwoByteStringInternal(literal); 350 return GetTwoByteStringInternal(literal);
352 } 351 }
353 const AstRawString* GetString(Handle<String> literal); 352 const AstRawString* GetString(Handle<String> literal);
354 const AstConsString* NewConsString(const AstString* left, 353 const AstConsString* NewConsString(const AstString* left,
355 const AstString* right); 354 const AstString* right);
356 355
357 void Internalize(Isolate* isolate); 356 void Internalize(Isolate* isolate);
358 bool IsInternalized() {
359 return isolate_ != NULL;
360 }
361 357
362 #define F(name, str) \ 358 #define F(name, str) \
363 const AstRawString* name##_string() { \ 359 const AstRawString* name##_string() { \
364 if (name##_string_ == NULL) { \ 360 if (name##_string_ == NULL) { \
365 const char* data = str; \ 361 const char* data = str; \
366 name##_string_ = GetOneByteString( \ 362 name##_string_ = GetOneByteString( \
367 Vector<const uint8_t>(reinterpret_cast<const uint8_t*>(data), \ 363 Vector<const uint8_t>(reinterpret_cast<const uint8_t*>(data), \
368 static_cast<int>(strlen(data)))); \ 364 static_cast<int>(strlen(data)))); \
369 } \ 365 } \
370 return name##_string_; \ 366 return name##_string_; \
371 } 367 }
372 STRING_CONSTANTS(F) 368 STRING_CONSTANTS(F)
373 #undef F 369 #undef F
374 370
375 const AstValue* NewString(const AstRawString* string); 371 const AstValue* NewString(const AstRawString* string);
376 // A JavaScript symbol (ECMA-262 edition 6). 372 // A JavaScript symbol (ECMA-262 edition 6).
377 const AstValue* NewSymbol(const char* name); 373 const AstValue* NewSymbol(const char* name);
378 const AstValue* NewNumber(double number, bool with_dot = false); 374 const AstValue* NewNumber(double number, bool with_dot = false);
379 const AstValue* NewSmi(int number); 375 const AstValue* NewSmi(int number);
380 const AstValue* NewBoolean(bool b); 376 const AstValue* NewBoolean(bool b);
381 const AstValue* NewStringList(ZoneList<const AstRawString*>* strings); 377 const AstValue* NewStringList(ZoneList<const AstRawString*>* strings);
382 const AstValue* NewNull(); 378 const AstValue* NewNull();
383 const AstValue* NewUndefined(); 379 const AstValue* NewUndefined();
384 const AstValue* NewTheHole(); 380 const AstValue* NewTheHole();
385 381
386 private: 382 private:
387 AstValue* AddValue(AstValue* value) { 383 AstValue* AddValue(AstValue* value) {
388 if (isolate_) { 384 value->set_next(values_);
389 value->Internalize(isolate_); 385 values_ = value;
390 } else {
391 value->set_next(values_);
392 values_ = value;
393 }
394 return value; 386 return value;
395 } 387 }
396 AstString* AddString(AstString* string) { 388 AstString* AddString(AstString* string) {
397 if (isolate_) { 389 *strings_end_ = string;
398 string->Internalize(isolate_); 390 strings_end_ = string->next_location();
399 } else {
400 *strings_end_ = string;
401 strings_end_ = string->next_location();
402 }
403 return string; 391 return string;
404 } 392 }
405 void ResetStrings() { 393 void ResetStrings() {
406 strings_ = nullptr; 394 strings_ = nullptr;
407 strings_end_ = &strings_; 395 strings_end_ = &strings_;
408 } 396 }
409 AstRawString* GetOneByteStringInternal(Vector<const uint8_t> literal); 397 AstRawString* GetOneByteStringInternal(Vector<const uint8_t> literal);
410 AstRawString* GetTwoByteStringInternal(Vector<const uint16_t> literal); 398 AstRawString* GetTwoByteStringInternal(Vector<const uint16_t> literal);
411 AstRawString* GetString(uint32_t hash, bool is_one_byte, 399 AstRawString* GetString(uint32_t hash, bool is_one_byte,
412 Vector<const byte> literal_bytes); 400 Vector<const byte> literal_bytes);
413 401
414 static bool AstRawStringCompare(void* a, void* b); 402 static bool AstRawStringCompare(void* a, void* b);
415 403
416 // All strings are copied here, one after another (no NULLs inbetween). 404 // All strings are copied here, one after another (no NULLs inbetween).
417 base::HashMap string_table_; 405 base::HashMap string_table_;
418 // For keeping track of all AstValues and AstRawStrings we've created (so that 406 // For keeping track of all AstValues and AstRawStrings we've created (so that
419 // they can be internalized later). 407 // they can be internalized later).
420 AstValue* values_; 408 AstValue* values_;
421 // We need to keep track of strings_ in order, since cons strings require 409 // We need to keep track of strings_ in order, since cons strings require
422 // their members to be internalized first. 410 // their members to be internalized first.
423 AstString* strings_; 411 AstString* strings_;
424 AstString** strings_end_; 412 AstString** strings_end_;
425 Zone* zone_; 413 Zone* zone_;
426 Isolate* isolate_;
427 414
428 uint32_t hash_seed_; 415 uint32_t hash_seed_;
429 416
430 #define F(name, str) const AstRawString* name##_string_; 417 #define F(name, str) const AstRawString* name##_string_;
431 STRING_CONSTANTS(F) 418 STRING_CONSTANTS(F)
432 #undef F 419 #undef F
433 420
434 #define F(name) AstValue* name##_; 421 #define F(name) AstValue* name##_;
435 OTHER_CONSTANTS(F) 422 OTHER_CONSTANTS(F)
436 #undef F 423 #undef F
437 }; 424 };
438 } // namespace internal 425 } // namespace internal
439 } // namespace v8 426 } // namespace v8
440 427
441 #undef STRING_CONSTANTS 428 #undef STRING_CONSTANTS
442 #undef OTHER_CONSTANTS 429 #undef OTHER_CONSTANTS
443 430
444 #endif // V8_AST_AST_VALUE_FACTORY_H_ 431 #endif // V8_AST_AST_VALUE_FACTORY_H_
OLDNEW
« no previous file with comments | « no previous file | src/ast/ast-value-factory.cc » ('j') | src/parsing/rewriter.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698