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-visitor.h" | 9 #include "src/ast/ast-expression-visitor.h" |
10 #include "src/ast/ast-literal-reindexer.h" | 10 #include "src/ast/ast-literal-reindexer.h" |
(...skipping 2178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2189 | 2189 |
2190 Assignment* assignment = | 2190 Assignment* assignment = |
2191 factory()->NewAssignment(Token::INIT, proxy, value, pos); | 2191 factory()->NewAssignment(Token::INIT, proxy, value, pos); |
2192 Statement* assignment_statement = | 2192 Statement* assignment_statement = |
2193 factory()->NewExpressionStatement(assignment, RelocInfo::kNoPosition); | 2193 factory()->NewExpressionStatement(assignment, RelocInfo::kNoPosition); |
2194 if (names) names->Add(name, zone()); | 2194 if (names) names->Add(name, zone()); |
2195 return assignment_statement; | 2195 return assignment_statement; |
2196 } | 2196 } |
2197 | 2197 |
2198 | 2198 |
2199 Block* Parser::ParseBlock(ZoneList<const AstRawString*>* labels, bool* ok) { | 2199 Block* Parser::ParseBlock(ZoneList<const AstRawString*>* labels, |
| 2200 bool finalize_block_scope, bool* ok) { |
2200 // The harmony mode uses block elements instead of statements. | 2201 // The harmony mode uses block elements instead of statements. |
2201 // | 2202 // |
2202 // Block :: | 2203 // Block :: |
2203 // '{' StatementList '}' | 2204 // '{' StatementList '}' |
2204 | 2205 |
2205 // Construct block expecting 16 statements. | 2206 // Construct block expecting 16 statements. |
2206 Block* body = | 2207 Block* body = |
2207 factory()->NewBlock(labels, 16, false, RelocInfo::kNoPosition); | 2208 factory()->NewBlock(labels, 16, false, RelocInfo::kNoPosition); |
2208 Scope* block_scope = NewScope(scope_, BLOCK_SCOPE); | 2209 Scope* block_scope = NewScope(scope_, BLOCK_SCOPE); |
2209 | 2210 |
2210 // Parse the statements and collect escaping labels. | 2211 // Parse the statements and collect escaping labels. |
2211 Expect(Token::LBRACE, CHECK_OK); | 2212 Expect(Token::LBRACE, CHECK_OK); |
2212 block_scope->set_start_position(scanner()->location().beg_pos); | 2213 block_scope->set_start_position(scanner()->location().beg_pos); |
2213 { BlockState block_state(&scope_, block_scope); | 2214 { BlockState block_state(&scope_, block_scope); |
2214 Target target(&this->target_stack_, body); | 2215 Target target(&this->target_stack_, body); |
2215 | 2216 |
2216 while (peek() != Token::RBRACE) { | 2217 while (peek() != Token::RBRACE) { |
2217 Statement* stat = ParseStatementListItem(CHECK_OK); | 2218 Statement* stat = ParseStatementListItem(CHECK_OK); |
2218 if (stat && !stat->IsEmpty()) { | 2219 if (stat && !stat->IsEmpty()) { |
2219 body->statements()->Add(stat, zone()); | 2220 body->statements()->Add(stat, zone()); |
2220 } | 2221 } |
2221 } | 2222 } |
2222 } | 2223 } |
2223 Expect(Token::RBRACE, CHECK_OK); | 2224 Expect(Token::RBRACE, CHECK_OK); |
2224 block_scope->set_end_position(scanner()->location().end_pos); | 2225 block_scope->set_end_position(scanner()->location().end_pos); |
2225 block_scope = block_scope->FinalizeBlockScope(); | 2226 if (finalize_block_scope) { |
| 2227 block_scope = block_scope->FinalizeBlockScope(); |
| 2228 } |
2226 body->set_scope(block_scope); | 2229 body->set_scope(block_scope); |
2227 return body; | 2230 return body; |
2228 } | 2231 } |
2229 | 2232 |
2230 | 2233 |
| 2234 Block* Parser::ParseBlock(ZoneList<const AstRawString*>* labels, bool* ok) { |
| 2235 return ParseBlock(labels, true, ok); |
| 2236 } |
| 2237 |
| 2238 |
2231 Block* Parser::DeclarationParsingResult::BuildInitializationBlock( | 2239 Block* Parser::DeclarationParsingResult::BuildInitializationBlock( |
2232 ZoneList<const AstRawString*>* names, bool* ok) { | 2240 ZoneList<const AstRawString*>* names, bool* ok) { |
2233 Block* result = descriptor.parser->factory()->NewBlock( | 2241 Block* result = descriptor.parser->factory()->NewBlock( |
2234 NULL, 1, true, descriptor.declaration_pos); | 2242 NULL, 1, true, descriptor.declaration_pos); |
2235 for (auto declaration : declarations) { | 2243 for (auto declaration : declarations) { |
2236 PatternRewriter::DeclareAndInitializeVariables( | 2244 PatternRewriter::DeclareAndInitializeVariables( |
2237 result, &descriptor, &declaration, names, CHECK_OK); | 2245 result, &descriptor, &declaration, names, CHECK_OK); |
2238 } | 2246 } |
2239 return result; | 2247 return result; |
2240 } | 2248 } |
(...skipping 1744 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3985 | 3993 |
3986 | 3994 |
3987 DoExpression* Parser::ParseDoExpression(bool* ok) { | 3995 DoExpression* Parser::ParseDoExpression(bool* ok) { |
3988 // AssignmentExpression :: | 3996 // AssignmentExpression :: |
3989 // do '{' StatementList '}' | 3997 // do '{' StatementList '}' |
3990 int pos = peek_position(); | 3998 int pos = peek_position(); |
3991 | 3999 |
3992 Expect(Token::DO, CHECK_OK); | 4000 Expect(Token::DO, CHECK_OK); |
3993 Variable* result = | 4001 Variable* result = |
3994 scope_->NewTemporary(ast_value_factory()->dot_result_string()); | 4002 scope_->NewTemporary(ast_value_factory()->dot_result_string()); |
3995 Block* block = ParseBlock(nullptr, CHECK_OK); | 4003 Block* block = ParseBlock(nullptr, false, CHECK_OK); |
3996 DoExpression* expr = factory()->NewDoExpression(block, result, pos); | 4004 DoExpression* expr = factory()->NewDoExpression(block, result, pos); |
3997 if (!Rewriter::Rewrite(this, expr, ast_value_factory())) { | 4005 if (!Rewriter::Rewrite(this, expr, ast_value_factory())) { |
3998 *ok = false; | 4006 *ok = false; |
3999 return nullptr; | 4007 return nullptr; |
4000 } | 4008 } |
| 4009 block->set_scope(block->scope()->FinalizeBlockScope()); |
4001 return expr; | 4010 return expr; |
4002 } | 4011 } |
4003 | 4012 |
4004 | 4013 |
4005 void ParserTraits::ParseArrowFunctionFormalParameterList( | 4014 void ParserTraits::ParseArrowFunctionFormalParameterList( |
4006 ParserFormalParameters* parameters, Expression* expr, | 4015 ParserFormalParameters* parameters, Expression* expr, |
4007 const Scanner::Location& params_loc, | 4016 const Scanner::Location& params_loc, |
4008 Scanner::Location* duplicate_loc, bool* ok) { | 4017 Scanner::Location* duplicate_loc, bool* ok) { |
4009 if (expr->IsEmptyParentheses()) return; | 4018 if (expr->IsEmptyParentheses()) return; |
4010 | 4019 |
(...skipping 1429 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5440 auto class_literal = value->AsClassLiteral(); | 5449 auto class_literal = value->AsClassLiteral(); |
5441 if (class_literal->raw_name() == nullptr) { | 5450 if (class_literal->raw_name() == nullptr) { |
5442 class_literal->set_raw_name(name); | 5451 class_literal->set_raw_name(name); |
5443 } | 5452 } |
5444 } | 5453 } |
5445 } | 5454 } |
5446 | 5455 |
5447 | 5456 |
5448 } // namespace internal | 5457 } // namespace internal |
5449 } // namespace v8 | 5458 } // namespace v8 |
OLD | NEW |