Skip to content

Commit

Permalink
Use static abstract interface methods in SymbolicRegexMatcher (#63546)
Browse files Browse the repository at this point in the history
  • Loading branch information
stephentoub authored Feb 11, 2022
1 parent 550a11d commit 6df806f
Showing 1 changed file with 7 additions and 5 deletions.
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

0 comments on commit 6df806f

Please sign in to comment.