darknesswind / NutCracker

fork from DamianXVI's squirrel decompiler
22 stars 11 forks source link

NutCracker is too eager to replace while loops with for loops #28

Open AdamMil opened 5 years ago

AdamMil commented 5 years ago

In DecompileLoopJumpInstruction, if the jump is backwards to the start of the loop it may decompile it as a continue statement, but it doesn't set the UsedBackwardJumpContinue flag, so the postprocessing step may convert it to a for loop improperly. See this code:

local i,x
while(true)
{
  if(x) continue;
  i++;
}

When compiled and decompiled (assuming some other bugs are fixed), the result is:

local i;
for( local x; true; i++ )
{
    if (x)
    {
        continue;
    }
}

This is not equivalent. In the first example, the increment is skipped if x is true but in the second example it is not.