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

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

Issue 1289643005: Rename accessors of class Field to make it more apparent as to what is being accessed - static fiel… (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: self-code-review Created 5 years, 3 months 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
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 4030 matching lines...) Expand 10 before | Expand all | Expand 10 after
4041 if (!field->has_static && has_initializer && has_simple_literal) { 4041 if (!field->has_static && has_initializer && has_simple_literal) {
4042 class_field.RecordStore(init_value); 4042 class_field.RecordStore(init_value);
4043 if (!init_value.IsNull() && init_value.IsDouble()) { 4043 if (!init_value.IsNull() && init_value.IsDouble()) {
4044 class_field.set_is_double_initialized(true); 4044 class_field.set_is_double_initialized(true);
4045 } 4045 }
4046 } 4046 }
4047 4047
4048 // For static final fields (this includes static const fields), set value to 4048 // For static final fields (this includes static const fields), set value to
4049 // "uninitialized" and create a kImplicitStaticFinalGetter getter method. 4049 // "uninitialized" and create a kImplicitStaticFinalGetter getter method.
4050 if (field->has_static && has_initializer) { 4050 if (field->has_static && has_initializer) {
4051 class_field.set_value(init_value); 4051 class_field.SetStaticFieldValue(init_value, true);
4052 if (!has_simple_literal) { 4052 if (!has_simple_literal) {
4053 String& getter_name = 4053 String& getter_name =
4054 String::Handle(Z, Field::GetterSymbol(*field->name)); 4054 String::Handle(Z, Field::GetterSymbol(*field->name));
4055 getter = Function::New(getter_name, 4055 getter = Function::New(getter_name,
4056 RawFunction::kImplicitStaticFinalGetter, 4056 RawFunction::kImplicitStaticFinalGetter,
4057 field->has_static, 4057 field->has_static,
4058 field->has_const, 4058 field->has_const,
4059 /* is_abstract = */ false, 4059 /* is_abstract = */ false,
4060 /* is_external = */ false, 4060 /* is_external = */ false,
4061 /* is_native = */ false, 4061 /* is_native = */ false,
(...skipping 718 matching lines...) Expand 10 before | Expand all | Expand 10 after
4780 /* is_const = */ true, 4780 /* is_const = */ true,
4781 /* is_reflectable = */ true, 4781 /* is_reflectable = */ true,
4782 cls, 4782 cls,
4783 cls.token_pos()); 4783 cls.token_pos());
4784 enum_value.set_type(dynamic_type); 4784 enum_value.set_type(dynamic_type);
4785 enum_value.set_has_initializer(false); 4785 enum_value.set_has_initializer(false);
4786 enum_members.AddField(enum_value); 4786 enum_members.AddField(enum_value);
4787 // Initialize the field with the ordinal value. It will be patched 4787 // Initialize the field with the ordinal value. It will be patched
4788 // later with the enum constant instance. 4788 // later with the enum constant instance.
4789 const Smi& ordinal_value = Smi::Handle(Z, Smi::New(i)); 4789 const Smi& ordinal_value = Smi::Handle(Z, Smi::New(i));
4790 enum_value.set_value(ordinal_value); 4790 enum_value.SetStaticFieldValue(ordinal_value, true);
4791 enum_value.RecordStore(ordinal_value); 4791 enum_value.RecordStore(ordinal_value);
4792 i++; 4792 i++;
4793 4793
4794 // For the user-visible name of the enumeration value, we need to 4794 // For the user-visible name of the enumeration value, we need to
4795 // unmangle private names. 4795 // unmangle private names.
4796 if (enum_ident->CharAt(0) == '_') { 4796 if (enum_ident->CharAt(0) == '_') {
4797 *enum_ident = String::IdentifierPrettyName(*enum_ident); 4797 *enum_ident = String::IdentifierPrettyName(*enum_ident);
4798 } 4798 }
4799 enum_value_name = Symbols::FromConcat(name_prefix, *enum_ident); 4799 enum_value_name = Symbols::FromConcat(name_prefix, *enum_ident);
4800 enum_names.Add(enum_value_name, Heap::kOld); 4800 enum_names.Add(enum_value_name, Heap::kOld);
(...skipping 17 matching lines...) Expand all
4818 /* is_const = */ true, 4818 /* is_const = */ true,
4819 /* is_reflectable = */ true, 4819 /* is_reflectable = */ true,
4820 cls, 4820 cls,
4821 cls.token_pos()); 4821 cls.token_pos());
4822 values_field.set_type(Type::Handle(Z, Type::ArrayType())); 4822 values_field.set_type(Type::Handle(Z, Type::ArrayType()));
4823 enum_members.AddField(values_field); 4823 enum_members.AddField(values_field);
4824 4824
4825 // Allocate the immutable array containing the enumeration values. 4825 // Allocate the immutable array containing the enumeration values.
4826 // The actual enum instance values will be patched in later. 4826 // The actual enum instance values will be patched in later.
4827 const Array& values_array = Array::Handle(Z, Array::New(i, Heap::kOld)); 4827 const Array& values_array = Array::Handle(Z, Array::New(i, Heap::kOld));
4828 values_field.set_value(values_array); 4828 values_field.SetStaticFieldValue(values_array, true);
4829 values_field.RecordStore(values_array); 4829 values_field.RecordStore(values_array);
4830 4830
4831 // Create a static field that contains the list of enumeration names. 4831 // Create a static field that contains the list of enumeration names.
4832 // Clone the _enum_names field from the helper class. 4832 // Clone the _enum_names field from the helper class.
4833 Field& names_field = Field::Handle(Z, 4833 Field& names_field = Field::Handle(Z,
4834 helper_class.LookupStaticField(Symbols::_EnumNames())); 4834 helper_class.LookupStaticField(Symbols::_EnumNames()));
4835 ASSERT(!names_field.IsNull()); 4835 ASSERT(!names_field.IsNull());
4836 names_field = names_field.Clone(cls); 4836 names_field = names_field.Clone(cls);
4837 enum_members.AddField(names_field); 4837 enum_members.AddField(names_field);
4838 const Array& names_array = Array::Handle(Array::MakeArray(enum_names)); 4838 const Array& names_array = Array::Handle(Array::MakeArray(enum_names));
4839 names_field.set_value(names_array); 4839 names_field.SetStaticFieldValue(names_array, true);
4840 names_field.RecordStore(names_array); 4840 names_field.RecordStore(names_array);
4841 4841
4842 // Clone the toString() function from the helper class. 4842 // Clone the toString() function from the helper class.
4843 Function& to_string_func = Function::Handle(Z, 4843 Function& to_string_func = Function::Handle(Z,
4844 helper_class.LookupDynamicFunctionAllowPrivate(Symbols::toString())); 4844 helper_class.LookupDynamicFunctionAllowPrivate(Symbols::toString()));
4845 ASSERT(!to_string_func.IsNull()); 4845 ASSERT(!to_string_func.IsNull());
4846 to_string_func = to_string_func.Clone(cls); 4846 to_string_func = to_string_func.Clone(cls);
4847 enum_members.AddFunction(to_string_func); 4847 enum_members.AddFunction(to_string_func);
4848 4848
4849 // Clone the hashCode getter function from the helper class. 4849 // Clone the hashCode getter function from the helper class.
(...skipping 572 matching lines...) Expand 10 before | Expand all | Expand 10 after
5422 if (library_.LookupLocalObject(accessor_name) != Object::null()) { 5422 if (library_.LookupLocalObject(accessor_name) != Object::null()) {
5423 ReportError(name_pos, "setter for '%s' is already defined", 5423 ReportError(name_pos, "setter for '%s' is already defined",
5424 var_name.ToCString()); 5424 var_name.ToCString());
5425 } 5425 }
5426 5426
5427 const bool is_reflectable = 5427 const bool is_reflectable =
5428 !(library_.is_dart_scheme() && library_.IsPrivate(var_name)); 5428 !(library_.is_dart_scheme() && library_.IsPrivate(var_name));
5429 field = Field::New(var_name, is_static, is_final, is_const, is_reflectable, 5429 field = Field::New(var_name, is_static, is_final, is_const, is_reflectable,
5430 current_class(), name_pos); 5430 current_class(), name_pos);
5431 field.set_type(type); 5431 field.set_type(type);
5432 field.set_value(Object::null_instance()); 5432 field.SetStaticFieldValue(Object::null_instance(), true);
5433 top_level->AddField(field); 5433 top_level->AddField(field);
5434 library_.AddObject(field, var_name); 5434 library_.AddObject(field, var_name);
5435 if (metadata_pos >= 0) { 5435 if (metadata_pos >= 0) {
5436 library_.AddFieldMetadata(field, metadata_pos); 5436 library_.AddFieldMetadata(field, metadata_pos);
5437 } 5437 }
5438 if (CurrentToken() == Token::kASSIGN) { 5438 if (CurrentToken() == Token::kASSIGN) {
5439 ConsumeToken(); 5439 ConsumeToken();
5440 Instance& field_value = Instance::Handle(Z, Object::sentinel().raw()); 5440 Instance& field_value = Instance::Handle(Z, Object::sentinel().raw());
5441 bool has_simple_literal = false; 5441 bool has_simple_literal = false;
5442 if (LookaheadToken(1) == Token::kSEMICOLON) { 5442 if (LookaheadToken(1) == Token::kSEMICOLON) {
5443 has_simple_literal = IsSimpleLiteral(type, &field_value); 5443 has_simple_literal = IsSimpleLiteral(type, &field_value);
5444 } 5444 }
5445 SkipExpr(); 5445 SkipExpr();
5446 field.set_value(field_value); 5446 field.SetStaticFieldValue(field_value, true);
5447 field.set_has_initializer(true); 5447 field.set_has_initializer(true);
5448 5448
5449 if (!has_simple_literal) { 5449 if (!has_simple_literal) {
5450 // Create a static final getter. 5450 // Create a static final getter.
5451 String& getter_name = String::Handle(Z, Field::GetterSymbol(var_name)); 5451 String& getter_name = String::Handle(Z, Field::GetterSymbol(var_name));
5452 getter = Function::New(getter_name, 5452 getter = Function::New(getter_name,
5453 RawFunction::kImplicitStaticFinalGetter, 5453 RawFunction::kImplicitStaticFinalGetter,
5454 is_static, 5454 is_static,
5455 is_const, 5455 is_const,
5456 /* is_abstract = */ false, 5456 /* is_abstract = */ false,
(...skipping 5364 matching lines...) Expand 10 before | Expand all | Expand 10 after
10821 return cascade; 10821 return cascade;
10822 } 10822 }
10823 10823
10824 10824
10825 // Convert loading of a static const field into a literal node. 10825 // Convert loading of a static const field into a literal node.
10826 static AstNode* LiteralIfStaticConst(Zone* zone, AstNode* expr) { 10826 static AstNode* LiteralIfStaticConst(Zone* zone, AstNode* expr) {
10827 if (expr->IsLoadStaticFieldNode()) { 10827 if (expr->IsLoadStaticFieldNode()) {
10828 const Field& field = expr->AsLoadStaticFieldNode()->field(); 10828 const Field& field = expr->AsLoadStaticFieldNode()->field();
10829 if (field.is_const() && 10829 if (field.is_const() &&
10830 !expr->AsLoadStaticFieldNode()->is_deferred_reference()) { 10830 !expr->AsLoadStaticFieldNode()->is_deferred_reference()) {
10831 ASSERT(field.value() != Object::sentinel().raw()); 10831 ASSERT(field.StaticFieldValue() != Object::sentinel().raw());
10832 ASSERT(field.value() != Object::transition_sentinel().raw()); 10832 ASSERT(field.StaticFieldValue() != Object::transition_sentinel().raw());
10833 return new(zone) LiteralNode(expr->token_pos(), 10833 return new(zone) LiteralNode(
10834 Instance::ZoneHandle(zone, field.value())); 10834 expr->token_pos(),
10835 Instance::ZoneHandle(zone, field.StaticFieldValue()));
10835 } 10836 }
10836 } 10837 }
10837 return expr; 10838 return expr;
10838 } 10839 }
10839 10840
10840 10841
10841 AstNode* Parser::ParseAwaitableExpr(bool require_compiletime_const, 10842 AstNode* Parser::ParseAwaitableExpr(bool require_compiletime_const,
10842 bool consume_cascades, 10843 bool consume_cascades,
10843 SequenceNode** await_preamble) { 10844 SequenceNode** await_preamble) {
10844 TRACE_PARSER("ParseAwaitableExpr"); 10845 TRACE_PARSER("ParseAwaitableExpr");
(...skipping 1141 matching lines...) Expand 10 before | Expand all | Expand 10 after
11986 // Otherwise, if the field is constant, initialize the field and return no ast. 11987 // Otherwise, if the field is constant, initialize the field and return no ast.
11987 // If the field is not initialized and not const, return the ast for the getter. 11988 // If the field is not initialized and not const, return the ast for the getter.
11988 StaticGetterNode* Parser::RunStaticFieldInitializer(const Field& field, 11989 StaticGetterNode* Parser::RunStaticFieldInitializer(const Field& field,
11989 intptr_t field_ref_pos) { 11990 intptr_t field_ref_pos) {
11990 ASSERT(field.is_static()); 11991 ASSERT(field.is_static());
11991 const Class& field_owner = Class::ZoneHandle(Z, field.owner()); 11992 const Class& field_owner = Class::ZoneHandle(Z, field.owner());
11992 const String& field_name = String::ZoneHandle(Z, field.name()); 11993 const String& field_name = String::ZoneHandle(Z, field.name());
11993 const String& getter_name = String::Handle(Z, Field::GetterName(field_name)); 11994 const String& getter_name = String::Handle(Z, Field::GetterName(field_name));
11994 const Function& getter = Function::Handle(Z, 11995 const Function& getter = Function::Handle(Z,
11995 field_owner.LookupStaticFunction(getter_name)); 11996 field_owner.LookupStaticFunction(getter_name));
11996 const Instance& value = Instance::Handle(Z, field.value()); 11997 const Instance& value = Instance::Handle(Z, field.StaticFieldValue());
11997 if (value.raw() == Object::transition_sentinel().raw()) { 11998 if (value.raw() == Object::transition_sentinel().raw()) {
11998 if (field.is_const()) { 11999 if (field.is_const()) {
11999 ReportError("circular dependency while initializing static field '%s'", 12000 ReportError("circular dependency while initializing static field '%s'",
12000 field_name.ToCString()); 12001 field_name.ToCString());
12001 } else { 12002 } else {
12002 // The implicit static getter will throw the exception if necessary. 12003 // The implicit static getter will throw the exception if necessary.
12003 return new(Z) StaticGetterNode( 12004 return new(Z) StaticGetterNode(
12004 field_ref_pos, NULL, field_owner, field_name); 12005 field_ref_pos, NULL, field_owner, field_name);
12005 } 12006 }
12006 } else if (value.raw() == Object::sentinel().raw()) { 12007 } else if (value.raw() == Object::sentinel().raw()) {
12007 // This field has not been referenced yet and thus the value has 12008 // This field has not been referenced yet and thus the value has
12008 // not been evaluated. If the field is const, call the static getter method 12009 // not been evaluated. If the field is const, call the static getter method
12009 // to evaluate the expression and canonicalize the value. 12010 // to evaluate the expression and canonicalize the value.
12010 if (field.is_const()) { 12011 if (field.is_const()) {
12011 field.set_value(Object::transition_sentinel()); 12012 field.SetStaticFieldValue(Object::transition_sentinel());
12012 const int kNumArguments = 0; // no arguments. 12013 const int kNumArguments = 0; // no arguments.
12013 const Function& func = Function::Handle(Z, 12014 const Function& func = Function::Handle(Z,
12014 Resolver::ResolveStatic(field_owner, 12015 Resolver::ResolveStatic(field_owner,
12015 getter_name, 12016 getter_name,
12016 kNumArguments, 12017 kNumArguments,
12017 Object::empty_array())); 12018 Object::empty_array()));
12018 ASSERT(!func.IsNull()); 12019 ASSERT(!func.IsNull());
12019 ASSERT(func.kind() == RawFunction::kImplicitStaticFinalGetter); 12020 ASSERT(func.kind() == RawFunction::kImplicitStaticFinalGetter);
12020 Object& const_value = Object::Handle(Z); 12021 Object& const_value = Object::Handle(Z);
12021 { 12022 {
12022 PAUSETIMERSCOPE(T, time_compilation); 12023 PAUSETIMERSCOPE(T, time_compilation);
12023 const_value = DartEntry::InvokeFunction(func, Object::empty_array()); 12024 const_value = DartEntry::InvokeFunction(func, Object::empty_array());
12024 } 12025 }
12025 if (const_value.IsError()) { 12026 if (const_value.IsError()) {
12026 const Error& error = Error::Cast(const_value); 12027 const Error& error = Error::Cast(const_value);
12027 if (error.IsUnhandledException()) { 12028 if (error.IsUnhandledException()) {
12028 // An exception may not occur in every parse attempt, i.e., the 12029 // An exception may not occur in every parse attempt, i.e., the
12029 // generated AST is not deterministic. Therefore mark the function as 12030 // generated AST is not deterministic. Therefore mark the function as
12030 // not optimizable. 12031 // not optimizable.
12031 current_function().SetIsOptimizable(false); 12032 current_function().SetIsOptimizable(false);
12032 field.set_value(Object::null_instance()); 12033 field.SetStaticFieldValue(Object::null_instance());
12033 // It is a compile-time error if evaluation of a compile-time constant 12034 // It is a compile-time error if evaluation of a compile-time constant
12034 // would raise an exception. 12035 // would raise an exception.
12035 const String& field_name = String::Handle(Z, field.name()); 12036 const String& field_name = String::Handle(Z, field.name());
12036 ReportErrors(error, 12037 ReportErrors(error,
12037 script_, field_ref_pos, 12038 script_, field_ref_pos,
12038 "error initializing const field '%s'", 12039 "error initializing const field '%s'",
12039 field_name.ToCString()); 12040 field_name.ToCString());
12040 } else { 12041 } else {
12041 ReportError(error); 12042 ReportError(error);
12042 } 12043 }
12043 UNREACHABLE(); 12044 UNREACHABLE();
12044 } 12045 }
12045 ASSERT(const_value.IsNull() || const_value.IsInstance()); 12046 ASSERT(const_value.IsNull() || const_value.IsInstance());
12046 Instance& instance = Instance::Handle(Z); 12047 Instance& instance = Instance::Handle(Z);
12047 instance ^= const_value.raw(); 12048 instance ^= const_value.raw();
12048 instance = TryCanonicalize(instance, field_ref_pos); 12049 instance = TryCanonicalize(instance, field_ref_pos);
12049 field.set_value(instance); 12050 field.SetStaticFieldValue(instance);
12050 return NULL; // Constant 12051 return NULL; // Constant
12051 } else { 12052 } else {
12052 return new(Z) StaticGetterNode( 12053 return new(Z) StaticGetterNode(
12053 field_ref_pos, NULL, field_owner, field_name); 12054 field_ref_pos, NULL, field_owner, field_name);
12054 } 12055 }
12055 } 12056 }
12056 if (getter.IsNull() || 12057 if (getter.IsNull() ||
12057 (getter.kind() == RawFunction::kImplicitStaticFinalGetter)) { 12058 (getter.kind() == RawFunction::kImplicitStaticFinalGetter)) {
12058 return NULL; 12059 return NULL;
12059 } 12060 }
(...skipping 1843 matching lines...) Expand 10 before | Expand all | Expand 10 after
13903 if (expr->IsLiteralNode()) { 13904 if (expr->IsLiteralNode()) {
13904 return expr->AsLiteralNode()->literal(); 13905 return expr->AsLiteralNode()->literal();
13905 } else if (expr->IsLoadLocalNode() && 13906 } else if (expr->IsLoadLocalNode() &&
13906 expr->AsLoadLocalNode()->local().IsConst()) { 13907 expr->AsLoadLocalNode()->local().IsConst()) {
13907 return *expr->AsLoadLocalNode()->local().ConstValue(); 13908 return *expr->AsLoadLocalNode()->local().ConstValue();
13908 } else if (expr->IsLoadStaticFieldNode()) { 13909 } else if (expr->IsLoadStaticFieldNode()) {
13909 const Field& field = expr->AsLoadStaticFieldNode()->field(); 13910 const Field& field = expr->AsLoadStaticFieldNode()->field();
13910 // We already checked that this field is const and has been 13911 // We already checked that this field is const and has been
13911 // initialized. 13912 // initialized.
13912 ASSERT(field.is_const()); 13913 ASSERT(field.is_const());
13913 ASSERT(field.value() != Object::sentinel().raw()); 13914 ASSERT(field.StaticFieldValue() != Object::sentinel().raw());
13914 ASSERT(field.value() != Object::transition_sentinel().raw()); 13915 ASSERT(field.StaticFieldValue() != Object::transition_sentinel().raw());
13915 return Instance::ZoneHandle(Z, field.value()); 13916 return Instance::ZoneHandle(Z, field.StaticFieldValue());
13916 } else { 13917 } else {
13917 ASSERT(expr->EvalConstExpr() != NULL); 13918 ASSERT(expr->EvalConstExpr() != NULL);
13918 ReturnNode* ret = new(Z) ReturnNode(expr->token_pos(), expr); 13919 ReturnNode* ret = new(Z) ReturnNode(expr->token_pos(), expr);
13919 // Compile time constant expressions cannot reference anything from a 13920 // Compile time constant expressions cannot reference anything from a
13920 // local scope. 13921 // local scope.
13921 LocalScope* empty_scope = new(Z) LocalScope(NULL, 0, 0); 13922 LocalScope* empty_scope = new(Z) LocalScope(NULL, 0, 0);
13922 SequenceNode* seq = new(Z) SequenceNode(expr->token_pos(), empty_scope); 13923 SequenceNode* seq = new(Z) SequenceNode(expr->token_pos(), empty_scope);
13923 seq->Add(ret); 13924 seq->Add(ret);
13924 13925
13925 Object& result = Object::Handle(Z, Compiler::ExecuteOnce(seq)); 13926 Object& result = Object::Handle(Z, Compiler::ExecuteOnce(seq));
(...skipping 363 matching lines...) Expand 10 before | Expand all | Expand 10 after
14289 void Parser::SkipQualIdent() { 14290 void Parser::SkipQualIdent() {
14290 ASSERT(IsIdentifier()); 14291 ASSERT(IsIdentifier());
14291 ConsumeToken(); 14292 ConsumeToken();
14292 if (CurrentToken() == Token::kPERIOD) { 14293 if (CurrentToken() == Token::kPERIOD) {
14293 ConsumeToken(); // Consume the kPERIOD token. 14294 ConsumeToken(); // Consume the kPERIOD token.
14294 ExpectIdentifier("identifier expected after '.'"); 14295 ExpectIdentifier("identifier expected after '.'");
14295 } 14296 }
14296 } 14297 }
14297 14298
14298 } // namespace dart 14299 } // namespace dart
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698