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

Side by Side Diff: src/ast/ast.h

Issue 2142233003: Templatize AstVisitor with its subclass (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Addressed comments Created 4 years, 5 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 | « src/asmjs/asm-wasm-builder.cc ('k') | src/ast/ast.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef V8_AST_AST_H_ 5 #ifndef V8_AST_AST_H_
6 #define V8_AST_AST_H_ 6 #define V8_AST_AST_H_
7 7
8 #include "src/ast/ast-value-factory.h" 8 #include "src/ast/ast-value-factory.h"
9 #include "src/ast/modules.h" 9 #include "src/ast/modules.h"
10 #include "src/ast/variables.h" 10 #include "src/ast/variables.h"
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 V(DoExpression) \ 107 V(DoExpression) \
108 V(RewritableExpression) 108 V(RewritableExpression)
109 109
110 #define AST_NODE_LIST(V) \ 110 #define AST_NODE_LIST(V) \
111 DECLARATION_NODE_LIST(V) \ 111 DECLARATION_NODE_LIST(V) \
112 STATEMENT_NODE_LIST(V) \ 112 STATEMENT_NODE_LIST(V) \
113 EXPRESSION_NODE_LIST(V) 113 EXPRESSION_NODE_LIST(V)
114 114
115 // Forward declarations 115 // Forward declarations
116 class AstNodeFactory; 116 class AstNodeFactory;
117 class AstVisitor;
118 class Declaration; 117 class Declaration;
119 class Module; 118 class Module;
120 class BreakableStatement; 119 class BreakableStatement;
121 class Expression; 120 class Expression;
122 class IterationStatement; 121 class IterationStatement;
123 class MaterializedLiteral; 122 class MaterializedLiteral;
124 class Statement; 123 class Statement;
125 class TypeFeedbackOracle; 124 class TypeFeedbackOracle;
126 125
127 #define DEF_FORWARD_DECLARATION(type) class type; 126 #define DEF_FORWARD_DECLARATION(type) class type;
128 AST_NODE_LIST(DEF_FORWARD_DECLARATION) 127 AST_NODE_LIST(DEF_FORWARD_DECLARATION)
129 #undef DEF_FORWARD_DECLARATION 128 #undef DEF_FORWARD_DECLARATION
130 129
131 130
132 // Typedef only introduced to avoid unreadable code. 131 // Typedef only introduced to avoid unreadable code.
133 typedef ZoneList<Handle<String>> ZoneStringList; 132 typedef ZoneList<Handle<String>> ZoneStringList;
134 typedef ZoneList<Handle<Object>> ZoneObjectList; 133 typedef ZoneList<Handle<Object>> ZoneObjectList;
135 134
136 135
137 #define DECLARE_NODE_TYPE(type) \ 136 #define DECLARE_NODE_TYPE(type) \
138 void Accept(AstVisitor* v) override; \
139 AstNode::NodeType node_type() const final { return AstNode::k##type; } \
140 friend class AstNodeFactory; 137 friend class AstNodeFactory;
141 138
142 139
143 class FeedbackVectorSlotCache { 140 class FeedbackVectorSlotCache {
144 public: 141 public:
145 explicit FeedbackVectorSlotCache(Zone* zone) 142 explicit FeedbackVectorSlotCache(Zone* zone)
146 : zone_(zone), 143 : zone_(zone),
147 hash_map_(base::HashMap::PointersMatch, 144 hash_map_(base::HashMap::PointersMatch,
148 ZoneHashMap::kDefaultHashMapCapacity, 145 ZoneHashMap::kDefaultHashMapCapacity,
149 ZoneAllocationPolicy(zone)) {} 146 ZoneAllocationPolicy(zone)) {}
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
189 int node_count_; 186 int node_count_;
190 FeedbackVectorSpec spec_; 187 FeedbackVectorSpec spec_;
191 }; 188 };
192 189
193 DEFINE_OPERATORS_FOR_FLAGS(AstProperties::Flags) 190 DEFINE_OPERATORS_FOR_FLAGS(AstProperties::Flags)
194 191
195 192
196 class AstNode: public ZoneObject { 193 class AstNode: public ZoneObject {
197 public: 194 public:
198 #define DECLARE_TYPE_ENUM(type) k##type, 195 #define DECLARE_TYPE_ENUM(type) k##type,
199 enum NodeType { 196 enum NodeType : uint8_t { kModule = 0, AST_NODE_LIST(DECLARE_TYPE_ENUM) };
200 AST_NODE_LIST(DECLARE_TYPE_ENUM)
201 kInvalid = -1
202 };
203 #undef DECLARE_TYPE_ENUM 197 #undef DECLARE_TYPE_ENUM
204 198
205 void* operator new(size_t size, Zone* zone) { return zone->New(size); } 199 void* operator new(size_t size, Zone* zone) { return zone->New(size); }
206 200
207 explicit AstNode(int position): position_(position) {} 201 NodeType node_type() const { return node_type_; }
208 virtual ~AstNode() {}
209
210 virtual void Accept(AstVisitor* v) = 0;
211 virtual NodeType node_type() const = 0;
212 int position() const { return position_; } 202 int position() const { return position_; }
213 203
214 #ifdef DEBUG 204 #ifdef DEBUG
215 void Print(Isolate* isolate); 205 void Print(Isolate* isolate);
216 #endif // DEBUG 206 #endif // DEBUG
217 207
218 // Type testing & conversion functions overridden by concrete subclasses. 208 // Type testing & conversion functions overridden by concrete subclasses.
219 #define DECLARE_NODE_FUNCTIONS(type) \ 209 #define DECLARE_NODE_FUNCTIONS(type) \
220 V8_INLINE bool Is##type() const; \ 210 V8_INLINE bool Is##type() const; \
221 V8_INLINE type* As##type(); \ 211 V8_INLINE type* As##type(); \
222 V8_INLINE const type* As##type() const; 212 V8_INLINE const type* As##type() const;
223 AST_NODE_LIST(DECLARE_NODE_FUNCTIONS) 213 AST_NODE_LIST(DECLARE_NODE_FUNCTIONS)
224 #undef DECLARE_NODE_FUNCTIONS 214 #undef DECLARE_NODE_FUNCTIONS
225 215
226 BreakableStatement* AsBreakableStatement(); 216 BreakableStatement* AsBreakableStatement();
227 IterationStatement* AsIterationStatement(); 217 IterationStatement* AsIterationStatement();
228 MaterializedLiteral* AsMaterializedLiteral(); 218 MaterializedLiteral* AsMaterializedLiteral();
229 219
220 protected:
221 AstNode(int position, NodeType type)
222 : position_(position), node_type_(type) {}
223
230 private: 224 private:
231 // Hidden to prevent accidental usage. It would have to load the 225 // Hidden to prevent accidental usage. It would have to load the
232 // current zone from the TLS. 226 // current zone from the TLS.
233 void* operator new(size_t size); 227 void* operator new(size_t size);
234 228
235 friend class CaseClause; // Generates AST IDs. 229 friend class CaseClause; // Generates AST IDs.
236 230
237 int position_; 231 int position_;
232 NodeType node_type_;
238 }; 233 };
239 234
240 235
241 class Statement : public AstNode { 236 class Statement : public AstNode {
242 public: 237 public:
243 explicit Statement(Zone* zone, int position) : AstNode(position) {}
244
245 bool IsEmpty() { return AsEmptyStatement() != NULL; } 238 bool IsEmpty() { return AsEmptyStatement() != NULL; }
246 bool IsJump() const; 239 bool IsJump() const;
240
241 protected:
242 Statement(Zone* zone, int position, NodeType type)
243 : AstNode(position, type) {}
247 }; 244 };
248 245
249 246
250 class SmallMapList final { 247 class SmallMapList final {
251 public: 248 public:
252 SmallMapList() {} 249 SmallMapList() {}
253 SmallMapList(int capacity, Zone* zone) : list_(capacity, zone) {} 250 SmallMapList(int capacity, Zone* zone) : list_(capacity, zone) {}
254 251
255 void Reserve(int capacity, Zone* zone) { list_.Reserve(capacity, zone); } 252 void Reserve(int capacity, Zone* zone) { list_.Reserve(capacity, zone); }
256 void Clear() { list_.Clear(); } 253 void Clear() { list_.Clear(); }
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
353 KeyedAccessStoreMode GetStoreMode() const; 350 KeyedAccessStoreMode GetStoreMode() const;
354 IcCheckType GetKeyType() const; 351 IcCheckType GetKeyType() const;
355 bool IsMonomorphic() const; 352 bool IsMonomorphic() const;
356 353
357 void set_base_id(int id) { base_id_ = id; } 354 void set_base_id(int id) { base_id_ = id; }
358 static int num_ids() { return parent_num_ids() + 2; } 355 static int num_ids() { return parent_num_ids() + 2; }
359 BailoutId id() const { return BailoutId(local_id(0)); } 356 BailoutId id() const { return BailoutId(local_id(0)); }
360 TypeFeedbackId test_id() const { return TypeFeedbackId(local_id(1)); } 357 TypeFeedbackId test_id() const { return TypeFeedbackId(local_id(1)); }
361 358
362 protected: 359 protected:
363 Expression(Zone* zone, int pos) 360 Expression(Zone* zone, int pos, NodeType type)
364 : AstNode(pos), 361 : AstNode(pos, type),
365 base_id_(BailoutId::None().ToInt()), 362 base_id_(BailoutId::None().ToInt()),
366 bit_field_(0) {} 363 bit_field_(0) {}
367 static int parent_num_ids() { return 0; } 364 static int parent_num_ids() { return 0; }
368 void set_to_boolean_types(uint16_t types) { 365 void set_to_boolean_types(uint16_t types) {
369 bit_field_ = ToBooleanTypesField::update(bit_field_, types); 366 bit_field_ = ToBooleanTypesField::update(bit_field_, types);
370 } 367 }
371 368
372 int base_id() const { 369 int base_id() const {
373 DCHECK(!BailoutId(base_id_).IsNone()); 370 DCHECK(!BailoutId(base_id_).IsNone());
374 return base_id_; 371 return base_id_;
(...skipping 29 matching lines...) Expand all
404 return breakable_type_ == TARGET_FOR_ANONYMOUS; 401 return breakable_type_ == TARGET_FOR_ANONYMOUS;
405 } 402 }
406 403
407 void set_base_id(int id) { base_id_ = id; } 404 void set_base_id(int id) { base_id_ = id; }
408 static int num_ids() { return parent_num_ids() + 2; } 405 static int num_ids() { return parent_num_ids() + 2; }
409 BailoutId EntryId() const { return BailoutId(local_id(0)); } 406 BailoutId EntryId() const { return BailoutId(local_id(0)); }
410 BailoutId ExitId() const { return BailoutId(local_id(1)); } 407 BailoutId ExitId() const { return BailoutId(local_id(1)); }
411 408
412 protected: 409 protected:
413 BreakableStatement(Zone* zone, ZoneList<const AstRawString*>* labels, 410 BreakableStatement(Zone* zone, ZoneList<const AstRawString*>* labels,
414 BreakableType breakable_type, int position) 411 BreakableType breakable_type, int position, NodeType type)
415 : Statement(zone, position), 412 : Statement(zone, position, type),
416 labels_(labels), 413 labels_(labels),
417 breakable_type_(breakable_type), 414 breakable_type_(breakable_type),
418 base_id_(BailoutId::None().ToInt()) { 415 base_id_(BailoutId::None().ToInt()) {
419 DCHECK(labels == NULL || labels->length() > 0); 416 DCHECK(labels == NULL || labels->length() > 0);
420 } 417 }
421 static int parent_num_ids() { return 0; } 418 static int parent_num_ids() { return 0; }
422 419
423 int base_id() const { 420 int base_id() const {
424 DCHECK(!BailoutId(base_id_).IsNone()); 421 DCHECK(!BailoutId(base_id_).IsNone());
425 return base_id_; 422 return base_id_;
(...skipping 23 matching lines...) Expand all
449 return !statements_.is_empty() && statements_.last()->IsJump() 446 return !statements_.is_empty() && statements_.last()->IsJump()
450 && labels() == NULL; // Good enough as an approximation... 447 && labels() == NULL; // Good enough as an approximation...
451 } 448 }
452 449
453 Scope* scope() const { return scope_; } 450 Scope* scope() const { return scope_; }
454 void set_scope(Scope* scope) { scope_ = scope; } 451 void set_scope(Scope* scope) { scope_ = scope; }
455 452
456 protected: 453 protected:
457 Block(Zone* zone, ZoneList<const AstRawString*>* labels, int capacity, 454 Block(Zone* zone, ZoneList<const AstRawString*>* labels, int capacity,
458 bool ignore_completion_value, int pos) 455 bool ignore_completion_value, int pos)
459 : BreakableStatement(zone, labels, TARGET_FOR_NAMED_ONLY, pos), 456 : BreakableStatement(zone, labels, TARGET_FOR_NAMED_ONLY, pos, kBlock),
460 statements_(capacity, zone), 457 statements_(capacity, zone),
461 ignore_completion_value_(ignore_completion_value), 458 ignore_completion_value_(ignore_completion_value),
462 scope_(NULL) {} 459 scope_(NULL) {}
463 static int parent_num_ids() { return BreakableStatement::num_ids(); } 460 static int parent_num_ids() { return BreakableStatement::num_ids(); }
464 461
465 private: 462 private:
466 int local_id(int n) const { return base_id() + parent_num_ids() + n; } 463 int local_id(int n) const { return base_id() + parent_num_ids() + n; }
467 464
468 ZoneList<Statement*> statements_; 465 ZoneList<Statement*> statements_;
469 bool ignore_completion_value_; 466 bool ignore_completion_value_;
470 Scope* scope_; 467 Scope* scope_;
471 }; 468 };
472 469
473 470
474 class DoExpression final : public Expression { 471 class DoExpression final : public Expression {
475 public: 472 public:
476 DECLARE_NODE_TYPE(DoExpression) 473 DECLARE_NODE_TYPE(DoExpression)
477 474
478 Block* block() { return block_; } 475 Block* block() { return block_; }
479 void set_block(Block* b) { block_ = b; } 476 void set_block(Block* b) { block_ = b; }
480 VariableProxy* result() { return result_; } 477 VariableProxy* result() { return result_; }
481 void set_result(VariableProxy* v) { result_ = v; } 478 void set_result(VariableProxy* v) { result_ = v; }
482 479
483 protected: 480 protected:
484 DoExpression(Zone* zone, Block* block, VariableProxy* result, int pos) 481 DoExpression(Zone* zone, Block* block, VariableProxy* result, int pos)
485 : Expression(zone, pos), block_(block), result_(result) { 482 : Expression(zone, pos, kDoExpression), block_(block), result_(result) {
486 DCHECK_NOT_NULL(block_); 483 DCHECK_NOT_NULL(block_);
487 DCHECK_NOT_NULL(result_); 484 DCHECK_NOT_NULL(result_);
488 } 485 }
489 static int parent_num_ids() { return Expression::num_ids(); } 486 static int parent_num_ids() { return Expression::num_ids(); }
490 487
491 private: 488 private:
492 int local_id(int n) const { return base_id() + parent_num_ids() + n; } 489 int local_id(int n) const { return base_id() + parent_num_ids() + n; }
493 490
494 Block* block_; 491 Block* block_;
495 VariableProxy* result_; 492 VariableProxy* result_;
496 }; 493 };
497 494
498 495
499 class Declaration : public AstNode { 496 class Declaration : public AstNode {
500 public: 497 public:
501 VariableProxy* proxy() const { return proxy_; } 498 VariableProxy* proxy() const { return proxy_; }
502 VariableMode mode() const { return mode_; } 499 VariableMode mode() const { return mode_; }
503 Scope* scope() const { return scope_; } 500 Scope* scope() const { return scope_; }
504 InitializationFlag initialization() const; 501 InitializationFlag initialization() const;
505 502
506 protected: 503 protected:
507 Declaration(Zone* zone, VariableProxy* proxy, VariableMode mode, Scope* scope, 504 Declaration(Zone* zone, VariableProxy* proxy, VariableMode mode, Scope* scope,
508 int pos) 505 int pos, NodeType type)
509 : AstNode(pos), mode_(mode), proxy_(proxy), scope_(scope) { 506 : AstNode(pos, type), mode_(mode), proxy_(proxy), scope_(scope) {
510 DCHECK(IsDeclaredVariableMode(mode)); 507 DCHECK(IsDeclaredVariableMode(mode));
511 } 508 }
512 509
513 private: 510 private:
514 VariableMode mode_; 511 VariableMode mode_;
515 VariableProxy* proxy_; 512 VariableProxy* proxy_;
516 513
517 // Nested scope from which the declaration originated. 514 // Nested scope from which the declaration originated.
518 Scope* scope_; 515 Scope* scope_;
519 }; 516 };
520 517
521 518
522 class VariableDeclaration final : public Declaration { 519 class VariableDeclaration final : public Declaration {
523 public: 520 public:
524 DECLARE_NODE_TYPE(VariableDeclaration) 521 DECLARE_NODE_TYPE(VariableDeclaration)
525 522
526 InitializationFlag initialization() const { 523 InitializationFlag initialization() const {
527 return mode() == VAR ? kCreatedInitialized : kNeedsInitialization; 524 return mode() == VAR ? kCreatedInitialized : kNeedsInitialization;
528 } 525 }
529 526
530 protected: 527 protected:
531 VariableDeclaration(Zone* zone, VariableProxy* proxy, VariableMode mode, 528 VariableDeclaration(Zone* zone, VariableProxy* proxy, VariableMode mode,
532 Scope* scope, int pos) 529 Scope* scope, int pos)
533 : Declaration(zone, proxy, mode, scope, pos) {} 530 : Declaration(zone, proxy, mode, scope, pos, kVariableDeclaration) {}
534 }; 531 };
535 532
536 533
537 class FunctionDeclaration final : public Declaration { 534 class FunctionDeclaration final : public Declaration {
538 public: 535 public:
539 DECLARE_NODE_TYPE(FunctionDeclaration) 536 DECLARE_NODE_TYPE(FunctionDeclaration)
540 537
541 FunctionLiteral* fun() const { return fun_; } 538 FunctionLiteral* fun() const { return fun_; }
542 void set_fun(FunctionLiteral* f) { fun_ = f; } 539 void set_fun(FunctionLiteral* f) { fun_ = f; }
543 InitializationFlag initialization() const { return kCreatedInitialized; } 540 InitializationFlag initialization() const { return kCreatedInitialized; }
544 541
545 protected: 542 protected:
546 FunctionDeclaration(Zone* zone, 543 FunctionDeclaration(Zone* zone, VariableProxy* proxy, VariableMode mode,
547 VariableProxy* proxy, 544 FunctionLiteral* fun, Scope* scope, int pos)
548 VariableMode mode, 545 : Declaration(zone, proxy, mode, scope, pos, kFunctionDeclaration),
549 FunctionLiteral* fun,
550 Scope* scope,
551 int pos)
552 : Declaration(zone, proxy, mode, scope, pos),
553 fun_(fun) { 546 fun_(fun) {
554 DCHECK(mode == VAR || mode == LET || mode == CONST); 547 DCHECK(mode == VAR || mode == LET || mode == CONST);
555 DCHECK(fun != NULL); 548 DCHECK(fun != NULL);
556 } 549 }
557 550
558 private: 551 private:
559 FunctionLiteral* fun_; 552 FunctionLiteral* fun_;
560 }; 553 };
561 554
562 555
563 class ImportDeclaration final : public Declaration { 556 class ImportDeclaration final : public Declaration {
564 public: 557 public:
565 DECLARE_NODE_TYPE(ImportDeclaration) 558 DECLARE_NODE_TYPE(ImportDeclaration)
566 559
567 const AstRawString* import_name() const { return import_name_; } 560 const AstRawString* import_name() const { return import_name_; }
568 const AstRawString* module_specifier() const { return module_specifier_; } 561 const AstRawString* module_specifier() const { return module_specifier_; }
569 void set_module_specifier(const AstRawString* module_specifier) { 562 void set_module_specifier(const AstRawString* module_specifier) {
570 DCHECK(module_specifier_ == NULL); 563 DCHECK(module_specifier_ == NULL);
571 module_specifier_ = module_specifier; 564 module_specifier_ = module_specifier;
572 } 565 }
573 InitializationFlag initialization() const { return kNeedsInitialization; } 566 InitializationFlag initialization() const { return kNeedsInitialization; }
574 567
575 protected: 568 protected:
576 ImportDeclaration(Zone* zone, VariableProxy* proxy, 569 ImportDeclaration(Zone* zone, VariableProxy* proxy,
577 const AstRawString* import_name, 570 const AstRawString* import_name,
578 const AstRawString* module_specifier, Scope* scope, int pos) 571 const AstRawString* module_specifier, Scope* scope, int pos)
579 : Declaration(zone, proxy, CONST, scope, pos), 572 : Declaration(zone, proxy, CONST, scope, pos, kImportDeclaration),
580 import_name_(import_name), 573 import_name_(import_name),
581 module_specifier_(module_specifier) {} 574 module_specifier_(module_specifier) {}
582 575
583 private: 576 private:
584 const AstRawString* import_name_; 577 const AstRawString* import_name_;
585 const AstRawString* module_specifier_; 578 const AstRawString* module_specifier_;
586 }; 579 };
587 580
588 581 class Module final : public AstNode {
589 class Module : public AstNode {
590 public: 582 public:
591 ModuleDescriptor* descriptor() const { return descriptor_; } 583 ModuleDescriptor* descriptor() const { return descriptor_; }
592 Block* body() const { return body_; } 584 Block* body() const { return body_; }
593 585
594 protected: 586 protected:
595 Module(Zone* zone, int pos) 587 Module(Zone* zone, int pos)
596 : AstNode(pos), descriptor_(ModuleDescriptor::New(zone)), body_(NULL) {} 588 : AstNode(pos, kModule),
589 descriptor_(ModuleDescriptor::New(zone)),
590 body_(NULL) {}
597 Module(Zone* zone, ModuleDescriptor* descriptor, int pos, Block* body = NULL) 591 Module(Zone* zone, ModuleDescriptor* descriptor, int pos, Block* body = NULL)
598 : AstNode(pos), descriptor_(descriptor), body_(body) {} 592 : AstNode(pos, kModule), descriptor_(descriptor), body_(body) {}
599 593
600 private: 594 private:
601 ModuleDescriptor* descriptor_; 595 ModuleDescriptor* descriptor_;
602 Block* body_; 596 Block* body_;
603 }; 597 };
604 598
605 599
606 class IterationStatement : public BreakableStatement { 600 class IterationStatement : public BreakableStatement {
607 public: 601 public:
608 Statement* body() const { return body_; } 602 Statement* body() const { return body_; }
609 void set_body(Statement* s) { body_ = s; } 603 void set_body(Statement* s) { body_ = s; }
610 604
611 int yield_count() const { return yield_count_; } 605 int yield_count() const { return yield_count_; }
612 int first_yield_id() const { return first_yield_id_; } 606 int first_yield_id() const { return first_yield_id_; }
613 void set_yield_count(int yield_count) { yield_count_ = yield_count; } 607 void set_yield_count(int yield_count) { yield_count_ = yield_count; }
614 void set_first_yield_id(int first_yield_id) { 608 void set_first_yield_id(int first_yield_id) {
615 first_yield_id_ = first_yield_id; 609 first_yield_id_ = first_yield_id;
616 } 610 }
617 611
618 static int num_ids() { return parent_num_ids() + 1; } 612 static int num_ids() { return parent_num_ids() + 1; }
619 BailoutId OsrEntryId() const { return BailoutId(local_id(0)); } 613 BailoutId OsrEntryId() const { return BailoutId(local_id(0)); }
620 614
621 // Code generation 615 // Code generation
622 Label* continue_target() { return &continue_target_; } 616 Label* continue_target() { return &continue_target_; }
623 617
624 protected: 618 protected:
625 IterationStatement(Zone* zone, ZoneList<const AstRawString*>* labels, int pos) 619 IterationStatement(Zone* zone, ZoneList<const AstRawString*>* labels, int pos,
626 : BreakableStatement(zone, labels, TARGET_FOR_ANONYMOUS, pos), 620 NodeType type)
621 : BreakableStatement(zone, labels, TARGET_FOR_ANONYMOUS, pos, type),
627 body_(NULL), 622 body_(NULL),
628 yield_count_(0), 623 yield_count_(0),
629 first_yield_id_(0) {} 624 first_yield_id_(0) {}
630 static int parent_num_ids() { return BreakableStatement::num_ids(); } 625 static int parent_num_ids() { return BreakableStatement::num_ids(); }
631 void Initialize(Statement* body) { body_ = body; } 626 void Initialize(Statement* body) { body_ = body; }
632 627
633 private: 628 private:
634 int local_id(int n) const { return base_id() + parent_num_ids() + n; } 629 int local_id(int n) const { return base_id() + parent_num_ids() + n; }
635 630
636 Statement* body_; 631 Statement* body_;
(...skipping 15 matching lines...) Expand all
652 Expression* cond() const { return cond_; } 647 Expression* cond() const { return cond_; }
653 void set_cond(Expression* e) { cond_ = e; } 648 void set_cond(Expression* e) { cond_ = e; }
654 649
655 static int num_ids() { return parent_num_ids() + 2; } 650 static int num_ids() { return parent_num_ids() + 2; }
656 BailoutId ContinueId() const { return BailoutId(local_id(0)); } 651 BailoutId ContinueId() const { return BailoutId(local_id(0)); }
657 BailoutId StackCheckId() const { return BackEdgeId(); } 652 BailoutId StackCheckId() const { return BackEdgeId(); }
658 BailoutId BackEdgeId() const { return BailoutId(local_id(1)); } 653 BailoutId BackEdgeId() const { return BailoutId(local_id(1)); }
659 654
660 protected: 655 protected:
661 DoWhileStatement(Zone* zone, ZoneList<const AstRawString*>* labels, int pos) 656 DoWhileStatement(Zone* zone, ZoneList<const AstRawString*>* labels, int pos)
662 : IterationStatement(zone, labels, pos), cond_(NULL) {} 657 : IterationStatement(zone, labels, pos, kDoWhileStatement), cond_(NULL) {}
663 static int parent_num_ids() { return IterationStatement::num_ids(); } 658 static int parent_num_ids() { return IterationStatement::num_ids(); }
664 659
665 private: 660 private:
666 int local_id(int n) const { return base_id() + parent_num_ids() + n; } 661 int local_id(int n) const { return base_id() + parent_num_ids() + n; }
667 662
668 Expression* cond_; 663 Expression* cond_;
669 }; 664 };
670 665
671 666
672 class WhileStatement final : public IterationStatement { 667 class WhileStatement final : public IterationStatement {
673 public: 668 public:
674 DECLARE_NODE_TYPE(WhileStatement) 669 DECLARE_NODE_TYPE(WhileStatement)
675 670
676 void Initialize(Expression* cond, Statement* body) { 671 void Initialize(Expression* cond, Statement* body) {
677 IterationStatement::Initialize(body); 672 IterationStatement::Initialize(body);
678 cond_ = cond; 673 cond_ = cond;
679 } 674 }
680 675
681 Expression* cond() const { return cond_; } 676 Expression* cond() const { return cond_; }
682 void set_cond(Expression* e) { cond_ = e; } 677 void set_cond(Expression* e) { cond_ = e; }
683 678
684 static int num_ids() { return parent_num_ids() + 1; } 679 static int num_ids() { return parent_num_ids() + 1; }
685 BailoutId ContinueId() const { return EntryId(); } 680 BailoutId ContinueId() const { return EntryId(); }
686 BailoutId StackCheckId() const { return BodyId(); } 681 BailoutId StackCheckId() const { return BodyId(); }
687 BailoutId BodyId() const { return BailoutId(local_id(0)); } 682 BailoutId BodyId() const { return BailoutId(local_id(0)); }
688 683
689 protected: 684 protected:
690 WhileStatement(Zone* zone, ZoneList<const AstRawString*>* labels, int pos) 685 WhileStatement(Zone* zone, ZoneList<const AstRawString*>* labels, int pos)
691 : IterationStatement(zone, labels, pos), cond_(NULL) {} 686 : IterationStatement(zone, labels, pos, kWhileStatement), cond_(NULL) {}
692 static int parent_num_ids() { return IterationStatement::num_ids(); } 687 static int parent_num_ids() { return IterationStatement::num_ids(); }
693 688
694 private: 689 private:
695 int local_id(int n) const { return base_id() + parent_num_ids() + n; } 690 int local_id(int n) const { return base_id() + parent_num_ids() + n; }
696 691
697 Expression* cond_; 692 Expression* cond_;
698 }; 693 };
699 694
700 695
701 class ForStatement final : public IterationStatement { 696 class ForStatement final : public IterationStatement {
(...skipping 18 matching lines...) Expand all
720 void set_cond(Expression* e) { cond_ = e; } 715 void set_cond(Expression* e) { cond_ = e; }
721 void set_next(Statement* s) { next_ = s; } 716 void set_next(Statement* s) { next_ = s; }
722 717
723 static int num_ids() { return parent_num_ids() + 2; } 718 static int num_ids() { return parent_num_ids() + 2; }
724 BailoutId ContinueId() const { return BailoutId(local_id(0)); } 719 BailoutId ContinueId() const { return BailoutId(local_id(0)); }
725 BailoutId StackCheckId() const { return BodyId(); } 720 BailoutId StackCheckId() const { return BodyId(); }
726 BailoutId BodyId() const { return BailoutId(local_id(1)); } 721 BailoutId BodyId() const { return BailoutId(local_id(1)); }
727 722
728 protected: 723 protected:
729 ForStatement(Zone* zone, ZoneList<const AstRawString*>* labels, int pos) 724 ForStatement(Zone* zone, ZoneList<const AstRawString*>* labels, int pos)
730 : IterationStatement(zone, labels, pos), 725 : IterationStatement(zone, labels, pos, kForStatement),
731 init_(NULL), 726 init_(NULL),
732 cond_(NULL), 727 cond_(NULL),
733 next_(NULL) {} 728 next_(NULL) {}
734 static int parent_num_ids() { return IterationStatement::num_ids(); } 729 static int parent_num_ids() { return IterationStatement::num_ids(); }
735 730
736 private: 731 private:
737 int local_id(int n) const { return base_id() + parent_num_ids() + n; } 732 int local_id(int n) const { return base_id() + parent_num_ids() + n; }
738 733
739 Statement* init_; 734 Statement* init_;
740 Expression* cond_; 735 Expression* cond_;
741 Statement* next_; 736 Statement* next_;
742 }; 737 };
743 738
744 739
745 class ForEachStatement : public IterationStatement { 740 class ForEachStatement : public IterationStatement {
746 public: 741 public:
747 enum VisitMode { 742 enum VisitMode {
748 ENUMERATE, // for (each in subject) body; 743 ENUMERATE, // for (each in subject) body;
749 ITERATE // for (each of subject) body; 744 ITERATE // for (each of subject) body;
750 }; 745 };
751 746
752 using IterationStatement::Initialize; 747 using IterationStatement::Initialize;
753 748
754 static const char* VisitModeString(VisitMode mode) { 749 static const char* VisitModeString(VisitMode mode) {
755 return mode == ITERATE ? "for-of" : "for-in"; 750 return mode == ITERATE ? "for-of" : "for-in";
756 } 751 }
757 752
758 protected: 753 protected:
759 ForEachStatement(Zone* zone, ZoneList<const AstRawString*>* labels, int pos) 754 ForEachStatement(Zone* zone, ZoneList<const AstRawString*>* labels, int pos,
760 : IterationStatement(zone, labels, pos) {} 755 NodeType type)
756 : IterationStatement(zone, labels, pos, type) {}
761 }; 757 };
762 758
763 759
764 class ForInStatement final : public ForEachStatement { 760 class ForInStatement final : public ForEachStatement {
765 public: 761 public:
766 DECLARE_NODE_TYPE(ForInStatement) 762 DECLARE_NODE_TYPE(ForInStatement)
767 763
768 void Initialize(Expression* each, Expression* subject, Statement* body) { 764 void Initialize(Expression* each, Expression* subject, Statement* body) {
769 ForEachStatement::Initialize(body); 765 ForEachStatement::Initialize(body);
770 each_ = each; 766 each_ = each;
(...skipping 28 matching lines...) Expand all
799 BailoutId EnumId() const { return BailoutId(local_id(1)); } 795 BailoutId EnumId() const { return BailoutId(local_id(1)); }
800 BailoutId ToObjectId() const { return BailoutId(local_id(2)); } 796 BailoutId ToObjectId() const { return BailoutId(local_id(2)); }
801 BailoutId PrepareId() const { return BailoutId(local_id(3)); } 797 BailoutId PrepareId() const { return BailoutId(local_id(3)); }
802 BailoutId FilterId() const { return BailoutId(local_id(4)); } 798 BailoutId FilterId() const { return BailoutId(local_id(4)); }
803 BailoutId AssignmentId() const { return BailoutId(local_id(5)); } 799 BailoutId AssignmentId() const { return BailoutId(local_id(5)); }
804 BailoutId ContinueId() const { return EntryId(); } 800 BailoutId ContinueId() const { return EntryId(); }
805 BailoutId StackCheckId() const { return BodyId(); } 801 BailoutId StackCheckId() const { return BodyId(); }
806 802
807 protected: 803 protected:
808 ForInStatement(Zone* zone, ZoneList<const AstRawString*>* labels, int pos) 804 ForInStatement(Zone* zone, ZoneList<const AstRawString*>* labels, int pos)
809 : ForEachStatement(zone, labels, pos), 805 : ForEachStatement(zone, labels, pos, kForInStatement),
810 each_(nullptr), 806 each_(nullptr),
811 subject_(nullptr), 807 subject_(nullptr),
812 for_in_type_(SLOW_FOR_IN) {} 808 for_in_type_(SLOW_FOR_IN) {}
813 static int parent_num_ids() { return ForEachStatement::num_ids(); } 809 static int parent_num_ids() { return ForEachStatement::num_ids(); }
814 810
815 private: 811 private:
816 int local_id(int n) const { return base_id() + parent_num_ids() + n; } 812 int local_id(int n) const { return base_id() + parent_num_ids() + n; }
817 813
818 Expression* each_; 814 Expression* each_;
819 Expression* subject_; 815 Expression* subject_;
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
868 void set_assign_each(Expression* e) { assign_each_ = e; } 864 void set_assign_each(Expression* e) { assign_each_ = e; }
869 865
870 BailoutId ContinueId() const { return EntryId(); } 866 BailoutId ContinueId() const { return EntryId(); }
871 BailoutId StackCheckId() const { return BackEdgeId(); } 867 BailoutId StackCheckId() const { return BackEdgeId(); }
872 868
873 static int num_ids() { return parent_num_ids() + 1; } 869 static int num_ids() { return parent_num_ids() + 1; }
874 BailoutId BackEdgeId() const { return BailoutId(local_id(0)); } 870 BailoutId BackEdgeId() const { return BailoutId(local_id(0)); }
875 871
876 protected: 872 protected:
877 ForOfStatement(Zone* zone, ZoneList<const AstRawString*>* labels, int pos) 873 ForOfStatement(Zone* zone, ZoneList<const AstRawString*>* labels, int pos)
878 : ForEachStatement(zone, labels, pos), 874 : ForEachStatement(zone, labels, pos, kForOfStatement),
879 iterator_(NULL), 875 iterator_(NULL),
880 assign_iterator_(NULL), 876 assign_iterator_(NULL),
881 next_result_(NULL), 877 next_result_(NULL),
882 result_done_(NULL), 878 result_done_(NULL),
883 assign_each_(NULL) {} 879 assign_each_(NULL) {}
884 static int parent_num_ids() { return ForEachStatement::num_ids(); } 880 static int parent_num_ids() { return ForEachStatement::num_ids(); }
885 881
886 private: 882 private:
887 int local_id(int n) const { return base_id() + parent_num_ids() + n; } 883 int local_id(int n) const { return base_id() + parent_num_ids() + n; }
888 884
889 Variable* iterator_; 885 Variable* iterator_;
890 Expression* assign_iterator_; 886 Expression* assign_iterator_;
891 Expression* next_result_; 887 Expression* next_result_;
892 Expression* result_done_; 888 Expression* result_done_;
893 Expression* assign_each_; 889 Expression* assign_each_;
894 }; 890 };
895 891
896 892
897 class ExpressionStatement final : public Statement { 893 class ExpressionStatement final : public Statement {
898 public: 894 public:
899 DECLARE_NODE_TYPE(ExpressionStatement) 895 DECLARE_NODE_TYPE(ExpressionStatement)
900 896
901 void set_expression(Expression* e) { expression_ = e; } 897 void set_expression(Expression* e) { expression_ = e; }
902 Expression* expression() const { return expression_; } 898 Expression* expression() const { return expression_; }
903 bool IsJump() const { return expression_->IsThrow(); } 899 bool IsJump() const { return expression_->IsThrow(); }
904 900
905 protected: 901 protected:
906 ExpressionStatement(Zone* zone, Expression* expression, int pos) 902 ExpressionStatement(Zone* zone, Expression* expression, int pos)
907 : Statement(zone, pos), expression_(expression) { } 903 : Statement(zone, pos, kExpressionStatement), expression_(expression) {}
908 904
909 private: 905 private:
910 Expression* expression_; 906 Expression* expression_;
911 }; 907 };
912 908
913 909
914 class JumpStatement : public Statement { 910 class JumpStatement : public Statement {
915 public: 911 public:
916 bool IsJump() const { return true; } 912 bool IsJump() const { return true; }
917 913
918 protected: 914 protected:
919 explicit JumpStatement(Zone* zone, int pos) : Statement(zone, pos) {} 915 JumpStatement(Zone* zone, int pos, NodeType type)
916 : Statement(zone, pos, type) {}
920 }; 917 };
921 918
922 919
923 class ContinueStatement final : public JumpStatement { 920 class ContinueStatement final : public JumpStatement {
924 public: 921 public:
925 DECLARE_NODE_TYPE(ContinueStatement) 922 DECLARE_NODE_TYPE(ContinueStatement)
926 923
927 IterationStatement* target() const { return target_; } 924 IterationStatement* target() const { return target_; }
928 925
929 protected: 926 protected:
930 explicit ContinueStatement(Zone* zone, IterationStatement* target, int pos) 927 ContinueStatement(Zone* zone, IterationStatement* target, int pos)
931 : JumpStatement(zone, pos), target_(target) { } 928 : JumpStatement(zone, pos, kContinueStatement), target_(target) {}
932 929
933 private: 930 private:
934 IterationStatement* target_; 931 IterationStatement* target_;
935 }; 932 };
936 933
937 934
938 class BreakStatement final : public JumpStatement { 935 class BreakStatement final : public JumpStatement {
939 public: 936 public:
940 DECLARE_NODE_TYPE(BreakStatement) 937 DECLARE_NODE_TYPE(BreakStatement)
941 938
942 BreakableStatement* target() const { return target_; } 939 BreakableStatement* target() const { return target_; }
943 940
944 protected: 941 protected:
945 explicit BreakStatement(Zone* zone, BreakableStatement* target, int pos) 942 BreakStatement(Zone* zone, BreakableStatement* target, int pos)
946 : JumpStatement(zone, pos), target_(target) { } 943 : JumpStatement(zone, pos, kBreakStatement), target_(target) {}
947 944
948 private: 945 private:
949 BreakableStatement* target_; 946 BreakableStatement* target_;
950 }; 947 };
951 948
952 949
953 class ReturnStatement final : public JumpStatement { 950 class ReturnStatement final : public JumpStatement {
954 public: 951 public:
955 DECLARE_NODE_TYPE(ReturnStatement) 952 DECLARE_NODE_TYPE(ReturnStatement)
956 953
957 Expression* expression() const { return expression_; } 954 Expression* expression() const { return expression_; }
958 955
959 void set_expression(Expression* e) { expression_ = e; } 956 void set_expression(Expression* e) { expression_ = e; }
960 957
961 protected: 958 protected:
962 explicit ReturnStatement(Zone* zone, Expression* expression, int pos) 959 ReturnStatement(Zone* zone, Expression* expression, int pos)
963 : JumpStatement(zone, pos), expression_(expression) { } 960 : JumpStatement(zone, pos, kReturnStatement), expression_(expression) {}
964 961
965 private: 962 private:
966 Expression* expression_; 963 Expression* expression_;
967 }; 964 };
968 965
969 966
970 class WithStatement final : public Statement { 967 class WithStatement final : public Statement {
971 public: 968 public:
972 DECLARE_NODE_TYPE(WithStatement) 969 DECLARE_NODE_TYPE(WithStatement)
973 970
974 Scope* scope() { return scope_; } 971 Scope* scope() { return scope_; }
975 Expression* expression() const { return expression_; } 972 Expression* expression() const { return expression_; }
976 void set_expression(Expression* e) { expression_ = e; } 973 void set_expression(Expression* e) { expression_ = e; }
977 Statement* statement() const { return statement_; } 974 Statement* statement() const { return statement_; }
978 void set_statement(Statement* s) { statement_ = s; } 975 void set_statement(Statement* s) { statement_ = s; }
979 976
980 void set_base_id(int id) { base_id_ = id; } 977 void set_base_id(int id) { base_id_ = id; }
981 static int num_ids() { return parent_num_ids() + 2; } 978 static int num_ids() { return parent_num_ids() + 2; }
982 BailoutId ToObjectId() const { return BailoutId(local_id(0)); } 979 BailoutId ToObjectId() const { return BailoutId(local_id(0)); }
983 BailoutId EntryId() const { return BailoutId(local_id(1)); } 980 BailoutId EntryId() const { return BailoutId(local_id(1)); }
984 981
985 protected: 982 protected:
986 WithStatement(Zone* zone, Scope* scope, Expression* expression, 983 WithStatement(Zone* zone, Scope* scope, Expression* expression,
987 Statement* statement, int pos) 984 Statement* statement, int pos)
988 : Statement(zone, pos), 985 : Statement(zone, pos, kWithStatement),
989 scope_(scope), 986 scope_(scope),
990 expression_(expression), 987 expression_(expression),
991 statement_(statement), 988 statement_(statement),
992 base_id_(BailoutId::None().ToInt()) {} 989 base_id_(BailoutId::None().ToInt()) {}
993 static int parent_num_ids() { return 0; } 990 static int parent_num_ids() { return 0; }
994 991
995 int base_id() const { 992 int base_id() const {
996 DCHECK(!BailoutId(base_id_).IsNone()); 993 DCHECK(!BailoutId(base_id_).IsNone());
997 return base_id_; 994 return base_id_;
998 } 995 }
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
1051 cases_ = cases; 1048 cases_ = cases;
1052 } 1049 }
1053 1050
1054 Expression* tag() const { return tag_; } 1051 Expression* tag() const { return tag_; }
1055 ZoneList<CaseClause*>* cases() const { return cases_; } 1052 ZoneList<CaseClause*>* cases() const { return cases_; }
1056 1053
1057 void set_tag(Expression* t) { tag_ = t; } 1054 void set_tag(Expression* t) { tag_ = t; }
1058 1055
1059 protected: 1056 protected:
1060 SwitchStatement(Zone* zone, ZoneList<const AstRawString*>* labels, int pos) 1057 SwitchStatement(Zone* zone, ZoneList<const AstRawString*>* labels, int pos)
1061 : BreakableStatement(zone, labels, TARGET_FOR_ANONYMOUS, pos), 1058 : BreakableStatement(zone, labels, TARGET_FOR_ANONYMOUS, pos,
1059 kSwitchStatement),
1062 tag_(NULL), 1060 tag_(NULL),
1063 cases_(NULL) {} 1061 cases_(NULL) {}
1064 1062
1065 private: 1063 private:
1066 Expression* tag_; 1064 Expression* tag_;
1067 ZoneList<CaseClause*>* cases_; 1065 ZoneList<CaseClause*>* cases_;
1068 }; 1066 };
1069 1067
1070 1068
1071 // If-statements always have non-null references to their then- and 1069 // If-statements always have non-null references to their then- and
(...skipping 23 matching lines...) Expand all
1095 1093
1096 void set_base_id(int id) { base_id_ = id; } 1094 void set_base_id(int id) { base_id_ = id; }
1097 static int num_ids() { return parent_num_ids() + 3; } 1095 static int num_ids() { return parent_num_ids() + 3; }
1098 BailoutId IfId() const { return BailoutId(local_id(0)); } 1096 BailoutId IfId() const { return BailoutId(local_id(0)); }
1099 BailoutId ThenId() const { return BailoutId(local_id(1)); } 1097 BailoutId ThenId() const { return BailoutId(local_id(1)); }
1100 BailoutId ElseId() const { return BailoutId(local_id(2)); } 1098 BailoutId ElseId() const { return BailoutId(local_id(2)); }
1101 1099
1102 protected: 1100 protected:
1103 IfStatement(Zone* zone, Expression* condition, Statement* then_statement, 1101 IfStatement(Zone* zone, Expression* condition, Statement* then_statement,
1104 Statement* else_statement, int pos) 1102 Statement* else_statement, int pos)
1105 : Statement(zone, pos), 1103 : Statement(zone, pos, kIfStatement),
1106 condition_(condition), 1104 condition_(condition),
1107 then_statement_(then_statement), 1105 then_statement_(then_statement),
1108 else_statement_(else_statement), 1106 else_statement_(else_statement),
1109 base_id_(BailoutId::None().ToInt()) {} 1107 base_id_(BailoutId::None().ToInt()) {}
1110 static int parent_num_ids() { return 0; } 1108 static int parent_num_ids() { return 0; }
1111 1109
1112 int base_id() const { 1110 int base_id() const {
1113 DCHECK(!BailoutId(base_id_).IsNone()); 1111 DCHECK(!BailoutId(base_id_).IsNone());
1114 return base_id_; 1112 return base_id_;
1115 } 1113 }
(...skipping 20 matching lines...) Expand all
1136 // table. The runtime uses this information to implement a feature that 1134 // table. The runtime uses this information to implement a feature that
1137 // notifies the debugger when an uncaught exception is thrown, _before_ the 1135 // notifies the debugger when an uncaught exception is thrown, _before_ the
1138 // exception propagates to the top. 1136 // exception propagates to the top.
1139 // 1137 //
1140 // Since it's generally undecidable whether an exception will be caught, our 1138 // Since it's generally undecidable whether an exception will be caught, our
1141 // prediction is only an approximation. 1139 // prediction is only an approximation.
1142 bool catch_predicted() const { return catch_predicted_; } 1140 bool catch_predicted() const { return catch_predicted_; }
1143 void set_catch_predicted(bool b) { catch_predicted_ = b; } 1141 void set_catch_predicted(bool b) { catch_predicted_ = b; }
1144 1142
1145 protected: 1143 protected:
1146 TryStatement(Zone* zone, Block* try_block, int pos) 1144 TryStatement(Zone* zone, Block* try_block, int pos, NodeType type)
1147 : Statement(zone, pos), try_block_(try_block), catch_predicted_(false) {} 1145 : Statement(zone, pos, type),
1146 try_block_(try_block),
1147 catch_predicted_(false) {}
1148 1148
1149 private: 1149 private:
1150 Block* try_block_; 1150 Block* try_block_;
1151 bool catch_predicted_; 1151 bool catch_predicted_;
1152 }; 1152 };
1153 1153
1154 1154
1155 class TryCatchStatement final : public TryStatement { 1155 class TryCatchStatement final : public TryStatement {
1156 public: 1156 public:
1157 DECLARE_NODE_TYPE(TryCatchStatement) 1157 DECLARE_NODE_TYPE(TryCatchStatement)
(...skipping 12 matching lines...) Expand all
1170 // rethrow the caught exception (using %ReThrow), which reuses the pending 1170 // rethrow the caught exception (using %ReThrow), which reuses the pending
1171 // message instead of generating a new one. 1171 // message instead of generating a new one.
1172 // (When the catch block doesn't rethrow but is guaranteed to perform an 1172 // (When the catch block doesn't rethrow but is guaranteed to perform an
1173 // ordinary throw, not clearing the old message is safe but not very useful.) 1173 // ordinary throw, not clearing the old message is safe but not very useful.)
1174 bool clear_pending_message() { return clear_pending_message_; } 1174 bool clear_pending_message() { return clear_pending_message_; }
1175 1175
1176 protected: 1176 protected:
1177 TryCatchStatement(Zone* zone, Block* try_block, Scope* scope, 1177 TryCatchStatement(Zone* zone, Block* try_block, Scope* scope,
1178 Variable* variable, Block* catch_block, 1178 Variable* variable, Block* catch_block,
1179 bool clear_pending_message, int pos) 1179 bool clear_pending_message, int pos)
1180 : TryStatement(zone, try_block, pos), 1180 : TryStatement(zone, try_block, pos, kTryCatchStatement),
1181 scope_(scope), 1181 scope_(scope),
1182 variable_(variable), 1182 variable_(variable),
1183 catch_block_(catch_block), 1183 catch_block_(catch_block),
1184 clear_pending_message_(clear_pending_message) {} 1184 clear_pending_message_(clear_pending_message) {}
1185 1185
1186 private: 1186 private:
1187 Scope* scope_; 1187 Scope* scope_;
1188 Variable* variable_; 1188 Variable* variable_;
1189 Block* catch_block_; 1189 Block* catch_block_;
1190 bool clear_pending_message_; 1190 bool clear_pending_message_;
1191 }; 1191 };
1192 1192
1193 1193
1194 class TryFinallyStatement final : public TryStatement { 1194 class TryFinallyStatement final : public TryStatement {
1195 public: 1195 public:
1196 DECLARE_NODE_TYPE(TryFinallyStatement) 1196 DECLARE_NODE_TYPE(TryFinallyStatement)
1197 1197
1198 Block* finally_block() const { return finally_block_; } 1198 Block* finally_block() const { return finally_block_; }
1199 void set_finally_block(Block* b) { finally_block_ = b; } 1199 void set_finally_block(Block* b) { finally_block_ = b; }
1200 1200
1201 protected: 1201 protected:
1202 TryFinallyStatement(Zone* zone, Block* try_block, Block* finally_block, 1202 TryFinallyStatement(Zone* zone, Block* try_block, Block* finally_block,
1203 int pos) 1203 int pos)
1204 : TryStatement(zone, try_block, pos), finally_block_(finally_block) {} 1204 : TryStatement(zone, try_block, pos, kTryFinallyStatement),
1205 finally_block_(finally_block) {}
1205 1206
1206 private: 1207 private:
1207 Block* finally_block_; 1208 Block* finally_block_;
1208 }; 1209 };
1209 1210
1210 1211
1211 class DebuggerStatement final : public Statement { 1212 class DebuggerStatement final : public Statement {
1212 public: 1213 public:
1213 DECLARE_NODE_TYPE(DebuggerStatement) 1214 DECLARE_NODE_TYPE(DebuggerStatement)
1214 1215
1215 void set_base_id(int id) { base_id_ = id; } 1216 void set_base_id(int id) { base_id_ = id; }
1216 static int num_ids() { return parent_num_ids() + 1; } 1217 static int num_ids() { return parent_num_ids() + 1; }
1217 BailoutId DebugBreakId() const { return BailoutId(local_id(0)); } 1218 BailoutId DebugBreakId() const { return BailoutId(local_id(0)); }
1218 1219
1219 protected: 1220 protected:
1220 explicit DebuggerStatement(Zone* zone, int pos) 1221 DebuggerStatement(Zone* zone, int pos)
1221 : Statement(zone, pos), base_id_(BailoutId::None().ToInt()) {} 1222 : Statement(zone, pos, kDebuggerStatement),
1223 base_id_(BailoutId::None().ToInt()) {}
1222 static int parent_num_ids() { return 0; } 1224 static int parent_num_ids() { return 0; }
1223 1225
1224 int base_id() const { 1226 int base_id() const {
1225 DCHECK(!BailoutId(base_id_).IsNone()); 1227 DCHECK(!BailoutId(base_id_).IsNone());
1226 return base_id_; 1228 return base_id_;
1227 } 1229 }
1228 1230
1229 private: 1231 private:
1230 int local_id(int n) const { return base_id() + parent_num_ids() + n; } 1232 int local_id(int n) const { return base_id() + parent_num_ids() + n; }
1231 1233
1232 int base_id_; 1234 int base_id_;
1233 }; 1235 };
1234 1236
1235 1237
1236 class EmptyStatement final : public Statement { 1238 class EmptyStatement final : public Statement {
1237 public: 1239 public:
1238 DECLARE_NODE_TYPE(EmptyStatement) 1240 DECLARE_NODE_TYPE(EmptyStatement)
1239 1241
1240 protected: 1242 protected:
1241 explicit EmptyStatement(Zone* zone, int pos): Statement(zone, pos) {} 1243 EmptyStatement(Zone* zone, int pos) : Statement(zone, pos, kEmptyStatement) {}
1242 }; 1244 };
1243 1245
1244 1246
1245 // Delegates to another statement, which may be overwritten. 1247 // Delegates to another statement, which may be overwritten.
1246 // This was introduced to implement ES2015 Annex B3.3 for conditionally making 1248 // This was introduced to implement ES2015 Annex B3.3 for conditionally making
1247 // sloppy-mode block-scoped functions have a var binding, which is changed 1249 // sloppy-mode block-scoped functions have a var binding, which is changed
1248 // from one statement to another during parsing. 1250 // from one statement to another during parsing.
1249 class SloppyBlockFunctionStatement final : public Statement { 1251 class SloppyBlockFunctionStatement final : public Statement {
1250 public: 1252 public:
1251 DECLARE_NODE_TYPE(SloppyBlockFunctionStatement) 1253 DECLARE_NODE_TYPE(SloppyBlockFunctionStatement)
1252 1254
1253 Statement* statement() const { return statement_; } 1255 Statement* statement() const { return statement_; }
1254 void set_statement(Statement* statement) { statement_ = statement; } 1256 void set_statement(Statement* statement) { statement_ = statement; }
1255 Scope* scope() const { return scope_; } 1257 Scope* scope() const { return scope_; }
1256 1258
1257 private: 1259 private:
1258 SloppyBlockFunctionStatement(Zone* zone, Statement* statement, Scope* scope) 1260 SloppyBlockFunctionStatement(Zone* zone, Statement* statement, Scope* scope)
1259 : Statement(zone, kNoSourcePosition), 1261 : Statement(zone, kNoSourcePosition, kSloppyBlockFunctionStatement),
1260 statement_(statement), 1262 statement_(statement),
1261 scope_(scope) {} 1263 scope_(scope) {}
1262 1264
1263 Statement* statement_; 1265 Statement* statement_;
1264 Scope* const scope_; 1266 Scope* const scope_;
1265 }; 1267 };
1266 1268
1267 1269
1268 class Literal final : public Expression { 1270 class Literal final : public Expression {
1269 public: 1271 public:
(...skipping 22 matching lines...) Expand all
1292 uint32_t Hash(); 1294 uint32_t Hash();
1293 static bool Match(void* literal1, void* literal2); 1295 static bool Match(void* literal1, void* literal2);
1294 1296
1295 static int num_ids() { return parent_num_ids() + 1; } 1297 static int num_ids() { return parent_num_ids() + 1; }
1296 TypeFeedbackId LiteralFeedbackId() const { 1298 TypeFeedbackId LiteralFeedbackId() const {
1297 return TypeFeedbackId(local_id(0)); 1299 return TypeFeedbackId(local_id(0));
1298 } 1300 }
1299 1301
1300 protected: 1302 protected:
1301 Literal(Zone* zone, const AstValue* value, int position) 1303 Literal(Zone* zone, const AstValue* value, int position)
1302 : Expression(zone, position), value_(value) {} 1304 : Expression(zone, position, kLiteral), value_(value) {}
1303 static int parent_num_ids() { return Expression::num_ids(); } 1305 static int parent_num_ids() { return Expression::num_ids(); }
1304 1306
1305 private: 1307 private:
1306 int local_id(int n) const { return base_id() + parent_num_ids() + n; } 1308 int local_id(int n) const { return base_id() + parent_num_ids() + n; }
1307 1309
1308 const AstValue* value_; 1310 const AstValue* value_;
1309 }; 1311 };
1310 1312
1311 1313
1312 class AstLiteralReindexer; 1314 class AstLiteralReindexer;
1313 1315
1314 // Base class for literals that needs space in the corresponding JSFunction. 1316 // Base class for literals that needs space in the corresponding JSFunction.
1315 class MaterializedLiteral : public Expression { 1317 class MaterializedLiteral : public Expression {
1316 public: 1318 public:
1317 int literal_index() { return literal_index_; } 1319 int literal_index() { return literal_index_; }
1318 1320
1319 int depth() const { 1321 int depth() const {
1320 // only callable after initialization. 1322 // only callable after initialization.
1321 DCHECK(depth_ >= 1); 1323 DCHECK(depth_ >= 1);
1322 return depth_; 1324 return depth_;
1323 } 1325 }
1324 1326
1325 protected: 1327 protected:
1326 MaterializedLiteral(Zone* zone, int literal_index, int pos) 1328 MaterializedLiteral(Zone* zone, int literal_index, int pos, NodeType type)
1327 : Expression(zone, pos), 1329 : Expression(zone, pos, type),
1328 literal_index_(literal_index), 1330 literal_index_(literal_index),
1329 is_simple_(false), 1331 is_simple_(false),
1330 depth_(0) {} 1332 depth_(0) {}
1331 1333
1332 // A materialized literal is simple if the values consist of only 1334 // A materialized literal is simple if the values consist of only
1333 // constants and simple object and array literals. 1335 // constants and simple object and array literals.
1334 bool is_simple() const { return is_simple_; } 1336 bool is_simple() const { return is_simple_; }
1335 void set_is_simple(bool is_simple) { is_simple_ = is_simple; } 1337 void set_is_simple(bool is_simple) { is_simple_ = is_simple; }
1336 friend class CompileTimeValue; 1338 friend class CompileTimeValue;
1337 1339
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
1500 } 1502 }
1501 1503
1502 // Object literals need one feedback slot for each non-trivial value, as well 1504 // Object literals need one feedback slot for each non-trivial value, as well
1503 // as some slots for home objects. 1505 // as some slots for home objects.
1504 void AssignFeedbackVectorSlots(Isolate* isolate, FeedbackVectorSpec* spec, 1506 void AssignFeedbackVectorSlots(Isolate* isolate, FeedbackVectorSpec* spec,
1505 FeedbackVectorSlotCache* cache); 1507 FeedbackVectorSlotCache* cache);
1506 1508
1507 protected: 1509 protected:
1508 ObjectLiteral(Zone* zone, ZoneList<Property*>* properties, int literal_index, 1510 ObjectLiteral(Zone* zone, ZoneList<Property*>* properties, int literal_index,
1509 int boilerplate_properties, int pos) 1511 int boilerplate_properties, int pos)
1510 : MaterializedLiteral(zone, literal_index, pos), 1512 : MaterializedLiteral(zone, literal_index, pos, kObjectLiteral),
1511 properties_(properties), 1513 properties_(properties),
1512 boilerplate_properties_(boilerplate_properties), 1514 boilerplate_properties_(boilerplate_properties),
1513 fast_elements_(false), 1515 fast_elements_(false),
1514 has_elements_(false), 1516 has_elements_(false),
1515 may_store_doubles_(false) {} 1517 may_store_doubles_(false) {}
1516 static int parent_num_ids() { return MaterializedLiteral::num_ids(); } 1518 static int parent_num_ids() { return MaterializedLiteral::num_ids(); }
1517 1519
1518 private: 1520 private:
1519 int local_id(int n) const { return base_id() + parent_num_ids() + n; } 1521 int local_id(int n) const { return base_id() + parent_num_ids() + n; }
1520 Handle<FixedArray> constant_properties_; 1522 Handle<FixedArray> constant_properties_;
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
1553 class RegExpLiteral final : public MaterializedLiteral { 1555 class RegExpLiteral final : public MaterializedLiteral {
1554 public: 1556 public:
1555 DECLARE_NODE_TYPE(RegExpLiteral) 1557 DECLARE_NODE_TYPE(RegExpLiteral)
1556 1558
1557 Handle<String> pattern() const { return pattern_->string(); } 1559 Handle<String> pattern() const { return pattern_->string(); }
1558 int flags() const { return flags_; } 1560 int flags() const { return flags_; }
1559 1561
1560 protected: 1562 protected:
1561 RegExpLiteral(Zone* zone, const AstRawString* pattern, int flags, 1563 RegExpLiteral(Zone* zone, const AstRawString* pattern, int flags,
1562 int literal_index, int pos) 1564 int literal_index, int pos)
1563 : MaterializedLiteral(zone, literal_index, pos), 1565 : MaterializedLiteral(zone, literal_index, pos, kRegExpLiteral),
1564 pattern_(pattern), 1566 pattern_(pattern),
1565 flags_(flags) { 1567 flags_(flags) {
1566 set_depth(1); 1568 set_depth(1);
1567 } 1569 }
1568 1570
1569 private: 1571 private:
1570 const AstRawString* const pattern_; 1572 const AstRawString* const pattern_;
1571 int const flags_; 1573 int const flags_;
1572 }; 1574 };
1573 1575
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
1627 kDisableMementos = 1 << 1 1629 kDisableMementos = 1 << 1
1628 }; 1630 };
1629 1631
1630 void AssignFeedbackVectorSlots(Isolate* isolate, FeedbackVectorSpec* spec, 1632 void AssignFeedbackVectorSlots(Isolate* isolate, FeedbackVectorSpec* spec,
1631 FeedbackVectorSlotCache* cache); 1633 FeedbackVectorSlotCache* cache);
1632 FeedbackVectorSlot LiteralFeedbackSlot() const { return literal_slot_; } 1634 FeedbackVectorSlot LiteralFeedbackSlot() const { return literal_slot_; }
1633 1635
1634 protected: 1636 protected:
1635 ArrayLiteral(Zone* zone, ZoneList<Expression*>* values, 1637 ArrayLiteral(Zone* zone, ZoneList<Expression*>* values,
1636 int first_spread_index, int literal_index, int pos) 1638 int first_spread_index, int literal_index, int pos)
1637 : MaterializedLiteral(zone, literal_index, pos), 1639 : MaterializedLiteral(zone, literal_index, pos, kArrayLiteral),
1638 values_(values), 1640 values_(values),
1639 first_spread_index_(first_spread_index) {} 1641 first_spread_index_(first_spread_index) {}
1640 static int parent_num_ids() { return MaterializedLiteral::num_ids(); } 1642 static int parent_num_ids() { return MaterializedLiteral::num_ids(); }
1641 1643
1642 private: 1644 private:
1643 int local_id(int n) const { return base_id() + parent_num_ids() + n; } 1645 int local_id(int n) const { return base_id() + parent_num_ids() + n; }
1644 1646
1645 Handle<FixedArray> constant_elements_; 1647 Handle<FixedArray> constant_elements_;
1646 ZoneList<Expression*>* values_; 1648 ZoneList<Expression*>* values_;
1647 int first_spread_index_; 1649 int first_spread_index_;
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
1813 static LhsKind GetAssignType(Property* property) { 1815 static LhsKind GetAssignType(Property* property) {
1814 if (property == NULL) return VARIABLE; 1816 if (property == NULL) return VARIABLE;
1815 bool super_access = property->IsSuperAccess(); 1817 bool super_access = property->IsSuperAccess();
1816 return (property->key()->IsPropertyName()) 1818 return (property->key()->IsPropertyName())
1817 ? (super_access ? NAMED_SUPER_PROPERTY : NAMED_PROPERTY) 1819 ? (super_access ? NAMED_SUPER_PROPERTY : NAMED_PROPERTY)
1818 : (super_access ? KEYED_SUPER_PROPERTY : KEYED_PROPERTY); 1820 : (super_access ? KEYED_SUPER_PROPERTY : KEYED_PROPERTY);
1819 } 1821 }
1820 1822
1821 protected: 1823 protected:
1822 Property(Zone* zone, Expression* obj, Expression* key, int pos) 1824 Property(Zone* zone, Expression* obj, Expression* key, int pos)
1823 : Expression(zone, pos), 1825 : Expression(zone, pos, kProperty),
1824 bit_field_(IsForCallField::encode(false) | 1826 bit_field_(IsForCallField::encode(false) |
1825 IsStringAccessField::encode(false) | 1827 IsStringAccessField::encode(false) |
1826 InlineCacheStateField::encode(UNINITIALIZED)), 1828 InlineCacheStateField::encode(UNINITIALIZED)),
1827 obj_(obj), 1829 obj_(obj),
1828 key_(key) {} 1830 key_(key) {}
1829 static int parent_num_ids() { return Expression::num_ids(); } 1831 static int parent_num_ids() { return Expression::num_ids(); }
1830 1832
1831 private: 1833 private:
1832 int local_id(int n) const { return base_id() + parent_num_ids() + n; } 1834 int local_id(int n) const { return base_id() + parent_num_ids() + n; }
1833 1835
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
1933 bool IsUsingCallFeedbackICSlot(Isolate* isolate) const; 1935 bool IsUsingCallFeedbackICSlot(Isolate* isolate) const;
1934 1936
1935 #ifdef DEBUG 1937 #ifdef DEBUG
1936 // Used to assert that the FullCodeGenerator records the return site. 1938 // Used to assert that the FullCodeGenerator records the return site.
1937 bool return_is_recorded_; 1939 bool return_is_recorded_;
1938 #endif 1940 #endif
1939 1941
1940 protected: 1942 protected:
1941 Call(Zone* zone, Expression* expression, ZoneList<Expression*>* arguments, 1943 Call(Zone* zone, Expression* expression, ZoneList<Expression*>* arguments,
1942 int pos) 1944 int pos)
1943 : Expression(zone, pos), 1945 : Expression(zone, pos, kCall),
1944 expression_(expression), 1946 expression_(expression),
1945 arguments_(arguments), 1947 arguments_(arguments),
1946 bit_field_(IsUninitializedField::encode(false)) { 1948 bit_field_(IsUninitializedField::encode(false)) {
1947 if (expression->IsProperty()) { 1949 if (expression->IsProperty()) {
1948 expression->AsProperty()->mark_for_call(); 1950 expression->AsProperty()->mark_for_call();
1949 } 1951 }
1950 } 1952 }
1951 static int parent_num_ids() { return Expression::num_ids(); } 1953 static int parent_num_ids() { return Expression::num_ids(); }
1952 1954
1953 private: 1955 private:
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
2004 void set_is_monomorphic(bool monomorphic) { is_monomorphic_ = monomorphic; } 2006 void set_is_monomorphic(bool monomorphic) { is_monomorphic_ = monomorphic; }
2005 void set_target(Handle<JSFunction> target) { target_ = target; } 2007 void set_target(Handle<JSFunction> target) { target_ = target; }
2006 void SetKnownGlobalTarget(Handle<JSFunction> target) { 2008 void SetKnownGlobalTarget(Handle<JSFunction> target) {
2007 target_ = target; 2009 target_ = target;
2008 is_monomorphic_ = true; 2010 is_monomorphic_ = true;
2009 } 2011 }
2010 2012
2011 protected: 2013 protected:
2012 CallNew(Zone* zone, Expression* expression, ZoneList<Expression*>* arguments, 2014 CallNew(Zone* zone, Expression* expression, ZoneList<Expression*>* arguments,
2013 int pos) 2015 int pos)
2014 : Expression(zone, pos), 2016 : Expression(zone, pos, kCallNew),
2015 expression_(expression), 2017 expression_(expression),
2016 arguments_(arguments), 2018 arguments_(arguments),
2017 is_monomorphic_(false) {} 2019 is_monomorphic_(false) {}
2018 2020
2019 static int parent_num_ids() { return Expression::num_ids(); } 2021 static int parent_num_ids() { return Expression::num_ids(); }
2020 2022
2021 private: 2023 private:
2022 int local_id(int n) const { return base_id() + parent_num_ids() + n; } 2024 int local_id(int n) const { return base_id() + parent_num_ids() + n; }
2023 2025
2024 Expression* expression_; 2026 Expression* expression_;
(...skipping 28 matching lines...) Expand all
2053 static int num_ids() { return parent_num_ids() + 1; } 2055 static int num_ids() { return parent_num_ids() + 1; }
2054 BailoutId CallId() { return BailoutId(local_id(0)); } 2056 BailoutId CallId() { return BailoutId(local_id(0)); }
2055 2057
2056 const char* debug_name() { 2058 const char* debug_name() {
2057 return is_jsruntime() ? "(context function)" : function_->name; 2059 return is_jsruntime() ? "(context function)" : function_->name;
2058 } 2060 }
2059 2061
2060 protected: 2062 protected:
2061 CallRuntime(Zone* zone, const Runtime::Function* function, 2063 CallRuntime(Zone* zone, const Runtime::Function* function,
2062 ZoneList<Expression*>* arguments, int pos) 2064 ZoneList<Expression*>* arguments, int pos)
2063 : Expression(zone, pos), function_(function), arguments_(arguments) {} 2065 : Expression(zone, pos, kCallRuntime),
2066 function_(function),
2067 arguments_(arguments) {}
2064 2068
2065 CallRuntime(Zone* zone, int context_index, ZoneList<Expression*>* arguments, 2069 CallRuntime(Zone* zone, int context_index, ZoneList<Expression*>* arguments,
2066 int pos) 2070 int pos)
2067 : Expression(zone, pos), 2071 : Expression(zone, pos, kCallRuntime),
2068 function_(NULL), 2072 function_(NULL),
2069 context_index_(context_index), 2073 context_index_(context_index),
2070 arguments_(arguments) {} 2074 arguments_(arguments) {}
2071 2075
2072 static int parent_num_ids() { return Expression::num_ids(); } 2076 static int parent_num_ids() { return Expression::num_ids(); }
2073 2077
2074 private: 2078 private:
2075 int local_id(int n) const { return base_id() + parent_num_ids() + n; } 2079 int local_id(int n) const { return base_id() + parent_num_ids() + n; }
2076 2080
2077 const Runtime::Function* function_; 2081 const Runtime::Function* function_;
(...skipping 13 matching lines...) Expand all
2091 // For unary not (Token::NOT), the AST ids where true and false will 2095 // For unary not (Token::NOT), the AST ids where true and false will
2092 // actually be materialized, respectively. 2096 // actually be materialized, respectively.
2093 static int num_ids() { return parent_num_ids() + 2; } 2097 static int num_ids() { return parent_num_ids() + 2; }
2094 BailoutId MaterializeTrueId() const { return BailoutId(local_id(0)); } 2098 BailoutId MaterializeTrueId() const { return BailoutId(local_id(0)); }
2095 BailoutId MaterializeFalseId() const { return BailoutId(local_id(1)); } 2099 BailoutId MaterializeFalseId() const { return BailoutId(local_id(1)); }
2096 2100
2097 void RecordToBooleanTypeFeedback(TypeFeedbackOracle* oracle); 2101 void RecordToBooleanTypeFeedback(TypeFeedbackOracle* oracle);
2098 2102
2099 protected: 2103 protected:
2100 UnaryOperation(Zone* zone, Token::Value op, Expression* expression, int pos) 2104 UnaryOperation(Zone* zone, Token::Value op, Expression* expression, int pos)
2101 : Expression(zone, pos), op_(op), expression_(expression) { 2105 : Expression(zone, pos, kUnaryOperation),
2106 op_(op),
2107 expression_(expression) {
2102 DCHECK(Token::IsUnaryOp(op)); 2108 DCHECK(Token::IsUnaryOp(op));
2103 } 2109 }
2104 static int parent_num_ids() { return Expression::num_ids(); } 2110 static int parent_num_ids() { return Expression::num_ids(); }
2105 2111
2106 private: 2112 private:
2107 int local_id(int n) const { return base_id() + parent_num_ids() + n; } 2113 int local_id(int n) const { return base_id() + parent_num_ids() + n; }
2108 2114
2109 Token::Value op_; 2115 Token::Value op_;
2110 Expression* expression_; 2116 Expression* expression_;
2111 }; 2117 };
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
2150 void set_fixed_right_arg(Maybe<int> arg) { 2156 void set_fixed_right_arg(Maybe<int> arg) {
2151 has_fixed_right_arg_ = arg.IsJust(); 2157 has_fixed_right_arg_ = arg.IsJust();
2152 if (arg.IsJust()) fixed_right_arg_value_ = arg.FromJust(); 2158 if (arg.IsJust()) fixed_right_arg_value_ = arg.FromJust();
2153 } 2159 }
2154 2160
2155 void RecordToBooleanTypeFeedback(TypeFeedbackOracle* oracle); 2161 void RecordToBooleanTypeFeedback(TypeFeedbackOracle* oracle);
2156 2162
2157 protected: 2163 protected:
2158 BinaryOperation(Zone* zone, Token::Value op, Expression* left, 2164 BinaryOperation(Zone* zone, Token::Value op, Expression* left,
2159 Expression* right, int pos) 2165 Expression* right, int pos)
2160 : Expression(zone, pos), 2166 : Expression(zone, pos, kBinaryOperation),
2161 op_(static_cast<byte>(op)), 2167 op_(static_cast<byte>(op)),
2162 has_fixed_right_arg_(false), 2168 has_fixed_right_arg_(false),
2163 fixed_right_arg_value_(0), 2169 fixed_right_arg_value_(0),
2164 left_(left), 2170 left_(left),
2165 right_(right) { 2171 right_(right) {
2166 DCHECK(Token::IsBinaryOp(op)); 2172 DCHECK(Token::IsBinaryOp(op));
2167 } 2173 }
2168 static int parent_num_ids() { return Expression::num_ids(); } 2174 static int parent_num_ids() { return Expression::num_ids(); }
2169 2175
2170 private: 2176 private:
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
2221 return TypeFeedbackId(local_id(3)); 2227 return TypeFeedbackId(local_id(3));
2222 } 2228 }
2223 2229
2224 void AssignFeedbackVectorSlots(Isolate* isolate, FeedbackVectorSpec* spec, 2230 void AssignFeedbackVectorSlots(Isolate* isolate, FeedbackVectorSpec* spec,
2225 FeedbackVectorSlotCache* cache); 2231 FeedbackVectorSlotCache* cache);
2226 FeedbackVectorSlot CountSlot() const { return slot_; } 2232 FeedbackVectorSlot CountSlot() const { return slot_; }
2227 2233
2228 protected: 2234 protected:
2229 CountOperation(Zone* zone, Token::Value op, bool is_prefix, Expression* expr, 2235 CountOperation(Zone* zone, Token::Value op, bool is_prefix, Expression* expr,
2230 int pos) 2236 int pos)
2231 : Expression(zone, pos), 2237 : Expression(zone, pos, kCountOperation),
2232 bit_field_( 2238 bit_field_(
2233 IsPrefixField::encode(is_prefix) | KeyTypeField::encode(ELEMENT) | 2239 IsPrefixField::encode(is_prefix) | KeyTypeField::encode(ELEMENT) |
2234 StoreModeField::encode(STANDARD_STORE) | TokenField::encode(op)), 2240 StoreModeField::encode(STANDARD_STORE) | TokenField::encode(op)),
2235 type_(NULL), 2241 type_(NULL),
2236 expression_(expr) {} 2242 expression_(expr) {}
2237 static int parent_num_ids() { return Expression::num_ids(); } 2243 static int parent_num_ids() { return Expression::num_ids(); }
2238 2244
2239 private: 2245 private:
2240 int local_id(int n) const { return base_id() + parent_num_ids() + n; } 2246 int local_id(int n) const { return base_id() + parent_num_ids() + n; }
2241 2247
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
2274 void set_combined_type(Type* type) { combined_type_ = type; } 2280 void set_combined_type(Type* type) { combined_type_ = type; }
2275 2281
2276 // Match special cases. 2282 // Match special cases.
2277 bool IsLiteralCompareTypeof(Expression** expr, Handle<String>* check); 2283 bool IsLiteralCompareTypeof(Expression** expr, Handle<String>* check);
2278 bool IsLiteralCompareUndefined(Expression** expr); 2284 bool IsLiteralCompareUndefined(Expression** expr);
2279 bool IsLiteralCompareNull(Expression** expr); 2285 bool IsLiteralCompareNull(Expression** expr);
2280 2286
2281 protected: 2287 protected:
2282 CompareOperation(Zone* zone, Token::Value op, Expression* left, 2288 CompareOperation(Zone* zone, Token::Value op, Expression* left,
2283 Expression* right, int pos) 2289 Expression* right, int pos)
2284 : Expression(zone, pos), 2290 : Expression(zone, pos, kCompareOperation),
2285 op_(op), 2291 op_(op),
2286 left_(left), 2292 left_(left),
2287 right_(right), 2293 right_(right),
2288 combined_type_(Type::None()) { 2294 combined_type_(Type::None()) {
2289 DCHECK(Token::IsCompareOp(op)); 2295 DCHECK(Token::IsCompareOp(op));
2290 } 2296 }
2291 static int parent_num_ids() { return Expression::num_ids(); } 2297 static int parent_num_ids() { return Expression::num_ids(); }
2292 2298
2293 private: 2299 private:
2294 int local_id(int n) const { return base_id() + parent_num_ids() + n; } 2300 int local_id(int n) const { return base_id() + parent_num_ids() + n; }
(...skipping 12 matching lines...) Expand all
2307 2313
2308 Expression* expression() const { return expression_; } 2314 Expression* expression() const { return expression_; }
2309 void set_expression(Expression* e) { expression_ = e; } 2315 void set_expression(Expression* e) { expression_ = e; }
2310 2316
2311 int expression_position() const { return expr_pos_; } 2317 int expression_position() const { return expr_pos_; }
2312 2318
2313 static int num_ids() { return parent_num_ids(); } 2319 static int num_ids() { return parent_num_ids(); }
2314 2320
2315 protected: 2321 protected:
2316 Spread(Zone* zone, Expression* expression, int pos, int expr_pos) 2322 Spread(Zone* zone, Expression* expression, int pos, int expr_pos)
2317 : Expression(zone, pos), expression_(expression), expr_pos_(expr_pos) {} 2323 : Expression(zone, pos, kSpread),
2324 expression_(expression),
2325 expr_pos_(expr_pos) {}
2318 static int parent_num_ids() { return Expression::num_ids(); } 2326 static int parent_num_ids() { return Expression::num_ids(); }
2319 2327
2320 private: 2328 private:
2321 int local_id(int n) const { return base_id() + parent_num_ids() + n; } 2329 int local_id(int n) const { return base_id() + parent_num_ids() + n; }
2322 2330
2323 Expression* expression_; 2331 Expression* expression_;
2324 int expr_pos_; 2332 int expr_pos_;
2325 }; 2333 };
2326 2334
2327 2335
(...skipping 14 matching lines...) Expand all
2342 else_expression_->MarkTail(); 2350 else_expression_->MarkTail();
2343 } 2351 }
2344 2352
2345 static int num_ids() { return parent_num_ids() + 2; } 2353 static int num_ids() { return parent_num_ids() + 2; }
2346 BailoutId ThenId() const { return BailoutId(local_id(0)); } 2354 BailoutId ThenId() const { return BailoutId(local_id(0)); }
2347 BailoutId ElseId() const { return BailoutId(local_id(1)); } 2355 BailoutId ElseId() const { return BailoutId(local_id(1)); }
2348 2356
2349 protected: 2357 protected:
2350 Conditional(Zone* zone, Expression* condition, Expression* then_expression, 2358 Conditional(Zone* zone, Expression* condition, Expression* then_expression,
2351 Expression* else_expression, int position) 2359 Expression* else_expression, int position)
2352 : Expression(zone, position), 2360 : Expression(zone, position, kConditional),
2353 condition_(condition), 2361 condition_(condition),
2354 then_expression_(then_expression), 2362 then_expression_(then_expression),
2355 else_expression_(else_expression) {} 2363 else_expression_(else_expression) {}
2356 static int parent_num_ids() { return Expression::num_ids(); } 2364 static int parent_num_ids() { return Expression::num_ids(); }
2357 2365
2358 private: 2366 private:
2359 int local_id(int n) const { return base_id() + parent_num_ids() + n; } 2367 int local_id(int n) const { return base_id() + parent_num_ids() + n; }
2360 2368
2361 Expression* condition_; 2369 Expression* condition_;
2362 Expression* then_expression_; 2370 Expression* then_expression_;
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
2469 DCHECK_NOT_NULL(new_expression); 2477 DCHECK_NOT_NULL(new_expression);
2470 DCHECK(!new_expression->IsRewritableExpression()); 2478 DCHECK(!new_expression->IsRewritableExpression());
2471 expr_ = new_expression; 2479 expr_ = new_expression;
2472 is_rewritten_ = true; 2480 is_rewritten_ = true;
2473 } 2481 }
2474 2482
2475 static int num_ids() { return parent_num_ids(); } 2483 static int num_ids() { return parent_num_ids(); }
2476 2484
2477 protected: 2485 protected:
2478 RewritableExpression(Zone* zone, Expression* expression) 2486 RewritableExpression(Zone* zone, Expression* expression)
2479 : Expression(zone, expression->position()), 2487 : Expression(zone, expression->position(), kRewritableExpression),
2480 is_rewritten_(false), 2488 is_rewritten_(false),
2481 expr_(expression) { 2489 expr_(expression) {
2482 DCHECK(!expression->IsRewritableExpression()); 2490 DCHECK(!expression->IsRewritableExpression());
2483 } 2491 }
2484 2492
2485 private: 2493 private:
2486 int local_id(int n) const { return base_id() + parent_num_ids() + n; } 2494 int local_id(int n) const { return base_id() + parent_num_ids() + n; }
2487 2495
2488 bool is_rewritten_; 2496 bool is_rewritten_;
2489 Expression* expr_; 2497 Expression* expr_;
(...skipping 15 matching lines...) Expand all
2505 } 2513 }
2506 int yield_id() const { return yield_id_; } 2514 int yield_id() const { return yield_id_; }
2507 2515
2508 void set_generator_object(Expression* e) { generator_object_ = e; } 2516 void set_generator_object(Expression* e) { generator_object_ = e; }
2509 void set_expression(Expression* e) { expression_ = e; } 2517 void set_expression(Expression* e) { expression_ = e; }
2510 void set_yield_id(int yield_id) { yield_id_ = yield_id; } 2518 void set_yield_id(int yield_id) { yield_id_ = yield_id; }
2511 2519
2512 protected: 2520 protected:
2513 Yield(Zone* zone, Expression* generator_object, Expression* expression, 2521 Yield(Zone* zone, Expression* generator_object, Expression* expression,
2514 int pos, OnException on_exception) 2522 int pos, OnException on_exception)
2515 : Expression(zone, pos), 2523 : Expression(zone, pos, kYield),
2516 generator_object_(generator_object), 2524 generator_object_(generator_object),
2517 expression_(expression), 2525 expression_(expression),
2518 on_exception_(on_exception), 2526 on_exception_(on_exception),
2519 yield_id_(-1) {} 2527 yield_id_(-1) {}
2520 2528
2521 private: 2529 private:
2522 Expression* generator_object_; 2530 Expression* generator_object_;
2523 Expression* expression_; 2531 Expression* expression_;
2524 OnException on_exception_; 2532 OnException on_exception_;
2525 int yield_id_; 2533 int yield_id_;
2526 }; 2534 };
2527 2535
2528 2536
2529 class Throw final : public Expression { 2537 class Throw final : public Expression {
2530 public: 2538 public:
2531 DECLARE_NODE_TYPE(Throw) 2539 DECLARE_NODE_TYPE(Throw)
2532 2540
2533 Expression* exception() const { return exception_; } 2541 Expression* exception() const { return exception_; }
2534 void set_exception(Expression* e) { exception_ = e; } 2542 void set_exception(Expression* e) { exception_ = e; }
2535 2543
2536 protected: 2544 protected:
2537 Throw(Zone* zone, Expression* exception, int pos) 2545 Throw(Zone* zone, Expression* exception, int pos)
2538 : Expression(zone, pos), exception_(exception) {} 2546 : Expression(zone, pos, kThrow), exception_(exception) {}
2539 2547
2540 private: 2548 private:
2541 Expression* exception_; 2549 Expression* exception_;
2542 }; 2550 };
2543 2551
2544 2552
2545 class FunctionLiteral final : public Expression { 2553 class FunctionLiteral final : public Expression {
2546 public: 2554 public:
2547 enum FunctionType { 2555 enum FunctionType {
2548 kAnonymousExpression, 2556 kAnonymousExpression,
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
2677 2685
2678 protected: 2686 protected:
2679 FunctionLiteral(Zone* zone, const AstString* name, 2687 FunctionLiteral(Zone* zone, const AstString* name,
2680 AstValueFactory* ast_value_factory, Scope* scope, 2688 AstValueFactory* ast_value_factory, Scope* scope,
2681 ZoneList<Statement*>* body, int materialized_literal_count, 2689 ZoneList<Statement*>* body, int materialized_literal_count,
2682 int expected_property_count, int parameter_count, 2690 int expected_property_count, int parameter_count,
2683 FunctionType function_type, 2691 FunctionType function_type,
2684 ParameterFlag has_duplicate_parameters, 2692 ParameterFlag has_duplicate_parameters,
2685 EagerCompileHint eager_compile_hint, FunctionKind kind, 2693 EagerCompileHint eager_compile_hint, FunctionKind kind,
2686 int position, bool is_function) 2694 int position, bool is_function)
2687 : Expression(zone, position), 2695 : Expression(zone, position, kFunctionLiteral),
2688 raw_name_(name), 2696 raw_name_(name),
2689 scope_(scope), 2697 scope_(scope),
2690 body_(body), 2698 body_(body),
2691 raw_inferred_name_(ast_value_factory->empty_string()), 2699 raw_inferred_name_(ast_value_factory->empty_string()),
2692 ast_properties_(zone), 2700 ast_properties_(zone),
2693 dont_optimize_reason_(kNoReason), 2701 dont_optimize_reason_(kNoReason),
2694 materialized_literal_count_(materialized_literal_count), 2702 materialized_literal_count_(materialized_literal_count),
2695 expected_property_count_(expected_property_count), 2703 expected_property_count_(expected_property_count),
2696 parameter_count_(parameter_count), 2704 parameter_count_(parameter_count),
2697 function_token_position_(kNoSourcePosition), 2705 function_token_position_(kNoSourcePosition),
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
2779 2787
2780 bool IsAnonymousFunctionDefinition() const { 2788 bool IsAnonymousFunctionDefinition() const {
2781 return constructor()->raw_name()->length() == 0; 2789 return constructor()->raw_name()->length() == 0;
2782 } 2790 }
2783 2791
2784 protected: 2792 protected:
2785 ClassLiteral(Zone* zone, Scope* scope, VariableProxy* class_variable_proxy, 2793 ClassLiteral(Zone* zone, Scope* scope, VariableProxy* class_variable_proxy,
2786 Expression* extends, FunctionLiteral* constructor, 2794 Expression* extends, FunctionLiteral* constructor,
2787 ZoneList<Property*>* properties, int start_position, 2795 ZoneList<Property*>* properties, int start_position,
2788 int end_position) 2796 int end_position)
2789 : Expression(zone, start_position), 2797 : Expression(zone, start_position, kClassLiteral),
2790 scope_(scope), 2798 scope_(scope),
2791 class_variable_proxy_(class_variable_proxy), 2799 class_variable_proxy_(class_variable_proxy),
2792 extends_(extends), 2800 extends_(extends),
2793 constructor_(constructor), 2801 constructor_(constructor),
2794 properties_(properties), 2802 properties_(properties),
2795 end_position_(end_position) {} 2803 end_position_(end_position) {}
2796 2804
2797 static int parent_num_ids() { return Expression::num_ids(); } 2805 static int parent_num_ids() { return Expression::num_ids(); }
2798 2806
2799 private: 2807 private:
(...skipping 13 matching lines...) Expand all
2813 class NativeFunctionLiteral final : public Expression { 2821 class NativeFunctionLiteral final : public Expression {
2814 public: 2822 public:
2815 DECLARE_NODE_TYPE(NativeFunctionLiteral) 2823 DECLARE_NODE_TYPE(NativeFunctionLiteral)
2816 2824
2817 Handle<String> name() const { return name_->string(); } 2825 Handle<String> name() const { return name_->string(); }
2818 v8::Extension* extension() const { return extension_; } 2826 v8::Extension* extension() const { return extension_; }
2819 2827
2820 protected: 2828 protected:
2821 NativeFunctionLiteral(Zone* zone, const AstRawString* name, 2829 NativeFunctionLiteral(Zone* zone, const AstRawString* name,
2822 v8::Extension* extension, int pos) 2830 v8::Extension* extension, int pos)
2823 : Expression(zone, pos), name_(name), extension_(extension) {} 2831 : Expression(zone, pos, kNativeFunctionLiteral),
2832 name_(name),
2833 extension_(extension) {}
2824 2834
2825 private: 2835 private:
2826 const AstRawString* name_; 2836 const AstRawString* name_;
2827 v8::Extension* extension_; 2837 v8::Extension* extension_;
2828 }; 2838 };
2829 2839
2830 2840
2831 class ThisFunction final : public Expression { 2841 class ThisFunction final : public Expression {
2832 public: 2842 public:
2833 DECLARE_NODE_TYPE(ThisFunction) 2843 DECLARE_NODE_TYPE(ThisFunction)
2834 2844
2835 protected: 2845 protected:
2836 ThisFunction(Zone* zone, int pos) : Expression(zone, pos) {} 2846 ThisFunction(Zone* zone, int pos) : Expression(zone, pos, kThisFunction) {}
2837 }; 2847 };
2838 2848
2839 2849
2840 class SuperPropertyReference final : public Expression { 2850 class SuperPropertyReference final : public Expression {
2841 public: 2851 public:
2842 DECLARE_NODE_TYPE(SuperPropertyReference) 2852 DECLARE_NODE_TYPE(SuperPropertyReference)
2843 2853
2844 VariableProxy* this_var() const { return this_var_; } 2854 VariableProxy* this_var() const { return this_var_; }
2845 void set_this_var(VariableProxy* v) { this_var_ = v; } 2855 void set_this_var(VariableProxy* v) { this_var_ = v; }
2846 Expression* home_object() const { return home_object_; } 2856 Expression* home_object() const { return home_object_; }
2847 void set_home_object(Expression* e) { home_object_ = e; } 2857 void set_home_object(Expression* e) { home_object_ = e; }
2848 2858
2849 protected: 2859 protected:
2850 SuperPropertyReference(Zone* zone, VariableProxy* this_var, 2860 SuperPropertyReference(Zone* zone, VariableProxy* this_var,
2851 Expression* home_object, int pos) 2861 Expression* home_object, int pos)
2852 : Expression(zone, pos), this_var_(this_var), home_object_(home_object) { 2862 : Expression(zone, pos, kSuperPropertyReference),
2863 this_var_(this_var),
2864 home_object_(home_object) {
2853 DCHECK(this_var->is_this()); 2865 DCHECK(this_var->is_this());
2854 DCHECK(home_object->IsProperty()); 2866 DCHECK(home_object->IsProperty());
2855 } 2867 }
2856 2868
2857 private: 2869 private:
2858 VariableProxy* this_var_; 2870 VariableProxy* this_var_;
2859 Expression* home_object_; 2871 Expression* home_object_;
2860 }; 2872 };
2861 2873
2862 2874
2863 class SuperCallReference final : public Expression { 2875 class SuperCallReference final : public Expression {
2864 public: 2876 public:
2865 DECLARE_NODE_TYPE(SuperCallReference) 2877 DECLARE_NODE_TYPE(SuperCallReference)
2866 2878
2867 VariableProxy* this_var() const { return this_var_; } 2879 VariableProxy* this_var() const { return this_var_; }
2868 void set_this_var(VariableProxy* v) { this_var_ = v; } 2880 void set_this_var(VariableProxy* v) { this_var_ = v; }
2869 VariableProxy* new_target_var() const { return new_target_var_; } 2881 VariableProxy* new_target_var() const { return new_target_var_; }
2870 void set_new_target_var(VariableProxy* v) { new_target_var_ = v; } 2882 void set_new_target_var(VariableProxy* v) { new_target_var_ = v; }
2871 VariableProxy* this_function_var() const { return this_function_var_; } 2883 VariableProxy* this_function_var() const { return this_function_var_; }
2872 void set_this_function_var(VariableProxy* v) { this_function_var_ = v; } 2884 void set_this_function_var(VariableProxy* v) { this_function_var_ = v; }
2873 2885
2874 protected: 2886 protected:
2875 SuperCallReference(Zone* zone, VariableProxy* this_var, 2887 SuperCallReference(Zone* zone, VariableProxy* this_var,
2876 VariableProxy* new_target_var, 2888 VariableProxy* new_target_var,
2877 VariableProxy* this_function_var, int pos) 2889 VariableProxy* this_function_var, int pos)
2878 : Expression(zone, pos), 2890 : Expression(zone, pos, kSuperCallReference),
2879 this_var_(this_var), 2891 this_var_(this_var),
2880 new_target_var_(new_target_var), 2892 new_target_var_(new_target_var),
2881 this_function_var_(this_function_var) { 2893 this_function_var_(this_function_var) {
2882 DCHECK(this_var->is_this()); 2894 DCHECK(this_var->is_this());
2883 DCHECK(new_target_var->raw_name()->IsOneByteEqualTo(".new.target")); 2895 DCHECK(new_target_var->raw_name()->IsOneByteEqualTo(".new.target"));
2884 DCHECK(this_function_var->raw_name()->IsOneByteEqualTo(".this_function")); 2896 DCHECK(this_function_var->raw_name()->IsOneByteEqualTo(".this_function"));
2885 } 2897 }
2886 2898
2887 private: 2899 private:
2888 VariableProxy* this_var_; 2900 VariableProxy* this_var_;
2889 VariableProxy* new_target_var_; 2901 VariableProxy* new_target_var_;
2890 VariableProxy* this_function_var_; 2902 VariableProxy* this_function_var_;
2891 }; 2903 };
2892 2904
2893 2905
2894 // This class is produced when parsing the () in arrow functions without any 2906 // This class is produced when parsing the () in arrow functions without any
2895 // arguments and is not actually a valid expression. 2907 // arguments and is not actually a valid expression.
2896 class EmptyParentheses final : public Expression { 2908 class EmptyParentheses final : public Expression {
2897 public: 2909 public:
2898 DECLARE_NODE_TYPE(EmptyParentheses) 2910 DECLARE_NODE_TYPE(EmptyParentheses)
2899 2911
2900 private: 2912 private:
2901 EmptyParentheses(Zone* zone, int pos) : Expression(zone, pos) {} 2913 EmptyParentheses(Zone* zone, int pos)
2914 : Expression(zone, pos, kEmptyParentheses) {}
2902 }; 2915 };
2903 2916
2904 2917
2905 #undef DECLARE_NODE_TYPE 2918 #undef DECLARE_NODE_TYPE
2906 2919
2907 2920
2908 // ---------------------------------------------------------------------------- 2921 // ----------------------------------------------------------------------------
2909 // Basic visitor 2922 // Basic visitor
2910 // - leaf node visitors are abstract. 2923 // Sub-class should parametrize AstVisitor with itself, e.g.:
2924 // class SpecificVisitor : public AstVisitor<SpecificVisitor> { ... }
2911 2925
2926 template <class Subclass>
2912 class AstVisitor BASE_EMBEDDED { 2927 class AstVisitor BASE_EMBEDDED {
2913 public: 2928 public:
2914 AstVisitor() {} 2929 void Visit(AstNode* node) { This()->Visit(node); }
2915 virtual ~AstVisitor() {}
2916 2930
2917 // Stack overflow check and dynamic dispatch. 2931 void VisitDeclarations(ZoneList<Declaration*>* declarations) {
2918 virtual void Visit(AstNode* node) = 0; 2932 for (int i = 0; i < declarations->length(); i++) {
2933 Visit(declarations->at(i));
2934 }
2935 }
2919 2936
2920 // Iteration left-to-right. 2937 void VisitStatements(ZoneList<Statement*>* statements) {
2921 virtual void VisitDeclarations(ZoneList<Declaration*>* declarations); 2938 for (int i = 0; i < statements->length(); i++) {
2922 virtual void VisitStatements(ZoneList<Statement*>* statements); 2939 Statement* stmt = statements->at(i);
2923 virtual void VisitExpressions(ZoneList<Expression*>* expressions); 2940 Visit(stmt);
2941 if (stmt->IsJump()) break;
2942 }
2943 }
2924 2944
2925 // Individual AST nodes. 2945 void VisitExpressions(ZoneList<Expression*>* expressions) {
2926 #define DEF_VISIT(type) \ 2946 for (int i = 0; i < expressions->length(); i++) {
2927 virtual void Visit##type(type* node) = 0; 2947 // The variable statement visiting code may pass NULL expressions
2928 AST_NODE_LIST(DEF_VISIT) 2948 // to this code. Maybe this should be handled by introducing an
2929 #undef DEF_VISIT 2949 // undefined expression or literal? Revisit this code if this
2950 // changes
2951 Expression* expression = expressions->at(i);
2952 if (expression != NULL) Visit(expression);
2953 }
2954 }
2955
2956 private:
2957 Subclass* This() { return static_cast<Subclass*>(this); }
2930 }; 2958 };
2931 2959
2960 #define GENERATE_VISIT_CASE(NodeType) \
2961 case AstNode::k##NodeType: \
2962 return Visit##NodeType(static_cast<NodeType*>(node));
2963
2964 #define GENERATE_AST_VISITOR_SWITCH() \
2965 switch (node->node_type()) { \
2966 AST_NODE_LIST(GENERATE_VISIT_CASE) \
2967 case AstNode::kModule: \
2968 UNREACHABLE(); \
2969 }
2970
2932 #define DEFINE_AST_VISITOR_SUBCLASS_MEMBERS() \ 2971 #define DEFINE_AST_VISITOR_SUBCLASS_MEMBERS() \
2933 public: \ 2972 public: \
2934 void Visit(AstNode* node) final { \ 2973 void Visit(AstNode* node) { \
2935 if (!CheckStackOverflow()) node->Accept(this); \ 2974 if (CheckStackOverflow()) return; \
2975 GENERATE_AST_VISITOR_SWITCH() \
2936 } \ 2976 } \
2937 \ 2977 \
2938 void SetStackOverflow() { stack_overflow_ = true; } \ 2978 void SetStackOverflow() { stack_overflow_ = true; } \
2939 void ClearStackOverflow() { stack_overflow_ = false; } \ 2979 void ClearStackOverflow() { stack_overflow_ = false; } \
2940 bool HasStackOverflow() const { return stack_overflow_; } \ 2980 bool HasStackOverflow() const { return stack_overflow_; } \
2941 \ 2981 \
2942 bool CheckStackOverflow() { \ 2982 bool CheckStackOverflow() { \
2943 if (stack_overflow_) return true; \ 2983 if (stack_overflow_) return true; \
2944 if (GetCurrentStackPosition() < stack_limit_) { \ 2984 if (GetCurrentStackPosition() < stack_limit_) { \
2945 stack_overflow_ = true; \ 2985 stack_overflow_ = true; \
2946 return true; \ 2986 return true; \
2947 } \ 2987 } \
2948 return false; \ 2988 return false; \
2949 } \ 2989 } \
2950 \ 2990 \
2951 private: \ 2991 private: \
2952 void InitializeAstVisitor(Isolate* isolate) { \ 2992 void InitializeAstVisitor(Isolate* isolate) { \
2953 stack_limit_ = isolate->stack_guard()->real_climit(); \ 2993 stack_limit_ = isolate->stack_guard()->real_climit(); \
2954 stack_overflow_ = false; \ 2994 stack_overflow_ = false; \
2955 } \ 2995 } \
2956 \ 2996 \
2957 void InitializeAstVisitor(uintptr_t stack_limit) { \ 2997 void InitializeAstVisitor(uintptr_t stack_limit) { \
2958 stack_limit_ = stack_limit; \ 2998 stack_limit_ = stack_limit; \
2959 stack_overflow_ = false; \ 2999 stack_overflow_ = false; \
2960 } \ 3000 } \
2961 \ 3001 \
2962 uintptr_t stack_limit_; \ 3002 uintptr_t stack_limit_; \
2963 bool stack_overflow_ 3003 bool stack_overflow_
2964 3004
3005 #define DEFINE_AST_VISITOR_MEMBERS_WITHOUT_STACKOVERFLOW() \
3006 public: \
3007 void Visit(AstNode* node) { GENERATE_AST_VISITOR_SWITCH() } \
3008 \
3009 private:
3010
2965 #define DEFINE_AST_REWRITER_SUBCLASS_MEMBERS() \ 3011 #define DEFINE_AST_REWRITER_SUBCLASS_MEMBERS() \
2966 public: \ 3012 public: \
2967 AstNode* Rewrite(AstNode* node) { \ 3013 AstNode* Rewrite(AstNode* node) { \
2968 DCHECK_NULL(replacement_); \ 3014 DCHECK_NULL(replacement_); \
2969 DCHECK_NOT_NULL(node); \ 3015 DCHECK_NOT_NULL(node); \
2970 Visit(node); \ 3016 Visit(node); \
2971 if (HasStackOverflow()) return node; \ 3017 if (HasStackOverflow()) return node; \
2972 if (replacement_ == nullptr) return node; \ 3018 if (replacement_ == nullptr) return node; \
2973 AstNode* result = replacement_; \ 3019 AstNode* result = replacement_; \
2974 replacement_ = nullptr; \ 3020 replacement_ = nullptr; \
2975 return result; \ 3021 return result; \
2976 } \ 3022 } \
2977 \ 3023 \
2978 private: \ 3024 private: \
2979 void InitializeAstRewriter(Isolate* isolate) { \ 3025 void InitializeAstRewriter(Isolate* isolate) { \
2980 InitializeAstVisitor(isolate); \ 3026 InitializeAstVisitor(isolate); \
2981 replacement_ = nullptr; \ 3027 replacement_ = nullptr; \
2982 } \ 3028 } \
2983 \ 3029 \
2984 void InitializeAstRewriter(uintptr_t stack_limit) { \ 3030 void InitializeAstRewriter(uintptr_t stack_limit) { \
2985 InitializeAstVisitor(stack_limit); \ 3031 InitializeAstVisitor(stack_limit); \
2986 replacement_ = nullptr; \ 3032 replacement_ = nullptr; \
2987 } \ 3033 } \
2988 \ 3034 \
2989 DEFINE_AST_VISITOR_SUBCLASS_MEMBERS(); \ 3035 DEFINE_AST_VISITOR_SUBCLASS_MEMBERS(); \
2990 \ 3036 \
2991 protected: \ 3037 protected: \
2992 AstNode* replacement_ 3038 AstNode* replacement_
2993
2994 // Generic macro for rewriting things; `GET` is the expression to be 3039 // Generic macro for rewriting things; `GET` is the expression to be
2995 // rewritten; `SET` is a command that should do the rewriting, i.e. 3040 // rewritten; `SET` is a command that should do the rewriting, i.e.
2996 // something sensible with the variable called `replacement`. 3041 // something sensible with the variable called `replacement`.
2997 #define AST_REWRITE(Type, GET, SET) \ 3042 #define AST_REWRITE(Type, GET, SET) \
2998 do { \ 3043 do { \
2999 DCHECK(!HasStackOverflow()); \ 3044 DCHECK(!HasStackOverflow()); \
3000 DCHECK_NULL(replacement_); \ 3045 DCHECK_NULL(replacement_); \
3001 Visit(GET); \ 3046 Visit(GET); \
3002 if (HasStackOverflow()) return; \ 3047 if (HasStackOverflow()) return; \
3003 if (replacement_ == nullptr) break; \ 3048 if (replacement_ == nullptr) break; \
(...skipping 19 matching lines...) Expand all
3023 auto _list = (list); \ 3068 auto _list = (list); \
3024 auto _index = (index); \ 3069 auto _index = (index); \
3025 AST_REWRITE(Type, _list->at(_index), _list->Set(_index, replacement)); \ 3070 AST_REWRITE(Type, _list->at(_index), _list->Set(_index, replacement)); \
3026 } while (false) 3071 } while (false)
3027 3072
3028 3073
3029 // ---------------------------------------------------------------------------- 3074 // ----------------------------------------------------------------------------
3030 // Traversing visitor 3075 // Traversing visitor
3031 // - fully traverses the entire AST. 3076 // - fully traverses the entire AST.
3032 3077
3033 class AstTraversalVisitor : public AstVisitor { 3078 // This AstVistor is not final, and provides the AstVisitor methods as virtual
3079 // methods so they can be specialized by subclasses.
3080 class AstTraversalVisitor : public AstVisitor<AstTraversalVisitor> {
3034 public: 3081 public:
3035 explicit AstTraversalVisitor(Isolate* isolate); 3082 explicit AstTraversalVisitor(Isolate* isolate);
3036 explicit AstTraversalVisitor(uintptr_t stack_limit); 3083 explicit AstTraversalVisitor(uintptr_t stack_limit);
3037 virtual ~AstTraversalVisitor() {} 3084 virtual ~AstTraversalVisitor() {}
3038 3085
3039 // Iteration left-to-right. 3086 // Iteration left-to-right.
3040 void VisitDeclarations(ZoneList<Declaration*>* declarations) override; 3087 void VisitDeclarations(ZoneList<Declaration*>* declarations);
3041 void VisitStatements(ZoneList<Statement*>* statements) override; 3088 void VisitStatements(ZoneList<Statement*>* statements);
3042 3089
3043 // Individual nodes 3090 // Individual nodes
3044 #define DECLARE_VISIT(type) void Visit##type(type* node) override; 3091 #define DECLARE_VISIT(type) virtual void Visit##type(type* node);
3045 AST_NODE_LIST(DECLARE_VISIT) 3092 AST_NODE_LIST(DECLARE_VISIT)
3046 #undef DECLARE_VISIT 3093 #undef DECLARE_VISIT
3047 3094
3048 protected: 3095 protected:
3049 int depth() { return depth_; } 3096 int depth() { return depth_; }
3050 3097
3051 private: 3098 private:
3052 DEFINE_AST_VISITOR_SUBCLASS_MEMBERS(); 3099 DEFINE_AST_VISITOR_SUBCLASS_MEMBERS();
3053 3100
3054 int depth_; 3101 int depth_;
(...skipping 491 matching lines...) Expand 10 before | Expand all | Expand 10 after
3546 : NULL; \ 3593 : NULL; \
3547 } 3594 }
3548 AST_NODE_LIST(DECLARE_NODE_FUNCTIONS) 3595 AST_NODE_LIST(DECLARE_NODE_FUNCTIONS)
3549 #undef DECLARE_NODE_FUNCTIONS 3596 #undef DECLARE_NODE_FUNCTIONS
3550 3597
3551 3598
3552 } // namespace internal 3599 } // namespace internal
3553 } // namespace v8 3600 } // namespace v8
3554 3601
3555 #endif // V8_AST_AST_H_ 3602 #endif // V8_AST_AST_H_
OLDNEW
« no previous file with comments | « src/asmjs/asm-wasm-builder.cc ('k') | src/ast/ast.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698