()
| 1778 | } |
| 1779 | |
| 1780 | private Loop forLoop() throws IOException { |
| 1781 | if (currentToken != Token.FOR) codeBug(); |
| 1782 | consumeToken(); |
| 1783 | int forPos = ts.tokenBeg, lineno = lineNumber(), column = columnNumber(); |
| 1784 | boolean isForEach = false, isForIn = false, isForOf = false; |
| 1785 | int eachPos = -1, inPos = -1, lp = -1, rp = -1; |
| 1786 | AstNode init = null; // init is also foo in 'foo in object' |
| 1787 | AstNode cond = null; // cond is also object in 'foo in object' |
| 1788 | AstNode incr = null; |
| 1789 | Loop pn = null; |
| 1790 | |
| 1791 | Scope tempScope = new Scope(); |
| 1792 | pushScope(tempScope); // decide below what AST class to use |
| 1793 | try { |
| 1794 | // See if this is a for each () instead of just a for () |
| 1795 | if (matchToken(Token.NAME, true)) { |
| 1796 | if ("each".equals(ts.getString())) { |
| 1797 | isForEach = true; |
| 1798 | eachPos = ts.tokenBeg - forPos; |
| 1799 | } else { |
| 1800 | reportError("msg.no.paren.for"); |
| 1801 | } |
| 1802 | } |
| 1803 | |
| 1804 | if (mustMatchToken(Token.LP, "msg.no.paren.for", true)) lp = ts.tokenBeg - forPos; |
| 1805 | int tt = peekToken(); |
| 1806 | |
| 1807 | init = forLoopInit(tt); |
| 1808 | if (matchToken(Token.IN, true)) { |
| 1809 | isForIn = true; |
| 1810 | inPos = ts.tokenBeg - forPos; |
| 1811 | markDestructuring(init); |
| 1812 | cond = expr(false); // object over which we're iterating |
| 1813 | } else if (compilerEnv.getLanguageVersion() >= Context.VERSION_ES6 |
| 1814 | && matchToken(Token.NAME, true) |
| 1815 | && "of".equals(ts.getString())) { |
| 1816 | isForOf = true; |
| 1817 | inPos = ts.tokenBeg - forPos; |
| 1818 | markDestructuring(init); |
| 1819 | cond = expr(false); // object over which we're iterating |
| 1820 | } else { // ordinary for-loop |
| 1821 | // For ordinary for loops, destructuring declarations must have initializers |
| 1822 | if (init instanceof VariableDeclaration) { |
| 1823 | VariableDeclaration varDecl = (VariableDeclaration) init; |
| 1824 | for (VariableInitializer vi : varDecl.getVariables()) { |
| 1825 | if (vi.isDestructuring() && vi.getInitializer() == null) { |
| 1826 | reportError("msg.destruct.assign.no.init"); |
| 1827 | } |
| 1828 | } |
| 1829 | } |
| 1830 | |
| 1831 | mustMatchToken(Token.SEMI, "msg.no.semi.for", true); |
| 1832 | if (peekToken() == Token.SEMI) { |
| 1833 | // no loop condition |
| 1834 | cond = new EmptyExpression(ts.tokenBeg, 1); |
| 1835 | // We haven't consumed the token, so we need the CURRENT lexer position |
| 1836 | cond.setLineColumnNumber(ts.getLineno(), ts.getTokenColumn()); |
| 1837 | } else { |
no test coverage detected