Chromium Code Reviews| Index: src/parsing/parser.cc |
| diff --git a/src/parsing/parser.cc b/src/parsing/parser.cc |
| index f6a0131707310c89d319e9b0e24f1849b9005ba5..5b1d45ac4d1f1d7dac4ea9d1ebcc1a670ada9b01 100644 |
| --- a/src/parsing/parser.cc |
| +++ b/src/parsing/parser.cc |
| @@ -2290,13 +2290,12 @@ Block* Parser::ParseBlock(ZoneList<const AstRawString*>* labels, bool* ok) { |
| // Construct block expecting 16 statements. |
| Block* body = factory()->NewBlock(labels, 16, false, kNoSourcePosition); |
| - Scope* block_scope = NewScope(BLOCK_SCOPE); |
| // Parse the statements and collect escaping labels. |
| Expect(Token::LBRACE, CHECK_OK); |
| - block_scope->set_start_position(scanner()->location().beg_pos); |
| { |
| - BlockState block_state(&scope_state_, block_scope); |
| + BlockState block_state(&scope_state_); |
| + block_state.set_start_position(scanner()->location().beg_pos); |
| Target target(&this->target_stack_, body); |
| while (peek() != Token::RBRACE) { |
| @@ -2305,11 +2304,11 @@ Block* Parser::ParseBlock(ZoneList<const AstRawString*>* labels, bool* ok) { |
| body->statements()->Add(stat, zone()); |
| } |
| } |
| + |
| + Expect(Token::RBRACE, CHECK_OK); |
| + block_state.set_end_position(scanner()->location().end_pos); |
| + body->set_scope(block_state.FinalizedBlockScope()); |
|
adamk
2016/07/21 17:48:05
Calling FinalizeBlockScope while still inside the
marja
2016/07/22 07:17:00
(I like this version because it has the set_scope
|
| } |
| - Expect(Token::RBRACE, CHECK_OK); |
| - block_scope->set_end_position(scanner()->location().end_pos); |
| - block_scope = block_scope->FinalizeBlockScope(); |
| - body->set_scope(block_scope); |
| return body; |
| } |
| @@ -2907,15 +2906,14 @@ Statement* Parser::ParseSwitchStatement(ZoneList<const AstRawString*>* labels, |
| zone()); |
| Block* cases_block = factory()->NewBlock(NULL, 1, false, kNoSourcePosition); |
| - Scope* cases_scope = NewScope(BLOCK_SCOPE); |
| - cases_scope->SetNonlinear(); |
| SwitchStatement* switch_statement = |
| factory()->NewSwitchStatement(labels, switch_pos); |
| - cases_scope->set_start_position(scanner()->location().beg_pos); |
| { |
| - BlockState cases_block_state(&scope_state_, cases_scope); |
| + BlockState cases_block_state(&scope_state_); |
| + cases_block_state.set_start_position(scanner()->location().beg_pos); |
| + cases_block_state.SetNonlinear(); |
| Target target(&this->target_stack_, switch_statement); |
| Expression* tag_read = factory()->NewVariableProxy(tag_variable); |
| @@ -2930,12 +2928,11 @@ Statement* Parser::ParseSwitchStatement(ZoneList<const AstRawString*>* labels, |
| } |
| switch_statement->Initialize(tag_read, cases); |
| cases_block->statements()->Add(switch_statement, zone()); |
| - } |
| - Expect(Token::RBRACE, CHECK_OK); |
| + Expect(Token::RBRACE, CHECK_OK); |
| - cases_scope->set_end_position(scanner()->location().end_pos); |
| - cases_scope = cases_scope->FinalizeBlockScope(); |
| - cases_block->set_scope(cases_scope); |
| + cases_block_state.set_end_position(scanner()->location().end_pos); |
| + cases_block->set_scope(cases_block_state.FinalizedBlockScope()); |
| + } |
| switch_block->statements()->Add(cases_block, zone()); |
| @@ -3012,10 +3009,9 @@ TryStatement* Parser::ParseTryStatement(bool* ok) { |
| // Create a block scope to hold any lexical declarations created |
| // as part of destructuring the catch parameter. |
| - Scope* block_scope = NewScope(BLOCK_SCOPE); |
| - block_scope->set_start_position(scanner()->location().beg_pos); |
| { |
| - BlockState block_state(&scope_state_, block_scope); |
| + BlockState block_state(&scope_state_); |
| + block_state.set_start_position(scanner()->location().beg_pos); |
| Target target(&this->target_stack_, catch_block); |
| const AstRawString* name = ast_value_factory()->dot_catch_string(); |
| @@ -3081,10 +3077,9 @@ TryStatement* Parser::ParseTryStatement(bool* ok) { |
| return nullptr; |
| } |
| } |
| + block_state.set_end_position(scanner()->location().end_pos); |
| + catch_block->set_scope(block_state.FinalizedBlockScope()); |
| } |
| - block_scope->set_end_position(scanner()->location().end_pos); |
| - block_scope = block_scope->FinalizeBlockScope(); |
| - catch_block->set_scope(block_scope); |
| } |
| catch_scope->set_end_position(scanner()->location().end_pos); |
| @@ -3639,15 +3634,13 @@ Statement* Parser::ParseScopedStatement(ZoneList<const AstRawString*>* labels, |
| } |
| // Make a block around the statement for a lexical binding |
| // is introduced by a FunctionDeclaration. |
| - Scope* body_scope = NewScope(BLOCK_SCOPE); |
| - body_scope->set_start_position(scanner()->location().beg_pos); |
| - BlockState block_state(&scope_state_, body_scope); |
| + BlockState block_state(&scope_state_); |
| + block_state.set_start_position(scanner()->location().beg_pos); |
| Block* block = factory()->NewBlock(NULL, 1, false, kNoSourcePosition); |
| Statement* body = ParseFunctionDeclaration(CHECK_OK); |
| block->statements()->Add(body, zone()); |
| - body_scope->set_end_position(scanner()->location().end_pos); |
| - body_scope = body_scope->FinalizeBlockScope(); |
| - block->set_scope(body_scope); |
| + block_state.set_end_position(scanner()->location().end_pos); |
| + block->set_scope(block_state.FinalizedBlockScope()); |
| return block; |
| } |
| } |
| @@ -3660,13 +3653,11 @@ Statement* Parser::ParseForStatement(ZoneList<const AstRawString*>* labels, |
| bool bound_names_are_lexical = false; |
| // Create an in-between scope for let-bound iteration variables. |
| - Scope* for_scope = NewScope(BLOCK_SCOPE); |
| - |
| - BlockState block_state(&scope_state_, for_scope); |
| + BlockState for_state(&scope_state_); |
| Expect(Token::FOR, CHECK_OK); |
| Expect(Token::LPAREN, CHECK_OK); |
| - for_scope->set_start_position(scanner()->location().beg_pos); |
| - for_scope->set_is_hidden(); |
| + for_state.set_start_position(scanner()->location().beg_pos); |
| + for_state.set_is_hidden(); |
| DeclarationParsingResult parsing_result; |
| if (peek() != Token::SEMICOLON) { |
| if (peek() == Token::VAR || peek() == Token::CONST || |
| @@ -3765,8 +3756,6 @@ Statement* Parser::ParseForStatement(ZoneList<const AstRawString*>* labels, |
| Expect(Token::RPAREN, CHECK_OK); |
| - Scope* body_scope = NewScope(BLOCK_SCOPE); |
| - body_scope->set_start_position(scanner()->location().beg_pos); |
| Block* body_block = |
| factory()->NewBlock(NULL, 3, false, kNoSourcePosition); |
| @@ -3775,7 +3764,8 @@ Statement* Parser::ParseForStatement(ZoneList<const AstRawString*>* labels, |
| { |
| ReturnExprScope no_tail_calls(function_state_, |
| ReturnExprContext::kInsideForInOfBody); |
| - BlockState block_state(&scope_state_, body_scope); |
| + BlockState block_state(&scope_state_); |
| + block_state.set_start_position(scanner()->location().beg_pos); |
| Statement* body = ParseScopedStatement(NULL, true, CHECK_OK); |
| @@ -3833,10 +3823,9 @@ Statement* Parser::ParseForStatement(ZoneList<const AstRawString*>* labels, |
| factory()->NewVariableProxy(temp, each_beg_pos, each_end_pos); |
| final_loop = InitializeForEachStatement( |
| loop, temp_proxy, enumerable, body_block, each_keyword_position); |
| + block_state.set_end_position(scanner()->location().end_pos); |
| + body_block->set_scope(block_state.FinalizedBlockScope()); |
| } |
| - body_scope->set_end_position(scanner()->location().end_pos); |
| - body_scope = body_scope->FinalizeBlockScope(); |
| - body_block->set_scope(body_scope); |
| // Create a TDZ for any lexically-bound names. |
| if (bound_names_are_lexical) { |
| @@ -3858,8 +3847,8 @@ Statement* Parser::ParseForStatement(ZoneList<const AstRawString*>* labels, |
| } |
| } |
| - for_scope->set_end_position(scanner()->location().end_pos); |
| - for_scope = for_scope->FinalizeBlockScope(); |
| + for_state.set_end_position(scanner()->location().end_pos); |
| + Scope* for_scope = for_state.FinalizedBlockScope(); |
| // Parsed for-in loop w/ variable declarations. |
| if (init_block != nullptr) { |
| init_block->statements()->Add(final_loop, zone()); |
| @@ -3922,9 +3911,7 @@ Statement* Parser::ParseForStatement(ZoneList<const AstRawString*>* labels, |
| Statement* final_loop = InitializeForEachStatement( |
| loop, expression, enumerable, body, each_keyword_position); |
| - for_scope->set_end_position(scanner()->location().end_pos); |
| - for_scope = for_scope->FinalizeBlockScope(); |
| - DCHECK(for_scope == nullptr); |
| + DCHECK_NULL(for_state.FinalizedBlockScope()); |
| return final_loop; |
| } else { |
| @@ -3947,8 +3934,9 @@ Statement* Parser::ParseForStatement(ZoneList<const AstRawString*>* labels, |
| // If there are let bindings, then condition and the next statement of the |
| // for loop must be parsed in a new scope. |
| Scope* inner_scope = scope(); |
| + // TODO(verwaest): Allocate this through a ScopeState as well. |
| if (bound_names_are_lexical && bound_names.length() > 0) { |
| - inner_scope = NewScopeWithParent(for_scope, BLOCK_SCOPE); |
| + inner_scope = NewScopeWithParent(inner_scope, BLOCK_SCOPE); |
| inner_scope->set_start_position(scanner()->location().beg_pos); |
| } |
| { |
| @@ -3970,14 +3958,13 @@ Statement* Parser::ParseForStatement(ZoneList<const AstRawString*>* labels, |
| Statement* result = NULL; |
| if (bound_names_are_lexical && bound_names.length() > 0) { |
| - BlockState block_state(&scope_state_, for_scope); |
| result = DesugarLexicalBindingsInForStatement( |
| inner_scope, parsing_result.descriptor.mode, &bound_names, loop, init, |
| cond, next, body, CHECK_OK); |
| - for_scope->set_end_position(scanner()->location().end_pos); |
| + for_state.set_end_position(scanner()->location().end_pos); |
| } else { |
| - for_scope->set_end_position(scanner()->location().end_pos); |
| - for_scope = for_scope->FinalizeBlockScope(); |
| + for_state.set_end_position(scanner()->location().end_pos); |
| + Scope* for_scope = for_state.FinalizedBlockScope(); |
| if (for_scope) { |
| // Rewrite a for statement of the form |
| // for (const x = i; c; n) b |
| @@ -4995,30 +4982,30 @@ ClassLiteral* Parser::ParseClassLiteral(ExpressionClassifier* classifier, |
| ReportMessageAt(class_name_location, |
| MessageTemplate::kUnexpectedStrictReserved); |
| *ok = false; |
| - return NULL; |
| + return nullptr; |
| } |
| if (IsEvalOrArguments(name)) { |
| ReportMessageAt(class_name_location, MessageTemplate::kStrictEvalArguments); |
| *ok = false; |
| - return NULL; |
| + return nullptr; |
| } |
| - Scope* block_scope = NewScope(BLOCK_SCOPE); |
| - BlockState block_state(&scope_state_, block_scope); |
| + BlockState block_state(&scope_state_); |
| RaiseLanguageMode(STRICT); |
| scope()->SetScopeName(name); |
| - VariableProxy* proxy = NULL; |
| - if (name != NULL) { |
| + VariableProxy* proxy = nullptr; |
| + if (name != nullptr) { |
| proxy = NewUnresolved(name, CONST); |
| - Declaration* declaration = |
| - factory()->NewVariableDeclaration(proxy, CONST, block_scope, pos); |
| + // TODO(verwaest): declare via block_state. |
| + Declaration* declaration = factory()->NewVariableDeclaration( |
| + proxy, CONST, block_state.scope(), pos); |
| Declare(declaration, DeclarationDescriptor::NORMAL, true, CHECK_OK); |
| } |
| - Expression* extends = NULL; |
| + Expression* extends = nullptr; |
| if (Check(Token::EXTENDS)) { |
| - block_scope->set_start_position(scanner()->location().end_pos); |
| + block_state.set_start_position(scanner()->location().end_pos); |
| ExpressionClassifier extends_classifier(this); |
| extends = ParseLeftHandSideExpression(&extends_classifier, CHECK_OK); |
| CheckNoTailCallExpressions(&extends_classifier, CHECK_OK); |
| @@ -5028,13 +5015,13 @@ ClassLiteral* Parser::ParseClassLiteral(ExpressionClassifier* classifier, |
| ExpressionClassifier::ExpressionProductions); |
| } |
| } else { |
| - block_scope->set_start_position(scanner()->location().end_pos); |
| + block_state.set_start_position(scanner()->location().end_pos); |
| } |
| ClassLiteralChecker checker(this); |
| ZoneList<ObjectLiteral::Property*>* properties = NewPropertyList(4, zone()); |
| - FunctionLiteral* constructor = NULL; |
| + FunctionLiteral* constructor = nullptr; |
| bool has_seen_constructor = false; |
| Expect(Token::LBRACE, CHECK_OK); |
| @@ -5057,7 +5044,7 @@ ClassLiteral* Parser::ParseClassLiteral(ExpressionClassifier* classifier, |
| ExpressionClassifier::ExpressionProductions); |
| } |
| - if (has_seen_constructor && constructor == NULL) { |
| + if (has_seen_constructor && constructor == nullptr) { |
| constructor = GetPropertyValue(property)->AsFunctionLiteral(); |
| DCHECK_NOT_NULL(constructor); |
| constructor->set_raw_name( |
| @@ -5066,7 +5053,7 @@ ClassLiteral* Parser::ParseClassLiteral(ExpressionClassifier* classifier, |
| properties->Add(property, zone()); |
| } |
| - if (fni_ != NULL) fni_->Infer(); |
| + if (fni_ != nullptr) fni_->Infer(); |
| if (property_name != ast_value_factory()->constructor_string()) { |
| SetFunctionNameFromPropertyName(property, property_name); |
| @@ -5076,21 +5063,22 @@ ClassLiteral* Parser::ParseClassLiteral(ExpressionClassifier* classifier, |
| Expect(Token::RBRACE, CHECK_OK); |
| int end_pos = scanner()->location().end_pos; |
| - if (constructor == NULL) { |
| - DCHECK_EQ(this->scope(), block_scope); |
| + if (constructor == nullptr) { |
| constructor = DefaultConstructor(name, has_extends, pos, end_pos, |
| - block_scope->language_mode()); |
| + block_state.language_mode()); |
| } |
| // Note that we do not finalize this block scope because it is |
| // used as a sentinel value indicating an anonymous class. |
| - block_scope->set_end_position(end_pos); |
| + block_state.set_end_position(end_pos); |
| - if (name != NULL) { |
| + if (name != nullptr) { |
| DCHECK_NOT_NULL(proxy); |
| proxy->var()->set_initializer_position(end_pos); |
| } |
| + // TODO(verwaest): Use FinalizedBlockScope() once supported. |
| + Scope* block_scope = block_state.scope(); |
| return factory()->NewClassLiteral(block_scope, proxy, extends, constructor, |
| properties, pos, end_pos); |
| } |