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/become.h" | 10 #include "vm/become.h" |
(...skipping 8764 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8775 case RawScript::kScriptTag: | 8775 case RawScript::kScriptTag: |
8776 return "script"; | 8776 return "script"; |
8777 case RawScript::kLibraryTag: | 8777 case RawScript::kLibraryTag: |
8778 return "library"; | 8778 return "library"; |
8779 case RawScript::kSourceTag: | 8779 case RawScript::kSourceTag: |
8780 return "source"; | 8780 return "source"; |
8781 case RawScript::kPatchTag: | 8781 case RawScript::kPatchTag: |
8782 return "patch"; | 8782 return "patch"; |
8783 case RawScript::kEvaluateTag: | 8783 case RawScript::kEvaluateTag: |
8784 return "evaluate"; | 8784 return "evaluate"; |
| 8785 case RawScript::kKernelTag: |
| 8786 return "kernel"; |
8785 default: | 8787 default: |
8786 UNIMPLEMENTED(); | 8788 UNIMPLEMENTED(); |
8787 } | 8789 } |
8788 UNREACHABLE(); | 8790 UNREACHABLE(); |
8789 return NULL; | 8791 return NULL; |
8790 } | 8792 } |
8791 | 8793 |
8792 | 8794 |
8793 void Script::set_url(const String& value) const { | 8795 void Script::set_url(const String& value) const { |
8794 StorePointer(&raw_ptr()->url_, value.raw()); | 8796 StorePointer(&raw_ptr()->url_, value.raw()); |
8795 } | 8797 } |
8796 | 8798 |
8797 | 8799 |
8798 void Script::set_resolved_url(const String& value) const { | 8800 void Script::set_resolved_url(const String& value) const { |
8799 StorePointer(&raw_ptr()->resolved_url_, value.raw()); | 8801 StorePointer(&raw_ptr()->resolved_url_, value.raw()); |
8800 } | 8802 } |
8801 | 8803 |
8802 | 8804 |
8803 void Script::set_source(const String& value) const { | 8805 void Script::set_source(const String& value) const { |
8804 StorePointer(&raw_ptr()->source_, value.raw()); | 8806 StorePointer(&raw_ptr()->source_, value.raw()); |
8805 } | 8807 } |
8806 | 8808 |
| 8809 void Script::set_line_starts(const Array& value) const { |
| 8810 StorePointer(&raw_ptr()->line_starts_, value.raw()); |
| 8811 } |
| 8812 |
8807 | 8813 |
8808 void Script::set_kind(RawScript::Kind value) const { | 8814 void Script::set_kind(RawScript::Kind value) const { |
8809 StoreNonPointer(&raw_ptr()->kind_, value); | 8815 StoreNonPointer(&raw_ptr()->kind_, value); |
8810 } | 8816 } |
8811 | 8817 |
8812 | 8818 |
8813 void Script::set_load_timestamp(int64_t value) const { | 8819 void Script::set_load_timestamp(int64_t value) const { |
8814 StoreNonPointer(&raw_ptr()->load_timestamp_, value); | 8820 StoreNonPointer(&raw_ptr()->load_timestamp_, value); |
8815 } | 8821 } |
8816 | 8822 |
(...skipping 30 matching lines...) Expand all Loading... |
8847 StoreNonPointer(&raw_ptr()->col_offset_, col_offset); | 8853 StoreNonPointer(&raw_ptr()->col_offset_, col_offset); |
8848 } | 8854 } |
8849 | 8855 |
8850 | 8856 |
8851 void Script::GetTokenLocation(TokenPosition token_pos, | 8857 void Script::GetTokenLocation(TokenPosition token_pos, |
8852 intptr_t* line, | 8858 intptr_t* line, |
8853 intptr_t* column, | 8859 intptr_t* column, |
8854 intptr_t* token_len) const { | 8860 intptr_t* token_len) const { |
8855 ASSERT(line != NULL); | 8861 ASSERT(line != NULL); |
8856 Zone* zone = Thread::Current()->zone(); | 8862 Zone* zone = Thread::Current()->zone(); |
| 8863 |
| 8864 if (kind() == RawScript::kKernelTag) { |
| 8865 const Array& line_starts_array = Array::Handle(line_starts()); |
| 8866 if (line_starts_array.IsNull()) { |
| 8867 // Scripts in the AOT snapshot do not have a line starts array. |
| 8868 *line = -1; |
| 8869 if (column != NULL) { |
| 8870 *column = -1; |
| 8871 } |
| 8872 if (token_len != NULL) { |
| 8873 *token_len = 1; |
| 8874 } |
| 8875 return; |
| 8876 } |
| 8877 ASSERT(line_starts_array.Length() > 0); |
| 8878 intptr_t offset = token_pos.value(); |
| 8879 int min = 0; |
| 8880 int max = line_starts_array.Length() - 1; |
| 8881 |
| 8882 // Binary search to find the line containing this offset. |
| 8883 Smi& smi = Smi::Handle(); |
| 8884 while (min < max) { |
| 8885 int midpoint = (max - min + 1) / 2 + min; |
| 8886 |
| 8887 smi ^= line_starts_array.At(midpoint); |
| 8888 if (smi.Value() > offset) { |
| 8889 max = midpoint - 1; |
| 8890 } else { |
| 8891 min = midpoint; |
| 8892 } |
| 8893 } |
| 8894 *line = min + 1; |
| 8895 smi ^= line_starts_array.At(min); |
| 8896 *column = offset - smi.Value() + 1; |
| 8897 if (token_len != NULL) { |
| 8898 *token_len = 1; |
| 8899 } |
| 8900 return; |
| 8901 } |
| 8902 |
8857 const TokenStream& tkns = TokenStream::Handle(zone, tokens()); | 8903 const TokenStream& tkns = TokenStream::Handle(zone, tokens()); |
8858 if (tkns.IsNull()) { | 8904 if (tkns.IsNull()) { |
8859 ASSERT((Dart::snapshot_kind() == Snapshot::kAppNoJIT) || | 8905 ASSERT((Dart::snapshot_kind() == Snapshot::kAppNoJIT)); |
8860 (url() == Symbols::KernelScriptUri().raw())); | |
8861 *line = -1; | 8906 *line = -1; |
8862 if (column != NULL) { | 8907 if (column != NULL) { |
8863 *column = -1; | 8908 *column = -1; |
8864 } | 8909 } |
8865 if (token_len != NULL) { | 8910 if (token_len != NULL) { |
8866 *token_len = 1; | 8911 *token_len = 1; |
8867 } | 8912 } |
8868 return; | 8913 return; |
8869 } | 8914 } |
8870 if (column == NULL) { | 8915 if (column == NULL) { |
(...skipping 13434 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
22305 intptr_t frame_index) { | 22350 intptr_t frame_index) { |
22306 const TokenPosition token_pos = code.GetTokenIndexOfPC(pc); | 22351 const TokenPosition token_pos = code.GetTokenIndexOfPC(pc); |
22307 const Script& script = Script::Handle(zone, function.script()); | 22352 const Script& script = Script::Handle(zone, function.script()); |
22308 const String& function_name = | 22353 const String& function_name = |
22309 String::Handle(zone, function.QualifiedUserVisibleName()); | 22354 String::Handle(zone, function.QualifiedUserVisibleName()); |
22310 const String& url = String::Handle( | 22355 const String& url = String::Handle( |
22311 zone, script.IsNull() ? String::New("Kernel") : script.url()); | 22356 zone, script.IsNull() ? String::New("Kernel") : script.url()); |
22312 intptr_t line = -1; | 22357 intptr_t line = -1; |
22313 intptr_t column = -1; | 22358 intptr_t column = -1; |
22314 if (!script.IsNull() && token_pos.IsReal()) { | 22359 if (!script.IsNull() && token_pos.IsReal()) { |
22315 if (script.HasSource()) { | 22360 if (script.HasSource() || script.kind() == RawScript::kKernelTag) { |
22316 script.GetTokenLocation(token_pos, &line, &column); | 22361 script.GetTokenLocation(token_pos, &line, &column); |
22317 } else { | 22362 } else { |
22318 script.GetTokenLocation(token_pos, &line, NULL); | 22363 script.GetTokenLocation(token_pos, &line, NULL); |
22319 } | 22364 } |
22320 } | 22365 } |
22321 char* chars = NULL; | 22366 char* chars = NULL; |
22322 if (column >= 0) { | 22367 if (column >= 0) { |
22323 chars = | 22368 chars = |
22324 OS::SCreate(zone, "#%-6" Pd " %s (%s:%" Pd ":%" Pd ")\n", frame_index, | 22369 OS::SCreate(zone, "#%-6" Pd " %s (%s:%" Pd ":%" Pd ")\n", frame_index, |
22325 function_name.ToCString(), url.ToCString(), line, column); | 22370 function_name.ToCString(), url.ToCString(), line, column); |
(...skipping 393 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
22719 return UserTag::null(); | 22764 return UserTag::null(); |
22720 } | 22765 } |
22721 | 22766 |
22722 | 22767 |
22723 const char* UserTag::ToCString() const { | 22768 const char* UserTag::ToCString() const { |
22724 const String& tag_label = String::Handle(label()); | 22769 const String& tag_label = String::Handle(label()); |
22725 return tag_label.ToCString(); | 22770 return tag_label.ToCString(); |
22726 } | 22771 } |
22727 | 22772 |
22728 } // namespace dart | 22773 } // namespace dart |
OLD | NEW |