Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(20)

Side by Side Diff: runtime/vm/parser.cc

Issue 1406943006: Pass type argument to Field construction, thus freezing that field, denoting it cannot be changed l… (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: f Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « runtime/vm/object_test.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 4029 matching lines...) Expand 10 before | Expand all | Expand 10 after
4040 4040
4041 // Create the field object. 4041 // Create the field object.
4042 const bool is_reflectable = 4042 const bool is_reflectable =
4043 !(library_.is_dart_scheme() && library_.IsPrivate(*field->name)); 4043 !(library_.is_dart_scheme() && library_.IsPrivate(*field->name));
4044 class_field = Field::New(*field->name, 4044 class_field = Field::New(*field->name,
4045 field->has_static, 4045 field->has_static,
4046 field->has_final, 4046 field->has_final,
4047 field->has_const, 4047 field->has_const,
4048 is_reflectable, 4048 is_reflectable,
4049 current_class(), 4049 current_class(),
4050 *field->type,
4050 field->name_pos); 4051 field->name_pos);
4051 class_field.set_type(*field->type);
4052 class_field.set_has_initializer(has_initializer); 4052 class_field.set_has_initializer(has_initializer);
4053 members->AddField(class_field); 4053 members->AddField(class_field);
4054 field->field_ = &class_field; 4054 field->field_ = &class_field;
4055 if (field->metadata_pos >= 0) { 4055 if (field->metadata_pos >= 0) {
4056 library_.AddFieldMetadata(class_field, field->metadata_pos); 4056 library_.AddFieldMetadata(class_field, field->metadata_pos);
4057 } 4057 }
4058 4058
4059 // Start tracking types for fields with simple initializers in their 4059 // Start tracking types for fields with simple initializers in their
4060 // definition. This avoids some of the overhead to track this at runtime 4060 // definition. This avoids some of the overhead to track this at runtime
4061 // and rules out many fields from being unnecessary unboxing candidates. 4061 // and rules out many fields from being unnecessary unboxing candidates.
(...skipping 659 matching lines...) Expand 10 before | Expand all | Expand 10 after
4721 4721
4722 // Add instance field 'final int index'. 4722 // Add instance field 'final int index'.
4723 Field& index_field = Field::ZoneHandle(Z); 4723 Field& index_field = Field::ZoneHandle(Z);
4724 const Type& int_type = Type::Handle(Z, Type::IntType()); 4724 const Type& int_type = Type::Handle(Z, Type::IntType());
4725 index_field = Field::New(Symbols::Index(), 4725 index_field = Field::New(Symbols::Index(),
4726 false, // Not static. 4726 false, // Not static.
4727 true, // Field is final. 4727 true, // Field is final.
4728 false, // Not const. 4728 false, // Not const.
4729 true, // Is reflectable. 4729 true, // Is reflectable.
4730 cls, 4730 cls,
4731 int_type,
4731 cls.token_pos()); 4732 cls.token_pos());
4732 index_field.set_type(int_type);
4733 enum_members.AddField(index_field); 4733 enum_members.AddField(index_field);
4734 4734
4735 // Add implicit getter for index field. 4735 // Add implicit getter for index field.
4736 const String& getter_name = 4736 const String& getter_name =
4737 String::Handle(Z, Field::GetterSymbol(Symbols::Index())); 4737 String::Handle(Z, Field::GetterSymbol(Symbols::Index()));
4738 Function& getter = Function::Handle(Z); 4738 Function& getter = Function::Handle(Z);
4739 getter = Function::New(getter_name, 4739 getter = Function::New(getter_name,
4740 RawFunction::kImplicitGetter, 4740 RawFunction::kImplicitGetter,
4741 /* is_static = */ false, 4741 /* is_static = */ false,
4742 /* is_const = */ true, 4742 /* is_const = */ true,
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
4793 } 4793 }
4794 declared_names.Add(enum_ident); 4794 declared_names.Add(enum_ident);
4795 4795
4796 // Create the static const field for the enumeration value. 4796 // Create the static const field for the enumeration value.
4797 enum_value = Field::New(*enum_ident, 4797 enum_value = Field::New(*enum_ident,
4798 /* is_static = */ true, 4798 /* is_static = */ true,
4799 /* is_final = */ true, 4799 /* is_final = */ true,
4800 /* is_const = */ true, 4800 /* is_const = */ true,
4801 /* is_reflectable = */ true, 4801 /* is_reflectable = */ true,
4802 cls, 4802 cls,
4803 Object::dynamic_type(),
4803 cls.token_pos()); 4804 cls.token_pos());
4804 enum_value.set_type(Object::dynamic_type());
4805 enum_value.set_has_initializer(false); 4805 enum_value.set_has_initializer(false);
4806 enum_members.AddField(enum_value); 4806 enum_members.AddField(enum_value);
4807 // Initialize the field with the ordinal value. It will be patched 4807 // Initialize the field with the ordinal value. It will be patched
4808 // later with the enum constant instance. 4808 // later with the enum constant instance.
4809 const Smi& ordinal_value = Smi::Handle(Z, Smi::New(i)); 4809 const Smi& ordinal_value = Smi::Handle(Z, Smi::New(i));
4810 enum_value.SetStaticValue(ordinal_value, true); 4810 enum_value.SetStaticValue(ordinal_value, true);
4811 enum_value.RecordStore(ordinal_value); 4811 enum_value.RecordStore(ordinal_value);
4812 i++; 4812 i++;
4813 4813
4814 // For the user-visible name of the enumeration value, we need to 4814 // For the user-visible name of the enumeration value, we need to
(...skipping 16 matching lines...) Expand all
4831 ASSERT(!helper_class.IsNull()); 4831 ASSERT(!helper_class.IsNull());
4832 4832
4833 // Add static field 'const List values'. 4833 // Add static field 'const List values'.
4834 Field& values_field = Field::ZoneHandle(Z); 4834 Field& values_field = Field::ZoneHandle(Z);
4835 values_field = Field::New(Symbols::Values(), 4835 values_field = Field::New(Symbols::Values(),
4836 /* is_static = */ true, 4836 /* is_static = */ true,
4837 /* is_final = */ true, 4837 /* is_final = */ true,
4838 /* is_const = */ true, 4838 /* is_const = */ true,
4839 /* is_reflectable = */ true, 4839 /* is_reflectable = */ true,
4840 cls, 4840 cls,
4841 Type::Handle(Z, Type::ArrayType()),
4841 cls.token_pos()); 4842 cls.token_pos());
4842 values_field.set_type(Type::Handle(Z, Type::ArrayType()));
4843 enum_members.AddField(values_field); 4843 enum_members.AddField(values_field);
4844 4844
4845 // Allocate the immutable array containing the enumeration values. 4845 // Allocate the immutable array containing the enumeration values.
4846 // The actual enum instance values will be patched in later. 4846 // The actual enum instance values will be patched in later.
4847 const Array& values_array = Array::Handle(Z, Array::New(i, Heap::kOld)); 4847 const Array& values_array = Array::Handle(Z, Array::New(i, Heap::kOld));
4848 values_field.SetStaticValue(values_array, true); 4848 values_field.SetStaticValue(values_array, true);
4849 values_field.RecordStore(values_array); 4849 values_field.RecordStore(values_array);
4850 4850
4851 // Create a static field that contains the list of enumeration names. 4851 // Create a static field that contains the list of enumeration names.
4852 // Clone the _enum_names field from the helper class. 4852 // Clone the _enum_names field from the helper class.
(...skipping 587 matching lines...) Expand 10 before | Expand all | Expand 10 after
5440 } 5440 }
5441 accessor_name = Field::SetterName(var_name); 5441 accessor_name = Field::SetterName(var_name);
5442 if (library_.LookupLocalObject(accessor_name) != Object::null()) { 5442 if (library_.LookupLocalObject(accessor_name) != Object::null()) {
5443 ReportError(name_pos, "setter for '%s' is already defined", 5443 ReportError(name_pos, "setter for '%s' is already defined",
5444 var_name.ToCString()); 5444 var_name.ToCString());
5445 } 5445 }
5446 5446
5447 const bool is_reflectable = 5447 const bool is_reflectable =
5448 !(library_.is_dart_scheme() && library_.IsPrivate(var_name)); 5448 !(library_.is_dart_scheme() && library_.IsPrivate(var_name));
5449 field = Field::New(var_name, is_static, is_final, is_const, is_reflectable, 5449 field = Field::New(var_name, is_static, is_final, is_const, is_reflectable,
5450 current_class(), name_pos); 5450 current_class(), type, name_pos);
5451 field.set_type(type);
5452 field.SetStaticValue(Object::null_instance(), true); 5451 field.SetStaticValue(Object::null_instance(), true);
5453 top_level->AddField(field); 5452 top_level->AddField(field);
5454 library_.AddObject(field, var_name); 5453 library_.AddObject(field, var_name);
5455 if (metadata_pos >= 0) { 5454 if (metadata_pos >= 0) {
5456 library_.AddFieldMetadata(field, metadata_pos); 5455 library_.AddFieldMetadata(field, metadata_pos);
5457 } 5456 }
5458 if (CurrentToken() == Token::kASSIGN) { 5457 if (CurrentToken() == Token::kASSIGN) {
5459 ConsumeToken(); 5458 ConsumeToken();
5460 Instance& field_value = Instance::Handle(Z, Object::sentinel().raw()); 5459 Instance& field_value = Instance::Handle(Z, Object::sentinel().raw());
5461 bool has_simple_literal = false; 5460 bool has_simple_literal = false;
(...skipping 8871 matching lines...) Expand 10 before | Expand all | Expand 10 after
14333 void Parser::SkipQualIdent() { 14332 void Parser::SkipQualIdent() {
14334 ASSERT(IsIdentifier()); 14333 ASSERT(IsIdentifier());
14335 ConsumeToken(); 14334 ConsumeToken();
14336 if (CurrentToken() == Token::kPERIOD) { 14335 if (CurrentToken() == Token::kPERIOD) {
14337 ConsumeToken(); // Consume the kPERIOD token. 14336 ConsumeToken(); // Consume the kPERIOD token.
14338 ExpectIdentifier("identifier expected after '.'"); 14337 ExpectIdentifier("identifier expected after '.'");
14339 } 14338 }
14340 } 14339 }
14341 14340
14342 } // namespace dart 14341 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/object_test.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698