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
|
|
@ -19,9 +19,6 @@
|
|||
## Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
|
||||
## 02111-1307, USA.
|
||||
|
||||
AM_CPPFLAGS = -I$(srcdir)/..
|
||||
AM_CXXFLAGS = $(WARNING_CXXFLAGS)
|
||||
|
||||
ltlastdir = $(pkgincludedir)/ltlast
|
||||
|
||||
ltlast_HEADERS = \
|
||||
|
|
@ -31,17 +28,6 @@ ltlast_HEADERS = \
|
|||
constant.hh \
|
||||
formula.hh \
|
||||
multop.hh \
|
||||
predecl.hh \
|
||||
refformula.hh \
|
||||
unop.hh \
|
||||
visitor.hh
|
||||
|
||||
noinst_LTLIBRARIES = libltlast.la
|
||||
libltlast_la_SOURCES = \
|
||||
atomic_prop.cc \
|
||||
binop.cc \
|
||||
constant.cc \
|
||||
formula.cc \
|
||||
multop.cc \
|
||||
refformula.cc \
|
||||
unop.cc
|
||||
|
|
|
|||
|
|
@ -23,8 +23,6 @@
|
|||
/// \brief Define all LTL node types.
|
||||
///
|
||||
/// This file is usually needed when \b defining a visitor.
|
||||
/// Prefer ltlast/predecl.hh when only \b declaring methods and functions
|
||||
/// over LTL nodes.
|
||||
#ifndef SPOT_LTLAST_ALLNODES_HH
|
||||
# define SPOT_LTLAST_ALLNODES_HH
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
// Copyright (C) 2003, 2004 Laboratoire d'Informatique de Paris 6 (LIP6),
|
||||
// Copyright (C) 2008 Laboratoire d'Informatique de Paris 6 (LIP6),
|
||||
// département Systèmes Répartis Coopératifs (SRC), Université Pierre
|
||||
// et Marie Curie.
|
||||
//
|
||||
|
|
@ -24,11 +24,8 @@
|
|||
#ifndef SPOT_LTLAST_ATOMIC_PROP_HH
|
||||
# define SPOT_LTLAST_ATOMIC_PROP_HH
|
||||
|
||||
#include <string>
|
||||
#include <iosfwd>
|
||||
#include <map>
|
||||
#include "refformula.hh"
|
||||
#include "ltlenv/environment.hh"
|
||||
# include "formula.hh"
|
||||
# include "internal/atomic_prop.hh"
|
||||
|
||||
namespace spot
|
||||
{
|
||||
|
|
@ -37,38 +34,7 @@ namespace spot
|
|||
|
||||
/// \brief Atomic propositions.
|
||||
/// \ingroup ltl_ast
|
||||
class atomic_prop : public ref_formula
|
||||
{
|
||||
public:
|
||||
/// Build an atomic proposition with name \a name in
|
||||
/// environment \a env.
|
||||
static atomic_prop* instance(const std::string& name, environment& env);
|
||||
|
||||
virtual void accept(visitor& visitor);
|
||||
virtual void accept(const_visitor& visitor) const;
|
||||
|
||||
/// Get the name of the atomic proposition.
|
||||
const std::string& name() const;
|
||||
/// Get the environment of the atomic proposition.
|
||||
environment& env() 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);
|
||||
|
||||
protected:
|
||||
atomic_prop(const std::string& name, environment& env);
|
||||
virtual ~atomic_prop();
|
||||
|
||||
typedef std::pair<std::string, environment*> pair;
|
||||
typedef std::map<pair, atomic_prop*> map;
|
||||
static map instances;
|
||||
|
||||
private:
|
||||
std::string name_;
|
||||
environment* env_;
|
||||
};
|
||||
typedef spot::internal::atomic_prop<ltl_t> atomic_prop;
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
// Copyright (C) 2003, 2004 Laboratoire d'Informatique de Paris 6 (LIP6),
|
||||
// Copyright (C) 2008 Laboratoire d'Informatique de Paris 6 (LIP6),
|
||||
// département Systèmes Répartis Coopératifs (SRC), Université Pierre
|
||||
// et Marie Curie.
|
||||
//
|
||||
|
|
@ -27,8 +27,8 @@
|
|||
#ifndef SPOT_LTLAST_BINOP_HH
|
||||
# define SPOT_LTLAST_BINOP_HH
|
||||
|
||||
#include <map>
|
||||
#include "refformula.hh"
|
||||
# include "formula.hh"
|
||||
# include "internal/binop.hh"
|
||||
|
||||
namespace spot
|
||||
{
|
||||
|
|
@ -37,53 +37,7 @@ namespace spot
|
|||
|
||||
/// \brief Binary operator.
|
||||
/// \ingroup ltl_ast
|
||||
class binop : public ref_formula
|
||||
{
|
||||
public:
|
||||
/// Different kinds of binary opertaors
|
||||
///
|
||||
/// And and Or are not here. Because they
|
||||
/// are often nested we represent them as multops.
|
||||
enum type { Xor, Implies, Equiv, U, R };
|
||||
|
||||
/// Build an unary operator with operation \a op and
|
||||
/// children \a first and \a second.
|
||||
static binop* instance(type op, formula* first, formula* second);
|
||||
|
||||
virtual void accept(visitor& v);
|
||||
virtual void accept(const_visitor& v) const;
|
||||
|
||||
/// Get the first operand.
|
||||
const formula* first() const;
|
||||
/// Get the first operand.
|
||||
formula* first();
|
||||
/// Get the second operand.
|
||||
const formula* second() const;
|
||||
/// Get the second operand.
|
||||
formula* second();
|
||||
|
||||
/// Get the type of this operator.
|
||||
type op() const;
|
||||
/// Get the type of this operator, as a string.
|
||||
const char* op_name() const;
|
||||
|
||||
/// Number of instantiated binary operators. For debugging.
|
||||
static unsigned instance_count();
|
||||
|
||||
protected:
|
||||
typedef std::pair<formula*, formula*> pairf;
|
||||
typedef std::pair<type, pairf> pair;
|
||||
typedef std::map<pair, formula*> map;
|
||||
static map instances;
|
||||
|
||||
binop(type op, formula* first, formula* second);
|
||||
virtual ~binop();
|
||||
|
||||
private:
|
||||
type op_;
|
||||
formula* first_;
|
||||
formula* second_;
|
||||
};
|
||||
typedef spot::internal::binop<ltl_t> binop;
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,7 +24,8 @@
|
|||
#ifndef SPOT_LTLAST_CONSTANT_HH
|
||||
# define SPOT_LTLAST_CONSTANT_HH
|
||||
|
||||
#include "formula.hh"
|
||||
# include "formula.hh"
|
||||
# include "internal/constant.hh"
|
||||
|
||||
namespace spot
|
||||
{
|
||||
|
|
@ -33,30 +34,7 @@ namespace spot
|
|||
|
||||
/// \brief A constant (True or False)
|
||||
/// \ingroup ltl_ast
|
||||
class constant : public formula
|
||||
{
|
||||
public:
|
||||
enum type { False, True };
|
||||
virtual void accept(visitor& v);
|
||||
virtual void accept(const_visitor& v) const;
|
||||
|
||||
/// Return the value of the constant.
|
||||
type val() const;
|
||||
/// Return the value of the constant as a string.
|
||||
const char* val_name() const;
|
||||
|
||||
/// Get the sole instance of spot::ltl::constant::constant(True).
|
||||
static constant* true_instance();
|
||||
/// Get the sole instance of spot::ltl::constant::constant(False).
|
||||
static constant* false_instance();
|
||||
|
||||
protected:
|
||||
constant(type val);
|
||||
virtual ~constant();
|
||||
|
||||
private:
|
||||
type val_;
|
||||
};
|
||||
typedef spot::internal::constant<ltl_t> constant;
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
// Copyright (C) 2003, 2004 Laboratoire d'Informatique de Paris 6 (LIP6),
|
||||
// Copyright (C) 2008 Laboratoire d'Informatique de Paris 6 (LIP6),
|
||||
// département Systèmes Répartis Coopératifs (SRC), Université Pierre
|
||||
// et Marie Curie.
|
||||
//
|
||||
|
|
@ -24,9 +24,8 @@
|
|||
#ifndef SPOT_LTLAST_MULTOP_HH
|
||||
# define SPOT_LTLAST_MULTOP_HH
|
||||
|
||||
#include <vector>
|
||||
#include <map>
|
||||
#include "refformula.hh"
|
||||
# include "formula.hh"
|
||||
# include "internal/multop.hh"
|
||||
|
||||
namespace spot
|
||||
{
|
||||
|
|
@ -37,87 +36,7 @@ namespace spot
|
|||
/// \ingroup ltl_ast
|
||||
///
|
||||
/// These operators are considered commutative and associative.
|
||||
class multop : public ref_formula
|
||||
{
|
||||
public:
|
||||
enum type { Or, And };
|
||||
|
||||
/// List of formulae.
|
||||
typedef std::vector<formula*> vec;
|
||||
|
||||
/// \brief Build a spot::ltl::multop with two children.
|
||||
///
|
||||
/// If one of the children itself is a spot::ltl::multop
|
||||
/// with the same type, it will be merged. I.e., children
|
||||
/// if that child will be added, and that child itself will
|
||||
/// be destroyed. This allows incremental building of
|
||||
/// n-ary ltl::multop.
|
||||
///
|
||||
/// This functions can perform slight optimizations and
|
||||
/// may not return an ltl::multop objects. For instance
|
||||
/// if \c first and \c second are equal, that formula is
|
||||
/// returned as-is.
|
||||
static formula* instance(type op, formula* first, formula* second);
|
||||
|
||||
/// \brief Build a spot::ltl::multop with many children.
|
||||
///
|
||||
/// Same as the other instance() function, but take a vector of
|
||||
/// formula in argument. This vector is acquired by the
|
||||
/// spot::ltl::multop class, the caller should allocate it with
|
||||
/// \c new, but not use it (especially not destroy it) after it
|
||||
/// has been passed to spot::ltl::multop.
|
||||
///
|
||||
/// This functions can perform slight optimizations and
|
||||
/// may not return an ltl::multop objects. For instance
|
||||
/// if the vector contain only one unique element, this
|
||||
/// this formula will be returned as-is.
|
||||
static formula* instance(type op, vec* v);
|
||||
|
||||
virtual void accept(visitor& v);
|
||||
virtual void accept(const_visitor& v) const;
|
||||
|
||||
/// Get the number of children.
|
||||
unsigned size() const;
|
||||
/// \brief Get the nth children.
|
||||
///
|
||||
/// Starting with \a n = 0.
|
||||
const formula* nth(unsigned n) const;
|
||||
/// \brief Get the nth children.
|
||||
///
|
||||
/// Starting with \a n = 0.
|
||||
formula* nth(unsigned n);
|
||||
|
||||
/// Get the type of this operator.
|
||||
type op() const;
|
||||
/// Get the type of this operator, as a string.
|
||||
const char* op_name() const;
|
||||
|
||||
/// Number of instantiated multi-operand operators. For debugging.
|
||||
static unsigned instance_count();
|
||||
|
||||
protected:
|
||||
typedef std::pair<type, vec*> pair;
|
||||
/// Comparison functor used internally by ltl::multop.
|
||||
struct paircmp
|
||||
{
|
||||
bool
|
||||
operator () (const pair& p1, const pair& p2) const
|
||||
{
|
||||
if (p1.first != p2.first)
|
||||
return p1.first < p2.first;
|
||||
return *p1.second < *p2.second;
|
||||
}
|
||||
};
|
||||
typedef std::map<pair, formula*, paircmp> map;
|
||||
static map instances;
|
||||
|
||||
multop(type op, vec* v);
|
||||
virtual ~multop();
|
||||
|
||||
private:
|
||||
type op_;
|
||||
vec* children_;
|
||||
};
|
||||
typedef spot::internal::multop<ltl_t> multop;
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
// Copyright (C) 2003, 2004, 2005 Laboratoire d'Informatique de Paris 6 (LIP6),
|
||||
// Copyright (C) 2008 Laboratoire d'Informatique de Paris 6 (LIP6),
|
||||
// département Systèmes Répartis Coopératifs (SRC), Université Pierre
|
||||
// et Marie Curie.
|
||||
//
|
||||
|
|
@ -24,7 +24,8 @@
|
|||
#ifndef SPOT_LTLAST_REFFORMULA_HH
|
||||
# define SPOT_LTLAST_REFFORMULA_HH
|
||||
|
||||
#include "formula.hh"
|
||||
# include "formula.hh"
|
||||
# include "internal/refformula.hh"
|
||||
|
||||
namespace spot
|
||||
{
|
||||
|
|
@ -33,18 +34,7 @@ namespace spot
|
|||
|
||||
/// \brief A reference-counted LTL formula.
|
||||
/// \ingroup ltl_ast
|
||||
class ref_formula : public formula
|
||||
{
|
||||
protected:
|
||||
virtual ~ref_formula();
|
||||
ref_formula();
|
||||
void ref_();
|
||||
bool unref_();
|
||||
/// Number of references to this formula.
|
||||
unsigned ref_count_();
|
||||
private:
|
||||
unsigned ref_counter_;
|
||||
};
|
||||
typedef spot::internal::ref_formula<ltl_t> ref_formula;
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
// Copyright (C) 2003, 2004 Laboratoire d'Informatique de Paris 6 (LIP6),
|
||||
// Copyright (C) 2008 Laboratoire d'Informatique de Paris 6 (LIP6),
|
||||
// département Systèmes Répartis Coopératifs (SRC), Université Pierre
|
||||
// et Marie Curie.
|
||||
//
|
||||
|
|
@ -24,8 +24,8 @@
|
|||
#ifndef SPOT_LTLAST_UNOP_HH
|
||||
# define SPOT_LTLAST_UNOP_HH
|
||||
|
||||
#include <map>
|
||||
#include "refformula.hh"
|
||||
# include "formula.hh"
|
||||
# include "internal/unop.hh"
|
||||
|
||||
namespace spot
|
||||
{
|
||||
|
|
@ -34,43 +34,7 @@ namespace spot
|
|||
|
||||
/// \brief Unary operators.
|
||||
/// \ingroup ltl_ast
|
||||
class unop : public ref_formula
|
||||
{
|
||||
public:
|
||||
enum type { Not, X, F, G };
|
||||
|
||||
/// Build an unary operator with operation \a op and
|
||||
/// child \a child.
|
||||
static unop* instance(type op, formula* child);
|
||||
|
||||
virtual void accept(visitor& v);
|
||||
virtual void accept(const_visitor& v) const;
|
||||
|
||||
/// Get the sole operand of this operator.
|
||||
const formula* child() const;
|
||||
/// Get the sole operand of this operator.
|
||||
formula* child();
|
||||
|
||||
/// Get the type of this operator.
|
||||
type op() const;
|
||||
/// Get the type of this operator, as a string.
|
||||
const char* op_name() const;
|
||||
|
||||
/// Number of instantiated unary operators. For debugging.
|
||||
static unsigned instance_count();
|
||||
|
||||
protected:
|
||||
typedef std::pair<type, formula*> pair;
|
||||
typedef std::map<pair, formula*> map;
|
||||
static map instances;
|
||||
|
||||
unop(type op, formula* child);
|
||||
virtual ~unop();
|
||||
|
||||
private:
|
||||
type op_;
|
||||
formula* child_;
|
||||
};
|
||||
typedef spot::internal::unop<ltl_t> unop;
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
// Copyright (C) 2003, 2004, 2005 Laboratoire d'Informatique de Paris 6 (LIP6),
|
||||
// département Systèmes Répartis Coopératifs (SRC), Université Pierre
|
||||
// et Marie Curie.
|
||||
// Copyright (C) 2003, 2004, 2005, 2008 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.
|
||||
//
|
||||
|
|
@ -24,7 +24,11 @@
|
|||
#ifndef SPOT_LTLAST_VISITOR_HH
|
||||
# define SPOT_LTLAST_VISITOR_HH
|
||||
|
||||
#include "predecl.hh"
|
||||
# include "binop.hh"
|
||||
# include "unop.hh"
|
||||
# include "multop.hh"
|
||||
# include "atomic_prop.hh"
|
||||
# include "constant.hh"
|
||||
|
||||
namespace spot
|
||||
{
|
||||
|
|
@ -67,7 +71,6 @@ namespace spot
|
|||
virtual void visit(const multop* node) = 0;
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue