| 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 5261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5272 String& var_name = *ExpectIdentifier("variable name expected"); | 5272 String& var_name = *ExpectIdentifier("variable name expected"); |
| 5273 | 5273 |
| 5274 if (library_.LookupLocalObject(var_name) != Object::null()) { | 5274 if (library_.LookupLocalObject(var_name) != Object::null()) { |
| 5275 ReportError(name_pos, "'%s' is already defined", var_name.ToCString()); | 5275 ReportError(name_pos, "'%s' is already defined", var_name.ToCString()); |
| 5276 } | 5276 } |
| 5277 | 5277 |
| 5278 // Check whether a getter or setter for this name exists. A const | 5278 // Check whether a getter or setter for this name exists. A const |
| 5279 // or final field implies a setter which throws a NoSuchMethodError, | 5279 // or final field implies a setter which throws a NoSuchMethodError, |
| 5280 // thus we need to check for conflicts with existing setters and | 5280 // thus we need to check for conflicts with existing setters and |
| 5281 // getters. | 5281 // getters. |
| 5282 String& accessor_name = String::Handle(Z, | 5282 String& accessor_name = String::Handle(Z, Field::GetterName(var_name)); |
| 5283 Field::GetterName(var_name)); | |
| 5284 if (library_.LookupLocalObject(accessor_name) != Object::null()) { | 5283 if (library_.LookupLocalObject(accessor_name) != Object::null()) { |
| 5285 ReportError(name_pos, "getter for '%s' is already defined", | 5284 ReportError(name_pos, "getter for '%s' is already defined", |
| 5286 var_name.ToCString()); | 5285 var_name.ToCString()); |
| 5287 } | 5286 } |
| 5288 accessor_name = Field::SetterName(var_name); | 5287 accessor_name = Field::SetterName(var_name); |
| 5289 if (library_.LookupLocalObject(accessor_name) != Object::null()) { | 5288 if (library_.LookupLocalObject(accessor_name) != Object::null()) { |
| 5290 ReportError(name_pos, "setter for '%s' is already defined", | 5289 ReportError(name_pos, "setter for '%s' is already defined", |
| 5291 var_name.ToCString()); | 5290 var_name.ToCString()); |
| 5292 } | 5291 } |
| 5293 | 5292 |
| 5294 field = Field::New(var_name, is_static, is_final, is_const, is_synthetic, | 5293 field = Field::New(var_name, is_static, is_final, is_const, is_synthetic, |
| 5295 current_class(), name_pos); | 5294 current_class(), name_pos); |
| 5296 field.set_type(type); | 5295 field.set_type(type); |
| 5297 field.set_value(Instance::Handle(Z, Instance::null())); | 5296 field.set_value(Instance::Handle(Z, Instance::null())); |
| 5298 top_level->fields.Add(field); | 5297 top_level->fields.Add(field); |
| 5299 library_.AddObject(field, var_name); | 5298 library_.AddObject(field, var_name); |
| 5300 if (metadata_pos >= 0) { | 5299 if (metadata_pos >= 0) { |
| 5301 library_.AddFieldMetadata(field, metadata_pos); | 5300 library_.AddFieldMetadata(field, metadata_pos); |
| 5302 } | 5301 } |
| 5303 if (CurrentToken() == Token::kASSIGN) { | 5302 if (CurrentToken() == Token::kASSIGN) { |
| 5304 ConsumeToken(); | 5303 ConsumeToken(); |
| 5305 Instance& field_value = Instance::Handle(Z, | 5304 Instance& field_value = Instance::Handle(Z, Object::sentinel().raw()); |
| 5306 Object::sentinel().raw()); | |
| 5307 bool has_simple_literal = false; | 5305 bool has_simple_literal = false; |
| 5308 if (LookaheadToken(1) == Token::kSEMICOLON) { | 5306 if (LookaheadToken(1) == Token::kSEMICOLON) { |
| 5309 has_simple_literal = IsSimpleLiteral(type, &field_value); | 5307 has_simple_literal = IsSimpleLiteral(type, &field_value); |
| 5310 } | 5308 } |
| 5311 SkipExpr(); | 5309 SkipExpr(); |
| 5312 field.set_value(field_value); | 5310 field.set_value(field_value); |
| 5313 if (!has_simple_literal) { | 5311 if (!has_simple_literal) { |
| 5314 // Create a static final getter. | 5312 // Create a static final getter. |
| 5315 String& getter_name = String::Handle(Z, | 5313 String& getter_name = String::Handle(Z, Field::GetterSymbol(var_name)); |
| 5316 Field::GetterSymbol(var_name)); | |
| 5317 getter = Function::New(getter_name, | 5314 getter = Function::New(getter_name, |
| 5318 RawFunction::kImplicitStaticFinalGetter, | 5315 RawFunction::kImplicitStaticFinalGetter, |
| 5319 is_static, | 5316 is_static, |
| 5320 is_const, | 5317 is_const, |
| 5321 /* is_abstract = */ false, | 5318 /* is_abstract = */ false, |
| 5322 /* is_external = */ false, | 5319 /* is_external = */ false, |
| 5323 /* is_native = */ false, | 5320 /* is_native = */ false, |
| 5324 current_class(), | 5321 current_class(), |
| 5325 name_pos); | 5322 name_pos); |
| 5326 getter.set_result_type(type); | 5323 getter.set_result_type(type); |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5404 const intptr_t name_pos = TokenPos(); | 5401 const intptr_t name_pos = TokenPos(); |
| 5405 const String& func_name = *ExpectIdentifier("function name expected"); | 5402 const String& func_name = *ExpectIdentifier("function name expected"); |
| 5406 | 5403 |
| 5407 bool found = library_.LookupLocalObject(func_name) != Object::null(); | 5404 bool found = library_.LookupLocalObject(func_name) != Object::null(); |
| 5408 if (found && !is_patch) { | 5405 if (found && !is_patch) { |
| 5409 ReportError(name_pos, "'%s' is already defined", func_name.ToCString()); | 5406 ReportError(name_pos, "'%s' is already defined", func_name.ToCString()); |
| 5410 } else if (!found && is_patch) { | 5407 } else if (!found && is_patch) { |
| 5411 ReportError(name_pos, "missing '%s' cannot be patched", | 5408 ReportError(name_pos, "missing '%s' cannot be patched", |
| 5412 func_name.ToCString()); | 5409 func_name.ToCString()); |
| 5413 } | 5410 } |
| 5414 String& accessor_name = String::Handle(Z, | 5411 String& accessor_name = String::Handle(Z, Field::GetterName(func_name)); |
| 5415 Field::GetterName(func_name)); | |
| 5416 if (library_.LookupLocalObject(accessor_name) != Object::null()) { | 5412 if (library_.LookupLocalObject(accessor_name) != Object::null()) { |
| 5417 ReportError(name_pos, "'%s' is already defined as getter", | 5413 ReportError(name_pos, "'%s' is already defined as getter", |
| 5418 func_name.ToCString()); | 5414 func_name.ToCString()); |
| 5419 } | 5415 } |
| 5420 // A setter named x= may co-exist with a function named x, thus we do | 5416 // A setter named x= may co-exist with a function named x, thus we do |
| 5421 // not need to check setters. | 5417 // not need to check setters. |
| 5422 | 5418 |
| 5423 CheckToken(Token::kLPAREN); | 5419 CheckToken(Token::kLPAREN); |
| 5424 const intptr_t function_pos = TokenPos(); | 5420 const intptr_t function_pos = TokenPos(); |
| 5425 ParamList params; | 5421 ParamList params; |
| (...skipping 8056 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 13482 void Parser::SkipQualIdent() { | 13478 void Parser::SkipQualIdent() { |
| 13483 ASSERT(IsIdentifier()); | 13479 ASSERT(IsIdentifier()); |
| 13484 ConsumeToken(); | 13480 ConsumeToken(); |
| 13485 if (CurrentToken() == Token::kPERIOD) { | 13481 if (CurrentToken() == Token::kPERIOD) { |
| 13486 ConsumeToken(); // Consume the kPERIOD token. | 13482 ConsumeToken(); // Consume the kPERIOD token. |
| 13487 ExpectIdentifier("identifier expected after '.'"); | 13483 ExpectIdentifier("identifier expected after '.'"); |
| 13488 } | 13484 } |
| 13489 } | 13485 } |
| 13490 | 13486 |
| 13491 } // namespace dart | 13487 } // namespace dart |
| OLD | NEW |