| OLD | NEW |
| 1 // Copyright 2010 the V8 project authors. All rights reserved. | 1 // Copyright 2010 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 177 ASSERT(pos_ >= Scanner::kCharacterLookaheadBufferSize); | 177 ASSERT(pos_ >= Scanner::kCharacterLookaheadBufferSize); |
| 178 ASSERT(raw_data_[pos_ - Scanner::kCharacterLookaheadBufferSize] == ch); | 178 ASSERT(raw_data_[pos_ - Scanner::kCharacterLookaheadBufferSize] == ch); |
| 179 } | 179 } |
| 180 | 180 |
| 181 | 181 |
| 182 template <typename StringType, typename CharType> | 182 template <typename StringType, typename CharType> |
| 183 void ExternalStringUTF16Buffer<StringType, CharType>::SeekForward(int pos) { | 183 void ExternalStringUTF16Buffer<StringType, CharType>::SeekForward(int pos) { |
| 184 pos_ = pos; | 184 pos_ = pos; |
| 185 } | 185 } |
| 186 | 186 |
| 187 | |
| 188 // ---------------------------------------------------------------------------- | |
| 189 // Keyword Matcher | |
| 190 | |
| 191 KeywordMatcher::FirstState KeywordMatcher::first_states_[] = { | |
| 192 { "break", KEYWORD_PREFIX, Token::BREAK }, | |
| 193 { NULL, C, Token::ILLEGAL }, | |
| 194 { NULL, D, Token::ILLEGAL }, | |
| 195 { "else", KEYWORD_PREFIX, Token::ELSE }, | |
| 196 { NULL, F, Token::ILLEGAL }, | |
| 197 { NULL, UNMATCHABLE, Token::ILLEGAL }, | |
| 198 { NULL, UNMATCHABLE, Token::ILLEGAL }, | |
| 199 { NULL, I, Token::ILLEGAL }, | |
| 200 { NULL, UNMATCHABLE, Token::ILLEGAL }, | |
| 201 { NULL, UNMATCHABLE, Token::ILLEGAL }, | |
| 202 { NULL, UNMATCHABLE, Token::ILLEGAL }, | |
| 203 { NULL, UNMATCHABLE, Token::ILLEGAL }, | |
| 204 { NULL, N, Token::ILLEGAL }, | |
| 205 { NULL, UNMATCHABLE, Token::ILLEGAL }, | |
| 206 { NULL, UNMATCHABLE, Token::ILLEGAL }, | |
| 207 { NULL, UNMATCHABLE, Token::ILLEGAL }, | |
| 208 { "return", KEYWORD_PREFIX, Token::RETURN }, | |
| 209 { "switch", KEYWORD_PREFIX, Token::SWITCH }, | |
| 210 { NULL, T, Token::ILLEGAL }, | |
| 211 { NULL, UNMATCHABLE, Token::ILLEGAL }, | |
| 212 { NULL, V, Token::ILLEGAL }, | |
| 213 { NULL, W, Token::ILLEGAL } | |
| 214 }; | |
| 215 | |
| 216 | |
| 217 void KeywordMatcher::Step(uc32 input) { | |
| 218 switch (state_) { | |
| 219 case INITIAL: { | |
| 220 // matching the first character is the only state with significant fanout. | |
| 221 // Match only lower-case letters in range 'b'..'w'. | |
| 222 unsigned int offset = input - kFirstCharRangeMin; | |
| 223 if (offset < kFirstCharRangeLength) { | |
| 224 state_ = first_states_[offset].state; | |
| 225 if (state_ == KEYWORD_PREFIX) { | |
| 226 keyword_ = first_states_[offset].keyword; | |
| 227 counter_ = 1; | |
| 228 keyword_token_ = first_states_[offset].token; | |
| 229 } | |
| 230 return; | |
| 231 } | |
| 232 break; | |
| 233 } | |
| 234 case KEYWORD_PREFIX: | |
| 235 if (keyword_[counter_] == input) { | |
| 236 ASSERT_NE(input, '\0'); | |
| 237 counter_++; | |
| 238 if (keyword_[counter_] == '\0') { | |
| 239 state_ = KEYWORD_MATCHED; | |
| 240 token_ = keyword_token_; | |
| 241 } | |
| 242 return; | |
| 243 } | |
| 244 break; | |
| 245 case KEYWORD_MATCHED: | |
| 246 token_ = Token::IDENTIFIER; | |
| 247 break; | |
| 248 case C: | |
| 249 if (MatchState(input, 'a', CA)) return; | |
| 250 if (MatchState(input, 'o', CO)) return; | |
| 251 break; | |
| 252 case CA: | |
| 253 if (MatchKeywordStart(input, "case", 2, Token::CASE)) return; | |
| 254 if (MatchKeywordStart(input, "catch", 2, Token::CATCH)) return; | |
| 255 break; | |
| 256 case CO: | |
| 257 if (MatchState(input, 'n', CON)) return; | |
| 258 break; | |
| 259 case CON: | |
| 260 if (MatchKeywordStart(input, "const", 3, Token::CONST)) return; | |
| 261 if (MatchKeywordStart(input, "continue", 3, Token::CONTINUE)) return; | |
| 262 break; | |
| 263 case D: | |
| 264 if (MatchState(input, 'e', DE)) return; | |
| 265 if (MatchKeyword(input, 'o', KEYWORD_MATCHED, Token::DO)) return; | |
| 266 break; | |
| 267 case DE: | |
| 268 if (MatchKeywordStart(input, "debugger", 2, Token::DEBUGGER)) return; | |
| 269 if (MatchKeywordStart(input, "default", 2, Token::DEFAULT)) return; | |
| 270 if (MatchKeywordStart(input, "delete", 2, Token::DELETE)) return; | |
| 271 break; | |
| 272 case F: | |
| 273 if (MatchKeywordStart(input, "false", 1, Token::FALSE_LITERAL)) return; | |
| 274 if (MatchKeywordStart(input, "finally", 1, Token::FINALLY)) return; | |
| 275 if (MatchKeywordStart(input, "for", 1, Token::FOR)) return; | |
| 276 if (MatchKeywordStart(input, "function", 1, Token::FUNCTION)) return; | |
| 277 break; | |
| 278 case I: | |
| 279 if (MatchKeyword(input, 'f', KEYWORD_MATCHED, Token::IF)) return; | |
| 280 if (MatchKeyword(input, 'n', IN, Token::IN)) return; | |
| 281 break; | |
| 282 case IN: | |
| 283 token_ = Token::IDENTIFIER; | |
| 284 if (MatchKeywordStart(input, "instanceof", 2, Token::INSTANCEOF)) { | |
| 285 return; | |
| 286 } | |
| 287 break; | |
| 288 case N: | |
| 289 if (MatchKeywordStart(input, "native", 1, Token::NATIVE)) return; | |
| 290 if (MatchKeywordStart(input, "new", 1, Token::NEW)) return; | |
| 291 if (MatchKeywordStart(input, "null", 1, Token::NULL_LITERAL)) return; | |
| 292 break; | |
| 293 case T: | |
| 294 if (MatchState(input, 'h', TH)) return; | |
| 295 if (MatchState(input, 'r', TR)) return; | |
| 296 if (MatchKeywordStart(input, "typeof", 1, Token::TYPEOF)) return; | |
| 297 break; | |
| 298 case TH: | |
| 299 if (MatchKeywordStart(input, "this", 2, Token::THIS)) return; | |
| 300 if (MatchKeywordStart(input, "throw", 2, Token::THROW)) return; | |
| 301 break; | |
| 302 case TR: | |
| 303 if (MatchKeywordStart(input, "true", 2, Token::TRUE_LITERAL)) return; | |
| 304 if (MatchKeyword(input, 'y', KEYWORD_MATCHED, Token::TRY)) return; | |
| 305 break; | |
| 306 case V: | |
| 307 if (MatchKeywordStart(input, "var", 1, Token::VAR)) return; | |
| 308 if (MatchKeywordStart(input, "void", 1, Token::VOID)) return; | |
| 309 break; | |
| 310 case W: | |
| 311 if (MatchKeywordStart(input, "while", 1, Token::WHILE)) return; | |
| 312 if (MatchKeywordStart(input, "with", 1, Token::WITH)) return; | |
| 313 break; | |
| 314 default: | |
| 315 UNREACHABLE(); | |
| 316 } | |
| 317 // On fallthrough, it's a failure. | |
| 318 state_ = UNMATCHABLE; | |
| 319 } | |
| 320 | |
| 321 | |
| 322 | |
| 323 // ---------------------------------------------------------------------------- | 187 // ---------------------------------------------------------------------------- |
| 324 // Scanner::LiteralScope | 188 // Scanner::LiteralScope |
| 325 | 189 |
| 326 Scanner::LiteralScope::LiteralScope(Scanner* self) | 190 Scanner::LiteralScope::LiteralScope(Scanner* self) |
| 327 : scanner_(self), complete_(false) { | 191 : scanner_(self), complete_(false) { |
| 328 self->StartLiteral(); | 192 self->StartLiteral(); |
| 329 } | 193 } |
| 330 | 194 |
| 331 | 195 |
| 332 Scanner::LiteralScope::~LiteralScope() { | 196 Scanner::LiteralScope::~LiteralScope() { |
| (...skipping 1017 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1350 } | 1214 } |
| 1351 AddCharAdvance(); | 1215 AddCharAdvance(); |
| 1352 } | 1216 } |
| 1353 literal.Complete(); | 1217 literal.Complete(); |
| 1354 | 1218 |
| 1355 next_.location.end_pos = source_pos() - 1; | 1219 next_.location.end_pos = source_pos() - 1; |
| 1356 return true; | 1220 return true; |
| 1357 } | 1221 } |
| 1358 | 1222 |
| 1359 } } // namespace v8::internal | 1223 } } // namespace v8::internal |
| OLD | NEW |