Skip to content

Commit 9bc061c

Browse files
authored
Reduce code size
1 parent d9e7253 commit 9bc061c

File tree

1 file changed

+30
-51
lines changed

1 file changed

+30
-51
lines changed

dataflow/src/main/java/org/checkerframework/dataflow/cfg/builder/CFGTranslationPhaseOne.java

Lines changed: 30 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1947,7 +1947,6 @@ public Node visitCompoundAssignment(CompoundAssignmentTree tree, Void p) {
19471947
} else if (kind == Tree.Kind.DIVIDE_ASSIGNMENT) {
19481948
if (TypesUtils.isIntegralPrimitive(exprType)) {
19491949
operNode = new IntegerDivisionNode(operTree, targetRHS, value);
1950-
19511950
extendWithNodeWithException(operNode, arithmeticExceptionType);
19521951
} else {
19531952
operNode = new FloatingDivisionNode(operTree, targetRHS, value);
@@ -1956,7 +1955,6 @@ public Node visitCompoundAssignment(CompoundAssignmentTree tree, Void p) {
19561955
assert kind == Tree.Kind.REMAINDER_ASSIGNMENT;
19571956
if (TypesUtils.isIntegralPrimitive(exprType)) {
19581957
operNode = new IntegerRemainderNode(operTree, targetRHS, value);
1959-
19601958
extendWithNodeWithException(operNode, arithmeticExceptionType);
19611959
} else {
19621960
operNode = new FloatingRemainderNode(operTree, targetRHS, value);
@@ -2133,7 +2131,7 @@ public Node visitBinary(BinaryTree tree, Void p) {
21332131
// Note that for binary operations it is important to perform any required promotion on the
21342132
// left operand before generating any Nodes for the right operand, because labels must be
21352133
// inserted AFTER ALL preceding Nodes and BEFORE ALL following Nodes.
2136-
Node r = null;
2134+
Node r;
21372135
Tree leftTree = tree.getLeftOperand();
21382136
Tree rightTree = tree.getRightOperand();
21392137

@@ -2158,7 +2156,6 @@ public Node visitBinary(BinaryTree tree, Void p) {
21582156
} else if (kind == Tree.Kind.DIVIDE) {
21592157
if (TypesUtils.isIntegralPrimitive(exprType)) {
21602158
r = new IntegerDivisionNode(tree, left, right);
2161-
21622159
extendWithNodeWithException(r, arithmeticExceptionType);
21632160
} else {
21642161
r = new FloatingDivisionNode(tree, left, right);
@@ -2167,7 +2164,6 @@ public Node visitBinary(BinaryTree tree, Void p) {
21672164
assert kind == Tree.Kind.REMAINDER;
21682165
if (TypesUtils.isIntegralPrimitive(exprType)) {
21692166
r = new IntegerRemainderNode(tree, left, right);
2170-
21712167
extendWithNodeWithException(r, arithmeticExceptionType);
21722168
} else {
21732169
r = new FloatingRemainderNode(tree, left, right);
@@ -2247,21 +2243,17 @@ public Node visitBinary(BinaryTree tree, Void p) {
22472243
Node left = binaryNumericPromotion(scan(leftTree, p), promotedType);
22482244
Node right = binaryNumericPromotion(scan(rightTree, p), promotedType);
22492245

2250-
Node node;
22512246
if (kind == Tree.Kind.GREATER_THAN) {
2252-
node = new GreaterThanNode(tree, left, right);
2247+
r = new GreaterThanNode(tree, left, right);
22532248
} else if (kind == Tree.Kind.GREATER_THAN_EQUAL) {
2254-
node = new GreaterThanOrEqualNode(tree, left, right);
2249+
r = new GreaterThanOrEqualNode(tree, left, right);
22552250
} else if (kind == Tree.Kind.LESS_THAN) {
2256-
node = new LessThanNode(tree, left, right);
2251+
r = new LessThanNode(tree, left, right);
22572252
} else {
22582253
assert kind == Tree.Kind.LESS_THAN_EQUAL;
2259-
node = new LessThanOrEqualNode(tree, left, right);
2254+
r = new LessThanOrEqualNode(tree, left, right);
22602255
}
2261-
2262-
extendWithNode(node);
2263-
2264-
return node;
2256+
break;
22652257
}
22662258

22672259
case EQUAL_TO:
@@ -2289,16 +2281,13 @@ public Node visitBinary(BinaryTree tree, Void p) {
22892281
right = unboxAsNeeded(right, rightInfo.isBoxed());
22902282
}
22912283

2292-
Node node;
22932284
if (kind == Tree.Kind.EQUAL_TO) {
2294-
node = new EqualToNode(tree, left, right);
2285+
r = new EqualToNode(tree, left, right);
22952286
} else {
22962287
assert kind == Tree.Kind.NOT_EQUAL_TO;
2297-
node = new NotEqualNode(tree, left, right);
2288+
r = new NotEqualNode(tree, left, right);
22982289
}
2299-
extendWithNode(node);
2300-
2301-
return node;
2290+
break;
23022291
}
23032292

23042293
case AND:
@@ -2326,19 +2315,15 @@ public Node visitBinary(BinaryTree tree, Void p) {
23262315
right = unbox(scan(rightTree, p));
23272316
}
23282317

2329-
Node node;
23302318
if (kind == Tree.Kind.AND) {
2331-
node = new BitwiseAndNode(tree, left, right);
2319+
r = new BitwiseAndNode(tree, left, right);
23322320
} else if (kind == Tree.Kind.OR) {
2333-
node = new BitwiseOrNode(tree, left, right);
2321+
r = new BitwiseOrNode(tree, left, right);
23342322
} else {
23352323
assert kind == Tree.Kind.XOR;
2336-
node = new BitwiseXorNode(tree, left, right);
2324+
r = new BitwiseXorNode(tree, left, right);
23372325
}
2338-
2339-
extendWithNode(node);
2340-
2341-
return node;
2326+
break;
23422327
}
23432328

23442329
case CONDITIONAL_AND:
@@ -2369,14 +2354,12 @@ public Node visitBinary(BinaryTree tree, Void p) {
23692354

23702355
// conditional expression itself
23712356
addLabelForNextNode(shortCircuitLabel);
2372-
Node node;
23732357
if (kind == Tree.Kind.CONDITIONAL_AND) {
2374-
node = new ConditionalAndNode(tree, left, right);
2358+
r = new ConditionalAndNode(tree, left, right);
23752359
} else {
2376-
node = new ConditionalOrNode(tree, left, right);
2360+
r = new ConditionalOrNode(tree, left, right);
23772361
}
2378-
extendWithNode(node);
2379-
return node;
2362+
break;
23802363
}
23812364
default:
23822365
throw new BugInCF("unexpected binary tree: " + kind);
@@ -2864,16 +2847,16 @@ private IPair<IdentifierTree, LocalVariableNode> buildVarUseNode(VariableTree va
28642847
@Override
28652848
public Node visitContinue(ContinueTree tree, Void p) {
28662849
Name label = tree.getLabel();
2850+
UnconditionalJump uj;
28672851
if (label == null) {
28682852
assert continueTargetLC != null : "no target for continue statement";
2869-
2870-
extendWithExtendedNode(new UnconditionalJump(continueTargetLC.accessLabel()));
2853+
uj = new UnconditionalJump(continueTargetLC.accessLabel());
28712854
} else {
28722855
assert continueLabels.containsKey(label);
2873-
2874-
extendWithExtendedNode(new UnconditionalJump(continueLabels.get(label)));
2856+
uj = new UnconditionalJump(continueLabels.get(label));
28752857
}
28762858

2859+
extendWithExtendedNode(uj);
28772860
return null;
28782861
}
28792862

@@ -3421,7 +3404,7 @@ public Node visitLabeledStatement(LabeledStatementTree tree, Void p) {
34213404

34223405
@Override
34233406
public Node visitLiteral(LiteralTree tree, Void p) {
3424-
Node r = null;
3407+
Node r;
34253408
switch (tree.getKind()) {
34263409
case BOOLEAN_LITERAL:
34273410
r = new BooleanLiteralNode(tree);
@@ -3450,7 +3433,6 @@ public Node visitLiteral(LiteralTree tree, Void p) {
34503433
default:
34513434
throw new BugInCF("unexpected literal tree: " + tree);
34523435
}
3453-
assert r != null : "unexpected literal tree";
34543436
extendWithNode(r);
34553437
return r;
34563438
}
@@ -4169,7 +4151,7 @@ public Node visitInstanceOf(InstanceOfTree tree, Void p) {
41694151

41704152
@Override
41714153
public Node visitUnary(UnaryTree tree, Void p) {
4172-
Node result = null;
4154+
Node result;
41734155
Tree.Kind kind = tree.getKind();
41744156
switch (kind) {
41754157
case BITWISE_COMPLEMENT:
@@ -4196,7 +4178,7 @@ public Node visitUnary(UnaryTree tree, Void p) {
41964178
throw new BugInCF("Unexpected unary tree kind: " + kind);
41974179
}
41984180
extendWithNode(result);
4199-
break;
4181+
return result;
42004182
}
42014183

42024184
case LOGICAL_COMPLEMENT:
@@ -4205,7 +4187,7 @@ public Node visitUnary(UnaryTree tree, Void p) {
42054187
Node expr = scan(tree.getExpression(), p);
42064188
result = new ConditionalNotNode(tree, unbox(expr));
42074189
extendWithNode(result);
4208-
break;
4190+
return result;
42094191
}
42104192

42114193
case POSTFIX_DECREMENT:
@@ -4249,13 +4231,12 @@ public Node visitUnary(UnaryTree tree, Void p) {
42494231
result = new LocalVariableNode(resultExpr);
42504232
result.setInSource(false);
42514233
extendWithNode(result);
4234+
createIncrementOrDecrementAssign(tree, expr, isIncrement, isPostfix);
4235+
} else {
4236+
result = createIncrementOrDecrementAssign(tree, expr, isIncrement, isPostfix);
4237+
extendWithNode(result);
42524238
}
4253-
AssignmentNode unaryAssign =
4254-
createIncrementOrDecrementAssign(tree, expr, isIncrement, isPostfix);
4255-
if (!isPostfix) {
4256-
result = unaryAssign;
4257-
}
4258-
break;
4239+
return result;
42594240
}
42604241

42614242
case OTHER:
@@ -4265,13 +4246,11 @@ public Node visitUnary(UnaryTree tree, Void p) {
42654246
Node expr = scan(tree.getExpression(), p);
42664247
result = new NullChkNode(tree, expr);
42674248
extendWithNode(result);
4268-
break;
4249+
return result;
42694250
}
42704251

42714252
throw new BugInCF("Unknown kind (" + kind + ") of unary expression: " + tree);
42724253
}
4273-
4274-
return result;
42754254
}
42764255

42774256
/**

0 commit comments

Comments
 (0)