diff --git a/ChangeLog b/ChangeLog index 7b8ecd1e4..32de0c1b1 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,11 @@ 2004-10-29 Alexandre Duret-Lutz + * src/sanity/style.test: Diagnose superfluous constructs such + as `if (x) delete x;'. + * iface/gspn/gspn.cc, iface/gspn/ssp.cc, src/ltlvisit/basicreduce.cc, + src/tgba/tgba.cc, src/tgba/tgbaproduct.cc, src/tgbaalgos/magic.cc, + src/tgbatest/ltl2tgba.cc: Remove such constructs. + * src/tgbatest/ltl2tgba.cc: Replace -e, -E, -m, -M, and -n by -eALGO and -EALGO to ease the addition of new algorithms. * src/tgbatest/emptchk.test, src/tgbatest/emptchke.test: Adjust. diff --git a/iface/gspn/gspn.cc b/iface/gspn/gspn.cc index 931833513..0a1984803 100644 --- a/iface/gspn/gspn.cc +++ b/iface/gspn/gspn.cc @@ -175,10 +175,8 @@ namespace spot tgba_gspn_private_::~tgba_gspn_private_() { dict->unregister_all_my_variables(this); - if (last_state_conds_input) - delete last_state_conds_input; - if (all_indexes) - delete[] all_indexes; + delete last_state_conds_input; + delete[] all_indexes; } bdd index_to_bdd(AtomicProp index) const @@ -213,8 +211,7 @@ namespace spot } satisfy_free(cube); - if (last_state_conds_input) - delete last_state_conds_input; + delete last_state_conds_input; last_state_conds_input = s->clone(); } return last_state_conds_output; diff --git a/iface/gspn/ssp.cc b/iface/gspn/ssp.cc index 8962cbd4c..1dad0144d 100644 --- a/iface/gspn/ssp.cc +++ b/iface/gspn/ssp.cc @@ -162,8 +162,7 @@ namespace spot tgba_gspn_ssp_private_::~tgba_gspn_ssp_private_() { dict->unregister_all_my_variables(this); - if (all_props) - delete[] all_props; + delete[] all_props; } }; diff --git a/src/ltlvisit/basicreduce.cc b/src/ltlvisit/basicreduce.cc index a49e161f1..8f0883d00 100644 --- a/src/ltlvisit/basicreduce.cc +++ b/src/ltlvisit/basicreduce.cc @@ -509,11 +509,6 @@ namespace spot destroy(*i); } - /* - delete tmpFG; - tmpFG = 0; - */ - break; } @@ -525,22 +520,21 @@ namespace spot tmpOther->push_back(unop::instance(unop::X, multop::instance(mo->op(), tmpX))); - else if (tmpX) + else delete tmpX; if (tmpU && !tmpU->empty()) tmpOther->push_back(multop::instance(mo->op(), tmpU)); - else if (tmpU) + else delete tmpU; if (tmpR && !tmpR->empty()) tmpOther->push_back(multop::instance(mo->op(), tmpR)); - else if (tmpR) + else delete tmpR; - if (tmpGF && !tmpGF->empty()) { formula* ftmp @@ -550,7 +544,7 @@ namespace spot tmpGF))); tmpOther->push_back(ftmp); } - else if (tmpGF) + else delete tmpGF; @@ -569,14 +563,13 @@ namespace spot multop::instance(mo->op(), tmpFG)); tmpOther->push_back(ftmp); } - else if (tmpFG) + else delete tmpFG; result_ = multop::instance(op, tmpOther); return; - } protected: diff --git a/src/sanity/style.test b/src/sanity/style.test index c46c47838..c1382db2e 100755 --- a/src/sanity/style.test +++ b/src/sanity/style.test @@ -37,7 +37,7 @@ for dir in "${INCDIR-..}" "${INCDIR-..}"/../iface; do sed 's,[ ]*//.*,,' < $file > $tmp grep '[ ]$' $tmp && - diag 'Trailing space or tab.' + diag 'Trailing whitespace.' grep '[ ]if(' $tmp && diag 'Missing space after "if"' @@ -137,6 +137,14 @@ for dir in "${INCDIR-..}" "${INCDIR-..}"/../iface; do grep '[^a-zA-Z0-9_](\*[a-zA-Z0-9_]*)\.' $tmp && diag 'Use "x->y", not "(*x).y"' + res=`perl -ne '$/ = undef; + print "$&\n" + while /if \((.*)(\s*==\s*0)?\)\s*delete(\[\])?\s+\1;(?!\s+else)/g' $tmp` + if test -n "$res"; then + echo "$res" + diag 'No "if (x)" required before "delete x;".' + fi + case $file in *.hh | *.hxx) if egrep '(cout|cerr|clog)' $tmp >/dev/null; then diff --git a/src/tgba/tgba.cc b/src/tgba/tgba.cc index 40d469ba1..237b0ef9d 100644 --- a/src/tgba/tgba.cc +++ b/src/tgba/tgba.cc @@ -31,10 +31,8 @@ namespace spot tgba::~tgba() { - if (last_support_conditions_input_) - delete last_support_conditions_input_; - if (last_support_variables_input_) - delete last_support_variables_input_; + delete last_support_conditions_input_; + delete last_support_variables_input_; } bdd @@ -43,10 +41,8 @@ namespace spot if (!last_support_conditions_input_ || last_support_conditions_input_->compare(state) != 0) { - last_support_conditions_output_ = - compute_support_conditions(state); - if (last_support_conditions_input_) - delete last_support_conditions_input_; + last_support_conditions_output_ = compute_support_conditions(state); + delete last_support_conditions_input_; last_support_conditions_input_ = state->clone(); } return last_support_conditions_output_; @@ -58,10 +54,8 @@ namespace spot if (!last_support_variables_input_ || last_support_variables_input_->compare(state) != 0) { - last_support_variables_output_ = - compute_support_variables(state); - if (last_support_variables_input_) - delete last_support_variables_input_; + last_support_variables_output_ = compute_support_variables(state); + delete last_support_variables_input_; last_support_variables_input_ = state->clone(); } return last_support_variables_output_; diff --git a/src/tgba/tgbaproduct.cc b/src/tgba/tgbaproduct.cc index c5c2b82db..87f91d752 100644 --- a/src/tgba/tgbaproduct.cc +++ b/src/tgba/tgbaproduct.cc @@ -81,8 +81,7 @@ namespace spot tgba_succ_iterator_product::~tgba_succ_iterator_product() { delete left_; - if (right_) - delete right_; + delete right_; } void diff --git a/src/tgbaalgos/magic.cc b/src/tgbaalgos/magic.cc index 0af3b0729..3a6048f02 100644 --- a/src/tgbaalgos/magic.cc +++ b/src/tgbaalgos/magic.cc @@ -68,8 +68,7 @@ namespace spot ++s; delete ptr; } - if (x) - delete x; + delete x; // Release all iterators on the stack. while (!stack.empty()) { @@ -165,8 +164,7 @@ namespace spot { if (!has(s, true)) { - if (x) - delete x; + delete x; x = s->clone(); push(s, true); continue; diff --git a/src/tgbatest/ltl2tgba.cc b/src/tgbatest/ltl2tgba.cc index e4cc0f466..e75f2d5af 100644 --- a/src/tgbatest/ltl2tgba.cc +++ b/src/tgbatest/ltl2tgba.cc @@ -116,8 +116,7 @@ syntax(char* prog) << " couvreur99" << std::endl << " couvreur99_shy" << std::endl << " magic_search" << std::endl - << " magic_search_repeated" << std::endl - ; + << " magic_search_repeated" << std::endl; exit(2); } @@ -319,31 +318,33 @@ main(int argc, char** argv) } } - if (echeck_algo == "couvreur99") + if (echeck_algo != "") { - echeck = Couvreur; + if (echeck_algo == "couvreur99") + { + echeck = Couvreur; + } + else if (echeck_algo == "couvreur99_shy") + { + echeck = Couvreur2; + } + else if (echeck_algo == "magic_search") + { + echeck = MagicSearch; + degeneralize_opt = true; + } + else if (echeck_algo == "magic_search_repeated") + { + echeck = MagicSearch; + degeneralize_opt = true; + magic_many = true; + } + else + { + std::cerr << "unknown emptiness-check: " << echeck_algo << std::endl; + syntax(argv[0]); + } } - else if (echeck_algo == "couvreur99_shy") - { - echeck = Couvreur2; - } - else if (echeck_algo == "magic_search") - { - echeck = MagicSearch; - degeneralize_opt = true; - } - else if (echeck_algo == "magic_search_repeated") - { - echeck = MagicSearch; - degeneralize_opt = true; - magic_many = true; - } - else - { - std::cerr << "unknown emptiness-check: " << echeck_algo << std::endl; - syntax(argv[0]); - } - std::string input; @@ -591,13 +592,9 @@ main(int argc, char** argv) if (f) spot::ltl::destroy(f); - if (expl) - delete expl; - if (degeneralize_opt) - delete degeneralized; - if (aut_red) - delete aut_red; - + delete expl; + delete degeneralized; + delete aut_red; delete to_free; } else