private void TransformRegion(IRegion region) { List <PredicateCmd> genuineInvariants = new List <PredicateCmd>(); List <PredicateCmd> oldCandidateInvariants = new List <PredicateCmd>(); foreach (var inv in region.RemoveInvariants()) { string c; if (Houdini.MatchCandidate(inv.Expr, candidates, out c)) { Debug.Assert(inv is AssertCmd); oldCandidateInvariants.Add(inv); } else { genuineInvariants.Add(inv); } } TransformPow2Candidates(region, oldCandidateInvariants); TransformImplicationCandidates(region, oldCandidateInvariants); TransformRemainingCandidates(region, oldCandidateInvariants); foreach (var p in genuineInvariants) { region.AddInvariant(p); } }
private void TransformPow2Candidates(IRegion region, List <PredicateCmd> oldCandidateInvariants) { IdentifierExpr v = null; do { foreach (var p in oldCandidateInvariants) { v = TryGetPow2VariableFromCandidate(p); if (v != null) { break; } } if (v != null) { oldCandidateInvariants.RemoveAll(item => TryGetPow2VariableFromCandidate(item) != null && TryGetPow2VariableFromCandidate(item).Name.Equals(v.Name)); Function pow2ExistentialFunction = CreateExistentialFunction( new List <TypedIdent> { new TypedIdent(Token.NoToken, "x", v.Type) }); pow2ExistentialFunction.AddAttribute("absdomain", new object[] { "PowDomain" }); existentialFunctions.Add(pow2ExistentialFunction); region.AddInvariant(new AssertCmd( Token.NoToken, new NAryExpr(Token.NoToken, new FunctionCall(pow2ExistentialFunction), new List <Expr> { v }))); } }while (v != null); }
private void TransformRemainingCandidates(IRegion region, List <PredicateCmd> oldCandidateInvariants) { if (oldCandidateInvariants.Count() > 0) { List <TypedIdent> args = new List <TypedIdent>(); for (int i = 0; i < oldCandidateInvariants.Count(); i++) { args.Add(new TypedIdent(Token.NoToken, "x" + i, Type.Bool)); } Function existentialFunction = CreateExistentialFunction(args); existentialFunctions.Add(existentialFunction); List <Expr> oldCandidateInvariantExprs = new List <Expr>(); foreach (var p in oldCandidateInvariants) { string c; Expr e; Houdini.GetCandidateWithoutConstant(p.Expr, candidates, out c, out e); Debug.Assert(e != null); oldCandidateInvariantExprs.Add(e); } region.AddInvariant(new AssertCmd( Token.NoToken, new NAryExpr(Token.NoToken, new FunctionCall(existentialFunction), oldCandidateInvariantExprs))); } }
private void TransformRemainingCandidates(IRegion region, List <PredicateCmd> oldCandidateInvariants) { if (oldCandidateInvariants.Count() > 0) { List <Variable> args = new List <Variable>(); for (int i = 0; i < oldCandidateInvariants.Count(); i++) { args.Add(new LocalVariable(Token.NoToken, new TypedIdent(Token.NoToken, "x" + i, Microsoft.Boogie.Type.Bool))); } Function existentialFunction = new Function(Token.NoToken, "_existential_func" + counter, args, new LocalVariable(Token.NoToken, new TypedIdent(Token.NoToken, "", Microsoft.Boogie.Type.Bool))); existentialFunctions.Add(existentialFunction); existentialFunction.AddAttribute("existential", new object[] { Expr.True }); List <Expr> oldCandidateInvariantExprs = new List <Expr>(); foreach (var p in oldCandidateInvariants) { string c; Expr e; Houdini.GetCandidateWithoutConstant(p.Expr, candidates, out c, out e); Debug.Assert(e != null); oldCandidateInvariantExprs.Add(e); } region.AddInvariant(new AssertCmd(Token.NoToken, new NAryExpr(Token.NoToken, new FunctionCall(existentialFunction), oldCandidateInvariantExprs))); counter++; } }
private void TransformImplicationCandidates(IRegion region, List <PredicateCmd> oldCandidateInvariants) { IdentifierExpr antecedent = null; HashSet <IdentifierExpr> visited = new HashSet <IdentifierExpr>(); do { PredicateCmd current = null; foreach (var p in oldCandidateInvariants) { antecedent = TryGetNegatedBooleanFromCandidate(p, visited); if (antecedent != null) { visited.Add(antecedent); current = p; break; } } if (antecedent != null) { Debug.Assert(current != null); HashSet <PredicateCmd> toRemove = new HashSet <PredicateCmd>(); foreach (var p in oldCandidateInvariants) { string c; Expr e; Houdini.GetCandidateWithoutConstant(p.Expr, candidates, out c, out e); Debug.Assert(e != null); NAryExpr ne = e as NAryExpr; if (ne != null && ne.Fun is BinaryOperator && ((BinaryOperator)ne.Fun).Op == BinaryOperator.Opcode.Imp && ne.Args[0] is IdentifierExpr && ((IdentifierExpr)ne.Args[0]).Name.Equals(antecedent.Name)) { Expr consequent = ne.Args[1]; toRemove.Add(current); toRemove.Add(p); Function implicationExistentialFunction = CreateExistentialFunction( new List <TypedIdent> { new TypedIdent(Token.NoToken, "x", Type.Bool), new TypedIdent(Token.NoToken, "y", Type.Bool) }); implicationExistentialFunction.AddAttribute("absdomain", new object[] { "ImplicationDomain" }); existentialFunctions.Add(implicationExistentialFunction); region.AddInvariant(new AssertCmd( Token.NoToken, new NAryExpr(Token.NoToken, new FunctionCall(implicationExistentialFunction), new List <Expr> { antecedent, consequent }))); } } oldCandidateInvariants.RemoveAll(item => toRemove.Contains(item)); } }while (antecedent != null); }