Z3
 
Loading...
Searching...
No Matches
OnClause.cs
Go to the documentation of this file.
1/*++
2Copyright (c) 2012 Microsoft Corporation
3
4Module Name:
5
6 OnClause.cs
7
8Abstract:
9
10 Callback on clause inferences
11
12Author:
13
14 Nikolaj Bjorner (nbjorner) 2022-10-19
15
16Notes:
17
18
19--*/
20
21using System;
22using System.Diagnostics;
23using System.Linq;
24using System.Collections.Generic;
25using System.Runtime.InteropServices;
26
27namespace Microsoft.Z3
28{
29
30 using Z3_context = System.IntPtr;
31 using Z3_solver = System.IntPtr;
32 using voidp = System.IntPtr;
33 using uintp = System.IntPtr;
34 using Z3_ast = System.IntPtr;
35 using Z3_ast_vector = System.IntPtr;
36
37
41 public class OnClause : IDisposable
42 {
52 public delegate void OnClauseEh(Expr proof_hint, ASTVector clause);
53
54
55 // access managed objects through a static array.
56 // thread safety is ignored for now.
57 GCHandle gch;
58 Solver solver;
59 Context ctx;
60 OnClauseEh on_clause;
61
62 Native.Z3_on_clause_eh on_clause_eh;
63
64 static void _on_clause(voidp ctx, Z3_ast _proof_hint, uint n, uint[] deps, Z3_ast_vector _clause)
65 {
66 var onc = (OnClause)GCHandle.FromIntPtr(ctx).Target;
67 using var proof_hint = Expr.Create(onc.ctx, _proof_hint);
68 using var clause = new ASTVector(onc.ctx, _clause);
69 onc.on_clause(proof_hint, clause);
70 }
71
75 public OnClause(Solver s, OnClauseEh onc)
76 {
77 gch = GCHandle.Alloc(this);
78 solver = s;
79 ctx = solver.Context;
80 on_clause = onc;
81 on_clause_eh = _on_clause;
82 Native.Z3_solver_register_on_clause(ctx.nCtx, solver.NativeObject, GCHandle.ToIntPtr(gch), on_clause_eh);
83 }
84
88 ~OnClause()
89 {
90 Dispose();
91 }
92
96 public virtual void Dispose()
97 {
98 if (!gch.IsAllocated)
99 return;
100 gch.Free();
101 }
102 }
103}
Vectors of ASTs.
Definition ASTVector.cs:29
The main interaction with Z3 happens via the Context.
Definition Context.cs:34
Expressions are terms.
Definition Expr.cs:31
OnClause - clause inference callback.
Definition OnClause.cs:42
virtual void Dispose()
Must be called. The object will not be garbage collected automatically even if the context is dispose...
Definition OnClause.cs:96
delegate void OnClauseEh(Expr proof_hint, ASTVector clause)
Delegate type for when clauses are inferred. An inference is a pair comprising of.
OnClause(Solver s, OnClauseEh onc)
OnClause constructor.
Definition OnClause.cs:75
Context Context
Access Context object.
Definition Z3Object.cs:111
System.IntPtr voidp
Definition OnClause.cs:32
System.IntPtr Z3_context
Definition Context.cs:29
System.IntPtr Z3_ast_vector
System.IntPtr Z3_ast
System.IntPtr uintp
Definition OnClause.cs:33
System.IntPtr Z3_solver