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

Side by Side Diff: src/parsing/pattern-rewriter.cc

Issue 1702063002: Non-pattern rewriting revisited (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Fix a bug I introduced when rebasing Created 4 years, 10 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-base.h ('k') | src/parsing/preparser.h » ('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 2015 the V8 project authors. All rights reserved. 1 // Copyright 2015 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/ast/ast.h" 5 #include "src/ast/ast.h"
6 #include "src/messages.h" 6 #include "src/messages.h"
7 #include "src/parsing/parameter-initializer-rewriter.h" 7 #include "src/parsing/parameter-initializer-rewriter.h"
8 #include "src/parsing/parser.h" 8 #include "src/parsing/parser.h"
9 9
10 namespace v8 { 10 namespace v8 {
(...skipping 15 matching lines...) Expand all
26 rewriter.descriptor_ = declaration_descriptor; 26 rewriter.descriptor_ = declaration_descriptor;
27 rewriter.names_ = names; 27 rewriter.names_ = names;
28 rewriter.ok_ = ok; 28 rewriter.ok_ = ok;
29 rewriter.recursion_level_ = 0; 29 rewriter.recursion_level_ = 0;
30 30
31 rewriter.RecurseIntoSubpattern(rewriter.pattern_, declaration->initializer); 31 rewriter.RecurseIntoSubpattern(rewriter.pattern_, declaration->initializer);
32 } 32 }
33 33
34 34
35 void Parser::PatternRewriter::RewriteDestructuringAssignment( 35 void Parser::PatternRewriter::RewriteDestructuringAssignment(
36 Parser* parser, RewritableAssignmentExpression* to_rewrite, Scope* scope) { 36 Parser* parser, RewritableExpression* to_rewrite, Scope* scope) {
37 PatternRewriter rewriter; 37 PatternRewriter rewriter;
38 38
39 DCHECK(!to_rewrite->is_rewritten()); 39 DCHECK(!to_rewrite->is_rewritten());
40 40
41 bool ok = true; 41 bool ok = true;
42 rewriter.scope_ = scope; 42 rewriter.scope_ = scope;
43 rewriter.parser_ = parser; 43 rewriter.parser_ = parser;
44 rewriter.context_ = ASSIGNMENT; 44 rewriter.context_ = ASSIGNMENT;
45 rewriter.pattern_ = to_rewrite; 45 rewriter.pattern_ = to_rewrite;
46 rewriter.block_ = nullptr; 46 rewriter.block_ = nullptr;
47 rewriter.descriptor_ = nullptr; 47 rewriter.descriptor_ = nullptr;
48 rewriter.names_ = nullptr; 48 rewriter.names_ = nullptr;
49 rewriter.ok_ = &ok; 49 rewriter.ok_ = &ok;
50 rewriter.recursion_level_ = 0; 50 rewriter.recursion_level_ = 0;
51 51
52 rewriter.RecurseIntoSubpattern(rewriter.pattern_, nullptr); 52 rewriter.RecurseIntoSubpattern(rewriter.pattern_, nullptr);
53 DCHECK(ok); 53 DCHECK(ok);
54 } 54 }
55 55
56 56
57 Expression* Parser::PatternRewriter::RewriteDestructuringAssignment( 57 Expression* Parser::PatternRewriter::RewriteDestructuringAssignment(
58 Parser* parser, Assignment* assignment, Scope* scope) { 58 Parser* parser, Assignment* assignment, Scope* scope) {
59 DCHECK_NOT_NULL(assignment); 59 DCHECK_NOT_NULL(assignment);
60 DCHECK_EQ(Token::ASSIGN, assignment->op()); 60 DCHECK_EQ(Token::ASSIGN, assignment->op());
61 auto to_rewrite = 61 auto to_rewrite = parser->factory()->NewRewritableExpression(assignment);
62 parser->factory()->NewRewritableAssignmentExpression(assignment);
63 RewriteDestructuringAssignment(parser, to_rewrite, scope); 62 RewriteDestructuringAssignment(parser, to_rewrite, scope);
64 return to_rewrite->expression(); 63 return to_rewrite->expression();
65 } 64 }
66 65
67 66
68 bool Parser::PatternRewriter::IsAssignmentContext(PatternContext c) const { 67 bool Parser::PatternRewriter::IsAssignmentContext(PatternContext c) const {
69 return c == ASSIGNMENT || c == ASSIGNMENT_INITIALIZER; 68 return c == ASSIGNMENT || c == ASSIGNMENT_INITIALIZER;
70 } 69 }
71 70
72 71
(...skipping 11 matching lines...) Expand all
84 return old_context; 83 return old_context;
85 } 84 }
86 85
87 86
88 Parser::PatternRewriter::PatternContext 87 Parser::PatternRewriter::PatternContext
89 Parser::PatternRewriter::SetInitializerContextIfNeeded(Expression* node) { 88 Parser::PatternRewriter::SetInitializerContextIfNeeded(Expression* node) {
90 // Set appropriate initializer context for BindingElement and 89 // Set appropriate initializer context for BindingElement and
91 // AssignmentElement nodes 90 // AssignmentElement nodes
92 PatternContext old_context = context(); 91 PatternContext old_context = context();
93 bool is_destructuring_assignment = 92 bool is_destructuring_assignment =
94 node->IsRewritableAssignmentExpression() && 93 node->IsRewritableExpression() &&
95 !node->AsRewritableAssignmentExpression()->is_rewritten(); 94 !node->AsRewritableExpression()->is_rewritten();
96 bool is_assignment = 95 bool is_assignment =
97 node->IsAssignment() && node->AsAssignment()->op() == Token::ASSIGN; 96 node->IsAssignment() && node->AsAssignment()->op() == Token::ASSIGN;
98 if (is_destructuring_assignment || is_assignment) { 97 if (is_destructuring_assignment || is_assignment) {
99 switch (old_context) { 98 switch (old_context) {
100 case BINDING: 99 case BINDING:
101 set_context(INITIALIZER); 100 set_context(INITIALIZER);
102 break; 101 break;
103 case ASSIGNMENT: 102 case ASSIGNMENT:
104 set_context(ASSIGNMENT_INITIALIZER); 103 set_context(ASSIGNMENT_INITIALIZER);
105 break; 104 break;
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after
317 RelocInfo::kNoPosition); 316 RelocInfo::kNoPosition);
318 317
319 block_->statements()->Add( 318 block_->statements()->Add(
320 factory()->NewExpressionStatement(assignment, RelocInfo::kNoPosition), 319 factory()->NewExpressionStatement(assignment, RelocInfo::kNoPosition),
321 zone()); 320 zone());
322 } 321 }
323 return temp; 322 return temp;
324 } 323 }
325 324
326 325
327 void Parser::PatternRewriter::VisitRewritableAssignmentExpression( 326 void Parser::PatternRewriter::VisitRewritableExpression(
328 RewritableAssignmentExpression* node) { 327 RewritableExpression* node) {
329 if (!IsAssignmentContext()) { 328 // If this is not a destructuring assignment...
330 // Mark the assignment as rewritten to prevent redundant rewriting, and 329 if (!IsAssignmentContext() || !node->expression()->IsAssignment()) {
330 // Mark the node as rewritten to prevent redundant rewriting, and
331 // perform BindingPattern rewriting 331 // perform BindingPattern rewriting
332 DCHECK(!node->is_rewritten()); 332 DCHECK(!node->is_rewritten());
333 node->Rewrite(node->expression()); 333 node->Rewrite(node->expression());
334 return node->expression()->Accept(this); 334 return node->expression()->Accept(this);
335 } 335 }
336 336
337 if (node->is_rewritten()) return; 337 if (node->is_rewritten()) return;
338 DCHECK(IsAssignmentContext()); 338 DCHECK(IsAssignmentContext());
339 Assignment* assign = node->expression()->AsAssignment(); 339 Assignment* assign = node->expression()->AsAssignment();
340 DCHECK_NOT_NULL(assign); 340 DCHECK_NOT_NULL(assign);
(...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after
619 NOT_A_PATTERN(TryFinallyStatement) 619 NOT_A_PATTERN(TryFinallyStatement)
620 NOT_A_PATTERN(UnaryOperation) 620 NOT_A_PATTERN(UnaryOperation)
621 NOT_A_PATTERN(VariableDeclaration) 621 NOT_A_PATTERN(VariableDeclaration)
622 NOT_A_PATTERN(WhileStatement) 622 NOT_A_PATTERN(WhileStatement)
623 NOT_A_PATTERN(WithStatement) 623 NOT_A_PATTERN(WithStatement)
624 NOT_A_PATTERN(Yield) 624 NOT_A_PATTERN(Yield)
625 625
626 #undef NOT_A_PATTERN 626 #undef NOT_A_PATTERN
627 } // namespace internal 627 } // namespace internal
628 } // namespace v8 628 } // namespace v8
OLDNEW
« no previous file with comments | « src/parsing/parser-base.h ('k') | src/parsing/preparser.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698