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 3837 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3848 jsobj.AddProperty("patch", is_patch()); | 3848 jsobj.AddProperty("patch", is_patch()); |
3849 jsobj.AddProperty("finalized", is_finalized()); | 3849 jsobj.AddProperty("finalized", is_finalized()); |
3850 jsobj.AddProperty("const", is_const()); | 3850 jsobj.AddProperty("const", is_const()); |
3851 const Class& superClass = Class::Handle(SuperClass()); | 3851 const Class& superClass = Class::Handle(SuperClass()); |
3852 if (!superClass.IsNull()) { | 3852 if (!superClass.IsNull()) { |
3853 jsobj.AddProperty("super", superClass); | 3853 jsobj.AddProperty("super", superClass); |
3854 } | 3854 } |
3855 jsobj.AddProperty("library", Object::Handle(library())); | 3855 jsobj.AddProperty("library", Object::Handle(library())); |
3856 const Script& script = Script::Handle(this->script()); | 3856 const Script& script = Script::Handle(this->script()); |
3857 if (!script.IsNull()) { | 3857 if (!script.IsNull()) { |
3858 intptr_t line_number = 0; | |
3859 intptr_t column_number = 0; | |
3860 script.GetTokenLocation(token_pos(), &line_number, &column_number); | |
3861 jsobj.AddProperty("script", script); | 3858 jsobj.AddProperty("script", script); |
3862 jsobj.AddProperty("line", line_number); | 3859 jsobj.AddProperty("tokenPos", token_pos()); |
3863 jsobj.AddProperty("col", column_number); | |
3864 } | 3860 } |
3865 { | 3861 { |
3866 JSONArray interfaces_array(&jsobj, "interfaces"); | 3862 JSONArray interfaces_array(&jsobj, "interfaces"); |
3867 const Array& interface_array = Array::Handle(interfaces()); | 3863 const Array& interface_array = Array::Handle(interfaces()); |
3868 Type& interface_type = Type::Handle(); | 3864 Type& interface_type = Type::Handle(); |
3869 Class& interface_cls = Class::Handle(); | 3865 Class& interface_cls = Class::Handle(); |
3870 if (!interface_array.IsNull()) { | 3866 if (!interface_array.IsNull()) { |
3871 for (intptr_t i = 0; i < interface_array.Length(); ++i) { | 3867 for (intptr_t i = 0; i < interface_array.Length(); ++i) { |
3872 // TODO(turnidge): Use the Type directly once regis has added | 3868 // TODO(turnidge): Use the Type directly once regis has added |
3873 // types to the vmservice. | 3869 // types to the vmservice. |
(...skipping 2488 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6362 jsobj.AddProperty("unoptimized_code", Object::Handle(unoptimized_code())); | 6358 jsobj.AddProperty("unoptimized_code", Object::Handle(unoptimized_code())); |
6363 jsobj.AddProperty("usage_counter", usage_counter()); | 6359 jsobj.AddProperty("usage_counter", usage_counter()); |
6364 jsobj.AddProperty("optimized_call_site_count", optimized_call_site_count()); | 6360 jsobj.AddProperty("optimized_call_site_count", optimized_call_site_count()); |
6365 jsobj.AddProperty("code", Object::Handle(CurrentCode())); | 6361 jsobj.AddProperty("code", Object::Handle(CurrentCode())); |
6366 jsobj.AddProperty("deoptimizations", | 6362 jsobj.AddProperty("deoptimizations", |
6367 static_cast<intptr_t>(deoptimization_counter())); | 6363 static_cast<intptr_t>(deoptimization_counter())); |
6368 | 6364 |
6369 const Script& script = Script::Handle(this->script()); | 6365 const Script& script = Script::Handle(this->script()); |
6370 if (!script.IsNull()) { | 6366 if (!script.IsNull()) { |
6371 jsobj.AddProperty("script", script); | 6367 jsobj.AddProperty("script", script); |
6372 jsobj.AddProperty("token_pos", token_pos()); | 6368 jsobj.AddProperty("tokenPos", token_pos()); |
6373 jsobj.AddProperty("end_token_pos", end_token_pos()); | 6369 jsobj.AddProperty("endTokenPos", end_token_pos()); |
6374 } | 6370 } |
6375 } | 6371 } |
6376 | 6372 |
6377 | 6373 |
6378 void ClosureData::set_context_scope(const ContextScope& value) const { | 6374 void ClosureData::set_context_scope(const ContextScope& value) const { |
6379 StorePointer(&raw_ptr()->context_scope_, value.raw()); | 6375 StorePointer(&raw_ptr()->context_scope_, value.raw()); |
6380 } | 6376 } |
6381 | 6377 |
6382 | 6378 |
6383 void ClosureData::set_implicit_static_closure(const Instance& closure) const { | 6379 void ClosureData::set_implicit_static_closure(const Instance& closure) const { |
(...skipping 1393 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7777 result.SetLocationOffset(0, 0); | 7773 result.SetLocationOffset(0, 0); |
7778 return result.raw(); | 7774 return result.raw(); |
7779 } | 7775 } |
7780 | 7776 |
7781 | 7777 |
7782 const char* Script::ToCString() const { | 7778 const char* Script::ToCString() const { |
7783 return "Script"; | 7779 return "Script"; |
7784 } | 7780 } |
7785 | 7781 |
7786 | 7782 |
| 7783 // See also Dart_ScriptGetTokenInfo. |
7787 void Script::PrintToJSONStream(JSONStream* stream, bool ref) const { | 7784 void Script::PrintToJSONStream(JSONStream* stream, bool ref) const { |
7788 JSONObject jsobj(stream); | 7785 JSONObject jsobj(stream); |
7789 jsobj.AddProperty("type", JSONType(ref)); | 7786 jsobj.AddProperty("type", JSONType(ref)); |
7790 const String& name = String::Handle(url()); | 7787 const String& name = String::Handle(url()); |
7791 ASSERT(!name.IsNull()); | 7788 ASSERT(!name.IsNull()); |
7792 const String& encoded_url = String::Handle(String::EncodeURI(name)); | 7789 const String& encoded_url = String::Handle(String::EncodeURI(name)); |
7793 ASSERT(!encoded_url.IsNull()); | 7790 ASSERT(!encoded_url.IsNull()); |
7794 jsobj.AddPropertyF("id", "scripts/%s", encoded_url.ToCString()); | 7791 jsobj.AddPropertyF("id", "scripts/%s", encoded_url.ToCString()); |
7795 jsobj.AddProperty("name", name.ToCString()); | 7792 jsobj.AddProperty("name", name.ToCString()); |
7796 jsobj.AddProperty("user_name", name.ToCString()); | 7793 jsobj.AddProperty("user_name", name.ToCString()); |
7797 jsobj.AddProperty("kind", GetKindAsCString()); | 7794 jsobj.AddProperty("kind", GetKindAsCString()); |
7798 if (ref) { | 7795 if (ref) { |
7799 return; | 7796 return; |
7800 } | 7797 } |
7801 const String& source = String::Handle(Source()); | 7798 const String& source = String::Handle(Source()); |
7802 jsobj.AddProperty("source", source.ToCString()); | 7799 jsobj.AddProperty("source", source.ToCString()); |
| 7800 |
| 7801 // Print the line number table |
| 7802 { |
| 7803 JSONArray tokenPosTable(&jsobj, "tokenPosTable"); |
| 7804 |
| 7805 const TokenStream& tokenStream = TokenStream::Handle(tokens()); |
| 7806 ASSERT(!tokenStream.IsNull()); |
| 7807 TokenStream::Iterator tokens(tokenStream, 0); |
| 7808 |
| 7809 const String& key = Symbols::Empty(); |
| 7810 Scanner scanner(source, key); |
| 7811 scanner.Scan(); |
| 7812 while (scanner.current_token().kind != Token::kEOS) { |
| 7813 ASSERT(tokens.IsValid()); |
| 7814 ASSERT(scanner.current_token().kind == tokens.CurrentTokenKind()); |
| 7815 int current_line = scanner.current_token().position.line; |
| 7816 |
| 7817 // Each entry begins with a line number... |
| 7818 JSONArray lineInfo(&tokenPosTable); |
| 7819 lineInfo.AddValue(current_line + line_offset()); |
| 7820 |
| 7821 // ...and is followed by (token offset, col number) pairs. |
| 7822 // |
| 7823 // TODO(hausner): Could optimize here by not reporting tokens |
| 7824 // that will never be a location used by the debugger, e.g. |
| 7825 // braces, semicolons, most keywords etc. |
| 7826 while (scanner.current_token().kind != Token::kEOS) { |
| 7827 ASSERT(tokens.IsValid()); |
| 7828 ASSERT(scanner.current_token().kind == tokens.CurrentTokenKind()); |
| 7829 |
| 7830 int token_line = scanner.current_token().position.line; |
| 7831 if (token_line != current_line) { |
| 7832 // We have hit a new line. Break to the outer loop. |
| 7833 break; |
| 7834 } |
| 7835 lineInfo.AddValue(tokens.CurrentPosition()); |
| 7836 |
| 7837 intptr_t column = scanner.current_token().position.column; |
| 7838 if (token_line == 1) { |
| 7839 // On the first line of the script we must add the column offset. |
| 7840 column += col_offset(); |
| 7841 } |
| 7842 lineInfo.AddValue(column); |
| 7843 scanner.Scan(); |
| 7844 tokens.Advance(); |
| 7845 } |
| 7846 } |
| 7847 } |
7803 } | 7848 } |
7804 | 7849 |
7805 | 7850 |
7806 DictionaryIterator::DictionaryIterator(const Library& library) | 7851 DictionaryIterator::DictionaryIterator(const Library& library) |
7807 : array_(Array::Handle(library.dictionary())), | 7852 : array_(Array::Handle(library.dictionary())), |
7808 // Last element in array is a Smi indicating the number of entries used. | 7853 // Last element in array is a Smi indicating the number of entries used. |
7809 size_(Array::Handle(library.dictionary()).Length() - 1), | 7854 size_(Array::Handle(library.dictionary()).Length() - 1), |
7810 next_ix_(0) { | 7855 next_ix_(0) { |
7811 MoveToNextObject(); | 7856 MoveToNextObject(); |
7812 } | 7857 } |
(...skipping 10190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
18003 return "_MirrorReference"; | 18048 return "_MirrorReference"; |
18004 } | 18049 } |
18005 | 18050 |
18006 | 18051 |
18007 void MirrorReference::PrintToJSONStream(JSONStream* stream, bool ref) const { | 18052 void MirrorReference::PrintToJSONStream(JSONStream* stream, bool ref) const { |
18008 Instance::PrintToJSONStream(stream, ref); | 18053 Instance::PrintToJSONStream(stream, ref); |
18009 } | 18054 } |
18010 | 18055 |
18011 | 18056 |
18012 } // namespace dart | 18057 } // namespace dart |
OLD | NEW |