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/cpu.h" | 10 #include "vm/cpu.h" |
(...skipping 7368 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7379 } else { | 7379 } else { |
7380 jsobj.AddProperty("_guardLength", guarded_list_length()); | 7380 jsobj.AddProperty("_guardLength", guarded_list_length()); |
7381 } | 7381 } |
7382 const Class& origin_cls = Class::Handle(origin()); | 7382 const Class& origin_cls = Class::Handle(origin()); |
7383 const Script& script = Script::Handle(origin_cls.script()); | 7383 const Script& script = Script::Handle(origin_cls.script()); |
7384 if (!script.IsNull()) { | 7384 if (!script.IsNull()) { |
7385 jsobj.AddLocation(script, token_pos()); | 7385 jsobj.AddLocation(script, token_pos()); |
7386 } | 7386 } |
7387 } | 7387 } |
7388 | 7388 |
| 7389 // Build a closure object that gets (or sets) the contents of a static |
| 7390 // field f and cache the closure in a newly created static field |
| 7391 // named #f (or #f= in case of a setter). |
| 7392 RawInstance* Field::AccessorClosure(bool make_setter) const { |
| 7393 ASSERT(is_static()); |
| 7394 const Class& field_owner = Class::Handle(owner()); |
| 7395 |
| 7396 String& closure_name = String::Handle(this->name()); |
| 7397 closure_name = Symbols::FromConcat(Symbols::HashMark(), closure_name); |
| 7398 if (make_setter) { |
| 7399 closure_name = Symbols::FromConcat(Symbols::HashMark(), closure_name); |
| 7400 } |
| 7401 |
| 7402 Field& closure_field = Field::Handle(); |
| 7403 closure_field = field_owner.LookupStaticField(closure_name); |
| 7404 if (!closure_field.IsNull()) { |
| 7405 ASSERT(closure_field.is_static()); |
| 7406 const Instance& closure = Instance::Handle(closure_field.value()); |
| 7407 ASSERT(!closure.IsNull()); |
| 7408 ASSERT(closure.IsClosure()); |
| 7409 return closure.raw(); |
| 7410 } |
| 7411 |
| 7412 // This is the first time a closure for this field is requested. |
| 7413 // Create the closure and a new static field in which it is stored. |
| 7414 const char* field_name = String::Handle(name()).ToCString(); |
| 7415 String& expr_src = String::Handle(); |
| 7416 if (make_setter) { |
| 7417 expr_src = |
| 7418 String::NewFormatted("(%s_) { return %s = %s_; }", |
| 7419 field_name, field_name, field_name); |
| 7420 } else { |
| 7421 expr_src = String::NewFormatted("() { return %s; }", field_name); |
| 7422 } |
| 7423 Object& result = |
| 7424 Object::Handle(field_owner.Evaluate(expr_src, |
| 7425 Object::empty_array(), |
| 7426 Object::empty_array())); |
| 7427 ASSERT(result.IsInstance()); |
| 7428 // The caller may expect the closure to be allocated in old space. Copy |
| 7429 // the result here, since Object::Clone() is a private method. |
| 7430 result = Object::Clone(result, Heap::kOld); |
| 7431 |
| 7432 closure_field = Field::New(closure_name, |
| 7433 true, // is_static |
| 7434 true, // is_final |
| 7435 true, // is_const |
| 7436 true, // is_synthetic |
| 7437 field_owner, |
| 7438 this->token_pos()); |
| 7439 closure_field.set_value(Instance::Cast(result)); |
| 7440 closure_field.set_type(Type::Handle(Type::DynamicType())); |
| 7441 field_owner.AddField(closure_field); |
| 7442 |
| 7443 return Instance::RawCast(result.raw()); |
| 7444 } |
| 7445 |
| 7446 |
| 7447 RawInstance* Field::GetterClosure() const { |
| 7448 return AccessorClosure(false); |
| 7449 } |
| 7450 |
| 7451 |
| 7452 RawInstance* Field::SetterClosure() const { |
| 7453 return AccessorClosure(true); |
| 7454 } |
| 7455 |
7389 | 7456 |
7390 RawArray* Field::dependent_code() const { | 7457 RawArray* Field::dependent_code() const { |
7391 return raw_ptr()->dependent_code_; | 7458 return raw_ptr()->dependent_code_; |
7392 } | 7459 } |
7393 | 7460 |
7394 | 7461 |
7395 void Field::set_dependent_code(const Array& array) const { | 7462 void Field::set_dependent_code(const Array& array) const { |
7396 StorePointer(&raw_ptr()->dependent_code_, array.raw()); | 7463 StorePointer(&raw_ptr()->dependent_code_, array.raw()); |
7397 } | 7464 } |
7398 | 7465 |
(...skipping 13811 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
21210 return tag_label.ToCString(); | 21277 return tag_label.ToCString(); |
21211 } | 21278 } |
21212 | 21279 |
21213 | 21280 |
21214 void UserTag::PrintJSONImpl(JSONStream* stream, bool ref) const { | 21281 void UserTag::PrintJSONImpl(JSONStream* stream, bool ref) const { |
21215 Instance::PrintJSONImpl(stream, ref); | 21282 Instance::PrintJSONImpl(stream, ref); |
21216 } | 21283 } |
21217 | 21284 |
21218 | 21285 |
21219 } // namespace dart | 21286 } // namespace dart |
OLD | NEW |