regex ir opt code rewriting, use over-again opt method

This commit is contained in:
Youmu Liu
2026-06-29 17:14:52 +08:00
parent 347d4b5a47
commit e60eb0ada6
6 changed files with 188 additions and 411 deletions
+26 -9
View File
@@ -55,6 +55,15 @@ namespace StgSharp.RegularAnalysis.Text
}
internal interface IRegexComplex
{
bool IsFullyOptimized { get; set; }
int CommandCount { get; set; }
}
internal interface IRegexCount
{
@@ -73,15 +82,17 @@ namespace StgSharp.RegularAnalysis.Text
internal sealed class RegexFindComplexIR(
bool nearest,
int count
) : RegexIR
) : RegexIR, IRegexComplex
{
public bool IsFullyOptimized { get; set; }
public int CommandCount { get; set; } = count;
internal override RegexIRCommand Command => RegexIRCommand.Find_Complex;
private bool IsNearest { get; } = nearest;
private int CommandCount { get; } = count;
internal override string AsCommand(
int lineNum
)
@@ -209,7 +220,7 @@ namespace StgSharp.RegularAnalysis.Text
int max,
bool isGreedy,
int operation
) : RegexIR, IRegexCount
) : RegexIR, IRegexCount, IRegexComplex
{
public bool IsGreedy { get; } = isGreedy;
@@ -218,11 +229,13 @@ namespace StgSharp.RegularAnalysis.Text
public bool IsPlus => Min == 1 && Max < 0;
public bool IsFullyOptimized { get; set; }
public int Min { get; } = min;
public int Max { get; } = max;
public int OperationCount { get; } = operation;
public int CommandCount { get; set; } = operation;
internal override RegexIRCommand Command { get; } = RegexIRCommand.Count_Complex;
@@ -230,7 +243,7 @@ namespace StgSharp.RegularAnalysis.Text
int lineNum
)
{
return $"[{lineNum}]\t COUNT {(IsGreedy ? "GREEDY" : "NON_GREEDY")} MIN: {Min} MAX: {Max} OPERATION: {OperationCount}";
return $"[{lineNum}]\t COUNT {(IsGreedy ? "GREEDY" : "NON_GREEDY")} MIN: {Min} MAX: {Max} OPERATION: {CommandCount}";
}
}
@@ -253,7 +266,7 @@ namespace StgSharp.RegularAnalysis.Text
public int Max { get; } = max;
public string Sequence { get; } = seq;
public string Sequence { get; } = seq.Length == 2 && seq[0] == '\\' ? seq[1..2] : seq;
internal override RegexIRCommand Command { get; } = RegexIRCommand.Count_Seq;
@@ -299,13 +312,17 @@ namespace StgSharp.RegularAnalysis.Text
}
internal sealed class RegexTryIR(
internal sealed class RegexMatchComplexIR(
int count
) : RegexIR
) : RegexIR, IRegexComplex
{
public bool IsFullyOptimized { get; set; }
public int CountOfCommand { get; } = count;
public int CommandCount { get; set; }
internal override RegexIRCommand Command => RegexIRCommand.Try;
internal override string AsCommand(