MCPcopy Create free account
hub / github.com/CppCXY/EmmyLuaCodeStyle / test_then_block

Function test_then_block

3rd/lua-5.4.3/src/lparser.c:1626–1660  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1624
1625
1626static 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
1663static 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