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 #include "src/parsing/parser.h" | 5 #include "src/parsing/parser.h" |
6 | 6 |
7 #include "src/api.h" | 7 #include "src/api.h" |
8 #include "src/ast/ast.h" | 8 #include "src/ast/ast.h" |
9 #include "src/ast/ast-expression-rewriter.h" | 9 #include "src/ast/ast-expression-rewriter.h" |
10 #include "src/ast/ast-expression-visitor.h" | 10 #include "src/ast/ast-expression-visitor.h" |
(...skipping 2500 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2511 int pos = peek_position(); | 2511 int pos = peek_position(); |
2512 | 2512 |
2513 switch (peek()) { | 2513 switch (peek()) { |
2514 case Token::FUNCTION: | 2514 case Token::FUNCTION: |
2515 case Token::LBRACE: | 2515 case Token::LBRACE: |
2516 UNREACHABLE(); // Always handled by the callers. | 2516 UNREACHABLE(); // Always handled by the callers. |
2517 case Token::CLASS: | 2517 case Token::CLASS: |
2518 ReportUnexpectedToken(Next()); | 2518 ReportUnexpectedToken(Next()); |
2519 *ok = false; | 2519 *ok = false; |
2520 return nullptr; | 2520 return nullptr; |
2521 | |
2522 default: | 2521 default: |
2523 break; | 2522 break; |
2524 } | 2523 } |
2525 | 2524 |
2526 bool starts_with_idenfifier = peek_any_identifier(); | 2525 bool starts_with_idenfifier = peek_any_identifier(); |
2527 Expression* expr = ParseExpression(true, CHECK_OK); | 2526 Expression* expr = ParseExpression(true, CHECK_OK); |
2528 if (peek() == Token::COLON && starts_with_idenfifier && expr != NULL && | 2527 if (peek() == Token::COLON && starts_with_idenfifier && expr != NULL && |
2529 expr->AsVariableProxy() != NULL && | 2528 expr->AsVariableProxy() != NULL && |
2530 !expr->AsVariableProxy()->is_this()) { | 2529 !expr->AsVariableProxy()->is_this()) { |
2531 // Expression is a single identifier, and not, e.g., a parenthesized | 2530 // Expression is a single identifier, and not, e.g., a parenthesized |
(...skipping 3063 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5595 Expression* async_function_await = parser_->factory()->NewCallRuntime( | 5594 Expression* async_function_await = parser_->factory()->NewCallRuntime( |
5596 Context::ASYNC_FUNCTION_AWAIT_INDEX, async_function_await_args, | 5595 Context::ASYNC_FUNCTION_AWAIT_INDEX, async_function_await_args, |
5597 RelocInfo::kNoPosition); | 5596 RelocInfo::kNoPosition); |
5598 | 5597 |
5599 generator_object = | 5598 generator_object = |
5600 parser_->factory()->NewVariableProxy(generator_object_variable); | 5599 parser_->factory()->NewVariableProxy(generator_object_variable); |
5601 return parser_->factory()->NewYield(generator_object, async_function_await, | 5600 return parser_->factory()->NewYield(generator_object, async_function_await, |
5602 pos); | 5601 pos); |
5603 } | 5602 } |
5604 | 5603 |
| 5604 ZoneList<Expression*>* ParserTraits::GetNonPatternList() const { |
| 5605 return parser_->function_state_->non_patterns_to_rewrite(); |
| 5606 } |
| 5607 |
| 5608 |
| 5609 ZoneList<typename ParserTraits::Type::ExpressionClassifier::Error>* |
| 5610 ParserTraits::GetReportedErrorList() const { |
| 5611 return parser_->function_state_->GetReportedErrorList(); |
| 5612 } |
| 5613 |
| 5614 |
5605 Zone* ParserTraits::zone() const { | 5615 Zone* ParserTraits::zone() const { |
5606 return parser_->function_state_->scope()->zone(); | 5616 return parser_->function_state_->scope()->zone(); |
5607 } | 5617 } |
5608 | 5618 |
5609 | 5619 |
5610 ZoneList<Expression*>* ParserTraits::GetNonPatternList() const { | |
5611 return parser_->function_state_->non_patterns_to_rewrite(); | |
5612 } | |
5613 | |
5614 | |
5615 class NonPatternRewriter : public AstExpressionRewriter { | 5620 class NonPatternRewriter : public AstExpressionRewriter { |
5616 public: | 5621 public: |
5617 NonPatternRewriter(uintptr_t stack_limit, Parser* parser) | 5622 NonPatternRewriter(uintptr_t stack_limit, Parser* parser) |
5618 : AstExpressionRewriter(stack_limit), parser_(parser) {} | 5623 : AstExpressionRewriter(stack_limit), parser_(parser) {} |
5619 ~NonPatternRewriter() override {} | 5624 ~NonPatternRewriter() override {} |
5620 | 5625 |
5621 private: | 5626 private: |
5622 bool RewriteExpression(Expression* expr) override { | 5627 bool RewriteExpression(Expression* expr) override { |
5623 if (expr->IsRewritableExpression()) return true; | 5628 if (expr->IsRewritableExpression()) return true; |
5624 // Rewrite only what could have been a pattern but is not. | 5629 // Rewrite only what could have been a pattern but is not. |
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5818 } | 5823 } |
5819 | 5824 |
5820 | 5825 |
5821 void ParserTraits::QueueDestructuringAssignmentForRewriting(Expression* expr) { | 5826 void ParserTraits::QueueDestructuringAssignmentForRewriting(Expression* expr) { |
5822 DCHECK(expr->IsRewritableExpression()); | 5827 DCHECK(expr->IsRewritableExpression()); |
5823 parser_->function_state_->AddDestructuringAssignment( | 5828 parser_->function_state_->AddDestructuringAssignment( |
5824 Parser::DestructuringAssignment(expr, parser_->scope_)); | 5829 Parser::DestructuringAssignment(expr, parser_->scope_)); |
5825 } | 5830 } |
5826 | 5831 |
5827 | 5832 |
5828 void ParserTraits::QueueNonPatternForRewriting(Expression* expr) { | 5833 void ParserTraits::QueueNonPatternForRewriting(Expression* expr, bool* ok) { |
5829 DCHECK(expr->IsRewritableExpression()); | 5834 DCHECK(expr->IsRewritableExpression()); |
5830 parser_->function_state_->AddNonPatternForRewriting(expr); | 5835 parser_->function_state_->AddNonPatternForRewriting(expr, ok); |
5831 } | 5836 } |
5832 | 5837 |
5833 | 5838 |
5834 void ParserTraits::SetFunctionNameFromPropertyName( | 5839 void ParserTraits::SetFunctionNameFromPropertyName( |
5835 ObjectLiteralProperty* property, const AstRawString* name) { | 5840 ObjectLiteralProperty* property, const AstRawString* name) { |
5836 Expression* value = property->value(); | 5841 Expression* value = property->value(); |
5837 | 5842 |
5838 // Computed name setting must happen at runtime. | 5843 // Computed name setting must happen at runtime. |
5839 if (property->is_computed_name()) return; | 5844 if (property->is_computed_name()) return; |
5840 | 5845 |
(...skipping 1071 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6912 try_block, target); | 6917 try_block, target); |
6913 final_loop = target; | 6918 final_loop = target; |
6914 } | 6919 } |
6915 | 6920 |
6916 return final_loop; | 6921 return final_loop; |
6917 } | 6922 } |
6918 | 6923 |
6919 | 6924 |
6920 } // namespace internal | 6925 } // namespace internal |
6921 } // namespace v8 | 6926 } // namespace v8 |
OLD | NEW |