21 using System.Diagnostics.Contracts;
23 namespace Microsoft.Z3
28 [ContractVerification(
true)]
50 Contract.Ensures(Contract.Result<
FuncDecl>() != null);
52 return m_constructorDecl;
63 Contract.Ensures(Contract.Result<
FuncDecl>() != null);
76 Contract.Ensures(Contract.Result<
FuncDecl[]>() != null);
78 return m_accessorDecls;
90 #region Object invariant
92 [ContractInvariantMethod]
93 private void ObjectInvariant()
95 Contract.Invariant(m_testerDecl == null || m_constructorDecl != null);
96 Contract.Invariant(m_testerDecl == null || m_accessorDecls != null);
102 readonly
private uint n = 0;
103 private FuncDecl m_testerDecl = null;
104 private FuncDecl m_constructorDecl = null;
105 private FuncDecl[] m_accessorDecls = null;
107 internal Constructor(Context ctx, Symbol name, Symbol recognizer, Symbol[] fieldNames,
108 Sort[] sorts, uint[] sortRefs)
111 Contract.Requires(ctx != null);
112 Contract.Requires(name != null);
113 Contract.Requires(recognizer != null);
115 n = AST.ArrayLength(fieldNames);
117 if (n != AST.ArrayLength(sorts))
118 throw new Z3Exception(
"Number of field names does not match number of sorts");
119 if (sortRefs != null && sortRefs.Length != n)
120 throw new Z3Exception(
"Number of field names does not match number of sort refs");
122 if (sortRefs == null) sortRefs =
new uint[n];
124 NativeObject = Native.Z3_mk_constructor(ctx.nCtx, name.NativeObject, recognizer.NativeObject,
126 Symbol.ArrayToNative(fieldNames),
127 Sort.ArrayToNative(sorts),
134 Contract.Ensures(m_constructorDecl != null);
135 Contract.Ensures(m_testerDecl != null);
136 Contract.Ensures(m_accessorDecls != null);
138 if (m_testerDecl != null)
return;
139 IntPtr constructor = IntPtr.Zero;
140 IntPtr tester = IntPtr.Zero;
141 IntPtr[] accessors =
new IntPtr[n];
142 Native.Z3_query_constructor(Context.nCtx, NativeObject, n, ref constructor, ref tester, accessors);
143 m_constructorDecl =
new FuncDecl(Context, constructor);
144 m_testerDecl =
new FuncDecl(Context, tester);
145 m_accessorDecls =
new FuncDecl[n];
146 for (uint i = 0; i < n; i++)
147 m_accessorDecls[i] =
new FuncDecl(Context, accessors[i]);
170 Contract.Requires(ctx != null);
176 Contract.Requires(ctx != null);
177 Contract.Requires(constructors != null);