MCPcopy Create free account
hub / github.com/F-Stack/f-stack / forstat

Function forstat

app/redis-6.2.6/deps/lua/src/lparser.c:1116–1343  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1114
1115
1116static void forstat (LexState *ls, int line) {
1117 /* forstat -> FOR (fornum | forlist) END */
1118 FuncState *fs = ls->fs;
1119 TString *varname;
1120 BlockCnt bl;
1121 enterblock(fs, &bl, 1); /* scope for loop and control variables */
1122 luaX_next(ls); /* skip `for' */
1123 varname = str_checkname(ls); /* first variable name */
1124 switch (ls->t.token) {
1125 case '=': fornum(ls, varname, line); break;
1126 case ',': case TK_IN: forlist(ls, varname); break;
1127 default: luaX_syntaxerror(ls, LUA_QL("=") " or " LUA_QL("in") " expected");
1128 }
1129 check_match(ls, TK_END, TK_FOR, line);
1130 leaveblock(fs); /* loop scope (`break' jumps to this point) */
1131}
1132
1133
1134static int test_then_block (LexState *ls) {
1135 /* test_then_block -> [IF | ELSEIF] cond THEN block */
1136 int condexit;
1137 luaX_next(ls); /* skip IF or ELSEIF */
1138 condexit = cond(ls);
1139 checknext(ls, TK_THEN);
1140 block(ls); /* `then' part */
1141 return condexit;
1142}
1143
1144
1145static void ifstat (LexState *ls, int line) {
1146 /* ifstat -> IF cond THEN block {ELSEIF cond THEN block} [ELSE block] END */
1147 FuncState *fs = ls->fs;
1148 int flist;
1149 int escapelist = NO_JUMP;
1150 flist = test_then_block(ls); /* IF cond THEN block */
1151 while (ls->t.token == TK_ELSEIF) {
1152 luaK_concat(fs, &escapelist, luaK_jump(fs));
1153 luaK_patchtohere(fs, flist);
1154 flist = test_then_block(ls); /* ELSEIF cond THEN block */
1155 }
1156 if (ls->t.token == TK_ELSE) {
1157 luaK_concat(fs, &escapelist, luaK_jump(fs));
1158 luaK_patchtohere(fs, flist);
1159 luaX_next(ls); /* skip ELSE (after patch, for correct line info) */
1160 block(ls); /* `else' part */
1161 }
1162 else
1163 luaK_concat(fs, &escapelist, flist);
1164 luaK_patchtohere(fs, escapelist);
1165 check_match(ls, TK_END, TK_IF, line);
1166}
1167
1168
1169static void localfunc (LexState *ls) {
1170 expdesc v, b;
1171 FuncState *fs = ls->fs;
1172 new_localvar(ls, str_checkname(ls), 0);
1173 init_exp(&v, VLOCAL, fs->freereg);

Callers 1

statementFunction · 0.70

Calls 7

enterblockFunction · 0.70
luaX_nextFunction · 0.70
str_checknameFunction · 0.70
fornumFunction · 0.70
forlistFunction · 0.70
luaX_syntaxerrorFunction · 0.70
leaveblockFunction · 0.70

Tested by

no test coverage detected