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/v8.h" | 8 #include "src/v8.h" |
9 | 9 |
10 #include "src/bailout-reason.h" | 10 #include "src/bailout-reason.h" |
(...skipping 571 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
582 ExpressionT ParseUnaryExpression(bool* ok); | 582 ExpressionT ParseUnaryExpression(bool* ok); |
583 ExpressionT ParsePostfixExpression(bool* ok); | 583 ExpressionT ParsePostfixExpression(bool* ok); |
584 ExpressionT ParseLeftHandSideExpression(bool* ok); | 584 ExpressionT ParseLeftHandSideExpression(bool* ok); |
585 ExpressionT ParseMemberWithNewPrefixesExpression(bool* ok); | 585 ExpressionT ParseMemberWithNewPrefixesExpression(bool* ok); |
586 ExpressionT ParseMemberExpression(bool* ok); | 586 ExpressionT ParseMemberExpression(bool* ok); |
587 ExpressionT ParseMemberExpressionContinuation(ExpressionT expression, | 587 ExpressionT ParseMemberExpressionContinuation(ExpressionT expression, |
588 bool* ok); | 588 bool* ok); |
589 ExpressionT ParseArrowFunctionLiteral(int start_pos, ExpressionT params_ast, | 589 ExpressionT ParseArrowFunctionLiteral(int start_pos, ExpressionT params_ast, |
590 bool* ok); | 590 bool* ok); |
591 ExpressionT ParseTemplateLiteral(ExpressionT tag, int start, bool* ok); | 591 ExpressionT ParseTemplateLiteral(ExpressionT tag, int start, bool* ok); |
592 ExpressionT ParseTemplateLiteralAsMemberExpressionContinuation( | |
593 ExpressionT tag, bool* ok); | |
592 void AddTemplateExpression(ExpressionT); | 594 void AddTemplateExpression(ExpressionT); |
593 ExpressionT ParseSuperExpression(bool is_new, bool* ok); | 595 ExpressionT ParseSuperExpression(bool is_new, bool* ok); |
594 | 596 |
595 // Checks if the expression is a valid reference expression (e.g., on the | 597 // Checks if the expression is a valid reference expression (e.g., on the |
596 // left-hand side of assignments). Although ruled out by ECMA as early errors, | 598 // left-hand side of assignments). Although ruled out by ECMA as early errors, |
597 // we allow calls for web compatibility and rewrite them to a runtime throw. | 599 // we allow calls for web compatibility and rewrite them to a runtime throw. |
598 ExpressionT CheckAndRewriteReferenceExpression( | 600 ExpressionT CheckAndRewriteReferenceExpression( |
599 ExpressionT expression, | 601 ExpressionT expression, |
600 Scanner::Location location, const char* message, bool* ok); | 602 Scanner::Location location, const char* message, bool* ok); |
601 | 603 |
(...skipping 2046 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2648 // These calls are marked as potentially direct eval calls. Whether | 2650 // These calls are marked as potentially direct eval calls. Whether |
2649 // they are actually direct calls to eval is determined at run time. | 2651 // they are actually direct calls to eval is determined at run time. |
2650 this->CheckPossibleEvalCall(result, scope_); | 2652 this->CheckPossibleEvalCall(result, scope_); |
2651 result = factory()->NewCall(result, args, pos); | 2653 result = factory()->NewCall(result, args, pos); |
2652 if (fni_ != NULL) fni_->RemoveLastFunction(); | 2654 if (fni_ != NULL) fni_->RemoveLastFunction(); |
2653 break; | 2655 break; |
2654 } | 2656 } |
2655 | 2657 |
2656 case Token::TEMPLATE_SPAN: | 2658 case Token::TEMPLATE_SPAN: |
2657 case Token::TEMPLATE_TAIL: { | 2659 case Token::TEMPLATE_TAIL: { |
2658 int pos; | 2660 result = ParseTemplateLiteralAsMemberExpressionContinuation( |
2659 if (scanner()->current_token() == Token::IDENTIFIER) { | 2661 result, CHECK_OK); |
2660 pos = position(); | |
2661 } else { | |
2662 pos = peek_position(); | |
2663 if (result->IsFunctionLiteral() && mode() == PARSE_EAGERLY) { | |
2664 // If the tag function looks like an IIFE, set_parenthesized() to | |
2665 // force eager compilation. | |
2666 result->AsFunctionLiteral()->set_parenthesized(); | |
2667 } | |
2668 } | |
2669 result = ParseTemplateLiteral(result, pos, CHECK_OK); | |
2670 break; | 2662 break; |
2671 } | 2663 } |
2672 | 2664 |
2673 case Token::PERIOD: { | 2665 case Token::PERIOD: { |
2674 Consume(Token::PERIOD); | 2666 Consume(Token::PERIOD); |
2675 int pos = position(); | 2667 int pos = position(); |
2676 IdentifierT name = ParseIdentifierName(CHECK_OK); | 2668 IdentifierT name = ParseIdentifierName(CHECK_OK); |
2677 result = factory()->NewProperty( | 2669 result = factory()->NewProperty( |
2678 result, factory()->NewStringLiteral(name, pos), pos); | 2670 result, factory()->NewStringLiteral(name, pos), pos); |
2679 if (fni_ != NULL) this->PushLiteralName(fni_, name); | 2671 if (fni_ != NULL) this->PushLiteralName(fni_, name); |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2810 *ok = false; | 2802 *ok = false; |
2811 return this->EmptyExpression(); | 2803 return this->EmptyExpression(); |
2812 } | 2804 } |
2813 | 2805 |
2814 | 2806 |
2815 template <class Traits> | 2807 template <class Traits> |
2816 typename ParserBase<Traits>::ExpressionT | 2808 typename ParserBase<Traits>::ExpressionT |
2817 ParserBase<Traits>::ParseMemberExpressionContinuation(ExpressionT expression, | 2809 ParserBase<Traits>::ParseMemberExpressionContinuation(ExpressionT expression, |
2818 bool* ok) { | 2810 bool* ok) { |
2819 // Parses this part of MemberExpression: | 2811 // Parses this part of MemberExpression: |
2820 // ('[' Expression ']' | '.' Identifier)* | 2812 // ('[' Expression ']' | '.' Identifier)* |
arv (Not doing code reviews)
2015/03/11 18:48:54
update this comment?
| |
2821 while (true) { | 2813 while (true) { |
2822 switch (peek()) { | 2814 switch (peek()) { |
2823 case Token::LBRACK: { | 2815 case Token::LBRACK: { |
2824 Consume(Token::LBRACK); | 2816 Consume(Token::LBRACK); |
2825 int pos = position(); | 2817 int pos = position(); |
2826 ExpressionT index = this->ParseExpression(true, CHECK_OK); | 2818 ExpressionT index = this->ParseExpression(true, CHECK_OK); |
2827 expression = factory()->NewProperty(expression, index, pos); | 2819 expression = factory()->NewProperty(expression, index, pos); |
2828 if (fni_ != NULL) { | 2820 if (fni_ != NULL) { |
2829 this->PushPropertyName(fni_, index); | 2821 this->PushPropertyName(fni_, index); |
2830 } | 2822 } |
2831 Expect(Token::RBRACK, CHECK_OK); | 2823 Expect(Token::RBRACK, CHECK_OK); |
2832 break; | 2824 break; |
2833 } | 2825 } |
2834 case Token::PERIOD: { | 2826 case Token::PERIOD: { |
2835 Consume(Token::PERIOD); | 2827 Consume(Token::PERIOD); |
2836 int pos = position(); | 2828 int pos = position(); |
2837 IdentifierT name = ParseIdentifierName(CHECK_OK); | 2829 IdentifierT name = ParseIdentifierName(CHECK_OK); |
2838 expression = factory()->NewProperty( | 2830 expression = factory()->NewProperty( |
2839 expression, factory()->NewStringLiteral(name, pos), pos); | 2831 expression, factory()->NewStringLiteral(name, pos), pos); |
2840 if (fni_ != NULL) { | 2832 if (fni_ != NULL) { |
2841 this->PushLiteralName(fni_, name); | 2833 this->PushLiteralName(fni_, name); |
2842 } | 2834 } |
2843 break; | 2835 break; |
2844 } | 2836 } |
2837 case Token::TEMPLATE_SPAN: | |
2838 case Token::TEMPLATE_TAIL: { | |
2839 expression = ParseTemplateLiteralAsMemberExpressionContinuation( | |
2840 expression, CHECK_OK); | |
2841 break; | |
2842 } | |
2845 default: | 2843 default: |
2846 return expression; | 2844 return expression; |
2847 } | 2845 } |
2848 } | 2846 } |
2849 DCHECK(false); | 2847 DCHECK(false); |
2850 return this->EmptyExpression(); | 2848 return this->EmptyExpression(); |
2851 } | 2849 } |
2852 | 2850 |
2853 | 2851 |
2854 template <class Traits> | 2852 template <class Traits> |
2855 typename ParserBase<Traits>::ExpressionT | 2853 typename ParserBase<Traits>::ExpressionT |
2854 ParserBase<Traits>::ParseTemplateLiteralAsMemberExpressionContinuation( | |
2855 ExpressionT expression, bool* ok) { | |
2856 int pos; | |
2857 if (scanner()->current_token() == Token::IDENTIFIER) { | |
2858 pos = position(); | |
2859 } else { | |
2860 pos = peek_position(); | |
2861 if (expression->IsFunctionLiteral() && mode() == PARSE_EAGERLY) { | |
2862 // If the tag function looks like an IIFE, set_parenthesized() to | |
2863 // force eager compilation. | |
2864 expression->AsFunctionLiteral()->set_parenthesized(); | |
2865 } | |
2866 } | |
2867 return ParseTemplateLiteral(expression, pos, CHECK_OK); | |
2868 } | |
2869 | |
2870 | |
2871 template <class Traits> | |
2872 typename ParserBase<Traits>::ExpressionT | |
2856 ParserBase<Traits>::ParseArrowFunctionLiteral(int start_pos, | 2873 ParserBase<Traits>::ParseArrowFunctionLiteral(int start_pos, |
2857 ExpressionT params_ast, | 2874 ExpressionT params_ast, |
2858 bool* ok) { | 2875 bool* ok) { |
2859 if (peek() == Token::ARROW && scanner_->HasAnyLineTerminatorBeforeNext()) { | 2876 if (peek() == Token::ARROW && scanner_->HasAnyLineTerminatorBeforeNext()) { |
2860 // ASI inserts `;` after arrow parameters if a line terminator is found. | 2877 // ASI inserts `;` after arrow parameters if a line terminator is found. |
2861 // `=> ...` is never a valid expression, so report as syntax error. | 2878 // `=> ...` is never a valid expression, so report as syntax error. |
2862 // If next token is not `=>`, it's a syntax error anyways. | 2879 // If next token is not `=>`, it's a syntax error anyways. |
2863 ReportUnexpectedTokenAt(scanner_->peek_location(), Token::ARROW); | 2880 ReportUnexpectedTokenAt(scanner_->peek_location(), Token::ARROW); |
2864 *ok = false; | 2881 *ok = false; |
2865 return this->EmptyExpression(); | 2882 return this->EmptyExpression(); |
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3135 *ok = false; | 3152 *ok = false; |
3136 return; | 3153 return; |
3137 } | 3154 } |
3138 has_seen_constructor_ = true; | 3155 has_seen_constructor_ = true; |
3139 return; | 3156 return; |
3140 } | 3157 } |
3141 } | 3158 } |
3142 } } // v8::internal | 3159 } } // v8::internal |
3143 | 3160 |
3144 #endif // V8_PREPARSER_H | 3161 #endif // V8_PREPARSER_H |
OLD | NEW |