Chromium Code Reviews| Index: runtime/vm/object.cc |
| diff --git a/runtime/vm/object.cc b/runtime/vm/object.cc |
| index 14a9b6342e531e446bb6d7de622b27ef62467593..8da02560960b1fbf193e03293c71a2d64a03b59b 100644 |
| --- a/runtime/vm/object.cc |
| +++ b/runtime/vm/object.cc |
| @@ -3461,6 +3461,11 @@ TokenPosition Class::ComputeEndTokenPos() const { |
| Zone* zone = Thread::Current()->zone(); |
| const Script& scr = Script::Handle(zone, script()); |
| ASSERT(!scr.IsNull()); |
| + |
| + if (scr.kind() == RawScript::kKernelTag) { |
| + return TokenPosition::kMinSource; |
| + } |
| + |
| const TokenStream& tkns = TokenStream::Handle(zone, scr.tokens()); |
| if (tkns.IsNull()) { |
| ASSERT(Dart::snapshot_kind() == Snapshot::kAppAOT); |
| @@ -8680,6 +8685,11 @@ RawString* Script::Source() const { |
| RawString* Script::GenerateSource() const { |
| + if (kind() == RawScript::kKernelTag) { |
| + // In kernel it's embedded. |
| + return raw_ptr()->source_; |
| + } |
| + |
| const TokenStream& token_stream = TokenStream::Handle(tokens()); |
| if (token_stream.IsNull()) { |
| ASSERT(Dart::snapshot_kind() == Snapshot::kAppAOT); |
| @@ -8701,8 +8711,32 @@ RawGrowableObjectArray* Script::GenerateLineNumberArray() const { |
| const String& source = String::Handle(zone, Source()); |
| const String& key = Symbols::Empty(); |
| const Object& line_separator = Object::Handle(zone); |
| - const TokenStream& tkns = TokenStream::Handle(zone, tokens()); |
| Smi& value = Smi::Handle(zone); |
| + |
| + if (kind() == RawScript::kKernelTag) { |
| + const Array& line_starts_array = Array::Handle(line_starts()); |
| + if (line_starts_array.IsNull()) { |
| + // Scripts in the AOT snapshot do not have a line starts array. |
| + // We cannot really answer, but at least respond with null-entry. |
|
Kevin Millikin (Google)
2016/12/20 12:03:34
Don't write that we cannot really answer, we do an
jensj
2016/12/20 13:30:23
Done.
|
| + info.Add(line_separator); // new line. |
| + return info.raw(); |
| + } |
| + intptr_t line_count = line_starts_array.Length(); |
| + ASSERT(line_count > 0); |
| + |
| + for (int i = 0; i < line_count; i++) { |
| + info.Add(line_separator); // new line. |
|
Kevin Millikin (Google)
2016/12/20 12:03:34
Capitalize even these end-of-line comments.
jensj
2016/12/20 13:30:23
Done.
|
| + value = Smi::New(i + 1); |
| + info.Add(value); // line number. |
| + value ^= line_starts_array.At(i); |
| + info.Add(value); // token position. |
| + value = Smi::New(1); |
| + info.Add(value); // column. |
| + } |
| + return info.raw(); |
| + } |
| + |
| + const TokenStream& tkns = TokenStream::Handle(zone, tokens()); |
| String& tokenValue = String::Handle(zone); |
| ASSERT(!tkns.IsNull()); |
| TokenStream::Iterator tkit(zone, tkns, TokenPosition::kMinSource, |
| @@ -8834,6 +8868,10 @@ void Script::set_tokens(const TokenStream& value) const { |
| void Script::Tokenize(const String& private_key, bool use_shared_tokens) const { |
| + if (kind() == RawScript::kKernelTag) { |
| + return; |
| + } |
| + |
| Thread* thread = Thread::Current(); |
| Zone* zone = thread->zone(); |
| const TokenStream& tkns = TokenStream::Handle(zone, tokens()); |
| @@ -8900,7 +8938,9 @@ void Script::GetTokenLocation(TokenPosition token_pos, |
| } |
| *line = min + 1; |
| smi ^= line_starts_array.At(min); |
| - *column = offset - smi.Value() + 1; |
| + if (column != NULL) { |
| + *column = offset - smi.Value() + 1; |
| + } |
| if (token_len != NULL) { |
| *token_len = 1; |
| } |
| @@ -8959,6 +8999,31 @@ void Script::TokenRangeAtLine(intptr_t line_number, |
| TokenPosition* last_token_index) const { |
| ASSERT(first_token_index != NULL && last_token_index != NULL); |
| ASSERT(line_number > 0); |
| + |
| + if (kind() == RawScript::kKernelTag) { |
| + const Array& line_starts_array = Array::Handle(line_starts()); |
| + if (line_starts_array.IsNull()) { |
| + // Scripts in the AOT snapshot do not have a line starts array. |
| + *first_token_index = TokenPosition::kNoSource; |
| + *last_token_index = TokenPosition::kNoSource; |
| + return; |
| + } |
| + ASSERT(line_starts_array.Length() >= line_number); |
| + Smi& value = Smi::Handle(); |
| + value ^= line_starts_array.At(line_number - 1); |
| + *first_token_index = TokenPosition(value.Value()); |
| + if (line_starts_array.Length() > line_number) { |
| + value ^= line_starts_array.At(line_number); |
| + *last_token_index = TokenPosition(value.Value() - 1); |
| + } else { |
| + // We don't currently have this number. |
| + // TODO(jensj): Either use the biggest token position seen, or include |
| + // the end of the file in the line-starts array. |
| + *last_token_index = TokenPosition(value.Value() + 42); |
|
Kevin Millikin (Google)
2016/12/20 12:03:34
42 is too cute. You could just use value.Value().
jensj
2016/12/20 13:30:23
I'll change that. I initially wrote this before in
|
| + } |
| + return; |
| + } |
| + |
| Zone* zone = Thread::Current()->zone(); |
| *first_token_index = TokenPosition::kNoSource; |
| *last_token_index = TokenPosition::kNoSource; |