Script: continue in a do-while loop jumps to test instead of start of loop

This matches C and other languages.
stable-5.3
Günther Brammer 2013-01-08 21:21:11 +01:00 committed by Armin Burgmeier
parent 6c531abbfe
commit 9f3489c053
1 changed files with 4 additions and 3 deletions

View File

@ -2012,11 +2012,12 @@ void C4AulParse::Parse_DoWhile()
{
Shift();
// Save position for later jump back
int iStart = JumpHere();
int Start = JumpHere();
// We got a loop
PushLoop();
// Execute body
Parse_Statement();
int BeforeCond = JumpHere();
// Execute condition
if (TokenType != ATT_IDTF || !SEqual(Idtf, C4AUL_While))
UnexpectedToken("'while'");
@ -2025,14 +2026,14 @@ void C4AulParse::Parse_DoWhile()
Parse_Expression();
Match(ATT_BCLOSE);
// Jump back
AddJump(AB_COND, iStart);
AddJump(AB_COND, Start);
if (Type != PARSER) return;
// Set targets for break/continue
for (Loop::Control *pCtrl = pLoopStack->Controls; pCtrl; pCtrl = pCtrl->Next)
if (pCtrl->Break)
SetJumpHere(pCtrl->Pos);
else
SetJump(pCtrl->Pos, iStart);
SetJump(pCtrl->Pos, BeforeCond);
PopLoop();
}