| 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 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 210 int materialized_literal_count() { | 210 int materialized_literal_count() { |
| 211 return next_materialized_literal_index_; | 211 return next_materialized_literal_index_; |
| 212 } | 212 } |
| 213 | 213 |
| 214 int NextHandlerIndex() { return next_handler_index_++; } | 214 int NextHandlerIndex() { return next_handler_index_++; } |
| 215 int handler_count() { return next_handler_index_; } | 215 int handler_count() { return next_handler_index_; } |
| 216 | 216 |
| 217 void AddProperty() { expected_property_count_++; } | 217 void AddProperty() { expected_property_count_++; } |
| 218 int expected_property_count() { return expected_property_count_; } | 218 int expected_property_count() { return expected_property_count_; } |
| 219 | 219 |
| 220 Scanner::Location return_location() const { return return_location_; } |
| 220 Scanner::Location super_call_location() const { | 221 Scanner::Location super_call_location() const { |
| 221 return super_call_location_; | 222 return super_call_location_; |
| 222 } | 223 } |
| 224 void set_return_location(Scanner::Location location) { |
| 225 return_location_ = location; |
| 226 } |
| 223 void set_super_call_location(Scanner::Location location) { | 227 void set_super_call_location(Scanner::Location location) { |
| 224 super_call_location_ = location; | 228 super_call_location_ = location; |
| 225 } | 229 } |
| 226 | 230 |
| 227 bool is_generator() const { return IsGeneratorFunction(kind_); } | 231 bool is_generator() const { return IsGeneratorFunction(kind_); } |
| 228 | 232 |
| 229 FunctionKind kind() const { return kind_; } | 233 FunctionKind kind() const { return kind_; } |
| 230 FunctionState* outer() const { return outer_function_state_; } | 234 FunctionState* outer() const { return outer_function_state_; } |
| 231 | 235 |
| 232 void set_generator_object_variable( | 236 void set_generator_object_variable( |
| (...skipping 14 matching lines...) Expand all Loading... |
| 247 // the function. Includes regexp literals, and boilerplate for object and | 251 // the function. Includes regexp literals, and boilerplate for object and |
| 248 // array literals. | 252 // array literals. |
| 249 int next_materialized_literal_index_; | 253 int next_materialized_literal_index_; |
| 250 | 254 |
| 251 // Used to assign a per-function index to try and catch handlers. | 255 // Used to assign a per-function index to try and catch handlers. |
| 252 int next_handler_index_; | 256 int next_handler_index_; |
| 253 | 257 |
| 254 // Properties count estimation. | 258 // Properties count estimation. |
| 255 int expected_property_count_; | 259 int expected_property_count_; |
| 256 | 260 |
| 261 // Location of most recent 'return' statement (invalid if none). |
| 262 Scanner::Location return_location_; |
| 263 |
| 257 // Location of call to the "super" constructor (invalid if none). | 264 // Location of call to the "super" constructor (invalid if none). |
| 258 Scanner::Location super_call_location_; | 265 Scanner::Location super_call_location_; |
| 259 | 266 |
| 260 FunctionKind kind_; | 267 FunctionKind kind_; |
| 261 // For generators, this variable may hold the generator object. It variable | 268 // For generators, this variable may hold the generator object. It variable |
| 262 // is used by yield expressions and return statements. It is not necessary | 269 // is used by yield expressions and return statements. It is not necessary |
| 263 // for generator functions to have this variable set. | 270 // for generator functions to have this variable set. |
| 264 Variable* generator_object_variable_; | 271 Variable* generator_object_variable_; |
| 265 | 272 |
| 266 FunctionState** function_state_stack_; | 273 FunctionState** function_state_stack_; |
| (...skipping 1393 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1660 } | 1667 } |
| 1661 | 1668 |
| 1662 | 1669 |
| 1663 template <class Traits> | 1670 template <class Traits> |
| 1664 ParserBase<Traits>::FunctionState::FunctionState( | 1671 ParserBase<Traits>::FunctionState::FunctionState( |
| 1665 FunctionState** function_state_stack, Scope** scope_stack, Scope* scope, | 1672 FunctionState** function_state_stack, Scope** scope_stack, Scope* scope, |
| 1666 FunctionKind kind, typename Traits::Type::Factory* factory) | 1673 FunctionKind kind, typename Traits::Type::Factory* factory) |
| 1667 : next_materialized_literal_index_(0), | 1674 : next_materialized_literal_index_(0), |
| 1668 next_handler_index_(0), | 1675 next_handler_index_(0), |
| 1669 expected_property_count_(0), | 1676 expected_property_count_(0), |
| 1677 return_location_(Scanner::Location::invalid()), |
| 1670 super_call_location_(Scanner::Location::invalid()), | 1678 super_call_location_(Scanner::Location::invalid()), |
| 1671 kind_(kind), | 1679 kind_(kind), |
| 1672 generator_object_variable_(NULL), | 1680 generator_object_variable_(NULL), |
| 1673 function_state_stack_(function_state_stack), | 1681 function_state_stack_(function_state_stack), |
| 1674 outer_function_state_(*function_state_stack), | 1682 outer_function_state_(*function_state_stack), |
| 1675 scope_stack_(scope_stack), | 1683 scope_stack_(scope_stack), |
| 1676 outer_scope_(*scope_stack), | 1684 outer_scope_(*scope_stack), |
| 1677 factory_(factory) { | 1685 factory_(factory) { |
| 1678 *scope_stack_ = scope; | 1686 *scope_stack_ = scope; |
| 1679 *function_state_stack = this; | 1687 *function_state_stack = this; |
| (...skipping 1109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2789 FunctionKind kind = function_state->kind(); | 2797 FunctionKind kind = function_state->kind(); |
| 2790 if (IsConciseMethod(kind) || IsAccessorFunction(kind) || | 2798 if (IsConciseMethod(kind) || IsAccessorFunction(kind) || |
| 2791 i::IsConstructor(kind)) { | 2799 i::IsConstructor(kind)) { |
| 2792 if (peek() == Token::PERIOD || peek() == Token::LBRACK) { | 2800 if (peek() == Token::PERIOD || peek() == Token::LBRACK) { |
| 2793 scope_->RecordSuperPropertyUsage(); | 2801 scope_->RecordSuperPropertyUsage(); |
| 2794 return this->SuperReference(scope_, factory()); | 2802 return this->SuperReference(scope_, factory()); |
| 2795 } | 2803 } |
| 2796 // new super() is never allowed. | 2804 // new super() is never allowed. |
| 2797 // super() is only allowed in derived constructor | 2805 // super() is only allowed in derived constructor |
| 2798 if (!is_new && peek() == Token::LPAREN && IsSubclassConstructor(kind)) { | 2806 if (!is_new && peek() == Token::LPAREN && IsSubclassConstructor(kind)) { |
| 2799 if (is_strong(language_mode()) && | 2807 if (is_strong(language_mode())) { |
| 2800 function_state->super_call_location().IsValid()) { | 2808 if (function_state->super_call_location().IsValid()) { |
| 2801 ReportMessageAt(scanner()->location(), "strong_super_call_duplicate"); | 2809 ReportMessageAt(scanner()->location(), "strong_super_call_duplicate"); |
| 2802 *ok = false; | 2810 *ok = false; |
| 2803 return this->EmptyExpression(); | 2811 return this->EmptyExpression(); |
| 2812 } else if (function_state->return_location().IsValid()) { |
| 2813 ReportMessageAt(function_state->return_location(), |
| 2814 "strong_constructor_return_misplaced"); |
| 2815 *ok = false; |
| 2816 return this->EmptyExpression(); |
| 2817 } |
| 2804 } | 2818 } |
| 2805 function_state->set_super_call_location(scanner()->location()); | 2819 function_state->set_super_call_location(scanner()->location()); |
| 2806 return this->SuperReference(scope_, factory()); | 2820 return this->SuperReference(scope_, factory()); |
| 2807 } | 2821 } |
| 2808 } | 2822 } |
| 2809 | 2823 |
| 2810 ReportMessageAt(scanner()->location(), "unexpected_super"); | 2824 ReportMessageAt(scanner()->location(), "unexpected_super"); |
| 2811 *ok = false; | 2825 *ok = false; |
| 2812 return this->EmptyExpression(); | 2826 return this->EmptyExpression(); |
| 2813 } | 2827 } |
| (...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3153 *ok = false; | 3167 *ok = false; |
| 3154 return; | 3168 return; |
| 3155 } | 3169 } |
| 3156 has_seen_constructor_ = true; | 3170 has_seen_constructor_ = true; |
| 3157 return; | 3171 return; |
| 3158 } | 3172 } |
| 3159 } | 3173 } |
| 3160 } } // v8::internal | 3174 } } // v8::internal |
| 3161 | 3175 |
| 3162 #endif // V8_PREPARSER_H | 3176 #endif // V8_PREPARSER_H |
| OLD | NEW |