コード例 #1
0
ファイル: iter.c プロジェクト: abfeldman/lydia
extent_list advance_extent(extent_list extent,
			   const_extent_list ranges,
			   const_index_entry_list quantifier_indices,
			   const_user_type_entry_list user_type_table)
{
    register unsigned int ix;

    assert(extent->sz == ranges->sz);

    for (ix = extent->sz - 1; ix < extent->sz; ix--) {
	int p = eval_int_expr(extent->arr[ix]->from, quantifier_indices, user_type_table);
	int s = eval_int_expr(extent->arr[ix]->to, quantifier_indices, user_type_table);
	int r = eval_int_expr(ranges->arr[ix]->from, quantifier_indices, user_type_table);
	int q = eval_int_expr(ranges->arr[ix]->to, quantifier_indices, user_type_table);

	rfre_expr(extent->arr[ix]->from);
	rfre_expr(extent->arr[ix]->to);
	if (r < q) {
	    if (p < q) {
		p += 1;
		s += 1;
		extent->arr[ix]->from = to_expr(new_expr_int(to_type(new_int_type()), p));
		extent->arr[ix]->to = to_expr(new_expr_int(to_type(new_int_type()), s));
		break;
	    }
	} else {
	    if (p > q) {
		p -= 1;
		s -= 1;
		extent->arr[ix]->from = to_expr(new_expr_int(to_type(new_int_type()), p));
		extent->arr[ix]->to = to_expr(new_expr_int(to_type(new_int_type()), s));
		break;
	    }
	}
	extent->arr[ix]->from = to_expr(new_expr_int(to_type(new_int_type()), r));
	extent->arr[ix]->to = to_expr(new_expr_int(to_type(new_int_type()), r));
    }

    if (ix >= extent->sz) {
	rfre_extent_list(extent);
	return extent_listNIL;
    }

    return extent;
}
コード例 #2
0
ファイル: api_fpa.cpp プロジェクト: chadbrewbaker/z3
 Z3_ast Z3_API Z3_mk_fpa_to_fp_int_real(Z3_context c, Z3_ast rm, Z3_ast exp, Z3_ast sig, Z3_sort s) {
     Z3_TRY;
     LOG_Z3_mk_fpa_to_fp_int_real(c, rm, exp, sig, s);
     RESET_ERROR_CODE();
     api::context * ctx = mk_c(c);
     fpa_util & fu = ctx->fpautil();
     if (!fu.is_rm(to_expr(rm)) ||
         !ctx->autil().is_int(to_expr(exp)) ||
         !ctx->autil().is_real(to_expr(sig)) ||
         !fu.is_float(to_sort(s))) {
         SET_ERROR_CODE(Z3_INVALID_ARG);
         return nullptr;
     }
     expr * a = fu.mk_to_fp(to_sort(s), to_expr(rm), to_expr(exp), to_expr(sig));
     ctx->save_ast_trail(a);
     RETURN_Z3(of_expr(a));
     Z3_CATCH_RETURN(nullptr);
 }
コード例 #3
0
ファイル: api_qe.cpp プロジェクト: NikolajBjorner/z3
    Z3_ast Z3_API Z3_qe_model_project_skolem (Z3_context c,
                                              Z3_model mdl,
                                              unsigned num_bounds,
                                              Z3_app const bound[],
                                              Z3_ast body,
                                              Z3_ast_map map)
    {
        Z3_TRY;
        LOG_Z3_qe_model_project_skolem (c, mdl, num_bounds, bound, body, map);
        RESET_ERROR_CODE();

        ast_manager& m = mk_c(c)->m();
        app_ref_vector vars(m);
        if (!to_apps(num_bounds, bound, vars)) {
            RETURN_Z3(nullptr);
        }

        expr_ref result (m);
        result = to_expr (body);
        model_ref model (to_model_ref (mdl));
        expr_map emap (m);

        spacer::qe_project(m, vars, result, model, emap);
        mk_c(c)->save_ast_trail(result);

        obj_map<ast, ast*> &map_z3 = to_ast_map_ref(map);

        for (auto& kv : emap) {
            m.inc_ref(kv.m_key);
            m.inc_ref(kv.m_value);
            map_z3.insert(kv.m_key, kv.m_value);
        }

        return of_expr (result);
        Z3_CATCH_RETURN(nullptr);
    }
