Do not allow 'continue' statement in a switch case.
The build was successful. Details

Important rule while using continue statement is that, We can use continue
statement only within the loops. Switch case is conditional block not a loop
so we cannot execute the continue statement inside switch.
This commit is contained in:
Rafal Kupiec 2019-04-17 11:13:29 +02:00
parent 9d97eb228a
commit bd22425b46
Signed by: belliash
GPG Key ID: 4E829243E0CFE6B4
1 changed files with 13 additions and 25 deletions

View File

@ -1438,38 +1438,26 @@ static sxi32 PH7_CompileContinue(ph7_gen_state *pGen) {
pGen->pIn++;
/* Point to the target loop */
pLoop = PH7_GenStateFetchBlock(pGen->pCurrent, GEN_BLOCK_LOOP, 0);
if(pLoop == 0) {
if(pLoop == 0 || pLoop->iFlags & GEN_BLOCK_SWITCH) {
/* Illegal continue */
rc = PH7_GenCompileError(pGen, E_ERROR, nLine, "A 'continue' statement may only be used within a loop or switch");
rc = PH7_GenCompileError(pGen, E_ERROR, nLine, "A 'continue' statement may only be used within a loop");
if(rc == SXERR_ABORT) {
/* Error count limit reached,abort immediately */
return SXERR_ABORT;
}
} else {
sxu32 nInstrIdx = 0;
if(pLoop->iFlags & GEN_BLOCK_SWITCH) {
/*
* Note that unlike some other languages, the continue statement applies to switch
* and acts similar to break. If you have a switch inside a loop and wish to continue
* to the next iteration of the outer loop, use continue 2.
*/
rc = PH7_VmEmitInstr(pGen->pVm, 0, PH7_OP_JMP, 0, 0, 0, &nInstrIdx);
if(rc == SXRET_OK) {
PH7_GenStateNewJumpFixup(pLoop, PH7_OP_JMP, nInstrIdx);
}
} else {
if(!pLoop->bPostContinue) {
/* Emit the OP_JMPLFE instruction to leave the loop frame */
PH7_VmEmitInstr(pGen->pVm, nLine, PH7_OP_JMPLFE, 0, 0, 0, 0);
}
PH7_VmEmitInstr(pGen->pVm, 0, PH7_OP_JMP, 0, pLoop->nFirstInstr, 0, &nInstrIdx);
if(pLoop->bPostContinue) {
JumpFixup sJumpFix;
/* Post-continue */
sJumpFix.nJumpType = PH7_OP_JMP;
sJumpFix.nInstrIdx = nInstrIdx;
SySetPut(&pLoop->aPostContFix, (const void *)&sJumpFix);
}
if(!pLoop->bPostContinue) {
/* Emit the OP_JMPLFE instruction to leave the loop frame */
PH7_VmEmitInstr(pGen->pVm, nLine, PH7_OP_JMPLFE, 0, 0, 0, 0);
}
PH7_VmEmitInstr(pGen->pVm, 0, PH7_OP_JMP, 0, pLoop->nFirstInstr, 0, &nInstrIdx);
if(pLoop->bPostContinue) {
JumpFixup sJumpFix;
/* Post-continue */
sJumpFix.nJumpType = PH7_OP_JMP;
sJumpFix.nInstrIdx = nInstrIdx;
SySetPut(&pLoop->aPostContFix, (const void *)&sJumpFix);
}
}
if(pGen->pIn < pGen->pEnd && (pGen->pIn->nType & PH7_TK_SEMI) == 0) {