Open AdamMil opened 5 years ago
While debugging, I notice this:
void NutFunction::DecompileJCMP(VMState& state, int condVar, int offsetIp, int iterVar, int cmpOp) const
{
...
bool bCanBreak = (state.m_BlockState.inLoop || state.m_BlockState.inSwitch);
Here, m_BlockState refers to the 'if' statement and .inLoop is false. However, m_BlockState.parent refers to the loop and has .inLoop true. I think either bCanBreak needs to examine the chain of parent blocks, or inLoop needs to be propagated from parent to child.
I changed the code to:
bool bCanBreak = false;
for (BlockState *p = &state.m_BlockState; !bCanBreak && p; p = p->parent)
{
bCanBreak = (p->inLoop || p->inSwitch);
}
And got the correct output for my example. But I'm not sure that's the correct change.
Perhaps elseEnd > prevBlockState.blockEnd
also needs to be fixed to compare against the containing loop or switch end?
Consider this small script:
When compiled and decompiled, the output is:
The 'break' statement is missing, resulting in an infinite loop.