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 333 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
344 // Type testing & conversion. | 344 // Type testing & conversion. |
345 virtual BreakableStatement* AsBreakableStatement() { return this; } | 345 virtual BreakableStatement* AsBreakableStatement() { return this; } |
346 | 346 |
347 // Code generation | 347 // Code generation |
348 BreakTarget* break_target() { return &break_target_; } | 348 BreakTarget* break_target() { return &break_target_; } |
349 | 349 |
350 // Testers. | 350 // Testers. |
351 bool is_target_for_anonymous() const { return type_ == TARGET_FOR_ANONYMOUS; } | 351 bool is_target_for_anonymous() const { return type_ == TARGET_FOR_ANONYMOUS; } |
352 | 352 |
353 protected: | 353 protected: |
354 BreakableStatement(ZoneStringList* labels, Type type) | 354 inline BreakableStatement(ZoneStringList* labels, Type type); |
355 : labels_(labels), type_(type) { | |
356 ASSERT(labels == NULL || labels->length() > 0); | |
357 } | |
358 | 355 |
359 explicit BreakableStatement(BreakableStatement* other); | 356 explicit BreakableStatement(BreakableStatement* other); |
360 | 357 |
361 private: | 358 private: |
362 ZoneStringList* labels_; | 359 ZoneStringList* labels_; |
363 Type type_; | 360 Type type_; |
364 BreakTarget break_target_; | 361 BreakTarget break_target_; |
365 }; | 362 }; |
366 | 363 |
367 | 364 |
368 class Block: public BreakableStatement { | 365 class Block: public BreakableStatement { |
369 public: | 366 public: |
370 Block(ZoneStringList* labels, int capacity, bool is_initializer_block) | 367 inline Block(ZoneStringList* labels, int capacity, bool is_initializer_block); |
371 : BreakableStatement(labels, TARGET_FOR_NAMED_ONLY), | |
372 statements_(capacity), | |
373 is_initializer_block_(is_initializer_block) { } | |
374 | 368 |
375 // Construct a clone initialized from the original block and | 369 // Construct a clone initialized from the original block and |
376 // a deep copy of all statements of the original block. | 370 // a deep copy of all statements of the original block. |
377 Block(Block* other, ZoneList<Statement*>* statements); | 371 Block(Block* other, ZoneList<Statement*>* statements); |
378 | 372 |
379 virtual void Accept(AstVisitor* v); | 373 virtual void Accept(AstVisitor* v); |
380 | 374 |
381 virtual Block* AsBlock() { return this; } | 375 virtual Block* AsBlock() { return this; } |
382 | 376 |
383 virtual Assignment* StatementAsSimpleAssignment() { | 377 virtual Assignment* StatementAsSimpleAssignment() { |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
430 // Type testing & conversion. | 424 // Type testing & conversion. |
431 virtual IterationStatement* AsIterationStatement() { return this; } | 425 virtual IterationStatement* AsIterationStatement() { return this; } |
432 | 426 |
433 Statement* body() const { return body_; } | 427 Statement* body() const { return body_; } |
434 void set_body(Statement* stmt) { body_ = stmt; } | 428 void set_body(Statement* stmt) { body_ = stmt; } |
435 | 429 |
436 // Code generation | 430 // Code generation |
437 BreakTarget* continue_target() { return &continue_target_; } | 431 BreakTarget* continue_target() { return &continue_target_; } |
438 | 432 |
439 protected: | 433 protected: |
440 explicit IterationStatement(ZoneStringList* labels) | 434 explicit inline IterationStatement(ZoneStringList* labels); |
441 : BreakableStatement(labels, TARGET_FOR_ANONYMOUS), body_(NULL) { } | |
442 | 435 |
443 // Construct a clone initialized from original and | 436 // Construct a clone initialized from original and |
444 // a deep copy of the original body. | 437 // a deep copy of the original body. |
445 IterationStatement(IterationStatement* other, Statement* body); | 438 IterationStatement(IterationStatement* other, Statement* body); |
446 | 439 |
447 void Initialize(Statement* body) { | 440 void Initialize(Statement* body) { |
448 body_ = body; | 441 body_ = body; |
449 } | 442 } |
450 | 443 |
451 private: | 444 private: |
452 Statement* body_; | 445 Statement* body_; |
453 BreakTarget continue_target_; | 446 BreakTarget continue_target_; |
454 }; | 447 }; |
455 | 448 |
456 | 449 |
457 class DoWhileStatement: public IterationStatement { | 450 class DoWhileStatement: public IterationStatement { |
458 public: | 451 public: |
459 explicit DoWhileStatement(ZoneStringList* labels) | 452 explicit inline DoWhileStatement(ZoneStringList* labels); |
460 : IterationStatement(labels), cond_(NULL), condition_position_(-1) { | |
461 } | |
462 | 453 |
463 void Initialize(Expression* cond, Statement* body) { | 454 void Initialize(Expression* cond, Statement* body) { |
464 IterationStatement::Initialize(body); | 455 IterationStatement::Initialize(body); |
465 cond_ = cond; | 456 cond_ = cond; |
466 } | 457 } |
467 | 458 |
468 virtual void Accept(AstVisitor* v); | 459 virtual void Accept(AstVisitor* v); |
469 | 460 |
470 Expression* cond() const { return cond_; } | 461 Expression* cond() const { return cond_; } |
471 | 462 |
472 // Position where condition expression starts. We need it to make | 463 // Position where condition expression starts. We need it to make |
473 // the loop's condition a breakable location. | 464 // the loop's condition a breakable location. |
474 int condition_position() { return condition_position_; } | 465 int condition_position() { return condition_position_; } |
475 void set_condition_position(int pos) { condition_position_ = pos; } | 466 void set_condition_position(int pos) { condition_position_ = pos; } |
476 | 467 |
477 private: | 468 private: |
478 Expression* cond_; | 469 Expression* cond_; |
479 int condition_position_; | 470 int condition_position_; |
480 }; | 471 }; |
481 | 472 |
482 | 473 |
483 class WhileStatement: public IterationStatement { | 474 class WhileStatement: public IterationStatement { |
484 public: | 475 public: |
485 explicit WhileStatement(ZoneStringList* labels) | 476 explicit WhileStatement(ZoneStringList* labels); |
486 : IterationStatement(labels), | |
487 cond_(NULL), | |
488 may_have_function_literal_(true) { | |
489 } | |
490 | 477 |
491 void Initialize(Expression* cond, Statement* body) { | 478 void Initialize(Expression* cond, Statement* body) { |
492 IterationStatement::Initialize(body); | 479 IterationStatement::Initialize(body); |
493 cond_ = cond; | 480 cond_ = cond; |
494 } | 481 } |
495 | 482 |
496 virtual void Accept(AstVisitor* v); | 483 virtual void Accept(AstVisitor* v); |
497 | 484 |
498 Expression* cond() const { return cond_; } | 485 Expression* cond() const { return cond_; } |
499 bool may_have_function_literal() const { | 486 bool may_have_function_literal() const { |
500 return may_have_function_literal_; | 487 return may_have_function_literal_; |
501 } | 488 } |
502 | 489 |
503 private: | 490 private: |
504 Expression* cond_; | 491 Expression* cond_; |
505 // True if there is a function literal subexpression in the condition. | 492 // True if there is a function literal subexpression in the condition. |
506 bool may_have_function_literal_; | 493 bool may_have_function_literal_; |
507 | 494 |
508 friend class AstOptimizer; | 495 friend class AstOptimizer; |
509 }; | 496 }; |
510 | 497 |
511 | 498 |
512 class ForStatement: public IterationStatement { | 499 class ForStatement: public IterationStatement { |
513 public: | 500 public: |
514 explicit ForStatement(ZoneStringList* labels) | 501 explicit inline ForStatement(ZoneStringList* labels); |
515 : IterationStatement(labels), | |
516 init_(NULL), | |
517 cond_(NULL), | |
518 next_(NULL), | |
519 may_have_function_literal_(true), | |
520 loop_variable_(NULL), | |
521 peel_this_loop_(false) {} | |
522 | 502 |
523 // Construct a for-statement initialized from another for-statement | 503 // Construct a for-statement initialized from another for-statement |
524 // and deep copies of all parts of the original statement. | 504 // and deep copies of all parts of the original statement. |
525 ForStatement(ForStatement* other, | 505 ForStatement(ForStatement* other, |
526 Statement* init, | 506 Statement* init, |
527 Expression* cond, | 507 Expression* cond, |
528 Statement* next, | 508 Statement* next, |
529 Statement* body); | 509 Statement* body); |
530 | 510 |
531 virtual ForStatement* AsForStatement() { return this; } | 511 virtual ForStatement* AsForStatement() { return this; } |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
567 bool may_have_function_literal_; | 547 bool may_have_function_literal_; |
568 Variable* loop_variable_; | 548 Variable* loop_variable_; |
569 bool peel_this_loop_; | 549 bool peel_this_loop_; |
570 | 550 |
571 friend class AstOptimizer; | 551 friend class AstOptimizer; |
572 }; | 552 }; |
573 | 553 |
574 | 554 |
575 class ForInStatement: public IterationStatement { | 555 class ForInStatement: public IterationStatement { |
576 public: | 556 public: |
577 explicit ForInStatement(ZoneStringList* labels) | 557 explicit inline ForInStatement(ZoneStringList* labels); |
578 : IterationStatement(labels), each_(NULL), enumerable_(NULL) { } | |
579 | 558 |
580 void Initialize(Expression* each, Expression* enumerable, Statement* body) { | 559 void Initialize(Expression* each, Expression* enumerable, Statement* body) { |
581 IterationStatement::Initialize(body); | 560 IterationStatement::Initialize(body); |
582 each_ = each; | 561 each_ = each; |
583 enumerable_ = enumerable; | 562 enumerable_ = enumerable; |
584 } | 563 } |
585 | 564 |
586 virtual void Accept(AstVisitor* v); | 565 virtual void Accept(AstVisitor* v); |
587 | 566 |
588 Expression* each() const { return each_; } | 567 Expression* each() const { return each_; } |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
684 class WithExitStatement: public Statement { | 663 class WithExitStatement: public Statement { |
685 public: | 664 public: |
686 WithExitStatement() { } | 665 WithExitStatement() { } |
687 | 666 |
688 virtual void Accept(AstVisitor* v); | 667 virtual void Accept(AstVisitor* v); |
689 }; | 668 }; |
690 | 669 |
691 | 670 |
692 class CaseClause: public ZoneObject { | 671 class CaseClause: public ZoneObject { |
693 public: | 672 public: |
694 CaseClause(Expression* label, ZoneList<Statement*>* statements) | 673 CaseClause(Expression* label, ZoneList<Statement*>* statements); |
695 : label_(label), statements_(statements) { } | |
696 | 674 |
697 bool is_default() const { return label_ == NULL; } | 675 bool is_default() const { return label_ == NULL; } |
698 Expression* label() const { | 676 Expression* label() const { |
699 CHECK(!is_default()); | 677 CHECK(!is_default()); |
700 return label_; | 678 return label_; |
701 } | 679 } |
702 JumpTarget* body_target() { return &body_target_; } | 680 JumpTarget* body_target() { return &body_target_; } |
703 ZoneList<Statement*>* statements() const { return statements_; } | 681 ZoneList<Statement*>* statements() const { return statements_; } |
704 | 682 |
705 private: | 683 private: |
706 Expression* label_; | 684 Expression* label_; |
707 JumpTarget body_target_; | 685 JumpTarget body_target_; |
708 ZoneList<Statement*>* statements_; | 686 ZoneList<Statement*>* statements_; |
709 }; | 687 }; |
710 | 688 |
711 | 689 |
712 class SwitchStatement: public BreakableStatement { | 690 class SwitchStatement: public BreakableStatement { |
713 public: | 691 public: |
714 explicit SwitchStatement(ZoneStringList* labels) | 692 explicit inline SwitchStatement(ZoneStringList* labels); |
715 : BreakableStatement(labels, TARGET_FOR_ANONYMOUS), | |
716 tag_(NULL), cases_(NULL) { } | |
717 | 693 |
718 void Initialize(Expression* tag, ZoneList<CaseClause*>* cases) { | 694 void Initialize(Expression* tag, ZoneList<CaseClause*>* cases) { |
719 tag_ = tag; | 695 tag_ = tag; |
720 cases_ = cases; | 696 cases_ = cases; |
721 } | 697 } |
722 | 698 |
723 virtual void Accept(AstVisitor* v); | 699 virtual void Accept(AstVisitor* v); |
724 | 700 |
725 Expression* tag() const { return tag_; } | 701 Expression* tag() const { return tag_; } |
726 ZoneList<CaseClause*>* cases() const { return cases_; } | 702 ZoneList<CaseClause*>* cases() const { return cases_; } |
(...skipping 1385 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2112 | 2088 |
2113 // Holds the result of copying an expression. | 2089 // Holds the result of copying an expression. |
2114 Expression* expr_; | 2090 Expression* expr_; |
2115 // Holds the result of copying a statement. | 2091 // Holds the result of copying a statement. |
2116 Statement* stmt_; | 2092 Statement* stmt_; |
2117 }; | 2093 }; |
2118 | 2094 |
2119 } } // namespace v8::internal | 2095 } } // namespace v8::internal |
2120 | 2096 |
2121 #endif // V8_AST_H_ | 2097 #endif // V8_AST_H_ |
OLD | NEW |