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/bootstrap.h" | 9 #include "vm/bootstrap.h" |
10 #include "vm/class_finalizer.h" | 10 #include "vm/class_finalizer.h" |
(...skipping 3536 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3547 field->has_const ? "const" : "final", | 3547 field->has_const ? "const" : "final", |
3548 field->name->ToCString()); | 3548 field->name->ToCString()); |
3549 } | 3549 } |
3550 } | 3550 } |
3551 | 3551 |
3552 // Create the field object. | 3552 // Create the field object. |
3553 class_field = Field::New(*field->name, | 3553 class_field = Field::New(*field->name, |
3554 field->has_static, | 3554 field->has_static, |
3555 field->has_final, | 3555 field->has_final, |
3556 field->has_const, | 3556 field->has_const, |
| 3557 false, // Not synthetic. |
3557 current_class(), | 3558 current_class(), |
3558 field->name_pos); | 3559 field->name_pos); |
3559 class_field.set_type(*field->type); | 3560 class_field.set_type(*field->type); |
3560 class_field.set_has_initializer(has_initializer); | 3561 class_field.set_has_initializer(has_initializer); |
3561 members->AddField(class_field); | 3562 members->AddField(class_field); |
3562 field->field_ = &class_field; | 3563 field->field_ = &class_field; |
3563 if (field->metadata_pos >= 0) { | 3564 if (field->metadata_pos >= 0) { |
3564 library_.AddFieldMetadata(class_field, field->metadata_pos); | 3565 library_.AddFieldMetadata(class_field, field->metadata_pos); |
3565 } | 3566 } |
3566 | 3567 |
(...skipping 1117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4684 } | 4685 } |
4685 | 4686 |
4686 | 4687 |
4687 void Parser::ParseTopLevelVariable(TopLevel* top_level, | 4688 void Parser::ParseTopLevelVariable(TopLevel* top_level, |
4688 intptr_t metadata_pos) { | 4689 intptr_t metadata_pos) { |
4689 TRACE_PARSER("ParseTopLevelVariable"); | 4690 TRACE_PARSER("ParseTopLevelVariable"); |
4690 const bool is_const = (CurrentToken() == Token::kCONST); | 4691 const bool is_const = (CurrentToken() == Token::kCONST); |
4691 // Const fields are implicitly final. | 4692 // Const fields are implicitly final. |
4692 const bool is_final = is_const || (CurrentToken() == Token::kFINAL); | 4693 const bool is_final = is_const || (CurrentToken() == Token::kFINAL); |
4693 const bool is_static = true; | 4694 const bool is_static = true; |
| 4695 const bool is_synthetic = false; |
4694 const AbstractType& type = AbstractType::ZoneHandle(I, | 4696 const AbstractType& type = AbstractType::ZoneHandle(I, |
4695 ParseConstFinalVarOrType(ClassFinalizer::kResolveTypeParameters)); | 4697 ParseConstFinalVarOrType(ClassFinalizer::kResolveTypeParameters)); |
4696 Field& field = Field::Handle(I); | 4698 Field& field = Field::Handle(I); |
4697 Function& getter = Function::Handle(I); | 4699 Function& getter = Function::Handle(I); |
4698 while (true) { | 4700 while (true) { |
4699 const intptr_t name_pos = TokenPos(); | 4701 const intptr_t name_pos = TokenPos(); |
4700 String& var_name = *ExpectIdentifier("variable name expected"); | 4702 String& var_name = *ExpectIdentifier("variable name expected"); |
4701 | 4703 |
4702 if (library_.LookupLocalObject(var_name) != Object::null()) { | 4704 if (library_.LookupLocalObject(var_name) != Object::null()) { |
4703 ReportError(name_pos, "'%s' is already defined", var_name.ToCString()); | 4705 ReportError(name_pos, "'%s' is already defined", var_name.ToCString()); |
4704 } | 4706 } |
4705 | 4707 |
4706 // Check whether a getter or setter for this name exists. A const | 4708 // Check whether a getter or setter for this name exists. A const |
4707 // or final field implies a setter which throws a NoSuchMethodError, | 4709 // or final field implies a setter which throws a NoSuchMethodError, |
4708 // thus we need to check for conflicts with existing setters and | 4710 // thus we need to check for conflicts with existing setters and |
4709 // getters. | 4711 // getters. |
4710 String& accessor_name = String::Handle(I, | 4712 String& accessor_name = String::Handle(I, |
4711 Field::GetterName(var_name)); | 4713 Field::GetterName(var_name)); |
4712 if (library_.LookupLocalObject(accessor_name) != Object::null()) { | 4714 if (library_.LookupLocalObject(accessor_name) != Object::null()) { |
4713 ReportError(name_pos, "getter for '%s' is already defined", | 4715 ReportError(name_pos, "getter for '%s' is already defined", |
4714 var_name.ToCString()); | 4716 var_name.ToCString()); |
4715 } | 4717 } |
4716 accessor_name = Field::SetterName(var_name); | 4718 accessor_name = Field::SetterName(var_name); |
4717 if (library_.LookupLocalObject(accessor_name) != Object::null()) { | 4719 if (library_.LookupLocalObject(accessor_name) != Object::null()) { |
4718 ReportError(name_pos, "setter for '%s' is already defined", | 4720 ReportError(name_pos, "setter for '%s' is already defined", |
4719 var_name.ToCString()); | 4721 var_name.ToCString()); |
4720 } | 4722 } |
4721 | 4723 |
4722 field = Field::New(var_name, is_static, is_final, is_const, | 4724 field = Field::New(var_name, is_static, is_final, is_const, is_synthetic, |
4723 current_class(), name_pos); | 4725 current_class(), name_pos); |
4724 field.set_type(type); | 4726 field.set_type(type); |
4725 field.set_value(Instance::Handle(I, Instance::null())); | 4727 field.set_value(Instance::Handle(I, Instance::null())); |
4726 top_level->fields.Add(field); | 4728 top_level->fields.Add(field); |
4727 library_.AddObject(field, var_name); | 4729 library_.AddObject(field, var_name); |
4728 if (metadata_pos >= 0) { | 4730 if (metadata_pos >= 0) { |
4729 library_.AddFieldMetadata(field, metadata_pos); | 4731 library_.AddFieldMetadata(field, metadata_pos); |
4730 } | 4732 } |
4731 if (CurrentToken() == Token::kASSIGN) { | 4733 if (CurrentToken() == Token::kASSIGN) { |
4732 ConsumeToken(); | 4734 ConsumeToken(); |
(...skipping 6324 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
11057 void Parser::SkipQualIdent() { | 11059 void Parser::SkipQualIdent() { |
11058 ASSERT(IsIdentifier()); | 11060 ASSERT(IsIdentifier()); |
11059 ConsumeToken(); | 11061 ConsumeToken(); |
11060 if (CurrentToken() == Token::kPERIOD) { | 11062 if (CurrentToken() == Token::kPERIOD) { |
11061 ConsumeToken(); // Consume the kPERIOD token. | 11063 ConsumeToken(); // Consume the kPERIOD token. |
11062 ExpectIdentifier("identifier expected after '.'"); | 11064 ExpectIdentifier("identifier expected after '.'"); |
11063 } | 11065 } |
11064 } | 11066 } |
11065 | 11067 |
11066 } // namespace dart | 11068 } // namespace dart |
OLD | NEW |