Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1)

Side by Side Diff: src/scanner-base.h

Issue 6246004: Fix bug when the scanner does a pushback at the end of input. (Closed)
Patch Set: Created 9 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/scanner.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 // Buffered stream of characters, using an internal UC16 buffer. 57 // Buffered stream of characters, using an internal UC16 buffer.
58 58
59 class UC16CharacterStream { 59 class UC16CharacterStream {
60 public: 60 public:
61 UC16CharacterStream() : pos_(0) { } 61 UC16CharacterStream() : pos_(0) { }
62 virtual ~UC16CharacterStream() { } 62 virtual ~UC16CharacterStream() { }
63 63
64 // Returns and advances past the next UC16 character in the input 64 // Returns and advances past the next UC16 character in the input
65 // stream. If there are no more characters, it returns a negative 65 // stream. If there are no more characters, it returns a negative
66 // value. 66 // value.
67 inline int32_t Advance() { 67 inline uc32 Advance() {
68 if (buffer_cursor_ < buffer_end_ || ReadBlock()) { 68 if (buffer_cursor_ < buffer_end_ || ReadBlock()) {
69 pos_++; 69 pos_++;
70 return *(buffer_cursor_++); 70 return static_cast<uc32>(*(buffer_cursor_++));
71 } 71 }
72 // Note: currently the following increment is necessary to avoid a 72 // Note: currently the following increment is necessary to avoid a
73 // parser problem! The scanner treats the final kEndOfInput as 73 // parser problem! The scanner treats the final kEndOfInput as
74 // a character with a position, and does math relative to that 74 // a character with a position, and does math relative to that
75 // position. 75 // position.
76 pos_++; 76 pos_++;
77 77
78 return kEndOfInput; 78 return kEndOfInput;
79 } 79 }
80 80
81 // Return the current position in the character stream. 81 // Return the current position in the character stream.
82 // Starts at zero. 82 // Starts at zero.
83 inline unsigned pos() const { return pos_; } 83 inline unsigned pos() const { return pos_; }
84 84
85 // Skips forward past the next character_count UC16 characters 85 // Skips forward past the next character_count UC16 characters
86 // in the input, or until the end of input if that comes sooner. 86 // in the input, or until the end of input if that comes sooner.
87 // Returns the number of characters actually skipped. If less 87 // Returns the number of characters actually skipped. If less
88 // than character_count, 88 // than character_count,
89 inline unsigned SeekForward(unsigned character_count) { 89 inline unsigned SeekForward(unsigned character_count) {
90 unsigned buffered_chars = 90 unsigned buffered_chars =
91 static_cast<unsigned>(buffer_end_ - buffer_cursor_); 91 static_cast<unsigned>(buffer_end_ - buffer_cursor_);
92 if (character_count <= buffered_chars) { 92 if (character_count <= buffered_chars) {
93 buffer_cursor_ += character_count; 93 buffer_cursor_ += character_count;
94 pos_ += character_count; 94 pos_ += character_count;
95 return character_count; 95 return character_count;
96 } 96 }
97 return SlowSeekForward(character_count); 97 return SlowSeekForward(character_count);
98 } 98 }
99 99
100 // Pushes back the most recently read UC16 character, i.e., 100 // Pushes back the most recently read UC16 character (or negative
Søren Thygesen Gjesse 2011/01/14 10:37:16 negative value -> kEndOfInput?
Lasse Reichstein 2011/01/14 10:49:04 The kEndOfInput name isn't publicly visible. All w
101 // the value returned by the most recent call to Advance. 101 // value if at end of input), i.e., the value returned by the most recent
102 // call to Advance.
102 // Must not be used right after calling SeekForward. 103 // Must not be used right after calling SeekForward.
103 virtual void PushBack(uc16 character) = 0; 104 virtual void PushBack(int32_t character) = 0;
104 105
105 protected: 106 protected:
106 static const int32_t kEndOfInput = -1; 107 static const uc32 kEndOfInput = -1;
107 108
108 // Ensures that the buffer_cursor_ points to the character at 109 // Ensures that the buffer_cursor_ points to the character at
109 // position pos_ of the input, if possible. If the position 110 // position pos_ of the input, if possible. If the position
110 // is at or after the end of the input, return false. If there 111 // is at or after the end of the input, return false. If there
111 // are more characters available, return true. 112 // are more characters available, return true.
112 virtual bool ReadBlock() = 0; 113 virtual bool ReadBlock() = 0;
113 virtual unsigned SlowSeekForward(unsigned character_count) = 0; 114 virtual unsigned SlowSeekForward(unsigned character_count) = 0;
114 115
115 const uc16* buffer_cursor_; 116 const uc16* buffer_cursor_;
116 const uc16* buffer_end_; 117 const uc16* buffer_end_;
(...skipping 499 matching lines...) Expand 10 before | Expand all | Expand 10 after
616 // keyword with the current prefix). 617 // keyword with the current prefix).
617 const char* keyword_; 618 const char* keyword_;
618 int counter_; 619 int counter_;
619 Token::Value keyword_token_; 620 Token::Value keyword_token_;
620 }; 621 };
621 622
622 623
623 } } // namespace v8::internal 624 } } // namespace v8::internal
624 625
625 #endif // V8_SCANNER_BASE_H_ 626 #endif // V8_SCANNER_BASE_H_
OLDNEW
« no previous file with comments | « src/scanner.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698