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

fix constness of twa::get_init_state() and twa_succ_iterator::dst()

Fixes #125.

* src/kripke/kripkegraph.hh, src/ta/ta.cc, src/ta/ta.hh,
src/ta/taexplicit.cc, src/ta/taexplicit.hh, src/ta/taproduct.cc,
src/ta/taproduct.hh, src/ta/tgtaproduct.cc, src/ta/tgtaproduct.hh,
src/taalgos/dot.cc, src/taalgos/emptinessta.cc,
src/taalgos/emptinessta.hh, src/taalgos/minimize.cc,
src/taalgos/reachiter.cc, src/taalgos/tgba2ta.cc, src/twa/twa.hh,
src/twa/twagraph.hh, src/twa/twaproduct.cc, src/twa/twaproduct.hh,
src/twaalgos/compsusp.cc, src/twaalgos/gtec/gtec.cc,
src/twaalgos/ltl2tgba_fm.cc, src/twaalgos/reachiter.cc,
src/twaalgos/stutter.cc: Adjust.
parent afbaa54d
......@@ -180,12 +180,11 @@ namespace spot
return init_number_;
}
// FIXME: The return type ought to be const.
virtual kripke_graph_state* get_init_state() const
virtual const kripke_graph_state* get_init_state() const
{
if (num_states() == 0)
const_cast<graph_t&>(g_).new_state();
return const_cast<kripke_graph_state*>(state_from_number(init_number_));
return state_from_number(init_number_);
}
/// \brief Allow to get an iterator on the state we passed in
......
......@@ -56,7 +56,7 @@ namespace spot
s.emplace_front(index);
}
std::list<state*>&
std::list<const state*>&
scc_stack_ta::rem()
{
return top().rem;
......
......@@ -90,9 +90,10 @@ namespace spot
}
typedef std::set<state*, state_ptr_less_than> states_set_t;
typedef std::set<const state*, state_ptr_less_than> const_states_set_t;
/// \brief Get the initial states set of the automaton.
virtual const states_set_t
virtual const_states_set_t
get_initial_states_set() const = 0;
/// \brief Get the artificial initial state set of the automaton.
......@@ -102,7 +103,7 @@ namespace spot
/// artificial initial state have one transition to each real initial state,
/// and this transition is labeled by the corresponding initial condition.
/// (For more details, see the paper cited above)
virtual spot::state*
virtual const spot::state*
get_artificial_initial_state() const
{
return nullptr;
......@@ -205,17 +206,14 @@ namespace spot
virtual bool next() = 0;
virtual bool done() const = 0;
virtual state*
dst() const = 0;
virtual const state* dst() const = 0;
/// \brief Get the changeset on the transition leading to current successor.
///
/// This is a boolean function of atomic propositions.
virtual bdd
cond() const = 0;
virtual bdd cond() const = 0;
acc_cond::mark_t
acc() const = 0;
acc_cond::mark_t acc() const = 0;
};
......@@ -238,7 +236,7 @@ namespace spot
/// transitions which connect the states of the connected component.
acc_cond::mark_t condition;
std::list<state*> rem;
std::list<const state*> rem;
};
/// Stack a new SCC with index \a index.
......@@ -262,7 +260,7 @@ namespace spot
size() const;
/// The \c rem member of the top SCC.
std::list<state*>&
std::list<const state*>&
rem();
/// Is the stack empty?
......
......@@ -71,7 +71,7 @@ namespace spot
return !transitions_ || i_ == transitions_->end();
}
state*
const state*
ta_explicit_succ_iterator::dst() const
{
trace
......@@ -81,8 +81,7 @@ namespace spot
trace
<< "***ta_explicit_succ_iterator::dst() (*i_)->condition =***"
<< (*i_)->condition << std::endl;
state_ta_explicit* s = (*i_)->dest;
return s;
return (*i_)->dest;
}
bdd
......@@ -273,7 +272,7 @@ namespace spot
if (trans)
for (it_trans = trans->begin(); it_trans != trans->end();)
{
state_ta_explicit* dest = (*it_trans)->dest;
auto dest = (*it_trans)->dest;
bool is_stuttering_transition = (get_tgba_condition()
== (dest)->get_tgba_condition());
bool dest_is_livelock_accepting =
......@@ -316,14 +315,11 @@ namespace spot
state_ta_explicit::free_transitions()
{
state_ta_explicit::transitions* trans = transitions_;
state_ta_explicit::transitions::iterator it_trans;
// We don't destroy the transitions in the state's destructor because
// they are not cloned.
if (trans)
for (it_trans = trans->begin(); it_trans != trans->end(); ++it_trans)
{
delete *it_trans;
}
for (auto& t: *trans)
delete t;
delete trans;
std::unordered_map<int, transitions*, std::hash<int> >::iterator i =
......@@ -353,7 +349,7 @@ namespace spot
acc().set_generalized_buchi();
if (artificial_initial_state)
{
state_ta_explicit* is = add_state(artificial_initial_state);
auto is = add_state(artificial_initial_state);
assert(is == artificial_initial_state);
(void)is;
}
......@@ -364,7 +360,8 @@ namespace spot
ta::states_set_t::iterator it;
for (it = states_set_.begin(); it != states_set_.end(); ++it)
{
state_ta_explicit* s = down_cast<state_ta_explicit*>(*it);
auto* s = const_cast<state_ta_explicit*>
(down_cast<const state_ta_explicit*>(*it));
s->free_transitions();
s->get_tgba_state()->destroy();
......@@ -379,7 +376,7 @@ namespace spot
std::pair<ta::states_set_t::iterator, bool> add_state_to_ta =
states_set_.insert(s);
return static_cast<state_ta_explicit*>(*add_state_to_ta.first);
return down_cast<state_ta_explicit*>(*add_state_to_ta.first);
}
void
......@@ -389,21 +386,21 @@ namespace spot
s->set_initial_state(true);
if (condition == bddfalse)
condition = get_state_condition(s);
std::pair<ta::states_set_t::iterator, bool> add_state =
initial_states_set_.insert(s);
auto add_state = initial_states_set_.insert(s);
if (get_artificial_initial_state())
if (add_state.second)
{
state_ta_explicit* i =
auto i =
down_cast<state_ta_explicit*>(get_artificial_initial_state());
create_transition(i, condition, 0U, s);
}
}
void
ta_explicit::delete_stuttering_and_hole_successors(spot::state* s)
ta_explicit::delete_stuttering_and_hole_successors(const spot::state* s)
{
state_ta_explicit * state = down_cast<state_ta_explicit*>(s);
auto state =
const_cast<state_ta_explicit*>(down_cast<const state_ta_explicit*>(s));
assert(state);
state->delete_stuttering_and_hole_successors();
if (state->is_initial_state())
......@@ -414,7 +411,8 @@ namespace spot
void
ta_explicit::create_transition(state_ta_explicit* source, bdd condition,
acc_cond::mark_t acceptance_conditions,
state_ta_explicit* dest, bool add_at_beginning)
const state_ta_explicit* dest,
bool add_at_beginning)
{
state_ta_explicit::transition* t = new state_ta_explicit::transition;
t->dest = dest;
......@@ -424,7 +422,7 @@ namespace spot
}
const ta::states_set_t
ta::const_states_set_t
ta_explicit::get_initial_states_set() const
{
return initial_states_set_;
......
......@@ -56,7 +56,7 @@ namespace spot
void
create_transition(state_ta_explicit* source, bdd condition,
acc_cond::mark_t acceptance_conditions,
state_ta_explicit* dest,
const state_ta_explicit* dest,
bool add_at_beginning = false);
void
......@@ -64,7 +64,7 @@ namespace spot
// ta interface
virtual
~ta_explicit();
virtual const states_set_t
virtual const_states_set_t
get_initial_states_set() const;
virtual ta_succ_iterator*
......@@ -108,7 +108,7 @@ namespace spot
}
virtual void
delete_stuttering_and_hole_successors(spot::state* s);
delete_stuttering_and_hole_successors(const spot::state* s);
ta::states_set_t
get_states_set()
......@@ -124,7 +124,7 @@ namespace spot
const_twa_ptr tgba_;
state_ta_explicit* artificial_initial_state_;
ta::states_set_t states_set_;
ta::states_set_t initial_states_set_;
ta::const_states_set_t initial_states_set_;
};
/// states used by spot::ta_explicit.
......@@ -139,7 +139,7 @@ namespace spot
{
bdd condition;
acc_cond::mark_t acceptance_conditions;
state_ta_explicit* dest;
const state_ta_explicit* dest;
};
typedef std::list<transition*> transitions;
......@@ -238,13 +238,10 @@ namespace spot
virtual bool next();
virtual bool done() const;
virtual state*
dst() const;
virtual bdd
cond() const;
virtual const state* dst() const;
virtual bdd cond() const;
virtual acc_cond::mark_t
acc() const;
virtual acc_cond::mark_t acc() const;
private:
state_ta_explicit::transitions* transitions_;
......
......@@ -259,26 +259,25 @@ namespace spot
dict_->unregister_all_my_variables(this);
}
const ta::states_set_t
ta::const_states_set_t
ta_product::get_initial_states_set() const
{
//build initial states set
ta::states_set_t ta_init_states_set;
ta::states_set_t::const_iterator it;
ta::const_states_set_t ta_init_states_set;
ta::const_states_set_t::const_iterator it;
ta::states_set_t initial_states_set;
state* kripke_init_state = kripke_->get_init_state();
bdd kripke_init_state_condition = kripke_->state_condition(
kripke_init_state);
ta::const_states_set_t initial_states_set;
const state* kripke_init = kripke_->get_init_state();
bdd kripke_init_condition = kripke_->state_condition(kripke_init);
spot::state* artificial_initial_state =
const spot::state* artificial_initial_state =
ta_->get_artificial_initial_state();
if (artificial_initial_state)
{
ta_succ_iterator* ta_init_it_ = ta_->succ_iter(
artificial_initial_state, kripke_init_state_condition);
artificial_initial_state, kripke_init_condition);
for (ta_init_it_->first(); !ta_init_it_->done(); ta_init_it_->next())
{
ta_init_states_set.insert(ta_init_it_->dst());
......@@ -291,21 +290,13 @@ namespace spot
ta_init_states_set = ta_->get_initial_states_set();
}
for (it = ta_init_states_set.begin(); it != ta_init_states_set.end(); ++it)
{
if (artificial_initial_state ||
(kripke_init_state_condition == ta_->get_state_condition(*it)))
{
state_ta_product* stp = new state_ta_product((*it),
kripke_init_state->clone());
initial_states_set.insert(stp);
}
}
for (auto s: ta_init_states_set)
if (artificial_initial_state ||
(kripke_init_condition == ta_->get_state_condition(s)))
initial_states_set.insert(new state_ta_product(s,
kripke_init->clone()));
kripke_init_state->destroy();
kripke_init->destroy();
return initial_states_set;
}
......@@ -369,8 +360,8 @@ namespace spot
const state_ta_product* stp = down_cast<const state_ta_product*> (s);
assert(stp);
state* ta_s = stp->get_ta_state();
state* kr_s = stp->get_kripke_state();
const state* ta_s = stp->get_ta_state();
const state* kr_s = stp->get_kripke_state();
return (ta_->is_initial_state(ta_s))
&& ((kripke_->get_init_state())->compare(kr_s) == 0)
......@@ -393,7 +384,7 @@ namespace spot
{
const state_ta_product* stp = down_cast<const state_ta_product*> (s);
assert(stp);
state* ta_s = stp->get_ta_state();
const state* ta_s = stp->get_ta_state();
return ta_->get_state_condition(ta_s);
}
......
......@@ -36,7 +36,7 @@ namespace spot
/// \brief Constructor
/// \param ta_state The state from the ta automaton.
/// \param kripke_state The state from Kripke structure.
state_ta_product(state* ta_state, state* kripke_state) :
state_ta_product(const state* ta_state, const state* kripke_state) :
ta_state_(ta_state), kripke_state_(kripke_state)
{
}
......@@ -47,13 +47,13 @@ namespace spot
virtual
~state_ta_product();
state*
const state*
get_ta_state() const
{
return ta_state_;
}
state*
const state*
get_kripke_state() const
{
return kripke_state_;
......@@ -67,8 +67,8 @@ namespace spot
clone() const;
private:
state* ta_state_; ///< State from the ta automaton.
state* kripke_state_; ///< State from the kripke structure.
const state* ta_state_; ///< State from the ta automaton.
const state* kripke_state_; ///< State from the kripke structure.
};
/// \brief Iterate over the successors of a product computed on the fly.
......@@ -117,12 +117,12 @@ namespace spot
const kripke* kripke_;
ta_succ_iterator* ta_succ_it_;
twa_succ_iterator* kripke_succ_it_;
state_ta_product* current_state_;
const state_ta_product* current_state_;
bdd current_condition_;
acc_cond::mark_t current_acceptance_conditions_;
bool is_stuttering_transition_;
bdd kripke_source_condition;
state * kripke_current_dest_state;
const state* kripke_current_dest_state;
};
......@@ -141,7 +141,7 @@ namespace spot
virtual
~ta_product();
virtual const std::set<state*, state_ptr_less_than>
virtual ta::const_states_set_t
get_initial_states_set() const;
virtual ta_succ_iterator_product*
......
......@@ -49,7 +49,7 @@ namespace spot
{
}
state*
const state*
tgta_product::get_init_state() const
{
fixed_size_pool* p = const_cast<fixed_size_pool*> (&pool_);
......@@ -79,7 +79,7 @@ namespace spot
: source_(s), tgta_(t), kripke_(k), pool_(pool)
{
state * tgta_init_state = tgta_->get_init_state();
const state* tgta_init_state = tgta_->get_init_state();
if ((s->right())->compare(tgta_init_state) == 0)
source_ = nullptr;
......
......@@ -35,8 +35,7 @@ namespace spot
tgta_product(const const_kripke_ptr& left,
const const_tgta_ptr& right);
virtual state*
get_init_state() const;
virtual const state* get_init_state() const;
virtual twa_succ_iterator*
succ_iter(const state* local_state) const;
......@@ -97,6 +96,6 @@ namespace spot
bdd current_condition_;
acc_cond::mark_t current_acceptance_conditions_;
bdd kripke_source_condition;
state* kripke_current_dest_state;
const state* kripke_current_dest_state;
};
}
......@@ -146,9 +146,7 @@ namespace spot
artificial_initial_state_ = t_automata_->get_artificial_initial_state();
ta::states_set_t init_states_set;
ta::states_set_t::const_iterator it;
ta::const_states_set_t init_states_set;
if (artificial_initial_state_)
{
......@@ -159,10 +157,9 @@ namespace spot
{
int n = 0;
init_states_set = t_automata_->get_initial_states_set();
for (it = init_states_set.begin();
it != init_states_set.end(); ++it)
for (auto s: init_states_set)
{
bdd init_condition = t_automata_->get_state_condition(*it);
bdd init_condition = t_automata_->get_state_condition(s);
std::string label = bdd_format_formula(t_automata_->get_dict(),
init_condition);
++n;
......@@ -223,7 +220,7 @@ namespace spot
private:
std::ostream& os_;
spot::state* artificial_initial_state_;
const spot::state* artificial_initial_state_;
bool opt_horizontal_ = true;
bool opt_circles_ = false;
......
......@@ -88,11 +88,11 @@ namespace spot
// Setup depth-first search from initial states.
auto& ta_ = a_->get_ta();
auto& kripke_ = a_->get_kripke();
state* kripke_init_state = kripke_->get_init_state();
auto kripke_init_state = kripke_->get_init_state();
bdd kripke_init_state_condition = kripke_->state_condition(
kripke_init_state);
spot::state* artificial_initial_state = ta_->get_artificial_initial_state();
auto artificial_initial_state = ta_->get_artificial_initial_state();
ta_succ_iterator* ta_init_it_ = ta_->succ_iter(artificial_initial_state,
kripke_init_state_condition);
......@@ -124,8 +124,7 @@ namespace spot
while (!todo.empty())
{
state* curr = todo.top().first;
auto curr = todo.top().first;
// We are looking at the next successor in SUCC.
ta_succ_iterator_product* succ = todo.top().second;
......@@ -249,7 +248,7 @@ namespace spot
// top of ROOT that have an index greater to the one of
// the SSCC of S2 (called the "threshold").
int threshold = std::abs(p.first->second);
std::list<state*> rem;
std::list<const state*> rem;
bool acc = false;
trace << "***PASS 1: CYCLE***\n";
......@@ -393,21 +392,17 @@ namespace spot
std::stack<pair_state_iter> todo;
// * init: the set of the depth-first search initial states
std::queue<spot::state*> ta_init_it_;
std::queue<const spot::state*> ta_init_it_;
const ta::states_set_t init_states_set = a_->get_initial_states_set();
ta::states_set_t::const_iterator it;
for (it = init_states_set.begin(); it != init_states_set.end(); ++it)
{
state* init_state = (*it);
ta_init_it_.push(init_state);
}
auto init_states_set = a_->get_initial_states_set();
for (auto init_state: init_states_set)
ta_init_it_.push(init_state);
while (!ta_init_it_.empty())
{
// Setup depth-first search from initial states.
{
state* init = ta_init_it_.front();
auto init = ta_init_it_.front();
ta_init_it_.pop();
if (!h.emplace(init, num + 1).second)
......@@ -426,8 +421,7 @@ namespace spot
while (!todo.empty())
{
state* curr = todo.top().first;
auto curr = todo.top().first;
// We are looking at the next successor in SUCC.
ta_succ_iterator_product* succ = todo.top().second;
......@@ -517,16 +511,12 @@ namespace spot
//self loop state
if (!curr->compare(i->first))
{
state* self_loop_state = curr;
if (t->is_livelock_accepting_state(self_loop_state))
{
clear(h, todo, ta_init_it_);
trace << "PASS 2: SUCCESS\n";
return true;
}
}
if (t->is_livelock_accepting_state(curr))
{
clear(h, todo, ta_init_it_);
trace << "PASS 2: SUCCESS\n";
return true;
}
// Now this is the most interesting case. We have reached a
// state S1 which is already part of a non-dead SSCC. Any such
......@@ -540,7 +530,7 @@ namespace spot
// top of ROOT that have an index greater to the one of
// the SSCC of S2 (called the "threshold").
int threshold = i->second;
std::list<state*> rem;
std::list<const state*> rem;
bool acc = false;
while (threshold < sscc.top().index)
......@@ -578,7 +568,7 @@ namespace spot
void
ta_check::clear(hash_type& h, std::stack<pair_state_iter> todo,
std::queue<spot::state*> init_states)
std::queue<const spot::state*> init_states)
{
set_states(states() + h.size());
......
......@@ -33,7 +33,8 @@ namespace spot
namespace
{
typedef std::pair<spot::state*, ta_succ_iterator_product*> pair_state_iter;
typedef std::pair<const spot::state*,
ta_succ_iterator_product*> pair_state_iter;
}
/// \addtogroup ta_emptiness_check Emptiness-checks
......@@ -127,7 +128,7 @@ namespace spot
protected:
void
clear(hash_type& h, std::stack<pair_state_iter> todo, std::queue<
spot::state*> init_set);
const spot::state*> init_set);
void
clear(hash_type& h, std::stack<pair_state_iter> todo,
......
......@@ -230,8 +230,7 @@ namespace spot
std::set<const state*>::iterator it;
spot::state* artificial_initial_state =
ta_->get_artificial_initial_state();
auto artificial_initial_state = ta_->get_artificial_initial_state();
for (it = states_set.begin(); it != states_set.end(); ++it)
{
......
......@@ -50,12 +50,10 @@ namespace spot
int n = 0;
start();
spot::state* artificial_initial_state =
t_automata_->get_artificial_initial_state();
const spot::state* artificial_initial_state =
t_automata_->get_artificial_initial_state();
ta::states_set_t init_states_set;
ta::states_set_t::const_iterator it;
ta::const_states_set_t init_states_set;