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"; | |
8787 default: | 8785 default: |
8788 UNIMPLEMENTED(); | 8786 UNIMPLEMENTED(); |
8789 } | 8787 } |
8790 UNREACHABLE(); | 8788 UNREACHABLE(); |
8791 return NULL; | 8789 return NULL; |
8792 } | 8790 } |
8793 | 8791 |
8794 | 8792 |
8795 void Script::set_url(const String& value) const { | 8793 void Script::set_url(const String& value) const { |
8796 StorePointer(&raw_ptr()->url_, value.raw()); | 8794 StorePointer(&raw_ptr()->url_, value.raw()); |
8797 } | 8795 } |
8798 | 8796 |
8799 | 8797 |
8800 void Script::set_resolved_url(const String& value) const { | 8798 void Script::set_resolved_url(const String& value) const { |
8801 StorePointer(&raw_ptr()->resolved_url_, value.raw()); | 8799 StorePointer(&raw_ptr()->resolved_url_, value.raw()); |
8802 } | 8800 } |
8803 | 8801 |
8804 | 8802 |
8805 void Script::set_source(const String& value) const { | 8803 void Script::set_source(const String& value) const { |
8806 StorePointer(&raw_ptr()->source_, value.raw()); | 8804 StorePointer(&raw_ptr()->source_, value.raw()); |
8807 } | 8805 } |
8808 | 8806 |
8809 void Script::set_line_starts(const Array& value) const { | |
8810 StorePointer(&raw_ptr()->line_starts_, value.raw()); | |
8811 } | |
8812 | |
8813 | 8807 |
8814 void Script::set_kind(RawScript::Kind value) const { | 8808 void Script::set_kind(RawScript::Kind value) const { |
8815 StoreNonPointer(&raw_ptr()->kind_, value); | 8809 StoreNonPointer(&raw_ptr()->kind_, value); |
8816 } | 8810 } |
8817 | 8811 |
8818 | 8812 |
8819 void Script::set_load_timestamp(int64_t value) const { | 8813 void Script::set_load_timestamp(int64_t value) const { |
8820 StoreNonPointer(&raw_ptr()->load_timestamp_, value); | 8814 StoreNonPointer(&raw_ptr()->load_timestamp_, value); |
8821 } | 8815 } |
8822 | 8816 |
(...skipping 30 matching lines...) Expand all Loading... |
8853 StoreNonPointer(&raw_ptr()->col_offset_, col_offset); | 8847 StoreNonPointer(&raw_ptr()->col_offset_, col_offset); |
8854 } | 8848 } |
8855 | 8849 |
8856 | 8850 |
8857 void Script::GetTokenLocation(TokenPosition token_pos, | 8851 void Script::GetTokenLocation(TokenPosition token_pos, |
8858 intptr_t* line, | 8852 intptr_t* line, |
8859 intptr_t* column, | 8853 intptr_t* column, |
8860 intptr_t* token_len) const { | 8854 intptr_t* token_len) const { |
8861 ASSERT(line != NULL); | 8855 ASSERT(line != NULL); |
8862 Zone* zone = Thread::Current()->zone(); | 8856 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 if (column != NULL) { | |
8896 smi ^= line_starts_array.At(min); | |
8897 *column = offset - smi.Value() + 1; | |
8898 } | |
8899 if (token_len != NULL) { | |
8900 *token_len = 1; | |
8901 } | |
8902 return; | |
8903 } | |
8904 | |
8905 const TokenStream& tkns = TokenStream::Handle(zone, tokens()); | 8857 const TokenStream& tkns = TokenStream::Handle(zone, tokens()); |
8906 if (tkns.IsNull()) { | 8858 if (tkns.IsNull()) { |
8907 ASSERT((Dart::snapshot_kind() == Snapshot::kAppNoJIT)); | 8859 ASSERT((Dart::snapshot_kind() == Snapshot::kAppNoJIT) || |
| 8860 (url() == Symbols::KernelScriptUri().raw())); |
8908 *line = -1; | 8861 *line = -1; |
8909 if (column != NULL) { | 8862 if (column != NULL) { |
8910 *column = -1; | 8863 *column = -1; |
8911 } | 8864 } |
8912 if (token_len != NULL) { | 8865 if (token_len != NULL) { |
8913 *token_len = 1; | 8866 *token_len = 1; |
8914 } | 8867 } |
8915 return; | 8868 return; |
8916 } | 8869 } |
8917 if (!HasSource()) { | 8870 if (column == NULL) { |
8918 TokenStream::Iterator tkit(zone, tkns, TokenPosition::kMinSource, | 8871 TokenStream::Iterator tkit(zone, tkns, TokenPosition::kMinSource, |
8919 TokenStream::Iterator::kAllTokens); | 8872 TokenStream::Iterator::kAllTokens); |
8920 intptr_t cur_line = line_offset() + 1; | 8873 intptr_t cur_line = line_offset() + 1; |
8921 while ((tkit.CurrentPosition() < token_pos) && | 8874 while ((tkit.CurrentPosition() < token_pos) && |
8922 (tkit.CurrentTokenKind() != Token::kEOS)) { | 8875 (tkit.CurrentTokenKind() != Token::kEOS)) { |
8923 if (tkit.CurrentTokenKind() == Token::kNEWLINE) { | 8876 if (tkit.CurrentTokenKind() == Token::kNEWLINE) { |
8924 cur_line++; | 8877 cur_line++; |
8925 } | 8878 } |
8926 tkit.Advance(); | 8879 tkit.Advance(); |
8927 } | 8880 } |
8928 *line = cur_line; | 8881 *line = cur_line; |
8929 } else { | 8882 } else { |
8930 const String& src = String::Handle(zone, Source()); | 8883 const String& src = String::Handle(zone, Source()); |
8931 intptr_t src_pos = tkns.ComputeSourcePosition(token_pos); | 8884 intptr_t src_pos = tkns.ComputeSourcePosition(token_pos); |
8932 Scanner scanner(src, Symbols::Empty()); | 8885 Scanner scanner(src, Symbols::Empty()); |
8933 scanner.ScanTo(src_pos); | 8886 scanner.ScanTo(src_pos); |
8934 intptr_t relative_line = scanner.CurrentPosition().line; | 8887 intptr_t relative_line = scanner.CurrentPosition().line; |
8935 *line = relative_line + line_offset(); | 8888 *line = relative_line + line_offset(); |
8936 if (column != NULL) { | 8889 *column = scanner.CurrentPosition().column; |
8937 *column = scanner.CurrentPosition().column; | |
8938 } | |
8939 if (token_len != NULL) { | 8890 if (token_len != NULL) { |
8940 if (scanner.current_token().literal != NULL) { | 8891 if (scanner.current_token().literal != NULL) { |
8941 *token_len = scanner.current_token().literal->Length(); | 8892 *token_len = scanner.current_token().literal->Length(); |
8942 } else { | 8893 } else { |
8943 *token_len = 1; | 8894 *token_len = 1; |
8944 } | 8895 } |
8945 } | 8896 } |
8946 // On the first line of the script we must add the column offset. | 8897 // On the first line of the script we must add the column offset. |
8947 if (column != NULL && relative_line == 1) { | 8898 if (relative_line == 1) { |
8948 *column += col_offset(); | 8899 *column += col_offset(); |
8949 } | 8900 } |
8950 } | 8901 } |
8951 } | 8902 } |
8952 | 8903 |
8953 | 8904 |
8954 void Script::TokenRangeAtLine(intptr_t line_number, | 8905 void Script::TokenRangeAtLine(intptr_t line_number, |
8955 TokenPosition* first_token_index, | 8906 TokenPosition* first_token_index, |
8956 TokenPosition* last_token_index) const { | 8907 TokenPosition* last_token_index) const { |
8957 ASSERT(first_token_index != NULL && last_token_index != NULL); | 8908 ASSERT(first_token_index != NULL && last_token_index != NULL); |
(...skipping 13396 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
22354 intptr_t frame_index) { | 22305 intptr_t frame_index) { |
22355 const TokenPosition token_pos = code.GetTokenIndexOfPC(pc); | 22306 const TokenPosition token_pos = code.GetTokenIndexOfPC(pc); |
22356 const Script& script = Script::Handle(zone, function.script()); | 22307 const Script& script = Script::Handle(zone, function.script()); |
22357 const String& function_name = | 22308 const String& function_name = |
22358 String::Handle(zone, function.QualifiedUserVisibleName()); | 22309 String::Handle(zone, function.QualifiedUserVisibleName()); |
22359 const String& url = String::Handle( | 22310 const String& url = String::Handle( |
22360 zone, script.IsNull() ? String::New("Kernel") : script.url()); | 22311 zone, script.IsNull() ? String::New("Kernel") : script.url()); |
22361 intptr_t line = -1; | 22312 intptr_t line = -1; |
22362 intptr_t column = -1; | 22313 intptr_t column = -1; |
22363 if (!script.IsNull() && token_pos.IsReal()) { | 22314 if (!script.IsNull() && token_pos.IsReal()) { |
22364 script.GetTokenLocation(token_pos, &line, &column); | 22315 if (script.HasSource()) { |
| 22316 script.GetTokenLocation(token_pos, &line, &column); |
| 22317 } else { |
| 22318 script.GetTokenLocation(token_pos, &line, NULL); |
| 22319 } |
22365 } | 22320 } |
22366 char* chars = NULL; | 22321 char* chars = NULL; |
22367 if (column >= 0) { | 22322 if (column >= 0) { |
22368 chars = | 22323 chars = |
22369 OS::SCreate(zone, "#%-6" Pd " %s (%s:%" Pd ":%" Pd ")\n", frame_index, | 22324 OS::SCreate(zone, "#%-6" Pd " %s (%s:%" Pd ":%" Pd ")\n", frame_index, |
22370 function_name.ToCString(), url.ToCString(), line, column); | 22325 function_name.ToCString(), url.ToCString(), line, column); |
22371 } else if (line >= 0) { | 22326 } else if (line >= 0) { |
22372 chars = OS::SCreate(zone, "#%-6" Pd " %s (%s:%" Pd ")\n", frame_index, | 22327 chars = OS::SCreate(zone, "#%-6" Pd " %s (%s:%" Pd ")\n", frame_index, |
22373 function_name.ToCString(), url.ToCString(), line); | 22328 function_name.ToCString(), url.ToCString(), line); |
22374 } else { | 22329 } else { |
(...skipping 389 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
22764 return UserTag::null(); | 22719 return UserTag::null(); |
22765 } | 22720 } |
22766 | 22721 |
22767 | 22722 |
22768 const char* UserTag::ToCString() const { | 22723 const char* UserTag::ToCString() const { |
22769 const String& tag_label = String::Handle(label()); | 22724 const String& tag_label = String::Handle(label()); |
22770 return tag_label.ToCString(); | 22725 return tag_label.ToCString(); |
22771 } | 22726 } |
22772 | 22727 |
22773 } // namespace dart | 22728 } // namespace dart |
OLD | NEW |