| 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_PARSING_PARSER_BASE_H | 5 #ifndef V8_PARSING_PARSER_BASE_H |
| 6 #define V8_PARSING_PARSER_BASE_H | 6 #define V8_PARSING_PARSER_BASE_H |
| 7 | 7 |
| 8 #include "src/ast/scopes.h" | 8 #include "src/ast/scopes.h" |
| 9 #include "src/bailout-reason.h" | 9 #include "src/bailout-reason.h" |
| 10 #include "src/base/hashmap.h" | 10 #include "src/base/hashmap.h" |
| (...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 191 scanner_(scanner), | 191 scanner_(scanner), |
| 192 stack_overflow_(false), | 192 stack_overflow_(false), |
| 193 allow_lazy_(false), | 193 allow_lazy_(false), |
| 194 allow_natives_(false), | 194 allow_natives_(false), |
| 195 allow_tailcalls_(false), | 195 allow_tailcalls_(false), |
| 196 allow_harmony_restrictive_declarations_(false), | 196 allow_harmony_restrictive_declarations_(false), |
| 197 allow_harmony_do_expressions_(false), | 197 allow_harmony_do_expressions_(false), |
| 198 allow_harmony_for_in_(false), | 198 allow_harmony_for_in_(false), |
| 199 allow_harmony_function_sent_(false), | 199 allow_harmony_function_sent_(false), |
| 200 allow_harmony_async_await_(false), | 200 allow_harmony_async_await_(false), |
| 201 allow_harmony_restrictive_generators_(false) {} | 201 allow_harmony_restrictive_generators_(false), |
| 202 allow_harmony_trailing_commas_(false) {} |
| 202 | 203 |
| 203 #define ALLOW_ACCESSORS(name) \ | 204 #define ALLOW_ACCESSORS(name) \ |
| 204 bool allow_##name() const { return allow_##name##_; } \ | 205 bool allow_##name() const { return allow_##name##_; } \ |
| 205 void set_allow_##name(bool allow) { allow_##name##_ = allow; } | 206 void set_allow_##name(bool allow) { allow_##name##_ = allow; } |
| 206 | 207 |
| 207 #define SCANNER_ACCESSORS(name) \ | 208 #define SCANNER_ACCESSORS(name) \ |
| 208 bool allow_##name() const { return scanner_->allow_##name(); } \ | 209 bool allow_##name() const { return scanner_->allow_##name(); } \ |
| 209 void set_allow_##name(bool allow) { \ | 210 void set_allow_##name(bool allow) { \ |
| 210 return scanner_->set_allow_##name(allow); \ | 211 return scanner_->set_allow_##name(allow); \ |
| 211 } | 212 } |
| 212 | 213 |
| 213 ALLOW_ACCESSORS(lazy); | 214 ALLOW_ACCESSORS(lazy); |
| 214 ALLOW_ACCESSORS(natives); | 215 ALLOW_ACCESSORS(natives); |
| 215 ALLOW_ACCESSORS(tailcalls); | 216 ALLOW_ACCESSORS(tailcalls); |
| 216 ALLOW_ACCESSORS(harmony_restrictive_declarations); | 217 ALLOW_ACCESSORS(harmony_restrictive_declarations); |
| 217 ALLOW_ACCESSORS(harmony_do_expressions); | 218 ALLOW_ACCESSORS(harmony_do_expressions); |
| 218 ALLOW_ACCESSORS(harmony_for_in); | 219 ALLOW_ACCESSORS(harmony_for_in); |
| 219 ALLOW_ACCESSORS(harmony_function_sent); | 220 ALLOW_ACCESSORS(harmony_function_sent); |
| 220 ALLOW_ACCESSORS(harmony_async_await); | 221 ALLOW_ACCESSORS(harmony_async_await); |
| 221 ALLOW_ACCESSORS(harmony_restrictive_generators); | 222 ALLOW_ACCESSORS(harmony_restrictive_generators); |
| 223 ALLOW_ACCESSORS(harmony_trailing_commas); |
| 222 SCANNER_ACCESSORS(harmony_exponentiation_operator); | 224 SCANNER_ACCESSORS(harmony_exponentiation_operator); |
| 223 | 225 |
| 224 #undef SCANNER_ACCESSORS | 226 #undef SCANNER_ACCESSORS |
| 225 #undef ALLOW_ACCESSORS | 227 #undef ALLOW_ACCESSORS |
| 226 | 228 |
| 227 uintptr_t stack_limit() const { return stack_limit_; } | 229 uintptr_t stack_limit() const { return stack_limit_; } |
| 228 | 230 |
| 229 protected: | 231 protected: |
| 230 enum AllowRestrictedIdentifiers { | 232 enum AllowRestrictedIdentifiers { |
| 231 kAllowRestrictedIdentifiers, | 233 kAllowRestrictedIdentifiers, |
| (...skipping 950 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1182 | 1184 |
| 1183 bool allow_lazy_; | 1185 bool allow_lazy_; |
| 1184 bool allow_natives_; | 1186 bool allow_natives_; |
| 1185 bool allow_tailcalls_; | 1187 bool allow_tailcalls_; |
| 1186 bool allow_harmony_restrictive_declarations_; | 1188 bool allow_harmony_restrictive_declarations_; |
| 1187 bool allow_harmony_do_expressions_; | 1189 bool allow_harmony_do_expressions_; |
| 1188 bool allow_harmony_for_in_; | 1190 bool allow_harmony_for_in_; |
| 1189 bool allow_harmony_function_sent_; | 1191 bool allow_harmony_function_sent_; |
| 1190 bool allow_harmony_async_await_; | 1192 bool allow_harmony_async_await_; |
| 1191 bool allow_harmony_restrictive_generators_; | 1193 bool allow_harmony_restrictive_generators_; |
| 1194 bool allow_harmony_trailing_commas_; |
| 1192 }; | 1195 }; |
| 1193 | 1196 |
| 1194 template <class Traits> | 1197 template <class Traits> |
| 1195 ParserBase<Traits>::FunctionState::FunctionState( | 1198 ParserBase<Traits>::FunctionState::FunctionState( |
| 1196 FunctionState** function_state_stack, Scope** scope_stack, Scope* scope, | 1199 FunctionState** function_state_stack, Scope** scope_stack, Scope* scope, |
| 1197 FunctionKind kind, typename Traits::Type::Factory* factory) | 1200 FunctionKind kind, typename Traits::Type::Factory* factory) |
| 1198 : next_materialized_literal_index_(0), | 1201 : next_materialized_literal_index_(0), |
| 1199 expected_property_count_(0), | 1202 expected_property_count_(0), |
| 1200 this_location_(Scanner::Location::invalid()), | 1203 this_location_(Scanner::Location::invalid()), |
| 1201 return_location_(Scanner::Location::invalid()), | 1204 return_location_(Scanner::Location::invalid()), |
| (...skipping 491 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1693 while (peek() == Token::COMMA) { | 1696 while (peek() == Token::COMMA) { |
| 1694 CheckNoTailCallExpressions(classifier, CHECK_OK); | 1697 CheckNoTailCallExpressions(classifier, CHECK_OK); |
| 1695 if (seen_rest) { | 1698 if (seen_rest) { |
| 1696 // At this point the production can't possibly be valid, but we don't know | 1699 // At this point the production can't possibly be valid, but we don't know |
| 1697 // which error to signal. | 1700 // which error to signal. |
| 1698 classifier->RecordArrowFormalParametersError( | 1701 classifier->RecordArrowFormalParametersError( |
| 1699 scanner()->peek_location(), MessageTemplate::kParamAfterRest); | 1702 scanner()->peek_location(), MessageTemplate::kParamAfterRest); |
| 1700 } | 1703 } |
| 1701 Consume(Token::COMMA); | 1704 Consume(Token::COMMA); |
| 1702 bool is_rest = false; | 1705 bool is_rest = false; |
| 1703 if (peek() == Token::ELLIPSIS) { | 1706 if (allow_harmony_trailing_commas() && peek() == Token::RPAREN && |
| 1707 PeekAhead() == Token::ARROW) { |
| 1708 // a trailing comma is allowed at the end of an arrow parameter list |
| 1709 break; |
| 1710 } else if (peek() == Token::ELLIPSIS) { |
| 1704 // 'x, y, ...z' in CoverParenthesizedExpressionAndArrowParameterList only | 1711 // 'x, y, ...z' in CoverParenthesizedExpressionAndArrowParameterList only |
| 1705 // as the formal parameters of'(x, y, ...z) => foo', and is not itself a | 1712 // as the formal parameters of'(x, y, ...z) => foo', and is not itself a |
| 1706 // valid expression or binding pattern. | 1713 // valid expression or binding pattern. |
| 1707 ExpressionUnexpectedToken(classifier); | 1714 ExpressionUnexpectedToken(classifier); |
| 1708 BindingPatternUnexpectedToken(classifier); | 1715 BindingPatternUnexpectedToken(classifier); |
| 1709 Consume(Token::ELLIPSIS); | 1716 Consume(Token::ELLIPSIS); |
| 1710 seen_rest = is_rest = true; | 1717 seen_rest = is_rest = true; |
| 1711 } | 1718 } |
| 1712 int pos = position(), expr_pos = peek_position(); | 1719 int pos = position(), expr_pos = peek_position(); |
| 1713 ExpressionClassifier binding_classifier(this); | 1720 ExpressionClassifier binding_classifier(this); |
| (...skipping 475 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2189 } | 2196 } |
| 2190 | 2197 |
| 2191 if (result->length() > Code::kMaxArguments) { | 2198 if (result->length() > Code::kMaxArguments) { |
| 2192 ReportMessage(MessageTemplate::kTooManyArguments); | 2199 ReportMessage(MessageTemplate::kTooManyArguments); |
| 2193 *ok = false; | 2200 *ok = false; |
| 2194 return this->NullExpressionList(); | 2201 return this->NullExpressionList(); |
| 2195 } | 2202 } |
| 2196 done = (peek() != Token::COMMA); | 2203 done = (peek() != Token::COMMA); |
| 2197 if (!done) { | 2204 if (!done) { |
| 2198 Next(); | 2205 Next(); |
| 2206 if (allow_harmony_trailing_commas() && peek() == Token::RPAREN) { |
| 2207 // allow trailing comma |
| 2208 done = true; |
| 2209 } |
| 2199 } | 2210 } |
| 2200 } | 2211 } |
| 2201 Scanner::Location location = scanner_->location(); | 2212 Scanner::Location location = scanner_->location(); |
| 2202 if (Token::RPAREN != Next()) { | 2213 if (Token::RPAREN != Next()) { |
| 2203 ReportMessageAt(location, MessageTemplate::kUnterminatedArgList); | 2214 ReportMessageAt(location, MessageTemplate::kUnterminatedArgList); |
| 2204 *ok = false; | 2215 *ok = false; |
| 2205 return this->NullExpressionList(); | 2216 return this->NullExpressionList(); |
| 2206 } | 2217 } |
| 2207 *first_spread_arg_loc = spread_arg; | 2218 *first_spread_arg_loc = spread_arg; |
| 2208 | 2219 |
| (...skipping 988 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3197 } | 3208 } |
| 3198 | 3209 |
| 3199 Traits::AddFormalParameter(parameters, pattern, initializer, | 3210 Traits::AddFormalParameter(parameters, pattern, initializer, |
| 3200 scanner()->location().end_pos, is_rest); | 3211 scanner()->location().end_pos, is_rest); |
| 3201 } | 3212 } |
| 3202 | 3213 |
| 3203 | 3214 |
| 3204 template <class Traits> | 3215 template <class Traits> |
| 3205 void ParserBase<Traits>::ParseFormalParameterList( | 3216 void ParserBase<Traits>::ParseFormalParameterList( |
| 3206 FormalParametersT* parameters, ExpressionClassifier* classifier, bool* ok) { | 3217 FormalParametersT* parameters, ExpressionClassifier* classifier, bool* ok) { |
| 3207 // FormalParameters[Yield,GeneratorParameter] : | 3218 // FormalParameters[Yield] : |
| 3208 // [empty] | 3219 // [empty] |
| 3209 // FormalParameterList[?Yield, ?GeneratorParameter] | 3220 // FunctionRestParameter[?Yield] |
| 3221 // FormalParameterList[?Yield] |
| 3222 // FormalParameterList[?Yield] , |
| 3223 // FormalParameterList[?Yield] , FunctionRestParameter[?Yield] |
| 3210 // | 3224 // |
| 3211 // FormalParameterList[Yield,GeneratorParameter] : | 3225 // FormalParameterList[Yield] : |
| 3212 // FunctionRestParameter[?Yield] | 3226 // FormalParameter[?Yield] |
| 3213 // FormalsList[?Yield, ?GeneratorParameter] | 3227 // FormalParameterList[?Yield] , FormalParameter[?Yield] |
| 3214 // FormalsList[?Yield, ?GeneratorParameter] , FunctionRestParameter[?Yield] | |
| 3215 // | |
| 3216 // FormalsList[Yield,GeneratorParameter] : | |
| 3217 // FormalParameter[?Yield, ?GeneratorParameter] | |
| 3218 // FormalsList[?Yield, ?GeneratorParameter] , | |
| 3219 // FormalParameter[?Yield,?GeneratorParameter] | |
| 3220 | 3228 |
| 3221 DCHECK_EQ(0, parameters->Arity()); | 3229 DCHECK_EQ(0, parameters->Arity()); |
| 3222 | 3230 |
| 3223 if (peek() != Token::RPAREN) { | 3231 if (peek() != Token::RPAREN) { |
| 3224 do { | 3232 while (true) { |
| 3225 if (parameters->Arity() > Code::kMaxArguments) { | 3233 if (parameters->Arity() > Code::kMaxArguments) { |
| 3226 ReportMessage(MessageTemplate::kTooManyParameters); | 3234 ReportMessage(MessageTemplate::kTooManyParameters); |
| 3227 *ok = false; | 3235 *ok = false; |
| 3228 return; | 3236 return; |
| 3229 } | 3237 } |
| 3230 parameters->has_rest = Check(Token::ELLIPSIS); | 3238 parameters->has_rest = Check(Token::ELLIPSIS); |
| 3231 ParseFormalParameter(parameters, classifier, ok); | 3239 ParseFormalParameter(parameters, classifier, ok); |
| 3232 if (!*ok) return; | 3240 if (!*ok) return; |
| 3233 } while (!parameters->has_rest && Check(Token::COMMA)); | |
| 3234 | 3241 |
| 3235 if (parameters->has_rest) { | 3242 if (parameters->has_rest) { |
| 3236 parameters->is_simple = false; | 3243 parameters->is_simple = false; |
| 3237 classifier->RecordNonSimpleParameter(); | 3244 classifier->RecordNonSimpleParameter(); |
| 3238 if (peek() == Token::COMMA) { | 3245 if (peek() == Token::COMMA) { |
| 3239 ReportMessageAt(scanner()->peek_location(), | 3246 ReportMessageAt(scanner()->peek_location(), |
| 3240 MessageTemplate::kParamAfterRest); | 3247 MessageTemplate::kParamAfterRest); |
| 3241 *ok = false; | 3248 *ok = false; |
| 3242 return; | 3249 return; |
| 3250 } |
| 3251 break; |
| 3252 } |
| 3253 if (!Check(Token::COMMA)) break; |
| 3254 if (allow_harmony_trailing_commas() && peek() == Token::RPAREN) { |
| 3255 // allow the trailing comma |
| 3256 break; |
| 3243 } | 3257 } |
| 3244 } | 3258 } |
| 3245 } | 3259 } |
| 3246 | 3260 |
| 3247 for (int i = 0; i < parameters->Arity(); ++i) { | 3261 for (int i = 0; i < parameters->Arity(); ++i) { |
| 3248 auto parameter = parameters->at(i); | 3262 auto parameter = parameters->at(i); |
| 3249 Traits::DeclareFormalParameter(parameters->scope, parameter, classifier); | 3263 Traits::DeclareFormalParameter(parameters->scope, parameter, classifier); |
| 3250 } | 3264 } |
| 3251 } | 3265 } |
| 3252 | 3266 |
| (...skipping 383 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3636 has_seen_constructor_ = true; | 3650 has_seen_constructor_ = true; |
| 3637 return; | 3651 return; |
| 3638 } | 3652 } |
| 3639 } | 3653 } |
| 3640 | 3654 |
| 3641 | 3655 |
| 3642 } // namespace internal | 3656 } // namespace internal |
| 3643 } // namespace v8 | 3657 } // namespace v8 |
| 3644 | 3658 |
| 3645 #endif // V8_PARSING_PARSER_BASE_H | 3659 #endif // V8_PARSING_PARSER_BASE_H |
| OLD | NEW |