Commit 1a5c0cb1 authored by Alexandre Duret-Lutz's avatar Alexandre Duret-Lutz
Browse files

tgba_succ_iterator: have first() and next() return a bool

The returned Boolean indicates whether there is a successor or not.
This way

|  for (i->first(); !i->done(); i->next())
|    {
|       ...
|    }

can be replaced by

| if (i->first()) do
|   {
|      ...
|   }
| while (i->next());

avoiding all the virtual calls to done().

* iface/dve2/dve2.cc, src/kripke/kripkeexplicit.cc,
src/kripke/kripkeexplicit.hh, 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/tgba/succiter.hh,
src/tgba/succiterconcrete.cc, src/tgba/succiterconcrete.hh,
src/tgba/taatgba.cc, src/tgba/taatgba.hh, src/tgba/tgba.hh,
src/tgba/tgbaexplicit.hh, src/tgba/tgbakvcomplement.cc,
src/tgba/tgbamask.cc, src/tgba/tgbaproduct.cc,
src/tgba/tgbasafracomplement.cc, src/tgba/tgbasgba.cc,
src/tgba/tgbatba.cc, src/tgba/tgbaunion.cc, src/tgba/tgbaunion.hh,
src/tgba/wdbacomp.cc: Implement and adjust to this new interface.
parent 06c69f88
......@@ -272,15 +272,17 @@ namespace spot
}
virtual
void first()
bool first()
{
it_ = cc_->transitions.begin();
return it_ != cc_->transitions.end();
}
virtual
void next()
bool next()
{
++it_;
return it_ != cc_->transitions.end();
}
virtual
......
......@@ -99,14 +99,16 @@ namespace spot
{
}
void kripke_explicit_succ_iterator::first()
bool kripke_explicit_succ_iterator::first()
{
it_ = s_->get_succ().begin();
return it_ != s_->get_succ().end();
}
void kripke_explicit_succ_iterator::next()
bool kripke_explicit_succ_iterator::next()
{
++it_;
return it_ != s_->get_succ().end();
}
bool kripke_explicit_succ_iterator::done() const
......
// -*- coding: utf-8 -*-
// Copyright (C) 2011, 2012, 2013 Laboratoire de Recherche et
// Copyright (C) 2011, 2012, 2013, 2014 Laboratoire de Recherche et
// Développement de l'Epita (LRDE)
//
// This file is part of Spot, a model checking library.
......@@ -97,8 +97,8 @@ namespace spot
~kripke_explicit_succ_iterator();
virtual void first();
virtual void next();
virtual bool first();
virtual bool next();
virtual bool done() const;
virtual state_kripke* current_state() const;
......
// -*- coding: utf-8 -*-
// Copyright (C) 2010, 2012, 2013 Laboratoire de Recherche et
// Copyright (C) 2010, 2012, 2013, 2014 Laboratoire de Recherche et
// Developpement de l Epita (LRDE).
//
// This file is part of Spot, a model checking library.
......@@ -191,12 +191,9 @@ namespace spot
{
}
virtual void
first() = 0;
virtual void
next() = 0;
virtual bool
done() const = 0;
virtual bool first() = 0;
virtual bool next() = 0;
virtual bool done() const = 0;
virtual state*
current_state() const = 0;
......
// -*- coding: utf-8 -*-
// Copyright (C) 2010, 2011, 2012, 2013 Laboratoire de Recherche et
// Développement de l'Epita (LRDE).
// Copyright (C) 2010, 2011, 2012, 2013, 2014 Laboratoire de Recherche
// et Développement de l'Epita (LRDE).
//
// This file is part of Spot, a model checking library.
//
......@@ -54,24 +54,26 @@ namespace spot
transitions_ = s->get_transitions(condition);
}
void
bool
ta_explicit_succ_iterator::first()
{
if (transitions_ != 0)
i_ = transitions_->begin();
if (!transitions_)
return false;
i_ = transitions_->begin();
return i_ != transitions_->end();
}
void
bool
ta_explicit_succ_iterator::next()
{
++i_;
return i_ != transitions_->end();
}
bool
ta_explicit_succ_iterator::done() const
{
return transitions_ == 0 || transitions_->empty() || i_
== transitions_->end();
return !transitions_ || i_ == transitions_->end();
}
state*
......
// -*- coding: utf-8 -*-
// Copyright (C) 2010, 2011, 2012, 2013 Laboratoire de Recherche et
// Développement de l'Epita (LRDE).
// Copyright (C) 2010, 2011, 2012, 2013, 2014 Laboratoire de Recherche
// et Développement de l'Epita (LRDE).
//
// This file is part of Spot, a model checking library.
//
......@@ -248,12 +248,9 @@ namespace spot
ta_explicit_succ_iterator(const state_ta_explicit* s, bdd condition);
virtual void
first();
virtual void
next();
virtual bool
done() const;
virtual bool first();
virtual bool next();
virtual bool done() const;
virtual state*
current_state() const;
......
// -*- coding: utf-8 -*-
// Copyright (C) 2011, 2012 Laboratoire de Recherche et Développement
// Copyright (C) 2011, 2012, 2014 Laboratoire de Recherche et Développement
// de l'Epita (LRDE).
//
//
......@@ -150,17 +150,18 @@ namespace spot
}
void
bool
ta_succ_iterator_product::first()
{
next_kripke_dest();
if (!done())
next_non_stuttering_();
return next_non_stuttering_();
return false;
}
void
bool
ta_succ_iterator_product::next()
{
delete current_state_;
......@@ -173,11 +174,11 @@ namespace spot
step_();
if (!done())
next_non_stuttering_();
return next_non_stuttering_();
return false;
}
void
bool
ta_succ_iterator_product::next_non_stuttering_()
{
......@@ -190,7 +191,7 @@ namespace spot
current_state_ = new state_ta_product(source_->get_ta_state(),
kripke_current_dest_state->clone());
current_acceptance_conditions_ = bddfalse;
return;
return true;
}
if (!ta_succ_it_->done())
......@@ -199,11 +200,12 @@ namespace spot
kripke_current_dest_state->clone());
current_acceptance_conditions_
= ta_succ_it_->current_acceptance_conditions();
return;
return true;
}
step_();
}
return false;
}
bool
......
// -*- coding: utf-8 -*-
// Copyright (C) 2011, 2012, 2013 Laboratoire de Recherche et
// Copyright (C) 2011, 2012, 2013, 2014 Laboratoire de Recherche et
// Développement de l'Epita (LRDE).
//
// This file is part of Spot, a model checking library.
......@@ -83,12 +83,9 @@ namespace spot
~ta_succ_iterator_product();
// iteration
void
first();
void
next();
bool
done() const;
bool first();
bool next();
bool done() const;
// inspection
state_ta_product*
......@@ -106,10 +103,8 @@ namespace spot
protected:
//@{
/// Internal routines to advance to the next successor.
void
step_();
void
next_non_stuttering_();
void step_();
bool next_non_stuttering_();
/// \brief Move to the next successor in the kripke structure
void
......
// -*- coding: utf-8 -*-
// Copyright (C) 2012 Laboratoire de Recherche et Developpement
// Copyright (C) 2012, 2014 Laboratoire de Recherche et Développement
// de l Epita (LRDE).
//
// This file is part of Spot, a model checking library.
......@@ -173,19 +173,16 @@ namespace spot
}
void
bool
tgta_succ_iterator_product::first()
{
next_kripke_dest();
trace
<< "*** first() .... if(done()) = ***" << done() << std::endl;
if (!done())
find_next_succ_();
trace << "*** first() .... if(done()) = ***" << done() << std::endl;
return find_next_succ_();
}
void
bool
tgta_succ_iterator_product::next()
{
current_state_->destroy();
......@@ -193,18 +190,14 @@ namespace spot
step_();
trace
<< "*** next() .... if(done()) = ***" << done() << std::endl;
if (!done())
find_next_succ_();
trace << "*** next() .... if(done()) = ***" << done() << std::endl;
return find_next_succ_();
}
void
bool
tgta_succ_iterator_product::find_next_succ_()
{
while (!done())
{
if (!tgta_succ_it_->done())
......@@ -214,11 +207,12 @@ namespace spot
tgta_succ_it_->current_state(), pool_);
current_acceptance_conditions_
= tgta_succ_it_->current_acceptance_conditions();
return;
return true;
}
step_();
}
return false;
}
bool
......
// -*- coding: utf-8 -*-
// Copyright (C) 2011, 2012, 2013 Laboratoire de Recherche et Développement
// de l'Epita (LRDE).
// Copyright (C) 2011, 2012, 2013, 2014 Laboratoire de Recherche et
// Développement de l'Epita (LRDE).
//
// This file is part of Spot, a model checking library.
//
......@@ -54,12 +54,9 @@ namespace spot
~tgta_succ_iterator_product();
// iteration
void
first();
void
next();
bool
done() const;
bool first();
bool next();
bool done() const;
// inspection
state_product*
......@@ -75,8 +72,7 @@ namespace spot
/// Internal routines to advance to the next successor.
void
step_();
void
find_next_succ_();
bool find_next_succ_();
void
next_kripke_dest();
......
......@@ -53,17 +53,21 @@ namespace spot
/// This method can be called several times to make multiple
/// passes over successors.
///
/// \warning One should always call \c done() to
/// ensure there is a successor, even after \c first(). A
/// common trap is to assume that there is at least one
/// successor: this is wrong.
virtual void first() = 0;
/// \warning One should always call \c done() (or better: check
/// the return value of first()) to ensure there is a successor,
/// even after \c first(). A common trap is to assume that there
/// is at least one successor: this is wrong.
///
/// \return whether there is actually a successor
virtual bool first() = 0;
/// \brief Jump to the next successor (if any).
///
/// \warning Again, one should always call \c done() to ensure
/// there is a successor.
virtual void next() = 0;
/// \warning Again, one should always call \c done() (or better:
/// check the return value of next()) ensure there is a successor.
///
/// \return whether there is actually a successor
virtual bool next() = 0;
/// \brief Check whether the iteration is finished.
///
......@@ -132,8 +136,7 @@ namespace spot
void operator++()
{
it_->next();
if (it_->done())
if (!it_->next())
it_ = nullptr;
}
};
......
......@@ -29,16 +29,18 @@ namespace spot
{
}
void
bool
tgba_succ_iterator_concrete::first()
{
succ_set_left_ = succ_set_;
current_ = bddfalse;
if (!done())
next();
return next();
else
return false;
}
void
bool
tgba_succ_iterator_concrete::next()
{
assert(!done());
......@@ -86,7 +88,7 @@ namespace spot
succ_set_left_ -= current_;
if (succ_set_left_ == bddfalse) // No more successors?
return;
return false;
// Pick one transition, and extract its destination.
bdd trans = bdd_satoneset(succ_set_left_, data_.next_set,
......@@ -157,6 +159,8 @@ namespace spot
current_state_ = bdd_replace(dest, data_.dict->next_to_now);
}
while ((current_state_ & data_.relation) == bddfalse);
return succ_set_left_ != bddfalse;
}
bool
......
......@@ -61,8 +61,8 @@ namespace spot
virtual ~tgba_succ_iterator_concrete();
// iteration
void first();
void next();
bool first();
bool next();
bool done() const;
// inspection
......
// -*- coding: utf-8 -*-
// Copyright (C) 2009, 2010, 2011, 2012, 2013 Laboratoire de Recherche
// et Développement de l'Epita (LRDE)
// Copyright (C) 2009, 2010, 2011, 2012, 2013, 2014 Laboratoire de
// Recherche et Développement de l'Epita (LRDE)
//
// This file is part of Spot, a model checking library.
//
......@@ -315,16 +315,18 @@ namespace spot
}
}
void
bool
taa_succ_iterator::first()
{
i_ = succ_.begin();
return i_ != succ_.end();
}
void
bool
taa_succ_iterator::next()
{
++i_;
return i_ != succ_.end();
}
bool
......
......@@ -113,8 +113,8 @@ namespace spot
taa_succ_iterator(const taa_tgba::state_set* s, bdd all_acc);
virtual ~taa_succ_iterator();
virtual void first();
virtual void next();
virtual bool first();
virtual bool next();
virtual bool done() const;
virtual set_state* current_state() const;
......
......@@ -102,8 +102,7 @@ namespace spot
internal::succ_iterator begin()
{
it_->first();
return it_->done() ? nullptr : it_;
return it_->first() ? it_ : nullptr;
}
internal::succ_iterator end()
......
......@@ -208,14 +208,16 @@ namespace spot
all_acceptance_conditions_ = all_acc;
}
virtual void first()
virtual bool first()
{
it_ = start_->successors.begin();
return it_ != start_->successors.end();
}
virtual void next()
virtual bool next()
{
++it_;
return it_ != start_->successors.end();
}
virtual bool done() const
......
......@@ -258,8 +258,8 @@ namespace spot
const state_kv_complement* origin);
virtual ~tgba_kv_complement_succ_iterator() {};
virtual void first();
virtual void next();
virtual bool first();
virtual bool next();
virtual bool done() const;
virtual state_kv_complement* current_state() const;
virtual bdd current_condition() const;
......@@ -470,24 +470,25 @@ namespace spot
current_ranks_ = highest_current_ranks_;
}
void
bool
tgba_kv_complement_succ_iterator::first()
{
current_condition_ = condition_list_.begin();
if (done())
return;
if (current_condition_ == condition_list_.end())
return false;
successor_highest_rank(*current_condition_);
if (!is_valid_rank())
next_valid_rank();
return current_condition_ != condition_list_.end();
}
void
bool
tgba_kv_complement_succ_iterator::next()
{
if (done())
return;
if (current_condition_ == condition_list_.end())
return false;
if (!next_valid_rank())
{
......@@ -499,12 +500,13 @@ namespace spot
next_valid_rank();
}
}
return current_condition_ != condition_list_.end();
}
bool
tgba_kv_complement_succ_iterator::done() const
{
return (current_condition_ == condition_list_.end());
return current_condition_ == condition_list_.end();
}
state_kv_complement*
......
......@@ -40,14 +40,16 @@ namespace spot
t.dest->destroy();
}
void first()
bool first()
{
it_ = trans_.begin();
return it_ != trans_.end();
}
virtual void next()
bool next()
{
++it_;
return it_ != trans_.end();
}
bool done() const
......
......@@ -104,26 +104,24 @@ namespace spot
delete right_;
}
virtual void next_non_false_() = 0;
virtual bool next_non_false_() = 0;
void first()
bool first()
{
if (!right_)
return;
return false;
left_->first();
right_->first();
// If one of the two successor sets is empty initially, we
// reset right_, so that done() can detect this situation
// easily. (We choose to reset right_ because this variable
// is already used by done().)
if (left_->done() || right_->done())
if (!(left_->first() && right_->first()))
{
delete right_;
right_ = 0;
return;
return false;
}
next_non_false_();
return next_non_false_();
}
bool done() const
......@@ -166,19 +164,18 @@ namespace spot
{
}
void step_()
bool step_()
{
left_->next();
if (left_->done())
{