| 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/flags.h" | 8 #include "vm/flags.h" |
| 9 #include "vm/object.h" | 9 #include "vm/object.h" |
| 10 #include "vm/object_store.h" | 10 #include "vm/object_store.h" |
| (...skipping 24 matching lines...) Expand all Loading... |
| 35 Token::Kind token = static_cast<Token::Kind>(Token::kFirstKeyword + i); | 35 Token::Kind token = static_cast<Token::Kind>(Token::kFirstKeyword + i); |
| 36 keywords_[i].kind = token; | 36 keywords_[i].kind = token; |
| 37 keywords_[i].keyword_chars = Token::Str(token); | 37 keywords_[i].keyword_chars = Token::Str(token); |
| 38 keywords_[i].keyword_len = strlen(Token::Str(token)); | 38 keywords_[i].keyword_len = strlen(Token::Str(token)); |
| 39 keywords_[i].keyword_symbol = NULL; | 39 keywords_[i].keyword_symbol = NULL; |
| 40 } | 40 } |
| 41 } | 41 } |
| 42 | 42 |
| 43 | 43 |
| 44 void Scanner::Reset() { | 44 void Scanner::Reset() { |
| 45 // Non-chaning newline properties. |
| 46 newline_token_.kind = Token::kNEWLINE; |
| 47 newline_token_.literal = NULL; |
| 48 newline_token_.length = 1; |
| 49 // We don't preserve the column information. |
| 50 newline_token_.position.column = 0; |
| 51 |
| 45 lookahead_pos_ = -1; | 52 lookahead_pos_ = -1; |
| 46 token_start_ = 0; | 53 token_start_ = 0; |
| 47 c0_ = '\0'; | 54 c0_ = '\0'; |
| 48 newline_seen_ = false; | 55 newline_seen_ = false; |
| 56 prev_token_line_ = 1; |
| 49 while (saved_context_ != NULL) { | 57 while (saved_context_ != NULL) { |
| 50 ScanContext* ctx = saved_context_; | 58 ScanContext* ctx = saved_context_; |
| 51 saved_context_ = ctx->next; | 59 saved_context_ = ctx->next; |
| 52 delete ctx; | 60 delete ctx; |
| 53 } | 61 } |
| 54 string_delimiter_ = '\0'; | 62 string_delimiter_ = '\0'; |
| 55 string_is_multiline_ = false; | 63 string_is_multiline_ = false; |
| 56 brace_level_ = 0; | 64 brace_level_ = 0; |
| 57 c0_pos_.line = 1; | 65 c0_pos_.line = 1; |
| 58 c0_pos_.column = 0; | 66 c0_pos_.column = 0; |
| (...skipping 797 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 856 } | 864 } |
| 857 } while (current_token_.kind == Token::kWHITESP); | 865 } while (current_token_.kind == Token::kWHITESP); |
| 858 current_token_.length = lookahead_pos_ - token_start_; | 866 current_token_.length = lookahead_pos_ - token_start_; |
| 859 } | 867 } |
| 860 | 868 |
| 861 | 869 |
| 862 void Scanner::ScanAll(GrowableTokenStream* token_stream) { | 870 void Scanner::ScanAll(GrowableTokenStream* token_stream) { |
| 863 Reset(); | 871 Reset(); |
| 864 do { | 872 do { |
| 865 Scan(); | 873 Scan(); |
| 874 |
| 875 for (intptr_t diff = current_token_.position.line - prev_token_line_; |
| 876 diff > 0; |
| 877 diff--) { |
| 878 newline_token_.position.line = current_token_.position.line - diff; |
| 879 token_stream->Add(newline_token_); |
| 880 } |
| 881 |
| 866 token_stream->Add(current_token_); | 882 token_stream->Add(current_token_); |
| 883 prev_token_line_ = current_token_.position.line; |
| 867 } while (current_token_.kind != Token::kEOS); | 884 } while (current_token_.kind != Token::kEOS); |
| 868 } | 885 } |
| 869 | 886 |
| 870 | 887 |
| 871 void Scanner::ScanTo(intptr_t token_index) { | 888 void Scanner::ScanTo(intptr_t token_index) { |
| 872 int index = 0; | 889 int index = 0; |
| 873 Reset(); | 890 Reset(); |
| 874 do { | 891 do { |
| 875 Scan(); | 892 Scan(); |
| 876 index++; | 893 index++; |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 948 "%c%#" Px "", kPrivateKeySeparator, key_value); | 965 "%c%#" Px "", kPrivateKeySeparator, key_value); |
| 949 const String& result = String::Handle(String::New(private_key, Heap::kOld)); | 966 const String& result = String::Handle(String::New(private_key, Heap::kOld)); |
| 950 return result.raw(); | 967 return result.raw(); |
| 951 } | 968 } |
| 952 | 969 |
| 953 | 970 |
| 954 void Scanner::InitOnce() { | 971 void Scanner::InitOnce() { |
| 955 } | 972 } |
| 956 | 973 |
| 957 } // namespace dart | 974 } // namespace dart |
| OLD | NEW |