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

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

Issue 1712203002: Revert of Non-pattern rewriting revisited (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: 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, RewritableExpression* to_rewrite, Scope* scope) { 36 Parser* parser, RewritableAssignmentExpression* 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 = parser->factory()->NewRewritableExpression(assignment); 61 auto to_rewrite =
62 parser->factory()->NewRewritableAssignmentExpression(assignment);
62 RewriteDestructuringAssignment(parser, to_rewrite, scope); 63 RewriteDestructuringAssignment(parser, to_rewrite, scope);
63 return to_rewrite->expression(); 64 return to_rewrite->expression();
64 } 65 }
65 66
66 67
67 bool Parser::PatternRewriter::IsAssignmentContext(PatternContext c) const { 68 bool Parser::PatternRewriter::IsAssignmentContext(PatternContext c) const {
68 return c == ASSIGNMENT || c == ASSIGNMENT_INITIALIZER; 69 return c == ASSIGNMENT || c == ASSIGNMENT_INITIALIZER;
69 } 70 }
70 71
71 72
(...skipping 11 matching lines...) Expand all
83 return old_context; 84 return old_context;
84 } 85 }
85 86
86 87
87 Parser::PatternRewriter::PatternContext 88 Parser::PatternRewriter::PatternContext
88 Parser::PatternRewriter::SetInitializerContextIfNeeded(Expression* node) { 89 Parser::PatternRewriter::SetInitializerContextIfNeeded(Expression* node) {
89 // Set appropriate initializer context for BindingElement and 90 // Set appropriate initializer context for BindingElement and
90 // AssignmentElement nodes 91 // AssignmentElement nodes
91 PatternContext old_context = context(); 92 PatternContext old_context = context();
92 bool is_destructuring_assignment = 93 bool is_destructuring_assignment =
93 node->IsRewritableExpression() && 94 node->IsRewritableAssignmentExpression() &&
94 !node->AsRewritableExpression()->is_rewritten(); 95 !node->AsRewritableAssignmentExpression()->is_rewritten();
95 bool is_assignment = 96 bool is_assignment =
96 node->IsAssignment() && node->AsAssignment()->op() == Token::ASSIGN; 97 node->IsAssignment() && node->AsAssignment()->op() == Token::ASSIGN;
97 if (is_destructuring_assignment || is_assignment) { 98 if (is_destructuring_assignment || is_assignment) {
98 switch (old_context) { 99 switch (old_context) {
99 case BINDING: 100 case BINDING:
100 set_context(INITIALIZER); 101 set_context(INITIALIZER);
101 break; 102 break;
102 case ASSIGNMENT: 103 case ASSIGNMENT:
103 set_context(ASSIGNMENT_INITIALIZER); 104 set_context(ASSIGNMENT_INITIALIZER);
104 break; 105 break;
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after
316 RelocInfo::kNoPosition); 317 RelocInfo::kNoPosition);
317 318
318 block_->statements()->Add( 319 block_->statements()->Add(
319 factory()->NewExpressionStatement(assignment, RelocInfo::kNoPosition), 320 factory()->NewExpressionStatement(assignment, RelocInfo::kNoPosition),
320 zone()); 321 zone());
321 } 322 }
322 return temp; 323 return temp;
323 } 324 }
324 325
325 326
326 void Parser::PatternRewriter::VisitRewritableExpression( 327 void Parser::PatternRewriter::VisitRewritableAssignmentExpression(
327 RewritableExpression* node) { 328 RewritableAssignmentExpression* node) {
328 // If this is not a destructuring assignment... 329 if (!IsAssignmentContext()) {
329 if (!IsAssignmentContext() || !node->expression()->IsAssignment()) { 330 // Mark the assignment as rewritten to prevent redundant rewriting, and
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