| 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/bailout-reason.h" | 8 #include "src/bailout-reason.h" |
| 9 #include "src/expression-classifier.h" | 9 #include "src/expression-classifier.h" |
| 10 #include "src/func-name-inferrer.h" | 10 #include "src/func-name-inferrer.h" |
| (...skipping 1290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1301 FunctionLiteral::IsFunctionFlag is_function, | 1301 FunctionLiteral::IsFunctionFlag is_function, |
| 1302 FunctionLiteral::EagerCompileHint eager_compile_hint, FunctionKind kind, | 1302 FunctionLiteral::EagerCompileHint eager_compile_hint, FunctionKind kind, |
| 1303 int position) { | 1303 int position) { |
| 1304 return PreParserExpression::Default(); | 1304 return PreParserExpression::Default(); |
| 1305 } | 1305 } |
| 1306 | 1306 |
| 1307 PreParserExpression NewSpread(PreParserExpression expression, int pos) { | 1307 PreParserExpression NewSpread(PreParserExpression expression, int pos) { |
| 1308 return PreParserExpression::Spread(expression); | 1308 return PreParserExpression::Spread(expression); |
| 1309 } | 1309 } |
| 1310 | 1310 |
| 1311 PreParserExpression NewEmptyParentheses(int pos) { | |
| 1312 return PreParserExpression::Default(); | |
| 1313 } | |
| 1314 | |
| 1315 // Return the object itself as AstVisitor and implement the needed | 1311 // Return the object itself as AstVisitor and implement the needed |
| 1316 // dummy method right in this class. | 1312 // dummy method right in this class. |
| 1317 PreParserFactory* visitor() { return this; } | 1313 PreParserFactory* visitor() { return this; } |
| 1318 int* ast_properties() { | 1314 int* ast_properties() { |
| 1319 static int dummy = 42; | 1315 static int dummy = 42; |
| 1320 return &dummy; | 1316 return &dummy; |
| 1321 } | 1317 } |
| 1322 }; | 1318 }; |
| 1323 | 1319 |
| 1324 | 1320 |
| (...skipping 934 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2259 // Arrow function formal parameters are either a single identifier or a | 2255 // Arrow function formal parameters are either a single identifier or a |
| 2260 // list of BindingPattern productions enclosed in parentheses. | 2256 // list of BindingPattern productions enclosed in parentheses. |
| 2261 // Parentheses are not valid on the LHS of a BindingPattern, so we use the | 2257 // Parentheses are not valid on the LHS of a BindingPattern, so we use the |
| 2262 // is_valid_binding_pattern() check to detect multiple levels of | 2258 // is_valid_binding_pattern() check to detect multiple levels of |
| 2263 // parenthesization. | 2259 // parenthesization. |
| 2264 if (!classifier->is_valid_binding_pattern()) { | 2260 if (!classifier->is_valid_binding_pattern()) { |
| 2265 ArrowFormalParametersUnexpectedToken(classifier); | 2261 ArrowFormalParametersUnexpectedToken(classifier); |
| 2266 } | 2262 } |
| 2267 BindingPatternUnexpectedToken(classifier); | 2263 BindingPatternUnexpectedToken(classifier); |
| 2268 Consume(Token::LPAREN); | 2264 Consume(Token::LPAREN); |
| 2269 if (Check(Token::RPAREN)) { | 2265 if (allow_harmony_arrow_functions() && Check(Token::RPAREN)) { |
| 2270 // ()=>x. The continuation that looks for the => is in | 2266 // As a primary expression, the only thing that can follow "()" is "=>". |
| 2271 // ParseAssignmentExpression. | |
| 2272 classifier->RecordExpressionError(scanner()->location(), | |
| 2273 MessageTemplate::kUnexpectedToken, | |
| 2274 Token::String(Token::RPAREN)); | |
| 2275 classifier->RecordBindingPatternError(scanner()->location(), | 2267 classifier->RecordBindingPatternError(scanner()->location(), |
| 2276 MessageTemplate::kUnexpectedToken, | 2268 MessageTemplate::kUnexpectedToken, |
| 2277 Token::String(Token::RPAREN)); | 2269 Token::String(Token::RPAREN)); |
| 2278 result = factory()->NewEmptyParentheses(beg_pos); | 2270 // Give a good error to the user who might have typed e.g. "return();". |
| 2279 } else if (allow_harmony_rest_parameters() && Check(Token::ELLIPSIS)) { | 2271 if (peek() != Token::ARROW) { |
| 2280 // (...x)=>x. The continuation that looks for the => is in | 2272 ReportUnexpectedTokenAt(scanner_->peek_location(), peek(), |
| 2281 // ParseAssignmentExpression. | 2273 MessageTemplate::kMissingArrow); |
| 2282 int ellipsis_pos = scanner()->location().beg_pos; | |
| 2283 classifier->RecordExpressionError(scanner()->location(), | |
| 2284 MessageTemplate::kUnexpectedToken, | |
| 2285 Token::String(Token::ELLIPSIS)); | |
| 2286 Scanner::Location expr_loc = scanner()->peek_location(); | |
| 2287 Token::Value tok = peek(); | |
| 2288 result = this->ParseAssignmentExpression(true, classifier, CHECK_OK); | |
| 2289 // Patterns are not allowed as rest parameters. There is no way we can | |
| 2290 // succeed so go ahead and use the convenient ReportUnexpectedToken | |
| 2291 // interface. | |
| 2292 if (!Traits::IsIdentifier(result)) { | |
| 2293 ReportUnexpectedTokenAt(expr_loc, tok); | |
| 2294 *ok = false; | 2274 *ok = false; |
| 2295 return this->EmptyExpression(); | 2275 return this->EmptyExpression(); |
| 2296 } | 2276 } |
| 2297 result = factory()->NewSpread(result, ellipsis_pos); | 2277 Scope* scope = |
| 2278 this->NewScope(scope_, ARROW_SCOPE, FunctionKind::kArrowFunction); |
| 2279 FormalParametersT parameters(scope); |
| 2280 scope->set_start_position(beg_pos); |
| 2281 ExpressionClassifier args_classifier; |
| 2282 result = this->ParseArrowFunctionLiteral(parameters, args_classifier, |
| 2283 CHECK_OK); |
| 2284 } else if (allow_harmony_arrow_functions() && |
| 2285 allow_harmony_rest_parameters() && Check(Token::ELLIPSIS)) { |
| 2286 // (...x) => y |
| 2287 Scope* scope = |
| 2288 this->NewScope(scope_, ARROW_SCOPE, FunctionKind::kArrowFunction); |
| 2289 FormalParametersT formals(scope); |
| 2290 scope->set_start_position(beg_pos); |
| 2291 ExpressionClassifier formals_classifier; |
| 2292 formals.has_rest = true; |
| 2293 this->ParseFormalParameter(&formals, &formals_classifier, CHECK_OK); |
| 2294 Traits::DeclareFormalParameter( |
| 2295 formals.scope, formals.at(0), formals.is_simple, |
| 2296 &formals_classifier); |
| 2298 if (peek() == Token::COMMA) { | 2297 if (peek() == Token::COMMA) { |
| 2299 ReportMessageAt(scanner()->peek_location(), | 2298 ReportMessageAt(scanner()->peek_location(), |
| 2300 MessageTemplate::kParamAfterRest); | 2299 MessageTemplate::kParamAfterRest); |
| 2301 *ok = false; | 2300 *ok = false; |
| 2302 return this->EmptyExpression(); | 2301 return this->EmptyExpression(); |
| 2303 } | 2302 } |
| 2304 Expect(Token::RPAREN, CHECK_OK); | 2303 Expect(Token::RPAREN, CHECK_OK); |
| 2304 result = this->ParseArrowFunctionLiteral(formals, formals_classifier, |
| 2305 CHECK_OK); |
| 2305 } else { | 2306 } else { |
| 2306 // Heuristically try to detect immediately called functions before | 2307 // Heuristically try to detect immediately called functions before |
| 2307 // seeing the call parentheses. | 2308 // seeing the call parentheses. |
| 2308 parenthesized_function_ = (peek() == Token::FUNCTION); | 2309 parenthesized_function_ = (peek() == Token::FUNCTION); |
| 2309 result = this->ParseExpression(true, classifier, CHECK_OK); | 2310 result = this->ParseExpression(true, classifier, CHECK_OK); |
| 2310 Expect(Token::RPAREN, CHECK_OK); | 2311 Expect(Token::RPAREN, CHECK_OK); |
| 2311 } | 2312 } |
| 2312 break; | 2313 break; |
| 2313 | 2314 |
| 2314 case Token::CLASS: { | 2315 case Token::CLASS: { |
| (...skipping 1730 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4045 *ok = false; | 4046 *ok = false; |
| 4046 return; | 4047 return; |
| 4047 } | 4048 } |
| 4048 has_seen_constructor_ = true; | 4049 has_seen_constructor_ = true; |
| 4049 return; | 4050 return; |
| 4050 } | 4051 } |
| 4051 } | 4052 } |
| 4052 } } // v8::internal | 4053 } } // v8::internal |
| 4053 | 4054 |
| 4054 #endif // V8_PREPARSER_H | 4055 #endif // V8_PREPARSER_H |
| OLD | NEW |