Chromium Code Reviews| 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() { |
| 18 for (int i = 0; i < Token::numKeywords; i++) { | 19 for (int i = 0; i < Token::numKeywords; i++) { |
| 19 Token::Kind token = static_cast<Token::Kind>(Token::kFirstKeyword + i); | 20 Token::Kind token = static_cast<Token::Kind>(Token::kFirstKeyword + i); |
| 20 keywords_[i].kind = token; | 21 keywords_[i].kind = token; |
| 21 keywords_[i].keyword_chars = Token::Str(token); | 22 keywords_[i].keyword_chars = Token::Str(token); |
| 22 keywords_[i].keyword_len = strlen(Token::Str(token)); | 23 keywords_[i].keyword_len = strlen(Token::Str(token)); |
| 23 keywords_[i].keyword_symbol = NULL; | |
| 24 } | 24 } |
| 25 } | 25 } |
| 26 | 26 |
| 27 | 27 |
| 28 void Scanner::Reset() { | 28 void Scanner::Reset() { |
| 29 lookahead_pos_ = 0; | 29 lookahead_pos_ = 0; |
| 30 token_start_ = 0; | 30 token_start_ = 0; |
| 31 c0_ = source_length_ == 0 ? '\0' : source_.CharAt(0); | 31 c0_ = source_length_ == 0 ? '\0' : source_.CharAt(0); |
| 32 newline_seen_ = false; | 32 newline_seen_ = false; |
| 33 while (saved_context_ != NULL) { | 33 while (saved_context_ != NULL) { |
| (...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 252 while (i < Token::numKeywords && | 252 while (i < Token::numKeywords && |
| 253 keywords_[i].keyword_chars[0] <= ident_char0) { | 253 keywords_[i].keyword_chars[0] <= ident_char0) { |
| 254 if (keywords_[i].keyword_len == ident_length) { | 254 if (keywords_[i].keyword_len == ident_length) { |
| 255 const char* keyword = keywords_[i].keyword_chars; | 255 const char* keyword = keywords_[i].keyword_chars; |
| 256 int char_pos = 0; | 256 int char_pos = 0; |
| 257 while ((char_pos < ident_length) && | 257 while ((char_pos < ident_length) && |
| 258 (keyword[char_pos] == source_.CharAt(ident_pos + char_pos))) { | 258 (keyword[char_pos] == source_.CharAt(ident_pos + char_pos))) { |
| 259 char_pos++; | 259 char_pos++; |
| 260 } | 260 } |
| 261 if (char_pos == ident_length) { | 261 if (char_pos == ident_length) { |
| 262 if (keywords_[i].keyword_symbol == NULL) { | 262 ObjectStore* object_store = Isolate::Current()->object_store(); |
| 263 keywords_[i].keyword_symbol = &String::ZoneHandle( | 263 String& symbol = String::ZoneHandle(); |
|
hausner
2012/02/25 00:41:57
NB: for each keyword occurrence in the source text
siva
2012/02/28 19:57:31
I have redone this code a bit to address the conce
hausner
2012/02/29 00:22:37
Nice, thank you.
On 2012/02/28 19:57:31, asiva wr
| |
| 264 String::NewSymbol(source_, ident_pos, ident_length)); | 264 symbol ^= object_store->GetKeywordSymbol(i); |
| 265 if (symbol.IsNull()) { | |
| 266 symbol = String::NewSymbol(source_, ident_pos, ident_length); | |
| 267 object_store->SetKeywordSymbol(i, symbol); | |
| 265 } | 268 } |
| 266 current_token_.literal = keywords_[i].keyword_symbol; | 269 current_token_.literal = &symbol; |
| 267 current_token_.kind = keywords_[i].kind; | 270 current_token_.kind = keywords_[i].kind; |
| 268 return; | 271 return; |
| 269 } | 272 } |
| 270 } | 273 } |
| 271 i++; | 274 i++; |
| 272 } | 275 } |
| 273 | 276 |
| 274 // We did not read a keyword. | 277 // We did not read a keyword. |
| 275 current_token_.kind = Token::kIDENT; | 278 current_token_.kind = Token::kIDENT; |
| 276 String& literal = | 279 String& literal = |
| (...skipping 619 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 896 "%c%"PRIxPTR, kPrivateKeySeparator, key_value); | 899 "%c%"PRIxPTR, kPrivateKeySeparator, key_value); |
| 897 const String& result = String::Handle(String::New(private_key)); | 900 const String& result = String::Handle(String::New(private_key)); |
| 898 return result.raw(); | 901 return result.raw(); |
| 899 } | 902 } |
| 900 | 903 |
| 901 | 904 |
| 902 void Scanner::InitOnce() { | 905 void Scanner::InitOnce() { |
| 903 } | 906 } |
| 904 | 907 |
| 905 } // namespace dart | 908 } // namespace dart |
| OLD | NEW |