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

Side by Side Diff: src/parsing/parser-base.h

Issue 2638513002: Enable --harmony-trailing-commas (Closed)
Patch Set: Created 3 years, 11 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
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_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/ast.h" 8 #include "src/ast/ast.h"
9 #include "src/ast/scopes.h" 9 #include "src/ast/scopes.h"
10 #include "src/bailout-reason.h" 10 #include "src/bailout-reason.h"
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after
209 classifier_(nullptr), 209 classifier_(nullptr),
210 scanner_(scanner), 210 scanner_(scanner),
211 stack_overflow_(false), 211 stack_overflow_(false),
212 default_eager_compile_hint_(FunctionLiteral::kShouldLazyCompile), 212 default_eager_compile_hint_(FunctionLiteral::kShouldLazyCompile),
213 function_literal_id_(0), 213 function_literal_id_(0),
214 allow_natives_(false), 214 allow_natives_(false),
215 allow_tailcalls_(false), 215 allow_tailcalls_(false),
216 allow_harmony_do_expressions_(false), 216 allow_harmony_do_expressions_(false),
217 allow_harmony_function_sent_(false), 217 allow_harmony_function_sent_(false),
218 allow_harmony_restrictive_generators_(false), 218 allow_harmony_restrictive_generators_(false),
219 allow_harmony_trailing_commas_(false),
220 allow_harmony_class_fields_(false), 219 allow_harmony_class_fields_(false),
221 allow_harmony_object_spread_(false) {} 220 allow_harmony_object_spread_(false) {}
222 221
223 #define ALLOW_ACCESSORS(name) \ 222 #define ALLOW_ACCESSORS(name) \
224 bool allow_##name() const { return allow_##name##_; } \ 223 bool allow_##name() const { return allow_##name##_; } \
225 void set_allow_##name(bool allow) { allow_##name##_ = allow; } 224 void set_allow_##name(bool allow) { allow_##name##_ = allow; }
226 225
227 ALLOW_ACCESSORS(natives); 226 ALLOW_ACCESSORS(natives);
228 ALLOW_ACCESSORS(tailcalls); 227 ALLOW_ACCESSORS(tailcalls);
229 ALLOW_ACCESSORS(harmony_do_expressions); 228 ALLOW_ACCESSORS(harmony_do_expressions);
230 ALLOW_ACCESSORS(harmony_function_sent); 229 ALLOW_ACCESSORS(harmony_function_sent);
231 ALLOW_ACCESSORS(harmony_restrictive_generators); 230 ALLOW_ACCESSORS(harmony_restrictive_generators);
232 ALLOW_ACCESSORS(harmony_trailing_commas);
233 ALLOW_ACCESSORS(harmony_class_fields); 231 ALLOW_ACCESSORS(harmony_class_fields);
234 ALLOW_ACCESSORS(harmony_object_spread); 232 ALLOW_ACCESSORS(harmony_object_spread);
235 233
236 #undef ALLOW_ACCESSORS 234 #undef ALLOW_ACCESSORS
237 235
238 uintptr_t stack_limit() const { return stack_limit_; } 236 uintptr_t stack_limit() const { return stack_limit_; }
239 237
240 void set_stack_limit(uintptr_t stack_limit) { stack_limit_ = stack_limit; } 238 void set_stack_limit(uintptr_t stack_limit) { stack_limit_ = stack_limit; }
241 239
242 void set_default_eager_compile_hint( 240 void set_default_eager_compile_hint(
(...skipping 1204 matching lines...) Expand 10 before | Expand all | Expand 10 after
1447 1445
1448 FunctionLiteral::EagerCompileHint default_eager_compile_hint_; 1446 FunctionLiteral::EagerCompileHint default_eager_compile_hint_;
1449 1447
1450 int function_literal_id_; 1448 int function_literal_id_;
1451 1449
1452 bool allow_natives_; 1450 bool allow_natives_;
1453 bool allow_tailcalls_; 1451 bool allow_tailcalls_;
1454 bool allow_harmony_do_expressions_; 1452 bool allow_harmony_do_expressions_;
1455 bool allow_harmony_function_sent_; 1453 bool allow_harmony_function_sent_;
1456 bool allow_harmony_restrictive_generators_; 1454 bool allow_harmony_restrictive_generators_;
1457 bool allow_harmony_trailing_commas_;
1458 bool allow_harmony_class_fields_; 1455 bool allow_harmony_class_fields_;
1459 bool allow_harmony_object_spread_; 1456 bool allow_harmony_object_spread_;
1460 1457
1461 friend class DiscardableZoneScope; 1458 friend class DiscardableZoneScope;
1462 }; 1459 };
1463 1460
1464 template <typename Impl> 1461 template <typename Impl>
1465 ParserBase<Impl>::FunctionState::FunctionState( 1462 ParserBase<Impl>::FunctionState::FunctionState(
1466 FunctionState** function_state_stack, ScopeState** scope_stack, 1463 FunctionState** function_state_stack, ScopeState** scope_stack,
1467 DeclarationScope* scope) 1464 DeclarationScope* scope)
(...skipping 433 matching lines...) Expand 10 before | Expand all | Expand 10 after
1901 factory()->NewBinaryOperation(Token::COMMA, result, right, comma_pos); 1898 factory()->NewBinaryOperation(Token::COMMA, result, right, comma_pos);
1902 } 1899 }
1903 1900
1904 if (!Check(Token::COMMA)) break; 1901 if (!Check(Token::COMMA)) break;
1905 1902
1906 if (right->IsSpread()) { 1903 if (right->IsSpread()) {
1907 classifier()->RecordArrowFormalParametersError( 1904 classifier()->RecordArrowFormalParametersError(
1908 scanner()->location(), MessageTemplate::kParamAfterRest); 1905 scanner()->location(), MessageTemplate::kParamAfterRest);
1909 } 1906 }
1910 1907
1911 if (allow_harmony_trailing_commas() && peek() == Token::RPAREN && 1908 if (peek() == Token::RPAREN && PeekAhead() == Token::ARROW) {
1912 PeekAhead() == Token::ARROW) {
1913 // a trailing comma is allowed at the end of an arrow parameter list 1909 // a trailing comma is allowed at the end of an arrow parameter list
1914 break; 1910 break;
1915 } 1911 }
1916 1912
1917 // Pass on the 'set_next_function_is_likely_called' flag if we have 1913 // Pass on the 'set_next_function_is_likely_called' flag if we have
1918 // several function literals separated by comma. 1914 // several function literals separated by comma.
1919 if (peek() == Token::FUNCTION && 1915 if (peek() == Token::FUNCTION &&
1920 function_state_->previous_function_was_likely_called()) { 1916 function_state_->previous_function_was_likely_called()) {
1921 function_state_->set_next_function_is_likely_called(); 1917 function_state_->set_next_function_is_likely_called();
1922 } 1918 }
(...skipping 686 matching lines...) Expand 10 before | Expand all | Expand 10 after
2609 } 2605 }
2610 2606
2611 if (result->length() > Code::kMaxArguments) { 2607 if (result->length() > Code::kMaxArguments) {
2612 ReportMessage(MessageTemplate::kTooManyArguments); 2608 ReportMessage(MessageTemplate::kTooManyArguments);
2613 *ok = false; 2609 *ok = false;
2614 return impl()->NullExpressionList(); 2610 return impl()->NullExpressionList();
2615 } 2611 }
2616 done = (peek() != Token::COMMA); 2612 done = (peek() != Token::COMMA);
2617 if (!done) { 2613 if (!done) {
2618 Next(); 2614 Next();
2619 if (allow_harmony_trailing_commas() && peek() == Token::RPAREN) { 2615 if (peek() == Token::RPAREN) {
2620 // allow trailing comma 2616 // allow trailing comma
2621 done = true; 2617 done = true;
2622 } 2618 }
2623 } 2619 }
2624 } 2620 }
2625 Scanner::Location location = scanner_->location(); 2621 Scanner::Location location = scanner_->location();
2626 if (Token::RPAREN != Next()) { 2622 if (Token::RPAREN != Next()) {
2627 impl()->ReportMessageAt(location, MessageTemplate::kUnterminatedArgList); 2623 impl()->ReportMessageAt(location, MessageTemplate::kUnterminatedArgList);
2628 *ok = false; 2624 *ok = false;
2629 return impl()->NullExpressionList(); 2625 return impl()->NullExpressionList();
(...skipping 915 matching lines...) Expand 10 before | Expand all | Expand 10 after
3545 classifier()->RecordNonSimpleParameter(); 3541 classifier()->RecordNonSimpleParameter();
3546 if (peek() == Token::COMMA) { 3542 if (peek() == Token::COMMA) {
3547 impl()->ReportMessageAt(scanner()->peek_location(), 3543 impl()->ReportMessageAt(scanner()->peek_location(),
3548 MessageTemplate::kParamAfterRest); 3544 MessageTemplate::kParamAfterRest);
3549 *ok = false; 3545 *ok = false;
3550 return; 3546 return;
3551 } 3547 }
3552 break; 3548 break;
3553 } 3549 }
3554 if (!Check(Token::COMMA)) break; 3550 if (!Check(Token::COMMA)) break;
3555 if (allow_harmony_trailing_commas() && peek() == Token::RPAREN) { 3551 if (peek() == Token::RPAREN) {
3556 // allow the trailing comma 3552 // allow the trailing comma
3557 break; 3553 break;
3558 } 3554 }
3559 } 3555 }
3560 } 3556 }
3561 3557
3562 impl()->DeclareFormalParameters(parameters->scope, parameters->params); 3558 impl()->DeclareFormalParameters(parameters->scope, parameters->params);
3563 } 3559 }
3564 3560
3565 template <typename Impl> 3561 template <typename Impl>
(...skipping 1963 matching lines...) Expand 10 before | Expand all | Expand 10 after
5529 has_seen_constructor_ = true; 5525 has_seen_constructor_ = true;
5530 return; 5526 return;
5531 } 5527 }
5532 } 5528 }
5533 5529
5534 5530
5535 } // namespace internal 5531 } // namespace internal
5536 } // namespace v8 5532 } // namespace v8
5537 5533
5538 #endif // V8_PARSING_PARSER_BASE_H 5534 #endif // V8_PARSING_PARSER_BASE_H
OLDNEW
« src/flag-definitions.h ('K') | « src/parsing/parser.cc ('k') | test/cctest/test-parsing.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698