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 3843 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3854 jsobj.AddProperty("patch", is_patch()); | 3854 jsobj.AddProperty("patch", is_patch()); |
3855 jsobj.AddProperty("finalized", is_finalized()); | 3855 jsobj.AddProperty("finalized", is_finalized()); |
3856 jsobj.AddProperty("const", is_const()); | 3856 jsobj.AddProperty("const", is_const()); |
3857 const Class& superClass = Class::Handle(SuperClass()); | 3857 const Class& superClass = Class::Handle(SuperClass()); |
3858 if (!superClass.IsNull()) { | 3858 if (!superClass.IsNull()) { |
3859 jsobj.AddProperty("super", superClass); | 3859 jsobj.AddProperty("super", superClass); |
3860 } | 3860 } |
3861 jsobj.AddProperty("library", Object::Handle(library())); | 3861 jsobj.AddProperty("library", Object::Handle(library())); |
3862 const Script& script = Script::Handle(this->script()); | 3862 const Script& script = Script::Handle(this->script()); |
3863 if (!script.IsNull()) { | 3863 if (!script.IsNull()) { |
3864 intptr_t line_number = 0; | |
3865 intptr_t column_number = 0; | |
3866 script.GetTokenLocation(token_pos(), &line_number, &column_number); | |
3867 jsobj.AddProperty("script", script); | 3864 jsobj.AddProperty("script", script); |
3868 jsobj.AddProperty("line", line_number); | 3865 jsobj.AddProperty("tokenPos", token_pos()); |
3869 jsobj.AddProperty("col", column_number); | |
3870 } | 3866 } |
3871 { | 3867 { |
3872 JSONArray interfaces_array(&jsobj, "interfaces"); | 3868 JSONArray interfaces_array(&jsobj, "interfaces"); |
3873 const Array& interface_array = Array::Handle(interfaces()); | 3869 const Array& interface_array = Array::Handle(interfaces()); |
3874 Type& interface_type = Type::Handle(); | 3870 Type& interface_type = Type::Handle(); |
3875 Class& interface_cls = Class::Handle(); | 3871 Class& interface_cls = Class::Handle(); |
3876 if (!interface_array.IsNull()) { | 3872 if (!interface_array.IsNull()) { |
3877 for (intptr_t i = 0; i < interface_array.Length(); ++i) { | 3873 for (intptr_t i = 0; i < interface_array.Length(); ++i) { |
3878 // TODO(turnidge): Use the Type directly once regis has added | 3874 // TODO(turnidge): Use the Type directly once regis has added |
3879 // types to the vmservice. | 3875 // types to the vmservice. |
(...skipping 2531 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6411 jsobj.AddProperty("unoptimized_code", Object::Handle(unoptimized_code())); | 6407 jsobj.AddProperty("unoptimized_code", Object::Handle(unoptimized_code())); |
6412 jsobj.AddProperty("usage_counter", usage_counter()); | 6408 jsobj.AddProperty("usage_counter", usage_counter()); |
6413 jsobj.AddProperty("optimized_call_site_count", optimized_call_site_count()); | 6409 jsobj.AddProperty("optimized_call_site_count", optimized_call_site_count()); |
6414 jsobj.AddProperty("code", Object::Handle(CurrentCode())); | 6410 jsobj.AddProperty("code", Object::Handle(CurrentCode())); |
6415 jsobj.AddProperty("deoptimizations", | 6411 jsobj.AddProperty("deoptimizations", |
6416 static_cast<intptr_t>(deoptimization_counter())); | 6412 static_cast<intptr_t>(deoptimization_counter())); |
6417 | 6413 |
6418 const Script& script = Script::Handle(this->script()); | 6414 const Script& script = Script::Handle(this->script()); |
6419 if (!script.IsNull()) { | 6415 if (!script.IsNull()) { |
6420 jsobj.AddProperty("script", script); | 6416 jsobj.AddProperty("script", script); |
6421 jsobj.AddProperty("token_pos", token_pos()); | 6417 jsobj.AddProperty("tokenPos", token_pos()); |
6422 jsobj.AddProperty("end_token_pos", end_token_pos()); | 6418 jsobj.AddProperty("endTokenPos", end_token_pos()); |
6423 } | 6419 } |
6424 } | 6420 } |
6425 | 6421 |
6426 | 6422 |
6427 void ClosureData::set_context_scope(const ContextScope& value) const { | 6423 void ClosureData::set_context_scope(const ContextScope& value) const { |
6428 StorePointer(&raw_ptr()->context_scope_, value.raw()); | 6424 StorePointer(&raw_ptr()->context_scope_, value.raw()); |
6429 } | 6425 } |
6430 | 6426 |
6431 | 6427 |
6432 void ClosureData::set_implicit_static_closure(const Instance& closure) const { | 6428 void ClosureData::set_implicit_static_closure(const Instance& closure) const { |
(...skipping 1404 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7837 result.SetLocationOffset(0, 0); | 7833 result.SetLocationOffset(0, 0); |
7838 return result.raw(); | 7834 return result.raw(); |
7839 } | 7835 } |
7840 | 7836 |
7841 | 7837 |
7842 const char* Script::ToCString() const { | 7838 const char* Script::ToCString() const { |
7843 return "Script"; | 7839 return "Script"; |
7844 } | 7840 } |
7845 | 7841 |
7846 | 7842 |
| 7843 // See also Dart_ScriptGetTokenInfo. |
7847 void Script::PrintToJSONStream(JSONStream* stream, bool ref) const { | 7844 void Script::PrintToJSONStream(JSONStream* stream, bool ref) const { |
7848 JSONObject jsobj(stream); | 7845 JSONObject jsobj(stream); |
7849 jsobj.AddProperty("type", JSONType(ref)); | 7846 jsobj.AddProperty("type", JSONType(ref)); |
7850 const String& name = String::Handle(url()); | 7847 const String& name = String::Handle(url()); |
7851 ASSERT(!name.IsNull()); | 7848 ASSERT(!name.IsNull()); |
7852 const String& encoded_url = String::Handle(String::EncodeURI(name)); | 7849 const String& encoded_url = String::Handle(String::EncodeURI(name)); |
7853 ASSERT(!encoded_url.IsNull()); | 7850 ASSERT(!encoded_url.IsNull()); |
7854 jsobj.AddPropertyF("id", "scripts/%s", encoded_url.ToCString()); | 7851 jsobj.AddPropertyF("id", "scripts/%s", encoded_url.ToCString()); |
7855 jsobj.AddProperty("name", name.ToCString()); | 7852 jsobj.AddProperty("name", name.ToCString()); |
7856 jsobj.AddProperty("user_name", name.ToCString()); | 7853 jsobj.AddProperty("user_name", name.ToCString()); |
7857 jsobj.AddProperty("kind", GetKindAsCString()); | 7854 jsobj.AddProperty("kind", GetKindAsCString()); |
7858 if (ref) { | 7855 if (ref) { |
7859 return; | 7856 return; |
7860 } | 7857 } |
7861 const String& source = String::Handle(Source()); | 7858 const String& source = String::Handle(Source()); |
7862 jsobj.AddProperty("source", source.ToCString()); | 7859 jsobj.AddProperty("source", source.ToCString()); |
| 7860 |
| 7861 // Print the line number table |
| 7862 { |
| 7863 JSONArray tokenPosTable(&jsobj, "tokenPosTable"); |
| 7864 |
| 7865 const TokenStream& tokenStream = TokenStream::Handle(tokens()); |
| 7866 ASSERT(!tokenStream.IsNull()); |
| 7867 TokenStream::Iterator tokens(tokenStream, 0); |
| 7868 |
| 7869 const String& key = Symbols::Empty(); |
| 7870 Scanner scanner(source, key); |
| 7871 scanner.Scan(); |
| 7872 while (scanner.current_token().kind != Token::kEOS) { |
| 7873 ASSERT(tokens.IsValid()); |
| 7874 ASSERT(scanner.current_token().kind == tokens.CurrentTokenKind()); |
| 7875 int current_line = scanner.current_token().position.line; |
| 7876 |
| 7877 // Each entry begins with a line number... |
| 7878 JSONArray lineInfo(&tokenPosTable); |
| 7879 lineInfo.AddValue(current_line + line_offset()); |
| 7880 |
| 7881 // ...and is followed by (token offset, col number) pairs. |
| 7882 // |
| 7883 // TODO(hausner): Could optimize here by not reporting tokens |
| 7884 // that will never be a location used by the debugger, e.g. |
| 7885 // braces, semicolons, most keywords etc. |
| 7886 while (scanner.current_token().kind != Token::kEOS) { |
| 7887 ASSERT(tokens.IsValid()); |
| 7888 ASSERT(scanner.current_token().kind == tokens.CurrentTokenKind()); |
| 7889 |
| 7890 int token_line = scanner.current_token().position.line; |
| 7891 if (token_line != current_line) { |
| 7892 // We have hit a new line. Break to the outer loop. |
| 7893 break; |
| 7894 } |
| 7895 lineInfo.AddValue(tokens.CurrentPosition()); |
| 7896 |
| 7897 intptr_t column = scanner.current_token().position.column; |
| 7898 if (token_line == 1) { |
| 7899 // On the first line of the script we must add the column offset. |
| 7900 column += col_offset(); |
| 7901 } |
| 7902 lineInfo.AddValue(column); |
| 7903 scanner.Scan(); |
| 7904 tokens.Advance(); |
| 7905 } |
| 7906 } |
| 7907 } |
7863 } | 7908 } |
7864 | 7909 |
7865 | 7910 |
7866 DictionaryIterator::DictionaryIterator(const Library& library) | 7911 DictionaryIterator::DictionaryIterator(const Library& library) |
7867 : array_(Array::Handle(library.dictionary())), | 7912 : array_(Array::Handle(library.dictionary())), |
7868 // Last element in array is a Smi indicating the number of entries used. | 7913 // Last element in array is a Smi indicating the number of entries used. |
7869 size_(Array::Handle(library.dictionary()).Length() - 1), | 7914 size_(Array::Handle(library.dictionary()).Length() - 1), |
7870 next_ix_(0) { | 7915 next_ix_(0) { |
7871 MoveToNextObject(); | 7916 MoveToNextObject(); |
7872 } | 7917 } |
(...skipping 10344 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
18217 return "_MirrorReference"; | 18262 return "_MirrorReference"; |
18218 } | 18263 } |
18219 | 18264 |
18220 | 18265 |
18221 void MirrorReference::PrintToJSONStream(JSONStream* stream, bool ref) const { | 18266 void MirrorReference::PrintToJSONStream(JSONStream* stream, bool ref) const { |
18222 Instance::PrintToJSONStream(stream, ref); | 18267 Instance::PrintToJSONStream(stream, ref); |
18223 } | 18268 } |
18224 | 18269 |
18225 | 18270 |
18226 } // namespace dart | 18271 } // namespace dart |
OLD | NEW |