Changeset 63423 in webkit for trunk/JavaScriptCore/parser/Lexer.cpp
- Timestamp:
- Jul 15, 2010, 7:10:43 AM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/parser/Lexer.cpp
r63322 r63423 47 47 48 48 49 enum CharacterType s{49 enum CharacterType { 50 50 // Types for the main switch 51 CharacterInvalid, 52 53 CharacterAlpha, 51 52 // The first three types are fixed, and also used for identifying 53 // ASCII alpha and alphanumeric characters (see isIdentStart and isIdentPart). 54 CharacterIdentifierStart, 54 55 CharacterZero, 55 56 CharacterNumber, 56 57 58 CharacterInvalid, 57 59 CharacterLineTerminator, 58 60 CharacterExclamationMark, … … 88 90 }; 89 91 90 // 128 asciicodes91 static unsigned short AsciiCharacters[128] = {92 // 128 ASCII codes 93 static const unsigned short typesOfASCIICharacters[128] = { 92 94 /* 0 - Null */ CharacterInvalid, 93 95 /* 1 - Start of Heading */ CharacterInvalid, … … 126 128 /* 34 - " */ CharacterQuote, 127 129 /* 35 - # */ CharacterInvalid, 128 /* 36 - $ */ Character Alpha,130 /* 36 - $ */ CharacterIdentifierStart, 129 131 /* 37 - % */ CharacterModulo, 130 132 /* 38 - & */ CharacterAnd, … … 155 157 /* 63 - ? */ CharacterQuestion, 156 158 /* 64 - @ */ CharacterInvalid, 157 /* 65 - A */ Character Alpha,158 /* 66 - B */ Character Alpha,159 /* 67 - C */ Character Alpha,160 /* 68 - D */ Character Alpha,161 /* 69 - E */ Character Alpha,162 /* 70 - F */ Character Alpha,163 /* 71 - G */ Character Alpha,164 /* 72 - H */ Character Alpha,165 /* 73 - I */ Character Alpha,166 /* 74 - J */ Character Alpha,167 /* 75 - K */ Character Alpha,168 /* 76 - L */ Character Alpha,169 /* 77 - M */ Character Alpha,170 /* 78 - N */ Character Alpha,171 /* 79 - O */ Character Alpha,172 /* 80 - P */ Character Alpha,173 /* 81 - Q */ Character Alpha,174 /* 82 - R */ Character Alpha,175 /* 83 - S */ Character Alpha,176 /* 84 - T */ Character Alpha,177 /* 85 - U */ Character Alpha,178 /* 86 - V */ Character Alpha,179 /* 87 - W */ Character Alpha,180 /* 88 - X */ Character Alpha,181 /* 89 - Y */ Character Alpha,182 /* 90 - Z */ Character Alpha,159 /* 65 - A */ CharacterIdentifierStart, 160 /* 66 - B */ CharacterIdentifierStart, 161 /* 67 - C */ CharacterIdentifierStart, 162 /* 68 - D */ CharacterIdentifierStart, 163 /* 69 - E */ CharacterIdentifierStart, 164 /* 70 - F */ CharacterIdentifierStart, 165 /* 71 - G */ CharacterIdentifierStart, 166 /* 72 - H */ CharacterIdentifierStart, 167 /* 73 - I */ CharacterIdentifierStart, 168 /* 74 - J */ CharacterIdentifierStart, 169 /* 75 - K */ CharacterIdentifierStart, 170 /* 76 - L */ CharacterIdentifierStart, 171 /* 77 - M */ CharacterIdentifierStart, 172 /* 78 - N */ CharacterIdentifierStart, 173 /* 79 - O */ CharacterIdentifierStart, 174 /* 80 - P */ CharacterIdentifierStart, 175 /* 81 - Q */ CharacterIdentifierStart, 176 /* 82 - R */ CharacterIdentifierStart, 177 /* 83 - S */ CharacterIdentifierStart, 178 /* 84 - T */ CharacterIdentifierStart, 179 /* 85 - U */ CharacterIdentifierStart, 180 /* 86 - V */ CharacterIdentifierStart, 181 /* 87 - W */ CharacterIdentifierStart, 182 /* 88 - X */ CharacterIdentifierStart, 183 /* 89 - Y */ CharacterIdentifierStart, 184 /* 90 - Z */ CharacterIdentifierStart, 183 185 /* 91 - [ */ CharacterOpenBracket, 184 186 /* 92 - \ */ CharacterBackSlash, 185 187 /* 93 - ] */ CharacterCloseBracket, 186 188 /* 94 - ^ */ CharacterXor, 187 /* 95 - _ */ Character Alpha,189 /* 95 - _ */ CharacterIdentifierStart, 188 190 /* 96 - ` */ CharacterInvalid, 189 /* 97 - a */ Character Alpha,190 /* 98 - b */ Character Alpha,191 /* 99 - c */ Character Alpha,192 /* 100 - d */ Character Alpha,193 /* 101 - e */ Character Alpha,194 /* 102 - f */ Character Alpha,195 /* 103 - g */ Character Alpha,196 /* 104 - h */ Character Alpha,197 /* 105 - i */ Character Alpha,198 /* 106 - j */ Character Alpha,199 /* 107 - k */ Character Alpha,200 /* 108 - l */ Character Alpha,201 /* 109 - m */ Character Alpha,202 /* 110 - n */ Character Alpha,203 /* 111 - o */ Character Alpha,204 /* 112 - p */ Character Alpha,205 /* 113 - q */ Character Alpha,206 /* 114 - r */ Character Alpha,207 /* 115 - s */ Character Alpha,208 /* 116 - t */ Character Alpha,209 /* 117 - u */ Character Alpha,210 /* 118 - v */ Character Alpha,211 /* 119 - w */ Character Alpha,212 /* 120 - x */ Character Alpha,213 /* 121 - y */ Character Alpha,214 /* 122 - z */ Character Alpha,191 /* 97 - a */ CharacterIdentifierStart, 192 /* 98 - b */ CharacterIdentifierStart, 193 /* 99 - c */ CharacterIdentifierStart, 194 /* 100 - d */ CharacterIdentifierStart, 195 /* 101 - e */ CharacterIdentifierStart, 196 /* 102 - f */ CharacterIdentifierStart, 197 /* 103 - g */ CharacterIdentifierStart, 198 /* 104 - h */ CharacterIdentifierStart, 199 /* 105 - i */ CharacterIdentifierStart, 200 /* 106 - j */ CharacterIdentifierStart, 201 /* 107 - k */ CharacterIdentifierStart, 202 /* 108 - l */ CharacterIdentifierStart, 203 /* 109 - m */ CharacterIdentifierStart, 204 /* 110 - n */ CharacterIdentifierStart, 205 /* 111 - o */ CharacterIdentifierStart, 206 /* 112 - p */ CharacterIdentifierStart, 207 /* 113 - q */ CharacterIdentifierStart, 208 /* 114 - r */ CharacterIdentifierStart, 209 /* 115 - s */ CharacterIdentifierStart, 210 /* 116 - t */ CharacterIdentifierStart, 211 /* 117 - u */ CharacterIdentifierStart, 212 /* 118 - v */ CharacterIdentifierStart, 213 /* 119 - w */ CharacterIdentifierStart, 214 /* 120 - x */ CharacterIdentifierStart, 215 /* 121 - y */ CharacterIdentifierStart, 216 /* 122 - z */ CharacterIdentifierStart, 215 217 /* 123 - { */ CharacterOpenBrace, 216 218 /* 124 - | */ CharacterOr, … … 336 338 static inline bool isIdentStart(int c) 337 339 { 338 return isASCII(c) ? isASCIIAlpha(c) || c == '$' || c == '_': isNonASCIIIdentStart(c);340 return isASCII(c) ? typesOfASCIICharacters[c] == CharacterIdentifierStart : isNonASCIIIdentStart(c); 339 341 } 340 342 … … 347 349 static inline bool isIdentPart(int c) 348 350 { 349 return isASCII(c) ? isASCIIAlphanumeric(c) || c == '$' || c == '_' : isNonASCIIIdentPart(c); 351 // Character types are divided into two groups depending on whether they can be part of an 352 // identifier or not. Those whose type value is less or equal than CharacterNumber can be 353 // part of an identifier. (See the CharacterType definition for more details.) 354 return isASCII(c) ? typesOfASCIICharacters[c] <= CharacterNumber : isNonASCIIIdentPart(c); 350 355 } 351 356 … … 457 462 stringStart = currentCharacter(); 458 463 continue; 459 } else if (UNLIKELY(((static_cast<unsigned>(m_current) - 0xE) & 0x2000))) { 464 } 465 // Fast check for characters that require special handling. 466 // Catches -1, \n, \r, 0x2028, and 0x2029 as efficiently 467 // as possible, and lets through all common ASCII characters. 468 if (UNLIKELY(((static_cast<unsigned>(m_current) - 0xE) & 0x2000))) { 460 469 // New-line or end of input is not allowed 461 470 if (UNLIKELY(isLineTerminator(m_current)) || UNLIKELY(m_current == -1)) … … 494 503 m_delimited = false; 495 504 496 if (isASCII(m_current)) { 497 ASSERT(m_current >= 0 && m_current < 128); 498 499 switch (AsciiCharacters[m_current]) { 505 CharacterType type; 506 if (LIKELY(isASCII(m_current))) 507 type = static_cast<CharacterType>(typesOfASCIICharacters[m_current]); 508 else if (isNonASCIIIdentStart(m_current)) 509 type = CharacterIdentifierStart; 510 else if (isLineTerminator(m_current)) 511 type = CharacterLineTerminator; 512 else 513 type = CharacterInvalid; 514 515 switch (type) { 500 516 case CharacterGreater: 501 517 shift(); … … 751 767 token = STRING; 752 768 break; 753 case Character Alpha:769 case CharacterIdentifierStart: 754 770 ASSERT(isIdentStart(m_current)); 755 771 goto startIdentifierOrKeyword; … … 770 786 goto returnError; 771 787 } 772 } else {773 // Rare characters774 775 if (isNonASCIIIdentStart(m_current))776 goto startIdentifierOrKeyword;777 if (isLineTerminator(m_current)) {778 shiftLineTerminator();779 m_atLineStart = true;780 m_terminator = true;781 if (lastTokenWasRestrKeyword())782 goto doneSemicolon;783 goto start;784 }785 goto returnError;786 }787 788 788 789 m_atLineStart = false;
Note:
See TracChangeset
for help on using the changeset viewer.