Index: runtime/vm/symbols.cc |
=================================================================== |
--- runtime/vm/symbols.cc (revision 30276) |
+++ runtime/vm/symbols.cc (working copy) |
@@ -26,6 +26,13 @@ |
literal, |
PREDEFINED_SYMBOLS_LIST(DEFINE_SYMBOL_LITERAL) |
#undef DEFINE_SYMBOL_LITERAL |
+ |
+ "", // matches kKwTableStart. |
+ |
+#define DEFINE_KEYWORD_SYMBOL_INDEX(token, chars, ignore1, ignore2) \ |
+ chars, |
+ DART_KEYWORD_LIST(DEFINE_KEYWORD_SYMBOL_INDEX) |
+#undef DEFINE_KEYWORD_SYMBOL_INDEX |
}; |
intptr_t Symbols::num_of_grows_; |
@@ -40,6 +47,16 @@ |
} |
+const String& Symbols::Keyword(Token::Kind keyword) { |
+ const int kw_index = keyword - Token::kFirstKeyword; |
+ ASSERT((0 <= kw_index) && (kw_index < Token::numKeywords)); |
+ ASSERT(Token::kABSTRACT == Token::kFirstKeyword); |
+ const intptr_t keyword_id = Symbols::kABSTRACTId + kw_index; |
Ivan Posva
2013/11/14 19:37:57
This should all be based on kKwTableStart if I am
hausner
2013/11/14 19:41:43
Yes. The kABSTRACTId is a left-over from before I
|
+ ASSERT(symbol_handles_[keyword_id] != NULL); |
+ return *symbol_handles_[keyword_id]; |
+} |
+ |
+ |
void Symbols::InitOnce(Isolate* isolate) { |
// Should only be run by the vm isolate. |
ASSERT(isolate == Dart::vm_isolate()); |
@@ -61,7 +78,7 @@ |
// First set up all the predefined string symbols. |
- for (intptr_t i = 1; i < Symbols::kNullCharId; i++) { |
+ for (intptr_t i = 1; i < Symbols::kKwTableStart; i++) { |
// The symbol_table needs to be reloaded as it might have grown in the |
// previous iteration. |
symbol_table = object_store->symbol_table(); |
@@ -72,6 +89,15 @@ |
} |
Object::RegisterSingletonClassNames(); |
+ // Create symbols for language keywords. Some keywords are equal to |
+ // symbols we already created, so use New() instead of Add() to ensure |
+ // that the symbols are canonicalized. |
+ for (intptr_t i = Symbols::kKwTableStart; i < Symbols::kNullCharId; i++) { |
+ String* str = String::ReadOnlyHandle(); |
+ *str = New(names[i]); |
+ symbol_handles_[i] = str; |
+ } |
+ |
// Add Latin1 characters as Symbols, so that Symbols::FromCharCode is fast. |
for (intptr_t c = 0; c < kNumberOfOneCharCodeSymbols; c++) { |
// The symbol_table needs to be reloaded as it might have grown in the |