| 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 "vm/bigint_operations.h" | 8 #include "vm/bigint_operations.h" |
| 9 #include "vm/bootstrap.h" | 9 #include "vm/bootstrap.h" |
| 10 #include "vm/class_finalizer.h" | 10 #include "vm/class_finalizer.h" |
| (...skipping 5122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5133 ErrorMsg(ident_pos, | 5133 ErrorMsg(ident_pos, |
| 5134 "missing initialization of 'final' or 'const' variable"); | 5134 "missing initialization of 'final' or 'const' variable"); |
| 5135 } else { | 5135 } else { |
| 5136 // Initialize variable with null. | 5136 // Initialize variable with null. |
| 5137 AstNode* null_expr = new LiteralNode(ident_pos, Instance::ZoneHandle()); | 5137 AstNode* null_expr = new LiteralNode(ident_pos, Instance::ZoneHandle()); |
| 5138 initialization = new StoreLocalNode(ident_pos, variable, null_expr); | 5138 initialization = new StoreLocalNode(ident_pos, variable, null_expr); |
| 5139 } | 5139 } |
| 5140 // Add variable to scope after parsing the initalizer expression. | 5140 // Add variable to scope after parsing the initalizer expression. |
| 5141 // The expression must not be able to refer to the variable. | 5141 // The expression must not be able to refer to the variable. |
| 5142 if (!current_block_->scope->AddVariable(variable)) { | 5142 if (!current_block_->scope->AddVariable(variable)) { |
| 5143 ErrorMsg(ident_pos, "identifier '%s' already defined", | 5143 LocalVariable* existing_var = |
| 5144 variable->name().ToCString()); | 5144 current_block_->scope->LookupVariable(variable->name(), true); |
| 5145 ASSERT(existing_var != NULL); |
| 5146 if (existing_var->owner() == current_block_->scope) { |
| 5147 ErrorMsg(ident_pos, "identifier '%s' already defined", |
| 5148 variable->name().ToCString()); |
| 5149 } else { |
| 5150 ErrorMsg(ident_pos, |
| 5151 "'%s' from outer scope has already been used, cannot redefine", |
| 5152 variable->name().ToCString()); |
| 5153 } |
| 5145 } | 5154 } |
| 5146 if (is_final || is_const) { | 5155 if (is_final || is_const) { |
| 5147 variable->set_is_final(); | 5156 variable->set_is_final(); |
| 5148 } | 5157 } |
| 5149 return initialization; | 5158 return initialization; |
| 5150 } | 5159 } |
| 5151 | 5160 |
| 5152 | 5161 |
| 5153 // Parses ('var' | 'final' [type] | 'const' [type] | type). | 5162 // Parses ('var' | 'final' [type] | 'const' [type] | type). |
| 5154 // The presence of 'final' or 'const' must be detected and remembered | 5163 // The presence of 'final' or 'const' must be detected and remembered |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5293 | 5302 |
| 5294 // Add the function variable to the scope before parsing the function in | 5303 // Add the function variable to the scope before parsing the function in |
| 5295 // order to allow self reference from inside the function. | 5304 // order to allow self reference from inside the function. |
| 5296 function_variable = new LocalVariable(ident_pos, | 5305 function_variable = new LocalVariable(ident_pos, |
| 5297 *variable_name, | 5306 *variable_name, |
| 5298 function_type); | 5307 function_type); |
| 5299 function_variable->set_is_final(); | 5308 function_variable->set_is_final(); |
| 5300 ASSERT(current_block_ != NULL); | 5309 ASSERT(current_block_ != NULL); |
| 5301 ASSERT(current_block_->scope != NULL); | 5310 ASSERT(current_block_->scope != NULL); |
| 5302 if (!current_block_->scope->AddVariable(function_variable)) { | 5311 if (!current_block_->scope->AddVariable(function_variable)) { |
| 5303 ErrorMsg(ident_pos, "identifier '%s' already defined", | 5312 LocalVariable* existing_var = |
| 5304 function_variable->name().ToCString()); | 5313 current_block_->scope->LookupVariable(function_variable->name(), |
| 5314 true); |
| 5315 ASSERT(existing_var != NULL); |
| 5316 if (existing_var->owner() == current_block_->scope) { |
| 5317 ErrorMsg(ident_pos, "identifier '%s' already defined", |
| 5318 function_variable->name().ToCString()); |
| 5319 } else { |
| 5320 ErrorMsg(ident_pos, |
| 5321 "'%s' from outer scope has already been used, cannot redefine", |
| 5322 function_variable->name().ToCString()); |
| 5323 } |
| 5305 } | 5324 } |
| 5306 } | 5325 } |
| 5307 | 5326 |
| 5308 // Parse the local function. | 5327 // Parse the local function. |
| 5309 Array& default_parameter_values = Array::Handle(); | 5328 Array& default_parameter_values = Array::Handle(); |
| 5310 SequenceNode* statements = Parser::ParseFunc(function, | 5329 SequenceNode* statements = Parser::ParseFunc(function, |
| 5311 default_parameter_values); | 5330 default_parameter_values); |
| 5312 ASSERT(is_new_closure || (function.end_token_pos() == (TokenPos() - 1))); | 5331 ASSERT(is_new_closure || (function.end_token_pos() == (TokenPos() - 1))); |
| 5313 function.set_end_token_pos(TokenPos() - 1); | 5332 function.set_end_token_pos(TokenPos() - 1); |
| 5314 | 5333 |
| (...skipping 4963 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 10278 void Parser::SkipQualIdent() { | 10297 void Parser::SkipQualIdent() { |
| 10279 ASSERT(IsIdentifier()); | 10298 ASSERT(IsIdentifier()); |
| 10280 ConsumeToken(); | 10299 ConsumeToken(); |
| 10281 if (CurrentToken() == Token::kPERIOD) { | 10300 if (CurrentToken() == Token::kPERIOD) { |
| 10282 ConsumeToken(); // Consume the kPERIOD token. | 10301 ConsumeToken(); // Consume the kPERIOD token. |
| 10283 ExpectIdentifier("identifier expected after '.'"); | 10302 ExpectIdentifier("identifier expected after '.'"); |
| 10284 } | 10303 } |
| 10285 } | 10304 } |
| 10286 | 10305 |
| 10287 } // namespace dart | 10306 } // namespace dart |
| OLD | NEW |