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

Function localstat

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

Source from the content-addressed store, hash-verified

1714
1715
1716static void localstat (LexState *ls) {
1717 /* stat -> LOCAL NAME ATTRIB { ',' NAME ATTRIB } ['=' explist] */
1718 FuncState *fs = ls->fs;
1719 int toclose = -1; /* index of to-be-closed variable (if any) */
1720 Vardesc *var; /* last variable */
1721 int vidx, kind; /* index and kind of last variable */
1722 int nvars = 0;
1723 int nexps;
1724 expdesc e;
1725 do {
1726 vidx = new_localvar(ls, str_checkname(ls));
1727 kind = getlocalattribute(ls);
1728 getlocalvardesc(fs, vidx)->vd.kind = kind;
1729 if (kind == RDKTOCLOSE) { /* to-be-closed? */
1730 if (toclose != -1) /* one already present? */
1731 luaK_semerror(ls, "multiple to-be-closed variables in local list");
1732 toclose = fs->nactvar + nvars;
1733 }
1734 nvars++;
1735 } while (testnext(ls, ','));
1736 if (testnext(ls, '='))
1737 nexps = explist(ls, &e);
1738 else {
1739 e.k = VVOID;
1740 nexps = 0;
1741 }
1742 var = getlocalvardesc(fs, vidx); /* get last variable */
1743 if (nvars == nexps && /* no adjustments? */
1744 var->vd.kind == RDKCONST && /* last variable is const? */
1745 luaK_exp2const(fs, &e, &var->k)) { /* compile-time constant? */
1746 var->vd.kind = RDKCTC; /* variable is a compile-time constant */
1747 adjustlocalvars(ls, nvars - 1); /* exclude last variable */
1748 fs->nactvar++; /* but count it */
1749 }
1750 else {
1751 adjust_assign(ls, nvars, nexps, &e);
1752 adjustlocalvars(ls, nvars);
1753 }
1754 checktoclose(ls, toclose);
1755}
1756
1757
1758static int funcname (LexState *ls, expdesc *v) {

Callers 1

statementFunction · 0.85

Calls 11

new_localvarFunction · 0.85
str_checknameFunction · 0.85
getlocalattributeFunction · 0.85
getlocalvardescFunction · 0.85
luaK_semerrorFunction · 0.85
testnextFunction · 0.85
explistFunction · 0.85
luaK_exp2constFunction · 0.85
adjustlocalvarsFunction · 0.85
adjust_assignFunction · 0.85
checktocloseFunction · 0.85

Tested by

no test coverage detected