private List <Expression> SplitExpression(BinaryExpr.Opcode op, BinaryExpr expression) { var expList = new List <Expression>(); if (!expression.Op.Equals(op)) { expList.Add(expression); } else if (IsChained(expression)) { expList.Add(expression); expList.AddRange(SplitExpression(op, expression.E0 as BinaryExpr)); expList.AddRange(SplitExpression(op, expression.E1 as BinaryExpr)); } else { if (!(expression.E0 is BinaryExpr)) { expList.Add(expression.E0); } else { expList.AddRange(SplitExpression(op, expression.E0 as BinaryExpr)); } if (!(expression.E1 is BinaryExpr)) { expList.Add(expression.E1); } else { expList.AddRange(SplitExpression(op, expression.E1 as BinaryExpr)); } } return(expList); }
public static BinaryExpr MakeBinaryExpr(BinaryExpr.Opcode op, BinaryExpr.ResolvedOpcode rop, Type t, Expression e0, Expression e1) { Util.Assert(t != null && e0.Type != null && e1.Type != null); BinaryExpr e = new BinaryExpr(e0.tok, op, e0, e1); e.ResolvedOp = rop; e.Type = t; return(e); }
internal static IEnumerable <Expression> SplitAndStich(BinaryExpr pair, BinaryExpr.Opcode separator) { foreach (var e1 in SplitExpr(pair.E1, separator)) { // Notice the token. This makes triggers/splitting-picks-the-right-tokens.dfy possible yield return(new BinaryExpr(e1.tok, pair.Op, pair.E0, e1) { ResolvedOp = pair.ResolvedOp, Type = pair.Type }); } }
private static BinaryExpr.Opcode FlipOpcode(BinaryExpr.Opcode opCode) { if (opCode == BinaryExpr.Opcode.And) { return(BinaryExpr.Opcode.Or); } else if (opCode == BinaryExpr.Opcode.Or) { return(BinaryExpr.Opcode.And); } else { throw new ArgumentException(); } }
internal static IEnumerable <Expression> SplitExpr(Expression expr, BinaryExpr.Opcode separator) { expr = expr.Resolved; var unary = expr as UnaryOpExpr; var binary = expr as BinaryExpr; if (unary != null && unary.Op == UnaryOpExpr.Opcode.Not) { foreach (var e in SplitExpr(unary.E, FlipOpcode(separator))) { yield return(Not(e)); } } else if (binary != null && binary.Op == separator) { foreach (var e in SplitExpr(binary.E0, separator)) { yield return(e); } foreach (var e in SplitExpr(binary.E1, separator)) { yield return(e); } } else if (binary != null && binary.Op == BinaryExpr.Opcode.Imp && separator == BinaryExpr.Opcode.Or) { foreach (var e in SplitExpr(Not(binary.E0), separator)) { yield return(e); } foreach (var e in SplitExpr(binary.E1, separator)) { yield return(e); } } else { yield return(expr); } }
public string GenerateString(BinaryExpr.Opcode opcode) { switch (opcode) { case BinaryExpr.Opcode.Ge: return(">="); case BinaryExpr.Opcode.Gt: return(">"); case BinaryExpr.Opcode.Le: return("<="); case BinaryExpr.Opcode.Lt: return("<"); case BinaryExpr.Opcode.Eq: return("=="); case BinaryExpr.Opcode.Neq: return("!="); case BinaryExpr.Opcode.Add: return("+"); case BinaryExpr.Opcode.Sub: return("-"); case BinaryExpr.Opcode.Mul: return("*"); case BinaryExpr.Opcode.Div: return("/"); case BinaryExpr.Opcode.Mod: return("%"); case BinaryExpr.Opcode.And: return("&&"); case BinaryExpr.Opcode.Or: return("||"); case BinaryExpr.Opcode.Imp: return("==>"); case BinaryExpr.Opcode.Exp: return("<=="); case BinaryExpr.Opcode.In: return("in"); case BinaryExpr.Opcode.NotIn: return("!in"); case BinaryExpr.Opcode.Disjoint: return("!!"); default: throw new NotImplementedException(); } }