| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 #include "vm/parser.h" | 5 #include "vm/parser.h" |
| 6 | 6 |
| 7 #include "lib/invocation_mirror.h" | 7 #include "lib/invocation_mirror.h" |
| 8 #include "platform/utils.h" | 8 #include "platform/utils.h" |
| 9 #include "vm/ast_transformer.h" | 9 #include "vm/ast_transformer.h" |
| 10 #include "vm/bootstrap.h" | 10 #include "vm/bootstrap.h" |
| (...skipping 6679 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6690 ASSERT(CurrentToken() == Token::kIF); | 6690 ASSERT(CurrentToken() == Token::kIF); |
| 6691 const intptr_t if_pos = TokenPos(); | 6691 const intptr_t if_pos = TokenPos(); |
| 6692 SourceLabel* label = NULL; | 6692 SourceLabel* label = NULL; |
| 6693 if (label_name != NULL) { | 6693 if (label_name != NULL) { |
| 6694 label = SourceLabel::New(if_pos, label_name, SourceLabel::kStatement); | 6694 label = SourceLabel::New(if_pos, label_name, SourceLabel::kStatement); |
| 6695 OpenBlock(); | 6695 OpenBlock(); |
| 6696 current_block_->scope->AddLabel(label); | 6696 current_block_->scope->AddLabel(label); |
| 6697 } | 6697 } |
| 6698 ConsumeToken(); | 6698 ConsumeToken(); |
| 6699 ExpectToken(Token::kLPAREN); | 6699 ExpectToken(Token::kLPAREN); |
| 6700 AstNode* cond_expr = ParseExpr(kAllowConst, kConsumeCascades); | 6700 AstNode* cond_expr = ParseAwaitableExpr(kAllowConst, kConsumeCascades); |
| 6701 ExpectToken(Token::kRPAREN); | 6701 ExpectToken(Token::kRPAREN); |
| 6702 const bool parsing_loop_body = false; | 6702 const bool parsing_loop_body = false; |
| 6703 SequenceNode* true_branch = ParseNestedStatement(parsing_loop_body, NULL); | 6703 SequenceNode* true_branch = ParseNestedStatement(parsing_loop_body, NULL); |
| 6704 SequenceNode* false_branch = NULL; | 6704 SequenceNode* false_branch = NULL; |
| 6705 if (CurrentToken() == Token::kELSE) { | 6705 if (CurrentToken() == Token::kELSE) { |
| 6706 ConsumeToken(); | 6706 ConsumeToken(); |
| 6707 false_branch = ParseNestedStatement(parsing_loop_body, NULL); | 6707 false_branch = ParseNestedStatement(parsing_loop_body, NULL); |
| 6708 } | 6708 } |
| 6709 AstNode* if_node = new(I) IfNode( | 6709 AstNode* if_node = new(I) IfNode( |
| 6710 if_pos, cond_expr, true_branch, false_branch); | 6710 if_pos, cond_expr, true_branch, false_branch); |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6863 | 6863 |
| 6864 AstNode* Parser::ParseSwitchStatement(String* label_name) { | 6864 AstNode* Parser::ParseSwitchStatement(String* label_name) { |
| 6865 TRACE_PARSER("ParseSwitchStatement"); | 6865 TRACE_PARSER("ParseSwitchStatement"); |
| 6866 ASSERT(CurrentToken() == Token::kSWITCH); | 6866 ASSERT(CurrentToken() == Token::kSWITCH); |
| 6867 const intptr_t switch_pos = TokenPos(); | 6867 const intptr_t switch_pos = TokenPos(); |
| 6868 SourceLabel* label = | 6868 SourceLabel* label = |
| 6869 SourceLabel::New(switch_pos, label_name, SourceLabel::kSwitch); | 6869 SourceLabel::New(switch_pos, label_name, SourceLabel::kSwitch); |
| 6870 ConsumeToken(); | 6870 ConsumeToken(); |
| 6871 ExpectToken(Token::kLPAREN); | 6871 ExpectToken(Token::kLPAREN); |
| 6872 const intptr_t expr_pos = TokenPos(); | 6872 const intptr_t expr_pos = TokenPos(); |
| 6873 AstNode* switch_expr = ParseExpr(kAllowConst, kConsumeCascades); | 6873 AstNode* switch_expr = ParseAwaitableExpr(kAllowConst, kConsumeCascades); |
| 6874 ExpectToken(Token::kRPAREN); | 6874 ExpectToken(Token::kRPAREN); |
| 6875 ExpectToken(Token::kLBRACE); | 6875 ExpectToken(Token::kLBRACE); |
| 6876 OpenBlock(); | 6876 OpenBlock(); |
| 6877 current_block_->scope->AddLabel(label); | 6877 current_block_->scope->AddLabel(label); |
| 6878 | 6878 |
| 6879 // Store switch expression in temporary local variable. The type of the | 6879 // Store switch expression in temporary local variable. The type of the |
| 6880 // variable is set to dynamic. It will later be patched to match the | 6880 // variable is set to dynamic. It will later be patched to match the |
| 6881 // type of the case clause expressions. Therefore, we have to allocate | 6881 // type of the case clause expressions. Therefore, we have to allocate |
| 6882 // a new type representing dynamic and can't reuse the canonical | 6882 // a new type representing dynamic and can't reuse the canonical |
| 6883 // type object for dynamic. | 6883 // type object for dynamic. |
| (...skipping 958 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7842 statement = ParseTryStatement(label_name); | 7842 statement = ParseTryStatement(label_name); |
| 7843 } else if (token == Token::kRETURN) { | 7843 } else if (token == Token::kRETURN) { |
| 7844 const intptr_t return_pos = TokenPos(); | 7844 const intptr_t return_pos = TokenPos(); |
| 7845 ConsumeToken(); | 7845 ConsumeToken(); |
| 7846 if (CurrentToken() != Token::kSEMICOLON) { | 7846 if (CurrentToken() != Token::kSEMICOLON) { |
| 7847 if (current_function().IsConstructor() && | 7847 if (current_function().IsConstructor() && |
| 7848 (current_block_->scope->function_level() == 0)) { | 7848 (current_block_->scope->function_level() == 0)) { |
| 7849 ReportError(return_pos, | 7849 ReportError(return_pos, |
| 7850 "return of a value not allowed in constructors"); | 7850 "return of a value not allowed in constructors"); |
| 7851 } | 7851 } |
| 7852 AstNode* expr = ParseExpr(kAllowConst, kConsumeCascades); | 7852 AstNode* expr = ParseAwaitableExpr(kAllowConst, kConsumeCascades); |
| 7853 statement = new(I) ReturnNode(statement_pos, expr); | 7853 statement = new(I) ReturnNode(statement_pos, expr); |
| 7854 } else { | 7854 } else { |
| 7855 statement = new(I) ReturnNode(statement_pos); | 7855 statement = new(I) ReturnNode(statement_pos); |
| 7856 } | 7856 } |
| 7857 AddNodeForFinallyInlining(statement); | 7857 AddNodeForFinallyInlining(statement); |
| 7858 ExpectSemicolon(); | 7858 ExpectSemicolon(); |
| 7859 } else if (token == Token::kIF) { | 7859 } else if (token == Token::kIF) { |
| 7860 statement = ParseIfStatement(label_name); | 7860 statement = ParseIfStatement(label_name); |
| 7861 } else if (token == Token::kASSERT) { | 7861 } else if (token == Token::kASSERT) { |
| 7862 statement = ParseAssertStatement(); | 7862 statement = ParseAssertStatement(); |
| (...skipping 3657 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 11520 void Parser::SkipQualIdent() { | 11520 void Parser::SkipQualIdent() { |
| 11521 ASSERT(IsIdentifier()); | 11521 ASSERT(IsIdentifier()); |
| 11522 ConsumeToken(); | 11522 ConsumeToken(); |
| 11523 if (CurrentToken() == Token::kPERIOD) { | 11523 if (CurrentToken() == Token::kPERIOD) { |
| 11524 ConsumeToken(); // Consume the kPERIOD token. | 11524 ConsumeToken(); // Consume the kPERIOD token. |
| 11525 ExpectIdentifier("identifier expected after '.'"); | 11525 ExpectIdentifier("identifier expected after '.'"); |
| 11526 } | 11526 } |
| 11527 } | 11527 } |
| 11528 | 11528 |
| 11529 } // namespace dart | 11529 } // namespace dart |
| OLD | NEW |