| 1624 | |
| 1625 | |
| 1626 | static void test_then_block (LexState *ls, int *escapelist) { |
| 1627 | /* test_then_block -> [IF | ELSEIF] cond THEN block */ |
| 1628 | BlockCnt bl; |
| 1629 | FuncState *fs = ls->fs; |
| 1630 | expdesc v; |
| 1631 | int jf; /* instruction to skip 'then' code (if condition is false) */ |
| 1632 | luaX_next(ls); /* skip IF or ELSEIF */ |
| 1633 | expr(ls, &v); /* read condition */ |
| 1634 | checknext(ls, TK_THEN); |
| 1635 | if (ls->t.token == TK_BREAK) { /* 'if x then break' ? */ |
| 1636 | int line = ls->linenumber; |
| 1637 | luaK_goiffalse(ls->fs, &v); /* will jump if condition is true */ |
| 1638 | luaX_next(ls); /* skip 'break' */ |
| 1639 | enterblock(fs, &bl, 0); /* must enter block before 'goto' */ |
| 1640 | newgotoentry(ls, luaS_newliteral(ls->L, "break"), line, v.t); |
| 1641 | while (testnext(ls, ';')) {} /* skip semicolons */ |
| 1642 | if (block_follow(ls, 0)) { /* jump is the entire block? */ |
| 1643 | leaveblock(fs); |
| 1644 | return; /* and that is it */ |
| 1645 | } |
| 1646 | else /* must skip over 'then' part if condition is false */ |
| 1647 | jf = luaK_jump(fs); |
| 1648 | } |
| 1649 | else { /* regular case (not a break) */ |
| 1650 | luaK_goiftrue(ls->fs, &v); /* skip over block if condition is false */ |
| 1651 | enterblock(fs, &bl, 0); |
| 1652 | jf = v.f; |
| 1653 | } |
| 1654 | statlist(ls); /* 'then' part */ |
| 1655 | leaveblock(fs); |
| 1656 | if (ls->t.token == TK_ELSE || |
| 1657 | ls->t.token == TK_ELSEIF) /* followed by 'else'/'elseif'? */ |
| 1658 | luaK_concat(fs, escapelist, luaK_jump(fs)); /* must jump over it */ |
| 1659 | luaK_patchtohere(fs, jf); |
| 1660 | } |
| 1661 | |
| 1662 | |
| 1663 | static void ifstat (LexState *ls, int line) { |
no test coverage detected