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/v8.h" | 5 #include "src/v8.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/bailout-reason.h" | 9 #include "src/bailout-reason.h" |
10 #include "src/base/platform/platform.h" | 10 #include "src/base/platform/platform.h" |
(...skipping 1624 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1635 } | 1635 } |
1636 | 1636 |
1637 DCHECK(result != NULL); | 1637 DCHECK(result != NULL); |
1638 return result; | 1638 return result; |
1639 } | 1639 } |
1640 | 1640 |
1641 | 1641 |
1642 Statement* Parser::ParseStatement(ZoneList<const AstRawString*>* labels, | 1642 Statement* Parser::ParseStatement(ZoneList<const AstRawString*>* labels, |
1643 bool* ok) { | 1643 bool* ok) { |
1644 // Statement :: | 1644 // Statement :: |
| 1645 // EmptyStatement |
| 1646 // ... |
| 1647 |
| 1648 if (peek() == Token::SEMICOLON) { |
| 1649 Next(); |
| 1650 return factory()->NewEmptyStatement(RelocInfo::kNoPosition); |
| 1651 } |
| 1652 return ParseSubStatement(labels, ok); |
| 1653 } |
| 1654 |
| 1655 |
| 1656 Statement* Parser::ParseSubStatement(ZoneList<const AstRawString*>* labels, |
| 1657 bool* ok) { |
| 1658 // Statement :: |
1645 // Block | 1659 // Block |
1646 // VariableStatement | 1660 // VariableStatement |
1647 // EmptyStatement | 1661 // EmptyStatement |
1648 // ExpressionStatement | 1662 // ExpressionStatement |
1649 // IfStatement | 1663 // IfStatement |
1650 // IterationStatement | 1664 // IterationStatement |
1651 // ContinueStatement | 1665 // ContinueStatement |
1652 // BreakStatement | 1666 // BreakStatement |
1653 // ReturnStatement | 1667 // ReturnStatement |
1654 // WithStatement | 1668 // WithStatement |
1655 // LabelledStatement | 1669 // LabelledStatement |
1656 // SwitchStatement | 1670 // SwitchStatement |
1657 // ThrowStatement | 1671 // ThrowStatement |
1658 // TryStatement | 1672 // TryStatement |
1659 // DebuggerStatement | 1673 // DebuggerStatement |
1660 | 1674 |
1661 // Note: Since labels can only be used by 'break' and 'continue' | 1675 // Note: Since labels can only be used by 'break' and 'continue' |
1662 // statements, which themselves are only valid within blocks, | 1676 // statements, which themselves are only valid within blocks, |
1663 // iterations or 'switch' statements (i.e., BreakableStatements), | 1677 // iterations or 'switch' statements (i.e., BreakableStatements), |
1664 // labels can be simply ignored in all other cases; except for | 1678 // labels can be simply ignored in all other cases; except for |
1665 // trivial labeled break statements 'label: break label' which is | 1679 // trivial labeled break statements 'label: break label' which is |
1666 // parsed into an empty statement. | 1680 // parsed into an empty statement. |
1667 switch (peek()) { | 1681 switch (peek()) { |
1668 case Token::LBRACE: | 1682 case Token::LBRACE: |
1669 return ParseBlock(labels, ok); | 1683 return ParseBlock(labels, ok); |
1670 | 1684 |
1671 case Token::SEMICOLON: | 1685 case Token::SEMICOLON: |
| 1686 if (is_strong(language_mode())) { |
| 1687 ReportMessageAt(scanner()->peek_location(), "strong_empty"); |
| 1688 *ok = false; |
| 1689 return NULL; |
| 1690 } |
1672 Next(); | 1691 Next(); |
1673 return factory()->NewEmptyStatement(RelocInfo::kNoPosition); | 1692 return factory()->NewEmptyStatement(RelocInfo::kNoPosition); |
1674 | 1693 |
1675 case Token::IF: | 1694 case Token::IF: |
1676 return ParseIfStatement(labels, ok); | 1695 return ParseIfStatement(labels, ok); |
1677 | 1696 |
1678 case Token::DO: | 1697 case Token::DO: |
1679 return ParseDoWhileStatement(labels, ok); | 1698 return ParseDoWhileStatement(labels, ok); |
1680 | 1699 |
1681 case Token::WHILE: | 1700 case Token::WHILE: |
(...skipping 846 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2528 IfStatement* Parser::ParseIfStatement(ZoneList<const AstRawString*>* labels, | 2547 IfStatement* Parser::ParseIfStatement(ZoneList<const AstRawString*>* labels, |
2529 bool* ok) { | 2548 bool* ok) { |
2530 // IfStatement :: | 2549 // IfStatement :: |
2531 // 'if' '(' Expression ')' Statement ('else' Statement)? | 2550 // 'if' '(' Expression ')' Statement ('else' Statement)? |
2532 | 2551 |
2533 int pos = peek_position(); | 2552 int pos = peek_position(); |
2534 Expect(Token::IF, CHECK_OK); | 2553 Expect(Token::IF, CHECK_OK); |
2535 Expect(Token::LPAREN, CHECK_OK); | 2554 Expect(Token::LPAREN, CHECK_OK); |
2536 Expression* condition = ParseExpression(true, CHECK_OK); | 2555 Expression* condition = ParseExpression(true, CHECK_OK); |
2537 Expect(Token::RPAREN, CHECK_OK); | 2556 Expect(Token::RPAREN, CHECK_OK); |
2538 Statement* then_statement = ParseStatement(labels, CHECK_OK); | 2557 Statement* then_statement = ParseSubStatement(labels, CHECK_OK); |
2539 Statement* else_statement = NULL; | 2558 Statement* else_statement = NULL; |
2540 if (peek() == Token::ELSE) { | 2559 if (peek() == Token::ELSE) { |
2541 Next(); | 2560 Next(); |
2542 else_statement = ParseStatement(labels, CHECK_OK); | 2561 else_statement = ParseSubStatement(labels, CHECK_OK); |
2543 } else { | 2562 } else { |
2544 else_statement = factory()->NewEmptyStatement(RelocInfo::kNoPosition); | 2563 else_statement = factory()->NewEmptyStatement(RelocInfo::kNoPosition); |
2545 } | 2564 } |
2546 return factory()->NewIfStatement( | 2565 return factory()->NewIfStatement( |
2547 condition, then_statement, else_statement, pos); | 2566 condition, then_statement, else_statement, pos); |
2548 } | 2567 } |
2549 | 2568 |
2550 | 2569 |
2551 Statement* Parser::ParseContinueStatement(bool* ok) { | 2570 Statement* Parser::ParseContinueStatement(bool* ok) { |
2552 // ContinueStatement :: | 2571 // ContinueStatement :: |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2677 | 2696 |
2678 Expect(Token::LPAREN, CHECK_OK); | 2697 Expect(Token::LPAREN, CHECK_OK); |
2679 Expression* expr = ParseExpression(true, CHECK_OK); | 2698 Expression* expr = ParseExpression(true, CHECK_OK); |
2680 Expect(Token::RPAREN, CHECK_OK); | 2699 Expect(Token::RPAREN, CHECK_OK); |
2681 | 2700 |
2682 scope_->DeclarationScope()->RecordWithStatement(); | 2701 scope_->DeclarationScope()->RecordWithStatement(); |
2683 Scope* with_scope = NewScope(scope_, WITH_SCOPE); | 2702 Scope* with_scope = NewScope(scope_, WITH_SCOPE); |
2684 Statement* stmt; | 2703 Statement* stmt; |
2685 { BlockState block_state(&scope_, with_scope); | 2704 { BlockState block_state(&scope_, with_scope); |
2686 with_scope->set_start_position(scanner()->peek_location().beg_pos); | 2705 with_scope->set_start_position(scanner()->peek_location().beg_pos); |
2687 stmt = ParseStatement(labels, CHECK_OK); | 2706 stmt = ParseSubStatement(labels, CHECK_OK); |
2688 with_scope->set_end_position(scanner()->location().end_pos); | 2707 with_scope->set_end_position(scanner()->location().end_pos); |
2689 } | 2708 } |
2690 return factory()->NewWithStatement(with_scope, expr, stmt, pos); | 2709 return factory()->NewWithStatement(with_scope, expr, stmt, pos); |
2691 } | 2710 } |
2692 | 2711 |
2693 | 2712 |
2694 CaseClause* Parser::ParseCaseClause(bool* default_seen_ptr, bool* ok) { | 2713 CaseClause* Parser::ParseCaseClause(bool* default_seen_ptr, bool* ok) { |
2695 // CaseClause :: | 2714 // CaseClause :: |
2696 // 'case' Expression ':' Statement* | 2715 // 'case' Expression ':' Statement* |
2697 // 'default' ':' Statement* | 2716 // 'default' ':' Statement* |
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2862 DoWhileStatement* Parser::ParseDoWhileStatement( | 2881 DoWhileStatement* Parser::ParseDoWhileStatement( |
2863 ZoneList<const AstRawString*>* labels, bool* ok) { | 2882 ZoneList<const AstRawString*>* labels, bool* ok) { |
2864 // DoStatement :: | 2883 // DoStatement :: |
2865 // 'do' Statement 'while' '(' Expression ')' ';' | 2884 // 'do' Statement 'while' '(' Expression ')' ';' |
2866 | 2885 |
2867 DoWhileStatement* loop = | 2886 DoWhileStatement* loop = |
2868 factory()->NewDoWhileStatement(labels, peek_position()); | 2887 factory()->NewDoWhileStatement(labels, peek_position()); |
2869 Target target(&this->target_stack_, loop); | 2888 Target target(&this->target_stack_, loop); |
2870 | 2889 |
2871 Expect(Token::DO, CHECK_OK); | 2890 Expect(Token::DO, CHECK_OK); |
2872 Statement* body = ParseStatement(NULL, CHECK_OK); | 2891 Statement* body = ParseSubStatement(NULL, CHECK_OK); |
2873 Expect(Token::WHILE, CHECK_OK); | 2892 Expect(Token::WHILE, CHECK_OK); |
2874 Expect(Token::LPAREN, CHECK_OK); | 2893 Expect(Token::LPAREN, CHECK_OK); |
2875 | 2894 |
2876 Expression* cond = ParseExpression(true, CHECK_OK); | 2895 Expression* cond = ParseExpression(true, CHECK_OK); |
2877 Expect(Token::RPAREN, CHECK_OK); | 2896 Expect(Token::RPAREN, CHECK_OK); |
2878 | 2897 |
2879 // Allow do-statements to be terminated with and without | 2898 // Allow do-statements to be terminated with and without |
2880 // semi-colons. This allows code such as 'do;while(0)return' to | 2899 // semi-colons. This allows code such as 'do;while(0)return' to |
2881 // parse, which would not be the case if we had used the | 2900 // parse, which would not be the case if we had used the |
2882 // ExpectSemicolon() functionality here. | 2901 // ExpectSemicolon() functionality here. |
2883 if (peek() == Token::SEMICOLON) Consume(Token::SEMICOLON); | 2902 if (peek() == Token::SEMICOLON) Consume(Token::SEMICOLON); |
2884 | 2903 |
2885 if (loop != NULL) loop->Initialize(cond, body); | 2904 if (loop != NULL) loop->Initialize(cond, body); |
2886 return loop; | 2905 return loop; |
2887 } | 2906 } |
2888 | 2907 |
2889 | 2908 |
2890 WhileStatement* Parser::ParseWhileStatement( | 2909 WhileStatement* Parser::ParseWhileStatement( |
2891 ZoneList<const AstRawString*>* labels, bool* ok) { | 2910 ZoneList<const AstRawString*>* labels, bool* ok) { |
2892 // WhileStatement :: | 2911 // WhileStatement :: |
2893 // 'while' '(' Expression ')' Statement | 2912 // 'while' '(' Expression ')' Statement |
2894 | 2913 |
2895 WhileStatement* loop = factory()->NewWhileStatement(labels, peek_position()); | 2914 WhileStatement* loop = factory()->NewWhileStatement(labels, peek_position()); |
2896 Target target(&this->target_stack_, loop); | 2915 Target target(&this->target_stack_, loop); |
2897 | 2916 |
2898 Expect(Token::WHILE, CHECK_OK); | 2917 Expect(Token::WHILE, CHECK_OK); |
2899 Expect(Token::LPAREN, CHECK_OK); | 2918 Expect(Token::LPAREN, CHECK_OK); |
2900 Expression* cond = ParseExpression(true, CHECK_OK); | 2919 Expression* cond = ParseExpression(true, CHECK_OK); |
2901 Expect(Token::RPAREN, CHECK_OK); | 2920 Expect(Token::RPAREN, CHECK_OK); |
2902 Statement* body = ParseStatement(NULL, CHECK_OK); | 2921 Statement* body = ParseSubStatement(NULL, CHECK_OK); |
2903 | 2922 |
2904 if (loop != NULL) loop->Initialize(cond, body); | 2923 if (loop != NULL) loop->Initialize(cond, body); |
2905 return loop; | 2924 return loop; |
2906 } | 2925 } |
2907 | 2926 |
2908 | 2927 |
2909 bool Parser::CheckInOrOf(bool accept_OF, | 2928 bool Parser::CheckInOrOf(bool accept_OF, |
2910 ForEachStatement::VisitMode* visit_mode) { | 2929 ForEachStatement::VisitMode* visit_mode) { |
2911 if (Check(Token::IN)) { | 2930 if (Check(Token::IN)) { |
2912 *visit_mode = ForEachStatement::ENUMERATE; | 2931 *visit_mode = ForEachStatement::ENUMERATE; |
(...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3255 is_const ? Interface::NewConst() : Interface::NewValue(); | 3274 is_const ? Interface::NewConst() : Interface::NewValue(); |
3256 ForEachStatement* loop = | 3275 ForEachStatement* loop = |
3257 factory()->NewForEachStatement(mode, labels, stmt_pos); | 3276 factory()->NewForEachStatement(mode, labels, stmt_pos); |
3258 Target target(&this->target_stack_, loop); | 3277 Target target(&this->target_stack_, loop); |
3259 | 3278 |
3260 Expression* enumerable = ParseExpression(true, CHECK_OK); | 3279 Expression* enumerable = ParseExpression(true, CHECK_OK); |
3261 Expect(Token::RPAREN, CHECK_OK); | 3280 Expect(Token::RPAREN, CHECK_OK); |
3262 | 3281 |
3263 VariableProxy* each = | 3282 VariableProxy* each = |
3264 scope_->NewUnresolved(factory(), name, interface, each_pos); | 3283 scope_->NewUnresolved(factory(), name, interface, each_pos); |
3265 Statement* body = ParseStatement(NULL, CHECK_OK); | 3284 Statement* body = ParseSubStatement(NULL, CHECK_OK); |
3266 InitializeForEachStatement(loop, each, enumerable, body); | 3285 InitializeForEachStatement(loop, each, enumerable, body); |
3267 Block* result = | 3286 Block* result = |
3268 factory()->NewBlock(NULL, 2, false, RelocInfo::kNoPosition); | 3287 factory()->NewBlock(NULL, 2, false, RelocInfo::kNoPosition); |
3269 result->AddStatement(variable_statement, zone()); | 3288 result->AddStatement(variable_statement, zone()); |
3270 result->AddStatement(loop, zone()); | 3289 result->AddStatement(loop, zone()); |
3271 scope_ = saved_scope; | 3290 scope_ = saved_scope; |
3272 for_scope->set_end_position(scanner()->location().end_pos); | 3291 for_scope->set_end_position(scanner()->location().end_pos); |
3273 for_scope = for_scope->FinalizeBlockScope(); | 3292 for_scope = for_scope->FinalizeBlockScope(); |
3274 DCHECK(for_scope == NULL); | 3293 DCHECK(for_scope == NULL); |
3275 // Parsed for-in loop w/ variable/const declaration. | 3294 // Parsed for-in loop w/ variable/const declaration. |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3314 Target target(&this->target_stack_, loop); | 3333 Target target(&this->target_stack_, loop); |
3315 | 3334 |
3316 // The expression does not see the loop variable. | 3335 // The expression does not see the loop variable. |
3317 scope_ = saved_scope; | 3336 scope_ = saved_scope; |
3318 Expression* enumerable = ParseExpression(true, CHECK_OK); | 3337 Expression* enumerable = ParseExpression(true, CHECK_OK); |
3319 scope_ = for_scope; | 3338 scope_ = for_scope; |
3320 Expect(Token::RPAREN, CHECK_OK); | 3339 Expect(Token::RPAREN, CHECK_OK); |
3321 | 3340 |
3322 VariableProxy* each = scope_->NewUnresolved( | 3341 VariableProxy* each = scope_->NewUnresolved( |
3323 factory(), name, Interface::NewValue(), each_pos); | 3342 factory(), name, Interface::NewValue(), each_pos); |
3324 Statement* body = ParseStatement(NULL, CHECK_OK); | 3343 Statement* body = ParseSubStatement(NULL, CHECK_OK); |
3325 Block* body_block = | 3344 Block* body_block = |
3326 factory()->NewBlock(NULL, 3, false, RelocInfo::kNoPosition); | 3345 factory()->NewBlock(NULL, 3, false, RelocInfo::kNoPosition); |
3327 Token::Value init_op = is_const ? Token::INIT_CONST : Token::ASSIGN; | 3346 Token::Value init_op = is_const ? Token::INIT_CONST : Token::ASSIGN; |
3328 Assignment* assignment = factory()->NewAssignment( | 3347 Assignment* assignment = factory()->NewAssignment( |
3329 init_op, each, temp_proxy, RelocInfo::kNoPosition); | 3348 init_op, each, temp_proxy, RelocInfo::kNoPosition); |
3330 Statement* assignment_statement = factory()->NewExpressionStatement( | 3349 Statement* assignment_statement = factory()->NewExpressionStatement( |
3331 assignment, RelocInfo::kNoPosition); | 3350 assignment, RelocInfo::kNoPosition); |
3332 body_block->AddStatement(variable_statement, zone()); | 3351 body_block->AddStatement(variable_statement, zone()); |
3333 body_block->AddStatement(assignment_statement, zone()); | 3352 body_block->AddStatement(assignment_statement, zone()); |
3334 body_block->AddStatement(body, zone()); | 3353 body_block->AddStatement(body, zone()); |
(...skipping 22 matching lines...) Expand all Loading... |
3357 expression = this->CheckAndRewriteReferenceExpression( | 3376 expression = this->CheckAndRewriteReferenceExpression( |
3358 expression, lhs_location, "invalid_lhs_in_for", CHECK_OK); | 3377 expression, lhs_location, "invalid_lhs_in_for", CHECK_OK); |
3359 | 3378 |
3360 ForEachStatement* loop = | 3379 ForEachStatement* loop = |
3361 factory()->NewForEachStatement(mode, labels, stmt_pos); | 3380 factory()->NewForEachStatement(mode, labels, stmt_pos); |
3362 Target target(&this->target_stack_, loop); | 3381 Target target(&this->target_stack_, loop); |
3363 | 3382 |
3364 Expression* enumerable = ParseExpression(true, CHECK_OK); | 3383 Expression* enumerable = ParseExpression(true, CHECK_OK); |
3365 Expect(Token::RPAREN, CHECK_OK); | 3384 Expect(Token::RPAREN, CHECK_OK); |
3366 | 3385 |
3367 Statement* body = ParseStatement(NULL, CHECK_OK); | 3386 Statement* body = ParseSubStatement(NULL, CHECK_OK); |
3368 InitializeForEachStatement(loop, expression, enumerable, body); | 3387 InitializeForEachStatement(loop, expression, enumerable, body); |
3369 scope_ = saved_scope; | 3388 scope_ = saved_scope; |
3370 for_scope->set_end_position(scanner()->location().end_pos); | 3389 for_scope->set_end_position(scanner()->location().end_pos); |
3371 for_scope = for_scope->FinalizeBlockScope(); | 3390 for_scope = for_scope->FinalizeBlockScope(); |
3372 DCHECK(for_scope == NULL); | 3391 DCHECK(for_scope == NULL); |
3373 // Parsed for-in loop. | 3392 // Parsed for-in loop. |
3374 return loop; | 3393 return loop; |
3375 | 3394 |
3376 } else { | 3395 } else { |
3377 init = factory()->NewExpressionStatement(expression, position()); | 3396 init = factory()->NewExpressionStatement(expression, position()); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3409 Expect(Token::SEMICOLON, CHECK_OK); | 3428 Expect(Token::SEMICOLON, CHECK_OK); |
3410 | 3429 |
3411 Statement* next = NULL; | 3430 Statement* next = NULL; |
3412 if (peek() != Token::RPAREN) { | 3431 if (peek() != Token::RPAREN) { |
3413 int next_pos = position(); | 3432 int next_pos = position(); |
3414 Expression* exp = ParseExpression(true, CHECK_OK); | 3433 Expression* exp = ParseExpression(true, CHECK_OK); |
3415 next = factory()->NewExpressionStatement(exp, next_pos); | 3434 next = factory()->NewExpressionStatement(exp, next_pos); |
3416 } | 3435 } |
3417 Expect(Token::RPAREN, CHECK_OK); | 3436 Expect(Token::RPAREN, CHECK_OK); |
3418 | 3437 |
3419 Statement* body = ParseStatement(NULL, CHECK_OK); | 3438 Statement* body = ParseSubStatement(NULL, CHECK_OK); |
3420 | 3439 |
3421 Statement* result = NULL; | 3440 Statement* result = NULL; |
3422 if (let_bindings.length() > 0) { | 3441 if (let_bindings.length() > 0) { |
3423 scope_ = for_scope; | 3442 scope_ = for_scope; |
3424 result = DesugarLetBindingsInForStatement(inner_scope, &let_bindings, loop, | 3443 result = DesugarLetBindingsInForStatement(inner_scope, &let_bindings, loop, |
3425 init, cond, next, body, CHECK_OK); | 3444 init, cond, next, body, CHECK_OK); |
3426 scope_ = saved_scope; | 3445 scope_ = saved_scope; |
3427 for_scope->set_end_position(scanner()->location().end_pos); | 3446 for_scope->set_end_position(scanner()->location().end_pos); |
3428 } else { | 3447 } else { |
3429 scope_ = saved_scope; | 3448 scope_ = saved_scope; |
(...skipping 2044 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5474 } else { | 5493 } else { |
5475 const uc16* data = reinterpret_cast<const uc16*>(raw_string->raw_data()); | 5494 const uc16* data = reinterpret_cast<const uc16*>(raw_string->raw_data()); |
5476 running_hash = StringHasher::ComputeRunningHash(running_hash, data, | 5495 running_hash = StringHasher::ComputeRunningHash(running_hash, data, |
5477 raw_string->length()); | 5496 raw_string->length()); |
5478 } | 5497 } |
5479 } | 5498 } |
5480 | 5499 |
5481 return running_hash; | 5500 return running_hash; |
5482 } | 5501 } |
5483 } } // namespace v8::internal | 5502 } } // namespace v8::internal |
OLD | NEW |