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

Side by Side Diff: runtime/vm/object.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: add-comment 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
« no previous file with comments | « runtime/vm/object.h ('k') | runtime/vm/parser.cc » ('j') | 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/object.h" 5 #include "vm/object.h"
6 6
7 #include "include/dart_api.h" 7 #include "include/dart_api.h"
8 #include "platform/assert.h" 8 #include "platform/assert.h"
9 #include "vm/assembler.h" 9 #include "vm/assembler.h"
10 #include "vm/cpu.h" 10 #include "vm/cpu.h"
(...skipping 1493 matching lines...) Expand 10 before | Expand all | Expand 10 after
1504 String& field_name = String::Handle(isolate); 1504 String& field_name = String::Handle(isolate);
1505 1505
1506 #define CLASS_LIST_WITH_NULL(V) \ 1506 #define CLASS_LIST_WITH_NULL(V) \
1507 V(Null) \ 1507 V(Null) \
1508 CLASS_LIST_NO_OBJECT(V) 1508 CLASS_LIST_NO_OBJECT(V)
1509 1509
1510 #define ADD_SET_FIELD(clazz) \ 1510 #define ADD_SET_FIELD(clazz) \
1511 field_name = Symbols::New("cid"#clazz); \ 1511 field_name = Symbols::New("cid"#clazz); \
1512 field = Field::New(field_name, true, false, true, false, cls, 0); \ 1512 field = Field::New(field_name, true, false, true, false, cls, 0); \
1513 value = Smi::New(k##clazz##Cid); \ 1513 value = Smi::New(k##clazz##Cid); \
1514 field.set_value(value); \ 1514 field.SetStaticValue(value, true); \
1515 field.set_type(Type::Handle(Type::IntType())); \ 1515 field.set_type(Type::Handle(Type::IntType())); \
1516 cls.AddField(field); \ 1516 cls.AddField(field); \
1517 1517
1518 CLASS_LIST_WITH_NULL(ADD_SET_FIELD) 1518 CLASS_LIST_WITH_NULL(ADD_SET_FIELD)
1519 #undef ADD_SET_FIELD 1519 #undef ADD_SET_FIELD
1520 1520
1521 isolate->object_store()->InitKnownObjects(); 1521 isolate->object_store()->InitKnownObjects();
1522 1522
1523 return Error::null(); 1523 return Error::null();
1524 #else // defined(DART_NO_SNAPSHOT). 1524 #else // defined(DART_NO_SNAPSHOT).
(...skipping 5730 matching lines...) Expand 10 before | Expand all | Expand 10 after
7255 RawClass* Field::origin() const { 7255 RawClass* Field::origin() const {
7256 const Object& obj = Object::Handle(raw_ptr()->owner_); 7256 const Object& obj = Object::Handle(raw_ptr()->owner_);
7257 if (obj.IsClass()) { 7257 if (obj.IsClass()) {
7258 return Class::Cast(obj).raw(); 7258 return Class::Cast(obj).raw();
7259 } 7259 }
7260 ASSERT(obj.IsPatchClass()); 7260 ASSERT(obj.IsPatchClass());
7261 return PatchClass::Cast(obj).source_class(); 7261 return PatchClass::Cast(obj).source_class();
7262 } 7262 }
7263 7263
7264 7264
7265 RawInstance* Field::value() const {
7266 ASSERT(is_static()); // Valid only for static dart fields.
7267 return raw_ptr()->value_;
7268 }
7269
7270
7271 void Field::set_value(const Instance& value) const {
7272 ASSERT(is_static()); // Valid only for static dart fields.
7273 StorePointer(&raw_ptr()->value_, value.raw());
7274 }
7275
7276
7277 void Field::set_type(const AbstractType& value) const { 7265 void Field::set_type(const AbstractType& value) const {
7278 ASSERT(!value.IsNull()); 7266 ASSERT(!value.IsNull());
7279 StorePointer(&raw_ptr()->type_, value.raw()); 7267 StorePointer(&raw_ptr()->type_, value.raw());
7280 } 7268 }
7281 7269
7282 7270
7283 RawField* Field::New() { 7271 RawField* Field::New() {
7284 ASSERT(Object::field_class() != Class::null()); 7272 ASSERT(Object::field_class() != Class::null());
7285 RawObject* raw = Object::Allocate(Field::kClassId, 7273 RawObject* raw = Object::Allocate(Field::kClassId,
7286 Field::InstanceSize(), 7274 Field::InstanceSize(),
7287 Heap::kOld); 7275 Heap::kOld);
7288 return reinterpret_cast<RawField*>(raw); 7276 return reinterpret_cast<RawField*>(raw);
7289 } 7277 }
7290 7278
7291 7279
7292 RawField* Field::New(const String& name, 7280 RawField* Field::New(const String& name,
7293 bool is_static, 7281 bool is_static,
7294 bool is_final, 7282 bool is_final,
7295 bool is_const, 7283 bool is_const,
7296 bool is_reflectable, 7284 bool is_reflectable,
7297 const Class& owner, 7285 const Class& owner,
7298 intptr_t token_pos) { 7286 intptr_t token_pos) {
7299 ASSERT(!owner.IsNull()); 7287 ASSERT(!owner.IsNull());
7300 const Field& result = Field::Handle(Field::New()); 7288 const Field& result = Field::Handle(Field::New());
7301 result.set_name(name); 7289 result.set_name(name);
7302 result.set_is_static(is_static); 7290 result.set_is_static(is_static);
7303 if (is_static) { 7291 if (!is_static) {
7304 result.set_value(Object::null_instance());
7305 } else {
7306 result.SetOffset(0); 7292 result.SetOffset(0);
7307 } 7293 }
7308 result.set_is_final(is_final); 7294 result.set_is_final(is_final);
7309 result.set_is_const(is_const); 7295 result.set_is_const(is_const);
7310 result.set_is_reflectable(is_reflectable); 7296 result.set_is_reflectable(is_reflectable);
7311 result.set_is_double_initialized(false); 7297 result.set_is_double_initialized(false);
7312 result.set_owner(owner); 7298 result.set_owner(owner);
7313 result.set_token_pos(token_pos); 7299 result.set_token_pos(token_pos);
7314 result.set_has_initializer(false); 7300 result.set_has_initializer(false);
7315 result.set_is_unboxing_candidate(true); 7301 result.set_is_unboxing_candidate(true);
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
7437 7423
7438 AbstractType& declared_type = AbstractType::Handle(type()); 7424 AbstractType& declared_type = AbstractType::Handle(type());
7439 jsobj.AddProperty("declaredType", declared_type); 7425 jsobj.AddProperty("declaredType", declared_type);
7440 jsobj.AddProperty("static", is_static()); 7426 jsobj.AddProperty("static", is_static());
7441 jsobj.AddProperty("final", is_final()); 7427 jsobj.AddProperty("final", is_final());
7442 jsobj.AddProperty("const", is_const()); 7428 jsobj.AddProperty("const", is_const());
7443 if (ref) { 7429 if (ref) {
7444 return; 7430 return;
7445 } 7431 }
7446 if (is_static()) { 7432 if (is_static()) {
7447 const Instance& valueObj = Instance::Handle(value()); 7433 const Instance& valueObj = Instance::Handle(StaticValue());
7448 jsobj.AddProperty("staticValue", valueObj); 7434 jsobj.AddProperty("staticValue", valueObj);
7449 } 7435 }
7450 7436
7451 jsobj.AddProperty("_guardNullable", is_nullable()); 7437 jsobj.AddProperty("_guardNullable", is_nullable());
7452 if (guarded_cid() == kIllegalCid) { 7438 if (guarded_cid() == kIllegalCid) {
7453 jsobj.AddProperty("_guardClass", "unknown"); 7439 jsobj.AddProperty("_guardClass", "unknown");
7454 } else if (guarded_cid() == kDynamicCid) { 7440 } else if (guarded_cid() == kDynamicCid) {
7455 jsobj.AddProperty("_guardClass", "dynamic"); 7441 jsobj.AddProperty("_guardClass", "dynamic");
7456 } else { 7442 } else {
7457 ClassTable* table = Isolate::Current()->class_table(); 7443 ClassTable* table = Isolate::Current()->class_table();
(...skipping 25 matching lines...) Expand all
7483 String& closure_name = String::Handle(this->name()); 7469 String& closure_name = String::Handle(this->name());
7484 closure_name = Symbols::FromConcat(Symbols::HashMark(), closure_name); 7470 closure_name = Symbols::FromConcat(Symbols::HashMark(), closure_name);
7485 if (make_setter) { 7471 if (make_setter) {
7486 closure_name = Symbols::FromConcat(Symbols::HashMark(), closure_name); 7472 closure_name = Symbols::FromConcat(Symbols::HashMark(), closure_name);
7487 } 7473 }
7488 7474
7489 Field& closure_field = Field::Handle(); 7475 Field& closure_field = Field::Handle();
7490 closure_field = field_owner.LookupStaticField(closure_name); 7476 closure_field = field_owner.LookupStaticField(closure_name);
7491 if (!closure_field.IsNull()) { 7477 if (!closure_field.IsNull()) {
7492 ASSERT(closure_field.is_static()); 7478 ASSERT(closure_field.is_static());
7493 const Instance& closure = Instance::Handle(closure_field.value()); 7479 const Instance& closure =
7480 Instance::Handle(closure_field.StaticValue());
7494 ASSERT(!closure.IsNull()); 7481 ASSERT(!closure.IsNull());
7495 ASSERT(closure.IsClosure()); 7482 ASSERT(closure.IsClosure());
7496 return closure.raw(); 7483 return closure.raw();
7497 } 7484 }
7498 7485
7499 // This is the first time a closure for this field is requested. 7486 // This is the first time a closure for this field is requested.
7500 // Create the closure and a new static field in which it is stored. 7487 // Create the closure and a new static field in which it is stored.
7501 const char* field_name = String::Handle(name()).ToCString(); 7488 const char* field_name = String::Handle(name()).ToCString();
7502 String& expr_src = String::Handle(); 7489 String& expr_src = String::Handle();
7503 if (make_setter) { 7490 if (make_setter) {
(...skipping 12 matching lines...) Expand all
7516 // the result here, since Object::Clone() is a private method. 7503 // the result here, since Object::Clone() is a private method.
7517 result = Object::Clone(result, Heap::kOld); 7504 result = Object::Clone(result, Heap::kOld);
7518 7505
7519 closure_field = Field::New(closure_name, 7506 closure_field = Field::New(closure_name,
7520 true, // is_static 7507 true, // is_static
7521 true, // is_final 7508 true, // is_final
7522 true, // is_const 7509 true, // is_const
7523 false, // is_reflectable 7510 false, // is_reflectable
7524 field_owner, 7511 field_owner,
7525 this->token_pos()); 7512 this->token_pos());
7526 closure_field.set_value(Instance::Cast(result)); 7513 closure_field.SetStaticValue(Instance::Cast(result), true);
7527 closure_field.set_type(Type::Handle(Type::DynamicType())); 7514 closure_field.set_type(Type::Handle(Type::DynamicType()));
7528 field_owner.AddField(closure_field); 7515 field_owner.AddField(closure_field);
7529 7516
7530 return Instance::RawCast(result.raw()); 7517 return Instance::RawCast(result.raw());
7531 } 7518 }
7532 7519
7533 7520
7534 RawInstance* Field::GetterClosure() const { 7521 RawInstance* Field::GetterClosure() const {
7535 return AccessorClosure(false); 7522 return AccessorClosure(false);
7536 } 7523 }
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
7592 } 7579 }
7593 7580
7594 7581
7595 void Field::DeoptimizeDependentCode() const { 7582 void Field::DeoptimizeDependentCode() const {
7596 FieldDependentArray a(*this); 7583 FieldDependentArray a(*this);
7597 a.DisableCode(); 7584 a.DisableCode();
7598 } 7585 }
7599 7586
7600 7587
7601 bool Field::IsUninitialized() const { 7588 bool Field::IsUninitialized() const {
7602 const Instance& value = Instance::Handle(raw_ptr()->value_); 7589 const Instance& value = Instance::Handle(raw_ptr()->value_.static_value_);
7603 ASSERT(value.raw() != Object::transition_sentinel().raw()); 7590 ASSERT(value.raw() != Object::transition_sentinel().raw());
7604 return value.raw() == Object::sentinel().raw(); 7591 return value.raw() == Object::sentinel().raw();
7605 } 7592 }
7606 7593
7607 7594
7608 void Field::set_initializer(const Function& initializer) const { 7595 void Field::SetPrecompiledInitializer(const Function& initializer) const {
7609 StorePointer(&raw_ptr()->initializer_, initializer.raw()); 7596 StorePointer(&raw_ptr()->initializer_.precompiled_, initializer.raw());
7597 }
7598
7599
7600 bool Field::HasPrecompiledInitializer() const {
7601 return raw_ptr()->initializer_.precompiled_->IsFunction();
7602 }
7603
7604
7605 void Field::SetSavedInitialStaticValue(const Instance& value) const {
7606 StorePointer(&raw_ptr()->initializer_.saved_value_, value.raw());
7610 } 7607 }
7611 7608
7612 7609
7613 void Field::EvaluateInitializer() const { 7610 void Field::EvaluateInitializer() const {
7614 ASSERT(is_static()); 7611 ASSERT(is_static());
7615 if (value() == Object::sentinel().raw()) { 7612 if (StaticValue() == Object::sentinel().raw()) {
7616 set_value(Object::transition_sentinel()); 7613 SetStaticValue(Object::transition_sentinel());
7617 Object& value = Object::Handle(Compiler::EvaluateStaticInitializer(*this)); 7614 Object& value = Object::Handle(Compiler::EvaluateStaticInitializer(*this));
7618 if (value.IsError()) { 7615 if (value.IsError()) {
7619 set_value(Object::null_instance()); 7616 SetStaticValue(Object::null_instance());
7620 Exceptions::PropagateError(Error::Cast(value)); 7617 Exceptions::PropagateError(Error::Cast(value));
7621 UNREACHABLE(); 7618 UNREACHABLE();
7622 } 7619 }
7623 ASSERT(value.IsNull() || value.IsInstance()); 7620 ASSERT(value.IsNull() || value.IsInstance());
7624 set_value(value.IsNull() ? Instance::null_instance() 7621 SetStaticValue(value.IsNull() ? Instance::null_instance()
7625 : Instance::Cast(value)); 7622 : Instance::Cast(value));
7626 return; 7623 return;
7627 } else if (value() == Object::transition_sentinel().raw()) { 7624 } else if (StaticValue() == Object::transition_sentinel().raw()) {
7628 set_value(Object::null_instance()); 7625 SetStaticValue(Object::null_instance());
7629 const Array& ctor_args = Array::Handle(Array::New(1)); 7626 const Array& ctor_args = Array::Handle(Array::New(1));
7630 const String& field_name = String::Handle(name()); 7627 const String& field_name = String::Handle(name());
7631 ctor_args.SetAt(0, field_name); 7628 ctor_args.SetAt(0, field_name);
7632 Exceptions::ThrowByType(Exceptions::kCyclicInitializationError, ctor_args); 7629 Exceptions::ThrowByType(Exceptions::kCyclicInitializationError, ctor_args);
7633 UNREACHABLE(); 7630 UNREACHABLE();
7634 return; 7631 return;
7635 } 7632 }
7636 UNREACHABLE(); 7633 UNREACHABLE();
7637 } 7634 }
7638 7635
(...skipping 1469 matching lines...) Expand 10 before | Expand all | Expand 10 after
9108 intptr_t token_pos) const { 9105 intptr_t token_pos) const {
9109 const String& metaname = String::Handle(Symbols::New(name)); 9106 const String& metaname = String::Handle(Symbols::New(name));
9110 Field& field = Field::Handle(Field::New(metaname, 9107 Field& field = Field::Handle(Field::New(metaname,
9111 true, // is_static 9108 true, // is_static
9112 false, // is_final 9109 false, // is_final
9113 false, // is_const 9110 false, // is_const
9114 false, // is_reflectable 9111 false, // is_reflectable
9115 cls, 9112 cls,
9116 token_pos)); 9113 token_pos));
9117 field.set_type(Type::Handle(Type::DynamicType())); 9114 field.set_type(Type::Handle(Type::DynamicType()));
9118 field.set_value(Array::empty_array()); 9115 field.SetStaticValue(Array::empty_array(), true);
9119 GrowableObjectArray& metadata = 9116 GrowableObjectArray& metadata =
9120 GrowableObjectArray::Handle(this->metadata()); 9117 GrowableObjectArray::Handle(this->metadata());
9121 metadata.Add(field, Heap::kOld); 9118 metadata.Add(field, Heap::kOld);
9122 cls.AddField(field); 9119 cls.AddField(field);
9123 } 9120 }
9124 9121
9125 9122
9126 void Library::AddClassMetadata(const Class& cls, 9123 void Library::AddClassMetadata(const Class& cls,
9127 const Class& toplevel_class, 9124 const Class& toplevel_class,
9128 intptr_t token_pos) const { 9125 intptr_t token_pos) const {
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
9202 !obj.IsLibrary() && !obj.IsTypeParameter()) { 9199 !obj.IsLibrary() && !obj.IsTypeParameter()) {
9203 return Object::null(); 9200 return Object::null();
9204 } 9201 }
9205 const String& metaname = String::Handle(MakeMetadataName(obj)); 9202 const String& metaname = String::Handle(MakeMetadataName(obj));
9206 Field& field = Field::Handle(GetMetadataField(metaname)); 9203 Field& field = Field::Handle(GetMetadataField(metaname));
9207 if (field.IsNull()) { 9204 if (field.IsNull()) {
9208 // There is no metadata for this object. 9205 // There is no metadata for this object.
9209 return Object::empty_array().raw(); 9206 return Object::empty_array().raw();
9210 } 9207 }
9211 Object& metadata = Object::Handle(); 9208 Object& metadata = Object::Handle();
9212 metadata = field.value(); 9209 metadata = field.StaticValue();
9213 if (field.value() == Object::empty_array().raw()) { 9210 if (field.StaticValue() == Object::empty_array().raw()) {
9214 metadata = Parser::ParseMetadata(Class::Handle(field.owner()), 9211 metadata = Parser::ParseMetadata(Class::Handle(field.owner()),
9215 field.token_pos()); 9212 field.token_pos());
9216 if (metadata.IsArray()) { 9213 if (metadata.IsArray()) {
9217 ASSERT(Array::Cast(metadata).raw() != Object::empty_array().raw()); 9214 ASSERT(Array::Cast(metadata).raw() != Object::empty_array().raw());
9218 field.set_value(Array::Cast(metadata)); 9215 field.SetStaticValue(Array::Cast(metadata), true);
9219 } 9216 }
9220 } 9217 }
9221 return metadata.raw(); 9218 return metadata.raw();
9222 } 9219 }
9223 9220
9224 9221
9225 static bool ShouldBePrivate(const String& name) { 9222 static bool ShouldBePrivate(const String& name) {
9226 return 9223 return
9227 (name.Length() >= 1 && 9224 (name.Length() >= 1 &&
9228 name.CharAt(0) == '_') || 9225 name.CharAt(0) == '_') ||
(...skipping 1388 matching lines...) Expand 10 before | Expand all | Expand 10 after
10617 void Namespace::AddMetadata(intptr_t token_pos, const Class& owner_class) { 10614 void Namespace::AddMetadata(intptr_t token_pos, const Class& owner_class) {
10618 ASSERT(Field::Handle(metadata_field()).IsNull()); 10615 ASSERT(Field::Handle(metadata_field()).IsNull());
10619 Field& field = Field::Handle(Field::New(Symbols::TopLevel(), 10616 Field& field = Field::Handle(Field::New(Symbols::TopLevel(),
10620 true, // is_static 10617 true, // is_static
10621 false, // is_final 10618 false, // is_final
10622 false, // is_const 10619 false, // is_const
10623 false, // is_reflectable 10620 false, // is_reflectable
10624 owner_class, 10621 owner_class,
10625 token_pos)); 10622 token_pos));
10626 field.set_type(Type::Handle(Type::DynamicType())); 10623 field.set_type(Type::Handle(Type::DynamicType()));
10627 field.set_value(Array::empty_array()); 10624 field.SetStaticValue(Array::empty_array(), true);
10628 set_metadata_field(field); 10625 set_metadata_field(field);
10629 owner_class.AddField(field); 10626 owner_class.AddField(field);
10630 } 10627 }
10631 10628
10632 10629
10633 RawObject* Namespace::GetMetadata() const { 10630 RawObject* Namespace::GetMetadata() const {
10634 Field& field = Field::Handle(metadata_field()); 10631 Field& field = Field::Handle(metadata_field());
10635 if (field.IsNull()) { 10632 if (field.IsNull()) {
10636 // There is no metadata for this object. 10633 // There is no metadata for this object.
10637 return Object::empty_array().raw(); 10634 return Object::empty_array().raw();
10638 } 10635 }
10639 Object& metadata = Object::Handle(); 10636 Object& metadata = Object::Handle();
10640 metadata = field.value(); 10637 metadata = field.StaticValue();
10641 if (field.value() == Object::empty_array().raw()) { 10638 if (field.StaticValue() == Object::empty_array().raw()) {
10642 metadata = Parser::ParseMetadata(Class::Handle(field.owner()), 10639 metadata = Parser::ParseMetadata(Class::Handle(field.owner()),
10643 field.token_pos()); 10640 field.token_pos());
10644 if (metadata.IsArray()) { 10641 if (metadata.IsArray()) {
10645 ASSERT(Array::Cast(metadata).raw() != Object::empty_array().raw()); 10642 ASSERT(Array::Cast(metadata).raw() != Object::empty_array().raw());
10646 field.set_value(Array::Cast(metadata)); 10643 field.SetStaticValue(Array::Cast(metadata), true);
10647 } 10644 }
10648 } 10645 }
10649 return metadata.raw(); 10646 return metadata.raw();
10650 } 10647 }
10651 10648
10652 10649
10653 const char* Namespace::ToCString() const { 10650 const char* Namespace::ToCString() const {
10654 const char* kFormat = "Namespace for library '%s'"; 10651 const char* kFormat = "Namespace for library '%s'";
10655 const Library& lib = Library::Handle(library()); 10652 const Library& lib = Library::Handle(library());
10656 intptr_t len = OS::SNPrint(NULL, 0, kFormat, lib.ToCString()) + 1; 10653 intptr_t len = OS::SNPrint(NULL, 0, kFormat, lib.ToCString()) + 1;
(...skipping 10873 matching lines...) Expand 10 before | Expand all | Expand 10 after
21530 return tag_label.ToCString(); 21527 return tag_label.ToCString();
21531 } 21528 }
21532 21529
21533 21530
21534 void UserTag::PrintJSONImpl(JSONStream* stream, bool ref) const { 21531 void UserTag::PrintJSONImpl(JSONStream* stream, bool ref) const {
21535 Instance::PrintJSONImpl(stream, ref); 21532 Instance::PrintJSONImpl(stream, ref);
21536 } 21533 }
21537 21534
21538 21535
21539 } // namespace dart 21536 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/object.h ('k') | runtime/vm/parser.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698