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/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 1696 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1707 typename ParserBase<Impl>::ExpressionT ParserBase<Impl>::ParseRegExpLiteral( | 1707 typename ParserBase<Impl>::ExpressionT ParserBase<Impl>::ParseRegExpLiteral( |
1708 bool* ok) { | 1708 bool* ok) { |
1709 int pos = peek_position(); | 1709 int pos = peek_position(); |
1710 if (!scanner()->ScanRegExpPattern()) { | 1710 if (!scanner()->ScanRegExpPattern()) { |
1711 Next(); | 1711 Next(); |
1712 ReportMessage(MessageTemplate::kUnterminatedRegExp); | 1712 ReportMessage(MessageTemplate::kUnterminatedRegExp); |
1713 *ok = false; | 1713 *ok = false; |
1714 return impl()->EmptyExpression(); | 1714 return impl()->EmptyExpression(); |
1715 } | 1715 } |
1716 | 1716 |
1717 int literal_index = function_state_->NextMaterializedLiteralIndex(); | 1717 function_state_->NextMaterializedLiteralIndex(); |
1718 | 1718 |
1719 IdentifierT js_pattern = impl()->GetNextSymbol(); | 1719 IdentifierT js_pattern = impl()->GetNextSymbol(); |
1720 Maybe<RegExp::Flags> flags = scanner()->ScanRegExpFlags(); | 1720 Maybe<RegExp::Flags> flags = scanner()->ScanRegExpFlags(); |
1721 if (flags.IsNothing()) { | 1721 if (flags.IsNothing()) { |
1722 Next(); | 1722 Next(); |
1723 ReportMessage(MessageTemplate::kMalformedRegExpFlags); | 1723 ReportMessage(MessageTemplate::kMalformedRegExpFlags); |
1724 *ok = false; | 1724 *ok = false; |
1725 return impl()->EmptyExpression(); | 1725 return impl()->EmptyExpression(); |
1726 } | 1726 } |
1727 int js_flags = flags.FromJust(); | 1727 int js_flags = flags.FromJust(); |
1728 Next(); | 1728 Next(); |
1729 return factory()->NewRegExpLiteral(js_pattern, js_flags, literal_index, pos); | 1729 return factory()->NewRegExpLiteral(js_pattern, js_flags, pos); |
1730 } | 1730 } |
1731 | 1731 |
1732 template <typename Impl> | 1732 template <typename Impl> |
1733 typename ParserBase<Impl>::ExpressionT ParserBase<Impl>::ParsePrimaryExpression( | 1733 typename ParserBase<Impl>::ExpressionT ParserBase<Impl>::ParsePrimaryExpression( |
1734 bool* is_async, bool* ok) { | 1734 bool* is_async, bool* ok) { |
1735 // PrimaryExpression :: | 1735 // PrimaryExpression :: |
1736 // 'this' | 1736 // 'this' |
1737 // 'null' | 1737 // 'null' |
1738 // 'true' | 1738 // 'true' |
1739 // 'false' | 1739 // 'false' |
(...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1997 CheckDestructuringElement(elem, beg_pos, scanner()->location().end_pos); | 1997 CheckDestructuringElement(elem, beg_pos, scanner()->location().end_pos); |
1998 } | 1998 } |
1999 values->Add(elem, zone_); | 1999 values->Add(elem, zone_); |
2000 if (peek() != Token::RBRACK) { | 2000 if (peek() != Token::RBRACK) { |
2001 Expect(Token::COMMA, CHECK_OK); | 2001 Expect(Token::COMMA, CHECK_OK); |
2002 } | 2002 } |
2003 } | 2003 } |
2004 Expect(Token::RBRACK, CHECK_OK); | 2004 Expect(Token::RBRACK, CHECK_OK); |
2005 | 2005 |
2006 // Update the scope information before the pre-parsing bailout. | 2006 // Update the scope information before the pre-parsing bailout. |
2007 int literal_index = function_state_->NextMaterializedLiteralIndex(); | 2007 function_state_->NextMaterializedLiteralIndex(); |
2008 | 2008 |
2009 ExpressionT result = factory()->NewArrayLiteral(values, first_spread_index, | 2009 ExpressionT result = |
2010 literal_index, pos); | 2010 factory()->NewArrayLiteral(values, first_spread_index, pos); |
2011 if (first_spread_index >= 0) { | 2011 if (first_spread_index >= 0) { |
2012 result = factory()->NewRewritableExpression(result); | 2012 result = factory()->NewRewritableExpression(result); |
2013 impl()->QueueNonPatternForRewriting(result, ok); | 2013 impl()->QueueNonPatternForRewriting(result, ok); |
2014 if (!*ok) { | 2014 if (!*ok) { |
2015 // If the non-pattern rewriting mechanism is used in the future for | 2015 // If the non-pattern rewriting mechanism is used in the future for |
2016 // rewriting other things than spreads, this error message will have | 2016 // rewriting other things than spreads, this error message will have |
2017 // to change. Also, this error message will never appear while pre- | 2017 // to change. Also, this error message will never appear while pre- |
2018 // parsing (this is OK, as it is an implementation limitation). | 2018 // parsing (this is OK, as it is an implementation limitation). |
2019 ReportMessage(MessageTemplate::kTooManySpreads); | 2019 ReportMessage(MessageTemplate::kTooManySpreads); |
2020 return impl()->EmptyExpression(); | 2020 return impl()->EmptyExpression(); |
(...skipping 577 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2598 if (peek() != Token::RBRACE) { | 2598 if (peek() != Token::RBRACE) { |
2599 // Need {} because of the CHECK_OK macro. | 2599 // Need {} because of the CHECK_OK macro. |
2600 Expect(Token::COMMA, CHECK_OK); | 2600 Expect(Token::COMMA, CHECK_OK); |
2601 } | 2601 } |
2602 | 2602 |
2603 if (fni_ != nullptr) fni_->Infer(); | 2603 if (fni_ != nullptr) fni_->Infer(); |
2604 } | 2604 } |
2605 Expect(Token::RBRACE, CHECK_OK); | 2605 Expect(Token::RBRACE, CHECK_OK); |
2606 | 2606 |
2607 // Computation of literal_index must happen before pre parse bailout. | 2607 // Computation of literal_index must happen before pre parse bailout. |
2608 int literal_index = function_state_->NextMaterializedLiteralIndex(); | 2608 function_state_->NextMaterializedLiteralIndex(); |
2609 | 2609 |
2610 // In pattern rewriter, we rewrite rest property to call out to a | 2610 // In pattern rewriter, we rewrite rest property to call out to a |
2611 // runtime function passing all the other properties as arguments to | 2611 // runtime function passing all the other properties as arguments to |
2612 // this runtime function. Here, we make sure that the number of | 2612 // this runtime function. Here, we make sure that the number of |
2613 // properties is less than number of arguments allowed for a runtime | 2613 // properties is less than number of arguments allowed for a runtime |
2614 // call. | 2614 // call. |
2615 if (has_rest_property && properties->length() > Code::kMaxArguments) { | 2615 if (has_rest_property && properties->length() > Code::kMaxArguments) { |
2616 this->classifier()->RecordPatternError(Scanner::Location(pos, position()), | 2616 this->classifier()->RecordPatternError(Scanner::Location(pos, position()), |
2617 MessageTemplate::kTooManyArguments); | 2617 MessageTemplate::kTooManyArguments); |
2618 } | 2618 } |
2619 | 2619 |
2620 return factory()->NewObjectLiteral(properties, literal_index, | 2620 return factory()->NewObjectLiteral( |
2621 number_of_boilerplate_properties, pos, | 2621 properties, number_of_boilerplate_properties, pos, has_rest_property); |
2622 has_rest_property); | |
2623 } | 2622 } |
2624 | 2623 |
2625 template <typename Impl> | 2624 template <typename Impl> |
2626 typename ParserBase<Impl>::ExpressionListT ParserBase<Impl>::ParseArguments( | 2625 typename ParserBase<Impl>::ExpressionListT ParserBase<Impl>::ParseArguments( |
2627 Scanner::Location* first_spread_arg_loc, bool maybe_arrow, bool* ok) { | 2626 Scanner::Location* first_spread_arg_loc, bool maybe_arrow, bool* ok) { |
2628 // Arguments :: | 2627 // Arguments :: |
2629 // '(' (AssignmentExpression)*[','] ')' | 2628 // '(' (AssignmentExpression)*[','] ')' |
2630 | 2629 |
2631 Scanner::Location spread_arg = Scanner::Location::invalid(); | 2630 Scanner::Location spread_arg = Scanner::Location::invalid(); |
2632 ExpressionListT result = impl()->NewExpressionList(4); | 2631 ExpressionListT result = impl()->NewExpressionList(4); |
(...skipping 1520 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4153 can_preparse && impl()->AllowsLazyParsingWithoutUnresolvedVariables(); | 4152 can_preparse && impl()->AllowsLazyParsingWithoutUnresolvedVariables(); |
4154 bool should_be_used_once_hint = false; | 4153 bool should_be_used_once_hint = false; |
4155 bool has_braces = true; | 4154 bool has_braces = true; |
4156 { | 4155 { |
4157 FunctionState function_state(&function_state_, &scope_state_, | 4156 FunctionState function_state(&function_state_, &scope_state_, |
4158 formal_parameters.scope); | 4157 formal_parameters.scope); |
4159 | 4158 |
4160 function_state.SkipMaterializedLiterals( | 4159 function_state.SkipMaterializedLiterals( |
4161 formal_parameters.materialized_literals_count); | 4160 formal_parameters.materialized_literals_count); |
4162 | 4161 |
4163 impl()->ReindexLiterals(formal_parameters); | |
4164 | |
4165 Expect(Token::ARROW, CHECK_OK); | 4162 Expect(Token::ARROW, CHECK_OK); |
4166 | 4163 |
4167 if (peek() == Token::LBRACE) { | 4164 if (peek() == Token::LBRACE) { |
4168 // Multiple statement body | 4165 // Multiple statement body |
4169 DCHECK_EQ(scope(), formal_parameters.scope); | 4166 DCHECK_EQ(scope(), formal_parameters.scope); |
4170 if (is_lazy_top_level_function) { | 4167 if (is_lazy_top_level_function) { |
4171 // FIXME(marja): Arrow function parameters will be parsed even if the | 4168 // FIXME(marja): Arrow function parameters will be parsed even if the |
4172 // body is preparsed; move relevant parts of parameter handling to | 4169 // body is preparsed; move relevant parts of parameter handling to |
4173 // simulate consistent parameter handling. | 4170 // simulate consistent parameter handling. |
4174 Scanner::BookmarkScope bookmark(scanner()); | 4171 Scanner::BookmarkScope bookmark(scanner()); |
(...skipping 1551 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5726 return; | 5723 return; |
5727 } | 5724 } |
5728 } | 5725 } |
5729 | 5726 |
5730 #undef CHECK_OK_VOID | 5727 #undef CHECK_OK_VOID |
5731 | 5728 |
5732 } // namespace internal | 5729 } // namespace internal |
5733 } // namespace v8 | 5730 } // namespace v8 |
5734 | 5731 |
5735 #endif // V8_PARSING_PARSER_BASE_H | 5732 #endif // V8_PARSING_PARSER_BASE_H |
OLD | NEW |