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 8749 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
8760 case RawScript::kScriptTag: | 8760 case RawScript::kScriptTag: |
8761 return "script"; | 8761 return "script"; |
8762 case RawScript::kLibraryTag: | 8762 case RawScript::kLibraryTag: |
8763 return "library"; | 8763 return "library"; |
8764 case RawScript::kSourceTag: | 8764 case RawScript::kSourceTag: |
8765 return "source"; | 8765 return "source"; |
8766 case RawScript::kPatchTag: | 8766 case RawScript::kPatchTag: |
8767 return "patch"; | 8767 return "patch"; |
8768 case RawScript::kEvaluateTag: | 8768 case RawScript::kEvaluateTag: |
8769 return "evaluate"; | 8769 return "evaluate"; |
8770 case RawScript::kKernelTag: | |
8771 return "kernel"; | |
8770 default: | 8772 default: |
8771 UNIMPLEMENTED(); | 8773 UNIMPLEMENTED(); |
8772 } | 8774 } |
8773 UNREACHABLE(); | 8775 UNREACHABLE(); |
8774 return NULL; | 8776 return NULL; |
8775 } | 8777 } |
8776 | 8778 |
8777 | 8779 |
8778 void Script::set_url(const String& value) const { | 8780 void Script::set_url(const String& value) const { |
8779 StorePointer(&raw_ptr()->url_, value.raw()); | 8781 StorePointer(&raw_ptr()->url_, value.raw()); |
8780 } | 8782 } |
8781 | 8783 |
8782 | 8784 |
8783 void Script::set_resolved_url(const String& value) const { | 8785 void Script::set_resolved_url(const String& value) const { |
8784 StorePointer(&raw_ptr()->resolved_url_, value.raw()); | 8786 StorePointer(&raw_ptr()->resolved_url_, value.raw()); |
8785 } | 8787 } |
8786 | 8788 |
8787 | 8789 |
8788 void Script::set_source(const String& value) const { | 8790 void Script::set_source(const String& value) const { |
8789 StorePointer(&raw_ptr()->source_, value.raw()); | 8791 StorePointer(&raw_ptr()->source_, value.raw()); |
8790 } | 8792 } |
8791 | 8793 |
8794 void Script::set_line_starts(const Array& value) const { | |
8795 StorePointer(&raw_ptr()->line_starts_, value.raw()); | |
8796 } | |
8797 | |
8792 | 8798 |
8793 void Script::set_kind(RawScript::Kind value) const { | 8799 void Script::set_kind(RawScript::Kind value) const { |
8794 StoreNonPointer(&raw_ptr()->kind_, value); | 8800 StoreNonPointer(&raw_ptr()->kind_, value); |
8795 } | 8801 } |
8796 | 8802 |
8797 | 8803 |
8798 void Script::set_load_timestamp(int64_t value) const { | 8804 void Script::set_load_timestamp(int64_t value) const { |
8799 StoreNonPointer(&raw_ptr()->load_timestamp_, value); | 8805 StoreNonPointer(&raw_ptr()->load_timestamp_, value); |
8800 } | 8806 } |
8801 | 8807 |
(...skipping 30 matching lines...) Expand all Loading... | |
8832 StoreNonPointer(&raw_ptr()->col_offset_, col_offset); | 8838 StoreNonPointer(&raw_ptr()->col_offset_, col_offset); |
8833 } | 8839 } |
8834 | 8840 |
8835 | 8841 |
8836 void Script::GetTokenLocation(TokenPosition token_pos, | 8842 void Script::GetTokenLocation(TokenPosition token_pos, |
8837 intptr_t* line, | 8843 intptr_t* line, |
8838 intptr_t* column, | 8844 intptr_t* column, |
8839 intptr_t* token_len) const { | 8845 intptr_t* token_len) const { |
8840 ASSERT(line != NULL); | 8846 ASSERT(line != NULL); |
8841 Zone* zone = Thread::Current()->zone(); | 8847 Zone* zone = Thread::Current()->zone(); |
8848 | |
8849 if (this->kind() == RawScript::kKernelTag) { | |
Kevin Millikin (Google)
2016/11/21 08:06:18
Don't need this->
jensj
2016/11/21 09:18:43
Done.
| |
8850 const Array& line_starts_array = Array::Handle(line_starts()); | |
8851 if (line_starts_array.IsNull()) { | |
8852 // Scripts in the AOT snapshot do not have a line starts array. | |
8853 *line = -1; | |
8854 if (column != NULL) { | |
8855 *column = -1; | |
8856 } | |
8857 if (token_len != NULL) { | |
8858 *token_len = 1; | |
8859 } | |
8860 return; | |
8861 } | |
8862 ASSERT(line_starts_array.Length() > 0); | |
8863 intptr_t offset = token_pos.value(); | |
8864 int min = 0; | |
8865 int max = line_starts_array.Length() - 1; | |
8866 | |
8867 // Binary search to find the line containing this offset. | |
8868 Smi& smi = Smi::Handle(); | |
8869 while (min < max) { | |
8870 int midpoint = (max - min + 1) / 2 + min; | |
8871 | |
8872 smi ^= line_starts_array.At(midpoint); | |
8873 if (smi.Value() > offset) { | |
8874 max = midpoint - 1; | |
8875 } else { | |
8876 min = midpoint; | |
8877 } | |
8878 } | |
8879 *line = min + 1; | |
8880 if (column != NULL) { | |
8881 smi ^= line_starts_array.At(min); | |
8882 *column = offset - smi.Value() + 1; | |
8883 } | |
8884 if (token_len != NULL) { | |
8885 *token_len = 1; | |
8886 } | |
8887 return; | |
8888 } | |
8889 | |
8842 const TokenStream& tkns = TokenStream::Handle(zone, tokens()); | 8890 const TokenStream& tkns = TokenStream::Handle(zone, tokens()); |
8843 if (tkns.IsNull()) { | 8891 if (tkns.IsNull()) { |
8844 ASSERT(Dart::snapshot_kind() == Snapshot::kAppNoJIT); | 8892 ASSERT(Dart::snapshot_kind() == Snapshot::kAppNoJIT); |
8845 *line = -1; | 8893 *line = -1; |
8846 if (column != NULL) { | 8894 if (column != NULL) { |
8847 *column = -1; | 8895 *column = -1; |
8848 } | 8896 } |
8849 if (token_len != NULL) { | 8897 if (token_len != NULL) { |
8850 *token_len = 1; | 8898 *token_len = 1; |
8851 } | 8899 } |
8852 return; | 8900 return; |
8853 } | 8901 } |
8854 if (column == NULL) { | 8902 if (!HasSource()) { |
8855 TokenStream::Iterator tkit(zone, tkns, TokenPosition::kMinSource, | 8903 TokenStream::Iterator tkit(zone, tkns, TokenPosition::kMinSource, |
8856 TokenStream::Iterator::kAllTokens); | 8904 TokenStream::Iterator::kAllTokens); |
8857 intptr_t cur_line = line_offset() + 1; | 8905 intptr_t cur_line = line_offset() + 1; |
8858 while ((tkit.CurrentPosition() < token_pos) && | 8906 while ((tkit.CurrentPosition() < token_pos) && |
8859 (tkit.CurrentTokenKind() != Token::kEOS)) { | 8907 (tkit.CurrentTokenKind() != Token::kEOS)) { |
8860 if (tkit.CurrentTokenKind() == Token::kNEWLINE) { | 8908 if (tkit.CurrentTokenKind() == Token::kNEWLINE) { |
8861 cur_line++; | 8909 cur_line++; |
8862 } | 8910 } |
8863 tkit.Advance(); | 8911 tkit.Advance(); |
8864 } | 8912 } |
8865 *line = cur_line; | 8913 *line = cur_line; |
8866 } else { | 8914 } else { |
8867 const String& src = String::Handle(zone, Source()); | 8915 const String& src = String::Handle(zone, Source()); |
8868 intptr_t src_pos = tkns.ComputeSourcePosition(token_pos); | 8916 intptr_t src_pos = tkns.ComputeSourcePosition(token_pos); |
8869 Scanner scanner(src, Symbols::Empty()); | 8917 Scanner scanner(src, Symbols::Empty()); |
8870 scanner.ScanTo(src_pos); | 8918 scanner.ScanTo(src_pos); |
8871 intptr_t relative_line = scanner.CurrentPosition().line; | 8919 intptr_t relative_line = scanner.CurrentPosition().line; |
8872 *line = relative_line + line_offset(); | 8920 *line = relative_line + line_offset(); |
8873 *column = scanner.CurrentPosition().column; | 8921 if (column != NULL) { |
8922 *column = scanner.CurrentPosition().column; | |
8923 } | |
8874 if (token_len != NULL) { | 8924 if (token_len != NULL) { |
8875 if (scanner.current_token().literal != NULL) { | 8925 if (scanner.current_token().literal != NULL) { |
8876 *token_len = scanner.current_token().literal->Length(); | 8926 *token_len = scanner.current_token().literal->Length(); |
8877 } else { | 8927 } else { |
8878 *token_len = 1; | 8928 *token_len = 1; |
8879 } | 8929 } |
8880 } | 8930 } |
8881 // On the first line of the script we must add the column offset. | 8931 // On the first line of the script we must add the column offset. |
8882 if (relative_line == 1) { | 8932 if (column != NULL && relative_line == 1) { |
8883 *column += col_offset(); | 8933 *column += col_offset(); |
8884 } | 8934 } |
8885 } | 8935 } |
8886 } | 8936 } |
8887 | 8937 |
8888 | 8938 |
8889 void Script::TokenRangeAtLine(intptr_t line_number, | 8939 void Script::TokenRangeAtLine(intptr_t line_number, |
8890 TokenPosition* first_token_index, | 8940 TokenPosition* first_token_index, |
8891 TokenPosition* last_token_index) const { | 8941 TokenPosition* last_token_index) const { |
8892 ASSERT(first_token_index != NULL && last_token_index != NULL); | 8942 ASSERT(first_token_index != NULL && last_token_index != NULL); |
(...skipping 13396 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
22289 intptr_t frame_index) { | 22339 intptr_t frame_index) { |
22290 const TokenPosition token_pos = code.GetTokenIndexOfPC(pc); | 22340 const TokenPosition token_pos = code.GetTokenIndexOfPC(pc); |
22291 const Script& script = Script::Handle(zone, function.script()); | 22341 const Script& script = Script::Handle(zone, function.script()); |
22292 const String& function_name = | 22342 const String& function_name = |
22293 String::Handle(zone, function.QualifiedUserVisibleName()); | 22343 String::Handle(zone, function.QualifiedUserVisibleName()); |
22294 const String& url = String::Handle( | 22344 const String& url = String::Handle( |
22295 zone, script.IsNull() ? String::New("Kernel") : script.url()); | 22345 zone, script.IsNull() ? String::New("Kernel") : script.url()); |
22296 intptr_t line = -1; | 22346 intptr_t line = -1; |
22297 intptr_t column = -1; | 22347 intptr_t column = -1; |
22298 if (!script.IsNull() && token_pos.IsReal()) { | 22348 if (!script.IsNull() && token_pos.IsReal()) { |
22299 if (script.HasSource()) { | 22349 script.GetTokenLocation(token_pos, &line, &column); |
22300 script.GetTokenLocation(token_pos, &line, &column); | |
22301 } else { | |
22302 script.GetTokenLocation(token_pos, &line, NULL); | |
22303 } | |
22304 } | 22350 } |
22305 char* chars = NULL; | 22351 char* chars = NULL; |
22306 if (column >= 0) { | 22352 if (column >= 0) { |
22307 chars = | 22353 chars = |
22308 OS::SCreate(zone, "#%-6" Pd " %s (%s:%" Pd ":%" Pd ")\n", frame_index, | 22354 OS::SCreate(zone, "#%-6" Pd " %s (%s:%" Pd ":%" Pd ")\n", frame_index, |
22309 function_name.ToCString(), url.ToCString(), line, column); | 22355 function_name.ToCString(), url.ToCString(), line, column); |
22310 } else if (line >= 0) { | 22356 } else if (line >= 0) { |
22311 chars = OS::SCreate(zone, "#%-6" Pd " %s (%s:%" Pd ")\n", frame_index, | 22357 chars = OS::SCreate(zone, "#%-6" Pd " %s (%s:%" Pd ")\n", frame_index, |
22312 function_name.ToCString(), url.ToCString(), line); | 22358 function_name.ToCString(), url.ToCString(), line); |
22313 } else { | 22359 } else { |
(...skipping 377 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
22691 return UserTag::null(); | 22737 return UserTag::null(); |
22692 } | 22738 } |
22693 | 22739 |
22694 | 22740 |
22695 const char* UserTag::ToCString() const { | 22741 const char* UserTag::ToCString() const { |
22696 const String& tag_label = String::Handle(label()); | 22742 const String& tag_label = String::Handle(label()); |
22697 return tag_label.ToCString(); | 22743 return tag_label.ToCString(); |
22698 } | 22744 } |
22699 | 22745 |
22700 } // namespace dart | 22746 } // namespace dart |
OLD | NEW |