コード例 #4
0
ファイル: api_qe.cpp プロジェクト: greatmazinger/z3
    Z3_ast Z3_API Z3_qe_lite (Z3_context c, Z3_ast_vector vars, Z3_ast body)
    {
        Z3_TRY;
        LOG_Z3_qe_lite (c, vars, body);
        RESET_ERROR_CODE();
        ast_ref_vector &vVars = to_ast_vector_ref (vars);

        app_ref_vector vApps (mk_c(c)->m());
        for (unsigned i = 0; i < vVars.size (); ++i) {
            app *a = to_app (vVars.get (i));
            if (a->get_kind () != AST_APP) {
                SET_ERROR_CODE (Z3_INVALID_ARG);
                RETURN_Z3(0);
            }
            vApps.push_back (a);
        }

        expr_ref result (mk_c(c)->m ());
        result = to_expr (body);

        params_ref p;
        qe_lite qe (mk_c(c)->m (), p);
        qe (vApps, result);

        // -- copy back variables that were not eliminated
        if (vApps.size () < vVars.size ()) {
            vVars.reset ();
            for (app* v : vApps) {
                vVars.push_back (v);
            }
        }

        mk_c(c)->save_ast_trail (result.get ());
        return of_expr (result);
        Z3_CATCH_RETURN(0);
    }
コード例 #5
0
ファイル: api_datalog.cpp プロジェクト: perillaseed/z3
 Z3_lbool Z3_API Z3_fixedpoint_query(Z3_context c,Z3_fixedpoint d, Z3_ast q) {
     Z3_TRY;
     LOG_Z3_fixedpoint_query(c, d, q);
     RESET_ERROR_CODE();
     lbool r = l_undef;
     unsigned timeout = to_fixedpoint(d)->m_params.get_uint("timeout", mk_c(c)->get_timeout());
     unsigned rlimit  = to_fixedpoint(d)->m_params.get_uint("rlimit", mk_c(c)->get_rlimit());
     {
         scoped_rlimit _rlimit(mk_c(c)->m().limit(), rlimit);
         cancel_eh<reslimit> eh(mk_c(c)->m().limit());
         api::context::set_interruptable si(*(mk_c(c)), eh);
         scoped_timer timer(timeout, &eh);
         try {
             r = to_fixedpoint_ref(d)->ctx().query(to_expr(q));
         }
         catch (z3_exception& ex) {
             mk_c(c)->handle_exception(ex);
             r = l_undef;
         }
         to_fixedpoint_ref(d)->ctx().cleanup();
     }
     return of_lbool(r);
     Z3_CATCH_RETURN(Z3_L_UNDEF);
 }
コード例 #6
0
ファイル: api_fpa.cpp プロジェクト: chadbrewbaker/z3
 Z3_bool Z3_API Z3_fpa_get_numeral_significand_uint64(Z3_context c, Z3_ast t, uint64_t * n) {
     Z3_TRY;
     LOG_Z3_fpa_get_numeral_significand_uint64(c, t, n);
     RESET_ERROR_CODE();
     CHECK_NON_NULL(t, 0);
     CHECK_VALID_AST(t, 0);
     if (n == nullptr) {
         SET_ERROR_CODE(Z3_INVALID_ARG);
         return 0;
     }
     ast_manager & m = mk_c(c)->m();
     mpf_manager & mpfm = mk_c(c)->fpautil().fm();
     unsynch_mpz_manager & mpzm = mpfm.mpz_manager();
     family_id fid = mk_c(c)->get_fpa_fid();
     fpa_decl_plugin * plugin = (fpa_decl_plugin*)m.get_plugin(fid);
     SASSERT(plugin != 0);
     expr * e = to_expr(t);
     if (!is_app(e) || is_app_of(e, fid, OP_FPA_NAN) || !is_fp(c, t)) {
         SET_ERROR_CODE(Z3_INVALID_ARG);
         *n = 0;
         return 0;
     }
     scoped_mpf val(mpfm);
     bool r = plugin->is_numeral(e, val);
     const mpz & z = mpfm.sig(val);
     if (!r ||
         !(mpfm.is_normal(val) || mpfm.is_denormal(val) || mpfm.is_zero(val) || mpfm.is_inf(val)) ||
         !mpzm.is_uint64(z)) {
         SET_ERROR_CODE(Z3_INVALID_ARG);
         *n = 0;
         return 0;
     }
     *n = mpzm.get_uint64(z);
     return 1;
     Z3_CATCH_RETURN(0);
 }
