@@ -650,7 +650,7 @@ string ReserveName(string prefix)
650
650
var additionalDeclarations = new HashSet < string > ( ) ;
651
651
652
652
// Declare some locals.
653
- string textSpanLocal = "localSpan " ;
653
+ string sliceSpan = "slice " ;
654
654
writer . WriteLine ( "global::System.ReadOnlySpan<char> runtextSpan = base.runtext;" ) ;
655
655
writer . WriteLine ( "int runtextpos = base.runtextpos;" ) ;
656
656
writer . WriteLine ( "int runtextend = base.runtextend;" ) ;
@@ -714,7 +714,7 @@ void LoadTextSpanLocal(IndentedTextWriter writer, bool defineLocal = false)
714
714
{
715
715
writer . Write ( "global::System.ReadOnlySpan<char> " ) ;
716
716
}
717
- writer . WriteLine ( $ "{ textSpanLocal } = runtextSpan.Slice(runtextpos, runtextend - runtextpos);") ;
717
+ writer . WriteLine ( $ "{ sliceSpan } = runtextSpan.Slice(runtextpos, runtextend - runtextpos);") ;
718
718
}
719
719
720
720
// Emits the sum of a constant and a value from a local.
@@ -734,16 +734,16 @@ void EmitSpanLengthCheck(int requiredLength, string? dynamicRequiredLength = nul
734
734
}
735
735
736
736
string SpanLengthCheck ( int requiredLength , string ? dynamicRequiredLength = null ) =>
737
- $ "(uint){ textSpanLocal } .Length < { Sum ( textSpanPos + requiredLength , dynamicRequiredLength ) } ";
737
+ $ "(uint){ sliceSpan } .Length < { Sum ( textSpanPos + requiredLength , dynamicRequiredLength ) } ";
738
738
739
- // Adds the value of textSpanPos into the runtextpos local, slices localSpan by the corresponding amount,
739
+ // Adds the value of textSpanPos into the runtextpos local, slices slice by the corresponding amount,
740
740
// and zeros out textSpanPos.
741
741
void TransferTextSpanPosToRunTextPos ( )
742
742
{
743
743
if ( textSpanPos > 0 )
744
744
{
745
745
EmitAdd ( writer , "runtextpos" , textSpanPos ) ;
746
- writer . WriteLine ( $ "{ textSpanLocal } = { textSpanLocal } .Slice({ textSpanPos } );") ;
746
+ writer . WriteLine ( $ "{ sliceSpan } = { sliceSpan } .Slice({ textSpanPos } );") ;
747
747
textSpanPos = 0 ;
748
748
}
749
749
}
@@ -815,7 +815,7 @@ void EmitSwitchedBranches()
815
815
EmitSpanLengthCheck ( 1 ) ;
816
816
writer . WriteLine ( ) ;
817
817
818
- using ( EmitBlock ( writer , $ "switch ({ ToLowerIfNeeded ( hasTextInfo , options , $ "{ textSpanLocal } [{ textSpanPos ++ } ]", IsCaseInsensitive ( node ) ) } )") )
818
+ using ( EmitBlock ( writer , $ "switch ({ ToLowerIfNeeded ( hasTextInfo , options , $ "{ sliceSpan } [{ textSpanPos ++ } ]", IsCaseInsensitive ( node ) ) } )") )
819
819
{
820
820
int startingTextSpanPos = textSpanPos ;
821
821
for ( int i = 0 ; i < childCount ; i ++ )
@@ -987,7 +987,7 @@ void EmitAllBranches()
987
987
988
988
// Reset state for next branch and loop around to generate it. This includes
989
989
// setting runtextpos back to what it was at the beginning of the alternation,
990
- // updating localSpan to be the full length it was, and if there's a capture that
990
+ // updating slice to be the full length it was, and if there's a capture that
991
991
// needs to be reset, uncapturing it.
992
992
if ( ! isLastBranch )
993
993
{
@@ -1051,7 +1051,7 @@ void EmitBackreference(RegexNode node)
1051
1051
{
1052
1052
string matchLength = ReserveName ( "backreference_matchLength" ) ;
1053
1053
writer . WriteLine ( $ "int { matchLength } = base.MatchLength({ capnum } );") ;
1054
- using ( EmitBlock ( writer , $ "if ({ textSpanLocal } .Length < { matchLength } )") )
1054
+ using ( EmitBlock ( writer , $ "if ({ sliceSpan } .Length < { matchLength } )") )
1055
1055
{
1056
1056
writer . WriteLine ( $ "goto { doneLabel } ;") ;
1057
1057
}
@@ -1063,7 +1063,7 @@ void EmitBackreference(RegexNode node)
1063
1063
string i = ReserveName ( "backreference_iteration" ) ;
1064
1064
using ( EmitBlock ( writer , $ "for (int { i } = 0; { i } < { matchLength } ; { i } ++)") )
1065
1065
{
1066
- using ( EmitBlock ( writer , $ "if ({ ToLowerIfNeeded ( hasTextInfo , options , $ "runtextSpan[{ matchIndex } + { i } ]", IsCaseInsensitive ( node ) ) } != { ToLowerIfNeeded ( hasTextInfo , options , $ "{ textSpanLocal } [{ i } ]", IsCaseInsensitive ( node ) ) } )") )
1066
+ using ( EmitBlock ( writer , $ "if ({ ToLowerIfNeeded ( hasTextInfo , options , $ "runtextSpan[{ matchIndex } + { i } ]", IsCaseInsensitive ( node ) ) } != { ToLowerIfNeeded ( hasTextInfo , options , $ "{ sliceSpan } [{ i } ]", IsCaseInsensitive ( node ) ) } )") )
1067
1067
{
1068
1068
writer . WriteLine ( $ "goto { doneLabel } ;") ;
1069
1069
}
@@ -1747,7 +1747,7 @@ void EmitSingleChar(RegexNode node, bool emitLengthCheck = true, string? offset
1747
1747
// to generate the code for a single check, so we map those looping constructs to the
1748
1748
// appropriate single check.
1749
1749
1750
- string expr = $ "{ textSpanLocal } [{ Sum ( textSpanPos , offset ) } ]";
1750
+ string expr = $ "{ sliceSpan } [{ Sum ( textSpanPos , offset ) } ]";
1751
1751
1752
1752
if ( node . IsSetFamily )
1753
1753
{
@@ -1830,14 +1830,14 @@ void EmitAnchors(RegexNode node)
1830
1830
case RegexNode . Bol :
1831
1831
if ( textSpanPos > 0 )
1832
1832
{
1833
- using ( EmitBlock ( writer , $ "if ({ textSpanLocal } [{ textSpanPos - 1 } ] != '\\ n')") )
1833
+ using ( EmitBlock ( writer , $ "if ({ sliceSpan } [{ textSpanPos - 1 } ] != '\\ n')") )
1834
1834
{
1835
1835
writer . WriteLine ( $ "goto { doneLabel } ;") ;
1836
1836
}
1837
1837
}
1838
1838
else
1839
1839
{
1840
- // We can't use our localSpan in this case, because we'd need to access localSpan [-1], so we access the runtextSpan field directly:
1840
+ // We can't use our slice in this case, because we'd need to access slice [-1], so we access the runtextSpan field directly:
1841
1841
using ( EmitBlock ( writer , $ "if (runtextpos > runtextbeg && runtextSpan[runtextpos - 1] != '\\ n')") )
1842
1842
{
1843
1843
writer . WriteLine ( $ "goto { doneLabel } ;") ;
@@ -1846,22 +1846,22 @@ void EmitAnchors(RegexNode node)
1846
1846
break ;
1847
1847
1848
1848
case RegexNode . End :
1849
- using ( EmitBlock ( writer , $ "if ({ textSpanLocal } .Length > { textSpanPos } )") )
1849
+ using ( EmitBlock ( writer , $ "if ({ sliceSpan } .Length > { textSpanPos } )") )
1850
1850
{
1851
1851
writer . WriteLine ( $ "goto { doneLabel } ;") ;
1852
1852
}
1853
1853
break ;
1854
1854
1855
1855
case RegexNode . EndZ :
1856
- writer . WriteLine ( $ "if ({ textSpanPos } < { textSpanLocal } .Length - 1 || ({ textSpanPos } < { textSpanLocal } .Length && { textSpanLocal } [{ textSpanPos } ] != '\\ n'))") ;
1856
+ writer . WriteLine ( $ "if ({ textSpanPos } < { sliceSpan } .Length - 1 || ({ textSpanPos } < { sliceSpan } .Length && { sliceSpan } [{ textSpanPos } ] != '\\ n'))") ;
1857
1857
using ( EmitBlock ( writer , null ) )
1858
1858
{
1859
1859
writer . WriteLine ( $ "goto { doneLabel } ;") ;
1860
1860
}
1861
1861
break ;
1862
1862
1863
1863
case RegexNode . Eol :
1864
- using ( EmitBlock ( writer , $ "if ({ textSpanPos } < { textSpanLocal } .Length && { textSpanLocal } [{ textSpanPos } ] != '\\ n')") )
1864
+ using ( EmitBlock ( writer , $ "if ({ textSpanPos } < { sliceSpan } .Length && { sliceSpan } [{ textSpanPos } ] != '\\ n')") )
1865
1865
{
1866
1866
writer . WriteLine ( $ "goto { doneLabel } ;") ;
1867
1867
}
@@ -1890,15 +1890,15 @@ void EmitMultiChar(RegexNode node, bool emitLengthCheck = true)
1890
1890
if ( useMultiCharReads )
1891
1891
{
1892
1892
additionalDeclarations . Add ( "global::System.ReadOnlySpan<byte> byteSpan;" ) ;
1893
- writer . WriteLine ( $ "byteSpan = global::System.Runtime.InteropServices.MemoryMarshal.AsBytes({ textSpanLocal } );") ;
1893
+ writer . WriteLine ( $ "byteSpan = global::System.Runtime.InteropServices.MemoryMarshal.AsBytes({ sliceSpan } );") ;
1894
1894
}
1895
1895
1896
1896
writer . Write ( "if (" ) ;
1897
1897
1898
1898
bool emittedFirstCheck = false ;
1899
1899
if ( emitLengthCheck )
1900
1900
{
1901
- writer . Write ( $ "(uint){ textSpanLocal } .Length < { textSpanPos + str . Length } ") ;
1901
+ writer . Write ( $ "(uint){ sliceSpan } .Length < { textSpanPos + str . Length } ") ;
1902
1902
emittedFirstCheck = true ;
1903
1903
}
1904
1904
@@ -1937,7 +1937,7 @@ void EmitOr()
1937
1937
for ( int i = ( str . Length * sizeof ( char ) - byteStr . Length ) / sizeof ( char ) ; i < str . Length ; i ++ )
1938
1938
{
1939
1939
EmitOr ( ) ;
1940
- writer . Write ( $ "{ ToLowerIfNeeded ( hasTextInfo , options , $ "{ textSpanLocal } [{ textSpanPos } ]", caseInsensitive ) } != { Literal ( str [ i ] ) } ") ;
1940
+ writer . Write ( $ "{ ToLowerIfNeeded ( hasTextInfo , options , $ "{ sliceSpan } [{ textSpanPos } ]", caseInsensitive ) } != { Literal ( str [ i ] ) } ") ;
1941
1941
textSpanPos ++ ;
1942
1942
}
1943
1943
@@ -1955,7 +1955,7 @@ void EmitOr()
1955
1955
// character-by-character while respecting the culture.
1956
1956
if ( ! caseInsensitive )
1957
1957
{
1958
- string sourceSpan = textSpanPos > 0 ? $ "{ textSpanLocal } .Slice({ textSpanPos } )" : textSpanLocal ;
1958
+ string sourceSpan = textSpanPos > 0 ? $ "{ sliceSpan } .Slice({ textSpanPos } )" : sliceSpan ;
1959
1959
using ( EmitBlock ( writer , $ "if (!global::System.MemoryExtensions.StartsWith({ sourceSpan } , { Literal ( node . Str ) } ))") )
1960
1960
{
1961
1961
writer . WriteLine ( $ "goto { doneLabel } ;") ;
@@ -1968,7 +1968,7 @@ void EmitOr()
1968
1968
using ( EmitBlock ( writer , $ "for (int i = 0; i < { Literal ( node . Str ) } .Length; i++)") )
1969
1969
{
1970
1970
string textSpanIndex = textSpanPos > 0 ? $ "i + { textSpanPos } " : "i" ;
1971
- using ( EmitBlock ( writer , $ "if ({ ToLower ( hasTextInfo , options , $ "{ textSpanLocal } [{ textSpanIndex } ]") } != { Literal ( str ) } [i])") )
1971
+ using ( EmitBlock ( writer , $ "if ({ ToLower ( hasTextInfo , options , $ "{ sliceSpan } [{ textSpanIndex } ]") } != { Literal ( str ) } [i])") )
1972
1972
{
1973
1973
writer . WriteLine ( $ "goto { doneLabel } ;") ;
1974
1974
}
@@ -2427,9 +2427,9 @@ void EmitSingleCharFixedRepeater(RegexNode node, bool emitLengthCheck = true)
2427
2427
2428
2428
if ( iterations <= MaxUnrollSize )
2429
2429
{
2430
- // if ((uint)(textSpanPos + iterations - 1) >= (uint)localSpan .Length ||
2431
- // localSpan [textSpanPos] != c1 ||
2432
- // localSpan [textSpanPos + 1] != c2 ||
2430
+ // if ((uint)(textSpanPos + iterations - 1) >= (uint)slice .Length ||
2431
+ // slice [textSpanPos] != c1 ||
2432
+ // slice [textSpanPos + 1] != c2 ||
2433
2433
// ...)
2434
2434
// {
2435
2435
// goto doneLabel;
@@ -2455,25 +2455,25 @@ void EmitSingleCharFixedRepeater(RegexNode node, bool emitLengthCheck = true)
2455
2455
}
2456
2456
else
2457
2457
{
2458
- // if ((uint)(textSpanPos + iterations - 1) >= (uint)localSpan .Length) goto doneLabel;
2458
+ // if ((uint)(textSpanPos + iterations - 1) >= (uint)slice .Length) goto doneLabel;
2459
2459
if ( emitLengthCheck )
2460
2460
{
2461
2461
EmitSpanLengthCheck ( iterations ) ;
2462
2462
}
2463
2463
2464
- string spanLocal = "slice " ; // As this repeater doesn't wrap arbitrary node emits, this shouldn't conflict with anything
2465
- writer . WriteLine ( $ "global::System.ReadOnlySpan<char> { spanLocal } = { textSpanLocal } .Slice({ textSpanPos } , { iterations } );") ;
2464
+ string repeaterSpan = "repeaterSlice " ; // As this repeater doesn't wrap arbitrary node emits, this shouldn't conflict with anything
2465
+ writer . WriteLine ( $ "global::System.ReadOnlySpan<char> { repeaterSpan } = { sliceSpan } .Slice({ textSpanPos } , { iterations } );") ;
2466
2466
string i = ReserveName ( "charrepeater_iteration" ) ;
2467
- using ( EmitBlock ( writer , $ "for (int { i } = 0; { i } < { spanLocal } .Length; { i } ++)") )
2467
+ using ( EmitBlock ( writer , $ "for (int { i } = 0; { i } < { repeaterSpan } .Length; { i } ++)") )
2468
2468
{
2469
2469
EmitTimeoutCheck ( writer , hasTimeout ) ;
2470
2470
2471
- string tmpTextSpanLocal = textSpanLocal ; // we want EmitSingleChar to refer to this temporary
2471
+ string tmpTextSpanLocal = sliceSpan ; // we want EmitSingleChar to refer to this temporary
2472
2472
int tmpTextSpanPos = textSpanPos ;
2473
- textSpanLocal = spanLocal ;
2473
+ sliceSpan = repeaterSpan ;
2474
2474
textSpanPos = 0 ;
2475
2475
EmitSingleChar ( node , emitLengthCheck : false , offset : i ) ;
2476
- textSpanLocal = tmpTextSpanLocal ;
2476
+ sliceSpan = tmpTextSpanLocal ;
2477
2477
textSpanPos = tmpTextSpanPos ;
2478
2478
}
2479
2479
textSpanPos += iterations ;
@@ -2515,7 +2515,7 @@ void EmitSingleCharAtomicLoop(RegexNode node, bool emitLengthChecksIfRequired =
2515
2515
// restriction is purely for simplicity; it could be removed in the future with additional code to
2516
2516
// handle the unbounded case.
2517
2517
2518
- writer . Write ( $ "int { iterationLocal } = global::System.MemoryExtensions.IndexOf({ textSpanLocal } ") ;
2518
+ writer . Write ( $ "int { iterationLocal } = global::System.MemoryExtensions.IndexOf({ sliceSpan } ") ;
2519
2519
if ( textSpanPos > 0 )
2520
2520
{
2521
2521
writer . Write ( $ ".Slice({ textSpanPos } )") ;
@@ -2525,8 +2525,8 @@ void EmitSingleCharAtomicLoop(RegexNode node, bool emitLengthChecksIfRequired =
2525
2525
using ( EmitBlock ( writer , $ "if ({ iterationLocal } == -1)") )
2526
2526
{
2527
2527
writer . WriteLine ( textSpanPos > 0 ?
2528
- $ "{ iterationLocal } = { textSpanLocal } .Length - { textSpanPos } ;" :
2529
- $ "{ iterationLocal } = { textSpanLocal } .Length;") ;
2528
+ $ "{ iterationLocal } = { sliceSpan } .Length - { textSpanPos } ;" :
2529
+ $ "{ iterationLocal } = { sliceSpan } .Length;") ;
2530
2530
}
2531
2531
}
2532
2532
else if ( node . IsSetFamily &&
@@ -2540,7 +2540,7 @@ void EmitSingleCharAtomicLoop(RegexNode node, bool emitLengthChecksIfRequired =
2540
2540
// As with the notoneloopatomic above, the unbounded constraint is purely for simplicity.
2541
2541
Debug . Assert ( numSetChars > 1 ) ;
2542
2542
2543
- writer . Write ( $ "int { iterationLocal } = global::System.MemoryExtensions.IndexOfAny({ textSpanLocal } ") ;
2543
+ writer . Write ( $ "int { iterationLocal } = global::System.MemoryExtensions.IndexOfAny({ sliceSpan } ") ;
2544
2544
if ( textSpanPos != 0 )
2545
2545
{
2546
2546
writer . Write ( $ ".Slice({ textSpanPos } )") ;
@@ -2554,8 +2554,8 @@ void EmitSingleCharAtomicLoop(RegexNode node, bool emitLengthChecksIfRequired =
2554
2554
using ( EmitBlock ( writer , $ "if ({ iterationLocal } == -1)") )
2555
2555
{
2556
2556
writer . WriteLine ( textSpanPos > 0 ?
2557
- $ "{ iterationLocal } = { textSpanLocal } .Length - { textSpanPos } ;" :
2558
- $ "{ iterationLocal } = { textSpanLocal } .Length;") ;
2557
+ $ "{ iterationLocal } = { sliceSpan } .Length - { textSpanPos } ;" :
2558
+ $ "{ iterationLocal } = { sliceSpan } .Length;") ;
2559
2559
}
2560
2560
}
2561
2561
else if ( node . IsSetFamily && maxIterations == int . MaxValue && node . Str == RegexCharClass . AnyClass )
@@ -2571,7 +2571,7 @@ void EmitSingleCharAtomicLoop(RegexNode node, bool emitLengthChecksIfRequired =
2571
2571
{
2572
2572
// For everything else, do a normal loop.
2573
2573
2574
- string expr = $ "{ textSpanLocal } [{ iterationLocal } ]";
2574
+ string expr = $ "{ sliceSpan } [{ iterationLocal } ]";
2575
2575
if ( node . IsSetFamily )
2576
2576
{
2577
2577
expr = MatchCharacterClass ( hasTextInfo , options , expr , node . Str ! , IsCaseInsensitive ( node ) , additionalDeclarations ) ;
@@ -2594,7 +2594,7 @@ void EmitSingleCharAtomicLoop(RegexNode node, bool emitLengthChecksIfRequired =
2594
2594
textSpanPos = 0 ;
2595
2595
2596
2596
string maxClause = maxIterations != int . MaxValue ? $ "{ iterationLocal } < { maxIterations } && " : "" ;
2597
- using ( EmitBlock ( writer , $ "while ({ maxClause } (uint){ iterationLocal } < (uint){ textSpanLocal } .Length && { expr } )") )
2597
+ using ( EmitBlock ( writer , $ "while ({ maxClause } (uint){ iterationLocal } < (uint){ sliceSpan } .Length && { expr } )") )
2598
2598
{
2599
2599
EmitTimeoutCheck ( writer , hasTimeout ) ;
2600
2600
writer . WriteLine ( $ "{ iterationLocal } ++;") ;
@@ -2613,7 +2613,7 @@ void EmitSingleCharAtomicLoop(RegexNode node, bool emitLengthChecksIfRequired =
2613
2613
// Now that we've completed our optional iterations, advance the text span
2614
2614
// and runtextpos by the number of iterations completed.
2615
2615
2616
- writer . WriteLine ( $ "{ textSpanLocal } = { textSpanLocal } .Slice({ iterationLocal } );") ;
2616
+ writer . WriteLine ( $ "{ sliceSpan } = { sliceSpan } .Slice({ iterationLocal } );") ;
2617
2617
writer . WriteLine ( $ "runtextpos += { iterationLocal } ;") ;
2618
2618
}
2619
2619
@@ -2622,7 +2622,7 @@ void EmitAtomicSingleCharZeroOrOne(RegexNode node)
2622
2622
{
2623
2623
Debug . Assert ( node . M == 0 && node . N == 1 ) ;
2624
2624
2625
- string expr = $ "{ textSpanLocal } [{ textSpanPos } ]";
2625
+ string expr = $ "{ sliceSpan } [{ textSpanPos } ]";
2626
2626
if ( node . IsSetFamily )
2627
2627
{
2628
2628
expr = MatchCharacterClass ( hasTextInfo , options , expr , node . Str ! , IsCaseInsensitive ( node ) , additionalDeclarations ) ;
@@ -2633,9 +2633,9 @@ void EmitAtomicSingleCharZeroOrOne(RegexNode node)
2633
2633
expr = $ "{ expr } { ( node . IsOneFamily ? "==" : "!=" ) } { Literal ( node . Ch ) } ";
2634
2634
}
2635
2635
2636
- using ( EmitBlock ( writer , $ "if ((uint){ textSpanPos } < (uint){ textSpanLocal } .Length && { expr } )") )
2636
+ using ( EmitBlock ( writer , $ "if ((uint){ textSpanPos } < (uint){ sliceSpan } .Length && { expr } )") )
2637
2637
{
2638
- writer . WriteLine ( $ "{ textSpanLocal } = { textSpanLocal } .Slice(1);") ;
2638
+ writer . WriteLine ( $ "{ sliceSpan } = { sliceSpan } .Slice(1);") ;
2639
2639
writer . WriteLine ( $ "runtextpos++;") ;
2640
2640
}
2641
2641
}
0 commit comments