MCPcopy Create free account
hub / github.com/EmmyLua/EmmyLuaDebugger / check_conflict

Function check_conflict

third-party/lua-5.4.6/src/lparser.c:1330–1365  ·  view source on GitHub ↗

** check whether, in an assignment to an upvalue/local variable, the ** upvalue/local variable is begin used in a previous assignment to a ** table. If so, save original upvalue/local value in a safe place and ** use this safe copy in the previous assignment. */

Source from the content-addressed store, hash-verified

1328** use this safe copy in the previous assignment.
1329*/
1330static void check_conflict (LexState *ls, struct LHS_assign *lh, expdesc *v) {
1331 FuncState *fs = ls->fs;
1332 int extra = fs->freereg; /* eventual position to save local variable */
1333 int conflict = 0;
1334 for (; lh; lh = lh->prev) { /* check all previous assignments */
1335 if (vkisindexed(lh->v.k)) { /* assignment to table field? */
1336 if (lh->v.k == VINDEXUP) { /* is table an upvalue? */
1337 if (v->k == VUPVAL && lh->v.u.ind.t == v->u.info) {
1338 conflict = 1; /* table is the upvalue being assigned now */
1339 lh->v.k = VINDEXSTR;
1340 lh->v.u.ind.t = extra; /* assignment will use safe copy */
1341 }
1342 }
1343 else { /* table is a register */
1344 if (v->k == VLOCAL && lh->v.u.ind.t == v->u.var.ridx) {
1345 conflict = 1; /* table is the local being assigned now */
1346 lh->v.u.ind.t = extra; /* assignment will use safe copy */
1347 }
1348 /* is index the local being assigned? */
1349 if (lh->v.k == VINDEXED && v->k == VLOCAL &&
1350 lh->v.u.ind.idx == v->u.var.ridx) {
1351 conflict = 1;
1352 lh->v.u.ind.idx = extra; /* previous assignment will use safe copy */
1353 }
1354 }
1355 }
1356 }
1357 if (conflict) {
1358 /* copy upvalue/local value to a temporary (in position 'extra') */
1359 if (v->k == VLOCAL)
1360 luaK_codeABC(fs, OP_MOVE, extra, v->u.var.ridx, 0);
1361 else
1362 luaK_codeABC(fs, OP_GETUPVAL, extra, v->u.info, 0);
1363 luaK_reserveregs(fs, 1);
1364 }
1365}
1366
1367/*
1368** Parse and compile a multiple assignment. The first "variable"

Callers 1

restassignFunction · 0.70

Calls 2

luaK_reserveregsFunction · 0.70
luaK_codeABCFunction · 0.50

Tested by

no test coverage detected