Unify processing of Keywords and predefined symbols in the same loop and add accessors for keyword symbol handles.

R=hausner@google.com

Review URL: https://codereview.chromium.org//1130843002

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@45602 260f80e4-7a28-3924-810f-c04153c831b5
This commit is contained in:
asiva@google.com 2015-05-07 17:28:02 +00:00
parent d0002db5ed
commit b5336c5726
2 changed files with 19 additions and 18 deletions

View file

@ -30,8 +30,8 @@ PREDEFINED_SYMBOLS_LIST(DEFINE_SYMBOL_LITERAL)
"", // matches kKwTableStart.
#define DEFINE_KEYWORD_SYMBOL_INDEX(token, chars, ignore1, ignore2) \
chars,
#define DEFINE_KEYWORD_SYMBOL_INDEX(t, s, p, a) \
s,
DART_KEYWORD_LIST(DEFINE_KEYWORD_SYMBOL_INDEX)
#undef DEFINE_KEYWORD_SYMBOL_INDEX
};
@ -65,23 +65,17 @@ void Symbols::InitOnce(Isolate* isolate) {
// Create all predefined symbols.
ASSERT((sizeof(names) / sizeof(const char*)) == Symbols::kNullCharId);
// First set up all the predefined string symbols.
for (intptr_t i = 1; i < Symbols::kKwTableStart; i++) {
// Set up all the predefined string symbols and create symbols for language
// keywords. We don't expect to find any overlaps between the predefined
// string symbols and the language keywords. If an overlap is introduced
// inadvertantly the ASSERT in AddToVMIsolate while fail.
for (intptr_t i = 1; i < Symbols::kNullCharId; i++) {
String* str = String::ReadOnlyHandle();
*str = OneByteString::New(names[i], Heap::kOld);
AddToVMIsolate(*str);
symbol_handles_[i] = str;
}
// 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++) {
intptr_t idx = (kNullCharId + c);

View file

@ -396,13 +396,13 @@ class Symbols : public AllStatic {
#define DEFINE_SYMBOL_INDEX(symbol, literal) \
k##symbol##Id,
PREDEFINED_SYMBOLS_LIST(DEFINE_SYMBOL_INDEX)
PREDEFINED_SYMBOLS_LIST(DEFINE_SYMBOL_INDEX)
#undef DEFINE_SYMBOL_INDEX
kKwTableStart, // First keyword at kKwTableStart + 1.
#define DEFINE_KEYWORD_SYMBOL_INDEX(token, chars, ignore1, ignore2) \
token##Id,
#define DEFINE_KEYWORD_SYMBOL_INDEX(t, s, p, a) \
t##Id,
DART_KEYWORD_LIST(DEFINE_KEYWORD_SYMBOL_INDEX)
#undef DEFINE_KEYWORD_SYMBOL_INDEX
@ -514,10 +514,17 @@ PREDEFINED_SYMBOLS_LIST(DEFINE_SYMBOL_INDEX)
static const String& True() { return *(symbol_handles_[kTRUEId]); }
static const String& Void() { return *(symbol_handles_[kVOIDId]); }
// Access methods for symbol handles stored in the vm isolate.
// Access methods for symbol handles stored in the vm isolate for predefined
// symbols.
#define DEFINE_SYMBOL_HANDLE_ACCESSOR(symbol, literal) \
static const String& symbol() { return *(symbol_handles_[k##symbol##Id]); }
PREDEFINED_SYMBOLS_LIST(DEFINE_SYMBOL_HANDLE_ACCESSOR)
PREDEFINED_SYMBOLS_LIST(DEFINE_SYMBOL_HANDLE_ACCESSOR)
#undef DEFINE_SYMBOL_HANDLE_ACCESSOR
// Access methods for symbol handles stored in the vm isolate for keywords.
#define DEFINE_SYMBOL_HANDLE_ACCESSOR(t, s, p, a) \
static const String& t() { return *(symbol_handles_[t##Id]); }
DART_KEYWORD_LIST(DEFINE_SYMBOL_HANDLE_ACCESSOR)
#undef DEFINE_SYMBOL_HANDLE_ACCESSOR
// Get symbol for scanner keyword.