| OLD | NEW |
| 1 // Copyright 2006-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2008 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 323 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 334 | 334 |
| 335 // ---------------------------------------------------------------------------- | 335 // ---------------------------------------------------------------------------- |
| 336 // Scanner | 336 // Scanner |
| 337 | 337 |
| 338 Scanner::Scanner(ParserMode pre) | 338 Scanner::Scanner(ParserMode pre) |
| 339 : is_pre_parsing_(pre == PREPARSE), stack_overflow_(false) { } | 339 : is_pre_parsing_(pre == PREPARSE), stack_overflow_(false) { } |
| 340 | 340 |
| 341 | 341 |
| 342 void Scanner::Initialize(Handle<String> source, | 342 void Scanner::Initialize(Handle<String> source, |
| 343 ParserLanguage language) { | 343 ParserLanguage language) { |
| 344 safe_string_input_buffer_.Reset(source.location()); | 344 Init(source, NULL, 0, source->length(), language); |
| 345 Init(source, &safe_string_input_buffer_, 0, source->length(), language); | |
| 346 } | 345 } |
| 347 | 346 |
| 348 | 347 |
| 349 void Scanner::Initialize(Handle<String> source, | 348 void Scanner::Initialize(Handle<String> source, |
| 350 unibrow::CharacterStream* stream, | 349 unibrow::CharacterStream* stream, |
| 351 ParserLanguage language) { | 350 ParserLanguage language) { |
| 352 Init(source, stream, 0, kNoEndPosition, language); | 351 Init(source, stream, 0, kNoEndPosition, language); |
| 353 } | 352 } |
| 354 | 353 |
| 355 | 354 |
| 356 void Scanner::Initialize(Handle<String> source, | 355 void Scanner::Initialize(Handle<String> source, |
| 357 int start_position, | 356 int start_position, |
| 358 int end_position, | 357 int end_position, |
| 359 ParserLanguage language) { | 358 ParserLanguage language) { |
| 360 safe_string_input_buffer_.Reset(source.location()); | 359 Init(source, NULL, start_position, end_position, language); |
| 361 Init(source, &safe_string_input_buffer_, | |
| 362 start_position, end_position, language); | |
| 363 } | 360 } |
| 364 | 361 |
| 365 | 362 |
| 366 void Scanner::Init(Handle<String> source, | 363 void Scanner::Init(Handle<String> source, |
| 367 unibrow::CharacterStream* stream, | 364 unibrow::CharacterStream* stream, |
| 368 int start_position, | 365 int start_position, |
| 369 int end_position, | 366 int end_position, |
| 370 ParserLanguage language) { | 367 ParserLanguage language) { |
| 368 // Either initialize the scanner from a character stream or from a |
| 369 // string. |
| 370 ASSERT(source.is_null() || stream == NULL); |
| 371 |
| 371 // Initialize the source buffer. | 372 // Initialize the source buffer. |
| 372 if (!source.is_null() && StringShape(*source).IsExternalTwoByte()) { | 373 if (!source.is_null() && StringShape(*source).IsExternalTwoByte()) { |
| 373 two_byte_string_buffer_.Initialize( | 374 two_byte_string_buffer_.Initialize( |
| 374 Handle<ExternalTwoByteString>::cast(source), | 375 Handle<ExternalTwoByteString>::cast(source), |
| 375 start_position, | 376 start_position, |
| 376 end_position); | 377 end_position); |
| 377 source_ = &two_byte_string_buffer_; | 378 source_ = &two_byte_string_buffer_; |
| 378 } else if (!source.is_null() && StringShape(*source).IsExternalAscii()) { | 379 } else if (!source.is_null() && StringShape(*source).IsExternalAscii()) { |
| 379 ascii_string_buffer_.Initialize( | 380 ascii_string_buffer_.Initialize( |
| 380 Handle<ExternalAsciiString>::cast(source), | 381 Handle<ExternalAsciiString>::cast(source), |
| 381 start_position, | 382 start_position, |
| 382 end_position); | 383 end_position); |
| 383 source_ = &ascii_string_buffer_; | 384 source_ = &ascii_string_buffer_; |
| 384 } else { | 385 } else { |
| 386 if (!source.is_null()) { |
| 387 safe_string_input_buffer_.Reset(source.location()); |
| 388 stream = &safe_string_input_buffer_; |
| 389 } |
| 385 char_stream_buffer_.Initialize(source, | 390 char_stream_buffer_.Initialize(source, |
| 386 stream, | 391 stream, |
| 387 start_position, | 392 start_position, |
| 388 end_position); | 393 end_position); |
| 389 source_ = &char_stream_buffer_; | 394 source_ = &char_stream_buffer_; |
| 390 } | 395 } |
| 391 | 396 |
| 392 is_parsing_json_ = (language == JSON); | 397 is_parsing_json_ = (language == JSON); |
| 393 | 398 |
| 394 // Set c0_ (one character ahead) | 399 // Set c0_ (one character ahead) |
| (...skipping 937 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1332 } | 1337 } |
| 1333 AddCharAdvance(); | 1338 AddCharAdvance(); |
| 1334 } | 1339 } |
| 1335 TerminateLiteral(); | 1340 TerminateLiteral(); |
| 1336 | 1341 |
| 1337 next_.location.end_pos = source_pos() - 1; | 1342 next_.location.end_pos = source_pos() - 1; |
| 1338 return true; | 1343 return true; |
| 1339 } | 1344 } |
| 1340 | 1345 |
| 1341 } } // namespace v8::internal | 1346 } } // namespace v8::internal |
| OLD | NEW |