Massage the AST so that identical sub-formula share the same

reference-counted formula*.  One can't call constructors for AST
items anymore, everything need to be acquired through instance()
class methods.

* src/ltlast/formula.cc, src/ltlast/refformula.cc,
src/ltlast/refformula.hh: New files.
* src/ltlast/Makefile.am (libltlast_la_SOURCES): Add them.
* src/ltlast/atomic_prop.cc, src/ltlast/atomic_prop.hh,
src/ltlast/unop.cc, src/ltlast/unop.hh,
src/ltlast/binop.cc, src/ltlast/binop.hh: Make the constructor
and destructor protected.  Define a static function `instance()'
to get an instance with specific argument.  Use a map called
`instances' to store all known instances.  Inherit from
ref_formula.
* src/ltlast/constant.hh, src/ltlast/constant.cc: Protect
the constructor and destructor.  Provide the false_instance()
and true_instance() functions instead.
* src/formula.hh (ref, unref, ref_, unref_): New methods.
* src/ltlast/multop.cc, src/ltlast/multop.hh: Protect
the constructor, destructor, as well as the add() method.
Provides the instance(), and add() class methods instead.
Store children_ as a pointer.
* src/ltlenv/defaultenv.cc (require): Adjust to
call atomic_prop::instance.
* src/ltlparse/ltlparse.yy: Adjust to call instance() functions
instead of constructors.
* src/ltltest/Makefile.am (LDADD): Tweak library ordering.
* src/ltlvisit/clone.hh (clone_visitor): Inherit from visitor,
not const_visitor, and adjust all prototypes appropriately.
* src/ltlvisit/clone.cc (clone_visitor): Likewise.
Call ref() or instance() methods instead of copy constructors.
* src/ltlvisit/equals.cc: Simplify atomic_prop and constant
cases.
* src/ltlvisit/lunabbrev.hh, src/ltlvisit/lunabbrev.cc,
src/ltlvisit/tunabbrev.hh, src/ltlvisit/tunabbrev.cc,
src/ltlvisit/nenoform.hh, src/ltlvisit/nenoform.cc: Use instance()
methods instead of constructor.  Make these children of visitor, not
const_visitor.
* src/ltltest/readltl.c (main): Do not delete the formula.
This commit is contained in:
Alexandre Duret-Lutz 2003-05-15 13:39:39 +00:00
parent f1838ab8ef
commit 5f6d8b6234
29 changed files with 548 additions and 253 deletions

View file

@ -1,7 +1,7 @@
#include "ltlast/allnodes.hh"
#include "lunabbrev.hh"
namespace spot
namespace spot
{
namespace ltl
{
@ -13,8 +13,8 @@ namespace spot
{
}
void
unabbreviate_logic_visitor::visit(const binop* bo)
void
unabbreviate_logic_visitor::visit(binop* bo)
{
formula* f1 = recurse(bo->first());
formula* f2 = recurse(bo->second());
@ -22,43 +22,48 @@ namespace spot
{
/* f1 ^ f2 == (f1 & !f2) | (f2 & !f1) */
case binop::Xor:
result_ = new multop(multop::Or,
new multop(multop::And, f1,
new unop(unop::Not, f2)),
new multop(multop::And, f2,
new unop(unop::Not, f1)));
result_ = multop::instance(multop::Or,
multop::instance(multop::And, f1,
unop::instance(unop::Not,
f2)),
multop::instance(multop::And, f2,
unop::instance(unop::Not,
f1)));
return;
/* f1 => f2 == !f1 | f2 */
case binop::Implies:
result_ = new multop(multop::Or, new unop(unop::Not, f1), f2);
result_ = multop::instance(multop::Or,
unop::instance(unop::Not, f1), f2);
return;
/* f1 <=> f2 == (f1 & f2) | (!f1 & !f2) */
case binop::Equiv:
result_ = new multop(multop::Or,
new multop(multop::And, f1, f2),
new multop(multop::And,
new unop(unop::Not, f1),
new unop(unop::Not, f2)));
result_ = multop::instance(multop::Or,
multop::instance(multop::And, f1, f2),
multop::instance(multop::And,
unop::instance(unop::Not,
f1),
unop::instance(unop::Not,
f2)));
return;
/* f1 U f2 == f1 U f2 */
/* f1 R f2 == f1 R f2 */
case binop::U:
case binop::R:
result_ = new binop(bo->op(), f1, f2);
result_ = binop::instance(bo->op(), f1, f2);
return;
}
/* Unreachable code. */
assert(0);
}
formula*
unabbreviate_logic_visitor::recurse(const formula* f)
formula*
unabbreviate_logic_visitor::recurse(formula* f)
{
return unabbreviate_logic(f);
}
formula*
unabbreviate_logic(const formula* f)
formula*
unabbreviate_logic(formula* f)
{
unabbreviate_logic_visitor v;
f->accept(v);