コード例 #1
0
ファイル: Couterexample.cs プロジェクト: cyjseagull/boogie
        private Model.Element GetModelValue(Model m, Variable v)
        {
            Model.Element elt;
            // first, get the unique name
            string    uniqueName;
            VCExprVar vvar = Context.BoogieExprTranslator.TryLookupVariable(v);

            if (vvar == null)
            {
                uniqueName = v.Name;
            }
            else
            {
                uniqueName = Context.Lookup(vvar);
            }

            var f = m.TryGetFunc(uniqueName);

            if (f == null)
            {
                f = m.MkFunc(uniqueName, 0);
            }

            elt = f.GetConstant();
            return(elt);
        }
コード例 #2
0
        void ApplyRedirections()
        {
            var mapping = new Dictionary <Model.Element, Model.Element>();

            foreach (var name in new string[] { "U_2_bool", "U_2_int" })
            {
                Model.Func f = Model.TryGetFunc(name);
                if (f != null && f.Arity == 1)
                {
                    foreach (var ft in f.Apps)
                    {
                        mapping[ft.Args[0]] = ft.Result;
                    }
                }
            }

            Model.Substitute(mapping);
        }
コード例 #3
0
        public void PopulateModelWithStates()
        {
            Contract.Requires(Model != null);

            Model m = Model;

            ApplyRedirections();

            var mvstates = m.TryGetFunc("$mv_state");

            if (MvInfo == null || mvstates == null || (mvstates.Arity == 1 && mvstates.Apps.Count() == 0))
            {
                return;
            }

            Contract.Assert(mvstates.Arity == 2);

            foreach (Variable v in MvInfo.AllVariables)
            {
                m.InitialState.AddBinding(v.Name, GetModelValue(v));
            }

            var states = new List <int>();

            foreach (var t in mvstates.Apps)
            {
                states.Add(t.Args[1].AsInt());
            }

            states.Sort();

            for (int i = 0; i < states.Count; ++i)
            {
                var s = states[i];
                if (0 <= s && s < MvInfo.CapturePoints.Count)
                {
                    VC.ModelViewInfo.Mapping map = MvInfo.CapturePoints[s];
                    var prevInc = i > 0 ? MvInfo.CapturePoints[states[i - 1]].IncarnationMap : new Dictionary <Variable, Expr>();
                    var cs      = m.MkState(map.Description);

                    foreach (Variable v in MvInfo.AllVariables)
                    {
                        Expr e = map.IncarnationMap.ContainsKey(v) ? map.IncarnationMap[v] : null;
                        if (e == null)
                        {
                            continue;
                        }

                        Expr prevIncV = prevInc.ContainsKey(v) ? prevInc[v] : null;
                        if (prevIncV == e)
                        {
                            continue;    // skip unchanged variables
                        }
                        Model.Element elt;

                        if (e is IdentifierExpr)
                        {
                            IdentifierExpr ide = (IdentifierExpr)e;
                            elt = GetModelValue(ide.Decl);
                        }
                        else if (e is LiteralExpr)
                        {
                            LiteralExpr lit = (LiteralExpr)e;
                            elt = m.MkElement(lit.Val.ToString());
                        }
                        else
                        {
                            elt = m.MkFunc(e.ToString(), 0).GetConstant();
                        }

                        cs.AddBinding(v.Name, elt);
                    }
                }
                else
                {
                    Contract.Assume(false);
                }
            }
        }
コード例 #4
0
ファイル: ICEHoudini.cs プロジェクト: Chenguang-Zhu/ICE-C5
        private Model.Element getValue(VCExpr arg, Model model)
        {
            if (arg is VCExprLiteral)
            {
                //return model.GetElement(arg.ToString());
                return model.MkElement(arg.ToString());
            }

            else if (arg is VCExprVar)
            {
                var el = model.TryGetFunc(prover.Context.Lookup(arg as VCExprVar));
                if (el != null)
                {
                    Debug.Assert(el.Arity == 0 && el.AppCount == 1);
                    return el.Apps.First().Result;
                }
                else
                {
                    // Variable not defined; assign arbitrary value
                    if (arg.Type.IsBool)
                        return model.MkElement("false");
                    else if (arg.Type.IsInt)
                        return model.MkIntElement(0);
                    else
                        return null;
                }
            }
            else if (arg is VCExprNAry && (arg as VCExprNAry).Op is VCExprBvOp)
            {
                // support for BV constants
                var bvc = (arg as VCExprNAry)[0] as VCExprLiteral;
                if (bvc != null)
                {
                    var ret = model.TryMkElement(bvc.ToString() + arg.Type.ToString());
                    if (ret != null && (ret is Model.BitVector)) return ret;
                }
            }

            var val = prover.Evaluate(arg);
            if (val is int || val is bool || val is Microsoft.Basetypes.BigNum)
            {
                return model.MkElement(val.ToString());
            }
            else
            {
                Debug.Assert(false);
            }
            return null;
        }