Chromium Code Reviews| 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 1223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1234 field ^= field_array.At(i); | 1234 field ^= field_array.At(i); |
| 1235 if (!field.is_static()) { | 1235 if (!field.is_static()) { |
| 1236 return true; | 1236 return true; |
| 1237 } | 1237 } |
| 1238 } | 1238 } |
| 1239 return false; | 1239 return false; |
| 1240 } | 1240 } |
| 1241 | 1241 |
| 1242 void Class::SetFunctions(const Array& value) const { | 1242 void Class::SetFunctions(const Array& value) const { |
| 1243 ASSERT(!value.IsNull()); | 1243 ASSERT(!value.IsNull()); |
| 1244 // Bind all the functions in the array to this class. | 1244 #if defined(DEBUG) |
| 1245 // Verify that all the functions in the array have this class as owner. | |
| 1245 Function& func = Function::Handle(); | 1246 Function& func = Function::Handle(); |
| 1246 intptr_t len = value.Length(); | 1247 intptr_t len = value.Length(); |
| 1247 for (intptr_t i = 0; i < len; i++) { | 1248 for (intptr_t i = 0; i < len; i++) { |
| 1248 func ^= value.At(i); | 1249 func ^= value.At(i); |
| 1249 func.set_owner(*this); | 1250 ASSERT(func.owner() == raw()); |
| 1250 } | 1251 } |
| 1252 #endif | |
| 1251 StorePointer(&raw_ptr()->functions_, value.raw()); | 1253 StorePointer(&raw_ptr()->functions_, value.raw()); |
| 1252 } | 1254 } |
| 1253 | 1255 |
| 1254 | 1256 |
| 1255 void Class::AddClosureFunction(const Function& function) const { | 1257 void Class::AddClosureFunction(const Function& function) const { |
| 1256 GrowableObjectArray& closures = | 1258 GrowableObjectArray& closures = |
| 1257 GrowableObjectArray::Handle(raw_ptr()->closure_functions_); | 1259 GrowableObjectArray::Handle(raw_ptr()->closure_functions_); |
| 1258 if (closures.IsNull()) { | 1260 if (closures.IsNull()) { |
| 1259 closures = GrowableObjectArray::New(4); | 1261 closures = GrowableObjectArray::New(4); |
| 1260 StorePointer(&raw_ptr()->closure_functions_, closures.raw()); | 1262 StorePointer(&raw_ptr()->closure_functions_, closures.raw()); |
| (...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1490 if (!is_prefinalized()) { | 1492 if (!is_prefinalized()) { |
| 1491 // Compute offsets of instance fields and instance size. | 1493 // Compute offsets of instance fields and instance size. |
| 1492 CalculateFieldOffsets(); | 1494 CalculateFieldOffsets(); |
| 1493 } | 1495 } |
| 1494 set_is_finalized(); | 1496 set_is_finalized(); |
| 1495 } | 1497 } |
| 1496 | 1498 |
| 1497 | 1499 |
| 1498 void Class::SetFields(const Array& value) const { | 1500 void Class::SetFields(const Array& value) const { |
| 1499 ASSERT(!value.IsNull()); | 1501 ASSERT(!value.IsNull()); |
| 1502 #if defined(DEBUG) | |
| 1503 // Verify that all the fields in the array have this class as owner. | |
| 1500 Field& field = Field::Handle(); | 1504 Field& field = Field::Handle(); |
| 1501 intptr_t len = value.Length(); | 1505 intptr_t len = value.Length(); |
| 1502 for (intptr_t i = 0; i < len; i++) { | 1506 for (intptr_t i = 0; i < len; i++) { |
| 1503 field ^= value.At(i); | 1507 field ^= value.At(i); |
| 1504 field.set_owner(*this); | 1508 ASSERT(field.owner() == raw()); |
| 1505 } | 1509 } |
| 1510 #endif | |
| 1506 // The value of static fields is already initialized to null. | 1511 // The value of static fields is already initialized to null. |
| 1507 StorePointer(&raw_ptr()->fields_, value.raw()); | 1512 StorePointer(&raw_ptr()->fields_, value.raw()); |
| 1508 } | 1513 } |
| 1509 | 1514 |
| 1510 | 1515 |
| 1511 template <class FakeInstance> | 1516 template <class FakeInstance> |
| 1512 RawClass* Class::New(intptr_t index) { | 1517 RawClass* Class::New(intptr_t index) { |
| 1513 ASSERT(Object::class_class() != Class::null()); | 1518 ASSERT(Object::class_class() != Class::null()); |
| 1514 Class& result = Class::Handle(); | 1519 Class& result = Class::Handle(); |
| 1515 { | 1520 { |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1569 RawClass* Class::NewSignatureClass(const String& name, | 1574 RawClass* Class::NewSignatureClass(const String& name, |
| 1570 const Function& signature_function, | 1575 const Function& signature_function, |
| 1571 const Script& script) { | 1576 const Script& script) { |
| 1572 ASSERT(!signature_function.IsNull()); | 1577 ASSERT(!signature_function.IsNull()); |
| 1573 const Class& owner_class = Class::Handle(signature_function.owner()); | 1578 const Class& owner_class = Class::Handle(signature_function.owner()); |
| 1574 ASSERT(!owner_class.IsNull()); | 1579 ASSERT(!owner_class.IsNull()); |
| 1575 TypeArguments& type_parameters = TypeArguments::Handle(); | 1580 TypeArguments& type_parameters = TypeArguments::Handle(); |
| 1576 // A signature class extends class Instance and is parameterized in the same | 1581 // A signature class extends class Instance and is parameterized in the same |
| 1577 // way as the owner class of its non-static signature function. | 1582 // way as the owner class of its non-static signature function. |
| 1578 // It is not type parameterized if its signature function is static. | 1583 // It is not type parameterized if its signature function is static. |
| 1579 if (!signature_function.is_static()) { | 1584 if (!signature_function.is_static() && |
| 1580 if ((owner_class.NumTypeParameters() > 0) && | 1585 (owner_class.NumTypeParameters() > 0) && |
| 1581 !signature_function.HasInstantiatedSignature()) { | 1586 !signature_function.HasInstantiatedSignature()) { |
| 1582 type_parameters = owner_class.type_parameters(); | 1587 type_parameters = owner_class.type_parameters(); |
| 1583 } | |
| 1584 } | 1588 } |
| 1585 const intptr_t token_pos = signature_function.token_pos(); | 1589 const intptr_t token_pos = signature_function.token_pos(); |
| 1586 Class& result = Class::Handle(New<Closure>(name, script, token_pos)); | 1590 Class& result = Class::Handle(New<Closure>(name, script, token_pos)); |
| 1587 const Type& super_type = Type::Handle(Type::ObjectType()); | 1591 const Type& super_type = Type::Handle(Type::ObjectType()); |
| 1588 ASSERT(!super_type.IsNull()); | 1592 ASSERT(!super_type.IsNull()); |
| 1589 result.set_super_type(super_type); | 1593 result.set_super_type(super_type); |
| 1590 result.set_signature_function(signature_function); | 1594 result.set_signature_function(signature_function); |
| 1591 result.set_type_parameters(type_parameters); | 1595 result.set_type_parameters(type_parameters); |
| 1592 result.SetFields(Array::Handle(Array::Empty())); | 1596 result.SetFields(Array::Handle(Array::Empty())); |
| 1593 result.SetFunctions(Array::Handle(Array::Empty())); | 1597 result.SetFunctions(Array::Handle(Array::Empty())); |
| (...skipping 2096 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3690 return outer_function.IsFactory(); | 3694 return outer_function.IsFactory(); |
| 3691 } | 3695 } |
| 3692 | 3696 |
| 3693 | 3697 |
| 3694 void Function::set_name(const String& value) const { | 3698 void Function::set_name(const String& value) const { |
| 3695 ASSERT(value.IsSymbol()); | 3699 ASSERT(value.IsSymbol()); |
| 3696 StorePointer(&raw_ptr()->name_, value.raw()); | 3700 StorePointer(&raw_ptr()->name_, value.raw()); |
| 3697 } | 3701 } |
| 3698 | 3702 |
| 3699 | 3703 |
| 3700 void Function::set_owner(const Class& value) const { | 3704 void Function::set_owner(const Class& value) const { |
|
hausner
2012/08/02 23:25:00
Make this accessor private?
regis
2012/08/02 23:58:37
Good point. Done for Function and for Field.
| |
| 3701 ASSERT(!value.IsNull()); | 3705 ASSERT(!value.IsNull()); |
| 3702 StorePointer(&raw_ptr()->owner_, value.raw()); | 3706 StorePointer(&raw_ptr()->owner_, value.raw()); |
| 3703 } | 3707 } |
| 3704 | 3708 |
| 3705 | 3709 |
| 3706 void Function::set_result_type(const AbstractType& value) const { | 3710 void Function::set_result_type(const AbstractType& value) const { |
| 3707 ASSERT(!value.IsNull()); | 3711 ASSERT(!value.IsNull()); |
| 3708 StorePointer(&raw_ptr()->result_type_, value.raw()); | 3712 StorePointer(&raw_ptr()->result_type_, value.raw()); |
| 3709 } | 3713 } |
| 3710 | 3714 |
| (...skipping 413 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4124 return reinterpret_cast<RawFunction*>(raw); | 4128 return reinterpret_cast<RawFunction*>(raw); |
| 4125 } | 4129 } |
| 4126 | 4130 |
| 4127 | 4131 |
| 4128 RawFunction* Function::New(const String& name, | 4132 RawFunction* Function::New(const String& name, |
| 4129 RawFunction::Kind kind, | 4133 RawFunction::Kind kind, |
| 4130 bool is_static, | 4134 bool is_static, |
| 4131 bool is_const, | 4135 bool is_const, |
| 4132 bool is_abstract, | 4136 bool is_abstract, |
| 4133 bool is_external, | 4137 bool is_external, |
| 4138 const Class& owner, | |
| 4134 intptr_t token_pos) { | 4139 intptr_t token_pos) { |
| 4135 ASSERT(name.IsOneByteString()); | 4140 ASSERT(name.IsOneByteString()); |
| 4141 ASSERT(!owner.IsNull()); | |
| 4136 const Function& result = Function::Handle(Function::New()); | 4142 const Function& result = Function::Handle(Function::New()); |
| 4137 result.set_parameter_types(Array::Handle(Array::Empty())); | 4143 result.set_parameter_types(Array::Handle(Array::Empty())); |
| 4138 result.set_parameter_names(Array::Handle(Array::Empty())); | 4144 result.set_parameter_names(Array::Handle(Array::Empty())); |
| 4139 result.set_name(name); | 4145 result.set_name(name); |
| 4140 result.set_kind(kind); | 4146 result.set_kind(kind); |
| 4141 result.set_is_static(is_static); | 4147 result.set_is_static(is_static); |
| 4142 result.set_is_const(is_const); | 4148 result.set_is_const(is_const); |
| 4143 result.set_is_external(is_external); | 4149 result.set_is_external(is_external); |
| 4150 result.set_owner(owner); | |
| 4144 result.set_token_pos(token_pos); | 4151 result.set_token_pos(token_pos); |
| 4145 result.set_end_token_pos(token_pos); | 4152 result.set_end_token_pos(token_pos); |
| 4146 result.set_num_fixed_parameters(0); | 4153 result.set_num_fixed_parameters(0); |
| 4147 result.set_num_optional_parameters(0); | 4154 result.set_num_optional_parameters(0); |
| 4148 result.set_usage_counter(0); | 4155 result.set_usage_counter(0); |
| 4149 result.set_deoptimization_counter(0); | 4156 result.set_deoptimization_counter(0); |
| 4150 result.set_is_optimizable(true); | 4157 result.set_is_optimizable(true); |
| 4151 result.set_is_native(false); | 4158 result.set_is_native(false); |
| 4152 result.set_is_abstract(is_abstract); | 4159 result.set_is_abstract(is_abstract); |
| 4153 return result.raw(); | 4160 return result.raw(); |
| 4154 } | 4161 } |
| 4155 | 4162 |
| 4156 | 4163 |
| 4157 RawFunction* Function::NewClosureFunction(const String& name, | 4164 RawFunction* Function::NewClosureFunction(const String& name, |
| 4158 const Function& parent, | 4165 const Function& parent, |
| 4159 intptr_t token_pos) { | 4166 intptr_t token_pos) { |
| 4160 ASSERT(name.IsOneByteString()); | 4167 ASSERT(name.IsOneByteString()); |
| 4161 ASSERT(!parent.IsNull()); | 4168 ASSERT(!parent.IsNull()); |
| 4162 const Class& parent_class = Class::Handle(parent.owner()); | 4169 const Class& parent_class = Class::Handle(parent.owner()); |
| 4163 ASSERT(!parent_class.IsNull()); | 4170 ASSERT(!parent_class.IsNull()); |
| 4164 const Function& result = Function::Handle( | 4171 const Function& result = Function::Handle( |
| 4165 Function::New(name, | 4172 Function::New(name, |
| 4166 RawFunction::kClosureFunction, | 4173 RawFunction::kClosureFunction, |
| 4167 /* is_static = */ parent.is_static(), | 4174 /* is_static = */ parent.is_static(), |
| 4168 /* is_const = */ false, | 4175 /* is_const = */ false, |
| 4169 /* is_abstract = */ false, | 4176 /* is_abstract = */ false, |
| 4170 /* is_external = */ false, | 4177 /* is_external = */ false, |
| 4178 parent_class, | |
| 4171 token_pos)); | 4179 token_pos)); |
| 4172 result.set_parent_function(parent); | 4180 result.set_parent_function(parent); |
| 4173 result.set_owner(parent_class); | |
| 4174 return result.raw(); | 4181 return result.raw(); |
| 4175 } | 4182 } |
| 4176 | 4183 |
| 4177 | 4184 |
| 4178 RawFunction* Function::ImplicitClosureFunction() const { | 4185 RawFunction* Function::ImplicitClosureFunction() const { |
| 4179 // Return the existing implicit closure function if any. | 4186 // Return the existing implicit closure function if any. |
| 4180 if (raw_ptr()->implicit_closure_function_ != Function::null()) { | 4187 if (raw_ptr()->implicit_closure_function_ != Function::null()) { |
| 4181 return raw_ptr()->implicit_closure_function_; | 4188 return raw_ptr()->implicit_closure_function_; |
| 4182 } | 4189 } |
| 4183 ASSERT(!IsSignatureFunction() && !IsClosureFunction()); | 4190 ASSERT(!IsSignatureFunction() && !IsClosureFunction()); |
| (...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4491 Field::InstanceSize(), | 4498 Field::InstanceSize(), |
| 4492 Heap::kOld); | 4499 Heap::kOld); |
| 4493 return reinterpret_cast<RawField*>(raw); | 4500 return reinterpret_cast<RawField*>(raw); |
| 4494 } | 4501 } |
| 4495 | 4502 |
| 4496 | 4503 |
| 4497 RawField* Field::New(const String& name, | 4504 RawField* Field::New(const String& name, |
| 4498 bool is_static, | 4505 bool is_static, |
| 4499 bool is_final, | 4506 bool is_final, |
| 4500 bool is_const, | 4507 bool is_const, |
| 4508 const Class& owner, | |
| 4501 intptr_t token_pos) { | 4509 intptr_t token_pos) { |
| 4502 ASSERT(name.IsOneByteString()); | 4510 ASSERT(name.IsOneByteString()); |
| 4511 ASSERT(!owner.IsNull()); | |
| 4503 const Field& result = Field::Handle(Field::New()); | 4512 const Field& result = Field::Handle(Field::New()); |
| 4504 result.set_name(name); | 4513 result.set_name(name); |
| 4505 result.set_is_static(is_static); | 4514 result.set_is_static(is_static); |
| 4506 if (is_static) { | 4515 if (is_static) { |
| 4507 result.set_value(Instance::Handle()); | 4516 result.set_value(Instance::Handle()); |
| 4508 } else { | 4517 } else { |
| 4509 result.SetOffset(0); | 4518 result.SetOffset(0); |
| 4510 } | 4519 } |
| 4511 result.set_is_final(is_final); | 4520 result.set_is_final(is_final); |
| 4512 result.set_is_const(is_const); | 4521 result.set_is_const(is_const); |
| 4522 result.set_owner(owner); | |
| 4513 result.set_token_pos(token_pos); | 4523 result.set_token_pos(token_pos); |
| 4514 result.set_has_initializer(false); | 4524 result.set_has_initializer(false); |
| 4515 return result.raw(); | 4525 return result.raw(); |
| 4516 } | 4526 } |
| 4517 | 4527 |
| 4518 | 4528 |
| 4519 const char* Field::ToCString() const { | 4529 const char* Field::ToCString() const { |
| 4520 const char* kF0 = is_static() ? " static" : ""; | 4530 const char* kF0 = is_static() ? " static" : ""; |
| 4521 const char* kF1 = is_final() ? " final" : ""; | 4531 const char* kF1 = is_final() ? " final" : ""; |
| 4522 const char* kF2 = is_const() ? " const" : ""; | 4532 const char* kF2 = is_const() ? " const" : ""; |
| (...skipping 6543 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 11066 const String& str = String::Handle(pattern()); | 11076 const String& str = String::Handle(pattern()); |
| 11067 const char* format = "JSRegExp: pattern=%s flags=%s"; | 11077 const char* format = "JSRegExp: pattern=%s flags=%s"; |
| 11068 intptr_t len = OS::SNPrint(NULL, 0, format, str.ToCString(), Flags()); | 11078 intptr_t len = OS::SNPrint(NULL, 0, format, str.ToCString(), Flags()); |
| 11069 char* chars = reinterpret_cast<char*>( | 11079 char* chars = reinterpret_cast<char*>( |
| 11070 Isolate::Current()->current_zone()->Allocate(len + 1)); | 11080 Isolate::Current()->current_zone()->Allocate(len + 1)); |
| 11071 OS::SNPrint(chars, (len + 1), format, str.ToCString(), Flags()); | 11081 OS::SNPrint(chars, (len + 1), format, str.ToCString(), Flags()); |
| 11072 return chars; | 11082 return chars; |
| 11073 } | 11083 } |
| 11074 | 11084 |
| 11075 } // namespace dart | 11085 } // namespace dart |
| OLD | NEW |