Commit 652e1e6d authored by verwaest's avatar verwaest Committed by Commit bot

Redirect Scope::NewTemporary over parser

BUG=v8:5209

Review-Url: https://codereview.chromium.org/2220363004
Cr-Commit-Position: refs/heads/master@{#38508}
parent 0904b84e
...@@ -2741,8 +2741,7 @@ Statement* Parser::ParseReturnStatement(bool* ok) { ...@@ -2741,8 +2741,7 @@ Statement* Parser::ParseReturnStatement(bool* ok) {
// %_IsJSReceiver(temp) ? temp : 1; // %_IsJSReceiver(temp) ? temp : 1;
// temp = expr // temp = expr
Variable* temp = Variable* temp = NewTemporary(ast_value_factory()->empty_string());
scope()->NewTemporary(ast_value_factory()->empty_string());
Assignment* assign = factory()->NewAssignment( Assignment* assign = factory()->NewAssignment(
Token::ASSIGN, factory()->NewVariableProxy(temp), return_value, pos); Token::ASSIGN, factory()->NewVariableProxy(temp), return_value, pos);
...@@ -2884,7 +2883,7 @@ Statement* Parser::ParseSwitchStatement(ZoneList<const AstRawString*>* labels, ...@@ -2884,7 +2883,7 @@ Statement* Parser::ParseSwitchStatement(ZoneList<const AstRawString*>* labels,
Expect(Token::RPAREN, CHECK_OK); Expect(Token::RPAREN, CHECK_OK);
Variable* tag_variable = Variable* tag_variable =
scope()->NewTemporary(ast_value_factory()->dot_switch_tag_string()); NewTemporary(ast_value_factory()->dot_switch_tag_string());
Assignment* tag_assign = factory()->NewAssignment( Assignment* tag_assign = factory()->NewAssignment(
Token::ASSIGN, factory()->NewVariableProxy(tag_variable), tag, Token::ASSIGN, factory()->NewVariableProxy(tag_variable), tag,
tag->position()); tag->position());
...@@ -3245,8 +3244,7 @@ Statement* Parser::InitializeForEachStatement(ForEachStatement* stmt, ...@@ -3245,8 +3244,7 @@ Statement* Parser::InitializeForEachStatement(ForEachStatement* stmt,
each_keyword_pos); each_keyword_pos);
} else { } else {
if (each->IsArrayLiteral() || each->IsObjectLiteral()) { if (each->IsArrayLiteral() || each->IsObjectLiteral()) {
Variable* temp = Variable* temp = NewTemporary(ast_value_factory()->empty_string());
scope()->NewTemporary(ast_value_factory()->empty_string());
VariableProxy* temp_proxy = factory()->NewVariableProxy(temp); VariableProxy* temp_proxy = factory()->NewVariableProxy(temp);
Expression* assign_each = PatternRewriter::RewriteDestructuringAssignment( Expression* assign_each = PatternRewriter::RewriteDestructuringAssignment(
this, factory()->NewAssignment(Token::ASSIGN, each, temp_proxy, this, factory()->NewAssignment(Token::ASSIGN, each, temp_proxy,
...@@ -3279,11 +3277,9 @@ Statement* Parser::InitializeForOfStatement(ForOfStatement* for_of, ...@@ -3279,11 +3277,9 @@ Statement* Parser::InitializeForOfStatement(ForOfStatement* for_of,
const int nopos = kNoSourcePosition; const int nopos = kNoSourcePosition;
auto avfactory = ast_value_factory(); auto avfactory = ast_value_factory();
Variable* iterator = Variable* iterator = NewTemporary(ast_value_factory()->dot_iterator_string());
scope()->NewTemporary(ast_value_factory()->dot_iterator_string()); Variable* result = NewTemporary(ast_value_factory()->dot_result_string());
Variable* result = Variable* completion = NewTemporary(avfactory->empty_string());
scope()->NewTemporary(ast_value_factory()->dot_result_string());
Variable* completion = scope()->NewTemporary(avfactory->empty_string());
// iterator = iterable[Symbol.iterator]() // iterator = iterable[Symbol.iterator]()
Expression* assign_iterator; Expression* assign_iterator;
...@@ -3339,7 +3335,7 @@ Statement* Parser::InitializeForOfStatement(ForOfStatement* for_of, ...@@ -3339,7 +3335,7 @@ Statement* Parser::InitializeForOfStatement(ForOfStatement* for_of,
// do { let tmp = #result_value; #set_completion_abrupt; tmp } // do { let tmp = #result_value; #set_completion_abrupt; tmp }
// Expression* result_value (gets overwritten) // Expression* result_value (gets overwritten)
if (finalize) { if (finalize) {
Variable* var_tmp = scope()->NewTemporary(avfactory->empty_string()); Variable* var_tmp = NewTemporary(avfactory->empty_string());
Expression* tmp = factory()->NewVariableProxy(var_tmp); Expression* tmp = factory()->NewVariableProxy(var_tmp);
Expression* assignment = Expression* assignment =
factory()->NewAssignment(Token::ASSIGN, tmp, result_value, nopos); factory()->NewAssignment(Token::ASSIGN, tmp, result_value, nopos);
...@@ -3449,7 +3445,7 @@ Statement* Parser::DesugarLexicalBindingsInForStatement( ...@@ -3449,7 +3445,7 @@ Statement* Parser::DesugarLexicalBindingsInForStatement(
// make statement: temp_x = x. // make statement: temp_x = x.
for (int i = 0; i < names->length(); i++) { for (int i = 0; i < names->length(); i++) {
VariableProxy* proxy = NewUnresolved(names->at(i), LET); VariableProxy* proxy = NewUnresolved(names->at(i), LET);
Variable* temp = scope()->NewTemporary(temp_name); Variable* temp = NewTemporary(temp_name);
VariableProxy* temp_proxy = factory()->NewVariableProxy(temp); VariableProxy* temp_proxy = factory()->NewVariableProxy(temp);
Assignment* assignment = factory()->NewAssignment(Token::ASSIGN, temp_proxy, Assignment* assignment = factory()->NewAssignment(Token::ASSIGN, temp_proxy,
proxy, kNoSourcePosition); proxy, kNoSourcePosition);
...@@ -3462,7 +3458,7 @@ Statement* Parser::DesugarLexicalBindingsInForStatement( ...@@ -3462,7 +3458,7 @@ Statement* Parser::DesugarLexicalBindingsInForStatement(
Variable* first = NULL; Variable* first = NULL;
// Make statement: first = 1. // Make statement: first = 1.
if (next) { if (next) {
first = scope()->NewTemporary(temp_name); first = NewTemporary(temp_name);
VariableProxy* first_proxy = factory()->NewVariableProxy(first); VariableProxy* first_proxy = factory()->NewVariableProxy(first);
Expression* const1 = factory()->NewSmiLiteral(1, kNoSourcePosition); Expression* const1 = factory()->NewSmiLiteral(1, kNoSourcePosition);
Assignment* assignment = factory()->NewAssignment( Assignment* assignment = factory()->NewAssignment(
...@@ -3537,7 +3533,7 @@ Statement* Parser::DesugarLexicalBindingsInForStatement( ...@@ -3537,7 +3533,7 @@ Statement* Parser::DesugarLexicalBindingsInForStatement(
ignore_completion_block->statements()->Add(clear_first_or_next, zone()); ignore_completion_block->statements()->Add(clear_first_or_next, zone());
} }
Variable* flag = scope()->NewTemporary(temp_name); Variable* flag = NewTemporary(temp_name);
// Make statement: flag = 1. // Make statement: flag = 1.
{ {
VariableProxy* flag_proxy = factory()->NewVariableProxy(flag); VariableProxy* flag_proxy = factory()->NewVariableProxy(flag);
...@@ -3746,8 +3742,7 @@ Statement* Parser::ParseForStatement(ZoneList<const AstRawString*>* labels, ...@@ -3746,8 +3742,7 @@ Statement* Parser::ParseForStatement(ZoneList<const AstRawString*>* labels,
// let x; // for TDZ // let x; // for TDZ
// } // }
Variable* temp = Variable* temp = NewTemporary(ast_value_factory()->dot_for_string());
scope()->NewTemporary(ast_value_factory()->dot_for_string());
ForEachStatement* loop = ForEachStatement* loop =
factory()->NewForEachStatement(mode, labels, stmt_pos); factory()->NewForEachStatement(mode, labels, stmt_pos);
Target target(&this->target_stack_, loop); Target target(&this->target_stack_, loop);
...@@ -4139,8 +4134,8 @@ void Parser::DesugarAsyncFunctionBody(const AstRawString* function_name, ...@@ -4139,8 +4134,8 @@ void Parser::DesugarAsyncFunctionBody(const AstRawString* function_name,
// } // }
// } // }
scope->ForceContextAllocation(); scope->ForceContextAllocation();
Variable* temp = this->scope()->NewTemporary( Variable* temp =
ast_value_factory()->dot_generator_object_string()); NewTemporary(ast_value_factory()->dot_generator_object_string());
function_state_->set_generator_object_variable(temp); function_state_->set_generator_object_variable(temp);
Expression* init_generator_variable = factory()->NewAssignment( Expression* init_generator_variable = factory()->NewAssignment(
...@@ -4178,8 +4173,7 @@ DoExpression* Parser::ParseDoExpression(bool* ok) { ...@@ -4178,8 +4173,7 @@ DoExpression* Parser::ParseDoExpression(bool* ok) {
int pos = peek_position(); int pos = peek_position();
Expect(Token::DO, CHECK_OK); Expect(Token::DO, CHECK_OK);
Variable* result = Variable* result = NewTemporary(ast_value_factory()->dot_result_string());
scope()->NewTemporary(ast_value_factory()->dot_result_string());
Block* block = ParseBlock(nullptr, CHECK_OK); Block* block = ParseBlock(nullptr, CHECK_OK);
DoExpression* expr = factory()->NewDoExpression(block, result, pos); DoExpression* expr = factory()->NewDoExpression(block, result, pos);
if (!Rewriter::Rewrite(this, GetClosureScope(), expr, ast_value_factory())) { if (!Rewriter::Rewrite(this, GetClosureScope(), expr, ast_value_factory())) {
...@@ -4382,8 +4376,8 @@ FunctionLiteral* Parser::ParseFunctionLiteral( ...@@ -4382,8 +4376,8 @@ FunctionLiteral* Parser::ParseFunctionLiteral(
// Calling a generator returns a generator object. That object is stored // Calling a generator returns a generator object. That object is stored
// in a temporary variable, a definition that is used by "yield" // in a temporary variable, a definition that is used by "yield"
// expressions. This also marks the FunctionState as a generator. // expressions. This also marks the FunctionState as a generator.
Variable* temp = this->scope()->NewTemporary( Variable* temp =
ast_value_factory()->dot_generator_object_string()); NewTemporary(ast_value_factory()->dot_generator_object_string());
function_state.set_generator_object_variable(temp); function_state.set_generator_object_variable(temp);
} }
...@@ -5105,8 +5099,7 @@ Expression* Parser::ParseClassLiteral(ExpressionClassifier* classifier, ...@@ -5105,8 +5099,7 @@ Expression* Parser::ParseClassLiteral(ExpressionClassifier* classifier,
} }
Block* do_block = factory()->NewBlock(nullptr, 1, false, pos); Block* do_block = factory()->NewBlock(nullptr, 1, false, pos);
Variable* result_var = Variable* result_var = NewTemporary(ast_value_factory()->empty_string());
scope()->NewTemporary(ast_value_factory()->empty_string());
do_block->set_scope(block_state.FinalizedBlockScope()); do_block->set_scope(block_state.FinalizedBlockScope());
DoExpression* do_expr = factory()->NewDoExpression(do_block, result_var, pos); DoExpression* do_expr = factory()->NewDoExpression(do_block, result_var, pos);
...@@ -5711,8 +5704,7 @@ Expression* Parser::SpreadCall(Expression* function, ...@@ -5711,8 +5704,7 @@ Expression* Parser::SpreadCall(Expression* function,
args->InsertAt(0, function, zone()); args->InsertAt(0, function, zone());
args->InsertAt(1, home, zone()); args->InsertAt(1, home, zone());
} else { } else {
Variable* temp = Variable* temp = NewTemporary(ast_value_factory()->empty_string());
scope()->NewTemporary(ast_value_factory()->empty_string());
VariableProxy* obj = factory()->NewVariableProxy(temp); VariableProxy* obj = factory()->NewVariableProxy(temp);
Assignment* assign_obj = factory()->NewAssignment( Assignment* assign_obj = factory()->NewAssignment(
Token::ASSIGN, obj, function->AsProperty()->obj(), Token::ASSIGN, obj, function->AsProperty()->obj(),
...@@ -5817,8 +5809,8 @@ Expression* ParserTraits::RewriteAwaitExpression(Expression* value, ...@@ -5817,8 +5809,8 @@ Expression* ParserTraits::RewriteAwaitExpression(Expression* value,
auto factory = parser_->factory(); auto factory = parser_->factory();
const int nopos = kNoSourcePosition; const int nopos = kNoSourcePosition;
Variable* temp_var = parser_->scope()->NewTemporary( Variable* temp_var =
parser_->ast_value_factory()->empty_string()); parser_->NewTemporary(parser_->ast_value_factory()->empty_string());
VariableProxy* temp_proxy = factory->NewVariableProxy(temp_var); VariableProxy* temp_proxy = factory->NewVariableProxy(temp_var);
Block* do_block = factory->NewBlock(nullptr, 2, false, nopos); Block* do_block = factory->NewBlock(nullptr, 2, false, nopos);
...@@ -5957,8 +5949,8 @@ Expression* Parser::RewriteAssignExponentiation(Expression* left, ...@@ -5957,8 +5949,8 @@ Expression* Parser::RewriteAssignExponentiation(Expression* left,
return factory()->NewAssignment(Token::ASSIGN, result, call, pos); return factory()->NewAssignment(Token::ASSIGN, result, call, pos);
} else if (left->IsProperty()) { } else if (left->IsProperty()) {
Property* prop = left->AsProperty(); Property* prop = left->AsProperty();
auto temp_obj = scope()->NewTemporary(ast_value_factory()->empty_string()); auto temp_obj = NewTemporary(ast_value_factory()->empty_string());
auto temp_key = scope()->NewTemporary(ast_value_factory()->empty_string()); auto temp_key = NewTemporary(ast_value_factory()->empty_string());
Expression* assign_obj = factory()->NewAssignment( Expression* assign_obj = factory()->NewAssignment(
Token::ASSIGN, factory()->NewVariableProxy(temp_obj), prop->obj(), Token::ASSIGN, factory()->NewVariableProxy(temp_obj), prop->obj(),
kNoSourcePosition); kNoSourcePosition);
...@@ -6001,8 +5993,7 @@ Expression* Parser::RewriteSpreads(ArrayLiteral* lit) { ...@@ -6001,8 +5993,7 @@ Expression* Parser::RewriteSpreads(ArrayLiteral* lit) {
// where $R, $i and $j are fresh temporary variables. // where $R, $i and $j are fresh temporary variables.
ZoneList<Expression*>::iterator s = lit->FirstSpread(); ZoneList<Expression*>::iterator s = lit->FirstSpread();
if (s == lit->EndValue()) return nullptr; // no spread, no rewriting... if (s == lit->EndValue()) return nullptr; // no spread, no rewriting...
Variable* result = Variable* result = NewTemporary(ast_value_factory()->dot_result_string());
scope()->NewTemporary(ast_value_factory()->dot_result_string());
// NOTE: The value assigned to R is the whole original array literal, // NOTE: The value assigned to R is the whole original array literal,
// spreads included. This will be fixed before the rewritten AST is returned. // spreads included. This will be fixed before the rewritten AST is returned.
// $R = lit // $R = lit
...@@ -6030,8 +6021,7 @@ Expression* Parser::RewriteSpreads(ArrayLiteral* lit) { ...@@ -6030,8 +6021,7 @@ Expression* Parser::RewriteSpreads(ArrayLiteral* lit) {
zone()); zone());
} else { } else {
// If it's a spread, we're adding a for/of loop iterating through it. // If it's a spread, we're adding a for/of loop iterating through it.
Variable* each = Variable* each = NewTemporary(ast_value_factory()->dot_for_string());
scope()->NewTemporary(ast_value_factory()->dot_for_string());
Expression* subject = spread->expression(); Expression* subject = spread->expression();
// %AppendElement($R, each) // %AppendElement($R, each)
Statement* append_body; Statement* append_body;
...@@ -6216,7 +6206,6 @@ Expression* ParserTraits::RewriteYieldStar( ...@@ -6216,7 +6206,6 @@ Expression* ParserTraits::RewriteYieldStar(
auto factory = parser_->factory(); auto factory = parser_->factory();
auto avfactory = parser_->ast_value_factory(); auto avfactory = parser_->ast_value_factory();
auto scope = parser_->scope();
auto zone = parser_->zone(); auto zone = parser_->zone();
...@@ -6225,7 +6214,7 @@ Expression* ParserTraits::RewriteYieldStar( ...@@ -6225,7 +6214,7 @@ Expression* ParserTraits::RewriteYieldStar(
// let input = undefined; // let input = undefined;
Variable* var_input = scope->NewTemporary(avfactory->empty_string()); Variable* var_input = parser_->NewTemporary(avfactory->empty_string());
Statement* initialize_input; Statement* initialize_input;
{ {
Expression* input_proxy = factory->NewVariableProxy(var_input); Expression* input_proxy = factory->NewVariableProxy(var_input);
...@@ -6236,7 +6225,7 @@ Expression* ParserTraits::RewriteYieldStar( ...@@ -6236,7 +6225,7 @@ Expression* ParserTraits::RewriteYieldStar(
// let mode = kNext; // let mode = kNext;
Variable* var_mode = scope->NewTemporary(avfactory->empty_string()); Variable* var_mode = parser_->NewTemporary(avfactory->empty_string());
Statement* initialize_mode; Statement* initialize_mode;
{ {
Expression* mode_proxy = factory->NewVariableProxy(var_mode); Expression* mode_proxy = factory->NewVariableProxy(var_mode);
...@@ -6248,7 +6237,7 @@ Expression* ParserTraits::RewriteYieldStar( ...@@ -6248,7 +6237,7 @@ Expression* ParserTraits::RewriteYieldStar(
// let output = undefined; // let output = undefined;
Variable* var_output = scope->NewTemporary(avfactory->empty_string()); Variable* var_output = parser_->NewTemporary(avfactory->empty_string());
Statement* initialize_output; Statement* initialize_output;
{ {
Expression* output_proxy = factory->NewVariableProxy(var_output); Expression* output_proxy = factory->NewVariableProxy(var_output);
...@@ -6260,7 +6249,7 @@ Expression* ParserTraits::RewriteYieldStar( ...@@ -6260,7 +6249,7 @@ Expression* ParserTraits::RewriteYieldStar(
// let iterator = iterable[Symbol.iterator]; // let iterator = iterable[Symbol.iterator];
Variable* var_iterator = scope->NewTemporary(avfactory->empty_string()); Variable* var_iterator = parser_->NewTemporary(avfactory->empty_string());
Statement* get_iterator; Statement* get_iterator;
{ {
Expression* iterator = GetIterator(iterable, factory, nopos); Expression* iterator = GetIterator(iterable, factory, nopos);
...@@ -6340,7 +6329,7 @@ Expression* ParserTraits::RewriteYieldStar( ...@@ -6340,7 +6329,7 @@ Expression* ParserTraits::RewriteYieldStar(
// let iteratorThrow = iterator.throw; // let iteratorThrow = iterator.throw;
Variable* var_throw = scope->NewTemporary(avfactory->empty_string()); Variable* var_throw = parser_->NewTemporary(avfactory->empty_string());
Statement* get_throw; Statement* get_throw;
{ {
Expression* iterator_proxy = factory->NewVariableProxy(var_iterator); Expression* iterator_proxy = factory->NewVariableProxy(var_iterator);
...@@ -6535,7 +6524,7 @@ Expression* ParserTraits::RewriteYieldStar( ...@@ -6535,7 +6524,7 @@ Expression* ParserTraits::RewriteYieldStar(
Block* catch_block = factory->NewBlock(nullptr, 1, false, nopos); Block* catch_block = factory->NewBlock(nullptr, 1, false, nopos);
catch_block->statements()->Add(set_mode_throw, zone); catch_block->statements()->Add(set_mode_throw, zone);
Scope* catch_scope = NewScopeWithParent(scope, CATCH_SCOPE); Scope* catch_scope = NewScope(CATCH_SCOPE);
catch_scope->set_is_hidden(); catch_scope->set_is_hidden();
const AstRawString* name = avfactory->dot_catch_string(); const AstRawString* name = avfactory->dot_catch_string();
Variable* catch_variable = Variable* catch_variable =
...@@ -6627,9 +6616,11 @@ Expression* ParserTraits::RewriteYieldStar( ...@@ -6627,9 +6616,11 @@ Expression* ParserTraits::RewriteYieldStar(
do_block->statements()->Add(do_block_, zone); do_block->statements()->Add(do_block_, zone);
do_block->statements()->Add(get_value, zone); do_block->statements()->Add(get_value, zone);
Variable* dot_result = scope->NewTemporary(avfactory->dot_result_string()); Variable* dot_result =
parser_->NewTemporary(avfactory->dot_result_string());
yield_star = factory->NewDoExpression(do_block, dot_result, nopos); yield_star = factory->NewDoExpression(do_block, dot_result, nopos);
Rewriter::Rewrite(parser_, scope->GetClosureScope(), yield_star, avfactory); Rewriter::Rewrite(parser_, parser_->GetClosureScope(), yield_star,
avfactory);
} }
return yield_star; return yield_star;
...@@ -6900,12 +6891,11 @@ void ParserTraits::BuildIteratorCloseForCompletion( ...@@ -6900,12 +6891,11 @@ void ParserTraits::BuildIteratorCloseForCompletion(
const int nopos = kNoSourcePosition; const int nopos = kNoSourcePosition;
auto factory = parser_->factory(); auto factory = parser_->factory();
auto avfactory = parser_->ast_value_factory(); auto avfactory = parser_->ast_value_factory();
auto scope = parser_->scope();
auto zone = parser_->zone(); auto zone = parser_->zone();
// let iteratorReturn = iterator.return; // let iteratorReturn = iterator.return;
Variable* var_return = scope->NewTemporary(avfactory->empty_string()); Variable* var_return = parser_->NewTemporary(avfactory->empty_string());
Statement* get_return; Statement* get_return;
{ {
Expression* iterator_proxy = factory->NewVariableProxy(iterator); Expression* iterator_proxy = factory->NewVariableProxy(iterator);
...@@ -6946,7 +6936,7 @@ void ParserTraits::BuildIteratorCloseForCompletion( ...@@ -6946,7 +6936,7 @@ void ParserTraits::BuildIteratorCloseForCompletion(
Block* catch_block = factory->NewBlock(nullptr, 0, false, nopos); Block* catch_block = factory->NewBlock(nullptr, 0, false, nopos);
Scope* catch_scope = NewScopeWithParent(scope, CATCH_SCOPE); Scope* catch_scope = NewScope(CATCH_SCOPE);
Variable* catch_variable = catch_scope->DeclareLocal( Variable* catch_variable = catch_scope->DeclareLocal(
avfactory->dot_catch_string(), VAR, kCreatedInitialized, avfactory->dot_catch_string(), VAR, kCreatedInitialized,
Variable::NORMAL); Variable::NORMAL);
...@@ -6962,7 +6952,7 @@ void ParserTraits::BuildIteratorCloseForCompletion( ...@@ -6962,7 +6952,7 @@ void ParserTraits::BuildIteratorCloseForCompletion(
// } // }
Block* validate_return; Block* validate_return;
{ {
Variable* var_output = scope->NewTemporary(avfactory->empty_string()); Variable* var_output = parser_->NewTemporary(avfactory->empty_string());
Statement* call_return; Statement* call_return;
{ {
auto args = new (zone) ZoneList<Expression*>(2, zone); auto args = new (zone) ZoneList<Expression*>(2, zone);
......
...@@ -776,6 +776,9 @@ class Parser : public ParserBase<ParserTraits> { ...@@ -776,6 +776,9 @@ class Parser : public ParserBase<ParserTraits> {
DeclarationScope* GetClosureScope() const { DeclarationScope* GetClosureScope() const {
return scope()->GetClosureScope(); return scope()->GetClosureScope();
} }
Variable* NewTemporary(const AstRawString* name) {
return scope()->NewTemporary(name);
}
// Limit the allowed number of local variables in a function. The hard limit // Limit the allowed number of local variables in a function. The hard limit
// is that offsets computed by FullCodeGenerator::StackOperand and similar // is that offsets computed by FullCodeGenerator::StackOperand and similar
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment