3
0
Fork 0
mirror of https://github.com/Z3Prover/z3 synced 2025-07-27 14:37:55 +00:00

Reorganizing the code

Signed-off-by: Leonardo de Moura <leonardo@microsoft.com>
This commit is contained in:
Leonardo de Moura 2012-10-20 22:03:58 -07:00
parent 2b8fb6c718
commit 492484c5aa
125 changed files with 632 additions and 390 deletions

74
src/ast/num_occurs.cpp Normal file
View file

@ -0,0 +1,74 @@
/*++
Copyright (c) 2006 Microsoft Corporation
Module Name:
num_occurs.cpp
Abstract:
<abstract>
Author:
Leonardo de Moura (leonardo) 2008-01-27.
Revision History:
--*/
#include"num_occurs.h"
void num_occurs::process(expr * t, expr_fast_mark1 & visited) {
ptr_buffer<expr, 128> stack;
#define VISIT(ARG) { \
if (!m_ignore_ref_count1 || ARG->get_ref_count() > 1) { \
obj_map<expr, unsigned>::obj_map_entry * entry = m_num_occurs.insert_if_not_there2(ARG, 0); \
entry->get_data().m_value++; \
} \
if (!visited.is_marked(ARG)) { \
visited.mark(ARG, true); \
stack.push_back(ARG); \
} \
}
VISIT(t);
while (!stack.empty()) {
expr * t = stack.back();
stack.pop_back();
unsigned j;
switch (t->get_kind()) {
case AST_APP:
j = to_app(t)->get_num_args();
while (j > 0) {
--j;
expr * arg = to_app(t)->get_arg(j);
VISIT(arg);
}
break;
case AST_QUANTIFIER:
if (!m_ignore_quantifiers) {
expr * child = to_quantifier(t)->get_expr();
VISIT(child);
}
break;
default:
break;
}
}
}
void num_occurs::operator()(expr * t) {
expr_fast_mark1 visited;
process(t, visited);
}
void num_occurs::operator()(unsigned num, expr * const * ts) {
expr_fast_mark1 visited;
for (unsigned i = 0; i < num; i++) {
process(ts[i], visited);
}
}

55
src/ast/num_occurs.h Normal file
View file

@ -0,0 +1,55 @@
/*++
Copyright (c) 2006 Microsoft Corporation
Module Name:
num_occurs.h
Abstract:
<abstract>
Author:
Leonardo de Moura (leonardo) 2008-01-27.
Revision History:
--*/
#ifndef _NUM_OCCURS_H_
#define _NUM_OCCURS_H_
#include"ast.h"
#include"obj_hashtable.h"
/**
\brief Functor for computing the number of occurrences of each sub-expression in a expression F.
*/
class num_occurs {
protected:
bool m_ignore_ref_count1;
bool m_ignore_quantifiers;
obj_map<expr, unsigned> m_num_occurs;
void process(expr * t, expr_fast_mark1 & visited);
public:
num_occurs(bool ignore_ref_count1 = false, bool ignore_quantifiers = false):
m_ignore_ref_count1(ignore_ref_count1),
m_ignore_quantifiers(ignore_quantifiers) {
}
void reset() { m_num_occurs.reset(); }
void operator()(expr * t);
void operator()(unsigned num, expr * const * ts);
unsigned get_num_occs(expr * n) const {
unsigned val;
if (m_num_occurs.find(n, val))
return val;
return 0;
}
};
#endif /* _NUM_OCCURS_H_ */

77
src/ast/occurs.cpp Normal file
View file

@ -0,0 +1,77 @@
/*++
Copyright (c) 2006 Microsoft Corporation
Module Name:
occurs.cpp
Abstract:
<abstract>
Author:
Leonardo de Moura (leonardo) 2007-06-07.
Revision History:
--*/
#include"occurs.h"
#include"for_each_expr.h"
// -----------------------------------
//
// Occurs check
//
// -----------------------------------
namespace occurs_namespace {
struct found {};
struct proc {
expr * m_n;
#define CHECK() { if (n == m_n) throw found(); }
proc(expr * n):m_n(n) {}
void operator()(var const * n) { CHECK(); }
void operator()(app const * n) { CHECK(); }
void operator()(quantifier const * n) { CHECK(); }
};
struct decl_proc {
func_decl * m_d;
decl_proc(func_decl * d):m_d(d) {}
void operator()(var const * n) { }
void operator()(app const * n) { if (n->get_decl() == m_d) throw found(); }
void operator()(quantifier const * n) { }
};
};
// Return true if n1 occurs in n2
bool occurs(expr * n1, expr * n2) {
occurs_namespace::proc p(n1);
try {
quick_for_each_expr(p, n2);
}
catch (occurs_namespace::found) {
return true;
}
return false;
}
bool occurs(func_decl * d, expr * n) {
occurs_namespace::decl_proc p(d);
try {
quick_for_each_expr(p, n);
}
catch (occurs_namespace::found) {
return true;
}
return false;
}

36
src/ast/occurs.h Normal file
View file

@ -0,0 +1,36 @@
/*++
Copyright (c) 2006 Microsoft Corporation
Module Name:
occurs.h
Abstract:
<abstract>
Author:
Leonardo de Moura (leonardo) 2007-06-07.
Revision History:
--*/
#ifndef _OCCURS_H_
#define _OCCURS_H_
class expr;
class func_decl;
/**
\brief Return true if n1 occurs in n2
*/
bool occurs(expr * n1, expr * n2);
/**
\brief Return true if d is used in n
*/
bool occurs(func_decl * d, expr * n);
#endif /* _OCCURS_H_ */