2012-10-02 11:35:25 -07:00
|
|
|
/*++
|
|
|
|
|
Copyright (c) 2012 Microsoft Corporation
|
|
|
|
|
|
|
|
|
|
Module Name:
|
|
|
|
|
|
|
|
|
|
api_params.cpp
|
|
|
|
|
|
|
|
|
|
Abstract:
|
|
|
|
|
API for creating parameter sets.
|
|
|
|
|
|
|
|
|
|
This is essentially a wrapper for params_ref.
|
|
|
|
|
|
|
|
|
|
Author:
|
|
|
|
|
|
|
|
|
|
Leonardo de Moura (leonardo) 2012-03-05.
|
|
|
|
|
|
|
|
|
|
Revision History:
|
|
|
|
|
|
|
|
|
|
--*/
|
2017-07-31 13:24:11 -07:00
|
|
|
#include "api/z3.h"
|
2017-08-17 17:47:40 +01:00
|
|
|
#include "api/api_log_macros.h"
|
2017-07-31 13:24:11 -07:00
|
|
|
#include "api/api_context.h"
|
|
|
|
|
#include "api/api_util.h"
|
|
|
|
|
#include "util/params.h"
|
2012-10-02 11:35:25 -07:00
|
|
|
|
|
|
|
|
extern "C" {
|
|
|
|
|
|
|
|
|
|
Z3_params Z3_API Z3_mk_params(Z3_context c) {
|
|
|
|
|
Z3_TRY;
|
|
|
|
|
LOG_Z3_mk_params(c);
|
|
|
|
|
RESET_ERROR_CODE();
|
2016-07-13 22:26:21 -07:00
|
|
|
Z3_params_ref * p = alloc(Z3_params_ref, *mk_c(c));
|
2012-10-02 11:35:25 -07:00
|
|
|
mk_c(c)->save_object(p);
|
|
|
|
|
Z3_params r = of_params(p);
|
|
|
|
|
RETURN_Z3(r);
|
2018-02-12 14:05:55 +07:00
|
|
|
Z3_CATCH_RETURN(nullptr);
|
2012-10-02 11:35:25 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
\brief Increment the reference counter of the given parameter set.
|
|
|
|
|
*/
|
|
|
|
|
void Z3_API Z3_params_inc_ref(Z3_context c, Z3_params p) {
|
|
|
|
|
Z3_TRY;
|
|
|
|
|
LOG_Z3_params_inc_ref(c, p);
|
|
|
|
|
RESET_ERROR_CODE();
|
|
|
|
|
to_params(p)->inc_ref();
|
|
|
|
|
Z3_CATCH;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
\brief Decrement the reference counter of the given parameter set.
|
|
|
|
|
*/
|
|
|
|
|
void Z3_API Z3_params_dec_ref(Z3_context c, Z3_params p) {
|
|
|
|
|
Z3_TRY;
|
|
|
|
|
LOG_Z3_params_dec_ref(c, p);
|
2021-04-08 10:34:09 -07:00
|
|
|
if (p)
|
|
|
|
|
to_params(p)->dec_ref();
|
2012-10-02 11:35:25 -07:00
|
|
|
Z3_CATCH;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
\brief Add a Boolean parameter \c k with value \c v to the parameter set \c p.
|
|
|
|
|
*/
|
2018-11-20 11:27:09 +07:00
|
|
|
void Z3_API Z3_params_set_bool(Z3_context c, Z3_params p, Z3_symbol k, bool v) {
|
2012-10-02 11:35:25 -07:00
|
|
|
Z3_TRY;
|
|
|
|
|
LOG_Z3_params_set_bool(c, p, k, v);
|
|
|
|
|
RESET_ERROR_CODE();
|
2020-07-11 20:24:45 +01:00
|
|
|
auto name = norm_param_name(to_symbol(k));
|
|
|
|
|
to_params(p)->m_params.set_bool(name.c_str(), v);
|
2012-10-02 11:35:25 -07:00
|
|
|
Z3_CATCH;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
\brief Add a unsigned parameter \c k with value \c v to the parameter set \c p.
|
|
|
|
|
*/
|
|
|
|
|
void Z3_API Z3_params_set_uint(Z3_context c, Z3_params p, Z3_symbol k, unsigned v) {
|
|
|
|
|
Z3_TRY;
|
|
|
|
|
LOG_Z3_params_set_uint(c, p, k, v);
|
|
|
|
|
RESET_ERROR_CODE();
|
2020-07-11 20:24:45 +01:00
|
|
|
auto name = norm_param_name(to_symbol(k));
|
|
|
|
|
to_params(p)->m_params.set_uint(name.c_str(), v);
|
2012-10-02 11:35:25 -07:00
|
|
|
Z3_CATCH;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
\brief Add a double parameter \c k with value \c v to the parameter set \c p.
|
|
|
|
|
*/
|
|
|
|
|
void Z3_API Z3_params_set_double(Z3_context c, Z3_params p, Z3_symbol k, double v) {
|
|
|
|
|
Z3_TRY;
|
|
|
|
|
LOG_Z3_params_set_double(c, p, k, v);
|
|
|
|
|
RESET_ERROR_CODE();
|
2020-07-11 20:24:45 +01:00
|
|
|
auto name = norm_param_name(to_symbol(k));
|
|
|
|
|
to_params(p)->m_params.set_double(name.c_str(), v);
|
2012-10-02 11:35:25 -07:00
|
|
|
Z3_CATCH;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
\brief Add a symbol parameter \c k with value \c v to the parameter set \c p.
|
|
|
|
|
*/
|
|
|
|
|
void Z3_API Z3_params_set_symbol(Z3_context c, Z3_params p, Z3_symbol k, Z3_symbol v) {
|
|
|
|
|
Z3_TRY;
|
|
|
|
|
LOG_Z3_params_set_symbol(c, p, k, v);
|
|
|
|
|
RESET_ERROR_CODE();
|
2020-07-11 20:24:45 +01:00
|
|
|
auto name = norm_param_name(to_symbol(k));
|
|
|
|
|
to_params(p)->m_params.set_sym(name.c_str(), to_symbol(v));
|
2012-10-02 11:35:25 -07:00
|
|
|
Z3_CATCH;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
\brief Convert a parameter set into a string. This function is mainly used for printing the
|
|
|
|
|
contents of a parameter set.
|
|
|
|
|
*/
|
|
|
|
|
Z3_string Z3_API Z3_params_to_string(Z3_context c, Z3_params p) {
|
|
|
|
|
Z3_TRY;
|
|
|
|
|
LOG_Z3_params_to_string(c, p);
|
|
|
|
|
RESET_ERROR_CODE();
|
|
|
|
|
std::ostringstream buffer;
|
|
|
|
|
to_params(p)->m_params.display(buffer);
|
2022-10-26 18:22:55 +01:00
|
|
|
return mk_c(c)->mk_external_string(std::move(buffer).str());
|
2012-10-02 11:35:25 -07:00
|
|
|
Z3_CATCH_RETURN("");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Z3_API Z3_params_validate(Z3_context c, Z3_params p, Z3_param_descrs d) {
|
|
|
|
|
Z3_TRY;
|
|
|
|
|
LOG_Z3_params_validate(c, p, d);
|
|
|
|
|
RESET_ERROR_CODE();
|
|
|
|
|
to_params(p)->m_params.validate(*to_param_descrs_ptr(d));
|
|
|
|
|
Z3_CATCH;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Z3_API Z3_param_descrs_inc_ref(Z3_context c, Z3_param_descrs p) {
|
|
|
|
|
Z3_TRY;
|
|
|
|
|
LOG_Z3_param_descrs_inc_ref(c, p);
|
|
|
|
|
RESET_ERROR_CODE();
|
|
|
|
|
to_param_descrs(p)->inc_ref();
|
|
|
|
|
Z3_CATCH;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Z3_API Z3_param_descrs_dec_ref(Z3_context c, Z3_param_descrs p) {
|
|
|
|
|
Z3_TRY;
|
|
|
|
|
LOG_Z3_param_descrs_dec_ref(c, p);
|
2022-05-16 16:44:13 -07:00
|
|
|
if (p)
|
|
|
|
|
to_param_descrs(p)->dec_ref();
|
2012-10-02 11:35:25 -07:00
|
|
|
Z3_CATCH;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Z3_param_kind Z3_API Z3_param_descrs_get_kind(Z3_context c, Z3_param_descrs p, Z3_symbol n) {
|
|
|
|
|
Z3_TRY;
|
|
|
|
|
LOG_Z3_param_descrs_get_kind(c, p, n);
|
|
|
|
|
RESET_ERROR_CODE();
|
|
|
|
|
param_kind k = to_param_descrs_ptr(p)->get_kind(to_symbol(n));
|
|
|
|
|
switch (k) {
|
|
|
|
|
case CPK_UINT: return Z3_PK_UINT;
|
|
|
|
|
case CPK_BOOL: return Z3_PK_BOOL;
|
|
|
|
|
case CPK_DOUBLE: return Z3_PK_DOUBLE;
|
|
|
|
|
case CPK_STRING: return Z3_PK_STRING;
|
|
|
|
|
case CPK_SYMBOL: return Z3_PK_SYMBOL;
|
|
|
|
|
case CPK_INVALID: return Z3_PK_INVALID;
|
|
|
|
|
default: return Z3_PK_OTHER;
|
|
|
|
|
}
|
|
|
|
|
Z3_CATCH_RETURN(Z3_PK_INVALID);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
unsigned Z3_API Z3_param_descrs_size(Z3_context c, Z3_param_descrs p) {
|
|
|
|
|
Z3_TRY;
|
|
|
|
|
LOG_Z3_param_descrs_size(c, p);
|
|
|
|
|
RESET_ERROR_CODE();
|
|
|
|
|
return to_param_descrs_ptr(p)->size();
|
|
|
|
|
Z3_CATCH_RETURN(0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Z3_symbol Z3_API Z3_param_descrs_get_name(Z3_context c, Z3_param_descrs p, unsigned i) {
|
|
|
|
|
Z3_TRY;
|
|
|
|
|
LOG_Z3_param_descrs_get_name(c, p, i);
|
|
|
|
|
RESET_ERROR_CODE();
|
|
|
|
|
if (i >= to_param_descrs_ptr(p)->size()) {
|
2018-07-04 16:04:37 -07:00
|
|
|
SET_ERROR_CODE(Z3_IOB, nullptr);
|
2020-01-10 12:02:08 -08:00
|
|
|
return of_symbol(symbol::null);
|
2012-10-02 11:35:25 -07:00
|
|
|
}
|
|
|
|
|
Z3_symbol result = of_symbol(to_param_descrs_ptr(p)->get_param_name(i));
|
|
|
|
|
return result;
|
2020-01-10 12:02:08 -08:00
|
|
|
Z3_CATCH_RETURN(of_symbol(symbol::null));
|
2012-10-02 11:35:25 -07:00
|
|
|
}
|
|
|
|
|
|
2016-02-12 11:45:00 +00:00
|
|
|
Z3_string Z3_API Z3_param_descrs_get_documentation(Z3_context c, Z3_param_descrs p, Z3_symbol s) {
|
|
|
|
|
Z3_TRY;
|
|
|
|
|
LOG_Z3_param_descrs_get_documentation(c, p, s);
|
|
|
|
|
RESET_ERROR_CODE();
|
|
|
|
|
char const* result = to_param_descrs_ptr(p)->get_descr(to_symbol(s));
|
2018-02-12 14:05:55 +07:00
|
|
|
if (result == nullptr) {
|
2018-07-04 16:04:37 -07:00
|
|
|
SET_ERROR_CODE(Z3_IOB, nullptr);
|
2018-02-12 14:05:55 +07:00
|
|
|
RETURN_Z3(nullptr);
|
2016-02-12 11:45:00 +00:00
|
|
|
}
|
|
|
|
|
return mk_c(c)->mk_external_string(result);
|
2018-02-12 14:05:55 +07:00
|
|
|
Z3_CATCH_RETURN(nullptr);
|
2016-02-12 11:45:00 +00:00
|
|
|
}
|
|
|
|
|
|
2012-10-12 09:13:04 -07:00
|
|
|
Z3_string Z3_API Z3_param_descrs_to_string(Z3_context c, Z3_param_descrs p) {
|
|
|
|
|
Z3_TRY;
|
|
|
|
|
LOG_Z3_param_descrs_to_string(c, p);
|
|
|
|
|
RESET_ERROR_CODE();
|
|
|
|
|
std::ostringstream buffer;
|
|
|
|
|
buffer << "(";
|
|
|
|
|
unsigned sz = to_param_descrs_ptr(p)->size();
|
|
|
|
|
for (unsigned i = 0; i < sz; i++) {
|
|
|
|
|
if (i > 0)
|
|
|
|
|
buffer << ", ";
|
|
|
|
|
buffer << to_param_descrs_ptr(p)->get_param_name(i);
|
|
|
|
|
}
|
|
|
|
|
buffer << ")";
|
2022-10-26 18:22:55 +01:00
|
|
|
return mk_c(c)->mk_external_string(std::move(buffer).str());
|
2012-10-12 09:13:04 -07:00
|
|
|
Z3_CATCH_RETURN("");
|
|
|
|
|
}
|
|
|
|
|
|
2012-10-02 11:35:25 -07:00
|
|
|
};
|