OLD | NEW |
1 // Copyright 2006-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2008 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 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
88 V(CallRuntime) \ | 88 V(CallRuntime) \ |
89 V(UnaryOperation) \ | 89 V(UnaryOperation) \ |
90 V(CountOperation) \ | 90 V(CountOperation) \ |
91 V(BinaryOperation) \ | 91 V(BinaryOperation) \ |
92 V(CompareOperation) \ | 92 V(CompareOperation) \ |
93 V(ThisFunction) | 93 V(ThisFunction) |
94 | 94 |
95 | 95 |
96 // Forward declarations | 96 // Forward declarations |
97 class TargetCollector; | 97 class TargetCollector; |
98 class MaterializedLiteral; | |
99 | 98 |
100 #define DEF_FORWARD_DECLARATION(type) class type; | 99 #define DEF_FORWARD_DECLARATION(type) class type; |
101 NODE_LIST(DEF_FORWARD_DECLARATION) | 100 NODE_LIST(DEF_FORWARD_DECLARATION) |
102 #undef DEF_FORWARD_DECLARATION | 101 #undef DEF_FORWARD_DECLARATION |
103 | 102 |
104 | 103 |
105 // Typedef only introduced to avoid unreadable code. | 104 // Typedef only introduced to avoid unreadable code. |
106 // Please do appreciate the required space in "> >". | 105 // Please do appreciate the required space in "> >". |
107 typedef ZoneList<Handle<String> > ZoneStringList; | 106 typedef ZoneList<Handle<String> > ZoneStringList; |
108 | 107 |
(...skipping 14 matching lines...) Expand all Loading... |
123 virtual VariableProxy* AsVariableProxy() { return NULL; } | 122 virtual VariableProxy* AsVariableProxy() { return NULL; } |
124 virtual Property* AsProperty() { return NULL; } | 123 virtual Property* AsProperty() { return NULL; } |
125 virtual Call* AsCall() { return NULL; } | 124 virtual Call* AsCall() { return NULL; } |
126 virtual TargetCollector* AsTargetCollector() { return NULL; } | 125 virtual TargetCollector* AsTargetCollector() { return NULL; } |
127 virtual BreakableStatement* AsBreakableStatement() { return NULL; } | 126 virtual BreakableStatement* AsBreakableStatement() { return NULL; } |
128 virtual IterationStatement* AsIterationStatement() { return NULL; } | 127 virtual IterationStatement* AsIterationStatement() { return NULL; } |
129 virtual UnaryOperation* AsUnaryOperation() { return NULL; } | 128 virtual UnaryOperation* AsUnaryOperation() { return NULL; } |
130 virtual BinaryOperation* AsBinaryOperation() { return NULL; } | 129 virtual BinaryOperation* AsBinaryOperation() { return NULL; } |
131 virtual Assignment* AsAssignment() { return NULL; } | 130 virtual Assignment* AsAssignment() { return NULL; } |
132 virtual FunctionLiteral* AsFunctionLiteral() { return NULL; } | 131 virtual FunctionLiteral* AsFunctionLiteral() { return NULL; } |
133 virtual MaterializedLiteral* AsMaterializedLiteral() { return NULL; } | |
134 virtual ObjectLiteral* AsObjectLiteral() { return NULL; } | |
135 virtual ArrayLiteral* AsArrayLiteral() { return NULL; } | |
136 | 132 |
137 void set_statement_pos(int statement_pos) { statement_pos_ = statement_pos; } | 133 void set_statement_pos(int statement_pos) { statement_pos_ = statement_pos; } |
138 int statement_pos() const { return statement_pos_; } | 134 int statement_pos() const { return statement_pos_; } |
139 | 135 |
140 private: | 136 private: |
141 int statement_pos_; | 137 int statement_pos_; |
142 }; | 138 }; |
143 | 139 |
144 | 140 |
145 class Statement: public Node { | 141 class Statement: public Node { |
(...skipping 477 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
623 Handle<Object> handle() const { return handle_; } | 619 Handle<Object> handle() const { return handle_; } |
624 | 620 |
625 private: | 621 private: |
626 Handle<Object> handle_; | 622 Handle<Object> handle_; |
627 }; | 623 }; |
628 | 624 |
629 | 625 |
630 // Base class for literals that needs space in the corresponding JSFunction. | 626 // Base class for literals that needs space in the corresponding JSFunction. |
631 class MaterializedLiteral: public Expression { | 627 class MaterializedLiteral: public Expression { |
632 public: | 628 public: |
633 explicit MaterializedLiteral(int literal_index, bool is_simple) | 629 explicit MaterializedLiteral(int literal_index) |
634 : literal_index_(literal_index), is_simple_(is_simple) {} | 630 : literal_index_(literal_index) {} |
635 | |
636 virtual MaterializedLiteral* AsMaterializedLiteral() { return this; } | |
637 | |
638 int literal_index() { return literal_index_; } | 631 int literal_index() { return literal_index_; } |
639 | |
640 // A materialized literal is simple if the values consist of only | |
641 // constants and simple object and array literals. | |
642 bool is_simple() const { return is_simple_; } | |
643 | |
644 private: | 632 private: |
645 int literal_index_; | 633 int literal_index_; |
646 bool is_simple_; | |
647 }; | 634 }; |
648 | 635 |
649 | 636 |
650 // An object literal has a boilerplate object that is used | 637 // An object literal has a boilerplate object that is used |
651 // for minimizing the work when constructing it at runtime. | 638 // for minimizing the work when constructing it at runtime. |
652 class ObjectLiteral: public MaterializedLiteral { | 639 class ObjectLiteral: public MaterializedLiteral { |
653 public: | 640 public: |
654 // Property is used for passing information | 641 // Property is used for passing information |
655 // about an object literal's properties from the parser | 642 // about an object literal's properties from the parser |
656 // to the code generator. | 643 // to the code generator. |
657 class Property: public ZoneObject { | 644 class Property: public ZoneObject { |
658 public: | 645 public: |
659 | 646 |
660 enum Kind { | 647 enum Kind { |
661 CONSTANT, // Property with constant value (compile time). | 648 CONSTANT, // Property with constant value (at compile time). |
662 COMPUTED, // Property with computed value (execution time). | 649 COMPUTED, // Property with computed value (at execution time). |
663 MATERIALIZED_LITERAL, // Property value is a materialized literal. | 650 GETTER, SETTER, // Property is an accessor function. |
664 GETTER, SETTER, // Property is an accessor function. | 651 PROTOTYPE // Property is __proto__. |
665 PROTOTYPE // Property is __proto__. | |
666 }; | 652 }; |
667 | 653 |
668 Property(Literal* key, Expression* value); | 654 Property(Literal* key, Expression* value); |
669 Property(bool is_getter, FunctionLiteral* value); | 655 Property(bool is_getter, FunctionLiteral* value); |
670 | 656 |
671 Literal* key() { return key_; } | 657 Literal* key() { return key_; } |
672 Expression* value() { return value_; } | 658 Expression* value() { return value_; } |
673 Kind kind() { return kind_; } | 659 Kind kind() { return kind_; } |
674 | 660 |
675 private: | 661 private: |
676 Literal* key_; | 662 Literal* key_; |
677 Expression* value_; | 663 Expression* value_; |
678 Kind kind_; | 664 Kind kind_; |
679 }; | 665 }; |
680 | 666 |
681 ObjectLiteral(Handle<FixedArray> constant_properties, | 667 ObjectLiteral(Handle<FixedArray> constant_properties, |
682 ZoneList<Property*>* properties, | 668 ZoneList<Property*>* properties, |
683 int literal_index, | 669 int literal_index) |
684 bool is_simple) | 670 : MaterializedLiteral(literal_index), |
685 : MaterializedLiteral(literal_index, is_simple), | |
686 constant_properties_(constant_properties), | 671 constant_properties_(constant_properties), |
687 properties_(properties) {} | 672 properties_(properties) { |
| 673 } |
688 | 674 |
689 virtual ObjectLiteral* AsObjectLiteral() { return this; } | |
690 virtual void Accept(AstVisitor* v); | 675 virtual void Accept(AstVisitor* v); |
691 | 676 |
692 Handle<FixedArray> constant_properties() const { | 677 Handle<FixedArray> constant_properties() const { |
693 return constant_properties_; | 678 return constant_properties_; |
694 } | 679 } |
695 ZoneList<Property*>* properties() const { return properties_; } | 680 ZoneList<Property*>* properties() const { return properties_; } |
696 | 681 |
697 private: | 682 private: |
698 Handle<FixedArray> constant_properties_; | 683 Handle<FixedArray> constant_properties_; |
699 ZoneList<Property*>* properties_; | 684 ZoneList<Property*>* properties_; |
700 }; | 685 }; |
701 | 686 |
702 | 687 |
703 // Node for capturing a regexp literal. | 688 // Node for capturing a regexp literal. |
704 class RegExpLiteral: public MaterializedLiteral { | 689 class RegExpLiteral: public MaterializedLiteral { |
705 public: | 690 public: |
706 RegExpLiteral(Handle<String> pattern, | 691 RegExpLiteral(Handle<String> pattern, |
707 Handle<String> flags, | 692 Handle<String> flags, |
708 int literal_index) | 693 int literal_index) |
709 : MaterializedLiteral(literal_index, false), | 694 : MaterializedLiteral(literal_index), |
710 pattern_(pattern), | 695 pattern_(pattern), |
711 flags_(flags) {} | 696 flags_(flags) {} |
712 | 697 |
713 virtual void Accept(AstVisitor* v); | 698 virtual void Accept(AstVisitor* v); |
714 | 699 |
715 Handle<String> pattern() const { return pattern_; } | 700 Handle<String> pattern() const { return pattern_; } |
716 Handle<String> flags() const { return flags_; } | 701 Handle<String> flags() const { return flags_; } |
717 | 702 |
718 private: | 703 private: |
719 Handle<String> pattern_; | 704 Handle<String> pattern_; |
720 Handle<String> flags_; | 705 Handle<String> flags_; |
721 }; | 706 }; |
722 | 707 |
723 // An array literal has a literals object that is used | 708 // An array literal has a literals object that is used |
724 // for minimizing the work when constructing it at runtime. | 709 // for minimizing the work when constructing it at runtime. |
725 class ArrayLiteral: public MaterializedLiteral { | 710 class ArrayLiteral: public Expression { |
726 public: | 711 public: |
727 ArrayLiteral(Handle<FixedArray> literals, | 712 ArrayLiteral(Handle<FixedArray> literals, |
728 ZoneList<Expression*>* values, | 713 ZoneList<Expression*>* values) |
729 int literal_index, | 714 : literals_(literals), values_(values) { |
730 bool is_simple) | 715 } |
731 : MaterializedLiteral(literal_index, is_simple), | |
732 literals_(literals), | |
733 values_(values) {} | |
734 | 716 |
735 virtual void Accept(AstVisitor* v); | 717 virtual void Accept(AstVisitor* v); |
736 virtual ArrayLiteral* AsArrayLiteral() { return this; } | |
737 | 718 |
738 Handle<FixedArray> literals() const { return literals_; } | 719 Handle<FixedArray> literals() const { return literals_; } |
739 ZoneList<Expression*>* values() const { return values_; } | 720 ZoneList<Expression*>* values() const { return values_; } |
740 | 721 |
741 private: | 722 private: |
742 Handle<FixedArray> literals_; | 723 Handle<FixedArray> literals_; |
743 ZoneList<Expression*>* values_; | 724 ZoneList<Expression*>* values_; |
744 }; | 725 }; |
745 | 726 |
746 | 727 |
(...skipping 930 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1677 #undef DEF_VISIT | 1658 #undef DEF_VISIT |
1678 | 1659 |
1679 private: | 1660 private: |
1680 bool stack_overflow_; | 1661 bool stack_overflow_; |
1681 }; | 1662 }; |
1682 | 1663 |
1683 | 1664 |
1684 } } // namespace v8::internal | 1665 } } // namespace v8::internal |
1685 | 1666 |
1686 #endif // V8_AST_H_ | 1667 #endif // V8_AST_H_ |
OLD | NEW |