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

Function check_conflict

3rd/lua-5.4.3/src/lparser.c:1319–1354  ·  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

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

Callers 1

restassignFunction · 0.85

Calls 1

luaK_reserveregsFunction · 0.85

Tested by

no test coverage detected