MCPcopy Create free account
hub / github.com/Serial-Studio/Serial-Studio / test_then_block

Function test_then_block

lib/lua/src/lparser.c:1638–1672  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

Callers 1

ifstatFunction · 0.85

Calls 14

luaX_nextFunction · 0.85
exprFunction · 0.85
checknextFunction · 0.85
luaK_goiffalseFunction · 0.85
enterblockFunction · 0.85
newgotoentryFunction · 0.85
testnextFunction · 0.85
block_followFunction · 0.85
leaveblockFunction · 0.85
luaK_jumpFunction · 0.85
luaK_goiftrueFunction · 0.85
statlistFunction · 0.85

Tested by

no test coverage detected