1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 01:17:35 +00:00

LibRegex: Preserve capture groups and matches across ForkReplace

This makes the (flawed) ForkStay inserted as a loop header unnecessary,
and finally fixes LibRegex rewriting weird loops in weird ways.
This commit is contained in:
Ali Mohammad Pur 2022-01-21 23:45:33 +03:30 committed by Linus Groh
parent bc20e4f71d
commit cd83325c7c
2 changed files with 2 additions and 10 deletions

View file

@ -449,6 +449,8 @@ Optional<bool> Matcher<Parser>::execute(MatchInput const& input, MatchState& sta
(*it) = state; (*it) = state;
it->instruction_position = state.fork_at_position; it->instruction_position = state.fork_at_position;
it->initiating_fork = *input.fork_to_replace; it->initiating_fork = *input.fork_to_replace;
it->capture_group_matches = state.capture_group_matches;
it->matches = state.matches;
found = true; found = true;
break; break;
} }

View file

@ -223,7 +223,6 @@ void Regex<Parser>::attempt_rewrite_loops_as_atomic_groups(BasicBlockList const&
// ------------------------- // -------------------------
// bb1 | RE1 // bb1 | RE1
// can be rewritten as: // can be rewritten as:
// loop.hdr | ForkStay bb1 (if RE1 matches _something_, empty otherwise)
// ------------------------- // -------------------------
// bb0 | RE0 // bb0 | RE0
// | ForkReplaceX bb0 // | ForkReplaceX bb0
@ -371,15 +370,6 @@ void Regex<Parser>::attempt_rewrite_loops_as_atomic_groups(BasicBlockList const&
} else { } else {
VERIFY_NOT_REACHED(); VERIFY_NOT_REACHED();
} }
if (candidate.form == AlternateForm::DirectLoopWithoutHeader) {
if (candidate.new_target_block.has_value()) {
// Insert a fork-stay targeted at the second block.
bytecode.insert(candidate.forking_block.start, (ByteCodeValueType)OpCodeId::ForkStay);
bytecode.insert(candidate.forking_block.start + 1, candidate.new_target_block->start - candidate.forking_block.start + 2);
needed_patches.insert(candidate.forking_block.start, 2u);
}
}
} }
if (!needed_patches.is_empty()) { if (!needed_patches.is_empty()) {