public void CachedHashCodeOldExpr() { var literalBv = new LiteralExpr(Token.NoToken, Microsoft.BaseTypes.BigNum.FromInt(0), 4, /*immutable=*/ true); var oldExpr = new OldExpr(Token.NoToken, literalBv, /*immutable=*/ true); Assert.AreEqual(oldExpr.ComputeHashCode(), oldExpr.GetHashCode()); }
public override Expr VisitOldExpr(OldExpr node) { insideOldExpr++; base.VisitOldExpr(node); insideOldExpr--; return(node); }
public Expr Old(Expr operand) { var result = new OldExpr(Token.NoToken, operand, Immutable); result.Type = operand.Type; return(result); }
public virtual Expr VisitOldExpr(OldExpr node) { Contract.Requires(node != null); Contract.Ensures(Contract.Result <Expr>() != null); node.Expr = this.VisitExpr(node.Expr); return(node); }
public override Expr VisitOldExpr(OldExpr node) { if (GetReplacementVariable(node, out var variable)) { return(new IdentifierExpr(variable.tok, variable)); } return(base.VisitOldExpr(node)); }
public override Expr VisitOldExpr(OldExpr node) { var body = Translate(node.Expr); ReturnResult(IsaBoogieTerm.Old(body)); return(node); }
public override Expr VisitOldExpr(OldExpr node) { insideOldExpr++; Expr e = (Expr)this.Visit(node.Expr); insideOldExpr--; return(e); }
public override Expr VisitOldExpr(OldExpr node) { var t = inold; inold = true; var ret = base.VisitOldExpr(node); inold = t; return(ret); }
public override Expr VisitOldExpr(OldExpr node) { var prev = inOld; inOld = true; var ret = base.VisitOldExpr(node); inOld = prev; return(ret); }
protected override bool VisitOneExpr(Expression expr, ref OldExpr /*?*/ enclosingOldContext) { var e = expr as ComprehensionExpr; // only consider quantifiers that are not empty (Bound.Vars.Count > 0) if (e != null && e.BoundVars.Count > 0 && !quantifiers.Contains(e)) { if (e is SetComprehension || e is MapComprehension) { quantifiers.Add(e); quantifierCollections.Add(new QuantifiersCollection(e, Enumerable.Repeat(e, 1), reporter)); } else if (e is ForallExpr || e is ExistsExpr) { var quantifier = e as QuantifierExpr; quantifiers.Add(quantifier); if (quantifier.SplitQuantifier != null) { var collection = quantifier.SplitQuantifier.Select(q => q as ComprehensionExpr).Where(q => q != null); quantifierCollections.Add(new QuantifiersCollection(e, collection, reporter)); quantifiers.UnionWith(quantifier.SplitQuantifier); } else { quantifierCollections.Add(new QuantifiersCollection(e, Enumerable.Repeat(quantifier, 1), reporter)); } } } if (expr is OldExpr) { enclosingOldContext = (OldExpr)expr; } else if (enclosingOldContext != null) // FIXME be more restrctive on the type of stuff that we annotate // Add the association (expr, oldContext) to exprsInOldContext. However, due to chaining expressions, // expr may already be a key in exprsInOldContext. { HashSet <OldExpr> prevValue; if (exprsInOldContext.TryGetValue(expr, out prevValue)) { prevValue.Add(enclosingOldContext); } else { var single = new HashSet <OldExpr>() { enclosingOldContext }; exprsInOldContext.Add(expr, single); } } return(true); }
public static Expr GetChild(this OldExpr e, int number) { switch (number) { case 0: return(e.Expr); default: throw new InvalidOperationException("OldExpr only has one child"); } }
public override Expr VisitOldExpr(OldExpr node) { Set freeVars = new Set(); node.Expr.ComputeFreeVariables(freeVars); foreach (var v in freeVars) { // Note, "v" is either a Variable or a TypeVariable if (v is Variable) { FreeOldVars.Add((Variable)v); } } return node; // don't visit subexpressions, since ComputeFreeVariables has already gone through those }
public override Expr VisitOldExpr(OldExpr node) { //Contract.Requires(node != null); Contract.Ensures(Contract.Result <Expr>() != null); bool previouslyInOld = insideOldExpr; insideOldExpr = true; Expr /*!*/ e = (Expr /*!*/)cce.NonNull(this.Visit(node.Expr)); insideOldExpr = previouslyInOld; return(e); }
public static void SetChild(this OldExpr e, int number, Expr NewChild) { switch (number) { case 0: e.Expr = NewChild; return; default: throw new InvalidOperationException("OldExpr only has one child"); } }
public override Expr VisitOldExpr(OldExpr node) { Contract.Ensures(Contract.Result <Expr>() != null); bool previouslyInOld = insideOldExpr; insideOldExpr = true; Expr tmp = (Expr)this.Visit(node.Expr); OldExpr e = new OldExpr(node.tok, tmp); insideOldExpr = previouslyInOld; return(e); }
public override Expr VisitOldExpr(OldExpr node) { InOldExpr = true; // Go into OldExpr var result = base.VisitOldExpr(node) as OldExpr; // And back out again InOldExpr = false; // Remove the OldExpr node by just returning its Expr return(result.Expr); }
internal static Expression MaybeWrapInOld(Expression expr, bool wrap) { if (wrap && !(expr is NameSegment) && !(expr is IdentifierExpr)) { var newExpr = new OldExpr(expr.tok, expr); newExpr.Type = expr.Type; return(newExpr); } else { return(expr); } }
public override Expr VisitOldExpr(OldExpr node) { if (inOld > 0) { //Log.WriteLine(Log.Warning, "Recursive \"old\" expression"); } inOld++; Expr ret = base.VisitOldExpr(node); inOld--; return(ret); }
public override Expr VisitOldExpr(OldExpr node) { if (oldVarSubst == null) { return(base.VisitOldExpr(node)); } if (node.Expr is IdentifierExpr && oldVarSubst.ContainsKey((node.Expr as IdentifierExpr).Name)) { return(Expr.Ident(oldVarSubst[(node.Expr as IdentifierExpr).Name])); } return(base.VisitOldExpr(node)); }
protected override bool VisitOneStmt(Statement stmt, ref OldExpr /*?*/ st) { if (stmt is ForallStmt) { ForallStmt s = (ForallStmt)stmt; if (s.ForallExpressions != null) { foreach (Expression expr in s.ForallExpressions) { VisitOneExpr(expr, ref st); } } } return(true); }
public override Expr VisitOldExpr(OldExpr node) { var previous = insideOldExpr; insideOldExpr = true; var ret = base.VisitOldExpr(node); insideOldExpr = previous; Debug.Assert(ret is OldExpr); // Drop the "old" return((ret as OldExpr).Expr); }
public override Expr VisitOldExpr(OldExpr node) { var freeVars = new GSet <object>(); node.Expr.ComputeFreeVariables(freeVars); foreach (var v in freeVars) { // Note, "v" is either a Variable or a TypeVariable if (v is Variable vVar && _pred(vVar)) { _freeOldVars.Add(vVar); } } return(node); // don't visit subexpressions, since ComputeFreeVariables has already gone through those }
public override Expr VisitOldExpr(OldExpr node) { var oldGlobals = State.GetCurrentStackFrame().OldGlobals; Debug.Assert(oldGlobals != null, "Old Globals should not be null!"); Debug.Assert(node.Expr is IdentifierExpr && (node.Expr as IdentifierExpr).Decl is GlobalVariable, "Unexpected expression in OldExpr"); var GV = (node.Expr as IdentifierExpr).Decl as GlobalVariable; if (GV == null) { throw new InvalidOperationException("Visited OldExpr but child node was not the expected type"); } Debug.Assert(oldGlobals.ContainsKey(GV), "A global variable is missing from the Current stackframe's list of OldGlobals"); return(oldGlobals[GV]); }
internal static IEnumerable <Expression> MaybeWrapInOld(Expression expr, HashSet <OldExpr> /*?*/ wrap) { Contract.Requires(expr != null); Contract.Requires(wrap == null || wrap.Count != 0); if (wrap != null && !(expr is NameSegment) && !(expr is IdentifierExpr)) { foreach (var w in wrap) { var newExpr = new OldExpr(expr.tok, expr, w.At) { AtLabel = w.AtLabel }; newExpr.Type = expr.Type; yield return(newExpr); } } else { yield return(expr); } }
public virtual void Visit(OldExpr oldExpression) { Visit(oldExpression.E); }
public void ProtectedOldExpr() { var e = new OldExpr(Token.NoToken, Expr.True, /*immutable=*/ true); Assert.Throws(typeof(InvalidOperationException), () => e.Expr = Expr.False); }
private static bool ShallowEq(OldExpr expr1, OldExpr expr2) { return(true); }
public override Expr VisitOldExpr(OldExpr node) { //Contract.Requires(node != null); Contract.Ensures(Contract.Result<Expr>() != null); return base.VisitOldExpr((OldExpr)node.Clone()); }
void ConstAtomExpression(out Expression e, bool allowSemi, bool allowLambda) { Contract.Ensures(Contract.ValueAtReturn(out e) != null); IToken/*!*/ x; BigInteger n; Basetypes.BigDec d; e = dummyExpr; Type toType = null; switch (la.kind) { case 131: { Get(); e = new LiteralExpr(t, false); break; } case 132: { Get(); e = new LiteralExpr(t, true); break; } case 133: { Get(); e = new LiteralExpr(t); break; } case 2: case 3: { Nat(out n); e = new LiteralExpr(t, n); break; } case 4: { Dec(out d); e = new LiteralExpr(t, d); break; } case 19: { Get(); e = new CharLiteralExpr(t, t.val.Substring(1, t.val.Length - 2)); break; } case 20: { Get(); bool isVerbatimString; string s = Util.RemoveParsedStringQuotes(t.val, out isVerbatimString); e = new StringLiteralExpr(t, s, isVerbatimString); break; } case 134: { Get(); e = new ThisExpr(t); break; } case 135: { Get(); x = t; Expect(50); Expression(out e, true, true); Expect(51); e = new UnaryOpExpr(x, UnaryOpExpr.Opcode.Fresh, e); break; } case 136: { Get(); x = t; Expect(50); Expression(out e, true, true); Expect(51); e = new OldExpr(x, e); break; } case 23: { Get(); x = t; Expression(out e, true, true); e = new UnaryOpExpr(x, UnaryOpExpr.Opcode.Cardinality, e); Expect(23); break; } case 8: case 10: { if (la.kind == 8) { Get(); x = t; toType = new IntType(); } else { Get(); x = t; toType = new RealType(); } Expect(50); Expression(out e, true, true); Expect(51); e = new ConversionExpr(x, e, toType); break; } case 50: { ParensExpression(out e, allowSemi, allowLambda); break; } default: SynErr(234); break; } }
public override Expr VisitOldExpr(OldExpr node) { //Contract.Requires(node != null); Contract.Ensures(Contract.Result<Expr>() != null); insideOldExpr++; node.Expr = this.VisitExpr(node.Expr); insideOldExpr--; return node; }
public override Expr VisitOldExpr(OldExpr node) { return(node); }
public void ProtectedOldExpr() { var e = new OldExpr(Token.NoToken, Expr.True, /*immutable=*/ true); e.Expr = Expr.False; }
public void CachedHashCodeOldExpr() { var literalBv = new LiteralExpr(Token.NoToken, Microsoft.Basetypes.BigNum.FromInt(0), 4, /*immutable=*/true); var oldExpr = new OldExpr(Token.NoToken, literalBv, /*immutable=*/true); Assert.AreEqual(oldExpr.ComputeHashCode(), oldExpr.GetHashCode()); }
public virtual Expr VisitOldExpr(OldExpr node) { Contract.Requires(node != null); Contract.Ensures(Contract.Result<Expr>() != null); node.Expr = this.VisitExpr(node.Expr); return node; }
public override Expr VisitOldExpr(OldExpr node) { //Contract.Requires(node != null); Contract.Ensures(Contract.Result<Expr>() != null); bool previouslyInOld = insideOldExpr; insideOldExpr = true; Expr/*!*/ e = (Expr/*!*/)cce.NonNull(this.Visit(node.Expr)); insideOldExpr = previouslyInOld; return e; }
public override Expr VisitOldExpr(OldExpr node) { Contract.Ensures(Contract.Result<Expr>() == node); this.VisitExpr(node.Expr); return node; }
public override Expr VisitOldExpr(OldExpr node) { Contract.Ensures(Contract.Result<Expr>() != null); bool previouslyInOld = insideOldExpr; insideOldExpr = true; Expr tmp = (Expr)this.Visit(node.Expr); OldExpr e = new OldExpr(node.tok, tmp); insideOldExpr = previouslyInOld; return e; }
public string GenerateString(OldExpr expression) { return(expression.tok.val + "(" + GenerateString(expression.E) + ")"); }
public override Expr VisitOldExpr(OldExpr node) { // don't recurse on subexpression return node; }
public override Expr VisitOldExpr(OldExpr node) { add(node); return(base.VisitOldExpr(node)); }
void AtomExpression(out Expr/*!*/ e) { Contract.Ensures(Contract.ValueAtReturn(out e) != null); IToken/*!*/ x; int n; BigNum bn; BigDec bd; BigFloat bf; List<Expr>/*!*/ es; List<Variable>/*!*/ ds; Trigger trig; List<TypeVariable>/*!*/ typeParams; IdentifierExpr/*!*/ id; QKeyValue kv; e = dummyExpr; List<Variable>/*!*/ locals; List<Block/*!*/>/*!*/ blocks; switch (la.kind) { case 83: { Get(); e = new LiteralExpr(t, false); break; } case 84: { Get(); e = new LiteralExpr(t, true); break; } case 3: { Nat(out bn); e = new LiteralExpr(t, bn); break; } case 5: case 6: { Dec(out bd); e = new LiteralExpr(t, bd); break; } case 7: { Float(out bf); e = new LiteralExpr(t, bf); break; } case 2: { BvLit(out bn, out n); e = new LiteralExpr(t, bn, n); break; } case 1: { Ident(out x); id = new IdentifierExpr(x, x.val); e = id; if (la.kind == 10) { Get(); if (StartOf(9)) { Expressions(out es); e = new NAryExpr(x, new FunctionCall(id), es); } else if (la.kind == 11) { e = new NAryExpr(x, new FunctionCall(id), new List<Expr>()); } else SynErr(124); Expect(11); } break; } case 85: { Get(); x = t; Expect(10); Expression(out e); Expect(11); e = new OldExpr(x, e); break; } case 15: { Get(); x = t; Expect(10); Expression(out e); Expect(11); e = new NAryExpr(x, new ArithmeticCoercion(x, ArithmeticCoercion.CoercionType.ToInt), new List<Expr>{ e }); break; } case 16: { Get(); x = t; Expect(10); Expression(out e); Expect(11); e = new NAryExpr(x, new ArithmeticCoercion(x, ArithmeticCoercion.CoercionType.ToReal), new List<Expr>{ e }); break; } case 10: { Get(); if (StartOf(9)) { Expression(out e); if (e is BvBounds) this.SemErr("parentheses around bitvector bounds " + "are not allowed"); } else if (la.kind == 89 || la.kind == 90) { Forall(); x = t; QuantifierBody(x, out typeParams, out ds, out kv, out trig, out e); if (typeParams.Count + ds.Count > 0) e = new ForallExpr(x, typeParams, ds, kv, trig, e); } else if (la.kind == 91 || la.kind == 92) { Exists(); x = t; QuantifierBody(x, out typeParams, out ds, out kv, out trig, out e); if (typeParams.Count + ds.Count > 0) e = new ExistsExpr(x, typeParams, ds, kv, trig, e); } else if (la.kind == 93 || la.kind == 94) { Lambda(); x = t; QuantifierBody(x, out typeParams, out ds, out kv, out trig, out e); if (trig != null) SemErr("triggers not allowed in lambda expressions"); if (typeParams.Count + ds.Count > 0) e = new LambdaExpr(x, typeParams, ds, kv, e); } else SynErr(125); Expect(11); break; } case 41: { IfThenElseExpression(out e); break; } case 86: { CodeExpression(out locals, out blocks); e = new CodeExpr(locals, blocks); break; } default: SynErr(126); break; } }
void ConstAtomExpression(out Expression e, bool allowSemi, bool allowLambda) { Contract.Ensures(Contract.ValueAtReturn(out e) != null); IToken/*!*/ x; BigInteger n; Basetypes.BigDec d; e = dummyExpr; Type toType = null; switch (la.kind) { case 138: { Get(); e = new LiteralExpr(t, false); break; } case 139: { Get(); e = new LiteralExpr(t, true); break; } case 140: { Get(); e = new LiteralExpr(t); break; } case 2: case 3: { Nat(out n); e = new LiteralExpr(t, n); break; } case 4: { Dec(out d); e = new LiteralExpr(t, d); break; } case 20: { Get(); e = new CharLiteralExpr(t, t.val.Substring(1, t.val.Length - 2)); break; } case 21: { Get(); bool isVerbatimString; string s = Util.RemoveParsedStringQuotes(t.val, out isVerbatimString); e = new StringLiteralExpr(t, s, isVerbatimString); break; } case 141: { Get(); e = new ThisExpr(t); break; } case 142: { Get(); x = t; Expect(54); Expression(out e, true, true); Expect(55); e = new UnaryOpExpr(x, UnaryOpExpr.Opcode.Fresh, e); break; } case 143: { Get(); x = t; Expect(54); Expression(out e, true, true); Expect(55); e = new UnaryOpExpr(x, UnaryOpExpr.Opcode.Allocated, e); break; } case 144: { Get(); x = t; FrameExpression fe; var mod = new List<FrameExpression>(); Expect(54); FrameExpression(out fe, false, false); mod.Add(fe); while (la.kind == 23) { Get(); FrameExpression(out fe, false, false); mod.Add(fe); } Expect(55); e = new UnchangedExpr(x, mod); break; } case 145: { Get(); x = t; Expect(54); Expression(out e, true, true); Expect(55); e = new OldExpr(x, e); break; } case 24: { Get(); x = t; Expression(out e, true, true, false); e = new UnaryOpExpr(x, UnaryOpExpr.Opcode.Cardinality, e); Expect(24); break; } case 9: case 11: { if (la.kind == 9) { Get(); x = t; toType = new IntType(); } else { Get(); x = t; toType = new RealType(); } errors.Deprecated(t, string.Format("the syntax \"{0}(expr)\" for type conversions has been deprecated; the new syntax is \"expr as {0}\"", x.val)); Expect(54); Expression(out e, true, true); Expect(55); e = new ConversionExpr(x, e, toType); break; } case 54: { ParensExpression(out e, allowSemi, allowLambda); break; } default: SynErr(262); break; } }