-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFuncDecl.java
More file actions
377 lines (332 loc) · 10.5 KB
/
FuncDecl.java
File metadata and controls
377 lines (332 loc) · 10.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
/**
* This file was automatically generated from FuncDecl.cs
* w/ further modifications by:
* @author Christoph M. Wintersteiger (cwinter)
**/
package com.microsoft.z3;
import com.microsoft.z3.enumerations.Z3_ast_kind;
import com.microsoft.z3.enumerations.Z3_decl_kind;
import com.microsoft.z3.enumerations.Z3_parameter_kind;
/**
* Function declarations.
**/
public class FuncDecl extends AST
{
/**
* Comparison operator.
*
* @return True if <paramref name="a"/> and <paramref name="b"/> share the
* same context and are equal, false otherwise.
**/
/* Overloaded operators are not translated. */
/**
* Comparison operator.
*
* @return True if <paramref name="a"/> and <paramref name="b"/> do not
* share the same context or are not equal, false otherwise.
**/
/* Overloaded operators are not translated. */
/**
* Object comparison.
**/
public boolean equals(Object o)
{
FuncDecl casted = (FuncDecl) o;
if (casted == null)
return false;
return this == casted;
}
/**
* A hash code.
**/
public int hashCode()
{
return super.hashCode();
}
/**
* A string representations of the function declaration.
**/
public String toString()
{
try
{
return Native.funcDeclToString(getContext().nCtx(), getNativeObject());
} catch (Z3Exception e)
{
return "Z3Exception: " + e.getMessage();
}
}
/**
* Returns a unique identifier for the function declaration.
**/
public int getId() throws Z3Exception
{
return Native.getFuncDeclId(getContext().nCtx(), getNativeObject());
}
/**
* The arity of the function declaration
**/
public int getArity() throws Z3Exception
{
return Native.getArity(getContext().nCtx(), getNativeObject());
}
/**
* The size of the domain of the function declaration <seealso
* cref="Arity"/>
**/
public int getDomainSize() throws Z3Exception
{
return Native.getDomainSize(getContext().nCtx(), getNativeObject());
}
/**
* The domain of the function declaration
**/
public Sort[] getDomain() throws Z3Exception
{
int n = getDomainSize();
Sort[] res = new Sort[n];
for (int i = 0; i < n; i++)
res[i] = Sort.create(getContext(),
Native.getDomain(getContext().nCtx(), getNativeObject(), i));
return res;
}
/**
* The range of the function declaration
**/
public Sort getRange() throws Z3Exception
{
return Sort.create(getContext(),
Native.getRange(getContext().nCtx(), getNativeObject()));
}
/**
* The kind of the function declaration.
**/
public Z3_decl_kind getDeclKind() throws Z3Exception
{
return Z3_decl_kind.fromInt(Native.getDeclKind(getContext().nCtx(),
getNativeObject()));
}
/**
* The name of the function declaration
**/
public Symbol getName() throws Z3Exception
{
return Symbol.create(getContext(),
Native.getDeclName(getContext().nCtx(), getNativeObject()));
}
/**
* The number of parameters of the function declaration
**/
public int getNumParameters() throws Z3Exception
{
return Native.getDeclNumParameters(getContext().nCtx(), getNativeObject());
}
/**
* The parameters of the function declaration
**/
public Parameter[] getParameters() throws Z3Exception
{
int num = getNumParameters();
Parameter[] res = new Parameter[num];
for (int i = 0; i < num; i++)
{
Z3_parameter_kind k = Z3_parameter_kind.fromInt(Native
.getDeclParameterKind(getContext().nCtx(), getNativeObject(), i));
switch (k)
{
case Z3_PARAMETER_INT:
res[i] = new Parameter(k, Native.getDeclIntParameter(getContext()
.nCtx(), getNativeObject(), i));
break;
case Z3_PARAMETER_DOUBLE:
res[i] = new Parameter(k, Native.getDeclDoubleParameter(
getContext().nCtx(), getNativeObject(), i));
break;
case Z3_PARAMETER_SYMBOL:
res[i] = new Parameter(k, Symbol.create(getContext(), Native
.getDeclSymbolParameter(getContext().nCtx(),
getNativeObject(), i)));
break;
case Z3_PARAMETER_SORT:
res[i] = new Parameter(k, Sort.create(getContext(), Native
.getDeclSortParameter(getContext().nCtx(), getNativeObject(),
i)));
break;
case Z3_PARAMETER_AST:
res[i] = new Parameter(k, new AST(getContext(),
Native.getDeclAstParameter(getContext().nCtx(),
getNativeObject(), i)));
break;
case Z3_PARAMETER_FUNC_DECL:
res[i] = new Parameter(k, new FuncDecl(getContext(),
Native.getDeclFuncDeclParameter(getContext().nCtx(),
getNativeObject(), i)));
break;
case Z3_PARAMETER_RATIONAL:
res[i] = new Parameter(k, Native.getDeclRationalParameter(
getContext().nCtx(), getNativeObject(), i));
break;
default:
throw new Z3Exception(
"Unknown function declaration parameter kind encountered");
}
}
return res;
}
/**
* Function declarations can have Parameters associated with them.
**/
public class Parameter
{
private Z3_parameter_kind kind;
private int i;
private double d;
private Symbol sym;
private Sort srt;
private AST ast;
private FuncDecl fd;
private String r;
/**
* The int value of the parameter.</summary>
**/
public int getInt() throws Z3Exception
{
if (getParameterKind() != Z3_parameter_kind.Z3_PARAMETER_INT)
throw new Z3Exception("parameter is not an int");
return i;
}
/**
* The double value of the parameter.</summary>
**/
public double getDouble() throws Z3Exception
{
if (getParameterKind() != Z3_parameter_kind.Z3_PARAMETER_DOUBLE)
throw new Z3Exception("parameter is not a double ");
return d;
}
/**
* The Symbol value of the parameter.</summary>
**/
public Symbol getSymbol() throws Z3Exception
{
if (getParameterKind() != Z3_parameter_kind.Z3_PARAMETER_SYMBOL)
throw new Z3Exception("parameter is not a Symbol");
return sym;
}
/**
* The Sort value of the parameter.</summary>
**/
public Sort getSort() throws Z3Exception
{
if (getParameterKind() != Z3_parameter_kind.Z3_PARAMETER_SORT)
throw new Z3Exception("parameter is not a Sort");
return srt;
}
/**
* The AST value of the parameter.</summary>
**/
public AST getAST() throws Z3Exception
{
if (getParameterKind() != Z3_parameter_kind.Z3_PARAMETER_AST)
throw new Z3Exception("parameter is not an AST");
return ast;
}
/**
* The FunctionDeclaration value of the parameter.</summary>
**/
public FuncDecl getFuncDecl() throws Z3Exception
{
if (getParameterKind() != Z3_parameter_kind.Z3_PARAMETER_FUNC_DECL)
throw new Z3Exception("parameter is not a function declaration");
return fd;
}
/**
* The rational string value of the parameter.</summary>
**/
public String getRational() throws Z3Exception
{
if (getParameterKind() != Z3_parameter_kind.Z3_PARAMETER_RATIONAL)
throw new Z3Exception("parameter is not a rational String");
return r;
}
/**
* The kind of the parameter.
**/
public Z3_parameter_kind getParameterKind() throws Z3Exception
{
return kind;
}
Parameter(Z3_parameter_kind k, int i)
{
this.kind = k;
this.i = i;
}
Parameter(Z3_parameter_kind k, double d)
{
this.kind = k;
this.d = d;
}
Parameter(Z3_parameter_kind k, Symbol s)
{
this.kind = k;
this.sym = s;
}
Parameter(Z3_parameter_kind k, Sort s)
{
this.kind = k;
this.srt = s;
}
Parameter(Z3_parameter_kind k, AST a)
{
this.kind = k;
this.ast = a;
}
Parameter(Z3_parameter_kind k, FuncDecl fd)
{
this.kind = k;
this.fd = fd;
}
Parameter(Z3_parameter_kind k, String r)
{
this.kind = k;
this.r = r;
}
}
FuncDecl(Context ctx, long obj) throws Z3Exception
{
super(ctx, obj);
}
FuncDecl(Context ctx, Symbol name, Sort[] domain, Sort range)
throws Z3Exception
{
super(ctx, Native.mkFuncDecl(ctx.nCtx(), name.getNativeObject(),
arrayLength(domain), arrayToNative(domain),
range.getNativeObject()));
}
FuncDecl(Context ctx, String prefix, Sort[] domain, Sort range)
throws Z3Exception
{
super(ctx, Native.mkFreshFuncDecl(ctx.nCtx(), prefix,
arrayLength(domain), arrayToNative(domain),
range.getNativeObject()));
}
void checkNativeObject(long obj) throws Z3Exception
{
if (Native.getAstKind(getContext().nCtx(), obj) != Z3_ast_kind.Z3_FUNC_DECL_AST
.toInt())
throw new Z3Exception(
"Underlying object is not a function declaration");
super.checkNativeObject(obj);
}
/**
* Create expression that applies function to arguments. <param
* name="args"></param>
*
* @return
**/
public Expr apply(Expr ... args) throws Z3Exception
{
getContext().checkContextMatch(args);
return Expr.create(getContext(), this, args);
}
}