mirror of
https://github.com/Z3Prover/z3
synced 2025-09-30 13:19:04 +00:00
Reorganizing the code. Moved nlsat to its own directory.
Signed-off-by: Leonardo de Moura <leonardo@microsoft.com>
This commit is contained in:
parent
c66b9ab615
commit
9a84cba6c9
22 changed files with 3 additions and 2 deletions
45
src/ast/for_each_ast.cpp
Normal file
45
src/ast/for_each_ast.cpp
Normal file
|
@ -0,0 +1,45 @@
|
|||
/*++
|
||||
Copyright (c) 2006 Microsoft Corporation
|
||||
|
||||
Module Name:
|
||||
|
||||
for_each_ast.cpp
|
||||
|
||||
Abstract:
|
||||
|
||||
For each ast visitor
|
||||
|
||||
Author:
|
||||
|
||||
Leonardo de Moura (leonardo) 2006-10-18.
|
||||
|
||||
Revision History:
|
||||
|
||||
--*/
|
||||
|
||||
#include"for_each_ast.h"
|
||||
|
||||
struct ast_counter_proc {
|
||||
unsigned m_num;
|
||||
ast_counter_proc():m_num(0) {}
|
||||
void operator()(ast *) { m_num++; }
|
||||
};
|
||||
|
||||
unsigned get_num_nodes(ast * n) {
|
||||
for_each_ast_proc<ast_counter_proc> counter;
|
||||
for_each_ast(counter, n);
|
||||
return counter.m_num;
|
||||
}
|
||||
|
||||
|
||||
bool for_each_parameter(ptr_vector<ast> & stack, ast_mark & visited, unsigned num_args, parameter const * params) {
|
||||
bool result = true;
|
||||
for (unsigned i = 0; i < num_args; i++) {
|
||||
parameter const& p = params[i];
|
||||
if (p.is_ast() && !visited.is_marked(p.get_ast())) {
|
||||
stack.push_back(p.get_ast());
|
||||
result = false;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
65
src/ast/for_each_expr.cpp
Normal file
65
src/ast/for_each_expr.cpp
Normal file
|
@ -0,0 +1,65 @@
|
|||
/*++
|
||||
Copyright (c) 2006 Microsoft Corporation
|
||||
|
||||
Module Name:
|
||||
|
||||
for_each_expr.cpp
|
||||
|
||||
Abstract:
|
||||
|
||||
<abstract>
|
||||
|
||||
Author:
|
||||
|
||||
Leonardo de Moura (leonardo) 2007-12-28.
|
||||
|
||||
Revision History:
|
||||
|
||||
--*/
|
||||
|
||||
#include"for_each_expr.h"
|
||||
|
||||
struct expr_counter_proc {
|
||||
unsigned m_num;
|
||||
expr_counter_proc():m_num(0) {}
|
||||
void operator()(var * n) { m_num++; }
|
||||
void operator()(app * n) { m_num++; if (n->get_decl()->is_associative()) m_num += n->get_num_args() - 2; }
|
||||
void operator()(quantifier * n) { m_num++; }
|
||||
};
|
||||
|
||||
unsigned get_num_exprs(expr * n, expr_mark & visited) {
|
||||
expr_counter_proc counter;
|
||||
for_each_expr(counter, visited, n);
|
||||
return counter.m_num;
|
||||
}
|
||||
|
||||
unsigned get_num_exprs(expr * n, expr_fast_mark1 & visited) {
|
||||
expr_counter_proc counter;
|
||||
for_each_expr_core<expr_counter_proc, expr_fast_mark1, false, false>(counter, visited, n);
|
||||
return counter.m_num;
|
||||
}
|
||||
|
||||
unsigned get_num_exprs(expr * n) {
|
||||
expr_fast_mark1 visited;
|
||||
return get_num_exprs(n, visited);
|
||||
}
|
||||
|
||||
namespace has_skolem_functions_ns {
|
||||
struct found {};
|
||||
struct proc {
|
||||
void operator()(var * n) const {}
|
||||
void operator()(app const * n) const { if (n->get_decl()->is_skolem() && n->get_num_args() > 0) throw found(); }
|
||||
void operator()(quantifier * n) const {}
|
||||
};
|
||||
};
|
||||
|
||||
bool has_skolem_functions(expr * n) {
|
||||
has_skolem_functions_ns::proc p;
|
||||
try {
|
||||
for_each_expr(p, n);
|
||||
}
|
||||
catch (has_skolem_functions_ns::found) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
157
src/ast/for_each_expr.h
Normal file
157
src/ast/for_each_expr.h
Normal file
|
@ -0,0 +1,157 @@
|
|||
/*++
|
||||
Copyright (c) 2006 Microsoft Corporation
|
||||
|
||||
Module Name:
|
||||
|
||||
for_each_expr.h
|
||||
|
||||
Abstract:
|
||||
|
||||
<abstract>
|
||||
|
||||
Author:
|
||||
|
||||
Leonardo de Moura (leonardo) 2007-12-28.
|
||||
|
||||
Revision History:
|
||||
|
||||
--*/
|
||||
#ifndef _FOR_EACH_EXPR_H_
|
||||
#define _FOR_EACH_EXPR_H_
|
||||
|
||||
#include"ast.h"
|
||||
#include"trace.h"
|
||||
|
||||
template<typename ForEachProc, typename ExprMark, bool MarkAll, bool IgnorePatterns>
|
||||
void for_each_expr_core(ForEachProc & proc, ExprMark & visited, expr * n) {
|
||||
typedef std::pair<expr *, unsigned> frame;
|
||||
|
||||
if (MarkAll || n->get_ref_count() > 1) {
|
||||
if (visited.is_marked(n))
|
||||
return;
|
||||
visited.mark(n);
|
||||
}
|
||||
|
||||
sbuffer<frame> stack;
|
||||
|
||||
stack.push_back(frame(n, 0));
|
||||
while (!stack.empty()) {
|
||||
start:
|
||||
frame & fr = stack.back();
|
||||
expr * curr = fr.first;
|
||||
switch (curr->get_kind()) {
|
||||
case AST_VAR:
|
||||
proc(to_var(curr));
|
||||
stack.pop_back();
|
||||
break;
|
||||
case AST_APP: {
|
||||
unsigned num_args = to_app(curr)->get_num_args();
|
||||
while (fr.second < num_args) {
|
||||
expr * arg = to_app(curr)->get_arg(fr.second);
|
||||
fr.second++;
|
||||
if (MarkAll || arg->get_ref_count() > 1) {
|
||||
if (visited.is_marked(arg))
|
||||
continue;
|
||||
visited.mark(arg);
|
||||
}
|
||||
switch (arg->get_kind()) {
|
||||
case AST_VAR:
|
||||
proc(to_var(arg));
|
||||
break;
|
||||
case AST_QUANTIFIER:
|
||||
stack.push_back(frame(arg, 0));
|
||||
goto start;
|
||||
case AST_APP:
|
||||
if (to_app(arg)->get_num_args() == 0) {
|
||||
proc(to_app(arg));
|
||||
}
|
||||
else {
|
||||
stack.push_back(frame(arg, 0));
|
||||
goto start;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
UNREACHABLE();
|
||||
break;
|
||||
}
|
||||
}
|
||||
stack.pop_back();
|
||||
proc(to_app(curr));
|
||||
break;
|
||||
}
|
||||
case AST_QUANTIFIER: {
|
||||
quantifier * q = to_quantifier(curr);
|
||||
unsigned num_children = IgnorePatterns ? 1 : q->get_num_children();
|
||||
while (fr.second < num_children) {
|
||||
expr * child = q->get_child(fr.second);
|
||||
fr.second++;
|
||||
if (MarkAll || child->get_ref_count() > 1) {
|
||||
if (visited.is_marked(child))
|
||||
continue;
|
||||
visited.mark(child);
|
||||
}
|
||||
stack.push_back(frame(child, 0));
|
||||
goto start;
|
||||
}
|
||||
stack.pop_back();
|
||||
proc(to_quantifier(curr));
|
||||
break;
|
||||
}
|
||||
default:
|
||||
UNREACHABLE();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
bool for_each_expr_args(ptr_vector<expr> & stack, expr_mark & visited, unsigned num_args, T * const * args) {
|
||||
bool result = true;
|
||||
for (unsigned i = 0; i < num_args; i++) {
|
||||
T * arg = args[i];
|
||||
if (!visited.is_marked(arg)) {
|
||||
stack.push_back(arg);
|
||||
result = false;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
template<typename ForEachProc>
|
||||
void for_each_expr(ForEachProc & proc, expr_mark & visited, expr * n) {
|
||||
for_each_expr_core<ForEachProc, expr_mark, true, false>(proc, visited, n);
|
||||
}
|
||||
|
||||
template<typename ForEachProc>
|
||||
void for_each_expr(ForEachProc & proc, expr * n) {
|
||||
expr_mark visited;
|
||||
for_each_expr_core<ForEachProc, expr_mark, false, false>(proc, visited, n);
|
||||
}
|
||||
|
||||
template<typename ForEachProc>
|
||||
void quick_for_each_expr(ForEachProc & proc, expr_fast_mark1 & visited, expr * n) {
|
||||
for_each_expr_core<ForEachProc, expr_fast_mark1, false, false>(proc, visited, n);
|
||||
}
|
||||
|
||||
template<typename ForEachProc>
|
||||
void quick_for_each_expr(ForEachProc & proc, expr * n) {
|
||||
expr_fast_mark1 visited;
|
||||
for_each_expr_core<ForEachProc, expr_fast_mark1, false, false>(proc, visited, n);
|
||||
}
|
||||
|
||||
template<typename EscapeProc>
|
||||
struct for_each_expr_proc : public EscapeProc {
|
||||
void operator()(expr * n) { EscapeProc::operator()(n); }
|
||||
void operator()(var * n) { operator()(static_cast<expr *>(n)); }
|
||||
void operator()(app * n) { operator()(static_cast<expr *>(n)); }
|
||||
void operator()(quantifier * n) { operator()(static_cast<expr *>(n)); }
|
||||
};
|
||||
|
||||
unsigned get_num_exprs(expr * n);
|
||||
unsigned get_num_exprs(expr * n, expr_mark & visited);
|
||||
unsigned get_num_exprs(expr * n, expr_fast_mark1 & visited);
|
||||
|
||||
bool has_skolem_functions(expr * n);
|
||||
|
||||
#endif /* _FOR_EACH_EXPR_H_ */
|
||||
|
83
src/ast/well_sorted.cpp
Normal file
83
src/ast/well_sorted.cpp
Normal file
|
@ -0,0 +1,83 @@
|
|||
/*++
|
||||
Copyright (c) 2006 Microsoft Corporation
|
||||
|
||||
Module Name:
|
||||
|
||||
well_sorted.cpp
|
||||
|
||||
Abstract:
|
||||
|
||||
<abstract>
|
||||
|
||||
Author:
|
||||
|
||||
Leonardo de Moura (leonardo) 2007-12-29.
|
||||
|
||||
Revision History:
|
||||
|
||||
--*/
|
||||
|
||||
#include<sstream>
|
||||
#include"for_each_expr.h"
|
||||
#include"well_sorted.h"
|
||||
#include"ast_ll_pp.h"
|
||||
#include"ast_pp.h"
|
||||
#include"warning.h"
|
||||
#include"ast_smt2_pp.h"
|
||||
|
||||
struct well_sorted_proc {
|
||||
ast_manager & m_manager;
|
||||
bool m_error;
|
||||
|
||||
well_sorted_proc(ast_manager & m):m_manager(m), m_error(false) {}
|
||||
|
||||
void operator()(var * v) {}
|
||||
|
||||
void operator()(quantifier * n) {
|
||||
expr const * e = n->get_expr();
|
||||
if (!m_manager.is_bool(e)) {
|
||||
warning_msg("quantifier's body must be a boolean.");
|
||||
m_error = true;
|
||||
}
|
||||
}
|
||||
|
||||
void operator()(app * n) {
|
||||
unsigned num_args = n->get_num_args();
|
||||
func_decl * decl = n->get_decl();
|
||||
if (num_args != decl->get_arity() && !decl->is_associative()) {
|
||||
TRACE("ws", tout << "unexpected number of arguments.\n" << mk_ismt2_pp(n, m_manager););
|
||||
warning_msg("unexpected number of arguments.");
|
||||
m_error = true;
|
||||
return;
|
||||
}
|
||||
|
||||
for (unsigned i = 0; i < num_args; i++) {
|
||||
sort * actual_sort = m_manager.get_sort(n->get_arg(i));
|
||||
sort * expected_sort = decl->is_associative() ? decl->get_domain(0) : decl->get_domain(i);
|
||||
if (expected_sort != actual_sort) {
|
||||
TRACE("tc", tout << "sort mismatch on argument #" << i << ".\n" << mk_ismt2_pp(n, m_manager);
|
||||
tout << "Sort mismatch for argument " << i+1 << " of " << mk_ismt2_pp(n, m_manager, false) << "\n";
|
||||
tout << "Expected sort: " << mk_pp(expected_sort, m_manager) << "\n";
|
||||
tout << "Actual sort: " << mk_pp(actual_sort, m_manager) << "\n";
|
||||
tout << "Function sort: " << mk_pp(decl, m_manager) << ".";
|
||||
);
|
||||
std::ostringstream strm;
|
||||
strm << "Sort mismatch for argument " << i+1 << " of " << mk_ll_pp(n, m_manager, false) << "\n";
|
||||
strm << "Expected sort: " << mk_pp(expected_sort, m_manager) << "\n";
|
||||
strm << "Actual sort: " << mk_pp(actual_sort, m_manager) << "\n";
|
||||
strm << "Function sort: " << mk_pp(decl, m_manager) << ".";
|
||||
warning_msg(strm.str().c_str());
|
||||
m_error = true;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
bool is_well_sorted(ast_manager const & m, expr * n) {
|
||||
well_sorted_proc p(const_cast<ast_manager&>(m));
|
||||
for_each_expr(p, n);
|
||||
return !p.m_error;
|
||||
}
|
||||
|
||||
|
28
src/ast/well_sorted.h
Normal file
28
src/ast/well_sorted.h
Normal file
|
@ -0,0 +1,28 @@
|
|||
/*++
|
||||
Copyright (c) 2006 Microsoft Corporation
|
||||
|
||||
Module Name:
|
||||
|
||||
well_sorted.h
|
||||
|
||||
Abstract:
|
||||
|
||||
<abstract>
|
||||
|
||||
Author:
|
||||
|
||||
Leonardo de Moura (leonardo) 2007-12-29.
|
||||
|
||||
Revision History:
|
||||
|
||||
--*/
|
||||
#ifndef _WELL_SORTED_H_
|
||||
#define _WELL_SORTED_H_
|
||||
|
||||
class ast_manager;
|
||||
class expr;
|
||||
|
||||
bool is_well_sorted(ast_manager const & m, expr * n);
|
||||
|
||||
#endif /* _WELL_SORTED_H_ */
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue