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:
parent
f1838ab8ef
commit
5f6d8b6234
29 changed files with 548 additions and 253 deletions
|
|
@ -6,42 +6,15 @@
|
|||
namespace spot
|
||||
{
|
||||
namespace ltl
|
||||
{
|
||||
multop::multop(type op)
|
||||
: op_(op)
|
||||
{
|
||||
multop::multop(type op, vec* v)
|
||||
: op_(op), children_(v)
|
||||
{
|
||||
}
|
||||
|
||||
multop::multop(type op, formula* first, formula* second)
|
||||
: op_(op)
|
||||
{
|
||||
children_.reserve(2);
|
||||
add(first);
|
||||
add(second);
|
||||
}
|
||||
|
||||
void
|
||||
multop::add(formula* f)
|
||||
{
|
||||
// If the formula we add is itself a multop for the same operator,
|
||||
// merge its children with ours.
|
||||
multop* p = dynamic_cast<multop*>(f);
|
||||
if (p && p->op() == op())
|
||||
{
|
||||
unsigned ps = p->size();
|
||||
for (unsigned i = 0; i < ps; ++i)
|
||||
children_.push_back(p->nth(i));
|
||||
// that sub-formula is now useless
|
||||
delete f;
|
||||
}
|
||||
else
|
||||
{
|
||||
children_.push_back(f);
|
||||
}
|
||||
}
|
||||
|
||||
multop::~multop()
|
||||
{
|
||||
delete children_;
|
||||
}
|
||||
|
||||
void
|
||||
|
|
@ -59,28 +32,28 @@ namespace spot
|
|||
unsigned
|
||||
multop::size() const
|
||||
{
|
||||
return children_.size();
|
||||
return children_->size();
|
||||
}
|
||||
|
||||
const formula*
|
||||
multop::nth(unsigned n) const
|
||||
{
|
||||
return children_[n];
|
||||
return (*children_)[n];
|
||||
}
|
||||
|
||||
formula*
|
||||
formula*
|
||||
multop::nth(unsigned n)
|
||||
{
|
||||
return children_[n];
|
||||
return (*children_)[n];
|
||||
}
|
||||
|
||||
multop::type
|
||||
multop::type
|
||||
multop::op() const
|
||||
{
|
||||
return op_;
|
||||
}
|
||||
|
||||
const char*
|
||||
const char*
|
||||
multop::op_name() const
|
||||
{
|
||||
switch (op_)
|
||||
|
|
@ -95,5 +68,69 @@ namespace spot
|
|||
return 0;
|
||||
}
|
||||
|
||||
multop::map multop::instances;
|
||||
|
||||
multop*
|
||||
multop::instance(type op, vec* v)
|
||||
{
|
||||
pair p(op, v);
|
||||
map::iterator i = instances.find(p);
|
||||
if (i != instances.end())
|
||||
{
|
||||
delete v;
|
||||
return static_cast<multop*>(i->second->ref());
|
||||
}
|
||||
multop* ap = new multop(op, v);
|
||||
instances[p] = ap;
|
||||
return static_cast<multop*>(ap->ref());
|
||||
|
||||
}
|
||||
|
||||
multop*
|
||||
multop::instance(type op)
|
||||
{
|
||||
return instance(op, new vec);
|
||||
}
|
||||
|
||||
multop*
|
||||
multop::instance(type op, formula* first, formula* second)
|
||||
{
|
||||
vec* v = new vec;
|
||||
multop::add(op, v, first);
|
||||
multop::add(op, v, second);
|
||||
return instance(op, v);
|
||||
}
|
||||
|
||||
multop::vec*
|
||||
multop::add(type op, vec* v, formula* f)
|
||||
{
|
||||
// If the formula we add is itself a multop for the same operator,
|
||||
// merge its children.
|
||||
multop* p = dynamic_cast<multop*>(f);
|
||||
if (p && p->op() == op)
|
||||
{
|
||||
unsigned ps = p->size();
|
||||
for (unsigned i = 0; i < ps; ++i)
|
||||
v->push_back(p->nth(i));
|
||||
// that sub-formula is now useless
|
||||
formula::unref(f);
|
||||
}
|
||||
else
|
||||
{
|
||||
v->push_back(f);
|
||||
}
|
||||
return v;
|
||||
}
|
||||
|
||||
void
|
||||
multop::add(multop** m, formula* f)
|
||||
{
|
||||
vec* v = new vec(*(*m)->children_);
|
||||
type op = (*m)->op();
|
||||
multop::add(op, v, f);
|
||||
formula::unref(*m);
|
||||
*m = instance(op, v);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue