Z3
 
Loading...
Searching...
No Matches
Sort.java
Go to the documentation of this file.
1
18package com.microsoft.z3;
19
20import com.microsoft.z3.enumerations.Z3_ast_kind;
21import com.microsoft.z3.enumerations.Z3_sort_kind;
22
26public class Sort extends AST
27{
31 @Override
32 public boolean equals(Object o)
33 {
34 if (o == this) return true;
35 if (!(o instanceof Sort)) return false;
36 Sort other = (Sort) o;
37
38 return (getContext().nCtx() == other.getContext().nCtx()) &&
39 (Native.isEqSort(getContext().nCtx(), getNativeObject(), other.getNativeObject()));
40 }
41
47 public int hashCode()
48 {
49 return super.hashCode();
50 }
51
55 public int getId()
56 {
57 return Native.getSortId(getContext().nCtx(), getNativeObject());
58 }
59
64 {
65 return Z3_sort_kind.fromInt(Native.getSortKind(getContext().nCtx(),
66 getNativeObject()));
67 }
68
72 public Symbol getName()
73 {
74 return Symbol.create(getContext(),
75 Native.getSortName(getContext().nCtx(), getNativeObject()));
76 }
77
81 @Override
82 public String toString() {
83 return Native.sortToString(getContext().nCtx(), getNativeObject());
84 }
85
95 {
96 return (Sort) super.translate(ctx);
97 }
98
102 Sort(Context ctx, long obj)
103 {
104 super(ctx, obj);
105 }
106
107 @Override
108 void checkNativeObject(long obj)
109 {
110 if (Native.getAstKind(getContext().nCtx(), obj) != Z3_ast_kind.Z3_SORT_AST
111 .toInt())
112 throw new Z3Exception("Underlying object is not a sort");
113 super.checkNativeObject(obj);
114 }
115
116 static Sort create(Context ctx, long obj)
117 {
118 Z3_sort_kind sk = Z3_sort_kind.fromInt(Native.getSortKind(ctx.nCtx(), obj));
119 switch (sk)
120 {
121 case Z3_ARRAY_SORT:
122 return new ArraySort<>(ctx, obj);
123 case Z3_BOOL_SORT:
124 return new BoolSort(ctx, obj);
125 case Z3_BV_SORT:
126 return new BitVecSort(ctx, obj);
127 case Z3_DATATYPE_SORT:
128 int n = Native.getDatatypeSortNumConstructors(ctx.nCtx(), obj);
129 boolean isEnum = true;
130 for (int i = 0; i < n && isEnum; i++) {
131 long ctor = Native.getDatatypeSortConstructor(ctx.nCtx(), obj, i);
132 if (Native.getDomainSize(ctx.nCtx(), ctor) != 0) {
133 isEnum = false;
134 }
135 }
136 if (isEnum) {
137 return new EnumSort<>(ctx, obj);
138 }
139 return new DatatypeSort<>(ctx, obj);
140 case Z3_INT_SORT:
141 return new IntSort(ctx, obj);
142 case Z3_REAL_SORT:
143 return new RealSort(ctx, obj);
145 return new UninterpretedSort(ctx, obj);
147 return new FiniteDomainSort(ctx, obj);
148 case Z3_RELATION_SORT:
149 return new RelationSort(ctx, obj);
151 return new FPSort(ctx, obj);
153 return new FPRMSort(ctx, obj);
154 case Z3_SEQ_SORT:
155 return new SeqSort<>(ctx, obj);
156 case Z3_RE_SORT:
157 return new ReSort<>(ctx, obj);
158 case Z3_CHAR_SORT:
159 return new CharSort(ctx, obj);
160 default:
161 throw new Z3Exception("Unknown sort kind");
162 }
163 }
164}
Z3_sort_kind getSortKind()
Definition Sort.java:63
Sort translate(Context ctx)
Definition Sort.java:94
boolean equals(Object o)
Definition Sort.java:32
String toString()
Definition Sort.java:82
Z3_ast_kind
The different kinds of Z3 AST (abstract syntax trees). That is, terms, formulas and types.
Definition z3_api.h:142
Z3_sort_kind
The different kinds of Z3 types (See Z3_get_sort_kind).
Definition z3_api.h:110
@ Z3_RELATION_SORT
Definition z3_api.h:118
@ Z3_BOOL_SORT
Definition z3_api.h:112
@ Z3_ROUNDING_MODE_SORT
Definition z3_api.h:121
@ Z3_BV_SORT
Definition z3_api.h:115
@ Z3_DATATYPE_SORT
Definition z3_api.h:117
@ Z3_INT_SORT
Definition z3_api.h:113
@ Z3_FINITE_DOMAIN_SORT
Definition z3_api.h:119
@ Z3_RE_SORT
Definition z3_api.h:123
@ Z3_UNINTERPRETED_SORT
Definition z3_api.h:111
@ Z3_FLOATING_POINT_SORT
Definition z3_api.h:120
@ Z3_ARRAY_SORT
Definition z3_api.h:116
@ Z3_CHAR_SORT
Definition z3_api.h:124
@ Z3_REAL_SORT
Definition z3_api.h:114
@ Z3_SEQ_SORT
Definition z3_api.h:122
RealSort(ctx=None)
Definition z3py.py:3321
FPSort(ebits, sbits, ctx=None)
Definition z3py.py:10713
CharSort(ctx=None)
Definition z3py.py:11567
FiniteDomainSort(name, sz, ctx=None)
Definition z3py.py:8427
IntSort(ctx=None)
Definition z3py.py:3304