| 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/cpu.h" | 10 #include "vm/cpu.h" |
| (...skipping 6346 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6357 ASSERT(line_offset >= 0); | 6357 ASSERT(line_offset >= 0); |
| 6358 ASSERT(col_offset >= 0); | 6358 ASSERT(col_offset >= 0); |
| 6359 raw_ptr()->line_offset_ = line_offset; | 6359 raw_ptr()->line_offset_ = line_offset; |
| 6360 raw_ptr()->col_offset_ = col_offset; | 6360 raw_ptr()->col_offset_ = col_offset; |
| 6361 } | 6361 } |
| 6362 | 6362 |
| 6363 | 6363 |
| 6364 void Script::GetTokenLocation(intptr_t token_pos, | 6364 void Script::GetTokenLocation(intptr_t token_pos, |
| 6365 intptr_t* line, | 6365 intptr_t* line, |
| 6366 intptr_t* column) const { | 6366 intptr_t* column) const { |
| 6367 const String& src = String::Handle(Source()); | 6367 ASSERT(line != NULL); |
| 6368 const TokenStream& tkns = TokenStream::Handle(tokens()); | 6368 const TokenStream& tkns = TokenStream::Handle(tokens()); |
| 6369 intptr_t src_pos = tkns.ComputeSourcePosition(token_pos); | 6369 if (column == NULL) { |
| 6370 Scanner scanner(src, Symbols::Empty()); | 6370 TokenStream::Iterator tkit(tkns, 0, TokenStream::Iterator::kAllTokens); |
| 6371 scanner.ScanTo(src_pos); | 6371 intptr_t cur_line = line_offset() + 1; |
| 6372 intptr_t relative_line = scanner.CurrentPosition().line; | 6372 while (tkit.CurrentPosition() < token_pos && |
| 6373 *line = relative_line + line_offset(); | 6373 tkit.CurrentTokenKind() != Token::kEOS) { |
| 6374 *column = scanner.CurrentPosition().column; | 6374 if (tkit.CurrentTokenKind() == Token::kNEWLINE) { |
| 6375 // On the first line of the script we must add the column offset. | 6375 cur_line++; |
| 6376 if (relative_line == 1) { | 6376 } |
| 6377 *column += col_offset(); | 6377 tkit.Advance(); |
| 6378 } |
| 6379 *line = cur_line; |
| 6380 } else { |
| 6381 const String& src = String::Handle(Source()); |
| 6382 intptr_t src_pos = tkns.ComputeSourcePosition(token_pos); |
| 6383 Scanner scanner(src, Symbols::Empty()); |
| 6384 scanner.ScanTo(src_pos); |
| 6385 intptr_t relative_line = scanner.CurrentPosition().line; |
| 6386 *line = relative_line + line_offset(); |
| 6387 *column = scanner.CurrentPosition().column; |
| 6388 // On the first line of the script we must add the column offset. |
| 6389 if (relative_line == 1) { |
| 6390 *column += col_offset(); |
| 6391 } |
| 6378 } | 6392 } |
| 6379 } | 6393 } |
| 6380 | 6394 |
| 6381 | 6395 |
| 6382 void Script::TokenRangeAtLine(intptr_t line_number, | 6396 void Script::TokenRangeAtLine(intptr_t line_number, |
| 6383 intptr_t* first_token_index, | 6397 intptr_t* first_token_index, |
| 6384 intptr_t* last_token_index) const { | 6398 intptr_t* last_token_index) const { |
| 6385 const String& src = String::Handle(Source()); | 6399 ASSERT(first_token_index != NULL && last_token_index != NULL); |
| 6400 ASSERT(line_number > 0); |
| 6401 *first_token_index = -1; |
| 6402 *last_token_index = -1; |
| 6386 const TokenStream& tkns = TokenStream::Handle(tokens()); | 6403 const TokenStream& tkns = TokenStream::Handle(tokens()); |
| 6387 line_number -= line_offset(); | 6404 line_number -= line_offset(); |
| 6388 if (line_number < 1) line_number = 1; | 6405 if (line_number < 1) line_number = 1; |
| 6389 Scanner scanner(src, Symbols::Empty()); | 6406 TokenStream::Iterator tkit(tkns, 0, TokenStream::Iterator::kAllTokens); |
| 6390 scanner.TokenRangeAtLine(line_number, first_token_index, last_token_index); | 6407 // Scan through the token stream to the required line. |
| 6391 if (*first_token_index >= 0) { | 6408 intptr_t cur_line = 1; |
| 6392 *first_token_index = tkns.ComputeTokenPosition(*first_token_index); | 6409 while (cur_line < line_number && tkit.CurrentTokenKind() != Token::kEOS) { |
| 6410 if (tkit.CurrentTokenKind() == Token::kNEWLINE) { |
| 6411 cur_line++; |
| 6412 } |
| 6413 tkit.Advance(); |
| 6393 } | 6414 } |
| 6394 if (*last_token_index >= 0) { | 6415 if (tkit.CurrentTokenKind() == Token::kEOS) { |
| 6395 *last_token_index = tkns.ComputeTokenPosition(*last_token_index); | 6416 // End of token stream before reaching required line. |
| 6417 return; |
| 6396 } | 6418 } |
| 6419 if (tkit.CurrentTokenKind() == Token::kNEWLINE) { |
| 6420 // No tokens on the current line. If there is a valid token afterwards, put |
| 6421 // it into first_token_index. |
| 6422 while (tkit.CurrentTokenKind() == Token::kNEWLINE && |
| 6423 tkit.CurrentTokenKind() != Token::kEOS) { |
| 6424 tkit.Advance(); |
| 6425 } |
| 6426 if (tkit.CurrentTokenKind() != Token::kEOS) { |
| 6427 *first_token_index = tkit.CurrentPosition(); |
| 6428 } |
| 6429 return; |
| 6430 } |
| 6431 *first_token_index = tkit.CurrentPosition(); |
| 6432 // We cannot do "CurrentPosition() - 1" for the last token, because we do not |
| 6433 // know whether the previous token is a simple one or not. |
| 6434 intptr_t end_pos = *first_token_index; |
| 6435 while (tkit.CurrentTokenKind() != Token::kNEWLINE && |
| 6436 tkit.CurrentTokenKind() != Token::kEOS) { |
| 6437 end_pos = tkit.CurrentPosition(); |
| 6438 tkit.Advance(); |
| 6439 } |
| 6440 *last_token_index = end_pos; |
| 6397 } | 6441 } |
| 6398 | 6442 |
| 6399 | 6443 |
| 6400 RawString* Script::GetLine(intptr_t line_number) const { | 6444 RawString* Script::GetLine(intptr_t line_number) const { |
| 6401 const String& src = String::Handle(Source()); | 6445 const String& src = String::Handle(Source()); |
| 6402 intptr_t relative_line_number = line_number - line_offset(); | 6446 intptr_t relative_line_number = line_number - line_offset(); |
| 6403 intptr_t current_line = 1; | 6447 intptr_t current_line = 1; |
| 6404 intptr_t line_start_idx = -1; | 6448 intptr_t line_start_idx = -1; |
| 6405 intptr_t last_char_idx = -1; | 6449 intptr_t last_char_idx = -1; |
| 6406 for (intptr_t ix = 0; | 6450 for (intptr_t ix = 0; |
| (...skipping 8630 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 15037 return "_MirrorReference"; | 15081 return "_MirrorReference"; |
| 15038 } | 15082 } |
| 15039 | 15083 |
| 15040 | 15084 |
| 15041 void MirrorReference::PrintToJSONStream(JSONStream* stream, bool ref) const { | 15085 void MirrorReference::PrintToJSONStream(JSONStream* stream, bool ref) const { |
| 15042 JSONObject jsobj(stream); | 15086 JSONObject jsobj(stream); |
| 15043 } | 15087 } |
| 15044 | 15088 |
| 15045 | 15089 |
| 15046 } // namespace dart | 15090 } // namespace dart |
| OLD | NEW |