mirror of
https://github.com/Z3Prover/z3
synced 2025-04-25 10:05:32 +00:00
converted pp_params
Signed-off-by: Leonardo de Moura <leonardo@microsoft.com>
This commit is contained in:
parent
4f9442864a
commit
3e6bddbad1
20 changed files with 114 additions and 223 deletions
|
@ -17,40 +17,9 @@ Revision History:
|
|||
|
||||
--*/
|
||||
#include"pp.h"
|
||||
#include"pp_params.hpp"
|
||||
using namespace format_ns;
|
||||
|
||||
void pp_param_descrs(param_descrs & p) {
|
||||
p.insert("max_indent", CPK_UINT, "max. indentation in pretty printer");
|
||||
p.insert("max_num_lines", CPK_UINT, "max. number of lines to be displayed in pretty printer");
|
||||
p.insert("max_width", CPK_UINT, "max. width in pretty printer");
|
||||
p.insert("max_ribbon", CPK_UINT, "max. ribbon (width - indentation) in pretty printer");
|
||||
p.insert("max_depth", CPK_UINT, "max. term depth (when pretty printing SMT2 terms/formulas)");
|
||||
p.insert("min_alias_size", CPK_UINT, "min. size for creating an alias for a shared term (when pretty printing SMT2 terms/formulas)");
|
||||
p.insert("decimal", CPK_BOOL, "pretty print real numbers using decimal notation (the output may be truncated). Z3 adds a '?' if the value is not precise");
|
||||
p.insert("decimal_precision", CPK_BOOL, "maximum number of decimal places to be used when pp.decimal=true");
|
||||
p.insert("bv_literals", CPK_BOOL, "use Bit-Vector literals (e.g, #x0F and #b0101) during pretty printing");
|
||||
p.insert("bv_neg", CPK_BOOL, "use bvneg when displaying Bit-Vector literals where the most significant bit is 1");
|
||||
p.insert("flat_assoc", CPK_BOOL, "flat associative operators (when pretty printing SMT2 terms/formulas)");
|
||||
p.insert("fixed_indent", CPK_BOOL, "use a fixed indentation for applications");
|
||||
p.insert("single_line", CPK_BOOL, "ignore line breaks when true");
|
||||
p.insert("bounded", CPK_BOOL, "ignore characters exceeding max widht");
|
||||
p.insert("simplify_implies", CPK_BOOL, "simplify nested implications for pretty printing");
|
||||
}
|
||||
|
||||
pp_params g_pp_params;
|
||||
|
||||
void set_pp_default_params(pp_params const & p) {
|
||||
g_pp_params = p;
|
||||
}
|
||||
|
||||
void register_pp_params(ini_params & p) {
|
||||
g_pp_params.register_params(p);
|
||||
}
|
||||
|
||||
pp_params const & get_pp_default_params() {
|
||||
return g_pp_params;
|
||||
}
|
||||
|
||||
static std::pair<unsigned, bool> space_upto_line_break(ast_manager & m, format * f) {
|
||||
unsigned r;
|
||||
SASSERT(f->get_family_id() == fm(m).get_family_id("format"));
|
||||
|
@ -87,7 +56,15 @@ inline bool fits(ast_manager & m, format * f, unsigned space_left) {
|
|||
return s <= space_left;
|
||||
}
|
||||
|
||||
void pp(std::ostream & out, format * f, ast_manager & m, pp_params const & p) {
|
||||
void pp(std::ostream & out, format * f, ast_manager & m, params_ref const & _p) {
|
||||
pp_params p(_p);
|
||||
unsigned max_width = p.max_width();
|
||||
unsigned max_ribbon = p.max_ribbon();
|
||||
unsigned max_num_lines = p.max_num_lines();
|
||||
unsigned max_indent = p.max_indent();
|
||||
bool bounded = p.bounded();
|
||||
bool single_line = p.single_line();
|
||||
|
||||
unsigned pos = 0;
|
||||
unsigned ribbon_pos = 0;
|
||||
unsigned line = 0;
|
||||
|
@ -98,7 +75,7 @@ void pp(std::ostream & out, format * f, ast_manager & m, pp_params const & p) {
|
|||
todo.push_back(std::make_pair(f, 0));
|
||||
app_ref space(mk_string(m, " "), fm(m));
|
||||
while (!todo.empty()) {
|
||||
if (line >= p.m_pp_max_num_lines)
|
||||
if (line >= max_num_lines)
|
||||
return;
|
||||
std::pair<format *, unsigned> pair = todo.back();
|
||||
format * f = pair.first;
|
||||
|
@ -107,10 +84,10 @@ void pp(std::ostream & out, format * f, ast_manager & m, pp_params const & p) {
|
|||
SASSERT(f->get_family_id() == fm(m).get_family_id("format"));
|
||||
switch (f->get_decl_kind()) {
|
||||
case OP_STRING:
|
||||
if (p.m_pp_bounded && pos > p.m_pp_max_width)
|
||||
if (bounded && pos > max_width)
|
||||
break;
|
||||
len = static_cast<unsigned>(strlen(f->get_decl()->get_parameter(0).get_symbol().bare_str()));
|
||||
if (p.m_pp_bounded && pos + len > p.m_pp_max_width) {
|
||||
if (bounded && pos + len > max_width) {
|
||||
out << "...";
|
||||
break;
|
||||
}
|
||||
|
@ -121,7 +98,7 @@ void pp(std::ostream & out, format * f, ast_manager & m, pp_params const & p) {
|
|||
case OP_INDENT:
|
||||
todo.push_back(std::make_pair(to_app(f->get_arg(0)),
|
||||
std::min(indent + f->get_decl()->get_parameter(0).get_int(),
|
||||
p.m_pp_max_indent)));
|
||||
max_indent)));
|
||||
break;
|
||||
case OP_COMPOSE:
|
||||
i = f->get_num_args();
|
||||
|
@ -131,7 +108,7 @@ void pp(std::ostream & out, format * f, ast_manager & m, pp_params const & p) {
|
|||
}
|
||||
break;
|
||||
case OP_CHOICE:
|
||||
space_left = std::min(p.m_pp_max_width - pos, p.m_pp_max_ribbon - pos);
|
||||
space_left = std::min(max_width - pos, max_ribbon - pos);
|
||||
if (space_left > 0 && fits(m, to_app(f->get_arg(0)), space_left))
|
||||
todo.push_back(std::make_pair(to_app(f->get_arg(0)), indent));
|
||||
else
|
||||
|
@ -139,14 +116,14 @@ void pp(std::ostream & out, format * f, ast_manager & m, pp_params const & p) {
|
|||
break;
|
||||
case OP_LINE_BREAK:
|
||||
case OP_LINE_BREAK_EXT:
|
||||
if (p.m_pp_single_line) {
|
||||
if (single_line) {
|
||||
todo.push_back(std::make_pair(space, indent));
|
||||
break;
|
||||
}
|
||||
pos = indent;
|
||||
ribbon_pos = 0;
|
||||
line++;
|
||||
if (line < p.m_pp_max_num_lines) {
|
||||
if (line < max_num_lines) {
|
||||
out << "\n";
|
||||
for (unsigned i = 0; i < indent; i++)
|
||||
out << " ";
|
||||
|
@ -160,7 +137,3 @@ void pp(std::ostream & out, format * f, ast_manager & m, pp_params const & p) {
|
|||
}
|
||||
}
|
||||
|
||||
void pp(std::ostream & out, format_ns::format * f, ast_manager & m) {
|
||||
pp(out, f, m, g_pp_params);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue