v8  3.14.5(node0.10.28)
V8 is Google's open source JavaScript engine
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
scanner-character-streams.h
Go to the documentation of this file.
1 // Copyright 2011 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are
4 // met:
5 //
6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided
11 // with the distribution.
12 // * Neither the name of Google Inc. nor the names of its
13 // contributors may be used to endorse or promote products derived
14 // from this software without specific prior written permission.
15 //
16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 
28 #ifndef V8_SCANNER_CHARACTER_STREAMS_H_
29 #define V8_SCANNER_CHARACTER_STREAMS_H_
30 
31 #include "scanner.h"
32 
33 namespace v8 {
34 namespace internal {
35 
36 // A buffered character stream based on a random access character
37 // source (ReadBlock can be called with pos_ pointing to any position,
38 // even positions before the current).
40  public:
43 
44  virtual void PushBack(uc32 character);
45 
46  protected:
47  static const unsigned kBufferSize = 512;
48  static const unsigned kPushBackStepSize = 16;
49 
50  virtual unsigned SlowSeekForward(unsigned delta);
51  virtual bool ReadBlock();
52  virtual void SlowPushBack(uc16 character);
53 
54  virtual unsigned BufferSeekForward(unsigned delta) = 0;
55  virtual unsigned FillBuffer(unsigned position, unsigned length) = 0;
56 
59 };
60 
61 
62 // Generic string stream.
64  public:
66  unsigned start_position,
67  unsigned end_position);
69 
70  protected:
71  virtual unsigned BufferSeekForward(unsigned delta);
72  virtual unsigned FillBuffer(unsigned position, unsigned length);
73 
75  unsigned start_position_;
76  unsigned length_;
77 };
78 
79 
80 // Utf16 stream based on a literal UTF-8 string.
82  public:
83  Utf8ToUtf16CharacterStream(const byte* data, unsigned length);
85 
86  protected:
87  virtual unsigned BufferSeekForward(unsigned delta);
88  virtual unsigned FillBuffer(unsigned char_position, unsigned length);
89  void SetRawPosition(unsigned char_position);
90 
91  const byte* raw_data_;
92  unsigned raw_data_length_; // Measured in bytes, not characters.
93  unsigned raw_data_pos_;
94  // The character position of the character at raw_data[raw_data_pos_].
95  // Not necessarily the same as pos_.
97 };
98 
99 
100 // UTF16 buffer to read characters from an external string.
102  public:
104  int start_position,
105  int end_position);
107 
108  virtual void PushBack(uc32 character) {
110  buffer_cursor_--;
111  pos_--;
112  }
113 
114  protected:
115  virtual unsigned SlowSeekForward(unsigned delta) {
116  // Fast case always handles seeking.
117  return 0;
118  }
119  virtual bool ReadBlock() {
120  // Entire string is read at start.
121  return false;
122  }
124  const uc16* raw_data_; // Pointer to the actual array of characters.
125 };
126 
127 } } // namespace v8::internal
128 
129 #endif // V8_SCANNER_CHARACTER_STREAMS_H_
virtual unsigned FillBuffer(unsigned position, unsigned length)=0
int32_t uc32
Definition: globals.h:260
#define ASSERT(condition)
Definition: checks.h:270
uint8_t byte
Definition: globals.h:156
virtual unsigned BufferSeekForward(unsigned delta)=0
Utf8ToUtf16CharacterStream(const byte *data, unsigned length)
GenericStringUtf16CharacterStream(Handle< String > data, unsigned start_position, unsigned end_position)
uint16_t uc16
Definition: globals.h:259
ExternalTwoByteStringUtf16CharacterStream(Handle< ExternalTwoByteString > data, int start_position, int end_position)
virtual unsigned BufferSeekForward(unsigned delta)
virtual unsigned FillBuffer(unsigned char_position, unsigned length)
virtual unsigned FillBuffer(unsigned position, unsigned length)