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);
 }
Beispiel #2
0
 Z3_lbool Z3_API Z3_solver_get_consequences(Z3_context c, 
                                     Z3_solver s,
                                     Z3_ast_vector assumptions,
                                     Z3_ast_vector variables,
                                     Z3_ast_vector consequences) {
     Z3_TRY;
     LOG_Z3_solver_get_consequences(c, s, assumptions, variables, consequences);
     ast_manager& m = mk_c(c)->m();
     RESET_ERROR_CODE();
     CHECK_SEARCHING(c);
     init_solver(c, s);
     expr_ref_vector _assumptions(m), _consequences(m), _variables(m);
     ast_ref_vector const& __assumptions = to_ast_vector_ref(assumptions);
     for (ast* e : __assumptions) {
         if (!is_expr(e)) {
             _assumptions.finalize(); _consequences.finalize(); _variables.finalize();
             SET_ERROR_CODE(Z3_INVALID_USAGE, "assumption is not an expression");
             return Z3_L_UNDEF;
         }
         _assumptions.push_back(to_expr(e));
     }
     ast_ref_vector const& __variables = to_ast_vector_ref(variables);
     for (ast* a : __variables) {
         if (!is_expr(a)) {
             _assumptions.finalize(); _consequences.finalize(); _variables.finalize();
             SET_ERROR_CODE(Z3_INVALID_USAGE, "variable is not an expression");
             return Z3_L_UNDEF;
         }
         _variables.push_back(to_expr(a));
     }
     lbool result = l_undef;
     unsigned timeout     = to_solver(s)->m_params.get_uint("timeout", mk_c(c)->get_timeout());
     unsigned rlimit      = to_solver(s)->m_params.get_uint("rlimit", mk_c(c)->get_rlimit());
     bool     use_ctrl_c  = to_solver(s)->m_params.get_bool("ctrl_c", false);
     cancel_eh<reslimit> eh(mk_c(c)->m().limit());
     api::context::set_interruptable si(*(mk_c(c)), eh);
     {
         scoped_ctrl_c ctrlc(eh, false, use_ctrl_c);
         scoped_timer timer(timeout, &eh);
         scoped_rlimit _rlimit(mk_c(c)->m().limit(), rlimit);
         try {
             result = to_solver_ref(s)->get_consequences(_assumptions, _variables, _consequences);
         }
         catch (z3_exception & ex) {
             to_solver_ref(s)->set_reason_unknown(eh);
             _assumptions.finalize(); _consequences.finalize(); _variables.finalize();
             mk_c(c)->handle_exception(ex);
             return Z3_L_UNDEF;
         }
     }
     if (result == l_undef) {
         to_solver_ref(s)->set_reason_unknown(eh);
     }
     for (expr* e : _consequences) {
         to_ast_vector_ref(consequences).push_back(e);
     }
     return static_cast<Z3_lbool>(result); 
     Z3_CATCH_RETURN(Z3_L_UNDEF);        
 }
 void Z3_API Z3_push(Z3_context c) {
     Z3_TRY;
     LOG_Z3_push(c);
     RESET_ERROR_CODE();
     CHECK_SEARCHING(c);
     mk_c(c)->push();
     Z3_CATCH;
 }
 Z3_search_failure Z3_API Z3_get_search_failure(Z3_context c) {
     Z3_TRY;
     LOG_Z3_get_search_failure(c);
     RESET_ERROR_CODE();
     CHECK_SEARCHING(c);
     smt::failure f = mk_c(c)->get_smt_kernel().last_failure();
     return api::mk_Z3_search_failure(f);
     Z3_CATCH_RETURN(Z3_UNKNOWN);
 }
 Z3_lbool Z3_API Z3_check(Z3_context c) {
     Z3_TRY;
     // This is just syntax sugar... 
     RESET_ERROR_CODE();   
     CHECK_SEARCHING(c);
     Z3_lbool r = Z3_check_and_get_model(c, 0);
     return r;
     Z3_CATCH_RETURN(Z3_L_UNDEF);
 }
 Z3_lbool Z3_API Z3_get_implied_equalities(Z3_context c, 
                                           unsigned num_terms,
                                           Z3_ast const terms[],
                                           unsigned class_ids[]) {
     Z3_TRY;
     LOG_Z3_get_implied_equalities(c, num_terms, terms, class_ids);
     RESET_ERROR_CODE();
     CHECK_SEARCHING(c);
     lbool result = smt::implied_equalities(mk_c(c)->get_smt_kernel(), num_terms, to_exprs(terms), class_ids);
     return static_cast<Z3_lbool>(result); 
     Z3_CATCH_RETURN(Z3_L_UNDEF);
 }
 void Z3_API Z3_pop(Z3_context c, unsigned num_scopes) {
     Z3_TRY;
     LOG_Z3_pop(c, num_scopes);
     RESET_ERROR_CODE();
     CHECK_SEARCHING(c);
     if (num_scopes > mk_c(c)->get_smt_kernel().get_scope_level()) {
         SET_ERROR_CODE(Z3_IOB);
         return;
     }
     if (num_scopes > 0) {
         mk_c(c)->pop(num_scopes);
     }
     Z3_CATCH;
 }
 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);
 }
