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/symbols.h" | 5 #include "vm/symbols.h" |
6 | 6 |
7 #include "vm/handles.h" | 7 #include "vm/handles.h" |
8 #include "vm/handles_impl.h" | 8 #include "vm/handles_impl.h" |
9 #include "vm/hash_table.h" | 9 #include "vm/hash_table.h" |
10 #include "vm/isolate.h" | 10 #include "vm/isolate.h" |
(...skipping 12 matching lines...) Expand all Loading... |
23 static const char* names[] = { | 23 static const char* names[] = { |
24 NULL, | 24 NULL, |
25 | 25 |
26 #define DEFINE_SYMBOL_LITERAL(symbol, literal) \ | 26 #define DEFINE_SYMBOL_LITERAL(symbol, literal) \ |
27 literal, | 27 literal, |
28 PREDEFINED_SYMBOLS_LIST(DEFINE_SYMBOL_LITERAL) | 28 PREDEFINED_SYMBOLS_LIST(DEFINE_SYMBOL_LITERAL) |
29 #undef DEFINE_SYMBOL_LITERAL | 29 #undef DEFINE_SYMBOL_LITERAL |
30 | 30 |
31 "", // matches kKwTableStart. | 31 "", // matches kKwTableStart. |
32 | 32 |
33 #define DEFINE_KEYWORD_SYMBOL_INDEX(token, chars, ignore1, ignore2) \ | 33 #define DEFINE_KEYWORD_SYMBOL_INDEX(t, s, p, a) \ |
34 chars, | 34 s, |
35 DART_KEYWORD_LIST(DEFINE_KEYWORD_SYMBOL_INDEX) | 35 DART_KEYWORD_LIST(DEFINE_KEYWORD_SYMBOL_INDEX) |
36 #undef DEFINE_KEYWORD_SYMBOL_INDEX | 36 #undef DEFINE_KEYWORD_SYMBOL_INDEX |
37 }; | 37 }; |
38 | 38 |
39 DEFINE_FLAG(bool, dump_symbol_stats, false, "Dump symbol table statistics"); | 39 DEFINE_FLAG(bool, dump_symbol_stats, false, "Dump symbol table statistics"); |
40 | 40 |
41 | 41 |
42 const char* Symbols::Name(SymbolId symbol) { | 42 const char* Symbols::Name(SymbolId symbol) { |
43 ASSERT((symbol > kIllegal) && (symbol < kNullCharId)); | 43 ASSERT((symbol > kIllegal) && (symbol < kNullCharId)); |
44 return names[symbol]; | 44 return names[symbol]; |
(...skipping 13 matching lines...) Expand all Loading... |
58 void Symbols::InitOnce(Isolate* isolate) { | 58 void Symbols::InitOnce(Isolate* isolate) { |
59 // Should only be run by the vm isolate. | 59 // Should only be run by the vm isolate. |
60 ASSERT(isolate == Dart::vm_isolate()); | 60 ASSERT(isolate == Dart::vm_isolate()); |
61 | 61 |
62 // Create and setup a symbol table in the vm isolate. | 62 // Create and setup a symbol table in the vm isolate. |
63 SetupSymbolTable(isolate); | 63 SetupSymbolTable(isolate); |
64 | 64 |
65 // Create all predefined symbols. | 65 // Create all predefined symbols. |
66 ASSERT((sizeof(names) / sizeof(const char*)) == Symbols::kNullCharId); | 66 ASSERT((sizeof(names) / sizeof(const char*)) == Symbols::kNullCharId); |
67 | 67 |
68 // First set up all the predefined string symbols. | 68 // Set up all the predefined string symbols and create symbols for language |
69 for (intptr_t i = 1; i < Symbols::kKwTableStart; i++) { | 69 // keywords. We don't expect to find any overlaps between the predefined |
| 70 // string symbols and the language keywords. If an overlap is introduced |
| 71 // inadvertantly the ASSERT in AddToVMIsolate while fail. |
| 72 for (intptr_t i = 1; i < Symbols::kNullCharId; i++) { |
70 String* str = String::ReadOnlyHandle(); | 73 String* str = String::ReadOnlyHandle(); |
71 *str = OneByteString::New(names[i], Heap::kOld); | 74 *str = OneByteString::New(names[i], Heap::kOld); |
72 AddToVMIsolate(*str); | 75 AddToVMIsolate(*str); |
73 symbol_handles_[i] = str; | 76 symbol_handles_[i] = str; |
74 } | 77 } |
75 | 78 |
76 // Create symbols for language keywords. Some keywords are equal to | |
77 // symbols we already created, so use New() instead of Add() to ensure | |
78 // that the symbols are canonicalized. | |
79 for (intptr_t i = Symbols::kKwTableStart; i < Symbols::kNullCharId; i++) { | |
80 String* str = String::ReadOnlyHandle(); | |
81 *str = New(names[i]); | |
82 symbol_handles_[i] = str; | |
83 } | |
84 | |
85 // Add Latin1 characters as Symbols, so that Symbols::FromCharCode is fast. | 79 // Add Latin1 characters as Symbols, so that Symbols::FromCharCode is fast. |
86 for (intptr_t c = 0; c < kNumberOfOneCharCodeSymbols; c++) { | 80 for (intptr_t c = 0; c < kNumberOfOneCharCodeSymbols; c++) { |
87 intptr_t idx = (kNullCharId + c); | 81 intptr_t idx = (kNullCharId + c); |
88 ASSERT(idx < kMaxPredefinedId); | 82 ASSERT(idx < kMaxPredefinedId); |
89 ASSERT(Utf::IsLatin1(c)); | 83 ASSERT(Utf::IsLatin1(c)); |
90 uint8_t ch = static_cast<uint8_t>(c); | 84 uint8_t ch = static_cast<uint8_t>(c); |
91 String* str = String::ReadOnlyHandle(); | 85 String* str = String::ReadOnlyHandle(); |
92 *str = OneByteString::New(&ch, 1, Heap::kOld); | 86 *str = OneByteString::New(&ch, 1, Heap::kOld); |
93 AddToVMIsolate(*str); | 87 AddToVMIsolate(*str); |
94 predefined_[c] = str->raw(); | 88 predefined_[c] = str->raw(); |
(...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
389 RawObject* Symbols::GetVMSymbol(intptr_t object_id) { | 383 RawObject* Symbols::GetVMSymbol(intptr_t object_id) { |
390 ASSERT(IsVMSymbolId(object_id)); | 384 ASSERT(IsVMSymbolId(object_id)); |
391 intptr_t i = (object_id - kMaxPredefinedObjectIds); | 385 intptr_t i = (object_id - kMaxPredefinedObjectIds); |
392 if ((i > kIllegal) && (i < Symbols::kMaxPredefinedId)) { | 386 if ((i > kIllegal) && (i < Symbols::kMaxPredefinedId)) { |
393 return symbol_handles_[i]->raw(); | 387 return symbol_handles_[i]->raw(); |
394 } | 388 } |
395 return Object::null(); | 389 return Object::null(); |
396 } | 390 } |
397 | 391 |
398 } // namespace dart | 392 } // namespace dart |
OLD | NEW |