void process(expr e) { if (e.num_args() > 0) { for (int i = 0; i < e.num_args(); i++) process(e.arg(i)); return; } if (e.kind() != Z3_APP_AST) return; //not a variable VARIBLE_VALUE vv; func_decl def = e.decl(); vv.name = def.name().str(); if (e.is_bool()) // bool { if (vv.name == "false" || vv.name == "true") return; vv.type = "bool"; vv.size = 1; vv.value = "false"; } else if (e.is_bv()) //bitvector { sort s = def.range(); vv.type = "bitvector"; vv.size = s.bv_size(); vv.value = "0"; } else // we do not handle other sorts { std::cout << "we just handle bool or bitvector.\n"; exit(0); } defaultSolution.insert(std::make_pair(def.name().str(), vv)); }
void ConstraintManager::addConstraint(expr constraint) { cid idx = id2Constraint.size(); expr pi = Utils::get_ctx().bool_const(string("pmuc"+to_string(idx)).c_str()); id2Constraint.push_back(constraint); if (isHLC) constraint = Utils::convert_to_cnf_simplified(constraint); vector<clid> clauses; if (constraint.decl().decl_kind() == Z3_OP_AND) { for (unsigned i = 0; i < constraint.num_args(); ++i) { clauses.push_back(clid2Clause.size()); clid2Clause.push_back(constraint.arg(i)); clid2Cid.push_back(idx); } } else { clauses.push_back(clid2Clause.size()); clid2Clause.push_back(constraint); clid2Cid.push_back(idx); } cid2clauses.push_back(clauses); id2CnfConstraint.push_back(constraint); id2AssumptionP.push_back(pi); p2Id[pi] = idx; }
void visit(expr const & e) { if (e.is_app()) { unsigned num = e.num_args(); for (unsigned i = 0; i < num; i++) { visit(e.arg(i)); } // do something // Example: print the visited expression func_decl f = e.decl(); std::cout << "application of " << f.name() << ": " << e << "\n"; } else if (e.is_quantifier()) { visit(e.body()); // do something } else { assert(e.is_var()); // do something } }