ltl: get rid of ltl::ref_formula

Instead, manage all reference counting from ltl::formula.
It ridance of virtual calls to clone() and destroy() easily compensate
the extra test in destroy() to not delete constant nodes.

* src/ltlast/refformula.cc, src/ltlast/refformula.hh: Delete.
* src/ltlast/Makefile.am, wrap/python/spot.i: Adjust.
* src/ltlast/atomic_prop.cc, src/ltlast/atomic_prop.hh,
src/ltlast/binop.cc, src/ltlast/binop.hh, src/ltlast/bunop.cc,
src/ltlast/bunop.hh, src/ltlast/formula.cc, src/ltlast/formula.hh,
src/ltlast/multop.cc, src/ltlast/multop.hh, src/ltlast/unop.cc,
src/ltlast/unop.hh: Ajust the reference counting code.
This commit is contained in:
Alexandre Duret-Lutz 2014-10-25 16:47:44 +02:00
parent d79da2e941
commit 8d947a8782
16 changed files with 70 additions and 210 deletions

View file

@ -97,14 +97,27 @@ namespace spot
/// \brief clone this node
///
/// This increments the reference counter of this node (if one is
/// used).
const formula* clone() const;
/// \brief release this node
///
/// This decrements the reference counter of this node (if one is
/// used) and can free the object.
void destroy() const;
/// This increments the reference counter of the node.
const formula* clone() const
{
++refs_;
return this;
}
/// \brief Release this node
void destroy() const
{
// Delete if this is the last node, and it is not a constant.
if (!refs_)
{
if (kind() != Constant)
delete this;
}
else
{
--refs_;
}
}
/// Return a canonic representation of the formula
virtual std::string dump() const = 0;
@ -293,17 +306,19 @@ namespace spot
return serial_;
}
protected:
virtual ~formula();
/// \brief increment reference counter if any
virtual void ref_() const;
/// \brief decrement reference counter if any, return true when
/// the instance must be deleted (usually when the counter hits 0).
virtual bool unref_() const;
virtual ~formula()
{
}
/// \brief The hash key of this formula.
size_t serial_;
// The number of actual references is refs_ + 1.
mutable unsigned refs_ = 0;
/// \brief Number of formulae created so far.
static size_t max_serial;
opkind kind_;
struct ltl_prop
{
// All properties here should be expressed in such a a way
@ -346,11 +361,6 @@ namespace spot
unsigned props;
ltl_prop is;
};
private:
/// \brief Number of formulae created so far.
static size_t max_serial;
opkind kind_;
};