Changeset 109769 in webkit for trunk/Source/JavaScriptCore/parser/Lexer.cpp
- Timestamp:
- Mar 5, 2012, 10:56:29 AM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/JavaScriptCore/parser/Lexer.cpp
r108841 r109769 96 96 }; 97 97 98 // 128 ASCIIcodes99 static const unsigned short typesOf ASCIICharacters[128] = {98 // 256 Latin-1 codes 99 static const unsigned short typesOfLatin1Characters[256] = { 100 100 /* 0 - Null */ CharacterInvalid, 101 101 /* 1 - Start of Heading */ CharacterInvalid, … … 226 226 /* 126 - ~ */ CharacterTilde, 227 227 /* 127 - Delete */ CharacterInvalid, 228 /* 128 - Cc category */ CharacterInvalid, 229 /* 129 - Cc category */ CharacterInvalid, 230 /* 130 - Cc category */ CharacterInvalid, 231 /* 131 - Cc category */ CharacterInvalid, 232 /* 132 - Cc category */ CharacterInvalid, 233 /* 133 - Cc category */ CharacterInvalid, 234 /* 134 - Cc category */ CharacterInvalid, 235 /* 135 - Cc category */ CharacterInvalid, 236 /* 136 - Cc category */ CharacterInvalid, 237 /* 137 - Cc category */ CharacterInvalid, 238 /* 138 - Cc category */ CharacterInvalid, 239 /* 139 - Cc category */ CharacterInvalid, 240 /* 140 - Cc category */ CharacterInvalid, 241 /* 141 - Cc category */ CharacterInvalid, 242 /* 142 - Cc category */ CharacterInvalid, 243 /* 143 - Cc category */ CharacterInvalid, 244 /* 144 - Cc category */ CharacterInvalid, 245 /* 145 - Cc category */ CharacterInvalid, 246 /* 146 - Cc category */ CharacterInvalid, 247 /* 147 - Cc category */ CharacterInvalid, 248 /* 148 - Cc category */ CharacterInvalid, 249 /* 149 - Cc category */ CharacterInvalid, 250 /* 150 - Cc category */ CharacterInvalid, 251 /* 151 - Cc category */ CharacterInvalid, 252 /* 152 - Cc category */ CharacterInvalid, 253 /* 153 - Cc category */ CharacterInvalid, 254 /* 154 - Cc category */ CharacterInvalid, 255 /* 155 - Cc category */ CharacterInvalid, 256 /* 156 - Cc category */ CharacterInvalid, 257 /* 157 - Cc category */ CharacterInvalid, 258 /* 158 - Cc category */ CharacterInvalid, 259 /* 159 - Cc category */ CharacterInvalid, 260 /* 160 - Zs category (nbsp) */ CharacterWhiteSpace, 261 /* 161 - Po category */ CharacterInvalid, 262 /* 162 - Sc category */ CharacterInvalid, 263 /* 163 - Sc category */ CharacterInvalid, 264 /* 164 - Sc category */ CharacterInvalid, 265 /* 165 - Sc category */ CharacterInvalid, 266 /* 166 - So category */ CharacterInvalid, 267 /* 167 - So category */ CharacterInvalid, 268 /* 168 - Sk category */ CharacterInvalid, 269 /* 169 - So category */ CharacterInvalid, 270 /* 170 - Ll category */ CharacterIdentifierStart, 271 /* 171 - Pi category */ CharacterInvalid, 272 /* 172 - Sm category */ CharacterInvalid, 273 /* 173 - Cf category */ CharacterInvalid, 274 /* 174 - So category */ CharacterInvalid, 275 /* 175 - Sk category */ CharacterInvalid, 276 /* 176 - So category */ CharacterInvalid, 277 /* 177 - Sm category */ CharacterInvalid, 278 /* 178 - No category */ CharacterInvalid, 279 /* 179 - No category */ CharacterInvalid, 280 /* 180 - Sk category */ CharacterInvalid, 281 /* 181 - Ll category */ CharacterIdentifierStart, 282 /* 182 - So category */ CharacterInvalid, 283 /* 183 - Po category */ CharacterInvalid, 284 /* 184 - Sk category */ CharacterInvalid, 285 /* 185 - No category */ CharacterInvalid, 286 /* 186 - Ll category */ CharacterIdentifierStart, 287 /* 187 - Pf category */ CharacterInvalid, 288 /* 188 - No category */ CharacterInvalid, 289 /* 189 - No category */ CharacterInvalid, 290 /* 190 - No category */ CharacterInvalid, 291 /* 191 - Po category */ CharacterInvalid, 292 /* 192 - Lu category */ CharacterIdentifierStart, 293 /* 193 - Lu category */ CharacterIdentifierStart, 294 /* 194 - Lu category */ CharacterIdentifierStart, 295 /* 195 - Lu category */ CharacterIdentifierStart, 296 /* 196 - Lu category */ CharacterIdentifierStart, 297 /* 197 - Lu category */ CharacterIdentifierStart, 298 /* 198 - Lu category */ CharacterIdentifierStart, 299 /* 199 - Lu category */ CharacterIdentifierStart, 300 /* 200 - Lu category */ CharacterIdentifierStart, 301 /* 201 - Lu category */ CharacterIdentifierStart, 302 /* 202 - Lu category */ CharacterIdentifierStart, 303 /* 203 - Lu category */ CharacterIdentifierStart, 304 /* 204 - Lu category */ CharacterIdentifierStart, 305 /* 205 - Lu category */ CharacterIdentifierStart, 306 /* 206 - Lu category */ CharacterIdentifierStart, 307 /* 207 - Lu category */ CharacterIdentifierStart, 308 /* 208 - Lu category */ CharacterIdentifierStart, 309 /* 209 - Lu category */ CharacterIdentifierStart, 310 /* 210 - Lu category */ CharacterIdentifierStart, 311 /* 211 - Lu category */ CharacterIdentifierStart, 312 /* 212 - Lu category */ CharacterIdentifierStart, 313 /* 213 - Lu category */ CharacterIdentifierStart, 314 /* 214 - Lu category */ CharacterIdentifierStart, 315 /* 215 - Sm category */ CharacterInvalid, 316 /* 216 - Lu category */ CharacterIdentifierStart, 317 /* 217 - Lu category */ CharacterIdentifierStart, 318 /* 218 - Lu category */ CharacterIdentifierStart, 319 /* 219 - Lu category */ CharacterIdentifierStart, 320 /* 220 - Lu category */ CharacterIdentifierStart, 321 /* 221 - Lu category */ CharacterIdentifierStart, 322 /* 222 - Lu category */ CharacterIdentifierStart, 323 /* 223 - Ll category */ CharacterIdentifierStart, 324 /* 224 - Ll category */ CharacterIdentifierStart, 325 /* 225 - Ll category */ CharacterIdentifierStart, 326 /* 226 - Ll category */ CharacterIdentifierStart, 327 /* 227 - Ll category */ CharacterIdentifierStart, 328 /* 228 - Ll category */ CharacterIdentifierStart, 329 /* 229 - Ll category */ CharacterIdentifierStart, 330 /* 230 - Ll category */ CharacterIdentifierStart, 331 /* 231 - Ll category */ CharacterIdentifierStart, 332 /* 232 - Ll category */ CharacterIdentifierStart, 333 /* 233 - Ll category */ CharacterIdentifierStart, 334 /* 234 - Ll category */ CharacterIdentifierStart, 335 /* 235 - Ll category */ CharacterIdentifierStart, 336 /* 236 - Ll category */ CharacterIdentifierStart, 337 /* 237 - Ll category */ CharacterIdentifierStart, 338 /* 238 - Ll category */ CharacterIdentifierStart, 339 /* 239 - Ll category */ CharacterIdentifierStart, 340 /* 240 - Ll category */ CharacterIdentifierStart, 341 /* 241 - Ll category */ CharacterIdentifierStart, 342 /* 242 - Ll category */ CharacterIdentifierStart, 343 /* 243 - Ll category */ CharacterIdentifierStart, 344 /* 244 - Ll category */ CharacterIdentifierStart, 345 /* 245 - Ll category */ CharacterIdentifierStart, 346 /* 246 - Ll category */ CharacterIdentifierStart, 347 /* 247 - Sm category */ CharacterInvalid, 348 /* 248 - Ll category */ CharacterIdentifierStart, 349 /* 249 - Ll category */ CharacterIdentifierStart, 350 /* 250 - Ll category */ CharacterIdentifierStart, 351 /* 251 - Ll category */ CharacterIdentifierStart, 352 /* 252 - Ll category */ CharacterIdentifierStart, 353 /* 253 - Ll category */ CharacterIdentifierStart, 354 /* 254 - Ll category */ CharacterIdentifierStart, 355 /* 255 - Ll category */ CharacterIdentifierStart 228 356 }; 229 357 … … 351 479 void Lexer<T>::shiftLineTerminator() 352 480 { 353 ASSERT(isLineTerminator( m_current));481 ASSERT(isLineTerminator(static_cast<T>(m_current))); 354 482 355 483 int m_prev = m_current; … … 369 497 } 370 498 371 static NEVER_INLINE bool isNon ASCIIIdentStart(int c)499 static NEVER_INLINE bool isNonLatin1IdentStart(int c) 372 500 { 373 501 return category(c) & (Letter_Uppercase | Letter_Lowercase | Letter_Titlecase | Letter_Modifier | Letter_Other); 374 502 } 375 503 376 static inline bool isIdentStart(int c) 377 { 378 return isASCII(c) ? typesOfASCIICharacters[c] == CharacterIdentifierStart : isNonASCIIIdentStart(c); 379 } 380 381 static NEVER_INLINE bool isNonASCIIIdentPart(int c) 504 static ALWAYS_INLINE bool isLatin1(LChar) 505 { 506 return true; 507 } 508 509 static ALWAYS_INLINE bool isLatin1(UChar c) 510 { 511 return c < 256; 512 } 513 514 static inline bool isIdentStart(LChar c) 515 { 516 return typesOfLatin1Characters[c] == CharacterIdentifierStart; 517 } 518 519 static inline bool isIdentStart(UChar c) 520 { 521 return isLatin1(c) ? isIdentStart(static_cast<LChar>(c)) : isNonLatin1IdentStart(c); 522 } 523 524 static NEVER_INLINE bool isNonLatin1IdentPart(int c) 382 525 { 383 526 return (category(c) & (Letter_Uppercase | Letter_Lowercase | Letter_Titlecase | Letter_Modifier | Letter_Other … … 385 528 } 386 529 387 static ALWAYS_INLINE bool isIdentPart( intc)530 static ALWAYS_INLINE bool isIdentPart(LChar c) 388 531 { 389 532 // Character types are divided into two groups depending on whether they can be part of an 390 533 // identifier or not. Those whose type value is less or equal than CharacterNumber can be 391 534 // part of an identifier. (See the CharacterType definition for more details.) 392 return isASCII(c) ? typesOfASCIICharacters[c] <= CharacterNumber : isNonASCIIIdentPart(c); 535 return typesOfLatin1Characters[c] <= CharacterNumber; 536 } 537 538 static ALWAYS_INLINE bool isIdentPart(UChar c) 539 { 540 return isLatin1(c) ? isIdentPart(static_cast<LChar>(c)) : isNonLatin1IdentPart(c); 393 541 } 394 542 … … 500 648 const LChar* identifierStart = currentCharacter(); 501 649 502 while ( isIdentPart(m_current))650 while (m_current != -1 && isIdentPart(static_cast<LChar>(m_current))) 503 651 shift(); 504 652 … … 551 699 UChar orAllChars = 0; 552 700 553 while ( isIdentPart(m_current)) {701 while (m_current != -1 && isIdentPart(static_cast<UChar>(m_current))) { 554 702 orAllChars |= m_current; 555 703 shift(); … … 605 753 606 754 while (true) { 607 if (LIKELY( isIdentPart(m_current))) {755 if (LIKELY(m_current != -1 && isIdentPart(static_cast<T>(m_current)))) { 608 756 shift(); 609 757 continue; … … 623 771 if (UNLIKELY(character == -1)) 624 772 return ERRORTOK; 625 if (UNLIKELY(m_buffer16.size() ? !isIdentPart(character) : !isIdentStart(character))) 773 UChar ucharacter = static_cast<UChar>(character); 774 if (UNLIKELY(m_buffer16.size() ? !isIdentPart(ucharacter) : !isIdentStart(ucharacter))) 626 775 return ERRORTOK; 627 776 if (shouldCreateIdentifier) 628 record16( character);777 record16(ucharacter); 629 778 identifierStart = currentCharacter(); 630 779 } … … 754 903 record16(escape); 755 904 shift(); 756 } else if (UNLIKELY(isLineTerminator( m_current)))905 } else if (UNLIKELY(isLineTerminator(static_cast<T>(m_current)))) 757 906 shiftLineTerminator(); 758 907 else if (m_current == 'x') { … … 827 976 if (UNLIKELY(((static_cast<unsigned>(m_current) - 0xE) & 0x2000))) { 828 977 // New-line or end of input is not allowed 829 if (UNLIKELY( isLineTerminator(m_current)) || UNLIKELY(m_current == -1)) {978 if (UNLIKELY(m_current == -1) || UNLIKELY(isLineTerminator(static_cast<T>(m_current)))) { 830 979 m_lexErrorMessage = "Unexpected EOF"; 831 980 return false; … … 1007 1156 return false; 1008 1157 1009 if (isLineTerminator( m_current)) {1158 if (isLineTerminator(static_cast<T>(m_current))) { 1010 1159 shiftLineTerminator(); 1011 1160 m_terminator = true; … … 1036 1185 1037 1186 start: 1038 while ( isWhiteSpace(m_current))1187 while (m_current != -1 && isWhiteSpace(static_cast<T>(m_current))) 1039 1188 shift(); 1040 1189 … … 1047 1196 1048 1197 CharacterType type; 1049 if (LIKELY(is ASCII(m_current)))1050 type = static_cast<CharacterType>(typesOf ASCIICharacters[m_current]);1051 else if (isNon ASCIIIdentStart(m_current))1198 if (LIKELY(isLatin1(static_cast<T>(m_current)))) 1199 type = static_cast<CharacterType>(typesOfLatin1Characters[m_current]); 1200 else if (isNonLatin1IdentStart(m_current)) 1052 1201 type = CharacterIdentifierStart; 1053 else if (isLineTerminator( m_current))1202 else if (isLineTerminator(static_cast<T>(m_current))) 1054 1203 type = CharacterLineTerminator; 1055 1204 else … … 1338 1487 1339 1488 // No identifiers allowed directly after numeric literal, e.g. "3in" is bad. 1340 if (UNLIKELY( isIdentStart(m_current))) {1489 if (UNLIKELY(m_current != -1 && isIdentStart(static_cast<T>(m_current)))) { 1341 1490 m_lexErrorMessage = "At least one digit must occur after a decimal point"; 1342 1491 goto returnError; … … 1358 1507 break; 1359 1508 case CharacterIdentifierStart: 1360 ASSERT(isIdentStart( m_current));1509 ASSERT(isIdentStart(static_cast<T>(m_current))); 1361 1510 // Fall through into CharacterBackSlash. 1362 1511 case CharacterBackSlash: … … 1367 1516 break; 1368 1517 case CharacterLineTerminator: 1369 ASSERT(isLineTerminator( m_current));1518 ASSERT(isLineTerminator(static_cast<T>(m_current))); 1370 1519 shiftLineTerminator(); 1371 1520 m_atLineStart = true; … … 1385 1534 1386 1535 inSingleLineComment: 1387 while (!isLineTerminator( m_current)) {1536 while (!isLineTerminator(static_cast<T>(m_current))) { 1388 1537 if (UNLIKELY(m_current == -1)) 1389 1538 return EOFTOK; … … 1433 1582 int current = m_current; 1434 1583 1435 if (isLineTerminator( current) || current == -1) {1584 if (isLineTerminator(static_cast<T>(current)) || current == -1) { 1436 1585 m_buffer16.resize(0); 1437 1586 return false; … … 1466 1615 m_buffer16.resize(0); 1467 1616 1468 while ( isIdentPart(m_current)) {1617 while (m_current != -1 && isIdentPart(static_cast<T>(m_current))) { 1469 1618 record16(m_current); 1470 1619 shift(); … … 1486 1635 int current = m_current; 1487 1636 1488 if (isLineTerminator( current) || current == -1)1637 if (isLineTerminator(static_cast<T>(current)) || current == -1) 1489 1638 return false; 1490 1639 … … 1512 1661 } 1513 1662 1514 while ( isIdentPart(m_current))1663 while (m_current != -1 && isIdentPart(static_cast<T>(m_current))) 1515 1664 shift(); 1516 1665
Note:
See TracChangeset
for help on using the changeset viewer.