Esempio n. 1
0
        public object Get(Model m, Expr v)
        {
            var e = m.Evaluate(v, true);

            if (e.Sort == this.BoolSort)
            {
                return(bool.Parse(e.ToString()));
            }

            if (e.Sort == this.ByteSort)
            {
                return(byte.Parse(e.ToString()));
            }

            if (e.Sort == this.ShortSort)
            {
                if (short.TryParse(e.ToString(), out short x))
                {
                    return(x);
                }

                return((short)ushort.Parse(e.ToString()));
            }

            if (e.Sort == this.IntSort)
            {
                if (int.TryParse(e.ToString(), out int x))
                {
                    return(x);
                }

                return((int)uint.Parse(e.ToString()));
            }

            if (e.Sort == this.BigIntSort)
            {
                return(BigInteger.Parse(e.ToString()));
            }

            if (e.Sort == this.StringSort)
            {
                return(CommonUtilities.ConvertZ3StringToCSharp(e.ToString()));
            }

            if (e.Sort == this.LongSort)
            {
                if (long.TryParse(e.ToString(), out long xl))
                {
                    return(xl);
                }

                return((long)ulong.Parse(e.ToString()));
            }

            // must be a fixed width integer
            var bytes = BigInteger.Parse(e.ToString()).ToByteArray();

            Array.Reverse(bytes);
            return(bytes);
        }
Esempio n. 2
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);
        }
Esempio n. 3
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);
     }
 }
Esempio n. 4
0
        public object Get(Model m, Expr v)
        {
            var e = m.Evaluate(v, true);

            if (e.Sort == this.BoolSort)
            {
                return(bool.Parse(e.ToString()));
            }

            if (e.Sort == this.ByteSort)
            {
                return(byte.Parse(e.ToString()));
            }

            if (e.Sort == this.ShortSort)
            {
                if (short.TryParse(e.ToString(), out short x))
                {
                    return(x);
                }

                return((short)ushort.Parse(e.ToString()));
            }

            if (e.Sort == this.IntSort)
            {
                if (int.TryParse(e.ToString(), out int x))
                {
                    return(x);
                }

                return((int)uint.Parse(e.ToString()));
            }

            if (e.Sort == this.StringSort)
            {
                // Remove beginning and ending quotation marks
                return(CommonUtilities.ConvertZ3StringToCSharp(e.ToString()));
            }

            if (long.TryParse(e.ToString(), out long xl))
            {
                return(xl);
            }

            return((long)ulong.Parse(e.ToString()));
        }