Skip to content

Commit 5889a7f

Browse files
committed
Turn on unsequenced expression rewriting by default.
Change on 2015/03/02 by kstanger <[email protected]> ------------- Created by MOE: http://code.google.com/p/moe-java MOE_MIGRATED_REVID=87512781
1 parent 99538e6 commit 5889a7f

File tree

4 files changed

+53
-8
lines changed

4 files changed

+53
-8
lines changed

doc/man/j2objc.1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@ Specify a ProGuard usage report for dead code elimination.
6969
.BI \-\-doc\-comments
7070
Translate Javadoc comments into Xcode-compatible comments.
7171
.TP
72-
.BI \-\-extract\-unsequenced
73-
Rewrite expressions that would produce unsequenced modification errors.
72+
.BI \-\-no\-extract\-unsequenced
73+
Don't rewrite expressions that would produce unsequenced modification errors.
7474
.TP
7575
.BI \-\-generate\-deprecated
7676
Generate deprecated attributes for deprecated methods, classes, and interfaces.

translator/src/main/java/com/google/devtools/j2objc/Options.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public class Options {
7575
private static boolean jsniWarnings = true;
7676
private static boolean buildClosure = false;
7777
private static boolean stripReflection = false;
78-
private static boolean extractUnsequencedModifications = false;
78+
private static boolean extractUnsequencedModifications = true;
7979
private static boolean docCommentsEnabled = false;
8080
private static boolean finalMethodsAsFunctions = true;
8181
private static boolean removeClassMethods = false;
@@ -299,6 +299,8 @@ public static String[] load(String[] args) throws IOException {
299299
buildClosure = true;
300300
} else if (arg.equals("--extract-unsequenced")) {
301301
extractUnsequencedModifications = true;
302+
} else if (arg.equals("--no-extract-unsequenced")) {
303+
extractUnsequencedModifications = false;
302304
} else if (arg.equals("--doc-comments")) {
303305
docCommentsEnabled = true;
304306
} else if (arg.startsWith(BATCH_PROCESSING_MAX_FLAG)) {

translator/src/main/java/com/google/devtools/j2objc/ast/TreeUtil.java

Lines changed: 47 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import org.eclipse.jdt.core.dom.IVariableBinding;
2727

2828
import java.io.File;
29+
import java.util.AbstractList;
2930
import java.util.Collections;
3031
import java.util.Comparator;
3132
import java.util.Iterator;
@@ -263,10 +264,52 @@ public static List<Statement> asStatementList(Statement node) {
263264
}
264265
}
265266
}
266-
Block block = new Block();
267-
node.replaceWith(block);
268-
block.getStatements().add(node);
269-
return block.getStatements();
267+
return new LonelyStatementList(node);
268+
}
269+
270+
/**
271+
* This list wraps a single statement, and inserts a block node in its place
272+
* upon adding additional nodes.
273+
*/
274+
private static class LonelyStatementList extends AbstractList<Statement> {
275+
276+
private final Statement lonelyStatement;
277+
private List<Statement> delegate = null;
278+
279+
public LonelyStatementList(Statement stmt) {
280+
lonelyStatement = stmt;
281+
}
282+
283+
private List<Statement> getDelegate() {
284+
if (delegate == null) {
285+
Block block = new Block();
286+
lonelyStatement.replaceWith(block);
287+
delegate = block.getStatements();
288+
delegate.add(lonelyStatement);
289+
}
290+
return delegate;
291+
}
292+
293+
public Statement get(int idx) {
294+
if (delegate != null) {
295+
return delegate.get(idx);
296+
}
297+
if (idx != 0) {
298+
throw new IndexOutOfBoundsException();
299+
}
300+
return lonelyStatement;
301+
}
302+
303+
public int size() {
304+
if (delegate != null) {
305+
return delegate.size();
306+
}
307+
return 1;
308+
}
309+
310+
public void add(int idx, Statement stmt) {
311+
getDelegate().add(idx, stmt);
312+
}
270313
}
271314

272315
public static void insertAfter(Statement node, Statement toInsert) {

translator/src/main/resources/com/google/devtools/j2objc/J2ObjC.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ Other options:\n\
4545
--build-closure Translate dependent classes if out-of-date.\n\
4646
--dead-code-report <file> Specify a ProGuard usage report for dead code elimination.\n\
4747
--doc-comments Translate Javadoc comments into Xcode-compatible comments.\n\
48-
--extract-unsequenced Rewrite expressions that would produce unsequenced\
48+
--no-extract-unsequenced Don't rewrite expressions that would produce unsequenced\
4949
\n modification errors.\n\
5050
--generate-deprecated Generate deprecated attributes for deprecated methods,\
5151
\n classes and interfaces.\n\

0 commit comments

Comments
 (0)