Implements spot::ltl::destroy() and exercise it.

* src/ltlast/atomic_prop.hh: Declare instance_count().
* src/ltlast/binop.hh, src/ltlast/unop.hh, src/ltlast/multop.hh:
Likewise.  Also, really inherit for ref_formula this time.
* src/ltlast/atomic_prop.cc, src/ltlast/binop.cc,
src/ltlast/unop.cc, src/ltlast/multop.cc: On destruction, suppress
the instance from the instance map.  Implement instance_count().
* src/ltlast/formula.cc, src/ltlast/formula.hh,
src/ltlast/ref_formula.cc, src/ltlast/ref_formula.hh: Add virtual
destructors.
* src/ltlparse/ltlparse.yy: Recover from binary operators with
missing right hand operand (the point is just to destroy the
the left hand operand).
* src/ltltest/equals.cc, src/ltltest/readltl.cc,
src/ltltest/tostring.cc: Destroy used formulae.  Make sure
instance_count()s are null are the end.
* src/ltltest/parseerr.test: Adjust expected result, now
that the parser lnows about missing right hand operands.
* src/ltlvisit/destroy.hh, src/ltlvisit/destroy.cc,
src/ltlvisit/postfix.hh, src/ltlvisit/postfix.cc: New files.
* src/ltlvisit/Makefile.am (libltlvisit_la_SOURCES): Add them.
* src/ltlvisit/lunabbrev.cc (Xor, Equiv): Clone formulae
occurring twice in the rewritten expression.
This commit is contained in:
Alexandre Duret-Lutz 2003-05-15 18:06:54 +00:00
parent 5f6d8b6234
commit 9123e56ff9
24 changed files with 382 additions and 24 deletions

View file

@ -13,6 +13,11 @@ namespace spot
atomic_prop::~atomic_prop()
{
// Get this instance out of the instance map.
pair p(name(), &env());
map::iterator i = instances.find(p);
assert (i != instances.end());
instances.erase(i);
}
void
@ -55,5 +60,11 @@ namespace spot
return static_cast<atomic_prop*>(ap->ref());
}
unsigned
atomic_prop::instance_count()
{
return instances.size();
}
}
}

View file

@ -26,6 +26,10 @@ namespace spot
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();
protected:
atomic_prop(const std::string& name, environment& env);
virtual ~atomic_prop();

View file

@ -13,6 +13,12 @@ namespace spot
binop::~binop()
{
// Get this instance out of the instance map.
pairf pf(first(), second());
pair p(op(), pf);
map::iterator i = instances.find(p);
assert (i != instances.end());
instances.erase(i);
}
void
@ -95,5 +101,10 @@ namespace spot
return static_cast<binop*>(ap->ref());
}
unsigned
binop::instance_count()
{
return instances.size();
}
}
}

View file

@ -2,7 +2,7 @@
# define SPOT_LTLAST_BINOP_HH
#include <map>
#include "formula.hh"
#include "refformula.hh"
namespace spot
{
@ -10,7 +10,7 @@ namespace spot
{
/// Binary operator.
class binop : public formula
class binop : public ref_formula
{
public:
/// Different kinds of binary opertaors
@ -40,6 +40,9 @@ namespace spot
/// 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;

View file

@ -11,6 +11,10 @@ namespace spot
return this;
}
formula::~formula()
{
}
void
formula::unref(formula* f)
{

View file

@ -15,6 +15,8 @@ namespace spot
class formula
{
public:
virtual ~formula();
virtual void accept(visitor& v) = 0;
virtual void accept(const_visitor& v) const = 0;

View file

@ -14,6 +14,12 @@ namespace spot
multop::~multop()
{
// Get this instance out of the instance map.
pair p(op(), children_);
map::iterator i = instances.find(p);
assert (i != instances.end());
instances.erase(i);
delete children_;
}
@ -132,5 +138,10 @@ namespace spot
*m = instance(op, v);
}
unsigned
multop::instance_count()
{
return instances.size();
}
}
}

View file

@ -3,7 +3,7 @@
#include <vector>
#include <map>
#include "formula.hh"
#include "refformula.hh"
namespace spot
{
@ -13,7 +13,7 @@ namespace spot
/// \brief Multi-operand operators.
///
/// These operators are considered commutative and associative.
class multop : public formula
class multop : public ref_formula
{
public:
enum type { Or, And };
@ -61,6 +61,9 @@ namespace spot
/// 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::vector<formula*> vec;
typedef std::pair<type, vec*> pair;

View file

@ -10,6 +10,10 @@ namespace spot
{
}
ref_formula::~ref_formula()
{
}
void
ref_formula::ref_()
{

View file

@ -12,6 +12,7 @@ namespace spot
class ref_formula : public formula
{
protected:
virtual ~ref_formula();
ref_formula();
void ref_();
bool unref_();

View file

@ -13,6 +13,11 @@ namespace spot
unop::~unop()
{
// Get this instance out of the instance map.
pair p(op(), child());
map::iterator i = instances.find(p);
assert (i != instances.end());
instances.erase(i);
}
void
@ -80,5 +85,10 @@ namespace spot
return static_cast<unop*>(ap->ref());
}
unsigned
unop::instance_count()
{
return instances.size();
}
}
}

View file

@ -2,7 +2,7 @@
# define SPOT_LTLAST_UNOP_HH
#include <map>
#include "formula.hh"
#include "refformula.hh"
namespace spot
{
@ -10,7 +10,7 @@ namespace spot
{
/// Unary operator.
class unop : public formula
class unop : public ref_formula
{
public:
enum type { Not, X, F, G };
@ -32,6 +32,9 @@ namespace spot
/// 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;