Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(918)

Side by Side Diff: src/parsing/parser.cc

Issue 2169833002: [parser] Refactor AstTraversalVisitor (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Rebase Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/parsing/parser.h ('k') | src/v8.gyp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 4602 matching lines...) Expand 10 before | Expand all | Expand 10 after
4624 MessageTemplate::kNonCoercible, ast_value_factory()->empty_string(), 4624 MessageTemplate::kNonCoercible, ast_value_factory()->empty_string(),
4625 kNoSourcePosition); 4625 kNoSourcePosition);
4626 IfStatement* if_statement = factory()->NewIfStatement( 4626 IfStatement* if_statement = factory()->NewIfStatement(
4627 condition, 4627 condition,
4628 factory()->NewExpressionStatement(throw_type_error, kNoSourcePosition), 4628 factory()->NewExpressionStatement(throw_type_error, kNoSourcePosition),
4629 factory()->NewEmptyStatement(kNoSourcePosition), kNoSourcePosition); 4629 factory()->NewEmptyStatement(kNoSourcePosition), kNoSourcePosition);
4630 return if_statement; 4630 return if_statement;
4631 } 4631 }
4632 4632
4633 4633
4634 class InitializerRewriter : public AstExpressionVisitor { 4634 class InitializerRewriter final
4635 : public AstTraversalVisitor<InitializerRewriter> {
4635 public: 4636 public:
4636 InitializerRewriter(uintptr_t stack_limit, Expression* root, Parser* parser, 4637 InitializerRewriter(uintptr_t stack_limit, Expression* root, Parser* parser,
4637 Scope* scope) 4638 Scope* scope)
4638 : AstExpressionVisitor(stack_limit, root), 4639 : AstTraversalVisitor(stack_limit, root),
4639 parser_(parser), 4640 parser_(parser),
4640 scope_(scope) {} 4641 scope_(scope) {}
4641 4642
4642 private: 4643 private:
4643 void VisitExpression(Expression* expr) override { 4644 // This is required so that the overriden Visit* methods can be
4644 RewritableExpression* to_rewrite = expr->AsRewritableExpression(); 4645 // called by the base class (template).
4645 if (to_rewrite == nullptr || to_rewrite->is_rewritten()) return; 4646 friend class AstTraversalVisitor<InitializerRewriter>;
4646 4647
4648 // Just rewrite destructuring assignments wrapped in RewritableExpressions.
4649 void VisitRewritableExpression(RewritableExpression* to_rewrite) {
4650 if (to_rewrite->is_rewritten()) return;
4647 Parser::PatternRewriter::RewriteDestructuringAssignment(parser_, to_rewrite, 4651 Parser::PatternRewriter::RewriteDestructuringAssignment(parser_, to_rewrite,
4648 scope_); 4652 scope_);
4649 } 4653 }
4650 4654
4651 // Code in function literals does not need to be eagerly rewritten, it will be 4655 // Code in function literals does not need to be eagerly rewritten, it will be
4652 // rewritten when scheduled. 4656 // rewritten when scheduled.
4653 void VisitFunctionLiteral(FunctionLiteral* expr) override {} 4657 void VisitFunctionLiteral(FunctionLiteral* expr) {}
4654 4658
4655 private:
4656 Parser* parser_; 4659 Parser* parser_;
4657 Scope* scope_; 4660 Scope* scope_;
4658 }; 4661 };
4659 4662
4660 4663
4661 void Parser::RewriteParameterInitializer(Expression* expr, Scope* scope) { 4664 void Parser::RewriteParameterInitializer(Expression* expr, Scope* scope) {
4662 InitializerRewriter rewriter(stack_limit_, expr, this, scope); 4665 InitializerRewriter rewriter(stack_limit_, expr, this, scope);
4663 rewriter.Run(); 4666 rewriter.Run();
4664 } 4667 }
4665 4668
(...skipping 2411 matching lines...) Expand 10 before | Expand all | Expand 10 after
7077 node->Print(Isolate::Current()); 7080 node->Print(Isolate::Current());
7078 } 7081 }
7079 #endif // DEBUG 7082 #endif // DEBUG
7080 7083
7081 #undef CHECK_OK 7084 #undef CHECK_OK
7082 #undef CHECK_OK_VOID 7085 #undef CHECK_OK_VOID
7083 #undef CHECK_FAILED 7086 #undef CHECK_FAILED
7084 7087
7085 } // namespace internal 7088 } // namespace internal
7086 } // namespace v8 7089 } // namespace v8
OLDNEW
« no previous file with comments | « src/parsing/parser.h ('k') | src/v8.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698