mirror of
https://github.com/Z3Prover/z3
synced 2025-04-23 09:05:31 +00:00
new files
Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com>
This commit is contained in:
parent
e4eca577f6
commit
bce1ee6d39
4 changed files with 282 additions and 0 deletions
96
src/ast/rewriter/func_decl_replace.cpp
Normal file
96
src/ast/rewriter/func_decl_replace.cpp
Normal file
|
@ -0,0 +1,96 @@
|
|||
/*++
|
||||
Copyright (c) 2019 Microsoft Corporation
|
||||
|
||||
Module Name:
|
||||
|
||||
func_decl_replace.cpp
|
||||
|
||||
Abstract:
|
||||
|
||||
Replace functions in expressions.
|
||||
|
||||
Author:
|
||||
|
||||
Nikolaj Bjorner (nbjorner) 2019-03-28
|
||||
|
||||
Revision History:
|
||||
|
||||
|
||||
--*/
|
||||
|
||||
|
||||
#include "ast/rewriter/func_decl_replace.h"
|
||||
|
||||
expr_ref func_decl_replace::operator()(expr* e) {
|
||||
m_todo.push_back(e);
|
||||
|
||||
while (!m_todo.empty()) {
|
||||
expr* a = m_todo.back(), *b;
|
||||
if (m_cache.contains(a)) {
|
||||
m_todo.pop_back();
|
||||
}
|
||||
else if (is_var(a)) {
|
||||
m_cache.insert(a, a);
|
||||
m_todo.pop_back();
|
||||
}
|
||||
else if (is_app(a)) {
|
||||
app* c = to_app(a);
|
||||
unsigned n = c->get_num_args();
|
||||
m_args.reset();
|
||||
bool arg_differs = false;
|
||||
for (unsigned i = 0; i < n; ++i) {
|
||||
expr* d = nullptr, *arg = c->get_arg(i);
|
||||
if (m_cache.find(arg, d)) {
|
||||
m_args.push_back(d);
|
||||
arg_differs |= arg != d;
|
||||
SASSERT(m.get_sort(arg) == m.get_sort(d));
|
||||
}
|
||||
else {
|
||||
m_todo.push_back(arg);
|
||||
}
|
||||
}
|
||||
if (m_args.size() == n) {
|
||||
if (arg_differs) {
|
||||
b = m.mk_app(c->get_decl(), m_args.size(), m_args.c_ptr());
|
||||
m_refs.push_back(b);
|
||||
SASSERT(m.get_sort(a) == m.get_sort(b));
|
||||
} else {
|
||||
b = a;
|
||||
}
|
||||
func_decl* f = nullptr;
|
||||
if (m_subst.find(c->get_decl(), f)) {
|
||||
b = m.mk_app(f, m_args.size(), m_args.c_ptr());
|
||||
m_refs.push_back(b);
|
||||
}
|
||||
m_cache.insert(a, b);
|
||||
m_todo.pop_back();
|
||||
}
|
||||
}
|
||||
else {
|
||||
quantifier* q = to_quantifier(a);
|
||||
SASSERT(is_quantifier(a));
|
||||
expr* body = q->get_expr(), *new_body;
|
||||
if (m_cache.find(body, new_body)) {
|
||||
if (new_body == body) {
|
||||
b = a;
|
||||
}
|
||||
else {
|
||||
b = m.update_quantifier(q, new_body);
|
||||
m_refs.push_back(b);
|
||||
}
|
||||
m_cache.insert(a, b);
|
||||
m_todo.pop_back();
|
||||
}
|
||||
else {
|
||||
m_todo.push_back(body);
|
||||
}
|
||||
}
|
||||
}
|
||||
return expr_ref(cache.find(e), m);
|
||||
}
|
||||
|
||||
void func_decl_replace::reset() {
|
||||
m_cache.reset();
|
||||
m_subst.reset();
|
||||
m_refs.reset();
|
||||
}
|
45
src/ast/rewriter/func_decl_replace.h
Normal file
45
src/ast/rewriter/func_decl_replace.h
Normal file
|
@ -0,0 +1,45 @@
|
|||
/*++
|
||||
Copyright (c) 2019 Microsoft Corporation
|
||||
|
||||
Module Name:
|
||||
|
||||
func_decl_replace.h
|
||||
|
||||
Abstract:
|
||||
|
||||
Replace functions in expressions.
|
||||
|
||||
Author:
|
||||
|
||||
Nikolaj Bjorner (nbjorner) 2019-03-28
|
||||
|
||||
Revision History:
|
||||
|
||||
|
||||
--*/
|
||||
|
||||
#ifndef FUNC_DECL_REPLACE_H_
|
||||
#define FUNC_DECL_REPLACE_H_
|
||||
|
||||
#include "ast/ast.h"
|
||||
|
||||
class func_decl_replace {
|
||||
ast_manager& m;
|
||||
obj_map<func_decl, func_decl*> m_subst;
|
||||
obj_map<expr, expr*> m_cache;
|
||||
ptr_vector<expr> m_todo, m_args;
|
||||
expr_ref_vector m_refs;
|
||||
|
||||
public:
|
||||
func_decl_replace(ast_manager& m): m(m), m_refs(m) {}
|
||||
|
||||
void insert(func_decl* src, func_decl* dst) { m_subst.insert(src, dst); }
|
||||
|
||||
expr_ref operator()(expr* e);
|
||||
|
||||
void reset();
|
||||
|
||||
bool empty() const { return m_subst.empty(); }
|
||||
};
|
||||
|
||||
#endif /* FUNC_DECL_REPLACE_H_ */
|
Loading…
Add table
Add a link
Reference in a new issue