Beispiel #1
0
        public void TestStringConversions(string s)
        {
            var context = new Context();
            var toz3    = CommonUtilities.ConvertCSharpStringToZ3(s);
            var tocs    = CommonUtilities.ConvertZ3StringToCSharp(context.MkString(toz3).ToString());

            Assert.AreEqual(s, tocs);
        }
Beispiel #2
0
 public void TestStringConversionsRandom()
 {
     for (int i = 0; i < 1000; i++)
     {
         string s       = RandomString();
         var    context = new Context();
         var    toz3    = CommonUtilities.ConvertCSharpStringToZ3(s);
         var    tocs    = CommonUtilities.ConvertZ3StringToCSharp(context.MkString(toz3).ToString());
         Assert.AreEqual(s, tocs);
     }
 }
        public SymbolicValue <TModel, TVar, TBool, TBitvec, TInt, TString> VisitZenConstantExpr <T>(ZenConstantExpr <T> expression, SymbolicEvaluationEnvironment <TModel, TVar, TBool, TBitvec, TInt, TString> parameter)
        {
            return(LookupOrCompute(expression, () =>
            {
                var type = typeof(T);

                if (type == ReflectionUtilities.BigIntType)
                {
                    var bi = this.Solver.CreateBigIntegerConst((BigInteger)(object)expression.Value);
                    return new SymbolicInteger <TModel, TVar, TBool, TBitvec, TInt, TString>(this.Solver, bi);
                }

                if (type == ReflectionUtilities.BoolType)
                {
                    var b = (bool)(object)expression.Value ? this.Solver.True() : this.Solver.False();
                    return new SymbolicBool <TModel, TVar, TBool, TBitvec, TInt, TString>(this.Solver, b);
                }

                if (type == ReflectionUtilities.ByteType)
                {
                    var bv = this.Solver.CreateByteConst((byte)(object)expression.Value);
                    return new SymbolicBitvec <TModel, TVar, TBool, TBitvec, TInt, TString>(this.Solver, bv);
                }

                if (type == ReflectionUtilities.ShortType)
                {
                    var bv = this.Solver.CreateShortConst((short)(object)expression.Value);
                    return new SymbolicBitvec <TModel, TVar, TBool, TBitvec, TInt, TString>(this.Solver, bv);
                }

                if (type == ReflectionUtilities.UshortType)
                {
                    var bv = this.Solver.CreateShortConst((short)(ushort)(object)expression.Value);
                    return new SymbolicBitvec <TModel, TVar, TBool, TBitvec, TInt, TString>(this.Solver, bv);
                }

                if (type == ReflectionUtilities.IntType)
                {
                    var bv = this.Solver.CreateIntConst((int)(object)expression.Value);
                    return new SymbolicBitvec <TModel, TVar, TBool, TBitvec, TInt, TString>(this.Solver, bv);
                }

                if (type == ReflectionUtilities.UintType)
                {
                    var bv = this.Solver.CreateIntConst((int)(uint)(object)expression.Value);
                    return new SymbolicBitvec <TModel, TVar, TBool, TBitvec, TInt, TString>(this.Solver, bv);
                }

                if (type == ReflectionUtilities.LongType)
                {
                    var bv = this.Solver.CreateLongConst((long)(object)expression.Value);
                    return new SymbolicBitvec <TModel, TVar, TBool, TBitvec, TInt, TString>(this.Solver, bv);
                }

                if (type == ReflectionUtilities.UlongType)
                {
                    var bv = this.Solver.CreateLongConst((long)(ulong)(object)expression.Value);
                    return new SymbolicBitvec <TModel, TVar, TBool, TBitvec, TInt, TString>(this.Solver, bv);
                }

                if (ReflectionUtilities.IsFixedIntegerType(type))
                {
                    var bv = this.Solver.CreateBitvecConst(((dynamic)expression.Value).GetBits());
                    return new SymbolicBitvec <TModel, TVar, TBool, TBitvec, TInt, TString>(this.Solver, bv);
                }

                // string type.
                var s = CommonUtilities.ConvertCSharpStringToZ3((string)(object)expression.Value);
                var v = this.Solver.CreateStringConst(s);
                return new SymbolicString <TModel, TVar, TBool, TBitvec, TInt, TString>(this.Solver, v);
            }));
        }