| 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; } |
| 134 virtual ObjectLiteral* AsObjectLiteral() { return NULL; } |
| 135 virtual ArrayLiteral* AsArrayLiteral() { return NULL; } |
| 132 | 136 |
| 133 void set_statement_pos(int statement_pos) { statement_pos_ = statement_pos; } | 137 void set_statement_pos(int statement_pos) { statement_pos_ = statement_pos; } |
| 134 int statement_pos() const { return statement_pos_; } | 138 int statement_pos() const { return statement_pos_; } |
| 135 | 139 |
| 136 private: | 140 private: |
| 137 int statement_pos_; | 141 int statement_pos_; |
| 138 }; | 142 }; |
| 139 | 143 |
| 140 | 144 |
| 141 class Statement: public Node { | 145 class Statement: public Node { |
| (...skipping 487 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 629 Handle<Object> handle() const { return handle_; } | 633 Handle<Object> handle() const { return handle_; } |
| 630 | 634 |
| 631 private: | 635 private: |
| 632 Handle<Object> handle_; | 636 Handle<Object> handle_; |
| 633 }; | 637 }; |
| 634 | 638 |
| 635 | 639 |
| 636 // Base class for literals that needs space in the corresponding JSFunction. | 640 // Base class for literals that needs space in the corresponding JSFunction. |
| 637 class MaterializedLiteral: public Expression { | 641 class MaterializedLiteral: public Expression { |
| 638 public: | 642 public: |
| 639 explicit MaterializedLiteral(int literal_index) | 643 explicit MaterializedLiteral(int literal_index, bool is_simple, int depth) |
| 640 : literal_index_(literal_index) {} | 644 : literal_index_(literal_index), is_simple_(is_simple), depth_(depth) {} |
| 645 |
| 646 virtual MaterializedLiteral* AsMaterializedLiteral() { return this; } |
| 647 |
| 641 int literal_index() { return literal_index_; } | 648 int literal_index() { return literal_index_; } |
| 649 |
| 650 // A materialized literal is simple if the values consist of only |
| 651 // constants and simple object and array literals. |
| 652 bool is_simple() const { return is_simple_; } |
| 653 |
| 654 int depth() const { return depth_; } |
| 655 |
| 642 private: | 656 private: |
| 643 int literal_index_; | 657 int literal_index_; |
| 658 bool is_simple_; |
| 659 int depth_; |
| 644 }; | 660 }; |
| 645 | 661 |
| 646 | 662 |
| 647 // An object literal has a boilerplate object that is used | 663 // An object literal has a boilerplate object that is used |
| 648 // for minimizing the work when constructing it at runtime. | 664 // for minimizing the work when constructing it at runtime. |
| 649 class ObjectLiteral: public MaterializedLiteral { | 665 class ObjectLiteral: public MaterializedLiteral { |
| 650 public: | 666 public: |
| 651 // Property is used for passing information | 667 // Property is used for passing information |
| 652 // about an object literal's properties from the parser | 668 // about an object literal's properties from the parser |
| 653 // to the code generator. | 669 // to the code generator. |
| 654 class Property: public ZoneObject { | 670 class Property: public ZoneObject { |
| 655 public: | 671 public: |
| 656 | 672 |
| 657 enum Kind { | 673 enum Kind { |
| 658 CONSTANT, // Property with constant value (at compile time). | 674 CONSTANT, // Property with constant value (compile time). |
| 659 COMPUTED, // Property with computed value (at execution time). | 675 COMPUTED, // Property with computed value (execution time). |
| 660 GETTER, SETTER, // Property is an accessor function. | 676 MATERIALIZED_LITERAL, // Property value is a materialized literal. |
| 661 PROTOTYPE // Property is __proto__. | 677 GETTER, SETTER, // Property is an accessor function. |
| 678 PROTOTYPE // Property is __proto__. |
| 662 }; | 679 }; |
| 663 | 680 |
| 664 Property(Literal* key, Expression* value); | 681 Property(Literal* key, Expression* value); |
| 665 Property(bool is_getter, FunctionLiteral* value); | 682 Property(bool is_getter, FunctionLiteral* value); |
| 666 | 683 |
| 667 Literal* key() { return key_; } | 684 Literal* key() { return key_; } |
| 668 Expression* value() { return value_; } | 685 Expression* value() { return value_; } |
| 669 Kind kind() { return kind_; } | 686 Kind kind() { return kind_; } |
| 670 | 687 |
| 671 private: | 688 private: |
| 672 Literal* key_; | 689 Literal* key_; |
| 673 Expression* value_; | 690 Expression* value_; |
| 674 Kind kind_; | 691 Kind kind_; |
| 675 }; | 692 }; |
| 676 | 693 |
| 677 ObjectLiteral(Handle<FixedArray> constant_properties, | 694 ObjectLiteral(Handle<FixedArray> constant_properties, |
| 678 ZoneList<Property*>* properties, | 695 ZoneList<Property*>* properties, |
| 679 int literal_index) | 696 int literal_index, |
| 680 : MaterializedLiteral(literal_index), | 697 bool is_simple, |
| 698 int depth) |
| 699 : MaterializedLiteral(literal_index, is_simple, depth), |
| 681 constant_properties_(constant_properties), | 700 constant_properties_(constant_properties), |
| 682 properties_(properties) { | 701 properties_(properties) {} |
| 683 } | |
| 684 | 702 |
| 703 virtual ObjectLiteral* AsObjectLiteral() { return this; } |
| 685 virtual void Accept(AstVisitor* v); | 704 virtual void Accept(AstVisitor* v); |
| 686 | 705 |
| 687 Handle<FixedArray> constant_properties() const { | 706 Handle<FixedArray> constant_properties() const { |
| 688 return constant_properties_; | 707 return constant_properties_; |
| 689 } | 708 } |
| 690 ZoneList<Property*>* properties() const { return properties_; } | 709 ZoneList<Property*>* properties() const { return properties_; } |
| 691 | 710 |
| 692 private: | 711 private: |
| 693 Handle<FixedArray> constant_properties_; | 712 Handle<FixedArray> constant_properties_; |
| 694 ZoneList<Property*>* properties_; | 713 ZoneList<Property*>* properties_; |
| 695 }; | 714 }; |
| 696 | 715 |
| 697 | 716 |
| 698 // Node for capturing a regexp literal. | 717 // Node for capturing a regexp literal. |
| 699 class RegExpLiteral: public MaterializedLiteral { | 718 class RegExpLiteral: public MaterializedLiteral { |
| 700 public: | 719 public: |
| 701 RegExpLiteral(Handle<String> pattern, | 720 RegExpLiteral(Handle<String> pattern, |
| 702 Handle<String> flags, | 721 Handle<String> flags, |
| 703 int literal_index) | 722 int literal_index) |
| 704 : MaterializedLiteral(literal_index), | 723 : MaterializedLiteral(literal_index, false, 1), |
| 705 pattern_(pattern), | 724 pattern_(pattern), |
| 706 flags_(flags) {} | 725 flags_(flags) {} |
| 707 | 726 |
| 708 virtual void Accept(AstVisitor* v); | 727 virtual void Accept(AstVisitor* v); |
| 709 | 728 |
| 710 Handle<String> pattern() const { return pattern_; } | 729 Handle<String> pattern() const { return pattern_; } |
| 711 Handle<String> flags() const { return flags_; } | 730 Handle<String> flags() const { return flags_; } |
| 712 | 731 |
| 713 private: | 732 private: |
| 714 Handle<String> pattern_; | 733 Handle<String> pattern_; |
| 715 Handle<String> flags_; | 734 Handle<String> flags_; |
| 716 }; | 735 }; |
| 717 | 736 |
| 718 // An array literal has a literals object that is used | 737 // An array literal has a literals object that is used |
| 719 // for minimizing the work when constructing it at runtime. | 738 // for minimizing the work when constructing it at runtime. |
| 720 class ArrayLiteral: public Expression { | 739 class ArrayLiteral: public MaterializedLiteral { |
| 721 public: | 740 public: |
| 722 ArrayLiteral(Handle<FixedArray> literals, | 741 ArrayLiteral(Handle<FixedArray> literals, |
| 723 ZoneList<Expression*>* values) | 742 ZoneList<Expression*>* values, |
| 724 : literals_(literals), values_(values) { | 743 int literal_index, |
| 725 } | 744 bool is_simple, |
| 745 int depth) |
| 746 : MaterializedLiteral(literal_index, is_simple, depth), |
| 747 literals_(literals), |
| 748 values_(values) {} |
| 726 | 749 |
| 727 virtual void Accept(AstVisitor* v); | 750 virtual void Accept(AstVisitor* v); |
| 751 virtual ArrayLiteral* AsArrayLiteral() { return this; } |
| 728 | 752 |
| 729 Handle<FixedArray> literals() const { return literals_; } | 753 Handle<FixedArray> literals() const { return literals_; } |
| 730 ZoneList<Expression*>* values() const { return values_; } | 754 ZoneList<Expression*>* values() const { return values_; } |
| 731 | 755 |
| 732 private: | 756 private: |
| 733 Handle<FixedArray> literals_; | 757 Handle<FixedArray> literals_; |
| 734 ZoneList<Expression*>* values_; | 758 ZoneList<Expression*>* values_; |
| 735 }; | 759 }; |
| 736 | 760 |
| 737 | 761 |
| (...skipping 930 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1668 #undef DEF_VISIT | 1692 #undef DEF_VISIT |
| 1669 | 1693 |
| 1670 private: | 1694 private: |
| 1671 bool stack_overflow_; | 1695 bool stack_overflow_; |
| 1672 }; | 1696 }; |
| 1673 | 1697 |
| 1674 | 1698 |
| 1675 } } // namespace v8::internal | 1699 } } // namespace v8::internal |
| 1676 | 1700 |
| 1677 #endif // V8_AST_H_ | 1701 #endif // V8_AST_H_ |
| OLD | NEW |