3
0
Fork 0
mirror of https://github.com/Z3Prover/z3 synced 2025-08-24 12:07:52 +00:00

merge with master

Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com>
This commit is contained in:
Nikolaj Bjorner 2018-03-25 14:57:01 -07:00
commit c513f3ca09
883 changed files with 13979 additions and 16480 deletions

View file

@ -18,6 +18,7 @@ Revision History:
--*/
#include "ast/decl_collector.h"
#include "ast/ast_pp.h"
void decl_collector::visit_sort(sort * n) {
SASSERT(!m_visited.is_marked(n));
@ -26,13 +27,19 @@ void decl_collector::visit_sort(sort * n) {
m_sorts.push_back(n);
else if (fid == m_dt_fid) {
m_sorts.push_back(n);
for (func_decl* cnstr : *m_dt_util.get_datatype_constructors(n)) {
m_decls.push_back(cnstr);
for (func_decl * accsr : *m_dt_util.get_constructor_accessors(cnstr)) {
m_decls.push_back(accsr);
for (func_decl * cnstr : *m_dt_util.get_datatype_constructors(n)) {
m_todo.push_back(cnstr);
ptr_vector<func_decl> const & cnstr_acc = *m_dt_util.get_constructor_accessors(cnstr);
unsigned num_cas = cnstr_acc.size();
for (unsigned j = 0; j < num_cas; j++) {
m_todo.push_back(cnstr_acc.get(j));
}
}
}
for (unsigned i = n->get_num_parameters(); i-- > 0; ) {
parameter const& p = n->get_parameter(i);
if (p.is_ast()) m_todo.push_back(p.get_ast());
}
}
bool decl_collector::is_bool(sort * s) {
@ -61,6 +68,7 @@ decl_collector::decl_collector(ast_manager & m, bool preds):
}
void decl_collector::visit(ast* n) {
datatype_util util(m());
m_todo.push_back(n);
while (!m_todo.empty()) {
n = m_todo.back();
@ -68,10 +76,11 @@ void decl_collector::visit(ast* n) {
if (!m_visited.is_marked(n)) {
switch(n->get_kind()) {
case AST_APP: {
for (expr * e : *to_app(n)) {
m_todo.push_back(e);
app * a = to_app(n);
for (expr* arg : *a) {
m_todo.push_back(arg);
}
m_todo.push_back(to_app(n)->get_decl());
m_todo.push_back(a->get_decl());
break;
}
case AST_QUANTIFIER: {
@ -86,7 +95,7 @@ void decl_collector::visit(ast* n) {
}
break;
}
case AST_SORT:
case AST_SORT:
visit_sort(to_sort(n));
break;
case AST_FUNC_DECL: {
@ -108,5 +117,44 @@ void decl_collector::visit(ast* n) {
}
}
void decl_collector::order_deps() {
top_sort<sort> st;
for (sort * s : m_sorts) st.insert(s, collect_deps(s));
st.topological_sort();
m_sorts.reset();
for (sort* s : st.top_sorted()) m_sorts.push_back(s);
}
decl_collector::sort_set* decl_collector::collect_deps(sort* s) {
sort_set* set = alloc(sort_set);
collect_deps(s, *set);
set->remove(s);
return set;
}
void decl_collector::collect_deps(sort* s, sort_set& set) {
if (set.contains(s)) return;
set.insert(s);
if (s->is_sort_of(m_dt_util.get_family_id(), DATATYPE_SORT)) {
unsigned num_sorts = m_dt_util.get_datatype_num_parameter_sorts(s);
for (unsigned i = 0; i < num_sorts; ++i) {
set.insert(m_dt_util.get_datatype_parameter_sort(s, i));
}
unsigned num_cnstr = m_dt_util.get_datatype_num_constructors(s);
for (unsigned i = 0; i < num_cnstr; i++) {
func_decl * cnstr = m_dt_util.get_datatype_constructors(s)->get(i);
set.insert(cnstr->get_range());
for (unsigned j = 0; j < cnstr->get_arity(); ++j)
set.insert(cnstr->get_domain(j));
}
}
for (unsigned i = s->get_num_parameters(); i-- > 0; ) {
parameter const& p = s->get_parameter(i);
if (p.is_ast() && is_sort(p.get_ast())) {
set.insert(to_sort(p.get_ast()));
}
}
}