void writeExpr(Expr expr) throws IOException { writeLocation(expr.getLocation()); expr.acceptVisitor(this); }
private Expr compare(BinaryOperation op, OperationType type, Variable value) { Expr expr = Expr.binary(op, type, Expr.var(value.getIndex()), Expr.constant(0)); expr.setLocation(currentLocation); return expr; }
protected abstract Expr clone(Map<Expr, Expr> cache);
public static Expr binary(BinaryOperation op, OperationType type, Expr first, Expr second, TextLocation loc) { Expr expr = binary(op, type, first, second); expr.setLocation(loc); return expr; }
List<Statement> sequenceBackup = resultSequence; resultSequence = new ArrayList<>(); statement.getCondition().acceptVisitor(this); statement.setCondition(resultExpr); resultSequence = sequenceBackup; statement.getBody().remove(0); if (statement.getCondition() != null) { Expr newCondition = Expr.binary(BinaryOperation.AND, null, statement.getCondition(), ExprOptimizer.invert(cond.getCondition())); newCondition.setLocation(statement.getCondition().getLocation()); statement.setCondition(newCondition); } else {
@Override public void visit(SubscriptExpr expr) { expr.getArray().acceptVisitor(this); expr.getIndex().acceptVisitor(this); }
public static Expr invert(Expr expr) { if (expr instanceof UnaryExpr) { UnaryExpr unary = (UnaryExpr) expr; if (unary.getOperation() == UnaryOperation.NOT) { return unary.getOperand(); } } else if (expr instanceof BinaryExpr) { BinaryExpr binary = (BinaryExpr) expr; Expr a = binary.getFirstOperand(); Expr b = binary.getSecondOperand(); switch (binary.getOperation()) { case EQUALS: return Expr.binary(BinaryOperation.NOT_EQUALS, binary.getType(), a, b, expr.getLocation()); case NOT_EQUALS: return Expr.binary(BinaryOperation.EQUALS, binary.getType(), a, b, expr.getLocation()); case LESS: return Expr.binary(BinaryOperation.GREATER_OR_EQUALS, binary.getType(), a, b, expr.getLocation()); case LESS_OR_EQUALS: return Expr.binary(BinaryOperation.GREATER, binary.getType(), a, b, expr.getLocation()); case GREATER: return Expr.binary(BinaryOperation.LESS_OR_EQUALS, binary.getType(), a, b, expr.getLocation()); case GREATER_OR_EQUALS: return Expr.binary(BinaryOperation.LESS, binary.getType(), a, b, expr.getLocation()); default: break; } } return Expr.invert(expr); } }
break; case NOT_NULL: branch(Expr.binary(BinaryOperation.NOT_EQUALS, null, Expr.var(insn.getOperand().getIndex()), Expr.constant(null)), insn.getConsequent(), insn.getAlternative()); break; case NULL: branch(Expr.binary(BinaryOperation.EQUALS, null, Expr.var(insn.getOperand().getIndex()), Expr.constant(null)), insn.getConsequent(), insn.getAlternative()); break;
@Override public void visit(ConstructMultiArrayInstruction insn) { Expr[] dimensionExprs = new Expr[insn.getDimensions().size()]; for (int i = 0; i < dimensionExprs.length; ++i) { dimensionExprs[i] = Expr.var(insn.getDimensions().get(i).getIndex()); } assign(Expr.createArray(insn.getItemType(), dimensionExprs), insn.getReceiver()); }
@Override public void visit(NullConstantInstruction insn) { assign(Expr.constant(null), insn.getReceiver()); }
@Override public void visit(IsInstanceInstruction insn) { assign(Expr.instanceOf(Expr.var(insn.getValue().getIndex()), insn.getType()), insn.getReceiver()); }
cond.getConsequent().clear(); cond.getConsequent().addAll(innerCond.getConsequent()); cond.setCondition(Expr.binary(BinaryOperation.AND, null, cond.getCondition(), innerCond.getCondition(), cond.getCondition().getLocation())); --i; } else if (cond.getAlternative().size() != 1
public static Expr invert(Expr expr) { UnaryExpr result = new UnaryExpr(); result.setOperand(expr); result.setOperation(UnaryOperation.NOT); result.setLocation(expr.getLocation()); return result; }
@Override public void visit(ConstructInstruction insn) { assign(Expr.createObject(insn.getType()), insn.getReceiver()); }
InvocationExpr constructrExpr = Expr.constructObject(expr.getMethod(), args); constructrExpr.setLocation(expr.getLocation()); assignment.setRightValue(constructrExpr);
List<Statement> sequenceBackup = resultSequence; resultSequence = new ArrayList<>(); statement.getCondition().acceptVisitor(this); statement.setCondition(resultExpr); resultSequence = sequenceBackup; statement.getBody().remove(0); if (statement.getCondition() != null) { Expr newCondition = Expr.binary(BinaryOperation.AND, null, statement.getCondition(), ExprOptimizer.invert(cond.getCondition())); newCondition.setLocation(statement.getCondition().getLocation()); statement.setCondition(newCondition); } else {
@Override public void visit(MonitorExitStatement statement) { statement.getObjectRef().acceptVisitor(this); } }
public static Expr invert(Expr expr) { if (expr instanceof UnaryExpr) { UnaryExpr unary = (UnaryExpr) expr; if (unary.getOperation() == UnaryOperation.NOT) { return unary.getOperand(); } } else if (expr instanceof BinaryExpr) { BinaryExpr binary = (BinaryExpr) expr; Expr a = binary.getFirstOperand(); Expr b = binary.getSecondOperand(); switch (binary.getOperation()) { case EQUALS: return Expr.binary(BinaryOperation.NOT_EQUALS, binary.getType(), a, b, expr.getLocation()); case NOT_EQUALS: return Expr.binary(BinaryOperation.EQUALS, binary.getType(), a, b, expr.getLocation()); case LESS: return Expr.binary(BinaryOperation.GREATER_OR_EQUALS, binary.getType(), a, b, expr.getLocation()); case LESS_OR_EQUALS: return Expr.binary(BinaryOperation.GREATER, binary.getType(), a, b); case GREATER: return Expr.binary(BinaryOperation.LESS_OR_EQUALS, binary.getType(), a, b, expr.getLocation()); case GREATER_OR_EQUALS: return Expr.binary(BinaryOperation.LESS, binary.getType(), a, b, expr.getLocation()); default: break; } } return Expr.invert(expr); } }
break; case NOT_NULL: branch(Expr.binary(BinaryOperation.NOT_EQUALS, null, Expr.var(insn.getOperand().getIndex()), Expr.constant(null)), insn.getConsequent(), insn.getAlternative()); break; case NULL: branch(Expr.binary(BinaryOperation.EQUALS, null, Expr.var(insn.getOperand().getIndex()), Expr.constant(null)), insn.getConsequent(), insn.getAlternative()); break;