OLD | NEW |
1 // Copyright 2006-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2008 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 21 matching lines...) Expand all Loading... |
32 #include "char-predicates-inl.h" | 32 #include "char-predicates-inl.h" |
33 | 33 |
34 namespace v8 { namespace internal { | 34 namespace v8 { namespace internal { |
35 | 35 |
36 | 36 |
37 class UTF8Buffer { | 37 class UTF8Buffer { |
38 public: | 38 public: |
39 UTF8Buffer(); | 39 UTF8Buffer(); |
40 ~UTF8Buffer(); | 40 ~UTF8Buffer(); |
41 | 41 |
42 void Initialize(char* src, int length); | 42 void AddChar(uc32 c) { |
43 void AddChar(uc32 c); | 43 if (cursor_ <= limit_ && |
44 void Reset() { pos_ = 0; } | 44 static_cast<unsigned>(c) <= unibrow::Utf8::kMaxOneByteChar) { |
45 int pos() const { return pos_; } | 45 *cursor_++ = static_cast<char>(c); |
| 46 } else { |
| 47 AddCharSlow(c); |
| 48 } |
| 49 } |
| 50 |
| 51 void Reset() { cursor_ = data_; } |
| 52 int pos() const { return cursor_ - data_; } |
46 char* data() const { return data_; } | 53 char* data() const { return data_; } |
47 | 54 |
48 private: | 55 private: |
49 char* data_; | 56 char* data_; |
50 int size_; | 57 char* cursor_; |
51 int pos_; | 58 char* limit_; |
| 59 |
| 60 int Capacity() const { |
| 61 return (limit_ - data_) + unibrow::Utf8::kMaxEncodedSize; |
| 62 } |
| 63 |
| 64 static char* ComputeLimit(char* data, int capacity) { |
| 65 return (data + capacity) - unibrow::Utf8::kMaxEncodedSize; |
| 66 } |
| 67 |
| 68 void AddCharSlow(uc32 c); |
52 }; | 69 }; |
53 | 70 |
54 | 71 |
55 class UTF16Buffer { | 72 class UTF16Buffer { |
56 public: | 73 public: |
57 UTF16Buffer(); | 74 UTF16Buffer(); |
58 | 75 |
59 void Initialize(Handle<String> data, unibrow::CharacterStream* stream); | 76 void Initialize(Handle<String> data, unibrow::CharacterStream* stream); |
60 void PushBack(uc32 ch); | 77 void PushBack(uc32 ch); |
61 uc32 Advance(); // returns a value < 0 when the buffer end is reached | 78 uc32 Advance(); // returns a value < 0 when the buffer end is reached |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
197 // Literal buffer support | 214 // Literal buffer support |
198 void StartLiteral(); | 215 void StartLiteral(); |
199 void AddChar(uc32 ch); | 216 void AddChar(uc32 ch); |
200 void AddCharAdvance(); | 217 void AddCharAdvance(); |
201 void TerminateLiteral(); | 218 void TerminateLiteral(); |
202 | 219 |
203 // Low-level scanning support. | 220 // Low-level scanning support. |
204 void Advance(); | 221 void Advance(); |
205 void PushBack(uc32 ch); | 222 void PushBack(uc32 ch); |
206 | 223 |
207 void SkipWhiteSpace(bool initial); | 224 bool SkipWhiteSpace(); |
208 Token::Value SkipSingleLineComment(); | 225 Token::Value SkipSingleLineComment(); |
209 Token::Value SkipMultiLineComment(); | 226 Token::Value SkipMultiLineComment(); |
210 | 227 |
211 inline Token::Value Select(Token::Value tok); | 228 inline Token::Value Select(Token::Value tok); |
212 inline Token::Value Select(uc32 next, Token::Value then, Token::Value else_); | 229 inline Token::Value Select(uc32 next, Token::Value then, Token::Value else_); |
213 | 230 |
214 void Scan(); | 231 void Scan(); |
215 Token::Value ScanToken(); | |
216 void ScanDecimalDigits(); | 232 void ScanDecimalDigits(); |
217 Token::Value ScanNumber(bool seen_period); | 233 Token::Value ScanNumber(bool seen_period); |
218 Token::Value ScanIdentifier(); | 234 Token::Value ScanIdentifier(); |
219 uc32 ScanHexEscape(uc32 c, int length); | 235 uc32 ScanHexEscape(uc32 c, int length); |
220 uc32 ScanOctalEscape(uc32 c, int length); | 236 uc32 ScanOctalEscape(uc32 c, int length); |
221 void ScanEscape(); | 237 void ScanEscape(); |
222 Token::Value ScanString(); | 238 Token::Value ScanString(); |
223 | 239 |
224 // Scans a possible HTML comment -- begins with '<!'. | 240 // Scans a possible HTML comment -- begins with '<!'. |
225 Token::Value ScanHtmlComment(); | 241 Token::Value ScanHtmlComment(); |
226 | 242 |
227 // Return the current source position. | 243 // Return the current source position. |
228 int source_pos() { | 244 int source_pos() { |
229 return source_.pos() - kCharacterLookaheadBufferSize + position_; | 245 return source_.pos() - kCharacterLookaheadBufferSize + position_; |
230 } | 246 } |
231 | 247 |
232 // Decodes a unicode escape-sequence which is part of an identifier. | 248 // Decodes a unicode escape-sequence which is part of an identifier. |
233 // If the escape sequence cannot be decoded the result is kBadRune. | 249 // If the escape sequence cannot be decoded the result is kBadRune. |
234 uc32 ScanIdentifierUnicodeEscape(); | 250 uc32 ScanIdentifierUnicodeEscape(); |
235 }; | 251 }; |
236 | 252 |
237 } } // namespace v8::internal | 253 } } // namespace v8::internal |
238 | 254 |
239 #endif // V8_SCANNER_H_ | 255 #endif // V8_SCANNER_H_ |
OLD | NEW |