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/dart_api_impl.h" | 7 #include "vm/dart_api_impl.h" |
8 #include "vm/dart_api_state.h" | 8 #include "vm/dart_api_state.h" |
9 #include "vm/debugger.h" | 9 #include "vm/debugger.h" |
10 #include "vm/isolate.h" | 10 #include "vm/isolate.h" |
(...skipping 569 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
580 const Script& script = Script::Handle(lib.LookupScript(script_url)); | 580 const Script& script = Script::Handle(lib.LookupScript(script_url)); |
581 if (script.IsNull()) { | 581 if (script.IsNull()) { |
582 return Api::NewError("%s: script '%s' not found in library '%s'", | 582 return Api::NewError("%s: script '%s' not found in library '%s'", |
583 CURRENT_FUNC, script_url.ToCString(), | 583 CURRENT_FUNC, script_url.ToCString(), |
584 String::Handle(lib.url()).ToCString()); | 584 String::Handle(lib.url()).ToCString()); |
585 } | 585 } |
586 return Api::NewHandle(isolate, script.Source()); | 586 return Api::NewHandle(isolate, script.Source()); |
587 } | 587 } |
588 | 588 |
589 | 589 |
| 590 DART_EXPORT Dart_Handle Dart_ScriptGetTokenInfo( |
| 591 intptr_t library_id, |
| 592 Dart_Handle script_url_in) { |
| 593 Isolate* isolate = Isolate::Current(); |
| 594 DARTSCOPE(isolate); |
| 595 const Library& lib = Library::Handle(Library::GetLibrary(library_id)); |
| 596 if (lib.IsNull()) { |
| 597 return Api::NewError("%s: %"Pd" is not a valid library id", |
| 598 CURRENT_FUNC, library_id); |
| 599 } |
| 600 UNWRAP_AND_CHECK_PARAM(String, script_url, script_url_in); |
| 601 const Script& script = Script::Handle(lib.LookupScript(script_url)); |
| 602 if (script.IsNull()) { |
| 603 return Api::NewError("%s: script '%s' not found in library '%s'", |
| 604 CURRENT_FUNC, script_url.ToCString(), |
| 605 String::Handle(lib.url()).ToCString()); |
| 606 } |
| 607 |
| 608 const GrowableObjectArray& info = |
| 609 GrowableObjectArray::Handle(GrowableObjectArray::New()); |
| 610 const String& source = String::Handle(script.Source()); |
| 611 const String& key = Symbols::Empty(); |
| 612 const Object& line_separator = Object::Handle(); |
| 613 const TokenStream& tkns = TokenStream::Handle(script.tokens()); |
| 614 ASSERT(!tkns.IsNull()); |
| 615 TokenStream::Iterator tkit(tkns, 0); |
| 616 int current_line = -1; |
| 617 Scanner s(source, key); |
| 618 s.Scan(); |
| 619 while (s.current_token().kind != Token::kEOS) { |
| 620 ASSERT(tkit.IsValid()); |
| 621 ASSERT(s.current_token().kind == tkit.CurrentTokenKind()); |
| 622 int token_line = s.current_token().position.line; |
| 623 if (token_line != current_line) { |
| 624 // emit line |
| 625 info.Add(line_separator); |
| 626 info.Add(Smi::Handle(Smi::New(token_line))); |
| 627 current_line = token_line; |
| 628 } |
| 629 // TODO(hausner): Could optimize here by not reporting tokens |
| 630 // that will never be a location used by the debugger, e.g. |
| 631 // braces, semicolons, most keywords etc. |
| 632 info.Add(Smi::Handle(Smi::New(tkit.CurrentPosition()))); |
| 633 info.Add(Smi::Handle(Smi::New(s.current_token().offset))); |
| 634 s.Scan(); |
| 635 tkit.Advance(); |
| 636 } |
| 637 return Api::NewHandle(isolate, Array::MakeArray(info)); |
| 638 } |
| 639 |
| 640 |
590 DART_EXPORT Dart_Handle Dart_GenerateScriptSource(Dart_Handle library_url_in, | 641 DART_EXPORT Dart_Handle Dart_GenerateScriptSource(Dart_Handle library_url_in, |
591 Dart_Handle script_url_in) { | 642 Dart_Handle script_url_in) { |
592 Isolate* isolate = Isolate::Current(); | 643 Isolate* isolate = Isolate::Current(); |
593 DARTSCOPE(isolate); | 644 DARTSCOPE(isolate); |
594 UNWRAP_AND_CHECK_PARAM(String, library_url, library_url_in); | 645 UNWRAP_AND_CHECK_PARAM(String, library_url, library_url_in); |
595 UNWRAP_AND_CHECK_PARAM(String, script_url, script_url_in); | 646 UNWRAP_AND_CHECK_PARAM(String, script_url, script_url_in); |
596 | 647 |
597 const Library& library = Library::Handle(Library::LookupLibrary(library_url)); | 648 const Library& library = Library::Handle(Library::LookupLibrary(library_url)); |
598 if (library.IsNull()) { | 649 if (library.IsNull()) { |
599 return Api::NewError("%s: library '%s' not found", | 650 return Api::NewError("%s: library '%s' not found", |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
771 | 822 |
772 | 823 |
773 DART_EXPORT char* Dart_GetVmStatus(const char* request) { | 824 DART_EXPORT char* Dart_GetVmStatus(const char* request) { |
774 if (strncmp(request, "/isolate/", 9) == 0) { | 825 if (strncmp(request, "/isolate/", 9) == 0) { |
775 return Isolate::GetStatus(request); | 826 return Isolate::GetStatus(request); |
776 } | 827 } |
777 return NULL; | 828 return NULL; |
778 } | 829 } |
779 | 830 |
780 } // namespace dart | 831 } // namespace dart |
OLD | NEW |