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 8602 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8613 intptr_t col_offset) const { | 8613 intptr_t col_offset) const { |
8614 ASSERT(line_offset >= 0); | 8614 ASSERT(line_offset >= 0); |
8615 ASSERT(col_offset >= 0); | 8615 ASSERT(col_offset >= 0); |
8616 StoreNonPointer(&raw_ptr()->line_offset_, line_offset); | 8616 StoreNonPointer(&raw_ptr()->line_offset_, line_offset); |
8617 StoreNonPointer(&raw_ptr()->col_offset_, col_offset); | 8617 StoreNonPointer(&raw_ptr()->col_offset_, col_offset); |
8618 } | 8618 } |
8619 | 8619 |
8620 | 8620 |
8621 void Script::GetTokenLocation(intptr_t token_pos, | 8621 void Script::GetTokenLocation(intptr_t token_pos, |
8622 intptr_t* line, | 8622 intptr_t* line, |
8623 intptr_t* column) const { | 8623 intptr_t* column, |
| 8624 intptr_t* token_len) const { |
8624 ASSERT(line != NULL); | 8625 ASSERT(line != NULL); |
8625 const TokenStream& tkns = TokenStream::Handle(tokens()); | 8626 const TokenStream& tkns = TokenStream::Handle(tokens()); |
8626 if (column == NULL) { | 8627 if (column == NULL) { |
8627 TokenStream::Iterator tkit(tkns, 0, TokenStream::Iterator::kAllTokens); | 8628 TokenStream::Iterator tkit(tkns, 0, TokenStream::Iterator::kAllTokens); |
8628 intptr_t cur_line = line_offset() + 1; | 8629 intptr_t cur_line = line_offset() + 1; |
8629 while (tkit.CurrentPosition() < token_pos && | 8630 while (tkit.CurrentPosition() < token_pos && |
8630 tkit.CurrentTokenKind() != Token::kEOS) { | 8631 tkit.CurrentTokenKind() != Token::kEOS) { |
8631 if (tkit.CurrentTokenKind() == Token::kNEWLINE) { | 8632 if (tkit.CurrentTokenKind() == Token::kNEWLINE) { |
8632 cur_line++; | 8633 cur_line++; |
8633 } | 8634 } |
8634 tkit.Advance(); | 8635 tkit.Advance(); |
8635 } | 8636 } |
8636 *line = cur_line; | 8637 *line = cur_line; |
8637 } else { | 8638 } else { |
8638 const String& src = String::Handle(Source()); | 8639 const String& src = String::Handle(Source()); |
8639 intptr_t src_pos = tkns.ComputeSourcePosition(token_pos); | 8640 intptr_t src_pos = tkns.ComputeSourcePosition(token_pos); |
8640 Scanner scanner(src, Symbols::Empty()); | 8641 Scanner scanner(src, Symbols::Empty()); |
8641 scanner.ScanTo(src_pos); | 8642 scanner.ScanTo(src_pos); |
8642 intptr_t relative_line = scanner.CurrentPosition().line; | 8643 intptr_t relative_line = scanner.CurrentPosition().line; |
8643 *line = relative_line + line_offset(); | 8644 *line = relative_line + line_offset(); |
8644 *column = scanner.CurrentPosition().column; | 8645 *column = scanner.CurrentPosition().column; |
| 8646 if (token_len != NULL) { |
| 8647 if (scanner.current_token().literal != NULL) { |
| 8648 *token_len = scanner.current_token().literal->Length(); |
| 8649 } else { |
| 8650 *token_len = 1; |
| 8651 } |
| 8652 } |
8645 // On the first line of the script we must add the column offset. | 8653 // On the first line of the script we must add the column offset. |
8646 if (relative_line == 1) { | 8654 if (relative_line == 1) { |
8647 *column += col_offset(); | 8655 *column += col_offset(); |
8648 } | 8656 } |
8649 } | 8657 } |
8650 } | 8658 } |
8651 | 8659 |
8652 | 8660 |
8653 void Script::TokenRangeAtLine(intptr_t line_number, | 8661 void Script::TokenRangeAtLine(intptr_t line_number, |
8654 intptr_t* first_token_index, | 8662 intptr_t* first_token_index, |
(...skipping 12890 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
21545 return tag_label.ToCString(); | 21553 return tag_label.ToCString(); |
21546 } | 21554 } |
21547 | 21555 |
21548 | 21556 |
21549 void UserTag::PrintJSONImpl(JSONStream* stream, bool ref) const { | 21557 void UserTag::PrintJSONImpl(JSONStream* stream, bool ref) const { |
21550 Instance::PrintJSONImpl(stream, ref); | 21558 Instance::PrintJSONImpl(stream, ref); |
21551 } | 21559 } |
21552 | 21560 |
21553 | 21561 |
21554 } // namespace dart | 21562 } // namespace dart |
OLD | NEW |