mirror of
https://github.com/Z3Prover/z3
synced 2026-05-05 18:05:15 +00:00
Modernize C++ patterns: range-based for loops and nullptr (#8167)
* Initial plan * Replace NULL with nullptr in test files Co-authored-by: NikolajBjorner <3085284+NikolajBjorner@users.noreply.github.com> * Convert iterator loops to range-based for loops (part 1) Co-authored-by: NikolajBjorner <3085284+NikolajBjorner@users.noreply.github.com> * Convert iterator loops to range-based for loops (part 2) Co-authored-by: NikolajBjorner <3085284+NikolajBjorner@users.noreply.github.com> * Fix compilation errors in iterator loop conversions 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:
parent
15108bf36e
commit
b5492e5cf9
16 changed files with 84 additions and 140 deletions
|
|
@ -189,9 +189,9 @@ namespace datalog {
|
|||
expr_ref_vector output(m);
|
||||
const func_decl_set& preds = m_rules.get_output_predicates();
|
||||
|
||||
for (func_decl_set::iterator I = preds.begin(), E = preds.end(); I != E; ++I) {
|
||||
for (func_decl* pred : preds) {
|
||||
exprs.reset();
|
||||
assert_pred_id(*I, m_ruleid_var_set, exprs);
|
||||
assert_pred_id(pred, m_ruleid_var_set, exprs);
|
||||
output.push_back(m.mk_and(exprs.size(), exprs.data()));
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -392,14 +392,12 @@ namespace datalog {
|
|||
if (t.lt.empty() && t.le.empty()) {
|
||||
return;
|
||||
}
|
||||
uint_set::iterator it = t.lt.begin(), end = t.lt.end();
|
||||
unsigned_vector ltv, lev;
|
||||
for (; it != end; ++it) {
|
||||
ltv.push_back(renaming[*it]);
|
||||
for (unsigned idx : t.lt) {
|
||||
ltv.push_back(renaming[idx]);
|
||||
}
|
||||
it = t.le.begin(), end = t.le.end();
|
||||
for (; it != end; ++it) {
|
||||
lev.push_back(renaming[*it]);
|
||||
for (unsigned idx : t.le) {
|
||||
lev.push_back(renaming[idx]);
|
||||
}
|
||||
TRACE(dl,
|
||||
tout << "project: ";
|
||||
|
|
@ -525,9 +523,8 @@ namespace datalog {
|
|||
}
|
||||
|
||||
void bound_relation::normalize(uint_set const& src, uint_set& dst) const {
|
||||
uint_set::iterator it = src.begin(), end = src.end();
|
||||
for (; it != end; ++it) {
|
||||
dst.insert(find(*it));
|
||||
for (unsigned idx : src) {
|
||||
dst.insert(find(idx));
|
||||
}
|
||||
}
|
||||
void bound_relation::normalize(uint_set2 const& src, uint_set2& dst) const {
|
||||
|
|
@ -551,13 +548,11 @@ namespace datalog {
|
|||
continue;
|
||||
}
|
||||
uint_set2& src = (*m_elems)[j];
|
||||
uint_set::iterator it = src.lt.begin(), end = src.lt.end();
|
||||
for(; it != end; ++it) {
|
||||
m_todo.push_back(std::make_pair(*it, true));
|
||||
for (unsigned idx : src.lt) {
|
||||
m_todo.push_back(std::make_pair(idx, true));
|
||||
}
|
||||
it = src.le.begin(), end = src.le.end();
|
||||
for(; it != end; ++it) {
|
||||
m_todo.push_back(std::make_pair(*it, strict));
|
||||
for (unsigned idx : src.le) {
|
||||
m_todo.push_back(std::make_pair(idx, strict));
|
||||
}
|
||||
if (strict) {
|
||||
dst.lt.insert(j);
|
||||
|
|
@ -628,18 +623,16 @@ namespace datalog {
|
|||
s.le.reset();
|
||||
continue;
|
||||
}
|
||||
uint_set::iterator it = s.lt.begin(), end = s.lt.end();
|
||||
for(; it != end; ++it) {
|
||||
ext_numeral const& hi = src[*it].inf();
|
||||
for (unsigned idx : s.lt) {
|
||||
ext_numeral const& hi = src[idx].inf();
|
||||
if (hi.is_infinite() || lo.to_rational() >= hi.to_rational()) {
|
||||
s.lt.remove(*it);
|
||||
s.lt.remove(idx);
|
||||
}
|
||||
}
|
||||
it = s.le.begin(), end = s.le.end();
|
||||
for(; it != end; ++it) {
|
||||
ext_numeral const& hi = src[*it].inf();
|
||||
for (unsigned idx : s.le) {
|
||||
ext_numeral const& hi = src[idx].inf();
|
||||
if (hi.is_infinite() || lo.to_rational() > hi.to_rational()) {
|
||||
s.le.remove(*it);
|
||||
s.le.remove(idx);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -662,13 +655,11 @@ namespace datalog {
|
|||
continue;
|
||||
}
|
||||
uint_set2 const& upper = (*this)[i];
|
||||
uint_set::iterator it = upper.lt.begin(), end = upper.lt.end();
|
||||
for (; it != end; ++it) {
|
||||
conjs.push_back(arith.mk_lt(m.mk_var(i, sig[i]), m.mk_var(*it, sig[*it])));
|
||||
for (unsigned idx : upper.lt) {
|
||||
conjs.push_back(arith.mk_lt(m.mk_var(i, sig[i]), m.mk_var(idx, sig[idx])));
|
||||
}
|
||||
it = upper.le.begin(), end = upper.le.end();
|
||||
for (; it != end; ++it) {
|
||||
conjs.push_back(arith.mk_le(m.mk_var(i, sig[i]), m.mk_var(*it, sig[*it])));
|
||||
for (unsigned idx : upper.le) {
|
||||
conjs.push_back(arith.mk_le(m.mk_var(i, sig[i]), m.mk_var(idx, sig[idx])));
|
||||
}
|
||||
}
|
||||
bsimp.mk_and(conjs.size(), conjs.data(), fml);
|
||||
|
|
@ -676,19 +667,17 @@ namespace datalog {
|
|||
|
||||
|
||||
void bound_relation::display_index(unsigned i, uint_set2 const& src, std::ostream & out) const {
|
||||
uint_set::iterator it = src.lt.begin(), end = src.lt.end();
|
||||
out << "#" << i;
|
||||
if (!src.lt.empty()) {
|
||||
out << " < ";
|
||||
for(; it != end; ++it) {
|
||||
out << *it << " ";
|
||||
for (unsigned idx : src.lt) {
|
||||
out << idx << " ";
|
||||
}
|
||||
}
|
||||
if (!src.le.empty()) {
|
||||
it = src.le.begin(), end = src.le.end();
|
||||
out << " <= ";
|
||||
for(; it != end; ++it) {
|
||||
out << *it << " ";
|
||||
for (unsigned idx : src.le) {
|
||||
out << idx << " ";
|
||||
}
|
||||
}
|
||||
if (src.lt.empty() && src.le.empty()) {
|
||||
|
|
|
|||
|
|
@ -427,9 +427,8 @@ namespace datalog {
|
|||
counter_tail.count_vars(r->get_tail(i));
|
||||
}
|
||||
|
||||
rule_counter::iterator I = counter_tail.begin(), E = counter_tail.end();
|
||||
for (; I != E; ++I) {
|
||||
int& n = counter.get(I->m_key);
|
||||
for (auto const& kv : counter_tail) {
|
||||
int& n = counter.get(kv.m_key);
|
||||
if (n == 0)
|
||||
n = -1;
|
||||
}
|
||||
|
|
@ -577,11 +576,8 @@ namespace datalog {
|
|||
}
|
||||
|
||||
//enforce equality of columns
|
||||
int2ints::iterator vit=var_indexes.begin();
|
||||
int2ints::iterator vend=var_indexes.end();
|
||||
for(; vit!=vend; ++vit) {
|
||||
int2ints::key_data & k = *vit;
|
||||
unsigned_vector & indexes = k.m_value;
|
||||
for (auto& kv : var_indexes) {
|
||||
unsigned_vector & indexes = kv.m_value;
|
||||
if(indexes.size()==1) {
|
||||
continue;
|
||||
}
|
||||
|
|
@ -688,13 +684,12 @@ namespace datalog {
|
|||
{
|
||||
unsigned_vector var_idx_to_remove;
|
||||
m_free_vars(r->get_head());
|
||||
for (int2ints::iterator I = var_indexes.begin(), E = var_indexes.end();
|
||||
I != E; ++I) {
|
||||
unsigned var_idx = I->m_key;
|
||||
for (auto const& kv : var_indexes) {
|
||||
unsigned var_idx = kv.m_key;
|
||||
if (!m_free_vars.contains(var_idx)) {
|
||||
unsigned_vector & cols = I->m_value;
|
||||
for (unsigned i = 0; i < cols.size(); ++i) {
|
||||
remove_columns.push_back(cols[i]);
|
||||
unsigned_vector const& cols = kv.m_value;
|
||||
for (unsigned col : cols) {
|
||||
remove_columns.push_back(col);
|
||||
}
|
||||
var_idx_to_remove.push_back(var_idx);
|
||||
}
|
||||
|
|
@ -715,9 +710,8 @@ namespace datalog {
|
|||
}
|
||||
}
|
||||
|
||||
for (int2ints::iterator I = var_indexes.begin(), E = var_indexes.end();
|
||||
I != E; ++I) {
|
||||
unsigned_vector & cols = I->m_value;
|
||||
for (auto& kv : var_indexes) {
|
||||
unsigned_vector & cols = kv.m_value;
|
||||
for (unsigned i = 0; i < cols.size(); ++i) {
|
||||
cols[i] -= offsets[cols[i]];
|
||||
}
|
||||
|
|
@ -895,10 +889,9 @@ namespace datalog {
|
|||
}
|
||||
}
|
||||
// add negative variables that are not in positive
|
||||
u_map<expr*>::iterator it = neg_vars.begin(), end = neg_vars.end();
|
||||
for (; it != end; ++it) {
|
||||
unsigned v = it->m_key;
|
||||
expr* e = it->m_value;
|
||||
for (auto const& kv : neg_vars) {
|
||||
unsigned v = kv.m_key;
|
||||
expr* e = kv.m_value;
|
||||
if (!pos_vars.contains(v)) {
|
||||
single_res_expr.push_back(e);
|
||||
make_add_unbound_column(r, v, pred, single_res, e->get_sort(), single_res, dealloc, acc);
|
||||
|
|
|
|||
|
|
@ -137,15 +137,11 @@ namespace datalog {
|
|||
std::sort(specs.back().begin(), specs.back().end());
|
||||
}
|
||||
|
||||
vector<rel_spec>::iterator sit = specs.begin(), send = specs.end();
|
||||
|
||||
res.reset();
|
||||
for(;;) {
|
||||
family_id next = -1;
|
||||
|
||||
sit = specs.begin();
|
||||
for(; sit!=send; ++sit) {
|
||||
rel_spec & s = *sit;
|
||||
for (rel_spec& s : specs) {
|
||||
if(!s.empty() && s.back()>next) {
|
||||
next = s.back();
|
||||
}
|
||||
|
|
@ -155,9 +151,7 @@ namespace datalog {
|
|||
break;
|
||||
}
|
||||
res.push_back(next);
|
||||
sit = specs.begin();
|
||||
for(; sit!=send; ++sit) {
|
||||
rel_spec & s = *sit;
|
||||
for (rel_spec& s : specs) {
|
||||
while (!s.empty() && s.back()==next) {
|
||||
s.pop_back();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -937,18 +937,11 @@ namespace datalog {
|
|||
unsigned t1first_func = t1.get_signature().first_functional();
|
||||
unsigned t2first_func = t2.get_signature().first_functional();
|
||||
|
||||
table_base::iterator els1it = t1.begin();
|
||||
table_base::iterator els1end = t1.end();
|
||||
table_base::iterator els2end = t2.end();
|
||||
|
||||
table_fact acc;
|
||||
|
||||
for(; els1it!=els1end; ++els1it) {
|
||||
const table_base::row_interface & row1 = *els1it;
|
||||
for (const table_base::row_interface& row1 : t1) {
|
||||
|
||||
table_base::iterator els2it = t2.begin();
|
||||
for(; els2it!=els2end; ++els2it) {
|
||||
const table_base::row_interface & row2 = *els2it;
|
||||
for (const table_base::row_interface& row2 : t2) {
|
||||
|
||||
bool match=true;
|
||||
for(unsigned i=0; i<m_col_cnt; i++) {
|
||||
|
|
@ -1491,10 +1484,7 @@ namespace datalog {
|
|||
|
||||
bool should_remove(const table_fact & f) const override {
|
||||
if(!m_all_neg_bound || m_overlap) {
|
||||
table_base::iterator nit = m_negated_table->begin();
|
||||
table_base::iterator nend = m_negated_table->end();
|
||||
for(; nit!=nend; ++nit) {
|
||||
const table_base::row_interface & nrow = *nit;
|
||||
for (const table_base::row_interface& nrow : *m_negated_table) {
|
||||
if(bindings_match(nrow, f)) {
|
||||
return true;
|
||||
}
|
||||
|
|
@ -1656,13 +1646,13 @@ namespace datalog {
|
|||
f.resize(m_result_col_cnt);
|
||||
}
|
||||
|
||||
void mk_project(table_base::iterator& it) {
|
||||
void mk_project(const table_base::row_interface& row) {
|
||||
for (unsigned i = 0, j = 0, r_i = 0; i < m_inp_col_cnt; ++i) {
|
||||
if (r_i < m_removed_col_cnt && m_removed_cols[r_i] == i) {
|
||||
++r_i;
|
||||
}
|
||||
else {
|
||||
m_row[j] = m_former_row[j] = (*it)[i];
|
||||
m_row[j] = m_former_row[j] = row[i];
|
||||
++j;
|
||||
}
|
||||
}
|
||||
|
|
@ -1674,9 +1664,8 @@ namespace datalog {
|
|||
SASSERT(plugin.can_handle_signature(res_sign));
|
||||
table_base * res = plugin.mk_empty(res_sign);
|
||||
|
||||
table_base::iterator it = t.begin(), end = t.end();
|
||||
for (; it != end; ++it) {
|
||||
mk_project(it);
|
||||
for (const table_base::row_interface& row : t) {
|
||||
mk_project(row);
|
||||
if (!res->suggest_fact(m_former_row)) {
|
||||
(*m_reducer)(m_former_row.data()+m_res_first_functional, m_row.data()+m_res_first_functional);
|
||||
res->ensure_fact(m_former_row);
|
||||
|
|
|
|||
|
|
@ -386,9 +386,7 @@ namespace datalog {
|
|||
rule_set::pred_set_vector const & pred_sets = all_rules.get_strats();
|
||||
bool non_empty = false;
|
||||
for (unsigned i = 1; i < pred_sets.size(); ++i) {
|
||||
func_decl_set::iterator it = pred_sets[i]->begin(), end = pred_sets[i]->end();
|
||||
for (; it != end; ++it) {
|
||||
func_decl* pred = *it;
|
||||
for (func_decl* pred : *pred_sets[i]) {
|
||||
relation_base & rel = get_relation(pred);
|
||||
if (!rel.fast_empty()) {
|
||||
non_empty = true;
|
||||
|
|
@ -405,9 +403,7 @@ namespace datalog {
|
|||
bool change = true;
|
||||
while (change) {
|
||||
change = false;
|
||||
func_decl_set::iterator it = pred_sets[i]->begin(), end = pred_sets[i]->end();
|
||||
for (; it != end; ++it) {
|
||||
func_decl* pred = *it;
|
||||
for (func_decl* pred : *pred_sets[i]) {
|
||||
if (depends_on_negation.contains(pred)) {
|
||||
continue;
|
||||
}
|
||||
|
|
@ -434,9 +430,7 @@ namespace datalog {
|
|||
}
|
||||
}
|
||||
}
|
||||
func_decl_set::iterator it = depends_on_negation.begin(), end = depends_on_negation.end();
|
||||
for (; it != end; ++it) {
|
||||
func_decl* pred = *it;
|
||||
for (func_decl* pred : depends_on_negation) {
|
||||
relation_base & rel = get_relation(pred);
|
||||
|
||||
if (!rel.empty()) {
|
||||
|
|
|
|||
|
|
@ -194,9 +194,8 @@ namespace datalog {
|
|||
m_disable_fast_pass(false) {
|
||||
}
|
||||
udoc_plugin::~udoc_plugin() {
|
||||
u_map<doc_manager*>::iterator it = m_dms.begin(), end = m_dms.end();
|
||||
for (; it != end; ++it) {
|
||||
dealloc(it->m_value);
|
||||
for (auto const& kv : m_dms) {
|
||||
dealloc(kv.m_value);
|
||||
}
|
||||
}
|
||||
udoc_relation& udoc_plugin::get(relation_base& r) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue