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 320 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
331 bool stack_overflow() const { return stack_overflow_; } | 331 bool stack_overflow() const { return stack_overflow_; } |
332 void set_stack_overflow() { stack_overflow_ = true; } | 332 void set_stack_overflow() { stack_overflow_ = true; } |
333 Mode mode() const { return mode_; } | 333 Mode mode() const { return mode_; } |
334 Zone* zone() const { return zone_; } | 334 Zone* zone() const { return zone_; } |
335 | 335 |
336 INLINE(Token::Value peek()) { | 336 INLINE(Token::Value peek()) { |
337 if (stack_overflow_) return Token::ILLEGAL; | 337 if (stack_overflow_) return Token::ILLEGAL; |
338 return scanner()->peek(); | 338 return scanner()->peek(); |
339 } | 339 } |
340 | 340 |
| 341 INLINE(Token::Value PeekAhead()) { |
| 342 if (stack_overflow_) return Token::ILLEGAL; |
| 343 return scanner()->PeekAhead(); |
| 344 } |
| 345 |
341 INLINE(Token::Value Next()) { | 346 INLINE(Token::Value Next()) { |
342 if (stack_overflow_) return Token::ILLEGAL; | 347 if (stack_overflow_) return Token::ILLEGAL; |
343 { | 348 { |
344 if (GetCurrentStackPosition() < stack_limit_) { | 349 if (GetCurrentStackPosition() < stack_limit_) { |
345 // Any further calls to Next or peek will return the illegal token. | 350 // Any further calls to Next or peek will return the illegal token. |
346 // The current call must return the next token, which might already | 351 // The current call must return the next token, which might already |
347 // have been peek'ed. | 352 // have been peek'ed. |
348 stack_overflow_ = true; | 353 stack_overflow_ = true; |
349 } | 354 } |
350 } | 355 } |
(...skipping 352 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
703 bool* ok); | 708 bool* ok); |
704 | 709 |
705 void ParseFormalParameter(FormalParametersT* parameters, | 710 void ParseFormalParameter(FormalParametersT* parameters, |
706 ExpressionClassifier* classifier, bool* ok); | 711 ExpressionClassifier* classifier, bool* ok); |
707 void ParseFormalParameterList(FormalParametersT* parameters, | 712 void ParseFormalParameterList(FormalParametersT* parameters, |
708 ExpressionClassifier* classifier, bool* ok); | 713 ExpressionClassifier* classifier, bool* ok); |
709 void CheckArityRestrictions( | 714 void CheckArityRestrictions( |
710 int param_count, FunctionLiteral::ArityRestriction arity_restriction, | 715 int param_count, FunctionLiteral::ArityRestriction arity_restriction, |
711 bool has_rest, int formals_start_pos, int formals_end_pos, bool* ok); | 716 bool has_rest, int formals_start_pos, int formals_end_pos, bool* ok); |
712 | 717 |
| 718 bool IsNextLetKeyword(); |
| 719 |
713 // Checks if the expression is a valid reference expression (e.g., on the | 720 // Checks if the expression is a valid reference expression (e.g., on the |
714 // left-hand side of assignments). Although ruled out by ECMA as early errors, | 721 // left-hand side of assignments). Although ruled out by ECMA as early errors, |
715 // we allow calls for web compatibility and rewrite them to a runtime throw. | 722 // we allow calls for web compatibility and rewrite them to a runtime throw. |
716 ExpressionT CheckAndRewriteReferenceExpression( | 723 ExpressionT CheckAndRewriteReferenceExpression( |
717 ExpressionT expression, int beg_pos, int end_pos, | 724 ExpressionT expression, int beg_pos, int end_pos, |
718 MessageTemplate::Template message, bool* ok); | 725 MessageTemplate::Template message, bool* ok); |
719 ExpressionT CheckAndRewriteReferenceExpression( | 726 ExpressionT CheckAndRewriteReferenceExpression( |
720 ExpressionT expression, int beg_pos, int end_pos, | 727 ExpressionT expression, int beg_pos, int end_pos, |
721 MessageTemplate::Template message, ParseErrorType type, bool* ok); | 728 MessageTemplate::Template message, ParseErrorType type, bool* ok); |
722 | 729 |
(...skipping 3016 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3739 *ok = false; | 3746 *ok = false; |
3740 } | 3747 } |
3741 break; | 3748 break; |
3742 default: | 3749 default: |
3743 break; | 3750 break; |
3744 } | 3751 } |
3745 } | 3752 } |
3746 | 3753 |
3747 | 3754 |
3748 template <class Traits> | 3755 template <class Traits> |
| 3756 bool ParserBase<Traits>::IsNextLetKeyword() { |
| 3757 DCHECK(peek() == Token::LET); |
| 3758 if (!allow_let()) { |
| 3759 return false; |
| 3760 } |
| 3761 Token::Value next_next = PeekAhead(); |
| 3762 switch (next_next) { |
| 3763 case Token::LBRACE: |
| 3764 case Token::LBRACK: |
| 3765 case Token::IDENTIFIER: |
| 3766 case Token::STATIC: |
| 3767 case Token::LET: // Yes, you can do let let = ... in sloppy mode |
| 3768 case Token::YIELD: |
| 3769 return true; |
| 3770 default: |
| 3771 return false; |
| 3772 } |
| 3773 } |
| 3774 |
| 3775 |
| 3776 template <class Traits> |
3749 typename ParserBase<Traits>::ExpressionT | 3777 typename ParserBase<Traits>::ExpressionT |
3750 ParserBase<Traits>::ParseArrowFunctionLiteral( | 3778 ParserBase<Traits>::ParseArrowFunctionLiteral( |
3751 const FormalParametersT& formal_parameters, | 3779 const FormalParametersT& formal_parameters, |
3752 const ExpressionClassifier& formals_classifier, bool* ok) { | 3780 const ExpressionClassifier& formals_classifier, bool* ok) { |
3753 if (peek() == Token::ARROW && scanner_->HasAnyLineTerminatorBeforeNext()) { | 3781 if (peek() == Token::ARROW && scanner_->HasAnyLineTerminatorBeforeNext()) { |
3754 // ASI inserts `;` after arrow parameters if a line terminator is found. | 3782 // ASI inserts `;` after arrow parameters if a line terminator is found. |
3755 // `=> ...` is never a valid expression, so report as syntax error. | 3783 // `=> ...` is never a valid expression, so report as syntax error. |
3756 // If next token is not `=>`, it's a syntax error anyways. | 3784 // If next token is not `=>`, it's a syntax error anyways. |
3757 ReportUnexpectedTokenAt(scanner_->peek_location(), Token::ARROW); | 3785 ReportUnexpectedTokenAt(scanner_->peek_location(), Token::ARROW); |
3758 *ok = false; | 3786 *ok = false; |
(...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4046 *ok = false; | 4074 *ok = false; |
4047 return; | 4075 return; |
4048 } | 4076 } |
4049 has_seen_constructor_ = true; | 4077 has_seen_constructor_ = true; |
4050 return; | 4078 return; |
4051 } | 4079 } |
4052 } | 4080 } |
4053 } } // v8::internal | 4081 } } // v8::internal |
4054 | 4082 |
4055 #endif // V8_PREPARSER_H | 4083 #endif // V8_PREPARSER_H |
OLD | NEW |