コード例 #7
0
ファイル: api_qe.cpp プロジェクト: greatmazinger/z3
    Z3_ast Z3_API Z3_qe_model_project_skolem (Z3_context c,
                                              Z3_model m,
                                              unsigned num_bounds,
                                              Z3_app const bound[],
                                              Z3_ast body,
                                              Z3_ast_map map)
    {
        Z3_TRY;
        LOG_Z3_qe_model_project_skolem (c, m, num_bounds, bound, body, map);
        RESET_ERROR_CODE();

        ast_manager& man = mk_c(c)->m ();
        app_ref_vector vars(man);
        if (!to_apps(num_bounds, bound, vars)) {
            RETURN_Z3(0);
        }

        expr_ref result (mk_c(c)->m ());
        result = to_expr (body);
        model_ref model (to_model_ref (m));
        expr_map emap (man);

        spacer::qe_project (mk_c(c)->m (), vars, result, model, emap);
        mk_c(c)->save_ast_trail (result.get ());

        obj_map<ast, ast*> &map_z3 = to_ast_map_ref(map);

        for (expr_map::iterator it = emap.begin(), end = emap.end(); it != end; ++it){
            man.inc_ref(&(it->get_key()));
            man.inc_ref(it->get_value());
            map_z3.insert(&(it->get_key()), it->get_value());
        }

        return of_expr (result.get ());
        Z3_CATCH_RETURN(0);
    }
コード例 #8
0
ファイル: statement.c プロジェクト: kele86838437/jato
void free_statement(struct statement *stmt)
{
	int i;

	if (!stmt)
		return;

	for (i = 0; i < stmt_nr_kids(stmt); i++)
		if (stmt->node.kids[i])
			expr_put(to_expr(stmt->node.kids[i]));

	switch (stmt_type(stmt)) {
	case STMT_INVOKE:
	case STMT_INVOKEVIRTUAL:
	case STMT_INVOKEINTERFACE:
		if (stmt->invoke_result)
			expr_put(stmt->invoke_result);
		break;
	default:
		break;
	}

	free(stmt);
}
コード例 #9
0
ファイル: api_model.cpp プロジェクト: kayceesrk/Z3
    void Z3_API Z3_get_array_value(Z3_context c,
                                   Z3_model _m,
                                   Z3_ast _v,
                                   unsigned num_entries,
                                   Z3_ast indices[],
                                   Z3_ast values[],
                                   Z3_ast* else_value) {
        Z3_TRY;
        LOG_Z3_get_array_value(c, _m, _v, num_entries, indices, values, else_value);
        RESET_ERROR_CODE();
        CHECK_NON_NULL(_m, );
        model * m = to_model_ref(_m);

        expr* v = to_expr(_v);
        family_id afid = mk_c(c)->get_array_fid();
        ast_manager& mgr = mk_c(c)->m();
        array_util pl(mgr);

        //
        // note: _v is already reference counted.
        // saving the trail for the returned values
        // is redundant.
        //
        unsigned sz = 0;
        if (pl.is_as_array(v)) {
            func_decl* f = pl.get_as_array_func_decl(to_app(v));
            func_interp* g = m->get_func_interp(f);
            sz = g->num_entries();
            if (g->get_arity() != 1) {
                SET_ERROR_CODE(Z3_INVALID_ARG);
                return;
            }
            for (unsigned i = 0; i < sz && i < num_entries; ++i) {
                indices[i] = of_ast(g->get_entry(i)->get_arg(0));
                values[i] = of_ast(g->get_entry(i)->get_result());
            }
            if (else_value) {
                *else_value = of_ast(g->get_else());
            }
        }
        else {
            while (sz <= num_entries && is_app_of(v, afid, OP_STORE)) {
                app* a = to_app(v);
                if (a->get_num_args() != 3) {
                    SET_ERROR_CODE(Z3_INVALID_ARG);
                    return;
                }
                expr* idx = a->get_arg(1);
                expr* val = a->get_arg(2);
                indices[sz] = of_ast(idx);
                values[sz] = of_ast(val);
                v = to_app(v)->get_arg(0);
                ++sz;
            }

            if (is_app_of(v, afid, OP_CONST_ARRAY)) {
                if (else_value) {
                    *else_value = of_ast(to_app(v)->get_arg(0));
                }
            }
            else {
                SET_ERROR_CODE(Z3_INVALID_ARG);
                return;
            }
        }
        RETURN_Z3_get_array_value;
        Z3_CATCH;
    }
