| 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/scanner.h" | 5 #include "vm/scanner.h" |
| 6 | 6 |
| 7 #include "platform/assert.h" | 7 #include "platform/assert.h" |
| 8 #include "vm/dart.h" | 8 #include "vm/dart.h" |
| 9 #include "vm/flags.h" | 9 #include "vm/flags.h" |
| 10 #include "vm/object.h" | 10 #include "vm/object.h" |
| (...skipping 891 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 902 // Script::GenerateLineNumberArray to stay in sync. | 902 // Script::GenerateLineNumberArray to stay in sync. |
| 903 empty_string_token_.position.line = current_token_.position.line; | 903 empty_string_token_.position.line = current_token_.position.line; |
| 904 token_stream->Add(empty_string_token_); | 904 token_stream->Add(empty_string_token_); |
| 905 } | 905 } |
| 906 token_stream->Add(current_token_); | 906 token_stream->Add(current_token_); |
| 907 prev_token_line_ = current_token_.position.line; | 907 prev_token_line_ = current_token_.position.line; |
| 908 } while (current_token_.kind != Token::kEOS); | 908 } while (current_token_.kind != Token::kEOS); |
| 909 } | 909 } |
| 910 | 910 |
| 911 | 911 |
| 912 void Scanner::ScanTo(intptr_t token_index) { | 912 void Scanner::ScanTo(TokenPosition token_index) { |
| 913 int index = 0; | 913 TokenPosition index = TokenPosition::kMinSource; |
| 914 Reset(); | 914 Reset(); |
| 915 do { | 915 do { |
| 916 Scan(); | 916 Scan(); |
| 917 | 917 |
| 918 bool inserted_new_lines = false; | 918 bool inserted_new_lines = false; |
| 919 for (intptr_t diff = current_token_.position.line - prev_token_line_; | 919 for (intptr_t diff = current_token_.position.line - prev_token_line_; |
| 920 diff > 0; | 920 diff > 0; |
| 921 diff--) { | 921 diff--) { |
| 922 index++; // Advance the index to account for tokens added in ScanAll. | 922 // Advance the index to account for tokens added in ScanAll. |
| 923 index.Next(); |
| 923 inserted_new_lines = true; | 924 inserted_new_lines = true; |
| 924 } | 925 } |
| 925 | 926 |
| 926 if (inserted_new_lines && | 927 if (inserted_new_lines && |
| 927 ((current_token_.kind == Token::kINTERPOL_VAR) || | 928 ((current_token_.kind == Token::kINTERPOL_VAR) || |
| 928 (current_token_.kind == Token::kINTERPOL_START))) { | 929 (current_token_.kind == Token::kINTERPOL_START))) { |
| 929 index++; // Advance the index to account for tokens added in ScanAll. | 930 // Advance the index to account for tokens added in ScanAll. |
| 931 index.Next(); |
| 930 } | 932 } |
| 931 index++; | 933 index.Next(); |
| 932 prev_token_line_ = current_token_.position.line; | 934 prev_token_line_ = current_token_.position.line; |
| 933 } while ((token_index >= index) && (current_token_.kind != Token::kEOS)); | 935 } while ((token_index >= index) && (current_token_.kind != Token::kEOS)); |
| 934 } | 936 } |
| 935 | 937 |
| 936 | 938 |
| 937 const Scanner::GrowableTokenStream& Scanner::GetStream() { | 939 const Scanner::GrowableTokenStream& Scanner::GetStream() { |
| 938 GrowableTokenStream* ts = new(Z) GrowableTokenStream(128); | 940 GrowableTokenStream* ts = new(Z) GrowableTokenStream(128); |
| 939 ScanAll(ts); | 941 ScanAll(ts); |
| 940 if (FLAG_print_tokens) { | 942 if (FLAG_print_tokens) { |
| 941 Scanner::PrintTokens(*ts); | 943 Scanner::PrintTokens(*ts); |
| (...skipping 29 matching lines...) Expand all Loading... |
| 971 keywords_[i].keyword_symbol = &Symbols::Keyword(token); | 973 keywords_[i].keyword_symbol = &Symbols::Keyword(token); |
| 972 | 974 |
| 973 int ch = keywords_[i].keyword_chars[0] - 'a'; | 975 int ch = keywords_[i].keyword_chars[0] - 'a'; |
| 974 if (keywords_char_offset_[ch] == Token::kNumKeywords) { | 976 if (keywords_char_offset_[ch] == Token::kNumKeywords) { |
| 975 keywords_char_offset_[ch] = i; | 977 keywords_char_offset_[ch] = i; |
| 976 } | 978 } |
| 977 } | 979 } |
| 978 } | 980 } |
| 979 | 981 |
| 980 } // namespace dart | 982 } // namespace dart |
| OLD | NEW |