Esempio n. 1
0
        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 Expr removeExistentialImplication(Expr expr)
        {
            string match;
            bool   result = Houdini.GetCandidateWithoutConstant(expr, this.candidateConsts, out match, out expr);

            Debug.Assert(result);
            return(expr);
        }
Esempio n. 4
0
        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);
        }
        private IdentifierExpr TryGetPow2VariableFromCandidate(PredicateCmd p)
        {
            IdentifierExpr v   = null;
            string         tag = QKeyValue.FindStringAttribute(p.Attributes, "tag");

            if (tag != null && tag.Contains("pow2 less than"))
            {
                string c; Expr e;
                Houdini.GetCandidateWithoutConstant(p.Expr, candidates, out c, out e);
                v = (e as NAryExpr).Args[0] as IdentifierExpr;
            }
            return(v);
        }
        private IdentifierExpr TryGetNegatedBooleanFromCandidate(PredicateCmd p, HashSet <IdentifierExpr> visited)
        {
            string tag = QKeyValue.FindStringAttribute(p.Attributes, "tag");

            if (tag != null && (tag.Contains("no read") || tag.Contains("no write")))
            {
                string c; Expr e;
                Houdini.GetCandidateWithoutConstant(p.Expr, candidates, out c, out e);
                IdentifierExpr possibleResult = (e as NAryExpr).Args[0] as IdentifierExpr;
                if (!visited.Contains(possibleResult))
                {
                    return(possibleResult);
                }
            }
            return(null);
        }