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 6659 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6670 | 6670 |
6671 // Returns ast nodes of the variable initialization. | 6671 // Returns ast nodes of the variable initialization. |
6672 AstNode* Parser::ParseVariableDeclaration(const AbstractType& type, | 6672 AstNode* Parser::ParseVariableDeclaration(const AbstractType& type, |
6673 bool is_final, | 6673 bool is_final, |
6674 bool is_const, | 6674 bool is_const, |
6675 SequenceNode** await_preamble) { | 6675 SequenceNode** await_preamble) { |
6676 TRACE_PARSER("ParseVariableDeclaration"); | 6676 TRACE_PARSER("ParseVariableDeclaration"); |
6677 ASSERT(IsIdentifier()); | 6677 ASSERT(IsIdentifier()); |
6678 const intptr_t ident_pos = TokenPos(); | 6678 const intptr_t ident_pos = TokenPos(); |
6679 const String& ident = *CurrentLiteral(); | 6679 const String& ident = *CurrentLiteral(); |
6680 LocalVariable* variable = new(Z) LocalVariable( | |
6681 ident_pos, ident, type); | |
6682 ConsumeToken(); // Variable identifier. | 6680 ConsumeToken(); // Variable identifier. |
6683 AstNode* initialization = NULL; | 6681 AstNode* initialization = NULL; |
| 6682 LocalVariable* variable = NULL; |
6684 if (CurrentToken() == Token::kASSIGN) { | 6683 if (CurrentToken() == Token::kASSIGN) { |
6685 // Variable initialization. | 6684 // Variable initialization. |
6686 const intptr_t assign_pos = TokenPos(); | 6685 const intptr_t assign_pos = TokenPos(); |
6687 ConsumeToken(); | 6686 ConsumeToken(); |
6688 AstNode* expr = ParseAwaitableExpr( | 6687 AstNode* expr = ParseAwaitableExpr( |
6689 is_const, kConsumeCascades, await_preamble); | 6688 is_const, kConsumeCascades, await_preamble); |
| 6689 const intptr_t expr_end_pos = TokenPos(); |
| 6690 variable = new(Z) LocalVariable( |
| 6691 expr_end_pos, ident, type); |
6690 initialization = new(Z) StoreLocalNode( | 6692 initialization = new(Z) StoreLocalNode( |
6691 assign_pos, variable, expr); | 6693 assign_pos, variable, expr); |
6692 if (is_const) { | 6694 if (is_const) { |
6693 ASSERT(expr->IsLiteralNode()); | 6695 ASSERT(expr->IsLiteralNode()); |
6694 variable->SetConstValue(expr->AsLiteralNode()->literal()); | 6696 variable->SetConstValue(expr->AsLiteralNode()->literal()); |
6695 } | 6697 } |
6696 } else if (is_final || is_const) { | 6698 } else if (is_final || is_const) { |
6697 ReportError(ident_pos, | 6699 ReportError(ident_pos, |
6698 "missing initialization of 'final' or 'const' variable"); | 6700 "missing initialization of 'final' or 'const' variable"); |
6699 } else { | 6701 } else { |
6700 // Initialize variable with null. | 6702 // Initialize variable with null. |
| 6703 variable = new(Z) LocalVariable( |
| 6704 ident_pos, ident, type); |
6701 AstNode* null_expr = new(Z) LiteralNode(ident_pos, Instance::ZoneHandle(Z)); | 6705 AstNode* null_expr = new(Z) LiteralNode(ident_pos, Instance::ZoneHandle(Z)); |
6702 initialization = new(Z) StoreLocalNode( | 6706 initialization = new(Z) StoreLocalNode( |
6703 ident_pos, variable, null_expr); | 6707 ident_pos, variable, null_expr); |
6704 } | 6708 } |
6705 | 6709 |
6706 ASSERT(current_block_ != NULL); | 6710 ASSERT(current_block_ != NULL); |
6707 const intptr_t previous_pos = | 6711 const intptr_t previous_pos = |
6708 current_block_->scope->PreviousReferencePos(ident); | 6712 current_block_->scope->PreviousReferencePos(ident); |
6709 if (previous_pos >= 0) { | 6713 if (previous_pos >= 0) { |
6710 ASSERT(!script_.IsNull()); | 6714 ASSERT(!script_.IsNull()); |
6711 if (previous_pos > ident_pos) { | 6715 if (previous_pos > ident_pos) { |
6712 ReportError(ident_pos, | 6716 ReportError(ident_pos, |
6713 "initializer of '%s' may not refer to itself", | 6717 "initializer of '%s' may not refer to itself", |
6714 ident.ToCString()); | 6718 ident.ToCString()); |
6715 | 6719 |
6716 } else { | 6720 } else { |
6717 intptr_t line_number; | 6721 intptr_t line_number; |
6718 script_.GetTokenLocation(previous_pos, &line_number, NULL); | 6722 script_.GetTokenLocation(previous_pos, &line_number, NULL); |
(...skipping 5846 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
12565 void Parser::SkipQualIdent() { | 12569 void Parser::SkipQualIdent() { |
12566 ASSERT(IsIdentifier()); | 12570 ASSERT(IsIdentifier()); |
12567 ConsumeToken(); | 12571 ConsumeToken(); |
12568 if (CurrentToken() == Token::kPERIOD) { | 12572 if (CurrentToken() == Token::kPERIOD) { |
12569 ConsumeToken(); // Consume the kPERIOD token. | 12573 ConsumeToken(); // Consume the kPERIOD token. |
12570 ExpectIdentifier("identifier expected after '.'"); | 12574 ExpectIdentifier("identifier expected after '.'"); |
12571 } | 12575 } |
12572 } | 12576 } |
12573 | 12577 |
12574 } // namespace dart | 12578 } // namespace dart |
OLD | NEW |