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

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: 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
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 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 V(DoExpression) \ 101 V(DoExpression) \
102 V(RewritableExpression) 102 V(RewritableExpression)
103 103
104 #define AST_NODE_LIST(V) \ 104 #define AST_NODE_LIST(V) \
105 DECLARATION_NODE_LIST(V) \ 105 DECLARATION_NODE_LIST(V) \
106 STATEMENT_NODE_LIST(V) \ 106 STATEMENT_NODE_LIST(V) \
107 EXPRESSION_NODE_LIST(V) 107 EXPRESSION_NODE_LIST(V)
108 108
109 // Forward declarations 109 // Forward declarations
110 class AstNodeFactory; 110 class AstNodeFactory;
111 class AstVisitor;
112 class Declaration; 111 class Declaration;
113 class Module; 112 class Module;
114 class BreakableStatement; 113 class BreakableStatement;
115 class Expression; 114 class Expression;
116 class IterationStatement; 115 class IterationStatement;
117 class MaterializedLiteral; 116 class MaterializedLiteral;
118 class Statement; 117 class Statement;
119 class TypeFeedbackOracle; 118 class TypeFeedbackOracle;
120 119
121 #define DEF_FORWARD_DECLARATION(type) class type; 120 #define DEF_FORWARD_DECLARATION(type) class type;
122 AST_NODE_LIST(DEF_FORWARD_DECLARATION) 121 AST_NODE_LIST(DEF_FORWARD_DECLARATION)
123 #undef DEF_FORWARD_DECLARATION 122 #undef DEF_FORWARD_DECLARATION
124 123
125 124
126 // Typedef only introduced to avoid unreadable code. 125 // Typedef only introduced to avoid unreadable code.
127 typedef ZoneList<Handle<String>> ZoneStringList; 126 typedef ZoneList<Handle<String>> ZoneStringList;
128 typedef ZoneList<Handle<Object>> ZoneObjectList; 127 typedef ZoneList<Handle<Object>> ZoneObjectList;
129 128
130 129
131 #define DECLARE_NODE_TYPE(type) \ 130 #define DECLARE_NODE_TYPE(type) \
Igor Sheludko 2016/07/14 16:39:54 As an idea for a next CL: This macro does not make
Toon Verwaest 2016/07/15 07:07:19 Acknowledged.
132 void Accept(AstVisitor* v) override; \
133 AstNode::NodeType node_type() const final { return AstNode::k##type; } \
134 friend class AstNodeFactory; 131 friend class AstNodeFactory;
135 132
136 133
137 class FeedbackVectorSlotCache { 134 class FeedbackVectorSlotCache {
138 public: 135 public:
139 explicit FeedbackVectorSlotCache(Zone* zone) 136 explicit FeedbackVectorSlotCache(Zone* zone)
140 : zone_(zone), 137 : zone_(zone),
141 hash_map_(base::HashMap::PointersMatch, 138 hash_map_(base::HashMap::PointersMatch,
142 ZoneHashMap::kDefaultHashMapCapacity, 139 ZoneHashMap::kDefaultHashMapCapacity,
143 ZoneAllocationPolicy(zone)) {} 140 ZoneAllocationPolicy(zone)) {}
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
183 int node_count_; 180 int node_count_;
184 FeedbackVectorSpec spec_; 181 FeedbackVectorSpec spec_;
185 }; 182 };
186 183
187 DEFINE_OPERATORS_FOR_FLAGS(AstProperties::Flags) 184 DEFINE_OPERATORS_FOR_FLAGS(AstProperties::Flags)
188 185
189 186
190 class AstNode: public ZoneObject { 187 class AstNode: public ZoneObject {
191 public: 188 public:
192 #define DECLARE_TYPE_ENUM(type) k##type, 189 #define DECLARE_TYPE_ENUM(type) k##type,
193 enum NodeType { 190 enum NodeType : uint8_t { kModule = 0, AST_NODE_LIST(DECLARE_TYPE_ENUM) };
vogelheim 2016/07/14 11:27:35 This is super weird: If Module is an AST node, sho
Toon Verwaest 2016/07/15 07:07:19 I agree, but it's a little involved. This should b
194 AST_NODE_LIST(DECLARE_TYPE_ENUM)
195 kInvalid = -1
196 };
197 #undef DECLARE_TYPE_ENUM 191 #undef DECLARE_TYPE_ENUM
198 192
199 void* operator new(size_t size, Zone* zone) { return zone->New(size); } 193 void* operator new(size_t size, Zone* zone) { return zone->New(size); }
200 194
201 explicit AstNode(int position): position_(position) {} 195 explicit AstNode(int position, NodeType type)
vogelheim 2016/07/14 11:27:35 nitpick: drop explicit (not needed w/ 2 args) [He
vogelheim 2016/07/14 11:27:35 more nitpick: This used to be an abstract class, s
Toon Verwaest 2016/07/15 07:07:19 Done.
202 virtual ~AstNode() {} 196 : position_(position), node_type_(type) {}
203 197
204 virtual void Accept(AstVisitor* v) = 0; 198 NodeType node_type() const { return node_type_; }
205 virtual NodeType node_type() const = 0;
206 int position() const { return position_; } 199 int position() const { return position_; }
207 200
208 #ifdef DEBUG 201 #ifdef DEBUG
209 void PrettyPrint(Isolate* isolate); 202 void PrettyPrint(Isolate* isolate);
210 void Print(Isolate* isolate); 203 void Print(Isolate* isolate);
211 #endif // DEBUG 204 #endif // DEBUG
212 205
213 // Type testing & conversion functions overridden by concrete subclasses. 206 // Type testing & conversion functions overridden by concrete subclasses.
214 #define DECLARE_NODE_FUNCTIONS(type) \ 207 #define DECLARE_NODE_FUNCTIONS(type) \
215 V8_INLINE bool Is##type() const; \ 208 V8_INLINE bool Is##type() const; \
216 V8_INLINE type* As##type(); \ 209 V8_INLINE type* As##type(); \
217 V8_INLINE const type* As##type() const; 210 V8_INLINE const type* As##type() const;
218 AST_NODE_LIST(DECLARE_NODE_FUNCTIONS) 211 AST_NODE_LIST(DECLARE_NODE_FUNCTIONS)
219 #undef DECLARE_NODE_FUNCTIONS 212 #undef DECLARE_NODE_FUNCTIONS
220 213
221 BreakableStatement* AsBreakableStatement(); 214 BreakableStatement* AsBreakableStatement();
222 IterationStatement* AsIterationStatement(); 215 IterationStatement* AsIterationStatement();
223 MaterializedLiteral* AsMaterializedLiteral(); 216 MaterializedLiteral* AsMaterializedLiteral();
224 217
225 private: 218 private:
226 // Hidden to prevent accidental usage. It would have to load the 219 // Hidden to prevent accidental usage. It would have to load the
227 // current zone from the TLS. 220 // current zone from the TLS.
228 void* operator new(size_t size); 221 void* operator new(size_t size);
229 222
230 friend class CaseClause; // Generates AST IDs. 223 friend class CaseClause; // Generates AST IDs.
231 224
232 int position_; 225 int position_;
226 NodeType node_type_;
233 }; 227 };
234 228
235 229
236 class Statement : public AstNode { 230 class Statement : public AstNode {
237 public: 231 public:
238 explicit Statement(Zone* zone, int position) : AstNode(position) {} 232 explicit Statement(Zone* zone, int position, NodeType type)
233 : AstNode(position, type) {}
239 234
240 bool IsEmpty() { return AsEmptyStatement() != NULL; } 235 bool IsEmpty() { return AsEmptyStatement() != NULL; }
241 bool IsJump() const; 236 bool IsJump() const;
242 }; 237 };
243 238
244 239
245 class SmallMapList final { 240 class SmallMapList final {
246 public: 241 public:
247 SmallMapList() {} 242 SmallMapList() {}
248 SmallMapList(int capacity, Zone* zone) : list_(capacity, zone) {} 243 SmallMapList(int capacity, Zone* zone) : list_(capacity, zone) {}
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
343 uint16_t to_boolean_types() const { 338 uint16_t to_boolean_types() const {
344 return ToBooleanTypesField::decode(bit_field_); 339 return ToBooleanTypesField::decode(bit_field_);
345 } 340 }
346 341
347 void set_base_id(int id) { base_id_ = id; } 342 void set_base_id(int id) { base_id_ = id; }
348 static int num_ids() { return parent_num_ids() + 2; } 343 static int num_ids() { return parent_num_ids() + 2; }
349 BailoutId id() const { return BailoutId(local_id(0)); } 344 BailoutId id() const { return BailoutId(local_id(0)); }
350 TypeFeedbackId test_id() const { return TypeFeedbackId(local_id(1)); } 345 TypeFeedbackId test_id() const { return TypeFeedbackId(local_id(1)); }
351 346
352 protected: 347 protected:
353 Expression(Zone* zone, int pos) 348 Expression(Zone* zone, int pos, NodeType type)
354 : AstNode(pos), 349 : AstNode(pos, type),
355 base_id_(BailoutId::None().ToInt()), 350 base_id_(BailoutId::None().ToInt()),
356 bit_field_(0) {} 351 bit_field_(0) {}
357 static int parent_num_ids() { return 0; } 352 static int parent_num_ids() { return 0; }
358 void set_to_boolean_types(uint16_t types) { 353 void set_to_boolean_types(uint16_t types) {
359 bit_field_ = ToBooleanTypesField::update(bit_field_, types); 354 bit_field_ = ToBooleanTypesField::update(bit_field_, types);
360 } 355 }
361 356
362 int base_id() const { 357 int base_id() const {
363 DCHECK(!BailoutId(base_id_).IsNone()); 358 DCHECK(!BailoutId(base_id_).IsNone());
364 return base_id_; 359 return base_id_;
(...skipping 29 matching lines...) Expand all
394 return breakable_type_ == TARGET_FOR_ANONYMOUS; 389 return breakable_type_ == TARGET_FOR_ANONYMOUS;
395 } 390 }
396 391
397 void set_base_id(int id) { base_id_ = id; } 392 void set_base_id(int id) { base_id_ = id; }
398 static int num_ids() { return parent_num_ids() + 2; } 393 static int num_ids() { return parent_num_ids() + 2; }
399 BailoutId EntryId() const { return BailoutId(local_id(0)); } 394 BailoutId EntryId() const { return BailoutId(local_id(0)); }
400 BailoutId ExitId() const { return BailoutId(local_id(1)); } 395 BailoutId ExitId() const { return BailoutId(local_id(1)); }
401 396
402 protected: 397 protected:
403 BreakableStatement(Zone* zone, ZoneList<const AstRawString*>* labels, 398 BreakableStatement(Zone* zone, ZoneList<const AstRawString*>* labels,
404 BreakableType breakable_type, int position) 399 BreakableType breakable_type, int position, NodeType type)
405 : Statement(zone, position), 400 : Statement(zone, position, type),
406 labels_(labels), 401 labels_(labels),
407 breakable_type_(breakable_type), 402 breakable_type_(breakable_type),
408 base_id_(BailoutId::None().ToInt()) { 403 base_id_(BailoutId::None().ToInt()) {
409 DCHECK(labels == NULL || labels->length() > 0); 404 DCHECK(labels == NULL || labels->length() > 0);
410 } 405 }
411 static int parent_num_ids() { return 0; } 406 static int parent_num_ids() { return 0; }
412 407
413 int base_id() const { 408 int base_id() const {
414 DCHECK(!BailoutId(base_id_).IsNone()); 409 DCHECK(!BailoutId(base_id_).IsNone());
415 return base_id_; 410 return base_id_;
(...skipping 23 matching lines...) Expand all
439 return !statements_.is_empty() && statements_.last()->IsJump() 434 return !statements_.is_empty() && statements_.last()->IsJump()
440 && labels() == NULL; // Good enough as an approximation... 435 && labels() == NULL; // Good enough as an approximation...
441 } 436 }
442 437
443 Scope* scope() const { return scope_; } 438 Scope* scope() const { return scope_; }
444 void set_scope(Scope* scope) { scope_ = scope; } 439 void set_scope(Scope* scope) { scope_ = scope; }
445 440
446 protected: 441 protected:
447 Block(Zone* zone, ZoneList<const AstRawString*>* labels, int capacity, 442 Block(Zone* zone, ZoneList<const AstRawString*>* labels, int capacity,
448 bool ignore_completion_value, int pos) 443 bool ignore_completion_value, int pos)
449 : BreakableStatement(zone, labels, TARGET_FOR_NAMED_ONLY, pos), 444 : BreakableStatement(zone, labels, TARGET_FOR_NAMED_ONLY, pos, kBlock),
450 statements_(capacity, zone), 445 statements_(capacity, zone),
451 ignore_completion_value_(ignore_completion_value), 446 ignore_completion_value_(ignore_completion_value),
452 scope_(NULL) {} 447 scope_(NULL) {}
453 static int parent_num_ids() { return BreakableStatement::num_ids(); } 448 static int parent_num_ids() { return BreakableStatement::num_ids(); }
454 449
455 private: 450 private:
456 int local_id(int n) const { return base_id() + parent_num_ids() + n; } 451 int local_id(int n) const { return base_id() + parent_num_ids() + n; }
457 452
458 ZoneList<Statement*> statements_; 453 ZoneList<Statement*> statements_;
459 bool ignore_completion_value_; 454 bool ignore_completion_value_;
460 Scope* scope_; 455 Scope* scope_;
461 }; 456 };
462 457
463 458
464 class DoExpression final : public Expression { 459 class DoExpression final : public Expression {
465 public: 460 public:
466 DECLARE_NODE_TYPE(DoExpression) 461 DECLARE_NODE_TYPE(DoExpression)
467 462
468 Block* block() { return block_; } 463 Block* block() { return block_; }
469 void set_block(Block* b) { block_ = b; } 464 void set_block(Block* b) { block_ = b; }
470 VariableProxy* result() { return result_; } 465 VariableProxy* result() { return result_; }
471 void set_result(VariableProxy* v) { result_ = v; } 466 void set_result(VariableProxy* v) { result_ = v; }
472 467
473 protected: 468 protected:
474 DoExpression(Zone* zone, Block* block, VariableProxy* result, int pos) 469 DoExpression(Zone* zone, Block* block, VariableProxy* result, int pos)
475 : Expression(zone, pos), block_(block), result_(result) { 470 : Expression(zone, pos, kDoExpression), block_(block), result_(result) {
476 DCHECK_NOT_NULL(block_); 471 DCHECK_NOT_NULL(block_);
477 DCHECK_NOT_NULL(result_); 472 DCHECK_NOT_NULL(result_);
478 } 473 }
479 static int parent_num_ids() { return Expression::num_ids(); } 474 static int parent_num_ids() { return Expression::num_ids(); }
480 475
481 private: 476 private:
482 int local_id(int n) const { return base_id() + parent_num_ids() + n; } 477 int local_id(int n) const { return base_id() + parent_num_ids() + n; }
483 478
484 Block* block_; 479 Block* block_;
485 VariableProxy* result_; 480 VariableProxy* result_;
486 }; 481 };
487 482
488 483
489 class Declaration : public AstNode { 484 class Declaration : public AstNode {
490 public: 485 public:
491 VariableProxy* proxy() const { return proxy_; } 486 VariableProxy* proxy() const { return proxy_; }
492 VariableMode mode() const { return mode_; } 487 VariableMode mode() const { return mode_; }
493 Scope* scope() const { return scope_; } 488 Scope* scope() const { return scope_; }
494 InitializationFlag initialization() const; 489 InitializationFlag initialization() const;
495 490
496 protected: 491 protected:
497 Declaration(Zone* zone, VariableProxy* proxy, VariableMode mode, Scope* scope, 492 Declaration(Zone* zone, VariableProxy* proxy, VariableMode mode, Scope* scope,
498 int pos) 493 int pos, NodeType type)
499 : AstNode(pos), mode_(mode), proxy_(proxy), scope_(scope) { 494 : AstNode(pos, type), mode_(mode), proxy_(proxy), scope_(scope) {
500 DCHECK(IsDeclaredVariableMode(mode)); 495 DCHECK(IsDeclaredVariableMode(mode));
501 } 496 }
502 497
503 private: 498 private:
504 VariableMode mode_; 499 VariableMode mode_;
505 VariableProxy* proxy_; 500 VariableProxy* proxy_;
506 501
507 // Nested scope from which the declaration originated. 502 // Nested scope from which the declaration originated.
508 Scope* scope_; 503 Scope* scope_;
509 }; 504 };
510 505
511 506
512 class VariableDeclaration final : public Declaration { 507 class VariableDeclaration final : public Declaration {
513 public: 508 public:
514 DECLARE_NODE_TYPE(VariableDeclaration) 509 DECLARE_NODE_TYPE(VariableDeclaration)
515 510
516 InitializationFlag initialization() const { 511 InitializationFlag initialization() const {
517 return mode() == VAR ? kCreatedInitialized : kNeedsInitialization; 512 return mode() == VAR ? kCreatedInitialized : kNeedsInitialization;
518 } 513 }
519 514
520 protected: 515 protected:
521 VariableDeclaration(Zone* zone, VariableProxy* proxy, VariableMode mode, 516 VariableDeclaration(Zone* zone, VariableProxy* proxy, VariableMode mode,
522 Scope* scope, int pos) 517 Scope* scope, int pos)
523 : Declaration(zone, proxy, mode, scope, pos) {} 518 : Declaration(zone, proxy, mode, scope, pos, kVariableDeclaration) {}
524 }; 519 };
525 520
526 521
527 class FunctionDeclaration final : public Declaration { 522 class FunctionDeclaration final : public Declaration {
528 public: 523 public:
529 DECLARE_NODE_TYPE(FunctionDeclaration) 524 DECLARE_NODE_TYPE(FunctionDeclaration)
530 525
531 FunctionLiteral* fun() const { return fun_; } 526 FunctionLiteral* fun() const { return fun_; }
532 void set_fun(FunctionLiteral* f) { fun_ = f; } 527 void set_fun(FunctionLiteral* f) { fun_ = f; }
533 InitializationFlag initialization() const { return kCreatedInitialized; } 528 InitializationFlag initialization() const { return kCreatedInitialized; }
534 529
535 protected: 530 protected:
536 FunctionDeclaration(Zone* zone, 531 FunctionDeclaration(Zone* zone, VariableProxy* proxy, VariableMode mode,
537 VariableProxy* proxy, 532 FunctionLiteral* fun, Scope* scope, int pos)
538 VariableMode mode, 533 : Declaration(zone, proxy, mode, scope, pos, kFunctionDeclaration),
539 FunctionLiteral* fun,
540 Scope* scope,
541 int pos)
542 : Declaration(zone, proxy, mode, scope, pos),
543 fun_(fun) { 534 fun_(fun) {
544 DCHECK(mode == VAR || mode == LET || mode == CONST); 535 DCHECK(mode == VAR || mode == LET || mode == CONST);
545 DCHECK(fun != NULL); 536 DCHECK(fun != NULL);
546 } 537 }
547 538
548 private: 539 private:
549 FunctionLiteral* fun_; 540 FunctionLiteral* fun_;
550 }; 541 };
551 542
552 543
553 class ImportDeclaration final : public Declaration { 544 class ImportDeclaration final : public Declaration {
554 public: 545 public:
555 DECLARE_NODE_TYPE(ImportDeclaration) 546 DECLARE_NODE_TYPE(ImportDeclaration)
556 547
557 const AstRawString* import_name() const { return import_name_; } 548 const AstRawString* import_name() const { return import_name_; }
558 const AstRawString* module_specifier() const { return module_specifier_; } 549 const AstRawString* module_specifier() const { return module_specifier_; }
559 void set_module_specifier(const AstRawString* module_specifier) { 550 void set_module_specifier(const AstRawString* module_specifier) {
560 DCHECK(module_specifier_ == NULL); 551 DCHECK(module_specifier_ == NULL);
561 module_specifier_ = module_specifier; 552 module_specifier_ = module_specifier;
562 } 553 }
563 InitializationFlag initialization() const { return kNeedsInitialization; } 554 InitializationFlag initialization() const { return kNeedsInitialization; }
564 555
565 protected: 556 protected:
566 ImportDeclaration(Zone* zone, VariableProxy* proxy, 557 ImportDeclaration(Zone* zone, VariableProxy* proxy,
567 const AstRawString* import_name, 558 const AstRawString* import_name,
568 const AstRawString* module_specifier, Scope* scope, int pos) 559 const AstRawString* module_specifier, Scope* scope, int pos)
569 : Declaration(zone, proxy, CONST, scope, pos), 560 : Declaration(zone, proxy, CONST, scope, pos, kImportDeclaration),
570 import_name_(import_name), 561 import_name_(import_name),
571 module_specifier_(module_specifier) {} 562 module_specifier_(module_specifier) {}
572 563
573 private: 564 private:
574 const AstRawString* import_name_; 565 const AstRawString* import_name_;
575 const AstRawString* module_specifier_; 566 const AstRawString* module_specifier_;
576 }; 567 };
577 568
578 569 class Module final : public AstNode {
579 class Module : public AstNode {
580 public: 570 public:
581 ModuleDescriptor* descriptor() const { return descriptor_; } 571 ModuleDescriptor* descriptor() const { return descriptor_; }
582 Block* body() const { return body_; } 572 Block* body() const { return body_; }
583 573
584 protected: 574 protected:
585 Module(Zone* zone, int pos) 575 Module(Zone* zone, int pos)
586 : AstNode(pos), descriptor_(ModuleDescriptor::New(zone)), body_(NULL) {} 576 : AstNode(pos, kModule),
577 descriptor_(ModuleDescriptor::New(zone)),
578 body_(NULL) {}
587 Module(Zone* zone, ModuleDescriptor* descriptor, int pos, Block* body = NULL) 579 Module(Zone* zone, ModuleDescriptor* descriptor, int pos, Block* body = NULL)
588 : AstNode(pos), descriptor_(descriptor), body_(body) {} 580 : AstNode(pos, kModule), descriptor_(descriptor), body_(body) {}
589 581
590 private: 582 private:
591 ModuleDescriptor* descriptor_; 583 ModuleDescriptor* descriptor_;
592 Block* body_; 584 Block* body_;
593 }; 585 };
594 586
595 587
596 class IterationStatement : public BreakableStatement { 588 class IterationStatement : public BreakableStatement {
597 public: 589 public:
598 Statement* body() const { return body_; } 590 Statement* body() const { return body_; }
599 void set_body(Statement* s) { body_ = s; } 591 void set_body(Statement* s) { body_ = s; }
600 592
601 int yield_count() const { return yield_count_; } 593 int yield_count() const { return yield_count_; }
602 int first_yield_id() const { return first_yield_id_; } 594 int first_yield_id() const { return first_yield_id_; }
603 void set_yield_count(int yield_count) { yield_count_ = yield_count; } 595 void set_yield_count(int yield_count) { yield_count_ = yield_count; }
604 void set_first_yield_id(int first_yield_id) { 596 void set_first_yield_id(int first_yield_id) {
605 first_yield_id_ = first_yield_id; 597 first_yield_id_ = first_yield_id;
606 } 598 }
607 599
608 static int num_ids() { return parent_num_ids() + 1; } 600 static int num_ids() { return parent_num_ids() + 1; }
609 BailoutId OsrEntryId() const { return BailoutId(local_id(0)); } 601 BailoutId OsrEntryId() const { return BailoutId(local_id(0)); }
610 602
611 // Code generation 603 // Code generation
612 Label* continue_target() { return &continue_target_; } 604 Label* continue_target() { return &continue_target_; }
613 605
614 protected: 606 protected:
615 IterationStatement(Zone* zone, ZoneList<const AstRawString*>* labels, int pos) 607 IterationStatement(Zone* zone, ZoneList<const AstRawString*>* labels, int pos,
616 : BreakableStatement(zone, labels, TARGET_FOR_ANONYMOUS, pos), 608 NodeType type)
609 : BreakableStatement(zone, labels, TARGET_FOR_ANONYMOUS, pos, type),
617 body_(NULL), 610 body_(NULL),
618 yield_count_(0), 611 yield_count_(0),
619 first_yield_id_(0) {} 612 first_yield_id_(0) {}
620 static int parent_num_ids() { return BreakableStatement::num_ids(); } 613 static int parent_num_ids() { return BreakableStatement::num_ids(); }
621 void Initialize(Statement* body) { body_ = body; } 614 void Initialize(Statement* body) { body_ = body; }
622 615
623 private: 616 private:
624 int local_id(int n) const { return base_id() + parent_num_ids() + n; } 617 int local_id(int n) const { return base_id() + parent_num_ids() + n; }
625 618
626 Statement* body_; 619 Statement* body_;
(...skipping 15 matching lines...) Expand all
642 Expression* cond() const { return cond_; } 635 Expression* cond() const { return cond_; }
643 void set_cond(Expression* e) { cond_ = e; } 636 void set_cond(Expression* e) { cond_ = e; }
644 637
645 static int num_ids() { return parent_num_ids() + 2; } 638 static int num_ids() { return parent_num_ids() + 2; }
646 BailoutId ContinueId() const { return BailoutId(local_id(0)); } 639 BailoutId ContinueId() const { return BailoutId(local_id(0)); }
647 BailoutId StackCheckId() const { return BackEdgeId(); } 640 BailoutId StackCheckId() const { return BackEdgeId(); }
648 BailoutId BackEdgeId() const { return BailoutId(local_id(1)); } 641 BailoutId BackEdgeId() const { return BailoutId(local_id(1)); }
649 642
650 protected: 643 protected:
651 DoWhileStatement(Zone* zone, ZoneList<const AstRawString*>* labels, int pos) 644 DoWhileStatement(Zone* zone, ZoneList<const AstRawString*>* labels, int pos)
652 : IterationStatement(zone, labels, pos), cond_(NULL) {} 645 : IterationStatement(zone, labels, pos, kDoWhileStatement), cond_(NULL) {}
653 static int parent_num_ids() { return IterationStatement::num_ids(); } 646 static int parent_num_ids() { return IterationStatement::num_ids(); }
654 647
655 private: 648 private:
656 int local_id(int n) const { return base_id() + parent_num_ids() + n; } 649 int local_id(int n) const { return base_id() + parent_num_ids() + n; }
657 650
658 Expression* cond_; 651 Expression* cond_;
659 }; 652 };
660 653
661 654
662 class WhileStatement final : public IterationStatement { 655 class WhileStatement final : public IterationStatement {
663 public: 656 public:
664 DECLARE_NODE_TYPE(WhileStatement) 657 DECLARE_NODE_TYPE(WhileStatement)
665 658
666 void Initialize(Expression* cond, Statement* body) { 659 void Initialize(Expression* cond, Statement* body) {
667 IterationStatement::Initialize(body); 660 IterationStatement::Initialize(body);
668 cond_ = cond; 661 cond_ = cond;
669 } 662 }
670 663
671 Expression* cond() const { return cond_; } 664 Expression* cond() const { return cond_; }
672 void set_cond(Expression* e) { cond_ = e; } 665 void set_cond(Expression* e) { cond_ = e; }
673 666
674 static int num_ids() { return parent_num_ids() + 1; } 667 static int num_ids() { return parent_num_ids() + 1; }
675 BailoutId ContinueId() const { return EntryId(); } 668 BailoutId ContinueId() const { return EntryId(); }
676 BailoutId StackCheckId() const { return BodyId(); } 669 BailoutId StackCheckId() const { return BodyId(); }
677 BailoutId BodyId() const { return BailoutId(local_id(0)); } 670 BailoutId BodyId() const { return BailoutId(local_id(0)); }
678 671
679 protected: 672 protected:
680 WhileStatement(Zone* zone, ZoneList<const AstRawString*>* labels, int pos) 673 WhileStatement(Zone* zone, ZoneList<const AstRawString*>* labels, int pos)
681 : IterationStatement(zone, labels, pos), cond_(NULL) {} 674 : IterationStatement(zone, labels, pos, kWhileStatement), cond_(NULL) {}
682 static int parent_num_ids() { return IterationStatement::num_ids(); } 675 static int parent_num_ids() { return IterationStatement::num_ids(); }
683 676
684 private: 677 private:
685 int local_id(int n) const { return base_id() + parent_num_ids() + n; } 678 int local_id(int n) const { return base_id() + parent_num_ids() + n; }
686 679
687 Expression* cond_; 680 Expression* cond_;
688 }; 681 };
689 682
690 683
691 class ForStatement final : public IterationStatement { 684 class ForStatement final : public IterationStatement {
(...skipping 18 matching lines...) Expand all
710 void set_cond(Expression* e) { cond_ = e; } 703 void set_cond(Expression* e) { cond_ = e; }
711 void set_next(Statement* s) { next_ = s; } 704 void set_next(Statement* s) { next_ = s; }
712 705
713 static int num_ids() { return parent_num_ids() + 2; } 706 static int num_ids() { return parent_num_ids() + 2; }
714 BailoutId ContinueId() const { return BailoutId(local_id(0)); } 707 BailoutId ContinueId() const { return BailoutId(local_id(0)); }
715 BailoutId StackCheckId() const { return BodyId(); } 708 BailoutId StackCheckId() const { return BodyId(); }
716 BailoutId BodyId() const { return BailoutId(local_id(1)); } 709 BailoutId BodyId() const { return BailoutId(local_id(1)); }
717 710
718 protected: 711 protected:
719 ForStatement(Zone* zone, ZoneList<const AstRawString*>* labels, int pos) 712 ForStatement(Zone* zone, ZoneList<const AstRawString*>* labels, int pos)
720 : IterationStatement(zone, labels, pos), 713 : IterationStatement(zone, labels, pos, kForStatement),
721 init_(NULL), 714 init_(NULL),
722 cond_(NULL), 715 cond_(NULL),
723 next_(NULL) {} 716 next_(NULL) {}
724 static int parent_num_ids() { return IterationStatement::num_ids(); } 717 static int parent_num_ids() { return IterationStatement::num_ids(); }
725 718
726 private: 719 private:
727 int local_id(int n) const { return base_id() + parent_num_ids() + n; } 720 int local_id(int n) const { return base_id() + parent_num_ids() + n; }
728 721
729 Statement* init_; 722 Statement* init_;
730 Expression* cond_; 723 Expression* cond_;
731 Statement* next_; 724 Statement* next_;
732 }; 725 };
733 726
734 727
735 class ForEachStatement : public IterationStatement { 728 class ForEachStatement : public IterationStatement {
736 public: 729 public:
737 enum VisitMode { 730 enum VisitMode {
738 ENUMERATE, // for (each in subject) body; 731 ENUMERATE, // for (each in subject) body;
739 ITERATE // for (each of subject) body; 732 ITERATE // for (each of subject) body;
740 }; 733 };
741 734
742 using IterationStatement::Initialize; 735 using IterationStatement::Initialize;
743 736
744 static const char* VisitModeString(VisitMode mode) { 737 static const char* VisitModeString(VisitMode mode) {
745 return mode == ITERATE ? "for-of" : "for-in"; 738 return mode == ITERATE ? "for-of" : "for-in";
746 } 739 }
747 740
748 protected: 741 protected:
749 ForEachStatement(Zone* zone, ZoneList<const AstRawString*>* labels, int pos) 742 ForEachStatement(Zone* zone, ZoneList<const AstRawString*>* labels, int pos,
750 : IterationStatement(zone, labels, pos) {} 743 NodeType type)
744 : IterationStatement(zone, labels, pos, type) {}
751 }; 745 };
752 746
753 747
754 class ForInStatement final : public ForEachStatement { 748 class ForInStatement final : public ForEachStatement {
755 public: 749 public:
756 DECLARE_NODE_TYPE(ForInStatement) 750 DECLARE_NODE_TYPE(ForInStatement)
757 751
758 void Initialize(Expression* each, Expression* subject, Statement* body) { 752 void Initialize(Expression* each, Expression* subject, Statement* body) {
759 ForEachStatement::Initialize(body); 753 ForEachStatement::Initialize(body);
760 each_ = each; 754 each_ = each;
(...skipping 28 matching lines...) Expand all
789 BailoutId EnumId() const { return BailoutId(local_id(1)); } 783 BailoutId EnumId() const { return BailoutId(local_id(1)); }
790 BailoutId ToObjectId() const { return BailoutId(local_id(2)); } 784 BailoutId ToObjectId() const { return BailoutId(local_id(2)); }
791 BailoutId PrepareId() const { return BailoutId(local_id(3)); } 785 BailoutId PrepareId() const { return BailoutId(local_id(3)); }
792 BailoutId FilterId() const { return BailoutId(local_id(4)); } 786 BailoutId FilterId() const { return BailoutId(local_id(4)); }
793 BailoutId AssignmentId() const { return BailoutId(local_id(5)); } 787 BailoutId AssignmentId() const { return BailoutId(local_id(5)); }
794 BailoutId ContinueId() const { return EntryId(); } 788 BailoutId ContinueId() const { return EntryId(); }
795 BailoutId StackCheckId() const { return BodyId(); } 789 BailoutId StackCheckId() const { return BodyId(); }
796 790
797 protected: 791 protected:
798 ForInStatement(Zone* zone, ZoneList<const AstRawString*>* labels, int pos) 792 ForInStatement(Zone* zone, ZoneList<const AstRawString*>* labels, int pos)
799 : ForEachStatement(zone, labels, pos), 793 : ForEachStatement(zone, labels, pos, kForInStatement),
800 each_(nullptr), 794 each_(nullptr),
801 subject_(nullptr), 795 subject_(nullptr),
802 for_in_type_(SLOW_FOR_IN) {} 796 for_in_type_(SLOW_FOR_IN) {}
803 static int parent_num_ids() { return ForEachStatement::num_ids(); } 797 static int parent_num_ids() { return ForEachStatement::num_ids(); }
804 798
805 private: 799 private:
806 int local_id(int n) const { return base_id() + parent_num_ids() + n; } 800 int local_id(int n) const { return base_id() + parent_num_ids() + n; }
807 801
808 Expression* each_; 802 Expression* each_;
809 Expression* subject_; 803 Expression* subject_;
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
858 void set_assign_each(Expression* e) { assign_each_ = e; } 852 void set_assign_each(Expression* e) { assign_each_ = e; }
859 853
860 BailoutId ContinueId() const { return EntryId(); } 854 BailoutId ContinueId() const { return EntryId(); }
861 BailoutId StackCheckId() const { return BackEdgeId(); } 855 BailoutId StackCheckId() const { return BackEdgeId(); }
862 856
863 static int num_ids() { return parent_num_ids() + 1; } 857 static int num_ids() { return parent_num_ids() + 1; }
864 BailoutId BackEdgeId() const { return BailoutId(local_id(0)); } 858 BailoutId BackEdgeId() const { return BailoutId(local_id(0)); }
865 859
866 protected: 860 protected:
867 ForOfStatement(Zone* zone, ZoneList<const AstRawString*>* labels, int pos) 861 ForOfStatement(Zone* zone, ZoneList<const AstRawString*>* labels, int pos)
868 : ForEachStatement(zone, labels, pos), 862 : ForEachStatement(zone, labels, pos, kForOfStatement),
869 iterator_(NULL), 863 iterator_(NULL),
870 assign_iterator_(NULL), 864 assign_iterator_(NULL),
871 next_result_(NULL), 865 next_result_(NULL),
872 result_done_(NULL), 866 result_done_(NULL),
873 assign_each_(NULL) {} 867 assign_each_(NULL) {}
874 static int parent_num_ids() { return ForEachStatement::num_ids(); } 868 static int parent_num_ids() { return ForEachStatement::num_ids(); }
875 869
876 private: 870 private:
877 int local_id(int n) const { return base_id() + parent_num_ids() + n; } 871 int local_id(int n) const { return base_id() + parent_num_ids() + n; }
878 872
879 Variable* iterator_; 873 Variable* iterator_;
880 Expression* assign_iterator_; 874 Expression* assign_iterator_;
881 Expression* next_result_; 875 Expression* next_result_;
882 Expression* result_done_; 876 Expression* result_done_;
883 Expression* assign_each_; 877 Expression* assign_each_;
884 }; 878 };
885 879
886 880
887 class ExpressionStatement final : public Statement { 881 class ExpressionStatement final : public Statement {
888 public: 882 public:
889 DECLARE_NODE_TYPE(ExpressionStatement) 883 DECLARE_NODE_TYPE(ExpressionStatement)
890 884
891 void set_expression(Expression* e) { expression_ = e; } 885 void set_expression(Expression* e) { expression_ = e; }
892 Expression* expression() const { return expression_; } 886 Expression* expression() const { return expression_; }
893 bool IsJump() const { return expression_->IsThrow(); } 887 bool IsJump() const { return expression_->IsThrow(); }
894 888
895 protected: 889 protected:
896 ExpressionStatement(Zone* zone, Expression* expression, int pos) 890 ExpressionStatement(Zone* zone, Expression* expression, int pos)
897 : Statement(zone, pos), expression_(expression) { } 891 : Statement(zone, pos, kExpressionStatement), expression_(expression) {}
898 892
899 private: 893 private:
900 Expression* expression_; 894 Expression* expression_;
901 }; 895 };
902 896
903 897
904 class JumpStatement : public Statement { 898 class JumpStatement : public Statement {
905 public: 899 public:
906 bool IsJump() const { return true; } 900 bool IsJump() const { return true; }
907 901
908 protected: 902 protected:
909 explicit JumpStatement(Zone* zone, int pos) : Statement(zone, pos) {} 903 explicit JumpStatement(Zone* zone, int pos, NodeType type)
904 : Statement(zone, pos, type) {}
910 }; 905 };
911 906
912 907
913 class ContinueStatement final : public JumpStatement { 908 class ContinueStatement final : public JumpStatement {
914 public: 909 public:
915 DECLARE_NODE_TYPE(ContinueStatement) 910 DECLARE_NODE_TYPE(ContinueStatement)
916 911
917 IterationStatement* target() const { return target_; } 912 IterationStatement* target() const { return target_; }
918 913
919 protected: 914 protected:
920 explicit ContinueStatement(Zone* zone, IterationStatement* target, int pos) 915 explicit ContinueStatement(Zone* zone, IterationStatement* target, int pos)
921 : JumpStatement(zone, pos), target_(target) { } 916 : JumpStatement(zone, pos, kContinueStatement), target_(target) {}
922 917
923 private: 918 private:
924 IterationStatement* target_; 919 IterationStatement* target_;
925 }; 920 };
926 921
927 922
928 class BreakStatement final : public JumpStatement { 923 class BreakStatement final : public JumpStatement {
929 public: 924 public:
930 DECLARE_NODE_TYPE(BreakStatement) 925 DECLARE_NODE_TYPE(BreakStatement)
931 926
932 BreakableStatement* target() const { return target_; } 927 BreakableStatement* target() const { return target_; }
933 928
934 protected: 929 protected:
935 explicit BreakStatement(Zone* zone, BreakableStatement* target, int pos) 930 explicit BreakStatement(Zone* zone, BreakableStatement* target, int pos)
936 : JumpStatement(zone, pos), target_(target) { } 931 : JumpStatement(zone, pos, kBreakStatement), target_(target) {}
937 932
938 private: 933 private:
939 BreakableStatement* target_; 934 BreakableStatement* target_;
940 }; 935 };
941 936
942 937
943 class ReturnStatement final : public JumpStatement { 938 class ReturnStatement final : public JumpStatement {
944 public: 939 public:
945 DECLARE_NODE_TYPE(ReturnStatement) 940 DECLARE_NODE_TYPE(ReturnStatement)
946 941
947 Expression* expression() const { return expression_; } 942 Expression* expression() const { return expression_; }
948 943
949 void set_expression(Expression* e) { expression_ = e; } 944 void set_expression(Expression* e) { expression_ = e; }
950 945
951 protected: 946 protected:
952 explicit ReturnStatement(Zone* zone, Expression* expression, int pos) 947 explicit ReturnStatement(Zone* zone, Expression* expression, int pos)
953 : JumpStatement(zone, pos), expression_(expression) { } 948 : JumpStatement(zone, pos, kReturnStatement), expression_(expression) {}
954 949
955 private: 950 private:
956 Expression* expression_; 951 Expression* expression_;
957 }; 952 };
958 953
959 954
960 class WithStatement final : public Statement { 955 class WithStatement final : public Statement {
961 public: 956 public:
962 DECLARE_NODE_TYPE(WithStatement) 957 DECLARE_NODE_TYPE(WithStatement)
963 958
964 Scope* scope() { return scope_; } 959 Scope* scope() { return scope_; }
965 Expression* expression() const { return expression_; } 960 Expression* expression() const { return expression_; }
966 void set_expression(Expression* e) { expression_ = e; } 961 void set_expression(Expression* e) { expression_ = e; }
967 Statement* statement() const { return statement_; } 962 Statement* statement() const { return statement_; }
968 void set_statement(Statement* s) { statement_ = s; } 963 void set_statement(Statement* s) { statement_ = s; }
969 964
970 void set_base_id(int id) { base_id_ = id; } 965 void set_base_id(int id) { base_id_ = id; }
971 static int num_ids() { return parent_num_ids() + 2; } 966 static int num_ids() { return parent_num_ids() + 2; }
972 BailoutId ToObjectId() const { return BailoutId(local_id(0)); } 967 BailoutId ToObjectId() const { return BailoutId(local_id(0)); }
973 BailoutId EntryId() const { return BailoutId(local_id(1)); } 968 BailoutId EntryId() const { return BailoutId(local_id(1)); }
974 969
975 protected: 970 protected:
976 WithStatement(Zone* zone, Scope* scope, Expression* expression, 971 WithStatement(Zone* zone, Scope* scope, Expression* expression,
977 Statement* statement, int pos) 972 Statement* statement, int pos)
978 : Statement(zone, pos), 973 : Statement(zone, pos, kWithStatement),
979 scope_(scope), 974 scope_(scope),
980 expression_(expression), 975 expression_(expression),
981 statement_(statement), 976 statement_(statement),
982 base_id_(BailoutId::None().ToInt()) {} 977 base_id_(BailoutId::None().ToInt()) {}
983 static int parent_num_ids() { return 0; } 978 static int parent_num_ids() { return 0; }
984 979
985 int base_id() const { 980 int base_id() const {
986 DCHECK(!BailoutId(base_id_).IsNone()); 981 DCHECK(!BailoutId(base_id_).IsNone());
987 return base_id_; 982 return base_id_;
988 } 983 }
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
1041 cases_ = cases; 1036 cases_ = cases;
1042 } 1037 }
1043 1038
1044 Expression* tag() const { return tag_; } 1039 Expression* tag() const { return tag_; }
1045 ZoneList<CaseClause*>* cases() const { return cases_; } 1040 ZoneList<CaseClause*>* cases() const { return cases_; }
1046 1041
1047 void set_tag(Expression* t) { tag_ = t; } 1042 void set_tag(Expression* t) { tag_ = t; }
1048 1043
1049 protected: 1044 protected:
1050 SwitchStatement(Zone* zone, ZoneList<const AstRawString*>* labels, int pos) 1045 SwitchStatement(Zone* zone, ZoneList<const AstRawString*>* labels, int pos)
1051 : BreakableStatement(zone, labels, TARGET_FOR_ANONYMOUS, pos), 1046 : BreakableStatement(zone, labels, TARGET_FOR_ANONYMOUS, pos,
1047 kSwitchStatement),
1052 tag_(NULL), 1048 tag_(NULL),
1053 cases_(NULL) {} 1049 cases_(NULL) {}
1054 1050
1055 private: 1051 private:
1056 Expression* tag_; 1052 Expression* tag_;
1057 ZoneList<CaseClause*>* cases_; 1053 ZoneList<CaseClause*>* cases_;
1058 }; 1054 };
1059 1055
1060 1056
1061 // If-statements always have non-null references to their then- and 1057 // If-statements always have non-null references to their then- and
(...skipping 23 matching lines...) Expand all
1085 1081
1086 void set_base_id(int id) { base_id_ = id; } 1082 void set_base_id(int id) { base_id_ = id; }
1087 static int num_ids() { return parent_num_ids() + 3; } 1083 static int num_ids() { return parent_num_ids() + 3; }
1088 BailoutId IfId() const { return BailoutId(local_id(0)); } 1084 BailoutId IfId() const { return BailoutId(local_id(0)); }
1089 BailoutId ThenId() const { return BailoutId(local_id(1)); } 1085 BailoutId ThenId() const { return BailoutId(local_id(1)); }
1090 BailoutId ElseId() const { return BailoutId(local_id(2)); } 1086 BailoutId ElseId() const { return BailoutId(local_id(2)); }
1091 1087
1092 protected: 1088 protected:
1093 IfStatement(Zone* zone, Expression* condition, Statement* then_statement, 1089 IfStatement(Zone* zone, Expression* condition, Statement* then_statement,
1094 Statement* else_statement, int pos) 1090 Statement* else_statement, int pos)
1095 : Statement(zone, pos), 1091 : Statement(zone, pos, kIfStatement),
1096 condition_(condition), 1092 condition_(condition),
1097 then_statement_(then_statement), 1093 then_statement_(then_statement),
1098 else_statement_(else_statement), 1094 else_statement_(else_statement),
1099 base_id_(BailoutId::None().ToInt()) {} 1095 base_id_(BailoutId::None().ToInt()) {}
1100 static int parent_num_ids() { return 0; } 1096 static int parent_num_ids() { return 0; }
1101 1097
1102 int base_id() const { 1098 int base_id() const {
1103 DCHECK(!BailoutId(base_id_).IsNone()); 1099 DCHECK(!BailoutId(base_id_).IsNone());
1104 return base_id_; 1100 return base_id_;
1105 } 1101 }
1106 1102
1107 private: 1103 private:
1108 int local_id(int n) const { return base_id() + parent_num_ids() + n; } 1104 int local_id(int n) const { return base_id() + parent_num_ids() + n; }
1109 1105
1110 Expression* condition_; 1106 Expression* condition_;
1111 Statement* then_statement_; 1107 Statement* then_statement_;
1112 Statement* else_statement_; 1108 Statement* else_statement_;
1113 int base_id_; 1109 int base_id_;
1114 }; 1110 };
1115 1111
1116 1112
1117 class TryStatement : public Statement { 1113 class TryStatement : public Statement {
1118 public: 1114 public:
1119 Block* try_block() const { return try_block_; } 1115 Block* try_block() const { return try_block_; }
1120 void set_try_block(Block* b) { try_block_ = b; } 1116 void set_try_block(Block* b) { try_block_ = b; }
1121 1117
1122 protected: 1118 protected:
1123 TryStatement(Zone* zone, Block* try_block, int pos) 1119 TryStatement(Zone* zone, Block* try_block, int pos, NodeType type)
1124 : Statement(zone, pos), try_block_(try_block) {} 1120 : Statement(zone, pos, type), try_block_(try_block) {}
1125 1121
1126 private: 1122 private:
1127 Block* try_block_; 1123 Block* try_block_;
1128 }; 1124 };
1129 1125
1130 1126
1131 class TryCatchStatement final : public TryStatement { 1127 class TryCatchStatement final : public TryStatement {
1132 public: 1128 public:
1133 DECLARE_NODE_TYPE(TryCatchStatement) 1129 DECLARE_NODE_TYPE(TryCatchStatement)
1134 1130
(...skipping 11 matching lines...) Expand all
1146 // rethrow the caught exception (using %ReThrow), which reuses the pending 1142 // rethrow the caught exception (using %ReThrow), which reuses the pending
1147 // message instead of generating a new one. 1143 // message instead of generating a new one.
1148 // (When the catch block doesn't rethrow but is guaranteed to perform an 1144 // (When the catch block doesn't rethrow but is guaranteed to perform an
1149 // ordinary throw, not clearing the old message is safe but not very useful.) 1145 // ordinary throw, not clearing the old message is safe but not very useful.)
1150 bool clear_pending_message() { return clear_pending_message_; } 1146 bool clear_pending_message() { return clear_pending_message_; }
1151 1147
1152 protected: 1148 protected:
1153 TryCatchStatement(Zone* zone, Block* try_block, Scope* scope, 1149 TryCatchStatement(Zone* zone, Block* try_block, Scope* scope,
1154 Variable* variable, Block* catch_block, 1150 Variable* variable, Block* catch_block,
1155 bool clear_pending_message, int pos) 1151 bool clear_pending_message, int pos)
1156 : TryStatement(zone, try_block, pos), 1152 : TryStatement(zone, try_block, pos, kTryCatchStatement),
1157 scope_(scope), 1153 scope_(scope),
1158 variable_(variable), 1154 variable_(variable),
1159 catch_block_(catch_block), 1155 catch_block_(catch_block),
1160 clear_pending_message_(clear_pending_message) {} 1156 clear_pending_message_(clear_pending_message) {}
1161 1157
1162 private: 1158 private:
1163 Scope* scope_; 1159 Scope* scope_;
1164 Variable* variable_; 1160 Variable* variable_;
1165 Block* catch_block_; 1161 Block* catch_block_;
1166 bool clear_pending_message_; 1162 bool clear_pending_message_;
1167 }; 1163 };
1168 1164
1169 1165
1170 class TryFinallyStatement final : public TryStatement { 1166 class TryFinallyStatement final : public TryStatement {
1171 public: 1167 public:
1172 DECLARE_NODE_TYPE(TryFinallyStatement) 1168 DECLARE_NODE_TYPE(TryFinallyStatement)
1173 1169
1174 Block* finally_block() const { return finally_block_; } 1170 Block* finally_block() const { return finally_block_; }
1175 void set_finally_block(Block* b) { finally_block_ = b; } 1171 void set_finally_block(Block* b) { finally_block_ = b; }
1176 1172
1177 protected: 1173 protected:
1178 TryFinallyStatement(Zone* zone, Block* try_block, Block* finally_block, 1174 TryFinallyStatement(Zone* zone, Block* try_block, Block* finally_block,
1179 int pos) 1175 int pos)
1180 : TryStatement(zone, try_block, pos), finally_block_(finally_block) {} 1176 : TryStatement(zone, try_block, pos, kTryFinallyStatement),
1177 finally_block_(finally_block) {}
1181 1178
1182 private: 1179 private:
1183 Block* finally_block_; 1180 Block* finally_block_;
1184 }; 1181 };
1185 1182
1186 1183
1187 class DebuggerStatement final : public Statement { 1184 class DebuggerStatement final : public Statement {
1188 public: 1185 public:
1189 DECLARE_NODE_TYPE(DebuggerStatement) 1186 DECLARE_NODE_TYPE(DebuggerStatement)
1190 1187
1191 void set_base_id(int id) { base_id_ = id; } 1188 void set_base_id(int id) { base_id_ = id; }
1192 static int num_ids() { return parent_num_ids() + 1; } 1189 static int num_ids() { return parent_num_ids() + 1; }
1193 BailoutId DebugBreakId() const { return BailoutId(local_id(0)); } 1190 BailoutId DebugBreakId() const { return BailoutId(local_id(0)); }
1194 1191
1195 protected: 1192 protected:
1196 explicit DebuggerStatement(Zone* zone, int pos) 1193 explicit DebuggerStatement(Zone* zone, int pos)
1197 : Statement(zone, pos), base_id_(BailoutId::None().ToInt()) {} 1194 : Statement(zone, pos, kDebuggerStatement),
1195 base_id_(BailoutId::None().ToInt()) {}
1198 static int parent_num_ids() { return 0; } 1196 static int parent_num_ids() { return 0; }
1199 1197
1200 int base_id() const { 1198 int base_id() const {
1201 DCHECK(!BailoutId(base_id_).IsNone()); 1199 DCHECK(!BailoutId(base_id_).IsNone());
1202 return base_id_; 1200 return base_id_;
1203 } 1201 }
1204 1202
1205 private: 1203 private:
1206 int local_id(int n) const { return base_id() + parent_num_ids() + n; } 1204 int local_id(int n) const { return base_id() + parent_num_ids() + n; }
1207 1205
1208 int base_id_; 1206 int base_id_;
1209 }; 1207 };
1210 1208
1211 1209
1212 class EmptyStatement final : public Statement { 1210 class EmptyStatement final : public Statement {
1213 public: 1211 public:
1214 DECLARE_NODE_TYPE(EmptyStatement) 1212 DECLARE_NODE_TYPE(EmptyStatement)
1215 1213
1216 protected: 1214 protected:
1217 explicit EmptyStatement(Zone* zone, int pos): Statement(zone, pos) {} 1215 explicit EmptyStatement(Zone* zone, int pos)
1216 : Statement(zone, pos, kEmptyStatement) {}
1218 }; 1217 };
1219 1218
1220 1219
1221 // Delegates to another statement, which may be overwritten. 1220 // Delegates to another statement, which may be overwritten.
1222 // This was introduced to implement ES2015 Annex B3.3 for conditionally making 1221 // This was introduced to implement ES2015 Annex B3.3 for conditionally making
1223 // sloppy-mode block-scoped functions have a var binding, which is changed 1222 // sloppy-mode block-scoped functions have a var binding, which is changed
1224 // from one statement to another during parsing. 1223 // from one statement to another during parsing.
1225 class SloppyBlockFunctionStatement final : public Statement { 1224 class SloppyBlockFunctionStatement final : public Statement {
1226 public: 1225 public:
1227 DECLARE_NODE_TYPE(SloppyBlockFunctionStatement) 1226 DECLARE_NODE_TYPE(SloppyBlockFunctionStatement)
1228 1227
1229 Statement* statement() const { return statement_; } 1228 Statement* statement() const { return statement_; }
1230 void set_statement(Statement* statement) { statement_ = statement; } 1229 void set_statement(Statement* statement) { statement_ = statement; }
1231 Scope* scope() const { return scope_; } 1230 Scope* scope() const { return scope_; }
1232 1231
1233 private: 1232 private:
1234 SloppyBlockFunctionStatement(Zone* zone, Statement* statement, Scope* scope) 1233 SloppyBlockFunctionStatement(Zone* zone, Statement* statement, Scope* scope)
1235 : Statement(zone, kNoSourcePosition), 1234 : Statement(zone, kNoSourcePosition, kSloppyBlockFunctionStatement),
1236 statement_(statement), 1235 statement_(statement),
1237 scope_(scope) {} 1236 scope_(scope) {}
1238 1237
1239 Statement* statement_; 1238 Statement* statement_;
1240 Scope* const scope_; 1239 Scope* const scope_;
1241 }; 1240 };
1242 1241
1243 1242
1244 class Literal final : public Expression { 1243 class Literal final : public Expression {
1245 public: 1244 public:
(...skipping 22 matching lines...) Expand all
1268 uint32_t Hash(); 1267 uint32_t Hash();
1269 static bool Match(void* literal1, void* literal2); 1268 static bool Match(void* literal1, void* literal2);
1270 1269
1271 static int num_ids() { return parent_num_ids() + 1; } 1270 static int num_ids() { return parent_num_ids() + 1; }
1272 TypeFeedbackId LiteralFeedbackId() const { 1271 TypeFeedbackId LiteralFeedbackId() const {
1273 return TypeFeedbackId(local_id(0)); 1272 return TypeFeedbackId(local_id(0));
1274 } 1273 }
1275 1274
1276 protected: 1275 protected:
1277 Literal(Zone* zone, const AstValue* value, int position) 1276 Literal(Zone* zone, const AstValue* value, int position)
1278 : Expression(zone, position), value_(value) {} 1277 : Expression(zone, position, kLiteral), value_(value) {}
1279 static int parent_num_ids() { return Expression::num_ids(); } 1278 static int parent_num_ids() { return Expression::num_ids(); }
1280 1279
1281 private: 1280 private:
1282 int local_id(int n) const { return base_id() + parent_num_ids() + n; } 1281 int local_id(int n) const { return base_id() + parent_num_ids() + n; }
1283 1282
1284 const AstValue* value_; 1283 const AstValue* value_;
1285 }; 1284 };
1286 1285
1287 1286
1288 class AstLiteralReindexer; 1287 class AstLiteralReindexer;
1289 1288
1290 // Base class for literals that needs space in the corresponding JSFunction. 1289 // Base class for literals that needs space in the corresponding JSFunction.
1291 class MaterializedLiteral : public Expression { 1290 class MaterializedLiteral : public Expression {
1292 public: 1291 public:
1293 int literal_index() { return literal_index_; } 1292 int literal_index() { return literal_index_; }
1294 1293
1295 int depth() const { 1294 int depth() const {
1296 // only callable after initialization. 1295 // only callable after initialization.
1297 DCHECK(depth_ >= 1); 1296 DCHECK(depth_ >= 1);
1298 return depth_; 1297 return depth_;
1299 } 1298 }
1300 1299
1301 protected: 1300 protected:
1302 MaterializedLiteral(Zone* zone, int literal_index, int pos) 1301 MaterializedLiteral(Zone* zone, int literal_index, int pos, NodeType type)
1303 : Expression(zone, pos), 1302 : Expression(zone, pos, type),
1304 literal_index_(literal_index), 1303 literal_index_(literal_index),
1305 is_simple_(false), 1304 is_simple_(false),
1306 depth_(0) {} 1305 depth_(0) {}
1307 1306
1308 // A materialized literal is simple if the values consist of only 1307 // A materialized literal is simple if the values consist of only
1309 // constants and simple object and array literals. 1308 // constants and simple object and array literals.
1310 bool is_simple() const { return is_simple_; } 1309 bool is_simple() const { return is_simple_; }
1311 void set_is_simple(bool is_simple) { is_simple_ = is_simple; } 1310 void set_is_simple(bool is_simple) { is_simple_ = is_simple; }
1312 friend class CompileTimeValue; 1311 friend class CompileTimeValue;
1313 1312
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
1476 } 1475 }
1477 1476
1478 // Object literals need one feedback slot for each non-trivial value, as well 1477 // Object literals need one feedback slot for each non-trivial value, as well
1479 // as some slots for home objects. 1478 // as some slots for home objects.
1480 void AssignFeedbackVectorSlots(Isolate* isolate, FeedbackVectorSpec* spec, 1479 void AssignFeedbackVectorSlots(Isolate* isolate, FeedbackVectorSpec* spec,
1481 FeedbackVectorSlotCache* cache); 1480 FeedbackVectorSlotCache* cache);
1482 1481
1483 protected: 1482 protected:
1484 ObjectLiteral(Zone* zone, ZoneList<Property*>* properties, int literal_index, 1483 ObjectLiteral(Zone* zone, ZoneList<Property*>* properties, int literal_index,
1485 int boilerplate_properties, int pos) 1484 int boilerplate_properties, int pos)
1486 : MaterializedLiteral(zone, literal_index, pos), 1485 : MaterializedLiteral(zone, literal_index, pos, kObjectLiteral),
1487 properties_(properties), 1486 properties_(properties),
1488 boilerplate_properties_(boilerplate_properties), 1487 boilerplate_properties_(boilerplate_properties),
1489 fast_elements_(false), 1488 fast_elements_(false),
1490 has_elements_(false), 1489 has_elements_(false),
1491 may_store_doubles_(false) {} 1490 may_store_doubles_(false) {}
1492 static int parent_num_ids() { return MaterializedLiteral::num_ids(); } 1491 static int parent_num_ids() { return MaterializedLiteral::num_ids(); }
1493 1492
1494 private: 1493 private:
1495 int local_id(int n) const { return base_id() + parent_num_ids() + n; } 1494 int local_id(int n) const { return base_id() + parent_num_ids() + n; }
1496 Handle<FixedArray> constant_properties_; 1495 Handle<FixedArray> constant_properties_;
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
1529 class RegExpLiteral final : public MaterializedLiteral { 1528 class RegExpLiteral final : public MaterializedLiteral {
1530 public: 1529 public:
1531 DECLARE_NODE_TYPE(RegExpLiteral) 1530 DECLARE_NODE_TYPE(RegExpLiteral)
1532 1531
1533 Handle<String> pattern() const { return pattern_->string(); } 1532 Handle<String> pattern() const { return pattern_->string(); }
1534 int flags() const { return flags_; } 1533 int flags() const { return flags_; }
1535 1534
1536 protected: 1535 protected:
1537 RegExpLiteral(Zone* zone, const AstRawString* pattern, int flags, 1536 RegExpLiteral(Zone* zone, const AstRawString* pattern, int flags,
1538 int literal_index, int pos) 1537 int literal_index, int pos)
1539 : MaterializedLiteral(zone, literal_index, pos), 1538 : MaterializedLiteral(zone, literal_index, pos, kRegExpLiteral),
1540 pattern_(pattern), 1539 pattern_(pattern),
1541 flags_(flags) { 1540 flags_(flags) {
1542 set_depth(1); 1541 set_depth(1);
1543 } 1542 }
1544 1543
1545 private: 1544 private:
1546 const AstRawString* const pattern_; 1545 const AstRawString* const pattern_;
1547 int const flags_; 1546 int const flags_;
1548 }; 1547 };
1549 1548
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
1603 kDisableMementos = 1 << 1 1602 kDisableMementos = 1 << 1
1604 }; 1603 };
1605 1604
1606 void AssignFeedbackVectorSlots(Isolate* isolate, FeedbackVectorSpec* spec, 1605 void AssignFeedbackVectorSlots(Isolate* isolate, FeedbackVectorSpec* spec,
1607 FeedbackVectorSlotCache* cache); 1606 FeedbackVectorSlotCache* cache);
1608 FeedbackVectorSlot LiteralFeedbackSlot() const { return literal_slot_; } 1607 FeedbackVectorSlot LiteralFeedbackSlot() const { return literal_slot_; }
1609 1608
1610 protected: 1609 protected:
1611 ArrayLiteral(Zone* zone, ZoneList<Expression*>* values, 1610 ArrayLiteral(Zone* zone, ZoneList<Expression*>* values,
1612 int first_spread_index, int literal_index, int pos) 1611 int first_spread_index, int literal_index, int pos)
1613 : MaterializedLiteral(zone, literal_index, pos), 1612 : MaterializedLiteral(zone, literal_index, pos, kArrayLiteral),
1614 values_(values), 1613 values_(values),
1615 first_spread_index_(first_spread_index) {} 1614 first_spread_index_(first_spread_index) {}
1616 static int parent_num_ids() { return MaterializedLiteral::num_ids(); } 1615 static int parent_num_ids() { return MaterializedLiteral::num_ids(); }
1617 1616
1618 private: 1617 private:
1619 int local_id(int n) const { return base_id() + parent_num_ids() + n; } 1618 int local_id(int n) const { return base_id() + parent_num_ids() + n; }
1620 1619
1621 Handle<FixedArray> constant_elements_; 1620 Handle<FixedArray> constant_elements_;
1622 ZoneList<Expression*>* values_; 1621 ZoneList<Expression*>* values_;
1623 int first_spread_index_; 1622 int first_spread_index_;
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
1789 static LhsKind GetAssignType(Property* property) { 1788 static LhsKind GetAssignType(Property* property) {
1790 if (property == NULL) return VARIABLE; 1789 if (property == NULL) return VARIABLE;
1791 bool super_access = property->IsSuperAccess(); 1790 bool super_access = property->IsSuperAccess();
1792 return (property->key()->IsPropertyName()) 1791 return (property->key()->IsPropertyName())
1793 ? (super_access ? NAMED_SUPER_PROPERTY : NAMED_PROPERTY) 1792 ? (super_access ? NAMED_SUPER_PROPERTY : NAMED_PROPERTY)
1794 : (super_access ? KEYED_SUPER_PROPERTY : KEYED_PROPERTY); 1793 : (super_access ? KEYED_SUPER_PROPERTY : KEYED_PROPERTY);
1795 } 1794 }
1796 1795
1797 protected: 1796 protected:
1798 Property(Zone* zone, Expression* obj, Expression* key, int pos) 1797 Property(Zone* zone, Expression* obj, Expression* key, int pos)
1799 : Expression(zone, pos), 1798 : Expression(zone, pos, kProperty),
1800 bit_field_(IsForCallField::encode(false) | 1799 bit_field_(IsForCallField::encode(false) |
1801 IsStringAccessField::encode(false) | 1800 IsStringAccessField::encode(false) |
1802 InlineCacheStateField::encode(UNINITIALIZED)), 1801 InlineCacheStateField::encode(UNINITIALIZED)),
1803 obj_(obj), 1802 obj_(obj),
1804 key_(key) {} 1803 key_(key) {}
1805 static int parent_num_ids() { return Expression::num_ids(); } 1804 static int parent_num_ids() { return Expression::num_ids(); }
1806 1805
1807 private: 1806 private:
1808 int local_id(int n) const { return base_id() + parent_num_ids() + n; } 1807 int local_id(int n) const { return base_id() + parent_num_ids() + n; }
1809 1808
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
1909 bool IsUsingCallFeedbackICSlot(Isolate* isolate) const; 1908 bool IsUsingCallFeedbackICSlot(Isolate* isolate) const;
1910 1909
1911 #ifdef DEBUG 1910 #ifdef DEBUG
1912 // Used to assert that the FullCodeGenerator records the return site. 1911 // Used to assert that the FullCodeGenerator records the return site.
1913 bool return_is_recorded_; 1912 bool return_is_recorded_;
1914 #endif 1913 #endif
1915 1914
1916 protected: 1915 protected:
1917 Call(Zone* zone, Expression* expression, ZoneList<Expression*>* arguments, 1916 Call(Zone* zone, Expression* expression, ZoneList<Expression*>* arguments,
1918 int pos) 1917 int pos)
1919 : Expression(zone, pos), 1918 : Expression(zone, pos, kCall),
1920 expression_(expression), 1919 expression_(expression),
1921 arguments_(arguments), 1920 arguments_(arguments),
1922 bit_field_(IsUninitializedField::encode(false)) { 1921 bit_field_(IsUninitializedField::encode(false)) {
1923 if (expression->IsProperty()) { 1922 if (expression->IsProperty()) {
1924 expression->AsProperty()->mark_for_call(); 1923 expression->AsProperty()->mark_for_call();
1925 } 1924 }
1926 } 1925 }
1927 static int parent_num_ids() { return Expression::num_ids(); } 1926 static int parent_num_ids() { return Expression::num_ids(); }
1928 1927
1929 private: 1928 private:
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
1980 void set_is_monomorphic(bool monomorphic) { is_monomorphic_ = monomorphic; } 1979 void set_is_monomorphic(bool monomorphic) { is_monomorphic_ = monomorphic; }
1981 void set_target(Handle<JSFunction> target) { target_ = target; } 1980 void set_target(Handle<JSFunction> target) { target_ = target; }
1982 void SetKnownGlobalTarget(Handle<JSFunction> target) { 1981 void SetKnownGlobalTarget(Handle<JSFunction> target) {
1983 target_ = target; 1982 target_ = target;
1984 is_monomorphic_ = true; 1983 is_monomorphic_ = true;
1985 } 1984 }
1986 1985
1987 protected: 1986 protected:
1988 CallNew(Zone* zone, Expression* expression, ZoneList<Expression*>* arguments, 1987 CallNew(Zone* zone, Expression* expression, ZoneList<Expression*>* arguments,
1989 int pos) 1988 int pos)
1990 : Expression(zone, pos), 1989 : Expression(zone, pos, kCallNew),
1991 expression_(expression), 1990 expression_(expression),
1992 arguments_(arguments), 1991 arguments_(arguments),
1993 is_monomorphic_(false) {} 1992 is_monomorphic_(false) {}
1994 1993
1995 static int parent_num_ids() { return Expression::num_ids(); } 1994 static int parent_num_ids() { return Expression::num_ids(); }
1996 1995
1997 private: 1996 private:
1998 int local_id(int n) const { return base_id() + parent_num_ids() + n; } 1997 int local_id(int n) const { return base_id() + parent_num_ids() + n; }
1999 1998
2000 Expression* expression_; 1999 Expression* expression_;
(...skipping 28 matching lines...) Expand all
2029 static int num_ids() { return parent_num_ids() + 1; } 2028 static int num_ids() { return parent_num_ids() + 1; }
2030 BailoutId CallId() { return BailoutId(local_id(0)); } 2029 BailoutId CallId() { return BailoutId(local_id(0)); }
2031 2030
2032 const char* debug_name() { 2031 const char* debug_name() {
2033 return is_jsruntime() ? "(context function)" : function_->name; 2032 return is_jsruntime() ? "(context function)" : function_->name;
2034 } 2033 }
2035 2034
2036 protected: 2035 protected:
2037 CallRuntime(Zone* zone, const Runtime::Function* function, 2036 CallRuntime(Zone* zone, const Runtime::Function* function,
2038 ZoneList<Expression*>* arguments, int pos) 2037 ZoneList<Expression*>* arguments, int pos)
2039 : Expression(zone, pos), function_(function), arguments_(arguments) {} 2038 : Expression(zone, pos, kCallRuntime),
2039 function_(function),
2040 arguments_(arguments) {}
2040 2041
2041 CallRuntime(Zone* zone, int context_index, ZoneList<Expression*>* arguments, 2042 CallRuntime(Zone* zone, int context_index, ZoneList<Expression*>* arguments,
2042 int pos) 2043 int pos)
2043 : Expression(zone, pos), 2044 : Expression(zone, pos, kCallRuntime),
2044 function_(NULL), 2045 function_(NULL),
2045 context_index_(context_index), 2046 context_index_(context_index),
2046 arguments_(arguments) {} 2047 arguments_(arguments) {}
2047 2048
2048 static int parent_num_ids() { return Expression::num_ids(); } 2049 static int parent_num_ids() { return Expression::num_ids(); }
2049 2050
2050 private: 2051 private:
2051 int local_id(int n) const { return base_id() + parent_num_ids() + n; } 2052 int local_id(int n) const { return base_id() + parent_num_ids() + n; }
2052 2053
2053 const Runtime::Function* function_; 2054 const Runtime::Function* function_;
(...skipping 13 matching lines...) Expand all
2067 // For unary not (Token::NOT), the AST ids where true and false will 2068 // For unary not (Token::NOT), the AST ids where true and false will
2068 // actually be materialized, respectively. 2069 // actually be materialized, respectively.
2069 static int num_ids() { return parent_num_ids() + 2; } 2070 static int num_ids() { return parent_num_ids() + 2; }
2070 BailoutId MaterializeTrueId() const { return BailoutId(local_id(0)); } 2071 BailoutId MaterializeTrueId() const { return BailoutId(local_id(0)); }
2071 BailoutId MaterializeFalseId() const { return BailoutId(local_id(1)); } 2072 BailoutId MaterializeFalseId() const { return BailoutId(local_id(1)); }
2072 2073
2073 void RecordToBooleanTypeFeedback(TypeFeedbackOracle* oracle); 2074 void RecordToBooleanTypeFeedback(TypeFeedbackOracle* oracle);
2074 2075
2075 protected: 2076 protected:
2076 UnaryOperation(Zone* zone, Token::Value op, Expression* expression, int pos) 2077 UnaryOperation(Zone* zone, Token::Value op, Expression* expression, int pos)
2077 : Expression(zone, pos), op_(op), expression_(expression) { 2078 : Expression(zone, pos, kUnaryOperation),
2079 op_(op),
2080 expression_(expression) {
2078 DCHECK(Token::IsUnaryOp(op)); 2081 DCHECK(Token::IsUnaryOp(op));
2079 } 2082 }
2080 static int parent_num_ids() { return Expression::num_ids(); } 2083 static int parent_num_ids() { return Expression::num_ids(); }
2081 2084
2082 private: 2085 private:
2083 int local_id(int n) const { return base_id() + parent_num_ids() + n; } 2086 int local_id(int n) const { return base_id() + parent_num_ids() + n; }
2084 2087
2085 Token::Value op_; 2088 Token::Value op_;
2086 Expression* expression_; 2089 Expression* expression_;
2087 }; 2090 };
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
2126 void set_fixed_right_arg(Maybe<int> arg) { 2129 void set_fixed_right_arg(Maybe<int> arg) {
2127 has_fixed_right_arg_ = arg.IsJust(); 2130 has_fixed_right_arg_ = arg.IsJust();
2128 if (arg.IsJust()) fixed_right_arg_value_ = arg.FromJust(); 2131 if (arg.IsJust()) fixed_right_arg_value_ = arg.FromJust();
2129 } 2132 }
2130 2133
2131 void RecordToBooleanTypeFeedback(TypeFeedbackOracle* oracle); 2134 void RecordToBooleanTypeFeedback(TypeFeedbackOracle* oracle);
2132 2135
2133 protected: 2136 protected:
2134 BinaryOperation(Zone* zone, Token::Value op, Expression* left, 2137 BinaryOperation(Zone* zone, Token::Value op, Expression* left,
2135 Expression* right, int pos) 2138 Expression* right, int pos)
2136 : Expression(zone, pos), 2139 : Expression(zone, pos, kBinaryOperation),
2137 op_(static_cast<byte>(op)), 2140 op_(static_cast<byte>(op)),
2138 has_fixed_right_arg_(false), 2141 has_fixed_right_arg_(false),
2139 fixed_right_arg_value_(0), 2142 fixed_right_arg_value_(0),
2140 left_(left), 2143 left_(left),
2141 right_(right) { 2144 right_(right) {
2142 DCHECK(Token::IsBinaryOp(op)); 2145 DCHECK(Token::IsBinaryOp(op));
2143 } 2146 }
2144 static int parent_num_ids() { return Expression::num_ids(); } 2147 static int parent_num_ids() { return Expression::num_ids(); }
2145 2148
2146 private: 2149 private:
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
2197 return TypeFeedbackId(local_id(3)); 2200 return TypeFeedbackId(local_id(3));
2198 } 2201 }
2199 2202
2200 void AssignFeedbackVectorSlots(Isolate* isolate, FeedbackVectorSpec* spec, 2203 void AssignFeedbackVectorSlots(Isolate* isolate, FeedbackVectorSpec* spec,
2201 FeedbackVectorSlotCache* cache); 2204 FeedbackVectorSlotCache* cache);
2202 FeedbackVectorSlot CountSlot() const { return slot_; } 2205 FeedbackVectorSlot CountSlot() const { return slot_; }
2203 2206
2204 protected: 2207 protected:
2205 CountOperation(Zone* zone, Token::Value op, bool is_prefix, Expression* expr, 2208 CountOperation(Zone* zone, Token::Value op, bool is_prefix, Expression* expr,
2206 int pos) 2209 int pos)
2207 : Expression(zone, pos), 2210 : Expression(zone, pos, kCountOperation),
2208 bit_field_( 2211 bit_field_(
2209 IsPrefixField::encode(is_prefix) | KeyTypeField::encode(ELEMENT) | 2212 IsPrefixField::encode(is_prefix) | KeyTypeField::encode(ELEMENT) |
2210 StoreModeField::encode(STANDARD_STORE) | TokenField::encode(op)), 2213 StoreModeField::encode(STANDARD_STORE) | TokenField::encode(op)),
2211 type_(NULL), 2214 type_(NULL),
2212 expression_(expr) {} 2215 expression_(expr) {}
2213 static int parent_num_ids() { return Expression::num_ids(); } 2216 static int parent_num_ids() { return Expression::num_ids(); }
2214 2217
2215 private: 2218 private:
2216 int local_id(int n) const { return base_id() + parent_num_ids() + n; } 2219 int local_id(int n) const { return base_id() + parent_num_ids() + n; }
2217 2220
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
2250 void set_combined_type(Type* type) { combined_type_ = type; } 2253 void set_combined_type(Type* type) { combined_type_ = type; }
2251 2254
2252 // Match special cases. 2255 // Match special cases.
2253 bool IsLiteralCompareTypeof(Expression** expr, Handle<String>* check); 2256 bool IsLiteralCompareTypeof(Expression** expr, Handle<String>* check);
2254 bool IsLiteralCompareUndefined(Expression** expr); 2257 bool IsLiteralCompareUndefined(Expression** expr);
2255 bool IsLiteralCompareNull(Expression** expr); 2258 bool IsLiteralCompareNull(Expression** expr);
2256 2259
2257 protected: 2260 protected:
2258 CompareOperation(Zone* zone, Token::Value op, Expression* left, 2261 CompareOperation(Zone* zone, Token::Value op, Expression* left,
2259 Expression* right, int pos) 2262 Expression* right, int pos)
2260 : Expression(zone, pos), 2263 : Expression(zone, pos, kCompareOperation),
2261 op_(op), 2264 op_(op),
2262 left_(left), 2265 left_(left),
2263 right_(right), 2266 right_(right),
2264 combined_type_(Type::None()) { 2267 combined_type_(Type::None()) {
2265 DCHECK(Token::IsCompareOp(op)); 2268 DCHECK(Token::IsCompareOp(op));
2266 } 2269 }
2267 static int parent_num_ids() { return Expression::num_ids(); } 2270 static int parent_num_ids() { return Expression::num_ids(); }
2268 2271
2269 private: 2272 private:
2270 int local_id(int n) const { return base_id() + parent_num_ids() + n; } 2273 int local_id(int n) const { return base_id() + parent_num_ids() + n; }
(...skipping 12 matching lines...) Expand all
2283 2286
2284 Expression* expression() const { return expression_; } 2287 Expression* expression() const { return expression_; }
2285 void set_expression(Expression* e) { expression_ = e; } 2288 void set_expression(Expression* e) { expression_ = e; }
2286 2289
2287 int expression_position() const { return expr_pos_; } 2290 int expression_position() const { return expr_pos_; }
2288 2291
2289 static int num_ids() { return parent_num_ids(); } 2292 static int num_ids() { return parent_num_ids(); }
2290 2293
2291 protected: 2294 protected:
2292 Spread(Zone* zone, Expression* expression, int pos, int expr_pos) 2295 Spread(Zone* zone, Expression* expression, int pos, int expr_pos)
2293 : Expression(zone, pos), expression_(expression), expr_pos_(expr_pos) {} 2296 : Expression(zone, pos, kSpread),
2297 expression_(expression),
2298 expr_pos_(expr_pos) {}
2294 static int parent_num_ids() { return Expression::num_ids(); } 2299 static int parent_num_ids() { return Expression::num_ids(); }
2295 2300
2296 private: 2301 private:
2297 int local_id(int n) const { return base_id() + parent_num_ids() + n; } 2302 int local_id(int n) const { return base_id() + parent_num_ids() + n; }
2298 2303
2299 Expression* expression_; 2304 Expression* expression_;
2300 int expr_pos_; 2305 int expr_pos_;
2301 }; 2306 };
2302 2307
2303 2308
(...skipping 14 matching lines...) Expand all
2318 else_expression_->MarkTail(); 2323 else_expression_->MarkTail();
2319 } 2324 }
2320 2325
2321 static int num_ids() { return parent_num_ids() + 2; } 2326 static int num_ids() { return parent_num_ids() + 2; }
2322 BailoutId ThenId() const { return BailoutId(local_id(0)); } 2327 BailoutId ThenId() const { return BailoutId(local_id(0)); }
2323 BailoutId ElseId() const { return BailoutId(local_id(1)); } 2328 BailoutId ElseId() const { return BailoutId(local_id(1)); }
2324 2329
2325 protected: 2330 protected:
2326 Conditional(Zone* zone, Expression* condition, Expression* then_expression, 2331 Conditional(Zone* zone, Expression* condition, Expression* then_expression,
2327 Expression* else_expression, int position) 2332 Expression* else_expression, int position)
2328 : Expression(zone, position), 2333 : Expression(zone, position, kConditional),
2329 condition_(condition), 2334 condition_(condition),
2330 then_expression_(then_expression), 2335 then_expression_(then_expression),
2331 else_expression_(else_expression) {} 2336 else_expression_(else_expression) {}
2332 static int parent_num_ids() { return Expression::num_ids(); } 2337 static int parent_num_ids() { return Expression::num_ids(); }
2333 2338
2334 private: 2339 private:
2335 int local_id(int n) const { return base_id() + parent_num_ids() + n; } 2340 int local_id(int n) const { return base_id() + parent_num_ids() + n; }
2336 2341
2337 Expression* condition_; 2342 Expression* condition_;
2338 Expression* then_expression_; 2343 Expression* then_expression_;
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
2445 DCHECK_NOT_NULL(new_expression); 2450 DCHECK_NOT_NULL(new_expression);
2446 DCHECK(!new_expression->IsRewritableExpression()); 2451 DCHECK(!new_expression->IsRewritableExpression());
2447 expr_ = new_expression; 2452 expr_ = new_expression;
2448 is_rewritten_ = true; 2453 is_rewritten_ = true;
2449 } 2454 }
2450 2455
2451 static int num_ids() { return parent_num_ids(); } 2456 static int num_ids() { return parent_num_ids(); }
2452 2457
2453 protected: 2458 protected:
2454 RewritableExpression(Zone* zone, Expression* expression) 2459 RewritableExpression(Zone* zone, Expression* expression)
2455 : Expression(zone, expression->position()), 2460 : Expression(zone, expression->position(), kRewritableExpression),
2456 is_rewritten_(false), 2461 is_rewritten_(false),
2457 expr_(expression) { 2462 expr_(expression) {
2458 DCHECK(!expression->IsRewritableExpression()); 2463 DCHECK(!expression->IsRewritableExpression());
2459 } 2464 }
2460 2465
2461 private: 2466 private:
2462 int local_id(int n) const { return base_id() + parent_num_ids() + n; } 2467 int local_id(int n) const { return base_id() + parent_num_ids() + n; }
2463 2468
2464 bool is_rewritten_; 2469 bool is_rewritten_;
2465 Expression* expr_; 2470 Expression* expr_;
(...skipping 10 matching lines...) Expand all
2476 Expression* expression() const { return expression_; } 2481 Expression* expression() const { return expression_; }
2477 int yield_id() const { return yield_id_; } 2482 int yield_id() const { return yield_id_; }
2478 2483
2479 void set_generator_object(Expression* e) { generator_object_ = e; } 2484 void set_generator_object(Expression* e) { generator_object_ = e; }
2480 void set_expression(Expression* e) { expression_ = e; } 2485 void set_expression(Expression* e) { expression_ = e; }
2481 void set_yield_id(int yield_id) { yield_id_ = yield_id; } 2486 void set_yield_id(int yield_id) { yield_id_ = yield_id; }
2482 2487
2483 protected: 2488 protected:
2484 Yield(Zone* zone, Expression* generator_object, Expression* expression, 2489 Yield(Zone* zone, Expression* generator_object, Expression* expression,
2485 int pos) 2490 int pos)
2486 : Expression(zone, pos), 2491 : Expression(zone, pos, kYield),
2487 generator_object_(generator_object), 2492 generator_object_(generator_object),
2488 expression_(expression), 2493 expression_(expression),
2489 yield_id_(-1) {} 2494 yield_id_(-1) {}
2490 2495
2491 private: 2496 private:
2492 Expression* generator_object_; 2497 Expression* generator_object_;
2493 Expression* expression_; 2498 Expression* expression_;
2494 int yield_id_; 2499 int yield_id_;
2495 }; 2500 };
2496 2501
2497 2502
2498 class Throw final : public Expression { 2503 class Throw final : public Expression {
2499 public: 2504 public:
2500 DECLARE_NODE_TYPE(Throw) 2505 DECLARE_NODE_TYPE(Throw)
2501 2506
2502 Expression* exception() const { return exception_; } 2507 Expression* exception() const { return exception_; }
2503 void set_exception(Expression* e) { exception_ = e; } 2508 void set_exception(Expression* e) { exception_ = e; }
2504 2509
2505 protected: 2510 protected:
2506 Throw(Zone* zone, Expression* exception, int pos) 2511 Throw(Zone* zone, Expression* exception, int pos)
2507 : Expression(zone, pos), exception_(exception) {} 2512 : Expression(zone, pos, kThrow), exception_(exception) {}
2508 2513
2509 private: 2514 private:
2510 Expression* exception_; 2515 Expression* exception_;
2511 }; 2516 };
2512 2517
2513 2518
2514 class FunctionLiteral final : public Expression { 2519 class FunctionLiteral final : public Expression {
2515 public: 2520 public:
2516 enum FunctionType { 2521 enum FunctionType {
2517 kAnonymousExpression, 2522 kAnonymousExpression,
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
2646 2651
2647 protected: 2652 protected:
2648 FunctionLiteral(Zone* zone, const AstString* name, 2653 FunctionLiteral(Zone* zone, const AstString* name,
2649 AstValueFactory* ast_value_factory, Scope* scope, 2654 AstValueFactory* ast_value_factory, Scope* scope,
2650 ZoneList<Statement*>* body, int materialized_literal_count, 2655 ZoneList<Statement*>* body, int materialized_literal_count,
2651 int expected_property_count, int parameter_count, 2656 int expected_property_count, int parameter_count,
2652 FunctionType function_type, 2657 FunctionType function_type,
2653 ParameterFlag has_duplicate_parameters, 2658 ParameterFlag has_duplicate_parameters,
2654 EagerCompileHint eager_compile_hint, FunctionKind kind, 2659 EagerCompileHint eager_compile_hint, FunctionKind kind,
2655 int position, bool is_function) 2660 int position, bool is_function)
2656 : Expression(zone, position), 2661 : Expression(zone, position, kFunctionLiteral),
2657 raw_name_(name), 2662 raw_name_(name),
2658 scope_(scope), 2663 scope_(scope),
2659 body_(body), 2664 body_(body),
2660 raw_inferred_name_(ast_value_factory->empty_string()), 2665 raw_inferred_name_(ast_value_factory->empty_string()),
2661 ast_properties_(zone), 2666 ast_properties_(zone),
2662 dont_optimize_reason_(kNoReason), 2667 dont_optimize_reason_(kNoReason),
2663 materialized_literal_count_(materialized_literal_count), 2668 materialized_literal_count_(materialized_literal_count),
2664 expected_property_count_(expected_property_count), 2669 expected_property_count_(expected_property_count),
2665 parameter_count_(parameter_count), 2670 parameter_count_(parameter_count),
2666 function_token_position_(kNoSourcePosition), 2671 function_token_position_(kNoSourcePosition),
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
2748 2753
2749 bool IsAnonymousFunctionDefinition() const { 2754 bool IsAnonymousFunctionDefinition() const {
2750 return constructor()->raw_name()->length() == 0; 2755 return constructor()->raw_name()->length() == 0;
2751 } 2756 }
2752 2757
2753 protected: 2758 protected:
2754 ClassLiteral(Zone* zone, Scope* scope, VariableProxy* class_variable_proxy, 2759 ClassLiteral(Zone* zone, Scope* scope, VariableProxy* class_variable_proxy,
2755 Expression* extends, FunctionLiteral* constructor, 2760 Expression* extends, FunctionLiteral* constructor,
2756 ZoneList<Property*>* properties, int start_position, 2761 ZoneList<Property*>* properties, int start_position,
2757 int end_position) 2762 int end_position)
2758 : Expression(zone, start_position), 2763 : Expression(zone, start_position, kClassLiteral),
2759 scope_(scope), 2764 scope_(scope),
2760 class_variable_proxy_(class_variable_proxy), 2765 class_variable_proxy_(class_variable_proxy),
2761 extends_(extends), 2766 extends_(extends),
2762 constructor_(constructor), 2767 constructor_(constructor),
2763 properties_(properties), 2768 properties_(properties),
2764 end_position_(end_position) {} 2769 end_position_(end_position) {}
2765 2770
2766 static int parent_num_ids() { return Expression::num_ids(); } 2771 static int parent_num_ids() { return Expression::num_ids(); }
2767 2772
2768 private: 2773 private:
(...skipping 13 matching lines...) Expand all
2782 class NativeFunctionLiteral final : public Expression { 2787 class NativeFunctionLiteral final : public Expression {
2783 public: 2788 public:
2784 DECLARE_NODE_TYPE(NativeFunctionLiteral) 2789 DECLARE_NODE_TYPE(NativeFunctionLiteral)
2785 2790
2786 Handle<String> name() const { return name_->string(); } 2791 Handle<String> name() const { return name_->string(); }
2787 v8::Extension* extension() const { return extension_; } 2792 v8::Extension* extension() const { return extension_; }
2788 2793
2789 protected: 2794 protected:
2790 NativeFunctionLiteral(Zone* zone, const AstRawString* name, 2795 NativeFunctionLiteral(Zone* zone, const AstRawString* name,
2791 v8::Extension* extension, int pos) 2796 v8::Extension* extension, int pos)
2792 : Expression(zone, pos), name_(name), extension_(extension) {} 2797 : Expression(zone, pos, kNativeFunctionLiteral),
2798 name_(name),
2799 extension_(extension) {}
2793 2800
2794 private: 2801 private:
2795 const AstRawString* name_; 2802 const AstRawString* name_;
2796 v8::Extension* extension_; 2803 v8::Extension* extension_;
2797 }; 2804 };
2798 2805
2799 2806
2800 class ThisFunction final : public Expression { 2807 class ThisFunction final : public Expression {
2801 public: 2808 public:
2802 DECLARE_NODE_TYPE(ThisFunction) 2809 DECLARE_NODE_TYPE(ThisFunction)
2803 2810
2804 protected: 2811 protected:
2805 ThisFunction(Zone* zone, int pos) : Expression(zone, pos) {} 2812 ThisFunction(Zone* zone, int pos) : Expression(zone, pos, kThisFunction) {}
2806 }; 2813 };
2807 2814
2808 2815
2809 class SuperPropertyReference final : public Expression { 2816 class SuperPropertyReference final : public Expression {
2810 public: 2817 public:
2811 DECLARE_NODE_TYPE(SuperPropertyReference) 2818 DECLARE_NODE_TYPE(SuperPropertyReference)
2812 2819
2813 VariableProxy* this_var() const { return this_var_; } 2820 VariableProxy* this_var() const { return this_var_; }
2814 void set_this_var(VariableProxy* v) { this_var_ = v; } 2821 void set_this_var(VariableProxy* v) { this_var_ = v; }
2815 Expression* home_object() const { return home_object_; } 2822 Expression* home_object() const { return home_object_; }
2816 void set_home_object(Expression* e) { home_object_ = e; } 2823 void set_home_object(Expression* e) { home_object_ = e; }
2817 2824
2818 protected: 2825 protected:
2819 SuperPropertyReference(Zone* zone, VariableProxy* this_var, 2826 SuperPropertyReference(Zone* zone, VariableProxy* this_var,
2820 Expression* home_object, int pos) 2827 Expression* home_object, int pos)
2821 : Expression(zone, pos), this_var_(this_var), home_object_(home_object) { 2828 : Expression(zone, pos, kSuperPropertyReference),
2829 this_var_(this_var),
2830 home_object_(home_object) {
2822 DCHECK(this_var->is_this()); 2831 DCHECK(this_var->is_this());
2823 DCHECK(home_object->IsProperty()); 2832 DCHECK(home_object->IsProperty());
2824 } 2833 }
2825 2834
2826 private: 2835 private:
2827 VariableProxy* this_var_; 2836 VariableProxy* this_var_;
2828 Expression* home_object_; 2837 Expression* home_object_;
2829 }; 2838 };
2830 2839
2831 2840
2832 class SuperCallReference final : public Expression { 2841 class SuperCallReference final : public Expression {
2833 public: 2842 public:
2834 DECLARE_NODE_TYPE(SuperCallReference) 2843 DECLARE_NODE_TYPE(SuperCallReference)
2835 2844
2836 VariableProxy* this_var() const { return this_var_; } 2845 VariableProxy* this_var() const { return this_var_; }
2837 void set_this_var(VariableProxy* v) { this_var_ = v; } 2846 void set_this_var(VariableProxy* v) { this_var_ = v; }
2838 VariableProxy* new_target_var() const { return new_target_var_; } 2847 VariableProxy* new_target_var() const { return new_target_var_; }
2839 void set_new_target_var(VariableProxy* v) { new_target_var_ = v; } 2848 void set_new_target_var(VariableProxy* v) { new_target_var_ = v; }
2840 VariableProxy* this_function_var() const { return this_function_var_; } 2849 VariableProxy* this_function_var() const { return this_function_var_; }
2841 void set_this_function_var(VariableProxy* v) { this_function_var_ = v; } 2850 void set_this_function_var(VariableProxy* v) { this_function_var_ = v; }
2842 2851
2843 protected: 2852 protected:
2844 SuperCallReference(Zone* zone, VariableProxy* this_var, 2853 SuperCallReference(Zone* zone, VariableProxy* this_var,
2845 VariableProxy* new_target_var, 2854 VariableProxy* new_target_var,
2846 VariableProxy* this_function_var, int pos) 2855 VariableProxy* this_function_var, int pos)
2847 : Expression(zone, pos), 2856 : Expression(zone, pos, kSuperCallReference),
2848 this_var_(this_var), 2857 this_var_(this_var),
2849 new_target_var_(new_target_var), 2858 new_target_var_(new_target_var),
2850 this_function_var_(this_function_var) { 2859 this_function_var_(this_function_var) {
2851 DCHECK(this_var->is_this()); 2860 DCHECK(this_var->is_this());
2852 DCHECK(new_target_var->raw_name()->IsOneByteEqualTo(".new.target")); 2861 DCHECK(new_target_var->raw_name()->IsOneByteEqualTo(".new.target"));
2853 DCHECK(this_function_var->raw_name()->IsOneByteEqualTo(".this_function")); 2862 DCHECK(this_function_var->raw_name()->IsOneByteEqualTo(".this_function"));
2854 } 2863 }
2855 2864
2856 private: 2865 private:
2857 VariableProxy* this_var_; 2866 VariableProxy* this_var_;
2858 VariableProxy* new_target_var_; 2867 VariableProxy* new_target_var_;
2859 VariableProxy* this_function_var_; 2868 VariableProxy* this_function_var_;
2860 }; 2869 };
2861 2870
2862 2871
2863 // This class is produced when parsing the () in arrow functions without any 2872 // This class is produced when parsing the () in arrow functions without any
2864 // arguments and is not actually a valid expression. 2873 // arguments and is not actually a valid expression.
2865 class EmptyParentheses final : public Expression { 2874 class EmptyParentheses final : public Expression {
2866 public: 2875 public:
2867 DECLARE_NODE_TYPE(EmptyParentheses) 2876 DECLARE_NODE_TYPE(EmptyParentheses)
2868 2877
2869 private: 2878 private:
2870 EmptyParentheses(Zone* zone, int pos) : Expression(zone, pos) {} 2879 EmptyParentheses(Zone* zone, int pos)
2880 : Expression(zone, pos, kEmptyParentheses) {}
2871 }; 2881 };
2872 2882
2873 2883
2874 #undef DECLARE_NODE_TYPE 2884 #undef DECLARE_NODE_TYPE
2875 2885
2876 2886
2877 // ---------------------------------------------------------------------------- 2887 // ----------------------------------------------------------------------------
2878 // Basic visitor 2888 // Basic visitor
2879 // - leaf node visitors are abstract. 2889 // - leaf node visitors are abstract.
vogelheim 2016/07/14 11:27:35 nitpick: comment is untrue now, is it? It might
Toon Verwaest 2016/07/15 07:07:19 Done.
2880 2890
2891 template <class Subclass>
2881 class AstVisitor BASE_EMBEDDED { 2892 class AstVisitor BASE_EMBEDDED {
2882 public: 2893 public:
2883 AstVisitor() {} 2894 void Visit(AstNode* node) { This()->Visit(node); }
2884 virtual ~AstVisitor() {}
2885
2886 // Stack overflow check and dynamic dispatch.
2887 virtual void Visit(AstNode* node) = 0;
2888 2895
2889 // Iteration left-to-right. 2896 // Iteration left-to-right.
vogelheim 2016/07/14 11:27:35 nitpick: In the previous version, I read the comme
Toon Verwaest 2016/07/15 07:07:19 Done.
2890 virtual void VisitDeclarations(ZoneList<Declaration*>* declarations); 2897 void VisitDeclarations(ZoneList<Declaration*>* declarations) {
2891 virtual void VisitStatements(ZoneList<Statement*>* statements); 2898 for (int i = 0; i < declarations->length(); i++) {
2892 virtual void VisitExpressions(ZoneList<Expression*>* expressions); 2899 Visit(declarations->at(i));
2900 }
2901 }
2893 2902
2894 // Individual AST nodes. 2903 void VisitStatements(ZoneList<Statement*>* statements) {
2895 #define DEF_VISIT(type) \ 2904 for (int i = 0; i < statements->length(); i++) {
2896 virtual void Visit##type(type* node) = 0; 2905 Statement* stmt = statements->at(i);
2897 AST_NODE_LIST(DEF_VISIT) 2906 Visit(stmt);
2898 #undef DEF_VISIT 2907 if (stmt->IsJump()) break;
2908 }
2909 }
2910
2911 void VisitExpressions(ZoneList<Expression*>* expressions) {
2912 for (int i = 0; i < expressions->length(); i++) {
2913 // The variable statement visiting code may pass NULL expressions
2914 // to this code. Maybe this should be handled by introducing an
2915 // undefined expression or literal? Revisit this code if this
2916 // changes
2917 Expression* expression = expressions->at(i);
2918 if (expression != NULL) Visit(expression);
2919 }
2920 }
2921
2922 private:
2923 Subclass* This() { return static_cast<Subclass*>(this); }
2899 }; 2924 };
2900 2925
2926 #define GENERATE_VISIT_CASE(NodeType) \
2927 case AstNode::k##NodeType: \
2928 return Visit##NodeType(static_cast<NodeType*>(node));
2929
2930 #define GENERATE_AST_VISITOR_SWITCH() \
2931 switch (node->node_type()) { \
2932 AST_NODE_LIST(GENERATE_VISIT_CASE) \
2933 case AstNode::kModule: \
2934 UNREACHABLE(); \
2935 }
2936
2937 #define DEFINE_AST_VISITOR_MEMBERS_WITHOUT_STACKOVERFLOW() \
vogelheim 2016/07/14 11:27:35 Super nitpick: - I was wondering about the name of
Toon Verwaest 2016/07/15 07:07:19 Done. This macro should probably go away. We could
2938 public: \
2939 void Visit(AstNode* node) { GENERATE_AST_VISITOR_SWITCH() } \
2940 \
2941 private:
2942
2901 #define DEFINE_AST_VISITOR_SUBCLASS_MEMBERS() \ 2943 #define DEFINE_AST_VISITOR_SUBCLASS_MEMBERS() \
2902 public: \ 2944 public: \
2903 void Visit(AstNode* node) final { \ 2945 void Visit(AstNode* node) { \
2904 if (!CheckStackOverflow()) node->Accept(this); \ 2946 if (CheckStackOverflow()) return; \
2947 GENERATE_AST_VISITOR_SWITCH() \
2905 } \ 2948 } \
2906 \ 2949 \
2907 void SetStackOverflow() { stack_overflow_ = true; } \ 2950 void SetStackOverflow() { stack_overflow_ = true; } \
2908 void ClearStackOverflow() { stack_overflow_ = false; } \ 2951 void ClearStackOverflow() { stack_overflow_ = false; } \
2909 bool HasStackOverflow() const { return stack_overflow_; } \ 2952 bool HasStackOverflow() const { return stack_overflow_; } \
2910 \ 2953 \
2911 bool CheckStackOverflow() { \ 2954 bool CheckStackOverflow() { \
2912 if (stack_overflow_) return true; \ 2955 if (stack_overflow_) return true; \
2913 if (GetCurrentStackPosition() < stack_limit_) { \ 2956 if (GetCurrentStackPosition() < stack_limit_) { \
2914 stack_overflow_ = true; \ 2957 stack_overflow_ = true; \
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
2952 \ 2995 \
2953 void InitializeAstRewriter(uintptr_t stack_limit) { \ 2996 void InitializeAstRewriter(uintptr_t stack_limit) { \
2954 InitializeAstVisitor(stack_limit); \ 2997 InitializeAstVisitor(stack_limit); \
2955 replacement_ = nullptr; \ 2998 replacement_ = nullptr; \
2956 } \ 2999 } \
2957 \ 3000 \
2958 DEFINE_AST_VISITOR_SUBCLASS_MEMBERS(); \ 3001 DEFINE_AST_VISITOR_SUBCLASS_MEMBERS(); \
2959 \ 3002 \
2960 protected: \ 3003 protected: \
2961 AstNode* replacement_ 3004 AstNode* replacement_
2962
2963 // Generic macro for rewriting things; `GET` is the expression to be 3005 // Generic macro for rewriting things; `GET` is the expression to be
2964 // rewritten; `SET` is a command that should do the rewriting, i.e. 3006 // rewritten; `SET` is a command that should do the rewriting, i.e.
2965 // something sensible with the variable called `replacement`. 3007 // something sensible with the variable called `replacement`.
2966 #define AST_REWRITE(Type, GET, SET) \ 3008 #define AST_REWRITE(Type, GET, SET) \
2967 do { \ 3009 do { \
2968 DCHECK(!HasStackOverflow()); \ 3010 DCHECK(!HasStackOverflow()); \
2969 DCHECK_NULL(replacement_); \ 3011 DCHECK_NULL(replacement_); \
2970 Visit(GET); \ 3012 Visit(GET); \
2971 if (HasStackOverflow()) return; \ 3013 if (HasStackOverflow()) return; \
2972 if (replacement_ == nullptr) break; \ 3014 if (replacement_ == nullptr) break; \
(...skipping 19 matching lines...) Expand all
2992 auto _list = (list); \ 3034 auto _list = (list); \
2993 auto _index = (index); \ 3035 auto _index = (index); \
2994 AST_REWRITE(Type, _list->at(_index), _list->Set(_index, replacement)); \ 3036 AST_REWRITE(Type, _list->at(_index), _list->Set(_index, replacement)); \
2995 } while (false) 3037 } while (false)
2996 3038
2997 3039
2998 // ---------------------------------------------------------------------------- 3040 // ----------------------------------------------------------------------------
2999 // Traversing visitor 3041 // Traversing visitor
3000 // - fully traverses the entire AST. 3042 // - fully traverses the entire AST.
3001 3043
3002 class AstTraversalVisitor : public AstVisitor { 3044 class AstTraversalVisitor : public AstVisitor<AstTraversalVisitor> {
3003 public: 3045 public:
3004 explicit AstTraversalVisitor(Isolate* isolate); 3046 explicit AstTraversalVisitor(Isolate* isolate);
3005 explicit AstTraversalVisitor(uintptr_t stack_limit); 3047 explicit AstTraversalVisitor(uintptr_t stack_limit);
3006 virtual ~AstTraversalVisitor() {} 3048 virtual ~AstTraversalVisitor() {}
3007 3049
3008 // Iteration left-to-right. 3050 // Iteration left-to-right.
3009 void VisitDeclarations(ZoneList<Declaration*>* declarations) override; 3051 void VisitDeclarations(ZoneList<Declaration*>* declarations);
3010 void VisitStatements(ZoneList<Statement*>* statements) override; 3052 void VisitStatements(ZoneList<Statement*>* statements);
3011 3053
3012 // Individual nodes 3054 // Individual nodes
3013 #define DECLARE_VISIT(type) void Visit##type(type* node) override; 3055 #define DECLARE_VISIT(type) virtual void Visit##type(type* node);
3014 AST_NODE_LIST(DECLARE_VISIT) 3056 AST_NODE_LIST(DECLARE_VISIT)
3015 #undef DECLARE_VISIT 3057 #undef DECLARE_VISIT
3016 3058
3017 protected: 3059 protected:
3018 int depth() { return depth_; } 3060 int depth() { return depth_; }
3019 3061
3020 private: 3062 private:
3021 DEFINE_AST_VISITOR_SUBCLASS_MEMBERS(); 3063 DEFINE_AST_VISITOR_SUBCLASS_MEMBERS();
3022 3064
3023 int depth_; 3065 int depth_;
(...skipping 492 matching lines...) Expand 10 before | Expand all | Expand 10 after
3516 : NULL; \ 3558 : NULL; \
3517 } 3559 }
3518 AST_NODE_LIST(DECLARE_NODE_FUNCTIONS) 3560 AST_NODE_LIST(DECLARE_NODE_FUNCTIONS)
3519 #undef DECLARE_NODE_FUNCTIONS 3561 #undef DECLARE_NODE_FUNCTIONS
3520 3562
3521 3563
3522 } // namespace internal 3564 } // namespace internal
3523 } // namespace v8 3565 } // namespace v8
3524 3566
3525 #endif // V8_AST_AST_H_ 3567 #endif // V8_AST_AST_H_
OLDNEW
« no previous file with comments | « src/asmjs/typing-asm.h ('k') | src/ast/ast.cc » ('j') | src/ast/ast.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698