| 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 3756 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3767 jsobj.AddProperty("type", "Null"); | 3767 jsobj.AddProperty("type", "Null"); |
| 3768 return; | 3768 return; |
| 3769 } | 3769 } |
| 3770 const char* internal_class_name = String::Handle(Name()).ToCString(); | 3770 const char* internal_class_name = String::Handle(Name()).ToCString(); |
| 3771 const char* user_visible_class_name = | 3771 const char* user_visible_class_name = |
| 3772 String::Handle(UserVisibleName()).ToCString(); | 3772 String::Handle(UserVisibleName()).ToCString(); |
| 3773 jsobj.AddProperty("type", JSONType(ref)); | 3773 jsobj.AddProperty("type", JSONType(ref)); |
| 3774 jsobj.AddPropertyF("id", "classes/%" Pd "", id()); | 3774 jsobj.AddPropertyF("id", "classes/%" Pd "", id()); |
| 3775 jsobj.AddProperty("name", internal_class_name); | 3775 jsobj.AddProperty("name", internal_class_name); |
| 3776 jsobj.AddProperty("user_name", user_visible_class_name); | 3776 jsobj.AddProperty("user_name", user_visible_class_name); |
| 3777 if (!ref) { | 3777 if (ref) { |
| 3778 const Error& err = Error::Handle(EnsureIsFinalized(Isolate::Current())); | 3778 return; |
| 3779 if (!err.IsNull()) { | 3779 } |
| 3780 jsobj.AddProperty("error", err); | 3780 |
| 3781 } | 3781 const Error& err = Error::Handle(EnsureIsFinalized(Isolate::Current())); |
| 3782 jsobj.AddProperty("implemented", is_implemented()); | 3782 if (!err.IsNull()) { |
| 3783 jsobj.AddProperty("abstract", is_abstract()); | 3783 jsobj.AddProperty("error", err); |
| 3784 jsobj.AddProperty("patch", is_patch()); | 3784 } |
| 3785 jsobj.AddProperty("finalized", is_finalized()); | 3785 jsobj.AddProperty("implemented", is_implemented()); |
| 3786 jsobj.AddProperty("const", is_const()); | 3786 jsobj.AddProperty("abstract", is_abstract()); |
| 3787 jsobj.AddProperty("super", Class::Handle(SuperClass())); | 3787 jsobj.AddProperty("patch", is_patch()); |
| 3788 jsobj.AddProperty("library", Object::Handle(library())); | 3788 jsobj.AddProperty("finalized", is_finalized()); |
| 3789 { | 3789 jsobj.AddProperty("const", is_const()); |
| 3790 JSONArray fields_array(&jsobj, "fields"); | 3790 jsobj.AddProperty("super", Class::Handle(SuperClass())); |
| 3791 const Array& field_array = Array::Handle(fields()); | 3791 jsobj.AddProperty("library", Object::Handle(library())); |
| 3792 Field& field = Field::Handle(); | 3792 const Script& script = Script::Handle(this->script()); |
| 3793 if (!field_array.IsNull()) { | 3793 intptr_t line_number = 0; |
| 3794 for (intptr_t i = 0; i < field_array.Length(); ++i) { | 3794 intptr_t column_number = 0; |
| 3795 field ^= field_array.At(i); | 3795 script.GetTokenLocation(token_pos(), &line_number, &column_number); |
| 3796 fields_array.AddValue(field); | 3796 jsobj.AddProperty("script", script); |
| 3797 jsobj.AddProperty("line", line_number); |
| 3798 jsobj.AddProperty("col", column_number); |
| 3799 { |
| 3800 JSONArray interfaces_array(&jsobj, "interfaces"); |
| 3801 const Array& interface_array = Array::Handle(interfaces()); |
| 3802 Type& interface_type = Type::Handle(); |
| 3803 Class& interface_cls = Class::Handle(); |
| 3804 if (!interface_array.IsNull()) { |
| 3805 for (intptr_t i = 0; i < interface_array.Length(); ++i) { |
| 3806 // TODO(turnidge): Use the Type directly once regis has added |
| 3807 // types to the vmservice. |
| 3808 interface_type ^= interface_array.At(i); |
| 3809 if (interface_type.HasResolvedTypeClass()) { |
| 3810 interface_cls = interface_type.type_class(); |
| 3811 interfaces_array.AddValue(interface_cls); |
| 3797 } | 3812 } |
| 3798 } | 3813 } |
| 3799 } | 3814 } |
| 3800 { | 3815 } |
| 3801 JSONArray functions_array(&jsobj, "functions"); | 3816 { |
| 3802 const Array& function_array = Array::Handle(functions()); | 3817 JSONArray fields_array(&jsobj, "fields"); |
| 3803 Function& function = Function::Handle(); | 3818 const Array& field_array = Array::Handle(fields()); |
| 3804 if (!function_array.IsNull()) { | 3819 Field& field = Field::Handle(); |
| 3805 for (intptr_t i = 0; i < function_array.Length(); i++) { | 3820 if (!field_array.IsNull()) { |
| 3806 function ^= function_array.At(i); | 3821 for (intptr_t i = 0; i < field_array.Length(); ++i) { |
| 3807 functions_array.AddValue(function); | 3822 field ^= field_array.At(i); |
| 3823 fields_array.AddValue(field); |
| 3824 } |
| 3825 } |
| 3826 } |
| 3827 { |
| 3828 JSONArray functions_array(&jsobj, "functions"); |
| 3829 const Array& function_array = Array::Handle(functions()); |
| 3830 Function& function = Function::Handle(); |
| 3831 if (!function_array.IsNull()) { |
| 3832 for (intptr_t i = 0; i < function_array.Length(); i++) { |
| 3833 function ^= function_array.At(i); |
| 3834 functions_array.AddValue(function); |
| 3835 } |
| 3836 } |
| 3837 } |
| 3838 { |
| 3839 JSONArray subclasses_array(&jsobj, "subclasses"); |
| 3840 const GrowableObjectArray& subclasses = |
| 3841 GrowableObjectArray::Handle(direct_subclasses()); |
| 3842 if (!subclasses.IsNull()) { |
| 3843 Class& subclass = Class::Handle(); |
| 3844 if (!subclasses.IsNull()) { |
| 3845 for (intptr_t i = 0; i < subclasses.Length(); ++i) { |
| 3846 // TODO(turnidge): Use the Type directly once regis has added |
| 3847 // types to the vmservice. |
| 3848 subclass ^= subclasses.At(i); |
| 3849 subclasses_array.AddValue(subclass); |
| 3808 } | 3850 } |
| 3809 } | 3851 } |
| 3810 } | 3852 } |
| 3811 } | 3853 } |
| 3812 } | 3854 } |
| 3813 | 3855 |
| 3814 | 3856 |
| 3815 void Class::InsertCanonicalConstant(intptr_t index, | 3857 void Class::InsertCanonicalConstant(intptr_t index, |
| 3816 const Instance& constant) const { | 3858 const Instance& constant) const { |
| 3817 // The constant needs to be added to the list. Grow the list if it is full. | 3859 // The constant needs to be added to the list. Grow the list if it is full. |
| (...skipping 2267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6085 char* chars = Isolate::Current()->current_zone()->Alloc<char>(len); | 6127 char* chars = Isolate::Current()->current_zone()->Alloc<char>(len); |
| 6086 OS::SNPrint(chars, len, kFormat, function_name, | 6128 OS::SNPrint(chars, len, kFormat, function_name, |
| 6087 static_str, abstract_str, kind_str, const_str); | 6129 static_str, abstract_str, kind_str, const_str); |
| 6088 return chars; | 6130 return chars; |
| 6089 } | 6131 } |
| 6090 | 6132 |
| 6091 | 6133 |
| 6092 void Function::PrintToJSONStream(JSONStream* stream, bool ref) const { | 6134 void Function::PrintToJSONStream(JSONStream* stream, bool ref) const { |
| 6093 const char* internal_name = String::Handle(name()).ToCString(); | 6135 const char* internal_name = String::Handle(name()).ToCString(); |
| 6094 const char* user_name = | 6136 const char* user_name = |
| 6095 String::Handle(QualifiedUserVisibleName()).ToCString(); | 6137 String::Handle(UserVisibleName()).ToCString(); |
| 6096 Class& cls = Class::Handle(Owner()); | 6138 Class& cls = Class::Handle(Owner()); |
| 6097 ASSERT(!cls.IsNull()); | 6139 ASSERT(!cls.IsNull()); |
| 6098 Error& err = Error::Handle(); | 6140 Error& err = Error::Handle(); |
| 6099 err ^= cls.EnsureIsFinalized(Isolate::Current()); | 6141 err ^= cls.EnsureIsFinalized(Isolate::Current()); |
| 6100 ASSERT(err.IsNull()); | 6142 ASSERT(err.IsNull()); |
| 6101 intptr_t id = -1; | 6143 intptr_t id = -1; |
| 6102 const char* selector = NULL; | 6144 const char* selector = NULL; |
| 6103 if (IsNonImplicitClosureFunction()) { | 6145 if (IsNonImplicitClosureFunction()) { |
| 6104 id = cls.FindClosureIndex(*this); | 6146 id = cls.FindClosureIndex(*this); |
| 6105 selector = "closures"; | 6147 selector = "closures"; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 6116 selector = "functions"; | 6158 selector = "functions"; |
| 6117 } | 6159 } |
| 6118 ASSERT(id >= 0); | 6160 ASSERT(id >= 0); |
| 6119 intptr_t cid = cls.id(); | 6161 intptr_t cid = cls.id(); |
| 6120 JSONObject jsobj(stream); | 6162 JSONObject jsobj(stream); |
| 6121 jsobj.AddProperty("type", JSONType(ref)); | 6163 jsobj.AddProperty("type", JSONType(ref)); |
| 6122 jsobj.AddPropertyF("id", "classes/%" Pd "/%s/%" Pd "", cid, selector, id); | 6164 jsobj.AddPropertyF("id", "classes/%" Pd "/%s/%" Pd "", cid, selector, id); |
| 6123 jsobj.AddProperty("name", internal_name); | 6165 jsobj.AddProperty("name", internal_name); |
| 6124 jsobj.AddProperty("user_name", user_name); | 6166 jsobj.AddProperty("user_name", user_name); |
| 6125 jsobj.AddProperty("class", cls); | 6167 jsobj.AddProperty("class", cls); |
| 6168 const Function& parent = Function::Handle(parent_function()); |
| 6169 if (!parent.IsNull()) { |
| 6170 jsobj.AddProperty("parent", parent); |
| 6171 } |
| 6126 const char* kind_string = Function::KindToCString(kind()); | 6172 const char* kind_string = Function::KindToCString(kind()); |
| 6127 jsobj.AddProperty("kind", kind_string); | 6173 jsobj.AddProperty("kind", kind_string); |
| 6128 if (ref) return; | 6174 if (ref) { |
| 6175 return; |
| 6176 } |
| 6129 jsobj.AddProperty("is_static", is_static()); | 6177 jsobj.AddProperty("is_static", is_static()); |
| 6130 jsobj.AddProperty("is_const", is_const()); | 6178 jsobj.AddProperty("is_const", is_const()); |
| 6131 jsobj.AddProperty("is_optimizable", is_optimizable()); | 6179 jsobj.AddProperty("is_optimizable", is_optimizable()); |
| 6132 jsobj.AddProperty("is_inlinable", IsInlineable()); | 6180 jsobj.AddProperty("is_inlinable", IsInlineable()); |
| 6133 jsobj.AddProperty("unoptimized_code", Object::Handle(unoptimized_code())); | 6181 jsobj.AddProperty("unoptimized_code", Object::Handle(unoptimized_code())); |
| 6134 jsobj.AddProperty("usage_counter", usage_counter()); | 6182 jsobj.AddProperty("usage_counter", usage_counter()); |
| 6135 jsobj.AddProperty("optimized_call_site_count", optimized_call_site_count()); | 6183 jsobj.AddProperty("optimized_call_site_count", optimized_call_site_count()); |
| 6136 jsobj.AddProperty("code", Object::Handle(CurrentCode())); | 6184 jsobj.AddProperty("code", Object::Handle(CurrentCode())); |
| 6137 jsobj.AddProperty("deoptimizations", | 6185 jsobj.AddProperty("deoptimizations", |
| 6138 static_cast<intptr_t>(deoptimization_counter())); | 6186 static_cast<intptr_t>(deoptimization_counter())); |
| (...skipping 2633 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8772 const String& name = String::Handle(url()); | 8820 const String& name = String::Handle(url()); |
| 8773 intptr_t len = OS::SNPrint(NULL, 0, kFormat, name.ToCString()) + 1; | 8821 intptr_t len = OS::SNPrint(NULL, 0, kFormat, name.ToCString()) + 1; |
| 8774 char* chars = Isolate::Current()->current_zone()->Alloc<char>(len); | 8822 char* chars = Isolate::Current()->current_zone()->Alloc<char>(len); |
| 8775 OS::SNPrint(chars, len, kFormat, name.ToCString()); | 8823 OS::SNPrint(chars, len, kFormat, name.ToCString()); |
| 8776 return chars; | 8824 return chars; |
| 8777 } | 8825 } |
| 8778 | 8826 |
| 8779 | 8827 |
| 8780 void Library::PrintToJSONStream(JSONStream* stream, bool ref) const { | 8828 void Library::PrintToJSONStream(JSONStream* stream, bool ref) const { |
| 8781 const char* library_name = String::Handle(name()).ToCString(); | 8829 const char* library_name = String::Handle(name()).ToCString(); |
| 8782 const char* library_url = String::Handle(url()).ToCString(); | |
| 8783 intptr_t id = index(); | 8830 intptr_t id = index(); |
| 8784 ASSERT(id >= 0); | 8831 ASSERT(id >= 0); |
| 8785 JSONObject jsobj(stream); | 8832 JSONObject jsobj(stream); |
| 8786 jsobj.AddProperty("type", JSONType(ref)); | 8833 jsobj.AddProperty("type", JSONType(ref)); |
| 8787 jsobj.AddPropertyF("id", "libraries/%" Pd "", id); | 8834 jsobj.AddPropertyF("id", "libraries/%" Pd "", id); |
| 8835 jsobj.AddProperty("user_name", library_name); |
| 8788 jsobj.AddProperty("name", library_name); | 8836 jsobj.AddProperty("name", library_name); |
| 8789 jsobj.AddProperty("user_name", library_url); | 8837 if (ref) { |
| 8790 if (ref) return; | 8838 return; |
| 8839 } |
| 8840 const char* library_url = String::Handle(url()).ToCString(); |
| 8841 jsobj.AddProperty("url", library_url); |
| 8791 { | 8842 { |
| 8792 JSONArray jsarr(&jsobj, "classes"); | 8843 JSONArray jsarr(&jsobj, "classes"); |
| 8793 ClassDictionaryIterator class_iter(*this); | 8844 ClassDictionaryIterator class_iter(*this); |
| 8794 Class& klass = Class::Handle(); | 8845 Class& klass = Class::Handle(); |
| 8795 while (class_iter.HasNext()) { | 8846 while (class_iter.HasNext()) { |
| 8796 klass = class_iter.GetNextClass(); | 8847 klass = class_iter.GetNextClass(); |
| 8797 if (!klass.IsCanonicalSignatureClass() && | 8848 if (!klass.IsCanonicalSignatureClass() && |
| 8798 !klass.IsAnonymousMixinApplication()) { | 8849 !klass.IsAnonymousMixinApplication()) { |
| 8799 jsarr.AddValue(klass); | 8850 jsarr.AddValue(klass); |
| 8800 } | 8851 } |
| 8801 } | 8852 } |
| 8802 } | 8853 } |
| 8803 { | 8854 { |
| 8804 JSONArray jsarr(&jsobj, "libraries"); | 8855 JSONArray jsarr(&jsobj, "imports"); |
| 8805 Library& lib = Library::Handle(); | 8856 Library& lib = Library::Handle(); |
| 8806 for (intptr_t i = 0; i < num_imports(); i++) { | 8857 for (intptr_t i = 0; i < num_imports(); i++) { |
| 8807 lib = ImportLibraryAt(i); | 8858 lib = ImportLibraryAt(i); |
| 8808 jsarr.AddValue(lib); | 8859 jsarr.AddValue(lib); |
| 8809 } | 8860 } |
| 8810 } | 8861 } |
| 8811 { | 8862 { |
| 8812 JSONArray jsarr(&jsobj, "variables"); | 8863 JSONArray jsarr(&jsobj, "variables"); |
| 8813 DictionaryIterator entries(*this); | 8864 DictionaryIterator entries(*this); |
| 8814 Object& entry = Object::Handle(); | 8865 Object& entry = Object::Handle(); |
| (...skipping 8820 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 17635 return "_MirrorReference"; | 17686 return "_MirrorReference"; |
| 17636 } | 17687 } |
| 17637 | 17688 |
| 17638 | 17689 |
| 17639 void MirrorReference::PrintToJSONStream(JSONStream* stream, bool ref) const { | 17690 void MirrorReference::PrintToJSONStream(JSONStream* stream, bool ref) const { |
| 17640 Instance::PrintToJSONStream(stream, ref); | 17691 Instance::PrintToJSONStream(stream, ref); |
| 17641 } | 17692 } |
| 17642 | 17693 |
| 17643 | 17694 |
| 17644 } // namespace dart | 17695 } // namespace dart |
| OLD | NEW |