| 1816 | |
| 1817 | |
| 1818 | static void localstat (LexState *ls) { |
| 1819 | /* stat -> LOCAL NAME attrib { ',' NAME attrib } ['=' explist] */ |
| 1820 | FuncState *fs = ls->fs; |
| 1821 | int toclose = -1; /* index of to-be-closed variable (if any) */ |
| 1822 | Vardesc *var; /* last variable */ |
| 1823 | int vidx; /* index of last variable */ |
| 1824 | int nvars = 0; |
| 1825 | int nexps; |
| 1826 | expdesc e; |
| 1827 | /* get prefixed attribute (if any); default is regular local variable */ |
| 1828 | lu_byte defkind = getvarattribute(ls, VDKREG); |
| 1829 | do { /* for each variable */ |
| 1830 | TString *vname = str_checkname(ls); /* get its name */ |
| 1831 | lu_byte kind = getvarattribute(ls, defkind); /* postfixed attribute */ |
| 1832 | vidx = new_varkind(ls, vname, kind); /* predeclare it */ |
| 1833 | if (kind == RDKTOCLOSE) { /* to-be-closed? */ |
| 1834 | if (toclose != -1) /* one already present? */ |
| 1835 | luaK_semerror(ls, "multiple to-be-closed variables in local list"); |
| 1836 | toclose = fs->nactvar + nvars; |
| 1837 | } |
| 1838 | nvars++; |
| 1839 | } while (testnext(ls, ',')); |
| 1840 | if (testnext(ls, '=')) /* initialization? */ |
| 1841 | nexps = explist(ls, &e); |
| 1842 | else { |
| 1843 | e.k = VVOID; |
| 1844 | nexps = 0; |
| 1845 | } |
| 1846 | var = getlocalvardesc(fs, vidx); /* retrieve last variable */ |
| 1847 | if (nvars == nexps && /* no adjustments? */ |
| 1848 | var->vd.kind == RDKCONST && /* last variable is const? */ |
| 1849 | luaK_exp2const(fs, &e, &var->k)) { /* compile-time constant? */ |
| 1850 | var->vd.kind = RDKCTC; /* variable is a compile-time constant */ |
| 1851 | adjustlocalvars(ls, nvars - 1); /* exclude last variable */ |
| 1852 | fs->nactvar++; /* but count it */ |
| 1853 | } |
| 1854 | else { |
| 1855 | adjust_assign(ls, nvars, nexps, &e); |
| 1856 | adjustlocalvars(ls, nvars); |
| 1857 | } |
| 1858 | checktoclose(fs, toclose); |
| 1859 | } |
| 1860 | |
| 1861 | |
| 1862 | static lu_byte getglobalattribute (LexState *ls, lu_byte df) { |
no test coverage detected