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 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
208 zone_(zone), | 208 zone_(zone), |
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_async_await_(false), | |
219 allow_harmony_restrictive_generators_(false), | 218 allow_harmony_restrictive_generators_(false), |
220 allow_harmony_trailing_commas_(false), | 219 allow_harmony_trailing_commas_(false), |
221 allow_harmony_class_fields_(false), | 220 allow_harmony_class_fields_(false), |
222 allow_harmony_object_spread_(false) {} | 221 allow_harmony_object_spread_(false) {} |
223 | 222 |
224 #define ALLOW_ACCESSORS(name) \ | 223 #define ALLOW_ACCESSORS(name) \ |
225 bool allow_##name() const { return allow_##name##_; } \ | 224 bool allow_##name() const { return allow_##name##_; } \ |
226 void set_allow_##name(bool allow) { allow_##name##_ = allow; } | 225 void set_allow_##name(bool allow) { allow_##name##_ = allow; } |
227 | 226 |
228 ALLOW_ACCESSORS(natives); | 227 ALLOW_ACCESSORS(natives); |
229 ALLOW_ACCESSORS(tailcalls); | 228 ALLOW_ACCESSORS(tailcalls); |
230 ALLOW_ACCESSORS(harmony_do_expressions); | 229 ALLOW_ACCESSORS(harmony_do_expressions); |
231 ALLOW_ACCESSORS(harmony_function_sent); | 230 ALLOW_ACCESSORS(harmony_function_sent); |
232 ALLOW_ACCESSORS(harmony_async_await); | |
233 ALLOW_ACCESSORS(harmony_restrictive_generators); | 231 ALLOW_ACCESSORS(harmony_restrictive_generators); |
234 ALLOW_ACCESSORS(harmony_trailing_commas); | 232 ALLOW_ACCESSORS(harmony_trailing_commas); |
235 ALLOW_ACCESSORS(harmony_class_fields); | 233 ALLOW_ACCESSORS(harmony_class_fields); |
236 ALLOW_ACCESSORS(harmony_object_spread); | 234 ALLOW_ACCESSORS(harmony_object_spread); |
237 | 235 |
238 #undef ALLOW_ACCESSORS | 236 #undef ALLOW_ACCESSORS |
239 | 237 |
240 uintptr_t stack_limit() const { return stack_limit_; } | 238 uintptr_t stack_limit() const { return stack_limit_; } |
241 | 239 |
242 void set_stack_limit(uintptr_t stack_limit) { stack_limit_ = stack_limit; } | 240 void set_stack_limit(uintptr_t stack_limit) { stack_limit_ = stack_limit; } |
(...skipping 1205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1448 bool stack_overflow_; | 1446 bool stack_overflow_; |
1449 | 1447 |
1450 FunctionLiteral::EagerCompileHint default_eager_compile_hint_; | 1448 FunctionLiteral::EagerCompileHint default_eager_compile_hint_; |
1451 | 1449 |
1452 int function_literal_id_; | 1450 int function_literal_id_; |
1453 | 1451 |
1454 bool allow_natives_; | 1452 bool allow_natives_; |
1455 bool allow_tailcalls_; | 1453 bool allow_tailcalls_; |
1456 bool allow_harmony_do_expressions_; | 1454 bool allow_harmony_do_expressions_; |
1457 bool allow_harmony_function_sent_; | 1455 bool allow_harmony_function_sent_; |
1458 bool allow_harmony_async_await_; | |
1459 bool allow_harmony_restrictive_generators_; | 1456 bool allow_harmony_restrictive_generators_; |
1460 bool allow_harmony_trailing_commas_; | 1457 bool allow_harmony_trailing_commas_; |
1461 bool allow_harmony_class_fields_; | 1458 bool allow_harmony_class_fields_; |
1462 bool allow_harmony_object_spread_; | 1459 bool allow_harmony_object_spread_; |
1463 | 1460 |
1464 friend class DiscardableZoneScope; | 1461 friend class DiscardableZoneScope; |
1465 }; | 1462 }; |
1466 | 1463 |
1467 template <typename Impl> | 1464 template <typename Impl> |
1468 ParserBase<Impl>::FunctionState::FunctionState( | 1465 ParserBase<Impl>::FunctionState::FunctionState( |
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1735 | 1732 |
1736 case Token::NULL_LITERAL: | 1733 case Token::NULL_LITERAL: |
1737 case Token::TRUE_LITERAL: | 1734 case Token::TRUE_LITERAL: |
1738 case Token::FALSE_LITERAL: | 1735 case Token::FALSE_LITERAL: |
1739 case Token::SMI: | 1736 case Token::SMI: |
1740 case Token::NUMBER: | 1737 case Token::NUMBER: |
1741 BindingPatternUnexpectedToken(); | 1738 BindingPatternUnexpectedToken(); |
1742 return impl()->ExpressionFromLiteral(Next(), beg_pos); | 1739 return impl()->ExpressionFromLiteral(Next(), beg_pos); |
1743 | 1740 |
1744 case Token::ASYNC: | 1741 case Token::ASYNC: |
1745 if (allow_harmony_async_await() && | 1742 if (!scanner()->HasAnyLineTerminatorAfterNext() && |
1746 !scanner()->HasAnyLineTerminatorAfterNext() && | |
1747 PeekAhead() == Token::FUNCTION) { | 1743 PeekAhead() == Token::FUNCTION) { |
1748 Consume(Token::ASYNC); | 1744 Consume(Token::ASYNC); |
1749 return ParseAsyncFunctionLiteral(CHECK_OK); | 1745 return ParseAsyncFunctionLiteral(CHECK_OK); |
1750 } | 1746 } |
1751 // CoverCallExpressionAndAsyncArrowHead | 1747 // CoverCallExpressionAndAsyncArrowHead |
1752 *is_async = true; | 1748 *is_async = true; |
1753 /* falls through */ | 1749 /* falls through */ |
1754 case Token::IDENTIFIER: | 1750 case Token::IDENTIFIER: |
1755 case Token::LET: | 1751 case Token::LET: |
1756 case Token::STATIC: | 1752 case Token::STATIC: |
(...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2040 DCHECK(!*is_computed_name); | 2036 DCHECK(!*is_computed_name); |
2041 | 2037 |
2042 *is_generator = Check(Token::MUL); | 2038 *is_generator = Check(Token::MUL); |
2043 if (*is_generator) { | 2039 if (*is_generator) { |
2044 *kind = PropertyKind::kMethodProperty; | 2040 *kind = PropertyKind::kMethodProperty; |
2045 } | 2041 } |
2046 | 2042 |
2047 Token::Value token = peek(); | 2043 Token::Value token = peek(); |
2048 int pos = peek_position(); | 2044 int pos = peek_position(); |
2049 | 2045 |
2050 if (allow_harmony_async_await() && !*is_generator && token == Token::ASYNC && | 2046 if (!*is_generator && token == Token::ASYNC && |
2051 !scanner()->HasAnyLineTerminatorAfterNext()) { | 2047 !scanner()->HasAnyLineTerminatorAfterNext()) { |
2052 Consume(Token::ASYNC); | 2048 Consume(Token::ASYNC); |
2053 token = peek(); | 2049 token = peek(); |
2054 if (SetPropertyKindFromToken(token, kind)) { | 2050 if (SetPropertyKindFromToken(token, kind)) { |
2055 *name = impl()->GetSymbol(); // TODO(bakkot) specialize on 'async' | 2051 *name = impl()->GetSymbol(); // TODO(bakkot) specialize on 'async' |
2056 impl()->PushLiteralName(*name); | 2052 impl()->PushLiteralName(*name); |
2057 return factory()->NewStringLiteral(*name, pos); | 2053 return factory()->NewStringLiteral(*name, pos); |
2058 } | 2054 } |
2059 *kind = PropertyKind::kMethodProperty; | 2055 *kind = PropertyKind::kMethodProperty; |
2060 *is_async = true; | 2056 *is_async = true; |
(...skipping 603 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2664 return ParseYieldExpression(accept_IN, ok); | 2660 return ParseYieldExpression(accept_IN, ok); |
2665 } | 2661 } |
2666 | 2662 |
2667 FuncNameInferrer::State fni_state(fni_); | 2663 FuncNameInferrer::State fni_state(fni_); |
2668 Checkpoint checkpoint(this); | 2664 Checkpoint checkpoint(this); |
2669 ExpressionClassifier arrow_formals_classifier( | 2665 ExpressionClassifier arrow_formals_classifier( |
2670 this, classifier()->duplicate_finder()); | 2666 this, classifier()->duplicate_finder()); |
2671 | 2667 |
2672 Scope::Snapshot scope_snapshot(scope()); | 2668 Scope::Snapshot scope_snapshot(scope()); |
2673 | 2669 |
2674 bool is_async = allow_harmony_async_await() && peek() == Token::ASYNC && | 2670 bool is_async = peek() == Token::ASYNC && |
2675 !scanner()->HasAnyLineTerminatorAfterNext() && | 2671 !scanner()->HasAnyLineTerminatorAfterNext() && |
2676 IsValidArrowFormalParametersStart(PeekAhead()); | 2672 IsValidArrowFormalParametersStart(PeekAhead()); |
2677 | 2673 |
2678 bool parenthesized_formals = peek() == Token::LPAREN; | 2674 bool parenthesized_formals = peek() == Token::LPAREN; |
2679 if (!is_async && !parenthesized_formals) { | 2675 if (!is_async && !parenthesized_formals) { |
2680 ArrowFormalParametersUnexpectedToken(); | 2676 ArrowFormalParametersUnexpectedToken(); |
2681 } | 2677 } |
2682 | 2678 |
2683 // Parse a simple, faster sub-grammar (primary expression) if it's evident | 2679 // Parse a simple, faster sub-grammar (primary expression) if it's evident |
2684 // that we have only a trivial expression to parse. | 2680 // that we have only a trivial expression to parse. |
(...skipping 1861 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4546 return ParseClassDeclaration(nullptr, false, ok); | 4542 return ParseClassDeclaration(nullptr, false, ok); |
4547 case Token::VAR: | 4543 case Token::VAR: |
4548 case Token::CONST: | 4544 case Token::CONST: |
4549 return ParseVariableStatement(kStatementListItem, nullptr, ok); | 4545 return ParseVariableStatement(kStatementListItem, nullptr, ok); |
4550 case Token::LET: | 4546 case Token::LET: |
4551 if (IsNextLetKeyword()) { | 4547 if (IsNextLetKeyword()) { |
4552 return ParseVariableStatement(kStatementListItem, nullptr, ok); | 4548 return ParseVariableStatement(kStatementListItem, nullptr, ok); |
4553 } | 4549 } |
4554 break; | 4550 break; |
4555 case Token::ASYNC: | 4551 case Token::ASYNC: |
4556 if (allow_harmony_async_await() && PeekAhead() == Token::FUNCTION && | 4552 if (PeekAhead() == Token::FUNCTION && |
4557 !scanner()->HasAnyLineTerminatorAfterNext()) { | 4553 !scanner()->HasAnyLineTerminatorAfterNext()) { |
4558 Consume(Token::ASYNC); | 4554 Consume(Token::ASYNC); |
4559 return ParseAsyncFunctionDeclaration(nullptr, false, ok); | 4555 return ParseAsyncFunctionDeclaration(nullptr, false, ok); |
4560 } | 4556 } |
4561 /* falls through */ | 4557 /* falls through */ |
4562 default: | 4558 default: |
4563 break; | 4559 break; |
4564 } | 4560 } |
4565 return ParseStatement(nullptr, kAllowLabelledFunctionStatement, ok); | 4561 return ParseStatement(nullptr, kAllowLabelledFunctionStatement, ok); |
4566 } | 4562 } |
(...skipping 966 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5533 has_seen_constructor_ = true; | 5529 has_seen_constructor_ = true; |
5534 return; | 5530 return; |
5535 } | 5531 } |
5536 } | 5532 } |
5537 | 5533 |
5538 | 5534 |
5539 } // namespace internal | 5535 } // namespace internal |
5540 } // namespace v8 | 5536 } // namespace v8 |
5541 | 5537 |
5542 #endif // V8_PARSING_PARSER_BASE_H | 5538 #endif // V8_PARSING_PARSER_BASE_H |
OLD | NEW |