Chromium Code Reviews| 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 1915 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1926 case Token::TRY: { | 1926 case Token::TRY: { |
| 1927 // These statements must have their labels preserved in an enclosing | 1927 // These statements must have their labels preserved in an enclosing |
| 1928 // block | 1928 // block |
| 1929 if (labels == NULL) { | 1929 if (labels == NULL) { |
| 1930 return ParseStatementAsUnlabelled(labels, ok); | 1930 return ParseStatementAsUnlabelled(labels, ok); |
| 1931 } else { | 1931 } else { |
| 1932 Block* result = | 1932 Block* result = |
| 1933 factory()->NewBlock(labels, 1, false, RelocInfo::kNoPosition); | 1933 factory()->NewBlock(labels, 1, false, RelocInfo::kNoPosition); |
| 1934 Target target(&this->target_stack_, result); | 1934 Target target(&this->target_stack_, result); |
| 1935 Statement* statement = ParseStatementAsUnlabelled(labels, CHECK_OK); | 1935 Statement* statement = ParseStatementAsUnlabelled(labels, CHECK_OK); |
| 1936 if (result) result->AddStatement(statement, zone()); | 1936 if (result) result->statements()->Add(statement, zone()); |
|
adamk
2015/10/05 17:39:28
Looks like these were all changed in this patch (f
| |
| 1937 return result; | 1937 return result; |
| 1938 } | 1938 } |
| 1939 } | 1939 } |
| 1940 | 1940 |
| 1941 case Token::WITH: | 1941 case Token::WITH: |
| 1942 return ParseWithStatement(labels, ok); | 1942 return ParseWithStatement(labels, ok); |
| 1943 | 1943 |
| 1944 case Token::SWITCH: | 1944 case Token::SWITCH: |
| 1945 return ParseSwitchStatement(labels, ok); | 1945 return ParseSwitchStatement(labels, ok); |
| 1946 | 1946 |
| (...skipping 407 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2354 // (ECMA-262, 3rd, 12.2) | 2354 // (ECMA-262, 3rd, 12.2) |
| 2355 // | 2355 // |
| 2356 // Construct block expecting 16 statements. | 2356 // Construct block expecting 16 statements. |
| 2357 Block* result = | 2357 Block* result = |
| 2358 factory()->NewBlock(labels, 16, false, RelocInfo::kNoPosition); | 2358 factory()->NewBlock(labels, 16, false, RelocInfo::kNoPosition); |
| 2359 Target target(&this->target_stack_, result); | 2359 Target target(&this->target_stack_, result); |
| 2360 Expect(Token::LBRACE, CHECK_OK); | 2360 Expect(Token::LBRACE, CHECK_OK); |
| 2361 while (peek() != Token::RBRACE) { | 2361 while (peek() != Token::RBRACE) { |
| 2362 Statement* stat = ParseStatement(NULL, CHECK_OK); | 2362 Statement* stat = ParseStatement(NULL, CHECK_OK); |
| 2363 if (stat && !stat->IsEmpty()) { | 2363 if (stat && !stat->IsEmpty()) { |
| 2364 result->AddStatement(stat, zone()); | 2364 result->statements()->Add(stat, zone()); |
| 2365 } | 2365 } |
| 2366 } | 2366 } |
| 2367 Expect(Token::RBRACE, CHECK_OK); | 2367 Expect(Token::RBRACE, CHECK_OK); |
| 2368 return result; | 2368 return result; |
| 2369 } | 2369 } |
| 2370 | 2370 |
| 2371 | 2371 |
| 2372 Block* Parser::ParseScopedBlock(ZoneList<const AstRawString*>* labels, | 2372 Block* Parser::ParseScopedBlock(ZoneList<const AstRawString*>* labels, |
| 2373 bool* ok) { | 2373 bool* ok) { |
| 2374 // The harmony mode uses block elements instead of statements. | 2374 // The harmony mode uses block elements instead of statements. |
| 2375 // | 2375 // |
| 2376 // Block :: | 2376 // Block :: |
| 2377 // '{' StatementList '}' | 2377 // '{' StatementList '}' |
| 2378 | 2378 |
| 2379 // Construct block expecting 16 statements. | 2379 // Construct block expecting 16 statements. |
| 2380 Block* body = | 2380 Block* body = |
| 2381 factory()->NewBlock(labels, 16, false, RelocInfo::kNoPosition); | 2381 factory()->NewBlock(labels, 16, false, RelocInfo::kNoPosition); |
| 2382 Scope* block_scope = NewScope(scope_, BLOCK_SCOPE); | 2382 Scope* block_scope = NewScope(scope_, BLOCK_SCOPE); |
| 2383 | 2383 |
| 2384 // Parse the statements and collect escaping labels. | 2384 // Parse the statements and collect escaping labels. |
| 2385 Expect(Token::LBRACE, CHECK_OK); | 2385 Expect(Token::LBRACE, CHECK_OK); |
| 2386 block_scope->set_start_position(scanner()->location().beg_pos); | 2386 block_scope->set_start_position(scanner()->location().beg_pos); |
| 2387 { BlockState block_state(&scope_, block_scope); | 2387 { BlockState block_state(&scope_, block_scope); |
| 2388 Target target(&this->target_stack_, body); | 2388 Target target(&this->target_stack_, body); |
| 2389 | 2389 |
| 2390 while (peek() != Token::RBRACE) { | 2390 while (peek() != Token::RBRACE) { |
| 2391 Statement* stat = ParseStatementListItem(CHECK_OK); | 2391 Statement* stat = ParseStatementListItem(CHECK_OK); |
| 2392 if (stat && !stat->IsEmpty()) { | 2392 if (stat && !stat->IsEmpty()) { |
| 2393 body->AddStatement(stat, zone()); | 2393 body->statements()->Add(stat, zone()); |
| 2394 } | 2394 } |
| 2395 } | 2395 } |
| 2396 } | 2396 } |
| 2397 Expect(Token::RBRACE, CHECK_OK); | 2397 Expect(Token::RBRACE, CHECK_OK); |
| 2398 block_scope->set_end_position(scanner()->location().end_pos); | 2398 block_scope->set_end_position(scanner()->location().end_pos); |
| 2399 block_scope = block_scope->FinalizeBlockScope(); | 2399 block_scope = block_scope->FinalizeBlockScope(); |
| 2400 body->set_scope(block_scope); | 2400 body->set_scope(block_scope); |
| 2401 return body; | 2401 return body; |
| 2402 } | 2402 } |
| 2403 | 2403 |
| (...skipping 618 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3022 Expression* tag = ParseExpression(true, CHECK_OK); | 3022 Expression* tag = ParseExpression(true, CHECK_OK); |
| 3023 Expect(Token::RPAREN, CHECK_OK); | 3023 Expect(Token::RPAREN, CHECK_OK); |
| 3024 | 3024 |
| 3025 Variable* tag_variable = | 3025 Variable* tag_variable = |
| 3026 scope_->NewTemporary(ast_value_factory()->dot_switch_tag_string()); | 3026 scope_->NewTemporary(ast_value_factory()->dot_switch_tag_string()); |
| 3027 Assignment* tag_assign = factory()->NewAssignment( | 3027 Assignment* tag_assign = factory()->NewAssignment( |
| 3028 Token::ASSIGN, factory()->NewVariableProxy(tag_variable), tag, | 3028 Token::ASSIGN, factory()->NewVariableProxy(tag_variable), tag, |
| 3029 tag->position()); | 3029 tag->position()); |
| 3030 Statement* tag_statement = | 3030 Statement* tag_statement = |
| 3031 factory()->NewExpressionStatement(tag_assign, RelocInfo::kNoPosition); | 3031 factory()->NewExpressionStatement(tag_assign, RelocInfo::kNoPosition); |
| 3032 switch_block->AddStatement(tag_statement, zone()); | 3032 switch_block->statements()->Add(tag_statement, zone()); |
| 3033 | 3033 |
| 3034 // make statement: undefined; | 3034 // make statement: undefined; |
| 3035 // This is needed so the tag isn't returned as the value, in case the switch | 3035 // This is needed so the tag isn't returned as the value, in case the switch |
| 3036 // statements don't have a value. | 3036 // statements don't have a value. |
| 3037 switch_block->AddStatement( | 3037 switch_block->statements()->Add( |
| 3038 factory()->NewExpressionStatement( | 3038 factory()->NewExpressionStatement( |
| 3039 factory()->NewUndefinedLiteral(RelocInfo::kNoPosition), | 3039 factory()->NewUndefinedLiteral(RelocInfo::kNoPosition), |
| 3040 RelocInfo::kNoPosition), | 3040 RelocInfo::kNoPosition), |
| 3041 zone()); | 3041 zone()); |
| 3042 | 3042 |
| 3043 Block* cases_block = | 3043 Block* cases_block = |
| 3044 factory()->NewBlock(NULL, 1, false, RelocInfo::kNoPosition); | 3044 factory()->NewBlock(NULL, 1, false, RelocInfo::kNoPosition); |
| 3045 Scope* cases_scope = NewScope(scope_, BLOCK_SCOPE); | 3045 Scope* cases_scope = NewScope(scope_, BLOCK_SCOPE); |
| 3046 cases_scope->SetNonlinear(); | 3046 cases_scope->SetNonlinear(); |
| 3047 | 3047 |
| 3048 SwitchStatement* switch_statement = | 3048 SwitchStatement* switch_statement = |
| 3049 factory()->NewSwitchStatement(labels, switch_pos); | 3049 factory()->NewSwitchStatement(labels, switch_pos); |
| 3050 | 3050 |
| 3051 cases_scope->set_start_position(scanner()->location().beg_pos); | 3051 cases_scope->set_start_position(scanner()->location().beg_pos); |
| 3052 { | 3052 { |
| 3053 BlockState cases_block_state(&scope_, cases_scope); | 3053 BlockState cases_block_state(&scope_, cases_scope); |
| 3054 Target target(&this->target_stack_, switch_statement); | 3054 Target target(&this->target_stack_, switch_statement); |
| 3055 | 3055 |
| 3056 Expression* tag_read = factory()->NewVariableProxy(tag_variable); | 3056 Expression* tag_read = factory()->NewVariableProxy(tag_variable); |
| 3057 | 3057 |
| 3058 bool default_seen = false; | 3058 bool default_seen = false; |
| 3059 ZoneList<CaseClause*>* cases = | 3059 ZoneList<CaseClause*>* cases = |
| 3060 new (zone()) ZoneList<CaseClause*>(4, zone()); | 3060 new (zone()) ZoneList<CaseClause*>(4, zone()); |
| 3061 Expect(Token::LBRACE, CHECK_OK); | 3061 Expect(Token::LBRACE, CHECK_OK); |
| 3062 while (peek() != Token::RBRACE) { | 3062 while (peek() != Token::RBRACE) { |
| 3063 CaseClause* clause = ParseCaseClause(&default_seen, CHECK_OK); | 3063 CaseClause* clause = ParseCaseClause(&default_seen, CHECK_OK); |
| 3064 cases->Add(clause, zone()); | 3064 cases->Add(clause, zone()); |
| 3065 } | 3065 } |
| 3066 switch_statement->Initialize(tag_read, cases); | 3066 switch_statement->Initialize(tag_read, cases); |
| 3067 cases_block->AddStatement(switch_statement, zone()); | 3067 cases_block->statements()->Add(switch_statement, zone()); |
| 3068 } | 3068 } |
| 3069 Expect(Token::RBRACE, CHECK_OK); | 3069 Expect(Token::RBRACE, CHECK_OK); |
| 3070 | 3070 |
| 3071 cases_scope->set_end_position(scanner()->location().end_pos); | 3071 cases_scope->set_end_position(scanner()->location().end_pos); |
| 3072 cases_scope = cases_scope->FinalizeBlockScope(); | 3072 cases_scope = cases_scope->FinalizeBlockScope(); |
| 3073 cases_block->set_scope(cases_scope); | 3073 cases_block->set_scope(cases_scope); |
| 3074 | 3074 |
| 3075 switch_block->AddStatement(cases_block, zone()); | 3075 switch_block->statements()->Add(cases_block, zone()); |
| 3076 | 3076 |
| 3077 return switch_block; | 3077 return switch_block; |
| 3078 } | 3078 } |
| 3079 | 3079 |
| 3080 | 3080 |
| 3081 Statement* Parser::ParseThrowStatement(bool* ok) { | 3081 Statement* Parser::ParseThrowStatement(bool* ok) { |
| 3082 // ThrowStatement :: | 3082 // ThrowStatement :: |
| 3083 // 'throw' Expression ';' | 3083 // 'throw' Expression ';' |
| 3084 | 3084 |
| 3085 Expect(Token::THROW, CHECK_OK); | 3085 Expect(Token::THROW, CHECK_OK); |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3156 // to: | 3156 // to: |
| 3157 // 'try { try B0 catch B1 } finally B2' | 3157 // 'try { try B0 catch B1 } finally B2' |
| 3158 | 3158 |
| 3159 if (catch_block != NULL && finally_block != NULL) { | 3159 if (catch_block != NULL && finally_block != NULL) { |
| 3160 // If we have both, create an inner try/catch. | 3160 // If we have both, create an inner try/catch. |
| 3161 DCHECK(catch_scope != NULL && catch_variable != NULL); | 3161 DCHECK(catch_scope != NULL && catch_variable != NULL); |
| 3162 TryCatchStatement* statement = | 3162 TryCatchStatement* statement = |
| 3163 factory()->NewTryCatchStatement(try_block, catch_scope, catch_variable, | 3163 factory()->NewTryCatchStatement(try_block, catch_scope, catch_variable, |
| 3164 catch_block, RelocInfo::kNoPosition); | 3164 catch_block, RelocInfo::kNoPosition); |
| 3165 try_block = factory()->NewBlock(NULL, 1, false, RelocInfo::kNoPosition); | 3165 try_block = factory()->NewBlock(NULL, 1, false, RelocInfo::kNoPosition); |
| 3166 try_block->AddStatement(statement, zone()); | 3166 try_block->statements()->Add(statement, zone()); |
| 3167 catch_block = NULL; // Clear to indicate it's been handled. | 3167 catch_block = NULL; // Clear to indicate it's been handled. |
| 3168 } | 3168 } |
| 3169 | 3169 |
| 3170 TryStatement* result = NULL; | 3170 TryStatement* result = NULL; |
| 3171 if (catch_block != NULL) { | 3171 if (catch_block != NULL) { |
| 3172 DCHECK(finally_block == NULL); | 3172 DCHECK(finally_block == NULL); |
| 3173 DCHECK(catch_scope != NULL && catch_variable != NULL); | 3173 DCHECK(catch_scope != NULL && catch_variable != NULL); |
| 3174 result = factory()->NewTryCatchStatement(try_block, catch_scope, | 3174 result = factory()->NewTryCatchStatement(try_block, catch_scope, |
| 3175 catch_variable, catch_block, pos); | 3175 catch_variable, catch_block, pos); |
| 3176 } else { | 3176 } else { |
| (...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3377 // } | 3377 // } |
| 3378 | 3378 |
| 3379 DCHECK(names->length() > 0); | 3379 DCHECK(names->length() > 0); |
| 3380 Scope* for_scope = scope_; | 3380 Scope* for_scope = scope_; |
| 3381 ZoneList<Variable*> temps(names->length(), zone()); | 3381 ZoneList<Variable*> temps(names->length(), zone()); |
| 3382 | 3382 |
| 3383 Block* outer_block = factory()->NewBlock(NULL, names->length() + 3, false, | 3383 Block* outer_block = factory()->NewBlock(NULL, names->length() + 3, false, |
| 3384 RelocInfo::kNoPosition); | 3384 RelocInfo::kNoPosition); |
| 3385 | 3385 |
| 3386 // Add statement: let/const x = i. | 3386 // Add statement: let/const x = i. |
| 3387 outer_block->AddStatement(init, zone()); | 3387 outer_block->statements()->Add(init, zone()); |
| 3388 | 3388 |
| 3389 const AstRawString* temp_name = ast_value_factory()->dot_for_string(); | 3389 const AstRawString* temp_name = ast_value_factory()->dot_for_string(); |
| 3390 | 3390 |
| 3391 // For each lexical variable x: | 3391 // For each lexical variable x: |
| 3392 // make statement: temp_x = x. | 3392 // make statement: temp_x = x. |
| 3393 for (int i = 0; i < names->length(); i++) { | 3393 for (int i = 0; i < names->length(); i++) { |
| 3394 VariableProxy* proxy = NewUnresolved(names->at(i), LET); | 3394 VariableProxy* proxy = NewUnresolved(names->at(i), LET); |
| 3395 Variable* temp = scope_->NewTemporary(temp_name); | 3395 Variable* temp = scope_->NewTemporary(temp_name); |
| 3396 VariableProxy* temp_proxy = factory()->NewVariableProxy(temp); | 3396 VariableProxy* temp_proxy = factory()->NewVariableProxy(temp); |
| 3397 Assignment* assignment = factory()->NewAssignment( | 3397 Assignment* assignment = factory()->NewAssignment( |
| 3398 Token::ASSIGN, temp_proxy, proxy, RelocInfo::kNoPosition); | 3398 Token::ASSIGN, temp_proxy, proxy, RelocInfo::kNoPosition); |
| 3399 Statement* assignment_statement = factory()->NewExpressionStatement( | 3399 Statement* assignment_statement = factory()->NewExpressionStatement( |
| 3400 assignment, RelocInfo::kNoPosition); | 3400 assignment, RelocInfo::kNoPosition); |
| 3401 outer_block->AddStatement(assignment_statement, zone()); | 3401 outer_block->statements()->Add(assignment_statement, zone()); |
| 3402 temps.Add(temp, zone()); | 3402 temps.Add(temp, zone()); |
| 3403 } | 3403 } |
| 3404 | 3404 |
| 3405 Variable* first = NULL; | 3405 Variable* first = NULL; |
| 3406 // Make statement: first = 1. | 3406 // Make statement: first = 1. |
| 3407 if (next) { | 3407 if (next) { |
| 3408 first = scope_->NewTemporary(temp_name); | 3408 first = scope_->NewTemporary(temp_name); |
| 3409 VariableProxy* first_proxy = factory()->NewVariableProxy(first); | 3409 VariableProxy* first_proxy = factory()->NewVariableProxy(first); |
| 3410 Expression* const1 = factory()->NewSmiLiteral(1, RelocInfo::kNoPosition); | 3410 Expression* const1 = factory()->NewSmiLiteral(1, RelocInfo::kNoPosition); |
| 3411 Assignment* assignment = factory()->NewAssignment( | 3411 Assignment* assignment = factory()->NewAssignment( |
| 3412 Token::ASSIGN, first_proxy, const1, RelocInfo::kNoPosition); | 3412 Token::ASSIGN, first_proxy, const1, RelocInfo::kNoPosition); |
| 3413 Statement* assignment_statement = | 3413 Statement* assignment_statement = |
| 3414 factory()->NewExpressionStatement(assignment, RelocInfo::kNoPosition); | 3414 factory()->NewExpressionStatement(assignment, RelocInfo::kNoPosition); |
| 3415 outer_block->AddStatement(assignment_statement, zone()); | 3415 outer_block->statements()->Add(assignment_statement, zone()); |
| 3416 } | 3416 } |
| 3417 | 3417 |
| 3418 // make statement: undefined; | 3418 // make statement: undefined; |
| 3419 outer_block->AddStatement( | 3419 outer_block->statements()->Add( |
| 3420 factory()->NewExpressionStatement( | 3420 factory()->NewExpressionStatement( |
| 3421 factory()->NewUndefinedLiteral(RelocInfo::kNoPosition), | 3421 factory()->NewUndefinedLiteral(RelocInfo::kNoPosition), |
| 3422 RelocInfo::kNoPosition), | 3422 RelocInfo::kNoPosition), |
| 3423 zone()); | 3423 zone()); |
| 3424 | 3424 |
| 3425 // Make statement: outer: for (;;) | 3425 // Make statement: outer: for (;;) |
| 3426 // Note that we don't actually create the label, or set this loop up as an | 3426 // Note that we don't actually create the label, or set this loop up as an |
| 3427 // explicit break target, instead handing it directly to those nodes that | 3427 // explicit break target, instead handing it directly to those nodes that |
| 3428 // need to know about it. This should be safe because we don't run any code | 3428 // need to know about it. This should be safe because we don't run any code |
| 3429 // in this function that looks up break targets. | 3429 // in this function that looks up break targets. |
| 3430 ForStatement* outer_loop = | 3430 ForStatement* outer_loop = |
| 3431 factory()->NewForStatement(NULL, RelocInfo::kNoPosition); | 3431 factory()->NewForStatement(NULL, RelocInfo::kNoPosition); |
| 3432 outer_block->AddStatement(outer_loop, zone()); | 3432 outer_block->statements()->Add(outer_loop, zone()); |
| 3433 | 3433 |
| 3434 outer_block->set_scope(for_scope); | 3434 outer_block->set_scope(for_scope); |
| 3435 scope_ = inner_scope; | 3435 scope_ = inner_scope; |
| 3436 | 3436 |
| 3437 Block* inner_block = | 3437 Block* inner_block = |
| 3438 factory()->NewBlock(NULL, 3, false, RelocInfo::kNoPosition); | 3438 factory()->NewBlock(NULL, 3, false, RelocInfo::kNoPosition); |
| 3439 Block* ignore_completion_block = factory()->NewBlock( | 3439 Block* ignore_completion_block = factory()->NewBlock( |
| 3440 NULL, names->length() + 2, true, RelocInfo::kNoPosition); | 3440 NULL, names->length() + 2, true, RelocInfo::kNoPosition); |
| 3441 ZoneList<Variable*> inner_vars(names->length(), zone()); | 3441 ZoneList<Variable*> inner_vars(names->length(), zone()); |
| 3442 // For each let variable x: | 3442 // For each let variable x: |
| 3443 // make statement: let/const x = temp_x. | 3443 // make statement: let/const x = temp_x. |
| 3444 VariableMode mode = is_const ? CONST : LET; | 3444 VariableMode mode = is_const ? CONST : LET; |
| 3445 for (int i = 0; i < names->length(); i++) { | 3445 for (int i = 0; i < names->length(); i++) { |
| 3446 VariableProxy* proxy = NewUnresolved(names->at(i), mode); | 3446 VariableProxy* proxy = NewUnresolved(names->at(i), mode); |
| 3447 Declaration* declaration = factory()->NewVariableDeclaration( | 3447 Declaration* declaration = factory()->NewVariableDeclaration( |
| 3448 proxy, mode, scope_, RelocInfo::kNoPosition); | 3448 proxy, mode, scope_, RelocInfo::kNoPosition); |
| 3449 Declare(declaration, DeclarationDescriptor::NORMAL, true, CHECK_OK); | 3449 Declare(declaration, DeclarationDescriptor::NORMAL, true, CHECK_OK); |
| 3450 inner_vars.Add(declaration->proxy()->var(), zone()); | 3450 inner_vars.Add(declaration->proxy()->var(), zone()); |
| 3451 VariableProxy* temp_proxy = factory()->NewVariableProxy(temps.at(i)); | 3451 VariableProxy* temp_proxy = factory()->NewVariableProxy(temps.at(i)); |
| 3452 Assignment* assignment = | 3452 Assignment* assignment = |
| 3453 factory()->NewAssignment(is_const ? Token::INIT_CONST : Token::INIT_LET, | 3453 factory()->NewAssignment(is_const ? Token::INIT_CONST : Token::INIT_LET, |
| 3454 proxy, temp_proxy, RelocInfo::kNoPosition); | 3454 proxy, temp_proxy, RelocInfo::kNoPosition); |
| 3455 Statement* assignment_statement = | 3455 Statement* assignment_statement = |
| 3456 factory()->NewExpressionStatement(assignment, RelocInfo::kNoPosition); | 3456 factory()->NewExpressionStatement(assignment, RelocInfo::kNoPosition); |
| 3457 DCHECK(init->position() != RelocInfo::kNoPosition); | 3457 DCHECK(init->position() != RelocInfo::kNoPosition); |
| 3458 proxy->var()->set_initializer_position(init->position()); | 3458 proxy->var()->set_initializer_position(init->position()); |
| 3459 ignore_completion_block->AddStatement(assignment_statement, zone()); | 3459 ignore_completion_block->statements()->Add(assignment_statement, zone()); |
| 3460 } | 3460 } |
| 3461 | 3461 |
| 3462 // Make statement: if (first == 1) { first = 0; } else { next; } | 3462 // Make statement: if (first == 1) { first = 0; } else { next; } |
| 3463 if (next) { | 3463 if (next) { |
| 3464 DCHECK(first); | 3464 DCHECK(first); |
| 3465 Expression* compare = NULL; | 3465 Expression* compare = NULL; |
| 3466 // Make compare expression: first == 1. | 3466 // Make compare expression: first == 1. |
| 3467 { | 3467 { |
| 3468 Expression* const1 = factory()->NewSmiLiteral(1, RelocInfo::kNoPosition); | 3468 Expression* const1 = factory()->NewSmiLiteral(1, RelocInfo::kNoPosition); |
| 3469 VariableProxy* first_proxy = factory()->NewVariableProxy(first); | 3469 VariableProxy* first_proxy = factory()->NewVariableProxy(first); |
| 3470 compare = factory()->NewCompareOperation(Token::EQ, first_proxy, const1, | 3470 compare = factory()->NewCompareOperation(Token::EQ, first_proxy, const1, |
| 3471 RelocInfo::kNoPosition); | 3471 RelocInfo::kNoPosition); |
| 3472 } | 3472 } |
| 3473 Statement* clear_first = NULL; | 3473 Statement* clear_first = NULL; |
| 3474 // Make statement: first = 0. | 3474 // Make statement: first = 0. |
| 3475 { | 3475 { |
| 3476 VariableProxy* first_proxy = factory()->NewVariableProxy(first); | 3476 VariableProxy* first_proxy = factory()->NewVariableProxy(first); |
| 3477 Expression* const0 = factory()->NewSmiLiteral(0, RelocInfo::kNoPosition); | 3477 Expression* const0 = factory()->NewSmiLiteral(0, RelocInfo::kNoPosition); |
| 3478 Assignment* assignment = factory()->NewAssignment( | 3478 Assignment* assignment = factory()->NewAssignment( |
| 3479 Token::ASSIGN, first_proxy, const0, RelocInfo::kNoPosition); | 3479 Token::ASSIGN, first_proxy, const0, RelocInfo::kNoPosition); |
| 3480 clear_first = | 3480 clear_first = |
| 3481 factory()->NewExpressionStatement(assignment, RelocInfo::kNoPosition); | 3481 factory()->NewExpressionStatement(assignment, RelocInfo::kNoPosition); |
| 3482 } | 3482 } |
| 3483 Statement* clear_first_or_next = factory()->NewIfStatement( | 3483 Statement* clear_first_or_next = factory()->NewIfStatement( |
| 3484 compare, clear_first, next, RelocInfo::kNoPosition); | 3484 compare, clear_first, next, RelocInfo::kNoPosition); |
| 3485 ignore_completion_block->AddStatement(clear_first_or_next, zone()); | 3485 ignore_completion_block->statements()->Add(clear_first_or_next, zone()); |
| 3486 } | 3486 } |
| 3487 | 3487 |
| 3488 Variable* flag = scope_->NewTemporary(temp_name); | 3488 Variable* flag = scope_->NewTemporary(temp_name); |
| 3489 // Make statement: flag = 1. | 3489 // Make statement: flag = 1. |
| 3490 { | 3490 { |
| 3491 VariableProxy* flag_proxy = factory()->NewVariableProxy(flag); | 3491 VariableProxy* flag_proxy = factory()->NewVariableProxy(flag); |
| 3492 Expression* const1 = factory()->NewSmiLiteral(1, RelocInfo::kNoPosition); | 3492 Expression* const1 = factory()->NewSmiLiteral(1, RelocInfo::kNoPosition); |
| 3493 Assignment* assignment = factory()->NewAssignment( | 3493 Assignment* assignment = factory()->NewAssignment( |
| 3494 Token::ASSIGN, flag_proxy, const1, RelocInfo::kNoPosition); | 3494 Token::ASSIGN, flag_proxy, const1, RelocInfo::kNoPosition); |
| 3495 Statement* assignment_statement = | 3495 Statement* assignment_statement = |
| 3496 factory()->NewExpressionStatement(assignment, RelocInfo::kNoPosition); | 3496 factory()->NewExpressionStatement(assignment, RelocInfo::kNoPosition); |
| 3497 ignore_completion_block->AddStatement(assignment_statement, zone()); | 3497 ignore_completion_block->statements()->Add(assignment_statement, zone()); |
| 3498 } | 3498 } |
| 3499 inner_block->AddStatement(ignore_completion_block, zone()); | 3499 inner_block->statements()->Add(ignore_completion_block, zone()); |
| 3500 // Make cond expression for main loop: flag == 1. | 3500 // Make cond expression for main loop: flag == 1. |
| 3501 Expression* flag_cond = NULL; | 3501 Expression* flag_cond = NULL; |
| 3502 { | 3502 { |
| 3503 Expression* const1 = factory()->NewSmiLiteral(1, RelocInfo::kNoPosition); | 3503 Expression* const1 = factory()->NewSmiLiteral(1, RelocInfo::kNoPosition); |
| 3504 VariableProxy* flag_proxy = factory()->NewVariableProxy(flag); | 3504 VariableProxy* flag_proxy = factory()->NewVariableProxy(flag); |
| 3505 flag_cond = factory()->NewCompareOperation(Token::EQ, flag_proxy, const1, | 3505 flag_cond = factory()->NewCompareOperation(Token::EQ, flag_proxy, const1, |
| 3506 RelocInfo::kNoPosition); | 3506 RelocInfo::kNoPosition); |
| 3507 } | 3507 } |
| 3508 | 3508 |
| 3509 // Create chain of expressions "flag = 0, temp_x = x, ..." | 3509 // Create chain of expressions "flag = 0, temp_x = x, ..." |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3541 factory()->NewBreakStatement(outer_loop, RelocInfo::kNoPosition); | 3541 factory()->NewBreakStatement(outer_loop, RelocInfo::kNoPosition); |
| 3542 body_or_stop = | 3542 body_or_stop = |
| 3543 factory()->NewIfStatement(cond, body, stop, cond->position()); | 3543 factory()->NewIfStatement(cond, body, stop, cond->position()); |
| 3544 } | 3544 } |
| 3545 | 3545 |
| 3546 // Make statement: labels: for (; flag == 1; flag = 0, temp_x = x) | 3546 // Make statement: labels: for (; flag == 1; flag = 0, temp_x = x) |
| 3547 // Note that we re-use the original loop node, which retains its labels | 3547 // Note that we re-use the original loop node, which retains its labels |
| 3548 // and ensures that any break or continue statements in body point to | 3548 // and ensures that any break or continue statements in body point to |
| 3549 // the right place. | 3549 // the right place. |
| 3550 loop->Initialize(NULL, flag_cond, compound_next_statement, body_or_stop); | 3550 loop->Initialize(NULL, flag_cond, compound_next_statement, body_or_stop); |
| 3551 inner_block->AddStatement(loop, zone()); | 3551 inner_block->statements()->Add(loop, zone()); |
| 3552 | 3552 |
| 3553 // Make statement: if (flag == 1) { break; } | 3553 // Make statement: if (flag == 1) { break; } |
| 3554 { | 3554 { |
| 3555 Expression* compare = NULL; | 3555 Expression* compare = NULL; |
| 3556 // Make compare expresion: flag == 1. | 3556 // Make compare expresion: flag == 1. |
| 3557 { | 3557 { |
| 3558 Expression* const1 = factory()->NewSmiLiteral(1, RelocInfo::kNoPosition); | 3558 Expression* const1 = factory()->NewSmiLiteral(1, RelocInfo::kNoPosition); |
| 3559 VariableProxy* flag_proxy = factory()->NewVariableProxy(flag); | 3559 VariableProxy* flag_proxy = factory()->NewVariableProxy(flag); |
| 3560 compare = factory()->NewCompareOperation(Token::EQ, flag_proxy, const1, | 3560 compare = factory()->NewCompareOperation(Token::EQ, flag_proxy, const1, |
| 3561 RelocInfo::kNoPosition); | 3561 RelocInfo::kNoPosition); |
| 3562 } | 3562 } |
| 3563 Statement* stop = | 3563 Statement* stop = |
| 3564 factory()->NewBreakStatement(outer_loop, RelocInfo::kNoPosition); | 3564 factory()->NewBreakStatement(outer_loop, RelocInfo::kNoPosition); |
| 3565 Statement* empty = factory()->NewEmptyStatement(RelocInfo::kNoPosition); | 3565 Statement* empty = factory()->NewEmptyStatement(RelocInfo::kNoPosition); |
| 3566 Statement* if_flag_break = | 3566 Statement* if_flag_break = |
| 3567 factory()->NewIfStatement(compare, stop, empty, RelocInfo::kNoPosition); | 3567 factory()->NewIfStatement(compare, stop, empty, RelocInfo::kNoPosition); |
| 3568 inner_block->AddStatement(if_flag_break, zone()); | 3568 inner_block->statements()->Add(if_flag_break, zone()); |
| 3569 } | 3569 } |
| 3570 | 3570 |
| 3571 inner_scope->set_end_position(scanner()->location().end_pos); | 3571 inner_scope->set_end_position(scanner()->location().end_pos); |
| 3572 inner_block->set_scope(inner_scope); | 3572 inner_block->set_scope(inner_scope); |
| 3573 scope_ = for_scope; | 3573 scope_ = for_scope; |
| 3574 | 3574 |
| 3575 outer_loop->Initialize(NULL, NULL, NULL, inner_block); | 3575 outer_loop->Initialize(NULL, NULL, NULL, inner_block); |
| 3576 return outer_block; | 3576 return outer_block; |
| 3577 } | 3577 } |
| 3578 | 3578 |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3639 Block* init_block = nullptr; | 3639 Block* init_block = nullptr; |
| 3640 | 3640 |
| 3641 // special case for legacy for (var/const x =.... in) | 3641 // special case for legacy for (var/const x =.... in) |
| 3642 if (!IsLexicalVariableMode(parsing_result.descriptor.mode) && | 3642 if (!IsLexicalVariableMode(parsing_result.descriptor.mode) && |
| 3643 parsing_result.declarations[0].initializer != nullptr) { | 3643 parsing_result.declarations[0].initializer != nullptr) { |
| 3644 VariableProxy* single_var = scope_->NewUnresolved( | 3644 VariableProxy* single_var = scope_->NewUnresolved( |
| 3645 factory(), parsing_result.SingleName(), Variable::NORMAL, | 3645 factory(), parsing_result.SingleName(), Variable::NORMAL, |
| 3646 each_beg_pos, each_end_pos); | 3646 each_beg_pos, each_end_pos); |
| 3647 init_block = factory()->NewBlock( | 3647 init_block = factory()->NewBlock( |
| 3648 nullptr, 2, true, parsing_result.descriptor.declaration_pos); | 3648 nullptr, 2, true, parsing_result.descriptor.declaration_pos); |
| 3649 init_block->AddStatement( | 3649 init_block->statements()->Add( |
| 3650 factory()->NewExpressionStatement( | 3650 factory()->NewExpressionStatement( |
| 3651 factory()->NewAssignment( | 3651 factory()->NewAssignment( |
| 3652 Token::ASSIGN, single_var, | 3652 Token::ASSIGN, single_var, |
| 3653 parsing_result.declarations[0].initializer, | 3653 parsing_result.declarations[0].initializer, |
| 3654 RelocInfo::kNoPosition), | 3654 RelocInfo::kNoPosition), |
| 3655 RelocInfo::kNoPosition), | 3655 RelocInfo::kNoPosition), |
| 3656 zone()); | 3656 zone()); |
| 3657 } | 3657 } |
| 3658 | 3658 |
| 3659 // Rewrite a for-in/of statement of the form | 3659 // Rewrite a for-in/of statement of the form |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3702 descriptor.initialization_pos = RelocInfo::kNoPosition; | 3702 descriptor.initialization_pos = RelocInfo::kNoPosition; |
| 3703 decl.initializer = factory()->NewVariableProxy(temp); | 3703 decl.initializer = factory()->NewVariableProxy(temp); |
| 3704 | 3704 |
| 3705 PatternRewriter::DeclareAndInitializeVariables( | 3705 PatternRewriter::DeclareAndInitializeVariables( |
| 3706 each_initialization_block, &descriptor, &decl, | 3706 each_initialization_block, &descriptor, &decl, |
| 3707 IsLexicalVariableMode(descriptor.mode) ? &lexical_bindings | 3707 IsLexicalVariableMode(descriptor.mode) ? &lexical_bindings |
| 3708 : nullptr, | 3708 : nullptr, |
| 3709 CHECK_OK); | 3709 CHECK_OK); |
| 3710 } | 3710 } |
| 3711 | 3711 |
| 3712 body_block->AddStatement(each_initialization_block, zone()); | 3712 body_block->statements()->Add(each_initialization_block, zone()); |
| 3713 body_block->AddStatement(body, zone()); | 3713 body_block->statements()->Add(body, zone()); |
| 3714 VariableProxy* temp_proxy = | 3714 VariableProxy* temp_proxy = |
| 3715 factory()->NewVariableProxy(temp, each_beg_pos, each_end_pos); | 3715 factory()->NewVariableProxy(temp, each_beg_pos, each_end_pos); |
| 3716 InitializeForEachStatement(loop, temp_proxy, enumerable, body_block); | 3716 InitializeForEachStatement(loop, temp_proxy, enumerable, body_block); |
| 3717 scope_ = for_scope; | 3717 scope_ = for_scope; |
| 3718 body_scope->set_end_position(scanner()->location().end_pos); | 3718 body_scope->set_end_position(scanner()->location().end_pos); |
| 3719 body_scope = body_scope->FinalizeBlockScope(); | 3719 body_scope = body_scope->FinalizeBlockScope(); |
| 3720 if (body_scope != nullptr) { | 3720 if (body_scope != nullptr) { |
| 3721 body_block->set_scope(body_scope); | 3721 body_block->set_scope(body_scope); |
| 3722 } | 3722 } |
| 3723 | 3723 |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 3739 true, CHECK_OK); | 3739 true, CHECK_OK); |
| 3740 tdz_var->set_initializer_position(position()); | 3740 tdz_var->set_initializer_position(position()); |
| 3741 } | 3741 } |
| 3742 } | 3742 } |
| 3743 | 3743 |
| 3744 scope_ = saved_scope; | 3744 scope_ = saved_scope; |
| 3745 for_scope->set_end_position(scanner()->location().end_pos); | 3745 for_scope->set_end_position(scanner()->location().end_pos); |
| 3746 for_scope = for_scope->FinalizeBlockScope(); | 3746 for_scope = for_scope->FinalizeBlockScope(); |
| 3747 // Parsed for-in loop w/ variable declarations. | 3747 // Parsed for-in loop w/ variable declarations. |
| 3748 if (init_block != nullptr) { | 3748 if (init_block != nullptr) { |
| 3749 init_block->AddStatement(loop, zone()); | 3749 init_block->statements()->Add(loop, zone()); |
| 3750 if (for_scope != nullptr) { | 3750 if (for_scope != nullptr) { |
| 3751 init_block->set_scope(for_scope); | 3751 init_block->set_scope(for_scope); |
| 3752 } | 3752 } |
| 3753 return init_block; | 3753 return init_block; |
| 3754 } else { | 3754 } else { |
| 3755 DCHECK_NULL(for_scope); | 3755 DCHECK_NULL(for_scope); |
| 3756 return loop; | 3756 return loop; |
| 3757 } | 3757 } |
| 3758 } else { | 3758 } else { |
| 3759 init = parsing_result.BuildInitializationBlock( | 3759 init = parsing_result.BuildInitializationBlock( |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3857 // | 3857 // |
| 3858 // into | 3858 // into |
| 3859 // | 3859 // |
| 3860 // { | 3860 // { |
| 3861 // const x = i; | 3861 // const x = i; |
| 3862 // for (; c; n) b | 3862 // for (; c; n) b |
| 3863 // } | 3863 // } |
| 3864 DCHECK(init != NULL); | 3864 DCHECK(init != NULL); |
| 3865 Block* block = | 3865 Block* block = |
| 3866 factory()->NewBlock(NULL, 2, false, RelocInfo::kNoPosition); | 3866 factory()->NewBlock(NULL, 2, false, RelocInfo::kNoPosition); |
| 3867 block->AddStatement(init, zone()); | 3867 block->statements()->Add(init, zone()); |
| 3868 block->AddStatement(loop, zone()); | 3868 block->statements()->Add(loop, zone()); |
| 3869 block->set_scope(for_scope); | 3869 block->set_scope(for_scope); |
| 3870 loop->Initialize(NULL, cond, next, body); | 3870 loop->Initialize(NULL, cond, next, body); |
| 3871 result = block; | 3871 result = block; |
| 3872 } else { | 3872 } else { |
| 3873 loop->Initialize(init, cond, next, body); | 3873 loop->Initialize(init, cond, next, body); |
| 3874 result = loop; | 3874 result = loop; |
| 3875 } | 3875 } |
| 3876 } | 3876 } |
| 3877 return result; | 3877 return result; |
| 3878 } | 3878 } |
| (...skipping 658 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4537 zone()); | 4537 zone()); |
| 4538 | 4538 |
| 4539 auto body = factory()->NewExpressionStatement( | 4539 auto body = factory()->NewExpressionStatement( |
| 4540 factory()->NewCallRuntime(Runtime::kAppendElement, | 4540 factory()->NewCallRuntime(Runtime::kAppendElement, |
| 4541 append_element_args, | 4541 append_element_args, |
| 4542 RelocInfo::kNoPosition), | 4542 RelocInfo::kNoPosition), |
| 4543 RelocInfo::kNoPosition); | 4543 RelocInfo::kNoPosition); |
| 4544 | 4544 |
| 4545 loop->Initialize(init, cond, next, body); | 4545 loop->Initialize(init, cond, next, body); |
| 4546 | 4546 |
| 4547 init_block->AddStatement( | 4547 init_block->statements()->Add( |
| 4548 factory()->NewExpressionStatement(init_array, RelocInfo::kNoPosition), | 4548 factory()->NewExpressionStatement(init_array, RelocInfo::kNoPosition), |
| 4549 zone()); | 4549 zone()); |
| 4550 | 4550 |
| 4551 init_block->AddStatement(loop, zone()); | 4551 init_block->statements()->Add(loop, zone()); |
| 4552 | 4552 |
| 4553 descriptor.initialization_pos = pos; | 4553 descriptor.initialization_pos = pos; |
| 4554 } | 4554 } |
| 4555 | 4555 |
| 4556 Scope* param_scope = scope_; | 4556 Scope* param_scope = scope_; |
| 4557 Block* param_block = init_block; | 4557 Block* param_block = init_block; |
| 4558 if (!parameter.is_simple() && scope_->calls_sloppy_eval()) { | 4558 if (!parameter.is_simple() && scope_->calls_sloppy_eval()) { |
| 4559 param_scope = NewScope(scope_, BLOCK_SCOPE); | 4559 param_scope = NewScope(scope_, BLOCK_SCOPE); |
| 4560 param_scope->set_is_declaration_scope(); | 4560 param_scope->set_is_declaration_scope(); |
| 4561 param_scope->set_start_position(parameter.pattern->position()); | 4561 param_scope->set_start_position(parameter.pattern->position()); |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 4572 parameter.pattern, parameter.pattern->position(), initial_value); | 4572 parameter.pattern, parameter.pattern->position(), initial_value); |
| 4573 PatternRewriter::DeclareAndInitializeVariables(param_block, &descriptor, | 4573 PatternRewriter::DeclareAndInitializeVariables(param_block, &descriptor, |
| 4574 &decl, nullptr, CHECK_OK); | 4574 &decl, nullptr, CHECK_OK); |
| 4575 } | 4575 } |
| 4576 | 4576 |
| 4577 if (!parameter.is_simple() && scope_->calls_sloppy_eval()) { | 4577 if (!parameter.is_simple() && scope_->calls_sloppy_eval()) { |
| 4578 param_scope = param_scope->FinalizeBlockScope(); | 4578 param_scope = param_scope->FinalizeBlockScope(); |
| 4579 if (param_scope != nullptr) { | 4579 if (param_scope != nullptr) { |
| 4580 CheckConflictingVarDeclarations(param_scope, CHECK_OK); | 4580 CheckConflictingVarDeclarations(param_scope, CHECK_OK); |
| 4581 } | 4581 } |
| 4582 init_block->AddStatement(param_block, zone()); | 4582 init_block->statements()->Add(param_block, zone()); |
| 4583 } | 4583 } |
| 4584 } | 4584 } |
| 4585 return init_block; | 4585 return init_block; |
| 4586 } | 4586 } |
| 4587 | 4587 |
| 4588 | 4588 |
| 4589 ZoneList<Statement*>* Parser::ParseEagerFunctionBody( | 4589 ZoneList<Statement*>* Parser::ParseEagerFunctionBody( |
| 4590 const AstRawString* function_name, int pos, | 4590 const AstRawString* function_name, int pos, |
| 4591 const ParserFormalParameters& parameters, FunctionKind kind, | 4591 const ParserFormalParameters& parameters, FunctionKind kind, |
| 4592 FunctionLiteral::FunctionType function_type, bool* ok) { | 4592 FunctionLiteral::FunctionType function_type, bool* ok) { |
| (...skipping 1701 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 6294 | 6294 |
| 6295 Expression* Parser::SpreadCallNew(Expression* function, | 6295 Expression* Parser::SpreadCallNew(Expression* function, |
| 6296 ZoneList<v8::internal::Expression*>* args, | 6296 ZoneList<v8::internal::Expression*>* args, |
| 6297 int pos) { | 6297 int pos) { |
| 6298 args->InsertAt(0, function, zone()); | 6298 args->InsertAt(0, function, zone()); |
| 6299 | 6299 |
| 6300 return factory()->NewCallRuntime(Context::REFLECT_CONSTRUCT_INDEX, args, pos); | 6300 return factory()->NewCallRuntime(Context::REFLECT_CONSTRUCT_INDEX, args, pos); |
| 6301 } | 6301 } |
| 6302 } // namespace internal | 6302 } // namespace internal |
| 6303 } // namespace v8 | 6303 } // namespace v8 |
| OLD | NEW |