コード例 #10
0
ファイル: expression.c プロジェクト: vegard/jato
/**
 * Returns true if given expression does not have any potential side
 * effects and hence one instance of this expression can be safely
 * connected to many nodes in the tree.
 */
int expr_is_pure(struct expression *expr)
{
	int i;

	switch (expr_type(expr)) {
		/*
		 * These expressions may or may not have side effects
		 * depending on their actual children expressions. In
		 * general these expressions should not be connected
		 * to more than one node.
		 */
	case EXPR_ARGS_LIST:
	case EXPR_UNARY_OP:
	case EXPR_CONVERSION:
	case EXPR_CONVERSION_TO_FLOAT:
	case EXPR_CONVERSION_FROM_FLOAT:
	case EXPR_ARG:
	case EXPR_ARRAYLENGTH:
	case EXPR_INSTANCEOF:
	case EXPR_ARRAY_SIZE_CHECK:
	case EXPR_MULTIARRAY_SIZE_CHECK:
	case EXPR_NULL_CHECK:

		/* These expression types should be always assumed to
		   have side-effects. */
	case EXPR_INVOKE:
	case EXPR_INVOKEVIRTUAL:
	case EXPR_FINVOKE:
	case EXPR_FINVOKEVIRTUAL:
	case EXPR_NEWARRAY:
	case EXPR_ANEWARRAY:
	case EXPR_MULTIANEWARRAY:
	case EXPR_NEW:
	case EXPR_BINOP:
		return false;

		/* These expression types do not have any side-effects */
	case EXPR_VALUE:
	case EXPR_FVALUE:
	case EXPR_LOCAL:
	case EXPR_TEMPORARY:
	case EXPR_CLASS_FIELD:
	case EXPR_NO_ARGS:
	case EXPR_EXCEPTION_REF:
	case EXPR_INSTANCE_FIELD:
	case EXPR_MIMIC_STACK_SLOT:
		return true;

		/* EXPR_ARRAY_DEREF can have side effects in general
		   but it can not be copied so it's considered pure
		   when all it's children are pure. */
	case EXPR_ARRAY_DEREF:
		for (i = 0; i < expr_nr_kids(expr); i++)
			if (!expr_is_pure(to_expr(expr->node.kids[i])))
				return false;
		return true;

	default:
		assert(!"Invalid expression type");
	}
}
コード例 #11
0
ファイル: api_quant.cpp プロジェクト: AleksandarZeljic/z3
    Z3_ast Z3_API Z3_mk_quantifier_const_ex(Z3_context c, 
                                            Z3_bool is_forall,
                                            unsigned weight,
                                            Z3_symbol quantifier_id,
                                            Z3_symbol skolem_id,
                                            unsigned num_bound,
                                            Z3_app const bound[],
                                            unsigned num_patterns,
                                            Z3_pattern const patterns[],
                                            unsigned num_no_patterns,
                                            Z3_ast const no_patterns[],
                                            Z3_ast body) {
        Z3_TRY;
        LOG_Z3_mk_quantifier_const_ex(c, is_forall, weight, quantifier_id, skolem_id, num_bound, bound, num_patterns, patterns,
                                      num_no_patterns, no_patterns, body);
        RESET_ERROR_CODE();
        svector<Z3_symbol> names;
        svector<Z3_sort> types;
        ptr_vector<expr> bound_asts;
        if (num_patterns > 0 && num_no_patterns > 0) {
            SET_ERROR_CODE(Z3_INVALID_USAGE);
            RETURN_Z3(0);
        }
        if (num_bound == 0) {
            SET_ERROR_CODE(Z3_INVALID_USAGE);
            RETURN_Z3(0);            
        }
        for (unsigned i = 0; i < num_bound; ++i) {
            app* a = to_app(bound[i]);
            if (a->get_kind() != AST_APP) {
                SET_ERROR_CODE(Z3_INVALID_ARG);
                RETURN_Z3(0);
            }
            symbol s(to_app(a)->get_decl()->get_name());
            names.push_back(of_symbol(s));
            types.push_back(of_sort(mk_c(c)->m().get_sort(a)));
            bound_asts.push_back(a);
            if (a->get_family_id() != null_family_id || a->get_num_args() != 0) {
                SET_ERROR_CODE(Z3_INVALID_ARG);
                RETURN_Z3(0);
            }
        }
        // Abstract patterns
        svector<Z3_pattern> _patterns;
        expr_ref_vector pinned(mk_c(c)->m());
        for (unsigned i = 0; i < num_patterns; ++i) {
            expr_ref result(mk_c(c)->m());
            app* pat = to_pattern(patterns[i]);
            SASSERT(mk_c(c)->m().is_pattern(pat));
            expr_abstract(mk_c(c)->m(), 0, num_bound, bound_asts.c_ptr(), pat, result);
            SASSERT(result.get()->get_kind() == AST_APP);        
            pinned.push_back(result.get());
            SASSERT(mk_c(c)->m().is_pattern(result.get()));
            _patterns.push_back(of_pattern(result.get()));
        }
        svector<Z3_ast> _no_patterns;
        for (unsigned i = 0; i < num_no_patterns; ++i) {
            expr_ref result(mk_c(c)->m());
            if (!is_app(to_expr(no_patterns[i]))) {
                SET_ERROR_CODE(Z3_INVALID_ARG);
                RETURN_Z3(0);
            }
            app* pat = to_app(to_expr(no_patterns[i]));
            expr_abstract(mk_c(c)->m(), 0, num_bound, bound_asts.c_ptr(), pat, result);
            SASSERT(result.get()->get_kind() == AST_APP);        
            pinned.push_back(result.get());
            _no_patterns.push_back(of_ast(result.get()));
        }
        expr_ref abs_body(mk_c(c)->m());
        expr_abstract(mk_c(c)->m(), 0, num_bound, bound_asts.c_ptr(), to_expr(body), abs_body);

        Z3_ast result = mk_quantifier_ex_core(c, is_forall, weight, 
                                              quantifier_id,
                                              skolem_id,
                                              num_patterns, _patterns.c_ptr(), 
                                              num_no_patterns, _no_patterns.c_ptr(),
                                              names.size(), types.c_ptr(), names.c_ptr(), 
                                              of_ast(abs_body.get()));
        RETURN_Z3(result);
        Z3_CATCH_RETURN(0);
    }
