| 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/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/bigint_operations.h" | 10 #include "vm/bigint_operations.h" |
| (...skipping 2057 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2068 } | 2068 } |
| 2069 | 2069 |
| 2070 | 2070 |
| 2071 void Class::set_interfaces(const Array& value) const { | 2071 void Class::set_interfaces(const Array& value) const { |
| 2072 // Verification and resolving of interfaces occurs in finalizer. | 2072 // Verification and resolving of interfaces occurs in finalizer. |
| 2073 ASSERT(!value.IsNull()); | 2073 ASSERT(!value.IsNull()); |
| 2074 StorePointer(&raw_ptr()->interfaces_, value.raw()); | 2074 StorePointer(&raw_ptr()->interfaces_, value.raw()); |
| 2075 } | 2075 } |
| 2076 | 2076 |
| 2077 | 2077 |
| 2078 void Class::set_mixin(const Type& value) const { |
| 2079 // Resolution and application of mixin type occurs in finalizer. |
| 2080 ASSERT(!value.IsNull()); |
| 2081 StorePointer(&raw_ptr()->mixin_, value.raw()); |
| 2082 } |
| 2083 |
| 2084 |
| 2078 void Class::AddDirectSubclass(const Class& subclass) const { | 2085 void Class::AddDirectSubclass(const Class& subclass) const { |
| 2079 ASSERT(!subclass.IsNull()); | 2086 ASSERT(!subclass.IsNull()); |
| 2080 ASSERT(subclass.SuperClass() == raw()); | 2087 ASSERT(subclass.SuperClass() == raw()); |
| 2081 // Do not keep track of the direct subclasses of class Object. | 2088 // Do not keep track of the direct subclasses of class Object. |
| 2082 ASSERT(!IsObjectClass()); | 2089 ASSERT(!IsObjectClass()); |
| 2083 GrowableObjectArray& direct_subclasses = | 2090 GrowableObjectArray& direct_subclasses = |
| 2084 GrowableObjectArray::Handle(raw_ptr()->direct_subclasses_); | 2091 GrowableObjectArray::Handle(raw_ptr()->direct_subclasses_); |
| 2085 if (direct_subclasses.IsNull()) { | 2092 if (direct_subclasses.IsNull()) { |
| 2086 direct_subclasses = GrowableObjectArray::New(4, Heap::kOld); | 2093 direct_subclasses = GrowableObjectArray::New(4, Heap::kOld); |
| 2087 StorePointer(&raw_ptr()->direct_subclasses_, direct_subclasses.raw()); | 2094 StorePointer(&raw_ptr()->direct_subclasses_, direct_subclasses.raw()); |
| (...skipping 1986 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4074 } | 4081 } |
| 4075 } | 4082 } |
| 4076 if (!found_param_name) { | 4083 if (!found_param_name) { |
| 4077 return false; | 4084 return false; |
| 4078 } | 4085 } |
| 4079 } | 4086 } |
| 4080 return true; | 4087 return true; |
| 4081 } | 4088 } |
| 4082 | 4089 |
| 4083 | 4090 |
| 4091 // The compiler generates an implicit constructor if a class definition |
| 4092 // does not contain an explicit constructor or factory. The implicit |
| 4093 // constructor has the same token position as the owner class. |
| 4094 bool Function::IsImplicitConstructor() const { |
| 4095 return IsConstructor() && |
| 4096 (token_pos() == Class::Handle(Owner()).token_pos()); |
| 4097 } |
| 4098 |
| 4099 |
| 4084 bool Function::IsImplicitClosureFunction() const { | 4100 bool Function::IsImplicitClosureFunction() const { |
| 4085 if (!IsClosureFunction()) { | 4101 if (!IsClosureFunction()) { |
| 4086 return false; | 4102 return false; |
| 4087 } | 4103 } |
| 4088 const Function& parent = Function::Handle(parent_function()); | 4104 const Function& parent = Function::Handle(parent_function()); |
| 4089 return (parent.implicit_closure_function() == raw()); | 4105 return (parent.implicit_closure_function() == raw()); |
| 4090 } | 4106 } |
| 4091 | 4107 |
| 4092 | 4108 |
| 4093 RawFunction* Function::New() { | 4109 RawFunction* Function::New() { |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4133 result.set_is_native(false); | 4149 result.set_is_native(false); |
| 4134 result.set_is_inlinable(true); | 4150 result.set_is_inlinable(true); |
| 4135 if (kind == RawFunction::kClosureFunction) { | 4151 if (kind == RawFunction::kClosureFunction) { |
| 4136 const ClosureData& data = ClosureData::Handle(ClosureData::New()); | 4152 const ClosureData& data = ClosureData::Handle(ClosureData::New()); |
| 4137 result.set_data(data); | 4153 result.set_data(data); |
| 4138 } | 4154 } |
| 4139 return result.raw(); | 4155 return result.raw(); |
| 4140 } | 4156 } |
| 4141 | 4157 |
| 4142 | 4158 |
| 4159 RawFunction* Function::Clone(const Class& new_owner) const { |
| 4160 ASSERT(!IsConstructor()); |
| 4161 Function& clone = Function::Handle(); |
| 4162 clone ^= Object::Clone(*this, Heap::kOld); |
| 4163 const Class& owner = Class::Handle(this->Owner()); |
| 4164 const PatchClass& clone_owner = |
| 4165 PatchClass::Handle(PatchClass::New(new_owner, owner)); |
| 4166 clone.set_owner(clone_owner); |
| 4167 clone.StorePointer(&clone.raw_ptr()->code_, Code::null()); |
| 4168 clone.StorePointer(&clone.raw_ptr()->unoptimized_code_, Code::null()); |
| 4169 clone.set_usage_counter(0); |
| 4170 clone.set_deoptimization_counter(0); |
| 4171 clone.set_optimized_instruction_count(0); |
| 4172 clone.set_optimized_call_site_count(0); |
| 4173 return clone.raw(); |
| 4174 } |
| 4175 |
| 4176 |
| 4143 RawFunction* Function::NewClosureFunction(const String& name, | 4177 RawFunction* Function::NewClosureFunction(const String& name, |
| 4144 const Function& parent, | 4178 const Function& parent, |
| 4145 intptr_t token_pos) { | 4179 intptr_t token_pos) { |
| 4146 ASSERT(!parent.IsNull()); | 4180 ASSERT(!parent.IsNull()); |
| 4147 // Use the owner defining the parent function and not the class containing it. | 4181 // Use the owner defining the parent function and not the class containing it. |
| 4148 const Object& parent_owner = Object::Handle(parent.raw_ptr()->owner_); | 4182 const Object& parent_owner = Object::Handle(parent.raw_ptr()->owner_); |
| 4149 ASSERT(!parent_owner.IsNull()); | 4183 ASSERT(!parent_owner.IsNull()); |
| 4150 const Function& result = Function::Handle( | 4184 const Function& result = Function::Handle( |
| 4151 Function::New(name, | 4185 Function::New(name, |
| 4152 RawFunction::kClosureFunction, | 4186 RawFunction::kClosureFunction, |
| (...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4371 RawClass* Function::Owner() const { | 4405 RawClass* Function::Owner() const { |
| 4372 const Object& obj = Object::Handle(raw_ptr()->owner_); | 4406 const Object& obj = Object::Handle(raw_ptr()->owner_); |
| 4373 if (obj.IsClass()) { | 4407 if (obj.IsClass()) { |
| 4374 return Class::Cast(obj).raw(); | 4408 return Class::Cast(obj).raw(); |
| 4375 } | 4409 } |
| 4376 ASSERT(obj.IsPatchClass()); | 4410 ASSERT(obj.IsPatchClass()); |
| 4377 return PatchClass::Cast(obj).patched_class(); | 4411 return PatchClass::Cast(obj).patched_class(); |
| 4378 } | 4412 } |
| 4379 | 4413 |
| 4380 | 4414 |
| 4415 RawClass* Function::origin() const { |
| 4416 const Object& obj = Object::Handle(raw_ptr()->owner_); |
| 4417 if (obj.IsClass()) { |
| 4418 return Class::Cast(obj).raw(); |
| 4419 } |
| 4420 ASSERT(obj.IsPatchClass()); |
| 4421 return PatchClass::Cast(obj).source_class(); |
| 4422 } |
| 4423 |
| 4424 |
| 4381 RawScript* Function::script() const { | 4425 RawScript* Function::script() const { |
| 4382 const Object& obj = Object::Handle(raw_ptr()->owner_); | 4426 const Object& obj = Object::Handle(raw_ptr()->owner_); |
| 4383 if (obj.IsClass()) { | 4427 if (obj.IsClass()) { |
| 4384 return Class::Cast(obj).script(); | 4428 return Class::Cast(obj).script(); |
| 4385 } | 4429 } |
| 4386 ASSERT(obj.IsPatchClass()); | 4430 ASSERT(obj.IsPatchClass()); |
| 4387 return PatchClass::Cast(obj).Script(); | 4431 return PatchClass::Cast(obj).Script(); |
| 4388 } | 4432 } |
| 4389 | 4433 |
| 4390 | 4434 |
| (...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4630 return function_name.StartsWith(String::Handle(String::New(kSetterPrefix))); | 4674 return function_name.StartsWith(String::Handle(String::New(kSetterPrefix))); |
| 4631 } | 4675 } |
| 4632 | 4676 |
| 4633 | 4677 |
| 4634 void Field::set_name(const String& value) const { | 4678 void Field::set_name(const String& value) const { |
| 4635 ASSERT(value.IsSymbol()); | 4679 ASSERT(value.IsSymbol()); |
| 4636 StorePointer(&raw_ptr()->name_, value.raw()); | 4680 StorePointer(&raw_ptr()->name_, value.raw()); |
| 4637 } | 4681 } |
| 4638 | 4682 |
| 4639 | 4683 |
| 4684 RawClass* Field::owner() const { |
| 4685 const Object& obj = Object::Handle(raw_ptr()->owner_); |
| 4686 if (obj.IsClass()) { |
| 4687 return Class::Cast(obj).raw(); |
| 4688 } |
| 4689 ASSERT(obj.IsPatchClass()); |
| 4690 return PatchClass::Cast(obj).patched_class(); |
| 4691 } |
| 4692 |
| 4693 |
| 4694 RawClass* Field::origin() const { |
| 4695 const Object& obj = Object::Handle(raw_ptr()->owner_); |
| 4696 if (obj.IsClass()) { |
| 4697 return Class::Cast(obj).raw(); |
| 4698 } |
| 4699 ASSERT(obj.IsPatchClass()); |
| 4700 return PatchClass::Cast(obj).source_class(); |
| 4701 } |
| 4702 |
| 4703 |
| 4640 RawInstance* Field::value() const { | 4704 RawInstance* Field::value() const { |
| 4641 ASSERT(is_static()); // Valid only for static dart fields. | 4705 ASSERT(is_static()); // Valid only for static dart fields. |
| 4642 return raw_ptr()->value_; | 4706 return raw_ptr()->value_; |
| 4643 } | 4707 } |
| 4644 | 4708 |
| 4645 | 4709 |
| 4646 void Field::set_value(const Instance& value) const { | 4710 void Field::set_value(const Instance& value) const { |
| 4647 ASSERT(is_static()); // Valid only for static dart fields. | 4711 ASSERT(is_static()); // Valid only for static dart fields. |
| 4648 StorePointer(&raw_ptr()->value_, value.raw()); | 4712 StorePointer(&raw_ptr()->value_, value.raw()); |
| 4649 } | 4713 } |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4681 } | 4745 } |
| 4682 result.set_is_final(is_final); | 4746 result.set_is_final(is_final); |
| 4683 result.set_is_const(is_const); | 4747 result.set_is_const(is_const); |
| 4684 result.set_owner(owner); | 4748 result.set_owner(owner); |
| 4685 result.set_token_pos(token_pos); | 4749 result.set_token_pos(token_pos); |
| 4686 result.set_has_initializer(false); | 4750 result.set_has_initializer(false); |
| 4687 return result.raw(); | 4751 return result.raw(); |
| 4688 } | 4752 } |
| 4689 | 4753 |
| 4690 | 4754 |
| 4755 |
| 4756 RawField* Field::Clone(const Class& new_owner) const { |
| 4757 Field& clone = Field::Handle(); |
| 4758 clone ^= Object::Clone(*this, Heap::kOld); |
| 4759 const Class& owner = Class::Handle(this->owner()); |
| 4760 const PatchClass& clone_owner = |
| 4761 PatchClass::Handle(PatchClass::New(new_owner, owner)); |
| 4762 clone.set_owner(clone_owner); |
| 4763 return clone.raw(); |
| 4764 } |
| 4765 |
| 4766 |
| 4691 RawString* Field::UserVisibleName() const { | 4767 RawString* Field::UserVisibleName() const { |
| 4692 const String& str = String::Handle(name()); | 4768 const String& str = String::Handle(name()); |
| 4693 return IdentifierPrettyName(str); | 4769 return IdentifierPrettyName(str); |
| 4694 } | 4770 } |
| 4695 | 4771 |
| 4696 | 4772 |
| 4697 const char* Field::ToCString() const { | 4773 const char* Field::ToCString() const { |
| 4698 const char* kF0 = is_static() ? " static" : ""; | 4774 const char* kF0 = is_static() ? " static" : ""; |
| 4699 const char* kF1 = is_final() ? " final" : ""; | 4775 const char* kF1 = is_final() ? " final" : ""; |
| 4700 const char* kF2 = is_const() ? " const" : ""; | 4776 const char* kF2 = is_const() ? " const" : ""; |
| (...skipping 8092 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 12793 } | 12869 } |
| 12794 return result.raw(); | 12870 return result.raw(); |
| 12795 } | 12871 } |
| 12796 | 12872 |
| 12797 | 12873 |
| 12798 const char* WeakProperty::ToCString() const { | 12874 const char* WeakProperty::ToCString() const { |
| 12799 return "_WeakProperty"; | 12875 return "_WeakProperty"; |
| 12800 } | 12876 } |
| 12801 | 12877 |
| 12802 } // namespace dart | 12878 } // namespace dart |
| OLD | NEW |