Z3_lbool Z3_API Z3_check_and_get_model(Z3_context c, Z3_model * m) {
     Z3_TRY;
     LOG_Z3_check_and_get_model(c, m);
     RESET_ERROR_CODE();
     CHECK_SEARCHING(c);
     cancel_eh<smt::kernel> eh(mk_c(c)->get_smt_kernel());
     api::context::set_interruptable(*(mk_c(c)), eh);
     flet<bool> _model(mk_c(c)->fparams().m_model, true);
     lbool result;
     try {
         model_ref _m;
         result = mk_c(c)->check(_m);
         if (m) {
             if (_m) {
                 Z3_model_ref * m_ref = alloc(Z3_model_ref); 
                 m_ref->m_model = _m;
                 // Must bump reference counter for backward compatibility reasons.
                 // Don't need to invoke save_object, since the counter was bumped
                 m_ref->inc_ref(); 
                 *m = of_model(m_ref);
             }
             else {
                 *m = 0;
             }
         }
     }
     catch (z3_exception & ex) {
         mk_c(c)->handle_exception(ex);
         RETURN_Z3_check_and_get_model static_cast<Z3_lbool>(l_undef);
     }
     RETURN_Z3_check_and_get_model static_cast<Z3_lbool>(result);
     Z3_CATCH_RETURN(Z3_L_UNDEF);
 }
Ejemplo n.º 2
0
 Z3_model Z3_API Z3_mk_model(Z3_context c) {
     Z3_TRY;
     LOG_Z3_mk_model(c);
     RESET_ERROR_CODE();
     Z3_model_ref * m_ref = alloc(Z3_model_ref, *mk_c(c)); 
     m_ref->m_model = alloc(model, mk_c(c)->m());
     mk_c(c)->save_object(m_ref);
     RETURN_Z3(of_model(m_ref));
     Z3_CATCH_RETURN(nullptr);
 }
Ejemplo n.º 3
0
 Z3_model Z3_API Z3_model_translate(Z3_context c, Z3_model m, Z3_context target) {
     Z3_TRY;
     LOG_Z3_model_translate(c, m, target);
     RESET_ERROR_CODE();
     Z3_model_ref* dst = alloc(Z3_model_ref, *mk_c(target));
     ast_translation tr(mk_c(c)->m(), mk_c(target)->m());
     dst->m_model = to_model_ref(m)->translate(tr);
     mk_c(target)->save_object(dst);
     RETURN_Z3(of_model(dst));
     Z3_CATCH_RETURN(nullptr);
 }
Ejemplo n.º 4
0
 Z3_model Z3_API Z3_goal_convert_model(Z3_context c, Z3_goal g, Z3_model m) {
     Z3_TRY;
     LOG_Z3_goal_convert_model(c, g, m);
     RESET_ERROR_CODE();
     model_ref new_m;
     Z3_model_ref * m_ref = alloc(Z3_model_ref, *mk_c(c)); 
     mk_c(c)->save_object(m_ref);
     if (m) m_ref->m_model = to_model_ref(m)->copy(); 
     if (to_goal_ref(g)->mc()) 
         (*to_goal_ref(g)->mc())(m_ref->m_model);
     RETURN_Z3(of_model(m_ref));
     Z3_CATCH_RETURN(0);
 }    
 Z3_lbool Z3_API Z3_check_assumptions(Z3_context c, 
                                      unsigned num_assumptions, Z3_ast const assumptions[], 
                                      Z3_model * m, Z3_ast* proof, 
                                      unsigned* core_size, Z3_ast core[]) {
     Z3_TRY;
     LOG_Z3_check_assumptions(c, num_assumptions, assumptions, m, proof, core_size, core);
     RESET_ERROR_CODE();
     CHECK_SEARCHING(c);
     expr * const* _assumptions = to_exprs(assumptions);
     flet<bool> _model(mk_c(c)->fparams().m_model, true);
     cancel_eh<smt::kernel> eh(mk_c(c)->get_smt_kernel());
     api::context::set_interruptable(*(mk_c(c)), eh);
     lbool result;
     result = mk_c(c)->get_smt_kernel().check(num_assumptions, _assumptions);
     if (result != l_false && m) {
         model_ref _m;
         mk_c(c)->get_smt_kernel().get_model(_m);
         if (_m) {
             Z3_model_ref * m_ref = alloc(Z3_model_ref); 
             m_ref->m_model = _m;
             // Must bump reference counter for backward compatibility reasons.
             // Don't need to invoke save_object, since the counter was bumped
             m_ref->inc_ref(); 
             *m = of_model(m_ref);
         }
         else {
             *m = 0;
         }
     }
     if (result == l_false && core_size) {
         *core_size = mk_c(c)->get_smt_kernel().get_unsat_core_size();
         if (*core_size > num_assumptions) {
             SET_ERROR_CODE(Z3_INVALID_ARG);
         }
         for (unsigned i = 0; i < *core_size; ++i) {
             core[i] = of_ast(mk_c(c)->get_smt_kernel().get_unsat_core_expr(i));
         }
     }
     else if (core_size) {
         *core_size = 0;
     }
     if (result == l_false && proof) {
         *proof = of_ast(mk_c(c)->get_smt_kernel().get_proof());
     }
     else if (proof) {
         *proof = 0; // breaks abstraction.
     }
     RETURN_Z3_check_assumptions static_cast<Z3_lbool>(result);         
     Z3_CATCH_RETURN(Z3_L_UNDEF);
 }
