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