parity: fix error handling

* spot/twaalgos/parity.cc: Do not throw a pointer to an exception,
throw the exception directly.  Factor all the throwing code in a
function.
* tests/python/parity.py: Add test case.
This commit is contained in:
Alexandre Duret-Lutz 2018-01-02 17:43:57 +01:00
parent 288ea95658
commit 0aca26e3f9
2 changed files with 19 additions and 7 deletions

View file

@ -1,5 +1,5 @@
// -*- coding: utf-8 -*- // -*- coding: utf-8 -*-
// Copyright (C) 2016 Laboratoire de Recherche et Développement // Copyright (C) 2016, 2018 Laboratoire de Recherche et Développement
// de l'Epita (LRDE). // de l'Epita (LRDE).
// //
// This file is part of Spot, a model checking library. // This file is part of Spot, a model checking library.
@ -62,6 +62,14 @@ namespace spot
e.acc.set(0); e.acc.set(0);
} }
} }
[[noreturn]] static void
input_is_not_parity(const char* fun)
{
throw std::runtime_error(std::string(fun) +
"(): input should have "
"parity acceptance");
}
} }
twa_graph_ptr twa_graph_ptr
@ -78,8 +86,7 @@ namespace spot
bool current_max; bool current_max;
bool current_odd; bool current_odd;
if (!aut->acc().is_parity(current_max, current_odd, true)) if (!aut->acc().is_parity(current_max, current_odd, true))
throw new std::invalid_argument("change_parity: input must have a parity " input_is_not_parity("change_parity");
"acceptance.");
auto old_num_sets = aut->num_sets(); auto old_num_sets = aut->num_sets();
bool output_max = true; bool output_max = true;
@ -160,8 +167,7 @@ namespace spot
bool current_max; bool current_max;
bool current_odd; bool current_odd;
if (!aut->acc().is_parity(current_max, current_odd, true)) if (!aut->acc().is_parity(current_max, current_odd, true))
throw new std::invalid_argument("cleanup_parity: input " input_is_not_parity("cleanup_parity");
"must have a parity acceptance.");
auto num_sets = aut->num_sets(); auto num_sets = aut->num_sets();
if (num_sets == 0) if (num_sets == 0)
return aut; return aut;
@ -247,8 +253,7 @@ namespace spot
bool current_max; bool current_max;
bool current_odd; bool current_odd;
if (!aut->acc().is_parity(current_max, current_odd, true)) if (!aut->acc().is_parity(current_max, current_odd, true))
throw new std::invalid_argument("colorize_parity: input " input_is_not_parity("colorize_parity");
"must have a parity acceptance.");
bool has_empty = false; bool has_empty = false;
for (const auto& e: aut->edges()) for (const auto& e: aut->edges())

View file

@ -29,3 +29,10 @@ for f in ('FGa', 'GFa & GFb & FGc', 'XXX(a U b)'):
a3 = spot.translate(f, 'det').postprocess('parity') a3 = spot.translate(f, 'det').postprocess('parity')
assert a3.acc().is_parity() assert a3.acc().is_parity()
a = spot.translate('GFa & GFb')
try:
spot.change_parity_here(a, spot.parity_kind_same, spot.parity_style_even)
except RuntimeError as e:
assert 'input should have parity acceptance' in str(e)
else:
exit(2)