mirror of
https://github.com/Z3Prover/z3
synced 2025-04-12 12:08:18 +00:00
add documentation methods to param_descrs, add C++ API and example for param_descrs. Issue #443
Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com>
This commit is contained in:
parent
9ed7dadc02
commit
8d61d36c3f
|
@ -1095,6 +1095,22 @@ void sudoku_example() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void param_descrs_example() {
|
||||||
|
std::cout << "parameter description example\n";
|
||||||
|
context c;
|
||||||
|
param_descrs p = param_descrs::simplify_param_descrs(c);
|
||||||
|
std::cout << p << "\n";
|
||||||
|
unsigned sz = p.size();
|
||||||
|
for (unsigned i = 0; i < sz; ++i) {
|
||||||
|
symbol nm = p.name(i);
|
||||||
|
char const* kind = "other";
|
||||||
|
Z3_param_kind k = p.kind(nm);
|
||||||
|
if (k == Z3_PK_UINT) kind = "uint";
|
||||||
|
if (k == Z3_PK_BOOL) kind = "bool";
|
||||||
|
std::cout << nm << ": " << p.documentation(nm) << " kind: " << kind << "\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -1136,6 +1152,7 @@ int main() {
|
||||||
substitute_example(); std::cout << "\n";
|
substitute_example(); std::cout << "\n";
|
||||||
opt_example(); std::cout << "\n";
|
opt_example(); std::cout << "\n";
|
||||||
extract_example(); std::cout << "\n";
|
extract_example(); std::cout << "\n";
|
||||||
|
param_descrs_example(); std::cout << "\n";
|
||||||
sudoku_example(); std::cout << "\n";
|
sudoku_example(); std::cout << "\n";
|
||||||
std::cout << "done\n";
|
std::cout << "done\n";
|
||||||
}
|
}
|
||||||
|
|
|
@ -179,6 +179,19 @@ extern "C" {
|
||||||
Z3_CATCH_RETURN(0);
|
Z3_CATCH_RETURN(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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));
|
||||||
|
if (result == 0) {
|
||||||
|
SET_ERROR_CODE(Z3_IOB);
|
||||||
|
RETURN_Z3(0);
|
||||||
|
}
|
||||||
|
return mk_c(c)->mk_external_string(result);
|
||||||
|
Z3_CATCH_RETURN(0);
|
||||||
|
}
|
||||||
|
|
||||||
Z3_string Z3_API Z3_param_descrs_to_string(Z3_context c, Z3_param_descrs p) {
|
Z3_string Z3_API Z3_param_descrs_to_string(Z3_context c, Z3_param_descrs p) {
|
||||||
Z3_TRY;
|
Z3_TRY;
|
||||||
LOG_Z3_param_descrs_to_string(c, p);
|
LOG_Z3_param_descrs_to_string(c, p);
|
||||||
|
|
|
@ -49,6 +49,7 @@ namespace z3 {
|
||||||
class context;
|
class context;
|
||||||
class symbol;
|
class symbol;
|
||||||
class params;
|
class params;
|
||||||
|
class param_descrs;
|
||||||
class ast;
|
class ast;
|
||||||
class sort;
|
class sort;
|
||||||
class func_decl;
|
class func_decl;
|
||||||
|
@ -286,6 +287,9 @@ namespace z3 {
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
class array {
|
class array {
|
||||||
T * m_array;
|
T * m_array;
|
||||||
|
@ -338,6 +342,30 @@ namespace z3 {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
class param_descrs : public object {
|
||||||
|
Z3_param_descrs m_descrs;
|
||||||
|
public:
|
||||||
|
param_descrs(context& c, Z3_param_descrs d): object(c), m_descrs(d) { Z3_param_descrs_inc_ref(c, d); }
|
||||||
|
param_descrs(param_descrs const& o): object(o.ctx()), m_descrs(o.m_descrs) { Z3_param_descrs_inc_ref(ctx(), m_descrs); }
|
||||||
|
param_descrs& operator=(param_descrs const& o) {
|
||||||
|
Z3_param_descrs_inc_ref(o.ctx(), o.m_descrs);
|
||||||
|
Z3_param_descrs_dec_ref(ctx(), m_descrs);
|
||||||
|
m_descrs = o.m_descrs;
|
||||||
|
m_ctx = o.m_ctx;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
~param_descrs() { Z3_param_descrs_dec_ref(ctx(), m_descrs); }
|
||||||
|
static param_descrs simplify_param_descrs(context& c) { return param_descrs(c, Z3_simplify_get_param_descrs(c)); }
|
||||||
|
|
||||||
|
unsigned size() { return Z3_param_descrs_size(ctx(), m_descrs); }
|
||||||
|
symbol name(unsigned i) { return symbol(ctx(), Z3_param_descrs_get_name(ctx(), m_descrs, i)); }
|
||||||
|
Z3_param_kind kind(symbol const& s) { return Z3_param_descrs_get_kind(ctx(), m_descrs, s); }
|
||||||
|
std::string documentation(symbol const& s) { char const* r = Z3_param_descrs_get_documentation(ctx(), m_descrs, s); check_error(); return r; }
|
||||||
|
std::string to_string() const { return Z3_param_descrs_to_string(ctx(), m_descrs); }
|
||||||
|
};
|
||||||
|
|
||||||
|
inline std::ostream& operator<<(std::ostream & out, param_descrs const & d) { return out << d.to_string(); }
|
||||||
|
|
||||||
class params : public object {
|
class params : public object {
|
||||||
Z3_params m_params;
|
Z3_params m_params;
|
||||||
public:
|
public:
|
||||||
|
@ -1572,6 +1600,8 @@ namespace z3 {
|
||||||
fmls,
|
fmls,
|
||||||
fml));
|
fml));
|
||||||
}
|
}
|
||||||
|
param_descrs get_param_descrs() { return param_descrs(ctx(), Z3_solver_get_param_descrs(ctx(), m_solver)); }
|
||||||
|
|
||||||
};
|
};
|
||||||
inline std::ostream & operator<<(std::ostream & out, solver const & s) { out << Z3_solver_to_string(s.ctx(), s); return out; }
|
inline std::ostream & operator<<(std::ostream & out, solver const & s) { out << Z3_solver_to_string(s.ctx(), s); return out; }
|
||||||
|
|
||||||
|
@ -1686,6 +1716,7 @@ namespace z3 {
|
||||||
friend tactic repeat(tactic const & t, unsigned max);
|
friend tactic repeat(tactic const & t, unsigned max);
|
||||||
friend tactic with(tactic const & t, params const & p);
|
friend tactic with(tactic const & t, params const & p);
|
||||||
friend tactic try_for(tactic const & t, unsigned ms);
|
friend tactic try_for(tactic const & t, unsigned ms);
|
||||||
|
param_descrs get_param_descrs() { return param_descrs(ctx(), Z3_tactic_get_param_descrs(ctx(), m_tactic)); }
|
||||||
};
|
};
|
||||||
|
|
||||||
inline tactic operator&(tactic const & t1, tactic const & t2) {
|
inline tactic operator&(tactic const & t1, tactic const & t2) {
|
||||||
|
|
|
@ -46,6 +46,15 @@ namespace Microsoft.Z3
|
||||||
return (Z3_param_kind)Native.Z3_param_descrs_get_kind(Context.nCtx, NativeObject, name.NativeObject);
|
return (Z3_param_kind)Native.Z3_param_descrs_get_kind(Context.nCtx, NativeObject, name.NativeObject);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Retrieve documentation of parameter.
|
||||||
|
/// </summary>
|
||||||
|
public string GetDocumentation(Symbol name)
|
||||||
|
{
|
||||||
|
Contract.Requires(name != null);
|
||||||
|
return Native.Z3_param_descrs_get_documentation(Context.nCtx, NativeObject, name.NativeObject);
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Retrieve all names of parameters.
|
/// Retrieve all names of parameters.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
|
@ -44,6 +44,15 @@ public class ParamDescrs extends Z3Object
|
||||||
getContext().nCtx(), getNativeObject(), name.getNativeObject()));
|
getContext().nCtx(), getNativeObject(), name.getNativeObject()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieve documentation of parameter.
|
||||||
|
**/
|
||||||
|
|
||||||
|
public String getDocumentation(Symbol name)
|
||||||
|
{
|
||||||
|
return Native.paramDescrsGetDocumentation(getContext().nCtx(), getNativeObject(), name.getNativeObject());
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve all names of parameters.
|
* Retrieve all names of parameters.
|
||||||
*
|
*
|
||||||
|
|
|
@ -4649,6 +4649,11 @@ class ParamDescrsRef:
|
||||||
"""
|
"""
|
||||||
return Z3_param_descrs_get_kind(self.ctx.ref(), self.descr, to_symbol(n, self.ctx))
|
return Z3_param_descrs_get_kind(self.ctx.ref(), self.descr, to_symbol(n, self.ctx))
|
||||||
|
|
||||||
|
def get_documentation(self, n):
|
||||||
|
"""Return the documentation string of the parameter named `n`.
|
||||||
|
"""
|
||||||
|
return Z3_param_descrs_get_documentation(self.ctx.ref(), self.descr, to_symbol(n, self.ctx))
|
||||||
|
|
||||||
def __getitem__(self, arg):
|
def __getitem__(self, arg):
|
||||||
if _is_int(arg):
|
if _is_int(arg):
|
||||||
return self.get_name(arg)
|
return self.get_name(arg)
|
||||||
|
|
|
@ -1666,6 +1666,13 @@ extern "C" {
|
||||||
*/
|
*/
|
||||||
Z3_symbol Z3_API Z3_param_descrs_get_name(Z3_context c, Z3_param_descrs p, unsigned i);
|
Z3_symbol Z3_API Z3_param_descrs_get_name(Z3_context c, Z3_param_descrs p, unsigned i);
|
||||||
|
|
||||||
|
/**
|
||||||
|
\brief Retrieve documentation string corresponding to parameter name \c s.
|
||||||
|
|
||||||
|
def_API('Z3_param_descrs_get_documentation', STRING, (_in(CONTEXT), _in(PARAM_DESCRS), _in(SYMBOL)))
|
||||||
|
*/
|
||||||
|
Z3_string Z3_API Z3_param_descrs_get_documentation(Z3_context c, Z3_param_descrs p, Z3_symbol s);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
\brief Convert a parameter description set into a string. This function is mainly used for printing the
|
\brief Convert a parameter description set into a string. This function is mainly used for printing the
|
||||||
contents of a parameter description set.
|
contents of a parameter description set.
|
||||||
|
|
Loading…
Reference in a new issue