diff --git a/src/kripke/kripkegraph.hh b/src/kripke/kripkegraph.hh index d145848fd..122d88bd6 100644 --- a/src/kripke/kripkegraph.hh +++ b/src/kripke/kripkegraph.hh @@ -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(g_).new_state(); - return const_cast(state_from_number(init_number_)); + return state_from_number(init_number_); } /// \brief Allow to get an iterator on the state we passed in diff --git a/src/ta/ta.cc b/src/ta/ta.cc index 17c62aff9..c8c825eb5 100644 --- a/src/ta/ta.cc +++ b/src/ta/ta.cc @@ -56,7 +56,7 @@ namespace spot s.emplace_front(index); } - std::list& + std::list& scc_stack_ta::rem() { return top().rem; diff --git a/src/ta/ta.hh b/src/ta/ta.hh index f2b8bdc04..e64ac465e 100644 --- a/src/ta/ta.hh +++ b/src/ta/ta.hh @@ -90,9 +90,10 @@ namespace spot } typedef std::set states_set_t; + typedef std::set 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 rem; + std::list 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& + std::list& rem(); /// Is the stack empty? diff --git a/src/ta/taexplicit.cc b/src/ta/taexplicit.cc index d70194145..796181746 100644 --- a/src/ta/taexplicit.cc +++ b/src/ta/taexplicit.cc @@ -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 >::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(*it); + auto* s = const_cast + (down_cast(*it)); s->free_transitions(); s->get_tgba_state()->destroy(); @@ -379,7 +376,7 @@ namespace spot std::pair add_state_to_ta = states_set_.insert(s); - return static_cast(*add_state_to_ta.first); + return down_cast(*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 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(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(s); + auto state = + const_cast(down_cast(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_; diff --git a/src/ta/taexplicit.hh b/src/ta/taexplicit.hh index 98cb0d6b6..38a222660 100644 --- a/src/ta/taexplicit.hh +++ b/src/ta/taexplicit.hh @@ -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 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_; diff --git a/src/ta/taproduct.cc b/src/ta/taproduct.cc index 60e90b0a9..dac0dd17a 100644 --- a/src/ta/taproduct.cc +++ b/src/ta/taproduct.cc @@ -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) - { + 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())); - 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); - } - - } - - kripke_init_state->destroy(); + kripke_init->destroy(); return initial_states_set; } @@ -369,8 +360,8 @@ namespace spot const state_ta_product* stp = down_cast (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 (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); } diff --git a/src/ta/taproduct.hh b/src/ta/taproduct.hh index 96ab85219..0db9c070d 100644 --- a/src/ta/taproduct.hh +++ b/src/ta/taproduct.hh @@ -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 + virtual ta::const_states_set_t get_initial_states_set() const; virtual ta_succ_iterator_product* diff --git a/src/ta/tgtaproduct.cc b/src/ta/tgtaproduct.cc index 16bfca601..8a444c405 100644 --- a/src/ta/tgtaproduct.cc +++ b/src/ta/tgtaproduct.cc @@ -49,7 +49,7 @@ namespace spot { } - state* + const state* tgta_product::get_init_state() const { fixed_size_pool* p = const_cast (&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; diff --git a/src/ta/tgtaproduct.hh b/src/ta/tgtaproduct.hh index 182233171..3429a6594 100644 --- a/src/ta/tgtaproduct.hh +++ b/src/ta/tgtaproduct.hh @@ -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; }; } diff --git a/src/taalgos/dot.cc b/src/taalgos/dot.cc index ed5bc8124..65237b1a3 100644 --- a/src/taalgos/dot.cc +++ b/src/taalgos/dot.cc @@ -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; diff --git a/src/taalgos/emptinessta.cc b/src/taalgos/emptinessta.cc index 08ba135ac..11d8b97c1 100644 --- a/src/taalgos/emptinessta.cc +++ b/src/taalgos/emptinessta.cc @@ -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 rem; + std::list rem; bool acc = false; trace << "***PASS 1: CYCLE***\n"; @@ -393,21 +392,17 @@ namespace spot std::stack todo; // * init: the set of the depth-first search initial states - std::queue ta_init_it_; + std::queue 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 rem; + std::list rem; bool acc = false; while (threshold < sscc.top().index) @@ -578,7 +568,7 @@ namespace spot void ta_check::clear(hash_type& h, std::stack todo, - std::queue init_states) + std::queue init_states) { set_states(states() + h.size()); diff --git a/src/taalgos/emptinessta.hh b/src/taalgos/emptinessta.hh index db451f1e2..cd2e4e63b 100644 --- a/src/taalgos/emptinessta.hh +++ b/src/taalgos/emptinessta.hh @@ -33,7 +33,8 @@ namespace spot namespace { - typedef std::pair pair_state_iter; + typedef std::pair pair_state_iter; } /// \addtogroup ta_emptiness_check Emptiness-checks @@ -127,7 +128,7 @@ namespace spot protected: void clear(hash_type& h, std::stack todo, std::queue< - spot::state*> init_set); + const spot::state*> init_set); void clear(hash_type& h, std::stack todo, diff --git a/src/taalgos/minimize.cc b/src/taalgos/minimize.cc index c0bdf0d5c..cd5daf939 100644 --- a/src/taalgos/minimize.cc +++ b/src/taalgos/minimize.cc @@ -230,8 +230,7 @@ namespace spot std::set::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) { diff --git a/src/taalgos/reachiter.cc b/src/taalgos/reachiter.cc index 86ecd1056..1ec9b72ee 100644 --- a/src/taalgos/reachiter.cc +++ b/src/taalgos/reachiter.cc @@ -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; if (artificial_initial_state) { @@ -66,13 +64,11 @@ namespace spot init_states_set = t_automata_->get_initial_states_set(); } - for (it = init_states_set.begin(); it != init_states_set.end(); ++it) + for (auto init_state: init_states_set) { - state* init_state = (*it); if (want_state(init_state)) add_state(init_state); seen[init_state] = ++n; - } const state* t; diff --git a/src/taalgos/tgba2ta.cc b/src/taalgos/tgba2ta.cc index eb629a1eb..bf6bc6557 100644 --- a/src/taalgos/tgba2ta.cc +++ b/src/taalgos/tgba2ta.cc @@ -42,7 +42,7 @@ namespace spot namespace { - typedef std::pair pair_state_iter; + typedef std::pair pair_state_iter; static void transform_to_single_pass_automaton @@ -52,7 +52,7 @@ namespace spot if (artificial_livelock_acc_state) { - state_ta_explicit* artificial_livelock_acc_state_added = + auto artificial_livelock_acc_state_added = testing_automata->add_state(artificial_livelock_acc_state); // unique artificial_livelock_acc_state @@ -71,7 +71,8 @@ namespace spot for (it = states_set.begin(); it != states_set.end(); ++it) { - state_ta_explicit* source = static_cast (*it); + auto source = const_cast + (static_cast(*it)); transitions_to_livelock_states->clear(); @@ -81,10 +82,10 @@ namespace spot if (trans) for (it_trans = trans->begin(); it_trans != trans->end();) { - state_ta_explicit* dest = (*it_trans)->dest; + auto dest = const_cast((*it_trans)->dest); state_ta_explicit::transitions* dest_trans = - (dest)->get_transitions(); + dest->get_transitions(); bool dest_trans_empty = !dest_trans || dest_trans->empty(); //select transitions where a destination is a livelock state @@ -175,9 +176,9 @@ namespace spot std::stack todo; // * init: the set of the depth-first search initial states - std::stack init_set; + std::stack init_set; - for (state* s: testing_aut->get_initial_states_set()) + for (auto s: testing_aut->get_initial_states_set()) init_set.push(s); while (!init_set.empty()) @@ -185,8 +186,7 @@ namespace spot // Setup depth-first search from initial states. { - state_ta_explicit* init = - down_cast (init_set.top()); + auto init = down_cast (init_set.top()); init_set.pop(); if (!h.emplace(init, num + 1).second) @@ -206,7 +206,7 @@ namespace spot while (!todo.empty()) { - state* curr = todo.top().first; + auto curr = todo.top().first; auto i = h.find(curr); // If we have reached a dead component, ignore it. @@ -254,8 +254,9 @@ namespace spot trace << "*** sscc.size() > 1: states: ***" << testing_aut->format_state(j) << '\n'; - state_ta_explicit* livelock_accepting_state = - down_cast(j); + auto livelock_accepting_state = + const_cast + (down_cast(j)); livelock_accepting_state-> set_livelock_accepting_state(true); @@ -285,7 +286,7 @@ namespace spot } // Fetch the values destination state we are interested in... - state* dest = succ->dst(); + auto dest = succ->dst(); auto acc_cond = succ->acc(); // ... and point the iterator to the next successor, for @@ -332,8 +333,8 @@ namespace spot if (!curr->compare(id->first)) { - state_ta_explicit * self_loop_state = - down_cast (curr); + auto self_loop_state = const_cast + (down_cast(curr)); assert(self_loop_state); if (testing_aut->is_accepting_state(self_loop_state) @@ -365,7 +366,7 @@ namespace spot // top of ROOT that have an index greater to the one of // the SSCC of S2 (called the "threshold"). int threshold = id->second; - std::list rem; + std::list rem; bool acc = false; while (threshold < sscc.top().index) @@ -412,7 +413,7 @@ namespace spot const_twa_ptr tgba_ = ta->get_tgba(); // build Initial states set: - state* tgba_init_state = tgba_->get_init_state(); + auto tgba_init_state = tgba_->get_init_state(); bdd tgba_condition = tgba_->support_conditions(tgba_init_state); @@ -546,7 +547,7 @@ namespace spot { ta_explicit_ptr ta; - state* tgba_init_state = tgba_->get_init_state(); + auto tgba_init_state = tgba_->get_init_state(); if (artificial_initial_state_mode) { state_ta_explicit* artificial_init_state = @@ -597,7 +598,7 @@ namespace spot tgta_explicit_ptr tgba_to_tgta(const const_twa_ptr& tgba_, bdd atomic_propositions_set_) { - state* tgba_init_state = tgba_->get_init_state(); + auto tgba_init_state = tgba_->get_init_state(); auto artificial_init_state = new state_ta_explicit(tgba_init_state->clone(), bddfalse, true); tgba_init_state->destroy(); diff --git a/src/twa/twa.hh b/src/twa/twa.hh index 0407fa4c6..87f2165bc 100644 --- a/src/twa/twa.hh +++ b/src/twa/twa.hh @@ -385,7 +385,7 @@ namespace spot /// /// The returned state should be destroyed (see state::destroy) /// by the caller after it is no longer used. - virtual state* dst() const = 0; + virtual const state* dst() const = 0; /// \brief Get the condition on the transition leading to this successor. /// /// This is a boolean function of atomic propositions. @@ -531,7 +531,7 @@ namespace spot /// The state has been allocated with \c new. It is the /// responsability of the caller to \c destroy it when no /// longer needed. - virtual state* get_init_state() const = 0; + virtual const state* get_init_state() const = 0; /// \brief Get an iterator over the successors of \a local_state. /// diff --git a/src/twa/twagraph.hh b/src/twa/twagraph.hh index 2b216c582..3ce5129ef 100644 --- a/src/twa/twagraph.hh +++ b/src/twa/twagraph.hh @@ -143,11 +143,10 @@ namespace spot return !p_; } - virtual twa_graph_state* dst() const + virtual const twa_graph_state* dst() const { assert(!done()); - return const_cast - (&g_->state_data(g_->edge_storage(p_).dst)); + return &g_->state_data(g_->edge_storage(p_).dst); } virtual bdd cond() const @@ -266,12 +265,11 @@ namespace spot return init_number_; } - // FIXME: The return type ought to be const. - virtual twa_graph_state* get_init_state() const + virtual const twa_graph_state* get_init_state() const { if (num_states() == 0) const_cast(g_).new_state(); - return const_cast(state_from_number(init_number_)); + return state_from_number(init_number_); } virtual twa_succ_iterator* diff --git a/src/twa/twaproduct.cc b/src/twa/twaproduct.cc index 983aa6e7b..b9ba03b4e 100644 --- a/src/twa/twaproduct.cc +++ b/src/twa/twaproduct.cc @@ -130,7 +130,7 @@ namespace spot return !right_ || right_->done(); } - state_product* dst() const + const state_product* dst() const { return new(pool_->allocate()) state_product(left_->dst(), right_->dst(), @@ -330,7 +330,7 @@ namespace spot } } - state* + const state* twa_product::get_init_state() const { fixed_size_pool* p = const_cast(&pool_); @@ -434,7 +434,7 @@ namespace spot std::swap(left_init_, right_init_); } - state* + const state* twa_product_init::get_init_state() const { fixed_size_pool* p = const_cast(&pool_); diff --git a/src/twa/twaproduct.hh b/src/twa/twaproduct.hh index 72855f2cd..1e0316eea 100644 --- a/src/twa/twaproduct.hh +++ b/src/twa/twaproduct.hh @@ -42,20 +42,22 @@ namespace spot /// \param pool The pool from which the state was allocated. /// These states are acquired by spot::state_product, and will /// be destroyed on destruction. - state_product(state* left, state* right, fixed_size_pool* pool) + state_product(const state* left, + const state* right, + fixed_size_pool* pool) : left_(left), right_(right), count_(1), pool_(pool) { } virtual void destroy() const; - state* + const state* left() const { return left_; } - state* + const state* right() const { return right_; @@ -66,8 +68,8 @@ namespace spot virtual state_product* clone() const; private: - state* left_; ///< State from the left automaton. - state* right_; ///< State from the right automaton. + const state* left_; ///< State from the left automaton. + const state* right_; ///< State from the right automaton. mutable unsigned count_; fixed_size_pool* pool_; @@ -88,7 +90,7 @@ namespace spot virtual ~twa_product(); - virtual state* get_init_state() const; + virtual const state* get_init_state() const; virtual twa_succ_iterator* succ_iter(const state* state) const; @@ -124,7 +126,7 @@ namespace spot public: twa_product_init(const const_twa_ptr& left, const const_twa_ptr& right, const state* left_init, const state* right_init); - virtual state* get_init_state() const; + virtual const state* get_init_state() const; protected: const state* left_init_; const state* right_init_; diff --git a/src/twaalgos/compsusp.cc b/src/twaalgos/compsusp.cc index 9d3d51b72..b2e460276 100644 --- a/src/twaalgos/compsusp.cc +++ b/src/twaalgos/compsusp.cc @@ -178,7 +178,7 @@ namespace spot pair_queue todo; state_pair p(left->get_init_state(), nullptr); - state* ris = right->get_init_state(); + const state* ris = right->get_init_state(); p.second = ris; unsigned i = res->new_state(); seen[p] = i; diff --git a/src/twaalgos/gtec/gtec.cc b/src/twaalgos/gtec/gtec.cc index 743356430..0537a9d5b 100644 --- a/src/twaalgos/gtec/gtec.cc +++ b/src/twaalgos/gtec/gtec.cc @@ -108,7 +108,7 @@ namespace spot { inc_transitions(); - state* s = i->dst(); + const state* s = i->dst(); auto j = ecs_->h.find(s); assert(j != ecs_->h.end()); s->destroy(); @@ -158,7 +158,7 @@ namespace spot // Setup depth-first search from the initial state. { - state* init = ecs_->aut->get_init_state(); + const state* init = ecs_->aut->get_init_state(); ecs_->h[init] = 1; ecs_->root.push(1); arc.push(0U); diff --git a/src/twaalgos/ltl2tgba_fm.cc b/src/twaalgos/ltl2tgba_fm.cc index 54691b654..63678e24c 100644 --- a/src/twaalgos/ltl2tgba_fm.cc +++ b/src/twaalgos/ltl2tgba_fm.cc @@ -1235,7 +1235,7 @@ namespace spot for (auto i: aut->succ(st)) { bdd label = i->cond(); - state* s = i->dst(); + const state* s = i->dst(); formula dest = namer->get_name(aut->state_number(s)); @@ -1280,7 +1280,7 @@ namespace spot for (auto i: aut->succ(st)) { bdd label = i->cond(); - state* s = i->dst(); + const state* s = i->dst(); formula dest = namer->get_name(aut->state_number(s)); missing -= label; diff --git a/src/twaalgos/reachiter.cc b/src/twaalgos/reachiter.cc index d32d3185d..a8111e6b4 100644 --- a/src/twaalgos/reachiter.cc +++ b/src/twaalgos/reachiter.cc @@ -50,7 +50,7 @@ namespace spot { int n = 0; start(); - state* i = aut_->get_init_state(); + const state* i = aut_->get_init_state(); if (want_state(i)) add_state(i); seen[i] = ++n; @@ -188,7 +188,7 @@ namespace spot { int n = 1; start(); - state* i = aut_->get_init_state(); + const state* i = aut_->get_init_state(); if (want_state(i)) push(i, n); seen[i] = n++; diff --git a/src/twaalgos/stutter.cc b/src/twaalgos/stutter.cc index 3d0f010dc..dfc469b9f 100644 --- a/src/twaalgos/stutter.cc +++ b/src/twaalgos/stutter.cc @@ -43,7 +43,7 @@ namespace spot class state_tgbasl: public state { public: - state_tgbasl(state* s, bdd cond) : s_(s), cond_(cond) + state_tgbasl(const state* s, bdd cond) : s_(s), cond_(cond) { } @@ -77,7 +77,7 @@ namespace spot return new state_tgbasl(*this); } - state* + const state* real_state() const { return s_; @@ -90,7 +90,7 @@ namespace spot } private: - state* s_; + const state* s_; bdd cond_; }; @@ -220,7 +220,7 @@ namespace spot get_dict()->unregister_all_my_variables(this); } - virtual state* get_init_state() const override + virtual const state* get_init_state() const override { return new state_tgbasl(a_->get_init_state(), bddfalse); }