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 3970 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3981 // Static const fields are implicitly final. | 3981 // Static const fields are implicitly final. |
3982 if (field->has_static && field->has_final) { | 3982 if (field->has_static && field->has_final) { |
3983 ReportError(field->name_pos, | 3983 ReportError(field->name_pos, |
3984 "static %s field '%s' must have an initializer expression", | 3984 "static %s field '%s' must have an initializer expression", |
3985 field->has_const ? "const" : "final", | 3985 field->has_const ? "const" : "final", |
3986 field->name->ToCString()); | 3986 field->name->ToCString()); |
3987 } | 3987 } |
3988 } | 3988 } |
3989 | 3989 |
3990 // Create the field object. | 3990 // Create the field object. |
| 3991 const bool is_reflectable = |
| 3992 !(library_.is_dart_scheme() && library_.IsPrivate(*field->name)); |
3991 class_field = Field::New(*field->name, | 3993 class_field = Field::New(*field->name, |
3992 field->has_static, | 3994 field->has_static, |
3993 field->has_final, | 3995 field->has_final, |
3994 field->has_const, | 3996 field->has_const, |
3995 false, // Not synthetic. | 3997 is_reflectable, |
3996 current_class(), | 3998 current_class(), |
3997 field->name_pos); | 3999 field->name_pos); |
3998 class_field.set_type(*field->type); | 4000 class_field.set_type(*field->type); |
3999 class_field.set_has_initializer(has_initializer); | 4001 class_field.set_has_initializer(has_initializer); |
4000 members->AddField(class_field); | 4002 members->AddField(class_field); |
4001 field->field_ = &class_field; | 4003 field->field_ = &class_field; |
4002 if (field->metadata_pos >= 0) { | 4004 if (field->metadata_pos >= 0) { |
4003 library_.AddFieldMetadata(class_field, field->metadata_pos); | 4005 library_.AddFieldMetadata(class_field, field->metadata_pos); |
4004 } | 4006 } |
4005 | 4007 |
(...skipping 658 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4664 ClassDesc enum_members(cls, enum_name, false, cls.token_pos()); | 4666 ClassDesc enum_members(cls, enum_name, false, cls.token_pos()); |
4665 | 4667 |
4666 // Add instance field 'final int index'. | 4668 // Add instance field 'final int index'. |
4667 Field& index_field = Field::ZoneHandle(Z); | 4669 Field& index_field = Field::ZoneHandle(Z); |
4668 const Type& int_type = Type::Handle(Z, Type::IntType()); | 4670 const Type& int_type = Type::Handle(Z, Type::IntType()); |
4669 const Type& dynamic_type = Type::Handle(Type::DynamicType()); | 4671 const Type& dynamic_type = Type::Handle(Type::DynamicType()); |
4670 index_field = Field::New(Symbols::Index(), | 4672 index_field = Field::New(Symbols::Index(), |
4671 false, // Not static. | 4673 false, // Not static. |
4672 true, // Field is final. | 4674 true, // Field is final. |
4673 false, // Not const. | 4675 false, // Not const. |
4674 false, // Not synthetic. | 4676 true, // Is reflectable. |
4675 cls, | 4677 cls, |
4676 cls.token_pos()); | 4678 cls.token_pos()); |
4677 index_field.set_type(int_type); | 4679 index_field.set_type(int_type); |
4678 enum_members.AddField(index_field); | 4680 enum_members.AddField(index_field); |
4679 | 4681 |
4680 // Add implicit getter for index field. | 4682 // Add implicit getter for index field. |
4681 const String& getter_name = | 4683 const String& getter_name = |
4682 String::Handle(Z, Field::GetterSymbol(Symbols::Index())); | 4684 String::Handle(Z, Field::GetterSymbol(Symbols::Index())); |
4683 Function& getter = Function::Handle(Z); | 4685 Function& getter = Function::Handle(Z); |
4684 getter = Function::New(getter_name, | 4686 getter = Function::New(getter_name, |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4736 enum_name.ToCString()); | 4738 enum_name.ToCString()); |
4737 } | 4739 } |
4738 } | 4740 } |
4739 declared_names.Add(enum_ident); | 4741 declared_names.Add(enum_ident); |
4740 | 4742 |
4741 // Create the static const field for the enumeration value. | 4743 // Create the static const field for the enumeration value. |
4742 enum_value = Field::New(*enum_ident, | 4744 enum_value = Field::New(*enum_ident, |
4743 /* is_static = */ true, | 4745 /* is_static = */ true, |
4744 /* is_final = */ true, | 4746 /* is_final = */ true, |
4745 /* is_const = */ true, | 4747 /* is_const = */ true, |
4746 /* is_synthetic = */ false, | 4748 /* is_reflectable = */ true, |
4747 cls, | 4749 cls, |
4748 cls.token_pos()); | 4750 cls.token_pos()); |
4749 enum_value.set_type(dynamic_type); | 4751 enum_value.set_type(dynamic_type); |
4750 enum_value.set_has_initializer(false); | 4752 enum_value.set_has_initializer(false); |
4751 enum_members.AddField(enum_value); | 4753 enum_members.AddField(enum_value); |
4752 // Initialize the field with the ordinal value. It will be patched | 4754 // Initialize the field with the ordinal value. It will be patched |
4753 // later with the enum constant instance. | 4755 // later with the enum constant instance. |
4754 const Smi& ordinal_value = Smi::Handle(Z, Smi::New(i)); | 4756 const Smi& ordinal_value = Smi::Handle(Z, Smi::New(i)); |
4755 enum_value.set_value(ordinal_value); | 4757 enum_value.set_value(ordinal_value); |
4756 enum_value.RecordStore(ordinal_value); | 4758 enum_value.RecordStore(ordinal_value); |
(...skipping 17 matching lines...) Expand all Loading... |
4774 const Class& helper_class = | 4776 const Class& helper_class = |
4775 Class::Handle(Z, Library::LookupCoreClass(Symbols::_EnumHelper())); | 4777 Class::Handle(Z, Library::LookupCoreClass(Symbols::_EnumHelper())); |
4776 ASSERT(!helper_class.IsNull()); | 4778 ASSERT(!helper_class.IsNull()); |
4777 | 4779 |
4778 // Add static field 'const List values'. | 4780 // Add static field 'const List values'. |
4779 Field& values_field = Field::ZoneHandle(Z); | 4781 Field& values_field = Field::ZoneHandle(Z); |
4780 values_field = Field::New(Symbols::Values(), | 4782 values_field = Field::New(Symbols::Values(), |
4781 /* is_static = */ true, | 4783 /* is_static = */ true, |
4782 /* is_final = */ true, | 4784 /* is_final = */ true, |
4783 /* is_const = */ true, | 4785 /* is_const = */ true, |
4784 /* is_synthetic = */ false, | 4786 /* is_reflectable = */ true, |
4785 cls, | 4787 cls, |
4786 cls.token_pos()); | 4788 cls.token_pos()); |
4787 values_field.set_type(Type::Handle(Z, Type::ArrayType())); | 4789 values_field.set_type(Type::Handle(Z, Type::ArrayType())); |
4788 enum_members.AddField(values_field); | 4790 enum_members.AddField(values_field); |
4789 | 4791 |
4790 // Allocate the immutable array containing the enumeration values. | 4792 // Allocate the immutable array containing the enumeration values. |
4791 // The actual enum instance values will be patched in later. | 4793 // The actual enum instance values will be patched in later. |
4792 const Array& values_array = Array::Handle(Z, Array::New(i, Heap::kOld)); | 4794 const Array& values_array = Array::Handle(Z, Array::New(i, Heap::kOld)); |
4793 values_field.set_value(values_array); | 4795 values_field.set_value(values_array); |
4794 values_field.RecordStore(values_array); | 4796 values_field.RecordStore(values_array); |
(...skipping 563 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5358 } | 5360 } |
5359 | 5361 |
5360 | 5362 |
5361 void Parser::ParseTopLevelVariable(TopLevel* top_level, | 5363 void Parser::ParseTopLevelVariable(TopLevel* top_level, |
5362 intptr_t metadata_pos) { | 5364 intptr_t metadata_pos) { |
5363 TRACE_PARSER("ParseTopLevelVariable"); | 5365 TRACE_PARSER("ParseTopLevelVariable"); |
5364 const bool is_const = (CurrentToken() == Token::kCONST); | 5366 const bool is_const = (CurrentToken() == Token::kCONST); |
5365 // Const fields are implicitly final. | 5367 // Const fields are implicitly final. |
5366 const bool is_final = is_const || (CurrentToken() == Token::kFINAL); | 5368 const bool is_final = is_const || (CurrentToken() == Token::kFINAL); |
5367 const bool is_static = true; | 5369 const bool is_static = true; |
5368 const bool is_synthetic = false; | |
5369 const AbstractType& type = AbstractType::ZoneHandle(Z, | 5370 const AbstractType& type = AbstractType::ZoneHandle(Z, |
5370 ParseConstFinalVarOrType(ClassFinalizer::kResolveTypeParameters)); | 5371 ParseConstFinalVarOrType(ClassFinalizer::kResolveTypeParameters)); |
5371 Field& field = Field::Handle(Z); | 5372 Field& field = Field::Handle(Z); |
5372 Function& getter = Function::Handle(Z); | 5373 Function& getter = Function::Handle(Z); |
5373 while (true) { | 5374 while (true) { |
5374 const intptr_t name_pos = TokenPos(); | 5375 const intptr_t name_pos = TokenPos(); |
5375 String& var_name = *ExpectIdentifier("variable name expected"); | 5376 String& var_name = *ExpectIdentifier("variable name expected"); |
5376 | 5377 |
5377 if (library_.LookupLocalObject(var_name) != Object::null()) { | 5378 if (library_.LookupLocalObject(var_name) != Object::null()) { |
5378 ReportError(name_pos, "'%s' is already defined", var_name.ToCString()); | 5379 ReportError(name_pos, "'%s' is already defined", var_name.ToCString()); |
5379 } | 5380 } |
5380 | 5381 |
5381 // Check whether a getter or setter for this name exists. A const | 5382 // Check whether a getter or setter for this name exists. A const |
5382 // or final field implies a setter which throws a NoSuchMethodError, | 5383 // or final field implies a setter which throws a NoSuchMethodError, |
5383 // thus we need to check for conflicts with existing setters and | 5384 // thus we need to check for conflicts with existing setters and |
5384 // getters. | 5385 // getters. |
5385 String& accessor_name = String::Handle(Z, Field::GetterName(var_name)); | 5386 String& accessor_name = String::Handle(Z, Field::GetterName(var_name)); |
5386 if (library_.LookupLocalObject(accessor_name) != Object::null()) { | 5387 if (library_.LookupLocalObject(accessor_name) != Object::null()) { |
5387 ReportError(name_pos, "getter for '%s' is already defined", | 5388 ReportError(name_pos, "getter for '%s' is already defined", |
5388 var_name.ToCString()); | 5389 var_name.ToCString()); |
5389 } | 5390 } |
5390 accessor_name = Field::SetterName(var_name); | 5391 accessor_name = Field::SetterName(var_name); |
5391 if (library_.LookupLocalObject(accessor_name) != Object::null()) { | 5392 if (library_.LookupLocalObject(accessor_name) != Object::null()) { |
5392 ReportError(name_pos, "setter for '%s' is already defined", | 5393 ReportError(name_pos, "setter for '%s' is already defined", |
5393 var_name.ToCString()); | 5394 var_name.ToCString()); |
5394 } | 5395 } |
5395 | 5396 |
5396 field = Field::New(var_name, is_static, is_final, is_const, is_synthetic, | 5397 const bool is_reflectable = |
| 5398 !(library_.is_dart_scheme() && library_.IsPrivate(var_name)); |
| 5399 field = Field::New(var_name, is_static, is_final, is_const, is_reflectable, |
5397 current_class(), name_pos); | 5400 current_class(), name_pos); |
5398 field.set_type(type); | 5401 field.set_type(type); |
5399 field.set_value(Instance::Handle(Z, Instance::null())); | 5402 field.set_value(Instance::Handle(Z, Instance::null())); |
5400 top_level->fields.Add(field); | 5403 top_level->fields.Add(field); |
5401 library_.AddObject(field, var_name); | 5404 library_.AddObject(field, var_name); |
5402 if (metadata_pos >= 0) { | 5405 if (metadata_pos >= 0) { |
5403 library_.AddFieldMetadata(field, metadata_pos); | 5406 library_.AddFieldMetadata(field, metadata_pos); |
5404 } | 5407 } |
5405 if (CurrentToken() == Token::kASSIGN) { | 5408 if (CurrentToken() == Token::kASSIGN) { |
5406 ConsumeToken(); | 5409 ConsumeToken(); |
(...skipping 8647 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
14054 void Parser::SkipQualIdent() { | 14057 void Parser::SkipQualIdent() { |
14055 ASSERT(IsIdentifier()); | 14058 ASSERT(IsIdentifier()); |
14056 ConsumeToken(); | 14059 ConsumeToken(); |
14057 if (CurrentToken() == Token::kPERIOD) { | 14060 if (CurrentToken() == Token::kPERIOD) { |
14058 ConsumeToken(); // Consume the kPERIOD token. | 14061 ConsumeToken(); // Consume the kPERIOD token. |
14059 ExpectIdentifier("identifier expected after '.'"); | 14062 ExpectIdentifier("identifier expected after '.'"); |
14060 } | 14063 } |
14061 } | 14064 } |
14062 | 14065 |
14063 } // namespace dart | 14066 } // namespace dart |
OLD | NEW |