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 ...@@ -180,12 +180,11 @@ namespace spot
return init_number_; return init_number_;
} }
// FIXME: The return type ought to be const. virtual const kripke_graph_state* get_init_state() const
virtual kripke_graph_state* get_init_state() const
{ {
if (num_states() == 0) if (num_states() == 0)
const_cast<graph_t&>(g_).new_state(); 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 /// \brief Allow to get an iterator on the state we passed in
......
...@@ -56,7 +56,7 @@ namespace spot ...@@ -56,7 +56,7 @@ namespace spot
s.emplace_front(index); s.emplace_front(index);
} }
std::list<state*>& std::list<const state*>&
scc_stack_ta::rem() scc_stack_ta::rem()
{ {
return top().rem; return top().rem;
......
...@@ -90,9 +90,10 @@ namespace spot ...@@ -90,9 +90,10 @@ namespace spot
} }
typedef std::set<state*, state_ptr_less_than> states_set_t; 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. /// \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; get_initial_states_set() const = 0;
/// \brief Get the artificial initial state set of the automaton. /// \brief Get the artificial initial state set of the automaton.
...@@ -102,7 +103,7 @@ namespace spot ...@@ -102,7 +103,7 @@ namespace spot
/// artificial initial state have one transition to each real initial state, /// artificial initial state have one transition to each real initial state,
/// and this transition is labeled by the corresponding initial condition. /// and this transition is labeled by the corresponding initial condition.
/// (For more details, see the paper cited above) /// (For more details, see the paper cited above)
virtual spot::state* virtual const spot::state*
get_artificial_initial_state() const get_artificial_initial_state() const
{ {
return nullptr; return nullptr;
...@@ -205,17 +206,14 @@ namespace spot ...@@ -205,17 +206,14 @@ namespace spot
virtual bool next() = 0; virtual bool next() = 0;
virtual bool done() const = 0; virtual bool done() const = 0;
virtual state* virtual const state* dst() const = 0;
dst() const = 0;
/// \brief Get the changeset on the transition leading to current successor. /// \brief Get the changeset on the transition leading to current successor.
/// ///
/// This is a boolean function of atomic propositions. /// This is a boolean function of atomic propositions.
virtual bdd virtual bdd cond() const = 0;
cond() const = 0;
acc_cond::mark_t acc_cond::mark_t acc() const = 0;
acc() const = 0;
}; };
...@@ -238,7 +236,7 @@ namespace spot ...@@ -238,7 +236,7 @@ namespace spot
/// transitions which connect the states of the connected component. /// transitions which connect the states of the connected component.
acc_cond::mark_t condition; acc_cond::mark_t condition;
std::list<state*> rem; std::list<const state*> rem;
}; };
/// Stack a new SCC with index \a index. /// Stack a new SCC with index \a index.
...@@ -262,7 +260,7 @@ namespace spot ...@@ -262,7 +260,7 @@ namespace spot
size() const; size() const;
/// The \c rem member of the top SCC. /// The \c rem member of the top SCC.
std::list<state*>& std::list<const state*>&
rem(); rem();
/// Is the stack empty? /// Is the stack empty?
......
...@@ -71,7 +71,7 @@ namespace spot ...@@ -71,7 +71,7 @@ namespace spot
return !transitions_ || i_ == transitions_->end(); return !transitions_ || i_ == transitions_->end();
} }
state* const state*
ta_explicit_succ_iterator::dst() const ta_explicit_succ_iterator::dst() const
{ {
trace trace
...@@ -81,8 +81,7 @@ namespace spot ...@@ -81,8 +81,7 @@ namespace spot
trace trace
<< "***ta_explicit_succ_iterator::dst() (*i_)->condition =***" << "***ta_explicit_succ_iterator::dst() (*i_)->condition =***"
<< (*i_)->condition << std::endl; << (*i_)->condition << std::endl;
state_ta_explicit* s = (*i_)->dest; return (*i_)->dest;
return s;
} }
bdd bdd
...@@ -273,7 +272,7 @@ namespace spot ...@@ -273,7 +272,7 @@ namespace spot
if (trans) if (trans)
for (it_trans = trans->begin(); it_trans != trans->end();) 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() bool is_stuttering_transition = (get_tgba_condition()
== (dest)->get_tgba_condition()); == (dest)->get_tgba_condition());
bool dest_is_livelock_accepting = bool dest_is_livelock_accepting =
...@@ -316,14 +315,11 @@ namespace spot ...@@ -316,14 +315,11 @@ namespace spot
state_ta_explicit::free_transitions() state_ta_explicit::free_transitions()
{ {
state_ta_explicit::transitions* trans = 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 // We don't destroy the transitions in the state's destructor because
// they are not cloned. // they are not cloned.
if (trans) if (trans)
for (it_trans = trans->begin(); it_trans != trans->end(); ++it_trans) for (auto& t: *trans)
{ delete t;
delete *it_trans;
}
delete trans; delete trans;
std::unordered_map<int, transitions*, std::hash<int> >::iterator i = std::unordered_map<int, transitions*, std::hash<int> >::iterator i =
...@@ -353,7 +349,7 @@ namespace spot ...@@ -353,7 +349,7 @@ namespace spot
acc().set_generalized_buchi(); acc().set_generalized_buchi();
if (artificial_initial_state) 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); assert(is == artificial_initial_state);
(void)is; (void)is;
} }
...@@ -364,7 +360,8 @@ namespace spot ...@@ -364,7 +360,8 @@ namespace spot
ta::states_set_t::iterator it; ta::states_set_t::iterator it;
for (it = states_set_.begin(); it != states_set_.end(); ++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->free_transitions();
s->get_tgba_state()->destroy(); s->get_tgba_state()->destroy();
...@@ -379,7 +376,7 @@ namespace spot ...@@ -379,7 +376,7 @@ namespace spot
std::pair<ta::states_set_t::iterator, bool> add_state_to_ta = std::pair<ta::states_set_t::iterator, bool> add_state_to_ta =
states_set_.insert(s); 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 void
...@@ -389,21 +386,21 @@ namespace spot ...@@ -389,21 +386,21 @@ namespace spot
s->set_initial_state(true); s->set_initial_state(true);
if (condition == bddfalse) if (condition == bddfalse)
condition = get_state_condition(s); condition = get_state_condition(s);
std::pair<ta::states_set_t::iterator, bool> add_state = auto add_state = initial_states_set_.insert(s);
initial_states_set_.insert(s);
if (get_artificial_initial_state()) if (get_artificial_initial_state())
if (add_state.second) if (add_state.second)
{ {
state_ta_explicit* i = auto i =
down_cast<state_ta_explicit*>(get_artificial_initial_state()); down_cast<state_ta_explicit*>(get_artificial_initial_state());
create_transition(i, condition, 0U, s); create_transition(i, condition, 0U, s);
} }
} }
void 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); assert(state);
state->delete_stuttering_and_hole_successors(); state->delete_stuttering_and_hole_successors();
if (state->is_initial_state()) if (state->is_initial_state())
...@@ -414,7 +411,8 @@ namespace spot ...@@ -414,7 +411,8 @@ namespace spot
void void
ta_explicit::create_transition(state_ta_explicit* source, bdd condition, ta_explicit::create_transition(state_ta_explicit* source, bdd condition,
acc_cond::mark_t acceptance_conditions, 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; state_ta_explicit::transition* t = new state_ta_explicit::transition;
t->dest = dest; t->dest = dest;
...@@ -424,7 +422,7 @@ namespace spot ...@@ -424,7 +422,7 @@ namespace spot
} }
const ta::states_set_t ta::const_states_set_t
ta_explicit::get_initial_states_set() const ta_explicit::get_initial_states_set() const
{ {
return initial_states_set_; return initial_states_set_;
......
...@@ -56,7 +56,7 @@ namespace spot ...@@ -56,7 +56,7 @@ namespace spot
void void
create_transition(state_ta_explicit* source, bdd condition, create_transition(state_ta_explicit* source, bdd condition,
acc_cond::mark_t acceptance_conditions, acc_cond::mark_t acceptance_conditions,
state_ta_explicit* dest, const state_ta_explicit* dest,
bool add_at_beginning = false); bool add_at_beginning = false);
void void
...@@ -64,7 +64,7 @@ namespace spot ...@@ -64,7 +64,7 @@ namespace spot
// ta interface // ta interface
virtual virtual
~ta_explicit(); ~ta_explicit();
virtual const states_set_t virtual const_states_set_t
get_initial_states_set() const; get_initial_states_set() const;
virtual ta_succ_iterator* virtual ta_succ_iterator*
...@@ -108,7 +108,7 @@ namespace spot ...@@ -108,7 +108,7 @@ namespace spot
} }
virtual void virtual void
delete_stuttering_and_hole_successors(spot::state* s); delete_stuttering_and_hole_successors(const spot::state* s);
ta::states_set_t ta::states_set_t
get_states_set() get_states_set()
...@@ -124,7 +124,7 @@ namespace spot ...@@ -124,7 +124,7 @@ namespace spot
const_twa_ptr tgba_; const_twa_ptr tgba_;
state_ta_explicit* artificial_initial_state_; state_ta_explicit* artificial_initial_state_;
ta::states_set_t states_set_; 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. /// states used by spot::ta_explicit.
...@@ -139,7 +139,7 @@ namespace spot ...@@ -139,7 +139,7 @@ namespace spot
{ {
bdd condition; bdd condition;
acc_cond::mark_t acceptance_conditions; acc_cond::mark_t acceptance_conditions;
state_ta_explicit* dest; const state_ta_explicit* dest;
}; };
typedef std::list<transition*> transitions; typedef std::list<transition*> transitions;
...@@ -238,13 +238,10 @@ namespace spot ...@@ -238,13 +238,10 @@ namespace spot
virtual bool next(); virtual bool next();
virtual bool done() const; virtual bool done() const;
virtual state* virtual const state* dst() const;
dst() const; virtual bdd cond() const;
virtual bdd
cond() const;
virtual acc_cond::mark_t virtual acc_cond::mark_t acc() const;
acc() const;
private: private:
state_ta_explicit::transitions* transitions_; state_ta_explicit::transitions* transitions_;
......
...@@ -259,26 +259,25 @@ namespace spot ...@@ -259,26 +259,25 @@ namespace spot
dict_->unregister_all_my_variables(this); dict_->unregister_all_my_variables(this);
} }
const ta::states_set_t ta::const_states_set_t
ta_product::get_initial_states_set() const ta_product::get_initial_states_set() const
{ {
//build initial states set //build initial states set
ta::states_set_t ta_init_states_set; ta::const_states_set_t ta_init_states_set;
ta::states_set_t::const_iterator it; ta::const_states_set_t::const_iterator it;
ta::states_set_t initial_states_set; ta::const_states_set_t initial_states_set;
state* kripke_init_state = kripke_->get_init_state(); const state* kripke_init = kripke_->get_init_state();
bdd kripke_init_state_condition = kripke_->state_condition( bdd kripke_init_condition = kripke_->state_condition(kripke_init);
kripke_init_state);
spot::state* artificial_initial_state = const spot::state* artificial_initial_state =
ta_->get_artificial_initial_state(); ta_->get_artificial_initial_state();
if (artificial_initial_state) if (artificial_initial_state)
{ {
ta_succ_iterator* ta_init_it_ = ta_->succ_iter( 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()) for (ta_init_it_->first(); !ta_init_it_->done(); ta_init_it_->next())
{ {
ta_init_states_set.insert(ta_init_it_->dst()); ta_init_states_set.insert(ta_init_it_->dst());
...@@ -291,21 +290,13 @@ namespace spot ...@@ -291,21 +290,13 @@ namespace spot
ta_init_states_set = ta_->get_initial_states_set(); ta_init_states_set = ta_->get_initial_states_set();
} }
for (it = ta_init_states_set.begin(); it != ta_init_states_set.end(); ++it) for (auto s: ta_init_states_set)
{ if (artificial_initial_state ||
(kripke_init_condition == ta_->get_state_condition(s)))
if (artificial_initial_state || initial_states_set.insert(new state_ta_product(s,
(kripke_init_state_condition == ta_->get_state_condition(*it))) kripke_init->clone()));
{
state_ta_product* stp = new state_ta_product((*it),
kripke_init_state->clone());
initial_states_set.insert(stp);
}
}
kripke_init_state->destroy(); kripke_init->destroy();
return initial_states_set; return initial_states_set;
} }
...@@ -369,8 +360,8 @@ namespace spot ...@@ -369,8 +360,8 @@ namespace spot
const state_ta_product* stp = down_cast<const state_ta_product*> (s); const state_ta_product* stp = down_cast<const state_ta_product*> (s);
assert(stp); assert(stp);
state* ta_s = stp->get_ta_state(); const state* ta_s = stp->get_ta_state();
state* kr_s = stp->get_kripke_state(); const state* kr_s = stp->get_kripke_state();
return (ta_->is_initial_state(ta_s)) return (ta_->is_initial_state(ta_s))
&& ((kripke_->get_init_state())->compare(kr_s) == 0) && ((kripke_->get_init_state())->compare(kr_s) == 0)
...@@ -393,7 +384,7 @@ namespace spot ...@@ -393,7 +384,7 @@ namespace spot
{ {
const state_ta_product* stp = down_cast<const state_ta_product*> (s); const state_ta_product* stp = down_cast<const state_ta_product*> (s);
assert(stp); assert(stp);
state* ta_s = stp->get_ta_state(); const state* ta_s = stp->get_ta_state();
return ta_->get_state_condition(ta_s); return ta_->get_state_condition(ta_s);
} }
......
...@@ -36,7 +36,7 @@ namespace spot ...@@ -36,7 +36,7 @@ namespace spot
/// \brief Constructor /// \brief Constructor
/// \param ta_state The state from the ta automaton. /// \param ta_state The state from the ta automaton.
/// \param kripke_state The state from Kripke structure. /// \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) ta_state_(ta_state), kripke_state_(kripke_state)
{ {
} }
...@@ -47,13 +47,13 @@ namespace spot ...@@ -47,13 +47,13 @@ namespace spot
virtual virtual
~state_ta_product(); ~state_ta_product();
state* const state*
get_ta_state() const get_ta_state() const
{ {
return ta_state_; return ta_state_;
} }
state* const state*
get_kripke_state() const get_kripke_state() const
{ {
return kripke_state_; return kripke_state_;
...@@ -67,8 +67,8 @@ namespace spot ...@@ -67,8 +67,8 @@ namespace spot
clone() const; clone() const;
private: private:
state* ta_state_; ///< State from the ta automaton. const state* ta_state_; ///< State from the ta automaton.
state* kripke_state_; ///< State from the kripke structure. const state* kripke_state_; ///< State from the kripke structure.
}; };
/// \brief Iterate over the successors of a product computed on the fly. /// \brief Iterate over the successors of a product computed on the fly.
...@@ -117,12 +117,12 @@ namespace spot ...@@ -117,12 +117,12 @@ namespace spot
const kripke* kripke_; const kripke* kripke_;
ta_succ_iterator* ta_succ_it_; ta_succ_iterator* ta_succ_it_;
twa_succ_iterator* kripke_succ_it_; twa_succ_iterator* kripke_succ_it_;
state_ta_product* current_state_; const state_ta_product* current_state_;
bdd current_condition_; bdd current_condition_;
acc_cond::mark_t current_acceptance_conditions_; acc_cond::mark_t current_acceptance_conditions_;
bool is_stuttering_transition_; bool is_stuttering_transition_;
bdd kripke_source_condition; bdd kripke_source_condition;
state * kripke_current_dest_state; const state* kripke_current_dest_state;
}; };
...@@ -141,7 +141,7 @@ namespace spot ...@@ -141,7 +141,7 @@ namespace spot
virtual virtual
~ta_product(); ~ta_product();
virtual const std::set<state*, state_ptr_less_than> virtual ta::const_states_set_t
get_initial_states_set() const; get_initial_states_set() const;
virtual ta_succ_iterator_product* virtual ta_succ_iterator_product*
......
...@@ -49,7 +49,7 @@ namespace spot ...@@ -49,7 +49,7 @@ namespace spot
{ {
} }
state* const state*
tgta_product::get_init_state() const tgta_product::get_init_state() const
{ {
fixed_size_pool* p = const_cast<fixed_size_pool*> (&pool_); fixed_size_pool* p = const_cast<fixed_size_pool*> (&pool_);
...@@ -79,7 +79,7 @@ namespace spot ...@@ -79,7 +79,7 @@ namespace spot
: source_(s), tgta_(t), kripke_(k), pool_(pool) : 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) if ((s->right())->compare(tgta_init_state) == 0)
source_ = nullptr; source_ = nullptr;
......
...@@ -35,8 +35,7 @@ namespace spot ...@@ -35,8 +35,7 @@ namespace spot
tgta_product(const const_kripke_ptr& left, tgta_product(const const_kripke_ptr& left,
const const_tgta_ptr& right); const const_tgta_ptr& right);
virtual state* virtual const state* get_init_state() const;
get_init_state() const;
virtual twa_succ_iterator* virtual twa_succ_iterator*
succ_iter(const state* local_state) const; succ_iter(const state* local_state) const;
...@@ -97,6 +96,6 @@ namespace spot ...@@ -97,6 +96,6 @@ namespace spot