OLD | NEW |
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 #include "vm/regexp_assembler_bytecode.h" | 5 #include "vm/regexp_assembler_bytecode.h" |
6 | 6 |
7 #include "vm/regexp_assembler_bytecode_inl.h" | 7 #include "vm/regexp_assembler_bytecode_inl.h" |
8 #include "vm/exceptions.h" | 8 #include "vm/exceptions.h" |
9 #include "vm/object_store.h" | 9 #include "vm/object_store.h" |
10 #include "vm/regexp_bytecodes.h" | 10 #include "vm/regexp_bytecodes.h" |
(...skipping 434 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
445 // BOGUS | 445 // BOGUS |
446 buffer_->Add(0); | 446 buffer_->Add(0); |
447 buffer_->Add(0); | 447 buffer_->Add(0); |
448 buffer_->Add(0); | 448 buffer_->Add(0); |
449 buffer_->Add(0); | 449 buffer_->Add(0); |
450 intptr_t x = buffer_->length(); | 450 intptr_t x = buffer_->length(); |
451 for (intptr_t i = 0; i < x; i++) buffer_->Add(0); | 451 for (intptr_t i = 0; i < x; i++) buffer_->Add(0); |
452 } | 452 } |
453 | 453 |
454 | 454 |
455 static intptr_t Prepare(const JSRegExp& regexp, | 455 static intptr_t Prepare(const RegExp& regexp, |
456 const String& subject, | 456 const String& subject, |
457 Zone* zone) { | 457 Zone* zone) { |
458 bool is_one_byte = subject.IsOneByteString() || | 458 bool is_one_byte = subject.IsOneByteString() || |
459 subject.IsExternalOneByteString(); | 459 subject.IsExternalOneByteString(); |
460 | 460 |
461 if (regexp.bytecode(is_one_byte) == TypedData::null()) { | 461 if (regexp.bytecode(is_one_byte) == TypedData::null()) { |
462 const String& pattern = String::Handle(zone, regexp.pattern()); | 462 const String& pattern = String::Handle(zone, regexp.pattern()); |
463 | 463 |
464 const bool multiline = regexp.is_multi_line(); | 464 const bool multiline = regexp.is_multi_line(); |
465 RegExpCompileData* compile_data = new(zone) RegExpCompileData(); | 465 RegExpCompileData* compile_data = new(zone) RegExpCompileData(); |
466 if (!RegExpParser::ParseRegExp(pattern, multiline, compile_data)) { | 466 if (!RegExpParser::ParseRegExp(pattern, multiline, compile_data)) { |
467 // Parsing failures are handled in the JSRegExp factory constructor. | 467 // Parsing failures are handled in the RegExp factory constructor. |
468 UNREACHABLE(); | 468 UNREACHABLE(); |
469 } | 469 } |
470 | 470 |
471 regexp.set_num_bracket_expressions(compile_data->capture_count); | 471 regexp.set_num_bracket_expressions(compile_data->capture_count); |
472 if (compile_data->simple) { | 472 if (compile_data->simple) { |
473 regexp.set_is_simple(); | 473 regexp.set_is_simple(); |
474 } else { | 474 } else { |
475 regexp.set_is_complex(); | 475 regexp.set_is_complex(); |
476 } | 476 } |
477 | 477 |
478 RegExpEngine::CompilationResult result = | 478 RegExpEngine::CompilationResult result = |
479 RegExpEngine::CompileBytecode(compile_data, regexp, is_one_byte, zone); | 479 RegExpEngine::CompileBytecode(compile_data, regexp, is_one_byte, zone); |
480 ASSERT(result.bytecode != NULL); | 480 ASSERT(result.bytecode != NULL); |
481 ASSERT((regexp.num_registers() == -1) || | 481 ASSERT((regexp.num_registers() == -1) || |
482 (regexp.num_registers() == result.num_registers)); | 482 (regexp.num_registers() == result.num_registers)); |
483 regexp.set_num_registers(result.num_registers); | 483 regexp.set_num_registers(result.num_registers); |
484 regexp.set_bytecode(is_one_byte, *(result.bytecode)); | 484 regexp.set_bytecode(is_one_byte, *(result.bytecode)); |
485 } | 485 } |
486 | 486 |
487 ASSERT(regexp.num_registers() != -1); | 487 ASSERT(regexp.num_registers() != -1); |
488 | 488 |
489 return regexp.num_registers() + | 489 return regexp.num_registers() + |
490 (Smi::Value(regexp.num_bracket_expressions()) + 1) * 2; | 490 (Smi::Value(regexp.num_bracket_expressions()) + 1) * 2; |
491 } | 491 } |
492 | 492 |
493 | 493 |
494 static IrregexpInterpreter::IrregexpResult ExecRaw(const JSRegExp& regexp, | 494 static IrregexpInterpreter::IrregexpResult ExecRaw(const RegExp& regexp, |
495 const String& subject, | 495 const String& subject, |
496 intptr_t index, | 496 intptr_t index, |
497 int32_t* output, | 497 int32_t* output, |
498 intptr_t output_size, | 498 intptr_t output_size, |
499 Zone* zone) { | 499 Zone* zone) { |
500 bool is_one_byte = subject.IsOneByteString() || | 500 bool is_one_byte = subject.IsOneByteString() || |
501 subject.IsExternalOneByteString(); | 501 subject.IsExternalOneByteString(); |
502 | 502 |
503 ASSERT(regexp.num_bracket_expressions() != Smi::null()); | 503 ASSERT(regexp.num_bracket_expressions() != Smi::null()); |
504 | 504 |
(...skipping 25 matching lines...) Expand all Loading... |
530 Isolate* isolate = thread->isolate(); | 530 Isolate* isolate = thread->isolate(); |
531 const Instance& exception = | 531 const Instance& exception = |
532 Instance::Handle(isolate->object_store()->stack_overflow()); | 532 Instance::Handle(isolate->object_store()->stack_overflow()); |
533 Exceptions::Throw(thread, exception); | 533 Exceptions::Throw(thread, exception); |
534 UNREACHABLE(); | 534 UNREACHABLE(); |
535 } | 535 } |
536 return result; | 536 return result; |
537 } | 537 } |
538 | 538 |
539 | 539 |
540 RawInstance* BytecodeRegExpMacroAssembler::Interpret(const JSRegExp& regexp, | 540 RawInstance* BytecodeRegExpMacroAssembler::Interpret(const RegExp& regexp, |
541 const String& subject, | 541 const String& subject, |
542 const Smi& start_index, | 542 const Smi& start_index, |
543 Zone* zone) { | 543 Zone* zone) { |
544 intptr_t required_registers = Prepare(regexp, subject, zone); | 544 intptr_t required_registers = Prepare(regexp, subject, zone); |
545 if (required_registers < 0) { | 545 if (required_registers < 0) { |
546 // Compiling failed with an exception. | 546 // Compiling failed with an exception. |
547 UNREACHABLE(); | 547 UNREACHABLE(); |
548 } | 548 } |
549 | 549 |
550 // V8 uses a shared copy on the isolate when smaller than some threshold. | 550 // V8 uses a shared copy on the isolate when smaller than some threshold. |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
585 } | 585 } |
586 if (result == IrregexpInterpreter::RE_EXCEPTION) { | 586 if (result == IrregexpInterpreter::RE_EXCEPTION) { |
587 UNREACHABLE(); | 587 UNREACHABLE(); |
588 } | 588 } |
589 ASSERT(result == IrregexpInterpreter::RE_FAILURE); | 589 ASSERT(result == IrregexpInterpreter::RE_FAILURE); |
590 return Instance::null(); | 590 return Instance::null(); |
591 } | 591 } |
592 | 592 |
593 | 593 |
594 } // namespace dart | 594 } // namespace dart |
OLD | NEW |