21 using System.Collections;
22 using System.Collections.Generic;
23 using System.Diagnostics.Contracts;
25 namespace Microsoft.Z3
30 [ContractVerification(
true)]
40 public static bool operator ==(
AST a,
AST b)
42 return Object.ReferenceEquals(a, b) ||
43 (!Object.ReferenceEquals(a, null) &&
44 !Object.ReferenceEquals(b, null) &&
45 a.Context.nCtx == b.Context.nCtx &&
56 public static bool operator !=(
AST a,
AST b)
64 public override bool Equals(
object o)
67 if (casted == null)
return false;
68 return this == casted;
76 public virtual int CompareTo(
object other)
78 if (other == null)
return 1;
86 else if (Id > oAST.
Id)
97 public override int GetHashCode()
117 Contract.Requires(ctx != null);
118 Contract.Ensures(Contract.Result<
AST>() != null);
120 if (ReferenceEquals(
Context, ctx))
147 default:
return false;
157 get {
return this.ASTKind ==
Z3_ast_kind.Z3_VAR_AST; }
163 public bool IsQuantifier
165 get {
return this.ASTKind ==
Z3_ast_kind.Z3_QUANTIFIER_AST; }
173 get {
return this.ASTKind ==
Z3_ast_kind.Z3_SORT_AST; }
179 public bool IsFuncDecl
181 get {
return this.ASTKind ==
Z3_ast_kind.Z3_FUNC_DECL_AST; }
187 public override string ToString()
195 public string SExpr()
197 Contract.Ensures(Contract.Result<
string>() != null);
203 internal AST(
Context ctx) : base(ctx) { Contract.Requires(ctx != null); }
204 internal AST(Context ctx, IntPtr obj) : base(ctx, obj) { Contract.Requires(ctx != null); }
206 internal class DecRefQueue : Z3.DecRefQueue
208 public override void IncRef(Context ctx, IntPtr obj)
210 Native.Z3_inc_ref(ctx.nCtx, obj);
213 public override void DecRef(Context ctx, IntPtr obj)
215 Native.Z3_dec_ref(ctx.nCtx, obj);
219 internal override void IncRef(IntPtr o)
223 throw new Z3Exception(
"inc() called on null context");
224 if (o == IntPtr.Zero)
225 throw new Z3Exception(
"inc() called on null AST");
226 Context.AST_DRQ.IncAndClear(Context, o);
230 internal override void DecRef(IntPtr o)
234 throw new Z3Exception(
"dec() called on null context");
235 if (o == IntPtr.Zero)
236 throw new Z3Exception(
"dec() called on null AST");
237 Context.AST_DRQ.Add(o);
241 internal static AST Create(Context ctx, IntPtr obj)
243 Contract.Requires(ctx != null);
244 Contract.Ensures(Contract.Result<AST>() != null);
246 switch ((
Z3_ast_kind)Native.Z3_get_ast_kind(ctx.nCtx, obj))
248 case Z3_ast_kind.Z3_FUNC_DECL_AST:
return new FuncDecl(ctx, obj);
249 case Z3_ast_kind.Z3_QUANTIFIER_AST:
return new Quantifier(ctx, obj);
250 case Z3_ast_kind.Z3_SORT_AST:
return Sort.Create(ctx, obj);
253 case Z3_ast_kind.Z3_VAR_AST:
return Expr.Create(ctx, obj);
255 throw new Z3Exception(
"Unknown AST kind");