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 #include "vm/flags.h" | 6 #include "vm/flags.h" |
7 | 7 |
8 #ifndef DART_PRECOMPILED_RUNTIME | 8 #ifndef DART_PRECOMPILED_RUNTIME |
9 | 9 |
10 #include "lib/invocation_mirror.h" | 10 #include "lib/invocation_mirror.h" |
(...skipping 4850 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4861 } | 4861 } |
4862 for (intptr_t n = 0; n < declared_names.length(); n++) { | 4862 for (intptr_t n = 0; n < declared_names.length(); n++) { |
4863 if (enum_ident->Equals(*declared_names[n])) { | 4863 if (enum_ident->Equals(*declared_names[n])) { |
4864 ReportError("Duplicate name '%s' in enum definition '%s'", | 4864 ReportError("Duplicate name '%s' in enum definition '%s'", |
4865 enum_ident->ToCString(), enum_name.ToCString()); | 4865 enum_ident->ToCString(), enum_name.ToCString()); |
4866 } | 4866 } |
4867 } | 4867 } |
4868 declared_names.Add(enum_ident); | 4868 declared_names.Add(enum_ident); |
4869 | 4869 |
4870 // Create the static const field for the enumeration value. | 4870 // Create the static const field for the enumeration value. |
| 4871 // Note that we do not set the field type to E, because we temporarily store |
| 4872 // a Smi in the field. The class finalizer would detect the bad type and |
| 4873 // reset the value to sentinel. |
4871 enum_value = Field::New(*enum_ident, | 4874 enum_value = Field::New(*enum_ident, |
4872 /* is_static = */ true, | 4875 /* is_static = */ true, |
4873 /* is_final = */ true, | 4876 /* is_final = */ true, |
4874 /* is_const = */ true, | 4877 /* is_const = */ true, |
4875 /* is_reflectable = */ true, cls, | 4878 /* is_reflectable = */ true, cls, |
4876 Object::dynamic_type(), cls.token_pos()); | 4879 Object::dynamic_type(), cls.token_pos()); |
4877 enum_value.set_has_initializer(false); | 4880 enum_value.set_has_initializer(false); |
4878 enum_members.AddField(enum_value); | 4881 enum_members.AddField(enum_value); |
4879 // Initialize the field with the ordinal value. It will be patched | 4882 // Initialize the field with the ordinal value. It will be patched |
4880 // later with the enum constant instance. | 4883 // later with the enum constant instance. |
4881 const Smi& ordinal_value = Smi::Handle(Z, Smi::New(i)); | 4884 const Smi& ordinal_value = Smi::Handle(Z, Smi::New(i)); |
4882 enum_value.SetStaticValue(ordinal_value, true); | 4885 enum_value.SetStaticValue(ordinal_value, true); |
4883 enum_value.RecordStore(ordinal_value); | 4886 enum_value.RecordStore(ordinal_value); |
4884 i++; | 4887 i++; |
4885 | 4888 |
4886 ConsumeToken(); // Enum value name. | 4889 ConsumeToken(); // Enum value name. |
4887 if (CurrentToken() == Token::kCOMMA) { | 4890 if (CurrentToken() == Token::kCOMMA) { |
4888 ConsumeToken(); | 4891 ConsumeToken(); |
4889 } | 4892 } |
4890 } | 4893 } |
4891 ExpectToken(Token::kRBRACE); | 4894 ExpectToken(Token::kRBRACE); |
4892 | 4895 |
4893 const Type& array_type = Type::Handle(Z, Type::ArrayType()); | 4896 const Class& array_class = Class::Handle(Z, I->object_store()->array_class()); |
4894 // Add static field 'const List values'. | 4897 TypeArguments& values_type_args = |
| 4898 TypeArguments::ZoneHandle(Z, TypeArguments::New(1)); |
| 4899 const Type& enum_type = Type::Handle(Type::NewNonParameterizedType(cls)); |
| 4900 values_type_args.SetTypeAt(0, enum_type); |
| 4901 Type& values_type = Type::ZoneHandle( |
| 4902 Z, Type::New(array_class, values_type_args, cls.token_pos(), Heap::kOld)); |
| 4903 values_type ^= ClassFinalizer::FinalizeType(cls, values_type, |
| 4904 ClassFinalizer::kCanonicalize); |
| 4905 values_type_args = values_type.arguments(); // Get canonical type arguments. |
| 4906 // Add static field 'const List<E> values'. |
4895 Field& values_field = Field::ZoneHandle(Z); | 4907 Field& values_field = Field::ZoneHandle(Z); |
4896 values_field = | 4908 values_field = Field::New(Symbols::Values(), |
4897 Field::New(Symbols::Values(), | 4909 /* is_static = */ true, |
4898 /* is_static = */ true, | 4910 /* is_final = */ true, |
4899 /* is_final = */ true, | 4911 /* is_const = */ true, |
4900 /* is_const = */ true, | 4912 /* is_reflectable = */ true, cls, values_type, |
4901 /* is_reflectable = */ true, cls, array_type, cls.token_pos()); | 4913 cls.token_pos()); |
4902 enum_members.AddField(values_field); | 4914 enum_members.AddField(values_field); |
4903 | 4915 |
4904 // Add static field 'const _deleted_enum_sentinel'. | 4916 // Add static field 'const _deleted_enum_sentinel'. |
| 4917 // This field does not need to be of type E. |
4905 Field& deleted_enum_sentinel = Field::ZoneHandle(Z); | 4918 Field& deleted_enum_sentinel = Field::ZoneHandle(Z); |
4906 deleted_enum_sentinel = Field::New(Symbols::_DeletedEnumSentinel(), | 4919 deleted_enum_sentinel = Field::New(Symbols::_DeletedEnumSentinel(), |
4907 /* is_static = */ true, | 4920 /* is_static = */ true, |
4908 /* is_final = */ true, | 4921 /* is_final = */ true, |
4909 /* is_const = */ true, | 4922 /* is_const = */ true, |
4910 /* is_reflectable = */ false, cls, | 4923 /* is_reflectable = */ false, cls, |
4911 Object::dynamic_type(), cls.token_pos()); | 4924 Object::dynamic_type(), cls.token_pos()); |
4912 enum_members.AddField(deleted_enum_sentinel); | 4925 enum_members.AddField(deleted_enum_sentinel); |
4913 | 4926 |
4914 // Allocate the immutable array containing the enumeration values. | 4927 // Allocate the immutable array containing the enumeration values. |
4915 // The actual enum instance values will be patched in later. | 4928 // The actual enum instance values will be patched in later. |
4916 const Array& values_array = Array::Handle(Z, Array::New(i, Heap::kOld)); | 4929 const Array& values_array = Array::Handle(Z, Array::New(i, Heap::kOld)); |
| 4930 values_array.SetTypeArguments(values_type_args); |
4917 values_field.SetStaticValue(values_array, true); | 4931 values_field.SetStaticValue(values_array, true); |
4918 values_field.RecordStore(values_array); | 4932 values_field.RecordStore(values_array); |
4919 | 4933 |
4920 // Clone the _name field from the helper class. | 4934 // Clone the _name field from the helper class. |
4921 Field& _name_field = Field::Handle( | 4935 Field& _name_field = Field::Handle( |
4922 Z, helper_class.LookupInstanceFieldAllowPrivate(Symbols::_name())); | 4936 Z, helper_class.LookupInstanceFieldAllowPrivate(Symbols::_name())); |
4923 ASSERT(!_name_field.IsNull()); | 4937 ASSERT(!_name_field.IsNull()); |
4924 _name_field = _name_field.Clone(cls); | 4938 _name_field = _name_field.Clone(cls); |
4925 enum_members.AddField(_name_field); | 4939 enum_members.AddField(_name_field); |
4926 | 4940 |
(...skipping 9741 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
14668 const ArgumentListNode& function_args, | 14682 const ArgumentListNode& function_args, |
14669 const LocalVariable* temp_for_last_arg, | 14683 const LocalVariable* temp_for_last_arg, |
14670 bool is_super_invocation) { | 14684 bool is_super_invocation) { |
14671 UNREACHABLE(); | 14685 UNREACHABLE(); |
14672 return NULL; | 14686 return NULL; |
14673 } | 14687 } |
14674 | 14688 |
14675 } // namespace dart | 14689 } // namespace dart |
14676 | 14690 |
14677 #endif // DART_PRECOMPILED_RUNTIME | 14691 #endif // DART_PRECOMPILED_RUNTIME |
OLD | NEW |