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 "include/dart_debugger_api.h" | 5 #include "include/dart_debugger_api.h" |
6 | 6 |
7 #include "vm/class_finalizer.h" | 7 #include "vm/class_finalizer.h" |
8 #include "vm/compiler.h" | 8 #include "vm/compiler.h" |
9 #include "vm/dart_api_impl.h" | 9 #include "vm/dart_api_impl.h" |
10 #include "vm/dart_api_state.h" | 10 #include "vm/dart_api_state.h" |
(...skipping 728 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
739 } | 739 } |
740 UNWRAP_AND_CHECK_PARAM(String, script_url, script_url_in); | 740 UNWRAP_AND_CHECK_PARAM(String, script_url, script_url_in); |
741 const Script& script = Script::Handle(lib.LookupScript(script_url)); | 741 const Script& script = Script::Handle(lib.LookupScript(script_url)); |
742 if (script.IsNull()) { | 742 if (script.IsNull()) { |
743 return Api::NewError("%s: script '%s' not found in library '%s'", | 743 return Api::NewError("%s: script '%s' not found in library '%s'", |
744 CURRENT_FUNC, script_url.ToCString(), | 744 CURRENT_FUNC, script_url.ToCString(), |
745 String::Handle(lib.url()).ToCString()); | 745 String::Handle(lib.url()).ToCString()); |
746 } | 746 } |
747 | 747 |
748 const GrowableObjectArray& info = | 748 const GrowableObjectArray& info = |
749 GrowableObjectArray::Handle(GrowableObjectArray::New()); | 749 GrowableObjectArray::Handle(script.GenerateLineNumberArray()); |
750 const String& source = String::Handle(script.Source()); | |
751 const String& key = Symbols::Empty(); | |
752 const Object& line_separator = Object::Handle(); | |
753 const TokenStream& tkns = TokenStream::Handle(script.tokens()); | |
754 int line_offset = script.line_offset(); | |
755 ASSERT(!tkns.IsNull()); | |
756 TokenStream::Iterator tkit(tkns, 0); | |
757 int current_line = -1; | |
758 Scanner s(source, key); | |
759 s.Scan(); | |
760 while (s.current_token().kind != Token::kEOS) { | |
761 ASSERT(tkit.IsValid()); | |
762 ASSERT(s.current_token().kind == tkit.CurrentTokenKind()); | |
763 int token_line = s.current_token().position.line; | |
764 if (token_line != current_line) { | |
765 // emit line | |
766 info.Add(line_separator); | |
767 info.Add(Smi::Handle(Smi::New(token_line + line_offset))); | |
768 current_line = token_line; | |
769 } | |
770 // TODO(hausner): Could optimize here by not reporting tokens | |
771 // that will never be a location used by the debugger, e.g. | |
772 // braces, semicolons, most keywords etc. | |
773 info.Add(Smi::Handle(Smi::New(tkit.CurrentPosition()))); | |
774 int column = s.current_token().position.column; | |
775 // On the first line of the script we must add the column offset. | |
776 if (token_line == 1) { | |
777 column += script.col_offset(); | |
778 } | |
779 info.Add(Smi::Handle(Smi::New(column))); | |
780 s.Scan(); | |
781 tkit.Advance(); | |
782 } | |
783 return Api::NewHandle(isolate, Array::MakeArray(info)); | 750 return Api::NewHandle(isolate, Array::MakeArray(info)); |
784 } | 751 } |
785 | 752 |
786 | 753 |
787 DART_EXPORT Dart_Handle Dart_GenerateScriptSource(Dart_Handle library_url_in, | 754 DART_EXPORT Dart_Handle Dart_GenerateScriptSource(Dart_Handle library_url_in, |
788 Dart_Handle script_url_in) { | 755 Dart_Handle script_url_in) { |
789 Isolate* isolate = Isolate::Current(); | 756 Isolate* isolate = Isolate::Current(); |
790 DARTSCOPE(isolate); | 757 DARTSCOPE(isolate); |
791 UNWRAP_AND_CHECK_PARAM(String, library_url, library_url_in); | 758 UNWRAP_AND_CHECK_PARAM(String, library_url, library_url_in); |
792 UNWRAP_AND_CHECK_PARAM(String, script_url, script_url_in); | 759 UNWRAP_AND_CHECK_PARAM(String, script_url, script_url_in); |
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
972 return Api::CastIsolate(isolate); | 939 return Api::CastIsolate(isolate); |
973 } | 940 } |
974 | 941 |
975 | 942 |
976 DART_EXPORT Dart_IsolateId Dart_GetIsolateId(Dart_Isolate dart_isolate) { | 943 DART_EXPORT Dart_IsolateId Dart_GetIsolateId(Dart_Isolate dart_isolate) { |
977 Isolate* isolate = reinterpret_cast<Isolate*>(dart_isolate); | 944 Isolate* isolate = reinterpret_cast<Isolate*>(dart_isolate); |
978 return isolate->debugger()->GetIsolateId(); | 945 return isolate->debugger()->GetIsolateId(); |
979 } | 946 } |
980 | 947 |
981 } // namespace dart | 948 } // namespace dart |
OLD | NEW |