Chromium Code Reviews| 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 3443 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3454 | 3454 |
| 3455 | 3455 |
| 3456 TokenPosition Class::ComputeEndTokenPos() const { | 3456 TokenPosition Class::ComputeEndTokenPos() const { |
| 3457 // Return the begin token for synthetic classes. | 3457 // Return the begin token for synthetic classes. |
| 3458 if (is_synthesized_class() || IsMixinApplication() || IsTopLevel()) { | 3458 if (is_synthesized_class() || IsMixinApplication() || IsTopLevel()) { |
| 3459 return token_pos(); | 3459 return token_pos(); |
| 3460 } | 3460 } |
| 3461 Zone* zone = Thread::Current()->zone(); | 3461 Zone* zone = Thread::Current()->zone(); |
| 3462 const Script& scr = Script::Handle(zone, script()); | 3462 const Script& scr = Script::Handle(zone, script()); |
| 3463 ASSERT(!scr.IsNull()); | 3463 ASSERT(!scr.IsNull()); |
| 3464 | |
| 3465 if (scr.kind() == RawScript::kKernelTag) { | |
| 3466 return TokenPosition::kMinSource; | |
|
Cutch
2016/12/21 00:27:12
here again, why aren't you returning the correct e
| |
| 3467 } | |
| 3468 | |
| 3464 const TokenStream& tkns = TokenStream::Handle(zone, scr.tokens()); | 3469 const TokenStream& tkns = TokenStream::Handle(zone, scr.tokens()); |
| 3465 if (tkns.IsNull()) { | 3470 if (tkns.IsNull()) { |
| 3466 ASSERT(Dart::snapshot_kind() == Snapshot::kAppAOT); | 3471 ASSERT(Dart::snapshot_kind() == Snapshot::kAppAOT); |
| 3467 return TokenPosition::kNoSource; | 3472 return TokenPosition::kNoSource; |
| 3468 } | 3473 } |
| 3469 TokenStream::Iterator tkit(zone, tkns, token_pos(), | 3474 TokenStream::Iterator tkit(zone, tkns, token_pos(), |
| 3470 TokenStream::Iterator::kNoNewlines); | 3475 TokenStream::Iterator::kNoNewlines); |
| 3471 intptr_t level = 0; | 3476 intptr_t level = 0; |
| 3472 while (tkit.CurrentTokenKind() != Token::kEOS) { | 3477 while (tkit.CurrentTokenKind() != Token::kEOS) { |
| 3473 if (tkit.CurrentTokenKind() == Token::kLBRACE) { | 3478 if (tkit.CurrentTokenKind() == Token::kLBRACE) { |
| (...skipping 5199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 8673 RawString* Script::Source() const { | 8678 RawString* Script::Source() const { |
| 8674 String& source = String::Handle(raw_ptr()->source_); | 8679 String& source = String::Handle(raw_ptr()->source_); |
| 8675 if (source.IsNull()) { | 8680 if (source.IsNull()) { |
| 8676 return GenerateSource(); | 8681 return GenerateSource(); |
| 8677 } | 8682 } |
| 8678 return raw_ptr()->source_; | 8683 return raw_ptr()->source_; |
| 8679 } | 8684 } |
| 8680 | 8685 |
| 8681 | 8686 |
| 8682 RawString* Script::GenerateSource() const { | 8687 RawString* Script::GenerateSource() const { |
| 8688 if (kind() == RawScript::kKernelTag) { | |
| 8689 // In kernel it's embedded. | |
| 8690 return raw_ptr()->source_; | |
| 8691 } | |
| 8692 | |
| 8683 const TokenStream& token_stream = TokenStream::Handle(tokens()); | 8693 const TokenStream& token_stream = TokenStream::Handle(tokens()); |
| 8684 if (token_stream.IsNull()) { | 8694 if (token_stream.IsNull()) { |
| 8685 ASSERT(Dart::snapshot_kind() == Snapshot::kAppAOT); | 8695 ASSERT(Dart::snapshot_kind() == Snapshot::kAppAOT); |
| 8686 return String::null(); | 8696 return String::null(); |
| 8687 } | 8697 } |
| 8688 return token_stream.GenerateSource(); | 8698 return token_stream.GenerateSource(); |
| 8689 } | 8699 } |
| 8690 | 8700 |
| 8691 | 8701 |
| 8692 void Script::set_compile_time_constants(const Array& value) const { | 8702 void Script::set_compile_time_constants(const Array& value) const { |
| 8693 StorePointer(&raw_ptr()->compile_time_constants_, value.raw()); | 8703 StorePointer(&raw_ptr()->compile_time_constants_, value.raw()); |
| 8694 } | 8704 } |
| 8695 | 8705 |
| 8696 | 8706 |
| 8697 RawGrowableObjectArray* Script::GenerateLineNumberArray() const { | 8707 RawGrowableObjectArray* Script::GenerateLineNumberArray() const { |
| 8698 Zone* zone = Thread::Current()->zone(); | 8708 Zone* zone = Thread::Current()->zone(); |
| 8699 const GrowableObjectArray& info = | 8709 const GrowableObjectArray& info = |
| 8700 GrowableObjectArray::Handle(zone, GrowableObjectArray::New()); | 8710 GrowableObjectArray::Handle(zone, GrowableObjectArray::New()); |
| 8701 const String& source = String::Handle(zone, Source()); | 8711 const String& source = String::Handle(zone, Source()); |
| 8702 const String& key = Symbols::Empty(); | 8712 const String& key = Symbols::Empty(); |
| 8703 const Object& line_separator = Object::Handle(zone); | 8713 const Object& line_separator = Object::Handle(zone); |
| 8714 Smi& value = Smi::Handle(zone); | |
| 8715 | |
| 8716 if (kind() == RawScript::kKernelTag) { | |
| 8717 const Array& line_starts_array = Array::Handle(line_starts()); | |
| 8718 if (line_starts_array.IsNull()) { | |
| 8719 // Scripts in the AOT snapshot do not have a line starts array. | |
| 8720 // A well-formed line number array has a leading null. | |
| 8721 info.Add(line_separator); // New line. | |
| 8722 return info.raw(); | |
| 8723 } | |
| 8724 intptr_t line_count = line_starts_array.Length(); | |
| 8725 ASSERT(line_count > 0); | |
| 8726 | |
| 8727 for (int i = 0; i < line_count; i++) { | |
| 8728 info.Add(line_separator); // New line. | |
| 8729 value = Smi::New(i + 1); | |
| 8730 info.Add(value); // Line number. | |
| 8731 value ^= line_starts_array.At(i); | |
| 8732 info.Add(value); // Token position. | |
| 8733 value = Smi::New(1); | |
| 8734 info.Add(value); // Column. | |
| 8735 } | |
| 8736 return info.raw(); | |
| 8737 } | |
| 8738 | |
| 8704 const TokenStream& tkns = TokenStream::Handle(zone, tokens()); | 8739 const TokenStream& tkns = TokenStream::Handle(zone, tokens()); |
| 8705 Smi& value = Smi::Handle(zone); | |
| 8706 String& tokenValue = String::Handle(zone); | 8740 String& tokenValue = String::Handle(zone); |
| 8707 ASSERT(!tkns.IsNull()); | 8741 ASSERT(!tkns.IsNull()); |
| 8708 TokenStream::Iterator tkit(zone, tkns, TokenPosition::kMinSource, | 8742 TokenStream::Iterator tkit(zone, tkns, TokenPosition::kMinSource, |
| 8709 TokenStream::Iterator::kAllTokens); | 8743 TokenStream::Iterator::kAllTokens); |
| 8710 int current_line = -1; | 8744 int current_line = -1; |
| 8711 Scanner s(source, key); | 8745 Scanner s(source, key); |
| 8712 s.Scan(); | 8746 s.Scan(); |
| 8713 bool skippedNewline = false; | 8747 bool skippedNewline = false; |
| 8714 while (tkit.CurrentTokenKind() != Token::kEOS) { | 8748 while (tkit.CurrentTokenKind() != Token::kEOS) { |
| 8715 if (tkit.CurrentTokenKind() == Token::kNEWLINE) { | 8749 if (tkit.CurrentTokenKind() == Token::kNEWLINE) { |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 8827 StoreNonPointer(&raw_ptr()->load_timestamp_, value); | 8861 StoreNonPointer(&raw_ptr()->load_timestamp_, value); |
| 8828 } | 8862 } |
| 8829 | 8863 |
| 8830 | 8864 |
| 8831 void Script::set_tokens(const TokenStream& value) const { | 8865 void Script::set_tokens(const TokenStream& value) const { |
| 8832 StorePointer(&raw_ptr()->tokens_, value.raw()); | 8866 StorePointer(&raw_ptr()->tokens_, value.raw()); |
| 8833 } | 8867 } |
| 8834 | 8868 |
| 8835 | 8869 |
| 8836 void Script::Tokenize(const String& private_key, bool use_shared_tokens) const { | 8870 void Script::Tokenize(const String& private_key, bool use_shared_tokens) const { |
| 8871 if (kind() == RawScript::kKernelTag) { | |
| 8872 return; | |
| 8873 } | |
| 8874 | |
| 8837 Thread* thread = Thread::Current(); | 8875 Thread* thread = Thread::Current(); |
| 8838 Zone* zone = thread->zone(); | 8876 Zone* zone = thread->zone(); |
| 8839 const TokenStream& tkns = TokenStream::Handle(zone, tokens()); | 8877 const TokenStream& tkns = TokenStream::Handle(zone, tokens()); |
| 8840 if (!tkns.IsNull()) { | 8878 if (!tkns.IsNull()) { |
| 8841 // Already tokenized. | 8879 // Already tokenized. |
| 8842 return; | 8880 return; |
| 8843 } | 8881 } |
| 8844 // Get the source, scan and allocate the token stream. | 8882 // Get the source, scan and allocate the token stream. |
| 8845 VMTagScope tagScope(thread, VMTag::kCompileScannerTagId); | 8883 VMTagScope tagScope(thread, VMTag::kCompileScannerTagId); |
| 8846 CSTAT_TIMER_SCOPE(thread, scanner_timer); | 8884 CSTAT_TIMER_SCOPE(thread, scanner_timer); |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 8893 | 8931 |
| 8894 smi ^= line_starts_array.At(midpoint); | 8932 smi ^= line_starts_array.At(midpoint); |
| 8895 if (smi.Value() > offset) { | 8933 if (smi.Value() > offset) { |
| 8896 max = midpoint - 1; | 8934 max = midpoint - 1; |
| 8897 } else { | 8935 } else { |
| 8898 min = midpoint; | 8936 min = midpoint; |
| 8899 } | 8937 } |
| 8900 } | 8938 } |
| 8901 *line = min + 1; | 8939 *line = min + 1; |
| 8902 smi ^= line_starts_array.At(min); | 8940 smi ^= line_starts_array.At(min); |
| 8903 *column = offset - smi.Value() + 1; | 8941 if (column != NULL) { |
| 8942 *column = offset - smi.Value() + 1; | |
| 8943 } | |
| 8904 if (token_len != NULL) { | 8944 if (token_len != NULL) { |
| 8905 *token_len = 1; | 8945 *token_len = 1; |
| 8906 } | 8946 } |
| 8907 return; | 8947 return; |
| 8908 } | 8948 } |
| 8909 | 8949 |
| 8910 const TokenStream& tkns = TokenStream::Handle(zone, tokens()); | 8950 const TokenStream& tkns = TokenStream::Handle(zone, tokens()); |
| 8911 if (tkns.IsNull()) { | 8951 if (tkns.IsNull()) { |
| 8912 ASSERT((Dart::snapshot_kind() == Snapshot::kAppAOT)); | 8952 ASSERT((Dart::snapshot_kind() == Snapshot::kAppAOT)); |
| 8913 *line = -1; | 8953 *line = -1; |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 8952 } | 8992 } |
| 8953 } | 8993 } |
| 8954 } | 8994 } |
| 8955 | 8995 |
| 8956 | 8996 |
| 8957 void Script::TokenRangeAtLine(intptr_t line_number, | 8997 void Script::TokenRangeAtLine(intptr_t line_number, |
| 8958 TokenPosition* first_token_index, | 8998 TokenPosition* first_token_index, |
| 8959 TokenPosition* last_token_index) const { | 8999 TokenPosition* last_token_index) const { |
| 8960 ASSERT(first_token_index != NULL && last_token_index != NULL); | 9000 ASSERT(first_token_index != NULL && last_token_index != NULL); |
| 8961 ASSERT(line_number > 0); | 9001 ASSERT(line_number > 0); |
| 9002 | |
| 9003 if (kind() == RawScript::kKernelTag) { | |
| 9004 const Array& line_starts_array = Array::Handle(line_starts()); | |
| 9005 if (line_starts_array.IsNull()) { | |
| 9006 // Scripts in the AOT snapshot do not have a line starts array. | |
| 9007 *first_token_index = TokenPosition::kNoSource; | |
| 9008 *last_token_index = TokenPosition::kNoSource; | |
| 9009 return; | |
| 9010 } | |
| 9011 ASSERT(line_starts_array.Length() >= line_number); | |
| 9012 Smi& value = Smi::Handle(); | |
| 9013 value ^= line_starts_array.At(line_number - 1); | |
| 9014 *first_token_index = TokenPosition(value.Value()); | |
| 9015 if (line_starts_array.Length() > line_number) { | |
| 9016 value ^= line_starts_array.At(line_number); | |
| 9017 *last_token_index = TokenPosition(value.Value() - 1); | |
| 9018 } else { | |
| 9019 // Length of source is last possible token in this script. | |
| 9020 *last_token_index = TokenPosition(String::Handle(Source()).Length()); | |
| 9021 } | |
| 9022 return; | |
| 9023 } | |
| 9024 | |
| 8962 Zone* zone = Thread::Current()->zone(); | 9025 Zone* zone = Thread::Current()->zone(); |
| 8963 *first_token_index = TokenPosition::kNoSource; | 9026 *first_token_index = TokenPosition::kNoSource; |
| 8964 *last_token_index = TokenPosition::kNoSource; | 9027 *last_token_index = TokenPosition::kNoSource; |
| 8965 const TokenStream& tkns = TokenStream::Handle(zone, tokens()); | 9028 const TokenStream& tkns = TokenStream::Handle(zone, tokens()); |
| 8966 line_number -= line_offset(); | 9029 line_number -= line_offset(); |
| 8967 if (line_number < 1) line_number = 1; | 9030 if (line_number < 1) line_number = 1; |
| 8968 TokenStream::Iterator tkit(zone, tkns, TokenPosition::kMinSource, | 9031 TokenStream::Iterator tkit(zone, tkns, TokenPosition::kMinSource, |
| 8969 TokenStream::Iterator::kAllTokens); | 9032 TokenStream::Iterator::kAllTokens); |
| 8970 // Scan through the token stream to the required line. | 9033 // Scan through the token stream to the required line. |
| 8971 intptr_t cur_line = 1; | 9034 intptr_t cur_line = 1; |
| (...skipping 13833 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 22805 return UserTag::null(); | 22868 return UserTag::null(); |
| 22806 } | 22869 } |
| 22807 | 22870 |
| 22808 | 22871 |
| 22809 const char* UserTag::ToCString() const { | 22872 const char* UserTag::ToCString() const { |
| 22810 const String& tag_label = String::Handle(label()); | 22873 const String& tag_label = String::Handle(label()); |
| 22811 return tag_label.ToCString(); | 22874 return tag_label.ToCString(); |
| 22812 } | 22875 } |
| 22813 | 22876 |
| 22814 } // namespace dart | 22877 } // namespace dart |
| OLD | NEW |