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

* src/sanity/style.test: Warn about places where size() is used

instead of empty().
* src/misc/bddalloc.cc (bdd_allocator::extend): Use empty() rather
than size() when checking emptiness of lists.
* src/tgbaalgos/reductgba_sim_del.cc, src/tgbaalgos/minimalce.cc,
src/ltlvisit/basicreduce.cc, src/ltlvisit/reduce.cc,
src/tgbaalgos/gtec/ce.cc, src/tgbaalgos/ltl2tgba_fm.cc,
src/misc/minato.cc: Likewise.
* src/ltlast/multop.cc (multop::instance): Call ->size() only once.
parent f0aa5803
2004-09-21 Alexandre Duret-Lutz <adl@src.lip6.fr>
* src/sanity/style.test: Warn about places where size() is used
instead of empty().
* src/misc/bddalloc.cc (bdd_allocator::extend): Use empty() rather
than size() when checking emptiness of lists.
* src/tgbaalgos/reductgba_sim_del.cc, src/tgbaalgos/minimalce.cc,
src/ltlvisit/basicreduce.cc, src/ltlvisit/reduce.cc,
src/tgbaalgos/gtec/ce.cc, src/tgbaalgos/ltl2tgba_fm.cc,
src/misc/minato.cc: Likewise.
* src/ltlast/multop.cc (multop::instance): Call ->size() only once.
2004-09-20 Alexandre Duret-Lutz <adl@src.lip6.fr> 2004-09-20 Alexandre Duret-Lutz <adl@src.lip6.fr>
Update to SWIG 1.3.22. Update to SWIG 1.3.22.
......
// Copyright (C) 2003 Laboratoire d'Informatique de Paris 6 (LIP6), // Copyright (C) 2003, 2004 Laboratoire d'Informatique de Paris 6 (LIP6),
// dpartement Systmes Rpartis Coopratifs (SRC), Universit Pierre // dpartement Systmes Rpartis Coopratifs (SRC), Universit Pierre
// et Marie Curie. // et Marie Curie.
// //
...@@ -152,7 +152,8 @@ namespace spot ...@@ -152,7 +152,8 @@ namespace spot
} }
} }
if (v->size() == 0) vec::size_type s = v->size();
if (s == 0)
{ {
delete v; delete v;
switch (op) switch (op)
...@@ -165,7 +166,7 @@ namespace spot ...@@ -165,7 +166,7 @@ namespace spot
/* Unreachable code. */ /* Unreachable code. */
assert(0); assert(0);
} }
if (v->size() == 1) else if (s == 1)
{ {
formula* res = (*v)[0]; formula* res = (*v)[0];
delete v; delete v;
......
...@@ -101,12 +101,12 @@ namespace spot ...@@ -101,12 +101,12 @@ namespace spot
res1->push_back(clone(mo->nth(i))); res1->push_back(clone(mo->nth(i)));
destroy(mo); destroy(mo);
multop::vec* res3 = new multop::vec; multop::vec* res3 = new multop::vec;
if (res1->size()) if (!res1->empty())
res3->push_back(unop::instance(op, res3->push_back(unop::instance(op,
multop::instance(op_child, res1))); multop::instance(op_child, res1)));
else else
delete res1; delete res1;
if (resGF->size()) if (!resGF->empty())
res3->push_back(multop::instance(op_child, resGF)); res3->push_back(multop::instance(op_child, resGF));
else else
delete resGF; delete resGF;
...@@ -518,27 +518,27 @@ namespace spot ...@@ -518,27 +518,27 @@ namespace spot
delete res; delete res;
if (tmpX && tmpX->size()) if (tmpX && !tmpX->empty())
tmpOther->push_back(unop::instance(unop::X, tmpOther->push_back(unop::instance(unop::X,
multop::instance(mo->op(), multop::instance(mo->op(),
tmpX))); tmpX)));
else if (tmpX && !tmpX->size()) else if (tmpX)
delete tmpX; delete tmpX;
if (tmpU && tmpU->size()) if (tmpU && !tmpU->empty())
tmpOther->push_back(multop::instance(mo->op(), tmpU)); tmpOther->push_back(multop::instance(mo->op(), tmpU));
else if (tmpU && !tmpU->size()) else if (tmpU)
delete tmpU; delete tmpU;
if (tmpR && tmpR->size()) if (tmpR && !tmpR->empty())
tmpOther->push_back(multop::instance(mo->op(), tmpR)); tmpOther->push_back(multop::instance(mo->op(), tmpR));
else if (tmpR && !tmpR->size()) else if (tmpR)
delete tmpR; delete tmpR;
if (tmpGF && tmpGF->size()) if (tmpGF && !tmpGF->empty())
{ {
formula* ftmp formula* ftmp
= unop::instance(unop::G, = unop::instance(unop::G,
...@@ -547,11 +547,11 @@ namespace spot ...@@ -547,11 +547,11 @@ namespace spot
tmpGF))); tmpGF)));
tmpOther->push_back(ftmp); tmpOther->push_back(ftmp);
} }
else if (tmpGF && !tmpGF->size()) else if (tmpGF)
delete tmpGF; delete tmpGF;
if (tmpFG && tmpFG->size()) if (tmpFG && !tmpFG->empty())
{ {
formula* ftmp = 0; formula* ftmp = 0;
if (mo->op() == multop::And) if (mo->op() == multop::And)
...@@ -566,7 +566,7 @@ namespace spot ...@@ -566,7 +566,7 @@ namespace spot
multop::instance(mo->op(), tmpFG)); multop::instance(mo->op(), tmpFG));
tmpOther->push_back(ftmp); tmpOther->push_back(ftmp);
} }
else if (tmpFG && !tmpFG->size()) else if (tmpFG)
delete tmpFG; delete tmpFG;
......
...@@ -268,7 +268,7 @@ namespace spot ...@@ -268,7 +268,7 @@ namespace spot
} }
if (res->size()) if (!res->empty())
{ {
result_ = multop::instance(mo->op(), res); result_ = multop::instance(mo->op(), res);
return; return;
......
...@@ -85,7 +85,7 @@ namespace spot ...@@ -85,7 +85,7 @@ namespace spot
{ {
// If we already have some free variable at the end // If we already have some free variable at the end
// of the variable space, allocate just the difference. // of the variable space, allocate just the difference.
if (fl.size() > 0 && fl.back().first + fl.back().second == lvarnum) if (!fl.empty() && fl.back().first + fl.back().second == lvarnum)
{ {
int res = fl.back().first; int res = fl.back().first;
int endvar = fl.back().second; int endvar = fl.back().second;
......
// Copyright (C) 2003 Laboratoire d'Informatique de Paris 6 (LIP6), // Copyright (C) 2003, 2004 Laboratoire d'Informatique de Paris 6 (LIP6),
// dpartement Systmes Rpartis Coopratifs (SRC), Universit Pierre // dpartement Systmes Rpartis Coopratifs (SRC), Universit Pierre
// et Marie Curie. // et Marie Curie.
// //
...@@ -44,7 +44,7 @@ namespace spot ...@@ -44,7 +44,7 @@ namespace spot
bdd bdd
minato_isop::next() minato_isop::next()
{ {
while (todo_.size()) while (!todo_.empty())
{ {
local_vars& l = todo_.top(); local_vars& l = todo_.top();
switch (l.step) switch (l.step)
......
...@@ -108,18 +108,23 @@ for dir in "${INCDIR-..}" "${INCDIR-..}"/../iface; do ...@@ -108,18 +108,23 @@ for dir in "${INCDIR-..}" "${INCDIR-..}"/../iface; do
grep '{.*{' $tmp && grep '{.*{' $tmp &&
diag 'No two { on the same line.' diag 'No two { on the same line.'
grep -e 'delete[ ]*[(][^(]*[)];' $tmp && grep 'delete[ ]*[(][^(]*[)];' $tmp &&
diag 'No useless parentheses after delete.' diag 'No useless parentheses after delete.'
grep -e 'return[ ]*[(][^(]*[)];' $tmp && grep 'return[ ]*[(][^(]*[)];' $tmp &&
diag 'No useless parentheses after return.' diag 'No useless parentheses after return.'
grep 'NULL' $tmp && grep 'NULL' $tmp &&
diag 'Use 0 instead of NULL. NULL is not portable.' diag 'Use 0 instead of NULL. NULL is not portable.'
# std::list::size() can be O(n). Better use empty() whenever
# possible, even for other containers.
grep -E '(->|[.])size\(\) [=!]= 0|![a-zA-Z0-9_]*(->|[.])size\(\)|(if |while |assert)\([a-zA-Z0-9_]*(->|[.])size\(\)\)' $tmp &&
diag 'Prefer empty() to check emptiness.'
case $file in case $file in
*.hh | *.hxx) *.hh | *.hxx)
if grep -e '(cout|cerr|clog)' $tmp >/dev/null; then if grep -E '(cout|cerr|clog)' $tmp >/dev/null; then
: :
else else
grep '#.*include.*<iostream>' $tmp && grep '#.*include.*<iostream>' $tmp &&
......
...@@ -338,9 +338,9 @@ namespace spot ...@@ -338,9 +338,9 @@ namespace spot
todo.pop(); todo.pop();
delete iter; delete iter;
seen.erase(s); seen.erase(s);
if (todo.size()) if (!todo.empty())
{ {
assert(path.size()); assert(!path.empty());
path.pop_back(); path.pop_back();
} }
continue; continue;
...@@ -377,7 +377,7 @@ namespace spot ...@@ -377,7 +377,7 @@ namespace spot
// If we already have a best path, let see if the current // If we already have a best path, let see if the current
// one is better. // one is better.
if (best_path.size()) if (!best_path.empty())
{ {
// When comparing the merits of two paths, only the // When comparing the merits of two paths, only the
// acceptance conditions we are trying the traverse // acceptance conditions we are trying the traverse
...@@ -491,9 +491,9 @@ namespace spot ...@@ -491,9 +491,9 @@ namespace spot
todo.pop(); todo.pop();
delete iter; delete iter;
seen.erase(s); seen.erase(s);
if (todo.size()) if (!todo.empty())
{ {
assert(path.size()); assert(!path.empty());
path.pop_back(); path.pop_back();
} }
continue; continue;
...@@ -530,7 +530,7 @@ namespace spot ...@@ -530,7 +530,7 @@ namespace spot
// If we already have a best path, let see if the current // If we already have a best path, let see if the current
// one is better. // one is better.
if (best_path.size()) if (!best_path.empty())
{ {
// When comparing the merits of two paths, only the // When comparing the merits of two paths, only the
// acceptance conditions we are trying the traverse // acceptance conditions we are trying the traverse
......
...@@ -552,7 +552,7 @@ namespace spot ...@@ -552,7 +552,7 @@ namespace spot
~formula_canonizer() ~formula_canonizer()
{ {
while (f2b_.size()) while (!f2b_.empty())
{ {
formula_to_bdd_map::iterator i = f2b_.begin(); formula_to_bdd_map::iterator i = f2b_.begin();
const formula* f = i->first; const formula* f = i->first;
......
...@@ -174,7 +174,7 @@ namespace spot ...@@ -174,7 +174,7 @@ namespace spot
++id; ++id;
} }
assert(cycle.size() != 0); assert(!cycle.empty());
is = cycle.end(); is = cycle.end();
is--; is--;
id = cycle.begin(); id = cycle.begin();
...@@ -593,7 +593,7 @@ namespace spot ...@@ -593,7 +593,7 @@ namespace spot
recurse_find(s, os); recurse_find(s, os);
//std::cout << "nb_found : " << nb_found << std::endl; //std::cout << "nb_found : " << nb_found << std::endl;
if (min_ce->size() == 0) if (min_ce->empty())
{ {
delete min_ce; delete min_ce;
min_ce = 0; min_ce = 0;
...@@ -629,7 +629,7 @@ namespace spot ...@@ -629,7 +629,7 @@ namespace spot
hash_type::iterator i; hash_type::iterator i;
tgba_succ_iterator* iter = 0; tgba_succ_iterator* iter = 0;
if (!h_lenght.size()) if (h_lenght.empty())
{ {
// it's a new search // it's a new search
//std::cout << "it's a new search" << std::endl; //std::cout << "it's a new search" << std::endl;
...@@ -670,7 +670,7 @@ namespace spot ...@@ -670,7 +670,7 @@ namespace spot
const state* succ = iter->current_state(); const state* succ = iter->current_state();
if ((min_ce->size() == 0) || if (min_ce->empty() ||
((int)stack.size() + 1 <= min_ce->size())) ((int)stack.size() + 1 <= min_ce->size()))
{ {
int depth = in_stack(succ, os); int depth = in_stack(succ, os);
...@@ -750,7 +750,7 @@ namespace spot ...@@ -750,7 +750,7 @@ namespace spot
} }
else if ((h_lenght[succ] > (int)stack.size() + 1) && else if ((h_lenght[succ] > (int)stack.size() + 1) &&
(min_ce->size() != 0)) !min_ce->empty())
{ {
s = succ; s = succ;
iter->next(); iter->next();
...@@ -832,7 +832,7 @@ namespace spot ...@@ -832,7 +832,7 @@ namespace spot
const state* succ = iter->current_state(); const state* succ = iter->current_state();
if ((min_ce->size() == 0) || if (min_ce->empty() ||
((int)stack.size() + 1 <= min_ce->size())) ((int)stack.size() + 1 <= min_ce->size()))
{ {
int depth = in_stack(succ, os); int depth = in_stack(succ, os);
...@@ -872,7 +872,7 @@ namespace spot ...@@ -872,7 +872,7 @@ namespace spot
recurse_find(succ, os, mode); recurse_find(succ, os, mode);
} }
else if ((h_lenght[succ] > (int)stack.size() + 1) && else if ((h_lenght[succ] > (int)stack.size() + 1) &&
(min_ce->size() != 0)) !min_ce->empty())
{ {
//std::cout << "recurse 3 : " << stack.size() << " "; //std::cout << "recurse 3 : " << stack.size() << " ";
mode = careful; mode = careful;
...@@ -946,7 +946,7 @@ namespace spot ...@@ -946,7 +946,7 @@ namespace spot
//std::cout << os.str() << "save counter" << std::endl; //std::cout << os.str() << "save counter" << std::endl;
nb_found++; nb_found++;
if (!min_ce->size()) if (min_ce->empty())
delete min_ce; delete min_ce;
min_ce = new ce::counter_example(a); min_ce = new ce::counter_example(a);
......
...@@ -72,7 +72,7 @@ namespace spot ...@@ -72,7 +72,7 @@ namespace spot
// We take the max of the progress measure of the successor node // We take the max of the progress measure of the successor node
// because we are on a spoiler. // because we are on a spoiler.
if (lnode_succ->size() == 0) if (lnode_succ->empty())
progress_measure_ = nb_spoiler_loose_ + 1; progress_measure_ = nb_spoiler_loose_ + 1;
if (progress_measure_ >= nb_spoiler_loose_ + 1) if (progress_measure_ >= nb_spoiler_loose_ + 1)
...@@ -229,7 +229,7 @@ namespace spot ...@@ -229,7 +229,7 @@ namespace spot
// We take the min of the progress measure of the successor node // We take the min of the progress measure of the successor node
// because we are on a duplicator. // because we are on a duplicator.
if (lnode_succ->size() == 0) if (lnode_succ->empty())
progress_measure_ = nb_spoiler_loose_ + 1; progress_measure_ = nb_spoiler_loose_ + 1;
if (progress_measure_ >= nb_spoiler_loose_ + 1) if (progress_measure_ >= nb_spoiler_loose_ + 1)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment