Commit b09c293f authored by Maximilien Colange's avatar Maximilien Colange
Browse files

Clean the usage of spot::acc_cond::mark_t

spot::acc_cond::mark_t is implemented as a bit vector using a single
unsigned, and implicit conversions between mark_t and unsigned may be
confusing. We try to use the proper interface.

* bin/autfilt.cc, bin/ltlsynt.cc, spot/kripke/kripke.cc,
  spot/misc/game.hh, spot/parseaut/parseaut.yy, spot/priv/accmap.hh,
  spot/ta/ta.cc, spot/ta/taexplicit.cc, spot/ta/taproduct.cc,
  spot/taalgos/emptinessta.cc, spot/taalgos/tgba2ta.cc, spot/twa/acc.cc,
  spot/twa/acc.hh, spot/twa/taatgba.cc, spot/twa/taatgba.hh,
  spot/twa/twagraph.hh, spot/twaalgos/alternation.cc,
  spot/twaalgos/cleanacc.cc, spot/twaalgos/cobuchi.cc,
  spot/twaalgos/complete.cc, spot/twaalgos/couvreurnew.cc,
  spot/twaalgos/degen.cc, spot/twaalgos/dot.cc,
  spot/twaalgos/dtwasat.cc, spot/twaalgos/dualize.cc,
  spot/twaalgos/emptiness.cc, spot/twaalgos/gtec/ce.cc,
  spot/twaalgos/gtec/gtec.cc, spot/twaalgos/gtec/sccstack.cc,
  spot/twaalgos/gv04.cc, spot/twaalgos/hoa.cc, spot/twaalgos/lbtt.cc,
  spot/twaalgos/ltl2tgba_fm.cc, spot/twaalgos/magic.cc,
  spot/twaalgos/ndfs_result.hxx, spot/twaalgos/rabin2parity.cc,
  spot/twaalgos/randomgraph.cc, spot/twaalgos/remfin.cc,
  spot/twaalgos/sbacc.cc, spot/twaalgos/sccfilter.cc,
  spot/twaalgos/sccinfo.cc, spot/twaalgos/sccinfo.hh,
  spot/twaalgos/se05.cc, spot/twaalgos/sepsets.cc,
  spot/twaalgos/simulation.cc, spot/twaalgos/strength.cc,
  spot/twaalgos/stripacc.cc, spot/twaalgos/stutter.cc,
  spot/twaalgos/sum.cc, spot/twaalgos/tau03.cc,
  spot/twaalgos/tau03opt.cc, spot/twaalgos/totgba.cc,
  spot/twaalgos/toweak.cc, python/spot/impl.i, tests/core/acc.cc,
  tests/core/twagraph.cc: do not confuse mark_t and unsigned
