From eec66e6d0717acc11d08b3af06e7a85cb78ec951 Mon Sep 17 00:00:00 2001 From: Alexandre Duret-Lutz Date: Wed, 16 Apr 2003 11:27:06 +0000 Subject: [PATCH] * 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. --- ChangeLog | 7 +++++++ src/ltlast/multop.cc | 23 +++++++++++++++++++---- src/ltltest/parseerr.test | 3 +++ 3 files changed, 29 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index a1d5dee71..fee359774 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2003-04-16 Alexandre DURET-LUTZ + + * 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. + 2003-04-15 Alexandre DURET-LUTZ * src/ltlast/formulae.hh (formulae::equals): Remove. diff --git a/src/ltlast/multop.cc b/src/ltlast/multop.cc index b2cdbae7a..fc37772b7 100644 --- a/src/ltlast/multop.cc +++ b/src/ltlast/multop.cc @@ -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(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() diff --git a/src/ltltest/parseerr.test b/src/ltltest/parseerr.test index 829bf3250..f439c8069 100755 --- a/src/ltltest/parseerr.test +++ b/src/ltltest/parseerr.test @@ -39,6 +39,9 @@ check 'a U b V c R' '' # leading and trailing garbage are skipped check '/2/3/4/5 a + b /6/7/8/' 'multop(Or, AP(a), AP(b))' check 'a U b c' 'binop(U, AP(a), AP(b))' +# (check multop merging while we are at it) +check 'a & b & c & d e' 'multop(And, AP(a), AP(b), AP(c), AP(d))' +check 'a & (b | c) & d should work' 'multop(And, AP(a), multop(Or, AP(b), AP(c)), AP(d))' # Recovery inside parentheses check 'a U (b c) U e R (f g <=> h)' \