| 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/thread.h" | 11 #include "vm/thread.h" |
| 11 #include "vm/token.h" | 12 #include "vm/token.h" |
| 12 | 13 |
| 13 namespace dart { | 14 namespace dart { |
| 14 | 15 |
| 15 DEFINE_FLAG(bool, print_tokens, false, "Print scanned tokens."); | 16 DEFINE_FLAG(bool, print_tokens, false, "Print scanned tokens."); |
| 16 | 17 |
| 17 void Scanner::InitKeywordTable() { | 18 void Scanner::InitKeywordTable() { |
| 19 ObjectStore* object_store = Isolate::Current()->object_store(); |
| 20 keyword_symbol_table_ = object_store->keyword_symbols(); |
| 21 if (keyword_symbol_table_.IsNull()) { |
| 22 object_store->InitKeywordTable(); |
| 23 keyword_symbol_table_ = object_store->keyword_symbols(); |
| 24 ASSERT(!keyword_symbol_table_.IsNull()); |
| 25 } |
| 18 for (int i = 0; i < Token::numKeywords; i++) { | 26 for (int i = 0; i < Token::numKeywords; i++) { |
| 19 Token::Kind token = static_cast<Token::Kind>(Token::kFirstKeyword + i); | 27 Token::Kind token = static_cast<Token::Kind>(Token::kFirstKeyword + i); |
| 20 keywords_[i].kind = token; | 28 keywords_[i].kind = token; |
| 21 keywords_[i].keyword_chars = Token::Str(token); | 29 keywords_[i].keyword_chars = Token::Str(token); |
| 22 keywords_[i].keyword_len = strlen(Token::Str(token)); | 30 keywords_[i].keyword_len = strlen(Token::Str(token)); |
| 23 keywords_[i].keyword_symbol = NULL; | 31 keywords_[i].keyword_symbol = NULL; |
| 24 } | 32 } |
| 25 } | 33 } |
| 26 | 34 |
| 27 | 35 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 41 c0_pos_.line = 1; | 49 c0_pos_.line = 1; |
| 42 c0_pos_.column = 0; | 50 c0_pos_.column = 0; |
| 43 ReadChar(); | 51 ReadChar(); |
| 44 } | 52 } |
| 45 | 53 |
| 46 | 54 |
| 47 Scanner::Scanner(const String& src, const String& private_key) | 55 Scanner::Scanner(const String& src, const String& private_key) |
| 48 : source_(src), | 56 : source_(src), |
| 49 source_length_(src.Length()), | 57 source_length_(src.Length()), |
| 50 saved_context_(NULL), | 58 saved_context_(NULL), |
| 51 private_key_(String::ZoneHandle(private_key.raw())) { | 59 private_key_(String::ZoneHandle(private_key.raw())), |
| 60 keyword_symbol_table_(Array::ZoneHandle()) { |
| 52 Reset(); | 61 Reset(); |
| 53 InitKeywordTable(); | 62 InitKeywordTable(); |
| 54 } | 63 } |
| 55 | 64 |
| 56 Scanner::~Scanner() { | 65 Scanner::~Scanner() { |
| 57 while (saved_context_ != NULL) { | 66 while (saved_context_ != NULL) { |
| 58 ScanContext* ctx = saved_context_; | 67 ScanContext* ctx = saved_context_; |
| 59 saved_context_ = ctx->next; | 68 saved_context_ = ctx->next; |
| 60 delete ctx; | 69 delete ctx; |
| 61 } | 70 } |
| (...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 254 keywords_[i].keyword_chars[0] <= ident_char0) { | 263 keywords_[i].keyword_chars[0] <= ident_char0) { |
| 255 if (keywords_[i].keyword_len == ident_length) { | 264 if (keywords_[i].keyword_len == ident_length) { |
| 256 const char* keyword = keywords_[i].keyword_chars; | 265 const char* keyword = keywords_[i].keyword_chars; |
| 257 int char_pos = 0; | 266 int char_pos = 0; |
| 258 while ((char_pos < ident_length) && | 267 while ((char_pos < ident_length) && |
| 259 (keyword[char_pos] == source_.CharAt(ident_pos + char_pos))) { | 268 (keyword[char_pos] == source_.CharAt(ident_pos + char_pos))) { |
| 260 char_pos++; | 269 char_pos++; |
| 261 } | 270 } |
| 262 if (char_pos == ident_length) { | 271 if (char_pos == ident_length) { |
| 263 if (keywords_[i].keyword_symbol == NULL) { | 272 if (keywords_[i].keyword_symbol == NULL) { |
| 264 keywords_[i].keyword_symbol = &String::ZoneHandle( | 273 String& symbol = String::ZoneHandle(); |
| 265 String::NewSymbol(source_, ident_pos, ident_length)); | 274 symbol ^= keyword_symbol_table_.At(i); |
| 275 if (symbol.IsNull()) { |
| 276 symbol = String::NewSymbol(source_, ident_pos, ident_length); |
| 277 keyword_symbol_table_.SetAt(i, symbol); |
| 278 } |
| 279 keywords_[i].keyword_symbol = &symbol; |
| 266 } | 280 } |
| 267 current_token_.literal = keywords_[i].keyword_symbol; | 281 current_token_.literal = keywords_[i].keyword_symbol; |
| 268 current_token_.kind = keywords_[i].kind; | 282 current_token_.kind = keywords_[i].kind; |
| 269 return; | 283 return; |
| 270 } | 284 } |
| 271 } | 285 } |
| 272 i++; | 286 i++; |
| 273 } | 287 } |
| 274 | 288 |
| 275 // We did not read a keyword. | 289 // We did not read a keyword. |
| (...skipping 621 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 897 "%c%"PRIxPTR, kPrivateKeySeparator, key_value); | 911 "%c%"PRIxPTR, kPrivateKeySeparator, key_value); |
| 898 const String& result = String::Handle(String::New(private_key)); | 912 const String& result = String::Handle(String::New(private_key)); |
| 899 return result.raw(); | 913 return result.raw(); |
| 900 } | 914 } |
| 901 | 915 |
| 902 | 916 |
| 903 void Scanner::InitOnce() { | 917 void Scanner::InitOnce() { |
| 904 } | 918 } |
| 905 | 919 |
| 906 } // namespace dart | 920 } // namespace dart |
| OLD | NEW |