| OLD | NEW |
| 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 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 222 | 222 |
| 223 bool harmony_numeric_literals_; | 223 bool harmony_numeric_literals_; |
| 224 bool harmony_modules_; | 224 bool harmony_modules_; |
| 225 bool harmony_scoping_; | 225 bool harmony_scoping_; |
| 226 | 226 |
| 227 private: | 227 private: |
| 228 static std::set<ScannerBase*>* scanners_; | 228 static std::set<ScannerBase*>* scanners_; |
| 229 }; | 229 }; |
| 230 | 230 |
| 231 | 231 |
| 232 template<typename YYCTYPE> | 232 template<typename Char> |
| 233 class ExperimentalScanner : public ScannerBase { | 233 class ExperimentalScanner : public ScannerBase { |
| 234 public: | 234 public: |
| 235 explicit ExperimentalScanner( | 235 explicit ExperimentalScanner( |
| 236 Handle<String> source, | 236 Handle<String> source, |
| 237 Isolate* isolate) | 237 Isolate* isolate) |
| 238 : ScannerBase(isolate), | 238 : ScannerBase(isolate), |
| 239 source_handle_(source), | 239 source_handle_(source), |
| 240 buffer_(NULL), | 240 buffer_(NULL), |
| 241 buffer_end_(NULL), | 241 buffer_end_(NULL), |
| 242 start_(NULL), | 242 start_(NULL), |
| 243 cursor_(NULL), | 243 cursor_(NULL), |
| 244 marker_(NULL) { | 244 marker_(NULL) { |
| 245 ASSERT(source->IsFlat()); | 245 ASSERT(source->IsFlat()); |
| 246 SetBufferBasedOnHandle(); | 246 SetBufferBasedOnHandle(); |
| 247 Scan(); | 247 Scan(); |
| 248 } | 248 } |
| 249 | 249 |
| 250 virtual ~ExperimentalScanner() { } | 250 virtual ~ExperimentalScanner() { } |
| 251 | 251 |
| 252 virtual void Scan(); | 252 virtual void Scan(); |
| 253 virtual uc32 ScanHexNumber(int length); | 253 virtual uc32 ScanHexNumber(int length); |
| 254 | 254 |
| 255 virtual void SetBufferBasedOnHandle() { | 255 virtual void SetBufferBasedOnHandle() { |
| 256 // We get a raw pointer from the Handle, but we also update it every time | 256 // We get a raw pointer from the Handle, but we also update it every time |
| 257 // there is a GC, so it is safe. | 257 // there is a GC, so it is safe. |
| 258 DisallowHeapAllocation no_gc; | 258 DisallowHeapAllocation no_gc; |
| 259 const YYCTYPE* new_buffer = GetNewBufferBasedOnHandle(); | 259 const Char* new_buffer = GetNewBufferBasedOnHandle(); |
| 260 if (new_buffer != buffer_) { | 260 if (new_buffer != buffer_) { |
| 261 int start_offset = start_ - buffer_; | 261 int start_offset = start_ - buffer_; |
| 262 int cursor_offset = cursor_ - buffer_; | 262 int cursor_offset = cursor_ - buffer_; |
| 263 int marker_offset = marker_ - buffer_; | 263 int marker_offset = marker_ - buffer_; |
| 264 buffer_ = new_buffer; | 264 buffer_ = new_buffer; |
| 265 buffer_end_ = buffer_ + source_handle_->length(); | 265 buffer_end_ = buffer_ + source_handle_->length(); |
| 266 start_ = buffer_ + start_offset; | 266 start_ = buffer_ + start_offset; |
| 267 cursor_ = buffer_ + cursor_offset; | 267 cursor_ = buffer_ + cursor_offset; |
| 268 marker_ = buffer_ + marker_offset; | 268 marker_ = buffer_ + marker_offset; |
| 269 } | 269 } |
| 270 } | 270 } |
| 271 | 271 |
| 272 const YYCTYPE* GetNewBufferBasedOnHandle() const; | 272 const Char* GetNewBufferBasedOnHandle() const; |
| 273 | 273 |
| 274 private: | 274 private: |
| 275 Handle<String> source_handle_; | 275 Handle<String> source_handle_; |
| 276 const YYCTYPE* buffer_; | 276 const Char* buffer_; |
| 277 const YYCTYPE* buffer_end_; | 277 const Char* buffer_end_; |
| 278 const YYCTYPE* start_; | 278 const Char* start_; |
| 279 const YYCTYPE* cursor_; | 279 const Char* cursor_; |
| 280 const YYCTYPE* marker_; | 280 const Char* marker_; |
| 281 }; | 281 }; |
| 282 | 282 |
| 283 | 283 |
| 284 template<typename YYCTYPE> | 284 template<typename Char> |
| 285 uc32 ExperimentalScanner<YYCTYPE>::ScanHexNumber(int length) { | 285 uc32 ExperimentalScanner<Char>::ScanHexNumber(int length) { |
| 286 // We have seen \uXXXX, let's see what it is. | 286 // We have seen \uXXXX, let's see what it is. |
| 287 // FIXME: we never end up in here if only a subset of the 4 chars are valid | 287 // FIXME: we never end up in here if only a subset of the 4 chars are valid |
| 288 // hex digits -> handle the case where they're not. | 288 // hex digits -> handle the case where they're not. |
| 289 uc32 x = 0; | 289 uc32 x = 0; |
| 290 for (const YYCTYPE* s = cursor_ - length; s != cursor_; ++s) { | 290 for (const Char* s = cursor_ - length; s != cursor_; ++s) { |
| 291 int d = HexValue(*s); | 291 int d = HexValue(*s); |
| 292 if (d < 0) { | 292 if (d < 0) { |
| 293 return -1; | 293 return -1; |
| 294 } | 294 } |
| 295 x = x * 16 + d; | 295 x = x * 16 + d; |
| 296 } | 296 } |
| 297 return x; | 297 return x; |
| 298 } | 298 } |
| 299 | 299 |
| 300 | 300 |
| 301 } } | 301 } } |
| 302 | 302 |
| 303 #endif // V8_LEXER_EXPERIMENTAL_SCANNER_H | 303 #endif // V8_LEXER_EXPERIMENTAL_SCANNER_H |
| OLD | NEW |