mirror of
https://github.com/Z3Prover/z3
synced 2025-06-15 02:16:16 +00:00
Further refactoring ackermannization.
This commit is contained in:
parent
2679b74543
commit
f3240024e7
20 changed files with 1621 additions and 0 deletions
153
src/ackermannization/ackr_model_converter.cpp
Normal file
153
src/ackermannization/ackr_model_converter.cpp
Normal file
|
@ -0,0 +1,153 @@
|
|||
/*++
|
||||
Copyright (c) 2015 Microsoft Corporation
|
||||
|
||||
Module Name:
|
||||
|
||||
ackr_model_converter.cpp
|
||||
|
||||
Abstract:
|
||||
|
||||
Author:
|
||||
|
||||
Mikolas Janota
|
||||
|
||||
Revision History:
|
||||
--*/
|
||||
#include"ackr_model_converter.h"
|
||||
#include"model_evaluator.h"
|
||||
#include"ast_smt2_pp.h"
|
||||
#include"ackr_info.h"
|
||||
|
||||
|
||||
class ackr_model_converter : public model_converter {
|
||||
public:
|
||||
ackr_model_converter(ast_manager & m,
|
||||
const ackr_info_ref& info,
|
||||
model_ref& abstr_model)
|
||||
: m(m)
|
||||
, info(info)
|
||||
, abstr_model(abstr_model)
|
||||
, fixed_model(true)
|
||||
{ }
|
||||
|
||||
ackr_model_converter(ast_manager & m,
|
||||
const ackr_info_ref& info)
|
||||
: m(m)
|
||||
, info(info)
|
||||
, fixed_model(false)
|
||||
{ }
|
||||
|
||||
virtual ~ackr_model_converter() { }
|
||||
|
||||
virtual void operator()(model_ref & md, unsigned goal_idx) {
|
||||
SASSERT(goal_idx == 0);
|
||||
SASSERT(!fixed_model || md.get() == 0 || (!md->get_num_constants() && !md->get_num_functions()));
|
||||
model_ref& old_model = fixed_model ? abstr_model : md;
|
||||
SASSERT(old_model.get());
|
||||
model * new_model = alloc(model, m);
|
||||
convert(old_model.get(), new_model);
|
||||
md = new_model;
|
||||
}
|
||||
|
||||
virtual void operator()(model_ref & md) { operator()(md, 0); }
|
||||
|
||||
//void display(std::ostream & out);
|
||||
|
||||
virtual model_converter * translate(ast_translation & translator) {NOT_IMPLEMENTED_YET();}
|
||||
protected:
|
||||
ast_manager& m;
|
||||
const ackr_info_ref info;
|
||||
model_ref abstr_model;
|
||||
bool fixed_model;
|
||||
void convert(model * source, model * destination);
|
||||
void add_entry(model_evaluator & evaluator,
|
||||
app* term, expr* value,
|
||||
obj_map<func_decl, func_interp*>& interpretations);
|
||||
void convert_sorts(model * source, model * destination);
|
||||
void convert_constants(model * source, model * destination);
|
||||
};
|
||||
|
||||
void ackr_model_converter::convert(model * source, model * destination) {
|
||||
//SASSERT(source->get_num_functions() == 0);
|
||||
for (unsigned i = 0; i < source->get_num_functions(); i++) {
|
||||
func_decl * const fd = source->get_function(i);
|
||||
func_interp * const fi = source->get_func_interp(fd);
|
||||
destination->register_decl(fd, fi);
|
||||
}
|
||||
convert_constants(source,destination);
|
||||
convert_sorts(source,destination);
|
||||
}
|
||||
|
||||
void ackr_model_converter::convert_constants(model * source, model * destination) {
|
||||
TRACE("ackr_model", tout << "converting constants\n";);
|
||||
obj_map<func_decl, func_interp*> interpretations;
|
||||
model_evaluator evaluator(*source);
|
||||
for (unsigned i = 0; i < source->get_num_constants(); i++) {
|
||||
func_decl * const c = source->get_constant(i);
|
||||
app * const term = info->find_term(c);
|
||||
expr * value = source->get_const_interp(c);
|
||||
if(!term) {
|
||||
destination->register_decl(c, value);
|
||||
} else {
|
||||
add_entry(evaluator, term, value, interpretations);
|
||||
}
|
||||
}
|
||||
|
||||
obj_map<func_decl, func_interp*>::iterator e = interpretations.end();
|
||||
for (obj_map<func_decl, func_interp*>::iterator i = interpretations.begin();
|
||||
i!=e; ++i) {
|
||||
func_decl* const fd = i->m_key;
|
||||
func_interp* const fi = i->get_value();
|
||||
fi->set_else(m.get_some_value(fd->get_range()));
|
||||
destination->register_decl(fd, fi);
|
||||
}
|
||||
}
|
||||
|
||||
void ackr_model_converter::add_entry(model_evaluator & evaluator,
|
||||
app* term, expr* value,
|
||||
obj_map<func_decl, func_interp*>& interpretations) {
|
||||
TRACE("ackr_model", tout << "add_entry"
|
||||
<< mk_ismt2_pp(term, m, 2)
|
||||
<< "->"
|
||||
<< mk_ismt2_pp(value, m, 2) << "\n";
|
||||
);
|
||||
|
||||
func_interp* fi = 0;
|
||||
func_decl * const declaration = term->get_decl();
|
||||
const unsigned sz = declaration->get_arity();
|
||||
SASSERT(sz == term->get_num_args());
|
||||
if (!interpretations.find(declaration, fi)) {
|
||||
fi = alloc(func_interp,m,sz);
|
||||
interpretations.insert(declaration, fi);
|
||||
}
|
||||
expr_ref_vector args(m);
|
||||
for (unsigned gi = 0; gi < sz; ++gi) {
|
||||
expr * const arg = term->get_arg(gi);
|
||||
expr_ref aarg(m);
|
||||
info->abstract(arg, aarg);
|
||||
expr_ref arg_value(m);
|
||||
evaluator(aarg,arg_value);
|
||||
args.push_back(arg_value);
|
||||
}
|
||||
if (fi->get_entry(args.c_ptr()) == 0) {
|
||||
fi->insert_new_entry(args.c_ptr(), value);
|
||||
} else {
|
||||
TRACE("ackr_model", tout << "entry already present\n";);
|
||||
}
|
||||
}
|
||||
|
||||
void ackr_model_converter::convert_sorts(model * source, model * destination) {
|
||||
for (unsigned i = 0; i < source->get_num_uninterpreted_sorts(); i++) {
|
||||
sort * const s = source->get_uninterpreted_sort(i);
|
||||
ptr_vector<expr> u = source->get_universe(s);
|
||||
destination->register_usort(s, u.size(), u.c_ptr());
|
||||
}
|
||||
}
|
||||
|
||||
model_converter * mk_ackr_model_converter(ast_manager & m, const ackr_info_ref& info) {
|
||||
return alloc(ackr_model_converter, m, info);
|
||||
}
|
||||
|
||||
model_converter * mk_ackr_model_converter(ast_manager & m, const ackr_info_ref& info, model_ref& abstr_model) {
|
||||
return alloc(ackr_model_converter, m, info, abstr_model);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue