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" | |
11 #include "src/ast/ast-literal-reindexer.h" | 10 #include "src/ast/ast-literal-reindexer.h" |
| 11 #include "src/ast/ast-traversal-visitor.h" |
12 #include "src/ast/scopeinfo.h" | 12 #include "src/ast/scopeinfo.h" |
13 #include "src/bailout-reason.h" | 13 #include "src/bailout-reason.h" |
14 #include "src/base/platform/platform.h" | 14 #include "src/base/platform/platform.h" |
15 #include "src/bootstrapper.h" | 15 #include "src/bootstrapper.h" |
16 #include "src/char-predicates-inl.h" | 16 #include "src/char-predicates-inl.h" |
17 #include "src/codegen.h" | 17 #include "src/codegen.h" |
18 #include "src/compiler.h" | 18 #include "src/compiler.h" |
19 #include "src/messages.h" | 19 #include "src/messages.h" |
20 #include "src/parsing/parameter-initializer-rewriter.h" | 20 #include "src/parsing/parameter-initializer-rewriter.h" |
21 #include "src/parsing/parser-base.h" | 21 #include "src/parsing/parser-base.h" |
(...skipping 4608 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4630 MessageTemplate::kNonCoercible, ast_value_factory()->empty_string(), | 4630 MessageTemplate::kNonCoercible, ast_value_factory()->empty_string(), |
4631 kNoSourcePosition); | 4631 kNoSourcePosition); |
4632 IfStatement* if_statement = factory()->NewIfStatement( | 4632 IfStatement* if_statement = factory()->NewIfStatement( |
4633 condition, | 4633 condition, |
4634 factory()->NewExpressionStatement(throw_type_error, kNoSourcePosition), | 4634 factory()->NewExpressionStatement(throw_type_error, kNoSourcePosition), |
4635 factory()->NewEmptyStatement(kNoSourcePosition), kNoSourcePosition); | 4635 factory()->NewEmptyStatement(kNoSourcePosition), kNoSourcePosition); |
4636 return if_statement; | 4636 return if_statement; |
4637 } | 4637 } |
4638 | 4638 |
4639 | 4639 |
4640 class InitializerRewriter : public AstExpressionVisitor { | 4640 class InitializerRewriter final |
| 4641 : public AstTraversalVisitor<InitializerRewriter> { |
4641 public: | 4642 public: |
4642 InitializerRewriter(uintptr_t stack_limit, Expression* root, Parser* parser, | 4643 InitializerRewriter(uintptr_t stack_limit, Expression* root, Parser* parser, |
4643 Scope* scope) | 4644 Scope* scope) |
4644 : AstExpressionVisitor(stack_limit, root), | 4645 : AstTraversalVisitor(stack_limit, root), |
4645 parser_(parser), | 4646 parser_(parser), |
4646 scope_(scope) {} | 4647 scope_(scope) {} |
4647 | 4648 |
4648 private: | 4649 protected: |
4649 void VisitExpression(Expression* expr) override { | 4650 // Just rewrite destructuring assignments wrapped in RewritableExpressions. |
4650 RewritableExpression* to_rewrite = expr->AsRewritableExpression(); | 4651 void VisitRewritableExpression(RewritableExpression* to_rewrite) { |
4651 if (to_rewrite == nullptr || to_rewrite->is_rewritten()) return; | 4652 if (to_rewrite->is_rewritten()) return; |
4652 | |
4653 Parser::PatternRewriter::RewriteDestructuringAssignment(parser_, to_rewrite, | 4653 Parser::PatternRewriter::RewriteDestructuringAssignment(parser_, to_rewrite, |
4654 scope_); | 4654 scope_); |
4655 } | 4655 } |
4656 | 4656 |
4657 // Code in function literals does not need to be eagerly rewritten, it will be | 4657 // Code in function literals does not need to be eagerly rewritten, it will be |
4658 // rewritten when scheduled. | 4658 // rewritten when scheduled. |
4659 void VisitFunctionLiteral(FunctionLiteral* expr) override {} | 4659 void VisitFunctionLiteral(FunctionLiteral* expr) {} |
4660 | 4660 |
4661 private: | 4661 private: |
4662 Parser* parser_; | 4662 Parser* parser_; |
4663 Scope* scope_; | 4663 Scope* scope_; |
| 4664 |
| 4665 DEFINE_AST_VISITOR_DISPATCH() |
4664 }; | 4666 }; |
4665 | 4667 |
4666 | 4668 |
4667 void Parser::RewriteParameterInitializer(Expression* expr, Scope* scope) { | 4669 void Parser::RewriteParameterInitializer(Expression* expr, Scope* scope) { |
4668 InitializerRewriter rewriter(stack_limit_, expr, this, scope); | 4670 InitializerRewriter rewriter(stack_limit_, expr, this, scope); |
4669 rewriter.Run(); | 4671 rewriter.Run(); |
4670 } | 4672 } |
4671 | 4673 |
4672 | 4674 |
4673 Block* Parser::BuildParameterInitializationBlock( | 4675 Block* Parser::BuildParameterInitializationBlock( |
(...skipping 2408 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7082 node->Print(Isolate::Current()); | 7084 node->Print(Isolate::Current()); |
7083 } | 7085 } |
7084 #endif // DEBUG | 7086 #endif // DEBUG |
7085 | 7087 |
7086 #undef CHECK_OK | 7088 #undef CHECK_OK |
7087 #undef CHECK_OK_CUSTOM | 7089 #undef CHECK_OK_CUSTOM |
7088 #undef CHECK_FAILED | 7090 #undef CHECK_FAILED |
7089 | 7091 |
7090 } // namespace internal | 7092 } // namespace internal |
7091 } // namespace v8 | 7093 } // namespace v8 |
OLD | NEW |