LEFT | RIGHT |
1 // Copyright (C) 2005 Google Inc. | 1 // Copyright (C) 2005 Google Inc. |
2 // | 2 // |
3 // Licensed under the Apache License, Version 2.0 (the "License"); | 3 // Licensed under the Apache License, Version 2.0 (the "License"); |
4 // you may not use this file except in compliance with the License. | 4 // you may not use this file except in compliance with the License. |
5 // You may obtain a copy of the License at | 5 // You may obtain a copy of the License at |
6 // | 6 // |
7 // http://www.apache.org/licenses/LICENSE-2.0 | 7 // http://www.apache.org/licenses/LICENSE-2.0 |
8 // | 8 // |
9 // Unless required by applicable law or agreed to in writing, software | 9 // Unless required by applicable law or agreed to in writing, software |
10 // distributed under the License is distributed on an "AS IS" BASIS, | 10 // distributed under the License is distributed on an "AS IS" BASIS, |
(...skipping 359 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
370 increment = noop(tq.lastPosition()); | 370 increment = noop(tq.lastPosition()); |
371 } | 371 } |
372 Statement body = parseBody(true); | 372 Statement body = parseBody(true); |
373 | 373 |
374 s = new ForLoop( | 374 s = new ForLoop( |
375 posFrom(start), label, initializer, condition, increment, body); | 375 posFrom(start), label, initializer, condition, increment, body); |
376 } else { | 376 } else { |
377 Statement initializer = parseDeclarationsOrExpression(true); | 377 Statement initializer = parseDeclarationsOrExpression(true); |
378 Expression initializerExpr = null; | 378 Expression initializerExpr = null; |
379 | 379 |
380 s = null; | |
381 if ((initializer instanceof Declaration // no multi-decls | 380 if ((initializer instanceof Declaration // no multi-decls |
382 && null == ((Declaration) initializer).getInitializer() | 381 && null == ((Declaration) initializer).getInitializer() |
383 && tq.checkToken(Keyword.IN)) | 382 && tq.checkToken(Keyword.IN)) |
384 || (!tq.lookaheadToken(Punctuation.SEMI) | 383 || (!tq.lookaheadToken(Punctuation.SEMI) |
385 && (initializerExpr = checkInExprWithLhs(initializer)) != null | 384 && (initializerExpr = checkInExprWithLhs(initializer)) != null |
386 )) { | 385 )) { |
387 | 386 |
388 Expression iterable; | 387 Expression iterable; |
389 Expression lvalue; | 388 Expression lvalue; |
390 if (null == initializerExpr) { | 389 if (null == initializerExpr) { |
(...skipping 1068 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1459 | 1458 |
1460 private static Operation checkInExprWithLhs(Statement s) { | 1459 private static Operation checkInExprWithLhs(Statement s) { |
1461 if (!(s instanceof ExpressionStmt)) { return null; } | 1460 if (!(s instanceof ExpressionStmt)) { return null; } |
1462 Expression e = ((ExpressionStmt) s).getExpression(); | 1461 Expression e = ((ExpressionStmt) s).getExpression(); |
1463 if (!(e instanceof Operation)) { return null; } | 1462 if (!(e instanceof Operation)) { return null; } |
1464 Operation op = (Operation) e; | 1463 Operation op = (Operation) e; |
1465 if (Operator.IN != op.getOperator()) { return null; } | 1464 if (Operator.IN != op.getOperator()) { return null; } |
1466 return op.children().get(0).isLeftHandSide() ? op : null; | 1465 return op.children().get(0).isLeftHandSide() ? op : null; |
1467 } | 1466 } |
1468 } | 1467 } |
LEFT | RIGHT |