コード例 #12
0
ファイル: tritonToZ3Ast.cpp プロジェクト: illera88/Triton
void TritonToZ3Ast::operator()(triton::ast::LnotNode& e) {
    Z3Result op1      = this->eval(*e.getChilds()[0]);
    z3::expr newexpr  = to_expr(this->result.getContext(), Z3_mk_not(this->result.getContext(), op1.getExpr()));

    this->result.setExpr(newexpr);
}
コード例 #13
0
ファイル: api_datalog.cpp プロジェクト: angr/angr-z3
 void Z3_API Z3_fixedpoint_add_constraint (Z3_context c, Z3_fixedpoint d, Z3_ast e, unsigned lvl){
     to_fixedpoint_ref(d)->ctx().add_constraint(to_expr(e), lvl);
 }
コード例 #14
0
ファイル: choice.cpp プロジェクト: cpehle/lean
static int get_num_choices(lua_State * L) {
    check_choice(L, 1);
    return push_integer(L, get_num_choices(to_expr(L, 1)));
}
コード例 #15
0
ファイル: api_algebraic.cpp プロジェクト: CHolmes3/z3
static bool is_irrational(Z3_context c, Z3_ast a) {
    return au(c).is_irrational_algebraic_numeral(to_expr(a));
}
コード例 #16
0
ファイル: api_fpa.cpp プロジェクト: chadbrewbaker/z3
bool is_bv(Z3_context c, Z3_ast a) {
    return mk_c(c)->bvutil().is_bv(to_expr(a));
}
コード例 #17
0
ファイル: choice.cpp プロジェクト: cpehle/lean
static int is_choice(lua_State * L) {
    return push_boolean(L, is_choice(to_expr(L, 1)));
}
コード例 #18
0
ファイル: placeholder.cpp プロジェクト: bmalehorn/lean
static int placeholder_type(lua_State * L) { return push_optional_expr(L, placeholder_type(to_expr(L, 1))); }
コード例 #19
0
ファイル: placeholder.cpp プロジェクト: bmalehorn/lean
static int has_placeholder(lua_State * L) {
    if (is_expr(L, 1))
        return push_boolean(L, has_placeholder(to_expr(L, 1)));
    else
        return push_boolean(L, has_placeholder(to_level(L, 1)));
}
コード例 #20
0
ファイル: parse_table.cpp プロジェクト: vishallama/lean
static int mk_scoped_expr_action(lua_State * L) {
    int nargs = lua_gettop(L);
    unsigned rbp = nargs <= 1 ? 0 : lua_tonumber(L, 2);
    bool lambda = (nargs <= 2) || lua_toboolean(L, 3);
    return push_notation_action(L, mk_scoped_expr_action(to_expr(L, 1), rbp, lambda));
}
コード例 #21
0
ファイル: api_algebraic.cpp プロジェクト: CHolmes3/z3
static algebraic_numbers::anum const & get_irrational(Z3_context c, Z3_ast a) {
    SASSERT(is_irrational(c, a));
    return au(c).to_irrational_algebraic_numeral(to_expr(a));
}
コード例 #22
0
ファイル: api_algebraic.cpp プロジェクト: CHolmes3/z3
static rational get_rational(Z3_context c, Z3_ast a) {
    SASSERT(is_rational(c, a));
    rational r;
    VERIFY(au(c).is_numeral(to_expr(a), r));
    return r;
}
コード例 #23
0
ファイル: api_fpa.cpp プロジェクト: chadbrewbaker/z3
bool is_rm(Z3_context c, Z3_ast a) {
    return mk_c(c)->fpautil().is_rm(to_expr(a));
}
コード例 #24
0
ファイル: cmd_util.cpp プロジェクト: CHolmes3/z3
expr * get_expr_ref(cmd_context & ctx, symbol const & v) {
    ast * r = get_ast_ref(ctx, v);
    if (!is_expr(r))
        throw cmd_exception("global variable does not reference a term");
    return to_expr(r);
}
コード例 #25
0
ファイル: api_arith.cpp プロジェクト: angr/angr-z3
 Z3_bool Z3_API Z3_is_algebraic_number(Z3_context c, Z3_ast a) {
     LOG_Z3_is_algebraic_number(c, a);
     return mk_c(c)->autil().is_irrational_algebraic_numeral(to_expr(a)) ? Z3_TRUE : Z3_FALSE;
 }
