revamp the formula hierarchy (montro-patch)
Flatten the formula ltl::formula hiearchy into a single ltl::vnode that has an enumerator to distinguish the types of node, and a common interface to access children, update reference counts, etc. The ltl::formula class is now a thin wrapper around an ltl::vnode pointer to keep track of reference counts automatically. Visitor are not used anymore; we now have map() and traversor() methods that are more concise. This basically fixes #43, but should be followed by some fine tuning that should now be localized to the formula.hh and formula.cc files. Some statistics about this patch. I started working on it on Sep 9, had a first compiling version two weeks later on Sep 22, and it then took 5 days to fixes the ~70 distincts bugs that were introduced during the conversion. About 13200 lines were modified, and one third of those were removed. * src/ltlast/formula.cc, src/ltlast/formula.hh: Complete rewrite, including what was in separate nearby files. * src/ltlast/allnodes.hh, src/ltlast/atomic_prop.cc, src/ltlast/atomic_prop.hh, src/ltlast/binop.cc, src/ltlast/binop.hh, src/ltlast/bunop.cc, src/ltlast/bunop.hh, src/ltlast/constant.cc, src/ltlast/constant.hh, src/ltlast/multop.cc, src/ltlast/multop.hh, src/ltlast/unop.cc, src/ltlast/unop.hh, src/ltlvisit/dump.cc, src/ltlvisit/dump.hh, src/ltlast/predecl.hh: Delete these files. Their feature have been merged in formula.hh and formula.cc. * src/ltlast/visitor.hh, src/ltlvisit/clone.cc, src/ltlvisit/clone.hh, src/ltlvisit/dump.hh, src/ltlvisit/postfix.cc, src/ltlvisit/postfix.hh: Delete these files, as we do not use visitors anymore. * bench/stutter/stutter_invariance_formulas.cc, bench/stutter/stutter_invariance_randomgraph.cc, doc/org/tut01.org, doc/org/tut02.org, doc/org/tut10.org, doc/org/tut22.org, iface/ltsmin/ltsmin.cc, iface/ltsmin/ltsmin.hh, iface/ltsmin/modelcheck.cc, src/bin/autfilt.cc, src/bin/common_aoutput.cc, src/bin/common_aoutput.hh, src/bin/common_finput.cc, src/bin/common_finput.hh, src/bin/common_output.cc, src/bin/common_output.hh, src/bin/common_trans.cc, src/bin/common_trans.hh, src/bin/dstar2tgba.cc, src/bin/genltl.cc, src/bin/ltl2tgba.cc, src/bin/ltl2tgta.cc, src/bin/ltlcross.cc, src/bin/ltldo.cc, src/bin/ltlfilt.cc, src/bin/ltlgrind.cc, src/bin/randaut.cc, src/bin/randltl.cc, src/kripke/kripkeexplicit.cc, src/kripke/kripkeexplicit.hh, src/kripkeparse/kripkeparse.yy, src/ltlast/Makefile.am, src/ltlenv/declenv.cc, src/ltlenv/declenv.hh, src/ltlenv/defaultenv.cc, src/ltlenv/defaultenv.hh, src/ltlenv/environment.hh, src/ltlparse/ltlparse.yy, src/ltlparse/public.hh, src/ltlvisit/Makefile.am, src/ltlvisit/apcollect.cc, src/ltlvisit/apcollect.hh, src/ltlvisit/contain.cc, src/ltlvisit/contain.hh, src/ltlvisit/dot.cc, src/ltlvisit/dot.hh, src/ltlvisit/exclusive.cc, src/ltlvisit/exclusive.hh, src/ltlvisit/length.cc, src/ltlvisit/length.hh, src/ltlvisit/mark.cc, src/ltlvisit/mark.hh, src/ltlvisit/mutation.cc, src/ltlvisit/mutation.hh, src/ltlvisit/nenoform.cc, src/ltlvisit/nenoform.hh, src/ltlvisit/print.cc, src/ltlvisit/print.hh, src/ltlvisit/randomltl.cc, src/ltlvisit/randomltl.hh, src/ltlvisit/relabel.cc, src/ltlvisit/relabel.hh, src/ltlvisit/remove_x.cc, src/ltlvisit/remove_x.hh, src/ltlvisit/simpfg.cc, src/ltlvisit/simpfg.hh, src/ltlvisit/simplify.cc, src/ltlvisit/simplify.hh, src/ltlvisit/snf.cc, src/ltlvisit/snf.hh, src/ltlvisit/unabbrev.cc, src/ltlvisit/unabbrev.hh, src/parseaut/parseaut.yy, src/ta/taexplicit.cc, src/ta/tgtaexplicit.cc, src/taalgos/minimize.cc, src/taalgos/tgba2ta.cc, src/tests/bare.test, src/tests/checkpsl.cc, src/tests/checkta.cc, src/tests/complementation.cc, src/tests/consterm.cc, src/tests/emptchk.cc, src/tests/equalsf.cc, src/tests/ikwiad.cc, src/tests/isop.test, src/tests/kind.cc, src/tests/length.cc, src/tests/ltldo.test, src/tests/ltlfilt.test, src/tests/ltlgrind.test, src/tests/ltlprod.cc, src/tests/ltlrel.cc, src/tests/parse_print_test.cc, src/tests/parseaut.test, src/tests/parseerr.test, src/tests/randtgba.cc, src/tests/readltl.cc, src/tests/reduc.cc, src/tests/syntimpl.cc, src/tests/taatgba.cc, src/tests/tostring.cc, src/tests/twagraph.cc, src/tests/utf8.test, src/twa/acc.cc, src/twa/bdddict.cc, src/twa/bdddict.hh, src/twa/bddprint.cc, src/twa/formula2bdd.cc, src/twa/formula2bdd.hh, src/twa/taatgba.cc, src/twa/taatgba.hh, src/twa/twa.cc, src/twa/twa.hh src/twa/twagraph.cc, src/twa/twagraph.hh, src/twa/twasafracomplement.cc, src/twaalgos/compsusp.cc, src/twaalgos/compsusp.hh, src/twaalgos/dtgbasat.cc, src/twaalgos/hoa.cc, src/twaalgos/lbtt.cc, src/twaalgos/ltl2taa.cc, src/twaalgos/ltl2taa.hh, src/twaalgos/ltl2tgba_fm.cc, src/twaalgos/ltl2tgba_fm.hh, src/twaalgos/minimize.cc, src/twaalgos/minimize.hh, src/twaalgos/neverclaim.cc, src/twaalgos/postproc.cc, src/twaalgos/postproc.hh, src/twaalgos/powerset.cc, src/twaalgos/powerset.hh, src/twaalgos/randomgraph.cc, src/twaalgos/remprop.cc, src/twaalgos/remprop.hh, src/twaalgos/stats.cc, src/twaalgos/stats.hh, src/twaalgos/stutter.cc, src/twaalgos/stutter.hh, src/twaalgos/translate.cc, src/twaalgos/translate.hh, wrap/python/ajax/spotcgi.in, wrap/python/spot.py, wrap/python/spot_impl.i, wrap/python/Makefile.am, wrap/python/tests/automata-io.ipynb, wrap/python/tests/formulas.ipynb, wrap/python/tests/ltl2tgba.py, wrap/python/tests/ltlparse.py, wrap/python/tests/ltlsimple.py, wrap/python/tests/randltl.ipynb: Adjust to use the new interface. * src/sanity/style.test: Accept more C++11 patterns. * NEWS: Mention the change.
This commit is contained in:
parent
1628b188fe
commit
b77f7e24c3
177 changed files with 8295 additions and 13332 deletions
|
|
@ -18,344 +18,176 @@
|
|||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
#include "mark.hh"
|
||||
#include "ltlast/allnodes.hh"
|
||||
#include <cassert>
|
||||
#include <algorithm>
|
||||
#include <set>
|
||||
#include <vector>
|
||||
#include "misc/casts.hh"
|
||||
|
||||
namespace spot
|
||||
{
|
||||
namespace ltl
|
||||
{
|
||||
namespace
|
||||
{
|
||||
class simplify_mark_visitor : public visitor
|
||||
{
|
||||
const formula* result_;
|
||||
mark_tools* tools_;
|
||||
|
||||
public:
|
||||
simplify_mark_visitor(mark_tools* t)
|
||||
: tools_(t)
|
||||
{
|
||||
}
|
||||
|
||||
~simplify_mark_visitor()
|
||||
{
|
||||
}
|
||||
|
||||
const formula*
|
||||
result()
|
||||
{
|
||||
return result_;
|
||||
}
|
||||
|
||||
void
|
||||
visit(const atomic_prop* ao)
|
||||
{
|
||||
result_ = ao->clone();
|
||||
}
|
||||
|
||||
void
|
||||
visit(const constant* c)
|
||||
{
|
||||
result_ = c->clone();
|
||||
}
|
||||
|
||||
void
|
||||
visit(const bunop* bo)
|
||||
{
|
||||
result_ = bo->clone();
|
||||
}
|
||||
|
||||
void
|
||||
visit(const unop* uo)
|
||||
{
|
||||
result_ = uo->clone();
|
||||
}
|
||||
|
||||
void
|
||||
visit(const multop* mo)
|
||||
{
|
||||
unsigned mos = mo->size();
|
||||
multop::vec* res = new multop::vec;
|
||||
switch (mo->op())
|
||||
{
|
||||
case multop::OrRat:
|
||||
case multop::AndNLM:
|
||||
case multop::AndRat:
|
||||
case multop::Concat:
|
||||
case multop::Fusion:
|
||||
SPOT_UNIMPLEMENTED();
|
||||
case multop::Or:
|
||||
for (unsigned i = 0; i < mos; ++i)
|
||||
res->push_back(recurse(mo->nth(i)));
|
||||
break;
|
||||
case multop::And:
|
||||
{
|
||||
typedef std::set<std::pair<const formula*,
|
||||
const formula*> > pset;
|
||||
pset empairs;
|
||||
typedef std::set<const formula*> sset;
|
||||
sset nmset;
|
||||
typedef std::vector<const binop*> unbinop;
|
||||
unbinop elist;
|
||||
typedef std::vector<const unop*> ununop;
|
||||
ununop nlist;
|
||||
|
||||
for (unsigned i = 0; i < mos; ++i)
|
||||
{
|
||||
const formula* f = mo->nth(i);
|
||||
if (const binop* bo = is_binop(f))
|
||||
{
|
||||
switch (bo->op())
|
||||
{
|
||||
case binop::EConcatMarked:
|
||||
empairs.emplace(bo->first(), bo->second());
|
||||
// fall through
|
||||
case binop::Xor:
|
||||
case binop::Implies:
|
||||
case binop::Equiv:
|
||||
case binop::U:
|
||||
case binop::W:
|
||||
case binop::M:
|
||||
case binop::R:
|
||||
case binop::UConcat:
|
||||
res->push_back(recurse(f));
|
||||
break;
|
||||
case binop::EConcat:
|
||||
elist.push_back(bo);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (const unop* uo = is_unop(f))
|
||||
{
|
||||
switch (uo->op())
|
||||
{
|
||||
case unop::NegClosureMarked:
|
||||
nmset.insert(uo->child());
|
||||
// fall through
|
||||
case unop::Not:
|
||||
case unop::X:
|
||||
case unop::F:
|
||||
case unop::G:
|
||||
case unop::Closure:
|
||||
res->push_back(recurse(f));
|
||||
break;
|
||||
case unop::NegClosure:
|
||||
nlist.push_back(uo);
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
res->push_back(recurse(f));
|
||||
}
|
||||
}
|
||||
// Keep only the non-marked EConcat for which we
|
||||
// have not seen a similar EConcatMarked.
|
||||
for (unbinop::const_iterator i = elist.begin();
|
||||
i != elist.end(); ++i)
|
||||
if (empairs.find(std::make_pair((*i)->first(),
|
||||
(*i)->second()))
|
||||
== empairs.end())
|
||||
res->push_back((*i)->clone());
|
||||
// Keep only the non-marked NegClosure for which we
|
||||
// have not seen a similar NegClosureMarked.
|
||||
for (ununop::const_iterator i = nlist.begin();
|
||||
i != nlist.end(); ++i)
|
||||
if (nmset.find((*i)->child()) == nmset.end())
|
||||
res->push_back((*i)->clone());
|
||||
}
|
||||
}
|
||||
result_ = multop::instance(mo->op(), res);
|
||||
}
|
||||
|
||||
void
|
||||
visit(const binop* bo)
|
||||
{
|
||||
result_ = bo->clone();
|
||||
}
|
||||
|
||||
const formula*
|
||||
recurse(const formula* f)
|
||||
{
|
||||
return tools_->simplify_mark(f);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
class mark_visitor : public visitor
|
||||
{
|
||||
const formula* result_;
|
||||
mark_tools* tools_;
|
||||
|
||||
public:
|
||||
mark_visitor(mark_tools* t)
|
||||
: tools_(t)
|
||||
{
|
||||
}
|
||||
~mark_visitor()
|
||||
{
|
||||
}
|
||||
|
||||
const formula*
|
||||
result()
|
||||
{
|
||||
return result_;
|
||||
}
|
||||
|
||||
void
|
||||
visit(const atomic_prop* ap)
|
||||
{
|
||||
result_ = ap->clone();
|
||||
}
|
||||
|
||||
void
|
||||
visit(const constant* c)
|
||||
{
|
||||
result_ = c->clone();
|
||||
}
|
||||
|
||||
void
|
||||
visit(const bunop* bo)
|
||||
{
|
||||
result_ = bo->clone();
|
||||
}
|
||||
|
||||
void
|
||||
visit(const unop* uo)
|
||||
{
|
||||
switch (uo->op())
|
||||
{
|
||||
case unop::Not:
|
||||
case unop::X:
|
||||
case unop::F:
|
||||
case unop::G:
|
||||
case unop::Closure:
|
||||
case unop::NegClosureMarked:
|
||||
result_ = uo->clone();
|
||||
return;
|
||||
case unop::NegClosure:
|
||||
result_ = unop::instance(unop::NegClosureMarked,
|
||||
uo->child()->clone());
|
||||
return;
|
||||
}
|
||||
SPOT_UNREACHABLE();
|
||||
}
|
||||
|
||||
void
|
||||
visit(const multop* mo)
|
||||
{
|
||||
multop::vec* res = new multop::vec;
|
||||
unsigned mos = mo->size();
|
||||
for (unsigned i = 0; i < mos; ++i)
|
||||
res->push_back(recurse(mo->nth(i)));
|
||||
result_ = multop::instance(mo->op(), res);
|
||||
}
|
||||
|
||||
void
|
||||
visit(const binop* bo)
|
||||
{
|
||||
switch (bo->op())
|
||||
{
|
||||
case binop::Xor:
|
||||
case binop::Implies:
|
||||
case binop::Equiv:
|
||||
SPOT_UNIMPLEMENTED();
|
||||
case binop::U:
|
||||
case binop::W:
|
||||
case binop::M:
|
||||
case binop::R:
|
||||
case binop::UConcat:
|
||||
case binop::EConcatMarked:
|
||||
result_ = bo->clone();
|
||||
return;
|
||||
case binop::EConcat:
|
||||
{
|
||||
const formula* f1 = bo->first()->clone();
|
||||
const formula* f2 = bo->second()->clone();
|
||||
result_ = binop::instance(binop::EConcatMarked, f1, f2);
|
||||
return;
|
||||
}
|
||||
}
|
||||
SPOT_UNREACHABLE();
|
||||
}
|
||||
|
||||
const formula*
|
||||
recurse(const formula* f)
|
||||
{
|
||||
return tools_->mark_concat_ops(f);
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
mark_tools::mark_tools()
|
||||
: simpvisitor_(new simplify_mark_visitor(this)),
|
||||
markvisitor_(new mark_visitor(this))
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
mark_tools::~mark_tools()
|
||||
{
|
||||
delete simpvisitor_;
|
||||
delete markvisitor_;
|
||||
{
|
||||
f2f_map::iterator i = simpmark_.begin();
|
||||
f2f_map::iterator end = simpmark_.end();
|
||||
while (i != end)
|
||||
{
|
||||
f2f_map::iterator old = i++;
|
||||
old->second->destroy();
|
||||
old->first->destroy();
|
||||
}
|
||||
}
|
||||
{
|
||||
f2f_map::iterator i = markops_.begin();
|
||||
f2f_map::iterator end = markops_.end();
|
||||
while (i != end)
|
||||
{
|
||||
f2f_map::iterator old = i++;
|
||||
old->second->destroy();
|
||||
old->first->destroy();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const formula*
|
||||
mark_tools::mark_concat_ops(const formula* f)
|
||||
formula
|
||||
mark_tools::mark_concat_ops(formula f)
|
||||
{
|
||||
f2f_map::iterator i = markops_.find(f);
|
||||
if (i != markops_.end())
|
||||
return i->second->clone();
|
||||
return i->second;
|
||||
|
||||
f->accept(*markvisitor_);
|
||||
ltl::formula res;
|
||||
switch (f.kind())
|
||||
{
|
||||
case op::False:
|
||||
case op::True:
|
||||
case op::EmptyWord:
|
||||
case op::AP:
|
||||
case op::Not:
|
||||
case op::X:
|
||||
case op::F:
|
||||
case op::G:
|
||||
case op::Closure:
|
||||
case op::NegClosureMarked:
|
||||
case op::OrRat:
|
||||
case op::AndRat:
|
||||
case op::AndNLM:
|
||||
case op::Star:
|
||||
case op::FStar:
|
||||
case op::U:
|
||||
case op::R:
|
||||
case op::W:
|
||||
case op::M:
|
||||
case op::EConcatMarked:
|
||||
case op::UConcat:
|
||||
case op::Concat:
|
||||
case op::Fusion:
|
||||
res = f;
|
||||
break;
|
||||
case op::NegClosure:
|
||||
res = ltl::formula::NegClosureMarked(f.nth(0));
|
||||
break;
|
||||
case op::EConcat:
|
||||
res = ltl::formula::EConcatMarked(f.nth(0), f.nth(1));
|
||||
break;
|
||||
case op::Or:
|
||||
case op::And:
|
||||
res = f.map([this](formula f)
|
||||
{
|
||||
return this->mark_concat_ops(f);
|
||||
});
|
||||
break;
|
||||
case op::Xor:
|
||||
case op::Implies:
|
||||
case op::Equiv:
|
||||
SPOT_UNIMPLEMENTED();
|
||||
}
|
||||
|
||||
const formula* r = down_cast<mark_visitor*>(markvisitor_)->result();
|
||||
markops_[f->clone()] = r->clone();
|
||||
return r;
|
||||
markops_[f] = res;
|
||||
return res;
|
||||
}
|
||||
|
||||
const formula*
|
||||
mark_tools::simplify_mark(const formula* f)
|
||||
formula
|
||||
mark_tools::simplify_mark(formula f)
|
||||
{
|
||||
if (!f->is_marked())
|
||||
return f->clone();
|
||||
if (!f.is_marked())
|
||||
return f;
|
||||
|
||||
f2f_map::iterator i = simpmark_.find(f);
|
||||
if (i != simpmark_.end())
|
||||
return i->second->clone();
|
||||
return i->second;
|
||||
|
||||
f->accept(*simpvisitor_);
|
||||
auto recurse = [this](formula f)
|
||||
{
|
||||
return this->simplify_mark(f);
|
||||
};
|
||||
|
||||
const formula* r =
|
||||
down_cast<simplify_mark_visitor*>(simpvisitor_)->result();
|
||||
simpmark_[f->clone()] = r->clone();
|
||||
return r;
|
||||
ltl::formula res;
|
||||
switch (f.kind())
|
||||
{
|
||||
case op::False:
|
||||
case op::True:
|
||||
case op::EmptyWord:
|
||||
case op::AP:
|
||||
case op::Not:
|
||||
case op::X:
|
||||
case op::F:
|
||||
case op::G:
|
||||
case op::Closure:
|
||||
case op::NegClosure:
|
||||
case op::NegClosureMarked:
|
||||
case op::U:
|
||||
case op::R:
|
||||
case op::W:
|
||||
case op::M:
|
||||
case op::EConcat:
|
||||
case op::EConcatMarked:
|
||||
case op::UConcat:
|
||||
res = f;
|
||||
break;
|
||||
case op::Or:
|
||||
res = f.map(recurse);
|
||||
break;
|
||||
case op::And:
|
||||
{
|
||||
std::set<std::pair<formula, formula>> empairs;
|
||||
std::set<formula> nmset;
|
||||
std::vector<formula> elist;
|
||||
std::vector<formula> nlist;
|
||||
std::vector<formula> v;
|
||||
|
||||
for (auto c: f)
|
||||
{
|
||||
if (c.is(op::EConcatMarked))
|
||||
{
|
||||
empairs.emplace(c.nth(0), c.nth(1));
|
||||
v.push_back(c.map(recurse));
|
||||
}
|
||||
else if (c.is(op::EConcat))
|
||||
{
|
||||
elist.push_back(c);
|
||||
}
|
||||
else if (c.is(op::NegClosureMarked))
|
||||
{
|
||||
nmset.insert(c.nth(0));
|
||||
v.push_back(c.map(recurse));
|
||||
}
|
||||
else if (c.is(op::NegClosure))
|
||||
{
|
||||
nlist.push_back(c);
|
||||
}
|
||||
else
|
||||
{
|
||||
v.push_back(c);
|
||||
}
|
||||
}
|
||||
// Keep only the non-marked EConcat for which we
|
||||
// have not seen a similar EConcatMarked.
|
||||
for (auto e: elist)
|
||||
if (empairs.find(std::make_pair(e.nth(0), e.nth(1)))
|
||||
== empairs.end())
|
||||
v.push_back(e);
|
||||
// Keep only the non-marked NegClosure for which we
|
||||
// have not seen a similar NegClosureMarked.
|
||||
for (auto n: nlist)
|
||||
if (nmset.find(n.nth(0)) == nmset.end())
|
||||
v.push_back(n);
|
||||
res = ltl::formula::And(v);
|
||||
}
|
||||
break;
|
||||
case op::Xor:
|
||||
case op::Implies:
|
||||
case op::Equiv:
|
||||
case op::OrRat:
|
||||
case op::AndRat:
|
||||
case op::AndNLM:
|
||||
case op::Star:
|
||||
case op::FStar:
|
||||
case op::Concat:
|
||||
case op::Fusion:
|
||||
SPOT_UNIMPLEMENTED();
|
||||
}
|
||||
|
||||
simpmark_[f] = res;
|
||||
return res;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue