| 1358 | |
| 1359 | |
| 1360 | static void forstat (LexState *ls, int line) { |
| 1361 | /* forstat -> FOR (fornum | forlist) END */ |
| 1362 | FuncState *fs = ls->fs; |
| 1363 | TString *varname; |
| 1364 | BlockCnt bl; |
| 1365 | enterblock(fs, &bl, 1); /* scope for loop and control variables */ |
| 1366 | luaX_next(ls); /* skip `for' */ |
| 1367 | varname = str_checkname(ls); /* first variable name */ |
| 1368 | switch (ls->t.token) { |
| 1369 | case '=': fornum(ls, varname, line); break; |
| 1370 | case ',': case TK_IN: forlist(ls, varname); break; |
| 1371 | default: luaX_syntaxerror(ls, LUA_QL("=") " or " LUA_QL("in") " expected"); |
| 1372 | } |
| 1373 | check_match(ls, TK_END, TK_FOR, line); |
| 1374 | leaveblock(fs); /* loop scope (`break' jumps to this point) */ |
| 1375 | } |
| 1376 | |
| 1377 | |
| 1378 | __attribute__((always_inline)) inline |
| 1379 | static void test_then_block (LexState *ls, int *escapelist) { |
| 1380 | /* test_then_block -> [IF | ELSEIF] cond THEN block */ |
| 1381 | BlockCnt bl; |
| 1382 | FuncState *fs = ls->fs; |
| 1383 | expdesc v; |
| 1384 | int jf; /* instruction to skip 'then' code (if condition is false) */ |
| 1385 | luaX_next(ls); /* skip IF or ELSEIF */ |
| 1386 | expr(ls, &v); /* read condition */ |
| 1387 | checknext(ls, TK_THEN); |
| 1388 | if (ls->t.token == TK_GOTO || ls->t.token == TK_BREAK) { |
| 1389 | luaK_goiffalse(ls->fs, &v); /* will jump to label if condition is true */ |
| 1390 | enterblock(fs, &bl, 0); /* must enter block before 'goto' */ |
| 1391 | gotostat(ls, v.t); /* handle goto/break */ |
| 1392 | skipnoopstat(ls); /* skip other no-op statements */ |
| 1393 | if (block_follow(ls, 0)) { /* 'goto' is the entire block? */ |
| 1394 | leaveblock(fs); |
| 1395 | return; /* and that is it */ |
| 1396 | } |
| 1397 | else /* must skip over 'then' part if condition is false */ |
| 1398 | jf = luaK_jump(fs); |
| 1399 | } |
| 1400 | else { /* regular case (not goto/break) */ |
| 1401 | luaK_goiftrue(ls->fs, &v); /* skip over block if condition is false */ |
| 1402 | enterblock(fs, &bl, 0); |
| 1403 | jf = v.f; |
| 1404 | } |
| 1405 | statlist(ls); /* `then' part */ |
| 1406 | leaveblock(fs); |
| 1407 | if (ls->t.token == TK_ELSE || |
| 1408 | ls->t.token == TK_ELSEIF) /* followed by 'else'/'elseif'? */ |
| 1409 | luaK_concat(fs, escapelist, luaK_jump(fs)); /* must jump over it */ |
| 1410 | luaK_patchtohere(fs, jf); |
| 1411 | } |
| 1412 | |
| 1413 | |
| 1414 | static void ifstat (LexState *ls, int line) { |
| 1415 | /* ifstat -> IF cond THEN block {ELSEIF cond THEN block} [ELSE block] END */ |
| 1416 | FuncState *fs = ls->fs; |
| 1417 | int escapelist = NO_JUMP; /* exit list for finished parts */ |
no test coverage detected