| 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 8287 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8298 result.SetLocationOffset(0, 0); | 8298 result.SetLocationOffset(0, 0); |
| 8299 return result.raw(); | 8299 return result.raw(); |
| 8300 } | 8300 } |
| 8301 | 8301 |
| 8302 | 8302 |
| 8303 const char* Script::ToCString() const { | 8303 const char* Script::ToCString() const { |
| 8304 return "Script"; | 8304 return "Script"; |
| 8305 } | 8305 } |
| 8306 | 8306 |
| 8307 | 8307 |
| 8308 RawLibrary* Script::FindLibrary() const { |
| 8309 Isolate* isolate = Isolate::Current(); |
| 8310 const GrowableObjectArray& libs = GrowableObjectArray::Handle( |
| 8311 isolate, isolate->object_store()->libraries()); |
| 8312 Library& lib = Library::Handle(); |
| 8313 Array& scripts = Array::Handle(); |
| 8314 for (intptr_t i = 0; i < libs.Length(); i++) { |
| 8315 lib ^= libs.At(i); |
| 8316 scripts = lib.LoadedScripts(); |
| 8317 for (intptr_t j = 0; j < scripts.Length(); j++) { |
| 8318 if (scripts.At(j) == raw()) { |
| 8319 return lib.raw(); |
| 8320 } |
| 8321 } |
| 8322 } |
| 8323 return Library::null(); |
| 8324 } |
| 8325 |
| 8326 |
| 8308 // See also Dart_ScriptGetTokenInfo. | 8327 // See also Dart_ScriptGetTokenInfo. |
| 8309 void Script::PrintJSONImpl(JSONStream* stream, bool ref) const { | 8328 void Script::PrintJSONImpl(JSONStream* stream, bool ref) const { |
| 8310 JSONObject jsobj(stream); | 8329 JSONObject jsobj(stream); |
| 8311 jsobj.AddProperty("type", JSONType(ref)); | 8330 jsobj.AddProperty("type", JSONType(ref)); |
| 8312 const String& name = String::Handle(url()); | 8331 const String& name = String::Handle(url()); |
| 8313 ASSERT(!name.IsNull()); | 8332 ASSERT(!name.IsNull()); |
| 8314 const String& encoded_url = String::Handle(String::EncodeURI(name)); | 8333 const String& encoded_url = String::Handle(String::EncodeURI(name)); |
| 8315 ASSERT(!encoded_url.IsNull()); | 8334 ASSERT(!encoded_url.IsNull()); |
| 8316 jsobj.AddPropertyF("id", "scripts/%s", encoded_url.ToCString()); | 8335 const Library& lib = Library::Handle(FindLibrary()); |
| 8336 intptr_t lib_index = (lib.IsNull()) ? -1 : lib.index(); |
| 8337 jsobj.AddPropertyF("id", "libraries/%" Pd "/scripts/%s", |
| 8338 lib_index, encoded_url.ToCString()); |
| 8317 jsobj.AddProperty("name", name.ToCString()); | 8339 jsobj.AddProperty("name", name.ToCString()); |
| 8318 jsobj.AddProperty("user_name", name.ToCString()); | 8340 jsobj.AddProperty("user_name", name.ToCString()); |
| 8319 jsobj.AddProperty("kind", GetKindAsCString()); | 8341 jsobj.AddProperty("kind", GetKindAsCString()); |
| 8320 if (ref) { | 8342 if (ref) { |
| 8321 return; | 8343 return; |
| 8322 } | 8344 } |
| 8345 jsobj.AddProperty("owning_library", lib); |
| 8323 const String& source = String::Handle(Source()); | 8346 const String& source = String::Handle(Source()); |
| 8324 jsobj.AddProperty("source", source.ToCString()); | 8347 jsobj.AddProperty("source", source.ToCString()); |
| 8325 | 8348 |
| 8326 // Print the line number table | 8349 // Print the line number table |
| 8327 { | 8350 { |
| 8328 JSONArray tokenPosTable(&jsobj, "tokenPosTable"); | 8351 JSONArray tokenPosTable(&jsobj, "tokenPosTable"); |
| 8329 | 8352 |
| 8330 const GrowableObjectArray& lineNumberArray = | 8353 const GrowableObjectArray& lineNumberArray = |
| 8331 GrowableObjectArray::Handle(GenerateLineNumberArray()); | 8354 GrowableObjectArray::Handle(GenerateLineNumberArray()); |
| 8332 Object& value = Object::Handle(); | 8355 Object& value = Object::Handle(); |
| (...skipping 563 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8896 owner_script = Function::Cast(entry).script(); | 8919 owner_script = Function::Cast(entry).script(); |
| 8897 } else if (entry.IsField()) { | 8920 } else if (entry.IsField()) { |
| 8898 cls = Field::Cast(entry).owner(); | 8921 cls = Field::Cast(entry).owner(); |
| 8899 owner_script = cls.script(); | 8922 owner_script = cls.script(); |
| 8900 } else { | 8923 } else { |
| 8901 continue; | 8924 continue; |
| 8902 } | 8925 } |
| 8903 AddScriptIfUnique(scripts, owner_script); | 8926 AddScriptIfUnique(scripts, owner_script); |
| 8904 } | 8927 } |
| 8905 | 8928 |
| 8929 // Special case: Scripts that only contain external top-level functions are |
| 8930 // not included above, but can be referenced through a library's anonymous |
| 8931 // classes. Example: dart-core:identical.dart. |
| 8932 Array& anon_classes = Array::Handle(anonymous_classes()); |
| 8933 Function& func = Function::Handle(); |
| 8934 Array& functions = Array::Handle(); |
| 8935 for (intptr_t i = 0; i < anon_classes.Length(); i++) { |
| 8936 cls ^= anon_classes.At(i); |
| 8937 if (cls.IsNull()) continue; |
| 8938 owner_script = cls.script(); |
| 8939 AddScriptIfUnique(scripts, owner_script); |
| 8940 functions = cls.functions(); |
| 8941 for (intptr_t j = 0; j < functions.Length(); j++) { |
| 8942 func ^= functions.At(j); |
| 8943 owner_script = func.script(); |
| 8944 AddScriptIfUnique(scripts, owner_script); |
| 8945 } |
| 8946 } |
| 8947 |
| 8906 // Create the array of scripts and cache it in loaded_scripts_. | 8948 // Create the array of scripts and cache it in loaded_scripts_. |
| 8907 const Array& scripts_array = Array::Handle(Array::MakeArray(scripts)); | 8949 const Array& scripts_array = Array::Handle(Array::MakeArray(scripts)); |
| 8908 StorePointer(&raw_ptr()->loaded_scripts_, scripts_array.raw()); | 8950 StorePointer(&raw_ptr()->loaded_scripts_, scripts_array.raw()); |
| 8909 } | 8951 } |
| 8910 return loaded_scripts(); | 8952 return loaded_scripts(); |
| 8911 } | 8953 } |
| 8912 | 8954 |
| 8913 | 8955 |
| 8914 // TODO(hausner): we might want to add a script dictionary to the | 8956 // TODO(hausner): we might want to add a script dictionary to the |
| 8915 // library class to make this lookup faster. | 8957 // library class to make this lookup faster. |
| (...skipping 10165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 19081 return tag_label.ToCString(); | 19123 return tag_label.ToCString(); |
| 19082 } | 19124 } |
| 19083 | 19125 |
| 19084 | 19126 |
| 19085 void UserTag::PrintJSONImpl(JSONStream* stream, bool ref) const { | 19127 void UserTag::PrintJSONImpl(JSONStream* stream, bool ref) const { |
| 19086 Instance::PrintJSONImpl(stream, ref); | 19128 Instance::PrintJSONImpl(stream, ref); |
| 19087 } | 19129 } |
| 19088 | 19130 |
| 19089 | 19131 |
| 19090 } // namespace dart | 19132 } // namespace dart |
| OLD | NEW |