| 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 3621 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3632 ASSERT(!value.IsNull()); | 3632 ASSERT(!value.IsNull()); |
| 3633 StorePointer(&raw_ptr()->mixin_, value.raw()); | 3633 StorePointer(&raw_ptr()->mixin_, value.raw()); |
| 3634 } | 3634 } |
| 3635 | 3635 |
| 3636 | 3636 |
| 3637 bool Class::IsMixinApplication() const { | 3637 bool Class::IsMixinApplication() const { |
| 3638 return mixin() != Type::null(); | 3638 return mixin() != Type::null(); |
| 3639 } | 3639 } |
| 3640 | 3640 |
| 3641 | 3641 |
| 3642 void Class::set_patch_class(const Class& cls) const { | 3642 void Class::SetPatchClass(const Class& cls) const { |
| 3643 ASSERT(patch_class() == Class::null()); | 3643 ASSERT(GetPatchClass() == Class::null()); |
| 3644 StorePointer(&raw_ptr()->patch_class_, cls.raw()); | 3644 const GrowableObjectArray& patch_classes = |
| 3645 GrowableObjectArray::Handle(Library::Handle(library()).patch_classes()); |
| 3646 patch_classes.Add(cls); |
| 3645 } | 3647 } |
| 3646 | 3648 |
| 3647 | 3649 |
| 3650 RawClass* Class::GetPatchClass() const { |
| 3651 const GrowableObjectArray& patch_classes = |
| 3652 GrowableObjectArray::Handle(Library::Handle(library()).patch_classes()); |
| 3653 Class& pc = Class::Handle(); |
| 3654 for (intptr_t i = 0; i < patch_classes.Length(); i++) { |
| 3655 pc ^= patch_classes.At(i); |
| 3656 if (pc.Name() == this->Name()) { // Names are canonicalized. |
| 3657 return pc.raw(); |
| 3658 } |
| 3659 } |
| 3660 return Class::null(); |
| 3661 } |
| 3662 |
| 3663 |
| 3648 void Class::AddDirectSubclass(const Class& subclass) const { | 3664 void Class::AddDirectSubclass(const Class& subclass) const { |
| 3649 ASSERT(!subclass.IsNull()); | 3665 ASSERT(!subclass.IsNull()); |
| 3650 ASSERT(subclass.SuperClass() == raw()); | 3666 ASSERT(subclass.SuperClass() == raw()); |
| 3651 // Do not keep track of the direct subclasses of class Object. | 3667 // Do not keep track of the direct subclasses of class Object. |
| 3652 ASSERT(!IsObjectClass()); | 3668 ASSERT(!IsObjectClass()); |
| 3653 GrowableObjectArray& direct_subclasses = | 3669 GrowableObjectArray& direct_subclasses = |
| 3654 GrowableObjectArray::Handle(raw_ptr()->direct_subclasses_); | 3670 GrowableObjectArray::Handle(raw_ptr()->direct_subclasses_); |
| 3655 if (direct_subclasses.IsNull()) { | 3671 if (direct_subclasses.IsNull()) { |
| 3656 direct_subclasses = GrowableObjectArray::New(4, Heap::kOld); | 3672 direct_subclasses = GrowableObjectArray::New(4, Heap::kOld); |
| 3657 StorePointer(&raw_ptr()->direct_subclasses_, direct_subclasses.raw()); | 3673 StorePointer(&raw_ptr()->direct_subclasses_, direct_subclasses.raw()); |
| (...skipping 5921 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 9579 | 9595 |
| 9580 RawArray* Library::LoadedScripts() const { | 9596 RawArray* Library::LoadedScripts() const { |
| 9581 // We compute the list of loaded scripts lazily. The result is | 9597 // We compute the list of loaded scripts lazily. The result is |
| 9582 // cached in loaded_scripts_. | 9598 // cached in loaded_scripts_. |
| 9583 if (loaded_scripts() == Array::null()) { | 9599 if (loaded_scripts() == Array::null()) { |
| 9584 // Iterate over the library dictionary and collect all scripts. | 9600 // Iterate over the library dictionary and collect all scripts. |
| 9585 const GrowableObjectArray& scripts = | 9601 const GrowableObjectArray& scripts = |
| 9586 GrowableObjectArray::Handle(GrowableObjectArray::New(8)); | 9602 GrowableObjectArray::Handle(GrowableObjectArray::New(8)); |
| 9587 Object& entry = Object::Handle(); | 9603 Object& entry = Object::Handle(); |
| 9588 Class& cls = Class::Handle(); | 9604 Class& cls = Class::Handle(); |
| 9589 Class& patch_cls = Class::Handle(); | |
| 9590 Script& owner_script = Script::Handle(); | 9605 Script& owner_script = Script::Handle(); |
| 9591 Script& patch_script = Script::Handle(); | |
| 9592 DictionaryIterator it(*this); | 9606 DictionaryIterator it(*this); |
| 9593 while (it.HasNext()) { | 9607 while (it.HasNext()) { |
| 9594 entry = it.GetNext(); | 9608 entry = it.GetNext(); |
| 9595 if (entry.IsClass()) { | 9609 if (entry.IsClass()) { |
| 9596 owner_script = Class::Cast(entry).script(); | 9610 owner_script = Class::Cast(entry).script(); |
| 9597 patch_cls = Class::Cast(entry).patch_class(); | |
| 9598 if (!patch_cls.IsNull()) { | |
| 9599 patch_script = patch_cls.script(); | |
| 9600 AddScriptIfUnique(scripts, patch_script); | |
| 9601 } | |
| 9602 } else if (entry.IsFunction()) { | 9611 } else if (entry.IsFunction()) { |
| 9603 owner_script = Function::Cast(entry).script(); | 9612 owner_script = Function::Cast(entry).script(); |
| 9604 } else if (entry.IsField()) { | 9613 } else if (entry.IsField()) { |
| 9605 cls = Field::Cast(entry).owner(); | 9614 cls = Field::Cast(entry).owner(); |
| 9606 owner_script = cls.script(); | 9615 owner_script = cls.script(); |
| 9607 } else { | 9616 } else { |
| 9608 continue; | 9617 continue; |
| 9609 } | 9618 } |
| 9610 AddScriptIfUnique(scripts, owner_script); | 9619 AddScriptIfUnique(scripts, owner_script); |
| 9611 } | 9620 } |
| 9612 | 9621 |
| 9622 // Add all scripts from patch classes. |
| 9623 GrowableObjectArray& patches = GrowableObjectArray::Handle(patch_classes()); |
| 9624 for (intptr_t i = 0; i < patches.Length(); i++) { |
| 9625 cls ^= patches.At(i); |
| 9626 owner_script = cls.script(); |
| 9627 AddScriptIfUnique(scripts, owner_script); |
| 9628 } |
| 9629 |
| 9613 // Special case: Scripts that only contain external top-level functions are | 9630 // Special case: Scripts that only contain external top-level functions are |
| 9614 // not included above, but can be referenced through a library's anonymous | 9631 // not included above, but can be referenced through a library's anonymous |
| 9615 // classes. Example: dart-core:identical.dart. | 9632 // classes. Example: dart-core:identical.dart. |
| 9616 Array& anon_classes = Array::Handle(anonymous_classes()); | 9633 Array& anon_classes = Array::Handle(anonymous_classes()); |
| 9617 Function& func = Function::Handle(); | 9634 Function& func = Function::Handle(); |
| 9618 Array& functions = Array::Handle(); | 9635 Array& functions = Array::Handle(); |
| 9619 for (intptr_t i = 0; i < anon_classes.Length(); i++) { | 9636 for (intptr_t i = 0; i < anon_classes.Length(); i++) { |
| 9620 cls ^= anon_classes.At(i); | 9637 cls ^= anon_classes.At(i); |
| 9621 if (cls.IsNull()) continue; | 9638 if (cls.IsNull()) continue; |
| 9622 owner_script = cls.script(); | 9639 owner_script = cls.script(); |
| (...skipping 373 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 9996 result.StorePointer(&result.raw_ptr()->name_, Symbols::Empty().raw()); | 10013 result.StorePointer(&result.raw_ptr()->name_, Symbols::Empty().raw()); |
| 9997 result.StorePointer(&result.raw_ptr()->url_, url.raw()); | 10014 result.StorePointer(&result.raw_ptr()->url_, url.raw()); |
| 9998 result.StorePointer(&result.raw_ptr()->resolved_names_, | 10015 result.StorePointer(&result.raw_ptr()->resolved_names_, |
| 9999 Object::empty_array().raw()); | 10016 Object::empty_array().raw()); |
| 10000 result.StorePointer(&result.raw_ptr()->dictionary_, | 10017 result.StorePointer(&result.raw_ptr()->dictionary_, |
| 10001 Object::empty_array().raw()); | 10018 Object::empty_array().raw()); |
| 10002 result.StorePointer(&result.raw_ptr()->metadata_, | 10019 result.StorePointer(&result.raw_ptr()->metadata_, |
| 10003 GrowableObjectArray::New(4, Heap::kOld)); | 10020 GrowableObjectArray::New(4, Heap::kOld)); |
| 10004 result.StorePointer(&result.raw_ptr()->anonymous_classes_, | 10021 result.StorePointer(&result.raw_ptr()->anonymous_classes_, |
| 10005 Object::empty_array().raw()); | 10022 Object::empty_array().raw()); |
| 10023 result.StorePointer(&result.raw_ptr()->patch_classes_, |
| 10024 GrowableObjectArray::New(Object::empty_array(), |
| 10025 Heap::kOld)); |
| 10006 result.StoreNonPointer(&result.raw_ptr()->num_anonymous_, 0); | 10026 result.StoreNonPointer(&result.raw_ptr()->num_anonymous_, 0); |
| 10007 result.StorePointer(&result.raw_ptr()->imports_, Object::empty_array().raw()); | 10027 result.StorePointer(&result.raw_ptr()->imports_, Object::empty_array().raw()); |
| 10008 result.StorePointer(&result.raw_ptr()->exports_, Object::empty_array().raw()); | 10028 result.StorePointer(&result.raw_ptr()->exports_, Object::empty_array().raw()); |
| 10009 result.StorePointer(&result.raw_ptr()->loaded_scripts_, Array::null()); | 10029 result.StorePointer(&result.raw_ptr()->loaded_scripts_, Array::null()); |
| 10010 result.StorePointer(&result.raw_ptr()->load_error_, Instance::null()); | 10030 result.StorePointer(&result.raw_ptr()->load_error_, Instance::null()); |
| 10011 result.set_native_entry_resolver(NULL); | 10031 result.set_native_entry_resolver(NULL); |
| 10012 result.set_native_entry_symbol_resolver(NULL); | 10032 result.set_native_entry_symbol_resolver(NULL); |
| 10013 result.set_is_in_fullsnapshot(false); | 10033 result.set_is_in_fullsnapshot(false); |
| 10014 result.StoreNonPointer(&result.raw_ptr()->corelib_imported_, true); | 10034 result.StoreNonPointer(&result.raw_ptr()->corelib_imported_, true); |
| 10015 result.set_debuggable(false); | 10035 result.set_debuggable(false); |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 10051 // classes are coming from the VM isolate, and are shared between multiple | 10071 // classes are coming from the VM isolate, and are shared between multiple |
| 10052 // isolates so setting their library pointers would be wrong. | 10072 // isolates so setting their library pointers would be wrong. |
| 10053 const Class& cls = Class::Handle(Object::dynamic_class()); | 10073 const Class& cls = Class::Handle(Object::dynamic_class()); |
| 10054 core_lib.AddObject(cls, String::Handle(cls.Name())); | 10074 core_lib.AddObject(cls, String::Handle(cls.Name())); |
| 10055 } | 10075 } |
| 10056 | 10076 |
| 10057 | 10077 |
| 10058 RawObject* Library::Evaluate(const String& expr, | 10078 RawObject* Library::Evaluate(const String& expr, |
| 10059 const Array& param_names, | 10079 const Array& param_names, |
| 10060 const Array& param_values) const { | 10080 const Array& param_values) const { |
| 10061 // Take or make a fake top-level class and evaluate the expression | 10081 // Take a top-level class and evaluate the expression |
| 10062 // as a static function of the class. | 10082 // as a static function of the class. |
| 10063 Class& top_level_class = Class::Handle(); | 10083 Class& top_level_class = Class::Handle(); |
| 10064 Array& top_level_classes = Array::Handle(anonymous_classes()); | 10084 Array& top_level_classes = Array::Handle(anonymous_classes()); |
| 10065 ASSERT(top_level_classes.Length() > 0); | 10085 ASSERT(top_level_classes.Length() > 0); |
| 10066 top_level_class ^= top_level_classes.At(0); | 10086 top_level_class ^= top_level_classes.At(0); |
| 10067 ASSERT(top_level_class.is_finalized()); | 10087 ASSERT(top_level_class.is_finalized()); |
| 10068 return top_level_class.Evaluate(expr, param_names, param_values); | 10088 return top_level_class.Evaluate(expr, param_names, param_values); |
| 10069 } | 10089 } |
| 10070 | 10090 |
| 10071 | 10091 |
| (...skipping 11500 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 21572 return tag_label.ToCString(); | 21592 return tag_label.ToCString(); |
| 21573 } | 21593 } |
| 21574 | 21594 |
| 21575 | 21595 |
| 21576 void UserTag::PrintJSONImpl(JSONStream* stream, bool ref) const { | 21596 void UserTag::PrintJSONImpl(JSONStream* stream, bool ref) const { |
| 21577 Instance::PrintJSONImpl(stream, ref); | 21597 Instance::PrintJSONImpl(stream, ref); |
| 21578 } | 21598 } |
| 21579 | 21599 |
| 21580 | 21600 |
| 21581 } // namespace dart | 21601 } // namespace dart |
| OLD | NEW |