Template ltlast/ & ltlenv/ classes in internal/ & Add ELTL parser.
This commit is contained in:
parent
21c98c0a01
commit
543190f2bc
74 changed files with 4299 additions and 468 deletions
|
|
@ -24,9 +24,7 @@
|
|||
#ifndef SPOT_LTLAST_FORMULA_HH
|
||||
# define SPOT_LTLAST_FORMULA_HH
|
||||
|
||||
#include <string>
|
||||
#include <cassert>
|
||||
#include "predecl.hh"
|
||||
# include "internal/formula.hh"
|
||||
|
||||
namespace spot
|
||||
{
|
||||
|
|
@ -61,6 +59,54 @@ namespace spot
|
|||
/// \addtogroup ltl_misc Miscellaneous algorithms for LTL formulae
|
||||
/// \ingroup ltl_algorithm
|
||||
|
||||
struct visitor;
|
||||
struct const_visitor;
|
||||
|
||||
struct ltl_t
|
||||
{
|
||||
typedef spot::ltl::visitor visitor;
|
||||
typedef spot::ltl::const_visitor const_visitor;
|
||||
|
||||
enum binop { Xor, Implies, Equiv, U, R };
|
||||
const char* binop_name(binop op) const
|
||||
{
|
||||
switch (op)
|
||||
{
|
||||
case Xor:
|
||||
return "Xor";
|
||||
case Implies:
|
||||
return "Implies";
|
||||
case Equiv:
|
||||
return "Equiv";
|
||||
case U:
|
||||
return "U";
|
||||
case R:
|
||||
return "R";
|
||||
}
|
||||
// Unreachable code.
|
||||
assert(0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
enum unop { Not, X, F, G };
|
||||
const char* unop_name(unop op) const
|
||||
{
|
||||
switch (op)
|
||||
{
|
||||
case Not:
|
||||
return "Not";
|
||||
case X:
|
||||
return "X";
|
||||
case F:
|
||||
return "F";
|
||||
case G:
|
||||
return "G";
|
||||
}
|
||||
// Unreachable code.
|
||||
assert(0);
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
|
||||
/// \brief An LTL formula.
|
||||
/// \ingroup ltl_essential
|
||||
|
|
@ -68,114 +114,10 @@ namespace spot
|
|||
///
|
||||
/// The only way you can work with a formula is to
|
||||
/// build a spot::ltl::visitor or spot::ltl::const_visitor.
|
||||
class formula
|
||||
{
|
||||
public:
|
||||
/// Entry point for vspot::ltl::visitor instances.
|
||||
virtual void accept(visitor& v) = 0;
|
||||
/// Entry point for vspot::ltl::const_visitor instances.
|
||||
virtual void accept(const_visitor& v) const = 0;
|
||||
|
||||
/// \brief clone this node
|
||||
///
|
||||
/// This increments the reference counter of this node (if one is
|
||||
/// used). You should almost never use this method directly as
|
||||
/// it doesn't touch the children. If you want to clone a
|
||||
/// whole formula, use spot::ltl::clone() instead.
|
||||
formula* ref();
|
||||
/// \brief release this node
|
||||
///
|
||||
/// This decrements the reference counter of this node (if one is
|
||||
/// used) and can free the object. You should almost never use
|
||||
/// this method directly as it doesn't touch the children. If you
|
||||
/// want to release a whole formula, use spot::ltl::destroy() instead.
|
||||
static void unref(formula* f);
|
||||
|
||||
/// Return a canonic representation of the formula
|
||||
const std::string& dump() const;
|
||||
|
||||
/// Return a hash_key for the formula.
|
||||
size_t
|
||||
hash() const
|
||||
{
|
||||
return hash_key_;
|
||||
}
|
||||
protected:
|
||||
virtual ~formula();
|
||||
|
||||
/// \brief increment reference counter if any
|
||||
virtual void ref_();
|
||||
/// \brief decrement reference counter if any, return true when
|
||||
/// the instance must be deleted (usually when the counter hits 0).
|
||||
virtual bool unref_();
|
||||
|
||||
/// \brief Compute key_ from dump_.
|
||||
///
|
||||
/// Should be called once in each object, after dump_ has been set.
|
||||
void set_key_();
|
||||
/// The canonic representation of the formula
|
||||
std::string dump_;
|
||||
/// \brief The hash key of this formula.
|
||||
///
|
||||
/// Initialized by set_key_().
|
||||
size_t hash_key_;
|
||||
};
|
||||
|
||||
/// \brief Strict Weak Ordering for <code>const formula*</code>.
|
||||
/// \ingroup ltl_essentials
|
||||
///
|
||||
/// This is meant to be used as a comparison functor for
|
||||
/// STL \c map whose key are of type <code>const formula*</code>.
|
||||
///
|
||||
/// For instance here is how one could declare
|
||||
/// a map of \c const::formula*.
|
||||
/// \code
|
||||
/// // Remember how many times each formula has been seen.
|
||||
/// std::map<const spot::ltl::formula*, int,
|
||||
/// spot::formula_ptr_less_than> seen;
|
||||
/// \endcode
|
||||
struct formula_ptr_less_than:
|
||||
public std::binary_function<const formula*, const formula*, bool>
|
||||
{
|
||||
bool
|
||||
operator()(const formula* left, const formula* right) const
|
||||
{
|
||||
assert(left);
|
||||
assert(right);
|
||||
size_t l = left->hash();
|
||||
size_t r = right->hash();
|
||||
if (1 != r)
|
||||
return l < r;
|
||||
return left->dump() < right->dump();
|
||||
}
|
||||
};
|
||||
|
||||
/// \brief Hash Function for <code>const formula*</code>.
|
||||
/// \ingroup ltl_essentials
|
||||
/// \ingroup hash_funcs
|
||||
///
|
||||
/// This is meant to be used as a hash functor for
|
||||
/// Sgi's \c hash_map whose key are of type <code>const formula*</code>.
|
||||
///
|
||||
/// For instance here is how one could declare
|
||||
/// a map of \c const::formula*.
|
||||
/// \code
|
||||
/// // Remember how many times each formula has been seen.
|
||||
/// Sgi::hash_map<const spot::ltl::formula*, int,
|
||||
/// const spot::ltl::formula_ptr_hash> seen;
|
||||
/// \endcode
|
||||
struct formula_ptr_hash:
|
||||
public std::unary_function<const formula*, size_t>
|
||||
{
|
||||
size_t
|
||||
operator()(const formula* that) const
|
||||
{
|
||||
assert(that);
|
||||
return that->hash();
|
||||
}
|
||||
};
|
||||
|
||||
typedef spot::internal::formula<ltl_t> formula;
|
||||
|
||||
typedef spot::internal::formula_ptr_less_than<ltl_t> formula_ptr_less_than;
|
||||
typedef spot::internal::formula_ptr_hash<ltl_t> formula_ptr_hash;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue