Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(294)

Side by Side Diff: runtime/vm/object.cc

Issue 24359005: Make Script::GetTokenLocation() and Script::TokenRangeAtLine() use token streams where possible. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | runtime/vm/object_test.cc » ('j') | runtime/vm/object_test.cc » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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());
6368 const TokenStream& tkns = TokenStream::Handle(tokens()); 6367 const TokenStream& tkns = TokenStream::Handle(tokens());
6369 intptr_t src_pos = tkns.ComputeSourcePosition(token_pos); 6368 if (column == NULL) {
6370 Scanner scanner(src, Symbols::Empty()); 6369 TokenStream::Iterator tkit(tkns, 0, TokenStream::Iterator::kAllTokens);
6371 scanner.ScanTo(src_pos); 6370 intptr_t relative_line = 1;
6372 intptr_t relative_line = scanner.CurrentPosition().line; 6371 while (tkit.CurrentPosition() < token_pos) {
hausner 2013/09/23 18:54:49 Does this terminate properly if I give a token pos
Michael Lippautz (Google) 2013/09/23 21:15:03 Fixed.
6373 *line = relative_line + line_offset(); 6372 if (tkit.CurrentTokenKind() == Token::kNEWLINE) {
6374 *column = scanner.CurrentPosition().column; 6373 relative_line++;
6375 // On the first line of the script we must add the column offset. 6374 }
6376 if (relative_line == 1) { 6375 tkit.Advance();
6377 *column += col_offset(); 6376 }
6377 *line = relative_line + line_offset();
6378 } else {
6379 const String& src = String::Handle(Source());
6380 intptr_t src_pos = tkns.ComputeSourcePosition(token_pos);
6381 Scanner scanner(src, Symbols::Empty());
6382 scanner.ScanTo(src_pos);
6383 intptr_t relative_line = scanner.CurrentPosition().line;
6384 *line = relative_line + line_offset();
6385 *column = scanner.CurrentPosition().column;
6386 // On the first line of the script we must add the column offset.
6387 if (relative_line == 1) {
6388 *column += col_offset();
6389 }
6378 } 6390 }
6379 } 6391 }
6380 6392
6381 6393
6382 void Script::TokenRangeAtLine(intptr_t line_number, 6394 void Script::TokenRangeAtLine(intptr_t line_number,
6383 intptr_t* first_token_index, 6395 intptr_t* first_token_index,
6384 intptr_t* last_token_index) const { 6396 intptr_t* last_token_index) const {
6385 const String& src = String::Handle(Source());
6386 const TokenStream& tkns = TokenStream::Handle(tokens()); 6397 const TokenStream& tkns = TokenStream::Handle(tokens());
6387 line_number -= line_offset(); 6398 line_number -= line_offset();
6388 if (line_number < 1) line_number = 1; 6399 if (line_number < 1) line_number = 1;
6389 Scanner scanner(src, Symbols::Empty()); 6400 TokenStream::Iterator tkit(tkns, 0, TokenStream::Iterator::kAllTokens);
6390 scanner.TokenRangeAtLine(line_number, first_token_index, last_token_index); 6401 // Scan through the token stream to the required line.
6391 if (*first_token_index >= 0) { 6402 while (line_number > 1) {
6392 *first_token_index = tkns.ComputeTokenPosition(*first_token_index); 6403 if (tkit.CurrentTokenKind() == Token::kNEWLINE) {
6404 line_number--;
6405 }
6406 tkit.Advance();
6393 } 6407 }
6394 if (*last_token_index >= 0) { 6408 *first_token_index = tkit.CurrentPosition();
6395 *last_token_index = tkns.ComputeTokenPosition(*last_token_index); 6409 // We cannot do "CurrentPosition() - 1" for the last token, because we do not
6410 // know whether the previous token is a simple or not.
6411 intptr_t end_pos = *first_token_index;
6412 while (tkit.CurrentTokenKind() != Token::kNEWLINE &&
6413 tkit.CurrentTokenKind() != Token::kEOS) {
6414 end_pos = tkit.CurrentPosition();
6415 tkit.Advance();
6396 } 6416 }
6417 *last_token_index = end_pos;
hausner 2013/09/23 18:54:49 The old code only assigned to the out parameters i
Michael Lippautz (Google) 2013/09/23 21:15:03 The out parameters are required to be non-NULL. Mo
6397 } 6418 }
6398 6419
6399 6420
6400 RawString* Script::GetLine(intptr_t line_number) const { 6421 RawString* Script::GetLine(intptr_t line_number) const {
6401 const String& src = String::Handle(Source()); 6422 const String& src = String::Handle(Source());
6402 intptr_t relative_line_number = line_number - line_offset(); 6423 intptr_t relative_line_number = line_number - line_offset();
6403 intptr_t current_line = 1; 6424 intptr_t current_line = 1;
6404 intptr_t line_start_idx = -1; 6425 intptr_t line_start_idx = -1;
6405 intptr_t last_char_idx = -1; 6426 intptr_t last_char_idx = -1;
6406 for (intptr_t ix = 0; 6427 for (intptr_t ix = 0;
(...skipping 8630 matching lines...) Expand 10 before | Expand all | Expand 10 after
15037 return "_MirrorReference"; 15058 return "_MirrorReference";
15038 } 15059 }
15039 15060
15040 15061
15041 void MirrorReference::PrintToJSONStream(JSONStream* stream, bool ref) const { 15062 void MirrorReference::PrintToJSONStream(JSONStream* stream, bool ref) const {
15042 JSONObject jsobj(stream); 15063 JSONObject jsobj(stream);
15043 } 15064 }
15044 15065
15045 15066
15046 } // namespace dart 15067 } // namespace dart
OLDNEW
« no previous file with comments | « no previous file | runtime/vm/object_test.cc » ('j') | runtime/vm/object_test.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698