| 1714 | |
| 1715 | |
| 1716 | static 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 | |
| 1758 | static int funcname (LexState *ls, expdesc *v) { |
no test coverage detected