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

Side by Side Diff: src/ast.h

Issue 9221011: Collect AstNode type information (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: refactor to AstVisitor approach Created 8 years, 10 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | src/ast.cc » ('j') | src/objects.h » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 21 matching lines...) Expand all
32 32
33 #include "assembler.h" 33 #include "assembler.h"
34 #include "factory.h" 34 #include "factory.h"
35 #include "isolate.h" 35 #include "isolate.h"
36 #include "jsregexp.h" 36 #include "jsregexp.h"
37 #include "list-inl.h" 37 #include "list-inl.h"
38 #include "runtime.h" 38 #include "runtime.h"
39 #include "small-pointer-list.h" 39 #include "small-pointer-list.h"
40 #include "smart-array-pointer.h" 40 #include "smart-array-pointer.h"
41 #include "token.h" 41 #include "token.h"
42 #include "utils.h"
42 #include "variables.h" 43 #include "variables.h"
43 #include "zone-inl.h" 44 #include "zone-inl.h"
44 45
45 namespace v8 { 46 namespace v8 {
46 namespace internal { 47 namespace internal {
47 48
48 // The abstract syntax tree is an intermediate, light-weight 49 // The abstract syntax tree is an intermediate, light-weight
49 // representation of the parsed JavaScript code suitable for 50 // representation of the parsed JavaScript code suitable for
50 // compilation to native code. 51 // compilation to native code.
51 52
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 V(BinaryOperation) \ 97 V(BinaryOperation) \
97 V(CompareOperation) \ 98 V(CompareOperation) \
98 V(ThisFunction) 99 V(ThisFunction)
99 100
100 #define AST_NODE_LIST(V) \ 101 #define AST_NODE_LIST(V) \
101 V(Declaration) \ 102 V(Declaration) \
102 STATEMENT_NODE_LIST(V) \ 103 STATEMENT_NODE_LIST(V) \
103 EXPRESSION_NODE_LIST(V) 104 EXPRESSION_NODE_LIST(V)
104 105
105 // Forward declarations 106 // Forward declarations
107 class AstConstructionVisitor;
108 class AstNodeFactory;
109 class AstProperties;
106 class AstVisitor; 110 class AstVisitor;
107 class BreakableStatement; 111 class BreakableStatement;
108 class Expression; 112 class Expression;
109 class IterationStatement; 113 class IterationStatement;
110 class MaterializedLiteral; 114 class MaterializedLiteral;
111 class Statement; 115 class Statement;
112 class TargetCollector; 116 class TargetCollector;
113 class TypeFeedbackOracle; 117 class TypeFeedbackOracle;
114 118
115 class RegExpAlternative; 119 class RegExpAlternative;
(...skipping 13 matching lines...) Expand all
129 AST_NODE_LIST(DEF_FORWARD_DECLARATION) 133 AST_NODE_LIST(DEF_FORWARD_DECLARATION)
130 #undef DEF_FORWARD_DECLARATION 134 #undef DEF_FORWARD_DECLARATION
131 135
132 136
133 // Typedef only introduced to avoid unreadable code. 137 // Typedef only introduced to avoid unreadable code.
134 // Please do appreciate the required space in "> >". 138 // Please do appreciate the required space in "> >".
135 typedef ZoneList<Handle<String> > ZoneStringList; 139 typedef ZoneList<Handle<String> > ZoneStringList;
136 typedef ZoneList<Handle<Object> > ZoneObjectList; 140 typedef ZoneList<Handle<Object> > ZoneObjectList;
137 141
138 142
143 #define DECLARE_NODE_TYPE(type) \
144 virtual void Accept(AstVisitor* v); \
145 virtual AstNode::Type node_type() const { return AstNode::k##type; } \
146
147
139 class AstNode: public ZoneObject { 148 class AstNode: public ZoneObject {
140 public: 149 public:
141 #define DECLARE_TYPE_ENUM(type) k##type, 150 #define DECLARE_TYPE_ENUM(type) k##type,
142 enum Type { 151 enum Type {
143 AST_NODE_LIST(DECLARE_TYPE_ENUM) 152 AST_NODE_LIST(DECLARE_TYPE_ENUM)
144 kInvalid = -1 153 kInvalid = -1
145 }; 154 };
146 #undef DECLARE_TYPE_ENUM 155 #undef DECLARE_TYPE_ENUM
147 156
148 static const int kNoNumber = -1; 157 static const int kNoNumber = -1;
149 static const int kFunctionEntryId = 2; // Using 0 could disguise errors. 158 static const int kFunctionEntryId = 2; // Using 0 could disguise errors.
150 // This AST id identifies the point after the declarations have been 159 // This AST id identifies the point after the declarations have been
151 // visited. We need it to capture the environment effects of declarations 160 // visited. We need it to capture the environment effects of declarations
152 // that emit code (function declarations). 161 // that emit code (function declarations).
153 static const int kDeclarationsId = 3; 162 static const int kDeclarationsId = 3;
154 163
155 // Override ZoneObject's new to count allocated AST nodes.
156 void* operator new(size_t size, Zone* zone) { 164 void* operator new(size_t size, Zone* zone) {
157 Isolate* isolate = zone->isolate();
158 isolate->set_ast_node_count(isolate->ast_node_count() + 1);
159 return zone->New(static_cast<int>(size)); 165 return zone->New(static_cast<int>(size));
160 } 166 }
161 167
162 AstNode() {} 168 AstNode() { }
163 169
164 virtual ~AstNode() { } 170 virtual ~AstNode() { }
165 171
166 virtual void Accept(AstVisitor* v) = 0; 172 virtual void Accept(AstVisitor* v) = 0;
167 virtual Type node_type() const { return kInvalid; } 173 virtual Type node_type() const { return kInvalid; }
168 174
169 // Type testing & conversion functions overridden by concrete subclasses. 175 // Type testing & conversion functions overridden by concrete subclasses.
170 #define DECLARE_NODE_FUNCTIONS(type) \ 176 #define DECLARE_NODE_FUNCTIONS(type) \
171 bool Is##type() { return node_type() == AstNode::k##type; } \ 177 bool Is##type() { return node_type() == AstNode::k##type; } \
172 type* As##type() { return Is##type() ? reinterpret_cast<type*>(this) : NULL; } 178 type* As##type() { return Is##type() ? reinterpret_cast<type*>(this) : NULL; }
173 AST_NODE_LIST(DECLARE_NODE_FUNCTIONS) 179 AST_NODE_LIST(DECLARE_NODE_FUNCTIONS)
174 #undef DECLARE_NODE_FUNCTIONS 180 #undef DECLARE_NODE_FUNCTIONS
175 181
176 virtual Statement* AsStatement() { return NULL; } 182 virtual Statement* AsStatement() { return NULL; }
177 virtual Expression* AsExpression() { return NULL; } 183 virtual Expression* AsExpression() { return NULL; }
178 virtual TargetCollector* AsTargetCollector() { return NULL; } 184 virtual TargetCollector* AsTargetCollector() { return NULL; }
179 virtual BreakableStatement* AsBreakableStatement() { return NULL; } 185 virtual BreakableStatement* AsBreakableStatement() { return NULL; }
180 virtual IterationStatement* AsIterationStatement() { return NULL; } 186 virtual IterationStatement* AsIterationStatement() { return NULL; }
181 virtual MaterializedLiteral* AsMaterializedLiteral() { return NULL; } 187 virtual MaterializedLiteral* AsMaterializedLiteral() { return NULL; }
182 188
183 // True if the node is simple enough for us to inline calls containing it.
184 virtual bool IsInlineable() const = 0;
185
186 static int Count() { return Isolate::Current()->ast_node_count(); }
187 static void ResetIds() { Isolate::Current()->set_ast_node_id(0); } 189 static void ResetIds() { Isolate::Current()->set_ast_node_id(0); }
188 190
189 protected: 191 protected:
190 static unsigned GetNextId(Isolate* isolate) { 192 static unsigned GetNextId(Isolate* isolate) {
191 return ReserveIdRange(isolate, 1); 193 return ReserveIdRange(isolate, 1);
192 } 194 }
193 195
194 static unsigned ReserveIdRange(Isolate* isolate, int n) { 196 static unsigned ReserveIdRange(Isolate* isolate, int n) {
195 unsigned tmp = isolate->ast_node_id(); 197 unsigned tmp = isolate->ast_node_id();
196 isolate->set_ast_node_id(tmp + n); 198 isolate->set_ast_node_id(tmp + n);
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
369 ZoneStringList* labels_; 371 ZoneStringList* labels_;
370 Type type_; 372 Type type_;
371 Label break_target_; 373 Label break_target_;
372 int entry_id_; 374 int entry_id_;
373 int exit_id_; 375 int exit_id_;
374 }; 376 };
375 377
376 378
377 class Block: public BreakableStatement { 379 class Block: public BreakableStatement {
378 public: 380 public:
379 Block(Isolate* isolate,
380 ZoneStringList* labels,
381 int capacity,
382 bool is_initializer_block)
383 : BreakableStatement(isolate, labels, TARGET_FOR_NAMED_ONLY),
384 statements_(capacity),
385 is_initializer_block_(is_initializer_block),
386 block_scope_(NULL) {
387 }
388
389
390 DECLARE_NODE_TYPE(Block) 381 DECLARE_NODE_TYPE(Block)
391 382
392 virtual bool IsInlineable() const;
393
394 void AddStatement(Statement* statement) { statements_.Add(statement); } 383 void AddStatement(Statement* statement) { statements_.Add(statement); }
395 384
396 ZoneList<Statement*>* statements() { return &statements_; } 385 ZoneList<Statement*>* statements() { return &statements_; }
397 bool is_initializer_block() const { return is_initializer_block_; } 386 bool is_initializer_block() const { return is_initializer_block_; }
398 387
399 Scope* block_scope() const { return block_scope_; } 388 Scope* block_scope() const { return block_scope_; }
400 void set_block_scope(Scope* block_scope) { block_scope_ = block_scope; } 389 void set_block_scope(Scope* block_scope) { block_scope_ = block_scope; }
401 390
391 protected:
392 friend class AstNodeFactory;
393
394 Block(Isolate* isolate,
395 ZoneStringList* labels,
396 int capacity,
397 bool is_initializer_block)
398 : BreakableStatement(isolate, labels, TARGET_FOR_NAMED_ONLY),
399 statements_(capacity),
400 is_initializer_block_(is_initializer_block),
401 block_scope_(NULL) {
402 }
403
402 private: 404 private:
403 ZoneList<Statement*> statements_; 405 ZoneList<Statement*> statements_;
404 bool is_initializer_block_; 406 bool is_initializer_block_;
405 Scope* block_scope_; 407 Scope* block_scope_;
406 }; 408 };
407 409
408 410
409 class Declaration: public AstNode { 411 class Declaration: public AstNode {
410 public: 412 public:
413 DECLARE_NODE_TYPE(Declaration)
414
415 VariableProxy* proxy() const { return proxy_; }
416 VariableMode mode() const { return mode_; }
417 FunctionLiteral* fun() const { return fun_; } // may be NULL
418 bool IsInlineable() const;
419 Scope* scope() const { return scope_; }
420
421 protected:
422 friend class AstNodeFactory;
423
411 Declaration(VariableProxy* proxy, 424 Declaration(VariableProxy* proxy,
412 VariableMode mode, 425 VariableMode mode,
413 FunctionLiteral* fun, 426 FunctionLiteral* fun,
414 Scope* scope) 427 Scope* scope)
415 : proxy_(proxy), 428 : proxy_(proxy),
416 mode_(mode), 429 mode_(mode),
417 fun_(fun), 430 fun_(fun),
418 scope_(scope) { 431 scope_(scope) {
419 ASSERT(mode == VAR || 432 ASSERT(mode == VAR ||
420 mode == CONST || 433 mode == CONST ||
421 mode == CONST_HARMONY || 434 mode == CONST_HARMONY ||
422 mode == LET); 435 mode == LET);
423 // At the moment there are no "const functions"'s in JavaScript... 436 // At the moment there are no "const functions"'s in JavaScript...
424 ASSERT(fun == NULL || mode == VAR || mode == LET); 437 ASSERT(fun == NULL || mode == VAR || mode == LET);
425 } 438 }
426 439
427 DECLARE_NODE_TYPE(Declaration)
428
429 VariableProxy* proxy() const { return proxy_; }
430 VariableMode mode() const { return mode_; }
431 FunctionLiteral* fun() const { return fun_; } // may be NULL
432 virtual bool IsInlineable() const;
433 Scope* scope() const { return scope_; }
434
435 private: 440 private:
436 VariableProxy* proxy_; 441 VariableProxy* proxy_;
437 VariableMode mode_; 442 VariableMode mode_;
438 FunctionLiteral* fun_; 443 FunctionLiteral* fun_;
439 444
440 // Nested scope from which the declaration originated. 445 // Nested scope from which the declaration originated.
441 Scope* scope_; 446 Scope* scope_;
442 }; 447 };
443 448
444 449
(...skipping 25 matching lines...) Expand all
470 475
471 private: 476 private:
472 Statement* body_; 477 Statement* body_;
473 Label continue_target_; 478 Label continue_target_;
474 int osr_entry_id_; 479 int osr_entry_id_;
475 }; 480 };
476 481
477 482
478 class DoWhileStatement: public IterationStatement { 483 class DoWhileStatement: public IterationStatement {
479 public: 484 public:
480 DoWhileStatement(Isolate* isolate, ZoneStringList* labels)
481 : IterationStatement(isolate, labels),
482 cond_(NULL),
483 condition_position_(-1),
484 continue_id_(GetNextId(isolate)),
485 back_edge_id_(GetNextId(isolate)) {
486 }
487
488 DECLARE_NODE_TYPE(DoWhileStatement) 485 DECLARE_NODE_TYPE(DoWhileStatement)
489 486
490 void Initialize(Expression* cond, Statement* body) { 487 void Initialize(Expression* cond, Statement* body) {
491 IterationStatement::Initialize(body); 488 IterationStatement::Initialize(body);
492 cond_ = cond; 489 cond_ = cond;
493 } 490 }
494 491
495 Expression* cond() const { return cond_; } 492 Expression* cond() const { return cond_; }
496 493
497 // Position where condition expression starts. We need it to make 494 // Position where condition expression starts. We need it to make
498 // the loop's condition a breakable location. 495 // the loop's condition a breakable location.
499 int condition_position() { return condition_position_; } 496 int condition_position() { return condition_position_; }
500 void set_condition_position(int pos) { condition_position_ = pos; } 497 void set_condition_position(int pos) { condition_position_ = pos; }
501 498
502 // Bailout support. 499 // Bailout support.
503 virtual int ContinueId() const { return continue_id_; } 500 virtual int ContinueId() const { return continue_id_; }
504 virtual int StackCheckId() const { return back_edge_id_; } 501 virtual int StackCheckId() const { return back_edge_id_; }
505 int BackEdgeId() const { return back_edge_id_; } 502 int BackEdgeId() const { return back_edge_id_; }
506 503
507 virtual bool IsInlineable() const; 504 protected:
505 friend class AstNodeFactory;
506
507 DoWhileStatement(Isolate* isolate, ZoneStringList* labels)
508 : IterationStatement(isolate, labels),
509 cond_(NULL),
510 condition_position_(-1),
511 continue_id_(GetNextId(isolate)),
512 back_edge_id_(GetNextId(isolate)) {
513 }
508 514
509 private: 515 private:
510 Expression* cond_; 516 Expression* cond_;
511 int condition_position_; 517 int condition_position_;
512 int continue_id_; 518 int continue_id_;
513 int back_edge_id_; 519 int back_edge_id_;
514 }; 520 };
515 521
516 522
517 class WhileStatement: public IterationStatement { 523 class WhileStatement: public IterationStatement {
518 public: 524 public:
519 WhileStatement(Isolate* isolate, ZoneStringList* labels)
520 : IterationStatement(isolate, labels),
521 cond_(NULL),
522 may_have_function_literal_(true),
523 body_id_(GetNextId(isolate)) {
524 }
525
526 DECLARE_NODE_TYPE(WhileStatement) 525 DECLARE_NODE_TYPE(WhileStatement)
527 526
528 void Initialize(Expression* cond, Statement* body) { 527 void Initialize(Expression* cond, Statement* body) {
529 IterationStatement::Initialize(body); 528 IterationStatement::Initialize(body);
530 cond_ = cond; 529 cond_ = cond;
531 } 530 }
532 531
533 Expression* cond() const { return cond_; } 532 Expression* cond() const { return cond_; }
534 bool may_have_function_literal() const { 533 bool may_have_function_literal() const {
535 return may_have_function_literal_; 534 return may_have_function_literal_;
536 } 535 }
537 void set_may_have_function_literal(bool value) { 536 void set_may_have_function_literal(bool value) {
538 may_have_function_literal_ = value; 537 may_have_function_literal_ = value;
539 } 538 }
540 virtual bool IsInlineable() const;
541 539
542 // Bailout support. 540 // Bailout support.
543 virtual int ContinueId() const { return EntryId(); } 541 virtual int ContinueId() const { return EntryId(); }
544 virtual int StackCheckId() const { return body_id_; } 542 virtual int StackCheckId() const { return body_id_; }
545 int BodyId() const { return body_id_; } 543 int BodyId() const { return body_id_; }
546 544
545 protected:
546 friend class AstNodeFactory;
547
548 WhileStatement(Isolate* isolate, ZoneStringList* labels)
549 : IterationStatement(isolate, labels),
550 cond_(NULL),
551 may_have_function_literal_(true),
552 body_id_(GetNextId(isolate)) {
553 }
554
547 private: 555 private:
548 Expression* cond_; 556 Expression* cond_;
549 // True if there is a function literal subexpression in the condition. 557 // True if there is a function literal subexpression in the condition.
550 bool may_have_function_literal_; 558 bool may_have_function_literal_;
551 int body_id_; 559 int body_id_;
552 }; 560 };
553 561
554 562
555 class ForStatement: public IterationStatement { 563 class ForStatement: public IterationStatement {
556 public: 564 public:
557 ForStatement(Isolate* isolate, ZoneStringList* labels)
558 : IterationStatement(isolate, labels),
559 init_(NULL),
560 cond_(NULL),
561 next_(NULL),
562 may_have_function_literal_(true),
563 loop_variable_(NULL),
564 continue_id_(GetNextId(isolate)),
565 body_id_(GetNextId(isolate)) {
566 }
567
568 DECLARE_NODE_TYPE(ForStatement) 565 DECLARE_NODE_TYPE(ForStatement)
569 566
570 void Initialize(Statement* init, 567 void Initialize(Statement* init,
571 Expression* cond, 568 Expression* cond,
572 Statement* next, 569 Statement* next,
573 Statement* body) { 570 Statement* body) {
574 IterationStatement::Initialize(body); 571 IterationStatement::Initialize(body);
575 init_ = init; 572 init_ = init;
576 cond_ = cond; 573 cond_ = cond;
577 next_ = next; 574 next_ = next;
(...skipping 11 matching lines...) Expand all
589 } 586 }
590 587
591 // Bailout support. 588 // Bailout support.
592 virtual int ContinueId() const { return continue_id_; } 589 virtual int ContinueId() const { return continue_id_; }
593 virtual int StackCheckId() const { return body_id_; } 590 virtual int StackCheckId() const { return body_id_; }
594 int BodyId() const { return body_id_; } 591 int BodyId() const { return body_id_; }
595 592
596 bool is_fast_smi_loop() { return loop_variable_ != NULL; } 593 bool is_fast_smi_loop() { return loop_variable_ != NULL; }
597 Variable* loop_variable() { return loop_variable_; } 594 Variable* loop_variable() { return loop_variable_; }
598 void set_loop_variable(Variable* var) { loop_variable_ = var; } 595 void set_loop_variable(Variable* var) { loop_variable_ = var; }
599 virtual bool IsInlineable() const; 596
597 protected:
598 friend class AstNodeFactory;
599
600 ForStatement(Isolate* isolate, ZoneStringList* labels)
601 : IterationStatement(isolate, labels),
602 init_(NULL),
603 cond_(NULL),
604 next_(NULL),
605 may_have_function_literal_(true),
606 loop_variable_(NULL),
607 continue_id_(GetNextId(isolate)),
608 body_id_(GetNextId(isolate)) {
609 }
600 610
601 private: 611 private:
602 Statement* init_; 612 Statement* init_;
603 Expression* cond_; 613 Expression* cond_;
604 Statement* next_; 614 Statement* next_;
605 // True if there is a function literal subexpression in the condition. 615 // True if there is a function literal subexpression in the condition.
606 bool may_have_function_literal_; 616 bool may_have_function_literal_;
607 Variable* loop_variable_; 617 Variable* loop_variable_;
608 int continue_id_; 618 int continue_id_;
609 int body_id_; 619 int body_id_;
610 }; 620 };
611 621
612 622
613 class ForInStatement: public IterationStatement { 623 class ForInStatement: public IterationStatement {
614 public: 624 public:
615 ForInStatement(Isolate* isolate, ZoneStringList* labels)
616 : IterationStatement(isolate, labels),
617 each_(NULL),
618 enumerable_(NULL),
619 assignment_id_(GetNextId(isolate)) {
620 }
621
622 DECLARE_NODE_TYPE(ForInStatement) 625 DECLARE_NODE_TYPE(ForInStatement)
623 626
624 void Initialize(Expression* each, Expression* enumerable, Statement* body) { 627 void Initialize(Expression* each, Expression* enumerable, Statement* body) {
625 IterationStatement::Initialize(body); 628 IterationStatement::Initialize(body);
626 each_ = each; 629 each_ = each;
627 enumerable_ = enumerable; 630 enumerable_ = enumerable;
628 } 631 }
629 632
630 Expression* each() const { return each_; } 633 Expression* each() const { return each_; }
631 Expression* enumerable() const { return enumerable_; } 634 Expression* enumerable() const { return enumerable_; }
632 virtual bool IsInlineable() const;
633 635
634 // Bailout support. 636 // Bailout support.
635 int AssignmentId() const { return assignment_id_; } 637 int AssignmentId() const { return assignment_id_; }
636 virtual int ContinueId() const { return EntryId(); } 638 virtual int ContinueId() const { return EntryId(); }
637 virtual int StackCheckId() const { return EntryId(); } 639 virtual int StackCheckId() const { return EntryId(); }
638 640
641 protected:
642 friend class AstNodeFactory;
643
644 ForInStatement(Isolate* isolate, ZoneStringList* labels)
645 : IterationStatement(isolate, labels),
646 each_(NULL),
647 enumerable_(NULL),
648 assignment_id_(GetNextId(isolate)) {
649 }
650
639 private: 651 private:
640 Expression* each_; 652 Expression* each_;
641 Expression* enumerable_; 653 Expression* enumerable_;
642 int assignment_id_; 654 int assignment_id_;
643 }; 655 };
644 656
645 657
646 class ExpressionStatement: public Statement { 658 class ExpressionStatement: public Statement {
647 public: 659 public:
648 explicit ExpressionStatement(Expression* expression)
649 : expression_(expression) { }
650
651 DECLARE_NODE_TYPE(ExpressionStatement) 660 DECLARE_NODE_TYPE(ExpressionStatement)
652 661
653 virtual bool IsInlineable() const;
654
655 void set_expression(Expression* e) { expression_ = e; } 662 void set_expression(Expression* e) { expression_ = e; }
656 Expression* expression() const { return expression_; } 663 Expression* expression() const { return expression_; }
657 664
665 protected:
666 friend class AstNodeFactory;
667
668 explicit ExpressionStatement(Expression* expression)
669 : expression_(expression) { }
670
658 private: 671 private:
659 Expression* expression_; 672 Expression* expression_;
660 }; 673 };
661 674
662 675
663 class ContinueStatement: public Statement { 676 class ContinueStatement: public Statement {
664 public: 677 public:
678 DECLARE_NODE_TYPE(ContinueStatement)
679
680 IterationStatement* target() const { return target_; }
681
682 protected:
683 friend class AstNodeFactory;
684
665 explicit ContinueStatement(IterationStatement* target) 685 explicit ContinueStatement(IterationStatement* target)
666 : target_(target) { } 686 : target_(target) { }
667 687
668 DECLARE_NODE_TYPE(ContinueStatement)
669
670 IterationStatement* target() const { return target_; }
671 virtual bool IsInlineable() const;
672
673 private: 688 private:
674 IterationStatement* target_; 689 IterationStatement* target_;
675 }; 690 };
676 691
677 692
678 class BreakStatement: public Statement { 693 class BreakStatement: public Statement {
679 public: 694 public:
695 DECLARE_NODE_TYPE(BreakStatement)
696
697 BreakableStatement* target() const { return target_; }
698
699 protected:
700 friend class AstNodeFactory;
701
680 explicit BreakStatement(BreakableStatement* target) 702 explicit BreakStatement(BreakableStatement* target)
681 : target_(target) { } 703 : target_(target) { }
682 704
683 DECLARE_NODE_TYPE(BreakStatement)
684
685 BreakableStatement* target() const { return target_; }
686 virtual bool IsInlineable() const;
687
688 private: 705 private:
689 BreakableStatement* target_; 706 BreakableStatement* target_;
690 }; 707 };
691 708
692 709
693 class ReturnStatement: public Statement { 710 class ReturnStatement: public Statement {
694 public: 711 public:
712 DECLARE_NODE_TYPE(ReturnStatement)
713
714 Expression* expression() const { return expression_; }
715
716 protected:
717 friend class AstNodeFactory;
718
695 explicit ReturnStatement(Expression* expression) 719 explicit ReturnStatement(Expression* expression)
696 : expression_(expression) { } 720 : expression_(expression) { }
697 721
698 DECLARE_NODE_TYPE(ReturnStatement)
699
700 Expression* expression() const { return expression_; }
701 virtual bool IsInlineable() const;
702
703 private: 722 private:
704 Expression* expression_; 723 Expression* expression_;
705 }; 724 };
706 725
707 726
708 class WithStatement: public Statement { 727 class WithStatement: public Statement {
709 public: 728 public:
710 WithStatement(Expression* expression, Statement* statement)
711 : expression_(expression), statement_(statement) { }
712
713 DECLARE_NODE_TYPE(WithStatement) 729 DECLARE_NODE_TYPE(WithStatement)
714 730
715 Expression* expression() const { return expression_; } 731 Expression* expression() const { return expression_; }
716 Statement* statement() const { return statement_; } 732 Statement* statement() const { return statement_; }
717 733
718 virtual bool IsInlineable() const; 734 protected:
735 friend class AstNodeFactory;
736
737 WithStatement(Expression* expression, Statement* statement)
738 : expression_(expression),
739 statement_(statement) { }
719 740
720 private: 741 private:
721 Expression* expression_; 742 Expression* expression_;
722 Statement* statement_; 743 Statement* statement_;
723 }; 744 };
724 745
725 746
726 class CaseClause: public ZoneObject { 747 class CaseClause: public ZoneObject {
727 public: 748 public:
728 CaseClause(Isolate* isolate, 749 CaseClause(Isolate* isolate,
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
764 OBJECT_ONLY 785 OBJECT_ONLY
765 }; 786 };
766 CompareTypeFeedback compare_type_; 787 CompareTypeFeedback compare_type_;
767 int compare_id_; 788 int compare_id_;
768 int entry_id_; 789 int entry_id_;
769 }; 790 };
770 791
771 792
772 class SwitchStatement: public BreakableStatement { 793 class SwitchStatement: public BreakableStatement {
773 public: 794 public:
774 SwitchStatement(Isolate* isolate, ZoneStringList* labels)
775 : BreakableStatement(isolate, labels, TARGET_FOR_ANONYMOUS),
776 tag_(NULL),
777 cases_(NULL) {
778 }
779
780
781 DECLARE_NODE_TYPE(SwitchStatement) 795 DECLARE_NODE_TYPE(SwitchStatement)
782 796
783 void Initialize(Expression* tag, ZoneList<CaseClause*>* cases) { 797 void Initialize(Expression* tag, ZoneList<CaseClause*>* cases) {
784 tag_ = tag; 798 tag_ = tag;
785 cases_ = cases; 799 cases_ = cases;
786 } 800 }
787 801
788 Expression* tag() const { return tag_; } 802 Expression* tag() const { return tag_; }
789 ZoneList<CaseClause*>* cases() const { return cases_; } 803 ZoneList<CaseClause*>* cases() const { return cases_; }
790 virtual bool IsInlineable() const; 804
805 protected:
806 friend class AstNodeFactory;
807
808 SwitchStatement(Isolate* isolate, ZoneStringList* labels)
809 : BreakableStatement(isolate, labels, TARGET_FOR_ANONYMOUS),
810 tag_(NULL),
811 cases_(NULL) { }
791 812
792 private: 813 private:
793 Expression* tag_; 814 Expression* tag_;
794 ZoneList<CaseClause*>* cases_; 815 ZoneList<CaseClause*>* cases_;
795 }; 816 };
796 817
797 818
798 // If-statements always have non-null references to their then- and 819 // If-statements always have non-null references to their then- and
799 // else-parts. When parsing if-statements with no explicit else-part, 820 // else-parts. When parsing if-statements with no explicit else-part,
800 // the parser implicitly creates an empty statement. Use the 821 // the parser implicitly creates an empty statement. Use the
801 // HasThenStatement() and HasElseStatement() functions to check if a 822 // HasThenStatement() and HasElseStatement() functions to check if a
802 // given if-statement has a then- or an else-part containing code. 823 // given if-statement has a then- or an else-part containing code.
803 class IfStatement: public Statement { 824 class IfStatement: public Statement {
804 public: 825 public:
805 IfStatement(Isolate* isolate,
806 Expression* condition,
807 Statement* then_statement,
808 Statement* else_statement)
809 : condition_(condition),
810 then_statement_(then_statement),
811 else_statement_(else_statement),
812 if_id_(GetNextId(isolate)),
813 then_id_(GetNextId(isolate)),
814 else_id_(GetNextId(isolate)) {
815 }
816
817 DECLARE_NODE_TYPE(IfStatement) 826 DECLARE_NODE_TYPE(IfStatement)
818 827
819 virtual bool IsInlineable() const;
820
821 bool HasThenStatement() const { return !then_statement()->IsEmpty(); } 828 bool HasThenStatement() const { return !then_statement()->IsEmpty(); }
822 bool HasElseStatement() const { return !else_statement()->IsEmpty(); } 829 bool HasElseStatement() const { return !else_statement()->IsEmpty(); }
823 830
824 Expression* condition() const { return condition_; } 831 Expression* condition() const { return condition_; }
825 Statement* then_statement() const { return then_statement_; } 832 Statement* then_statement() const { return then_statement_; }
826 Statement* else_statement() const { return else_statement_; } 833 Statement* else_statement() const { return else_statement_; }
827 834
828 int IfId() const { return if_id_; } 835 int IfId() const { return if_id_; }
829 int ThenId() const { return then_id_; } 836 int ThenId() const { return then_id_; }
830 int ElseId() const { return else_id_; } 837 int ElseId() const { return else_id_; }
831 838
839 protected:
840 friend class AstNodeFactory;
841
842 IfStatement(Isolate* isolate,
843 Expression* condition,
844 Statement* then_statement,
845 Statement* else_statement)
846 : condition_(condition),
847 then_statement_(then_statement),
848 else_statement_(else_statement),
849 if_id_(GetNextId(isolate)),
850 then_id_(GetNextId(isolate)),
851 else_id_(GetNextId(isolate)) {
852 }
853
832 private: 854 private:
833 Expression* condition_; 855 Expression* condition_;
834 Statement* then_statement_; 856 Statement* then_statement_;
835 Statement* else_statement_; 857 Statement* else_statement_;
836 int if_id_; 858 int if_id_;
837 int then_id_; 859 int then_id_;
838 int else_id_; 860 int else_id_;
839 }; 861 };
840 862
841 863
842 // NOTE: TargetCollectors are represented as nodes to fit in the target 864 // NOTE: TargetCollectors are represented as nodes to fit in the target
843 // stack in the compiler; this should probably be reworked. 865 // stack in the compiler; this should probably be reworked.
844 class TargetCollector: public AstNode { 866 class TargetCollector: public AstNode {
845 public: 867 public:
846 TargetCollector(): targets_(0) { } 868 TargetCollector() : targets_(0) { }
847 869
848 // Adds a jump target to the collector. The collector stores a pointer not 870 // Adds a jump target to the collector. The collector stores a pointer not
849 // a copy of the target to make binding work, so make sure not to pass in 871 // a copy of the target to make binding work, so make sure not to pass in
850 // references to something on the stack. 872 // references to something on the stack.
851 void AddTarget(Label* target); 873 void AddTarget(Label* target);
852 874
853 // Virtual behaviour. TargetCollectors are never part of the AST. 875 // Virtual behaviour. TargetCollectors are never part of the AST.
854 virtual void Accept(AstVisitor* v) { UNREACHABLE(); } 876 virtual void Accept(AstVisitor* v) { UNREACHABLE(); }
855 virtual TargetCollector* AsTargetCollector() { return this; } 877 virtual TargetCollector* AsTargetCollector() { return this; }
856 878
857 ZoneList<Label*>* targets() { return &targets_; } 879 ZoneList<Label*>* targets() { return &targets_; }
858 virtual bool IsInlineable() const;
859 880
860 private: 881 private:
861 ZoneList<Label*> targets_; 882 ZoneList<Label*> targets_;
862 }; 883 };
863 884
864 885
865 class TryStatement: public Statement { 886 class TryStatement: public Statement {
866 public: 887 public:
867 explicit TryStatement(int index, Block* try_block)
868 : index_(index),
869 try_block_(try_block),
870 escaping_targets_(NULL) {
871 }
872
873 void set_escaping_targets(ZoneList<Label*>* targets) { 888 void set_escaping_targets(ZoneList<Label*>* targets) {
874 escaping_targets_ = targets; 889 escaping_targets_ = targets;
875 } 890 }
876 891
877 int index() const { return index_; } 892 int index() const { return index_; }
878 Block* try_block() const { return try_block_; } 893 Block* try_block() const { return try_block_; }
879 ZoneList<Label*>* escaping_targets() const { return escaping_targets_; } 894 ZoneList<Label*>* escaping_targets() const { return escaping_targets_; }
880 virtual bool IsInlineable() const; 895
896 protected:
897 TryStatement(int index, Block* try_block)
898 : index_(index),
899 try_block_(try_block),
900 escaping_targets_(NULL) { }
881 901
882 private: 902 private:
883 // Unique (per-function) index of this handler. This is not an AST ID. 903 // Unique (per-function) index of this handler. This is not an AST ID.
884 int index_; 904 int index_;
885 905
886 Block* try_block_; 906 Block* try_block_;
887 ZoneList<Label*>* escaping_targets_; 907 ZoneList<Label*>* escaping_targets_;
888 }; 908 };
889 909
890 910
891 class TryCatchStatement: public TryStatement { 911 class TryCatchStatement: public TryStatement {
892 public: 912 public:
913 DECLARE_NODE_TYPE(TryCatchStatement)
914
915 Scope* scope() { return scope_; }
916 Variable* variable() { return variable_; }
917 Block* catch_block() const { return catch_block_; }
918
919 protected:
920 friend class AstNodeFactory;
921
893 TryCatchStatement(int index, 922 TryCatchStatement(int index,
894 Block* try_block, 923 Block* try_block,
895 Scope* scope, 924 Scope* scope,
896 Variable* variable, 925 Variable* variable,
897 Block* catch_block) 926 Block* catch_block)
898 : TryStatement(index, try_block), 927 : TryStatement(index, try_block),
899 scope_(scope), 928 scope_(scope),
900 variable_(variable), 929 variable_(variable),
901 catch_block_(catch_block) { 930 catch_block_(catch_block) {
902 } 931 }
903 932
904 DECLARE_NODE_TYPE(TryCatchStatement)
905
906 Scope* scope() { return scope_; }
907 Variable* variable() { return variable_; }
908 Block* catch_block() const { return catch_block_; }
909 virtual bool IsInlineable() const;
910
911 private: 933 private:
912 Scope* scope_; 934 Scope* scope_;
913 Variable* variable_; 935 Variable* variable_;
914 Block* catch_block_; 936 Block* catch_block_;
915 }; 937 };
916 938
917 939
918 class TryFinallyStatement: public TryStatement { 940 class TryFinallyStatement: public TryStatement {
919 public: 941 public:
942 DECLARE_NODE_TYPE(TryFinallyStatement)
943
944 Block* finally_block() const { return finally_block_; }
945
946 protected:
947 friend class AstNodeFactory;
948
920 TryFinallyStatement(int index, Block* try_block, Block* finally_block) 949 TryFinallyStatement(int index, Block* try_block, Block* finally_block)
921 : TryStatement(index, try_block), 950 : TryStatement(index, try_block),
922 finally_block_(finally_block) { } 951 finally_block_(finally_block) { }
923 952
924 DECLARE_NODE_TYPE(TryFinallyStatement)
925
926 Block* finally_block() const { return finally_block_; }
927 virtual bool IsInlineable() const;
928
929 private: 953 private:
930 Block* finally_block_; 954 Block* finally_block_;
931 }; 955 };
932 956
933 957
934 class DebuggerStatement: public Statement { 958 class DebuggerStatement: public Statement {
935 public: 959 public:
936 DECLARE_NODE_TYPE(DebuggerStatement) 960 DECLARE_NODE_TYPE(DebuggerStatement)
937 virtual bool IsInlineable() const; 961
962 protected:
963 friend class AstNodeFactory;
964
965 DebuggerStatement() {}
938 }; 966 };
939 967
940 968
941 class EmptyStatement: public Statement { 969 class EmptyStatement: public Statement {
942 public: 970 public:
943 DECLARE_NODE_TYPE(EmptyStatement) 971 DECLARE_NODE_TYPE(EmptyStatement)
944 972
945 virtual bool IsInlineable() const; 973 protected:
974 friend class AstNodeFactory;
975
976 EmptyStatement() {}
946 }; 977 };
947 978
948 979
949 class Literal: public Expression { 980 class Literal: public Expression {
950 public: 981 public:
951 Literal(Isolate* isolate, Handle<Object> handle)
952 : Expression(isolate), handle_(handle) { }
953
954 DECLARE_NODE_TYPE(Literal) 982 DECLARE_NODE_TYPE(Literal)
955 983
956 // Check if this literal is identical to the other literal. 984 // Check if this literal is identical to the other literal.
957 bool IsIdenticalTo(const Literal* other) const { 985 bool IsIdenticalTo(const Literal* other) const {
958 return handle_.is_identical_to(other->handle_); 986 return handle_.is_identical_to(other->handle_);
959 } 987 }
960 988
961 virtual bool IsPropertyName() { 989 virtual bool IsPropertyName() {
962 if (handle_->IsSymbol()) { 990 if (handle_->IsSymbol()) {
963 uint32_t ignored; 991 uint32_t ignored;
(...skipping 18 matching lines...) Expand all
982 bool IsTrue() const { 1010 bool IsTrue() const {
983 ASSERT(!handle_.is_null()); 1011 ASSERT(!handle_.is_null());
984 return handle_->IsTrue(); 1012 return handle_->IsTrue();
985 } 1013 }
986 bool IsFalse() const { 1014 bool IsFalse() const {
987 ASSERT(!handle_.is_null()); 1015 ASSERT(!handle_.is_null());
988 return handle_->IsFalse(); 1016 return handle_->IsFalse();
989 } 1017 }
990 1018
991 Handle<Object> handle() const { return handle_; } 1019 Handle<Object> handle() const { return handle_; }
992 virtual bool IsInlineable() const; 1020
1021 protected:
1022 friend class AstNodeFactory;
1023
1024 Literal(Isolate* isolate, Handle<Object> handle)
1025 : Expression(isolate),
1026 handle_(handle) { }
993 1027
994 private: 1028 private:
995 Handle<Object> handle_; 1029 Handle<Object> handle_;
996 }; 1030 };
997 1031
998 1032
999 // Base class for literals that needs space in the corresponding JSFunction. 1033 // Base class for literals that needs space in the corresponding JSFunction.
1000 class MaterializedLiteral: public Expression { 1034 class MaterializedLiteral: public Expression {
1001 public: 1035 public:
1002 MaterializedLiteral(Isolate* isolate,
1003 int literal_index,
1004 bool is_simple,
1005 int depth)
1006 : Expression(isolate),
1007 literal_index_(literal_index),
1008 is_simple_(is_simple),
1009 depth_(depth) {}
1010
1011 virtual MaterializedLiteral* AsMaterializedLiteral() { return this; } 1036 virtual MaterializedLiteral* AsMaterializedLiteral() { return this; }
1012 1037
1013 int literal_index() { return literal_index_; } 1038 int literal_index() { return literal_index_; }
1014 1039
1015 // A materialized literal is simple if the values consist of only 1040 // A materialized literal is simple if the values consist of only
1016 // constants and simple object and array literals. 1041 // constants and simple object and array literals.
1017 bool is_simple() const { return is_simple_; } 1042 bool is_simple() const { return is_simple_; }
1018 1043
1019 int depth() const { return depth_; } 1044 int depth() const { return depth_; }
1020 virtual bool IsInlineable() const; 1045
1046 protected:
1047 MaterializedLiteral(Isolate* isolate,
1048 int literal_index,
1049 bool is_simple,
1050 int depth)
1051 : Expression(isolate),
1052 literal_index_(literal_index),
1053 is_simple_(is_simple),
1054 depth_(depth) {}
1021 1055
1022 private: 1056 private:
1023 int literal_index_; 1057 int literal_index_;
1024 bool is_simple_; 1058 bool is_simple_;
1025 int depth_; 1059 int depth_;
1026 }; 1060 };
1027 1061
1028 1062
1029 // An object literal has a boilerplate object that is used 1063 // An object literal has a boilerplate object that is used
1030 // for minimizing the work when constructing it at runtime. 1064 // for minimizing the work when constructing it at runtime.
1031 class ObjectLiteral: public MaterializedLiteral { 1065 class ObjectLiteral: public MaterializedLiteral {
1032 public: 1066 public:
1033 // Property is used for passing information 1067 // Property is used for passing information
1034 // about an object literal's properties from the parser 1068 // about an object literal's properties from the parser
1035 // to the code generator. 1069 // to the code generator.
1036 class Property: public ZoneObject { 1070 class Property: public ZoneObject {
1037 public: 1071 public:
1038 enum Kind { 1072 enum Kind {
1039 CONSTANT, // Property with constant value (compile time). 1073 CONSTANT, // Property with constant value (compile time).
1040 COMPUTED, // Property with computed value (execution time). 1074 COMPUTED, // Property with computed value (execution time).
1041 MATERIALIZED_LITERAL, // Property value is a materialized literal. 1075 MATERIALIZED_LITERAL, // Property value is a materialized literal.
1042 GETTER, SETTER, // Property is an accessor function. 1076 GETTER, SETTER, // Property is an accessor function.
1043 PROTOTYPE // Property is __proto__. 1077 PROTOTYPE // Property is __proto__.
1044 }; 1078 };
1045 1079
1046 Property(Literal* key, Expression* value); 1080 Property(Literal* key, Expression* value);
1047 Property(bool is_getter, FunctionLiteral* value); 1081 Property(bool is_getter, FunctionLiteral* value, AstNodeFactory* factory);
1048 1082
1049 Literal* key() { return key_; } 1083 Literal* key() { return key_; }
1050 Expression* value() { return value_; } 1084 Expression* value() { return value_; }
1051 Kind kind() { return kind_; } 1085 Kind kind() { return kind_; }
1052 1086
1053 bool IsCompileTimeValue(); 1087 bool IsCompileTimeValue();
1054 1088
1055 void set_emit_store(bool emit_store); 1089 void set_emit_store(bool emit_store);
1056 bool emit_store(); 1090 bool emit_store();
1057 1091
1058 private: 1092 private:
1059 Literal* key_; 1093 Literal* key_;
1060 Expression* value_; 1094 Expression* value_;
1061 Kind kind_; 1095 Kind kind_;
1062 bool emit_store_; 1096 bool emit_store_;
1063 }; 1097 };
1064 1098
1065 ObjectLiteral(Isolate* isolate,
1066 Handle<FixedArray> constant_properties,
1067 ZoneList<Property*>* properties,
1068 int literal_index,
1069 bool is_simple,
1070 bool fast_elements,
1071 int depth,
1072 bool has_function)
1073 : MaterializedLiteral(isolate, literal_index, is_simple, depth),
1074 constant_properties_(constant_properties),
1075 properties_(properties),
1076 fast_elements_(fast_elements),
1077 has_function_(has_function) {}
1078
1079 DECLARE_NODE_TYPE(ObjectLiteral) 1099 DECLARE_NODE_TYPE(ObjectLiteral)
1080 1100
1081 Handle<FixedArray> constant_properties() const { 1101 Handle<FixedArray> constant_properties() const {
1082 return constant_properties_; 1102 return constant_properties_;
1083 } 1103 }
1084 ZoneList<Property*>* properties() const { return properties_; } 1104 ZoneList<Property*>* properties() const { return properties_; }
1085 1105
1086 bool fast_elements() const { return fast_elements_; } 1106 bool fast_elements() const { return fast_elements_; }
1087 1107
1088 bool has_function() { return has_function_; } 1108 bool has_function() { return has_function_; }
1089 1109
1090 // Mark all computed expressions that are bound to a key that 1110 // Mark all computed expressions that are bound to a key that
1091 // is shadowed by a later occurrence of the same key. For the 1111 // is shadowed by a later occurrence of the same key. For the
1092 // marked expressions, no store code is emitted. 1112 // marked expressions, no store code is emitted.
1093 void CalculateEmitStore(); 1113 void CalculateEmitStore();
1094 1114
1095 enum Flags { 1115 enum Flags {
1096 kNoFlags = 0, 1116 kNoFlags = 0,
1097 kFastElements = 1, 1117 kFastElements = 1,
1098 kHasFunction = 1 << 1 1118 kHasFunction = 1 << 1
1099 }; 1119 };
1100 1120
1121 protected:
1122 friend class AstNodeFactory;
1123
1124 ObjectLiteral(Isolate* isolate,
1125 Handle<FixedArray> constant_properties,
1126 ZoneList<Property*>* properties,
1127 int literal_index,
1128 bool is_simple,
1129 bool fast_elements,
1130 int depth,
1131 bool has_function)
1132 : MaterializedLiteral(isolate, literal_index, is_simple, depth),
1133 constant_properties_(constant_properties),
1134 properties_(properties),
1135 fast_elements_(fast_elements),
1136 has_function_(has_function) {}
1137
1101 private: 1138 private:
1102 Handle<FixedArray> constant_properties_; 1139 Handle<FixedArray> constant_properties_;
1103 ZoneList<Property*>* properties_; 1140 ZoneList<Property*>* properties_;
1104 bool fast_elements_; 1141 bool fast_elements_;
1105 bool has_function_; 1142 bool has_function_;
1106 }; 1143 };
1107 1144
1108 1145
1109 // Node for capturing a regexp literal. 1146 // Node for capturing a regexp literal.
1110 class RegExpLiteral: public MaterializedLiteral { 1147 class RegExpLiteral: public MaterializedLiteral {
1111 public: 1148 public:
1149 DECLARE_NODE_TYPE(RegExpLiteral)
1150
1151 Handle<String> pattern() const { return pattern_; }
1152 Handle<String> flags() const { return flags_; }
1153
1154 protected:
1155 friend class AstNodeFactory;
1156
1112 RegExpLiteral(Isolate* isolate, 1157 RegExpLiteral(Isolate* isolate,
1113 Handle<String> pattern, 1158 Handle<String> pattern,
1114 Handle<String> flags, 1159 Handle<String> flags,
1115 int literal_index) 1160 int literal_index)
1116 : MaterializedLiteral(isolate, literal_index, false, 1), 1161 : MaterializedLiteral(isolate, literal_index, false, 1),
1117 pattern_(pattern), 1162 pattern_(pattern),
1118 flags_(flags) {} 1163 flags_(flags) {}
1119 1164
1120 DECLARE_NODE_TYPE(RegExpLiteral)
1121
1122 Handle<String> pattern() const { return pattern_; }
1123 Handle<String> flags() const { return flags_; }
1124
1125 private: 1165 private:
1126 Handle<String> pattern_; 1166 Handle<String> pattern_;
1127 Handle<String> flags_; 1167 Handle<String> flags_;
1128 }; 1168 };
1129 1169
1130 // An array literal has a literals object that is used 1170 // An array literal has a literals object that is used
1131 // for minimizing the work when constructing it at runtime. 1171 // for minimizing the work when constructing it at runtime.
1132 class ArrayLiteral: public MaterializedLiteral { 1172 class ArrayLiteral: public MaterializedLiteral {
1133 public: 1173 public:
1174 DECLARE_NODE_TYPE(ArrayLiteral)
1175
1176 Handle<FixedArray> constant_elements() const { return constant_elements_; }
1177 ZoneList<Expression*>* values() const { return values_; }
1178
1179 // Return an AST id for an element that is used in simulate instructions.
1180 int GetIdForElement(int i) { return first_element_id_ + i; }
1181
1182 protected:
1183 friend class AstNodeFactory;
1184
1134 ArrayLiteral(Isolate* isolate, 1185 ArrayLiteral(Isolate* isolate,
1135 Handle<FixedArray> constant_elements, 1186 Handle<FixedArray> constant_elements,
1136 ZoneList<Expression*>* values, 1187 ZoneList<Expression*>* values,
1137 int literal_index, 1188 int literal_index,
1138 bool is_simple, 1189 bool is_simple,
1139 int depth) 1190 int depth)
1140 : MaterializedLiteral(isolate, literal_index, is_simple, depth), 1191 : MaterializedLiteral(isolate, literal_index, is_simple, depth),
1141 constant_elements_(constant_elements), 1192 constant_elements_(constant_elements),
1142 values_(values), 1193 values_(values),
1143 first_element_id_(ReserveIdRange(isolate, values->length())) {} 1194 first_element_id_(ReserveIdRange(isolate, values->length())) {}
1144 1195
1145 DECLARE_NODE_TYPE(ArrayLiteral)
1146
1147 Handle<FixedArray> constant_elements() const { return constant_elements_; }
1148 ZoneList<Expression*>* values() const { return values_; }
1149
1150 // Return an AST id for an element that is used in simulate instructions.
1151 int GetIdForElement(int i) { return first_element_id_ + i; }
1152
1153 private: 1196 private:
1154 Handle<FixedArray> constant_elements_; 1197 Handle<FixedArray> constant_elements_;
1155 ZoneList<Expression*>* values_; 1198 ZoneList<Expression*>* values_;
1156 int first_element_id_; 1199 int first_element_id_;
1157 }; 1200 };
1158 1201
1159 1202
1160 class VariableProxy: public Expression { 1203 class VariableProxy: public Expression {
1161 public: 1204 public:
1162 VariableProxy(Isolate* isolate, Variable* var);
1163
1164 VariableProxy(Isolate* isolate,
1165 Handle<String> name,
1166 bool is_this,
1167 int position = RelocInfo::kNoPosition);
1168
1169 DECLARE_NODE_TYPE(VariableProxy) 1205 DECLARE_NODE_TYPE(VariableProxy)
1170 1206
1171 virtual bool IsValidLeftHandSide() { 1207 virtual bool IsValidLeftHandSide() {
1172 return var_ == NULL ? true : var_->IsValidLeftHandSide(); 1208 return var_ == NULL ? true : var_->IsValidLeftHandSide();
1173 } 1209 }
1174 1210
1175 virtual bool IsInlineable() const;
1176
1177 bool IsVariable(Handle<String> n) { 1211 bool IsVariable(Handle<String> n) {
1178 return !is_this() && name().is_identical_to(n); 1212 return !is_this() && name().is_identical_to(n);
1179 } 1213 }
1180 1214
1181 bool IsArguments() { return var_ != NULL && var_->is_arguments(); } 1215 bool IsArguments() { return var_ != NULL && var_->is_arguments(); }
1182 1216
1183 bool IsLValue() { 1217 bool IsLValue() {
1184 return is_lvalue_; 1218 return is_lvalue_;
1185 } 1219 }
1186 1220
1187 Handle<String> name() const { return name_; } 1221 Handle<String> name() const { return name_; }
1188 Variable* var() const { return var_; } 1222 Variable* var() const { return var_; }
1189 bool is_this() const { return is_this_; } 1223 bool is_this() const { return is_this_; }
1190 int position() const { return position_; } 1224 int position() const { return position_; }
1191 1225
1192 void MarkAsTrivial() { is_trivial_ = true; } 1226 void MarkAsTrivial() { is_trivial_ = true; }
1193 void MarkAsLValue() { is_lvalue_ = true; } 1227 void MarkAsLValue() { is_lvalue_ = true; }
1194 1228
1195 // Bind this proxy to the variable var. 1229 // Bind this proxy to the variable var.
1196 void BindTo(Variable* var); 1230 void BindTo(Variable* var);
1197 1231
1232 void set_ast_properties(AstProperties* properties) {
1233 ast_properties_ = properties;
1234 }
1235
1198 protected: 1236 protected:
1237 friend class AstNodeFactory;
1238
1239 VariableProxy(Isolate* isolate, Variable* var);
1240
1241 VariableProxy(Isolate* isolate,
1242 Handle<String> name,
1243 bool is_this,
1244 int position);
1245
1199 Handle<String> name_; 1246 Handle<String> name_;
1200 Variable* var_; // resolved variable, or NULL 1247 Variable* var_; // resolved variable, or NULL
1201 bool is_this_; 1248 bool is_this_;
1202 bool is_trivial_; 1249 bool is_trivial_;
1203 // True if this variable proxy is being used in an assignment 1250 // True if this variable proxy is being used in an assignment
1204 // or with a increment/decrement operator. 1251 // or with a increment/decrement operator.
1205 bool is_lvalue_; 1252 bool is_lvalue_;
1206 int position_; 1253 int position_;
1254 AstProperties* ast_properties_;
fschneider 2012/01/30 13:54:26 It seems quite expensive to add a pointer to each
Jakob Kummerow 2012/02/01 14:46:09 The problem is that at the time the VariableProxy
fschneider 2012/02/02 15:54:07 It seems that we only visit the VariableProxy to f
Jakob Kummerow 2012/02/03 10:06:22 Done.
1207 }; 1255 };
1208 1256
1209 1257
1210 class Property: public Expression { 1258 class Property: public Expression {
1211 public: 1259 public:
1212 Property(Isolate* isolate,
1213 Expression* obj,
1214 Expression* key,
1215 int pos)
1216 : Expression(isolate),
1217 obj_(obj),
1218 key_(key),
1219 pos_(pos),
1220 is_monomorphic_(false),
1221 is_array_length_(false),
1222 is_string_length_(false),
1223 is_string_access_(false),
1224 is_function_prototype_(false) { }
1225
1226 DECLARE_NODE_TYPE(Property) 1260 DECLARE_NODE_TYPE(Property)
1227 1261
1228 virtual bool IsValidLeftHandSide() { return true; } 1262 virtual bool IsValidLeftHandSide() { return true; }
1229 virtual bool IsInlineable() const;
1230 1263
1231 Expression* obj() const { return obj_; } 1264 Expression* obj() const { return obj_; }
1232 Expression* key() const { return key_; } 1265 Expression* key() const { return key_; }
1233 virtual int position() const { return pos_; } 1266 virtual int position() const { return pos_; }
1234 1267
1235 bool IsStringLength() const { return is_string_length_; } 1268 bool IsStringLength() const { return is_string_length_; }
1236 bool IsStringAccess() const { return is_string_access_; } 1269 bool IsStringAccess() const { return is_string_access_; }
1237 bool IsFunctionPrototype() const { return is_function_prototype_; } 1270 bool IsFunctionPrototype() const { return is_function_prototype_; }
1238 1271
1239 // Type feedback information. 1272 // Type feedback information.
1240 void RecordTypeFeedback(TypeFeedbackOracle* oracle); 1273 void RecordTypeFeedback(TypeFeedbackOracle* oracle);
1241 virtual bool IsMonomorphic() { return is_monomorphic_; } 1274 virtual bool IsMonomorphic() { return is_monomorphic_; }
1242 virtual SmallMapList* GetReceiverTypes() { return &receiver_types_; } 1275 virtual SmallMapList* GetReceiverTypes() { return &receiver_types_; }
1243 bool IsArrayLength() { return is_array_length_; } 1276 bool IsArrayLength() { return is_array_length_; }
1244 1277
1278 protected:
1279 friend class AstNodeFactory;
1280
1281 Property(Isolate* isolate,
1282 Expression* obj,
1283 Expression* key,
1284 int pos)
1285 : Expression(isolate),
1286 obj_(obj),
1287 key_(key),
1288 pos_(pos),
1289 is_monomorphic_(false),
1290 is_array_length_(false),
1291 is_string_length_(false),
1292 is_string_access_(false),
1293 is_function_prototype_(false) { }
1294
1245 private: 1295 private:
1246 Expression* obj_; 1296 Expression* obj_;
1247 Expression* key_; 1297 Expression* key_;
1248 int pos_; 1298 int pos_;
1249 1299
1250 SmallMapList receiver_types_; 1300 SmallMapList receiver_types_;
1251 bool is_monomorphic_ : 1; 1301 bool is_monomorphic_ : 1;
1252 bool is_array_length_ : 1; 1302 bool is_array_length_ : 1;
1253 bool is_string_length_ : 1; 1303 bool is_string_length_ : 1;
1254 bool is_string_access_ : 1; 1304 bool is_string_access_ : 1;
1255 bool is_function_prototype_ : 1; 1305 bool is_function_prototype_ : 1;
1256 }; 1306 };
1257 1307
1258 1308
1259 class Call: public Expression { 1309 class Call: public Expression {
1260 public: 1310 public:
1261 Call(Isolate* isolate,
1262 Expression* expression,
1263 ZoneList<Expression*>* arguments,
1264 int pos)
1265 : Expression(isolate),
1266 expression_(expression),
1267 arguments_(arguments),
1268 pos_(pos),
1269 is_monomorphic_(false),
1270 check_type_(RECEIVER_MAP_CHECK),
1271 return_id_(GetNextId(isolate)) {
1272 }
1273
1274 DECLARE_NODE_TYPE(Call) 1311 DECLARE_NODE_TYPE(Call)
1275 1312
1276 virtual bool IsInlineable() const;
1277
1278 Expression* expression() const { return expression_; } 1313 Expression* expression() const { return expression_; }
1279 ZoneList<Expression*>* arguments() const { return arguments_; } 1314 ZoneList<Expression*>* arguments() const { return arguments_; }
1280 virtual int position() const { return pos_; } 1315 virtual int position() const { return pos_; }
1281 1316
1282 void RecordTypeFeedback(TypeFeedbackOracle* oracle, 1317 void RecordTypeFeedback(TypeFeedbackOracle* oracle,
1283 CallKind call_kind); 1318 CallKind call_kind);
1284 virtual SmallMapList* GetReceiverTypes() { return &receiver_types_; } 1319 virtual SmallMapList* GetReceiverTypes() { return &receiver_types_; }
1285 virtual bool IsMonomorphic() { return is_monomorphic_; } 1320 virtual bool IsMonomorphic() { return is_monomorphic_; }
1286 CheckType check_type() const { return check_type_; } 1321 CheckType check_type() const { return check_type_; }
1287 Handle<JSFunction> target() { return target_; } 1322 Handle<JSFunction> target() { return target_; }
1288 Handle<JSObject> holder() { return holder_; } 1323 Handle<JSObject> holder() { return holder_; }
1289 Handle<JSGlobalPropertyCell> cell() { return cell_; } 1324 Handle<JSGlobalPropertyCell> cell() { return cell_; }
1290 1325
1291 bool ComputeTarget(Handle<Map> type, Handle<String> name); 1326 bool ComputeTarget(Handle<Map> type, Handle<String> name);
1292 bool ComputeGlobalTarget(Handle<GlobalObject> global, LookupResult* lookup); 1327 bool ComputeGlobalTarget(Handle<GlobalObject> global, LookupResult* lookup);
1293 1328
1294 // Bailout support. 1329 // Bailout support.
1295 int ReturnId() const { return return_id_; } 1330 int ReturnId() const { return return_id_; }
1296 1331
1297 #ifdef DEBUG 1332 #ifdef DEBUG
1298 // Used to assert that the FullCodeGenerator records the return site. 1333 // Used to assert that the FullCodeGenerator records the return site.
1299 bool return_is_recorded_; 1334 bool return_is_recorded_;
1300 #endif 1335 #endif
1301 1336
1337 protected:
1338 friend class AstNodeFactory;
1339
1340 Call(Isolate* isolate,
1341 Expression* expression,
1342 ZoneList<Expression*>* arguments,
1343 int pos)
1344 : Expression(isolate),
1345 expression_(expression),
1346 arguments_(arguments),
1347 pos_(pos),
1348 is_monomorphic_(false),
1349 check_type_(RECEIVER_MAP_CHECK),
1350 return_id_(GetNextId(isolate)) { }
1351
1302 private: 1352 private:
1303 Expression* expression_; 1353 Expression* expression_;
1304 ZoneList<Expression*>* arguments_; 1354 ZoneList<Expression*>* arguments_;
1305 int pos_; 1355 int pos_;
1306 1356
1307 bool is_monomorphic_; 1357 bool is_monomorphic_;
1308 CheckType check_type_; 1358 CheckType check_type_;
1309 SmallMapList receiver_types_; 1359 SmallMapList receiver_types_;
1310 Handle<JSFunction> target_; 1360 Handle<JSFunction> target_;
1311 Handle<JSObject> holder_; 1361 Handle<JSObject> holder_;
1312 Handle<JSGlobalPropertyCell> cell_; 1362 Handle<JSGlobalPropertyCell> cell_;
1313 1363
1314 int return_id_; 1364 int return_id_;
1315 }; 1365 };
1316 1366
1317 1367
1318 class CallNew: public Expression { 1368 class CallNew: public Expression {
1319 public: 1369 public:
1370 DECLARE_NODE_TYPE(CallNew)
1371
1372 Expression* expression() const { return expression_; }
1373 ZoneList<Expression*>* arguments() const { return arguments_; }
1374 virtual int position() const { return pos_; }
1375
1376 protected:
1377 friend class AstNodeFactory;
1378
1320 CallNew(Isolate* isolate, 1379 CallNew(Isolate* isolate,
1321 Expression* expression, 1380 Expression* expression,
1322 ZoneList<Expression*>* arguments, 1381 ZoneList<Expression*>* arguments,
1323 int pos) 1382 int pos)
1324 : Expression(isolate), 1383 : Expression(isolate),
1325 expression_(expression), 1384 expression_(expression),
1326 arguments_(arguments), 1385 arguments_(arguments),
1327 pos_(pos) { } 1386 pos_(pos) { }
1328 1387
1329 DECLARE_NODE_TYPE(CallNew)
1330
1331 virtual bool IsInlineable() const;
1332
1333 Expression* expression() const { return expression_; }
1334 ZoneList<Expression*>* arguments() const { return arguments_; }
1335 virtual int position() const { return pos_; }
1336
1337 private: 1388 private:
1338 Expression* expression_; 1389 Expression* expression_;
1339 ZoneList<Expression*>* arguments_; 1390 ZoneList<Expression*>* arguments_;
1340 int pos_; 1391 int pos_;
1341 }; 1392 };
1342 1393
1343 1394
1344 // The CallRuntime class does not represent any official JavaScript 1395 // The CallRuntime class does not represent any official JavaScript
1345 // language construct. Instead it is used to call a C or JS function 1396 // language construct. Instead it is used to call a C or JS function
1346 // with a set of arguments. This is used from the builtins that are 1397 // with a set of arguments. This is used from the builtins that are
1347 // implemented in JavaScript (see "v8natives.js"). 1398 // implemented in JavaScript (see "v8natives.js").
1348 class CallRuntime: public Expression { 1399 class CallRuntime: public Expression {
1349 public: 1400 public:
1401 DECLARE_NODE_TYPE(CallRuntime)
1402
1403 Handle<String> name() const { return name_; }
1404 const Runtime::Function* function() const { return function_; }
1405 ZoneList<Expression*>* arguments() const { return arguments_; }
1406 bool is_jsruntime() const { return function_ == NULL; }
1407
1408 protected:
1409 friend class AstNodeFactory;
1410
1350 CallRuntime(Isolate* isolate, 1411 CallRuntime(Isolate* isolate,
1351 Handle<String> name, 1412 Handle<String> name,
1352 const Runtime::Function* function, 1413 const Runtime::Function* function,
1353 ZoneList<Expression*>* arguments) 1414 ZoneList<Expression*>* arguments)
1354 : Expression(isolate), 1415 : Expression(isolate),
1355 name_(name), 1416 name_(name),
1356 function_(function), 1417 function_(function),
1357 arguments_(arguments) { } 1418 arguments_(arguments) { }
1358 1419
1359 DECLARE_NODE_TYPE(CallRuntime)
1360
1361 virtual bool IsInlineable() const;
1362
1363 Handle<String> name() const { return name_; }
1364 const Runtime::Function* function() const { return function_; }
1365 ZoneList<Expression*>* arguments() const { return arguments_; }
1366 bool is_jsruntime() const { return function_ == NULL; }
1367
1368 private: 1420 private:
1369 Handle<String> name_; 1421 Handle<String> name_;
1370 const Runtime::Function* function_; 1422 const Runtime::Function* function_;
1371 ZoneList<Expression*>* arguments_; 1423 ZoneList<Expression*>* arguments_;
1372 }; 1424 };
1373 1425
1374 1426
1375 class UnaryOperation: public Expression { 1427 class UnaryOperation: public Expression {
1376 public: 1428 public:
1429 DECLARE_NODE_TYPE(UnaryOperation)
1430
1431 virtual bool ResultOverwriteAllowed();
1432
1433 Token::Value op() const { return op_; }
1434 Expression* expression() const { return expression_; }
1435 virtual int position() const { return pos_; }
1436
1437 int MaterializeTrueId() { return materialize_true_id_; }
1438 int MaterializeFalseId() { return materialize_false_id_; }
1439
1440 protected:
1441 friend class AstNodeFactory;
1442
1377 UnaryOperation(Isolate* isolate, 1443 UnaryOperation(Isolate* isolate,
1378 Token::Value op, 1444 Token::Value op,
1379 Expression* expression, 1445 Expression* expression,
1380 int pos) 1446 int pos)
1381 : Expression(isolate), 1447 : Expression(isolate),
1382 op_(op), 1448 op_(op),
1383 expression_(expression), 1449 expression_(expression),
1384 pos_(pos), 1450 pos_(pos),
1385 materialize_true_id_(AstNode::kNoNumber), 1451 materialize_true_id_(AstNode::kNoNumber),
1386 materialize_false_id_(AstNode::kNoNumber) { 1452 materialize_false_id_(AstNode::kNoNumber) {
1387 ASSERT(Token::IsUnaryOp(op)); 1453 ASSERT(Token::IsUnaryOp(op));
1388 if (op == Token::NOT) { 1454 if (op == Token::NOT) {
1389 materialize_true_id_ = GetNextId(isolate); 1455 materialize_true_id_ = GetNextId(isolate);
1390 materialize_false_id_ = GetNextId(isolate); 1456 materialize_false_id_ = GetNextId(isolate);
1391 } 1457 }
1392 } 1458 }
1393 1459
1394 DECLARE_NODE_TYPE(UnaryOperation)
1395
1396 virtual bool IsInlineable() const;
1397
1398 virtual bool ResultOverwriteAllowed();
1399
1400 Token::Value op() const { return op_; }
1401 Expression* expression() const { return expression_; }
1402 virtual int position() const { return pos_; }
1403
1404 int MaterializeTrueId() { return materialize_true_id_; }
1405 int MaterializeFalseId() { return materialize_false_id_; }
1406
1407 private: 1460 private:
1408 Token::Value op_; 1461 Token::Value op_;
1409 Expression* expression_; 1462 Expression* expression_;
1410 int pos_; 1463 int pos_;
1411 1464
1412 // For unary not (Token::NOT), the AST ids where true and false will 1465 // For unary not (Token::NOT), the AST ids where true and false will
1413 // actually be materialized, respectively. 1466 // actually be materialized, respectively.
1414 int materialize_true_id_; 1467 int materialize_true_id_;
1415 int materialize_false_id_; 1468 int materialize_false_id_;
1416 }; 1469 };
1417 1470
1418 1471
1419 class BinaryOperation: public Expression { 1472 class BinaryOperation: public Expression {
1420 public: 1473 public:
1421 BinaryOperation(Isolate* isolate,
1422 Token::Value op,
1423 Expression* left,
1424 Expression* right,
1425 int pos)
1426 : Expression(isolate), op_(op), left_(left), right_(right), pos_(pos) {
1427 ASSERT(Token::IsBinaryOp(op));
1428 right_id_ = (op == Token::AND || op == Token::OR)
1429 ? static_cast<int>(GetNextId(isolate))
1430 : AstNode::kNoNumber;
1431 }
1432
1433 DECLARE_NODE_TYPE(BinaryOperation) 1474 DECLARE_NODE_TYPE(BinaryOperation)
1434 1475
1435 virtual bool IsInlineable() const;
1436
1437 virtual bool ResultOverwriteAllowed(); 1476 virtual bool ResultOverwriteAllowed();
1438 1477
1439 Token::Value op() const { return op_; } 1478 Token::Value op() const { return op_; }
1440 Expression* left() const { return left_; } 1479 Expression* left() const { return left_; }
1441 Expression* right() const { return right_; } 1480 Expression* right() const { return right_; }
1442 virtual int position() const { return pos_; } 1481 virtual int position() const { return pos_; }
1443 1482
1444 // Bailout support. 1483 // Bailout support.
1445 int RightId() const { return right_id_; } 1484 int RightId() const { return right_id_; }
1446 1485
1486 protected:
1487 friend class AstNodeFactory;
1488
1489 BinaryOperation(Isolate* isolate,
1490 Token::Value op,
1491 Expression* left,
1492 Expression* right,
1493 int pos)
1494 : Expression(isolate), op_(op), left_(left), right_(right), pos_(pos) {
1495 ASSERT(Token::IsBinaryOp(op));
1496 right_id_ = (op == Token::AND || op == Token::OR)
1497 ? static_cast<int>(GetNextId(isolate))
1498 : AstNode::kNoNumber;
1499 }
1500
1447 private: 1501 private:
1448 Token::Value op_; 1502 Token::Value op_;
1449 Expression* left_; 1503 Expression* left_;
1450 Expression* right_; 1504 Expression* right_;
1451 int pos_; 1505 int pos_;
1452 // The short-circuit logical operations have an AST ID for their 1506 // The short-circuit logical operations have an AST ID for their
1453 // right-hand subexpression. 1507 // right-hand subexpression.
1454 int right_id_; 1508 int right_id_;
1455 }; 1509 };
1456 1510
1457 1511
1458 class CountOperation: public Expression { 1512 class CountOperation: public Expression {
1459 public: 1513 public:
1460 CountOperation(Isolate* isolate,
1461 Token::Value op,
1462 bool is_prefix,
1463 Expression* expr,
1464 int pos)
1465 : Expression(isolate),
1466 op_(op),
1467 is_prefix_(is_prefix),
1468 expression_(expr),
1469 pos_(pos),
1470 assignment_id_(GetNextId(isolate)),
1471 count_id_(GetNextId(isolate)) {}
1472
1473 DECLARE_NODE_TYPE(CountOperation) 1514 DECLARE_NODE_TYPE(CountOperation)
1474 1515
1475 bool is_prefix() const { return is_prefix_; } 1516 bool is_prefix() const { return is_prefix_; }
1476 bool is_postfix() const { return !is_prefix_; } 1517 bool is_postfix() const { return !is_prefix_; }
1477 1518
1478 Token::Value op() const { return op_; } 1519 Token::Value op() const { return op_; }
1479 Token::Value binary_op() { 1520 Token::Value binary_op() {
1480 return (op() == Token::INC) ? Token::ADD : Token::SUB; 1521 return (op() == Token::INC) ? Token::ADD : Token::SUB;
1481 } 1522 }
1482 1523
1483 Expression* expression() const { return expression_; } 1524 Expression* expression() const { return expression_; }
1484 virtual int position() const { return pos_; } 1525 virtual int position() const { return pos_; }
1485 1526
1486 virtual void MarkAsStatement() { is_prefix_ = true; } 1527 virtual void MarkAsStatement() { is_prefix_ = true; }
1487 1528
1488 virtual bool IsInlineable() const;
1489
1490 void RecordTypeFeedback(TypeFeedbackOracle* oracle); 1529 void RecordTypeFeedback(TypeFeedbackOracle* oracle);
1491 virtual bool IsMonomorphic() { return is_monomorphic_; } 1530 virtual bool IsMonomorphic() { return is_monomorphic_; }
1492 virtual SmallMapList* GetReceiverTypes() { return &receiver_types_; } 1531 virtual SmallMapList* GetReceiverTypes() { return &receiver_types_; }
1493 1532
1494 // Bailout support. 1533 // Bailout support.
1495 int AssignmentId() const { return assignment_id_; } 1534 int AssignmentId() const { return assignment_id_; }
1496 int CountId() const { return count_id_; } 1535 int CountId() const { return count_id_; }
1497 1536
1537 protected:
1538 friend class AstNodeFactory;
1539
1540 CountOperation(Isolate* isolate,
1541 Token::Value op,
1542 bool is_prefix,
1543 Expression* expr,
1544 int pos)
1545 : Expression(isolate),
1546 op_(op),
1547 is_prefix_(is_prefix),
1548 expression_(expr),
1549 pos_(pos),
1550 assignment_id_(GetNextId(isolate)),
1551 count_id_(GetNextId(isolate)) {}
1552
1498 private: 1553 private:
1499 Token::Value op_; 1554 Token::Value op_;
1500 bool is_prefix_; 1555 bool is_prefix_;
1501 bool is_monomorphic_; 1556 bool is_monomorphic_;
1502 Expression* expression_; 1557 Expression* expression_;
1503 int pos_; 1558 int pos_;
1504 int assignment_id_; 1559 int assignment_id_;
1505 int count_id_; 1560 int count_id_;
1506 SmallMapList receiver_types_; 1561 SmallMapList receiver_types_;
1507 }; 1562 };
1508 1563
1509 1564
1510 class CompareOperation: public Expression { 1565 class CompareOperation: public Expression {
1511 public: 1566 public:
1512 CompareOperation(Isolate* isolate,
1513 Token::Value op,
1514 Expression* left,
1515 Expression* right,
1516 int pos)
1517 : Expression(isolate),
1518 op_(op),
1519 left_(left),
1520 right_(right),
1521 pos_(pos),
1522 compare_type_(NONE) {
1523 ASSERT(Token::IsCompareOp(op));
1524 }
1525
1526 DECLARE_NODE_TYPE(CompareOperation) 1567 DECLARE_NODE_TYPE(CompareOperation)
1527 1568
1528 Token::Value op() const { return op_; } 1569 Token::Value op() const { return op_; }
1529 Expression* left() const { return left_; } 1570 Expression* left() const { return left_; }
1530 Expression* right() const { return right_; } 1571 Expression* right() const { return right_; }
1531 virtual int position() const { return pos_; } 1572 virtual int position() const { return pos_; }
1532 1573
1533 virtual bool IsInlineable() const;
1534
1535 // Type feedback information. 1574 // Type feedback information.
1536 void RecordTypeFeedback(TypeFeedbackOracle* oracle); 1575 void RecordTypeFeedback(TypeFeedbackOracle* oracle);
1537 bool IsSmiCompare() { return compare_type_ == SMI_ONLY; } 1576 bool IsSmiCompare() { return compare_type_ == SMI_ONLY; }
1538 bool IsObjectCompare() { return compare_type_ == OBJECT_ONLY; } 1577 bool IsObjectCompare() { return compare_type_ == OBJECT_ONLY; }
1539 1578
1540 // Match special cases. 1579 // Match special cases.
1541 bool IsLiteralCompareTypeof(Expression** expr, Handle<String>* check); 1580 bool IsLiteralCompareTypeof(Expression** expr, Handle<String>* check);
1542 bool IsLiteralCompareUndefined(Expression** expr); 1581 bool IsLiteralCompareUndefined(Expression** expr);
1543 bool IsLiteralCompareNull(Expression** expr); 1582 bool IsLiteralCompareNull(Expression** expr);
1544 1583
1584 protected:
1585 friend class AstNodeFactory;
1586
1587 CompareOperation(Isolate* isolate,
1588 Token::Value op,
1589 Expression* left,
1590 Expression* right,
1591 int pos)
1592 : Expression(isolate),
1593 op_(op),
1594 left_(left),
1595 right_(right),
1596 pos_(pos),
1597 compare_type_(NONE) {
1598 ASSERT(Token::IsCompareOp(op));
1599 }
1600
1545 private: 1601 private:
1546 Token::Value op_; 1602 Token::Value op_;
1547 Expression* left_; 1603 Expression* left_;
1548 Expression* right_; 1604 Expression* right_;
1549 int pos_; 1605 int pos_;
1550 1606
1551 enum CompareTypeFeedback { NONE, SMI_ONLY, OBJECT_ONLY }; 1607 enum CompareTypeFeedback { NONE, SMI_ONLY, OBJECT_ONLY };
1552 CompareTypeFeedback compare_type_; 1608 CompareTypeFeedback compare_type_;
1553 }; 1609 };
1554 1610
1555 1611
1556 class Conditional: public Expression { 1612 class Conditional: public Expression {
1557 public: 1613 public:
1614 DECLARE_NODE_TYPE(Conditional)
1615
1616 Expression* condition() const { return condition_; }
1617 Expression* then_expression() const { return then_expression_; }
1618 Expression* else_expression() const { return else_expression_; }
1619
1620 int then_expression_position() const { return then_expression_position_; }
1621 int else_expression_position() const { return else_expression_position_; }
1622
1623 int ThenId() const { return then_id_; }
1624 int ElseId() const { return else_id_; }
1625
1626 protected:
1627 friend class AstNodeFactory;
1628
1558 Conditional(Isolate* isolate, 1629 Conditional(Isolate* isolate,
1559 Expression* condition, 1630 Expression* condition,
1560 Expression* then_expression, 1631 Expression* then_expression,
1561 Expression* else_expression, 1632 Expression* else_expression,
1562 int then_expression_position, 1633 int then_expression_position,
1563 int else_expression_position) 1634 int else_expression_position)
1564 : Expression(isolate), 1635 : Expression(isolate),
1565 condition_(condition), 1636 condition_(condition),
1566 then_expression_(then_expression), 1637 then_expression_(then_expression),
1567 else_expression_(else_expression), 1638 else_expression_(else_expression),
1568 then_expression_position_(then_expression_position), 1639 then_expression_position_(then_expression_position),
1569 else_expression_position_(else_expression_position), 1640 else_expression_position_(else_expression_position),
1570 then_id_(GetNextId(isolate)), 1641 then_id_(GetNextId(isolate)),
1571 else_id_(GetNextId(isolate)) { 1642 else_id_(GetNextId(isolate)) { }
1572 }
1573
1574 DECLARE_NODE_TYPE(Conditional)
1575
1576 virtual bool IsInlineable() const;
1577
1578 Expression* condition() const { return condition_; }
1579 Expression* then_expression() const { return then_expression_; }
1580 Expression* else_expression() const { return else_expression_; }
1581
1582 int then_expression_position() const { return then_expression_position_; }
1583 int else_expression_position() const { return else_expression_position_; }
1584
1585 int ThenId() const { return then_id_; }
1586 int ElseId() const { return else_id_; }
1587 1643
1588 private: 1644 private:
1589 Expression* condition_; 1645 Expression* condition_;
1590 Expression* then_expression_; 1646 Expression* then_expression_;
1591 Expression* else_expression_; 1647 Expression* else_expression_;
1592 int then_expression_position_; 1648 int then_expression_position_;
1593 int else_expression_position_; 1649 int else_expression_position_;
1594 int then_id_; 1650 int then_id_;
1595 int else_id_; 1651 int else_id_;
1596 }; 1652 };
1597 1653
1598 1654
1599 class Assignment: public Expression { 1655 class Assignment: public Expression {
1600 public: 1656 public:
1601 Assignment(Isolate* isolate,
1602 Token::Value op,
1603 Expression* target,
1604 Expression* value,
1605 int pos);
1606
1607 DECLARE_NODE_TYPE(Assignment) 1657 DECLARE_NODE_TYPE(Assignment)
1608 1658
1609 virtual bool IsInlineable() const;
1610
1611 Assignment* AsSimpleAssignment() { return !is_compound() ? this : NULL; } 1659 Assignment* AsSimpleAssignment() { return !is_compound() ? this : NULL; }
1612 1660
1613 Token::Value binary_op() const; 1661 Token::Value binary_op() const;
1614 1662
1615 Token::Value op() const { return op_; } 1663 Token::Value op() const { return op_; }
1616 Expression* target() const { return target_; } 1664 Expression* target() const { return target_; }
1617 Expression* value() const { return value_; } 1665 Expression* value() const { return value_; }
1618 virtual int position() const { return pos_; } 1666 virtual int position() const { return pos_; }
1619 BinaryOperation* binary_operation() const { return binary_operation_; } 1667 BinaryOperation* binary_operation() const { return binary_operation_; }
1620 1668
(...skipping 11 matching lines...) Expand all
1632 1680
1633 // Type feedback information. 1681 // Type feedback information.
1634 void RecordTypeFeedback(TypeFeedbackOracle* oracle); 1682 void RecordTypeFeedback(TypeFeedbackOracle* oracle);
1635 virtual bool IsMonomorphic() { return is_monomorphic_; } 1683 virtual bool IsMonomorphic() { return is_monomorphic_; }
1636 virtual SmallMapList* GetReceiverTypes() { return &receiver_types_; } 1684 virtual SmallMapList* GetReceiverTypes() { return &receiver_types_; }
1637 1685
1638 // Bailout support. 1686 // Bailout support.
1639 int CompoundLoadId() const { return compound_load_id_; } 1687 int CompoundLoadId() const { return compound_load_id_; }
1640 int AssignmentId() const { return assignment_id_; } 1688 int AssignmentId() const { return assignment_id_; }
1641 1689
1690 protected:
1691 friend class AstNodeFactory;
1692
1693 Assignment(Isolate* isolate,
1694 Token::Value op,
1695 Expression* target,
1696 Expression* value,
1697 int pos,
1698 AstNodeFactory* factory);
1699
1642 private: 1700 private:
1643 Token::Value op_; 1701 Token::Value op_;
1644 Expression* target_; 1702 Expression* target_;
1645 Expression* value_; 1703 Expression* value_;
1646 int pos_; 1704 int pos_;
1647 BinaryOperation* binary_operation_; 1705 BinaryOperation* binary_operation_;
1648 int compound_load_id_; 1706 int compound_load_id_;
1649 int assignment_id_; 1707 int assignment_id_;
1650 1708
1651 bool block_start_; 1709 bool block_start_;
1652 bool block_end_; 1710 bool block_end_;
1653 1711
1654 bool is_monomorphic_; 1712 bool is_monomorphic_;
1655 SmallMapList receiver_types_; 1713 SmallMapList receiver_types_;
1656 }; 1714 };
1657 1715
1658 1716
1659 class Throw: public Expression { 1717 class Throw: public Expression {
1660 public: 1718 public:
1661 Throw(Isolate* isolate, Expression* exception, int pos)
1662 : Expression(isolate), exception_(exception), pos_(pos) {}
1663
1664 DECLARE_NODE_TYPE(Throw) 1719 DECLARE_NODE_TYPE(Throw)
1665 1720
1666 Expression* exception() const { return exception_; } 1721 Expression* exception() const { return exception_; }
1667 virtual int position() const { return pos_; } 1722 virtual int position() const { return pos_; }
1668 virtual bool IsInlineable() const; 1723
1724 protected:
1725 friend class AstNodeFactory;
1726
1727 Throw(Isolate* isolate, Expression* exception, int pos)
1728 : Expression(isolate), exception_(exception), pos_(pos) {}
1669 1729
1670 private: 1730 private:
1671 Expression* exception_; 1731 Expression* exception_;
1672 int pos_; 1732 int pos_;
1673 }; 1733 };
1674 1734
1675 1735
1676 class FunctionLiteral: public Expression { 1736 class FunctionLiteral: public Expression {
1677 public: 1737 public:
1678 enum Type { 1738 enum Type {
1679 ANONYMOUS_EXPRESSION, 1739 ANONYMOUS_EXPRESSION,
1680 NAMED_EXPRESSION, 1740 NAMED_EXPRESSION,
1681 DECLARATION 1741 DECLARATION
1682 }; 1742 };
1683 1743
1684 FunctionLiteral(Isolate* isolate,
1685 Handle<String> name,
1686 Scope* scope,
1687 ZoneList<Statement*>* body,
1688 int materialized_literal_count,
1689 int expected_property_count,
1690 int handler_count,
1691 bool has_only_simple_this_property_assignments,
1692 Handle<FixedArray> this_property_assignments,
1693 int parameter_count,
1694 Type type,
1695 bool has_duplicate_parameters)
1696 : Expression(isolate),
1697 name_(name),
1698 scope_(scope),
1699 body_(body),
1700 this_property_assignments_(this_property_assignments),
1701 inferred_name_(isolate->factory()->empty_string()),
1702 materialized_literal_count_(materialized_literal_count),
1703 expected_property_count_(expected_property_count),
1704 handler_count_(handler_count),
1705 parameter_count_(parameter_count),
1706 function_token_position_(RelocInfo::kNoPosition) {
1707 bitfield_ =
1708 HasOnlySimpleThisPropertyAssignments::encode(
1709 has_only_simple_this_property_assignments) |
1710 IsExpression::encode(type != DECLARATION) |
1711 IsAnonymous::encode(type == ANONYMOUS_EXPRESSION) |
1712 Pretenure::encode(false) |
1713 HasDuplicateParameters::encode(has_duplicate_parameters);
1714 }
1715
1716 DECLARE_NODE_TYPE(FunctionLiteral) 1744 DECLARE_NODE_TYPE(FunctionLiteral)
1717 1745
1718 Handle<String> name() const { return name_; } 1746 Handle<String> name() const { return name_; }
1719 Scope* scope() const { return scope_; } 1747 Scope* scope() const { return scope_; }
1720 ZoneList<Statement*>* body() const { return body_; } 1748 ZoneList<Statement*>* body() const { return body_; }
1721 void set_function_token_position(int pos) { function_token_position_ = pos; } 1749 void set_function_token_position(int pos) { function_token_position_ = pos; }
1722 int function_token_position() const { return function_token_position_; } 1750 int function_token_position() const { return function_token_position_; }
1723 int start_position() const; 1751 int start_position() const;
1724 int end_position() const; 1752 int end_position() const;
1725 bool is_expression() const { return IsExpression::decode(bitfield_); } 1753 bool is_expression() const { return IsExpression::decode(bitfield_); }
(...skipping 19 matching lines...) Expand all
1745 return inferred_name(); 1773 return inferred_name();
1746 } 1774 }
1747 1775
1748 Handle<String> inferred_name() const { return inferred_name_; } 1776 Handle<String> inferred_name() const { return inferred_name_; }
1749 void set_inferred_name(Handle<String> inferred_name) { 1777 void set_inferred_name(Handle<String> inferred_name) {
1750 inferred_name_ = inferred_name; 1778 inferred_name_ = inferred_name;
1751 } 1779 }
1752 1780
1753 bool pretenure() { return Pretenure::decode(bitfield_); } 1781 bool pretenure() { return Pretenure::decode(bitfield_); }
1754 void set_pretenure() { bitfield_ |= Pretenure::encode(true); } 1782 void set_pretenure() { bitfield_ |= Pretenure::encode(true); }
1755 virtual bool IsInlineable() const;
1756 1783
1757 bool has_duplicate_parameters() { 1784 bool has_duplicate_parameters() {
1758 return HasDuplicateParameters::decode(bitfield_); 1785 return HasDuplicateParameters::decode(bitfield_);
1759 } 1786 }
1760 1787
1788 bool ShouldSelfOptimize();
1789 int AstNodeCount();
1790 AstProperties* ast_properties() { return ast_properties_; }
1791 void set_ast_properties(AstProperties* ast_properties) {
1792 ast_properties_ = ast_properties;
1793 }
1794
1795 protected:
1796 friend class AstNodeFactory;
1797
1798 FunctionLiteral(Isolate* isolate,
1799 Handle<String> name,
1800 Scope* scope,
1801 ZoneList<Statement*>* body,
1802 int materialized_literal_count,
1803 int expected_property_count,
1804 int handler_count,
1805 bool has_only_simple_this_property_assignments,
1806 Handle<FixedArray> this_property_assignments,
1807 int parameter_count,
1808 Type type,
1809 bool has_duplicate_parameters)
1810 : Expression(isolate),
1811 name_(name),
1812 scope_(scope),
1813 body_(body),
1814 this_property_assignments_(this_property_assignments),
1815 inferred_name_(isolate->factory()->empty_string()),
1816 ast_properties_(NULL),
1817 materialized_literal_count_(materialized_literal_count),
1818 expected_property_count_(expected_property_count),
1819 handler_count_(handler_count),
1820 parameter_count_(parameter_count),
1821 function_token_position_(RelocInfo::kNoPosition) {
1822 bitfield_ =
1823 HasOnlySimpleThisPropertyAssignments::encode(
1824 has_only_simple_this_property_assignments) |
1825 IsExpression::encode(type != DECLARATION) |
1826 IsAnonymous::encode(type == ANONYMOUS_EXPRESSION) |
1827 Pretenure::encode(false) |
1828 HasDuplicateParameters::encode(has_duplicate_parameters);
1829 }
1830
1761 private: 1831 private:
1762 Handle<String> name_; 1832 Handle<String> name_;
1763 Scope* scope_; 1833 Scope* scope_;
1764 ZoneList<Statement*>* body_; 1834 ZoneList<Statement*>* body_;
1765 Handle<FixedArray> this_property_assignments_; 1835 Handle<FixedArray> this_property_assignments_;
1766 Handle<String> inferred_name_; 1836 Handle<String> inferred_name_;
1837 AstProperties* ast_properties_;
1767 1838
1768 int materialized_literal_count_; 1839 int materialized_literal_count_;
1769 int expected_property_count_; 1840 int expected_property_count_;
1770 int handler_count_; 1841 int handler_count_;
1771 int parameter_count_; 1842 int parameter_count_;
1772 int function_token_position_; 1843 int function_token_position_;
1773 1844
1774 unsigned bitfield_; 1845 unsigned bitfield_;
1775 class HasOnlySimpleThisPropertyAssignments: public BitField<bool, 0, 1> {}; 1846 class HasOnlySimpleThisPropertyAssignments: public BitField<bool, 0, 1> {};
1776 class IsExpression: public BitField<bool, 1, 1> {}; 1847 class IsExpression: public BitField<bool, 1, 1> {};
1777 class IsAnonymous: public BitField<bool, 2, 1> {}; 1848 class IsAnonymous: public BitField<bool, 2, 1> {};
1778 class Pretenure: public BitField<bool, 3, 1> {}; 1849 class Pretenure: public BitField<bool, 3, 1> {};
1779 class HasDuplicateParameters: public BitField<bool, 4, 1> {}; 1850 class HasDuplicateParameters: public BitField<bool, 4, 1> {};
1780 }; 1851 };
1781 1852
1782 1853
1783 class SharedFunctionInfoLiteral: public Expression { 1854 class SharedFunctionInfoLiteral: public Expression {
1784 public: 1855 public:
1785 SharedFunctionInfoLiteral(
1786 Isolate* isolate,
1787 Handle<SharedFunctionInfo> shared_function_info)
1788 : Expression(isolate), shared_function_info_(shared_function_info) { }
1789
1790 DECLARE_NODE_TYPE(SharedFunctionInfoLiteral) 1856 DECLARE_NODE_TYPE(SharedFunctionInfoLiteral)
1791 1857
1792 Handle<SharedFunctionInfo> shared_function_info() const { 1858 Handle<SharedFunctionInfo> shared_function_info() const {
1793 return shared_function_info_; 1859 return shared_function_info_;
1794 } 1860 }
1795 virtual bool IsInlineable() const; 1861
1862 protected:
1863 friend class AstNodeFactory;
1864
1865 SharedFunctionInfoLiteral(
1866 Isolate* isolate,
1867 Handle<SharedFunctionInfo> shared_function_info)
1868 : Expression(isolate),
1869 shared_function_info_(shared_function_info) { }
1796 1870
1797 private: 1871 private:
1798 Handle<SharedFunctionInfo> shared_function_info_; 1872 Handle<SharedFunctionInfo> shared_function_info_;
1799 }; 1873 };
1800 1874
1801 1875
1802 class ThisFunction: public Expression { 1876 class ThisFunction: public Expression {
1803 public: 1877 public:
1804 explicit ThisFunction(Isolate* isolate) : Expression(isolate) {}
1805 DECLARE_NODE_TYPE(ThisFunction) 1878 DECLARE_NODE_TYPE(ThisFunction)
1806 virtual bool IsInlineable() const; 1879
1880 protected:
1881 friend class AstNodeFactory;
1882
1883 explicit ThisFunction(Isolate* isolate): Expression(isolate) {}
1807 }; 1884 };
1808 1885
1809 1886
1810 // ---------------------------------------------------------------------------- 1887 // ----------------------------------------------------------------------------
1811 // Regular expressions 1888 // Regular expressions
1812 1889
1813 1890
1814 class RegExpVisitor BASE_EMBEDDED { 1891 class RegExpVisitor BASE_EMBEDDED {
1815 public: 1892 public:
1816 virtual ~RegExpVisitor() { } 1893 virtual ~RegExpVisitor() { }
(...skipping 383 matching lines...) Expand 10 before | Expand all | Expand 10 after
2200 2277
2201 protected: 2278 protected:
2202 Isolate* isolate() { return isolate_; } 2279 Isolate* isolate() { return isolate_; }
2203 2280
2204 private: 2281 private:
2205 Isolate* isolate_; 2282 Isolate* isolate_;
2206 bool stack_overflow_; 2283 bool stack_overflow_;
2207 }; 2284 };
2208 2285
2209 2286
2287 // ----------------------------------------------------------------------------
2288 // Construction time visitor.
2289
2290 enum AstPropertiesFlag {
2291 kDontCrankshaft,
2292 kDontInline,
2293 kDontSelfOptimize,
2294 kDontSoftInline
2295 };
2296
2297
2298 class AstProperties : public ZoneObject {
2299 public:
2300 class Flags : public EnumSet<AstPropertiesFlag, int> {};
2301
2302 AstProperties() : node_count_(0) {}
2303 virtual ~AstProperties(); // Implementation is out-of-line to make ld happy.
2304
2305 Flags* flags() { return &flags_; }
2306 int node_count() { return node_count_; }
2307 void increase_node_count() { node_count_++; }
2308
2309 void RevisitVariableProxy(VariableProxy* node);
2310
2311 private:
2312 Flags flags_;
2313 int node_count_;
2314 };
2315
2316
2317 class AstConstructionVisitor : public AstVisitor {
2318 public:
2319 AstConstructionVisitor() : properties_(NULL) {}
2320 virtual ~AstConstructionVisitor() {}
2321
2322 AstProperties* properties() { return properties_; }
2323 void set_ast_properties(AstProperties* properties) {
2324 properties_ = properties;
2325 }
2326
2327 private:
2328 // Node visitors.
2329 #define DEF_VISIT(type) \
2330 virtual void Visit##type(type* node);
2331 AST_NODE_LIST(DEF_VISIT)
2332 #undef DEF_VISIT
2333
2334 inline void increase_node_count() {
2335 properties_->increase_node_count();
2336 }
2337 inline void add_flag(AstPropertiesFlag flag) {
2338 properties_->flags()->Add(flag);
2339 }
2340
2341 AstProperties* properties_;
2342 };
2343
2344
2345
2346 // ----------------------------------------------------------------------------
2347 // AstNode factory
2348
2349 class AstNodeFactory {
fschneider 2012/01/30 12:10:35 maybe make it BASE_EMBEDDED.
Jakob Kummerow 2012/02/01 14:46:09 Done.
2350 public:
2351 AstNodeFactory(Isolate* isolate,
2352 Zone* zone = NULL,
2353 AstVisitor* visitor = NULL)
2354 : isolate_(isolate),
2355 zone_(zone),
2356 visitor_(visitor) {
2357 if (zone == NULL) {
2358 zone_ = isolate_->zone();
2359 }
2360 }
2361
2362 AstVisitor* visitor() { return visitor_; }
2363 void set_visitor(AstVisitor* visitor) {
2364 visitor_ = visitor;
2365 }
2366
2367 Block* NewBlock(ZoneStringList* labels,
2368 int capacity,
2369 bool is_initializer_block);
2370
2371 Declaration* NewDeclaration(VariableProxy* proxy,
2372 VariableMode mode,
2373 FunctionLiteral* fun,
2374 Scope* scope);
2375
2376 DoWhileStatement* NewDoWhileStatement(ZoneStringList* labels);
2377
2378 WhileStatement* NewWhileStatement(ZoneStringList* labels);
2379
2380 ForStatement* NewForStatement(ZoneStringList* labels);
2381
2382 ForInStatement* NewForInStatement(ZoneStringList* labels);
2383
2384 ExpressionStatement* NewExpressionStatement(Expression* expression);
2385
2386 ContinueStatement* NewContinueStatement(IterationStatement* target);
2387
2388 BreakStatement* NewBreakStatement(BreakableStatement* target);
2389
2390 ReturnStatement* NewReturnStatement(Expression* expression);
2391
2392 WithStatement* NewWithStatement(Expression* expression,
2393 Statement* statement);
2394
2395 SwitchStatement* NewSwitchStatement(ZoneStringList* labels);
2396
2397 IfStatement* NewIfStatement(Expression* condition,
2398 Statement* then_statement,
2399 Statement* else_statement);
2400
2401 TryCatchStatement* NewTryCatchStatement(int index,
2402 Block* try_block,
2403 Scope* scope,
2404 Variable* variable,
2405 Block* catch_block);
2406
2407 TryFinallyStatement* NewTryFinallyStatement(int index,
2408 Block* try_block,
2409 Block* finally_block);
2410
2411 DebuggerStatement* NewDebuggerStatement();
2412
2413 EmptyStatement* NewEmptyStatement();
2414
2415 Literal* NewLiteral(Handle<Object> handle);
2416
2417 Literal* NewNumberLiteral(double number);
2418
2419 ObjectLiteral* NewObjectLiteral(
2420 Handle<FixedArray> constant_properties,
2421 ZoneList<ObjectLiteral::Property*>* properties,
2422 int literal_index,
2423 bool is_simple,
2424 bool fast_elements,
2425 int depth,
2426 bool has_function);
2427
2428 RegExpLiteral* NewRegExpLiteral(Handle<String> pattern,
2429 Handle<String> flags,
2430 int literal_index);
2431
2432 ArrayLiteral* NewArrayLiteral(Handle<FixedArray> constant_elements,
2433 ZoneList<Expression*>* values,
2434 int literal_index,
2435 bool is_simple,
2436 int depth);
2437
2438 VariableProxy* NewVariableProxy(Variable* var);
2439
2440 VariableProxy* NewVariableProxy(Handle<String> name,
2441 bool is_this,
2442 int position = RelocInfo::kNoPosition);
2443
2444 Property* NewProperty(Expression* obj, Expression* key, int pos);
2445
2446 Call* NewCall(Expression* expression,
2447 ZoneList<Expression*>* arguments,
2448 int pos);
2449
2450 CallNew* NewCallNew(Expression* expression,
2451 ZoneList<Expression*>* arguments,
2452 int pos);
2453
2454 CallRuntime* NewCallRuntime(Handle<String> name,
2455 const Runtime::Function* function,
2456 ZoneList<Expression*>* arguments);
2457
2458 UnaryOperation* NewUnaryOperation(Token::Value op,
2459 Expression* expression,
2460 int pos);
2461
2462 BinaryOperation* NewBinaryOperation(Token::Value op,
2463 Expression* left,
2464 Expression* right,
2465 int pos);
2466
2467 CountOperation* NewCountOperation(Token::Value op,
2468 bool is_prefix,
2469 Expression* expr,
2470 int pos);
2471
2472 CompareOperation* NewCompareOperation(Token::Value op,
2473 Expression* left,
2474 Expression* right,
2475 int pos);
2476
2477 Conditional* NewConditional(Expression* condition,
2478 Expression* then_expression,
2479 Expression* else_expression,
2480 int then_expression_position,
2481 int else_expression_position);
2482
2483 Assignment* NewAssignment(Token::Value op,
2484 Expression* target,
2485 Expression* value,
2486 int pos);
2487
2488 Throw* NewThrow(Expression* exception, int pos);
2489
2490 FunctionLiteral* NewFunctionLiteral(
2491 Handle<String> name,
2492 Scope* scope,
2493 ZoneList<Statement*>* body,
2494 int materialized_literal_count,
2495 int expected_property_count,
2496 int handler_count,
2497 bool has_only_simple_this_property_assignments,
2498 Handle<FixedArray> this_property_assignments,
2499 int parameter_count,
2500 FunctionLiteral::Type type,
2501 bool has_duplicate_parameters,
2502 bool visit_with_visitor = true);
2503
2504 SharedFunctionInfoLiteral* NewSharedFunctionInfoLiteral(
2505 Handle<SharedFunctionInfo> shared_function_info);
2506
2507 ThisFunction* NewThisFunction();
2508
2509 private:
2510 void Visit(AstNode* node);
2511
2512 Isolate* isolate_;
2513 Zone* zone_;
2514 AstVisitor* visitor_;
2515 };
2516
2517
2210 } } // namespace v8::internal 2518 } } // namespace v8::internal
2211 2519
2212 #endif // V8_AST_H_ 2520 #endif // V8_AST_H_
OLDNEW
« no previous file with comments | « no previous file | src/ast.cc » ('j') | src/objects.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698