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

Use downcast when appropriate.

* src/taalgos/sba2ta.cc, src/ta/ta.cc, src/ta/taexplicit.cc,
src/ta/taproduct.cc, src/taalgos/emptinessta.cc: Use downcast
and cleanup whitespace.
parent bf01501e
// Copyright (C) 2010 Laboratoire de Recherche et Developpement
// Copyright (C) 2010, 2011 Laboratoire de Recherche et Developpement
// de l Epita (LRDE).
//
// This file is part of Spot, a model checking library.
......@@ -78,5 +78,3 @@ namespace spot
}
// Copyright (C) 2010 Laboratoire de Recherche et Developpement
// Copyright (C) 2010, 2011 Laboratoire de Recherche et Developpement
// de l Epita (LRDE).
//
// This file is part of Spot, a model checking library.
......@@ -103,15 +103,15 @@ namespace spot
{
Sgi::hash_map<int, transitions*, Sgi::hash<int> >::const_iterator i =
transitions_by_condition.find(condition.id());
transitions_by_condition.find(condition.id());
if (i == transitions_by_condition.end())
{
return 0;
return 0;
}
else
{
return i->second;
return i->second;
}
}
......@@ -128,8 +128,8 @@ namespace spot
if (transitions_condition == 0)
{
transitions_condition = new transitions;
transitions_by_condition[(t->condition).id()] = transitions_condition;
transitions_condition = new transitions;
transitions_by_condition[(t->condition).id()] = transitions_condition;
}
transitions_condition->push_back(t);
......@@ -188,7 +188,7 @@ namespace spot
int
state_ta_explicit::compare(const spot::state* other) const
{
const state_ta_explicit* o = dynamic_cast<const state_ta_explicit*> (other);
const state_ta_explicit* o = down_cast<const state_ta_explicit*> (other);
assert(o);
int compare_value = tgba_state_->compare(o->tgba_state_);
......@@ -219,37 +219,37 @@ namespace spot
if (trans != 0)
for (it_trans = trans->begin(); it_trans != trans->end();)
{
state_ta_explicit* dest = (*it_trans)->dest;
bool is_stuttering_transition = (get_tgba_condition()
== (dest)->get_tgba_condition());
bool dest_is_livelock_accepting = dest->is_livelock_accepting_state();
//Before deleting stuttering transitions, propaged back livelock and initial state's properties
if (is_stuttering_transition)
{
if (dest_is_livelock_accepting)
set_livelock_accepting_state(true);
if (dest->is_initial_state())
set_initial_state(true);
}
//remove hole successors states
state_ta_explicit::transitions* dest_trans =
(dest)->get_transitions();
bool dest_trans_empty = dest_trans == 0 || dest_trans->empty();
if (is_stuttering_transition || (dest_trans_empty
&& (!dest_is_livelock_accepting)))
{
get_transitions((*it_trans)->condition)->remove(*it_trans);
delete (*it_trans);
it_trans = trans->erase(it_trans);
}
else
{
it_trans++;
}
}
{
state_ta_explicit* dest = (*it_trans)->dest;
bool is_stuttering_transition = (get_tgba_condition()
== (dest)->get_tgba_condition());
bool dest_is_livelock_accepting = dest->is_livelock_accepting_state();
//Before deleting stuttering transitions, propaged back livelock and initial state's properties
if (is_stuttering_transition)
{
if (dest_is_livelock_accepting)
set_livelock_accepting_state(true);
if (dest->is_initial_state())
set_initial_state(true);
}
//remove hole successors states
state_ta_explicit::transitions* dest_trans =
(dest)->get_transitions();
bool dest_trans_empty = dest_trans == 0 || dest_trans->empty();
if (is_stuttering_transition || (dest_trans_empty
&& (!dest_is_livelock_accepting)))
{
get_transitions((*it_trans)->condition)->remove(*it_trans);
delete (*it_trans);
it_trans = trans->erase(it_trans);
}
else
{
it_trans++;
}
}
}
......@@ -262,18 +262,18 @@ namespace spot
// they are not cloned.
if (trans != 0)
for (it_trans = trans->begin(); it_trans != trans->end(); it_trans++)
{
delete *it_trans;
}
{
delete *it_trans;
}
delete trans;
get_tgba_state()->destroy();
Sgi::hash_map<int, transitions*, Sgi::hash<int> >::iterator i =
transitions_by_condition.begin();
transitions_by_condition.begin();
while (i != transitions_by_condition.end())
{
delete i->second;
++i;
delete i->second;
++i;
}
}
......@@ -293,10 +293,10 @@ namespace spot
ta::states_set_t::iterator it;
for (it = states_set_.begin(); it != states_set_.end(); it++)
{
state_ta_explicit* s = dynamic_cast<state_ta_explicit*> (*it);
state_ta_explicit* s = down_cast<state_ta_explicit*> (*it);
s->free_transitions();
delete s;
s->free_transitions();
delete s;
}
get_dict()->unregister_all_my_variables(this);
delete tgba_;
......@@ -306,17 +306,17 @@ namespace spot
ta_explicit::add_state(state_ta_explicit* s)
{
std::pair<ta::states_set_t::iterator, bool> add_state_to_ta =
states_set_.insert(s);
states_set_.insert(s);
return dynamic_cast<state_ta_explicit*> (*add_state_to_ta.first);
return static_cast<state_ta_explicit*> (*add_state_to_ta.first);
}
void
ta_explicit::add_to_initial_states_set(state* state)
{
state_ta_explicit * s = dynamic_cast<state_ta_explicit*> (state);
state_ta_explicit * s = down_cast<state_ta_explicit*> (state);
assert(s);
s->set_initial_state(true);
initial_states_set_.insert(s);
......@@ -326,7 +326,8 @@ namespace spot
void
ta_explicit::delete_stuttering_and_hole_successors(spot::state* s)
{
state_ta_explicit * state = dynamic_cast<state_ta_explicit*> (s);
state_ta_explicit * state = down_cast<state_ta_explicit*> (s);
assert(state);
state->delete_stuttering_and_hole_successors();
if (state->is_initial_state()) add_to_initial_states_set(state);
......@@ -354,35 +355,39 @@ namespace spot
ta_explicit::get_state_condition(const spot::state* initial_state) const
{
const state_ta_explicit* sta =
dynamic_cast<const state_ta_explicit*> (initial_state);
down_cast<const state_ta_explicit*> (initial_state);
assert(sta);
return sta->get_tgba_condition();
}
bool
ta_explicit::is_accepting_state(const spot::state* s) const
{
const state_ta_explicit* sta = dynamic_cast<const state_ta_explicit*> (s);
const state_ta_explicit* sta = down_cast<const state_ta_explicit*> (s);
assert(sta);
return sta->is_accepting_state();
}
bool
ta_explicit::is_initial_state(const spot::state* s) const
{
const state_ta_explicit* sta = dynamic_cast<const state_ta_explicit*> (s);
const state_ta_explicit* sta = down_cast<const state_ta_explicit*> (s);
assert(sta);
return sta->is_initial_state();
}
bool
ta_explicit::is_livelock_accepting_state(const spot::state* s) const
{
const state_ta_explicit* sta = dynamic_cast<const state_ta_explicit*> (s);
const state_ta_explicit* sta = down_cast<const state_ta_explicit*> (s);
assert(sta);
return sta->is_livelock_accepting_state();
}
ta_succ_iterator*
ta_explicit::succ_iter(const spot::state* state) const
{
const state_ta_explicit* s = dynamic_cast<const state_ta_explicit*> (state);
const state_ta_explicit* s = down_cast<const state_ta_explicit*> (state);
assert(s);
return new ta_explicit_succ_iterator(s);
}
......@@ -390,7 +395,7 @@ namespace spot
ta_succ_iterator*
ta_explicit::succ_iter(const spot::state* state, bdd condition) const
{
const state_ta_explicit* s = dynamic_cast<const state_ta_explicit*> (state);
const state_ta_explicit* s = down_cast<const state_ta_explicit*> (state);
assert(s);
return new ta_explicit_succ_iterator(s, condition);
}
......@@ -410,14 +415,14 @@ namespace spot
std::string
ta_explicit::format_state(const spot::state* s) const
{
const state_ta_explicit* sta = dynamic_cast<const state_ta_explicit*> (s);
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());
return tgba_->format_state(sta->get_tgba_state()) + "\n"
+ bdd_format_formula(get_dict(), sta->get_tgba_condition());
+ bdd_format_formula(get_dict(), sta->get_tgba_condition());
}
......@@ -428,26 +433,26 @@ namespace spot
for (it = states_set_.begin(); it != states_set_.end(); it++)
{
const state_ta_explicit* source =
dynamic_cast<const state_ta_explicit*> (*it);
state_ta_explicit::transitions* trans = source->get_transitions();
state_ta_explicit::transitions::iterator it_trans;
if (trans != 0)
for (it_trans = trans->begin(); it_trans != trans->end();)
{
if (source->get_tgba_condition()
== ((*it_trans)->dest)->get_tgba_condition())
{
delete *it_trans;
it_trans = trans->erase(it_trans);
}
else
{
it_trans++;
}
}
const state_ta_explicit* source =
static_cast<const state_ta_explicit*> (*it);
state_ta_explicit::transitions* trans = source->get_transitions();
state_ta_explicit::transitions::iterator it_trans;
if (trans != 0)
for (it_trans = trans->begin(); it_trans != trans->end();)
{
if (source->get_tgba_condition()
== ((*it_trans)->dest)->get_tgba_condition())
{
delete *it_trans;
it_trans = trans->erase(it_trans);
}
else
{
it_trans++;
}
}
}
}
......
......@@ -31,7 +31,7 @@ namespace spot
state_ta_product::state_ta_product(const state_ta_product& o) :
state(), ta_state_(o.get_ta_state()), kripke_state_(
o.get_kripke_state()->clone())
o.get_kripke_state()->clone())
{
}
......@@ -44,7 +44,7 @@ namespace spot
int
state_ta_product::compare(const state* other) const
{
const state_ta_product* o = dynamic_cast<const state_ta_product*> (other);
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)
......@@ -91,9 +91,9 @@ namespace spot
ta_succ_it_->next();
if (ta_succ_it_->done())
{
delete ta_succ_it_;
ta_succ_it_ = 0;
kripke_succ_it_->next();
delete ta_succ_it_;
ta_succ_it_ = 0;
kripke_succ_it_->next();
}
}
......@@ -111,9 +111,9 @@ namespace spot
// done().)
if (kripke_succ_it_->done())
{
delete kripke_succ_it_;
kripke_succ_it_ = 0;
return;
delete kripke_succ_it_;
kripke_succ_it_ = 0;
return;
}
next_non_stuttering_();
......@@ -126,8 +126,8 @@ namespace spot
current_state_ = 0;
if (is_stuttering_transition())
{
ta_succ_it_ = 0;
kripke_succ_it_->next();
ta_succ_it_ = 0;
kripke_succ_it_->next();
}
else
step_();
......@@ -144,34 +144,34 @@ namespace spot
while (!done())
{
state * kripke_succ_it_current_state = kripke_succ_it_->current_state();
bdd dc = kripke_->state_condition(kripke_succ_it_current_state);
is_stuttering_transition_ = (sc == dc);
if (is_stuttering_transition_)
{
//if stuttering transition, the TA automata stays in the same state
current_state_ = new state_ta_product(source_->get_ta_state(),
kripke_succ_it_current_state);
current_condition_ = bddtrue;
return;
}
if (ta_succ_it_ == 0){
current_condition_ = bdd_setxor(sc, dc);
ta_succ_it_ = ta_->succ_iter(source_->get_ta_state(), current_condition_);
ta_succ_it_->first();
}
if (!ta_succ_it_->done())
{
current_state_ = new state_ta_product(ta_succ_it_->current_state(),
kripke_succ_it_current_state);
return;
}
kripke_succ_it_current_state->destroy();
step_();
state * kripke_succ_it_current_state = kripke_succ_it_->current_state();
bdd dc = kripke_->state_condition(kripke_succ_it_current_state);
is_stuttering_transition_ = (sc == dc);
if (is_stuttering_transition_)
{
//if stuttering transition, the TA automata stays in the same state
current_state_ = new state_ta_product(source_->get_ta_state(),
kripke_succ_it_current_state);
current_condition_ = bddtrue;
return;
}
if (ta_succ_it_ == 0){
current_condition_ = bdd_setxor(sc, dc);
ta_succ_it_ = ta_->succ_iter(source_->get_ta_state(), current_condition_);
ta_succ_it_->first();
}
if (!ta_succ_it_->done())
{
current_state_ = new state_ta_product(ta_succ_it_->current_state(),
kripke_succ_it_current_state);
return;
}
kripke_succ_it_current_state->destroy();
step_();
}
}
......@@ -227,7 +227,7 @@ namespace spot
ta_product::ta_product(const ta* testing_automata,
const kripke* kripke_structure) :
dict_(testing_automata->get_dict()), ta_(testing_automata), kripke_(
kripke_structure)
kripke_structure)
{
assert(dict_ == kripke_structure->get_dict());
dict_->register_all_variables_of(&ta_, this);
......@@ -252,19 +252,19 @@ namespace spot
for (it = ta_init_states_set.begin(); it != ta_init_states_set.end(); it++)
{
state* kripke_init_state = kripke_->get_init_state();
if ((kripke_->state_condition(kripke_init_state))
== (ta_->get_state_condition(*it)))
{
state_ta_product* stp = new state_ta_product((*it),
kripke_init_state);
initial_states_set.insert(stp);
}
else
{
kripke_init_state->destroy();
}
state* kripke_init_state = kripke_->get_init_state();
if ((kripke_->state_condition(kripke_init_state))
== (ta_->get_state_condition(*it)))
{
state_ta_product* stp = new state_ta_product((*it),
kripke_init_state);
initial_states_set.insert(stp);
}
else
{
kripke_init_state->destroy();
}
}
......@@ -274,7 +274,7 @@ namespace spot
ta_succ_iterator_product*
ta_product::succ_iter(const state* s) const
{
const state_ta_product* stp = dynamic_cast<const state_ta_product*> (s);
const state_ta_product* stp = down_cast<const state_ta_product*> (s);
assert(s);
return new ta_succ_iterator_product(stp, ta_, kripke_);
......@@ -289,16 +289,17 @@ namespace spot
std::string
ta_product::format_state(const state* state) const
{
const state_ta_product* s = dynamic_cast<const state_ta_product*> (state);
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());
+ ta_->format_state(s->get_ta_state());
}
bool
ta_product::is_accepting_state(const spot::state* s) const
{
const state_ta_product* stp = dynamic_cast<const state_ta_product*> (s);
const state_ta_product* stp = down_cast<const state_ta_product*> (s);
assert(stp);
return ta_->is_accepting_state(stp->get_ta_state());
}
......@@ -306,7 +307,8 @@ namespace spot
bool
ta_product::is_livelock_accepting_state(const spot::state* s) const
{
const state_ta_product* stp = dynamic_cast<const state_ta_product*> (s);
const state_ta_product* stp = down_cast<const state_ta_product*> (s);
assert(stp);
return ta_->is_livelock_accepting_state(stp->get_ta_state());
}
......@@ -314,21 +316,23 @@ namespace spot
bool
ta_product::is_initial_state(const spot::state* s) const
{
const state_ta_product* stp = dynamic_cast<const state_ta_product*> (s);
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();
return (ta_->is_initial_state(ta_s))
&& ((kripke_->get_init_state())->compare(kr_s) == 0)
&& ((kripke_->state_condition(kr_s))
== (ta_->get_state_condition(ta_s)));
&& ((kripke_->get_init_state())->compare(kr_s) == 0)
&& ((kripke_->state_condition(kr_s))
== (ta_->get_state_condition(ta_s)));
}
bdd
ta_product::get_state_condition(const spot::state* s) const
{
const state_ta_product* stp = dynamic_cast<const state_ta_product*> (s);
const state_ta_product* stp = down_cast<const state_ta_product*> (s);
assert(stp);
state* ta_s = stp->get_ta_state();
return ta_->get_state_condition(ta_s);
}
......@@ -337,7 +341,8 @@ namespace spot
ta_product::free_state(const spot::state* s) const
{
const state_ta_product* stp = dynamic_cast<const state_ta_product*> (s);
const state_ta_product* stp = down_cast<const state_ta_product*> (s);
assert(stp);
ta_->free_state(stp->get_ta_state());
delete stp;
......
This diff is collapsed.
......@@ -50,70 +50,70 @@ namespace spot
bdd satone_tgba_condition;
while ((satone_tgba_condition = bdd_satoneset(tgba_condition,
atomic_propositions_set_, bddtrue)) != bddfalse)
atomic_propositions_set_, bddtrue)) != bddfalse)
{
tgba_condition -= satone_tgba_condition;
state_ta_explicit* init_state = new state_ta_explicit(
tgba_init_state->clone(), satone_tgba_condition, true,
tgba_->state_is_accepting(tgba_init_state));
state_ta_explicit* is = ta->add_state(init_state);
assert(is == init_state);
ta->add_to_initial_states_set(is);
todo.push(init_state);
tgba_condition -= satone_tgba_condition;
state_ta_explicit* init_state = new state_ta_explicit(
tgba_init_state->clone(), satone_tgba_condition, true,
tgba_->state_is_accepting(tgba_init_state));
state_ta_explicit* is = ta->add_state(init_state);
assert(is == init_state);
ta->add_to_initial_states_set(is);
todo.push(init_state);
}
tgba_init_state->destroy();
while (!todo.empty())
{
state_ta_explicit* source = todo.top();
todo.pop();
tgba_succ_iterator* tgba_succ_it = tgba_->succ_iter(
source->get_tgba_state());
for (tgba_succ_it->first(); !tgba_succ_it->done(); tgba_succ_it->next())
{
const state* tgba_state = tgba_succ_it->current_state();
bdd tgba_condition = tgba_succ_it->current_condition();
bdd satone_tgba_condition;
while ((satone_tgba_condition = bdd_satoneset(tgba_condition,
atomic_propositions_set_, bddtrue)) != bddfalse)
{
tgba_condition -= satone_tgba_condition;
bdd all_props = bddtrue;
bdd dest_condition;
if (satone_tgba_condition == source->get_tgba_condition())
while ((dest_condition = bdd_satoneset(all_props,
atomic_propositions_set_, bddtrue)) != bddfalse)
{
all_props -= dest_condition;
state_ta_explicit* new_dest = new state_ta_explicit(
tgba_state->clone(), dest_condition, false,
tgba_->state_is_accepting(tgba_state));
state_ta_explicit* dest = ta->add_state(new_dest);
if (dest != new_dest)
{
// the state dest already exists in the testing automata
new_dest->get_tgba_state()->destroy();
delete new_dest;
}
else
{
todo.push(dest);
}
ta->create_transition(source, bdd_setxor(
source->get_tgba_condition(),
dest->get_tgba_condition()), dest);
}