Beispiel #9
0
 Z3_lbool Z3_API Z3_get_implied_equalities(Z3_context c, 
                                           Z3_solver s,
                                           unsigned num_terms,
                                           Z3_ast const terms[],
                                           unsigned class_ids[]) {
     Z3_TRY;
     LOG_Z3_get_implied_equalities(c, s, num_terms, terms, class_ids);
     ast_manager& m = mk_c(c)->m();
     RESET_ERROR_CODE();
     CHECK_SEARCHING(c);
     init_solver(c, s);
     lbool result = smt::implied_equalities(m, *to_solver_ref(s), num_terms, to_exprs(terms), class_ids);
     return static_cast<Z3_lbool>(result); 
     Z3_CATCH_RETURN(Z3_L_UNDEF);
 }
Beispiel #10
0
 Z3_lbool Z3_API Z3_solver_get_consequences(Z3_context c, 
                                     Z3_solver s,
                                     Z3_ast_vector assumptions,
                                     Z3_ast_vector variables,
                                     Z3_ast_vector consequences) {
     Z3_TRY;
     LOG_Z3_solver_get_consequences(c, s, assumptions, variables, consequences);
     ast_manager& m = mk_c(c)->m();
     RESET_ERROR_CODE();
     CHECK_SEARCHING(c);
     init_solver(c, s);
     expr_ref_vector _assumptions(m), _consequences(m), _variables(m);
     ast_ref_vector const& __assumptions = to_ast_vector_ref(assumptions);
     unsigned sz = __assumptions.size();
     for (unsigned i = 0; i < sz; ++i) {
         if (!is_expr(__assumptions[i])) {
             SET_ERROR_CODE(Z3_INVALID_USAGE);
             return Z3_L_UNDEF;
         }
         _assumptions.push_back(to_expr(__assumptions[i]));
     }
     ast_ref_vector const& __variables = to_ast_vector_ref(variables);
     sz = __variables.size();
     for (unsigned i = 0; i < sz; ++i) {
         if (!is_expr(__variables[i])) {
             SET_ERROR_CODE(Z3_INVALID_USAGE);
             return Z3_L_UNDEF;
         }
         _variables.push_back(to_expr(__variables[i]));
     }
     lbool result = to_solver_ref(s)->get_consequences(_assumptions, _variables, _consequences);
     for (unsigned i = 0; i < _consequences.size(); ++i) {
         to_ast_vector_ref(consequences).push_back(_consequences[i].get());
     }
     return static_cast<Z3_lbool>(result); 
     Z3_CATCH_RETURN(Z3_L_UNDEF);        
 }