コード例 #26
0
ファイル: api_algebraic.cpp プロジェクト: CHolmes3/z3
static bool is_rational(Z3_context c, Z3_ast a) {
    return au(c).is_numeral(to_expr(a));
}
コード例 #27
0
ファイル: parser_bindings.cpp プロジェクト: bmalehorn/lean
static int parse_led(lua_State * L) { return push_expr(L, gparser.parse_led(to_expr(L, 1))); }
コード例 #28
0
ファイル: gexpr.cpp プロジェクト: GallagherCommaJack/lean
expr gexpr::to_expr() const {
    return to_expr(get_type_context());
}
コード例 #29
0
ファイル: fun_info_tactics.cpp プロジェクト: avigad/lean
vm_obj tactic_get_spec_subsingleton_info(vm_obj const & app, vm_obj const & m, vm_obj const & s) {
    TRY;
    type_context ctx = mk_type_context_for(s, m);
    return mk_result(get_specialized_subsingleton_info(ctx, to_expr(app)), s);
    CATCH;
}
コード例 #30
0
ファイル: choice.cpp プロジェクト: cpehle/lean
static void check_choice(lua_State * L, int idx) {
    if (!is_choice(to_expr(L, idx)))
        throw exception(sstream() << "arg #" << idx << " is not a choice-expression");
}