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 1769 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1780 return result; | 1780 return result; |
| 1781 } | 1781 } |
| 1782 | 1782 |
| 1783 | 1783 |
| 1784 // Apply the members from the patch class to the original class. | 1784 // Apply the members from the patch class to the original class. |
| 1785 const char* Class::ApplyPatch(const Class& patch) const { | 1785 const char* Class::ApplyPatch(const Class& patch) const { |
| 1786 ASSERT(!is_finalized()); | 1786 ASSERT(!is_finalized()); |
| 1787 // Shared handles used during the iteration. | 1787 // Shared handles used during the iteration. |
| 1788 String& member_name = String::Handle(); | 1788 String& member_name = String::Handle(); |
| 1789 | 1789 |
| 1790 const Script& patch_script = Script::Handle(patch.script()); | 1790 const PatchClass& patch_class = |
| 1791 const PatchClass& patch_class = PatchClass::Handle( | 1791 PatchClass::Handle(PatchClass::New(*this, patch)); |
| 1792 PatchClass::New(*this, patch_script)); | |
| 1793 | 1792 |
| 1794 Array& orig_list = Array::Handle(functions()); | 1793 Array& orig_list = Array::Handle(functions()); |
| 1795 intptr_t orig_len = orig_list.Length(); | 1794 intptr_t orig_len = orig_list.Length(); |
| 1796 Array& patch_list = Array::Handle(patch.functions()); | 1795 Array& patch_list = Array::Handle(patch.functions()); |
| 1797 intptr_t patch_len = patch_list.Length(); | 1796 intptr_t patch_len = patch_list.Length(); |
| 1798 | 1797 |
| 1799 // TODO(iposva): Verify that only patching existing methods and adding only | 1798 // TODO(iposva): Verify that only patching existing methods and adding only |
| 1800 // new private methods. | 1799 // new private methods. |
| 1801 Function& func = Function::Handle(); | 1800 Function& func = Function::Handle(); |
| 1802 Function& orig_func = Function::Handle(); | 1801 Function& orig_func = Function::Handle(); |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 1817 return FormatPatchError("mismatched parameters: %s", member_name); | 1816 return FormatPatchError("mismatched parameters: %s", member_name); |
| 1818 } | 1817 } |
| 1819 } | 1818 } |
| 1820 for (intptr_t i = 0; i < patch_len; i++) { | 1819 for (intptr_t i = 0; i < patch_len; i++) { |
| 1821 func ^= patch_list.At(i); | 1820 func ^= patch_list.At(i); |
| 1822 func.set_owner(patch_class); | 1821 func.set_owner(patch_class); |
| 1823 new_functions.Add(func); | 1822 new_functions.Add(func); |
| 1824 } | 1823 } |
| 1825 Array& new_list = Array::Handle(Array::MakeArray(new_functions)); | 1824 Array& new_list = Array::Handle(Array::MakeArray(new_functions)); |
| 1826 SetFunctions(new_list); | 1825 SetFunctions(new_list); |
| 1827 | 1826 |
|
Ivan Posva
2013/02/05 21:14:02
At this point the functions in the patch class are
Ivan Posva
2013/02/05 21:16:08
Correction your honor!
patch.SetFunctions(Object:
| |
| 1828 // Merge the two list of fields. Raise an error when duplicates are found or | 1827 // Merge the two list of fields. Raise an error when duplicates are found or |
| 1829 // when a public field is being added. | 1828 // when a public field is being added. |
| 1830 orig_list = fields(); | 1829 orig_list = fields(); |
| 1831 orig_len = orig_list.Length(); | 1830 orig_len = orig_list.Length(); |
| 1832 patch_list = patch.fields(); | 1831 patch_list = patch.fields(); |
| 1833 patch_len = patch_list.Length(); | 1832 patch_len = patch_list.Length(); |
| 1834 | 1833 |
| 1835 Field& field = Field::Handle(); | 1834 Field& field = Field::Handle(); |
| 1836 Field& orig_field = Field::Handle(); | 1835 Field& orig_field = Field::Handle(); |
| 1837 new_list = Array::New(patch_len + orig_len); | 1836 new_list = Array::New(patch_len + orig_len); |
| 1838 for (intptr_t i = 0; i < patch_len; i++) { | 1837 for (intptr_t i = 0; i < patch_len; i++) { |
| 1839 field ^= patch_list.At(i); | 1838 field ^= patch_list.At(i); |
| 1840 field.set_owner(*this); | 1839 field.set_owner(*this); |
| 1841 member_name = field.name(); | 1840 member_name = field.name(); |
| 1842 // TODO(iposva): Verify non-public fields only. | 1841 // TODO(iposva): Verify non-public fields only. |
| 1843 | 1842 |
| 1844 // Verify no duplicate additions. | 1843 // Verify no duplicate additions. |
| 1845 orig_field ^= LookupField(member_name); | 1844 orig_field ^= LookupField(member_name); |
| 1846 if (!orig_field.IsNull()) { | 1845 if (!orig_field.IsNull()) { |
| 1847 return FormatPatchError("duplicate field: %s", member_name); | 1846 return FormatPatchError("duplicate field: %s", member_name); |
| 1848 } | 1847 } |
| 1849 new_list.SetAt(i, field); | 1848 new_list.SetAt(i, field); |
| 1850 } | 1849 } |
| 1851 for (intptr_t i = 0; i < orig_len; i++) { | 1850 for (intptr_t i = 0; i < orig_len; i++) { |
| 1852 field ^= orig_list.At(i); | 1851 field ^= orig_list.At(i); |
| 1853 new_list.SetAt(patch_len + i, field); | 1852 new_list.SetAt(patch_len + i, field); |
| 1854 } | 1853 } |
| 1855 SetFields(new_list); | 1854 SetFields(new_list); |
|
Ivan Posva
2013/02/05 21:14:02
ditto for the fields:
patch.SetFields(Array::Handl
Ivan Posva
2013/02/05 21:16:08
ditto
| |
| 1856 return NULL; | 1855 return NULL; |
| 1857 } | 1856 } |
| 1858 | 1857 |
| 1859 | 1858 |
| 1860 void Class::SetFields(const Array& value) const { | 1859 void Class::SetFields(const Array& value) const { |
| 1861 ASSERT(!value.IsNull()); | 1860 ASSERT(!value.IsNull()); |
| 1862 #if defined(DEBUG) | 1861 #if defined(DEBUG) |
| 1863 // Verify that all the fields in the array have this class as owner. | 1862 // Verify that all the fields in the array have this class as owner. |
| 1864 Field& field = Field::Handle(); | 1863 Field& field = Field::Handle(); |
| 1865 intptr_t len = value.Length(); | 1864 intptr_t len = value.Length(); |
| (...skipping 1373 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3239 const Class& cls = Class::Handle(patched_class()); | 3238 const Class& cls = Class::Handle(patched_class()); |
| 3240 const char* cls_name = cls.ToCString(); | 3239 const char* cls_name = cls.ToCString(); |
| 3241 intptr_t len = OS::SNPrint(NULL, 0, kFormat, cls_name) + 1; | 3240 intptr_t len = OS::SNPrint(NULL, 0, kFormat, cls_name) + 1; |
| 3242 char* chars = Isolate::Current()->current_zone()->Alloc<char>(len); | 3241 char* chars = Isolate::Current()->current_zone()->Alloc<char>(len); |
| 3243 OS::SNPrint(chars, len, kFormat, cls_name); | 3242 OS::SNPrint(chars, len, kFormat, cls_name); |
| 3244 return chars; | 3243 return chars; |
| 3245 } | 3244 } |
| 3246 | 3245 |
| 3247 | 3246 |
| 3248 RawPatchClass* PatchClass::New(const Class& patched_class, | 3247 RawPatchClass* PatchClass::New(const Class& patched_class, |
| 3249 const Script& script) { | 3248 const Class& source_class) { |
| 3250 const PatchClass& result = PatchClass::Handle(PatchClass::New()); | 3249 const PatchClass& result = PatchClass::Handle(PatchClass::New()); |
| 3251 result.set_patched_class(patched_class); | 3250 result.set_patched_class(patched_class); |
| 3252 result.set_script(script); | 3251 result.set_source_class(source_class); |
| 3253 return result.raw(); | 3252 return result.raw(); |
| 3254 } | 3253 } |
| 3255 | 3254 |
| 3256 | 3255 |
| 3257 RawPatchClass* PatchClass::New() { | 3256 RawPatchClass* PatchClass::New() { |
| 3258 ASSERT(Object::patch_class_class() != Class::null()); | 3257 ASSERT(Object::patch_class_class() != Class::null()); |
| 3259 RawObject* raw = Object::Allocate(PatchClass::kClassId, | 3258 RawObject* raw = Object::Allocate(PatchClass::kClassId, |
| 3260 PatchClass::InstanceSize(), | 3259 PatchClass::InstanceSize(), |
| 3261 Heap::kOld); | 3260 Heap::kOld); |
| 3262 return reinterpret_cast<RawPatchClass*>(raw); | 3261 return reinterpret_cast<RawPatchClass*>(raw); |
| 3263 } | 3262 } |
| 3264 | 3263 |
| 3265 | 3264 |
| 3265 RawScript* PatchClass::Script() const { | |
| 3266 const Class& source_class = Class::Handle(this->source_class()); | |
| 3267 return source_class.script(); | |
| 3268 } | |
| 3269 | |
| 3270 | |
| 3266 void PatchClass::set_patched_class(const Class& value) const { | 3271 void PatchClass::set_patched_class(const Class& value) const { |
| 3267 StorePointer(&raw_ptr()->patched_class_, value.raw()); | 3272 StorePointer(&raw_ptr()->patched_class_, value.raw()); |
| 3268 } | 3273 } |
| 3269 | 3274 |
| 3270 | 3275 |
| 3271 void PatchClass::set_script(const Script& value) const { | 3276 void PatchClass::set_source_class(const Class& value) const { |
| 3272 StorePointer(&raw_ptr()->script_, value.raw()); | 3277 StorePointer(&raw_ptr()->source_class_, value.raw()); |
| 3273 } | 3278 } |
| 3274 | 3279 |
| 3275 | 3280 |
| 3276 bool Function::HasBreakpoint() const { | 3281 bool Function::HasBreakpoint() const { |
| 3277 return Isolate::Current()->debugger()->HasBreakpoint(*this); | 3282 return Isolate::Current()->debugger()->HasBreakpoint(*this); |
| 3278 } | 3283 } |
| 3279 | 3284 |
| 3280 | 3285 |
| 3281 void Function::SetCode(const Code& value) const { | 3286 void Function::SetCode(const Code& value) const { |
| 3282 StorePointer(&raw_ptr()->code_, value.raw()); | 3287 StorePointer(&raw_ptr()->code_, value.raw()); |
| (...skipping 1085 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4368 return PatchClass::Cast(obj).patched_class(); | 4373 return PatchClass::Cast(obj).patched_class(); |
| 4369 } | 4374 } |
| 4370 | 4375 |
| 4371 | 4376 |
| 4372 RawScript* Function::script() const { | 4377 RawScript* Function::script() const { |
| 4373 const Object& obj = Object::Handle(raw_ptr()->owner_); | 4378 const Object& obj = Object::Handle(raw_ptr()->owner_); |
| 4374 if (obj.IsClass()) { | 4379 if (obj.IsClass()) { |
| 4375 return Class::Cast(obj).script(); | 4380 return Class::Cast(obj).script(); |
| 4376 } | 4381 } |
| 4377 ASSERT(obj.IsPatchClass()); | 4382 ASSERT(obj.IsPatchClass()); |
| 4378 return PatchClass::Cast(obj).script(); | 4383 return PatchClass::Cast(obj).Script(); |
| 4379 } | 4384 } |
| 4380 | 4385 |
| 4381 | 4386 |
| 4382 bool Function::HasOptimizedCode() const { | 4387 bool Function::HasOptimizedCode() const { |
| 4383 return HasCode() && Code::Handle(raw_ptr()->code_).is_optimized(); | 4388 return HasCode() && Code::Handle(raw_ptr()->code_).is_optimized(); |
| 4384 } | 4389 } |
| 4385 | 4390 |
| 4386 | 4391 |
| 4387 RawString* Function::UserVisibleName() const { | 4392 RawString* Function::UserVisibleName() const { |
| 4388 const String& str = String::Handle(name()); | 4393 const String& str = String::Handle(name()); |
| (...skipping 8399 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 12788 } | 12793 } |
| 12789 return result.raw(); | 12794 return result.raw(); |
| 12790 } | 12795 } |
| 12791 | 12796 |
| 12792 | 12797 |
| 12793 const char* WeakProperty::ToCString() const { | 12798 const char* WeakProperty::ToCString() const { |
| 12794 return "_WeakProperty"; | 12799 return "_WeakProperty"; |
| 12795 } | 12800 } |
| 12796 | 12801 |
| 12797 } // namespace dart | 12802 } // namespace dart |
| OLD | NEW |