3
0
Fork 0
mirror of https://github.com/Z3Prover/z3 synced 2026-02-19 23:14:40 +00:00

Standardize for-loop increments to prefix form (++i) (#8199)

* Initial plan

* Convert postfix to prefix increment in for loops

Co-authored-by: NikolajBjorner <3085284+NikolajBjorner@users.noreply.github.com>

* Fix member variable increment conversion bug

Co-authored-by: NikolajBjorner <3085284+NikolajBjorner@users.noreply.github.com>

* Update API generator to produce prefix increments

Co-authored-by: NikolajBjorner <3085284+NikolajBjorner@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: NikolajBjorner <3085284+NikolajBjorner@users.noreply.github.com>
This commit is contained in:
Copilot 2026-01-14 19:55:31 -08:00 committed by Nikolaj Bjorner
parent 851b8ea31c
commit 317dd92105
475 changed files with 3237 additions and 3237 deletions

View file

@ -325,7 +325,7 @@ extern "C" {
static bool to_anum_vector(Z3_context c, unsigned n, Z3_ast a[], scoped_anum_vector & as) {
algebraic_numbers::manager & _am = am(c);
scoped_anum tmp(_am);
for (unsigned i = 0; i < n; i++) {
for (unsigned i = 0; i < n; ++i) {
if (is_rational(c, a[i])) {
_am.set(tmp, get_rational(c, a[i]).to_mpq());
as.push_back(tmp);
@ -378,7 +378,7 @@ extern "C" {
}
Z3_ast_vector_ref* result = alloc(Z3_ast_vector_ref, *mk_c(c), mk_c(c)->m());
mk_c(c)->save_object(result);
for (unsigned i = 0; i < roots.size(); i++) {
for (unsigned i = 0; i < roots.size(); ++i) {
result->m_ast_vector.push_back(au(c).mk_numeral(_am, roots.get(i), false));
}
RETURN_Z3(of_ast_vector(result));

View file

@ -901,7 +901,7 @@ extern "C" {
expr * const * from = to_exprs(num_exprs, _from);
expr * const * to = to_exprs(num_exprs, _to);
expr * r = nullptr;
for (unsigned i = 0; i < num_exprs; i++) {
for (unsigned i = 0; i < num_exprs; ++i) {
if (from[i]->get_sort() != to[i]->get_sort()) {
SET_ERROR_CODE(Z3_SORT_ERROR, nullptr);
RETURN_Z3(of_expr(nullptr));
@ -910,7 +910,7 @@ extern "C" {
SASSERT(to[i]->get_ref_count() > 0);
}
expr_safe_replace subst(m);
for (unsigned i = 0; i < num_exprs; i++) {
for (unsigned i = 0; i < num_exprs; ++i) {
subst.insert(from[i], to[i]);
}
expr_ref new_a(m);
@ -940,7 +940,7 @@ extern "C" {
obj_map<func_decl, expr*> rep;
obj_map<expr, expr*> cache;
for (unsigned i = 0; i < num_funs; i++) {
for (unsigned i = 0; i < num_funs; ++i) {
if (from[i]->get_range() != to[i]->get_sort()) {
SET_ERROR_CODE(Z3_SORT_ERROR, nullptr);
RETURN_Z3(of_expr(nullptr));

View file

@ -112,7 +112,7 @@ extern "C" {
Z3_ast_vector_ref * new_v = alloc(Z3_ast_vector_ref, *mk_c(t), mk_c(t)->m());
mk_c(t)->save_object(new_v);
unsigned sz = to_ast_vector_ref(v).size();
for (unsigned i = 0; i < sz; i++) {
for (unsigned i = 0; i < sz; ++i) {
ast * new_ast = translator(to_ast_vector_ref(v).get(i));
new_v->m_ast_vector.push_back(new_ast);
}
@ -127,7 +127,7 @@ extern "C" {
std::ostringstream buffer;
buffer << "(ast-vector";
unsigned sz = to_ast_vector_ref(v).size();
for (unsigned i = 0; i < sz; i++) {
for (unsigned i = 0; i < sz; ++i) {
buffer << "\n " << mk_ismt2_pp(to_ast_vector_ref(v).get(i), mk_c(c)->m(), 2);
}
buffer << ")";

View file

@ -77,7 +77,7 @@ extern "C" {
// Create projections
ptr_vector<func_decl> const & _accs = *dt_util.get_constructor_accessors(decl);
SASSERT(_accs.size() == num_fields);
for (unsigned i = 0; i < _accs.size(); i++) {
for (unsigned i = 0; i < _accs.size(); ++i) {
mk_c(c)->save_multiple_ast_trail(_accs[i]);
proj_decls[i] = of_func_decl(_accs[i]);
}

View file

@ -141,7 +141,7 @@ extern "C" {
Z3_TRY;
LOG_Z3_optimize_check(c, o, num_assumptions, assumptions);
RESET_ERROR_CODE();
for (unsigned i = 0; i < num_assumptions; i++) {
for (unsigned i = 0; i < num_assumptions; ++i) {
if (!is_expr(to_ast(assumptions[i]))) {
SET_ERROR_CODE(Z3_INVALID_ARG, "assumption is not an expression");
return Z3_L_UNDEF;
@ -432,7 +432,7 @@ extern "C" {
unsigned n = to_optimize_ptr(o)->num_objectives();
Z3_ast_vector_ref * v = alloc(Z3_ast_vector_ref, *mk_c(c), mk_c(c)->m());
mk_c(c)->save_object(v);
for (unsigned i = 0; i < n; i++) {
for (unsigned i = 0; i < n; ++i) {
v->m_ast_vector.push_back(to_optimize_ptr(o)->get_objective(i));
}
RETURN_Z3(of_ast_vector(v));

View file

@ -202,7 +202,7 @@ extern "C" {
std::ostringstream buffer;
buffer << "(";
unsigned sz = to_param_descrs_ptr(p)->size();
for (unsigned i = 0; i < sz; i++) {
for (unsigned i = 0; i < sz; ++i) {
if (i > 0)
buffer << ", ";
buffer << to_param_descrs_ptr(p)->get_param_name(i);

View file

@ -56,7 +56,7 @@ extern "C" {
scoped_timer timer(mk_c(c)->params().m_timeout, &eh);
pm.psc_chain(_p, _q, v_x, rs);
}
for (unsigned i = 0; i < rs.size(); i++) {
for (unsigned i = 0; i < rs.size(); ++i) {
r = rs.get(i);
converter.to_expr(r, true, _r);
result->m_ast_vector.push_back(_r);

View file

@ -73,7 +73,7 @@ extern "C" {
expr * const* no_ps = reinterpret_cast<expr * const*>(no_patterns);
symbol qid = to_symbol(quantifier_id);
pattern_validator v(mk_c(c)->m());
for (unsigned i = 0; i < num_patterns; i++) {
for (unsigned i = 0; i < num_patterns; ++i) {
if (!v(num_decls, ps[i], 0, 0)) {
SET_ERROR_CODE(Z3_INVALID_PATTERN, nullptr);
return nullptr;

View file

@ -115,7 +115,7 @@ extern "C" {
reset_rcf_cancel(c);
rcnumeral_vector av;
unsigned rz = 0;
for (unsigned i = 0; i < n; i++) {
for (unsigned i = 0; i < n; ++i) {
if (!rcfm(c).is_zero(to_rcnumeral(a[i])))
rz = i + 1;
av.push_back(to_rcnumeral(a[i]));
@ -129,7 +129,7 @@ extern "C" {
rcnumeral_vector rs;
rcfm(c).isolate_roots(av.size(), av.data(), rs);
unsigned num_roots = rs.size();
for (unsigned i = 0; i < num_roots; i++) {
for (unsigned i = 0; i < num_roots; ++i) {
roots[i] = from_rcnumeral(rs[i]);
}
RETURN_Z3_rcf_mk_roots num_roots;

View file

@ -558,7 +558,7 @@ extern "C" {
Z3_ast_vector_ref * v = alloc(Z3_ast_vector_ref, *mk_c(c), mk_c(c)->m());
mk_c(c)->save_object(v);
unsigned sz = to_solver_ref(s)->get_num_assertions();
for (unsigned i = 0; i < sz; i++) {
for (unsigned i = 0; i < sz; ++i) {
v->m_ast_vector.push_back(to_solver_ref(s)->get_assertion(i));
}
RETURN_Z3(of_ast_vector(v));
@ -638,7 +638,7 @@ extern "C" {
#define TOSTRING(x) STRINGIFY(x)
static Z3_lbool _solver_check(Z3_context c, Z3_solver s, unsigned num_assumptions, Z3_ast const assumptions[]) {
for (unsigned i = 0; i < num_assumptions; i++) {
for (unsigned i = 0; i < num_assumptions; ++i) {
if (!is_expr(to_ast(assumptions[i]))) {
SET_ERROR_CODE(Z3_INVALID_ARG, "assumption is not an expression");
return Z3_L_UNDEF;

View file

@ -140,7 +140,7 @@ extern "C" {
LOG_Z3_tactic_par_or(c, num, ts);
RESET_ERROR_CODE();
ptr_buffer<tactic> _ts;
for (unsigned i = 0; i < num; i++) {
for (unsigned i = 0; i < num; ++i) {
_ts.push_back(to_tactic_ref(ts[i]));
}
tactic * new_t = par(num, _ts.data());
@ -496,7 +496,7 @@ extern "C" {
std::ostringstream buffer;
buffer << "(goals\n";
unsigned sz = to_apply_result(r)->m_subgoals.size();
for (unsigned i = 0; i < sz; i++) {
for (unsigned i = 0; i < sz; ++i) {
to_apply_result(r)->m_subgoals[i]->display(buffer);
}
buffer << ')';

View file

@ -1267,7 +1267,7 @@ namespace z3 {
expr_vector args() const {
expr_vector vec(ctx());
unsigned argCnt = num_args();
for (unsigned i = 0; i < argCnt; i++)
for (unsigned i = 0; i < argCnt; ++i)
vec.push_back(arg(i));
return vec;
}
@ -2398,7 +2398,7 @@ namespace z3 {
template<typename T>
template<typename T2>
array<T>::array(ast_vector_tpl<T2> const & v):m_array(new T[v.size()]), m_size(v.size()) {
for (unsigned i = 0; i < m_size; i++) {
for (unsigned i = 0; i < m_size; ++i) {
m_array[i] = v[i];
}
}
@ -2929,7 +2929,7 @@ namespace z3 {
check_result check() { Z3_lbool r = Z3_solver_check(ctx(), m_solver); check_error(); return to_check_result(r); }
check_result check(unsigned n, expr * const assumptions) {
array<Z3_ast> _assumptions(n);
for (unsigned i = 0; i < n; i++) {
for (unsigned i = 0; i < n; ++i) {
check_context(*this, assumptions[i]);
_assumptions[i] = assumptions[i];
}
@ -2940,7 +2940,7 @@ namespace z3 {
check_result check(expr_vector const& assumptions) {
unsigned n = assumptions.size();
array<Z3_ast> _assumptions(n);
for (unsigned i = 0; i < n; i++) {
for (unsigned i = 0; i < n; ++i) {
check_context(*this, assumptions[i]);
_assumptions[i] = assumptions[i];
}
@ -3171,7 +3171,7 @@ namespace z3 {
return operator[](0u);
else {
array<Z3_ast> args(n);
for (unsigned i = 0; i < n; i++)
for (unsigned i = 0; i < n; ++i)
args[i] = operator[](i);
return expr(ctx(), Z3_mk_and(ctx(), n, args.ptr()));
}
@ -3500,7 +3500,7 @@ namespace z3 {
check_result check(expr_vector const& asms) {
unsigned n = asms.size();
array<Z3_ast> _asms(n);
for (unsigned i = 0; i < n; i++) {
for (unsigned i = 0; i < n; ++i) {
check_context(*this, asms[i]);
_asms[i] = asms[i];
}
@ -3642,25 +3642,25 @@ namespace z3 {
}
inline sort context::enumeration_sort(char const * name, unsigned n, char const * const * enum_names, func_decl_vector & cs, func_decl_vector & ts) {
array<Z3_symbol> _enum_names(n);
for (unsigned i = 0; i < n; i++) { _enum_names[i] = Z3_mk_string_symbol(*this, enum_names[i]); }
for (unsigned i = 0; i < n; ++i) { _enum_names[i] = Z3_mk_string_symbol(*this, enum_names[i]); }
array<Z3_func_decl> _cs(n);
array<Z3_func_decl> _ts(n);
Z3_symbol _name = Z3_mk_string_symbol(*this, name);
sort s = to_sort(*this, Z3_mk_enumeration_sort(*this, _name, n, _enum_names.ptr(), _cs.ptr(), _ts.ptr()));
check_error();
for (unsigned i = 0; i < n; i++) { cs.push_back(func_decl(*this, _cs[i])); ts.push_back(func_decl(*this, _ts[i])); }
for (unsigned i = 0; i < n; ++i) { cs.push_back(func_decl(*this, _cs[i])); ts.push_back(func_decl(*this, _ts[i])); }
return s;
}
inline func_decl context::tuple_sort(char const * name, unsigned n, char const * const * names, sort const* sorts, func_decl_vector & projs) {
array<Z3_symbol> _names(n);
array<Z3_sort> _sorts(n);
for (unsigned i = 0; i < n; i++) { _names[i] = Z3_mk_string_symbol(*this, names[i]); _sorts[i] = sorts[i]; }
for (unsigned i = 0; i < n; ++i) { _names[i] = Z3_mk_string_symbol(*this, names[i]); _sorts[i] = sorts[i]; }
array<Z3_func_decl> _projs(n);
Z3_symbol _name = Z3_mk_string_symbol(*this, name);
Z3_func_decl tuple;
sort _ignore_s = to_sort(*this, Z3_mk_tuple_sort(*this, _name, n, _names.ptr(), _sorts.ptr(), &tuple, _projs.ptr()));
check_error();
for (unsigned i = 0; i < n; i++) { projs.push_back(func_decl(*this, _projs[i])); }
for (unsigned i = 0; i < n; ++i) { projs.push_back(func_decl(*this, _projs[i])); }
return func_decl(*this, tuple);
}
@ -3783,7 +3783,7 @@ namespace z3 {
inline func_decl context::function(symbol const & name, unsigned arity, sort const * domain, sort const & range) {
array<Z3_sort> args(arity);
for (unsigned i = 0; i < arity; i++) {
for (unsigned i = 0; i < arity; ++i) {
check_context(domain[i], range);
args[i] = domain[i];
}
@ -3798,7 +3798,7 @@ namespace z3 {
inline func_decl context::function(symbol const& name, sort_vector const& domain, sort const& range) {
array<Z3_sort> args(domain.size());
for (unsigned i = 0; i < domain.size(); i++) {
for (unsigned i = 0; i < domain.size(); ++i) {
check_context(domain[i], range);
args[i] = domain[i];
}
@ -3854,7 +3854,7 @@ namespace z3 {
inline func_decl context::recfun(symbol const & name, unsigned arity, sort const * domain, sort const & range) {
array<Z3_sort> args(arity);
for (unsigned i = 0; i < arity; i++) {
for (unsigned i = 0; i < arity; ++i) {
check_context(domain[i], range);
args[i] = domain[i];
}
@ -3978,7 +3978,7 @@ namespace z3 {
inline expr func_decl::operator()(unsigned n, expr const * args) const {
array<Z3_ast> _args(n);
for (unsigned i = 0; i < n; i++) {
for (unsigned i = 0; i < n; ++i) {
check_context(*this, args[i]);
_args[i] = args[i];
}
@ -3989,7 +3989,7 @@ namespace z3 {
}
inline expr func_decl::operator()(expr_vector const& args) const {
array<Z3_ast> _args(args.size());
for (unsigned i = 0; i < args.size(); i++) {
for (unsigned i = 0; i < args.size(); ++i) {
check_context(*this, args[i]);
_args[i] = args[i];
}
@ -5016,7 +5016,7 @@ namespace z3 {
std::vector<Z3_rcf_num> a(n);
std::vector<Z3_rcf_num> roots(n);
for (unsigned i = 0; i < n; i++) {
for (unsigned i = 0; i < n; ++i) {
a[i] = coeffs[i];
}
@ -5024,7 +5024,7 @@ namespace z3 {
std::vector<rcf_num> result;
result.reserve(num_roots);
for (unsigned i = 0; i < num_roots; i++) {
for (unsigned i = 0; i < num_roots; ++i) {
result.push_back(rcf_num(c, roots[i]));
}

View file

@ -413,7 +413,7 @@ JLCXX_MODULE define_julia_module(jlcxx::Module &m)
.method("trail", [](solver &s, jlcxx::ArrayRef<unsigned> levels) {
int sz = levels.size();
z3::array<unsigned> _levels(sz);
for (int i = 0; i < sz; i++) {
for (int i = 0; i < sz; ++i) {
_levels[i] = levels[i];
}
return s.trail(_levels);
@ -643,7 +643,7 @@ JLCXX_MODULE define_julia_module(jlcxx::Module &m)
[](context& c, char const * name, jlcxx::ArrayRef<jl_value_t*,1> names, func_decl_vector &cs, func_decl_vector &ts) {
int sz = names.size();
std::vector<const char *> _names;
for (int i = 0; i < sz; i++) {
for (int i = 0; i < sz; ++i) {
const char *x = jl_string_data(names[i]);
_names.push_back(x);
}
@ -654,7 +654,7 @@ JLCXX_MODULE define_julia_module(jlcxx::Module &m)
int sz = names.size();
std::vector<sort> _sorts;
std::vector<const char *> _names;
for (int i = 0; i < sz; i++) {
for (int i = 0; i < sz; ++i) {
const sort &x = jlcxx::unbox<sort&>(sorts[i]);
const char *y = jl_string_data(names[i]);
_sorts.push_back(x);

View file

@ -155,7 +155,7 @@ struct z3_replayer::imp {
}
void display_args(std::ostream & out) const {
for (unsigned i = 0; i < m_args.size(); i++) {
for (unsigned i = 0; i < m_args.size(); ++i) {
if (i > 0) out << " ";
display_arg(out, m_args[i]);
}
@ -348,7 +348,7 @@ struct z3_replayer::imp {
throw z3_replayer_exception("invalid array size");
uint64_t aidx;
value_kind nk;
for (unsigned i = asz - sz; i < asz; i++) {
for (unsigned i = asz - sz; i < asz; ++i) {
if (m_args[i].m_kind != k)
throw z3_replayer_exception("invalid array: mixed value types");
}
@ -357,7 +357,7 @@ struct z3_replayer::imp {
nk = UINT_ARRAY;
m_unsigned_arrays.push_back(unsigned_vector());
unsigned_vector & v = m_unsigned_arrays.back();
for (unsigned i = asz - sz; i < asz; i++) {
for (unsigned i = asz - sz; i < asz; ++i) {
v.push_back(static_cast<unsigned>(m_args[i].m_uint));
}
}
@ -366,7 +366,7 @@ struct z3_replayer::imp {
nk = INT_ARRAY;
m_int_arrays.push_back(svector<int>());
svector<int> & v = m_int_arrays.back();
for (unsigned i = asz - sz; i < asz; i++) {
for (unsigned i = asz - sz; i < asz; ++i) {
v.push_back(static_cast<int>(m_args[i].m_int));
}
}
@ -375,7 +375,7 @@ struct z3_replayer::imp {
nk = SYMBOL_ARRAY;
m_sym_arrays.push_back(svector<Z3_symbol>());
svector<Z3_symbol> & v = m_sym_arrays.back();
for (unsigned i = asz - sz; i < asz; i++) {
for (unsigned i = asz - sz; i < asz; ++i) {
v.push_back(reinterpret_cast<Z3_symbol>(const_cast<char*>(m_args[i].m_str)));
}
}
@ -383,14 +383,14 @@ struct z3_replayer::imp {
TRACE(z3_replayer_bug,
tout << "args: "; display_args(tout); tout << "\n";
tout << "push_back, sz: " << sz << ", m_obj_arrays.size(): " << m_obj_arrays.size() << "\n";
for (unsigned i = asz - sz; i < asz; i++) {
for (unsigned i = asz - sz; i < asz; ++i) {
tout << "pushing: " << m_args[i].m_obj << "\n";
});
aidx = m_obj_arrays.size();
nk = OBJECT_ARRAY;
m_obj_arrays.push_back(ptr_vector<void>());
ptr_vector<void> & v = m_obj_arrays.back();
for (unsigned i = asz - sz; i < asz; i++) {
for (unsigned i = asz - sz; i < asz; ++i) {
v.push_back(m_args[i].m_obj);
}
}
@ -658,7 +658,7 @@ struct z3_replayer::imp {
unsigned idx = static_cast<unsigned>(m_args[pos].m_uint);
ptr_vector<void> const & v = m_obj_arrays[idx];
TRACE(z3_replayer_bug, tout << "pos: " << pos << ", idx: " << idx << " size(): " << v.size() << "\n";
for (unsigned i = 0; i < v.size(); i++) tout << v[i] << " "; tout << "\n";);
for (unsigned i = 0; i < v.size(); ++i) tout << v[i] << " "; tout << "\n";);
return v.data();
}