| 1745 | |
| 1746 | |
| 1747 | static void localstat (LexState *ls) { |
| 1748 | /* stat -> LOCAL ATTRIB NAME {',' ATTRIB NAME} ['=' explist] */ |
| 1749 | FuncState *fs = ls->fs; |
| 1750 | int toclose = -1; /* index of to-be-closed variable (if any) */ |
| 1751 | Vardesc *var; /* last variable */ |
| 1752 | int ivar, kind; /* index and kind of last variable */ |
| 1753 | int nvars = 0; |
| 1754 | int nexps; |
| 1755 | expdesc e; |
| 1756 | do { |
| 1757 | ivar = new_localvar(ls, str_checkname(ls)); |
| 1758 | kind = getlocalattribute(ls); |
| 1759 | getlocalvardesc(fs, ivar)->vd.kind = kind; |
| 1760 | if (kind == RDKTOCLOSE) { /* to-be-closed? */ |
| 1761 | if (toclose != -1) /* one already present? */ |
| 1762 | luaK_semerror(ls, "multiple to-be-closed variables in local list"); |
| 1763 | toclose = luaY_nvarstack(fs) + nvars; |
| 1764 | } |
| 1765 | nvars++; |
| 1766 | } while (testnext(ls, ',')); |
| 1767 | if (testnext(ls, '=')) |
| 1768 | nexps = explist(ls, &e); |
| 1769 | else { |
| 1770 | e.k = VVOID; |
| 1771 | nexps = 0; |
| 1772 | } |
| 1773 | var = getlocalvardesc(fs, ivar); /* get last variable */ |
| 1774 | if (nvars == nexps && /* no adjustments? */ |
| 1775 | var->vd.kind == RDKCONST && /* last variable is const? */ |
| 1776 | luaK_exp2const(fs, &e, &var->k)) { /* compile-time constant? */ |
| 1777 | var->vd.kind = RDKCTC; /* variable is a compile-time constant */ |
| 1778 | adjustlocalvars(ls, nvars - 1); /* exclude last variable */ |
| 1779 | fs->nactvar++; /* but count it */ |
| 1780 | } |
| 1781 | else { |
| 1782 | adjust_assign(ls, nvars, nexps, &e); |
| 1783 | adjustlocalvars(ls, nvars); |
| 1784 | } |
| 1785 | checktoclose(ls, toclose); |
| 1786 | } |
| 1787 | |
| 1788 | |
| 1789 | static int funcname (LexState *ls, expdesc *v) { |
no test coverage detected