MCPcopy Create free account
hub / github.com/EmmyLua/EmmyLuaDebugger / test_then_block

Function test_then_block

third-party/lua-5.4.6/src/lparser.c:1637–1671  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

Callers 1

ifstatFunction · 0.70

Calls 14

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

Tested by

no test coverage detected