| OLD | NEW |
| 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 2264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2275 Declare(declaration, DeclarationDescriptor::NORMAL, true, CHECK_OK); | 2275 Declare(declaration, DeclarationDescriptor::NORMAL, true, CHECK_OK); |
| 2276 proxy->var()->set_initializer_position(position()); | 2276 proxy->var()->set_initializer_position(position()); |
| 2277 Assignment* assignment = | 2277 Assignment* assignment = |
| 2278 factory()->NewAssignment(Token::INIT, proxy, value, pos); | 2278 factory()->NewAssignment(Token::INIT, proxy, value, pos); |
| 2279 Statement* assignment_statement = | 2279 Statement* assignment_statement = |
| 2280 factory()->NewExpressionStatement(assignment, kNoSourcePosition); | 2280 factory()->NewExpressionStatement(assignment, kNoSourcePosition); |
| 2281 if (names) names->Add(variable_name, zone()); | 2281 if (names) names->Add(variable_name, zone()); |
| 2282 return assignment_statement; | 2282 return assignment_statement; |
| 2283 } | 2283 } |
| 2284 | 2284 |
| 2285 | 2285 Block* Parser::ParseBlock(ZoneList<const AstRawString*>* labels, bool* ok) { |
| 2286 Block* Parser::ParseBlock(ZoneList<const AstRawString*>* labels, | |
| 2287 bool finalize_block_scope, bool* ok) { | |
| 2288 // The harmony mode uses block elements instead of statements. | 2286 // The harmony mode uses block elements instead of statements. |
| 2289 // | 2287 // |
| 2290 // Block :: | 2288 // Block :: |
| 2291 // '{' StatementList '}' | 2289 // '{' StatementList '}' |
| 2292 | 2290 |
| 2293 // Construct block expecting 16 statements. | 2291 // Construct block expecting 16 statements. |
| 2294 Block* body = factory()->NewBlock(labels, 16, false, kNoSourcePosition); | 2292 Block* body = factory()->NewBlock(labels, 16, false, kNoSourcePosition); |
| 2295 Scope* block_scope = NewScope(BLOCK_SCOPE); | 2293 Scope* block_scope = NewScope(BLOCK_SCOPE); |
| 2296 | 2294 |
| 2297 // Parse the statements and collect escaping labels. | 2295 // Parse the statements and collect escaping labels. |
| 2298 Expect(Token::LBRACE, CHECK_OK); | 2296 Expect(Token::LBRACE, CHECK_OK); |
| 2299 block_scope->set_start_position(scanner()->location().beg_pos); | 2297 block_scope->set_start_position(scanner()->location().beg_pos); |
| 2300 { | 2298 { |
| 2301 BlockState block_state(&scope_state_, block_scope); | 2299 BlockState block_state(&scope_state_, block_scope); |
| 2302 Target target(&this->target_stack_, body); | 2300 Target target(&this->target_stack_, body); |
| 2303 | 2301 |
| 2304 while (peek() != Token::RBRACE) { | 2302 while (peek() != Token::RBRACE) { |
| 2305 Statement* stat = ParseStatementListItem(CHECK_OK); | 2303 Statement* stat = ParseStatementListItem(CHECK_OK); |
| 2306 if (stat && !stat->IsEmpty()) { | 2304 if (stat && !stat->IsEmpty()) { |
| 2307 body->statements()->Add(stat, zone()); | 2305 body->statements()->Add(stat, zone()); |
| 2308 } | 2306 } |
| 2309 } | 2307 } |
| 2310 } | 2308 } |
| 2311 Expect(Token::RBRACE, CHECK_OK); | 2309 Expect(Token::RBRACE, CHECK_OK); |
| 2312 block_scope->set_end_position(scanner()->location().end_pos); | 2310 block_scope->set_end_position(scanner()->location().end_pos); |
| 2313 if (finalize_block_scope) { | 2311 block_scope = block_scope->FinalizeBlockScope(); |
| 2314 block_scope = block_scope->FinalizeBlockScope(); | |
| 2315 } | |
| 2316 body->set_scope(block_scope); | 2312 body->set_scope(block_scope); |
| 2317 return body; | 2313 return body; |
| 2318 } | 2314 } |
| 2319 | 2315 |
| 2320 | 2316 |
| 2321 Block* Parser::ParseBlock(ZoneList<const AstRawString*>* labels, bool* ok) { | |
| 2322 return ParseBlock(labels, true, ok); | |
| 2323 } | |
| 2324 | |
| 2325 | |
| 2326 Block* Parser::DeclarationParsingResult::BuildInitializationBlock( | 2317 Block* Parser::DeclarationParsingResult::BuildInitializationBlock( |
| 2327 ZoneList<const AstRawString*>* names, bool* ok) { | 2318 ZoneList<const AstRawString*>* names, bool* ok) { |
| 2328 Block* result = descriptor.parser->factory()->NewBlock( | 2319 Block* result = descriptor.parser->factory()->NewBlock( |
| 2329 NULL, 1, true, descriptor.declaration_pos); | 2320 NULL, 1, true, descriptor.declaration_pos); |
| 2330 for (auto declaration : declarations) { | 2321 for (auto declaration : declarations) { |
| 2331 PatternRewriter::DeclareAndInitializeVariables( | 2322 PatternRewriter::DeclareAndInitializeVariables( |
| 2332 result, &descriptor, &declaration, names, CHECK_OK); | 2323 result, &descriptor, &declaration, names, CHECK_OK); |
| 2333 } | 2324 } |
| 2334 return result; | 2325 return result; |
| 2335 } | 2326 } |
| (...skipping 1864 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4200 } | 4191 } |
| 4201 | 4192 |
| 4202 DoExpression* Parser::ParseDoExpression(bool* ok) { | 4193 DoExpression* Parser::ParseDoExpression(bool* ok) { |
| 4203 // AssignmentExpression :: | 4194 // AssignmentExpression :: |
| 4204 // do '{' StatementList '}' | 4195 // do '{' StatementList '}' |
| 4205 int pos = peek_position(); | 4196 int pos = peek_position(); |
| 4206 | 4197 |
| 4207 Expect(Token::DO, CHECK_OK); | 4198 Expect(Token::DO, CHECK_OK); |
| 4208 Variable* result = | 4199 Variable* result = |
| 4209 scope()->NewTemporary(ast_value_factory()->dot_result_string()); | 4200 scope()->NewTemporary(ast_value_factory()->dot_result_string()); |
| 4210 Block* block = ParseBlock(nullptr, false, CHECK_OK); | 4201 Block* block = ParseBlock(nullptr, CHECK_OK); |
| 4211 DoExpression* expr = factory()->NewDoExpression(block, result, pos); | 4202 DoExpression* expr = factory()->NewDoExpression(block, result, pos); |
| 4212 if (!Rewriter::Rewrite(this, expr, ast_value_factory())) { | 4203 if (!Rewriter::Rewrite(this, scope(), expr, ast_value_factory())) { |
| 4213 *ok = false; | 4204 *ok = false; |
| 4214 return nullptr; | 4205 return nullptr; |
| 4215 } | 4206 } |
| 4216 block->set_scope(block->scope()->FinalizeBlockScope()); | |
| 4217 return expr; | 4207 return expr; |
| 4218 } | 4208 } |
| 4219 | 4209 |
| 4220 | 4210 |
| 4221 void ParserTraits::ParseArrowFunctionFormalParameterList( | 4211 void ParserTraits::ParseArrowFunctionFormalParameterList( |
| 4222 ParserFormalParameters* parameters, Expression* expr, | 4212 ParserFormalParameters* parameters, Expression* expr, |
| 4223 const Scanner::Location& params_loc, | 4213 const Scanner::Location& params_loc, |
| 4224 Scanner::Location* duplicate_loc, bool* ok) { | 4214 Scanner::Location* duplicate_loc, bool* ok) { |
| 4225 if (expr->IsEmptyParentheses()) return; | 4215 if (expr->IsEmptyParentheses()) return; |
| 4226 | 4216 |
| (...skipping 2367 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6594 do_block_->statements()->Add(validate_iterator, zone); | 6584 do_block_->statements()->Add(validate_iterator, zone); |
| 6595 do_block_->statements()->Add(loop, zone); | 6585 do_block_->statements()->Add(loop, zone); |
| 6596 do_block_->statements()->Add(maybe_return_value, zone); | 6586 do_block_->statements()->Add(maybe_return_value, zone); |
| 6597 | 6587 |
| 6598 Block* do_block = factory->NewBlock(nullptr, 2, false, nopos); | 6588 Block* do_block = factory->NewBlock(nullptr, 2, false, nopos); |
| 6599 do_block->statements()->Add(do_block_, zone); | 6589 do_block->statements()->Add(do_block_, zone); |
| 6600 do_block->statements()->Add(get_value, zone); | 6590 do_block->statements()->Add(get_value, zone); |
| 6601 | 6591 |
| 6602 Variable* dot_result = scope->NewTemporary(avfactory->dot_result_string()); | 6592 Variable* dot_result = scope->NewTemporary(avfactory->dot_result_string()); |
| 6603 yield_star = factory->NewDoExpression(do_block, dot_result, nopos); | 6593 yield_star = factory->NewDoExpression(do_block, dot_result, nopos); |
| 6604 Rewriter::Rewrite(parser_, yield_star, avfactory); | 6594 Rewriter::Rewrite(parser_, scope, yield_star, avfactory); |
| 6605 } | 6595 } |
| 6606 | 6596 |
| 6607 return yield_star; | 6597 return yield_star; |
| 6608 } | 6598 } |
| 6609 | 6599 |
| 6610 Statement* ParserTraits::CheckCallable(Variable* var, Expression* error, | 6600 Statement* ParserTraits::CheckCallable(Variable* var, Expression* error, |
| 6611 int pos) { | 6601 int pos) { |
| 6612 auto factory = parser_->factory(); | 6602 auto factory = parser_->factory(); |
| 6613 auto avfactory = parser_->ast_value_factory(); | 6603 auto avfactory = parser_->ast_value_factory(); |
| 6614 const int nopos = kNoSourcePosition; | 6604 const int nopos = kNoSourcePosition; |
| (...skipping 456 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7071 node->Print(Isolate::Current()); | 7061 node->Print(Isolate::Current()); |
| 7072 } | 7062 } |
| 7073 #endif // DEBUG | 7063 #endif // DEBUG |
| 7074 | 7064 |
| 7075 #undef CHECK_OK | 7065 #undef CHECK_OK |
| 7076 #undef CHECK_OK_VOID | 7066 #undef CHECK_OK_VOID |
| 7077 #undef CHECK_FAILED | 7067 #undef CHECK_FAILED |
| 7078 | 7068 |
| 7079 } // namespace internal | 7069 } // namespace internal |
| 7080 } // namespace v8 | 7070 } // namespace v8 |
| OLD | NEW |