Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use static abstract interface methods in SymbolicRegexMatcher #63546

Merged
merged 2 commits into from
Feb 11, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -238,8 +238,10 @@ internal SymbolicRegexMatcher(SymbolicRegexNode<TSetType> sr, RegexCode code, Ch
/// <summary>Interface for transitions used by the <see cref="Delta"/> method.</summary>
private interface ITransition
{
#pragma warning disable CA2252 // This API requires opting into preview features
/// <summary>Find the next state given the current state and next character.</summary>
DfaMatchingState<TSetType> TakeTransition(SymbolicRegexMatcher<TSetType> matcher, DfaMatchingState<TSetType> currentState, int mintermId, TSetType minterm);
static abstract DfaMatchingState<TSetType> TakeTransition(SymbolicRegexMatcher<TSetType> matcher, DfaMatchingState<TSetType> currentState, int mintermId, TSetType minterm);
#pragma warning restore CA2252
}

/// <summary>Compute the target state for the source state and input[i] character.</summary>
Expand All @@ -262,14 +264,14 @@ private DfaMatchingState<TSetType> Delta<TTransition>(ReadOnlySpan<char> input,
minterms[mintermId] :
_builder._solver.False; // minterm=False represents \Z

return default(TTransition).TakeTransition(this, sourceState, mintermId, minterm);
return TTransition.TakeTransition(this, sourceState, mintermId, minterm);
}

/// <summary>Transition for Brzozowski-style derivatives (i.e. a DFA).</summary>
private readonly struct BrzozowskiTransition : ITransition
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public DfaMatchingState<TSetType> TakeTransition(
public static DfaMatchingState<TSetType> TakeTransition(
SymbolicRegexMatcher<TSetType> matcher, DfaMatchingState<TSetType> currentState, int mintermId, TSetType minterm)
{
SymbolicRegexBuilder<TSetType> builder = matcher._builder;
Expand All @@ -284,13 +286,13 @@ public DfaMatchingState<TSetType> TakeTransition(
private readonly struct AntimirovTransition : ITransition
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public DfaMatchingState<TSetType> TakeTransition(
public static DfaMatchingState<TSetType> TakeTransition(
SymbolicRegexMatcher<TSetType> matcher, DfaMatchingState<TSetType> currentStates, int mintermId, TSetType minterm)
{
if (currentStates.Node.Kind != SymbolicRegexKind.Or)
{
// Fall back to Brzozowski when the state is not a disjunction.
return default(BrzozowskiTransition).TakeTransition(matcher, currentStates, mintermId, minterm);
return BrzozowskiTransition.TakeTransition(matcher, currentStates, mintermId, minterm);
}

SymbolicRegexBuilder<TSetType> builder = matcher._builder;
Expand Down