3
0
Fork 0
mirror of https://github.com/Z3Prover/z3 synced 2025-04-07 09:55:19 +00:00
z3/src/api/dotnet/EnumSort.cs
Christoph M. Wintersteiger ee2c9095c6 .NET FPA API overhaul
Signed-off-by: Christoph M. Wintersteiger <cwinter@microsoft.com>
2015-01-08 17:21:29 +00:00

96 lines
2.8 KiB
C#

/*++
Copyright (c) 2012 Microsoft Corporation
Module Name:
EnumSort.cs
Abstract:
Z3 Managed API: Enum Sorts
Author:
Christoph Wintersteiger (cwinter) 2012-11-23
Notes:
--*/
using System;
using System.Diagnostics.Contracts;
namespace Microsoft.Z3
{
/// <summary>
/// Enumeration sorts.
/// </summary>
[ContractVerification(true)]
public class EnumSort : Sort
{
/// <summary>
/// The function declarations of the constants in the enumeration.
/// </summary>
public FuncDecl[] ConstDecls
{
get
{
Contract.Ensures(Contract.Result<FuncDecl[]>() != null);
uint n = Native.Z3_get_datatype_sort_num_constructors(Context.nCtx, NativeObject);
FuncDecl[] t = new FuncDecl[n];
for (uint i = 0; i < n; i++)
t[i] = new FuncDecl(Context, Native.Z3_get_datatype_sort_constructor(Context.nCtx, NativeObject, i));
return t;
}
}
/// <summary>
/// The constants in the enumeration.
/// </summary>
public Expr[] Consts
{
get
{
Contract.Ensures(Contract.Result<Expr[]>() != null);
FuncDecl[] cds = ConstDecls;
Expr[] t = new Expr[cds.Length];
for (uint i = 0; i < t.Length; i++)
t[i] = Context.MkApp(cds[i]);
return t;
}
}
/// <summary>
/// The test predicates for the constants in the enumeration.
/// </summary>
public FuncDecl[] TesterDecls
{
get
{
Contract.Ensures(Contract.Result<FuncDecl[]>() != null);
uint n = Native.Z3_get_datatype_sort_num_constructors(Context.nCtx, NativeObject);
FuncDecl[] t = new FuncDecl[n];
for (uint i = 0; i < n; i++)
t[i] = new FuncDecl(Context, Native.Z3_get_datatype_sort_recognizer(Context.nCtx, NativeObject, i));
return t;
}
}
#region Internal
internal EnumSort(Context ctx, Symbol name, Symbol[] enumNames)
: base(ctx, IntPtr.Zero)
{
Contract.Requires(ctx != null);
Contract.Requires(name != null);
Contract.Requires(enumNames != null);
int n = enumNames.Length;
IntPtr[] n_constdecls = new IntPtr[n];
IntPtr[] n_testers = new IntPtr[n];
NativeObject = Native.Z3_mk_enumeration_sort(ctx.nCtx, name.NativeObject, (uint)n,
Symbol.ArrayToNative(enumNames), n_constdecls, n_testers);
}
#endregion
};
}