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

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: Created 4 years, 5 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
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 4608 matching lines...) Expand 10 before | Expand all | Expand 10 after
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:
adamk 2016/07/21 18:11:57 Same note about "protected", maybe I'm missing som
nickie 2016/07/22 08:40:18 Nope, I was... :-) Done, in the same way.
4649 void VisitExpression(Expression* expr) override { 4650 friend class AstTraversalVisitor<InitializerRewriter>;
4650 RewritableExpression* to_rewrite = expr->AsRewritableExpression();
4651 if (to_rewrite == nullptr || to_rewrite->is_rewritten()) return;
4652 4651
4652 // Just rewrite destructuring assignments wrapped in RewritableExpressions.
4653 void VisitRewritableExpression(RewritableExpression* to_rewrite) {
4654 if (to_rewrite->is_rewritten()) return;
4653 Parser::PatternRewriter::RewriteDestructuringAssignment(parser_, to_rewrite, 4655 Parser::PatternRewriter::RewriteDestructuringAssignment(parser_, to_rewrite,
4654 scope_); 4656 scope_);
4655 } 4657 }
4656 4658
4657 // Code in function literals does not need to be eagerly rewritten, it will be 4659 // Code in function literals does not need to be eagerly rewritten, it will be
4658 // rewritten when scheduled. 4660 // rewritten when scheduled.
4659 void VisitFunctionLiteral(FunctionLiteral* expr) override {} 4661 void VisitFunctionLiteral(FunctionLiteral* expr) {}
4660 4662
4661 private: 4663 private:
4662 Parser* parser_; 4664 Parser* parser_;
4663 Scope* scope_; 4665 Scope* scope_;
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();
(...skipping 2412 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698