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

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

Issue 11366058: - Prepopulate the keyword symbol table otherwise we can end up (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 1 month 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 | no next file » | no next file with comments »
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/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"
11 #include "vm/symbols.h" 11 #include "vm/symbols.h"
12 #include "vm/thread.h" 12 #include "vm/thread.h"
13 #include "vm/token.h" 13 #include "vm/token.h"
14 14
15 namespace dart { 15 namespace dart {
16 16
17 DEFINE_FLAG(bool, disable_privacy, false, "Disable library privacy."); 17 DEFINE_FLAG(bool, disable_privacy, false, "Disable library privacy.");
18 DEFINE_FLAG(bool, print_tokens, false, "Print scanned tokens."); 18 DEFINE_FLAG(bool, print_tokens, false, "Print scanned tokens.");
19 19
20 void Scanner::InitKeywordTable() { 20 void Scanner::InitKeywordTable() {
21 ObjectStore* object_store = Isolate::Current()->object_store(); 21 ObjectStore* object_store = Isolate::Current()->object_store();
22 keyword_symbol_table_ = object_store->keyword_symbols(); 22 keyword_symbol_table_ = object_store->keyword_symbols();
23 if (keyword_symbol_table_.IsNull()) { 23 if (keyword_symbol_table_.IsNull()) {
24 object_store->InitKeywordTable(); 24 object_store->InitKeywordTable();
hausner 2012/11/02 16:35:18 Looking at this code now I see that ObjectStore::I
25 keyword_symbol_table_ = object_store->keyword_symbols(); 25 keyword_symbol_table_ = object_store->keyword_symbols();
26 ASSERT(!keyword_symbol_table_.IsNull()); 26 ASSERT(!keyword_symbol_table_.IsNull());
27 String& symbol = String::Handle();
28 for (int i = 0; i < Token::numKeywords; i++) {
29 Token::Kind token = static_cast<Token::Kind>(Token::kFirstKeyword + i);
30 symbol = Symbols::New(Token::Str(token));
31 keyword_symbol_table_.SetAt(i, symbol);
32 }
27 } 33 }
28 for (int i = 0; i < Token::numKeywords; i++) { 34 for (int i = 0; i < Token::numKeywords; i++) {
29 Token::Kind token = static_cast<Token::Kind>(Token::kFirstKeyword + i); 35 Token::Kind token = static_cast<Token::Kind>(Token::kFirstKeyword + i);
30 keywords_[i].kind = token; 36 keywords_[i].kind = token;
31 keywords_[i].keyword_chars = Token::Str(token); 37 keywords_[i].keyword_chars = Token::Str(token);
32 keywords_[i].keyword_len = strlen(Token::Str(token)); 38 keywords_[i].keyword_len = strlen(Token::Str(token));
33 keywords_[i].keyword_symbol = NULL; 39 keywords_[i].keyword_symbol = NULL;
34 } 40 }
35 } 41 }
36 42
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after
269 const char* keyword = keywords_[i].keyword_chars; 275 const char* keyword = keywords_[i].keyword_chars;
270 int char_pos = 0; 276 int char_pos = 0;
271 while ((char_pos < ident_length) && 277 while ((char_pos < ident_length) &&
272 (keyword[char_pos] == source_.CharAt(ident_pos + char_pos))) { 278 (keyword[char_pos] == source_.CharAt(ident_pos + char_pos))) {
273 char_pos++; 279 char_pos++;
274 } 280 }
275 if (char_pos == ident_length) { 281 if (char_pos == ident_length) {
276 if (keywords_[i].keyword_symbol == NULL) { 282 if (keywords_[i].keyword_symbol == NULL) {
277 String& symbol = String::ZoneHandle(); 283 String& symbol = String::ZoneHandle();
278 symbol ^= keyword_symbol_table_.At(i); 284 symbol ^= keyword_symbol_table_.At(i);
279 if (symbol.IsNull()) { 285 ASSERT(!symbol.IsNull());
280 symbol = Symbols::New(source_, ident_pos, ident_length);
281 keyword_symbol_table_.SetAt(i, symbol);
282 }
283 keywords_[i].keyword_symbol = &symbol; 286 keywords_[i].keyword_symbol = &symbol;
284 } 287 }
285 current_token_.literal = keywords_[i].keyword_symbol; 288 current_token_.literal = keywords_[i].keyword_symbol;
286 current_token_.kind = keywords_[i].kind; 289 current_token_.kind = keywords_[i].kind;
287 return; 290 return;
288 } 291 }
289 } 292 }
290 i++; 293 i++;
291 } 294 }
292 295
(...skipping 656 matching lines...) Expand 10 before | Expand all | Expand 10 after
949 "%c%#"Px"", kPrivateKeySeparator, key_value); 952 "%c%#"Px"", kPrivateKeySeparator, key_value);
950 const String& result = String::Handle(String::New(private_key, Heap::kOld)); 953 const String& result = String::Handle(String::New(private_key, Heap::kOld));
951 return result.raw(); 954 return result.raw();
952 } 955 }
953 956
954 957
955 void Scanner::InitOnce() { 958 void Scanner::InitOnce() {
956 } 959 }
957 960
958 } // namespace dart 961 } // namespace dart
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698