mirror of
https://github.com/Z3Prover/z3
synced 2025-05-11 17:54:43 +00:00
Reorganizing code. Added script for generating VS project files
Signed-off-by: Leonardo de Moura <leonardo@microsoft.com>
This commit is contained in:
parent
2c464d413d
commit
8a6997960a
68 changed files with 167 additions and 170 deletions
109
src/ast/recurse_expr_def.h
Normal file
109
src/ast/recurse_expr_def.h
Normal file
|
@ -0,0 +1,109 @@
|
|||
/*++
|
||||
Copyright (c) 2006 Microsoft Corporation
|
||||
|
||||
Module Name:
|
||||
|
||||
recurse_expr_def.h
|
||||
|
||||
Abstract:
|
||||
|
||||
Traverse an expression applying a visitor.
|
||||
|
||||
Author:
|
||||
|
||||
Leonardo de Moura (leonardo) 2008-01-11.
|
||||
|
||||
Revision History:
|
||||
|
||||
--*/
|
||||
#ifndef _RECURSE_EXPR_DEF_H_
|
||||
#define _RECURSE_EXPR_DEF_H_
|
||||
|
||||
#include"recurse_expr.h"
|
||||
|
||||
template<typename T, typename Visitor, bool IgnorePatterns, bool CallDestructors>
|
||||
inline void recurse_expr<T, Visitor, IgnorePatterns, CallDestructors>::visit(expr * n, bool & visited) {
|
||||
if (!is_cached(n)) {
|
||||
m_todo.push_back(n);
|
||||
visited = false;
|
||||
}
|
||||
}
|
||||
|
||||
template<typename T, typename Visitor, bool IgnorePatterns, bool CallDestructors>
|
||||
bool recurse_expr<T, Visitor, IgnorePatterns, CallDestructors>::visit_children(expr * n) {
|
||||
bool visited = true;
|
||||
unsigned num;
|
||||
switch (n->get_kind()) {
|
||||
case AST_APP:
|
||||
num = to_app(n)->get_num_args();
|
||||
for (unsigned j = 0; j < num; j++)
|
||||
visit(to_app(n)->get_arg(j), visited);
|
||||
break;
|
||||
case AST_QUANTIFIER:
|
||||
if (!IgnorePatterns) {
|
||||
num = to_quantifier(n)->get_num_patterns();
|
||||
for (unsigned j = 0; j < num; j++)
|
||||
visit(to_quantifier(n)->get_pattern(j), visited);
|
||||
num = to_quantifier(n)->get_num_no_patterns();
|
||||
for (unsigned j = 0; j < num; j++)
|
||||
visit(to_quantifier(n)->get_no_pattern(j), visited);
|
||||
}
|
||||
visit(to_quantifier(n)->get_expr(), visited);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return visited;
|
||||
}
|
||||
|
||||
template<typename T, typename Visitor, bool IgnorePatterns, bool CallDestructors>
|
||||
void recurse_expr<T, Visitor, IgnorePatterns, CallDestructors>::process(expr * n) {
|
||||
unsigned num;
|
||||
switch (n->get_kind()) {
|
||||
case AST_APP:
|
||||
m_results1.reset();
|
||||
num = to_app(n)->get_num_args();
|
||||
for (unsigned j = 0; j < num; j++)
|
||||
m_results1.push_back(get_cached(to_app(n)->get_arg(j)));
|
||||
cache_result(n, this->Visitor::visit(to_app(n), m_results1.c_ptr()));
|
||||
break;
|
||||
case AST_VAR:
|
||||
cache_result(n, this->Visitor::visit(to_var(n)));
|
||||
break;
|
||||
case AST_QUANTIFIER:
|
||||
if (IgnorePatterns) {
|
||||
cache_result(n, this->Visitor::visit(to_quantifier(n), get_cached(to_quantifier(n)->get_expr()), 0, 0));
|
||||
}
|
||||
else {
|
||||
m_results1.reset();
|
||||
m_results2.reset();
|
||||
num = to_quantifier(n)->get_num_patterns();
|
||||
for (unsigned j = 0; j < num; j++)
|
||||
m_results1.push_back(get_cached(to_quantifier(n)->get_pattern(j)));
|
||||
num = to_quantifier(n)->get_num_no_patterns();
|
||||
for (unsigned j = 0; j < num; j++)
|
||||
m_results2.push_back(get_cached(to_quantifier(n)->get_no_pattern(j)));
|
||||
cache_result(n, this->Visitor::visit(to_quantifier(n), get_cached(to_quantifier(n)->get_expr()), m_results1.c_ptr(), m_results2.c_ptr()));
|
||||
}
|
||||
break;
|
||||
default:
|
||||
UNREACHABLE();
|
||||
}
|
||||
}
|
||||
|
||||
template<typename T, typename Visitor, bool IgnorePatterns, bool CallDestructors>
|
||||
T recurse_expr<T, Visitor, IgnorePatterns, CallDestructors>::operator()(expr * r) {
|
||||
m_todo.push_back(r);
|
||||
while (!m_todo.empty()) {
|
||||
expr * n = m_todo.back();
|
||||
if (is_cached(n))
|
||||
m_todo.pop_back();
|
||||
else if (visit_children(n)) {
|
||||
m_todo.pop_back();
|
||||
process(n);
|
||||
}
|
||||
}
|
||||
return get_cached(r);
|
||||
}
|
||||
|
||||
#endif /* _RECURSE_EXPR_DEF_H_ */
|
Loading…
Add table
Add a link
Reference in a new issue