OLD | NEW |
1 // Copyright 2010 the V8 project authors. All rights reserved. | 1 // Copyright 2010 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 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
111 AST_NODE_LIST(DEF_FORWARD_DECLARATION) | 111 AST_NODE_LIST(DEF_FORWARD_DECLARATION) |
112 #undef DEF_FORWARD_DECLARATION | 112 #undef DEF_FORWARD_DECLARATION |
113 | 113 |
114 | 114 |
115 // Typedef only introduced to avoid unreadable code. | 115 // Typedef only introduced to avoid unreadable code. |
116 // Please do appreciate the required space in "> >". | 116 // Please do appreciate the required space in "> >". |
117 typedef ZoneList<Handle<String> > ZoneStringList; | 117 typedef ZoneList<Handle<String> > ZoneStringList; |
118 typedef ZoneList<Handle<Object> > ZoneObjectList; | 118 typedef ZoneList<Handle<Object> > ZoneObjectList; |
119 | 119 |
120 | 120 |
| 121 #define DECLARE_NODE_TYPE(type) \ |
| 122 virtual void Accept(AstVisitor* v); \ |
| 123 virtual AstNode::Type node_type() const { return AstNode::k##type; } \ |
| 124 virtual type* As##type() { return this; } |
| 125 |
| 126 |
121 class AstNode: public ZoneObject { | 127 class AstNode: public ZoneObject { |
122 public: | 128 public: |
| 129 #define DECLARE_TYPE_ENUM(type) k##type, |
| 130 enum Type { |
| 131 AST_NODE_LIST(DECLARE_TYPE_ENUM) |
| 132 kInvalid = -1 |
| 133 }; |
| 134 #undef DECLARE_TYPE_ENUM |
| 135 |
123 virtual ~AstNode() { } | 136 virtual ~AstNode() { } |
| 137 |
124 virtual void Accept(AstVisitor* v) = 0; | 138 virtual void Accept(AstVisitor* v) = 0; |
| 139 virtual Type node_type() const { return kInvalid; } |
125 | 140 |
126 // Type testing & conversion. | 141 // Type testing & conversion functions overridden by concrete subclasses. |
| 142 #define DECLARE_NODE_FUNCTIONS(type) \ |
| 143 virtual type* As##type() { return NULL; } |
| 144 AST_NODE_LIST(DECLARE_NODE_FUNCTIONS) |
| 145 #undef DECLARE_NODE_FUNCTIONS |
| 146 |
127 virtual Statement* AsStatement() { return NULL; } | 147 virtual Statement* AsStatement() { return NULL; } |
128 virtual Block* AsBlock() { return NULL; } | |
129 virtual ExpressionStatement* AsExpressionStatement() { return NULL; } | |
130 virtual EmptyStatement* AsEmptyStatement() { return NULL; } | |
131 virtual Expression* AsExpression() { return NULL; } | 148 virtual Expression* AsExpression() { return NULL; } |
132 virtual Literal* AsLiteral() { return NULL; } | |
133 virtual Slot* AsSlot() { return NULL; } | |
134 virtual VariableProxy* AsVariableProxy() { return NULL; } | |
135 virtual Property* AsProperty() { return NULL; } | |
136 virtual Call* AsCall() { return NULL; } | |
137 virtual TargetCollector* AsTargetCollector() { return NULL; } | 149 virtual TargetCollector* AsTargetCollector() { return NULL; } |
138 virtual BreakableStatement* AsBreakableStatement() { return NULL; } | 150 virtual BreakableStatement* AsBreakableStatement() { return NULL; } |
139 virtual IterationStatement* AsIterationStatement() { return NULL; } | 151 virtual IterationStatement* AsIterationStatement() { return NULL; } |
140 virtual ForStatement* AsForStatement() { return NULL; } | |
141 virtual UnaryOperation* AsUnaryOperation() { return NULL; } | |
142 virtual CountOperation* AsCountOperation() { return NULL; } | |
143 virtual BinaryOperation* AsBinaryOperation() { return NULL; } | |
144 virtual Assignment* AsAssignment() { return NULL; } | |
145 virtual FunctionLiteral* AsFunctionLiteral() { return NULL; } | |
146 virtual MaterializedLiteral* AsMaterializedLiteral() { return NULL; } | 152 virtual MaterializedLiteral* AsMaterializedLiteral() { return NULL; } |
147 virtual ObjectLiteral* AsObjectLiteral() { return NULL; } | |
148 virtual ArrayLiteral* AsArrayLiteral() { return NULL; } | |
149 virtual CompareOperation* AsCompareOperation() { return NULL; } | |
150 }; | 153 }; |
151 | 154 |
152 | 155 |
153 class Statement: public AstNode { | 156 class Statement: public AstNode { |
154 public: | 157 public: |
155 Statement() : statement_pos_(RelocInfo::kNoPosition) {} | 158 Statement() : statement_pos_(RelocInfo::kNoPosition) {} |
156 | 159 |
157 virtual Statement* AsStatement() { return this; } | 160 virtual Statement* AsStatement() { return this; } |
158 virtual ReturnStatement* AsReturnStatement() { return NULL; } | |
159 | 161 |
160 virtual Assignment* StatementAsSimpleAssignment() { return NULL; } | 162 virtual Assignment* StatementAsSimpleAssignment() { return NULL; } |
161 virtual CountOperation* StatementAsCountOperation() { return NULL; } | 163 virtual CountOperation* StatementAsCountOperation() { return NULL; } |
162 | 164 |
163 bool IsEmpty() { return AsEmptyStatement() != NULL; } | 165 bool IsEmpty() { return AsEmptyStatement() != NULL; } |
164 | 166 |
165 void set_statement_pos(int statement_pos) { statement_pos_ = statement_pos; } | 167 void set_statement_pos(int statement_pos) { statement_pos_ = statement_pos; } |
166 int statement_pos() const { return statement_pos_; } | 168 int statement_pos() const { return statement_pos_; } |
167 | 169 |
168 private: | 170 private: |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
306 ZoneStringList* labels_; | 308 ZoneStringList* labels_; |
307 Type type_; | 309 Type type_; |
308 BreakTarget break_target_; | 310 BreakTarget break_target_; |
309 }; | 311 }; |
310 | 312 |
311 | 313 |
312 class Block: public BreakableStatement { | 314 class Block: public BreakableStatement { |
313 public: | 315 public: |
314 inline Block(ZoneStringList* labels, int capacity, bool is_initializer_block); | 316 inline Block(ZoneStringList* labels, int capacity, bool is_initializer_block); |
315 | 317 |
316 virtual void Accept(AstVisitor* v); | 318 DECLARE_NODE_TYPE(Block) |
317 | |
318 virtual Block* AsBlock() { return this; } | |
319 | 319 |
320 virtual Assignment* StatementAsSimpleAssignment() { | 320 virtual Assignment* StatementAsSimpleAssignment() { |
321 if (statements_.length() != 1) return NULL; | 321 if (statements_.length() != 1) return NULL; |
322 return statements_[0]->StatementAsSimpleAssignment(); | 322 return statements_[0]->StatementAsSimpleAssignment(); |
323 } | 323 } |
324 | 324 |
325 virtual CountOperation* StatementAsCountOperation() { | 325 virtual CountOperation* StatementAsCountOperation() { |
326 if (statements_.length() != 1) return NULL; | 326 if (statements_.length() != 1) return NULL; |
327 return statements_[0]->StatementAsCountOperation(); | 327 return statements_[0]->StatementAsCountOperation(); |
328 } | 328 } |
(...skipping 13 matching lines...) Expand all Loading... |
342 public: | 342 public: |
343 Declaration(VariableProxy* proxy, Variable::Mode mode, FunctionLiteral* fun) | 343 Declaration(VariableProxy* proxy, Variable::Mode mode, FunctionLiteral* fun) |
344 : proxy_(proxy), | 344 : proxy_(proxy), |
345 mode_(mode), | 345 mode_(mode), |
346 fun_(fun) { | 346 fun_(fun) { |
347 ASSERT(mode == Variable::VAR || mode == Variable::CONST); | 347 ASSERT(mode == Variable::VAR || mode == Variable::CONST); |
348 // At the moment there are no "const functions"'s in JavaScript... | 348 // At the moment there are no "const functions"'s in JavaScript... |
349 ASSERT(fun == NULL || mode == Variable::VAR); | 349 ASSERT(fun == NULL || mode == Variable::VAR); |
350 } | 350 } |
351 | 351 |
352 virtual void Accept(AstVisitor* v); | 352 DECLARE_NODE_TYPE(Declaration) |
353 | 353 |
354 VariableProxy* proxy() const { return proxy_; } | 354 VariableProxy* proxy() const { return proxy_; } |
355 Variable::Mode mode() const { return mode_; } | 355 Variable::Mode mode() const { return mode_; } |
356 FunctionLiteral* fun() const { return fun_; } // may be NULL | 356 FunctionLiteral* fun() const { return fun_; } // may be NULL |
357 | 357 |
358 private: | 358 private: |
359 VariableProxy* proxy_; | 359 VariableProxy* proxy_; |
360 Variable::Mode mode_; | 360 Variable::Mode mode_; |
361 FunctionLiteral* fun_; | 361 FunctionLiteral* fun_; |
362 }; | 362 }; |
(...skipping 20 matching lines...) Expand all Loading... |
383 private: | 383 private: |
384 Statement* body_; | 384 Statement* body_; |
385 BreakTarget continue_target_; | 385 BreakTarget continue_target_; |
386 }; | 386 }; |
387 | 387 |
388 | 388 |
389 class DoWhileStatement: public IterationStatement { | 389 class DoWhileStatement: public IterationStatement { |
390 public: | 390 public: |
391 explicit inline DoWhileStatement(ZoneStringList* labels); | 391 explicit inline DoWhileStatement(ZoneStringList* labels); |
392 | 392 |
| 393 DECLARE_NODE_TYPE(DoWhileStatement) |
| 394 |
393 void Initialize(Expression* cond, Statement* body) { | 395 void Initialize(Expression* cond, Statement* body) { |
394 IterationStatement::Initialize(body); | 396 IterationStatement::Initialize(body); |
395 cond_ = cond; | 397 cond_ = cond; |
396 } | 398 } |
397 | 399 |
398 virtual void Accept(AstVisitor* v); | |
399 | |
400 Expression* cond() const { return cond_; } | 400 Expression* cond() const { return cond_; } |
401 | 401 |
402 // Position where condition expression starts. We need it to make | 402 // Position where condition expression starts. We need it to make |
403 // the loop's condition a breakable location. | 403 // the loop's condition a breakable location. |
404 int condition_position() { return condition_position_; } | 404 int condition_position() { return condition_position_; } |
405 void set_condition_position(int pos) { condition_position_ = pos; } | 405 void set_condition_position(int pos) { condition_position_ = pos; } |
406 | 406 |
407 private: | 407 private: |
408 Expression* cond_; | 408 Expression* cond_; |
409 int condition_position_; | 409 int condition_position_; |
410 }; | 410 }; |
411 | 411 |
412 | 412 |
413 class WhileStatement: public IterationStatement { | 413 class WhileStatement: public IterationStatement { |
414 public: | 414 public: |
415 explicit WhileStatement(ZoneStringList* labels); | 415 explicit WhileStatement(ZoneStringList* labels); |
416 | 416 |
| 417 DECLARE_NODE_TYPE(WhileStatement) |
| 418 |
417 void Initialize(Expression* cond, Statement* body) { | 419 void Initialize(Expression* cond, Statement* body) { |
418 IterationStatement::Initialize(body); | 420 IterationStatement::Initialize(body); |
419 cond_ = cond; | 421 cond_ = cond; |
420 } | 422 } |
421 | 423 |
422 virtual void Accept(AstVisitor* v); | |
423 | |
424 Expression* cond() const { return cond_; } | 424 Expression* cond() const { return cond_; } |
425 bool may_have_function_literal() const { | 425 bool may_have_function_literal() const { |
426 return may_have_function_literal_; | 426 return may_have_function_literal_; |
427 } | 427 } |
428 void set_may_have_function_literal(bool value) { | 428 void set_may_have_function_literal(bool value) { |
429 may_have_function_literal_ = value; | 429 may_have_function_literal_ = value; |
430 } | 430 } |
431 | 431 |
432 private: | 432 private: |
433 Expression* cond_; | 433 Expression* cond_; |
434 // True if there is a function literal subexpression in the condition. | 434 // True if there is a function literal subexpression in the condition. |
435 bool may_have_function_literal_; | 435 bool may_have_function_literal_; |
436 }; | 436 }; |
437 | 437 |
438 | 438 |
439 class ForStatement: public IterationStatement { | 439 class ForStatement: public IterationStatement { |
440 public: | 440 public: |
441 explicit inline ForStatement(ZoneStringList* labels); | 441 explicit inline ForStatement(ZoneStringList* labels); |
442 | 442 |
443 virtual ForStatement* AsForStatement() { return this; } | 443 DECLARE_NODE_TYPE(ForStatement) |
444 | 444 |
445 void Initialize(Statement* init, | 445 void Initialize(Statement* init, |
446 Expression* cond, | 446 Expression* cond, |
447 Statement* next, | 447 Statement* next, |
448 Statement* body) { | 448 Statement* body) { |
449 IterationStatement::Initialize(body); | 449 IterationStatement::Initialize(body); |
450 init_ = init; | 450 init_ = init; |
451 cond_ = cond; | 451 cond_ = cond; |
452 next_ = next; | 452 next_ = next; |
453 } | 453 } |
454 | 454 |
455 virtual void Accept(AstVisitor* v); | |
456 | |
457 Statement* init() const { return init_; } | 455 Statement* init() const { return init_; } |
458 void set_init(Statement* stmt) { init_ = stmt; } | 456 void set_init(Statement* stmt) { init_ = stmt; } |
459 Expression* cond() const { return cond_; } | 457 Expression* cond() const { return cond_; } |
460 void set_cond(Expression* expr) { cond_ = expr; } | 458 void set_cond(Expression* expr) { cond_ = expr; } |
461 Statement* next() const { return next_; } | 459 Statement* next() const { return next_; } |
462 void set_next(Statement* stmt) { next_ = stmt; } | 460 void set_next(Statement* stmt) { next_ = stmt; } |
463 | 461 |
464 bool may_have_function_literal() const { | 462 bool may_have_function_literal() const { |
465 return may_have_function_literal_; | 463 return may_have_function_literal_; |
466 } | 464 } |
(...skipping 12 matching lines...) Expand all Loading... |
479 // True if there is a function literal subexpression in the condition. | 477 // True if there is a function literal subexpression in the condition. |
480 bool may_have_function_literal_; | 478 bool may_have_function_literal_; |
481 Variable* loop_variable_; | 479 Variable* loop_variable_; |
482 }; | 480 }; |
483 | 481 |
484 | 482 |
485 class ForInStatement: public IterationStatement { | 483 class ForInStatement: public IterationStatement { |
486 public: | 484 public: |
487 explicit inline ForInStatement(ZoneStringList* labels); | 485 explicit inline ForInStatement(ZoneStringList* labels); |
488 | 486 |
| 487 DECLARE_NODE_TYPE(ForInStatement) |
| 488 |
489 void Initialize(Expression* each, Expression* enumerable, Statement* body) { | 489 void Initialize(Expression* each, Expression* enumerable, Statement* body) { |
490 IterationStatement::Initialize(body); | 490 IterationStatement::Initialize(body); |
491 each_ = each; | 491 each_ = each; |
492 enumerable_ = enumerable; | 492 enumerable_ = enumerable; |
493 } | 493 } |
494 | 494 |
495 virtual void Accept(AstVisitor* v); | |
496 | |
497 Expression* each() const { return each_; } | 495 Expression* each() const { return each_; } |
498 Expression* enumerable() const { return enumerable_; } | 496 Expression* enumerable() const { return enumerable_; } |
499 | 497 |
500 private: | 498 private: |
501 Expression* each_; | 499 Expression* each_; |
502 Expression* enumerable_; | 500 Expression* enumerable_; |
503 }; | 501 }; |
504 | 502 |
505 | 503 |
506 class ExpressionStatement: public Statement { | 504 class ExpressionStatement: public Statement { |
507 public: | 505 public: |
508 explicit ExpressionStatement(Expression* expression) | 506 explicit ExpressionStatement(Expression* expression) |
509 : expression_(expression) { } | 507 : expression_(expression) { } |
510 | 508 |
511 virtual void Accept(AstVisitor* v); | 509 DECLARE_NODE_TYPE(ExpressionStatement) |
512 | |
513 // Type testing & conversion. | |
514 virtual ExpressionStatement* AsExpressionStatement() { return this; } | |
515 | 510 |
516 virtual Assignment* StatementAsSimpleAssignment(); | 511 virtual Assignment* StatementAsSimpleAssignment(); |
517 virtual CountOperation* StatementAsCountOperation(); | 512 virtual CountOperation* StatementAsCountOperation(); |
518 | 513 |
519 void set_expression(Expression* e) { expression_ = e; } | 514 void set_expression(Expression* e) { expression_ = e; } |
520 Expression* expression() { return expression_; } | 515 Expression* expression() { return expression_; } |
521 | 516 |
522 private: | 517 private: |
523 Expression* expression_; | 518 Expression* expression_; |
524 }; | 519 }; |
525 | 520 |
526 | 521 |
527 class ContinueStatement: public Statement { | 522 class ContinueStatement: public Statement { |
528 public: | 523 public: |
529 explicit ContinueStatement(IterationStatement* target) | 524 explicit ContinueStatement(IterationStatement* target) |
530 : target_(target) { } | 525 : target_(target) { } |
531 | 526 |
532 virtual void Accept(AstVisitor* v); | 527 DECLARE_NODE_TYPE(ContinueStatement) |
533 | 528 |
534 IterationStatement* target() const { return target_; } | 529 IterationStatement* target() const { return target_; } |
535 | 530 |
536 private: | 531 private: |
537 IterationStatement* target_; | 532 IterationStatement* target_; |
538 }; | 533 }; |
539 | 534 |
540 | 535 |
541 class BreakStatement: public Statement { | 536 class BreakStatement: public Statement { |
542 public: | 537 public: |
543 explicit BreakStatement(BreakableStatement* target) | 538 explicit BreakStatement(BreakableStatement* target) |
544 : target_(target) { } | 539 : target_(target) { } |
545 | 540 |
546 virtual void Accept(AstVisitor* v); | 541 DECLARE_NODE_TYPE(BreakStatement) |
547 | 542 |
548 BreakableStatement* target() const { return target_; } | 543 BreakableStatement* target() const { return target_; } |
549 | 544 |
550 private: | 545 private: |
551 BreakableStatement* target_; | 546 BreakableStatement* target_; |
552 }; | 547 }; |
553 | 548 |
554 | 549 |
555 class ReturnStatement: public Statement { | 550 class ReturnStatement: public Statement { |
556 public: | 551 public: |
557 explicit ReturnStatement(Expression* expression) | 552 explicit ReturnStatement(Expression* expression) |
558 : expression_(expression) { } | 553 : expression_(expression) { } |
559 | 554 |
560 virtual void Accept(AstVisitor* v); | 555 DECLARE_NODE_TYPE(ReturnStatement) |
561 | |
562 // Type testing & conversion. | |
563 virtual ReturnStatement* AsReturnStatement() { return this; } | |
564 | 556 |
565 Expression* expression() { return expression_; } | 557 Expression* expression() { return expression_; } |
566 | 558 |
567 private: | 559 private: |
568 Expression* expression_; | 560 Expression* expression_; |
569 }; | 561 }; |
570 | 562 |
571 | 563 |
572 class WithEnterStatement: public Statement { | 564 class WithEnterStatement: public Statement { |
573 public: | 565 public: |
574 explicit WithEnterStatement(Expression* expression, bool is_catch_block) | 566 explicit WithEnterStatement(Expression* expression, bool is_catch_block) |
575 : expression_(expression), is_catch_block_(is_catch_block) { } | 567 : expression_(expression), is_catch_block_(is_catch_block) { } |
576 | 568 |
577 virtual void Accept(AstVisitor* v); | 569 DECLARE_NODE_TYPE(WithEnterStatement) |
578 | 570 |
579 Expression* expression() const { return expression_; } | 571 Expression* expression() const { return expression_; } |
580 | 572 |
581 bool is_catch_block() const { return is_catch_block_; } | 573 bool is_catch_block() const { return is_catch_block_; } |
582 | 574 |
583 private: | 575 private: |
584 Expression* expression_; | 576 Expression* expression_; |
585 bool is_catch_block_; | 577 bool is_catch_block_; |
586 }; | 578 }; |
587 | 579 |
588 | 580 |
589 class WithExitStatement: public Statement { | 581 class WithExitStatement: public Statement { |
590 public: | 582 public: |
591 WithExitStatement() { } | 583 WithExitStatement() { } |
592 | 584 |
593 virtual void Accept(AstVisitor* v); | 585 DECLARE_NODE_TYPE(WithExitStatement) |
594 }; | 586 }; |
595 | 587 |
596 | 588 |
597 class CaseClause: public ZoneObject { | 589 class CaseClause: public ZoneObject { |
598 public: | 590 public: |
599 CaseClause(Expression* label, ZoneList<Statement*>* statements); | 591 CaseClause(Expression* label, ZoneList<Statement*>* statements); |
600 | 592 |
601 bool is_default() const { return label_ == NULL; } | 593 bool is_default() const { return label_ == NULL; } |
602 Expression* label() const { | 594 Expression* label() const { |
603 CHECK(!is_default()); | 595 CHECK(!is_default()); |
604 return label_; | 596 return label_; |
605 } | 597 } |
606 JumpTarget* body_target() { return &body_target_; } | 598 JumpTarget* body_target() { return &body_target_; } |
607 ZoneList<Statement*>* statements() const { return statements_; } | 599 ZoneList<Statement*>* statements() const { return statements_; } |
608 | 600 |
609 private: | 601 private: |
610 Expression* label_; | 602 Expression* label_; |
611 JumpTarget body_target_; | 603 JumpTarget body_target_; |
612 ZoneList<Statement*>* statements_; | 604 ZoneList<Statement*>* statements_; |
613 }; | 605 }; |
614 | 606 |
615 | 607 |
616 class SwitchStatement: public BreakableStatement { | 608 class SwitchStatement: public BreakableStatement { |
617 public: | 609 public: |
618 explicit inline SwitchStatement(ZoneStringList* labels); | 610 explicit inline SwitchStatement(ZoneStringList* labels); |
619 | 611 |
| 612 DECLARE_NODE_TYPE(SwitchStatement) |
| 613 |
620 void Initialize(Expression* tag, ZoneList<CaseClause*>* cases) { | 614 void Initialize(Expression* tag, ZoneList<CaseClause*>* cases) { |
621 tag_ = tag; | 615 tag_ = tag; |
622 cases_ = cases; | 616 cases_ = cases; |
623 } | 617 } |
624 | 618 |
625 virtual void Accept(AstVisitor* v); | |
626 | |
627 Expression* tag() const { return tag_; } | 619 Expression* tag() const { return tag_; } |
628 ZoneList<CaseClause*>* cases() const { return cases_; } | 620 ZoneList<CaseClause*>* cases() const { return cases_; } |
629 | 621 |
630 private: | 622 private: |
631 Expression* tag_; | 623 Expression* tag_; |
632 ZoneList<CaseClause*>* cases_; | 624 ZoneList<CaseClause*>* cases_; |
633 }; | 625 }; |
634 | 626 |
635 | 627 |
636 // If-statements always have non-null references to their then- and | 628 // If-statements always have non-null references to their then- and |
637 // else-parts. When parsing if-statements with no explicit else-part, | 629 // else-parts. When parsing if-statements with no explicit else-part, |
638 // the parser implicitly creates an empty statement. Use the | 630 // the parser implicitly creates an empty statement. Use the |
639 // HasThenStatement() and HasElseStatement() functions to check if a | 631 // HasThenStatement() and HasElseStatement() functions to check if a |
640 // given if-statement has a then- or an else-part containing code. | 632 // given if-statement has a then- or an else-part containing code. |
641 class IfStatement: public Statement { | 633 class IfStatement: public Statement { |
642 public: | 634 public: |
643 IfStatement(Expression* condition, | 635 IfStatement(Expression* condition, |
644 Statement* then_statement, | 636 Statement* then_statement, |
645 Statement* else_statement) | 637 Statement* else_statement) |
646 : condition_(condition), | 638 : condition_(condition), |
647 then_statement_(then_statement), | 639 then_statement_(then_statement), |
648 else_statement_(else_statement) { } | 640 else_statement_(else_statement) { } |
649 | 641 |
650 virtual void Accept(AstVisitor* v); | 642 DECLARE_NODE_TYPE(IfStatement) |
651 | 643 |
652 bool HasThenStatement() const { return !then_statement()->IsEmpty(); } | 644 bool HasThenStatement() const { return !then_statement()->IsEmpty(); } |
653 bool HasElseStatement() const { return !else_statement()->IsEmpty(); } | 645 bool HasElseStatement() const { return !else_statement()->IsEmpty(); } |
654 | 646 |
655 Expression* condition() const { return condition_; } | 647 Expression* condition() const { return condition_; } |
656 Statement* then_statement() const { return then_statement_; } | 648 Statement* then_statement() const { return then_statement_; } |
657 void set_then_statement(Statement* stmt) { then_statement_ = stmt; } | 649 void set_then_statement(Statement* stmt) { then_statement_ = stmt; } |
658 Statement* else_statement() const { return else_statement_; } | 650 Statement* else_statement() const { return else_statement_; } |
659 void set_else_statement(Statement* stmt) { else_statement_ = stmt; } | 651 void set_else_statement(Statement* stmt) { else_statement_ = stmt; } |
660 | 652 |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
710 class TryCatchStatement: public TryStatement { | 702 class TryCatchStatement: public TryStatement { |
711 public: | 703 public: |
712 TryCatchStatement(Block* try_block, | 704 TryCatchStatement(Block* try_block, |
713 VariableProxy* catch_var, | 705 VariableProxy* catch_var, |
714 Block* catch_block) | 706 Block* catch_block) |
715 : TryStatement(try_block), | 707 : TryStatement(try_block), |
716 catch_var_(catch_var), | 708 catch_var_(catch_var), |
717 catch_block_(catch_block) { | 709 catch_block_(catch_block) { |
718 } | 710 } |
719 | 711 |
720 virtual void Accept(AstVisitor* v); | 712 DECLARE_NODE_TYPE(TryCatchStatement) |
721 | 713 |
722 VariableProxy* catch_var() const { return catch_var_; } | 714 VariableProxy* catch_var() const { return catch_var_; } |
723 Block* catch_block() const { return catch_block_; } | 715 Block* catch_block() const { return catch_block_; } |
724 | 716 |
725 private: | 717 private: |
726 VariableProxy* catch_var_; | 718 VariableProxy* catch_var_; |
727 Block* catch_block_; | 719 Block* catch_block_; |
728 }; | 720 }; |
729 | 721 |
730 | 722 |
731 class TryFinallyStatement: public TryStatement { | 723 class TryFinallyStatement: public TryStatement { |
732 public: | 724 public: |
733 TryFinallyStatement(Block* try_block, Block* finally_block) | 725 TryFinallyStatement(Block* try_block, Block* finally_block) |
734 : TryStatement(try_block), | 726 : TryStatement(try_block), |
735 finally_block_(finally_block) { } | 727 finally_block_(finally_block) { } |
736 | 728 |
737 virtual void Accept(AstVisitor* v); | 729 DECLARE_NODE_TYPE(TryFinallyStatement) |
738 | 730 |
739 Block* finally_block() const { return finally_block_; } | 731 Block* finally_block() const { return finally_block_; } |
740 | 732 |
741 private: | 733 private: |
742 Block* finally_block_; | 734 Block* finally_block_; |
743 }; | 735 }; |
744 | 736 |
745 | 737 |
746 class DebuggerStatement: public Statement { | 738 class DebuggerStatement: public Statement { |
747 public: | 739 public: |
748 virtual void Accept(AstVisitor* v); | 740 DECLARE_NODE_TYPE(DebuggerStatement) |
749 }; | 741 }; |
750 | 742 |
751 | 743 |
752 class EmptyStatement: public Statement { | 744 class EmptyStatement: public Statement { |
753 public: | 745 public: |
754 EmptyStatement() {} | 746 DECLARE_NODE_TYPE(EmptyStatement) |
755 | |
756 virtual void Accept(AstVisitor* v); | |
757 | |
758 // Type testing & conversion. | |
759 virtual EmptyStatement* AsEmptyStatement() { return this; } | |
760 }; | 747 }; |
761 | 748 |
762 | 749 |
763 class Literal: public Expression { | 750 class Literal: public Expression { |
764 public: | 751 public: |
765 explicit Literal(Handle<Object> handle) : handle_(handle) { } | 752 explicit Literal(Handle<Object> handle) : handle_(handle) { } |
766 | 753 |
767 virtual void Accept(AstVisitor* v); | 754 DECLARE_NODE_TYPE(Literal) |
| 755 |
768 virtual bool IsTrivial() { return true; } | 756 virtual bool IsTrivial() { return true; } |
769 virtual bool IsSmiLiteral() { return handle_->IsSmi(); } | 757 virtual bool IsSmiLiteral() { return handle_->IsSmi(); } |
770 | 758 |
771 // Type testing & conversion. | |
772 virtual Literal* AsLiteral() { return this; } | |
773 | |
774 // Check if this literal is identical to the other literal. | 759 // Check if this literal is identical to the other literal. |
775 bool IsIdenticalTo(const Literal* other) const { | 760 bool IsIdenticalTo(const Literal* other) const { |
776 return handle_.is_identical_to(other->handle_); | 761 return handle_.is_identical_to(other->handle_); |
777 } | 762 } |
778 | 763 |
779 virtual bool IsPropertyName() { | 764 virtual bool IsPropertyName() { |
780 if (handle_->IsSymbol()) { | 765 if (handle_->IsSymbol()) { |
781 uint32_t ignored; | 766 uint32_t ignored; |
782 return !String::cast(*handle_)->AsArrayIndex(&ignored); | 767 return !String::cast(*handle_)->AsArrayIndex(&ignored); |
783 } | 768 } |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
857 ZoneList<Property*>* properties, | 842 ZoneList<Property*>* properties, |
858 int literal_index, | 843 int literal_index, |
859 bool is_simple, | 844 bool is_simple, |
860 bool fast_elements, | 845 bool fast_elements, |
861 int depth) | 846 int depth) |
862 : MaterializedLiteral(literal_index, is_simple, depth), | 847 : MaterializedLiteral(literal_index, is_simple, depth), |
863 constant_properties_(constant_properties), | 848 constant_properties_(constant_properties), |
864 properties_(properties), | 849 properties_(properties), |
865 fast_elements_(fast_elements) {} | 850 fast_elements_(fast_elements) {} |
866 | 851 |
867 virtual ObjectLiteral* AsObjectLiteral() { return this; } | 852 DECLARE_NODE_TYPE(ObjectLiteral) |
868 virtual void Accept(AstVisitor* v); | |
869 | 853 |
870 Handle<FixedArray> constant_properties() const { | 854 Handle<FixedArray> constant_properties() const { |
871 return constant_properties_; | 855 return constant_properties_; |
872 } | 856 } |
873 ZoneList<Property*>* properties() const { return properties_; } | 857 ZoneList<Property*>* properties() const { return properties_; } |
874 | 858 |
875 bool fast_elements() const { return fast_elements_; } | 859 bool fast_elements() const { return fast_elements_; } |
876 | 860 |
877 private: | 861 private: |
878 Handle<FixedArray> constant_properties_; | 862 Handle<FixedArray> constant_properties_; |
879 ZoneList<Property*>* properties_; | 863 ZoneList<Property*>* properties_; |
880 bool fast_elements_; | 864 bool fast_elements_; |
881 }; | 865 }; |
882 | 866 |
883 | 867 |
884 // Node for capturing a regexp literal. | 868 // Node for capturing a regexp literal. |
885 class RegExpLiteral: public MaterializedLiteral { | 869 class RegExpLiteral: public MaterializedLiteral { |
886 public: | 870 public: |
887 RegExpLiteral(Handle<String> pattern, | 871 RegExpLiteral(Handle<String> pattern, |
888 Handle<String> flags, | 872 Handle<String> flags, |
889 int literal_index) | 873 int literal_index) |
890 : MaterializedLiteral(literal_index, false, 1), | 874 : MaterializedLiteral(literal_index, false, 1), |
891 pattern_(pattern), | 875 pattern_(pattern), |
892 flags_(flags) {} | 876 flags_(flags) {} |
893 | 877 |
894 virtual void Accept(AstVisitor* v); | 878 DECLARE_NODE_TYPE(RegExpLiteral) |
895 | 879 |
896 Handle<String> pattern() const { return pattern_; } | 880 Handle<String> pattern() const { return pattern_; } |
897 Handle<String> flags() const { return flags_; } | 881 Handle<String> flags() const { return flags_; } |
898 | 882 |
899 private: | 883 private: |
900 Handle<String> pattern_; | 884 Handle<String> pattern_; |
901 Handle<String> flags_; | 885 Handle<String> flags_; |
902 }; | 886 }; |
903 | 887 |
904 // An array literal has a literals object that is used | 888 // An array literal has a literals object that is used |
905 // for minimizing the work when constructing it at runtime. | 889 // for minimizing the work when constructing it at runtime. |
906 class ArrayLiteral: public MaterializedLiteral { | 890 class ArrayLiteral: public MaterializedLiteral { |
907 public: | 891 public: |
908 ArrayLiteral(Handle<FixedArray> constant_elements, | 892 ArrayLiteral(Handle<FixedArray> constant_elements, |
909 ZoneList<Expression*>* values, | 893 ZoneList<Expression*>* values, |
910 int literal_index, | 894 int literal_index, |
911 bool is_simple, | 895 bool is_simple, |
912 int depth) | 896 int depth) |
913 : MaterializedLiteral(literal_index, is_simple, depth), | 897 : MaterializedLiteral(literal_index, is_simple, depth), |
914 constant_elements_(constant_elements), | 898 constant_elements_(constant_elements), |
915 values_(values) {} | 899 values_(values) {} |
916 | 900 |
917 virtual void Accept(AstVisitor* v); | 901 DECLARE_NODE_TYPE(ArrayLiteral) |
918 virtual ArrayLiteral* AsArrayLiteral() { return this; } | |
919 | 902 |
920 Handle<FixedArray> constant_elements() const { return constant_elements_; } | 903 Handle<FixedArray> constant_elements() const { return constant_elements_; } |
921 ZoneList<Expression*>* values() const { return values_; } | 904 ZoneList<Expression*>* values() const { return values_; } |
922 | 905 |
923 private: | 906 private: |
924 Handle<FixedArray> constant_elements_; | 907 Handle<FixedArray> constant_elements_; |
925 ZoneList<Expression*>* values_; | 908 ZoneList<Expression*>* values_; |
926 }; | 909 }; |
927 | 910 |
928 | 911 |
929 // Node for constructing a context extension object for a catch block. | 912 // Node for constructing a context extension object for a catch block. |
930 // The catch context extension object has one property, the catch | 913 // The catch context extension object has one property, the catch |
931 // variable, which should be DontDelete. | 914 // variable, which should be DontDelete. |
932 class CatchExtensionObject: public Expression { | 915 class CatchExtensionObject: public Expression { |
933 public: | 916 public: |
934 CatchExtensionObject(Literal* key, VariableProxy* value) | 917 CatchExtensionObject(Literal* key, VariableProxy* value) |
935 : key_(key), value_(value) { | 918 : key_(key), value_(value) { |
936 } | 919 } |
937 | 920 |
938 virtual void Accept(AstVisitor* v); | 921 DECLARE_NODE_TYPE(CatchExtensionObject) |
939 | 922 |
940 Literal* key() const { return key_; } | 923 Literal* key() const { return key_; } |
941 VariableProxy* value() const { return value_; } | 924 VariableProxy* value() const { return value_; } |
942 | 925 |
943 private: | 926 private: |
944 Literal* key_; | 927 Literal* key_; |
945 VariableProxy* value_; | 928 VariableProxy* value_; |
946 }; | 929 }; |
947 | 930 |
948 | 931 |
949 class VariableProxy: public Expression { | 932 class VariableProxy: public Expression { |
950 public: | 933 public: |
951 explicit VariableProxy(Variable* var); | 934 explicit VariableProxy(Variable* var); |
952 | 935 |
953 virtual void Accept(AstVisitor* v); | 936 DECLARE_NODE_TYPE(VariableProxy) |
954 | 937 |
955 // Type testing & conversion | 938 // Type testing & conversion |
956 virtual Property* AsProperty() { | 939 virtual Property* AsProperty() { |
957 return var_ == NULL ? NULL : var_->AsProperty(); | 940 return var_ == NULL ? NULL : var_->AsProperty(); |
958 } | 941 } |
959 | 942 |
960 virtual VariableProxy* AsVariableProxy() { | |
961 return this; | |
962 } | |
963 | |
964 Variable* AsVariable() { | 943 Variable* AsVariable() { |
965 if (this == NULL || var_ == NULL) return NULL; | 944 if (this == NULL || var_ == NULL) return NULL; |
966 Expression* rewrite = var_->rewrite(); | 945 Expression* rewrite = var_->rewrite(); |
967 if (rewrite == NULL || rewrite->AsSlot() != NULL) return var_; | 946 if (rewrite == NULL || rewrite->AsSlot() != NULL) return var_; |
968 return NULL; | 947 return NULL; |
969 } | 948 } |
970 | 949 |
971 virtual bool IsValidLeftHandSide() { | 950 virtual bool IsValidLeftHandSide() { |
972 return var_ == NULL ? true : var_->IsValidLeftHandSide(); | 951 return var_ == NULL ? true : var_->IsValidLeftHandSide(); |
973 } | 952 } |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1048 // with lookup starting at the current context. index() | 1027 // with lookup starting at the current context. index() |
1049 // is invalid. | 1028 // is invalid. |
1050 LOOKUP | 1029 LOOKUP |
1051 }; | 1030 }; |
1052 | 1031 |
1053 Slot(Variable* var, Type type, int index) | 1032 Slot(Variable* var, Type type, int index) |
1054 : var_(var), type_(type), index_(index) { | 1033 : var_(var), type_(type), index_(index) { |
1055 ASSERT(var != NULL); | 1034 ASSERT(var != NULL); |
1056 } | 1035 } |
1057 | 1036 |
1058 virtual void Accept(AstVisitor* v); | 1037 DECLARE_NODE_TYPE(Slot) |
1059 | |
1060 // Type testing & conversion | |
1061 virtual Slot* AsSlot() { return this; } | |
1062 | 1038 |
1063 bool IsStackAllocated() { return type_ == PARAMETER || type_ == LOCAL; } | 1039 bool IsStackAllocated() { return type_ == PARAMETER || type_ == LOCAL; } |
1064 | 1040 |
1065 // Accessors | 1041 // Accessors |
1066 Variable* var() const { return var_; } | 1042 Variable* var() const { return var_; } |
1067 Type type() const { return type_; } | 1043 Type type() const { return type_; } |
1068 int index() const { return index_; } | 1044 int index() const { return index_; } |
1069 bool is_arguments() const { return var_->is_arguments(); } | 1045 bool is_arguments() const { return var_->is_arguments(); } |
1070 | 1046 |
1071 private: | 1047 private: |
1072 Variable* var_; | 1048 Variable* var_; |
1073 Type type_; | 1049 Type type_; |
1074 int index_; | 1050 int index_; |
1075 }; | 1051 }; |
1076 | 1052 |
1077 | 1053 |
1078 class Property: public Expression { | 1054 class Property: public Expression { |
1079 public: | 1055 public: |
1080 // Synthetic properties are property lookups introduced by the system, | 1056 // Synthetic properties are property lookups introduced by the system, |
1081 // to objects that aren't visible to the user. Function calls to synthetic | 1057 // to objects that aren't visible to the user. Function calls to synthetic |
1082 // properties should use the global object as receiver, not the base object | 1058 // properties should use the global object as receiver, not the base object |
1083 // of the resolved Reference. | 1059 // of the resolved Reference. |
1084 enum Type { NORMAL, SYNTHETIC }; | 1060 enum Type { NORMAL, SYNTHETIC }; |
1085 Property(Expression* obj, Expression* key, int pos, Type type = NORMAL) | 1061 Property(Expression* obj, Expression* key, int pos, Type type = NORMAL) |
1086 : obj_(obj), key_(key), pos_(pos), type_(type) { } | 1062 : obj_(obj), key_(key), pos_(pos), type_(type) { } |
1087 | 1063 |
1088 virtual void Accept(AstVisitor* v); | 1064 DECLARE_NODE_TYPE(Property) |
1089 | |
1090 // Type testing & conversion | |
1091 virtual Property* AsProperty() { return this; } | |
1092 | 1065 |
1093 virtual bool IsValidLeftHandSide() { return true; } | 1066 virtual bool IsValidLeftHandSide() { return true; } |
1094 | 1067 |
1095 Expression* obj() const { return obj_; } | 1068 Expression* obj() const { return obj_; } |
1096 Expression* key() const { return key_; } | 1069 Expression* key() const { return key_; } |
1097 int position() const { return pos_; } | 1070 int position() const { return pos_; } |
1098 bool is_synthetic() const { return type_ == SYNTHETIC; } | 1071 bool is_synthetic() const { return type_ == SYNTHETIC; } |
1099 | 1072 |
1100 // Returns a property singleton property access on 'this'. Used | 1073 // Returns a property singleton property access on 'this'. Used |
1101 // during preparsing. | 1074 // during preparsing. |
1102 static Property* this_property() { return &this_property_; } | 1075 static Property* this_property() { return &this_property_; } |
1103 | 1076 |
1104 private: | 1077 private: |
1105 Expression* obj_; | 1078 Expression* obj_; |
1106 Expression* key_; | 1079 Expression* key_; |
1107 int pos_; | 1080 int pos_; |
1108 Type type_; | 1081 Type type_; |
1109 | 1082 |
1110 // Dummy property used during preparsing. | 1083 // Dummy property used during preparsing. |
1111 static Property this_property_; | 1084 static Property this_property_; |
1112 }; | 1085 }; |
1113 | 1086 |
1114 | 1087 |
1115 class Call: public Expression { | 1088 class Call: public Expression { |
1116 public: | 1089 public: |
1117 Call(Expression* expression, ZoneList<Expression*>* arguments, int pos) | 1090 Call(Expression* expression, ZoneList<Expression*>* arguments, int pos) |
1118 : expression_(expression), arguments_(arguments), pos_(pos) { } | 1091 : expression_(expression), arguments_(arguments), pos_(pos) { } |
1119 | 1092 |
1120 virtual void Accept(AstVisitor* v); | 1093 DECLARE_NODE_TYPE(Call) |
1121 | |
1122 // Type testing and conversion. | |
1123 virtual Call* AsCall() { return this; } | |
1124 | 1094 |
1125 Expression* expression() const { return expression_; } | 1095 Expression* expression() const { return expression_; } |
1126 ZoneList<Expression*>* arguments() const { return arguments_; } | 1096 ZoneList<Expression*>* arguments() const { return arguments_; } |
1127 int position() { return pos_; } | 1097 int position() { return pos_; } |
1128 | 1098 |
1129 static Call* sentinel() { return &sentinel_; } | 1099 static Call* sentinel() { return &sentinel_; } |
1130 | 1100 |
1131 private: | 1101 private: |
1132 Expression* expression_; | 1102 Expression* expression_; |
1133 ZoneList<Expression*>* arguments_; | 1103 ZoneList<Expression*>* arguments_; |
1134 int pos_; | 1104 int pos_; |
1135 | 1105 |
1136 static Call sentinel_; | 1106 static Call sentinel_; |
1137 }; | 1107 }; |
1138 | 1108 |
1139 | 1109 |
1140 class CallNew: public Expression { | 1110 class CallNew: public Expression { |
1141 public: | 1111 public: |
1142 CallNew(Expression* expression, ZoneList<Expression*>* arguments, int pos) | 1112 CallNew(Expression* expression, ZoneList<Expression*>* arguments, int pos) |
1143 : expression_(expression), arguments_(arguments), pos_(pos) { } | 1113 : expression_(expression), arguments_(arguments), pos_(pos) { } |
1144 | 1114 |
1145 virtual void Accept(AstVisitor* v); | 1115 DECLARE_NODE_TYPE(CallNew) |
1146 | 1116 |
1147 Expression* expression() const { return expression_; } | 1117 Expression* expression() const { return expression_; } |
1148 ZoneList<Expression*>* arguments() const { return arguments_; } | 1118 ZoneList<Expression*>* arguments() const { return arguments_; } |
1149 int position() { return pos_; } | 1119 int position() { return pos_; } |
1150 | 1120 |
1151 private: | 1121 private: |
1152 Expression* expression_; | 1122 Expression* expression_; |
1153 ZoneList<Expression*>* arguments_; | 1123 ZoneList<Expression*>* arguments_; |
1154 int pos_; | 1124 int pos_; |
1155 }; | 1125 }; |
1156 | 1126 |
1157 | 1127 |
1158 // The CallRuntime class does not represent any official JavaScript | 1128 // The CallRuntime class does not represent any official JavaScript |
1159 // language construct. Instead it is used to call a C or JS function | 1129 // language construct. Instead it is used to call a C or JS function |
1160 // with a set of arguments. This is used from the builtins that are | 1130 // with a set of arguments. This is used from the builtins that are |
1161 // implemented in JavaScript (see "v8natives.js"). | 1131 // implemented in JavaScript (see "v8natives.js"). |
1162 class CallRuntime: public Expression { | 1132 class CallRuntime: public Expression { |
1163 public: | 1133 public: |
1164 CallRuntime(Handle<String> name, | 1134 CallRuntime(Handle<String> name, |
1165 Runtime::Function* function, | 1135 Runtime::Function* function, |
1166 ZoneList<Expression*>* arguments) | 1136 ZoneList<Expression*>* arguments) |
1167 : name_(name), function_(function), arguments_(arguments) { } | 1137 : name_(name), function_(function), arguments_(arguments) { } |
1168 | 1138 |
1169 virtual void Accept(AstVisitor* v); | 1139 DECLARE_NODE_TYPE(CallRuntime) |
1170 | 1140 |
1171 Handle<String> name() const { return name_; } | 1141 Handle<String> name() const { return name_; } |
1172 Runtime::Function* function() const { return function_; } | 1142 Runtime::Function* function() const { return function_; } |
1173 ZoneList<Expression*>* arguments() const { return arguments_; } | 1143 ZoneList<Expression*>* arguments() const { return arguments_; } |
1174 bool is_jsruntime() const { return function_ == NULL; } | 1144 bool is_jsruntime() const { return function_ == NULL; } |
1175 | 1145 |
1176 private: | 1146 private: |
1177 Handle<String> name_; | 1147 Handle<String> name_; |
1178 Runtime::Function* function_; | 1148 Runtime::Function* function_; |
1179 ZoneList<Expression*>* arguments_; | 1149 ZoneList<Expression*>* arguments_; |
1180 }; | 1150 }; |
1181 | 1151 |
1182 | 1152 |
1183 class UnaryOperation: public Expression { | 1153 class UnaryOperation: public Expression { |
1184 public: | 1154 public: |
1185 UnaryOperation(Token::Value op, Expression* expression) | 1155 UnaryOperation(Token::Value op, Expression* expression) |
1186 : op_(op), expression_(expression) { | 1156 : op_(op), expression_(expression) { |
1187 ASSERT(Token::IsUnaryOp(op)); | 1157 ASSERT(Token::IsUnaryOp(op)); |
1188 } | 1158 } |
1189 | 1159 |
1190 virtual void Accept(AstVisitor* v); | 1160 DECLARE_NODE_TYPE(UnaryOperation) |
| 1161 |
1191 virtual bool ResultOverwriteAllowed(); | 1162 virtual bool ResultOverwriteAllowed(); |
1192 | 1163 |
1193 // Type testing & conversion | |
1194 virtual UnaryOperation* AsUnaryOperation() { return this; } | |
1195 | |
1196 Token::Value op() const { return op_; } | 1164 Token::Value op() const { return op_; } |
1197 Expression* expression() const { return expression_; } | 1165 Expression* expression() const { return expression_; } |
1198 | 1166 |
1199 private: | 1167 private: |
1200 Token::Value op_; | 1168 Token::Value op_; |
1201 Expression* expression_; | 1169 Expression* expression_; |
1202 }; | 1170 }; |
1203 | 1171 |
1204 | 1172 |
1205 class BinaryOperation: public Expression { | 1173 class BinaryOperation: public Expression { |
1206 public: | 1174 public: |
1207 BinaryOperation(Token::Value op, | 1175 BinaryOperation(Token::Value op, |
1208 Expression* left, | 1176 Expression* left, |
1209 Expression* right, | 1177 Expression* right, |
1210 int pos) | 1178 int pos) |
1211 : op_(op), left_(left), right_(right), pos_(pos) { | 1179 : op_(op), left_(left), right_(right), pos_(pos) { |
1212 ASSERT(Token::IsBinaryOp(op)); | 1180 ASSERT(Token::IsBinaryOp(op)); |
1213 } | 1181 } |
1214 | 1182 |
1215 // Create the binary operation corresponding to a compound assignment. | 1183 // Create the binary operation corresponding to a compound assignment. |
1216 explicit BinaryOperation(Assignment* assignment); | 1184 explicit BinaryOperation(Assignment* assignment); |
1217 | 1185 |
1218 virtual void Accept(AstVisitor* v); | 1186 DECLARE_NODE_TYPE(BinaryOperation) |
| 1187 |
1219 virtual bool ResultOverwriteAllowed(); | 1188 virtual bool ResultOverwriteAllowed(); |
1220 | 1189 |
1221 // Type testing & conversion | |
1222 virtual BinaryOperation* AsBinaryOperation() { return this; } | |
1223 | |
1224 Token::Value op() const { return op_; } | 1190 Token::Value op() const { return op_; } |
1225 Expression* left() const { return left_; } | 1191 Expression* left() const { return left_; } |
1226 Expression* right() const { return right_; } | 1192 Expression* right() const { return right_; } |
1227 int position() const { return pos_; } | 1193 int position() const { return pos_; } |
1228 | 1194 |
1229 private: | 1195 private: |
1230 Token::Value op_; | 1196 Token::Value op_; |
1231 Expression* left_; | 1197 Expression* left_; |
1232 Expression* right_; | 1198 Expression* right_; |
1233 int pos_; | 1199 int pos_; |
1234 }; | 1200 }; |
1235 | 1201 |
1236 | 1202 |
1237 class IncrementOperation: public Expression { | 1203 class IncrementOperation: public Expression { |
1238 public: | 1204 public: |
1239 IncrementOperation(Token::Value op, Expression* expr) | 1205 IncrementOperation(Token::Value op, Expression* expr) |
1240 : op_(op), expression_(expr) { | 1206 : op_(op), expression_(expr) { |
1241 ASSERT(Token::IsCountOp(op)); | 1207 ASSERT(Token::IsCountOp(op)); |
1242 } | 1208 } |
1243 | 1209 |
| 1210 DECLARE_NODE_TYPE(IncrementOperation) |
| 1211 |
1244 Token::Value op() const { return op_; } | 1212 Token::Value op() const { return op_; } |
1245 bool is_increment() { return op_ == Token::INC; } | 1213 bool is_increment() { return op_ == Token::INC; } |
1246 Expression* expression() const { return expression_; } | 1214 Expression* expression() const { return expression_; } |
1247 | 1215 |
1248 virtual void Accept(AstVisitor* v); | |
1249 | |
1250 private: | 1216 private: |
1251 Token::Value op_; | 1217 Token::Value op_; |
1252 Expression* expression_; | 1218 Expression* expression_; |
1253 int pos_; | 1219 int pos_; |
1254 }; | 1220 }; |
1255 | 1221 |
1256 | 1222 |
1257 class CountOperation: public Expression { | 1223 class CountOperation: public Expression { |
1258 public: | 1224 public: |
1259 CountOperation(bool is_prefix, IncrementOperation* increment, int pos) | 1225 CountOperation(bool is_prefix, IncrementOperation* increment, int pos) |
1260 : is_prefix_(is_prefix), increment_(increment), pos_(pos) { } | 1226 : is_prefix_(is_prefix), increment_(increment), pos_(pos) { } |
1261 | 1227 |
1262 virtual void Accept(AstVisitor* v); | 1228 DECLARE_NODE_TYPE(CountOperation) |
1263 | |
1264 virtual CountOperation* AsCountOperation() { return this; } | |
1265 | 1229 |
1266 bool is_prefix() const { return is_prefix_; } | 1230 bool is_prefix() const { return is_prefix_; } |
1267 bool is_postfix() const { return !is_prefix_; } | 1231 bool is_postfix() const { return !is_prefix_; } |
1268 | 1232 |
1269 Token::Value op() const { return increment_->op(); } | 1233 Token::Value op() const { return increment_->op(); } |
1270 Token::Value binary_op() { | 1234 Token::Value binary_op() { |
1271 return (op() == Token::INC) ? Token::ADD : Token::SUB; | 1235 return (op() == Token::INC) ? Token::ADD : Token::SUB; |
1272 } | 1236 } |
1273 | 1237 |
1274 Expression* expression() const { return increment_->expression(); } | 1238 Expression* expression() const { return increment_->expression(); } |
(...skipping 12 matching lines...) Expand all Loading... |
1287 class CompareOperation: public Expression { | 1251 class CompareOperation: public Expression { |
1288 public: | 1252 public: |
1289 CompareOperation(Token::Value op, | 1253 CompareOperation(Token::Value op, |
1290 Expression* left, | 1254 Expression* left, |
1291 Expression* right, | 1255 Expression* right, |
1292 int pos) | 1256 int pos) |
1293 : op_(op), left_(left), right_(right), pos_(pos) { | 1257 : op_(op), left_(left), right_(right), pos_(pos) { |
1294 ASSERT(Token::IsCompareOp(op)); | 1258 ASSERT(Token::IsCompareOp(op)); |
1295 } | 1259 } |
1296 | 1260 |
1297 virtual void Accept(AstVisitor* v); | 1261 DECLARE_NODE_TYPE(CompareOperation) |
1298 | 1262 |
1299 Token::Value op() const { return op_; } | 1263 Token::Value op() const { return op_; } |
1300 Expression* left() const { return left_; } | 1264 Expression* left() const { return left_; } |
1301 Expression* right() const { return right_; } | 1265 Expression* right() const { return right_; } |
1302 int position() const { return pos_; } | 1266 int position() const { return pos_; } |
1303 | 1267 |
1304 // Type testing & conversion | |
1305 virtual CompareOperation* AsCompareOperation() { return this; } | |
1306 | |
1307 private: | 1268 private: |
1308 Token::Value op_; | 1269 Token::Value op_; |
1309 Expression* left_; | 1270 Expression* left_; |
1310 Expression* right_; | 1271 Expression* right_; |
1311 int pos_; | 1272 int pos_; |
1312 }; | 1273 }; |
1313 | 1274 |
1314 | 1275 |
1315 class CompareToNull: public Expression { | 1276 class CompareToNull: public Expression { |
1316 public: | 1277 public: |
1317 CompareToNull(bool is_strict, Expression* expression) | 1278 CompareToNull(bool is_strict, Expression* expression) |
1318 : is_strict_(is_strict), expression_(expression) { } | 1279 : is_strict_(is_strict), expression_(expression) { } |
1319 | 1280 |
1320 virtual void Accept(AstVisitor* v); | 1281 DECLARE_NODE_TYPE(CompareToNull) |
1321 | 1282 |
1322 bool is_strict() const { return is_strict_; } | 1283 bool is_strict() const { return is_strict_; } |
1323 Token::Value op() const { return is_strict_ ? Token::EQ_STRICT : Token::EQ; } | 1284 Token::Value op() const { return is_strict_ ? Token::EQ_STRICT : Token::EQ; } |
1324 Expression* expression() const { return expression_; } | 1285 Expression* expression() const { return expression_; } |
1325 | 1286 |
1326 private: | 1287 private: |
1327 bool is_strict_; | 1288 bool is_strict_; |
1328 Expression* expression_; | 1289 Expression* expression_; |
1329 }; | 1290 }; |
1330 | 1291 |
1331 | 1292 |
1332 class Conditional: public Expression { | 1293 class Conditional: public Expression { |
1333 public: | 1294 public: |
1334 Conditional(Expression* condition, | 1295 Conditional(Expression* condition, |
1335 Expression* then_expression, | 1296 Expression* then_expression, |
1336 Expression* else_expression, | 1297 Expression* else_expression, |
1337 int then_expression_position, | 1298 int then_expression_position, |
1338 int else_expression_position) | 1299 int else_expression_position) |
1339 : condition_(condition), | 1300 : condition_(condition), |
1340 then_expression_(then_expression), | 1301 then_expression_(then_expression), |
1341 else_expression_(else_expression), | 1302 else_expression_(else_expression), |
1342 then_expression_position_(then_expression_position), | 1303 then_expression_position_(then_expression_position), |
1343 else_expression_position_(else_expression_position) { } | 1304 else_expression_position_(else_expression_position) { } |
1344 | 1305 |
1345 virtual void Accept(AstVisitor* v); | 1306 DECLARE_NODE_TYPE(Conditional) |
1346 | 1307 |
1347 Expression* condition() const { return condition_; } | 1308 Expression* condition() const { return condition_; } |
1348 Expression* then_expression() const { return then_expression_; } | 1309 Expression* then_expression() const { return then_expression_; } |
1349 Expression* else_expression() const { return else_expression_; } | 1310 Expression* else_expression() const { return else_expression_; } |
1350 | 1311 |
1351 int then_expression_position() { return then_expression_position_; } | 1312 int then_expression_position() { return then_expression_position_; } |
1352 int else_expression_position() { return else_expression_position_; } | 1313 int else_expression_position() { return else_expression_position_; } |
1353 | 1314 |
1354 private: | 1315 private: |
1355 Expression* condition_; | 1316 Expression* condition_; |
1356 Expression* then_expression_; | 1317 Expression* then_expression_; |
1357 Expression* else_expression_; | 1318 Expression* else_expression_; |
1358 int then_expression_position_; | 1319 int then_expression_position_; |
1359 int else_expression_position_; | 1320 int else_expression_position_; |
1360 }; | 1321 }; |
1361 | 1322 |
1362 | 1323 |
1363 class Assignment: public Expression { | 1324 class Assignment: public Expression { |
1364 public: | 1325 public: |
1365 Assignment(Token::Value op, Expression* target, Expression* value, int pos) | 1326 Assignment(Token::Value op, Expression* target, Expression* value, int pos) |
1366 : op_(op), target_(target), value_(value), pos_(pos), | 1327 : op_(op), target_(target), value_(value), pos_(pos), |
1367 block_start_(false), block_end_(false) { | 1328 block_start_(false), block_end_(false) { |
1368 ASSERT(Token::IsAssignmentOp(op)); | 1329 ASSERT(Token::IsAssignmentOp(op)); |
1369 } | 1330 } |
1370 | 1331 |
1371 virtual void Accept(AstVisitor* v); | 1332 DECLARE_NODE_TYPE(Assignment) |
1372 virtual Assignment* AsAssignment() { return this; } | |
1373 | 1333 |
1374 Assignment* AsSimpleAssignment() { return !is_compound() ? this : NULL; } | 1334 Assignment* AsSimpleAssignment() { return !is_compound() ? this : NULL; } |
1375 | 1335 |
1376 Token::Value binary_op() const; | 1336 Token::Value binary_op() const; |
1377 | 1337 |
1378 Token::Value op() const { return op_; } | 1338 Token::Value op() const { return op_; } |
1379 Expression* target() const { return target_; } | 1339 Expression* target() const { return target_; } |
1380 Expression* value() const { return value_; } | 1340 Expression* value() const { return value_; } |
1381 int position() { return pos_; } | 1341 int position() { return pos_; } |
1382 // This check relies on the definition order of token in token.h. | 1342 // This check relies on the definition order of token in token.h. |
(...skipping 16 matching lines...) Expand all Loading... |
1399 bool block_start_; | 1359 bool block_start_; |
1400 bool block_end_; | 1360 bool block_end_; |
1401 }; | 1361 }; |
1402 | 1362 |
1403 | 1363 |
1404 class Throw: public Expression { | 1364 class Throw: public Expression { |
1405 public: | 1365 public: |
1406 Throw(Expression* exception, int pos) | 1366 Throw(Expression* exception, int pos) |
1407 : exception_(exception), pos_(pos) {} | 1367 : exception_(exception), pos_(pos) {} |
1408 | 1368 |
1409 virtual void Accept(AstVisitor* v); | 1369 DECLARE_NODE_TYPE(Throw) |
1410 | 1370 |
1411 Expression* exception() const { return exception_; } | 1371 Expression* exception() const { return exception_; } |
1412 int position() const { return pos_; } | 1372 int position() const { return pos_; } |
1413 | 1373 |
1414 private: | 1374 private: |
1415 Expression* exception_; | 1375 Expression* exception_; |
1416 int pos_; | 1376 int pos_; |
1417 }; | 1377 }; |
1418 | 1378 |
1419 | 1379 |
(...skipping 25 matching lines...) Expand all Loading... |
1445 is_expression_(is_expression), | 1405 is_expression_(is_expression), |
1446 contains_loops_(contains_loops), | 1406 contains_loops_(contains_loops), |
1447 function_token_position_(RelocInfo::kNoPosition), | 1407 function_token_position_(RelocInfo::kNoPosition), |
1448 inferred_name_(Heap::empty_string()), | 1408 inferred_name_(Heap::empty_string()), |
1449 try_full_codegen_(false) { | 1409 try_full_codegen_(false) { |
1450 #ifdef DEBUG | 1410 #ifdef DEBUG |
1451 already_compiled_ = false; | 1411 already_compiled_ = false; |
1452 #endif | 1412 #endif |
1453 } | 1413 } |
1454 | 1414 |
1455 virtual void Accept(AstVisitor* v); | 1415 DECLARE_NODE_TYPE(FunctionLiteral) |
1456 | |
1457 // Type testing & conversion | |
1458 virtual FunctionLiteral* AsFunctionLiteral() { return this; } | |
1459 | 1416 |
1460 Handle<String> name() const { return name_; } | 1417 Handle<String> name() const { return name_; } |
1461 Scope* scope() const { return scope_; } | 1418 Scope* scope() const { return scope_; } |
1462 ZoneList<Statement*>* body() const { return body_; } | 1419 ZoneList<Statement*>* body() const { return body_; } |
1463 void set_function_token_position(int pos) { function_token_position_ = pos; } | 1420 void set_function_token_position(int pos) { function_token_position_ = pos; } |
1464 int function_token_position() const { return function_token_position_; } | 1421 int function_token_position() const { return function_token_position_; } |
1465 int start_position() const { return start_position_; } | 1422 int start_position() const { return start_position_; } |
1466 int end_position() const { return end_position_; } | 1423 int end_position() const { return end_position_; } |
1467 bool is_expression() const { return is_expression_; } | 1424 bool is_expression() const { return is_expression_; } |
1468 bool contains_loops() const { return contains_loops_; } | 1425 bool contains_loops() const { return contains_loops_; } |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1515 #endif | 1472 #endif |
1516 }; | 1473 }; |
1517 | 1474 |
1518 | 1475 |
1519 class SharedFunctionInfoLiteral: public Expression { | 1476 class SharedFunctionInfoLiteral: public Expression { |
1520 public: | 1477 public: |
1521 explicit SharedFunctionInfoLiteral( | 1478 explicit SharedFunctionInfoLiteral( |
1522 Handle<SharedFunctionInfo> shared_function_info) | 1479 Handle<SharedFunctionInfo> shared_function_info) |
1523 : shared_function_info_(shared_function_info) { } | 1480 : shared_function_info_(shared_function_info) { } |
1524 | 1481 |
| 1482 DECLARE_NODE_TYPE(SharedFunctionInfoLiteral) |
| 1483 |
1525 Handle<SharedFunctionInfo> shared_function_info() const { | 1484 Handle<SharedFunctionInfo> shared_function_info() const { |
1526 return shared_function_info_; | 1485 return shared_function_info_; |
1527 } | 1486 } |
1528 | 1487 |
1529 virtual void Accept(AstVisitor* v); | |
1530 | |
1531 private: | 1488 private: |
1532 Handle<SharedFunctionInfo> shared_function_info_; | 1489 Handle<SharedFunctionInfo> shared_function_info_; |
1533 }; | 1490 }; |
1534 | 1491 |
1535 | 1492 |
1536 class ThisFunction: public Expression { | 1493 class ThisFunction: public Expression { |
1537 public: | 1494 public: |
1538 virtual void Accept(AstVisitor* v); | 1495 DECLARE_NODE_TYPE(ThisFunction) |
1539 }; | 1496 }; |
1540 | 1497 |
1541 | 1498 |
1542 // ---------------------------------------------------------------------------- | 1499 // ---------------------------------------------------------------------------- |
1543 // Regular expressions | 1500 // Regular expressions |
1544 | 1501 |
1545 | 1502 |
1546 class RegExpVisitor BASE_EMBEDDED { | 1503 class RegExpVisitor BASE_EMBEDDED { |
1547 public: | 1504 public: |
1548 virtual ~RegExpVisitor() { } | 1505 virtual ~RegExpVisitor() { } |
(...skipping 370 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1919 AST_NODE_LIST(DEF_VISIT) | 1876 AST_NODE_LIST(DEF_VISIT) |
1920 #undef DEF_VISIT | 1877 #undef DEF_VISIT |
1921 | 1878 |
1922 private: | 1879 private: |
1923 bool stack_overflow_; | 1880 bool stack_overflow_; |
1924 }; | 1881 }; |
1925 | 1882 |
1926 } } // namespace v8::internal | 1883 } } // namespace v8::internal |
1927 | 1884 |
1928 #endif // V8_AST_H_ | 1885 #endif // V8_AST_H_ |
OLD | NEW |