| OLD | NEW |
| 1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // Features shared by parsing and pre-parsing scanners. | 5 // Features shared by parsing and pre-parsing scanners. |
| 6 | 6 |
| 7 #ifndef V8_SCANNER_H_ | 7 #ifndef V8_SCANNER_H_ |
| 8 #define V8_SCANNER_H_ | 8 #define V8_SCANNER_H_ |
| 9 | 9 |
| 10 #include "allocation.h" | 10 #include "allocation.h" |
| (...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 180 UnicodeCache* unicode_constants_; | 180 UnicodeCache* unicode_constants_; |
| 181 // Backing store used to store strings used as hashmap keys. | 181 // Backing store used to store strings used as hashmap keys. |
| 182 SequenceCollector<unsigned char> backing_store_; | 182 SequenceCollector<unsigned char> backing_store_; |
| 183 HashMap map_; | 183 HashMap map_; |
| 184 // Buffer used for string->number->canonical string conversions. | 184 // Buffer used for string->number->canonical string conversions. |
| 185 char number_buffer_[kBufferSize]; | 185 char number_buffer_[kBufferSize]; |
| 186 }; | 186 }; |
| 187 | 187 |
| 188 | 188 |
| 189 // ---------------------------------------------------------------------------- | 189 // ---------------------------------------------------------------------------- |
| 190 // ParamListFinder discovers sequences of tokens which form a valid function |
| 191 // parameter list. |
| 192 |
| 193 class ParamListFinder { |
| 194 public: |
| 195 ParamListFinder(): state_(Invalid), start_pos_(-1) { } |
| 196 |
| 197 void Update(Token::Value token, int pos) { |
| 198 switch (state_) { |
| 199 case Valid: |
| 200 state_ = Invalid; |
| 201 start_pos_ = -1; |
| 202 // Fall-through. |
| 203 case Invalid: |
| 204 if (token == Token::LPAREN) { |
| 205 state_ = LeftParen; |
| 206 start_pos_ = pos; |
| 207 } |
| 208 break; |
| 209 |
| 210 case LeftParen: |
| 211 switch (token) { |
| 212 case Token::LPAREN: |
| 213 start_pos_ = pos; |
| 214 break; |
| 215 case Token::RPAREN: |
| 216 state_ = Valid; |
| 217 break; |
| 218 case Token::IDENTIFIER: |
| 219 state_ = Identifier; |
| 220 break; |
| 221 default: |
| 222 state_ = Invalid; |
| 223 } |
| 224 break; |
| 225 |
| 226 case Identifier: |
| 227 switch (token) { |
| 228 case Token::RPAREN: |
| 229 state_ = Valid; |
| 230 break; |
| 231 case Token::COMMA: |
| 232 state_ = Comma; |
| 233 break; |
| 234 default: |
| 235 state_ = Invalid; |
| 236 } |
| 237 break; |
| 238 |
| 239 case Comma: |
| 240 if (token == Token::IDENTIFIER) { |
| 241 state_ = Identifier; |
| 242 } else { |
| 243 state_ = Invalid; |
| 244 } |
| 245 break; |
| 246 } |
| 247 } |
| 248 |
| 249 bool IsValid(int pos) const { |
| 250 return state_ == Valid && start_pos_ == pos; |
| 251 } |
| 252 |
| 253 private: |
| 254 enum State { |
| 255 Invalid, |
| 256 Valid, |
| 257 LeftParen, |
| 258 Identifier, |
| 259 Comma |
| 260 }; |
| 261 |
| 262 State state_; |
| 263 int start_pos_; |
| 264 }; |
| 265 |
| 266 |
| 267 // ---------------------------------------------------------------------------- |
| 190 // LiteralBuffer - Collector of chars of literals. | 268 // LiteralBuffer - Collector of chars of literals. |
| 191 | 269 |
| 192 class LiteralBuffer { | 270 class LiteralBuffer { |
| 193 public: | 271 public: |
| 194 LiteralBuffer() : is_one_byte_(true), position_(0), backing_store_() { } | 272 LiteralBuffer() : is_one_byte_(true), position_(0), backing_store_() { } |
| 195 | 273 |
| 196 ~LiteralBuffer() { | 274 ~LiteralBuffer() { |
| 197 if (backing_store_.length() > 0) { | 275 if (backing_store_.length() > 0) { |
| 198 backing_store_.Dispose(); | 276 backing_store_.Dispose(); |
| 199 } | 277 } |
| (...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 395 if (is_literal_one_byte() && | 473 if (is_literal_one_byte() && |
| 396 literal_length() == 3 && | 474 literal_length() == 3 && |
| 397 !literal_contains_escapes()) { | 475 !literal_contains_escapes()) { |
| 398 const char* token = | 476 const char* token = |
| 399 reinterpret_cast<const char*>(literal_one_byte_string().start()); | 477 reinterpret_cast<const char*>(literal_one_byte_string().start()); |
| 400 *is_get = strncmp(token, "get", 3) == 0; | 478 *is_get = strncmp(token, "get", 3) == 0; |
| 401 *is_set = !*is_get && strncmp(token, "set", 3) == 0; | 479 *is_set = !*is_get && strncmp(token, "set", 3) == 0; |
| 402 } | 480 } |
| 403 } | 481 } |
| 404 | 482 |
| 483 bool IsValidParameterList(int pos) const { |
| 484 return param_list_finder_.IsValid(pos); |
| 485 } |
| 486 |
| 405 int FindNumber(DuplicateFinder* finder, int value); | 487 int FindNumber(DuplicateFinder* finder, int value); |
| 406 int FindSymbol(DuplicateFinder* finder, int value); | 488 int FindSymbol(DuplicateFinder* finder, int value); |
| 407 | 489 |
| 408 UnicodeCache* unicode_cache() { return unicode_cache_; } | 490 UnicodeCache* unicode_cache() { return unicode_cache_; } |
| 409 | 491 |
| 410 // Returns the location of the last seen octal literal. | 492 // Returns the location of the last seen octal literal. |
| 411 Location octal_position() const { return octal_pos_; } | 493 Location octal_position() const { return octal_pos_; } |
| 412 void clear_octal_position() { octal_pos_ = Location::invalid(); } | 494 void clear_octal_position() { octal_pos_ = Location::invalid(); } |
| 413 | 495 |
| 414 // Seek forward to the given position. This operation does not | 496 // Seek forward to the given position. This operation does not |
| (...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 598 int source_pos() { | 680 int source_pos() { |
| 599 return source_->pos() - kCharacterLookaheadBufferSize; | 681 return source_->pos() - kCharacterLookaheadBufferSize; |
| 600 } | 682 } |
| 601 | 683 |
| 602 UnicodeCache* unicode_cache_; | 684 UnicodeCache* unicode_cache_; |
| 603 | 685 |
| 604 // Buffers collecting literal strings, numbers, etc. | 686 // Buffers collecting literal strings, numbers, etc. |
| 605 LiteralBuffer literal_buffer1_; | 687 LiteralBuffer literal_buffer1_; |
| 606 LiteralBuffer literal_buffer2_; | 688 LiteralBuffer literal_buffer2_; |
| 607 | 689 |
| 690 ParamListFinder param_list_finder_; |
| 691 |
| 608 TokenDesc current_; // desc for current token (as returned by Next()) | 692 TokenDesc current_; // desc for current token (as returned by Next()) |
| 609 TokenDesc next_; // desc for next token (one token look-ahead) | 693 TokenDesc next_; // desc for next token (one token look-ahead) |
| 610 | 694 |
| 611 // Input stream. Must be initialized to an Utf16CharacterStream. | 695 // Input stream. Must be initialized to an Utf16CharacterStream. |
| 612 Utf16CharacterStream* source_; | 696 Utf16CharacterStream* source_; |
| 613 | 697 |
| 614 | 698 |
| 615 // Start position of the octal literal last scanned. | 699 // Start position of the octal literal last scanned. |
| 616 Location octal_pos_; | 700 Location octal_pos_; |
| 617 | 701 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 629 bool harmony_scoping_; | 713 bool harmony_scoping_; |
| 630 // Whether we scan 'module', 'import', 'export' as keywords. | 714 // Whether we scan 'module', 'import', 'export' as keywords. |
| 631 bool harmony_modules_; | 715 bool harmony_modules_; |
| 632 // Whether we scan 0o777 and 0b111 as numbers. | 716 // Whether we scan 0o777 and 0b111 as numbers. |
| 633 bool harmony_numeric_literals_; | 717 bool harmony_numeric_literals_; |
| 634 }; | 718 }; |
| 635 | 719 |
| 636 } } // namespace v8::internal | 720 } } // namespace v8::internal |
| 637 | 721 |
| 638 #endif // V8_SCANNER_H_ | 722 #endif // V8_SCANNER_H_ |
| OLD | NEW |