Ejemplo n.º 6
0
 Z3_model Z3_API Z3_solver_get_model(Z3_context c, Z3_solver s) {
     Z3_TRY;
     LOG_Z3_solver_get_model(c, s);
     RESET_ERROR_CODE();
     init_solver(c, s);
     model_ref _m;
     to_solver_ref(s)->get_model(_m);
     if (!_m) {
         SET_ERROR_CODE(Z3_INVALID_USAGE);
         RETURN_Z3(0);
     }
     Z3_model_ref * m_ref = alloc(Z3_model_ref); 
     m_ref->m_model = _m;
     mk_c(c)->save_object(m_ref);
     RETURN_Z3(of_model(m_ref));
     Z3_CATCH_RETURN(0);
 }
Ejemplo n.º 7
0
 Z3_model Z3_API Z3_apply_result_convert_model(Z3_context c, Z3_apply_result r, unsigned i, Z3_model m) {
     Z3_TRY;
     LOG_Z3_apply_result_convert_model(c, r, i, m);
     RESET_ERROR_CODE();
     if (i > to_apply_result(r)->m_subgoals.size()) {
         SET_ERROR_CODE(Z3_IOB);
         RETURN_Z3(0);
     }
     model_ref new_m = to_model_ref(m)->copy();
     if (to_apply_result(r)->m_mc)
         to_apply_result(r)->m_mc->operator()(new_m, i);
     Z3_model_ref * m_ref = alloc(Z3_model_ref); 
     m_ref->m_model = new_m;
     mk_c(c)->save_object(m_ref);
     RETURN_Z3(of_model(m_ref));
     Z3_CATCH_RETURN(0);
 }
Ejemplo n.º 8
0
 Z3_model Z3_API Z3_solver_get_model(Z3_context c, Z3_solver s) {
     Z3_TRY;
     LOG_Z3_solver_get_model(c, s);
     RESET_ERROR_CODE();
     init_solver(c, s);
     model_ref _m;
     to_solver_ref(s)->get_model(_m);
     if (!_m) {
         SET_ERROR_CODE(Z3_INVALID_USAGE, "there is no current model");
         RETURN_Z3(nullptr);
     }
     if (_m) {
         if (mk_c(c)->params().m_model_compress) _m->compress();
     }
     Z3_model_ref * m_ref = alloc(Z3_model_ref, *mk_c(c)); 
     m_ref->m_model = _m;
     mk_c(c)->save_object(m_ref);
     RETURN_Z3(of_model(m_ref));
     Z3_CATCH_RETURN(nullptr);
 }