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