V8 Project
scanner-character-streams.h
Go to the documentation of this file.
1 // Copyright 2011 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef V8_SCANNER_CHARACTER_STREAMS_H_
6 #define V8_SCANNER_CHARACTER_STREAMS_H_
7 
8 #include "src/scanner.h"
9 
10 namespace v8 {
11 namespace internal {
12 
13 // A buffered character stream based on a random access character
14 // source (ReadBlock can be called with pos_ pointing to any position,
15 // even positions before the current).
17  public:
20 
21  virtual void PushBack(uc32 character);
22 
23  protected:
24  static const unsigned kBufferSize = 512;
25  static const unsigned kPushBackStepSize = 16;
26 
27  virtual unsigned SlowSeekForward(unsigned delta);
28  virtual bool ReadBlock();
29  virtual void SlowPushBack(uc16 character);
30 
31  virtual unsigned BufferSeekForward(unsigned delta) = 0;
32  virtual unsigned FillBuffer(unsigned position) = 0;
33 
36 };
37 
38 
39 // Generic string stream.
41  public:
43  unsigned start_position,
44  unsigned end_position);
46 
47  protected:
48  virtual unsigned BufferSeekForward(unsigned delta);
49  virtual unsigned FillBuffer(unsigned position);
50 
52  unsigned length_;
53 };
54 
55 
56 // Utf16 stream based on a literal UTF-8 string.
58  public:
59  Utf8ToUtf16CharacterStream(const byte* data, unsigned length);
61 
62  static unsigned CopyChars(uint16_t* dest, unsigned length, const byte* src,
63  unsigned* src_pos, unsigned src_length);
64 
65  protected:
66  virtual unsigned BufferSeekForward(unsigned delta);
67  virtual unsigned FillBuffer(unsigned char_position);
68  void SetRawPosition(unsigned char_position);
69 
70  const byte* raw_data_;
71  unsigned raw_data_length_; // Measured in bytes, not characters.
72  unsigned raw_data_pos_;
73  // The character position of the character at raw_data[raw_data_pos_].
74  // Not necessarily the same as pos_.
76 };
77 
78 
79 // ExternalStreamingStream is a wrapper around an ExternalSourceStream (see
80 // include/v8.h) subclass implemented by the embedder.
82  public:
85  : source_stream_(source_stream),
86  encoding_(encoding),
91 
92  virtual ~ExternalStreamingStream() { delete[] current_data_; }
93 
94  virtual unsigned BufferSeekForward(unsigned delta) OVERRIDE {
95  // We never need to seek forward when streaming scripts. We only seek
96  // forward when we want to parse a function whose location we already know,
97  // and when streaming, we don't know the locations of anything we haven't
98  // seen yet.
99  UNREACHABLE();
100  return 0;
101  }
102 
103  virtual unsigned FillBuffer(unsigned position);
104 
105  private:
106  void HandleUtf8SplitCharacters(unsigned* data_in_buffer);
107 
110  const uint8_t* current_data_;
113  // For converting UTF-8 characters which are split across two data chunks.
116 };
117 
118 
119 // UTF16 buffer to read characters from an external string.
121  public:
123  int start_position,
124  int end_position);
126 
127  virtual void PushBack(uc32 character) {
129  buffer_cursor_--;
130  pos_--;
131  }
132 
133  protected:
134  virtual unsigned SlowSeekForward(unsigned delta) {
135  // Fast case always handles seeking.
136  return 0;
137  }
138  virtual bool ReadBlock() {
139  // Entire string is read at start.
140  return false;
141  }
143  const uc16* raw_data_; // Pointer to the actual array of characters.
144 };
145 
146 } } // namespace v8::internal
147 
148 #endif // V8_SCANNER_CHARACTER_STREAMS_H_
For streaming incomplete script data to V8.
Definition: v8.h:1096
virtual unsigned BufferSeekForward(unsigned delta)=0
virtual unsigned FillBuffer(unsigned position)=0
ScriptCompiler::ExternalSourceStream * source_stream_
virtual unsigned BufferSeekForward(unsigned delta) OVERRIDE
v8::ScriptCompiler::StreamedSource::Encoding encoding_
virtual unsigned FillBuffer(unsigned position)
void HandleUtf8SplitCharacters(unsigned *data_in_buffer)
ExternalStreamingStream(ScriptCompiler::ExternalSourceStream *source_stream, v8::ScriptCompiler::StreamedSource::Encoding encoding)
ExternalTwoByteStringUtf16CharacterStream(Handle< ExternalTwoByteString > data, int start_position, int end_position)
GenericStringUtf16CharacterStream(Handle< String > data, unsigned start_position, unsigned end_position)
const uint16_t * buffer_cursor_
Definition: scanner.h:102
virtual unsigned FillBuffer(unsigned char_position)
Utf8ToUtf16CharacterStream(const byte *data, unsigned length)
virtual unsigned BufferSeekForward(unsigned delta)
static unsigned CopyChars(uint16_t *dest, unsigned length, const byte *src, unsigned *src_pos, unsigned src_length)
#define OVERRIDE
enable harmony numeric enable harmony object literal extensions Optimize object Array DOM strings and string trace pretenuring decisions of HAllocate instructions Enables optimizations which favor memory size over execution speed maximum source size in bytes considered for a single inlining maximum cumulative number of AST nodes considered for inlining trace the tracking of allocation sites deoptimize every n garbage collections perform array bounds checks elimination analyze liveness of environment slots and zap dead values flushes the cache of optimized code for closures on every GC allow uint32 values on optimize frames if they are used only in safe operations track concurrent recompilation artificial compilation delay in ms do not emit check maps for constant values that have a leaf deoptimize the optimized code if the layout of the maps changes enable context specialization in TurboFan execution budget before interrupt is triggered max percentage of megamorphic generic ICs to allow optimization enable use of SAHF instruction if enable use of VFP3 instructions if available enable use of NEON instructions if enable use of SDIV and UDIV instructions if enable use of MLS instructions if enable loading bit constant by means of movw movt instruction enable unaligned accesses for enable use of d16 d31 registers on ARM this requires VFP3 force all emitted branches to be in long enable alignment of csp to bytes on platforms which prefer the register to always be NULL
#define UNREACHABLE()
Definition: logging.h:30
#define DCHECK(condition)
Definition: logging.h:205
unsigned short uint16_t
Definition: unicode.cc:23
uint16_t uc16
Definition: globals.h:184
int32_t uc32
Definition: globals.h:185
Debugger support for the V8 JavaScript engine.
Definition: accessors.cc:20