Rework the 'down_cast' macro, closing #196.

* spot/misc/casts.hh: New inline functions and compile-time checks.
* spot/kripke/kripkegraph.hh, spot/ta/taexplicit.cc,
  spot/ta/taproduct.cc, spot/ta/tgtaproduct.cc, spot/taalgos/tgba2ta.cc,
  spot/twa/taatgba.hh, spot/twa/taatgba.cc, spot/twa/twagraph.hh,
  spot/twa/twaproduct.cc, spot/twaalgos/emptiness.cc,
  spot/twaalgos/stutter.cc, spot/ltsmin/ltsmin.cc, tests/core/ikwiad.cc,
  tests/core/ngraph.cc: Remove downcast checks from code.
This commit is contained in:
Maximilien Colange 2017-02-01 17:50:01 +01:00
parent 07a76e4d93
commit 3f5470898d
15 changed files with 143 additions and 89 deletions

View file

@ -1,6 +1,6 @@
// -*- coding: utf-8 -*-
// Copyright (C) 2010, 2011, 2012, 2013, 2014, 2015, 2016 Laboratoire
// de Recherche et Développement de l'Epita (LRDE).
// Copyright (C) 2010-2017 Laboratoire de Recherche et Développement de
// l'Epita (LRDE).
//
// This file is part of Spot, a model checking library.
//
@ -230,7 +230,6 @@ namespace spot
state_ta_explicit::compare(const spot::state* other) const
{
const state_ta_explicit* o = down_cast<const state_ta_explicit*>(other);
assert(o);
int compare_value = tgba_state_->compare(o->tgba_state_);
@ -362,7 +361,6 @@ namespace spot
{
auto* s = const_cast<state_ta_explicit*>
(down_cast<const state_ta_explicit*>(*it));
assert(s);
s->free_transitions();
s->get_tgba_state()->destroy();
delete s;
@ -383,7 +381,6 @@ namespace spot
ta_explicit::add_to_initial_states_set(state* state, bdd condition)
{
state_ta_explicit* s = down_cast<state_ta_explicit*>(state);
assert(s);
s->set_initial_state(true);
if (condition == bddfalse)
condition = get_state_condition(s);
@ -402,7 +399,6 @@ namespace spot
{
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())
add_to_initial_states_set(state);
@ -435,7 +431,6 @@ namespace spot
{
const state_ta_explicit* sta =
down_cast<const state_ta_explicit*>(initial_state);
assert(sta);
return sta->get_tgba_condition();
}
@ -443,7 +438,6 @@ namespace spot
ta_explicit::is_accepting_state(const spot::state* s) const
{
const state_ta_explicit* sta = down_cast<const state_ta_explicit*>(s);
assert(sta);
return sta->is_accepting_state();
}
@ -451,7 +445,6 @@ namespace spot
ta_explicit::is_initial_state(const spot::state* s) const
{
const state_ta_explicit* sta = down_cast<const state_ta_explicit*>(s);
assert(sta);
return sta->is_initial_state();
}
@ -459,7 +452,6 @@ namespace spot
ta_explicit::is_livelock_accepting_state(const spot::state* s) const
{
const state_ta_explicit* sta = down_cast<const state_ta_explicit*>(s);
assert(sta);
return sta->is_livelock_accepting_state();
}
@ -467,7 +459,6 @@ namespace spot
ta_explicit::succ_iter(const spot::state* state) const
{
const state_ta_explicit* s = down_cast<const state_ta_explicit*>(state);
assert(s);
return new ta_explicit_succ_iterator(s);
}
@ -475,7 +466,6 @@ namespace spot
ta_explicit::succ_iter(const spot::state* state, bdd condition) const
{
const state_ta_explicit* s = down_cast<const state_ta_explicit*>(state);
assert(s);
return new ta_explicit_succ_iterator(s, condition);
}
@ -495,7 +485,6 @@ namespace spot
ta_explicit::format_state(const spot::state* s) const
{
const state_ta_explicit* sta = down_cast<const state_ta_explicit*>(s);
assert(sta);
if (sta->get_tgba_condition() == bddtrue)
return tgba_->format_state(sta->get_tgba_state());

View file

@ -1,6 +1,6 @@
// -*- coding: utf-8 -*-
// Copyright (C) 2011, 2012, 2014, 2015, 2016 Laboratoire de Recherche
// et Développement de l'Epita (LRDE).
// Copyright (C) 2011, 2012, 2014-2017 Laboratoire de Recherche et
// Développement de l'Epita (LRDE).
//
//
// This file is part of Spot, a model checking library.
@ -38,7 +38,6 @@ namespace spot
state_ta_product::compare(const state* other) const
{
const state_ta_product* o = down_cast<const state_ta_product*> (other);
assert(o);
int res = ta_state_->compare(o->get_ta_state());
if (res != 0)
return res;
@ -298,7 +297,6 @@ namespace spot
ta_product::succ_iter(const state* s) const
{
const state_ta_product* stp = down_cast<const state_ta_product*>(s);
assert(stp);
return new ta_succ_iterator_product(stp, ta_.get(), kripke_.get());
}
@ -307,7 +305,6 @@ namespace spot
ta_product::succ_iter(const spot::state* s, bdd changeset) const
{
const state_ta_product* stp = down_cast<const state_ta_product*>(s);
assert(stp);
return new ta_succ_iterator_product_by_changeset(stp,
ta_.get(), kripke_.get(),
changeset);
@ -324,7 +321,6 @@ namespace spot
ta_product::format_state(const state* state) const
{
const state_ta_product* s = down_cast<const state_ta_product*> (state);
assert(s);
return kripke_->format_state(s->get_kripke_state()) + " * \n"
+ ta_->format_state(s->get_ta_state());
}
@ -333,8 +329,6 @@ namespace spot
ta_product::is_accepting_state(const spot::state* s) const
{
const state_ta_product* stp = down_cast<const state_ta_product*> (s);
assert(stp);
return ta_->is_accepting_state(stp->get_ta_state());
}
@ -342,8 +336,6 @@ namespace spot
ta_product::is_livelock_accepting_state(const spot::state* s) const
{
const state_ta_product* stp = down_cast<const state_ta_product*> (s);
assert(stp);
return ta_->is_livelock_accepting_state(stp->get_ta_state());
}
@ -351,7 +343,6 @@ namespace spot
ta_product::is_initial_state(const spot::state* s) const
{
const state_ta_product* stp = down_cast<const state_ta_product*> (s);
assert(stp);
const state* ta_s = stp->get_ta_state();
const state* kr_s = stp->get_kripke_state();
@ -366,7 +357,6 @@ namespace spot
ta_product::is_hole_state_in_ta_component(const spot::state* s) const
{
const state_ta_product* stp = down_cast<const state_ta_product*> (s);
assert(stp);
ta_succ_iterator* ta_succ_iter = get_ta()->succ_iter(stp->get_ta_state());
bool is_hole_state = ta_succ_iter->done();
delete ta_succ_iter;
@ -377,7 +367,6 @@ namespace spot
ta_product::get_state_condition(const spot::state* s) const
{
const state_ta_product* stp = down_cast<const state_ta_product*> (s);
assert(stp);
const state* ta_s = stp->get_ta_state();
return ta_->get_state_condition(ta_s);
}
@ -387,7 +376,6 @@ namespace spot
{
const state_ta_product* stp = down_cast<const state_ta_product*> (s);
assert(stp);
ta_->free_state(stp->get_ta_state());
delete stp;

View file

@ -1,6 +1,6 @@
// -*- coding: utf-8 -*-
// Copyright (C) 2012, 2014, 2015 Laboratoire de Recherche et
// Développement de l Epita (LRDE).
// Copyright (C) 2012, 2014-2017 Laboratoire de Recherche et Développement de
// l Epita (LRDE).
//
// This file is part of Spot, a model checking library.
//
@ -61,7 +61,6 @@ namespace spot
tgta_product::succ_iter(const state* state) const
{
const state_product* s = down_cast<const state_product*> (state);
assert(s);
fixed_size_pool* p = const_cast<fixed_size_pool*> (&pool_);