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

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

Issue 1639343005: [generators] Implement Generator.prototype.return. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@yield-star
Patch Set: Another rebase 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/objects.h ('k') | src/runtime/runtime.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 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" 10 #include "src/ast/ast-expression-visitor.h"
(...skipping 5851 matching lines...) Expand 10 before | Expand all | Expand 10 after
5862 5862
5863 const int nopos = RelocInfo::kNoPosition; 5863 const int nopos = RelocInfo::kNoPosition;
5864 5864
5865 auto factory = parser_->factory(); 5865 auto factory = parser_->factory();
5866 auto avfactory = parser_->ast_value_factory(); 5866 auto avfactory = parser_->ast_value_factory();
5867 auto scope = parser_->scope_; 5867 auto scope = parser_->scope_;
5868 auto zone = parser_->zone(); 5868 auto zone = parser_->zone();
5869 5869
5870 Statement* skip = factory->NewEmptyStatement(nopos); 5870 Statement* skip = factory->NewEmptyStatement(nopos);
5871 5871
5872 enum { kNext, kReturn, kThrow };
5873 // TODO(neis): Use JSGenerator::ResumeMode once extended with RETURN.
5874
5875 // Forward definition for break/continue statements. 5872 // Forward definition for break/continue statements.
5876 WhileStatement* loop = factory->NewWhileStatement(nullptr, nopos); 5873 WhileStatement* loop = factory->NewWhileStatement(nullptr, nopos);
5877 5874
5878 5875
5879 // let input = undefined; 5876 // let input = undefined;
5880 Variable* var_input = scope->NewTemporary(avfactory->empty_string()); 5877 Variable* var_input = scope->NewTemporary(avfactory->empty_string());
5881 Statement* initialize_input; 5878 Statement* initialize_input;
5882 { 5879 {
5883 Expression* input_proxy = factory->NewVariableProxy(var_input); 5880 Expression* input_proxy = factory->NewVariableProxy(var_input);
5884 Expression* assignment = factory->NewAssignment( 5881 Expression* assignment = factory->NewAssignment(
5885 Token::ASSIGN, input_proxy, factory->NewUndefinedLiteral(nopos), nopos); 5882 Token::ASSIGN, input_proxy, factory->NewUndefinedLiteral(nopos), nopos);
5886 initialize_input = factory->NewExpressionStatement(assignment, nopos); 5883 initialize_input = factory->NewExpressionStatement(assignment, nopos);
5887 } 5884 }
5888 5885
5889 5886
5890 // let mode = kNext; 5887 // let mode = kNext;
5891 Variable* var_mode = scope->NewTemporary(avfactory->empty_string()); 5888 Variable* var_mode = scope->NewTemporary(avfactory->empty_string());
5892 Statement* initialize_mode; 5889 Statement* initialize_mode;
5893 { 5890 {
5894 Expression* mode_proxy = factory->NewVariableProxy(var_mode); 5891 Expression* mode_proxy = factory->NewVariableProxy(var_mode);
5895 Expression* knext = factory->NewSmiLiteral(kNext, nopos); 5892 Expression* knext = factory->NewSmiLiteral(JSGeneratorObject::NEXT, nopos);
5896 Expression* assignment = 5893 Expression* assignment =
5897 factory->NewAssignment(Token::ASSIGN, mode_proxy, knext, nopos); 5894 factory->NewAssignment(Token::ASSIGN, mode_proxy, knext, nopos);
5898 initialize_mode = factory->NewExpressionStatement(assignment, nopos); 5895 initialize_mode = factory->NewExpressionStatement(assignment, nopos);
5899 } 5896 }
5900 5897
5901 5898
5902 // let output = undefined; 5899 // let output = undefined;
5903 Variable* var_output = scope->NewTemporary(avfactory->empty_string()); 5900 Variable* var_output = scope->NewTemporary(avfactory->empty_string());
5904 Statement* initialize_output; 5901 Statement* initialize_output;
5905 { 5902 {
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
6080 Expression* property = factory->NewProperty(output_proxy, literal, nopos); 6077 Expression* property = factory->NewProperty(output_proxy, literal, nopos);
6081 BreakStatement* break_loop = factory->NewBreakStatement(loop, nopos); 6078 BreakStatement* break_loop = factory->NewBreakStatement(loop, nopos);
6082 if_done = factory->NewIfStatement(property, break_loop, skip, nopos); 6079 if_done = factory->NewIfStatement(property, break_loop, skip, nopos);
6083 } 6080 }
6084 6081
6085 6082
6086 // mode = kReturn; 6083 // mode = kReturn;
6087 Statement* set_mode_return; 6084 Statement* set_mode_return;
6088 { 6085 {
6089 Expression* mode_proxy = factory->NewVariableProxy(var_mode); 6086 Expression* mode_proxy = factory->NewVariableProxy(var_mode);
6090 Expression* kreturn = factory->NewSmiLiteral(kReturn, nopos); 6087 Expression* kreturn =
6088 factory->NewSmiLiteral(JSGeneratorObject::RETURN, nopos);
6091 Expression* assignment = 6089 Expression* assignment =
6092 factory->NewAssignment(Token::ASSIGN, mode_proxy, kreturn, nopos); 6090 factory->NewAssignment(Token::ASSIGN, mode_proxy, kreturn, nopos);
6093 set_mode_return = factory->NewExpressionStatement(assignment, nopos); 6091 set_mode_return = factory->NewExpressionStatement(assignment, nopos);
6094 } 6092 }
6095 6093
6096 6094
6097 // RawYield(output); 6095 // RawYield(output);
6098 Statement* yield_output; 6096 Statement* yield_output;
6099 { 6097 {
6100 Expression* output_proxy = factory->NewVariableProxy(var_output); 6098 Expression* output_proxy = factory->NewVariableProxy(var_output);
6101 Yield* yield = factory->NewYield( 6099 Yield* yield = factory->NewYield(
6102 generator, output_proxy, Yield::kInitial, nopos); 6100 generator, output_proxy, Yield::kInitial, nopos);
6103 yield_output = factory->NewExpressionStatement(yield, nopos); 6101 yield_output = factory->NewExpressionStatement(yield, nopos);
6104 } 6102 }
6105 6103
6106 6104
6107 // mode = kNext; 6105 // mode = kNext;
6108 Statement* set_mode_next; 6106 Statement* set_mode_next;
6109 { 6107 {
6110 Expression* mode_proxy = factory->NewVariableProxy(var_mode); 6108 Expression* mode_proxy = factory->NewVariableProxy(var_mode);
6111 Expression* knext = factory->NewSmiLiteral(kNext, nopos); 6109 Expression* knext = factory->NewSmiLiteral(JSGeneratorObject::NEXT, nopos);
6112 Expression* assignment = 6110 Expression* assignment =
6113 factory->NewAssignment(Token::ASSIGN, mode_proxy, knext, nopos); 6111 factory->NewAssignment(Token::ASSIGN, mode_proxy, knext, nopos);
6114 set_mode_next = factory->NewExpressionStatement(assignment, nopos); 6112 set_mode_next = factory->NewExpressionStatement(assignment, nopos);
6115 } 6113 }
6116 6114
6117 6115
6118 // mode = kThrow; 6116 // mode = kThrow;
6119 Statement* set_mode_throw; 6117 Statement* set_mode_throw;
6120 { 6118 {
6121 Expression* mode_proxy = factory->NewVariableProxy(var_mode); 6119 Expression* mode_proxy = factory->NewVariableProxy(var_mode);
6122 Expression* kthrow = factory->NewSmiLiteral(kThrow, nopos); 6120 Expression* kthrow =
6121 factory->NewSmiLiteral(JSGeneratorObject::THROW, nopos);
6123 Expression* assignment = 6122 Expression* assignment =
6124 factory->NewAssignment(Token::ASSIGN, mode_proxy, kthrow, nopos); 6123 factory->NewAssignment(Token::ASSIGN, mode_proxy, kthrow, nopos);
6125 set_mode_throw = factory->NewExpressionStatement(assignment, nopos); 6124 set_mode_throw = factory->NewExpressionStatement(assignment, nopos);
6126 } 6125 }
6127 6126
6128 6127
6129 // input = function.sent; 6128 // input = function.sent;
6130 Statement* get_input; 6129 Statement* get_input;
6131 { 6130 {
6132 Expression* function_sent = FunctionSentExpression(scope, factory, nopos); 6131 Expression* function_sent = FunctionSentExpression(scope, factory, nopos);
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
6201 case_return->Add(factory->NewBreakStatement(switch_mode, nopos), zone); 6200 case_return->Add(factory->NewBreakStatement(switch_mode, nopos), zone);
6202 6201
6203 auto case_throw = new (zone) ZoneList<Statement*>(5, zone); 6202 auto case_throw = new (zone) ZoneList<Statement*>(5, zone);
6204 case_throw->Add(get_throw, zone); 6203 case_throw->Add(get_throw, zone);
6205 case_throw->Add(check_throw, zone); 6204 case_throw->Add(check_throw, zone);
6206 case_throw->Add(call_throw, zone); 6205 case_throw->Add(call_throw, zone);
6207 case_throw->Add(validate_throw_output, zone); 6206 case_throw->Add(validate_throw_output, zone);
6208 case_throw->Add(factory->NewBreakStatement(switch_mode, nopos), zone); 6207 case_throw->Add(factory->NewBreakStatement(switch_mode, nopos), zone);
6209 6208
6210 auto cases = new (zone) ZoneList<CaseClause*>(3, zone); 6209 auto cases = new (zone) ZoneList<CaseClause*>(3, zone);
6211 Expression* knext = factory->NewSmiLiteral(kNext, nopos); 6210 Expression* knext = factory->NewSmiLiteral(JSGeneratorObject::NEXT, nopos);
6212 Expression* kreturn = factory->NewSmiLiteral(kReturn, nopos); 6211 Expression* kreturn =
6213 Expression* kthrow = factory->NewSmiLiteral(kThrow, nopos); 6212 factory->NewSmiLiteral(JSGeneratorObject::RETURN, nopos);
6213 Expression* kthrow =
6214 factory->NewSmiLiteral(JSGeneratorObject::THROW, nopos);
6214 cases->Add(factory->NewCaseClause(knext, case_next, nopos), zone); 6215 cases->Add(factory->NewCaseClause(knext, case_next, nopos), zone);
6215 cases->Add(factory->NewCaseClause(kreturn, case_return, nopos), zone); 6216 cases->Add(factory->NewCaseClause(kreturn, case_return, nopos), zone);
6216 cases->Add(factory->NewCaseClause(kthrow, case_throw, nopos), zone); 6217 cases->Add(factory->NewCaseClause(kthrow, case_throw, nopos), zone);
6217 6218
6218 switch_mode->Initialize(factory->NewVariableProxy(var_mode), cases); 6219 switch_mode->Initialize(factory->NewVariableProxy(var_mode), cases);
6219 } 6220 }
6220 6221
6221 6222
6222 // while (true) { ... } 6223 // while (true) { ... }
6223 // Already defined earlier: WhileStatement* loop = ... 6224 // Already defined earlier: WhileStatement* loop = ...
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
6349 6350
6350 statements->Add(get_return, zone); 6351 statements->Add(get_return, zone);
6351 statements->Add(check_return, zone); 6352 statements->Add(check_return, zone);
6352 statements->Add(call_return, zone); 6353 statements->Add(call_return, zone);
6353 statements->Add(validate_output, zone); 6354 statements->Add(validate_output, zone);
6354 } 6355 }
6355 6356
6356 6357
6357 } // namespace internal 6358 } // namespace internal
6358 } // namespace v8 6359 } // namespace v8
OLDNEW
« no previous file with comments | « src/objects.h ('k') | src/runtime/runtime.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698