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

Side by Side Diff: src/preparser-api.cc

Issue 6580038: [Isolates] Merge from bleeding_edge, revisions 5934-6100. (Closed) Base URL: http://v8.googlecode.com/svn/branches/experimental/isolates/
Patch Set: '' Created 9 years, 10 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 | Annotate | Revision Log
« no previous file with comments | « src/preparser.cc ('k') | src/profile-generator.h » ('j') | 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 21 matching lines...) Expand all
32 #include "utils.h" 32 #include "utils.h"
33 #include "list.h" 33 #include "list.h"
34 #include "scanner-base.h" 34 #include "scanner-base.h"
35 #include "preparse-data.h" 35 #include "preparse-data.h"
36 #include "preparser.h" 36 #include "preparser.h"
37 37
38 namespace v8 { 38 namespace v8 {
39 namespace internal { 39 namespace internal {
40 40
41 // UTF16Buffer based on a v8::UnicodeInputStream. 41 // UTF16Buffer based on a v8::UnicodeInputStream.
42 class InputStreamUTF16Buffer : public UTF16Buffer { 42 class InputStreamUTF16Buffer : public UC16CharacterStream {
43 public: 43 public:
44 explicit InputStreamUTF16Buffer(UnicodeInputStream* stream) 44 /* The InputStreamUTF16Buffer maintains an internal buffer
45 : UTF16Buffer(), 45 * that is filled in chunks from the UC16CharacterStream.
46 stream_(stream) { } 46 * It also maintains unlimited pushback capability, but optimized
47 * for small pushbacks.
48 * The pushback_buffer_ pointer points to the limit of pushbacks
49 * in the current buffer. There is room for a few pushback'ed chars before
50 * the buffer containing the most recently read chunk. If this is overflowed,
51 * an external buffer is allocated/reused to hold further pushbacks, and
52 * pushback_buffer_ and buffer_cursor_/buffer_end_ now points to the
53 * new buffer. When this buffer is read to the end again, the cursor is
54 * switched back to the internal buffer
55 */
56 explicit InputStreamUTF16Buffer(v8::UnicodeInputStream* stream)
57 : UC16CharacterStream(),
58 stream_(stream),
59 pushback_buffer_(buffer_),
60 pushback_buffer_end_cache_(NULL),
61 pushback_buffer_backing_(NULL),
62 pushback_buffer_backing_size_(0) {
63 buffer_cursor_ = buffer_end_ = buffer_ + kPushBackSize;
64 }
47 65
48 virtual ~InputStreamUTF16Buffer() { } 66 virtual ~InputStreamUTF16Buffer() {
67 if (pushback_buffer_backing_ != NULL) {
68 DeleteArray(pushback_buffer_backing_);
69 }
70 }
49 71
50 virtual void PushBack(uc32 ch) { 72 virtual void PushBack(uc16 ch) {
51 stream_->PushBack(ch); 73 ASSERT(pos_ > 0);
74 if (buffer_cursor_ <= pushback_buffer_) {
75 // No more room in the current buffer to do pushbacks.
76 if (pushback_buffer_end_cache_ == NULL) {
77 // We have overflowed the pushback space at the beginning of buffer_.
78 // Switch to using a separate allocated pushback buffer.
79 if (pushback_buffer_backing_ == NULL) {
80 // Allocate a buffer the first time we need it.
81 pushback_buffer_backing_ = NewArray<uc16>(kPushBackSize);
82 pushback_buffer_backing_size_ = kPushBackSize;
83 }
84 pushback_buffer_ = pushback_buffer_backing_;
85 pushback_buffer_end_cache_ = buffer_end_;
86 buffer_end_ = pushback_buffer_backing_ + pushback_buffer_backing_size_;
87 buffer_cursor_ = buffer_end_ - 1;
88 } else {
89 // Hit the bottom of the allocated pushback buffer.
90 // Double the buffer and continue.
91 uc16* new_buffer = NewArray<uc16>(pushback_buffer_backing_size_ * 2);
92 memcpy(new_buffer + pushback_buffer_backing_size_,
93 pushback_buffer_backing_,
94 pushback_buffer_backing_size_);
95 DeleteArray(pushback_buffer_backing_);
96 buffer_cursor_ = new_buffer + pushback_buffer_backing_size_;
97 pushback_buffer_backing_ = pushback_buffer_ = new_buffer;
98 buffer_end_ = pushback_buffer_backing_ + pushback_buffer_backing_size_;
99 }
100 }
101 pushback_buffer_[buffer_cursor_ - pushback_buffer_- 1] = ch;
52 pos_--; 102 pos_--;
53 } 103 }
54 104
55 virtual uc32 Advance() { 105 protected:
56 uc32 result = stream_->Next(); 106 virtual bool ReadBlock() {
57 if (result >= 0) pos_++; 107 if (pushback_buffer_end_cache_ != NULL) {
58 return result; 108 buffer_cursor_ = buffer_;
109 buffer_end_ = pushback_buffer_end_cache_;
110 pushback_buffer_end_cache_ = NULL;
111 return buffer_end_ > buffer_cursor_;
112 }
113 // Copy the top of the buffer into the pushback area.
114 int32_t value;
115 uc16* buffer_start = buffer_ + kPushBackSize;
116 buffer_cursor_ = buffer_end_ = buffer_start;
117 while ((value = stream_->Next()) >= 0) {
118 if (value > static_cast<int32_t>(unibrow::Utf8::kMaxThreeByteChar)) {
119 value = unibrow::Utf8::kBadChar;
120 }
121 // buffer_end_ is a const pointer, but buffer_ is writable.
122 buffer_start[buffer_end_++ - buffer_start] = static_cast<uc16>(value);
123 if (buffer_end_ == buffer_ + kPushBackSize + kBufferSize) break;
124 }
125 return buffer_end_ > buffer_start;
59 } 126 }
60 127
61 virtual void SeekForward(int pos) { 128 virtual unsigned SlowSeekForward(unsigned pos) {
62 // Seeking in the input is not used by preparsing. 129 // Seeking in the input is not used by preparsing.
63 // It's only used by the real parser based on preparser data. 130 // It's only used by the real parser based on preparser data.
64 UNIMPLEMENTED(); 131 UNIMPLEMENTED();
132 return 0;
65 } 133 }
66 134
67 private: 135 private:
136 static const unsigned kBufferSize = 512;
137 static const unsigned kPushBackSize = 16;
68 v8::UnicodeInputStream* const stream_; 138 v8::UnicodeInputStream* const stream_;
139 // Buffer holding first kPushBackSize characters of pushback buffer,
140 // then kBufferSize chars of read-ahead.
141 // The pushback buffer is only used if pushing back characters past
142 // the start of a block.
143 uc16 buffer_[kPushBackSize + kBufferSize];
144 // Limit of pushbacks before new allocation is necessary.
145 uc16* pushback_buffer_;
146 // Only if that pushback buffer at the start of buffer_ isn't sufficient
147 // is the following used.
148 const uc16* pushback_buffer_end_cache_;
149 uc16* pushback_buffer_backing_;
150 unsigned pushback_buffer_backing_size_;
69 }; 151 };
70 152
71 153
72 class StandAloneJavaScriptScanner : public JavaScriptScanner { 154 class StandAloneJavaScriptScanner : public JavaScriptScanner {
73 public: 155 public:
74 void Initialize(UTF16Buffer* source) { 156 void Initialize(UC16CharacterStream* source) {
75 source_ = source; 157 source_ = source;
76 literal_flags_ = kLiteralString | kLiteralIdentifier; 158 literal_flags_ = kLiteralString | kLiteralIdentifier;
77 Init(); 159 Init();
78 // Skip initial whitespace allowing HTML comment ends just like 160 // Skip initial whitespace allowing HTML comment ends just like
79 // after a newline and scan first token. 161 // after a newline and scan first token.
80 has_line_terminator_before_next_ = true; 162 has_line_terminator_before_next_ = true;
81 SkipWhiteSpace(); 163 SkipWhiteSpace();
82 Scan(); 164 Scan();
83 } 165 }
84 }; 166 };
85 167
86 168
87 // Functions declared by allocation.h 169 // Functions declared by allocation.h
88 170
89 void FatalProcessOutOfMemory(const char* reason) { 171 void FatalProcessOutOfMemory(const char* reason) {
90 V8_Fatal(__FILE__, __LINE__, reason); 172 V8_Fatal(__FILE__, __LINE__, reason);
91 } 173 }
92 174
93 bool EnableSlowAsserts() { return true; } 175 bool EnableSlowAsserts() { return true; }
94 176
95
96 } // namespace internal. 177 } // namespace internal.
97 178
98 179
99 UnicodeInputStream::~UnicodeInputStream() { } 180 UnicodeInputStream::~UnicodeInputStream() { }
100 181
101 182
102 PreParserData Preparse(UnicodeInputStream* input, size_t max_stack) { 183 PreParserData Preparse(UnicodeInputStream* input, size_t max_stack) {
103 internal::InputStreamUTF16Buffer buffer(input); 184 internal::InputStreamUTF16Buffer buffer(input);
104 uintptr_t stack_limit = reinterpret_cast<uintptr_t>(&buffer) - max_stack; 185 uintptr_t stack_limit = reinterpret_cast<uintptr_t>(&buffer) - max_stack;
105 internal::StandAloneJavaScriptScanner scanner; 186 internal::StandAloneJavaScriptScanner scanner;
(...skipping 13 matching lines...) Expand all
119 return PreParserData(size, data); 200 return PreParserData(size, data);
120 } 201 }
121 202
122 } // namespace v8. 203 } // namespace v8.
123 204
124 205
125 // Used by ASSERT macros and other immediate exits. 206 // Used by ASSERT macros and other immediate exits.
126 extern "C" void V8_Fatal(const char* file, int line, const char* format, ...) { 207 extern "C" void V8_Fatal(const char* file, int line, const char* format, ...) {
127 exit(EXIT_FAILURE); 208 exit(EXIT_FAILURE);
128 } 209 }
OLDNEW
« no previous file with comments | « src/preparser.cc ('k') | src/profile-generator.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698