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/parser.h" | 5 #include "src/parser.h" |
6 | 6 |
7 #include "src/api.h" | 7 #include "src/api.h" |
8 #include "src/ast.h" | 8 #include "src/ast.h" |
9 #include "src/ast-literal-reindexer.h" | 9 #include "src/ast-literal-reindexer.h" |
10 #include "src/bailout-reason.h" | 10 #include "src/bailout-reason.h" |
(...skipping 2334 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2345 is_strong(language_mode()) ? Token::INIT_CONST : Token::INIT_LET; | 2345 is_strong(language_mode()) ? Token::INIT_CONST : Token::INIT_LET; |
2346 Assignment* assignment = factory()->NewAssignment(init_op, proxy, value, pos); | 2346 Assignment* assignment = factory()->NewAssignment(init_op, proxy, value, pos); |
2347 Statement* assignment_statement = | 2347 Statement* assignment_statement = |
2348 factory()->NewExpressionStatement(assignment, RelocInfo::kNoPosition); | 2348 factory()->NewExpressionStatement(assignment, RelocInfo::kNoPosition); |
2349 if (names) names->Add(name, zone()); | 2349 if (names) names->Add(name, zone()); |
2350 return assignment_statement; | 2350 return assignment_statement; |
2351 } | 2351 } |
2352 | 2352 |
2353 | 2353 |
2354 Block* Parser::ParseBlock(ZoneList<const AstRawString*>* labels, bool* ok) { | 2354 Block* Parser::ParseBlock(ZoneList<const AstRawString*>* labels, bool* ok) { |
2355 if (is_strict(language_mode()) || allow_harmony_sloppy()) { | |
2356 return ParseScopedBlock(labels, ok); | |
2357 } | |
2358 | |
2359 // Block :: | |
2360 // '{' Statement* '}' | |
2361 | |
2362 // Note that a Block does not introduce a new execution scope! | |
2363 // (ECMA-262, 3rd, 12.2) | |
2364 // | |
2365 // Construct block expecting 16 statements. | |
2366 Block* result = | |
2367 factory()->NewBlock(labels, 16, false, RelocInfo::kNoPosition); | |
2368 Target target(&this->target_stack_, result); | |
2369 Expect(Token::LBRACE, CHECK_OK); | |
2370 while (peek() != Token::RBRACE) { | |
2371 Statement* stat = ParseStatement(NULL, CHECK_OK); | |
2372 if (stat && !stat->IsEmpty()) { | |
2373 result->statements()->Add(stat, zone()); | |
2374 } | |
2375 } | |
2376 Expect(Token::RBRACE, CHECK_OK); | |
2377 return result; | |
2378 } | |
2379 | |
2380 | |
2381 Block* Parser::ParseScopedBlock(ZoneList<const AstRawString*>* labels, | |
2382 bool* ok) { | |
2383 // The harmony mode uses block elements instead of statements. | 2355 // The harmony mode uses block elements instead of statements. |
2384 // | 2356 // |
2385 // Block :: | 2357 // Block :: |
2386 // '{' StatementList '}' | 2358 // '{' StatementList '}' |
2387 | 2359 |
2388 // Construct block expecting 16 statements. | 2360 // Construct block expecting 16 statements. |
2389 Block* body = | 2361 Block* body = |
2390 factory()->NewBlock(labels, 16, false, RelocInfo::kNoPosition); | 2362 factory()->NewBlock(labels, 16, false, RelocInfo::kNoPosition); |
2391 Scope* block_scope = NewScope(scope_, BLOCK_SCOPE); | 2363 Scope* block_scope = NewScope(scope_, BLOCK_SCOPE); |
2392 | 2364 |
(...skipping 790 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3183 } | 3155 } |
3184 | 3156 |
3185 catch_variable = catch_scope->DeclareLocal(name, VAR, kCreatedInitialized, | 3157 catch_variable = catch_scope->DeclareLocal(name, VAR, kCreatedInitialized, |
3186 Variable::NORMAL); | 3158 Variable::NORMAL); |
3187 | 3159 |
3188 Expect(Token::RPAREN, CHECK_OK); | 3160 Expect(Token::RPAREN, CHECK_OK); |
3189 | 3161 |
3190 { | 3162 { |
3191 BlockState block_state(&scope_, catch_scope); | 3163 BlockState block_state(&scope_, catch_scope); |
3192 | 3164 |
3193 // TODO(adamk): Make a version of ParseScopedBlock that takes a scope and | 3165 // TODO(adamk): Make a version of ParseBlock that takes a scope and |
3194 // a block. | 3166 // a block. |
3195 catch_block = | 3167 catch_block = |
3196 factory()->NewBlock(nullptr, 16, false, RelocInfo::kNoPosition); | 3168 factory()->NewBlock(nullptr, 16, false, RelocInfo::kNoPosition); |
3197 Scope* block_scope = NewScope(scope_, BLOCK_SCOPE); | 3169 Scope* block_scope = NewScope(scope_, BLOCK_SCOPE); |
3198 | 3170 |
3199 block_scope->set_start_position(scanner()->location().beg_pos); | 3171 block_scope->set_start_position(scanner()->location().beg_pos); |
3200 { | 3172 { |
3201 BlockState block_state(&scope_, block_scope); | 3173 BlockState block_state(&scope_, block_scope); |
3202 Target target(&this->target_stack_, catch_block); | 3174 Target target(&this->target_stack_, catch_block); |
3203 | 3175 |
(...skipping 925 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4129 | 4101 |
4130 | 4102 |
4131 DoExpression* Parser::ParseDoExpression(bool* ok) { | 4103 DoExpression* Parser::ParseDoExpression(bool* ok) { |
4132 // AssignmentExpression :: | 4104 // AssignmentExpression :: |
4133 // do '{' StatementList '}' | 4105 // do '{' StatementList '}' |
4134 int pos = peek_position(); | 4106 int pos = peek_position(); |
4135 | 4107 |
4136 Expect(Token::DO, CHECK_OK); | 4108 Expect(Token::DO, CHECK_OK); |
4137 Variable* result = | 4109 Variable* result = |
4138 scope_->NewTemporary(ast_value_factory()->dot_result_string()); | 4110 scope_->NewTemporary(ast_value_factory()->dot_result_string()); |
4139 Block* block = ParseScopedBlock(nullptr, CHECK_OK); | 4111 Block* block = ParseBlock(nullptr, CHECK_OK); |
4140 DoExpression* expr = factory()->NewDoExpression(block, result, pos); | 4112 DoExpression* expr = factory()->NewDoExpression(block, result, pos); |
4141 if (!Rewriter::Rewrite(this, expr, ast_value_factory())) { | 4113 if (!Rewriter::Rewrite(this, expr, ast_value_factory())) { |
4142 *ok = false; | 4114 *ok = false; |
4143 return nullptr; | 4115 return nullptr; |
4144 } | 4116 } |
4145 return expr; | 4117 return expr; |
4146 } | 4118 } |
4147 | 4119 |
4148 | 4120 |
4149 void ParserTraits::ParseArrowFunctionFormalParameterList( | 4121 void ParserTraits::ParseArrowFunctionFormalParameterList( |
(...skipping 2303 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6453 } | 6425 } |
6454 | 6426 |
6455 | 6427 |
6456 void Parser::RaiseLanguageMode(LanguageMode mode) { | 6428 void Parser::RaiseLanguageMode(LanguageMode mode) { |
6457 SetLanguageMode(scope_, | 6429 SetLanguageMode(scope_, |
6458 static_cast<LanguageMode>(scope_->language_mode() | mode)); | 6430 static_cast<LanguageMode>(scope_->language_mode() | mode)); |
6459 } | 6431 } |
6460 | 6432 |
6461 } // namespace internal | 6433 } // namespace internal |
6462 } // namespace v8 | 6434 } // namespace v8 |
OLD | NEW |