3
0
Fork 0
mirror of https://github.com/Z3Prover/z3 synced 2025-04-29 20:05:51 +00:00

Added finite domain expressions and numerals to the .NET, Java, and Python APIs.

Relates to #318
This commit is contained in:
Christoph M. Wintersteiger 2015-12-02 17:01:52 +00:00
parent 9e756fb6db
commit cbda38ee80
10 changed files with 380 additions and 12 deletions

View file

@ -1815,6 +1815,7 @@ namespace Microsoft.Z3
case Z3_sort_kind.Z3_BV_SORT: return new BitVecNum(ctx, obj);
case Z3_sort_kind.Z3_FLOATING_POINT_SORT: return new FPNum(ctx, obj);
case Z3_sort_kind.Z3_ROUNDING_MODE_SORT: return new FPRMNum(ctx, obj);
case Z3_sort_kind.Z3_FINITE_DOMAIN_SORT: return new FiniteDomainNum(ctx, obj);
}
}
@ -1828,6 +1829,7 @@ namespace Microsoft.Z3
case Z3_sort_kind.Z3_DATATYPE_SORT: return new DatatypeExpr(ctx, obj);
case Z3_sort_kind.Z3_FLOATING_POINT_SORT: return new FPExpr(ctx, obj);
case Z3_sort_kind.Z3_ROUNDING_MODE_SORT: return new FPRMExpr(ctx, obj);
case Z3_sort_kind.Z3_FINITE_DOMAIN_SORT: return new FiniteDomainExpr(ctx, obj);
}
return new Expr(ctx, obj);

View file

@ -0,0 +1,38 @@
/*++
Copyright (<c>) 2012 Microsoft Corporation
Module Name:
FiniteDomainExpr.cs
Abstract:
Z3 Managed API: Finite-domain Expressions
Author:
Christoph Wintersteiger (cwinter) 2015-12-02
Notes:
--*/
using System;
using System.Diagnostics.Contracts;
namespace Microsoft.Z3
{
/// <summary>
/// Finite-domain expressions
/// </summary>
public class FiniteDomainExpr : Expr
{
#region Internal
/// <summary> Constructor for DatatypeExpr </summary>
internal FiniteDomainExpr(Context ctx, IntPtr obj)
: base(ctx, obj)
{
Contract.Requires(ctx != null);
}
#endregion
}
}

View file

@ -0,0 +1,115 @@
/*++
Copyright (<c>) 2012 Microsoft Corporation
Module Name:
FiniteDomainNum.cs
Abstract:
Z3 Managed API: Finite-domain Numerals
Author:
Christoph Wintersteiger (cwinter) 2015-12-02
Notes:
--*/
using System;
using System.Diagnostics.Contracts;
#if !FRAMEWORK_LT_4
using System.Numerics;
#endif
namespace Microsoft.Z3
{
/// <summary>
/// Finite-domain numerals
/// </summary>
[ContractVerification(true)]
public class FiniteDomainNum : FiniteDomainExpr
{
/// <summary>
/// Retrieve the 64-bit unsigned integer value.
/// </summary>
public UInt64 UInt64
{
get
{
UInt64 res = 0;
if (Native.Z3_get_numeral_uint64(Context.nCtx, NativeObject, ref res) == 0)
throw new Z3Exception("Numeral is not a 64 bit unsigned");
return res;
}
}
/// <summary>
/// Retrieve the int value.
/// </summary>
public int Int
{
get
{
int res = 0;
if (Native.Z3_get_numeral_int(Context.nCtx, NativeObject, ref res) == 0)
throw new Z3Exception("Numeral is not an int");
return res;
}
}
/// <summary>
/// Retrieve the 64-bit int value.
/// </summary>
public Int64 Int64
{
get
{
Int64 res = 0;
if (Native.Z3_get_numeral_int64(Context.nCtx, NativeObject, ref res) == 0)
throw new Z3Exception("Numeral is not an int64");
return res;
}
}
/// <summary>
/// Retrieve the int value.
/// </summary>
public uint UInt
{
get
{
uint res = 0;
if (Native.Z3_get_numeral_uint(Context.nCtx, NativeObject, ref res) == 0)
throw new Z3Exception("Numeral is not a uint");
return res;
}
}
#if !FRAMEWORK_LT_4
/// <summary>
/// Retrieve the BigInteger value.
/// </summary>
public BigInteger BigInteger
{
get
{
return BigInteger.Parse(this.ToString());
}
}
#endif
/// <summary>
/// Returns a string representation of the numeral.
/// </summary>
public override string ToString()
{
return Native.Z3_get_numeral_string(Context.nCtx, NativeObject);
}
#region Internal
internal FiniteDomainNum(Context ctx, IntPtr obj) : base(ctx, obj) { Contract.Requires(ctx != null); }
#endregion
}
}

View file

@ -342,6 +342,8 @@
<Compile Include="ConstructorList.cs" />
<Compile Include="DatatypeExpr.cs" />
<Compile Include="DatatypeSort.cs" />
<Compile Include="FiniteDomainExpr.cs" />
<Compile Include="FiniteDomainNum.cs" />
<Compile Include="FPExpr.cs" />
<Compile Include="FPNum.cs" />
<Compile Include="FPRMExpr.cs" />