这是我的枚举类型测试程序的源代码:
Z3_symbol enum_names[3];
Z3_func_decl enum_consts[3];
Z3_func_decl enum_testers[3];
enum_names[0]=Z3_mk_string_symbol(z3_cont,"a");
enum_names[1]=Z3_mk_string_symbol(z3_cont,"b");
enum_names[3]=Z3_mk_string_symbol(z3_cont,"c");
Z3_symbol enum_nm = Z3_mk_string_symbol(z3_cont,"enumT");
Z3_sort s = Z3_mk_enumeration_sort(z3_cont, enum_nm, 3, enum_names, enum_consts, enum_testers);
z3::sort ss(z3_cont,s);
z3::expr a = z3::expr(z3_cont,Z3_mk_app(z3_cont,enum_consts[0],0,0));
z3::expr b = z3::expr(z3_cont,Z3_mk_app(z3_cont,enum_consts[1],0,0));
z3::expr x = z3::expr(z3_cont,Z3_mk_const(z3_cont,Z3_mk_string_symbol(z3_cont,"x"),s));
z3::expr test = (x==a)&&(x==b);
cout<<"1:"<<test<<endl;
printf("%s\n", Z3_func_decl_to_string(z3_cont, enum_consts[0]));
printf("%s\n", Z3_func_decl_to_string(z3_cont, enum_consts[1]));
printf("%s\n", Z3_func_decl_to_string(z3_cont, enum_consts[2]));
z3::tactic qe(z3_cont,"ctx-solver-simplify");
z3::goal g(z3_cont);
g.add(test);
z3::expr res(z3_cont);
z3::apply_result result_of_elimination = qe.apply(g);
if ( result_of_elimination.size() == 1){
z3::goal result_formula = result_of_elimination[0];
res = result_formula.operator[](0);
for (int i = 1; i < result_formula.size(); ++i){
res = res && result_formula.operator[](i);
}
}
cout<<"2:"<<res<<endl;
printf("%s\n", Z3_func_decl_to_string(z3_cont, enum_consts[0]));
printf("%s\n", Z3_func_decl_to_string(z3_cont, enum_consts[1]));
printf("%s\n", Z3_func_decl_to_string(z3_cont, enum_consts[2]));
屏幕输出如下: 1:(and (= xa) (= xb))
(declare-fun a () enumT)
(declare-fun b () enumT)
(declare-fun x() enumT) 这里我期待“c”,为什么是“x”?
2:假
(declare-fun a () enumT)
(declare-fun bv () (_BitVec 1)) 为什么不是“b”?
(declare-fun x () enumT)
主要问题是在调用了一些策略之后我应该如何在我的程序中使用枚举常量?
enum_consts 结构损坏,Z3_mk_app(z3_cont,Z3_mk_func_decl(z3_cont,Z3_mk_string_symbol(z3_cont,"a"),0,0,s),0,0) 不起作用。