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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
51 void StartLiteral() { | 51 void StartLiteral() { |
52 buffer_.StartSequence(); | 52 buffer_.StartSequence(); |
53 } | 53 } |
54 | 54 |
55 Vector<const char> EndLiteral() { | 55 Vector<const char> EndLiteral() { |
56 buffer_.Add(kEndMarker); | 56 buffer_.Add(kEndMarker); |
57 Vector<char> sequence = buffer_.EndSequence(); | 57 Vector<char> sequence = buffer_.EndSequence(); |
58 return Vector<const char>(sequence.start(), sequence.length()); | 58 return Vector<const char>(sequence.start(), sequence.length()); |
59 } | 59 } |
60 | 60 |
61 void DropLiteral() { | |
62 buffer_.DropSequence(); | |
63 } | |
64 | |
65 void Reset() { | |
66 buffer_.Reset(); | |
67 } | |
68 | |
61 // The end marker added after a parsed literal. | 69 // The end marker added after a parsed literal. |
62 // Using zero allows the usage of strlen and similar functions on | 70 // Using zero allows the usage of strlen and similar functions on |
63 // identifiers and numbers (but not strings, since they may contain zero | 71 // identifiers and numbers (but not strings, since they may contain zero |
64 // bytes). | 72 // bytes). |
65 // TODO(lrn): Use '\xff' as end marker, since it cannot occur inside | 73 // TODO(lrn): Use '\xff' as end marker, since it cannot occur inside |
66 // an utf-8 string. This requires changes in all places that uses | 74 // an utf-8 string. This requires changes in all places that uses |
67 // str-functions on the literals, but allows a single pointer to represent | 75 // str-functions on the literals, but allows a single pointer to represent |
68 // the literal, even if it contains embedded zeros. | 76 // the literal, even if it contains embedded zeros. |
69 static const char kEndMarker = '\x00'; | 77 static const char kEndMarker = '\x00'; |
70 private: | 78 private: |
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
255 | 263 |
256 | 264 |
257 enum ParserMode { PARSE, PREPARSE }; | 265 enum ParserMode { PARSE, PREPARSE }; |
258 enum ParserLanguage { JAVASCRIPT, JSON }; | 266 enum ParserLanguage { JAVASCRIPT, JSON }; |
259 | 267 |
260 | 268 |
261 class Scanner { | 269 class Scanner { |
262 public: | 270 public: |
263 typedef unibrow::Utf8InputBuffer<1024> Utf8Decoder; | 271 typedef unibrow::Utf8InputBuffer<1024> Utf8Decoder; |
264 | 272 |
273 class LiteralScope { | |
274 public: | |
275 explicit LiteralScope(Scanner* self); | |
276 | |
277 ~LiteralScope(); | |
278 | |
279 void Complete(); | |
280 private: | |
Mads Ager (chromium)
2010/08/24 12:19:32
Strange spacing going on here. Please add blank li
Lasse Reichstein
2010/08/24 12:30:21
Done.
| |
281 Scanner* scanner_; | |
282 bool complete_; | |
283 }; | |
284 | |
265 // Construction | 285 // Construction |
266 explicit Scanner(ParserMode parse_mode); | 286 explicit Scanner(ParserMode parse_mode); |
267 | 287 |
268 // Initialize the Scanner to scan source. | 288 // Initialize the Scanner to scan source. |
269 void Initialize(Handle<String> source, | 289 void Initialize(Handle<String> source, |
270 ParserLanguage language); | 290 ParserLanguage language); |
271 void Initialize(Handle<String> source, | 291 void Initialize(Handle<String> source, |
272 unibrow::CharacterStream* stream, | 292 unibrow::CharacterStream* stream, |
273 ParserLanguage language); | 293 ParserLanguage language); |
274 void Initialize(Handle<String> source, | 294 void Initialize(Handle<String> source, |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
375 void Init(Handle<String> source, | 395 void Init(Handle<String> source, |
376 unibrow::CharacterStream* stream, | 396 unibrow::CharacterStream* stream, |
377 int start_position, int end_position, | 397 int start_position, int end_position, |
378 ParserLanguage language); | 398 ParserLanguage language); |
379 | 399 |
380 // Literal buffer support | 400 // Literal buffer support |
381 inline void StartLiteral(); | 401 inline void StartLiteral(); |
382 inline void AddChar(uc32 ch); | 402 inline void AddChar(uc32 ch); |
383 inline void AddCharAdvance(); | 403 inline void AddCharAdvance(); |
384 inline void TerminateLiteral(); | 404 inline void TerminateLiteral(); |
405 // Stops scanning of a literal, e.g., due to an encountered error. | |
406 inline void DropLiteral(); | |
385 | 407 |
386 // Low-level scanning support. | 408 // Low-level scanning support. |
387 void Advance() { c0_ = source_->Advance(); } | 409 void Advance() { c0_ = source_->Advance(); } |
388 void PushBack(uc32 ch) { | 410 void PushBack(uc32 ch) { |
389 source_->PushBack(ch); | 411 source_->PushBack(ch); |
390 c0_ = ch; | 412 c0_ = ch; |
391 } | 413 } |
392 | 414 |
393 bool SkipWhiteSpace() { | 415 bool SkipWhiteSpace() { |
394 if (is_parsing_json_) { | 416 if (is_parsing_json_) { |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
491 bool stack_overflow_; | 513 bool stack_overflow_; |
492 static StaticResource<Utf8Decoder> utf8_decoder_; | 514 static StaticResource<Utf8Decoder> utf8_decoder_; |
493 | 515 |
494 // One Unicode character look-ahead; c0_ < 0 at the end of the input. | 516 // One Unicode character look-ahead; c0_ < 0 at the end of the input. |
495 uc32 c0_; | 517 uc32 c0_; |
496 }; | 518 }; |
497 | 519 |
498 } } // namespace v8::internal | 520 } } // namespace v8::internal |
499 | 521 |
500 #endif // V8_SCANNER_H_ | 522 #endif // V8_SCANNER_H_ |
OLD | NEW |