acc: refactor strip() routines

* src/tgba/acc.cc, src/tgba/acc.hh: Move the strip() routine from
acc_cond into acc_cond::mark_t, and the strip() routine from
cleanacc.cc into acc_cond::acc_code.  Introduce helper functions
to create inf()/fin()/t()/f() at the acc_code level.
* src/tgbaalgos/cleanacc.cc: Simplify, using the strip() function
from acc_code.
* src/tgbaalgos/mask.cc (mask_acc_sets): Use the strip() function
from acc_code so that it work on non-Buchi acceptance.
* src/tgbatest/maskacc.test: Add a test for the latter change.
* src/tgbaalgos/sccfilter.cc, src/tgbatest/acc.cc: Adjust the
use mark_t::strip().
This commit is contained in:
Alexandre Duret-Lutz 2015-02-25 22:36:13 +01:00
parent 717c857794
commit 5b2c7b55ed
7 changed files with 267 additions and 165 deletions

View file

@ -21,61 +21,6 @@
namespace spot
{
namespace
{
acc_cond::acc_code strip(const acc_cond& acc,
const acc_cond::acc_word* pos,
acc_cond::mark_t useless)
{
auto start = pos - pos->size;
switch (pos->op)
{
case acc_cond::acc_op::And:
{
--pos;
acc_cond::acc_code res;
do
{
auto tmp = strip(acc, pos, useless);
tmp.append_and(std::move(res));
std::swap(tmp, res);
pos -= pos->size + 1;
}
while (pos > start);
return res;
}
case acc_cond::acc_op::Or:
{
--pos;
acc_cond::acc_code res = acc.fin(0); // f
do
{
auto tmp = strip(acc, pos, useless);
tmp.append_or(std::move(res));
std::swap(tmp, res);
pos -= pos->size + 1;
}
while (pos > start);
return res;
}
case acc_cond::acc_op::Fin:
if (pos[-1].mark & useless)
return acc.inf(0U); // t
return acc.fin(acc.strip(pos[-1].mark, useless));
case acc_cond::acc_op::Inf:
if (pos[-1].mark & useless)
return acc.fin(0U); // f
return acc.inf(acc.strip(pos[-1].mark, useless));
case acc_cond::acc_op::FinNeg:
case acc_cond::acc_op::InfNeg:
SPOT_UNREACHABLE();
return acc_cond::acc_code{};
}
SPOT_UNREACHABLE();
return acc_cond::acc_code{};
}
}
void cleanup_acceptance(tgba_digraph_ptr& aut)
{
auto& acc = aut->acc();
@ -83,29 +28,7 @@ namespace spot
return;
auto& c = aut->get_acceptance();
acc_cond::mark_t used_in_cond = 0U;
if (!c.is_true())
{
auto pos = &c.back();
auto end = &c.front();
while (pos > end)
{
switch (pos->op)
{
case acc_cond::acc_op::And:
case acc_cond::acc_op::Or:
--pos;
break;
case acc_cond::acc_op::Fin:
case acc_cond::acc_op::Inf:
case acc_cond::acc_op::FinNeg:
case acc_cond::acc_op::InfNeg:
used_in_cond |= pos[-1].mark;
pos -= 2;
break;
}
}
}
acc_cond::mark_t used_in_cond = c.used_sets();
acc_cond::mark_t used_in_aut = 0U;
for (auto& t: aut->transitions())
@ -120,16 +43,10 @@ namespace spot
// Remove useless marks from the automaton
for (auto& t: aut->transitions())
t.acc = acc.strip(t.acc, useless);
t.acc = t.acc.strip(useless);
// Remove useless marks from the acceptance condition
acc_cond::acc_code newc;
if (c.is_true() || c.is_false())
newc = c;
else
newc = strip(acc, &c.back(), useless);
aut->set_acceptance(useful.count(), newc);
aut->set_acceptance(useful.count(), c.strip(useless, true));
}
}