mirror of
https://github.com/Z3Prover/z3
synced 2025-07-20 11:22:04 +00:00
other components
Signed-off-by: Leonardo de Moura <leonardo@microsoft.com>
This commit is contained in:
parent
e9eab22e5c
commit
68269c43a6
250 changed files with 70871 additions and 0 deletions
50
test/expr_pattern_match.cpp
Normal file
50
test/expr_pattern_match.cpp
Normal file
|
@ -0,0 +1,50 @@
|
|||
#include "expr_pattern_match.h"
|
||||
#include "smtparser.h"
|
||||
#include "ast_pp.h"
|
||||
#include "arith_decl_plugin.h"
|
||||
#include "bv_decl_plugin.h"
|
||||
#include "array_decl_plugin.h"
|
||||
|
||||
void tst_expr_pattern_match() {
|
||||
ast_manager manager;
|
||||
manager.register_decl_plugins();
|
||||
|
||||
expr_pattern_match apm(manager);
|
||||
|
||||
apm.display(std::cout);
|
||||
|
||||
const char* test_string = "(benchmark patterns :status unknown :logic ALL \n"
|
||||
":extrasorts (S) \n"
|
||||
":extrafuns ((R S S bool)) \n"
|
||||
":formula (forall (x S) (y S) (z S) \n"
|
||||
" (or (not (R x y)) (not (R y z)) (R x z)) \n"
|
||||
" ; :pats { (R x y) (R y z) } \n"
|
||||
" :weight { 2 } \n"
|
||||
" )\n"
|
||||
")";
|
||||
smtlib::parser* parser = smtlib::parser::create(manager);
|
||||
parser->initialize_smtlib();
|
||||
std::cout << "parsing test string\n";
|
||||
if (!parser->parse_string(test_string)) {
|
||||
UNREACHABLE();
|
||||
}
|
||||
std::cout << "test string parsed\n";
|
||||
smtlib::benchmark* bench = parser->get_benchmark();
|
||||
|
||||
for (unsigned i = 0; i < bench->get_num_formulas(); ++i) {
|
||||
expr* fml = bench->begin_formulas()[i];
|
||||
SASSERT(fml->get_kind() == AST_QUANTIFIER);
|
||||
quantifier* qf = to_quantifier(fml);
|
||||
app_ref_vector patterns(manager);
|
||||
unsigned weight = 0;
|
||||
if (apm.match_quantifier(qf, patterns, weight)) {
|
||||
std::cout << "Found pattern match\n";
|
||||
for (unsigned i = 0; i < patterns.size(); ++i) {
|
||||
ast_pp(std::cout, patterns[i].get(), manager) << "\n";
|
||||
}
|
||||
std::cout << "weight: " << weight << "\n";
|
||||
}
|
||||
}
|
||||
dealloc(parser);
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue