| OLD | NEW |
| 1 // Copyright 2013 the V8 project authors. All rights reserved. | 1 // Copyright 2013 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 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 285 public: | 285 public: |
| 286 explicit ExperimentalScanner( | 286 explicit ExperimentalScanner( |
| 287 Handle<String> source, | 287 Handle<String> source, |
| 288 Isolate* isolate) | 288 Isolate* isolate) |
| 289 : ScannerBase(isolate), | 289 : ScannerBase(isolate), |
| 290 source_handle_(source), | 290 source_handle_(source), |
| 291 buffer_(NULL), | 291 buffer_(NULL), |
| 292 buffer_end_(NULL), | 292 buffer_end_(NULL), |
| 293 start_(NULL), | 293 start_(NULL), |
| 294 cursor_(NULL), | 294 cursor_(NULL), |
| 295 marker_(NULL), | |
| 296 last_octal_end_(NULL) { | 295 last_octal_end_(NULL) { |
| 297 ASSERT(source->IsFlat()); | 296 ASSERT(source->IsFlat()); |
| 298 UpdateBufferBasedOnHandle(); | 297 UpdateBufferBasedOnHandle(); |
| 299 current_.beg_pos = current_.end_pos = next_.beg_pos = next_.end_pos = 0; | 298 current_.beg_pos = current_.end_pos = next_.beg_pos = next_.end_pos = 0; |
| 300 } | 299 } |
| 301 | 300 |
| 302 virtual void Init() { | 301 virtual void Init() { |
| 303 Scan(); | 302 Scan(); |
| 304 } | 303 } |
| 305 | 304 |
| 306 virtual ~ExperimentalScanner() { } | 305 virtual ~ExperimentalScanner() { } |
| 307 | 306 |
| 308 virtual void SeekForward(int pos); | 307 virtual void SeekForward(int pos); |
| 309 virtual void SetEnd(int pos); | 308 virtual void SetEnd(int pos); |
| 310 virtual bool ScanRegExpPattern(bool seen_equal); | 309 virtual bool ScanRegExpPattern(bool seen_equal); |
| 311 virtual bool ScanRegExpFlags(); | 310 virtual bool ScanRegExpFlags(); |
| 312 virtual Location octal_position() const; | 311 virtual Location octal_position() const; |
| 313 virtual void clear_octal_position() { | 312 virtual void clear_octal_position() { |
| 314 last_octal_end_ = NULL; | 313 last_octal_end_ = NULL; |
| 315 } | 314 } |
| 316 | 315 |
| 317 virtual void UpdateBufferBasedOnHandle() { | 316 virtual void UpdateBufferBasedOnHandle() { |
| 318 // We get a raw pointer from the Handle, but we also update it every time | 317 // We get a raw pointer from the Handle, but we also update it every time |
| 319 // there is a GC, so it is safe. | 318 // there is a GC, so it is safe. |
| 320 DisallowHeapAllocation no_gc; | 319 DisallowHeapAllocation no_gc; |
| 321 const Char* new_buffer = GetNewBufferBasedOnHandle(); | 320 const Char* new_buffer = GetNewBufferBasedOnHandle(); |
| 322 if (new_buffer != buffer_) { | 321 if (new_buffer != buffer_) { |
| 323 int start_offset = start_ - buffer_; | 322 int start_offset = start_ - buffer_; |
| 324 int cursor_offset = cursor_ - buffer_; | 323 int cursor_offset = cursor_ - buffer_; |
| 325 int marker_offset = marker_ - buffer_; | |
| 326 int last_octal_end_offset = last_octal_end_ - buffer_; | 324 int last_octal_end_offset = last_octal_end_ - buffer_; |
| 327 buffer_ = new_buffer; | 325 buffer_ = new_buffer; |
| 328 buffer_end_ = buffer_ + source_handle_->length(); | 326 buffer_end_ = buffer_ + source_handle_->length(); |
| 329 start_ = buffer_ + start_offset; | 327 start_ = buffer_ + start_offset; |
| 330 cursor_ = buffer_ + cursor_offset; | 328 cursor_ = buffer_ + cursor_offset; |
| 331 marker_ = buffer_ + marker_offset; | |
| 332 if (last_octal_end_ != NULL) { | 329 if (last_octal_end_ != NULL) { |
| 333 last_octal_end_ = buffer_ + last_octal_end_offset; | 330 last_octal_end_ = buffer_ + last_octal_end_offset; |
| 334 } | 331 } |
| 335 ResetLiterals(); | 332 ResetLiterals(); |
| 336 } | 333 } |
| 337 } | 334 } |
| 338 | 335 |
| 339 protected: | 336 protected: |
| 340 virtual void Scan(); | 337 virtual void Scan(); |
| 341 | 338 |
| (...skipping 24 matching lines...) Expand all Loading... |
| 366 uc32* result); | 363 uc32* result); |
| 367 const Char* ScanEscape(const Char* start, | 364 const Char* ScanEscape(const Char* start, |
| 368 const Char* end, | 365 const Char* end, |
| 369 LiteralBuffer* literal); | 366 LiteralBuffer* literal); |
| 370 | 367 |
| 371 Handle<String> source_handle_; | 368 Handle<String> source_handle_; |
| 372 const Char* buffer_; | 369 const Char* buffer_; |
| 373 const Char* buffer_end_; | 370 const Char* buffer_end_; |
| 374 const Char* start_; | 371 const Char* start_; |
| 375 const Char* cursor_; | 372 const Char* cursor_; |
| 376 const Char* marker_; | |
| 377 | 373 |
| 378 // Where we have seen the last octal number or an octal escape inside a | 374 // Where we have seen the last octal number or an octal escape inside a |
| 379 // string. Used by octal_position(). | 375 // string. Used by octal_position(). |
| 380 const Char* last_octal_end_; | 376 const Char* last_octal_end_; |
| 381 }; | 377 }; |
| 382 | 378 |
| 383 | 379 |
| 384 template<typename Char> | 380 template<typename Char> |
| 385 void ExperimentalScanner<Char>::SeekForward(int pos) { | 381 void ExperimentalScanner<Char>::SeekForward(int pos) { |
| 386 cursor_ = buffer_ + pos; | 382 cursor_ = buffer_ + pos; |
| 387 start_ = cursor_; | 383 start_ = cursor_; |
| 388 marker_ = cursor_; | |
| 389 has_line_terminator_before_next_ = false; | 384 has_line_terminator_before_next_ = false; |
| 390 has_multiline_comment_before_next_ = false; | 385 has_multiline_comment_before_next_ = false; |
| 391 Scan(); // Fills in next_. | 386 Scan(); // Fills in next_. |
| 392 } | 387 } |
| 393 | 388 |
| 394 | 389 |
| 395 template<typename Char> | 390 template<typename Char> |
| 396 void ExperimentalScanner<Char>::SetEnd(int pos) { | 391 void ExperimentalScanner<Char>::SetEnd(int pos) { |
| 397 buffer_end_ = buffer_ + pos; | 392 buffer_end_ = buffer_ + pos; |
| 398 } | 393 } |
| (...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 611 // character. | 606 // character. |
| 612 const Char* temp_cursor = last_octal_end_ - 1; | 607 const Char* temp_cursor = last_octal_end_ - 1; |
| 613 while (temp_cursor >= buffer_ && *temp_cursor >= '0' && *temp_cursor <= '7') | 608 while (temp_cursor >= buffer_ && *temp_cursor >= '0' && *temp_cursor <= '7') |
| 614 --temp_cursor; | 609 --temp_cursor; |
| 615 return Location(temp_cursor - buffer_ + 1, last_octal_end_ - buffer_); | 610 return Location(temp_cursor - buffer_ + 1, last_octal_end_ - buffer_); |
| 616 } | 611 } |
| 617 | 612 |
| 618 } } | 613 } } |
| 619 | 614 |
| 620 #endif // V8_LEXER_EXPERIMENTAL_SCANNER_H | 615 #endif // V8_LEXER_EXPERIMENTAL_SCANNER_H |
| OLD | NEW |