Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(187)

Side by Side Diff: src/preparser.h

Issue 1286383005: Parse arrow functions at proper precedence level (Closed) Base URL: https://chromium.googlesource.com/v8/v8@master
Patch Set: Fix nits Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/pattern-rewriter.cc ('k') | src/prettyprinter.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
1311 // Return the object itself as AstVisitor and implement the needed 1315 // Return the object itself as AstVisitor and implement the needed
1312 // dummy method right in this class. 1316 // dummy method right in this class.
1313 PreParserFactory* visitor() { return this; } 1317 PreParserFactory* visitor() { return this; }
1314 int* ast_properties() { 1318 int* ast_properties() {
1315 static int dummy = 42; 1319 static int dummy = 42;
1316 return &dummy; 1320 return &dummy;
1317 } 1321 }
1318 }; 1322 };
1319 1323
1320 1324
(...skipping 934 matching lines...) Expand 10 before | Expand all | Expand 10 after
2255 // Arrow function formal parameters are either a single identifier or a 2259 // Arrow function formal parameters are either a single identifier or a
2256 // list of BindingPattern productions enclosed in parentheses. 2260 // list of BindingPattern productions enclosed in parentheses.
2257 // Parentheses are not valid on the LHS of a BindingPattern, so we use the 2261 // Parentheses are not valid on the LHS of a BindingPattern, so we use the
2258 // is_valid_binding_pattern() check to detect multiple levels of 2262 // is_valid_binding_pattern() check to detect multiple levels of
2259 // parenthesization. 2263 // parenthesization.
2260 if (!classifier->is_valid_binding_pattern()) { 2264 if (!classifier->is_valid_binding_pattern()) {
2261 ArrowFormalParametersUnexpectedToken(classifier); 2265 ArrowFormalParametersUnexpectedToken(classifier);
2262 } 2266 }
2263 BindingPatternUnexpectedToken(classifier); 2267 BindingPatternUnexpectedToken(classifier);
2264 Consume(Token::LPAREN); 2268 Consume(Token::LPAREN);
2265 if (allow_harmony_arrow_functions() && Check(Token::RPAREN)) { 2269 if (Check(Token::RPAREN)) {
2266 // As a primary expression, the only thing that can follow "()" is "=>". 2270 // ()=>x. The continuation that looks for the => is in
2271 // ParseAssignmentExpression.
2272 classifier->RecordExpressionError(scanner()->location(),
2273 MessageTemplate::kUnexpectedToken,
2274 Token::String(Token::RPAREN));
2267 classifier->RecordBindingPatternError(scanner()->location(), 2275 classifier->RecordBindingPatternError(scanner()->location(),
2268 MessageTemplate::kUnexpectedToken, 2276 MessageTemplate::kUnexpectedToken,
2269 Token::String(Token::RPAREN)); 2277 Token::String(Token::RPAREN));
2270 // Give a good error to the user who might have typed e.g. "return();". 2278 result = factory()->NewEmptyParentheses(beg_pos);
2271 if (peek() != Token::ARROW) { 2279 } else if (allow_harmony_rest_parameters() && Check(Token::ELLIPSIS)) {
2272 ReportUnexpectedTokenAt(scanner_->peek_location(), peek(), 2280 // (...x)=>x. The continuation that looks for the => is in
2273 MessageTemplate::kMissingArrow); 2281 // ParseAssignmentExpression.
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);
2274 *ok = false; 2294 *ok = false;
2275 return this->EmptyExpression(); 2295 return this->EmptyExpression();
2276 } 2296 }
2277 Scope* scope = 2297 result = factory()->NewSpread(result, ellipsis_pos);
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);
2297 if (peek() == Token::COMMA) { 2298 if (peek() == Token::COMMA) {
2298 ReportMessageAt(scanner()->peek_location(), 2299 ReportMessageAt(scanner()->peek_location(),
2299 MessageTemplate::kParamAfterRest); 2300 MessageTemplate::kParamAfterRest);
2300 *ok = false; 2301 *ok = false;
2301 return this->EmptyExpression(); 2302 return this->EmptyExpression();
2302 } 2303 }
2303 Expect(Token::RPAREN, CHECK_OK); 2304 Expect(Token::RPAREN, CHECK_OK);
2304 result = this->ParseArrowFunctionLiteral(formals, formals_classifier,
2305 CHECK_OK);
2306 } else { 2305 } else {
2307 // Heuristically try to detect immediately called functions before 2306 // Heuristically try to detect immediately called functions before
2308 // seeing the call parentheses. 2307 // seeing the call parentheses.
2309 parenthesized_function_ = (peek() == Token::FUNCTION); 2308 parenthesized_function_ = (peek() == Token::FUNCTION);
2310 result = this->ParseExpression(true, classifier, CHECK_OK); 2309 result = this->ParseExpression(true, classifier, CHECK_OK);
2311 Expect(Token::RPAREN, CHECK_OK); 2310 Expect(Token::RPAREN, CHECK_OK);
2312 } 2311 }
2313 break; 2312 break;
2314 2313
2315 case Token::CLASS: { 2314 case Token::CLASS: {
(...skipping 1730 matching lines...) Expand 10 before | Expand all | Expand 10 after
4046 *ok = false; 4045 *ok = false;
4047 return; 4046 return;
4048 } 4047 }
4049 has_seen_constructor_ = true; 4048 has_seen_constructor_ = true;
4050 return; 4049 return;
4051 } 4050 }
4052 } 4051 }
4053 } } // v8::internal 4052 } } // v8::internal
4054 4053
4055 #endif // V8_PREPARSER_H 4054 #endif // V8_PREPARSER_H
OLDNEW
« no previous file with comments | « src/pattern-rewriter.cc ('k') | src/prettyprinter.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698