| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef V8_PREPARSER_H | 5 #ifndef V8_PREPARSER_H |
| 6 #define V8_PREPARSER_H | 6 #define V8_PREPARSER_H |
| 7 | 7 |
| 8 #include "src/v8.h" | 8 #include "src/v8.h" |
| 9 | 9 |
| 10 #include "src/bailout-reason.h" | 10 #include "src/bailout-reason.h" |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 143 // used to hold the parser's per-function and per-block state. | 143 // used to hold the parser's per-function and per-block state. |
| 144 class BlockState BASE_EMBEDDED { | 144 class BlockState BASE_EMBEDDED { |
| 145 public: | 145 public: |
| 146 BlockState(typename Traits::Type::Scope** scope_stack, | 146 BlockState(typename Traits::Type::Scope** scope_stack, |
| 147 typename Traits::Type::Scope* scope) | 147 typename Traits::Type::Scope* scope) |
| 148 : scope_stack_(scope_stack), | 148 : scope_stack_(scope_stack), |
| 149 outer_scope_(*scope_stack), | 149 outer_scope_(*scope_stack), |
| 150 scope_(scope) { | 150 scope_(scope) { |
| 151 *scope_stack_ = scope_; | 151 *scope_stack_ = scope_; |
| 152 } | 152 } |
| 153 BlockState(typename Traits::Type::Scope** scope_stack, | |
| 154 typename Traits::Type::Scope** scope) | |
| 155 : scope_stack_(scope_stack), | |
| 156 outer_scope_(*scope_stack), | |
| 157 scope_(*scope) { | |
| 158 *scope_stack_ = scope_; | |
| 159 } | |
| 160 ~BlockState() { *scope_stack_ = outer_scope_; } | 153 ~BlockState() { *scope_stack_ = outer_scope_; } |
| 161 | 154 |
| 162 private: | 155 private: |
| 163 typename Traits::Type::Scope** scope_stack_; | 156 typename Traits::Type::Scope** scope_stack_; |
| 164 typename Traits::Type::Scope* outer_scope_; | 157 typename Traits::Type::Scope* outer_scope_; |
| 165 typename Traits::Type::Scope* scope_; | 158 typename Traits::Type::Scope* scope_; |
| 166 }; | 159 }; |
| 167 | 160 |
| 168 class FunctionState BASE_EMBEDDED { | 161 class FunctionState BASE_EMBEDDED { |
| 169 public: | 162 public: |
| 170 FunctionState(FunctionState** function_state_stack, | 163 FunctionState(FunctionState** function_state_stack, |
| 171 typename Traits::Type::Scope** scope_stack, | 164 typename Traits::Type::Scope** scope_stack, |
| 172 typename Traits::Type::Scope* scope, | 165 typename Traits::Type::Scope* scope, |
| 173 typename Traits::Type::Factory* factory); | 166 typename Traits::Type::Factory* factory); |
| 174 FunctionState(FunctionState** function_state_stack, | |
| 175 typename Traits::Type::Scope** scope_stack, | |
| 176 typename Traits::Type::Scope** scope, | |
| 177 typename Traits::Type::Factory* factory); | |
| 178 ~FunctionState(); | 167 ~FunctionState(); |
| 179 | 168 |
| 180 int NextMaterializedLiteralIndex() { | 169 int NextMaterializedLiteralIndex() { |
| 181 return next_materialized_literal_index_++; | 170 return next_materialized_literal_index_++; |
| 182 } | 171 } |
| 183 int materialized_literal_count() { | 172 int materialized_literal_count() { |
| 184 return next_materialized_literal_index_ - JSFunction::kLiteralsPrefixSize; | 173 return next_materialized_literal_index_ - JSFunction::kLiteralsPrefixSize; |
| 185 } | 174 } |
| 186 | 175 |
| 187 int NextHandlerIndex() { return next_handler_index_++; } | 176 int NextHandlerIndex() { return next_handler_index_++; } |
| (...skipping 928 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1116 class PreParserTraits { | 1105 class PreParserTraits { |
| 1117 public: | 1106 public: |
| 1118 struct Type { | 1107 struct Type { |
| 1119 // TODO(marja): To be removed. The Traits object should contain all the data | 1108 // TODO(marja): To be removed. The Traits object should contain all the data |
| 1120 // it needs. | 1109 // it needs. |
| 1121 typedef PreParser* Parser; | 1110 typedef PreParser* Parser; |
| 1122 | 1111 |
| 1123 // Used by FunctionState and BlockState. | 1112 // Used by FunctionState and BlockState. |
| 1124 typedef PreParserScope Scope; | 1113 typedef PreParserScope Scope; |
| 1125 typedef PreParserScope ScopePtr; | 1114 typedef PreParserScope ScopePtr; |
| 1115 inline static Scope* ptr_to_scope(ScopePtr& scope) { return &scope; } |
| 1126 | 1116 |
| 1127 // PreParser doesn't need to store generator variables. | 1117 // PreParser doesn't need to store generator variables. |
| 1128 typedef void GeneratorVariable; | 1118 typedef void GeneratorVariable; |
| 1129 // No interaction with Zones. | 1119 // No interaction with Zones. |
| 1130 typedef void Zone; | 1120 typedef void Zone; |
| 1131 | 1121 |
| 1132 typedef int AstProperties; | 1122 typedef int AstProperties; |
| 1133 typedef Vector<PreParserIdentifier> ParameterIdentifierVector; | 1123 typedef Vector<PreParserIdentifier> ParameterIdentifierVector; |
| 1134 | 1124 |
| 1135 // Return types for traversing functions. | 1125 // Return types for traversing functions. |
| (...skipping 435 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1571 outer_function_state_(*function_state_stack), | 1561 outer_function_state_(*function_state_stack), |
| 1572 scope_stack_(scope_stack), | 1562 scope_stack_(scope_stack), |
| 1573 outer_scope_(*scope_stack), | 1563 outer_scope_(*scope_stack), |
| 1574 factory_(factory) { | 1564 factory_(factory) { |
| 1575 *scope_stack_ = scope; | 1565 *scope_stack_ = scope; |
| 1576 *function_state_stack = this; | 1566 *function_state_stack = this; |
| 1577 } | 1567 } |
| 1578 | 1568 |
| 1579 | 1569 |
| 1580 template <class Traits> | 1570 template <class Traits> |
| 1581 ParserBase<Traits>::FunctionState::FunctionState( | |
| 1582 FunctionState** function_state_stack, | |
| 1583 typename Traits::Type::Scope** scope_stack, | |
| 1584 typename Traits::Type::Scope** scope, | |
| 1585 typename Traits::Type::Factory* factory) | |
| 1586 : next_materialized_literal_index_(JSFunction::kLiteralsPrefixSize), | |
| 1587 next_handler_index_(0), | |
| 1588 expected_property_count_(0), | |
| 1589 is_generator_(false), | |
| 1590 generator_object_variable_(NULL), | |
| 1591 function_state_stack_(function_state_stack), | |
| 1592 outer_function_state_(*function_state_stack), | |
| 1593 scope_stack_(scope_stack), | |
| 1594 outer_scope_(*scope_stack), | |
| 1595 factory_(factory) { | |
| 1596 *scope_stack_ = *scope; | |
| 1597 *function_state_stack = this; | |
| 1598 } | |
| 1599 | |
| 1600 | |
| 1601 template <class Traits> | |
| 1602 ParserBase<Traits>::FunctionState::~FunctionState() { | 1571 ParserBase<Traits>::FunctionState::~FunctionState() { |
| 1603 *scope_stack_ = outer_scope_; | 1572 *scope_stack_ = outer_scope_; |
| 1604 *function_state_stack_ = outer_function_state_; | 1573 *function_state_stack_ = outer_function_state_; |
| 1605 } | 1574 } |
| 1606 | 1575 |
| 1607 | 1576 |
| 1608 template<class Traits> | 1577 template<class Traits> |
| 1609 void ParserBase<Traits>::ReportUnexpectedToken(Token::Value token) { | 1578 void ParserBase<Traits>::ReportUnexpectedToken(Token::Value token) { |
| 1610 Scanner::Location source_location = scanner()->location(); | 1579 Scanner::Location source_location = scanner()->location(); |
| 1611 | 1580 |
| (...skipping 1017 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2629 typename Traits::Type::AstProperties ast_properties; | 2598 typename Traits::Type::AstProperties ast_properties; |
| 2630 BailoutReason dont_optimize_reason = kNoReason; | 2599 BailoutReason dont_optimize_reason = kNoReason; |
| 2631 int num_parameters = -1; | 2600 int num_parameters = -1; |
| 2632 int materialized_literal_count = -1; | 2601 int materialized_literal_count = -1; |
| 2633 int expected_property_count = -1; | 2602 int expected_property_count = -1; |
| 2634 int handler_count = 0; | 2603 int handler_count = 0; |
| 2635 | 2604 |
| 2636 { | 2605 { |
| 2637 typename Traits::Type::Factory function_factory( | 2606 typename Traits::Type::Factory function_factory( |
| 2638 zone(), this->ast_value_factory(), ast_node_id_gen_); | 2607 zone(), this->ast_value_factory(), ast_node_id_gen_); |
| 2639 FunctionState function_state(&function_state_, &scope_, &scope, | 2608 FunctionState function_state(&function_state_, &scope_, |
| 2609 Traits::Type::ptr_to_scope(scope), |
| 2640 &function_factory); | 2610 &function_factory); |
| 2641 Scanner::Location dupe_error_loc = Scanner::Location::invalid(); | 2611 Scanner::Location dupe_error_loc = Scanner::Location::invalid(); |
| 2642 num_parameters = Traits::DeclareArrowParametersFromExpression( | 2612 num_parameters = Traits::DeclareArrowParametersFromExpression( |
| 2643 params_ast, scope_, &dupe_error_loc, ok); | 2613 params_ast, scope_, &dupe_error_loc, ok); |
| 2644 if (!*ok) { | 2614 if (!*ok) { |
| 2645 ReportMessageAt( | 2615 ReportMessageAt( |
| 2646 Scanner::Location(start_pos, scanner()->location().beg_pos), | 2616 Scanner::Location(start_pos, scanner()->location().beg_pos), |
| 2647 "malformed_arrow_function_parameter_list"); | 2617 "malformed_arrow_function_parameter_list"); |
| 2648 return this->EmptyExpression(); | 2618 return this->EmptyExpression(); |
| 2649 } | 2619 } |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2744 } | 2714 } |
| 2745 if (this->IsEvalOrArguments(name)) { | 2715 if (this->IsEvalOrArguments(name)) { |
| 2746 ReportMessageAt(class_name_location, "strict_eval_arguments"); | 2716 ReportMessageAt(class_name_location, "strict_eval_arguments"); |
| 2747 *ok = false; | 2717 *ok = false; |
| 2748 return this->EmptyExpression(); | 2718 return this->EmptyExpression(); |
| 2749 } | 2719 } |
| 2750 | 2720 |
| 2751 ExpressionT extends = this->EmptyExpression(); | 2721 ExpressionT extends = this->EmptyExpression(); |
| 2752 if (Check(Token::EXTENDS)) { | 2722 if (Check(Token::EXTENDS)) { |
| 2753 typename Traits::Type::ScopePtr scope = this->NewScope(scope_, BLOCK_SCOPE); | 2723 typename Traits::Type::ScopePtr scope = this->NewScope(scope_, BLOCK_SCOPE); |
| 2754 BlockState block_state(&scope_, &scope); | 2724 BlockState block_state(&scope_, Traits::Type::ptr_to_scope(scope)); |
| 2755 scope_->SetStrictMode(STRICT); | 2725 scope_->SetStrictMode(STRICT); |
| 2756 extends = this->ParseLeftHandSideExpression(CHECK_OK); | 2726 extends = this->ParseLeftHandSideExpression(CHECK_OK); |
| 2757 } | 2727 } |
| 2758 | 2728 |
| 2759 // TODO(arv): Implement scopes and name binding in class body only. | 2729 // TODO(arv): Implement scopes and name binding in class body only. |
| 2760 typename Traits::Type::ScopePtr scope = this->NewScope(scope_, BLOCK_SCOPE); | 2730 typename Traits::Type::ScopePtr scope = this->NewScope(scope_, BLOCK_SCOPE); |
| 2761 BlockState block_state(&scope_, &scope); | 2731 BlockState block_state(&scope_, Traits::Type::ptr_to_scope(scope)); |
| 2762 scope_->SetStrictMode(STRICT); | 2732 scope_->SetStrictMode(STRICT); |
| 2763 scope_->SetScopeName(name); | 2733 scope_->SetScopeName(name); |
| 2764 | 2734 |
| 2765 ObjectLiteralChecker checker(this, STRICT); | 2735 ObjectLiteralChecker checker(this, STRICT); |
| 2766 typename Traits::Type::PropertyList properties = | 2736 typename Traits::Type::PropertyList properties = |
| 2767 this->NewPropertyList(4, zone_); | 2737 this->NewPropertyList(4, zone_); |
| 2768 ExpressionT constructor = this->EmptyExpression(); | 2738 ExpressionT constructor = this->EmptyExpression(); |
| 2769 | 2739 |
| 2770 Expect(Token::LBRACE, CHECK_OK); | 2740 Expect(Token::LBRACE, CHECK_OK); |
| 2771 while (peek() != Token::RBRACE) { | 2741 while (peek() != Token::RBRACE) { |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2849 DCHECK(IsAccessorAccessorConflict(old_type, type)); | 2819 DCHECK(IsAccessorAccessorConflict(old_type, type)); |
| 2850 // Both accessors of the same type. | 2820 // Both accessors of the same type. |
| 2851 parser()->ReportMessage("accessor_get_set"); | 2821 parser()->ReportMessage("accessor_get_set"); |
| 2852 } | 2822 } |
| 2853 *ok = false; | 2823 *ok = false; |
| 2854 } | 2824 } |
| 2855 } | 2825 } |
| 2856 } } // v8::internal | 2826 } } // v8::internal |
| 2857 | 2827 |
| 2858 #endif // V8_PREPARSER_H | 2828 #endif // V8_PREPARSER_H |
| OLD | NEW |