* tests/python/acc_cond.ipynb: warn about possible change of the API
parent cfcc18e6
Pipeline #980 passed with stages
in 134 minutes and 17 seconds
......@@ -599,7 +599,7 @@ static bool opt_complement = false;
static bool opt_complement_acc = false;
static char* opt_decompose_scc = nullptr;
static bool opt_dualize = false;
static spot::acc_cond::mark_t opt_mask_acc = 0U;
static spot::acc_cond::mark_t opt_mask_acc = {};
static std::vector<bool> opt_keep_states = {};
static unsigned int opt_keep_states_initial = 0;
static bool opt_simpl_acc = false;
......
// -*- coding: utf-8 -*-
// Copyright (C) 2017 Laboratoire de Recherche et Développement
// Copyright (C) 2017-2018 Laboratoire de Recherche et Développement
// de l'Epita (LRDE).
//
// This file is part of Spot, a model checking library.
......@@ -173,7 +173,7 @@ namespace
unsigned q = split->new_state();
bdd in = bdd_existcomp(cube, input_bdd);
bdd out = bdd_exist(cube, input_bdd);
split->new_edge(src, q, in, 0);
split->new_edge(src, q, in, {});
split->new_edge(q, e.dst, out, e.acc);
}
}
......@@ -264,7 +264,7 @@ namespace
todo.push_back(e2.dst);
}
aut->new_edge(pg2aut[s], pg2aut[e2.dst],
(e1.cond & out), 0);
(e1.cond & out), {});
break;
}
++i;
......
......@@ -881,7 +881,7 @@ def state_is_accepting(self, src) -> "bool":
%extend spot::twa_graph {
unsigned new_univ_edge(unsigned src, const std::vector<unsigned>& v,
bdd cond, acc_cond::mark_t acc = 0U)
bdd cond, acc_cond::mark_t acc = {})
{
return self->new_univ_edge(src, v.begin(), v.end(), cond, acc);
}
......
......@@ -40,7 +40,7 @@ namespace spot
{
// Do not assert(!done()) here. It is OK to call
// this function on a state without successor.
return 0U;
return {};
}
kripke::~kripke()
......@@ -50,6 +50,6 @@ namespace spot
acc_cond::mark_t
kripke::state_acceptance_mark(const state*) const
{
return 0U;
return {};
}
}
// -*- coding: utf-8 -*-
// Copyright (C) 2017 Laboratoire de Recherche et Développement
// Copyright (C) 2017-2018 Laboratoire de Recherche et Développement
// de l'Epita (LRDE).
//
// This file is part of Spot, a model checking library.
......@@ -265,7 +265,7 @@ public:
acc_cond::mark_t acc() const override
{
return 0;
return {};
}
};
......
......@@ -115,8 +115,8 @@ extern "C" int strverscmp(const char *s1, const char *s2);
spot::location state_label_loc;
spot::location accset_loc;
spot::acc_cond::mark_t acc_state;
spot::acc_cond::mark_t neg_acc_sets = 0U;
spot::acc_cond::mark_t pos_acc_sets = 0U;
spot::acc_cond::mark_t neg_acc_sets = {};
spot::acc_cond::mark_t pos_acc_sets = {};
int plus;
int minus;
std::vector<std::string>* state_names = nullptr;
......@@ -1366,19 +1366,19 @@ acc-sig: '{' acc-sets '}'
}
acc-sets:
{
$$ = spot::acc_cond::mark_t(0U);
$$ = spot::acc_cond::mark_t({});
}
| acc-sets acc-set
{
if (res.ignore_acc || $2 == -1U)
$$ = spot::acc_cond::mark_t(0U);
$$ = spot::acc_cond::mark_t({});
else
$$ = $1 | res.aut_or_ks->acc().mark($2);
}
state-acc_opt:
{
$$ = spot::acc_cond::mark_t(0U);
$$ = spot::acc_cond::mark_t({});
}
| acc-sig
{
......@@ -1393,7 +1393,7 @@ state-acc_opt:
}
trans-acc_opt:
{
$$ = spot::acc_cond::mark_t(0U);
$$ = spot::acc_cond::mark_t({});
}
| acc-sig
{
......@@ -1686,7 +1686,7 @@ sign: '+' { $$ = res.plus; }
// Membership to a pair is represented as (+NUM,-NUM)
dstar_accsigs:
{
$$ = 0U;
$$ = spot::acc_cond::mark_t({});
}
| dstar_accsigs sign INT
{
......@@ -1830,7 +1830,7 @@ nc-state:
res.accept_all_seen = true;
auto acc = !strncmp("accept", $1->c_str(), 6) ?
res.h->aut->acc().all_sets() : spot::acc_cond::mark_t(0U);
res.h->aut->acc().all_sets() : spot::acc_cond::mark_t({});
res.namer->new_edge(*$1, *$1, bddtrue, acc);
delete $1;
}
......@@ -1839,7 +1839,7 @@ nc-state:
| nc-ident-list nc-transition-block
{
auto acc = !strncmp("accept", $1->c_str(), 6) ?
res.h->aut->acc().all_sets() : spot::acc_cond::mark_t(0U);
res.h->aut->acc().all_sets() : spot::acc_cond::mark_t({});
for (auto& p: *$2)
{
bdd c = bdd_from_int(p.first);
......@@ -2041,7 +2041,7 @@ lbtt-state: STATE_NUM INT lbtt-acc
std::vector<unsigned>{res.cur_state});
res.acc_state = $3;
}
lbtt-acc: { $$ = 0U; }
lbtt-acc: { $$ = spot::acc_cond::mark_t({}); }
| lbtt-acc ACC
{
$$ = $1;
......@@ -2183,7 +2183,7 @@ fix_acceptance_aux(spot::acc_cond& acc,
{
auto m = in[pos - 1].mark;
auto c = acc.fin(onlyneg & m);
spot::acc_cond::mark_t tmp = 0U;
spot::acc_cond::mark_t tmp = {};
for (auto i: both.sets())
{
if (m.has(i))
......@@ -2198,7 +2198,7 @@ fix_acceptance_aux(spot::acc_cond& acc,
{
auto m = in[pos - 1].mark;
auto c = acc.inf(onlyneg & m);
spot::acc_cond::mark_t tmp = 0U;
spot::acc_cond::mark_t tmp = {};
for (auto i: both.sets())
{
if (m.has(i))
......
// -*- coding: utf-8 -*-
// Copyright (C) 2014 Laboratoire de Recherche et Developpement de
// Copyright (C) 2014, 2018 Laboratoire de Recherche et Developpement de
// l'Epita (LRDE).
//
// This file is part of Spot, a model checking library.
......@@ -63,7 +63,7 @@ namespace spot
{
auto p = map_.find(name);
if (p == map_.end())
return std::make_pair(false, 0U);
return std::make_pair(false, acc_cond::mark_t({}));
return std::make_pair(true, acc_cond::mark_t({p->second}));
}
};
......@@ -85,7 +85,7 @@ namespace spot
if (n < aut_->acc().num_sets())
return std::make_pair(true, acc_cond::mark_t({n}));
else
return std::make_pair(false, 0U);
return std::make_pair(false, acc_cond::mark_t({}));
}
};
......@@ -113,7 +113,7 @@ namespace spot
map_[n] = res;
return std::make_pair(true, res);
}
return std::make_pair(false, 0U);
return std::make_pair(false, acc_cond::mark_t({}));
}
};
}
......@@ -29,7 +29,7 @@ namespace spot
{
index = i;
is_accepting = false;
condition = 0U;
condition = {};
}
scc_stack_ta::connected_component&
......
......@@ -391,7 +391,7 @@ namespace spot
{
auto i =
down_cast<state_ta_explicit*>(get_artificial_initial_state());
create_transition(i, condition, 0U, s);
create_transition(i, condition, {}, s);
}
}
......
......@@ -184,7 +184,7 @@ namespace spot
//if stuttering transition, the TA automata stays in the same state
current_state_ = new state_ta_product(source_->get_ta_state(),
kripke_current_dest_state->clone());
current_acceptance_conditions_ = 0U;
current_acceptance_conditions_ = {};
return true;
}
......
......@@ -109,7 +109,7 @@ namespace spot
}
scc.push(++num);
arc.push(0U);
arc.push({});
ta_succ_iterator_product* iter = a_->succ_iter(init);
iter->first();
......
......@@ -175,7 +175,7 @@ namespace spot
}
sscc.push(++num);
arc.push(0U);
arc.push({});
sscc.top().is_accepting
= testing_aut->is_accepting_state(init);
twa_succ_iterator* iter = testing_aut->succ_iter(init);
......@@ -407,7 +407,7 @@ namespace spot
twa_succ_iterator* it = tgba_->succ_iter(tgba_init_state);
it->first();
if (!it->done())
is_acc = it->acc() != 0U;
is_acc = !!it->acc();
delete it;
}
......@@ -459,7 +459,7 @@ namespace spot
twa_succ_iterator* it = tgba_->succ_iter(tgba_state);
it->first();
if (!it->done())
is_acc = it->acc() != 0U;
is_acc = !!it->acc();
delete it;
}
......@@ -631,7 +631,7 @@ namespace spot
if (state->compare(ta->get_artificial_initial_state()))
ta->create_transition(state, bdd_stutering_transition,
0U, state);
{}, state);
state->set_livelock_accepting_state(false);
state->set_accepting_state(false);
......
......@@ -34,13 +34,13 @@ namespace spot
{
std::ostream& operator<<(std::ostream& os, spot::acc_cond::mark_t m)
{
auto a = m.id;
auto a = m;
os << '{';
unsigned level = 0;
const char* comma = "";
while (a)
{
if (a & 1)
if (a.has(0))
{
os << comma << level;
comma = ",";
......@@ -129,8 +129,8 @@ namespace spot
SPOT_FALLTHROUGH;
case acc_cond::acc_op::Inf:
{
auto a = code[pos - 1].mark.id;
if (a == 0U)
auto a = code[pos - 1].mark;
if (!a)
{
if (style == LATEX)
os << "\\mathsf{t}";
......@@ -164,7 +164,7 @@ namespace spot
const char* inf_ = (style == LATEX) ? "\\mathsf{Inf}(" : "Inf(";
while (a)
{
if (a & 1)
if (a.has(0))
{
os << and_ << inf_ << negated_pre;
set_printer(os, level);
......@@ -184,8 +184,8 @@ namespace spot
SPOT_FALLTHROUGH;
case acc_cond::acc_op::Fin:
{
auto a = code[pos - 1].mark.id;
if (a == 0U)
auto a = code[pos - 1].mark;
if (!a)
{
if (style == LATEX)
os << "\\mathsf{f}";
......@@ -204,7 +204,7 @@ namespace spot
const char* fin_ = (style == LATEX) ? "\\mathsf{Fin}(" : "Fin(";
while (a)
{
if (a & 1)
if (a.has(0))
{
os << or_ << fin_ << negated_pre;
set_printer(os, level);
......@@ -330,14 +330,14 @@ namespace spot
case acc_cond::acc_op::And:
{
auto sub = pos - pos->sub.size;
acc_cond::mark_t m = 0U;
acc_cond::mark_t m = {};
while (sub < pos)
{
--pos;
if (auto s = eval_sets(inf, pos))
m |= s;
else
return 0U;
return {};
pos -= pos->sub.size;
}
return m;
......@@ -352,20 +352,20 @@ namespace spot
return s;
pos -= pos->sub.size;
}
return 0U;
return {};
}
case acc_cond::acc_op::Inf:
if ((pos[-1].mark & inf) == pos[-1].mark)
return pos[-1].mark;
else
return 0U;
return {};
case acc_cond::acc_op::Fin:
case acc_cond::acc_op::FinNeg:
case acc_cond::acc_op::InfNeg:
SPOT_UNREACHABLE();
}
SPOT_UNREACHABLE();
return 0U;
return {};
}
}
......@@ -387,7 +387,7 @@ namespace spot
bool acc_cond::acc_code::inf_satisfiable(mark_t inf) const
{
return !maybe_accepting(inf, 0U).is_false();
return !maybe_accepting(inf, {}).is_false();
}
......@@ -397,7 +397,7 @@ namespace spot
throw std::runtime_error
("Fin acceptance is not supported by this code path.");
if (code_.empty())
return 0U;
return {};
return eval_sets(inf, &code_.back());
}
......@@ -419,7 +419,7 @@ namespace spot
pos -= 2;
break;
case acc_cond::acc_op::Fin:
if (code_[pos - 2].mark == 0U) // f
if (!code_[pos - 2].mark) // f
{
pos -= 2;
break;
......@@ -458,8 +458,8 @@ namespace spot
// Pretend we were in a unary highop.
s = 5;
}
acc_cond::mark_t seen_fin = 0U;
acc_cond::mark_t seen_inf = 0U;
acc_cond::mark_t seen_fin = {};
acc_cond::mark_t seen_inf = {};
while (s)
{
if (code[--s].sub.op != lowop)
......@@ -481,7 +481,7 @@ namespace spot
if (o1 != acc_cond::acc_op::Fin
|| o2 != acc_cond::acc_op::Inf
|| m1.count() != 1
|| m2.id != (m1.id << 1))
|| m2 != (m1 << 1))
return false;
seen_fin |= m1;
seen_inf |= m2;
......@@ -511,8 +511,8 @@ namespace spot
if (mainop == singleop && m.count() != 1)
return false;
acc_cond::mark_t fin(0U);
acc_cond::mark_t inf(0U);
acc_cond::mark_t fin = {};
acc_cond::mark_t inf = {};
for (unsigned mark: m.sets())
{
if (mainop == acc_cond::acc_op::Fin)
......@@ -543,8 +543,8 @@ namespace spot
|| op == acc_cond::acc_op::Inf)
{
auto m = code[--s].mark;
acc_cond::mark_t fin(0U);
acc_cond::mark_t inf(0U);
acc_cond::mark_t fin = {};
acc_cond::mark_t inf = {};
if (op == singleop && m.count() != 1)
{
......@@ -631,7 +631,7 @@ namespace spot
return true;
if (code_.is_f())
{
pairs.emplace_back(0U, 0U);
pairs.emplace_back(mark_t({}), mark_t({}));
return true;
}
return is_rs_like(code_, acc_op::And, acc_op::Or, acc_op::Fin, pairs);
......@@ -644,7 +644,7 @@ namespace spot
return true;
if (code_.is_t())
{
pairs.emplace_back(0U, 0U);
pairs.emplace_back(mark_t({}), mark_t({}));
return true;
}
return is_rs_like(code_, acc_op::Or, acc_op::And, acc_op::Inf, pairs);
......@@ -668,8 +668,8 @@ namespace spot
return false;
auto s = code_.back().sub.size;
acc_cond::mark_t seen_fin = 0U;
acc_cond::mark_t seen_inf = 0U;
acc_cond::mark_t seen_fin = {};
acc_cond::mark_t seen_inf = {};
// Each pair is the position of a Fin followed
// by the number of Inf.
std::map<unsigned, unsigned> p;
......@@ -752,8 +752,8 @@ namespace spot
return false;
auto s = code_.back().sub.size;
acc_cond::mark_t seen_fin = 0U;
acc_cond::mark_t seen_inf = 0U;
acc_cond::mark_t seen_fin = {};
acc_cond::mark_t seen_inf = {};
// Each pairs is the position of a Inf followed
// by the number of Fin.
std::map<unsigned, unsigned> p;
......@@ -1054,12 +1054,12 @@ namespace spot
acc_code rescode = f();
while ((cube = isop.next()) != bddfalse)
{
mark_t i = 0U;
mark_t i = {};
acc_code f;
while (cube != bddtrue)
{
// The acceptance set associated to this BDD variable
mark_t s = 0U;
mark_t s = {};
s.set(sets[bdd_var(cube)]);
bdd h = bdd_high(cube);
......@@ -1123,12 +1123,12 @@ namespace spot
acc_code rescode;
while ((cube = isop.next()) != bddfalse)
{
mark_t m = 0U;
mark_t m = {};
acc_code i = f();
while (cube != bddtrue)
{
// The acceptance set associated to this BDD variable
mark_t s = 0U;
mark_t s = {};
s.set(sets[bdd_var(cube)]);
bdd h = bdd_high(cube);
......@@ -1156,9 +1156,9 @@ namespace spot
acc_cond::unsat_mark() const
{
if (is_t())
return {false, 0U};
return {false, mark_t({})};
if (!uses_fin_acceptance())
return {true, 0U};
return {true, mark_t({})};
auto used = code_.used_sets();
unsigned c = used.count();
......@@ -1185,12 +1185,12 @@ namespace spot
bdd res = to_bdd_rec(&code_.back(), &r[0]);
if (res == bddtrue)
return {false, 0U};
return {false, mark_t({})};
if (res == bddfalse)
return {true, 0U};
return {true, mark_t({})};
bdd cube = bdd_satone(!res);
mark_t i = 0U;
mark_t i = {};
while (cube != bddtrue)
{
// The acceptance set associated to this BDD variable
......@@ -1483,8 +1483,8 @@ namespace spot
acc_cond::acc_code::used_sets() const
{
if (is_t() || is_f())
return 0U;
acc_cond::mark_t used_in_cond = 0U;
return {};
acc_cond::mark_t used_in_cond = {};
auto pos = &back();
auto end = &front();
while (pos > end)
......@@ -1511,10 +1511,10 @@ namespace spot
acc_cond::acc_code::used_inf_fin_sets() const
{
if (is_t() || is_f())
return {0U, 0U};
return {mark_t({}), mark_t({})};
acc_cond::mark_t used_fin = 0U;
acc_cond::mark_t used_inf = 0U;
acc_cond::mark_t used_fin = {};
acc_cond::mark_t used_inf = {};
auto pos = &back();
auto end = &front();
while (pos > end)
......
......@@ -51,8 +51,8 @@ namespace spot
template<class iterator>
mark_t(const iterator& begin, const iterator& end) noexcept
: mark_t(0U)
{
id = 0U;
for (iterator i = begin; i != end; ++i)
set(*i);
}
......@@ -62,16 +62,23 @@ namespace spot
{
}
static mark_t all()
{
mark_t res({});
res.id -= 1;
return res;
}
bool operator==(unsigned o) const
{
SPOT_ASSERT(o == 0U);
return id == o;
return !id;
}
bool operator!=(unsigned o) const
{
SPOT_ASSERT(o == 0U);
return id != o;
return !!id;
}
bool operator==(mark_t o) const
......@@ -106,12 +113,12 @@ namespace spot
explicit operator bool() const
{
return id != 0;
return !!id;
}
bool has(unsigned u) const
{
return id & (1U << u);
return !!this->operator&(mark_t({0}) << u);
}
void set(unsigned u)
......@@ -220,7 +227,7 @@ namespace spot
bool subset(mark_t m) const
{
return (*this) - m == 0U;
return !((*this) - m);
}
bool proper_subset(mark_t m) const
......@@ -302,11 +309,11 @@ namespace spot
template<class iterator>
void fill(iterator here) const
{
auto a = id;
auto a = *this;
unsigned level = 0;
while (a)
{
if (a & 1)
if (a.has(0))
*here++ = level;
++level;
a >>= 1;
......@@ -437,21 +444,21 @@ namespace spot
{