* src/ltlast/multop.cc (multop::multop): Use multop::add.

(multop::add): If the formulae we add is itself a multop for the
same operator, merge its children with ours.
* src/ltltest/parseerr.test: Add two tests for multop merging.
This commit is contained in:
Alexandre Duret-Lutz 2003-04-16 11:27:06 +00:00
parent 2fd7b742f0
commit eec66e6d07
3 changed files with 29 additions and 4 deletions

View file

@ -8,16 +8,31 @@ namespace spot
namespace ltl
{
multop::multop(type op, formulae* first, formulae* second)
: op_(op), children_(2)
: op_(op)
{
children_[0] = first;
children_[1] = second;
children_.reserve(2);
add(first);
add(second);
}
void
multop::add(formulae* f)
{
children_.push_back(f);
// If the formulae 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-formulae is now useless
delete f;
}
else
{
children_.push_back(f);
}
}
multop::~multop()