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