* 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.
110 lines
1.7 KiB
C++
110 lines
1.7 KiB
C++
#include <cassert>
|
|
#include "binop.hh"
|
|
#include "visitor.hh"
|
|
|
|
namespace spot
|
|
{
|
|
namespace ltl
|
|
{
|
|
binop::binop(type op, formula* first, formula* second)
|
|
: op_(op), first_(first), second_(second)
|
|
{
|
|
}
|
|
|
|
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
|
|
binop::accept(visitor& v)
|
|
{
|
|
v.visit(this);
|
|
}
|
|
|
|
void
|
|
binop::accept(const_visitor& v) const
|
|
{
|
|
v.visit(this);
|
|
}
|
|
|
|
const formula*
|
|
binop::first() const
|
|
{
|
|
return first_;
|
|
}
|
|
|
|
formula*
|
|
binop::first()
|
|
{
|
|
return first_;
|
|
}
|
|
|
|
const formula*
|
|
binop::second() const
|
|
{
|
|
return second_;
|
|
}
|
|
|
|
formula*
|
|
binop::second()
|
|
{
|
|
return second_;
|
|
}
|
|
|
|
binop::type
|
|
binop::op() const
|
|
{
|
|
return op_;
|
|
}
|
|
|
|
const char*
|
|
binop::op_name() 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;
|
|
}
|
|
|
|
binop::map binop::instances;
|
|
|
|
binop*
|
|
binop::instance(type op, formula* first, formula* second)
|
|
{
|
|
pairf pf(first, second);
|
|
pair p(op, pf);
|
|
map::iterator i = instances.find(p);
|
|
if (i != instances.end())
|
|
{
|
|
return static_cast<binop*>(i->second->ref());
|
|
}
|
|
binop* ap = new binop(op, first, second);
|
|
instances[p] = ap;
|
|
return static_cast<binop*>(ap->ref());
|
|
}
|
|
|
|
unsigned
|
|
binop::instance_count()
|
|
{
|
|
return instances.size();
|
|
}
|
|
}
|
|
}
|