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