public override WExpr InterpretModel(Context context, Model model, ProgramBuilder builder) { WExpr rv = new WEIf((WCond)this.condition.InterpretModel(context, model, builder), this.thenBody.InterpretModel(context, model, builder), (elseBody != null) ? this.elseBody.InterpretModel(context, model, builder) : null); builder.CheckExpr(rv); return(rv); }
public override bool KeepProgram(WExpr expr) { #region filter out: x_i = x_i if (expr is WEArith) { WEArith e = (WEArith)expr; if (e.op == WEArith.ArithOp.plus || e.op == WEArith.ArithOp.minus) { if (e.arg1 is WEVar && e.arg2 is WEConst) { if (e.lhs.id == ((WEVar)e.arg1).id && ((WEConst)e.arg2).value == 0) { return(false); } } if (e.arg2 is WEVar && e.arg1 is WEConst) { if (e.lhs.id == ((WEVar)e.arg2).id && ((WEConst)e.arg1).value == 0) { return(false); } } } } #endregion #region filter out: x = x_i - x_i if (expr is WEArith) { WEArith e = (WEArith)expr; if (e.op == WEArith.ArithOp.minus) { if (e.arg1 is WEVar && e.arg2 is WEVar) { if (((WEVar)e.arg1).id == ((WEVar)e.arg2).id) { return(false); } } } } #endregion #region filter out: unsatisfiable and tautological comparisons if (expr is WCComparison) { WCComparison e = (WCComparison)expr; if (e.arg2 is WEVar) { if (e.arg1.id == ((WEVar)e.arg2).id) { return(false); } } else { if (e.arg2.IsZero() && e.op == WCComparison.CompareType.l) { return(false); } } } #endregion #region filter out: if statements where the <then> and <else> parts are the same if (expr is WEIf) { WEIf e = (WEIf)expr; if (e.elseBody != null) { if (e.thenBody.ToString() == e.elseBody.ToString()) { return(false); } } } #endregion #region filter out: compound conditions of the form C_i op C_i if (expr is WCCompound) { WCCompound e = (WCCompound)expr; if (e.cond1.ToString() == e.cond2.ToString()) { return(false); } } #endregion return(true); }