Z3
 
Loading...
Searching...
No Matches
FuncInterp.java
Go to the documentation of this file.
1
18package com.microsoft.z3;
19
20import java.lang.ref.ReferenceQueue;
21
27@SuppressWarnings("unchecked")
28public class FuncInterp<R extends Sort> extends Z3Object {
29
34 public static class Entry<R extends Sort> extends Z3Object {
35
42 public Expr<R> getValue()
43 {
44 return (Expr<R>) Expr.create(getContext(),
45 Native.funcEntryGetValue(getContext().nCtx(), getNativeObject()));
46 }
47
52 public int getNumArgs()
53 {
54 return Native.funcEntryGetNumArgs(getContext().nCtx(), getNativeObject());
55 }
56
63 public Expr<?>[] getArgs()
64 {
65 int n = getNumArgs();
66 Expr<?>[] res = new Expr[n];
67 for (int i = 0; i < n; i++)
68 res[i] = Expr.create(getContext(), Native.funcEntryGetArg(
69 getContext().nCtx(), getNativeObject(), i));
70 return res;
71 }
72
76 @Override
77 public String toString()
78 {
79 int n = getNumArgs();
80 String res = "[";
81 Expr<?>[] args = getArgs();
82 for (int i = 0; i < n; i++)
83 res += args[i] + ", ";
84 return res + getValue() + "]";
85 }
86
87 Entry(Context ctx, long obj) {
88 super(ctx, obj);
89 }
90
91 @Override
92 void incRef() {
93 Native.funcEntryIncRef(getContext().nCtx(), getNativeObject());
94 }
95
96 @Override
97 void addToReferenceQueue() {
98 getContext().getReferenceQueue().storeReference(this, FuncEntryRef::new);
99 }
100
101 private static class FuncEntryRef extends Z3ReferenceQueue.Reference<Entry<?>> {
102
103 private FuncEntryRef(Entry<?> referent, ReferenceQueue<Z3Object> q) {
104 super(referent, q);
105 }
106
107 @Override
108 void decRef(Context ctx, long z3Obj) {
109 Native.funcEntryDecRef(ctx.nCtx(), z3Obj);
110 }
111 }
112 }
113
119 public int getNumEntries()
120 {
121 return Native.funcInterpGetNumEntries(getContext().nCtx(), getNativeObject());
122 }
123
130 public Entry<R>[] getEntries()
131 {
132 int n = getNumEntries();
133 Entry<R>[] res = new Entry[n];
134 for (int i = 0; i < n; i++)
135 res[i] = new Entry<>(getContext(), Native.funcInterpGetEntry(getContext()
136 .nCtx(), getNativeObject(), i));
137 return res;
138 }
139
148 {
149 return (Expr<R>) Expr.create(getContext(),
150 Native.funcInterpGetElse(getContext().nCtx(), getNativeObject()));
151 }
152
158 public int getArity()
159 {
160 return Native.funcInterpGetArity(getContext().nCtx(), getNativeObject());
161 }
162
166 public String toString()
167 {
168 String res = "";
169 res += "[";
170 for (Entry<R> e : getEntries())
171 {
172 int n = e.getNumArgs();
173 if (n > 1)
174 res += "[";
175 Expr<?>[] args = e.getArgs();
176 for (int i = 0; i < n; i++)
177 {
178 if (i != 0)
179 res += ", ";
180 res += args[i];
181 }
182 if (n > 1)
183 res += "]";
184 res += " -> " + e.getValue() + ", ";
185 }
186 res += "else -> " + getElse();
187 res += "]";
188 return res;
189 }
190
191 FuncInterp(Context ctx, long obj)
192 {
193 super(ctx, obj);
194 }
195
196 @Override
197 void incRef() {
198 Native.funcInterpIncRef(getContext().nCtx(), getNativeObject());
199 }
200
201 @Override
202 void addToReferenceQueue() {
203 getContext().getReferenceQueue().storeReference(this, FuncInterpRef::new);
204 }
205
206 private static class FuncInterpRef extends Z3ReferenceQueue.Reference<FuncInterp<?>> {
207
208 private FuncInterpRef(FuncInterp<?> referent, ReferenceQueue<Z3Object> q) {
209 super(referent, q);
210 }
211
212 @Override
213 void decRef(Context ctx, long z3Obj) {
214 Native.funcInterpDecRef(ctx.nCtx(), z3Obj);
215 }
216 }
217}
Expr<?>[] getArgs()
Definition Expr.java:109