public static IEnumerable<ProofState> RegisterVariable(TacticVarDeclStmt declaration, ProofState state) { if(declaration.Update == null) yield break; var rhs = declaration.Update as UpdateStmt; if(rhs == null) { // check if rhs is SuchThatStmt if(declaration.Update is AssignSuchThatStmt) { foreach(var item in declaration.Locals) state.AddTacnyVar(item, null); foreach(var item in EvalSuchThatStmt(declaration.Update as AssignSuchThatStmt, state)) { yield return item.Copy(); } } else { foreach(var item in declaration.Locals) state.AddTacnyVar(item, null); } } else { foreach(var item in rhs.Rhss) { int index = rhs.Rhss.IndexOf(item); Contract.Assert(declaration.Locals.ElementAtOrDefault(index) != null, "register var err"); var exprRhs = item as ExprRhs; if(exprRhs?.Expr is ApplySuffix) { var aps = (ApplySuffix)exprRhs.Expr; foreach(var result in EvalTacnyExpression(state, aps)) { state.AddTacnyVar(declaration.Locals[index], result); } } else if(exprRhs?.Expr is Dafny.LiteralExpr) { state.AddTacnyVar(declaration.Locals[index], (Dafny.LiteralExpr)exprRhs?.Expr); } else if(exprRhs?.Expr is Dafny.NameSegment) { var name = ((Dafny.NameSegment)exprRhs.Expr).Name; if(state.ContainTacnyVal(name)) // in the case that referring to an exisiting tvar, dereference it state.AddTacnyVar(declaration.Locals[index], state.GetTacnyVarValue(name)); } else { state.AddTacnyVar(declaration.Locals[index], exprRhs?.Expr); } } } yield return state.Copy(); }
public static IEnumerable <ProofState> RegisterVariable(TacticVarDeclStmt declaration, ProofState state) { if (declaration.Update == null) { yield break; } var rhs = declaration.Update as UpdateStmt; if (rhs == null) { // check if rhs is SuchThatStmt if (declaration.Update is AssignSuchThatStmt) { foreach (var item in declaration.Locals) { state.AddTacnyVar(item, null); } foreach (var item in EvalSuchThatStmt(declaration.Update as AssignSuchThatStmt, state)) { yield return(item.Copy()); } } else { foreach (var item in declaration.Locals) { state.AddTacnyVar(item, null); } } } else { foreach (var item in rhs.Rhss) { int index = rhs.Rhss.IndexOf(item); Contract.Assert(declaration.Locals.ElementAtOrDefault(index) != null, "register var err"); var exprRhs = item as ExprRhs; if (exprRhs?.Expr is ApplySuffix) { var aps = (ApplySuffix)exprRhs.Expr; foreach (var result in EvalTacnyExpression(state, aps)) { state.AddTacnyVar(declaration.Locals[index], result); } } else if (exprRhs?.Expr is Dafny.LiteralExpr) { state.AddTacnyVar(declaration.Locals[index], (Dafny.LiteralExpr)exprRhs?.Expr); } else if (exprRhs?.Expr is Dafny.NameSegment) { var name = ((Dafny.NameSegment)exprRhs.Expr).Name; if (state.ContainTacnyVal(name)) { // in the case that referring to an exisiting tvar, dereference it state.AddTacnyVar(declaration.Locals[index], state.GetTacnyVarValue(name)); } } else { state.AddTacnyVar(declaration.Locals[index], exprRhs?.Expr); } } } yield return(state.Copy()); }