Commit e0bbc265 authored by Alexandre Duret-Lutz's avatar Alexandre Duret-Lutz
Browse files

c++11: more range-based for

* src/ltlvisit/simplify.cc, src/tgbaalgos/replayrun.cc: Here.
parent b4c125c2
// -*- coding: utf-8 -*- // -*- coding: utf-8 -*-
// Copyright (C) 2011, 2012, 2013 Laboratoire de Recherche et // Copyright (C) 2011, 2012, 2013, 2014 Laboratoire de Recherche et
// Developpement de l'Epita (LRDE). // Developpement de l'Epita (LRDE).
// //
// This file is part of Spot, a model checking library. // This file is part of Spot, a model checking library.
...@@ -994,13 +994,12 @@ namespace spot ...@@ -994,13 +994,12 @@ namespace spot
: split_(split), c_(cache) : split_(split), c_(cache)
{ {
init(); init();
multop::vec::const_iterator end = v->end(); for (auto f: *v)
for (multop::vec::const_iterator i = v->begin(); i < end; ++i)
{ {
if (*i) // skip null pointers left by previous simplifications if (f) // skip null pointers left by previous simplifications
{ {
process(*i); process(f);
(*i)->destroy(); f->destroy();
} }
} }
delete v; delete v;
...@@ -1259,11 +1258,9 @@ namespace spot ...@@ -1259,11 +1258,9 @@ namespace spot
} }
else else
{ {
for (multop::vec::iterator j = for (auto f: *s.res_other)
s.res_other->begin(); if (f)
j != s.res_other->end(); ++j) f->destroy();
if (*j)
(*j)->destroy();
delete s.res_other; delete s.res_other;
delete s.res_G; delete s.res_G;
delete s.res_X; delete s.res_X;
...@@ -1346,11 +1343,10 @@ namespace spot ...@@ -1346,11 +1343,10 @@ namespace spot
if (s.res_Univ) if (s.res_Univ)
{ {
// Strip any F. // Strip any F.
for (multop::vec::iterator i = s.res_Univ->begin(); for (auto& f: *s.res_Univ)
i != s.res_Univ->end(); ++i) if (const unop* u = is_F(f))
if (const unop* u = is_F(*i))
{ {
*i = u->child()->clone(); f = u->child()->clone();
u->destroy(); u->destroy();
} }
const formula* fu = const formula* fu =
...@@ -1475,11 +1471,10 @@ namespace spot ...@@ -1475,11 +1471,10 @@ namespace spot
if (s.res_Event) if (s.res_Event)
{ {
// Strip any G. // Strip any G.
for (multop::vec::iterator i = s.res_Event->begin(); for (auto& f: *s.res_Event)
i != s.res_Event->end(); ++i) if (const unop* u = is_G(f))
if (const unop* u = is_G(*i))
{ {
*i = u->child()->clone(); f = u->child()->clone();
u->destroy(); u->destroy();
} }
const formula* ge = const formula* ge =
...@@ -1530,11 +1525,9 @@ namespace spot ...@@ -1530,11 +1525,9 @@ namespace spot
} }
else else
{ {
for (multop::vec::iterator j = for (auto f: *s.res_other)
s.res_other->begin(); if (f)
j != s.res_other->end(); ++j) f->destroy();
if (*j)
(*j)->destroy();
delete s.res_other; delete s.res_other;
delete s.res_F; delete s.res_F;
delete s.res_X; delete s.res_X;
...@@ -2962,11 +2955,8 @@ namespace spot ...@@ -2962,11 +2955,8 @@ namespace spot
if (gs == wuset.end()) if (gs == wuset.end())
continue; continue;
const std::set<unsigned>& s = gs->second; for (unsigned pos: gs->second)
std::set<unsigned>::const_iterator g;
for (g = s.begin(); g != s.end(); ++g)
{ {
unsigned pos = *g;
const binop* wu = is_binop((*res)[pos]); const binop* wu = is_binop((*res)[pos]);
if (wu) if (wu)
{ {
...@@ -3027,15 +3017,14 @@ namespace spot ...@@ -3027,15 +3017,14 @@ namespace spot
multop::vec* xgv = new multop::vec; multop::vec* xgv = new multop::vec;
xgv->reserve(xgs); xgv->reserve(xgs);
fset_t::iterator i; fset_t::iterator i;
for (i = xgset.begin(); i != xgset.end(); ++i) for (auto f: xgset)
xgv->push_back(*i); xgv->push_back(f);
const formula* gv = const formula* gv =
multop::instance(multop::And, xgv); multop::instance(multop::And, xgv);
xv->push_back(unop::instance(unop::G, gv)); xv->push_back(unop::instance(unop::G, gv));
} }
fset_t::iterator j; for (auto f: xset)
for (j = xset.begin(); j != xset.end(); ++j) xv->push_back(f);
xv->push_back(*j);
const formula* av = const formula* av =
multop::instance(multop::And, xv); multop::instance(multop::And, xv);
res->push_back(unop::instance(unop::X, av)); res->push_back(unop::instance(unop::X, av));
...@@ -3078,13 +3067,11 @@ namespace spot ...@@ -3078,13 +3067,11 @@ namespace spot
{ {
multop::vec* eu = new multop::vec; multop::vec* eu = new multop::vec;
bool seen_g = false; bool seen_g = false;
for (multop::vec::const_iterator for (auto f: *s.res_EventUniv)
i = s.res_EventUniv->begin();
i != s.res_EventUniv->end(); ++i)
{ {
if ((*i)->is_eventual() && (*i)->is_universal()) if (f->is_eventual() && f->is_universal())
{ {
if (const unop* g = is_G(*i)) if (const unop* g = is_G(f))
{ {
seen_g = true; seen_g = true;
eu->push_back(g->child()->clone()); eu->push_back(g->child()->clone());
...@@ -3092,11 +3079,11 @@ namespace spot ...@@ -3092,11 +3079,11 @@ namespace spot
} }
else else
{ {
eu->push_back(*i); eu->push_back(f);
} }
} }
else else
s.res_other->push_back(*i); s.res_other->push_back(f);
} }
if (seen_g) if (seen_g)
{ {
...@@ -3139,7 +3126,7 @@ namespace spot ...@@ -3139,7 +3126,7 @@ namespace spot
// (a U b) & (c U b) = (a & c) U b // (a U b) & (c U b) = (a & c) U b
// (a U b) & (c W b) = (a & c) U b // (a U b) & (c W b) = (a & c) U b
// (a W b) & (c W b) = (a & c) W b // (a W b) & (c W b) = (a & c) W b
for (multop::vec::iterator i = s.res_U_or_W->begin(); for (auto i = s.res_U_or_W->begin();
i != s.res_U_or_W->end(); ++i) i != s.res_U_or_W->end(); ++i)
{ {
const binop* bo = static_cast<const binop*>(*i); const binop* bo = static_cast<const binop*>(*i);
...@@ -3171,7 +3158,7 @@ namespace spot ...@@ -3171,7 +3158,7 @@ namespace spot
// (a R b) & (a R c) = a R (b & c) // (a R b) & (a R c) = a R (b & c)
// (a R b) & (a M c) = a M (b & c) // (a R b) & (a M c) = a M (b & c)
// (a M b) & (a M c) = a M (b & c) // (a M b) & (a M c) = a M (b & c)
for (multop::vec::iterator i = s.res_R_or_M->begin(); for (auto i = s.res_R_or_M->begin();
i != s.res_R_or_M->end(); ++i) i != s.res_R_or_M->end(); ++i)
{ {
const binop* bo = static_cast<const binop*>(*i); const binop* bo = static_cast<const binop*>(*i);
...@@ -3204,7 +3191,7 @@ namespace spot ...@@ -3204,7 +3191,7 @@ namespace spot
// F(a) & (a M b) = a M b // F(a) & (a M b) = a M b
// F(b) & (a W b) = a U b // F(b) & (a W b) = a U b
// F(b) & (a U b) = a U b // F(b) & (a U b) = a U b
for (multop::vec::iterator i = s.res_F->begin(); for (auto i = s.res_F->begin();
i != s.res_F->end(); ++i) i != s.res_F->end(); ++i)
{ {
bool superfluous = false; bool superfluous = false;
...@@ -3278,12 +3265,11 @@ namespace spot ...@@ -3278,12 +3265,11 @@ namespace spot
if (!s.res_X->empty() && !opt_.favor_event_univ) if (!s.res_X->empty() && !opt_.favor_event_univ)
{ {
multop::vec* event = new multop::vec; multop::vec* event = new multop::vec;
for (multop::vec::iterator i = s.res_G->begin(); for (auto& f: *s.res_G)
i != s.res_G->end(); ++i) if (f->is_eventual())
if ((*i)->is_eventual())
{ {
event->push_back(*i); event->push_back(f);
*i = 0; // Remove it from res_G. f = 0; // Remove it from res_G.
} }
s.res_X->push_back(unop_multop(unop::G, s.res_X->push_back(unop_multop(unop::G,
multop::And, event)); multop::And, event));
...@@ -3317,13 +3303,12 @@ namespace spot ...@@ -3317,13 +3303,12 @@ namespace spot
multop::instance(multop::And, s.res_Bool); multop::instance(multop::And, s.res_Bool);
multop::vec* ares = new multop::vec; multop::vec* ares = new multop::vec;
for (multop::vec::iterator i = s.res_other->begin(); for (auto& f: *s.res_other)
i != s.res_other->end(); ++i) switch (f->kind())
switch ((*i)->kind())
{ {
case formula::BUnOp: case formula::BUnOp:
{ {
const bunop* r = down_cast<const bunop*>(*i); const bunop* r = down_cast<const bunop*>(f);
// b && r[*i..j] = b & r if i<=1<=j // b && r[*i..j] = b & r if i<=1<=j
// = 0 otherwise // = 0 otherwise
switch (r->op()) switch (r->op())
...@@ -3333,14 +3318,14 @@ namespace spot ...@@ -3333,14 +3318,14 @@ namespace spot
goto returnfalse; goto returnfalse;
ares->push_back(r->child()->clone()); ares->push_back(r->child()->clone());
r->destroy(); r->destroy();
*i = 0; f = 0;
break; break;
} }
break; break;
} }
case formula::MultOp: case formula::MultOp:
{ {
const multop* r = down_cast<const multop*>(*i); const multop* r = down_cast<const multop*>(f);
unsigned rs = r->size(); unsigned rs = r->size();
switch (r->op()) switch (r->op())
{ {
...@@ -3349,7 +3334,7 @@ namespace spot ...@@ -3349,7 +3334,7 @@ namespace spot
for (unsigned j = 0; j < rs; ++j) for (unsigned j = 0; j < rs; ++j)
ares->push_back(r->nth(j)->clone()); ares->push_back(r->nth(j)->clone());
r->destroy(); r->destroy();
*i = 0; f = 0;
break; break;
case multop::Concat: case multop::Concat:
// b && {r1;...;rn} = // b && {r1;...;rn} =
...@@ -3390,7 +3375,7 @@ namespace spot ...@@ -3390,7 +3375,7 @@ namespace spot
goto returnfalse; goto returnfalse;
} }
r->destroy(); r->destroy();
*i = 0; f = 0;
break; break;
} }
default: default:
...@@ -3400,8 +3385,8 @@ namespace spot ...@@ -3400,8 +3385,8 @@ namespace spot
} }
default: default:
common: common:
ares->push_back(*i); ares->push_back(f);
*i = 0; f = 0;
break; break;
} }
delete s.res_other; delete s.res_other;
...@@ -3414,14 +3399,12 @@ namespace spot ...@@ -3414,14 +3399,12 @@ namespace spot
return; return;
returnfalse: returnfalse:
b->destroy(); b->destroy();
for (multop::vec::iterator i = s.res_other->begin(); for (auto f: *s.res_other)
i != s.res_other->end(); ++i) if (f)
if (*i) f->destroy();
(*i)->destroy();
delete s.res_other; delete s.res_other;
for (multop::vec::iterator i = ares->begin(); for (auto f: *ares)
i != ares->end(); ++i) f->destroy();
(*i)->destroy();
delete ares; delete ares;
result_ = constant::false_instance(); result_ = constant::false_instance();
return; return;
...@@ -3441,14 +3424,13 @@ namespace spot ...@@ -3441,14 +3424,13 @@ namespace spot
multop::vec* tail1 = new multop::vec; multop::vec* tail1 = new multop::vec;
multop::vec* head2 = new multop::vec; multop::vec* head2 = new multop::vec;
multop::vec* tail2 = new multop::vec; multop::vec* tail2 = new multop::vec;
for (multop::vec::iterator i = s.res_other->begin(); for (auto& i: *s.res_other)
i != s.res_other->end(); ++i)
{ {
if (!*i) if (!i)
continue; continue;
if ((*i)->kind() != formula::MultOp) if (i->kind() != formula::MultOp)
continue; continue;
const multop* f = down_cast<const multop*>(*i); const multop* f = down_cast<const multop*>(i);
const formula* h = f->nth(0); const formula* h = f->nth(0);
if (!h->is_boolean()) if (!h->is_boolean())
continue; continue;
...@@ -3461,8 +3443,8 @@ namespace spot ...@@ -3461,8 +3443,8 @@ namespace spot
for (unsigned j = 1; j < s; ++j) for (unsigned j = 1; j < s; ++j)
tail->push_back(f->nth(j)->clone()); tail->push_back(f->nth(j)->clone());
tail1->push_back(multop::instance(op, tail)); tail1->push_back(multop::instance(op, tail));
(*i)->destroy(); i->destroy();
*i = 0; i = 0;
} }
else if (op == multop::Fusion) else if (op == multop::Fusion)
{ {
...@@ -3472,8 +3454,8 @@ namespace spot ...@@ -3472,8 +3454,8 @@ namespace spot
for (unsigned j = 1; j < s; ++j) for (unsigned j = 1; j < s; ++j)
tail->push_back(f->nth(j)->clone()); tail->push_back(f->nth(j)->clone());
tail2->push_back(multop::instance(op, tail)); tail2->push_back(multop::instance(op, tail));
(*i)->destroy(); i->destroy();
*i = 0; i = 0;
} }
else else
{ {
...@@ -3519,14 +3501,13 @@ namespace spot ...@@ -3519,14 +3501,13 @@ namespace spot
multop::vec* tail3 = new multop::vec; multop::vec* tail3 = new multop::vec;
multop::vec* head4 = new multop::vec; multop::vec* head4 = new multop::vec;
multop::vec* tail4 = new multop::vec; multop::vec* tail4 = new multop::vec;
for (multop::vec::iterator i = s.res_other->begin(); for (auto& i: *s.res_other)
i != s.res_other->end(); ++i)
{ {
if (!*i) if (!i)
continue; continue;
if ((*i)->kind() != formula::MultOp) if (i->kind() != formula::MultOp)
continue; continue;
const multop* f = down_cast<const multop*>(*i); const multop* f = down_cast<const multop*>(i);
unsigned s = f->size() - 1; unsigned s = f->size() - 1;
const formula* t = f->nth(s); const formula* t = f->nth(s);
if (!t->is_boolean()) if (!t->is_boolean())
...@@ -3539,8 +3520,8 @@ namespace spot ...@@ -3539,8 +3520,8 @@ namespace spot
for (unsigned j = 0; j < s; ++j) for (unsigned j = 0; j < s; ++j)
head->push_back(f->nth(j)->clone()); head->push_back(f->nth(j)->clone());
head3->push_back(multop::instance(op, head)); head3->push_back(multop::instance(op, head));
(*i)->destroy(); i->destroy();
*i = 0; i = 0;
} }
else if (op == multop::Fusion) else if (op == multop::Fusion)
{ {
...@@ -3549,8 +3530,8 @@ namespace spot ...@@ -3549,8 +3530,8 @@ namespace spot
for (unsigned j = 0; j < s; ++j) for (unsigned j = 0; j < s; ++j)
head->push_back(f->nth(j)->clone()); head->push_back(f->nth(j)->clone());
head4->push_back(multop::instance(op, head)); head4->push_back(multop::instance(op, head));
(*i)->destroy(); i->destroy();
*i = 0; i = 0;
} }
else else
{ {
...@@ -3718,11 +3699,8 @@ namespace spot ...@@ -3718,11 +3699,8 @@ namespace spot
fmap_t::const_iterator gs = rmset.find(x); fmap_t::const_iterator gs = rmset.find(x);
if (gs == rmset.end()) if (gs == rmset.end())
continue; continue;
const std::set<unsigned>& s = gs->second; for (unsigned pos: gs->second)
std::set<unsigned>::const_iterator g;
for (g = s.begin(); g != s.end(); ++g)
{ {
unsigned pos = *g;
const binop* rm = is_binop((*res)[pos]); const binop* rm = is_binop((*res)[pos]);
if (rm) if (rm)
{ {
...@@ -3791,17 +3769,15 @@ namespace spot ...@@ -3791,17 +3769,15 @@ namespace spot
// Group all XF(a)|XF(b|c|...)|... as XF(a|b|c|...) // Group all XF(a)|XF(b|c|...)|... as XF(a|b|c|...)
multop::vec* xfv = new multop::vec; multop::vec* xfv = new multop::vec;
xfv->reserve(xfs); xfv->reserve(xfs);
fset_t::iterator i; for (auto f: xfset)
for (i = xfset.begin(); i != xfset.end(); ++i) xfv->push_back(f);
xfv->push_back(*i);
const formula* fv = const formula* fv =
multop::instance(multop::Or, xfv); multop::instance(multop::Or, xfv);
xv->push_back(unop::instance(unop::F, fv)); xv->push_back(unop::instance(unop::F, fv));
} }
// Also gather the remaining Xa | X(b|c) as X(b|c). // Also gather the remaining Xa | X(b|c) as X(b|c).
fset_t::iterator j; for (auto f: xset)
for (j = xset.begin(); j != xset.end(); ++j) xv->push_back(f);
xv->push_back(*j);
const formula* ov = multop::instance(multop::Or, xv); const formula* ov = multop::instance(multop::Or, xv);
res->push_back(unop::instance(unop::X, ov)); res->push_back(unop::instance(unop::X, ov));
} }
...@@ -3874,12 +3850,10 @@ namespace spot ...@@ -3874,12 +3850,10 @@ namespace spot
// If some of the EventUniv formulae start // If some of the EventUniv formulae start
// with an F, Gather them all under the // with an F, Gather them all under the
// same F. Striping any leading F. // same F. Striping any leading F.
for (multop::vec::iterator i = for (auto& f: *s.res_EventUniv)
s.res_EventUniv->begin(); if (const unop* u = is_F(f))
i != s.res_EventUniv->end(); ++i)
if (const unop* u = is_F(*i))
{ {
*i = u->child()->clone(); f = u->child()->clone();
u->destroy(); u->destroy();
seen_f = true; seen_f = true;
} }
...@@ -3930,7 +3904,7 @@ namespace spot ...@@ -3930,7 +3904,7 @@ namespace spot
// (a U b) | (a U c) = a U (b | c) // (a U b) | (a U c) = a U (b | c)
// (a W b) | (a U c) = a W (b | c) // (a W b) | (a U c) = a W (b | c)
// (a W b) | (a W c) = a W (b | c) // (a W b) | (a W c) = a W (b | c)
for (multop::vec::iterator i = s.res_U_or_W->begin(); for (auto i = s.res_U_or_W->begin();
i != s.res_U_or_W->end(); ++i) i != s.res_U_or_W->end(); ++i)
{ {
const binop* bo = static_cast<const binop*>(*i); const binop* bo = static_cast<const binop*>(*i);
...@@ -3962,7 +3936,7 @@ namespace spot ...@@ -3962,7 +3936,7 @@ namespace spot
// (a R b) | (c R b) = (a | c) R b // (a R b) | (c R b) = (a | c) R b
// (a R b) | (c M b) = (a | c) R b // (a R b) | (c M b) = (a | c) R b
// (a M b) | (c M b) = (a | c) M b // (a M b) | (c M b) = (a | c) M b
for (multop::vec::iterator i = s.res_R_or_M->begin(); for (auto i = s.res_R_or_M->begin();
i != s.res_R_or_M->end(); ++i) i != s.res_R_or_M->end(); ++i)
{ {
const binop* bo = static_cast<const binop*>(*i); const binop* bo = static_cast<const binop*>(*i);
...@@ -3995,11 +3969,10 @@ namespace spot ...@@ -3995,11 +3969,10 @@ namespace spot
// G(a) | (a W b) = a W b // G(a) | (a W b) = a W b
// G(b) | (a R b) = a R b. // G(b) | (a R b) = a R b.
// G(b) | (a M b) = a R b. // G(b) | (a M b) = a R b.
for (multop::vec::iterator i = s.res_G->begin(); for (auto& f: *s.res_G)
i != s.res_G->end(); ++i)
{ {
bool superfluous = false; bool superfluous = false;
const unop* uo = static_cast<const unop*>(*i); const unop* uo = static_cast<const unop*>(f);
const formula* c = uo->child(); const formula* c = uo->child();
fmap_t::iterator j = uwmap.find(c); fmap_t::iterator j = uwmap.find(c);
...@@ -4036,8 +4009,8 @@ namespace spot ...@@ -4036,8 +4009,8 @@ namespace spot
} }
if (superfluous) if (superfluous)
{ {
(*i)->destroy();