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

@ -5,6 +5,8 @@ noinst_LTLIBRARIES = libltlvisit.la
libltlvisit_la_SOURCES = \
clone.cc \
clone.hh \
destroy.cc \
destroy.hh \
dotty.cc \
dotty.hh \
dump.cc \
@ -17,5 +19,7 @@ libltlvisit_la_SOURCES = \
lunabbrev.cc \
nenoform.hh \
nenoform.cc \
postfix.hh \
postfix.cc \
tunabbrev.hh \
tunabbrev.cc
tunabbrev.cc

25
src/ltlvisit/destroy.cc Normal file
View file

@ -0,0 +1,25 @@
#include "ltlvisit/destroy.hh"
namespace spot
{
namespace ltl
{
class destroy_visitor : public postfix_visitor
{
public:
virtual void
doit_default(formula* c)
{
formula::unref(c);
}
};
void
destroy(formula *f)
{
destroy_visitor v;
f->accept(v);
}
}
}

15
src/ltlvisit/destroy.hh Normal file
View file

@ -0,0 +1,15 @@
#ifndef SPOT_LTLVISIT_DESTROY_HH
# define SPOT_LTLVISIT_DESTROY_HH
#include "ltlvisit/postfix.hh"
namespace spot
{
namespace ltl
{
/// \brief Destroys a formula
void destroy(formula *f);
}
}
#endif // SPOT_LTLVISIT_DESTROY_HH

View file

@ -1,4 +1,5 @@
#include "ltlast/allnodes.hh"
#include "ltlvisit/clone.hh"
#include "lunabbrev.hh"
namespace spot
@ -23,10 +24,10 @@ namespace spot
/* f1 ^ f2 == (f1 & !f2) | (f2 & !f1) */
case binop::Xor:
result_ = multop::instance(multop::Or,
multop::instance(multop::And, f1,
multop::instance(multop::And, clone(f1),
unop::instance(unop::Not,
f2)),
multop::instance(multop::And, f2,
multop::instance(multop::And, clone(f2),
unop::instance(unop::Not,
f1)));
return;
@ -38,7 +39,8 @@ namespace spot
/* f1 <=> f2 == (f1 & f2) | (!f1 & !f2) */
case binop::Equiv:
result_ = multop::instance(multop::Or,
multop::instance(multop::And, f1, f2),
multop::instance(multop::And,
clone(f1), clone(f2)),
multop::instance(multop::And,
unop::instance(unop::Not,
f1),

89
src/ltlvisit/postfix.cc Normal file
View file

@ -0,0 +1,89 @@
#include "ltlvisit/postfix.hh"
#include "ltlast/allnodes.hh"
namespace spot
{
namespace ltl
{
postfix_visitor::postfix_visitor()
{
}
postfix_visitor::~postfix_visitor()
{
}
void
postfix_visitor::visit(atomic_prop* ap)
{
doit(ap);
}
void
postfix_visitor::visit(unop* uo)
{
uo->child()->accept(*this);
doit(uo);
}
void
postfix_visitor::visit(binop* bo)
{
bo->first()->accept(*this);
bo->second()->accept(*this);
doit(bo);
}
void
postfix_visitor::visit(multop* mo)
{
unsigned s = mo->size();
for (unsigned i = 0; i < s; ++i)
mo->nth(i)->accept(*this);
doit(mo);
}
void
postfix_visitor::visit(constant* c)
{
doit(c);
}
void
postfix_visitor::doit(atomic_prop* ap)
{
doit_default(ap);
}
void
postfix_visitor::doit(unop* uo)
{
doit_default(uo);
}
void
postfix_visitor::doit(binop* bo)
{
doit_default(bo);
}
void
postfix_visitor::doit(multop* mo)
{
doit_default(mo);
}
void
postfix_visitor::doit(constant* c)
{
doit_default(c);
}
void
postfix_visitor::doit_default(formula* f)
{
(void)f;
// Dummy implementation that does nothing.
}
}
}

38
src/ltlvisit/postfix.hh Normal file
View file

@ -0,0 +1,38 @@
#ifndef SPOT_LTLVISIT_POSTFIX_HH
# define SPOT_LTLVISIT_POSTFIX_HH
#include "ltlast/formula.hh"
#include "ltlast/visitor.hh"
namespace spot
{
namespace ltl
{
/// \brief Apply a algorithm on each node of an AST,
/// during a postfix traversal.
///
/// Override one or more of the postifix_visitor::doit methods
/// with the algorithm to apply.
class postfix_visitor : public visitor
{
public:
postfix_visitor();
virtual ~postfix_visitor();
void visit(atomic_prop* ap);
void visit(unop* uo);
void visit(binop* bo);
void visit(multop* mo);
void visit(constant* c);
virtual void doit(atomic_prop* ap);
virtual void doit(unop* uo);
virtual void doit(binop* bo);
virtual void doit(multop* mo);
virtual void doit(constant* c);
virtual void doit_default(formula* f);
};
}
}
#endif // SPOT_LTLVISIT_POSTFIX_HH