| 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 6654 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6665 // Returns ast nodes of the variable initialization. | 6665 // Returns ast nodes of the variable initialization. |
| 6666 AstNode* Parser::ParseVariableDeclaration(const AbstractType& type, | 6666 AstNode* Parser::ParseVariableDeclaration(const AbstractType& type, |
| 6667 bool is_final, | 6667 bool is_final, |
| 6668 bool is_const, | 6668 bool is_const, |
| 6669 SequenceNode** await_preamble) { | 6669 SequenceNode** await_preamble) { |
| 6670 TRACE_PARSER("ParseVariableDeclaration"); | 6670 TRACE_PARSER("ParseVariableDeclaration"); |
| 6671 ASSERT(IsIdentifier()); | 6671 ASSERT(IsIdentifier()); |
| 6672 const intptr_t ident_pos = TokenPos(); | 6672 const intptr_t ident_pos = TokenPos(); |
| 6673 const String& ident = *CurrentLiteral(); | 6673 const String& ident = *CurrentLiteral(); |
| 6674 ConsumeToken(); // Variable identifier. | 6674 ConsumeToken(); // Variable identifier. |
| 6675 const intptr_t assign_pos = TokenPos(); |
| 6675 AstNode* initialization = NULL; | 6676 AstNode* initialization = NULL; |
| 6676 LocalVariable* variable = NULL; | 6677 LocalVariable* variable = NULL; |
| 6677 if (CurrentToken() == Token::kASSIGN) { | 6678 if (CurrentToken() == Token::kASSIGN) { |
| 6678 // Variable initialization. | 6679 // Variable initialization. |
| 6679 const intptr_t assign_pos = TokenPos(); | |
| 6680 ConsumeToken(); | 6680 ConsumeToken(); |
| 6681 AstNode* expr = ParseAwaitableExpr( | 6681 AstNode* expr = ParseAwaitableExpr( |
| 6682 is_const, kConsumeCascades, await_preamble); | 6682 is_const, kConsumeCascades, await_preamble); |
| 6683 const intptr_t expr_end_pos = TokenPos(); | 6683 const intptr_t expr_end_pos = TokenPos(); |
| 6684 variable = new(Z) LocalVariable( | 6684 variable = new(Z) LocalVariable( |
| 6685 expr_end_pos, ident, type); | 6685 expr_end_pos, ident, type); |
| 6686 initialization = new(Z) StoreLocalNode( | 6686 initialization = new(Z) StoreLocalNode( |
| 6687 assign_pos, variable, expr); | 6687 assign_pos, variable, expr); |
| 6688 if (is_const) { | 6688 if (is_const) { |
| 6689 ASSERT(expr->IsLiteralNode()); | 6689 ASSERT(expr->IsLiteralNode()); |
| 6690 variable->SetConstValue(expr->AsLiteralNode()->literal()); | 6690 variable->SetConstValue(expr->AsLiteralNode()->literal()); |
| 6691 } | 6691 } |
| 6692 } else if (is_final || is_const) { | 6692 } else if (is_final || is_const) { |
| 6693 ReportError(ident_pos, | 6693 ReportError(ident_pos, |
| 6694 "missing initialization of 'final' or 'const' variable"); | 6694 "missing initialization of 'final' or 'const' variable"); |
| 6695 } else { | 6695 } else { |
| 6696 // Initialize variable with null. | 6696 // Initialize variable with null. |
| 6697 variable = new(Z) LocalVariable( | 6697 variable = new(Z) LocalVariable( |
| 6698 ident_pos, ident, type); | 6698 assign_pos, ident, type); |
| 6699 AstNode* null_expr = new(Z) LiteralNode(ident_pos, Instance::ZoneHandle(Z)); | 6699 AstNode* null_expr = new(Z) LiteralNode(ident_pos, Instance::ZoneHandle(Z)); |
| 6700 initialization = new(Z) StoreLocalNode( | 6700 initialization = new(Z) StoreLocalNode( |
| 6701 ident_pos, variable, null_expr); | 6701 ident_pos, variable, null_expr); |
| 6702 } | 6702 } |
| 6703 | 6703 |
| 6704 ASSERT(current_block_ != NULL); | 6704 ASSERT(current_block_ != NULL); |
| 6705 const intptr_t previous_pos = | 6705 const intptr_t previous_pos = |
| 6706 current_block_->scope->PreviousReferencePos(ident); | 6706 current_block_->scope->PreviousReferencePos(ident); |
| 6707 if (previous_pos >= 0) { | 6707 if (previous_pos >= 0) { |
| 6708 ASSERT(!script_.IsNull()); | 6708 ASSERT(!script_.IsNull()); |
| (...skipping 5848 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 12557 void Parser::SkipQualIdent() { | 12557 void Parser::SkipQualIdent() { |
| 12558 ASSERT(IsIdentifier()); | 12558 ASSERT(IsIdentifier()); |
| 12559 ConsumeToken(); | 12559 ConsumeToken(); |
| 12560 if (CurrentToken() == Token::kPERIOD) { | 12560 if (CurrentToken() == Token::kPERIOD) { |
| 12561 ConsumeToken(); // Consume the kPERIOD token. | 12561 ConsumeToken(); // Consume the kPERIOD token. |
| 12562 ExpectIdentifier("identifier expected after '.'"); | 12562 ExpectIdentifier("identifier expected after '.'"); |
| 12563 } | 12563 } |
| 12564 } | 12564 } |
| 12565 | 12565 |
| 12566 } // namespace dart | 12566 } // namespace dart |
| OLD | NEW |