@@ -425,20 +425,38 @@ private void Flow(ref string str)
425425 // Substring inner content
426426 var innerStr = afterStr . Substring ( 0 , endTagIndex ) ;
427427
428- var blocks = GetCodeBlocks ( innerStr ) ;
428+ var rawBlocks = GetCodeBlocks ( innerStr ) ;
429+ var emptyBlocks = _rnd . Next ( 0 , rawBlocks . Length / 2 + 1 ) ;
430+ var blocks = new string [ rawBlocks . Length + emptyBlocks ] ;
431+
432+ // Fill blocks
433+ for ( var i = 0 ; i < rawBlocks . Length ; i ++ )
434+ {
435+ blocks [ i ] = rawBlocks [ i ] ;
436+ }
437+ for ( var i = rawBlocks . Length ; i < blocks . Length ; i ++ )
438+ {
439+ blocks [ i ] = string . Empty ;
440+ }
429441
442+ var leftXors = new int [ blocks . Length ] ;
443+ var rightXors = new int [ blocks . Length ] ;
430444 var switchValues = new int [ blocks . Length ] ;
431445
432446 // Generate switch values
433447 for ( var i = 0 ; i < switchValues . Length ; i ++ )
434448 {
435449 while ( true )
436450 {
437- var rndValue = _rnd . Next ( int . MinValue , int . MaxValue ) ;
451+ var leftXor = _rnd . Next ( int . MinValue , int . MaxValue ) ;
452+ var rightXor = _rnd . Next ( int . MinValue , int . MaxValue ) ;
453+ var switchValue = leftXor ^ rightXor ;
438454
439- if ( switchValues . All ( v => v != rndValue ) )
455+ if ( switchValues . All ( v => v != switchValue ) )
440456 {
441- switchValues [ i ] = rndValue ;
457+ leftXors [ i ] = leftXor ;
458+ rightXors [ i ] = rightXor ;
459+ switchValues [ i ] = switchValue ;
442460 break ;
443461 }
444462 }
@@ -448,6 +466,13 @@ private void Flow(ref string str)
448466 var switchVarName = GetVariableName ( str ) ;
449467 var exitLoopVarName = GetVariableName ( str ) ;
450468
469+ var funcName = GetVariableName ( str ) ;
470+ var leftName = GetVariableName ( str ) ;
471+ var rightName = GetVariableName ( str ) ;
472+
473+ // Generate xor function
474+ var xorFunc = $ "Action<int,int>{ funcName } =({ leftName } ,{ rightName } )=>{ switchVarName } ={ leftName } ^{ rightName } ;";
475+
451476 var cases = new string [ switchValues . Length ] ;
452477
453478 // Fill cases
@@ -461,13 +486,13 @@ private void Flow(ref string str)
461486 // Not last
462487 else
463488 {
464- cases [ i ] = $ "case { switchValues [ i ] } :{{{blocks[i]}{ switchVarName } = { switchValues [ i + 1 ] } \0 break\0 }}<block>";
489+ cases [ i ] = $ "case { switchValues [ i ] } :{{{blocks[i]}{ funcName } ( { leftXors [ i + 1 ] } , { rightXors [ i + 1 ] } ); \0 break\0 }}<block>";
465490 }
466491 }
467492
468493 // Generate output
469494 var caseOutput = cases . Aggregate ( string . Empty , ( current , c ) => current + c ) ;
470- var output = $ "<swap>int { switchVarName } ={ switchValues [ 0 ] } ; bool { exitLoopVarName } =true;<swap/>while({ exitLoopVarName } ){{switch({ switchVarName } ){{<swap>{ caseOutput } <swap/>}}}}";
495+ var output = $ "<swap>int { switchVarName } ={ switchValues [ 0 ] } \0 { xorFunc } bool { exitLoopVarName } =true;<swap/>while({ exitLoopVarName } ){{switch({ switchVarName } ){{<swap>{ caseOutput } <swap/>}}}}";
471496
472497 // Remove old
473498 str = str . Remove ( tagIndex , tagLength + endTagIndex + endTagLength ) ;
0 commit comments