Skip to content

Commit

Permalink
na
Browse files Browse the repository at this point in the history
Signed-off-by: Nikolaj Bjorner <[email protected]>
  • Loading branch information
NikolajBjorner committed Aug 23, 2020
1 parent af389db commit 666e835
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 9 deletions.
15 changes: 11 additions & 4 deletions src/api/api_solver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -886,6 +886,13 @@ extern "C" {
Z3_CATCH_RETURN(nullptr);
}

class api_context_obj : public solver::context_obj {
api::context* c;
public:
api_context_obj(api::context* c):c(c) {}
~api_context_obj() override { dealloc(c); }
};

void Z3_API Z3_solver_propagate_init(
Z3_context c,
Z3_solver s,
Expand All @@ -898,12 +905,12 @@ extern "C" {
init_solver(c, s);
solver::push_eh_t _push = push_eh;
solver::pop_eh_t _pop = pop_eh;
solver::fresh_eh_t _fresh = [&](void * user_ctx, ast_manager& m, void*& _ctx) {
solver::fresh_eh_t _fresh = [&](void * user_ctx, ast_manager& m, solver::context_obj*& _ctx) {
context_params params;
params.set_foreign_manager(&m);
auto* ctx = reinterpret_cast<Z3_context>(alloc(api::context, &params, false));
_ctx = ctx;
return fresh_eh(user_ctx, ctx);
auto* ctx = alloc(api::context, &params, false);
_ctx = alloc(api_context_obj, ctx);
return fresh_eh(user_ctx, reinterpret_cast<Z3_context>(ctx));
};
to_solver_ref(s)->user_propagate_init(user_context, _push, _pop, _fresh);
Z3_CATCH;
Expand Down
7 changes: 5 additions & 2 deletions src/smt/user_propagator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ user_propagator::user_propagator(context& ctx):
{}

user_propagator::~user_propagator() {
if (m_api_context) memory::deallocate(m_api_context);
dealloc(m_api_context);
}

void user_propagator::force_push() {
Expand All @@ -48,7 +48,10 @@ unsigned user_propagator::add_expr(expr* e) {
return v;
}

void user_propagator::propagate(unsigned num_fixed, unsigned const* fixed_ids, unsigned num_eqs, unsigned const* eq_lhs, unsigned const* eq_rhs, expr* conseq) {
void user_propagator::propagate(
unsigned num_fixed, unsigned const* fixed_ids,
unsigned num_eqs, unsigned const* eq_lhs, unsigned const* eq_rhs,
expr* conseq) {
m_prop.push_back(prop_info(num_fixed, fixed_ids, num_eqs, eq_lhs, eq_rhs, expr_ref(conseq, m)));
}

Expand Down
2 changes: 1 addition & 1 deletion src/smt/user_propagator.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ namespace smt {
solver::fixed_eh_t m_fixed_eh;
solver::eq_eh_t m_eq_eh;
solver::eq_eh_t m_diseq_eh;
void* m_api_context { nullptr };
solver::context_obj* m_api_context { nullptr };

unsigned m_qhead { 0 };
vector<prop_info> m_prop;
Expand Down
7 changes: 5 additions & 2 deletions src/solver/solver.h
Original file line number Diff line number Diff line change
Expand Up @@ -243,11 +243,14 @@ class solver : public check_sat_result {
public:
virtual void propagate(unsigned num_fixed, unsigned const* fixed_ids, unsigned num_eqs, unsigned const* eq_lhs, unsigned const* eq_rhs, expr* conseq) = 0;
};

class context_obj {
public:
virtual ~context_obj() {}
};
typedef std::function<void(void*, solver::propagate_callback*)> final_eh_t;
typedef std::function<void(void*, solver::propagate_callback*, unsigned, expr*)> fixed_eh_t;
typedef std::function<void(void*, solver::propagate_callback*, unsigned, unsigned)> eq_eh_t;
typedef std::function<void*(void*, ast_manager&, void*&)> fresh_eh_t;
typedef std::function<void*(void*, ast_manager&, solver::context_obj*&)> fresh_eh_t;
typedef std::function<void(void*)> push_eh_t;
typedef std::function<void(void*,unsigned)> pop_eh_t;

Expand Down

0 comments on commit 666e835

Please sign in to comment.