/** * Transform a reference to a pruned instance field into a reference to the null field, which will * be used to replace <code>x</code>. */ public static JFieldRef transformToNullFieldRef(JFieldRef x, JProgram program) { JExpression instance = x.getInstance(); /* * We assert that field must be non-static if it's an rvalue, otherwise it * would have been rescued. */ // assert !x.getField().isStatic(); /* * HACK HACK HACK: ControlFlowAnalyzer has special hacks for dealing with * ClassLiterals, which causes the body of ClassLiteralHolder's clinit to * never be rescured. This in turn causes invalid references to static * methods, which violates otherwise good assumptions about compiler * operation. * * TODO: Remove this when ControlFlowAnalyzer doesn't special-case * CLH.clinit(). */ if (x.getField().isStatic() && instance == null) { instance = program.getLiteralNull(); } assert instance != null; if (!instance.hasSideEffects()) { instance = program.getLiteralNull(); } JFieldRef fieldRef = new JFieldRef( x.getSourceInfo(), instance, program.getNullField(), x.getEnclosingType(), primitiveTypeOrNullTypeOrArray(program, x.getType())); return fieldRef; }
private JExpression makeReplacementForAssignment( SourceInfo info, JVariableRef variableRef, JExpression rhs) { // Replace with a multi, which may wind up empty. JMultiExpression multi = new JMultiExpression(info); // If the lhs is a field ref, evaluate it first. if (variableRef instanceof JFieldRef) { JFieldRef fieldRef = (JFieldRef) variableRef; JExpression instance = fieldRef.getInstance(); if (instance != null) { multi.addExpressions(instance); } } // If there is an rhs, evaluate it second. if (rhs != null) { multi.addExpressions(rhs); } if (multi.getNumberOfExpressions() == 1) { return multi.getExpression(0); } else { return multi; } }