Exemple #1
0
    private RPFP.Node SExprToCex(SExpr resp, ErrorHandler handler, 
                                 Dictionary<int,Dictionary<string,string>> varSubst)
    {
        Dictionary<string, RPFP.Node> nmap = new Dictionary<string,RPFP.Node>();
        Dictionary<string, RPFP.Node> pmap = new Dictionary<string,RPFP.Node>();

        foreach(var node in rpfp.nodes)
            pmap.Add((node.Name as VCExprBoogieFunctionOp).Func.Name,node);

        RPFP.Node topnode = null;
        var lines = resp.Arguments;

        // last line of derivation is from query, skip it
        for (int i = 0; i < lines.Length-1; i++)
        {
            var line = lines[i];
            if (line.ArgCount != 6)
            {
                HandleProverError("bad derivation line from prover: " + line.ToString());
                return null;
            }
            var name = line[0];
            var conseq = line[1];
            var rule = line[2];
            var subst = line[3];
            var labs = line[4];
            var refs = line[5];
            var predName = conseq.Name;
            {
                string spacer = "@@"; // Hack! UniqueNamer is adding these and I can't stop it!
                int pos = predName.LastIndexOf(spacer);
                if (pos >= 0)
                    predName = predName.Substring(0, pos);
            }
            RPFP.Node node = null;
            if (!pmap.TryGetValue(predName, out node))
            {
                HandleProverError("unknown predicate from prover: " + predName.ToString());
                return null;
            }
            RPFP.Node cexnode = rpfp.CloneNode(node);
            cexnode.map = node;
            nmap.Add(name.Name, cexnode);
            List<RPFP.Node> Chs = new List<RPFP.Node>();

            if (refs.Name != "ref")
            {
                HandleProverError("bad references from prover: " + refs.ToString());
                return null;
            }
            foreach (var c in refs.Arguments)
            {
                if (c.Name == "true")
                    Chs.Add(null);
                else
                {
                    RPFP.Node ch = null;
                    if (!nmap.TryGetValue(c.Name, out ch))
                    {
                        HandleProverError("unknown reference from prover: " + c.ToString());
                        return null;
                    }
                    Chs.Add(ch);
                }
            }

            if (!rule.Name.StartsWith("rule!"))
            {
                HandleProverError("bad rule name from prover: " + refs.ToString());
                return null;
            }
            int ruleNum = Convert.ToInt32(rule.Name.Substring(5)) - 1;
            if (ruleNum < 0 || ruleNum > rpfp.edges.Count)
            {
                HandleProverError("bad rule name from prover: " + refs.ToString());
                return null;
            }
            RPFP.Edge orig_edge = rpfp.edges[ruleNum];
            RPFP.Edge e = rpfp.CreateEdge(cexnode, orig_edge.F, Chs.ToArray());
            e.map = orig_edge;
            topnode = cexnode;

            if (labs.Name != "labels")
            {
                HandleProverError("bad labels from prover: " + labs.ToString());
                return null;
            }
            e.labels = new HashSet<string>();
            foreach (var l in labs.Arguments)
                e.labels.Add(l.Name);

            if (subst.Name != "subst")
            {
                HandleProverError("bad subst from prover: " + subst.ToString());
                return null;
            }
            Dictionary<string, string> dict = new Dictionary<string, string>();
            varSubst[e.number] = dict;
            foreach (var s in subst.Arguments)
            {
                if (s.Name != "=" || s.Arguments.Length != 2)
                {
                    HandleProverError("bad equation from prover: " + s.ToString());
                    return null;
                }
                string uniqueName = s.Arguments[0].Name;
                string spacer = "@@"; // Hack! UniqueNamer is adding these and I can't stop it!
                int pos = uniqueName.LastIndexOf(spacer);
                if (pos >= 0)
                    uniqueName = uniqueName.Substring(0, pos);
                dict.Add(uniqueName, s.Arguments[1].ToString());
            }

        }
        if (topnode == null)
        {
            HandleProverError("empty derivation from prover: " + resp.ToString());
        }
        return topnode;
    }
Exemple #2
0
 private Model SExprToModel(SExpr resp, ErrorHandler handler)
 {
     // Concatenate all the arguments
     string modelString = resp[0].Name;
     // modelString = modelString.Substring(7, modelString.Length - 8); // remove "(model " and final ")"
     var models = Model.ParseModels(new StringReader("Error model: \n" + modelString));
     if (models == null || models.Count == 0)
     {
         HandleProverError("no model from prover: " + resp.ToString());
     }
     return models[0];
 }
Exemple #3
0
        void ConstructSimpleValue(SExpr element, SExpr type, StringBuilder m) {
            if (type.Name == "Bool" && element.ArgCount == 0) {
                m.Append(element.ToString());
                return;
            }

            if (type.Name == "Int") {
                if (element.ArgCount == 0) {
                    m.Append(element.ToString());
                    return;
                } else if (element.Name == "-" && element.ArgCount == 1) {
                    m.Append(element.ToString());
                    return;
                }
            }

            if (type.Name == "_" && type.ArgCount == 2 && type[0].Name == "BitVec") {
                if (element.Name == "_" && element.ArgCount == 2 &&
                    element[0].Name.StartsWith("bv") && element[0].ArgCount == 0 &&
                    element[1].Name == type.Arguments[1].Name && element[1].ArgCount == 0) {
                    m.Append(element[0].Name + '[' + element[1].Name + ']');
                    return;
                }
            }

            if (type.Name == "Array") {
                while (element.Name == "store") {
                    ConstructComplexValue(element[1], type[0], m);
                    m.Append(" -> ");
                    ConstructComplexValue(element[2], type[1], m);
                    m.Append("\n  ");
                    if (element[0].Name != "store") {
                        m.Append("else -> ");
                    }
                    element = element[0];
                }

                if (isConstArray(element, type)) {
                    ConstructComplexValue(getConstArrayElement(element), type[1], m);
                    return;
                } else if (element.Name == "_" && element.ArgCount == 2 &&
                           element[0].Name == "as-array") {
                    m.Append("as-array[" + element[1].Name + ']');
                    return;
                }
            }

            if (SortSet.ContainsKey(type.Name) && SortSet[type.Name] == 0) {
                var prefix = "@uc_T_" + type.Name.Substring(2) + "_";
                if (element.Name.StartsWith(prefix)) {
                    m.Append(type.Name + "!val!" + element.Name.Substring(prefix.Length));
                    return;
                }
            }

            if (Functions.ContainsKey(element.Name) &&
                type.Name == Functions[element.Name].Name) {
                m.Append(element.Name);
                return;
            }

            if (DataTypes.ContainsKey(type.Name) &&
                DataTypes[type.Name].Constructor == element.Name &&
                element.ArgCount == DataTypes[type.Name].Types.Count) {
                m.Append("(" + element.Name);
                for (int i = 0; i < element.ArgCount; ++i) {
                    m.Append(" ");
                    ConstructComplexValue(element[i], DataTypes[type.Name].Types[i], m);
                }
                m.Append(")");
                return;
            }

            Parent.HandleProverError("Unexpected value: " + element);
            throw new BadExprFromProver ();
        }