MCPcopy Create free account
hub / github.com/DFHack/dfhack / test_then_block

Function test_then_block

depends/lua/src/lparser.c:1383–1415  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1381
1382
1383static void test_then_block (LexState *ls, int *escapelist) {
1384 /* test_then_block -> [IF | ELSEIF] cond THEN block */
1385 BlockCnt bl;
1386 FuncState *fs = ls->fs;
1387 expdesc v;
1388 int jf; /* instruction to skip 'then' code (if condition is false) */
1389 luaX_next(ls); /* skip IF or ELSEIF */
1390 expr(ls, &v); /* read condition */
1391 checknext(ls, TK_THEN);
1392 if (ls->t.token == TK_GOTO || ls->t.token == TK_BREAK) {
1393 luaK_goiffalse(ls->fs, &v); /* will jump to label if condition is true */
1394 enterblock(fs, &bl, 0); /* must enter block before 'goto' */
1395 gotostat(ls, v.t); /* handle goto/break */
1396 while (testnext(ls, ';')) {} /* skip colons */
1397 if (block_follow(ls, 0)) { /* 'goto' is the entire block? */
1398 leaveblock(fs);
1399 return; /* and that is it */
1400 }
1401 else /* must skip over 'then' part if condition is false */
1402 jf = luaK_jump(fs);
1403 }
1404 else { /* regular case (not goto/break) */
1405 luaK_goiftrue(ls->fs, &v); /* skip over block if condition is false */
1406 enterblock(fs, &bl, 0);
1407 jf = v.f;
1408 }
1409 statlist(ls); /* 'then' part */
1410 leaveblock(fs);
1411 if (ls->t.token == TK_ELSE ||
1412 ls->t.token == TK_ELSEIF) /* followed by 'else'/'elseif'? */
1413 luaK_concat(fs, escapelist, luaK_jump(fs)); /* must jump over it */
1414 luaK_patchtohere(fs, jf);
1415}
1416
1417
1418static 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
gotostatFunction · 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