Preliminary support for Event-based GBA.
* src/evtgba/Makefile.am, src/evtgba/evtgba.cc, src/evtgba/evtgba.hh, src/evtgba/evtgbaiter.hh, src/evtgba/explicit.cc, src/evtgba/explicit.hh, src/evtgba/product.cc, src/evtgba/product.hh, src/evtgba/symbol.cc, src/evtgba/symbol.hh, src/evtgbaalgos/Makefile.am, src/evtgbaalgos/dotty.cc, src/evtgbaalgos/dotty.hh, src/evtgbaalgos/reachiter.cc, src/evtgbaalgos/reachiter.hh, src/evtgbaalgos/save.cc, src/evtgbaalgos/save.hh, src/evtgbaparse/Makefile.am, src/evtgbaparse/evtgbaparse.yy, src/evtgbaparse/evtgbascan.ll, src/evtgbaparse/fmterror.cc, src/evtgbaparse/parsedecl.hh, src/evtgbaparse/public.hh, src/evtgbatest/Makefile.am, src/evtgbatest/defs.in, src/evtgbatest/explicit.cc, src/evtgbatest/explicit.test, src/evtgbatest/product.cc, src/evtgbatest/product.test, src/evtgbatest/readsave.cc, src/evtgbatest/readsave.test: New files. * configure.ac: Create the Makefiles in these new subdirectories. * src/Makefile.am: Recurse them.
This commit is contained in:
parent
d9b29a0590
commit
73ff928b6f
38 changed files with 3067 additions and 3 deletions
6
src/evtgba/.cvsignore
Normal file
6
src/evtgba/.cvsignore
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
.deps
|
||||
.libs
|
||||
*.lo
|
||||
*.la
|
||||
Makefile
|
||||
Makefile.in
|
||||
39
src/evtgba/Makefile.am
Normal file
39
src/evtgba/Makefile.am
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
## Copyright (C) 2004 Laboratoire d'Informatique de Paris 6 (LIP6),
|
||||
## département Systèmes Répartis Coopératifs (SRC), Université Pierre
|
||||
## et Marie Curie.
|
||||
##
|
||||
## This file is part of Spot, a model checking library.
|
||||
##
|
||||
## Spot is free software; you can redistribute it and/or modify it
|
||||
## under the terms of the GNU General Public License as published by
|
||||
## the Free Software Foundation; either version 2 of the License, or
|
||||
## (at your option) any later version.
|
||||
##
|
||||
## Spot is distributed in the hope that it will be useful, but WITHOUT
|
||||
## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
## or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
|
||||
## License for more details.
|
||||
##
|
||||
## You should have received a copy of the GNU General Public License
|
||||
## along with Spot; see the file COPYING. If not, write to the Free
|
||||
## Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
|
||||
## 02111-1307, USA.
|
||||
|
||||
AM_CPPFLAGS = -I$(srcdir)/.. $(BUDDY_CPPFLAGS)
|
||||
AM_CXXFLAGS = $(WARNING_CXXFLAGS)
|
||||
|
||||
evtgbadir = $(pkgincludedir)/evtgba
|
||||
|
||||
evtgba_HEADERS = \
|
||||
evtgba.hh \
|
||||
evtgbaiter.hh \
|
||||
explicit.hh \
|
||||
product.hh \
|
||||
symbol.hh
|
||||
|
||||
noinst_LTLIBRARIES = libevtgba.la
|
||||
libevtgba_la_SOURCES = \
|
||||
evtgba.cc \
|
||||
explicit.cc \
|
||||
product.cc \
|
||||
symbol.cc
|
||||
69
src/evtgba/evtgba.cc
Normal file
69
src/evtgba/evtgba.cc
Normal file
|
|
@ -0,0 +1,69 @@
|
|||
// Copyright (C) 2004 Laboratoire d'Informatique de Paris 6 (LIP6),
|
||||
// département Systèmes Répartis Coopératifs (SRC), Université Pierre
|
||||
// et Marie Curie.
|
||||
//
|
||||
// This file is part of Spot, a model checking library.
|
||||
//
|
||||
// Spot is free software; you can redistribute it and/or modify it
|
||||
// under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation; either version 2 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Spot is distributed in the hope that it will be useful, but WITHOUT
|
||||
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
// or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
|
||||
// License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Spot; see the file COPYING. If not, write to the Free
|
||||
// Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
|
||||
// 02111-1307, USA.
|
||||
|
||||
#include <sstream>
|
||||
#include "evtgba.hh"
|
||||
#include "misc/escape.hh"
|
||||
#include "misc/bareword.hh"
|
||||
|
||||
namespace spot
|
||||
{
|
||||
evtgba::evtgba()
|
||||
{
|
||||
}
|
||||
|
||||
evtgba::~evtgba()
|
||||
{
|
||||
}
|
||||
|
||||
std::string
|
||||
evtgba::format_label(const symbol* symbol) const
|
||||
{
|
||||
return symbol->name();
|
||||
}
|
||||
|
||||
std::string
|
||||
evtgba::format_acceptance_condition(const symbol* symbol) const
|
||||
{
|
||||
return symbol->name();
|
||||
}
|
||||
|
||||
std::string
|
||||
evtgba::format_acceptance_conditions(const symbol_set& symset) const
|
||||
{
|
||||
std::ostringstream o;
|
||||
symbol_set::const_iterator i = symset.begin();
|
||||
if (i != symset.end())
|
||||
{
|
||||
o << '{';
|
||||
for (;;)
|
||||
{
|
||||
o << quote_unless_bare_word(format_acceptance_condition(*i));
|
||||
if (++i == symset.end())
|
||||
break;
|
||||
o << ", ";
|
||||
}
|
||||
o << '}';
|
||||
}
|
||||
return o.str();
|
||||
}
|
||||
|
||||
}
|
||||
69
src/evtgba/evtgba.hh
Normal file
69
src/evtgba/evtgba.hh
Normal file
|
|
@ -0,0 +1,69 @@
|
|||
// Copyright (C) 2004 Laboratoire d'Informatique de Paris 6 (LIP6),
|
||||
// département Systèmes Répartis Coopératifs (SRC), Université Pierre
|
||||
// et Marie Curie.
|
||||
//
|
||||
// This file is part of Spot, a model checking library.
|
||||
//
|
||||
// Spot is free software; you can redistribute it and/or modify it
|
||||
// under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation; either version 2 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Spot is distributed in the hope that it will be useful, but WITHOUT
|
||||
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
// or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
|
||||
// License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Spot; see the file COPYING. If not, write to the Free
|
||||
// Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
|
||||
// 02111-1307, USA.
|
||||
|
||||
#ifndef SPOT_EVTGBA_EVTGBA_HH
|
||||
# define SPOT_EVTGBA_EVTGBA_HH
|
||||
|
||||
#include "tgba/state.hh"
|
||||
#include "evtgbaiter.hh"
|
||||
|
||||
namespace spot
|
||||
{
|
||||
// FIXME: doc me
|
||||
class evtgba
|
||||
{
|
||||
protected:
|
||||
evtgba();
|
||||
|
||||
public:
|
||||
virtual ~evtgba();
|
||||
|
||||
virtual evtgba_iterator* init_iter() const = 0;
|
||||
virtual evtgba_iterator* succ_iter(const state* s) const = 0;
|
||||
virtual evtgba_iterator* pred_iter(const state* s) const = 0;
|
||||
|
||||
/// \brief Format the state as a string for printing.
|
||||
///
|
||||
/// This formating is the responsability of the automata
|
||||
/// who owns the state.
|
||||
virtual std::string format_state(const state* state) const = 0;
|
||||
|
||||
virtual std::string format_label(const symbol* symbol) const;
|
||||
virtual std::string format_acceptance_condition(const symbol* symbol) const;
|
||||
virtual std::string
|
||||
format_acceptance_conditions(const symbol_set& symset) const;
|
||||
|
||||
/// \brief Return the set of all acceptance conditions used
|
||||
/// by this automaton.
|
||||
///
|
||||
/// The goal of the emptiness check is to ensure that
|
||||
/// a strongly connected component walks through each
|
||||
/// of these acceptiong conditions. I.e., the union
|
||||
/// of the acceptiong conditions of all transition in
|
||||
/// the SCC should be equal to the result of this function.
|
||||
virtual const symbol_set& all_acceptance_conditions() const = 0;
|
||||
|
||||
virtual const symbol_set& alphabet() const = 0;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // SPOT_EVTGBA_EVTGBA_HH
|
||||
50
src/evtgba/evtgbaiter.hh
Normal file
50
src/evtgba/evtgbaiter.hh
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
// Copyright (C) 2004 Laboratoire d'Informatique de Paris 6 (LIP6),
|
||||
// département Systèmes Répartis Coopératifs (SRC), Université Pierre
|
||||
// et Marie Curie.
|
||||
//
|
||||
// This file is part of Spot, a model checking library.
|
||||
//
|
||||
// Spot is free software; you can redistribute it and/or modify it
|
||||
// under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation; either version 2 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Spot is distributed in the hope that it will be useful, but WITHOUT
|
||||
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
// or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
|
||||
// License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Spot; see the file COPYING. If not, write to the Free
|
||||
// Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
|
||||
// 02111-1307, USA.
|
||||
|
||||
#ifndef SPOT_EVTGBA_ITER_HH
|
||||
# define SPOT_EVTGBA_ITER_HH
|
||||
|
||||
#include "tgba/state.hh"
|
||||
#include "symbol.hh"
|
||||
#include "evtgbaiter.hh"
|
||||
|
||||
namespace spot
|
||||
{
|
||||
// FIXME: doc me
|
||||
class evtgba_iterator
|
||||
{
|
||||
public:
|
||||
virtual
|
||||
~evtgba_iterator()
|
||||
{
|
||||
}
|
||||
|
||||
virtual void first() = 0;
|
||||
virtual void next() = 0;
|
||||
virtual bool done() const = 0;
|
||||
|
||||
virtual const state* current_state() const = 0;
|
||||
virtual const symbol* current_label() const = 0;
|
||||
virtual symbol_set current_acceptance_conditions() const = 0;
|
||||
};
|
||||
}
|
||||
|
||||
#endif // SPOT_EVTGBA_ITER_HH
|
||||
284
src/evtgba/explicit.cc
Normal file
284
src/evtgba/explicit.cc
Normal file
|
|
@ -0,0 +1,284 @@
|
|||
// Copyright (C) 2004 Laboratoire d'Informatique de Paris 6 (LIP6),
|
||||
// département Systèmes Répartis Coopératifs (SRC), Université Pierre
|
||||
// et Marie Curie.
|
||||
//
|
||||
// This file is part of Spot, a model checking library.
|
||||
//
|
||||
// Spot is free software; you can redistribute it and/or modify it
|
||||
// under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation; either version 2 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Spot is distributed in the hope that it will be useful, but WITHOUT
|
||||
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
// or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
|
||||
// License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Spot; see the file COPYING. If not, write to the Free
|
||||
// Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
|
||||
// 02111-1307, USA.
|
||||
|
||||
#include "explicit.hh"
|
||||
#include "misc/bareword.hh"
|
||||
#include "misc/escape.hh"
|
||||
|
||||
namespace spot
|
||||
{
|
||||
const evtgba_explicit::state*
|
||||
state_evtgba_explicit::get_state() const
|
||||
{
|
||||
return state_;
|
||||
}
|
||||
|
||||
int
|
||||
state_evtgba_explicit::compare(const spot::state* other) const
|
||||
{
|
||||
const state_evtgba_explicit* o =
|
||||
dynamic_cast<const state_evtgba_explicit*>(other);
|
||||
assert(o);
|
||||
return o->get_state() - get_state();
|
||||
}
|
||||
|
||||
size_t
|
||||
state_evtgba_explicit::hash() const
|
||||
{
|
||||
return
|
||||
reinterpret_cast<const char*>(get_state()) - static_cast<const char*>(0);
|
||||
}
|
||||
|
||||
state_evtgba_explicit*
|
||||
state_evtgba_explicit::clone() const
|
||||
{
|
||||
return new state_evtgba_explicit(*this);
|
||||
}
|
||||
|
||||
namespace
|
||||
{
|
||||
class evtgba_explicit_iterator: public evtgba_iterator
|
||||
{
|
||||
public:
|
||||
evtgba_explicit_iterator(const evtgba_explicit::transition_list* s)
|
||||
: s_(s), i_(s_->end())
|
||||
{
|
||||
}
|
||||
|
||||
virtual
|
||||
~evtgba_explicit_iterator()
|
||||
{
|
||||
}
|
||||
|
||||
virtual void first()
|
||||
{
|
||||
i_ = s_->begin();
|
||||
}
|
||||
|
||||
virtual void
|
||||
next()
|
||||
{
|
||||
++i_;
|
||||
}
|
||||
|
||||
virtual bool
|
||||
done() const
|
||||
{
|
||||
return i_ == s_->end();
|
||||
}
|
||||
|
||||
virtual const symbol*
|
||||
current_label() const
|
||||
{
|
||||
return (*i_)->label;
|
||||
}
|
||||
|
||||
virtual symbol_set
|
||||
current_acceptance_conditions() const
|
||||
{
|
||||
return (*i_)->acceptance_conditions;
|
||||
}
|
||||
protected:
|
||||
const evtgba_explicit::transition_list* s_;
|
||||
evtgba_explicit::transition_list::const_iterator i_;
|
||||
};
|
||||
|
||||
|
||||
|
||||
class evtgba_explicit_iterator_fw: public evtgba_explicit_iterator
|
||||
{
|
||||
public:
|
||||
evtgba_explicit_iterator_fw(const evtgba_explicit::transition_list* s)
|
||||
: evtgba_explicit_iterator(s)
|
||||
{
|
||||
}
|
||||
|
||||
virtual
|
||||
~evtgba_explicit_iterator_fw()
|
||||
{
|
||||
}
|
||||
|
||||
const state*
|
||||
current_state() const
|
||||
{
|
||||
return new state_evtgba_explicit((*i_)->out);
|
||||
}
|
||||
};
|
||||
|
||||
class evtgba_explicit_iterator_bw: public evtgba_explicit_iterator
|
||||
{
|
||||
public:
|
||||
evtgba_explicit_iterator_bw(const evtgba_explicit::transition_list* s)
|
||||
: evtgba_explicit_iterator(s)
|
||||
{
|
||||
}
|
||||
|
||||
virtual
|
||||
~evtgba_explicit_iterator_bw()
|
||||
{
|
||||
}
|
||||
|
||||
const state*
|
||||
current_state() const
|
||||
{
|
||||
return new state_evtgba_explicit((*i_)->in);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
evtgba_explicit::evtgba_explicit()
|
||||
{
|
||||
}
|
||||
|
||||
evtgba_explicit::~evtgba_explicit()
|
||||
{
|
||||
for (transition_list::const_iterator i = init_states_.begin();
|
||||
i != init_states_.end(); ++i)
|
||||
delete *i;
|
||||
for (ns_map::const_iterator j = name_state_map_.begin();
|
||||
j != name_state_map_.end(); ++j)
|
||||
{
|
||||
for (transition_list::const_iterator i = j->second->out.begin();
|
||||
i != j->second->out.end(); ++i)
|
||||
delete *i;
|
||||
delete j->second;
|
||||
}
|
||||
for (symbol_set::const_iterator i = alphabet_.begin();
|
||||
i != alphabet_.end(); ++i)
|
||||
(*i)->unref();
|
||||
for (symbol_set::const_iterator i = acc_set_.begin();
|
||||
i != acc_set_.end(); ++i)
|
||||
(*i)->unref();
|
||||
}
|
||||
|
||||
evtgba_iterator*
|
||||
evtgba_explicit::init_iter() const
|
||||
{
|
||||
return new evtgba_explicit_iterator_fw(&init_states_);
|
||||
}
|
||||
|
||||
evtgba_iterator*
|
||||
evtgba_explicit::succ_iter(const spot::state* s) const
|
||||
{
|
||||
const state_evtgba_explicit* u =
|
||||
dynamic_cast<const state_evtgba_explicit*>(s);
|
||||
assert(u);
|
||||
return new evtgba_explicit_iterator_fw(&u->get_state()->out);
|
||||
}
|
||||
|
||||
evtgba_iterator*
|
||||
evtgba_explicit::pred_iter(const spot::state* s) const
|
||||
{
|
||||
const state_evtgba_explicit* u =
|
||||
dynamic_cast<const state_evtgba_explicit*>(s);
|
||||
assert(u);
|
||||
return new evtgba_explicit_iterator_fw(&u->get_state()->in);
|
||||
}
|
||||
|
||||
std::string
|
||||
evtgba_explicit::format_state(const spot::state* s) const
|
||||
{
|
||||
const state_evtgba_explicit* u =
|
||||
dynamic_cast<const state_evtgba_explicit*>(s);
|
||||
assert(u);
|
||||
sn_map::const_iterator i = state_name_map_.find(u->get_state());
|
||||
assert(i != state_name_map_.end());
|
||||
return i->second;
|
||||
}
|
||||
|
||||
const symbol_set&
|
||||
evtgba_explicit::all_acceptance_conditions() const
|
||||
{
|
||||
return acc_set_;
|
||||
}
|
||||
|
||||
const symbol_set&
|
||||
evtgba_explicit::alphabet() const
|
||||
{
|
||||
return alphabet_;
|
||||
}
|
||||
|
||||
evtgba_explicit::state*
|
||||
evtgba_explicit::declare_state(const std::string& name)
|
||||
{
|
||||
ns_map::const_iterator i = name_state_map_.find(name);
|
||||
if (i != name_state_map_.end())
|
||||
return i->second;
|
||||
state* s = new state;
|
||||
name_state_map_[name] = s;
|
||||
state_name_map_[s] = name;
|
||||
return s;
|
||||
}
|
||||
|
||||
evtgba_explicit::transition*
|
||||
evtgba_explicit::add_transition(const std::string& source,
|
||||
const rsymbol& label,
|
||||
rsymbol_set acc,
|
||||
const std::string& dest)
|
||||
{
|
||||
state* in = declare_state(source);
|
||||
state* out = declare_state(dest);
|
||||
transition* t = new transition;
|
||||
t->in = in;
|
||||
t->label = label;
|
||||
t->out = out;
|
||||
in->out.push_back(t);
|
||||
out->in.push_back(t);
|
||||
|
||||
for (rsymbol_set::const_iterator i = acc.begin(); i != acc.end(); ++i)
|
||||
{
|
||||
const symbol* s = *i;
|
||||
t->acceptance_conditions.insert(s);
|
||||
declare_acceptance_condition(*i);
|
||||
}
|
||||
|
||||
if (alphabet_.find(t->label) == alphabet_.end())
|
||||
{
|
||||
alphabet_.insert(t->label);
|
||||
t->label->ref();
|
||||
}
|
||||
|
||||
return t;
|
||||
}
|
||||
|
||||
void
|
||||
evtgba_explicit::declare_acceptance_condition(const rsymbol& acc)
|
||||
{
|
||||
const symbol* s = acc;
|
||||
if (acc_set_.find(s) == acc_set_.end())
|
||||
{
|
||||
acc_set_.insert(s);
|
||||
s->ref();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
evtgba_explicit::set_init_state(const std::string& name)
|
||||
{
|
||||
transition* t = new transition;
|
||||
t->in = 0;
|
||||
t->out = declare_state(name);
|
||||
t->label = 0;
|
||||
init_states_.push_back(t);
|
||||
}
|
||||
|
||||
}
|
||||
112
src/evtgba/explicit.hh
Normal file
112
src/evtgba/explicit.hh
Normal file
|
|
@ -0,0 +1,112 @@
|
|||
// Copyright (C) 2004 Laboratoire d'Informatique de Paris 6 (LIP6),
|
||||
// département Systèmes Répartis Coopératifs (SRC), Université Pierre
|
||||
// et Marie Curie.
|
||||
//
|
||||
// This file is part of Spot, a model checking library.
|
||||
//
|
||||
// Spot is free software; you can redistribute it and/or modify it
|
||||
// under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation; either version 2 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Spot is distributed in the hope that it will be useful, but WITHOUT
|
||||
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
// or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
|
||||
// License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Spot; see the file COPYING. If not, write to the Free
|
||||
// Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
|
||||
// 02111-1307, USA.
|
||||
|
||||
#ifndef SPOT_EVTGBA_EXPLICIT_HH
|
||||
# define SPOT_EVTGBA_EXPLICIT_HH
|
||||
|
||||
#include "evtgba.hh"
|
||||
#include <list>
|
||||
#include "misc/hash.hh"
|
||||
|
||||
namespace spot
|
||||
{
|
||||
// FIXME: doc me
|
||||
class evtgba_explicit: public evtgba
|
||||
{
|
||||
public:
|
||||
struct transition;
|
||||
typedef std::list<transition*> transition_list;
|
||||
struct state
|
||||
{
|
||||
transition_list in, out;
|
||||
};
|
||||
|
||||
/// Explicit transitions (used by spot::evtgba_explicit).
|
||||
struct transition
|
||||
{
|
||||
const symbol* label;
|
||||
symbol_set acceptance_conditions;
|
||||
state* in;
|
||||
state* out;
|
||||
};
|
||||
|
||||
evtgba_explicit();
|
||||
virtual ~evtgba_explicit();
|
||||
|
||||
// evtgba interface
|
||||
virtual evtgba_iterator* init_iter() const;
|
||||
virtual evtgba_iterator* succ_iter(const spot::state* s) const;
|
||||
virtual evtgba_iterator* pred_iter(const spot::state* s) const;
|
||||
virtual std::string format_state(const spot::state* state) const;
|
||||
virtual const symbol_set& all_acceptance_conditions() const;
|
||||
virtual const symbol_set& alphabet() const;
|
||||
|
||||
transition* add_transition(const std::string& source,
|
||||
const rsymbol& label,
|
||||
rsymbol_set acc,
|
||||
const std::string& dest);
|
||||
/// \brief Designate \a name as initial state.
|
||||
///
|
||||
/// Can be called multiple times in case there is several initial states.
|
||||
void set_init_state(const std::string& name);
|
||||
void declare_acceptance_condition(const rsymbol& acc);
|
||||
protected:
|
||||
|
||||
state* declare_state(const std::string& name);
|
||||
|
||||
typedef Sgi::hash_map<const std::string, evtgba_explicit::state*,
|
||||
string_hash> ns_map;
|
||||
typedef Sgi::hash_map<const evtgba_explicit::state*, std::string,
|
||||
ptr_hash<evtgba_explicit::state> > sn_map;
|
||||
|
||||
ns_map name_state_map_;
|
||||
sn_map state_name_map_;
|
||||
|
||||
symbol_set acc_set_;
|
||||
symbol_set alphabet_;
|
||||
transition_list init_states_;
|
||||
};
|
||||
|
||||
/// States used by spot::tgba_evtgba_explicit.
|
||||
class state_evtgba_explicit : public spot::state
|
||||
{
|
||||
public:
|
||||
state_evtgba_explicit(const evtgba_explicit::state* s)
|
||||
: state_(s)
|
||||
{
|
||||
}
|
||||
|
||||
virtual int compare(const spot::state* other) const;
|
||||
virtual size_t hash() const;
|
||||
virtual state_evtgba_explicit* clone() const;
|
||||
|
||||
virtual ~state_evtgba_explicit()
|
||||
{
|
||||
}
|
||||
|
||||
const evtgba_explicit::state* get_state() const;
|
||||
private:
|
||||
const evtgba_explicit::state* state_;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // SPOT_EVTGBA_EXPLICIT_HH
|
||||
471
src/evtgba/product.cc
Normal file
471
src/evtgba/product.cc
Normal file
|
|
@ -0,0 +1,471 @@
|
|||
// Copyright (C) 2004 Laboratoire d'Informatique de Paris 6 (LIP6),
|
||||
// département Systèmes Répartis Coopératifs (SRC), Université Pierre
|
||||
// et Marie Curie.
|
||||
//
|
||||
// This file is part of Spot, a model checking library.
|
||||
//
|
||||
// Spot is free software; you can redistribute it and/or modify it
|
||||
// under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation; either version 2 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Spot is distributed in the hope that it will be useful, but WITHOUT
|
||||
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
// or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
|
||||
// License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Spot; see the file COPYING. If not, write to the Free
|
||||
// Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
|
||||
// 02111-1307, USA.
|
||||
|
||||
#include "product.hh"
|
||||
#include "misc/modgray.hh"
|
||||
#include <cstdlib>
|
||||
#include <set>
|
||||
|
||||
namespace spot
|
||||
{
|
||||
namespace
|
||||
{
|
||||
class evtgba_product_state: public state
|
||||
{
|
||||
public:
|
||||
evtgba_product_state(state const* const* s, int n)
|
||||
: s_(s), n_(n)
|
||||
{
|
||||
}
|
||||
|
||||
~evtgba_product_state()
|
||||
{
|
||||
for (int j = 0; j < n_; ++j)
|
||||
delete s_[j];
|
||||
delete[] s_;
|
||||
}
|
||||
|
||||
state const*
|
||||
nth(int n) const
|
||||
{
|
||||
assert(n < n_);
|
||||
return s_[n];
|
||||
}
|
||||
|
||||
state const* const*
|
||||
all() const
|
||||
{
|
||||
return s_;
|
||||
}
|
||||
|
||||
int
|
||||
compare(const state* other) const
|
||||
{
|
||||
const evtgba_product_state* s =
|
||||
dynamic_cast<const evtgba_product_state*>(other);
|
||||
assert(s);
|
||||
assert(s->n_ == n_);
|
||||
for (int i = 0; i < n_; ++i)
|
||||
{
|
||||
int res = s_[i]->compare(s->nth(i));
|
||||
if (res)
|
||||
return res;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
size_t
|
||||
hash() const
|
||||
{
|
||||
// We assume that size_t has at least 32bits.
|
||||
size_t res = 0;
|
||||
for (int i = 0; i != n_; ++i)
|
||||
{
|
||||
size_t key = s_[i]->hash();
|
||||
|
||||
// Thomas Wang's 32 bit hash Function
|
||||
// http://www.concentric.net/~Ttwang/tech/inthash.htm
|
||||
key += ~(key << 15);
|
||||
key ^= (key >> 10);
|
||||
key += (key << 3);
|
||||
key ^= (key >> 6);
|
||||
key += ~(key << 11);
|
||||
key ^= (key >> 16);
|
||||
|
||||
res ^= key;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
evtgba_product_state*
|
||||
clone() const
|
||||
{
|
||||
state const** s = new state const*[n_];
|
||||
memcpy(s, s_, n_ * sizeof(*s_));
|
||||
return new evtgba_product_state(s, n_);
|
||||
}
|
||||
|
||||
|
||||
private:
|
||||
state const* const* s_;
|
||||
int n_;
|
||||
};
|
||||
|
||||
|
||||
class evtgba_product_init_iterator:
|
||||
public evtgba_iterator, private loopless_modular_mixed_radix_gray_code
|
||||
{
|
||||
public:
|
||||
evtgba_product_init_iterator(evtgba_iterator* const* op, int n)
|
||||
: loopless_modular_mixed_radix_gray_code(n), op_(op), n_(n), done_(0)
|
||||
{
|
||||
for (int j = 0; j < n_; ++j)
|
||||
{
|
||||
op_[j]->first();
|
||||
if (op_[j]->done())
|
||||
++done_;
|
||||
}
|
||||
}
|
||||
|
||||
~evtgba_product_init_iterator()
|
||||
{
|
||||
for (int j = 0; j < n_; ++j)
|
||||
delete op_[j];
|
||||
delete[] op_;
|
||||
}
|
||||
|
||||
virtual void
|
||||
first()
|
||||
{
|
||||
loopless_modular_mixed_radix_gray_code::first();
|
||||
step_();
|
||||
}
|
||||
|
||||
virtual void
|
||||
next()
|
||||
{
|
||||
loopless_modular_mixed_radix_gray_code::next();
|
||||
step_();
|
||||
}
|
||||
|
||||
virtual bool
|
||||
done() const
|
||||
{
|
||||
return loopless_modular_mixed_radix_gray_code::done();
|
||||
}
|
||||
|
||||
virtual const state*
|
||||
current_state() const
|
||||
{
|
||||
state const** s = new state const*[n_];
|
||||
for (int j = 0; j < n_; ++j)
|
||||
s[j] = op_[j]->current_state();
|
||||
return new evtgba_product_state(s, n_);
|
||||
}
|
||||
|
||||
virtual const symbol*
|
||||
current_label() const
|
||||
{
|
||||
assert(0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
virtual symbol_set
|
||||
current_acceptance_conditions() const
|
||||
{
|
||||
assert(0);
|
||||
symbol_set s;
|
||||
return s;
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
void
|
||||
pre_update(int j)
|
||||
{
|
||||
if (op_[j]->done())
|
||||
--done_;
|
||||
}
|
||||
|
||||
void
|
||||
post_update(int j)
|
||||
{
|
||||
if (op_[j]->done())
|
||||
++done_;
|
||||
}
|
||||
|
||||
virtual void
|
||||
a_first(int j)
|
||||
{
|
||||
pre_update(j);
|
||||
op_[j]->first();
|
||||
post_update(j);
|
||||
}
|
||||
|
||||
virtual void
|
||||
a_next(int j)
|
||||
{
|
||||
pre_update(j);
|
||||
op_[j]->next();
|
||||
post_update(j);
|
||||
}
|
||||
|
||||
virtual bool
|
||||
a_last(int j) const
|
||||
{
|
||||
return op_[j]->done();
|
||||
}
|
||||
|
||||
void
|
||||
step_()
|
||||
{
|
||||
while (done_ && !loopless_modular_mixed_radix_gray_code::done())
|
||||
loopless_modular_mixed_radix_gray_code::next();
|
||||
}
|
||||
|
||||
evtgba_iterator* const* op_;
|
||||
const int n_;
|
||||
int done_; // number of iterator for which done() is true.
|
||||
};
|
||||
|
||||
class evtgba_product_iterator:
|
||||
public evtgba_iterator, private loopless_modular_mixed_radix_gray_code
|
||||
{
|
||||
public:
|
||||
evtgba_product_iterator(evtgba_iterator* const* op, int n,
|
||||
state const* const* from,
|
||||
const evtgba_product::common_symbol_table& cst)
|
||||
: loopless_modular_mixed_radix_gray_code(n), op_(op), n_(n),
|
||||
from_(from), cst_(cst)
|
||||
{
|
||||
count_pointer_ = new int*[n];
|
||||
for (int j = 0; j < n; ++j)
|
||||
count_pointer_[j] = 0;
|
||||
}
|
||||
|
||||
virtual
|
||||
~evtgba_product_iterator()
|
||||
{
|
||||
delete[] count_pointer_;
|
||||
for (int j = 0; j < n_; ++j)
|
||||
delete op_[j];
|
||||
delete[] op_;
|
||||
}
|
||||
|
||||
virtual void
|
||||
first()
|
||||
{
|
||||
loopless_modular_mixed_radix_gray_code::first();
|
||||
step_();
|
||||
}
|
||||
|
||||
virtual void
|
||||
next()
|
||||
{
|
||||
loopless_modular_mixed_radix_gray_code::next();
|
||||
step_();
|
||||
}
|
||||
|
||||
virtual bool
|
||||
done() const
|
||||
{
|
||||
return loopless_modular_mixed_radix_gray_code::done();
|
||||
}
|
||||
|
||||
virtual const state*
|
||||
current_state() const
|
||||
{
|
||||
state const** s = new state const*[n_];
|
||||
for (int j = 0; j < n_; ++j)
|
||||
{
|
||||
if (op_[j]->done())
|
||||
s[j] = from_[j]->clone();
|
||||
else
|
||||
s[j] = op_[j]->current_state();
|
||||
}
|
||||
return new evtgba_product_state(s, n_);
|
||||
}
|
||||
|
||||
virtual const symbol*
|
||||
current_label() const
|
||||
{
|
||||
return lcm_.begin()->first;
|
||||
}
|
||||
|
||||
virtual symbol_set
|
||||
current_acceptance_conditions() const
|
||||
{
|
||||
symbol_set s;
|
||||
for (int j = 0; j < n_; ++j)
|
||||
if (!op_[j]->done())
|
||||
{
|
||||
symbol_set t = op_[j]->current_acceptance_conditions();
|
||||
s.insert(t.begin(), t.end());
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
void
|
||||
pre_update(int j)
|
||||
{
|
||||
if (!--*count_pointer_[j])
|
||||
lcm_.erase(op_[j]->current_label());
|
||||
count_pointer_[j] = 0;
|
||||
}
|
||||
|
||||
void
|
||||
post_update(int j)
|
||||
{
|
||||
if (!op_[j]->done())
|
||||
{
|
||||
count_pointer_[j] = &lcm_[op_[j]->current_label()];
|
||||
++*count_pointer_[j];
|
||||
}
|
||||
}
|
||||
|
||||
virtual void
|
||||
a_first(int j)
|
||||
{
|
||||
if (count_pointer_[j])
|
||||
pre_update(j);
|
||||
op_[j]->first();
|
||||
post_update(j);
|
||||
}
|
||||
|
||||
virtual void
|
||||
a_next(int j)
|
||||
{
|
||||
pre_update(j);
|
||||
op_[j]->next();
|
||||
post_update(j);
|
||||
}
|
||||
|
||||
virtual bool
|
||||
a_last(int j) const
|
||||
{
|
||||
return op_[j]->done();
|
||||
}
|
||||
|
||||
void
|
||||
step_()
|
||||
{
|
||||
while (!loopless_modular_mixed_radix_gray_code::done())
|
||||
{
|
||||
if (lcm_.size() == 1)
|
||||
{
|
||||
const symbol* l = lcm_.begin()->first;
|
||||
const std::set<int>& s = cst_.find(l)->second;
|
||||
std::set<int>::const_iterator i;
|
||||
for (i = s.begin(); i != s.end(); ++i)
|
||||
if (op_[*i]->done())
|
||||
break;
|
||||
if (i == s.end())
|
||||
return;
|
||||
}
|
||||
loopless_modular_mixed_radix_gray_code::next();
|
||||
}
|
||||
}
|
||||
|
||||
evtgba_iterator* const* op_;
|
||||
int n_;
|
||||
state const* const* from_;
|
||||
const evtgba_product::common_symbol_table& cst_;
|
||||
typedef std::map<const symbol*, int> label_count_map;
|
||||
label_count_map lcm_;
|
||||
int** count_pointer_;
|
||||
};
|
||||
|
||||
} // anonymous
|
||||
|
||||
|
||||
evtgba_product::evtgba_product(const evtgba_product_operands& op)
|
||||
: op_(op)
|
||||
{
|
||||
int n = 0;
|
||||
for (evtgba_product_operands::const_iterator i = op.begin();
|
||||
i != op.end(); ++i, ++n)
|
||||
{
|
||||
const symbol_set& al = (*i)->alphabet();
|
||||
alphabet_.insert(al.begin(), al.end());
|
||||
const symbol_set& ac = (*i)->all_acceptance_conditions();
|
||||
all_acc_.insert(ac.begin(), ac.end());
|
||||
|
||||
for (symbol_set::const_iterator j = al.begin(); j != al.end(); ++j)
|
||||
common_symbols_[*j].insert(n);
|
||||
}
|
||||
}
|
||||
|
||||
evtgba_product::~evtgba_product()
|
||||
{
|
||||
}
|
||||
|
||||
evtgba_iterator*
|
||||
evtgba_product::init_iter() const
|
||||
{
|
||||
int n = op_.size();
|
||||
evtgba_iterator** it = new evtgba_iterator *[n];
|
||||
for (int i = 0; i < n; ++i)
|
||||
it[i] = op_[i]->init_iter();
|
||||
|
||||
return new evtgba_product_init_iterator(it, n);
|
||||
}
|
||||
|
||||
evtgba_iterator*
|
||||
evtgba_product::succ_iter(const state* st) const
|
||||
{
|
||||
const evtgba_product_state* s =
|
||||
dynamic_cast<const evtgba_product_state*>(st);
|
||||
assert(s);
|
||||
|
||||
int n = op_.size();
|
||||
|
||||
evtgba_iterator** it = new evtgba_iterator *[n];
|
||||
for (int i = 0; i < n; ++i)
|
||||
it[i] = op_[i]->succ_iter(s->nth(i));
|
||||
|
||||
return new evtgba_product_iterator(it, n, s->all(), common_symbols_);
|
||||
}
|
||||
|
||||
evtgba_iterator*
|
||||
evtgba_product::pred_iter(const state* st) const
|
||||
{
|
||||
const evtgba_product_state* s =
|
||||
dynamic_cast<const evtgba_product_state*>(st);
|
||||
assert(s);
|
||||
|
||||
int n = op_.size();
|
||||
|
||||
evtgba_iterator** it = new evtgba_iterator *[n];
|
||||
for (int i = 0; i < n; ++i)
|
||||
it[i] = op_[i]->pred_iter(s->nth(i));
|
||||
|
||||
return new evtgba_product_iterator(it, n, s->all(), common_symbols_);
|
||||
}
|
||||
|
||||
std::string
|
||||
evtgba_product::format_state(const state* st) const
|
||||
{
|
||||
const evtgba_product_state* s =
|
||||
dynamic_cast<const evtgba_product_state*>(st);
|
||||
int n = op_.size();
|
||||
std::string res = "<" + op_[0]->format_state(s->nth(0));
|
||||
|
||||
for (int i = 1; i < n; ++i)
|
||||
res = res + ", " + op_[i]->format_state(s->nth(i));
|
||||
|
||||
return res + ">";
|
||||
}
|
||||
|
||||
const symbol_set&
|
||||
evtgba_product::all_acceptance_conditions() const
|
||||
{
|
||||
return all_acc_;
|
||||
}
|
||||
|
||||
const symbol_set&
|
||||
evtgba_product::alphabet() const
|
||||
{
|
||||
return alphabet_;
|
||||
}
|
||||
|
||||
}
|
||||
69
src/evtgba/product.hh
Normal file
69
src/evtgba/product.hh
Normal file
|
|
@ -0,0 +1,69 @@
|
|||
// Copyright (C) 2004 Laboratoire d'Informatique de Paris 6 (LIP6),
|
||||
// département Systèmes Répartis Coopératifs (SRC), Université Pierre
|
||||
// et Marie Curie.
|
||||
//
|
||||
// This file is part of Spot, a model checking library.
|
||||
//
|
||||
// Spot is free software; you can redistribute it and/or modify it
|
||||
// under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation; either version 2 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Spot is distributed in the hope that it will be useful, but WITHOUT
|
||||
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
// or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
|
||||
// License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Spot; see the file COPYING. If not, write to the Free
|
||||
// Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
|
||||
// 02111-1307, USA.
|
||||
|
||||
#ifndef SPOT_EVTGBA_PRODUCT_HH
|
||||
# define SPOT_EVTGBA_PRODUCT_HH
|
||||
|
||||
#include "evtgba/evtgba.hh"
|
||||
#include <vector>
|
||||
|
||||
namespace spot
|
||||
{
|
||||
// FIXME: doc me
|
||||
class evtgba_product: public evtgba
|
||||
{
|
||||
public:
|
||||
typedef std::vector<const evtgba*> evtgba_product_operands;
|
||||
evtgba_product(const evtgba_product_operands& op);
|
||||
virtual ~evtgba_product();
|
||||
|
||||
virtual evtgba_iterator* init_iter() const;
|
||||
virtual evtgba_iterator* succ_iter(const state* s) const;
|
||||
virtual evtgba_iterator* pred_iter(const state* s) const;
|
||||
|
||||
/// \brief Format the state as a string for printing.
|
||||
///
|
||||
/// This formating is the responsability of the automata
|
||||
/// who owns the state.
|
||||
virtual std::string format_state(const state* state) const;
|
||||
|
||||
/// \brief Return the set of all acceptance conditions used
|
||||
/// by this automaton.
|
||||
///
|
||||
/// The goal of the emptiness check is to ensure that
|
||||
/// a strongly connected component walks through each
|
||||
/// of these acceptiong conditions. I.e., the union
|
||||
/// of the acceptiong conditions of all transition in
|
||||
/// the SCC should be equal to the result of this function.
|
||||
virtual const symbol_set& all_acceptance_conditions() const;
|
||||
virtual const symbol_set& alphabet() const;
|
||||
|
||||
typedef std::map<const symbol*, std::set<int> > common_symbol_table;
|
||||
private:
|
||||
const evtgba_product_operands op_;
|
||||
symbol_set alphabet_;
|
||||
symbol_set all_acc_;
|
||||
common_symbol_table common_symbols_;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // SPOT_EVTGBA_PRODUCT_HH
|
||||
109
src/evtgba/symbol.cc
Normal file
109
src/evtgba/symbol.cc
Normal file
|
|
@ -0,0 +1,109 @@
|
|||
// Copyright (C) 2004 Laboratoire d'Informatique de Paris 6 (LIP6),
|
||||
// département Systèmes Répartis Coopératifs (SRC), Université Pierre
|
||||
// et Marie Curie.
|
||||
//
|
||||
// This file is part of Spot, a model checking library.
|
||||
//
|
||||
// Spot is free software; you can redistribute it and/or modify it
|
||||
// under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation; either version 2 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Spot is distributed in the hope that it will be useful, but WITHOUT
|
||||
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
// or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
|
||||
// License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Spot; see the file COPYING. If not, write to the Free
|
||||
// Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
|
||||
// 02111-1307, USA.
|
||||
|
||||
#include <cassert>
|
||||
#include "symbol.hh"
|
||||
#include <ostream>
|
||||
|
||||
namespace spot
|
||||
{
|
||||
symbol::map symbol::instances_;
|
||||
|
||||
symbol::symbol(const std::string* name)
|
||||
: name_(name), refs_(1)
|
||||
{
|
||||
}
|
||||
|
||||
symbol::~symbol()
|
||||
{
|
||||
map::iterator i = instances_.find(name());
|
||||
assert (i != instances_.end());
|
||||
instances_.erase(i);
|
||||
}
|
||||
|
||||
const symbol*
|
||||
symbol::instance(const std::string& name)
|
||||
{
|
||||
map::iterator i = instances_.find(name);
|
||||
if (i != instances_.end())
|
||||
{
|
||||
const symbol* s = i->second;
|
||||
s->ref();
|
||||
return s;
|
||||
}
|
||||
// Convoluted insertion because we want the NAME member of the
|
||||
// value to point to the key.
|
||||
i = instances_.insert(map::value_type(name, 0)).first;
|
||||
i->second = new symbol(&i->first);
|
||||
return i->second;
|
||||
}
|
||||
|
||||
const std::string&
|
||||
symbol::name() const
|
||||
{
|
||||
return *name_;
|
||||
}
|
||||
|
||||
void
|
||||
symbol::ref() const
|
||||
{
|
||||
++refs_;
|
||||
}
|
||||
|
||||
void
|
||||
symbol::unref() const
|
||||
{
|
||||
assert(refs_ > 0);
|
||||
--refs_;
|
||||
if (!refs_)
|
||||
delete this;
|
||||
}
|
||||
|
||||
int
|
||||
symbol::ref_count_() const
|
||||
{
|
||||
return refs_;
|
||||
}
|
||||
|
||||
unsigned
|
||||
symbol::instance_count()
|
||||
{
|
||||
return instances_.size();
|
||||
}
|
||||
|
||||
std::ostream&
|
||||
symbol::dump_instances(std::ostream& os)
|
||||
{
|
||||
for (map::iterator i = instances_.begin(); i != instances_.end(); ++i)
|
||||
{
|
||||
os << i->second << " = " << i->second->ref_count_()
|
||||
<< " * symbol(" << i->second->name() << ")" << std::endl;
|
||||
}
|
||||
return os;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
126
src/evtgba/symbol.hh
Normal file
126
src/evtgba/symbol.hh
Normal file
|
|
@ -0,0 +1,126 @@
|
|||
// Copyright (C) 2004 Laboratoire d'Informatique de Paris 6 (LIP6),
|
||||
// département Systèmes Répartis Coopératifs (SRC), Université Pierre
|
||||
// et Marie Curie.
|
||||
//
|
||||
// This file is part of Spot, a model checking library.
|
||||
//
|
||||
// Spot is free software; you can redistribute it and/or modify it
|
||||
// under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation; either version 2 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Spot is distributed in the hope that it will be useful, but WITHOUT
|
||||
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
// or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
|
||||
// License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Spot; see the file COPYING. If not, write to the Free
|
||||
// Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
|
||||
// 02111-1307, USA.
|
||||
|
||||
#ifndef SPOT_EVTGBA_SYMBOL_HH
|
||||
# define SPOT_EVTGBA_SYMBOL_HH
|
||||
|
||||
#include <string>
|
||||
#include <iosfwd>
|
||||
#include <map>
|
||||
#include <set>
|
||||
|
||||
namespace spot
|
||||
{
|
||||
class symbol
|
||||
{
|
||||
public:
|
||||
static const symbol* instance(const std::string& name);
|
||||
const std::string& name() const;
|
||||
|
||||
/// Number of instantiated atomic propositions. For debugging.
|
||||
static unsigned instance_count();
|
||||
/// List all instances of atomic propositions. For debugging.
|
||||
static std::ostream& dump_instances(std::ostream& os);
|
||||
|
||||
void ref() const;
|
||||
void unref() const;
|
||||
|
||||
protected:
|
||||
int ref_count_() const;
|
||||
symbol(const std::string* name);
|
||||
~symbol();
|
||||
typedef std::map<const std::string, const symbol*> map;
|
||||
static map instances_;
|
||||
private:
|
||||
symbol(const symbol&); /// Undefined.
|
||||
const std::string* name_;
|
||||
mutable int refs_;
|
||||
};
|
||||
|
||||
class rsymbol
|
||||
{
|
||||
public:
|
||||
rsymbol(const symbol* s): s_(s)
|
||||
{
|
||||
}
|
||||
|
||||
rsymbol(const std::string& s): s_(symbol::instance(s))
|
||||
{
|
||||
}
|
||||
|
||||
rsymbol(const char* s): s_(symbol::instance(s))
|
||||
{
|
||||
}
|
||||
|
||||
rsymbol(const rsymbol& rs): s_(rs.s_)
|
||||
{
|
||||
s_->ref();
|
||||
}
|
||||
|
||||
~rsymbol()
|
||||
{
|
||||
s_->unref();
|
||||
}
|
||||
|
||||
operator const symbol*() const
|
||||
{
|
||||
return s_;
|
||||
}
|
||||
|
||||
const rsymbol&
|
||||
operator=(const rsymbol& rs)
|
||||
{
|
||||
if (this != &rs)
|
||||
{
|
||||
this->~rsymbol();
|
||||
new (this) rsymbol(rs);
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
bool
|
||||
operator==(const rsymbol& rs) const
|
||||
{
|
||||
return s_ == rs.s_;
|
||||
}
|
||||
|
||||
bool
|
||||
operator!=(const rsymbol& rs) const
|
||||
{
|
||||
return s_ != rs.s_;
|
||||
}
|
||||
|
||||
bool
|
||||
operator<(const rsymbol& rs) const
|
||||
{
|
||||
return s_ < rs.s_;
|
||||
}
|
||||
|
||||
private:
|
||||
const symbol* s_;
|
||||
};
|
||||
|
||||
typedef std::set<const symbol*> symbol_set;
|
||||
typedef std::set<rsymbol> rsymbol_set;
|
||||
|
||||
}
|
||||
|
||||
#endif // SPOT_EVTGBA_SYMBOL_HH
|
||||
Loading…
Add table
Add a link
Reference in a new issue