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

Function restassign

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

** Parse and compile a multiple assignment. The first "variable" ** (a 'suffixedexp') was already read by the caller. ** ** assignment -> suffixedexp restassign ** restassign -> ',' suffixedexp restassign | '=' explist */

Source from the content-addressed store, hash-verified

1361** restassign -> ',' suffixedexp restassign | '=' explist
1362*/
1363static void restassign (LexState *ls, struct LHS_assign *lh, int nvars) {
1364 expdesc e;
1365 check_condition(ls, vkisvar(lh->v.k), "syntax error");
1366 check_readonly(ls, &lh->v);
1367 if (testnext(ls, ',')) { /* restassign -> ',' suffixedexp restassign */
1368 struct LHS_assign nv;
1369 nv.prev = lh;
1370 suffixedexp(ls, &nv.v);
1371 if (!vkisindexed(nv.v.k))
1372 check_conflict(ls, lh, &nv.v);
1373 enterlevel(ls); /* control recursion depth */
1374 restassign(ls, &nv, nvars+1);
1375 leavelevel(ls);
1376 }
1377 else { /* restassign -> '=' explist */
1378 int nexps;
1379 checknext(ls, '=');
1380 nexps = explist(ls, &e);
1381 if (nexps != nvars)
1382 adjust_assign(ls, nvars, nexps, &e);
1383 else {
1384 luaK_setoneret(ls->fs, &e); /* close last expression */
1385 luaK_storevar(ls->fs, &lh->v, &e);
1386 return; /* avoid default */
1387 }
1388 }
1389 init_exp(&e, VNONRELOC, ls->fs->freereg-1); /* default assignment */
1390 luaK_storevar(ls->fs, &lh->v, &e);
1391}
1392
1393
1394static int cond (LexState *ls) {

Callers 1

exprstatFunction · 0.85

Calls 10

check_readonlyFunction · 0.85
testnextFunction · 0.85
suffixedexpFunction · 0.85
check_conflictFunction · 0.85
checknextFunction · 0.85
explistFunction · 0.85
adjust_assignFunction · 0.85
luaK_setoneretFunction · 0.85
luaK_storevarFunction · 0.85
init_expFunction · 0.85

Tested by

no test coverage detected