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

Unified Diff: runtime/vm/symbols.cc

Issue 72923002: Add Dart keyword symbols to the VM isolate (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 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 side-by-side diff with in-line comments
Download patch
« runtime/vm/object_store.h ('K') | « runtime/vm/symbols.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
« runtime/vm/object_store.h ('K') | « runtime/vm/symbols.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698