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

Side by Side Diff: src/lexer/lexer.h

Issue 201613002: Experimental parser: allocate substrings (Closed) Base URL: https://v8.googlecode.com/svn/branches/experimental/parser
Patch Set: Created 6 years, 9 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 | « no previous file | src/lexer/lexer.cc » ('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 2013 the V8 project authors. All rights reserved. 1 // Copyright 2013 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 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
166 return next_literal_->is_one_byte(); 166 return next_literal_->is_one_byte();
167 } 167 }
168 168
169 bool is_next_contextual_keyword(Vector<const uint8_t> keyword) { 169 bool is_next_contextual_keyword(Vector<const uint8_t> keyword) {
170 if (!is_next_literal_one_byte()) return false; 170 if (!is_next_literal_one_byte()) return false;
171 Vector<const uint8_t> literal = next_literal_one_byte_string(); 171 Vector<const uint8_t> literal = next_literal_one_byte_string();
172 return literal.length() == keyword.length() && 172 return literal.length() == keyword.length() &&
173 (memcmp(literal.start(), keyword.start(), literal.length()) == 0); 173 (memcmp(literal.start(), keyword.start(), literal.length()) == 0);
174 } 174 }
175 175
176 Handle<String> AllocateNextLiteralString(Isolate* isolate, 176 virtual Handle<String> AllocateNextLiteralString(Isolate* isolate,
177 PretenureFlag tenured); 177 PretenureFlag tenured) = 0;
178 Handle<String> AllocateInternalizedString(Isolate* isolate); 178 virtual Handle<String> AllocateInternalizedString(Isolate* isolate) = 0;
179 179
180 double DoubleValue(); 180 double DoubleValue();
181 bool UnescapedLiteralMatches(const char* data, int length) { 181 bool UnescapedLiteralMatches(const char* data, int length) {
182 if (is_literal_one_byte() && 182 if (is_literal_one_byte() &&
183 literal_length() == length && 183 literal_length() == length &&
184 !literal_contains_escapes()) { 184 !literal_contains_escapes()) {
185 const char* token = 185 const char* token =
186 reinterpret_cast<const char*>(literal_one_byte_string().start()); 186 reinterpret_cast<const char*>(literal_one_byte_string().start());
187 return !strncmp(token, data, length); 187 return !strncmp(token, data, length);
188 } 188 }
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
240 is_in_buffer_(false), 240 is_in_buffer_(false),
241 is_one_byte_string_owned_(false) // TODO(dcarney): move to buffer 241 is_one_byte_string_owned_(false) // TODO(dcarney): move to buffer
242 { } 242 { }
243 243
244 ~LiteralDesc() { 244 ~LiteralDesc() {
245 if (is_one_byte_string_owned_) { 245 if (is_one_byte_string_owned_) {
246 one_byte_string_.Dispose(); 246 one_byte_string_.Dispose();
247 } 247 }
248 } 248 }
249 249
250 inline bool is_in_buffer() { return is_in_buffer_; }
250 inline bool is_one_byte() { return is_one_byte_; } 251 inline bool is_one_byte() { return is_one_byte_; }
251 inline Vector<const uint8_t> one_byte_string() { 252 inline Vector<const uint8_t> one_byte_string() {
252 ASSERT(is_one_byte_); 253 ASSERT(is_one_byte_);
253 return one_byte_string_; 254 return one_byte_string_;
254 } 255 }
255 inline Vector<const uint16_t> two_byte_string() { 256 inline Vector<const uint16_t> two_byte_string() {
256 ASSERT(!is_one_byte_); 257 ASSERT(!is_one_byte_);
257 return two_byte_string_; 258 return two_byte_string_;
258 } 259 }
259 260
260 inline bool Valid(int pos) { return beg_pos == pos; } 261 inline bool Valid(int pos) { return beg_pos == pos; }
261 inline void Invalidate() { if (is_in_buffer_) beg_pos = -1; } 262 inline void Invalidate() {
263 if (!is_in_buffer_ && !is_one_byte_string_owned_) beg_pos = -1;
264 }
262 265
263 // TODO(dcarney): make private as well. 266 // TODO(dcarney): make private as well.
264 int beg_pos; 267 int beg_pos;
265 int offset; 268 int offset;
266 int length; 269 int length;
267 LiteralBuffer buffer; 270 LiteralBuffer buffer;
268 271
269 void SetOneByteString(Vector<const uint8_t> string, bool owned); 272 void SetOneByteString(Vector<const uint8_t> string, bool owned);
270 void SetTwoByteString(Vector<const uint16_t> string); 273 void SetTwoByteString(Vector<const uint16_t> string);
271 void SetStringFromLiteralBuffer(); 274 void SetStringFromLiteralBuffer();
272 275
273 private: 276 private:
274 bool is_one_byte_; 277 bool is_one_byte_;
275 bool is_in_buffer_; 278 bool is_in_buffer_;
276 bool is_one_byte_string_owned_; 279 bool is_one_byte_string_owned_;
277 Vector<const uint8_t> one_byte_string_; 280 Vector<const uint8_t> one_byte_string_;
278 Vector<const uint16_t> two_byte_string_; 281 Vector<const uint16_t> two_byte_string_;
279 282
280 DISALLOW_COPY_AND_ASSIGN(LiteralDesc); 283 DISALLOW_COPY_AND_ASSIGN(LiteralDesc);
281 }; 284 };
282 285
283 protected:
284 struct TokenDesc { 286 struct TokenDesc {
285 int beg_pos; 287 int beg_pos;
286 int end_pos; 288 int end_pos;
287 Token::Value token; 289 Token::Value token;
288 bool has_escapes; 290 bool has_escapes;
289 bool is_onebyte; 291 bool is_in_primary_range;
290 }; 292 };
291 293
294 protected:
292 virtual void Scan() = 0; 295 virtual void Scan() = 0;
293 virtual void UpdateBufferBasedOnHandle() = 0; 296 virtual void UpdateBufferBasedOnHandle() = 0;
294 virtual bool FillLiteral(const TokenDesc& token, LiteralDesc* literal) = 0; 297 virtual bool FillLiteral(const TokenDesc& token, LiteralDesc* literal) = 0;
295 virtual Handle<String> InternalizeLiteral(LiteralDesc* literal) = 0; 298
296 virtual Handle<String> AllocateLiteral(LiteralDesc* literal, 299 void EnsureLiteralIsValid(const TokenDesc& token, LiteralDesc* literal) {
297 PretenureFlag tenured) = 0; 300 if (!literal->Valid(token.beg_pos)) FillLiteral(token, literal);
301 }
298 302
299 void EnsureCurrentLiteralIsValid() { 303 void EnsureCurrentLiteralIsValid() {
300 if (!current_literal_->Valid(current_.beg_pos)) { 304 EnsureLiteralIsValid(current_, current_literal_);
301 FillLiteral(current_, current_literal_);
302 }
303 } 305 }
304 306
305 void EnsureNextLiteralIsValid() { 307 void EnsureNextLiteralIsValid() {
306 if (!next_literal_->Valid(next_.beg_pos)) { 308 EnsureLiteralIsValid(next_, next_literal_);
307 FillLiteral(next_, next_literal_);
308 }
309 } 309 }
310 310
311 UnicodeCache* unicode_cache_; 311 UnicodeCache* unicode_cache_;
312 LiteralDesc* current_literal_; 312 LiteralDesc* current_literal_;
313 LiteralDesc* next_literal_; 313 LiteralDesc* next_literal_;
314 LiteralDesc literals_[2]; 314 LiteralDesc literals_[2];
315 315
316 TokenDesc current_; // desc for current token (as returned by Next()) 316 TokenDesc current_; // desc for current token (as returned by Next())
317 TokenDesc next_; // desc for next token (one token look-ahead) 317 TokenDesc next_; // desc for next token (one token look-ahead)
318 318
(...skipping 20 matching lines...) Expand all
339 int end_position); 339 int end_position);
340 Lexer(UnicodeCache* unicode_cache, const Char* source_ptr, int length); 340 Lexer(UnicodeCache* unicode_cache, const Char* source_ptr, int length);
341 virtual ~Lexer(); 341 virtual ~Lexer();
342 342
343 virtual void SeekForward(int pos); 343 virtual void SeekForward(int pos);
344 virtual bool ScanRegExpPattern(bool seen_equal); 344 virtual bool ScanRegExpPattern(bool seen_equal);
345 virtual bool ScanRegExpFlags(); 345 virtual bool ScanRegExpFlags();
346 virtual Location octal_position() const; 346 virtual Location octal_position() const;
347 virtual void clear_octal_position() { last_octal_end_ = NULL; } 347 virtual void clear_octal_position() { last_octal_end_ = NULL; }
348 348
349 static inline bool MustBeInBuffer(const TokenDesc& token) {
350 return token.has_escapes ||
351 (sizeof(Char) == 1 && !token.is_in_primary_range);
352 }
353
349 protected: 354 protected:
350 virtual void Scan(); 355 virtual void Scan();
351 356
352 private: 357 private:
353 uc32 ScanHexNumber(int length); 358 uc32 ScanHexNumber(int length);
354 359
355 bool ScanLiteralUnicodeEscape(); 360 bool ScanLiteralUnicodeEscape();
356 361
357 const Char* GetNewBufferBasedOnHandle() const; 362 const Char* GetNewBufferBasedOnHandle() const;
358 virtual void UpdateBufferBasedOnHandle(); 363 virtual void UpdateBufferBasedOnHandle();
359 364
360 virtual bool FillLiteral(const TokenDesc& token, LiteralDesc* literal); 365 virtual bool FillLiteral(const TokenDesc& token, LiteralDesc* literal);
361 virtual Handle<String> InternalizeLiteral(LiteralDesc* literal); 366
362 virtual Handle<String> AllocateLiteral(LiteralDesc* literal, 367 virtual Handle<String> AllocateNextLiteralString(Isolate* isolate,
363 PretenureFlag tenured); 368 PretenureFlag tenured);
369 virtual Handle<String> AllocateInternalizedString(Isolate* isolate);
364 370
365 // Helper function for FillLiteral. 371 // Helper function for FillLiteral.
366 template<bool is_one_byte> 372 template<bool is_one_byte>
367 static void SetLiteral( 373 static void SetLiteral(const Char* start, LiteralDesc* literal);
368 const Char* start, const Char* end, LiteralDesc* literal);
369 374
370 bool CopyToLiteralBuffer(const Char* start, 375 bool CopyToLiteralBuffer(const TokenDesc& token,
371 const Char* end,
372 const TokenDesc& token,
373 LiteralDesc* literal); 376 LiteralDesc* literal);
374 377
375 // One of source_handle_ or source_ptr_ is set. 378 // One of source_handle_ or source_ptr_ is set.
376 // If source_ptr_ is set, isolate_ is 0 and no isolate accesses are allowed. 379 // If source_ptr_ is set, isolate_ is 0 and no isolate accesses are allowed.
377 Isolate* isolate_; 380 Isolate* isolate_;
378 const Handle<String> source_handle_; 381 const Handle<String> source_handle_;
379 const Char* const source_ptr_; 382 const Char* const source_ptr_;
380 const int end_position_; 383 const int end_position_;
381 // Stream variables. 384 // Stream variables.
382 const Char* buffer_; 385 const Char* buffer_;
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
511 bool harmony_scoping_; 514 bool harmony_scoping_;
512 }; 515 };
513 516
514 517
515 #endif 518 #endif
516 519
517 520
518 } } 521 } }
519 522
520 #endif // V8_LEXER_EXPERIMENTAL_SCANNER_H 523 #endif // V8_LEXER_EXPERIMENTAL_SCANNER_H
OLDNEW
« no previous file with comments | « no previous file | src/lexer/lexer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698