From 51151ab27118b0fabc27ee5e8667355eff723a9d Mon Sep 17 00:00:00 2001 From: Alexandre Duret-Lutz Date: Thu, 14 Aug 2014 20:18:04 +0200 Subject: [PATCH] Handle all automata through shared_ptr. (monstro patch) A type such as 'const tgba_digraph*' and 'tgba_digraph*' are replaced by 'const_tgba_digraph_ptr' and 'tgba_digraph_ptr'. Additionally 'new tgba_digraph(...)' is replaced by 'make_tgba_digraph(...)'. This convention is followed by all automata types. Those smart pointers should normally be passed by const reference as input of function to avoid the atomic increments/decrements, but I probably missed a few, as this huge patch took me nearly 12h. * src/kripke/fwd.hh, src/tgba/fwd.hh: New files. * src/kripke/Makefile.am, src/tgba/Makefile.am: Adjust. * iface/dve2/dve2.cc, iface/dve2/dve2.hh, iface/dve2/dve2check.cc, src/bin/common_output.hh, src/bin/dstar2tgba.cc, src/bin/ltl2tgba.cc, src/bin/ltl2tgta.cc, src/bin/ltlcross.cc, src/bin/ltlfilt.cc, src/dstarparse/dra2ba.cc, src/dstarparse/dstar2tgba.cc, src/dstarparse/dstarparse.yy, src/dstarparse/nra2nba.cc, src/dstarparse/nsa2tgba.cc, src/dstarparse/public.hh, src/graphtest/tgbagraph.cc, src/kripke/fairkripke.hh, src/kripke/kripke.hh, src/kripke/kripkeexplicit.cc, src/kripke/kripkeexplicit.hh, src/kripke/kripkeprint.cc, src/kripke/kripkeprint.hh, src/kripkeparse/kripkeparse.yy, src/kripkeparse/public.hh, src/kripketest/parse_print_test.cc, src/ltlvisit/apcollect.cc, src/ltlvisit/apcollect.hh, src/ltlvisit/contain.cc, src/ltlvisit/contain.hh, src/neverparse/neverclaimparse.yy, src/neverparse/public.hh, src/priv/accmap.hh, src/priv/countstates.cc, src/priv/countstates.hh, src/saba/saba.hh, src/saba/sabacomplementtgba.cc, src/saba/sabacomplementtgba.hh, src/sabaalgos/sabadotty.cc, src/sabaalgos/sabadotty.hh, src/sabaalgos/sabareachiter.cc, src/sabaalgos/sabareachiter.hh, src/sabatest/sabacomplementtgba.cc, src/ta/ta.hh, src/ta/taexplicit.cc, src/ta/taexplicit.hh, src/ta/taproduct.cc, src/ta/taproduct.hh, src/ta/tgta.hh, src/ta/tgtaexplicit.cc, src/ta/tgtaexplicit.hh, src/ta/tgtaproduct.cc, src/ta/tgtaproduct.hh, src/taalgos/dotty.cc, src/taalgos/dotty.hh, src/taalgos/emptinessta.cc, src/taalgos/emptinessta.hh, src/taalgos/minimize.cc, src/taalgos/minimize.hh, src/taalgos/reachiter.cc, src/taalgos/reachiter.hh, src/taalgos/statessetbuilder.cc, src/taalgos/statessetbuilder.hh, src/taalgos/stats.cc, src/taalgos/stats.hh, src/taalgos/tgba2ta.cc, src/taalgos/tgba2ta.hh, src/tgba/bdddict.cc, src/tgba/bdddict.hh, src/tgba/formula2bdd.hh, src/tgba/futurecondcol.cc, src/tgba/futurecondcol.hh, src/tgba/taatgba.hh, src/tgba/tgba.cc, src/tgba/tgba.hh, src/tgba/tgbagraph.hh, src/tgba/tgbakvcomplement.cc, src/tgba/tgbakvcomplement.hh, src/tgba/tgbamask.cc, src/tgba/tgbamask.hh, src/tgba/tgbaproduct.cc, src/tgba/tgbaproduct.hh, src/tgba/tgbaproxy.cc, src/tgba/tgbaproxy.hh, src/tgba/tgbasafracomplement.cc, src/tgba/tgbasafracomplement.hh, src/tgba/tgbascc.cc, src/tgba/tgbascc.hh, src/tgba/tgbasgba.cc, src/tgba/tgbasgba.hh, src/tgba/wdbacomp.cc, src/tgba/wdbacomp.hh, src/tgbaalgos/bfssteps.cc, src/tgbaalgos/bfssteps.hh, src/tgbaalgos/complete.cc, src/tgbaalgos/complete.hh, src/tgbaalgos/compsusp.cc, src/tgbaalgos/compsusp.hh, src/tgbaalgos/cycles.hh, src/tgbaalgos/degen.cc, src/tgbaalgos/degen.hh, src/tgbaalgos/dotty.cc, src/tgbaalgos/dotty.hh, src/tgbaalgos/dottydec.cc, src/tgbaalgos/dottydec.hh, src/tgbaalgos/dtbasat.cc, src/tgbaalgos/dtbasat.hh, src/tgbaalgos/dtgbacomp.cc, src/tgbaalgos/dtgbacomp.hh, src/tgbaalgos/dtgbasat.cc, src/tgbaalgos/dtgbasat.hh, src/tgbaalgos/dupexp.cc, src/tgbaalgos/dupexp.hh, src/tgbaalgos/emptiness.cc, src/tgbaalgos/emptiness.hh, src/tgbaalgos/gtec/gtec.cc, src/tgbaalgos/gtec/gtec.hh, src/tgbaalgos/gtec/status.cc, src/tgbaalgos/gtec/status.hh, src/tgbaalgos/gv04.cc, src/tgbaalgos/gv04.hh, src/tgbaalgos/isdet.cc, src/tgbaalgos/isdet.hh, src/tgbaalgos/isweakscc.cc, src/tgbaalgos/lbtt.cc, src/tgbaalgos/lbtt.hh, src/tgbaalgos/ltl2taa.cc, src/tgbaalgos/ltl2taa.hh, src/tgbaalgos/ltl2tgba_fm.cc, src/tgbaalgos/ltl2tgba_fm.hh, src/tgbaalgos/magic.cc, src/tgbaalgos/magic.hh, src/tgbaalgos/minimize.cc, src/tgbaalgos/minimize.hh, src/tgbaalgos/ndfs_result.hxx, src/tgbaalgos/neverclaim.cc, src/tgbaalgos/neverclaim.hh, src/tgbaalgos/postproc.cc, src/tgbaalgos/postproc.hh, src/tgbaalgos/powerset.cc, src/tgbaalgos/powerset.hh, src/tgbaalgos/projrun.cc, src/tgbaalgos/projrun.hh, src/tgbaalgos/randomgraph.cc, src/tgbaalgos/randomgraph.hh, src/tgbaalgos/reachiter.cc, src/tgbaalgos/reachiter.hh, src/tgbaalgos/reducerun.cc, src/tgbaalgos/reducerun.hh, src/tgbaalgos/replayrun.cc, src/tgbaalgos/replayrun.hh, src/tgbaalgos/rundotdec.cc, src/tgbaalgos/rundotdec.hh, src/tgbaalgos/safety.cc, src/tgbaalgos/safety.hh, src/tgbaalgos/save.cc, src/tgbaalgos/save.hh, src/tgbaalgos/scc.cc, src/tgbaalgos/scc.hh, src/tgbaalgos/sccfilter.cc, src/tgbaalgos/sccfilter.hh, src/tgbaalgos/sccinfo.cc, src/tgbaalgos/sccinfo.hh, src/tgbaalgos/se05.cc, src/tgbaalgos/se05.hh, src/tgbaalgos/simulation.cc, src/tgbaalgos/simulation.hh, src/tgbaalgos/stats.cc, src/tgbaalgos/stats.hh, src/tgbaalgos/stripacc.cc, src/tgbaalgos/stripacc.hh, src/tgbaalgos/tau03.cc, src/tgbaalgos/tau03.hh, src/tgbaalgos/tau03opt.cc, src/tgbaalgos/tau03opt.hh, src/tgbaalgos/translate.cc, src/tgbaalgos/translate.hh, src/tgbaparse/public.hh, src/tgbaparse/tgbaparse.yy, src/tgbatest/complementation.cc, src/tgbatest/explprod.cc, src/tgbatest/ltl2tgba.cc, src/tgbatest/ltlprod.cc, src/tgbatest/maskacc.cc, src/tgbatest/powerset.cc, src/tgbatest/randtgba.cc, src/tgbatest/taatgba.cc, src/tgbatest/tgbaread.cc, src/tgbatest/tripprod.cc, wrap/python/ajax/spot.in, wrap/python/spot.i, wrap/python/tests/interdep.py: Use shared pointers for automata. --- iface/dve2/dve2.cc | 4 +- iface/dve2/dve2.hh | 2 +- iface/dve2/dve2check.cc | 28 ++- src/bin/common_output.hh | 5 +- src/bin/dstar2tgba.cc | 17 +- src/bin/ltl2tgba.cc | 3 +- src/bin/ltl2tgta.cc | 26 +-- src/bin/ltlcross.cc | 68 +++---- src/bin/ltlfilt.cc | 2 - src/dstarparse/dra2ba.cc | 44 ++-- src/dstarparse/dstar2tgba.cc | 4 +- src/dstarparse/dstarparse.yy | 18 +- src/dstarparse/nra2nba.cc | 20 +- src/dstarparse/nsa2tgba.cc | 5 +- src/dstarparse/public.hh | 29 +-- src/graphtest/tgbagraph.cc | 64 +++--- src/kripke/Makefile.am | 3 +- src/kripke/fairkripke.hh | 3 +- src/kripke/fwd.hh | 40 ++++ src/kripke/kripke.hh | 4 + src/kripke/kripkeexplicit.cc | 8 +- src/kripke/kripkeexplicit.hh | 10 +- src/kripke/kripkeprint.cc | 21 +- src/kripke/kripkeprint.hh | 9 +- src/kripkeparse/kripkeparse.yy | 8 +- src/kripkeparse/public.hh | 9 +- src/kripketest/parse_print_test.cc | 17 +- src/ltlvisit/apcollect.cc | 2 +- src/ltlvisit/apcollect.hh | 5 +- src/ltlvisit/contain.cc | 7 +- src/ltlvisit/contain.hh | 2 +- src/neverparse/neverclaimparse.yy | 6 +- src/neverparse/public.hh | 2 +- src/priv/accmap.hh | 10 +- src/priv/countstates.cc | 4 +- src/priv/countstates.hh | 7 +- src/saba/saba.hh | 5 +- src/saba/sabacomplementtgba.cc | 11 +- src/saba/sabacomplementtgba.hh | 17 +- src/sabaalgos/sabadotty.cc | 5 +- src/sabaalgos/sabadotty.hh | 9 +- src/sabaalgos/sabareachiter.cc | 9 +- src/sabaalgos/sabareachiter.hh | 10 +- src/sabatest/sabacomplementtgba.cc | 8 +- src/ta/ta.hh | 3 + src/ta/taexplicit.cc | 13 +- src/ta/taexplicit.hh | 23 ++- src/ta/taproduct.cc | 21 +- src/ta/taproduct.hh | 19 +- src/ta/tgta.hh | 7 +- src/ta/tgtaexplicit.cc | 25 +-- src/ta/tgtaexplicit.hh | 24 ++- src/ta/tgtaproduct.cc | 12 +- src/ta/tgtaproduct.hh | 19 +- src/taalgos/dotty.cc | 4 +- src/taalgos/dotty.hh | 6 +- src/taalgos/emptinessta.cc | 8 +- src/taalgos/emptinessta.hh | 6 +- src/taalgos/minimize.cc | 32 +-- src/taalgos/minimize.hh | 12 +- src/taalgos/reachiter.cc | 11 +- src/taalgos/reachiter.hh | 12 +- src/taalgos/statessetbuilder.cc | 7 +- src/taalgos/statessetbuilder.hh | 6 +- src/taalgos/stats.cc | 9 +- src/taalgos/stats.hh | 4 +- src/taalgos/tgba2ta.cc | 41 ++-- src/taalgos/tgba2ta.hh | 18 +- src/tgba/Makefile.am | 1 + src/tgba/bdddict.cc | 21 -- src/tgba/bdddict.hh | 115 ++++++++++- src/tgba/formula2bdd.hh | 12 +- src/tgba/futurecondcol.cc | 4 +- src/tgba/futurecondcol.hh | 15 +- src/tgba/fwd.hh | 44 ++++ src/tgba/taatgba.hh | 31 ++- src/tgba/tgba.cc | 5 +- src/tgba/tgba.hh | 4 +- src/tgba/tgbagraph.hh | 20 +- src/tgba/tgbakvcomplement.cc | 13 +- src/tgba/tgbakvcomplement.hh | 12 +- src/tgba/tgbamask.cc | 128 ++++++------ src/tgba/tgbamask.hh | 43 +--- src/tgba/tgbaproduct.cc | 18 +- src/tgba/tgbaproduct.hh | 24 ++- src/tgba/tgbaproxy.cc | 5 +- src/tgba/tgbaproxy.hh | 6 +- src/tgba/tgbasafracomplement.cc | 22 +- src/tgba/tgbasafracomplement.hh | 15 +- src/tgba/tgbascc.cc | 4 +- src/tgba/tgbascc.hh | 6 +- src/tgba/tgbasgba.cc | 3 +- src/tgba/tgbasgba.hh | 9 +- src/tgba/wdbacomp.cc | 16 +- src/tgba/wdbacomp.hh | 6 +- src/tgbaalgos/bfssteps.cc | 2 +- src/tgbaalgos/bfssteps.hh | 6 +- src/tgbaalgos/complete.cc | 6 +- src/tgbaalgos/complete.hh | 4 +- src/tgbaalgos/compsusp.cc | 46 ++--- src/tgbaalgos/compsusp.hh | 2 +- src/tgbaalgos/cycles.hh | 2 +- src/tgbaalgos/degen.cc | 27 +-- src/tgbaalgos/degen.hh | 8 +- src/tgbaalgos/dotty.cc | 10 +- src/tgbaalgos/dotty.hh | 5 +- src/tgbaalgos/dottydec.cc | 10 +- src/tgbaalgos/dottydec.hh | 9 +- src/tgbaalgos/dtbasat.cc | 40 ++-- src/tgbaalgos/dtbasat.hh | 14 +- src/tgbaalgos/dtgbacomp.cc | 4 +- src/tgbaalgos/dtgbacomp.hh | 4 +- src/tgbaalgos/dtgbasat.cc | 46 ++--- src/tgbaalgos/dtgbasat.hh | 15 +- src/tgbaalgos/dupexp.cc | 27 +-- src/tgbaalgos/dupexp.hh | 18 +- src/tgbaalgos/emptiness.cc | 21 +- src/tgbaalgos/emptiness.hh | 21 +- src/tgbaalgos/gtec/gtec.cc | 7 +- src/tgbaalgos/gtec/gtec.hh | 6 +- src/tgbaalgos/gtec/status.cc | 2 +- src/tgbaalgos/gtec/status.hh | 4 +- src/tgbaalgos/gv04.cc | 4 +- src/tgbaalgos/gv04.hh | 8 +- src/tgbaalgos/isdet.cc | 8 +- src/tgbaalgos/isdet.hh | 6 +- src/tgbaalgos/isweakscc.cc | 2 +- src/tgbaalgos/lbtt.cc | 29 ++- src/tgbaalgos/lbtt.hh | 4 +- src/tgbaalgos/ltl2taa.cc | 20 +- src/tgbaalgos/ltl2taa.hh | 8 +- src/tgbaalgos/ltl2tgba_fm.cc | 14 +- src/tgbaalgos/ltl2tgba_fm.hh | 4 +- src/tgbaalgos/magic.cc | 11 +- src/tgbaalgos/magic.hh | 10 +- src/tgbaalgos/minimize.cc | 106 ++++------ src/tgbaalgos/minimize.hh | 13 +- src/tgbaalgos/ndfs_result.hxx | 8 +- src/tgbaalgos/neverclaim.cc | 8 +- src/tgbaalgos/neverclaim.hh | 3 +- src/tgbaalgos/postproc.cc | 165 +++++---------- src/tgbaalgos/postproc.hh | 15 +- src/tgbaalgos/powerset.cc | 97 ++++----- src/tgbaalgos/powerset.hh | 18 +- src/tgbaalgos/projrun.cc | 6 +- src/tgbaalgos/projrun.hh | 10 +- src/tgbaalgos/randomgraph.cc | 6 +- src/tgbaalgos/randomgraph.hh | 2 +- src/tgbaalgos/reachiter.cc | 8 +- src/tgbaalgos/reachiter.hh | 12 +- src/tgbaalgos/reducerun.cc | 4 +- src/tgbaalgos/reducerun.hh | 8 +- src/tgbaalgos/replayrun.cc | 6 +- src/tgbaalgos/replayrun.hh | 7 +- src/tgbaalgos/rundotdec.cc | 5 +- src/tgbaalgos/rundotdec.hh | 7 +- src/tgbaalgos/safety.cc | 4 +- src/tgbaalgos/safety.hh | 4 +- src/tgbaalgos/save.cc | 4 +- src/tgbaalgos/save.hh | 2 +- src/tgbaalgos/scc.cc | 8 +- src/tgbaalgos/scc.hh | 13 +- src/tgbaalgos/sccfilter.cc | 22 +- src/tgbaalgos/sccfilter.hh | 15 +- src/tgbaalgos/sccinfo.cc | 4 +- src/tgbaalgos/sccinfo.hh | 8 +- src/tgbaalgos/se05.cc | 12 +- src/tgbaalgos/se05.hh | 14 +- src/tgbaalgos/simulation.cc | 156 ++++++--------- src/tgbaalgos/simulation.hh | 22 +- src/tgbaalgos/stats.cc | 10 +- src/tgbaalgos/stats.hh | 6 +- src/tgbaalgos/stripacc.cc | 2 +- src/tgbaalgos/stripacc.hh | 2 +- src/tgbaalgos/tau03.cc | 4 +- src/tgbaalgos/tau03.hh | 8 +- src/tgbaalgos/tau03opt.cc | 5 +- src/tgbaalgos/tau03opt.hh | 9 +- src/tgbaalgos/translate.cc | 6 +- src/tgbaalgos/translate.hh | 4 +- src/tgbaparse/public.hh | 2 +- src/tgbaparse/tgbaparse.yy | 7 +- src/tgbatest/complementation.cc | 64 +++--- src/tgbatest/explprod.cc | 31 ++- src/tgbatest/ltl2tgba.cc | 309 ++++++++++------------------- src/tgbatest/ltlprod.cc | 47 ++--- src/tgbatest/maskacc.cc | 32 +-- src/tgbatest/powerset.cc | 22 +- src/tgbatest/randtgba.cc | 28 +-- src/tgbatest/taatgba.cc | 31 +-- src/tgbatest/tgbaread.cc | 43 ++-- src/tgbatest/tripprod.cc | 41 ++-- wrap/python/ajax/spot.in | 8 +- wrap/python/spot.i | 75 +++---- wrap/python/tests/interdep.py | 3 +- 195 files changed, 1792 insertions(+), 1837 deletions(-) create mode 100644 src/kripke/fwd.hh create mode 100644 src/tgba/fwd.hh diff --git a/iface/dve2/dve2.cc b/iface/dve2/dve2.cc index 16b4b8ca8..dfe6001e6 100644 --- a/iface/dve2/dve2.cc +++ b/iface/dve2/dve2.cc @@ -997,7 +997,7 @@ namespace spot } - kripke* + kripke_ptr load_dve2(const std::string& file_arg, bdd_dict_ptr dict, const ltl::atomic_prop_set* to_observe, const ltl::formula* dead, @@ -1112,6 +1112,6 @@ namespace spot return 0; } - return new dve2_kripke(d, dict, ps, dead, compress); + return std::make_shared(d, dict, ps, dead, compress); } } diff --git a/iface/dve2/dve2.hh b/iface/dve2/dve2.hh index 3ff562118..1913781e6 100644 --- a/iface/dve2/dve2.hh +++ b/iface/dve2/dve2.hh @@ -56,7 +56,7 @@ namespace spot // \a dead an atomic proposition or constant to use for looping on // dead states // \a verbose whether to output verbose messages - SPOT_API kripke* + SPOT_API kripke_ptr load_dve2(const std::string& file, bdd_dict_ptr dict, const ltl::atomic_prop_set* to_observe, const ltl::formula* dead = ltl::constant::true_instance(), diff --git a/iface/dve2/dve2check.cc b/iface/dve2/dve2check.cc index f3913b4a3..052771210 100644 --- a/iface/dve2/dve2check.cc +++ b/iface/dve2/dve2check.cc @@ -62,7 +62,7 @@ Options:\n\ } int -main(int argc, char **argv) +checked_main(int argc, char **argv) { spot::timer_map tm; @@ -157,14 +157,14 @@ main(int argc, char **argv) spot::ltl::atomic_prop_set ap; auto dict = spot::make_bdd_dict(); - spot::kripke* model = 0; - const spot::tgba* prop = 0; - spot::tgba* product = 0; + spot::const_kripke_ptr model = 0; + spot::const_tgba_ptr prop = 0; + spot::const_tgba_ptr product = 0; spot::emptiness_check_instantiator* echeck_inst = 0; int exit_code = 0; - const spot::ltl::formula* f = 0; - const spot::ltl::formula* deadf = 0; spot::postprocessor post; + const spot::ltl::formula* deadf = 0; + const spot::ltl::formula* f = 0; if (dead == 0 || !strcasecmp(dead, "true")) { @@ -252,7 +252,7 @@ main(int argc, char **argv) goto safe_exit; } - product = new spot::tgba_product(model, prop); + product = spot::product(model, prop); if (output == DotProduct) { @@ -362,9 +362,6 @@ main(int argc, char **argv) safe_exit: delete echeck_inst; - delete product; - delete prop; - delete model; if (f) f->destroy(); @@ -373,15 +370,24 @@ main(int argc, char **argv) if (use_timer) tm.print(std::cout); tm.reset_all(); // This helps valgrind. + return exit_code; +} +int +main(int argc, char **argv) +{ + auto exit_code = checked_main(argc, argv); + + // Additional checks to debug reference counts in formulas. spot::ltl::atomic_prop::dump_instances(std::cerr); spot::ltl::unop::dump_instances(std::cerr); spot::ltl::binop::dump_instances(std::cerr); spot::ltl::multop::dump_instances(std::cerr); + spot::ltl::bunop::dump_instances(std::cerr); assert(spot::ltl::atomic_prop::instance_count() == 0); assert(spot::ltl::unop::instance_count() == 0); assert(spot::ltl::binop::instance_count() == 0); assert(spot::ltl::multop::instance_count() == 0); - + assert(spot::ltl::bunop::instance_count() == 0); exit(exit_code); } diff --git a/src/bin/common_output.hh b/src/bin/common_output.hh index 73bafb685..fa12140ac 100644 --- a/src/bin/common_output.hh +++ b/src/bin/common_output.hh @@ -1,5 +1,5 @@ // -*- coding: utf-8 -*- -// Copyright (C) 2012, 2013 Laboratoire de Recherche et Développement +// Copyright (C) 2012, 2013, 2014 Laboratoire de Recherche et Développement // de l'Epita (LRDE). // // This file is part of Spot, a model checking library. @@ -73,7 +73,8 @@ public: } std::ostream& - print(const spot::tgba* aut, const spot::ltl::formula* f = 0, + print(const spot::const_tgba_ptr& aut, + const spot::ltl::formula* f = 0, double run_time = -1.) { formula_ = f; diff --git a/src/bin/dstar2tgba.cc b/src/bin/dstar2tgba.cc index b3a0c35bc..1580771e5 100644 --- a/src/bin/dstar2tgba.cc +++ b/src/bin/dstar2tgba.cc @@ -224,7 +224,8 @@ namespace /// The \a f argument is not needed if the Formula does not need /// to be output. std::ostream& - print(const spot::dstar_aut* daut, const spot::tgba* aut, + print(const spot::const_dstar_aut_ptr& daut, + const spot::const_tgba_ptr& aut, const char* filename, double run_time) { filename_ = filename; @@ -292,17 +293,11 @@ namespace process_file(const char* filename) { spot::dstar_parse_error_list pel; - spot::dstar_aut* daut; - daut = spot::dstar_parse(filename, pel, spot::make_bdd_dict()); + auto daut = spot::dstar_parse(filename, pel, spot::make_bdd_dict()); if (spot::format_dstar_parse_errors(std::cerr, filename, pel)) - { - delete daut; - return 2; - } + return 2; if (!daut) - { - error(2, 0, "failed to read automaton from %s", filename); - } + error(2, 0, "failed to read automaton from %s", filename); const xtime_t before = gethrxtime(); @@ -336,8 +331,6 @@ namespace statistics.print(daut, aut, filename, conversion_time) << '\n'; break; } - delete aut; - delete daut; flush_cout(); return 0; } diff --git a/src/bin/ltl2tgba.cc b/src/bin/ltl2tgba.cc index a2f8fca07..dedbf650b 100644 --- a/src/bin/ltl2tgba.cc +++ b/src/bin/ltl2tgba.cc @@ -214,7 +214,7 @@ namespace const char* filename = 0, int linenum = 0) { const xtime_t before = gethrxtime(); - const spot::tgba* aut = trans.run(&f); + auto aut = trans.run(&f); const xtime_t after = gethrxtime(); const double prec = XTIME_PRECISION; const double translation_time = (after - before) / prec; @@ -254,7 +254,6 @@ namespace statistics.print(aut, f, translation_time) << '\n'; break; } - delete aut; f->destroy(); flush_cout(); return 0; diff --git a/src/bin/ltl2tgta.cc b/src/bin/ltl2tgta.cc index 3a0f12166..8348d391c 100644 --- a/src/bin/ltl2tgta.cc +++ b/src/bin/ltl2tgta.cc @@ -171,7 +171,7 @@ namespace process_formula(const spot::ltl::formula* f, const char* filename = 0, int linenum = 0) { - const spot::tgba* aut = trans.run(&f); + auto aut = trans.run(&f); // This should not happen, because the parser we use can only // read PSL/LTL formula, but since our ltl::formula* type can @@ -189,36 +189,22 @@ namespace if (ta_type != TGTA) { - spot::ta* testing_automaton = + auto testing_automaton = tgba_to_ta(aut, ap_set, type == spot::postprocessor::BA, opt_with_artificial_initial_state, opt_single_pass_emptiness_check, opt_with_artificial_livelock); if (level != spot::postprocessor::Low) - { - spot::ta* testing_automaton_nm = testing_automaton; - testing_automaton = spot::minimize_ta(testing_automaton); - delete testing_automaton_nm; - } + testing_automaton = spot::minimize_ta(testing_automaton); spot::dotty_reachable(std::cout, testing_automaton); - delete testing_automaton; } else { - spot::tgta_explicit* tgta = tgba_to_tgta(aut, ap_set); + auto tgta = tgba_to_tgta(aut, ap_set); if (level != spot::postprocessor::Low) - { - spot::tgta_explicit* a = spot::minimize_tgta(tgta); - delete tgta; - tgta = a; - } - spot::dotty_reachable(std::cout, - dynamic_cast(tgta) - ->get_ta()); - delete tgta; + tgta = spot::minimize_tgta(tgta); + spot::dotty_reachable(std::cout, tgta->get_ta()); } - - delete aut; f->destroy(); flush_cout(); return 0; diff --git a/src/bin/ltlcross.cc b/src/bin/ltlcross.cc index 8005b3878..39e1b898a 100644 --- a/src/bin/ltlcross.cc +++ b/src/bin/ltlcross.cc @@ -848,7 +848,7 @@ namespace string_to_tmp(string_ltl_wring, serial, filename_ltl_wring); } - const spot::tgba* + spot::const_tgba_ptr translate(unsigned int translator_num, char l, statistics_formula* fstats) { output.reset(translator_num); @@ -867,7 +867,7 @@ namespace const char* status_str = 0; - const spot::tgba* res = 0; + spot::const_tgba_ptr res = 0; if (timed_out) { // This is not considered to be a global error. @@ -911,8 +911,7 @@ namespace err << "error: failed to parse the produced neverclaim.\n"; spot::format_neverclaim_parse_errors(err, filename, pel); end_error(); - delete res; - res = 0; + res = nullptr; } break; } @@ -947,8 +946,7 @@ namespace { spot::dstar_parse_error_list pel; std::string filename = output.val()->name(); - spot::dstar_aut* aut; - aut = spot::dstar_parse(filename, pel, dict); + auto aut = spot::dstar_parse(filename, pel, dict); if (!pel.empty()) { status_str = "parse error"; @@ -958,8 +956,7 @@ namespace " output.\n"; spot::format_dstar_parse_errors(err, filename, pel); end_error(); - delete aut; - res = 0; + res = nullptr; } else { @@ -992,7 +989,6 @@ namespace } // convert it into TGBA for further processing res = dstar_to_tgba(aut); - delete aut; } break; } @@ -1049,10 +1045,11 @@ namespace }; static void - check_empty_prod(const spot::tgba* aut_i, const spot::tgba* aut_j, + check_empty_prod(const spot::const_tgba_ptr& aut_i, + const spot::const_tgba_ptr& aut_j, size_t i, size_t j, bool icomp, bool jcomp) { - spot::tgba_product* prod = new spot::tgba_product(aut_i, aut_j); + auto prod = spot::product(aut_i, aut_j); spot::emptiness_check* ec = spot::couvreur99(prod); spot::emptiness_check_result* res = ec->check(); @@ -1090,7 +1087,6 @@ namespace } delete res; delete ec; - delete prod; } static void @@ -1154,16 +1150,18 @@ namespace // Collect all the states of SSPACE that appear in the accepting SCCs // of PROD. static void - states_in_acc(const spot::scc_map* m, const spot::tgba* sspace, + states_in_acc(const spot::scc_map* m, + const spot::const_tgba_ptr& sspace, state_set& s) { - const spot::tgba* aut = m->get_aut(); + auto aut = m->get_aut(); unsigned c = m->scc_count(); for (unsigned n = 0; n < c; ++n) if (m->accepting(n)) for (auto i: m->states_of(n)) { spot::state* x = aut->project_state(i, sspace); + assert(x); if (!s.insert(x).second) x->destroy(); } @@ -1171,7 +1169,7 @@ namespace static bool consistency_check(const spot::scc_map* pos, const spot::scc_map* neg, - const spot::tgba* sspace) + const spot::const_tgba_ptr& sspace) { // the states of SSPACE should appear in the accepting SCC of at // least one of POS or NEG. Maybe both. @@ -1266,12 +1264,12 @@ namespace // These store the result of the translation of the positive and // negative formulas. size_t m = translators.size(); - std::vector pos(m); - std::vector neg(m); + std::vector pos(m); + std::vector neg(m); // These store the complement of the above results, when we can // compute it easily. - std::vector comp_pos(m); - std::vector comp_neg(m); + std::vector comp_pos(m); + std::vector comp_neg(m); unsigned n = vstats.size(); @@ -1400,20 +1398,19 @@ namespace { // build a random state-space. spot::srand(seed); - spot::tgba* statespace = spot::random_graph(states, density, - ap, dict); + auto statespace = spot::random_graph(states, density, ap, dict); // Products of the state space with the positive automata. - std::vector pos_prod(m); + std::vector pos_prod(m); // Products of the state space with the negative automata. - std::vector neg_prod(m); + std::vector neg_prod(m); // Associated SCC maps. std::vector pos_map(m); std::vector neg_map(m); for (size_t i = 0; i < m; ++i) if (pos[i]) { - spot::tgba* p = new spot::tgba_product(pos[i], statespace); + auto p = spot::product(pos[i], statespace); pos_prod[i] = p; spot::scc_map* sm = new spot::scc_map(p); sm->build_map(); @@ -1433,7 +1430,7 @@ namespace for (size_t i = 0; i < m; ++i) if (neg[i]) { - spot::tgba* p = new spot::tgba_product(neg[i], statespace); + auto p = spot::product(neg[i], statespace); neg_prod[i] = p; spot::scc_map* sm = new spot::scc_map(p); sm->build_map(); @@ -1475,31 +1472,14 @@ namespace // Cleanup. if (!no_checks) for (size_t i = 0; i < m; ++i) - { - delete neg_map[i]; - delete neg_prod[i]; - } + delete neg_map[i]; for (size_t i = 0; i < m; ++i) - { - delete pos_map[i]; - delete pos_prod[i]; - } - delete statespace; + delete pos_map[i]; ++seed; } std::cerr << std::endl; delete ap; - if (!no_checks) - for (size_t i = 0; i < m; ++i) - { - delete neg[i]; - delete comp_neg[i]; - delete comp_pos[i]; - } - for (size_t i = 0; i < m; ++i) - delete pos[i]; - // Shall we stop processing formulas now? abort_run = global_error_flag && stop_on_error; return 0; diff --git a/src/bin/ltlfilt.cc b/src/bin/ltlfilt.cc index 0aa57a81f..91da47244 100644 --- a/src/bin/ltlfilt.cc +++ b/src/bin/ltlfilt.cc @@ -560,9 +560,7 @@ namespace { matched &= !guarantee || is_guarantee_automaton(min); matched &= !safety || is_safety_mwdba(min); - delete min; } - delete aut; } matched ^= invert; diff --git a/src/dstarparse/dra2ba.cc b/src/dstarparse/dra2ba.cc index c06ebbc8e..7431e097d 100644 --- a/src/dstarparse/dra2ba.cc +++ b/src/dstarparse/dra2ba.cc @@ -48,7 +48,8 @@ namespace spot // This function is defined in nra2nba.cc, and used only here. SPOT_LOCAL - tgba_digraph* nra_to_nba(const dstar_aut* nra, const tgba* aut); + tgba_digraph_ptr nra_to_nba(const const_dstar_aut_ptr& nra, + const const_tgba_ptr& aut); namespace { @@ -63,15 +64,15 @@ namespace spot // retrive acceptances. static bool - filter_states(const tgba* aut, - const dstar_aut* dra, + filter_states(const const_tgba_ptr& aut, + const const_dstar_aut_ptr& dra, const state_list& sl, state_list& final, state_list& nonfinal); static bool - filter_scc(const tgba* aut, - const dstar_aut* dra, + filter_scc(const const_tgba_ptr& aut, + const const_dstar_aut_ptr& dra, state_list& final, state_list& nonfinal) { @@ -97,8 +98,8 @@ namespace spot } static bool - filter_states(const tgba* aut, - const dstar_aut* dra, + filter_states(const const_tgba_ptr& aut, + const const_dstar_aut_ptr& dra, const state_list& sl, state_list& final, state_list& nonfinal) @@ -146,15 +147,11 @@ namespace spot // could be improved. { state_set keep(sl.begin(), sl.end()); - const tgba* masked = - build_tgba_mask_keep(dra->aut, keep, sl.front()); - const tgba* nba = nra_to_nba(dra, masked); - emptiness_check* ec = couvreur99(nba); + auto masked = build_tgba_mask_keep(dra->aut, keep, sl.front()); + emptiness_check* ec = couvreur99(nra_to_nba(dra, masked)); emptiness_check_result* ecr = ec->check(); delete ecr; delete ec; - delete nba; - delete masked; if (ecr) { // This SCC is not DBA-realizable. @@ -197,13 +194,11 @@ namespace spot //std::cerr << "unknown\n"; // Build a sub-automaton for just the unknown states, // starting from any state in the SCC. - const tgba* scc_mask = - build_tgba_mask_keep(aut, unknown, *unknown.begin()); + auto scc_mask = build_tgba_mask_keep(aut, unknown, *unknown.begin()); state_list local_final; state_list local_nonfinal; bool dbarealizable = filter_scc(scc_mask, dra, local_final, local_nonfinal); - delete scc_mask; if (!dbarealizable) return false; for (state_list::const_iterator i = local_final.begin(); @@ -223,13 +218,13 @@ namespace spot class dra_to_ba_worker: public tgba_reachable_iterator_depth_first { public: - dra_to_ba_worker(const dstar_aut* a, + dra_to_ba_worker(const const_dstar_aut_ptr& a, const state_set& final, const scc_map& sm, const std::vector& realizable): tgba_reachable_iterator_depth_first(a->aut), in_(a), - out_(new tgba_digraph(a->aut->get_dict())), + out_(make_tgba_digraph(a->aut->get_dict())), final_(final), num_states_(a->aut->num_states()), sm_(sm), @@ -242,7 +237,7 @@ namespace spot out_->set_init_state(a->aut->get_init_state_number()); } - tgba_digraph* + tgba_digraph_ptr result() { return out_; @@ -301,8 +296,8 @@ namespace spot } protected: - const dstar_aut* in_; - tgba_digraph* out_; + const const_dstar_aut_ptr& in_; + tgba_digraph_ptr out_; const state_set& final_; size_t num_states_; bdd acc_; @@ -313,7 +308,7 @@ namespace spot } - tgba_digraph* dra_to_ba(const dstar_aut* dra, bool* dba) + tgba_digraph_ptr dra_to_ba(const const_dstar_aut_ptr& dra, bool* dba) { assert(dra->type == Rabin); @@ -358,10 +353,7 @@ namespace spot state_set fs(final.begin(), final.end()); dra_to_ba_worker w(dra, fs, sm, realizable); w.run(); - auto res1 = w.result(); - auto res2 = scc_filter_states(res1); - delete res1; - return res2; + return scc_filter_states(w.result()); } } diff --git a/src/dstarparse/dstar2tgba.cc b/src/dstarparse/dstar2tgba.cc index cb323f127..849c509b0 100644 --- a/src/dstarparse/dstar2tgba.cc +++ b/src/dstarparse/dstar2tgba.cc @@ -21,8 +21,8 @@ namespace spot { - tgba_digraph* - dstar_to_tgba(const dstar_aut* daut) + tgba_digraph_ptr + dstar_to_tgba(const const_dstar_aut_ptr& daut) { switch (daut->type) { diff --git a/src/dstarparse/dstarparse.yy b/src/dstarparse/dstarparse.yy index 3b6c02f7b..4d356964c 100644 --- a/src/dstarparse/dstarparse.yy +++ b/src/dstarparse/dstarparse.yy @@ -38,7 +38,7 @@ struct result_ { - spot::dstar_aut* d; + spot::dstar_aut_ptr d; spot::ltl::environment* env; std::vector guards; std::vector::const_iterator cur_guard; @@ -143,8 +143,7 @@ header: auttype opt_eols V2 opt_eols EXPLICIT opt_eols sizes } if (err) { - delete result.d->aut; - result.d->aut = 0; + result.d->aut = nullptr; YYABORT; } result.d->aut->new_states(result.state_count);; @@ -313,10 +312,10 @@ dstaryy::parser::error(const location_type& location, namespace spot { - dstar_aut* + dstar_aut_ptr dstar_parse(const std::string& name, dstar_parse_error_list& error_list, - bdd_dict_ptr dict, + const bdd_dict_ptr& dict, ltl::environment& env, bool debug) { @@ -327,8 +326,8 @@ namespace spot return 0; } result_ r; - r.d = new dstar_aut; - r.d->aut = new tgba_digraph(dict); + r.d = std::make_shared(); + r.d->aut = make_tgba_digraph(dict); r.d->accsets = 0; r.env = &env; dstaryy::parser parser(error_list, r); @@ -337,10 +336,7 @@ namespace spot dstaryyclose(); if (!r.d->aut || !r.d->accsets) - { - delete r.d; - return 0; - } + return nullptr; return r.d; } } diff --git a/src/dstarparse/nra2nba.cc b/src/dstarparse/nra2nba.cc index 935d2ab40..c599674cd 100644 --- a/src/dstarparse/nra2nba.cc +++ b/src/dstarparse/nra2nba.cc @@ -38,9 +38,9 @@ namespace spot // AUT is the automate we iterate on, while A is the automaton // we read the acceptance conditions from. Separating the two // makes its possible to mask AUT, as needed in dra_to_ba(). - nra_to_nba_worker(const dstar_aut* a, const tgba* aut): + nra_to_nba_worker(const const_dstar_aut_ptr& a, const_tgba_ptr aut): tgba_reachable_iterator_depth_first(aut), - out_(new tgba_digraph(aut->get_dict())), + out_(make_tgba_digraph(aut->get_dict())), d_(a), num_states_(a->aut->num_states()) { @@ -54,7 +54,7 @@ namespace spot i->destroy(); } - tgba_digraph* + tgba_digraph_ptr result() { return out_; @@ -104,8 +104,8 @@ namespace spot } protected: - tgba_digraph* out_; - const dstar_aut* d_; + tgba_digraph_ptr out_; + const_dstar_aut_ptr d_; size_t num_states_; }; @@ -114,19 +114,17 @@ namespace spot // In dra_to_dba() we call this function with a second argument // that is a masked version of nra->aut. SPOT_LOCAL - tgba_digraph* nra_to_nba(const dstar_aut* nra, const tgba* aut) + tgba_digraph_ptr nra_to_nba(const const_dstar_aut_ptr& nra, + const const_tgba_ptr& aut) { assert(nra->type == Rabin); nra_to_nba_worker w(nra, aut); w.run(); - auto res1 = w.result(); - auto res2 = scc_filter_states(res1); - delete res1; - return res2; + return scc_filter_states(w.result()); } SPOT_API - tgba_digraph* nra_to_nba(const dstar_aut* nra) + tgba_digraph_ptr nra_to_nba(const const_dstar_aut_ptr& nra) { return nra_to_nba(nra, nra->aut); } diff --git a/src/dstarparse/nsa2tgba.cc b/src/dstarparse/nsa2tgba.cc index 89e9ad29d..0aeca8fe7 100644 --- a/src/dstarparse/nsa2tgba.cc +++ b/src/dstarparse/nsa2tgba.cc @@ -99,11 +99,11 @@ namespace spot } SPOT_API - tgba_digraph* nsa_to_tgba(const dstar_aut* nsa) + tgba_digraph_ptr nsa_to_tgba(const const_dstar_aut_ptr& nsa) { assert(nsa->type == Streett); auto a = nsa->aut; - auto res = new tgba_digraph(a->get_dict()); + auto res = make_tgba_digraph(a->get_dict()); res->copy_ap_of(a); // Create accpair_count acceptance sets for the output. @@ -204,4 +204,3 @@ namespace spot } } - diff --git a/src/dstarparse/public.hh b/src/dstarparse/public.hh index 440db7e1f..291611f92 100644 --- a/src/dstarparse/public.hh +++ b/src/dstarparse/public.hh @@ -47,7 +47,7 @@ namespace spot { // Transition structure of the automaton. // This is encoded as a TGBA without acceptance condition. - tgba_digraph* aut; + tgba_digraph_ptr aut; /// Type of the acceptance. dstar_type type; /// Number of acceptance pairs. @@ -62,11 +62,12 @@ namespace spot ~dstar_aut() { - delete aut; delete accsets; } }; + typedef std::shared_ptr dstar_aut_ptr; + typedef std::shared_ptr const_dstar_aut_ptr; /// \brief Build a spot::tgba_digraph from ltl2dstar's output. /// \param filename The name of the file to parse. @@ -85,10 +86,10 @@ namespace spot /// was parsed succesfully, check \a error_list for emptiness. /// /// \warning This function is not reentrant. - SPOT_API dstar_aut* + SPOT_API dstar_aut_ptr dstar_parse(const std::string& filename, dstar_parse_error_list& error_list, - bdd_dict_ptr dict, + const bdd_dict_ptr& dict, ltl::environment& env = ltl::default_environment::instance(), bool debug = false); @@ -106,15 +107,15 @@ namespace spot /// \brief Convert a non-deterministic Rabin automaton into a /// non-deterministic Büchi automaton. - SPOT_API tgba_digraph* - nra_to_nba(const dstar_aut* nra); + SPOT_API tgba_digraph_ptr + nra_to_nba(const const_dstar_aut_ptr& nra); /// \brief Convert a non-deterministic Rabin automaton into a /// non-deterministic Büchi automaton. /// /// This version simply ignores all states in \a ignore. - SPOT_API tgba_digraph* - nra_to_nba(const dstar_aut* nra, const state_set* ignore); + SPOT_API tgba_digraph_ptr + nra_to_nba(const const_dstar_aut_ptr& nra, const state_set* ignore); /// \brief Convert a deterministic Rabin automaton into a /// Büchi automaton, deterministic when possible. @@ -132,19 +133,19 @@ namespace spot /// If the optional \a dba_output argument is non-null, the /// pointed Boolean will be updated to indicate whether the /// returned Büchi automaton is deterministic. - SPOT_API tgba_digraph* - dra_to_ba(const dstar_aut* dra, bool* dba_output = 0); + SPOT_API tgba_digraph_ptr + dra_to_ba(const const_dstar_aut_ptr& dra, bool* dba_output = 0); /// \brief Convert a non-deterministic Streett automaton into a /// non-deterministic tgba. - SPOT_API tgba_digraph* - nsa_to_tgba(const dstar_aut* nra); + SPOT_API tgba_digraph_ptr + nsa_to_tgba(const const_dstar_aut_ptr& nra); /// \brief Convert a Rabin or Streett automaton into a TGBA. /// /// This function calls dra_to_ba() or nsa_to_tgba(). - SPOT_API tgba_digraph* - dstar_to_tgba(const dstar_aut* dstar); + SPOT_API tgba_digraph_ptr + dstar_to_tgba(const const_dstar_aut_ptr& dstar); /// @} diff --git a/src/graphtest/tgbagraph.cc b/src/graphtest/tgbagraph.cc index f4fa3ce16..addaf1d3a 100644 --- a/src/graphtest/tgbagraph.cc +++ b/src/graphtest/tgbagraph.cc @@ -29,64 +29,64 @@ void f1() auto& e = spot::ltl::default_environment::instance(); - spot::tgba_digraph tg(d); + auto tg = make_tgba_digraph(d); auto* f1 = e.require("p1"); auto* f2 = e.require("p2"); - bdd p1 = bdd_ithvar(d->register_proposition(f1, &tg)); - bdd p2 = bdd_ithvar(d->register_proposition(f2, &tg)); - bdd a1 = bdd_ithvar(d->register_acceptance_variable(f1, &tg)); - bdd a2 = bdd_ithvar(d->register_acceptance_variable(f2, &tg)); + bdd p1 = bdd_ithvar(d->register_proposition(f1, tg)); + bdd p2 = bdd_ithvar(d->register_proposition(f2, tg)); + bdd a1 = bdd_ithvar(d->register_acceptance_variable(f1, tg)); + bdd a2 = bdd_ithvar(d->register_acceptance_variable(f2, tg)); f1->destroy(); f2->destroy(); - auto s1 = tg.new_state(); - auto s2 = tg.new_state(); - auto s3 = tg.new_state(); - tg.new_transition(s1, s1, bddfalse, bddfalse); - tg.new_transition(s1, s2, p1, bddfalse); - tg.new_transition(s1, s3, p2, !a1 & a2); - tg.new_transition(s2, s3, p1 & p2, a1 & !a2); - tg.new_transition(s3, s1, p1 | p2, (!a1 & a2) | (a1 & !a2)); - tg.new_transition(s3, s2, p1 >> p2, bddfalse); - tg.new_transition(s3, s3, bddtrue, (!a1 & a2) | (a1 & !a2)); + auto s1 = tg->new_state(); + auto s2 = tg->new_state(); + auto s3 = tg->new_state(); + tg->new_transition(s1, s1, bddfalse, bddfalse); + tg->new_transition(s1, s2, p1, bddfalse); + tg->new_transition(s1, s3, p2, !a1 & a2); + tg->new_transition(s2, s3, p1 & p2, a1 & !a2); + tg->new_transition(s3, s1, p1 | p2, (!a1 & a2) | (a1 & !a2)); + tg->new_transition(s3, s2, p1 >> p2, bddfalse); + tg->new_transition(s3, s3, bddtrue, (!a1 & a2) | (a1 & !a2)); - spot::dotty_reachable(std::cout, &tg); + spot::dotty_reachable(std::cout, tg); { - auto i = tg.get_graph().out_iteraser(s3); + auto i = tg->get_graph().out_iteraser(s3); ++i; i.erase(); i.erase(); assert(!i); - spot::dotty_reachable(std::cout, &tg); + spot::dotty_reachable(std::cout, tg); } { - auto i = tg.get_graph().out_iteraser(s3); + auto i = tg->get_graph().out_iteraser(s3); i.erase(); assert(!i); - spot::dotty_reachable(std::cout, &tg); + spot::dotty_reachable(std::cout, tg); } - tg.new_transition(s3, s1, p1 | p2, (!a1 & a2) | (a1 & !a2)); - tg.new_transition(s3, s2, p1 >> p2, bddfalse); - tg.new_transition(s3, s1, bddtrue, (!a1 & a2) | (a1 & !a2)); + tg->new_transition(s3, s1, p1 | p2, (!a1 & a2) | (a1 & !a2)); + tg->new_transition(s3, s2, p1 >> p2, bddfalse); + tg->new_transition(s3, s1, bddtrue, (!a1 & a2) | (a1 & !a2)); - std::cerr << tg.num_transitions() << '\n'; - assert(tg.num_transitions() == 7); + std::cerr << tg->num_transitions() << '\n'; + assert(tg->num_transitions() == 7); - spot::dotty_reachable(std::cout, &tg); - tg.merge_transitions(); - spot::dotty_reachable(std::cout, &tg); + spot::dotty_reachable(std::cout, tg); + tg->merge_transitions(); + spot::dotty_reachable(std::cout, tg); - std::cerr << tg.num_transitions() << '\n'; - assert(tg.num_transitions() == 5); + std::cerr << tg->num_transitions() << '\n'; + assert(tg->num_transitions() == 5); // Add enough states so that the state vector is reallocated. for (unsigned i = 0; i < 100; ++i) - tg.new_state(); - spot::dotty_reachable(std::cout, &tg); + tg->new_state(); + spot::dotty_reachable(std::cout, tg); } int main() diff --git a/src/kripke/Makefile.am b/src/kripke/Makefile.am index 55c445d6f..b26448f12 100644 --- a/src/kripke/Makefile.am +++ b/src/kripke/Makefile.am @@ -1,5 +1,5 @@ ## -*- coding: utf-8 -*- -## Copyright (C) 2009, 2011, 2013 Laboratoire de Recherche et +## Copyright (C) 2009, 2011, 2013, 2014 Laboratoire de Recherche et ## Developpement de l'Epita (LRDE). ## ## This file is part of Spot, a model checking library. @@ -24,6 +24,7 @@ kripkedir = $(pkgincludedir)/kripke kripke_HEADERS = \ fairkripke.hh \ + fwd.hh \ kripke.hh \ kripkeexplicit.hh \ kripkeprint.hh diff --git a/src/kripke/fairkripke.hh b/src/kripke/fairkripke.hh index af6d23917..b0f8e905b 100644 --- a/src/kripke/fairkripke.hh +++ b/src/kripke/fairkripke.hh @@ -22,14 +22,13 @@ #include "tgba/tgba.hh" #include "tgba/succiter.hh" +#include "fwd.hh" /// \addtogroup kripke Kripke Structures /// \ingroup tgba namespace spot { - class fair_kripke; - /// \ingroup kripke /// \brief Iterator code for a Fair Kripke structure. /// diff --git a/src/kripke/fwd.hh b/src/kripke/fwd.hh new file mode 100644 index 000000000..84cf9daa4 --- /dev/null +++ b/src/kripke/fwd.hh @@ -0,0 +1,40 @@ +// -*- coding: utf-8 -*- +// Copyright (C) 2014 Laboratoire de Recherche et Développement de +// l'Epita (LRDE). +// +// This file is part of Spot, a model checking library. +// +// Spot is free software; you can redistribute it and/or modify it +// under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 3 of the License, or +// (at your option) any later version. +// +// Spot is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +// or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public +// License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +#ifndef SPOT_KRIPKE_FWD_HH +# define SPOT_KRIPKE_FWD_HH + +#include + +namespace spot +{ + class fair_kripke; + typedef std::shared_ptr fair_kripke_ptr; + typedef std::shared_ptr const_fair_kripke_ptr; + + class kripke; + typedef std::shared_ptr const_kripke_ptr; + typedef std::shared_ptr tgba_kripke_ptr; + + class kripke_explicit; + typedef std::shared_ptr const_kripke_explicit_ptr; + typedef std::shared_ptr kripke_explicit_ptr; +} + +#endif // SPOT_KRIPKE_FWD_HH diff --git a/src/kripke/kripke.hh b/src/kripke/kripke.hh index 066e0dedd..abf87c541 100644 --- a/src/kripke/kripke.hh +++ b/src/kripke/kripke.hh @@ -98,6 +98,10 @@ namespace spot virtual bdd neg_acceptance_conditions() const; virtual bdd all_acceptance_conditions() const; }; + + + typedef std::shared_ptr kripke_ptr; + typedef std::shared_ptr const_kripke_ptr; } #endif // SPOT_KRIPKE_KRIPKE_HH diff --git a/src/kripke/kripkeexplicit.cc b/src/kripke/kripkeexplicit.cc index 16223912a..5ed89ef07 100644 --- a/src/kripke/kripkeexplicit.cc +++ b/src/kripke/kripkeexplicit.cc @@ -126,14 +126,8 @@ namespace spot // kripke_explicit - kripke_explicit::kripke_explicit(bdd_dict_ptr dict) - : dict_(dict), - init_(0) - { - } - kripke_explicit::kripke_explicit(bdd_dict_ptr dict, - state_kripke* init) + state_kripke* init) : dict_(dict), init_ (init) { diff --git a/src/kripke/kripkeexplicit.hh b/src/kripke/kripkeexplicit.hh index 57b03d19a..5e6c26cf3 100644 --- a/src/kripke/kripkeexplicit.hh +++ b/src/kripke/kripkeexplicit.hh @@ -114,8 +114,7 @@ namespace spot class SPOT_API kripke_explicit : public kripke { public: - kripke_explicit(bdd_dict_ptr); - kripke_explicit(bdd_dict_ptr, state_kripke*); + kripke_explicit(bdd_dict_ptr, state_kripke* = nullptr); ~kripke_explicit(); bdd_dict_ptr get_dict() const; @@ -180,5 +179,12 @@ namespace spot std::map ns_nodes_; std::map sn_nodes_; }; + + inline kripke_explicit_ptr + make_kripke_explicit(const bdd_dict_ptr& d, + state_kripke* init = nullptr) + { + return std::make_shared(d, init); + } } #endif // SPOT_KRIPKE_KRIPKEEXPLICIT_HH diff --git a/src/kripke/kripkeprint.cc b/src/kripke/kripkeprint.cc index 99aeb791d..65ec3cb7e 100644 --- a/src/kripke/kripkeprint.cc +++ b/src/kripke/kripkeprint.cc @@ -34,7 +34,7 @@ namespace spot class kripke_printer : public tgba_reachable_iterator_breadth_first { public: - kripke_printer(const kripke* a, std::ostream& os) + kripke_printer(const const_kripke_ptr& a, std::ostream& os) : tgba_reachable_iterator_breadth_first(a), os_(os) { } @@ -45,10 +45,9 @@ namespace spot os_ << '"'; escape_str(os_, aut_->format_state(s)); os_ << "\", \""; - const kripke* automata = down_cast (aut_); - assert(automata); - escape_str(os_, bdd_format_formula(d, - automata->state_condition(s))); + auto aut = std::static_pointer_cast (aut_); + assert(aut); + escape_str(os_, bdd_format_formula(d, aut->state_condition(s))); os_ << "\","; for (si->first(); !si->done(); si->next()) @@ -69,7 +68,7 @@ namespace spot public tgba_reachable_iterator_breadth_first { public: - kripke_printer_renumbered(const kripke* a, std::ostream& os) + kripke_printer_renumbered(const const_kripke_ptr& a, std::ostream& os) : tgba_reachable_iterator_breadth_first(a), os_(os), notfirst(false) { @@ -90,10 +89,10 @@ namespace spot const bdd_dict_ptr d = aut_->get_dict(); os_ << 'S' << in_s << ", \""; - const kripke* automata = down_cast(aut_); - assert(automata); + auto aut = std::static_pointer_cast(aut_); + assert(aut); escape_str(os_, bdd_format_formula(d, - automata->state_condition(s))); + aut->state_condition(s))); os_ << "\","; } @@ -119,7 +118,7 @@ namespace spot } std::ostream& - kripke_save_reachable(std::ostream& os, const kripke* k) + kripke_save_reachable(std::ostream& os, const const_kripke_ptr& k) { kripke_printer p(k, os); p.run(); @@ -127,7 +126,7 @@ namespace spot } std::ostream& - kripke_save_reachable_renumbered(std::ostream& os, const kripke* k) + kripke_save_reachable_renumbered(std::ostream& os, const const_kripke_ptr& k) { kripke_printer_renumbered p(k, os); p.run(); diff --git a/src/kripke/kripkeprint.hh b/src/kripke/kripkeprint.hh index 4f96bb422..a9f401e96 100644 --- a/src/kripke/kripkeprint.hh +++ b/src/kripke/kripkeprint.hh @@ -1,5 +1,5 @@ // -*- coding: utf-8 -*- -// Copyright (C) 2011, 2013 Laboratoire de Recherche et Developpement +// Copyright (C) 2011, 2013, 2014 Laboratoire de Recherche et Developpement // de l'Epita (LRDE) // // This file is part of Spot, a model checking library. @@ -23,12 +23,11 @@ # include "misc/common.hh" # include +# include "kripke.hh" namespace spot { - class kripke; - /// \ingroup tgba_io /// \brief Save the reachable part of Kripke structure in text format. /// @@ -39,7 +38,7 @@ namespace spot /// kripke_save_reachable_renumbered() for large output. /// SPOT_API std::ostream& - kripke_save_reachable(std::ostream& os, const kripke* k); + kripke_save_reachable(std::ostream& os, const const_kripke_ptr& k); /// \ingroup tgba_io /// \brief Save the reachable part of Kripke structure in text format. @@ -50,7 +49,7 @@ namespace spot /// the state name is lost. /// SPOT_API std::ostream& - kripke_save_reachable_renumbered(std::ostream& os, const kripke* k); + kripke_save_reachable_renumbered(std::ostream& os, const const_kripke_ptr& k); } // End namespace spot diff --git a/src/kripkeparse/kripkeparse.yy b/src/kripkeparse/kripkeparse.yy index ae2436ab4..4d9eed10c 100644 --- a/src/kripkeparse/kripkeparse.yy +++ b/src/kripkeparse/kripkeparse.yy @@ -41,7 +41,7 @@ typedef std::map formula_cache; %parse-param {spot::kripke_parse_error_list& error_list} %parse-param {spot::ltl::environment& parse_environment} -%parse-param {spot::kripke_explicit*& result} +%parse-param {spot::kripke_explicit_ptr& result} %parse-param {formula_cache& fcache} %union @@ -195,10 +195,10 @@ kripkeyy::parser::error(const location_type& location, namespace spot { - kripke_explicit* + kripke_explicit_ptr kripke_parse(const std::string& name, kripke_parse_error_list& error_list, - bdd_dict_ptr dict, + const bdd_dict_ptr& dict, environment& env, bool debug) { @@ -210,7 +210,7 @@ namespace spot return 0; } formula_cache fcache; - kripke_explicit* result = new kripke_explicit(dict); + auto result = make_kripke_explicit(dict); kripkeyy::parser parser(error_list, env, result, fcache); parser.set_debug_level(debug); parser.parse(); diff --git a/src/kripkeparse/public.hh b/src/kripkeparse/public.hh index fa8474ac0..1b6ea340f 100644 --- a/src/kripkeparse/public.hh +++ b/src/kripkeparse/public.hh @@ -1,5 +1,6 @@ -// Copyright (C) 2011, 2013 Laboratoire de Recherche et Developpement -// de l'Epita (LRDE) +// -*- coding: utf-8 -*_ +// Copyright (C) 2011, 2013, 2014 Laboratoire de Recherche et +// Developpement de l'Epita (LRDE) // // This file is part of Spot, a model checking library. // @@ -38,10 +39,10 @@ namespace spot - SPOT_API kripke_explicit* + SPOT_API kripke_explicit_ptr kripke_parse(const std::string& name, kripke_parse_error_list& error_list, - bdd_dict_ptr dict, + const bdd_dict_ptr& dict, ltl::environment& env = ltl::default_environment::instance(), bool debug = false); diff --git a/src/kripketest/parse_print_test.cc b/src/kripketest/parse_print_test.cc index 905b90cbf..5530bd51f 100644 --- a/src/kripketest/parse_print_test.cc +++ b/src/kripketest/parse_print_test.cc @@ -29,17 +29,18 @@ int main(int argc, char** argv) int return_value = 0; kripke_parse_error_list pel; - kripke_explicit* k = kripke_parse(argv[1], pel, make_bdd_dict()); - if (!pel.empty()) { - format_kripke_parse_errors(std::cerr, argv[1], pel); - return_value = 1; + auto k = kripke_parse(argv[1], pel, make_bdd_dict()); + if (!pel.empty()) + { + format_kripke_parse_errors(std::cerr, argv[1], pel); + return_value = 1; + } + + if (!return_value) + kripke_save_reachable(std::cout, k); } - if (!return_value) - kripke_save_reachable(std::cout, k); - - delete k; assert(ltl::atomic_prop::instance_count() == 0); assert(ltl::unop::instance_count() == 0); assert(ltl::binop::instance_count() == 0); diff --git a/src/ltlvisit/apcollect.cc b/src/ltlvisit/apcollect.cc index c0ce810bc..87cb44c74 100644 --- a/src/ltlvisit/apcollect.cc +++ b/src/ltlvisit/apcollect.cc @@ -72,7 +72,7 @@ namespace spot } bdd - atomic_prop_collect_as_bdd(const formula* f, const tgba* a) + atomic_prop_collect_as_bdd(const formula* f, const_tgba_ptr a) { spot::ltl::atomic_prop_set aps; atomic_prop_collect(f, &aps); diff --git a/src/ltlvisit/apcollect.hh b/src/ltlvisit/apcollect.hh index 382f203ea..6fac7d6cd 100644 --- a/src/ltlvisit/apcollect.hh +++ b/src/ltlvisit/apcollect.hh @@ -26,11 +26,10 @@ #include "ltlast/atomic_prop.hh" #include #include "bdd.h" +#include "tgba/fwd.hh" namespace spot { - class tgba; - namespace ltl { /// \addtogroup ltl_misc @@ -65,7 +64,7 @@ namespace spot /// \param a that automaton that should register the BDD variables used. /// \return A conjunction the atomic propositions. SPOT_API bdd - atomic_prop_collect_as_bdd(const formula* f, const tgba* a); + atomic_prop_collect_as_bdd(const formula* f, const_tgba_ptr a); /// @} } diff --git a/src/ltlvisit/contain.cc b/src/ltlvisit/contain.cc index 81e49cb9b..13ce4529c 100644 --- a/src/ltlvisit/contain.cc +++ b/src/ltlvisit/contain.cc @@ -56,7 +56,6 @@ namespace spot while (!translated_.empty()) { trans_map::iterator i = translated_.begin(); - delete i->second.translation; const formula* f = i->first; translated_.erase(i); f->destroy(); @@ -70,9 +69,8 @@ namespace spot if (i != l->incompatible.end()) return i->second; - const tgba* p = new tgba_product(l->translation, g->translation); - emptiness_check* ec = couvreur99(p); - emptiness_check_result* ecr = ec->check(); + auto ec = couvreur99(product(l->translation, g->translation)); + auto ecr = ec->check(); if (!ecr) { l->incompatible[g] = true; @@ -85,7 +83,6 @@ namespace spot delete ecr; } delete ec; - delete p; return !ecr; } diff --git a/src/ltlvisit/contain.hh b/src/ltlvisit/contain.hh index 006d9e8ea..d21d20010 100644 --- a/src/ltlvisit/contain.hh +++ b/src/ltlvisit/contain.hh @@ -37,7 +37,7 @@ namespace spot { struct record_ { - const tgba* translation; + const_tgba_ptr translation; typedef std::map incomp_map; incomp_map incompatible; }; diff --git a/src/neverparse/neverclaimparse.yy b/src/neverparse/neverclaimparse.yy index ac5dd958e..31f6d93b9 100644 --- a/src/neverparse/neverclaimparse.yy +++ b/src/neverparse/neverclaimparse.yy @@ -46,7 +46,7 @@ %parse-param {spot::neverclaim_parse_error_list& error_list} %parse-param {spot::ltl::environment& parse_environment} -%parse-param {spot::tgba_digraph*& result} +%parse-param {spot::tgba_digraph_ptr& result} %parse-param {named_tgba_t*& namer} %parse-param {formula_cache& fcache} %union @@ -286,7 +286,7 @@ neverclaimyy::parser::error(const location_type& location, namespace spot { - tgba_digraph* + tgba_digraph_ptr neverclaim_parse(const std::string& name, neverclaim_parse_error_list& error_list, bdd_dict_ptr dict, @@ -300,7 +300,7 @@ namespace spot return 0; } formula_cache fcache; - tgba_digraph* result = new tgba_digraph(dict); + tgba_digraph_ptr result = make_tgba_digraph(dict); auto namer = result->create_namer(); result->set_single_acceptance_set(); result->set_bprop(tgba_digraph::SBA); diff --git a/src/neverparse/public.hh b/src/neverparse/public.hh index e1960485d..ae79ffc65 100644 --- a/src/neverparse/public.hh +++ b/src/neverparse/public.hh @@ -55,7 +55,7 @@ namespace spot /// was parsed succesfully, check \a error_list for emptiness. /// /// \warning This function is not reentrant. - SPOT_API tgba_digraph* + SPOT_API tgba_digraph_ptr neverclaim_parse(const std::string& filename, neverclaim_parse_error_list& error_list, diff --git a/src/priv/accmap.hh b/src/priv/accmap.hh index fa89849bb..29e1f2ece 100644 --- a/src/priv/accmap.hh +++ b/src/priv/accmap.hh @@ -32,11 +32,11 @@ namespace spot { protected: bdd_dict_ptr dict_; - tgba_digraph* aut_; + tgba_digraph_ptr aut_; ltl::environment& env_; bdd neg_; - acc_mapper_common(tgba_digraph *aut, ltl::environment& env) + acc_mapper_common(const tgba_digraph_ptr& aut, ltl::environment& env) : dict_(aut->get_dict()), aut_(aut), env_(env), neg_(bddtrue) { } @@ -59,7 +59,7 @@ namespace spot std::unordered_map map_; public: - acc_mapper_string(tgba_digraph *aut, + acc_mapper_string(const tgba_digraph_ptr& aut, ltl::environment& env = ltl::default_environment::instance()) : acc_mapper_common(aut, env) @@ -102,7 +102,7 @@ namespace spot std::map map_; public: - acc_mapper_consecutive_int(tgba_digraph *aut, + acc_mapper_consecutive_int(const tgba_digraph_ptr& aut, unsigned count, ltl::environment& env = ltl::default_environment::instance()) @@ -144,7 +144,7 @@ namespace spot std::map map_; public: - acc_mapper_int(tgba_digraph *aut, + acc_mapper_int(const tgba_digraph_ptr& aut, unsigned count, ltl::environment& env = ltl::default_environment::instance()) diff --git a/src/priv/countstates.cc b/src/priv/countstates.cc index 587800731..0a2f4dec4 100644 --- a/src/priv/countstates.cc +++ b/src/priv/countstates.cc @@ -23,9 +23,9 @@ namespace spot { - unsigned count_states(const tgba* a) + unsigned count_states(const const_tgba_ptr& a) { - if (auto b = dynamic_cast(a)) + if (auto b = std::dynamic_pointer_cast(a)) return b->num_states(); return stats_reachable(a).states; } diff --git a/src/priv/countstates.hh b/src/priv/countstates.hh index 9c0c23a10..ec87b9618 100644 --- a/src/priv/countstates.hh +++ b/src/priv/countstates.hh @@ -20,16 +20,15 @@ #ifndef SPOT_PRIV_COUNTSTATES_HH # define SPOT_PRIV_COUNTSTATES_HH +#include "tgba/fwd.hh" #include "misc/common.hh" namespace spot { - class tgba; - unsigned count_states(const tgba* a); + unsigned count_states(const const_tgba_ptr& a); - class tgba_digraph; // Call a->num_states() directly! - unsigned count_states(const tgba_digraph* a) SPOT_DEPRECATED; + unsigned count_states(const_tgba_digraph_ptr a) SPOT_DEPRECATED; } #endif // SPOT_PRIV_COUNTSTATES_HH diff --git a/src/saba/saba.hh b/src/saba/saba.hh index a6882279e..7a9f235e8 100644 --- a/src/saba/saba.hh +++ b/src/saba/saba.hh @@ -1,5 +1,5 @@ // -*- coding: utf-8 -*- -// Copyright (C) 2009, 2010, 2013 Laboratoire de Recherche et +// Copyright (C) 2009, 2010, 2013, 2014 Laboratoire de Recherche et // Développement de l'Epita (LRDE). // // This file is part of Spot, a model checking library. @@ -109,6 +109,9 @@ namespace spot mutable int num_acc_; }; + typedef std::shared_ptr saba_ptr; + typedef std::shared_ptr const_saba_ptr; + } // end namespace spot. diff --git a/src/saba/sabacomplementtgba.cc b/src/saba/sabacomplementtgba.cc index 3dba478c6..7065497f9 100644 --- a/src/saba/sabacomplementtgba.cc +++ b/src/saba/sabacomplementtgba.cc @@ -23,6 +23,7 @@ #include "bdd.h" #include #include +#include "tgba/tgba.hh" #include "misc/hash.hh" #include "misc/bddlt.hh" #include "tgbaalgos/degen.hh" @@ -151,7 +152,8 @@ namespace spot typedef std::map bdd_list_t; - saba_complement_tgba_succ_iterator(const tgba_digraph* automaton, + saba_complement_tgba_succ_iterator(const const_tgba_digraph_ptr& + automaton, bdd the_acceptance_cond, const saba_state_complement_tgba* origin); @@ -168,7 +170,7 @@ namespace spot void state_conjunction(); void delete_condition_list(); - const tgba_digraph* automaton_; + const_tgba_digraph_ptr automaton_; bdd the_acceptance_cond_; const saba_state_complement_tgba* origin_; bdd_list_t condition_list_; @@ -178,7 +180,7 @@ namespace spot }; saba_complement_tgba_succ_iterator:: - saba_complement_tgba_succ_iterator(const tgba_digraph* automaton, + saba_complement_tgba_succ_iterator(const const_tgba_digraph_ptr& automaton, bdd the_acceptance_cond, const saba_state_complement_tgba* origin) : automaton_(automaton), the_acceptance_cond_(the_acceptance_cond), @@ -366,7 +368,7 @@ namespace spot } // end namespace anonymous. - saba_complement_tgba::saba_complement_tgba(const tgba* a) + saba_complement_tgba::saba_complement_tgba(const const_tgba_ptr& a) : automaton_(degeneralize(a)) { get_dict()->register_all_variables_of(automaton_, this); @@ -379,7 +381,6 @@ namespace spot saba_complement_tgba::~saba_complement_tgba() { get_dict()->unregister_all_my_variables(this); - delete automaton_; } saba_state* diff --git a/src/saba/sabacomplementtgba.hh b/src/saba/sabacomplementtgba.hh index f622eca30..27c750cf4 100644 --- a/src/saba/sabacomplementtgba.hh +++ b/src/saba/sabacomplementtgba.hh @@ -19,13 +19,11 @@ #ifndef SPOT_SABA_SABACOMPLEMENTTGBA_HH #define SPOT_SABA_SABACOMPLEMENTTGBA_HH -#include +#include "tgba/fwd.hh" #include "saba.hh" namespace spot { - class tgba_digraph; - /// \ingroup saba /// \brief Complement a TGBA and produce a SABA. /// @@ -55,7 +53,7 @@ namespace spot class SPOT_API saba_complement_tgba : public saba { public: - saba_complement_tgba(const tgba* a); + saba_complement_tgba(const const_tgba_ptr& a); virtual ~saba_complement_tgba(); // tgba interface @@ -67,11 +65,20 @@ namespace spot virtual std::string format_state(const saba_state* state) const; virtual bdd all_acceptance_conditions() const; private: - const tgba_digraph* automaton_; + const_tgba_digraph_ptr automaton_; bdd the_acceptance_cond_; unsigned nb_states_; }; // end class tgba_saba_complement. + typedef std::shared_ptr saba_complement_tgba_ptr; + typedef std::shared_ptr + const_saba_complement_tgba_ptr; + inline saba_complement_tgba_ptr make_saba_complement(const const_tgba_ptr& a) + { + return std::make_shared(a); + } + + } // end namespace spot. diff --git a/src/sabaalgos/sabadotty.cc b/src/sabaalgos/sabadotty.cc index 7f3bf1fc7..1222c1825 100644 --- a/src/sabaalgos/sabadotty.cc +++ b/src/sabaalgos/sabadotty.cc @@ -18,7 +18,6 @@ // along with this program. If not, see . #include -#include "saba/saba.hh" #include "sabadotty.hh" #include "tgba/bddprint.hh" #include "sabareachiter.hh" @@ -31,7 +30,7 @@ namespace spot class saba_dotty_bfs : public saba_reachable_iterator_breadth_first { public: - saba_dotty_bfs(std::ostream& os, const saba* a) + saba_dotty_bfs(std::ostream& os, const const_saba_ptr& a) : saba_reachable_iterator_breadth_first(a), os_(os) { } @@ -96,7 +95,7 @@ namespace spot } std::ostream& - saba_dotty_reachable(std::ostream& os, const saba* g) + saba_dotty_reachable(std::ostream& os, const const_saba_ptr& g) { saba_dotty_bfs d(os, g); d.run(); diff --git a/src/sabaalgos/sabadotty.hh b/src/sabaalgos/sabadotty.hh index 559d41f15..55180d866 100644 --- a/src/sabaalgos/sabadotty.hh +++ b/src/sabaalgos/sabadotty.hh @@ -1,6 +1,6 @@ // -*- coding: utf-8 -*- -// Copyright (C) 2009, 2013 Laboratoire de Recherche et Développement -// de l'Epita (LRDE). +// Copyright (C) 2009, 2013, 2014 Laboratoire de Recherche et +// Développement de l'Epita (LRDE). // // This file is part of Spot, a model checking library. // @@ -22,16 +22,15 @@ #include "misc/common.hh" #include +#include "saba/saba.hh" namespace spot { - class saba; - /// \ingroup saba_io /// \brief Print reachable states in dot format. SPOT_API std::ostream& saba_dotty_reachable(std::ostream& os, - const saba* g); + const const_saba_ptr& g); } #endif // SPOT_SABAALGOS_SABADOTTY_HH diff --git a/src/sabaalgos/sabareachiter.cc b/src/sabaalgos/sabareachiter.cc index 7274b0861..4682ce1ab 100644 --- a/src/sabaalgos/sabareachiter.cc +++ b/src/sabaalgos/sabareachiter.cc @@ -1,4 +1,5 @@ -// Copyright (C) 2009 Laboratoire de Recherche et Développement +// -*- coding: utf-8 -*- +// Copyright (C) 2009, 2014 Laboratoire de Recherche et Développement // de l'Epita (LRDE). // // This file is part of Spot, a model checking library. @@ -24,7 +25,7 @@ namespace spot // saba_reachable_iterator ////////////////////////////////////////////////////////////////////// - saba_reachable_iterator::saba_reachable_iterator(const saba* a) + saba_reachable_iterator::saba_reachable_iterator(const const_saba_ptr& a) : automata_(a) { } @@ -137,7 +138,7 @@ namespace spot ////////////////////////////////////////////////////////////////////// saba_reachable_iterator_depth_first:: - saba_reachable_iterator_depth_first(const saba* a) + saba_reachable_iterator_depth_first(const const_saba_ptr& a) : saba_reachable_iterator(a) { } @@ -162,7 +163,7 @@ namespace spot ////////////////////////////////////////////////////////////////////// saba_reachable_iterator_breadth_first:: - saba_reachable_iterator_breadth_first(const saba* a) + saba_reachable_iterator_breadth_first(const const_saba_ptr& a) : saba_reachable_iterator(a) { } diff --git a/src/sabaalgos/sabareachiter.hh b/src/sabaalgos/sabareachiter.hh index f2674d3c0..d80b79b93 100644 --- a/src/sabaalgos/sabareachiter.hh +++ b/src/sabaalgos/sabareachiter.hh @@ -1,5 +1,5 @@ // -*- coding: utf-8 -*- -// Copyright (C) 2009, 2010, 2013 Laboratoire de Recherche et +// Copyright (C) 2009, 2010, 2013, 2014 Laboratoire de Recherche et // Développement de l'Epita (LRDE). // // This file is part of Spot, a model checking library. @@ -32,7 +32,7 @@ namespace spot class SPOT_API saba_reachable_iterator { public: - saba_reachable_iterator(const saba* a); + saba_reachable_iterator(const const_saba_ptr& a); virtual ~saba_reachable_iterator(); /// \brief Iterate over all reachable states of a spot::saba. @@ -106,7 +106,7 @@ namespace spot const saba_succ_iterator* si); protected: - const saba* automata_; ///< The spot::saba to explore. + const_saba_ptr automata_; ///< The spot::saba to explore. typedef std::unordered_mapdestroy(); } diff --git a/src/ta/ta.hh b/src/ta/ta.hh index a8b6dde18..75e1783b9 100644 --- a/src/ta/ta.hh +++ b/src/ta/ta.hh @@ -175,6 +175,9 @@ namespace spot }; + typedef std::shared_ptr ta_ptr; + typedef std::shared_ptr const_ta_ptr; + /// \ingroup ta_essentials /// \brief Iterate over the successors of a state. /// diff --git a/src/ta/taexplicit.cc b/src/ta/taexplicit.cc index 661b2e697..06e7262f8 100644 --- a/src/ta/taexplicit.cc +++ b/src/ta/taexplicit.cc @@ -351,13 +351,12 @@ namespace spot // ta_explicit - ta_explicit::ta_explicit(const tgba* tgba, bdd all_acceptance_conditions, - state_ta_explicit* artificial_initial_state, - bool own_tgba) : + ta_explicit::ta_explicit(const const_tgba_ptr& tgba, + bdd all_acceptance_conditions, + state_ta_explicit* artificial_initial_state): tgba_(tgba), all_acceptance_conditions_(all_acceptance_conditions), - artificial_initial_state_(artificial_initial_state), - own_tgba_(own_tgba) + artificial_initial_state_(artificial_initial_state) { get_dict()->register_all_variables_of(&tgba_, this); if (artificial_initial_state != 0) @@ -379,8 +378,6 @@ namespace spot delete s; } get_dict()->unregister_all_my_variables(this); - if (own_tgba_) - delete tgba_; } state_ta_explicit* @@ -496,7 +493,7 @@ namespace spot return tgba_->get_dict(); } - const tgba* + const_tgba_ptr ta_explicit::get_tgba() const { return tgba_; diff --git a/src/ta/taexplicit.hh b/src/ta/taexplicit.hh index 421b44e85..4810192f9 100644 --- a/src/ta/taexplicit.hh +++ b/src/ta/taexplicit.hh @@ -41,11 +41,10 @@ namespace spot class SPOT_API ta_explicit : public ta { public: - ta_explicit(const tgba* tgba, bdd all_acceptance_conditions, - state_ta_explicit* artificial_initial_state = 0, - bool own_tgba = false); + ta_explicit(const const_tgba_ptr& tgba, bdd all_acceptance_conditions, + state_ta_explicit* artificial_initial_state = 0); - const tgba* + const_tgba_ptr get_tgba() const; state_ta_explicit* @@ -135,12 +134,11 @@ namespace spot ta_explicit(const ta_explicit& other) SPOT_DELETED; ta_explicit& operator=(const ta_explicit& other) SPOT_DELETED; - const tgba* tgba_; + const_tgba_ptr tgba_; bdd all_acceptance_conditions_; state_ta_explicit* artificial_initial_state_; ta::states_set_t states_set_; ta::states_set_t initial_states_set_; - bool own_tgba_; }; /// states used by spot::ta_explicit. @@ -265,6 +263,19 @@ namespace spot state_ta_explicit::transitions::const_iterator i_; }; + typedef std::shared_ptr ta_explicit_ptr; + typedef std::shared_ptr const_ta_explicit_ptr; + + inline ta_explicit_ptr make_ta_explicit(const const_tgba_ptr& tgba, + bdd all_acceptance_conditions, + state_ta_explicit* + artificial_initial_state = 0) + { + return std::make_shared(tgba, + all_acceptance_conditions, + artificial_initial_state); + } + } #endif // SPOT_TA_TAEXPLICIT_HH diff --git a/src/ta/taproduct.cc b/src/ta/taproduct.cc index 4dcc9411b..97c7bb763 100644 --- a/src/ta/taproduct.cc +++ b/src/ta/taproduct.cc @@ -242,15 +242,15 @@ namespace spot // ta_product - ta_product::ta_product(const ta* testing_automata, - const kripke* kripke_structure) : - dict_(testing_automata->get_dict()), ta_(testing_automata), kripke_( - kripke_structure) + ta_product::ta_product(const const_ta_ptr& testing_automata, + const const_kripke_ptr& kripke_structure): + dict_(testing_automata->get_dict()), + ta_(testing_automata), + kripke_(kripke_structure) { assert(dict_ == kripke_structure->get_dict()); - dict_->register_all_variables_of(&ta_, this); - dict_->register_all_variables_of(&kripke_, this); - + dict_->register_all_variables_of(ta_, this); + dict_->register_all_variables_of(kripke_, this); } ta_product::~ta_product() @@ -314,7 +314,7 @@ namespace spot const state_ta_product* stp = down_cast (s); assert(s); - return new ta_succ_iterator_product(stp, ta_, kripke_); + return new ta_succ_iterator_product(stp, ta_.get(), kripke_.get()); } @@ -323,8 +323,9 @@ namespace spot { const state_ta_product* stp = down_cast (s); assert(s); - return new ta_succ_iterator_product_by_changeset(stp, ta_, kripke_, - changeset); + return new ta_succ_iterator_product_by_changeset(stp, + ta_.get(), kripke_.get(), + changeset); } diff --git a/src/ta/taproduct.hh b/src/ta/taproduct.hh index fc5f9cad7..70dc39bc2 100644 --- a/src/ta/taproduct.hh +++ b/src/ta/taproduct.hh @@ -136,7 +136,8 @@ namespace spot /// \brief Constructor. /// \param testing_automaton The TA component in the product. /// \param kripke_structure The Kripke component in the product. - ta_product(const ta* testing_automaton, const kripke* kripke_structure); + ta_product(const const_ta_ptr& testing_automaton, + const const_kripke_ptr& kripke_structure); virtual ~ta_product(); @@ -179,13 +180,13 @@ namespace spot virtual void free_state(const spot::state* s) const; - const ta* + const const_ta_ptr& get_ta() const { return ta_; } - const kripke* + const const_kripke_ptr& get_kripke() const { return kripke_; @@ -193,8 +194,8 @@ namespace spot private: bdd_dict_ptr dict_; - const ta* ta_; - const kripke* kripke_; + const_ta_ptr ta_; + const_kripke_ptr kripke_; // Disallow copy. ta_product(const ta_product&) SPOT_DELETED; @@ -202,6 +203,14 @@ namespace spot }; + typedef std::shared_ptr ta_product_ptr; + typedef std::shared_ptr const_ta_product_ptr; + inline ta_product_ptr product(const const_ta_ptr& testing_automaton, + const const_kripke_ptr& kripke_structure) + { + return std::make_shared(testing_automaton, kripke_structure); + } + class SPOT_API ta_succ_iterator_product_by_changeset : public ta_succ_iterator_product { diff --git a/src/ta/tgta.hh b/src/ta/tgta.hh index 20446a28d..a7bcb4b95 100644 --- a/src/ta/tgta.hh +++ b/src/ta/tgta.hh @@ -1,6 +1,6 @@ // -*- coding: utf-8 -*- -// Copyright (C) 2010, 2011, 2012, 2013 Laboratoire de Recherche et -// Développement de l'Epita (LRDE). +// Copyright (C) 2010, 2011, 2012, 2013, 2014 Laboratoire de Recherche +// et Développement de l'Epita (LRDE). // // This file is part of Spot, a model checking library. // @@ -78,9 +78,10 @@ namespace spot /// virtual tgba_succ_iterator* succ_iter_by_changeset(const spot::state* s, bdd change_set) const =0; - }; + typedef std::shared_ptr tgta_ptr; + typedef std::shared_ptr const_tgta_ptr; } #endif // SPOT_TA_TGTA_HH diff --git a/src/ta/tgtaexplicit.cc b/src/ta/tgtaexplicit.cc index 84a2371dd..e02ccc788 100644 --- a/src/ta/tgtaexplicit.cc +++ b/src/ta/tgtaexplicit.cc @@ -29,23 +29,24 @@ namespace spot { - tgta_explicit::tgta_explicit(const tgba* tgba, bdd all_acceptance_conditions, - state_ta_explicit* artificial_initial_state, - bool own_tgba) : - ta_(tgba, all_acceptance_conditions, artificial_initial_state, own_tgba) + tgta_explicit::tgta_explicit(const const_tgba_ptr& tgba, + bdd all_acceptance_conditions, + state_ta_explicit* artificial_initial_state) : + ta_(make_ta_explicit(tgba, all_acceptance_conditions, + artificial_initial_state)) { } state* tgta_explicit::get_init_state() const { - return ta_.get_artificial_initial_state(); + return ta_->get_artificial_initial_state(); } tgba_succ_iterator* tgta_explicit::succ_iter(const spot::state* state) const { - return ta_.succ_iter(state); + return ta_->succ_iter(state); } bdd @@ -53,37 +54,37 @@ namespace spot { const state_ta_explicit* s = down_cast(in); assert(s); - return ta_.get_tgba()->support_conditions(s->get_tgba_state()); + return ta_->get_tgba()->support_conditions(s->get_tgba_state()); } bdd_dict_ptr tgta_explicit::get_dict() const { - return ta_.get_dict(); + return ta_->get_dict(); } bdd tgta_explicit::all_acceptance_conditions() const { - return ta_.all_acceptance_conditions(); + return ta_->all_acceptance_conditions(); } bdd tgta_explicit::neg_acceptance_conditions() const { - return ta_.get_tgba()->neg_acceptance_conditions(); + return ta_->get_tgba()->neg_acceptance_conditions(); } std::string tgta_explicit::format_state(const spot::state* s) const { - return ta_.format_state(s); + return ta_->format_state(s); } spot::tgba_succ_iterator* tgta_explicit::succ_iter_by_changeset(const spot::state* s, bdd chngset) const { - return ta_.succ_iter(s, chngset); + return ta_->succ_iter(s, chngset); } } diff --git a/src/ta/tgtaexplicit.hh b/src/ta/tgtaexplicit.hh index 7c1c40f71..fe37c9c76 100644 --- a/src/ta/tgtaexplicit.hh +++ b/src/ta/tgtaexplicit.hh @@ -38,9 +38,9 @@ namespace spot class SPOT_API tgta_explicit : public tgta { public: - tgta_explicit(const tgba* tgba, bdd all_acceptance_conditions, - state_ta_explicit* artificial_initial_state, - bool own_tgba = false); + tgta_explicit(const const_tgba_ptr& tgba, + bdd all_acceptance_conditions, + state_ta_explicit* artificial_initial_state); // tgba interface virtual spot::state* get_init_state() const; @@ -51,8 +51,8 @@ namespace spot virtual bdd_dict_ptr get_dict() const; - const ta_explicit* get_ta() const { return &ta_; } - ta_explicit* get_ta() { return &ta_; } + const_ta_explicit_ptr get_ta() const { return ta_; } + ta_explicit_ptr get_ta() { return ta_; } virtual bdd all_acceptance_conditions() const; virtual bdd neg_acceptance_conditions() const; @@ -64,9 +64,21 @@ namespace spot protected: virtual bdd compute_support_conditions(const spot::state* state) const; - ta_explicit ta_; + ta_explicit_ptr ta_; }; + typedef std::shared_ptr tgta_explicit_ptr; + typedef std::shared_ptr const_tgta_explicit_ptr; + + inline tgta_explicit_ptr make_tgta_explicit(const const_tgba_ptr& tgba, + bdd all_acceptance_conditions, + state_ta_explicit* + artificial_initial_state = 0) + { + return std::make_shared(tgba, + all_acceptance_conditions, + artificial_initial_state); + } } #endif // SPOT_TA_TGTAEXPLICIT_HH diff --git a/src/ta/tgtaproduct.cc b/src/ta/tgtaproduct.cc index 65f46f859..dab27a394 100644 --- a/src/ta/tgtaproduct.cc +++ b/src/ta/tgtaproduct.cc @@ -43,7 +43,8 @@ namespace spot //////////////////////////////////////////////////////////// // tgta_product - tgta_product::tgta_product(const kripke* left, const tgta* right) : + tgta_product::tgta_product(const const_kripke_ptr& left, + const const_tgta_ptr& right): tgba_product(left, right) { } @@ -64,15 +65,16 @@ namespace spot fixed_size_pool* p = const_cast (&pool_); - return new tgta_succ_iterator_product(s, - down_cast(left_), - down_cast(right_), p); + auto l = std::static_pointer_cast(left_); + auto r = std::static_pointer_cast(right_); + return new tgta_succ_iterator_product(s, l, r, p); } //////////////////////////////////////////////////////////// // tgbtgta_succ_iterator_product tgta_succ_iterator_product::tgta_succ_iterator_product( - const state_product* s, const kripke* k, const tgta* t, + const state_product* s, + const const_kripke_ptr& k, const const_tgta_ptr& t, fixed_size_pool* pool) : source_(s), tgta_(t), kripke_(k), pool_(pool) { diff --git a/src/ta/tgtaproduct.hh b/src/ta/tgtaproduct.hh index 5f52b559f..89225027a 100644 --- a/src/ta/tgtaproduct.hh +++ b/src/ta/tgtaproduct.hh @@ -33,7 +33,8 @@ namespace spot class SPOT_API tgta_product : public tgba_product { public: - tgta_product(const kripke* left, const tgta* right); + tgta_product(const const_kripke_ptr& left, + const const_tgta_ptr& right); virtual state* get_init_state() const; @@ -42,12 +43,20 @@ namespace spot succ_iter(const state* local_state) const; }; + inline tgba_ptr product(const const_kripke_ptr& left, + const const_tgta_ptr& right) + { + return std::make_shared(left, right); + } + /// \brief Iterate over the successors of a product computed on the fly. class SPOT_API tgta_succ_iterator_product : public tgba_succ_iterator { public: - tgta_succ_iterator_product(const state_product* s, const kripke* k, - const tgta* tgta, fixed_size_pool* pool); + tgta_succ_iterator_product(const state_product* s, + const const_kripke_ptr& k, + const const_tgta_ptr& tgta, + fixed_size_pool* pool); virtual ~tgta_succ_iterator_product(); @@ -80,8 +89,8 @@ namespace spot protected: const state_product* source_; - const tgta* tgta_; - const kripke* kripke_; + const_tgta_ptr tgta_; + const_kripke_ptr kripke_; fixed_size_pool* pool_; tgba_succ_iterator* tgta_succ_it_; tgba_succ_iterator* kripke_succ_it_; diff --git a/src/taalgos/dotty.cc b/src/taalgos/dotty.cc index 7010db873..3044325e1 100644 --- a/src/taalgos/dotty.cc +++ b/src/taalgos/dotty.cc @@ -31,7 +31,7 @@ namespace spot class dotty_bfs : public ta_reachable_iterator_breadth_first { public: - dotty_bfs(std::ostream& os, const ta* a) : + dotty_bfs(std::ostream& os, const const_ta_ptr& a) : ta_reachable_iterator_breadth_first(a), os_(os) { } @@ -123,7 +123,7 @@ namespace spot } std::ostream& - dotty_reachable(std::ostream& os, const ta* a) + dotty_reachable(std::ostream& os, const const_ta_ptr& a) { dotty_bfs d(os, a); d.run(); diff --git a/src/taalgos/dotty.hh b/src/taalgos/dotty.hh index 8629239e8..c8ef3f7f5 100644 --- a/src/taalgos/dotty.hh +++ b/src/taalgos/dotty.hh @@ -1,5 +1,5 @@ // -*- coding: utf-8 -*- -// Copyright (C) 2010, 2013 Laboratoire de Recherche et Développement +// Copyright (C) 2010, 2013, 2014 Laboratoire de Recherche et Développement // de l'Epita (LRDE). // // This file is part of Spot, a model checking library. @@ -25,10 +25,8 @@ namespace spot { - class ta; - SPOT_API std::ostream& - dotty_reachable(std::ostream& os, const ta* a); + dotty_reachable(std::ostream& os, const const_ta_ptr& a); } #endif // SPOT_TAALGOS_DOTTY_HH diff --git a/src/taalgos/emptinessta.cc b/src/taalgos/emptinessta.cc index 7820c749c..bb65d6f3d 100644 --- a/src/taalgos/emptinessta.cc +++ b/src/taalgos/emptinessta.cc @@ -34,7 +34,7 @@ namespace spot { - ta_check::ta_check(const ta_product* a, option_map o) : + ta_check::ta_check(const const_ta_product_ptr& a, option_map o) : a_(a), o_(o) { is_full_2_pass_ = o.get("is_full_2_pass", 0); @@ -89,8 +89,8 @@ namespace spot && (is_full_2_pass_ == disable_second_pass); // Setup depth-first search from initial states. - const ta* ta_ = a_->get_ta(); - const kripke* kripke_ = a_->get_kripke(); + auto& ta_ = a_->get_ta(); + auto& kripke_ = a_->get_kripke(); state* kripke_init_state = kripke_->get_init_state(); bdd kripke_init_state_condition = kripke_->state_condition( kripke_init_state); @@ -383,7 +383,7 @@ namespace spot } bool - ta_check::livelock_detection(const ta_product* t) + ta_check::livelock_detection(const const_ta_product_ptr& t) { // We use five main data in this algorithm: diff --git a/src/taalgos/emptinessta.hh b/src/taalgos/emptinessta.hh index 6db9bb376..121cc6012 100644 --- a/src/taalgos/emptinessta.hh +++ b/src/taalgos/emptinessta.hh @@ -89,7 +89,7 @@ namespace spot typedef std::unordered_map hash_type; public: - ta_check(const ta_product* a, option_map o = option_map()); + ta_check(const const_ta_product_ptr& a, option_map o = option_map()); virtual ~ta_check(); @@ -119,7 +119,7 @@ namespace spot /// Return false if the product automaton accepts no livelock-accepting run, /// otherwise true virtual bool - livelock_detection(const ta_product* t); + livelock_detection(const const_ta_product_ptr& t); /// Print statistics, if any. virtual std::ostream& @@ -141,7 +141,7 @@ namespace spot hash_type& h, int h_livelock_root, std::set liveset_curr); - const ta_product* a_; ///< The automaton. + const_ta_product_ptr a_; ///< The automaton. option_map o_; ///< The options // Force the second pass diff --git a/src/taalgos/minimize.cc b/src/taalgos/minimize.cc index 856469726..352be7513 100644 --- a/src/taalgos/minimize.cc +++ b/src/taalgos/minimize.cc @@ -49,7 +49,9 @@ namespace spot namespace { static std::ostream& - dump_hash_set(const hash_set* hs, const ta* aut, std::ostream& out) + dump_hash_set(const hash_set* hs, + const const_ta_ptr& aut, + std::ostream& out) { out << '{'; const char* sep = ""; @@ -63,7 +65,7 @@ namespace spot } static std::string - format_hash_set(const hash_set* hs, const ta* aut) + format_hash_set(const hash_set* hs, const const_ta_ptr& aut) { std::ostringstream s; dump_hash_set(hs, aut, s); @@ -73,8 +75,8 @@ namespace spot // From the base automaton and the list of sets, build the minimal // automaton static void - build_result(const ta* a, std::list& sets, - tgba_digraph* result_tgba, ta_explicit* result) + build_result(const const_ta_ptr& a, std::list& sets, + tgba_digraph_ptr result_tgba, const ta_explicit_ptr& result) { // For each set, create a state in the tgbaulting automaton. // For a state s, state_num[s] is the number of the state in the minimal @@ -181,7 +183,7 @@ namespace spot } static partition_t - build_partition(const ta* ta_) + build_partition(const const_ta_ptr& ta_) { partition_t cur_run; partition_t next_run; @@ -482,13 +484,12 @@ namespace spot } } - ta* - minimize_ta(const ta* ta_) + ta_explicit_ptr + minimize_ta(const const_ta_ptr& ta_) { - auto tgba = new tgba_digraph(ta_->get_dict()); - auto res = new ta_explicit(tgba, ta_->all_acceptance_conditions(), - 0, /* own_tgba = */ true); + auto tgba = make_tgba_digraph(ta_->get_dict()); + auto res = make_ta_explicit(tgba, ta_->all_acceptance_conditions(), 0); partition_t partition = build_partition(ta_); @@ -503,15 +504,14 @@ namespace spot return res; } - tgta_explicit* - minimize_tgta(const tgta_explicit* tgta_) + tgta_explicit_ptr + minimize_tgta(const const_tgta_explicit_ptr& tgta_) { - auto tgba = new tgba_digraph(tgta_->get_dict()); - auto res = new tgta_explicit(tgba, tgta_->all_acceptance_conditions(), - 0, /* own_tgba = */ true); + auto tgba = make_tgba_digraph(tgta_->get_dict()); + auto res = make_tgta_explicit(tgba, tgta_->all_acceptance_conditions(), 0); - const ta_explicit* ta = tgta_->get_ta(); + auto ta = tgta_->get_ta(); partition_t partition = build_partition(ta); diff --git a/src/taalgos/minimize.hh b/src/taalgos/minimize.hh index 2d9a81814..25e7d29ec 100644 --- a/src/taalgos/minimize.hh +++ b/src/taalgos/minimize.hh @@ -1,6 +1,6 @@ // -*- coding: utf-8 -*- -// Copyright (C) 2009, 2010, 2011, 2012, 2013 Laboratoire de Recherche -// et Développement de l'Epita (LRDE). +// Copyright (C) 2009, 2010, 2011, 2012, 2013, 2014 Laboratoire de +// Recherche et Développement de l'Epita (LRDE). // // This file is part of Spot, a model checking library. // @@ -56,8 +56,8 @@ namespace spot \endverbatim */ /// /// \param ta_ the TA automaton to convert into a simplified TA - SPOT_API ta* - minimize_ta(const ta* ta_); + SPOT_API ta_explicit_ptr + minimize_ta(const const_ta_ptr& ta_); @@ -70,8 +70,8 @@ namespace spot /// the acceptance conditions of the outgoing transitions. /// /// \param tgta_ the TGTA automaton to convert into a simplified TGTA - SPOT_API tgta_explicit* - minimize_tgta(const tgta_explicit* tgta_); + SPOT_API tgta_explicit_ptr + minimize_tgta(const const_tgta_explicit_ptr& tgta_); /// @} } diff --git a/src/taalgos/reachiter.cc b/src/taalgos/reachiter.cc index 256bffbe4..df11d0761 100644 --- a/src/taalgos/reachiter.cc +++ b/src/taalgos/reachiter.cc @@ -1,7 +1,6 @@ // -*- coding: utf-8 -*- -// Copyright (C) 2010, 2012 Laboratoire de Recherche et Développement -// de l Epita (LRDE). -// +// Copyright (C) 2010, 2012, 2014 Laboratoire de Recherche et Développement +// de l'Epita (LRDE). // // This file is part of Spot, a model checking library. // @@ -29,7 +28,7 @@ namespace spot // ta_reachable_iterator ////////////////////////////////////////////////////////////////////// - ta_reachable_iterator::ta_reachable_iterator(const ta* a) : + ta_reachable_iterator::ta_reachable_iterator(const const_ta_ptr& a) : t_automata_(a) { } @@ -139,7 +138,7 @@ namespace spot ////////////////////////////////////////////////////////////////////// ta_reachable_iterator_depth_first::ta_reachable_iterator_depth_first( - const ta* a) : + const const_ta_ptr& a) : ta_reachable_iterator(a) { } @@ -164,7 +163,7 @@ namespace spot ////////////////////////////////////////////////////////////////////// ta_reachable_iterator_breadth_first::ta_reachable_iterator_breadth_first( - const ta* a) : + const const_ta_ptr& a) : ta_reachable_iterator(a) { } diff --git a/src/taalgos/reachiter.hh b/src/taalgos/reachiter.hh index 40c68a2f7..3a0ed7a7d 100644 --- a/src/taalgos/reachiter.hh +++ b/src/taalgos/reachiter.hh @@ -1,6 +1,6 @@ // -*- coding: utf-8 -*- -// Copyright (C) 2010, 2011, 2012, 2013 Laboratoire de Recherche et -// Développement de l'Epita (LRDE). +// Copyright (C) 2010, 2011, 2012, 2013, 2014 Laboratoire de Recherche +// et Développement de l'Epita (LRDE). // // This file is part of Spot, a model checking library. // @@ -32,7 +32,7 @@ namespace spot class SPOT_API ta_reachable_iterator { public: - ta_reachable_iterator(const ta* a); + ta_reachable_iterator(const const_ta_ptr& a); virtual ~ta_reachable_iterator(); @@ -87,7 +87,7 @@ namespace spot protected: - const ta* t_automata_; ///< The spot::ta to explore. + const_ta_ptr t_automata_; ///< The spot::ta to explore. typedef std::unordered_map seen_map; @@ -101,7 +101,7 @@ namespace spot : public ta_reachable_iterator { public: - ta_reachable_iterator_depth_first(const ta* a); + ta_reachable_iterator_depth_first(const const_ta_ptr& a); virtual void add_state(const state* s); @@ -119,7 +119,7 @@ namespace spot : public ta_reachable_iterator { public: - ta_reachable_iterator_breadth_first(const ta* a); + ta_reachable_iterator_breadth_first(const const_ta_ptr& a); virtual void add_state(const state* s); diff --git a/src/taalgos/statessetbuilder.cc b/src/taalgos/statessetbuilder.cc index 7581a13a5..5e1b2c89d 100644 --- a/src/taalgos/statessetbuilder.cc +++ b/src/taalgos/statessetbuilder.cc @@ -1,4 +1,5 @@ -// Copyright (C) 2010 Laboratoire de Recherche et Développement +// -*- coding: utf-8 -*- +// Copyright (C) 2010, 2014 Laboratoire de Recherche et Développement // de l'Epita (LRDE). // // This file is part of Spot, a model checking library. @@ -28,7 +29,7 @@ namespace spot class states_set_builder_bfs : public ta_reachable_iterator_breadth_first { public: - states_set_builder_bfs(const ta* a) : + states_set_builder_bfs(const const_ta_ptr& a) : ta_reachable_iterator_breadth_first(a) { } @@ -58,7 +59,7 @@ namespace spot std::set - get_states_set(const ta* t) + get_states_set(const const_ta_ptr& t) { states_set_builder_bfs d(t); d.run(); diff --git a/src/taalgos/statessetbuilder.hh b/src/taalgos/statessetbuilder.hh index 2bdd215e6..c516a9a07 100644 --- a/src/taalgos/statessetbuilder.hh +++ b/src/taalgos/statessetbuilder.hh @@ -1,6 +1,6 @@ // -*- coding: utf-8 -*- -// Copyright (C) 2010, 2013 Laboratoire de Recherche et Développement -// de l'Epita (LRDE). +// Copyright (C) 2010, 2013, 2014 Laboratoire de Recherche et +// Développement de l'Epita (LRDE). // // This file is part of Spot, a model checking library. // @@ -26,7 +26,7 @@ namespace spot { /// \brief Compute states set for an automaton. - SPOT_API std::set get_states_set(const ta* t); + SPOT_API std::set get_states_set(const const_ta_ptr& t); /// @} } diff --git a/src/taalgos/stats.cc b/src/taalgos/stats.cc index ec576cf59..7e963154d 100644 --- a/src/taalgos/stats.cc +++ b/src/taalgos/stats.cc @@ -1,7 +1,8 @@ -// Copyright (C) 2008 Laboratoire de Recherche et Développement +// -*- coding: utf-8 -*- +// Copyright (C) 2008, 2014 Laboratoire de Recherche et Développement // de l'Epita (LRDE). // Copyright (C) 2004 Laboratoire d'Informatique de Paris 6 (LIP6), -// département Systèmes Répartis Coopératifs (SRC), Université Pierre +// département Systèmes Répartis Coopératifs (SRC), Université Pierre // et Marie Curie. // // This file is part of Spot, a model checking library. @@ -31,7 +32,7 @@ namespace spot class stats_bfs : public ta_reachable_iterator_breadth_first { public: - stats_bfs(const ta* a, ta_statistics& s) : + stats_bfs(const const_ta_ptr a, ta_statistics& s) : ta_reachable_iterator_breadth_first(a), s_(s) { } @@ -66,7 +67,7 @@ namespace spot } ta_statistics - stats_reachable(const ta* t) + stats_reachable(const const_ta_ptr& t) { ta_statistics s = { 0, 0, 0}; diff --git a/src/taalgos/stats.hh b/src/taalgos/stats.hh index 3c19ca3f5..0f2fb387c 100644 --- a/src/taalgos/stats.hh +++ b/src/taalgos/stats.hh @@ -1,5 +1,5 @@ // -*- coding: utf-8 -*- -// Copyright (C) 2011, 2013 Laboratoire de Recherche et Développement +// Copyright (C) 2011, 2013, 2014 Laboratoire de Recherche et Développement // de l'Epita (LRDE). // // This file is part of Spot, a model checking library. @@ -39,7 +39,7 @@ namespace spot }; /// \brief Compute statistics for an automaton. - SPOT_API ta_statistics stats_reachable(const ta* t); + SPOT_API ta_statistics stats_reachable(const const_ta_ptr& t); /// @} } diff --git a/src/taalgos/tgba2ta.cc b/src/taalgos/tgba2ta.cc index 1b970c6d1..5d830c4f7 100644 --- a/src/taalgos/tgba2ta.cc +++ b/src/taalgos/tgba2ta.cc @@ -50,7 +50,7 @@ namespace spot static void transform_to_single_pass_automaton - (ta_explicit* testing_automata, + (const ta_explicit_ptr& testing_automata, state_ta_explicit* artificial_livelock_acc_state = 0) { @@ -148,7 +148,7 @@ namespace spot } static void - compute_livelock_acceptance_states(ta_explicit* testing_automata, + compute_livelock_acceptance_states(const ta_explicit_ptr& testing_automata, bool single_pass_emptiness_check, state_ta_explicit* artificial_livelock_acc_state) @@ -408,14 +408,15 @@ namespace spot artificial_livelock_acc_state); } - ta_explicit* - build_ta(ta_explicit* ta, bdd atomic_propositions_set_, bool degeneralized, + ta_explicit_ptr + build_ta(const ta_explicit_ptr& ta, bdd atomic_propositions_set_, + bool degeneralized, bool single_pass_emptiness_check, bool artificial_livelock_state_mode) { std::stack todo; - const tgba* tgba_ = ta->get_tgba(); + const_tgba_ptr tgba_ = ta->get_tgba(); // build Initial states set: state* tgba_init_state = tgba_->get_init_state(); @@ -540,12 +541,12 @@ namespace spot } } - ta_explicit* - tgba_to_ta(const tgba* tgba_, bdd atomic_propositions_set_, + ta_explicit_ptr + tgba_to_ta(const const_tgba_ptr& tgba_, bdd atomic_propositions_set_, bool degeneralized, bool artificial_initial_state_mode, bool single_pass_emptiness_check, bool artificial_livelock_state_mode) { - ta_explicit* ta; + ta_explicit_ptr ta; state* tgba_init_state = tgba_->get_init_state(); if (artificial_initial_state_mode) @@ -553,18 +554,18 @@ namespace spot state_ta_explicit* artificial_init_state = new state_ta_explicit(tgba_init_state->clone(), bddfalse, true); - ta = new spot::ta_explicit(tgba_, tgba_->all_acceptance_conditions(), - artificial_init_state); + ta = make_ta_explicit(tgba_, tgba_->all_acceptance_conditions(), + artificial_init_state); } else { - ta = new spot::ta_explicit(tgba_, tgba_->all_acceptance_conditions()); + ta = make_ta_explicit(tgba_, tgba_->all_acceptance_conditions()); } tgba_init_state->destroy(); - // build ta automata: + // build ta automaton build_ta(ta, atomic_propositions_set_, degeneralized, - single_pass_emptiness_check, artificial_livelock_state_mode); + single_pass_emptiness_check, artificial_livelock_state_mode); // (degeneralized=true) => TA if (degeneralized) @@ -597,20 +598,20 @@ namespace spot return ta; } - tgta_explicit* - tgba_to_tgta(const tgba* tgba_, bdd atomic_propositions_set_) + tgta_explicit_ptr + tgba_to_tgta(const const_tgba_ptr& tgba_, bdd atomic_propositions_set_) { state* tgba_init_state = tgba_->get_init_state(); - state_ta_explicit* artificial_init_state = new state_ta_explicit( - tgba_init_state->clone(), bddfalse, true); + auto artificial_init_state = new state_ta_explicit(tgba_init_state->clone(), + bddfalse, true); tgba_init_state->destroy(); - tgta_explicit* tgta = new spot::tgta_explicit(tgba_, - tgba_->all_acceptance_conditions(), artificial_init_state); + auto tgta = make_tgta_explicit(tgba_, tgba_->all_acceptance_conditions(), + artificial_init_state); // build a Generalized TA automaton involving a single_pass_emptiness_check // (without an artificial livelock state): - ta_explicit* ta = tgta->get_ta(); + auto ta = tgta->get_ta(); build_ta(ta, atomic_propositions_set_, false, true, false); trace << "***tgba_to_tgbta: POST build_ta***" << std::endl; diff --git a/src/taalgos/tgba2ta.hh b/src/taalgos/tgba2ta.hh index babc69e2b..2b9ee7bcf 100644 --- a/src/taalgos/tgba2ta.hh +++ b/src/taalgos/tgba2ta.hh @@ -1,5 +1,5 @@ // -*- coding: utf-8 -*- -// Copyright (C) 2010, 2012, 2013 Laboratoire de Recherche et +// Copyright (C) 2010, 2012, 2013, 2014 Laboratoire de Recherche et // Développement de l'Epita (LRDE). // // This file is part of Spot, a model checking library. @@ -79,11 +79,12 @@ namespace spot /// /// \return A spot::ta_explicit that recognizes the same language as the /// TGBA \a tgba_to_convert. - SPOT_API ta_explicit* - tgba_to_ta(const tgba* tgba_to_convert, bdd atomic_propositions_set, - bool degeneralized = true, bool artificial_initial_state_mode = true, - bool single_pass_emptiness_check = false, - bool artificial_livelock_state_mode = false); + SPOT_API ta_explicit_ptr + tgba_to_ta(const const_tgba_ptr& tgba_to_convert, bdd atomic_propositions_set, + bool degeneralized = true, + bool artificial_initial_state_mode = true, + bool single_pass_emptiness_check = false, + bool artificial_livelock_state_mode = false); /// \ingroup tgba_ta /// \brief Build a spot::tgta_explicit* (TGTA) from an LTL formula. @@ -94,8 +95,9 @@ namespace spot /// /// \return A spot::tgta_explicit (spot::tgta) that recognizes the same /// language as the TGBA \a tgba_to_convert. - SPOT_API tgta_explicit* - tgba_to_tgta(const tgba* tgba_to_convert, bdd atomic_propositions_set); + SPOT_API tgta_explicit_ptr + tgba_to_tgta(const const_tgba_ptr& tgba_to_convert, + bdd atomic_propositions_set); } diff --git a/src/tgba/Makefile.am b/src/tgba/Makefile.am index 622272c86..959a193d0 100644 --- a/src/tgba/Makefile.am +++ b/src/tgba/Makefile.am @@ -30,6 +30,7 @@ tgba_HEADERS = \ bddprint.hh \ formula2bdd.hh \ futurecondcol.hh \ + fwd.hh \ state.hh \ succiter.hh \ taatgba.hh \ diff --git a/src/tgba/bdddict.cc b/src/tgba/bdddict.cc index 31296137a..61c1abc23 100644 --- a/src/tgba/bdddict.cc +++ b/src/tgba/bdddict.cc @@ -349,27 +349,6 @@ namespace spot priv_->free_anonymous_list_of.erase(me); } - bool - bdd_dict::is_registered_proposition(const ltl::formula* f, const void* by_me) - { - fv_map::iterator fi = var_map.find(f); - if (fi == var_map.end()) - return false; - ref_set& s = bdd_map[fi->second].refs; - return s.find(by_me) != s.end(); - } - - bool - bdd_dict::is_registered_acceptance_variable(const ltl::formula* f, - const void* by_me) - { - fv_map::iterator fi = acc_map.find(f); - if (fi == acc_map.end()) - return false; - ref_set& s = bdd_map[fi->second].refs; - return s.find(by_me) != s.end(); - } - std::ostream& bdd_dict::dump(std::ostream& os) const { diff --git a/src/tgba/bdddict.hh b/src/tgba/bdddict.hh index 60a85a6f1..c67b2aa41 100644 --- a/src/tgba/bdddict.hh +++ b/src/tgba/bdddict.hh @@ -99,8 +99,17 @@ namespace spot /// /// \return The variable number. Use bdd_ithvar() or bdd_nithvar() /// to convert this to a BDD. + /// @{ int register_proposition(const ltl::formula* f, const void* for_me); + template + int register_proposition(const ltl::formula* f, + std::shared_ptr for_me) + { + return register_proposition(f, for_me.get()); + } + /// @} + /// \brief Register BDD variables as atomic propositions. /// /// Register all variables occurring in \a f as atomic propositions @@ -108,8 +117,16 @@ namespace spot /// are already known from the dictionary (i.e., they have already /// been registered by register_proposition() for another /// automaton). + /// @{ void register_propositions(bdd f, const void* for_me); + template + void register_propositions(bdd f, std::shared_ptr for_me) + { + register_propositions(f, for_me.get()); + } + /// @} + /// \brief Register an atomic proposition. /// /// Return (and maybe allocate) a BDD variable designating an @@ -120,15 +137,32 @@ namespace spot /// /// \return The variable number. Use bdd_ithvar() or bdd_nithvar() /// to convert this to a BDD. + /// @{ int register_acceptance_variable(const ltl::formula* f, const void* for_me); + template + int register_acceptance_variable(const ltl::formula* f, + std::shared_ptr for_me) + { + return register_acceptance_variable(f, for_me.get()); + } + /// @} + /// \brief Clone an acceptance variable VAR for FOR_ME. /// /// This is used in products TGBAs when both operands share the /// same acceptance variables but they need to be distinguished in /// the result. + /// @{ int register_clone_acc(int var, const void* for_me); + template + int register_clone_acc(int var, std::shared_ptr for_me) + { + return register_clone_acc(var, for_me.get()); + } + /// @} + /// \brief Register BDD variables as acceptance variables. /// /// Register all variables occurring in \a f as acceptance variables @@ -136,8 +170,16 @@ namespace spot /// are already known from the dictionary (i.e., they have already /// been registered by register_acceptance_variable() for another /// automaton). + /// @{ void register_acceptance_variables(bdd f, const void* for_me); + template + void register_acceptance_variables(bdd f, std::shared_ptr for_me) + { + register_acceptance_variables(f, for_me.get()); + } + /// @} + /// \brief Convert one acceptance condition into the associated /// formula. /// @@ -166,16 +208,47 @@ namespace spot /// /// \return The variable number. Use bdd_ithvar() or bdd_nithvar() /// to convert this to a BDD. + /// @{ int register_anonymous_variables(int n, const void* for_me); + template + int register_anonymous_variables(int n, std::shared_ptr for_me) + { + return register_anonymous_variables(n, for_me.get()); + } + /// @} + /// \brief Duplicate the variable usage of another object. /// /// This tells this dictionary that the \a for_me object will be /// using the same BDD variables as the \a from_other objects. /// This ensures that the variables won't be freed when \a /// from_other is deleted if \a from_other is still alive. + /// @{ void register_all_variables_of(const void* from_other, const void* for_me); + template + void register_all_variables_of(const void* from_other, + std::shared_ptr for_me) + { + register_all_variables_of(from_other, for_me.get()); + } + + template + void register_all_variables_of(std::shared_ptr from_other, + const void* for_me) + { + register_all_variables_of(from_other.get(), for_me); + } + + template + void register_all_variables_of(std::shared_ptr from_other, + std::shared_ptr for_me) + { + register_all_variables_of(from_other.get(), for_me.get()); + } + /// @} + /// \brief Register the same propositions as another object. /// /// This tells this dictionary that the \a for_me object will be @@ -183,9 +256,32 @@ namespace spot /// the \a from_other object. This ensures that the variables /// won't be freed when \a from_other is deleted if \a from_other /// is still alive. + /// @{ void register_all_propositions_of(const void* from_other, const void* for_me); + template + void register_all_propositions_of(const void* from_other, + std::shared_ptr for_me) + { + register_all_propositions_of(from_other, for_me.get()); + } + + template + void register_all_propositions_of(std::shared_ptr from_other, + const void* for_me) + { + register_all_propositions_of(from_other.get(), for_me); + } + + template + void register_all_propositions_of(std::shared_ptr from_other, + std::shared_ptr for_me) + { + register_all_propositions_of(from_other.get(), for_me.get()); + } + /// @} + /// \brief Release all variables used by an object. /// /// Usually called in the destructor if \a me. @@ -193,16 +289,25 @@ namespace spot /// \brief Release all variables of a given type, used by an /// object. + /// @{ void unregister_all_typed_variables(var_type type, const void* me); + template + void unregister_all_typed_variables(var_type type, std::shared_ptr me) + { + unregister_all_typed_variables(type, me.get()); + } + /// @} + /// \brief Release a variable used by \a me. + /// @{ void unregister_variable(int var, const void* me); - /// @{ - /// Check whether formula \a f has already been registered by \a by_me. - bool is_registered_proposition(const ltl::formula* f, const void* by_me); - bool is_registered_acceptance_variable(const ltl::formula* f, - const void* by_me); + template + void unregister_variable(int var, std::shared_ptr me) + { + unregister_variable(var, me.get()); + } /// @} /// \brief Dump all variables for debugging. diff --git a/src/tgba/formula2bdd.hh b/src/tgba/formula2bdd.hh index 1525639e5..f6c138989 100644 --- a/src/tgba/formula2bdd.hh +++ b/src/tgba/formula2bdd.hh @@ -1,5 +1,5 @@ // -*- coding: utf-8 -*- -// Copyright (C) 2012, 2013 Laboratoire de Recherche et Développement de +// Copyright (C) 2012, 2013, 2014 Laboratoire de Recherche et Développement de // l'Epita (LRDE). // Copyright (C) 2003 Laboratoire d'Informatique de Paris 6 (LIP6), // département Systèmes Répartis Coopératifs (SRC), Université Pierre @@ -38,9 +38,19 @@ namespace spot /// passing it right away to bdd_to_formula(), you should not forget /// to unregister the variables that have been registered for \a /// for_me. See bdd_dict::unregister_all_my_variables(). + /// @{ SPOT_API bdd formula_to_bdd(const ltl::formula* f, bdd_dict_ptr d, void* for_me); + template + SPOT_API bdd + formula_to_bdd(const ltl::formula* f, bdd_dict_ptr d, + const std::shared_ptr& for_me) + { + return formula_to_bdd(f, d, for_me.get()); + } + /// @} + /// \brief Convert a BDD into a formula. /// /// Format the BDD as an irredundant sum of product (see the diff --git a/src/tgba/futurecondcol.cc b/src/tgba/futurecondcol.cc index 547623fbb..38f088666 100644 --- a/src/tgba/futurecondcol.cc +++ b/src/tgba/futurecondcol.cc @@ -42,8 +42,8 @@ namespace spot future_conds_[src] = res; } - future_conditions_collector::future_conditions_collector(const tgba* aut, - bool show) + future_conditions_collector::future_conditions_collector + (const const_tgba_ptr& aut, bool show) : tgba_scc(aut, show), // Initialize future_conds_ with as much empty // "cond_set"s as there are SCCs. diff --git a/src/tgba/futurecondcol.hh b/src/tgba/futurecondcol.hh index 4d2ebcb76..5409860b6 100644 --- a/src/tgba/futurecondcol.hh +++ b/src/tgba/futurecondcol.hh @@ -1,5 +1,5 @@ // -*- coding: utf-8 -*- -// Copyright (C) 2009, 2013 Laboratoire de recherche et développement +// Copyright (C) 2009, 2013, 2014 Laboratoire de recherche et développement // de l'Epita. // // This file is part of Spot, a model checking library. @@ -45,7 +45,7 @@ namespace spot /// If \a show is set to true, then the format_state() method will /// include the set of conditions computed for the given state in /// its output string. - future_conditions_collector(const tgba* aut, bool show = false); + future_conditions_collector(const const_tgba_ptr& aut, bool show = false); virtual ~future_conditions_collector(); /// Returns the set of future conditions visible after \a s @@ -65,6 +65,17 @@ namespace spot // strongly connected component. }; + typedef std::shared_ptr + future_conditions_collector_ptr; + typedef std::shared_ptr + const_future_conditions_collector_ptr; + + inline future_conditions_collector_ptr + make_future_conditions_collector(const const_tgba_ptr& aut, bool show = false) + { + return std::make_shared(aut, show); + } + } #endif // SPOT_TGBA_FUTURECONDCOL_HH diff --git a/src/tgba/fwd.hh b/src/tgba/fwd.hh new file mode 100644 index 000000000..24e089ae5 --- /dev/null +++ b/src/tgba/fwd.hh @@ -0,0 +1,44 @@ +// -*- coding: utf-8 -*- +// Copyright (C) 2014 Laboratoire de Recherche et Développement de +// l'Epita (LRDE). +// +// This file is part of Spot, a model checking library. +// +// Spot is free software; you can redistribute it and/or modify it +// under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 3 of the License, or +// (at your option) any later version. +// +// Spot is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +// or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public +// License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +#ifndef SPOT_TGBA_FWD_HH +# define SPOT_TGBA_FWD_HH + +#include + +namespace spot +{ + class tgba; + typedef std::shared_ptr tgba_ptr; + typedef std::shared_ptr const_tgba_ptr; + + class tgba_digraph; + typedef std::shared_ptr const_tgba_digraph_ptr; + typedef std::shared_ptr tgba_digraph_ptr; + + class tgba_product; + typedef std::shared_ptr const_tgba_product_ptr; + typedef std::shared_ptr tgba_product_ptr; + + class tgba_sgba_proxy; + typedef std::shared_ptr const_tgba_sgba_proxy_ptr; + typedef std::shared_ptr tgba_sgba_proxy_ptr; +} + +#endif // SPOT_TGBA_FWD_HH diff --git a/src/tgba/taatgba.hh b/src/tgba/taatgba.hh index 2368c2cec..c458a5bf9 100644 --- a/src/tgba/taatgba.hh +++ b/src/tgba/taatgba.hh @@ -151,7 +151,7 @@ namespace spot class SPOT_API taa_tgba_labelled : public taa_tgba { public: - taa_tgba_labelled(bdd_dict_ptr dict) : taa_tgba(dict) {}; + taa_tgba_labelled(const bdd_dict_ptr& dict) : taa_tgba(dict) {}; void set_init_state(const label& s) { @@ -319,10 +319,14 @@ namespace spot }; class SPOT_API taa_tgba_string : +#ifndef SWIG public taa_tgba_labelled +#else + public taa_tgba +#endif { public: - taa_tgba_string(bdd_dict_ptr dict) : + taa_tgba_string(const bdd_dict_ptr& dict) : taa_tgba_labelled(dict) {}; ~taa_tgba_string(); protected: @@ -330,17 +334,38 @@ namespace spot virtual std::string clone_if(const std::string& label) const; }; + typedef std::shared_ptr taa_tgba_string_ptr; + typedef std::shared_ptr const_taa_tgba_string_ptr; + + inline taa_tgba_string_ptr make_taa_tgba_string(const bdd_dict_ptr& dict) + { + return std::make_shared(dict); + } + class SPOT_API taa_tgba_formula : +#ifndef SWIG public taa_tgba_labelled +#else + public taa_tgba +#endif { public: - taa_tgba_formula(bdd_dict_ptr dict) : + taa_tgba_formula(const bdd_dict_ptr& dict) : taa_tgba_labelled(dict) {}; ~taa_tgba_formula(); protected: virtual std::string label_to_string(const label_t& label) const; virtual const ltl::formula* clone_if(const label_t& label) const; }; + + typedef std::shared_ptr taa_tgba_formula_ptr; + typedef std::shared_ptr const_taa_tgba_formula_ptr; + + inline taa_tgba_formula_ptr make_taa_tgba_formula(const bdd_dict_ptr& dict) + { + return std::make_shared(dict); + } + } #endif // SPOT_TGBA_TAATGBA_HH diff --git a/src/tgba/tgba.cc b/src/tgba/tgba.cc index bb9a1ff7d..056f7082c 100644 --- a/src/tgba/tgba.cc +++ b/src/tgba/tgba.cc @@ -53,9 +53,10 @@ namespace spot } state* - tgba::project_state(const state* s, const tgba* t) const + tgba::project_state(const state* s, + const const_tgba_ptr& t) const { - if (t == this) + if (t.get() == this) return s->clone(); return 0; } diff --git a/src/tgba/tgba.hh b/src/tgba/tgba.hh index 7a719befe..bc9e0c9cf 100644 --- a/src/tgba/tgba.hh +++ b/src/tgba/tgba.hh @@ -26,6 +26,7 @@ #include "state.hh" #include "bdddict.hh" #include "succiter.hh" +#include "fwd.hh" namespace spot { @@ -215,7 +216,8 @@ namespace spot /// \return 0 if the projection fails (\a s is unrelated to \a t), /// or a new \c state* (the projected state) that must be /// destroyed by the caller. - virtual state* project_state(const state* s, const tgba* t) const; + virtual state* project_state(const state* s, + const const_tgba_ptr& t) const; /// \brief Return the set of all acceptance conditions used /// by this automaton. diff --git a/src/tgba/tgbagraph.hh b/src/tgba/tgbagraph.hh index b2c4d25ab..91c84f8ce 100644 --- a/src/tgba/tgbagraph.hh +++ b/src/tgba/tgbagraph.hh @@ -20,6 +20,7 @@ #ifndef SPOT_TGBA_TGBAGRAPH_HH # define SPOT_TGBA_TGBAGRAPH_HH +#include "fwd.hh" #include "graph/graph.hh" #include "graph/ngraph.hh" #include "tgba/bdddict.hh" @@ -302,6 +303,17 @@ namespace spot return g_.trans_data(t); } + const tgba_graph_trans_data& trans_data(const tgba_succ_iterator* it) const + { + auto* i = down_cast*>(it); + return g_.trans_data(i->pos()); + } + + const tgba_graph_trans_data& trans_data(unsigned t) const + { + return g_.trans_data(t); + } + void set_acceptance_conditions(bdd all); bdd set_single_acceptance_set(); @@ -346,12 +358,12 @@ namespace spot SPOT_RETURN(g_.transitions()); /// \brief Copy the acceptance conditions of another tgba. - void copy_acceptance_conditions_of(const tgba *a) + void copy_acceptance_conditions_of(const const_tgba_ptr& a) { set_acceptance_conditions(a->neg_acceptance_conditions()); } - void copy_ap_of(const tgba* a) + void copy_ap_of(const const_tgba_ptr& a) { dict_->register_all_propositions_of(a, this); } @@ -420,6 +432,10 @@ namespace spot }; + inline tgba_digraph_ptr make_tgba_digraph(bdd_dict_ptr dict) + { + return std::make_shared(dict); + } } #endif // SPOT_TGBA_TGBAGRAPH_HH diff --git a/src/tgba/tgbakvcomplement.cc b/src/tgba/tgbakvcomplement.cc index cd1949681..867ac235f 100644 --- a/src/tgba/tgbakvcomplement.cc +++ b/src/tgba/tgbakvcomplement.cc @@ -72,14 +72,14 @@ namespace spot return hash; } - std::string format(const tgba* a) const + std::string format(const bdd_dict_ptr& d) const { std::ostringstream ss; ss << "{rank: " << rank; if (rank & 1) { ss << ", bdd: {" << condition.order() << ", " - << bdd_format_accset(a->get_dict(), condition.get_bdd()) + << bdd_format_accset(d, condition.get_bdd()) << "} "; } ss << '}'; @@ -588,8 +588,8 @@ namespace spot } } - tgba_kv_complement::tgba_kv_complement(const tgba* a) - : automaton_(new tgba_sgba_proxy(a)) + tgba_kv_complement::tgba_kv_complement(const const_tgba_ptr& a) + : automaton_(make_sgba(a)) { get_dict()->register_all_variables_of(automaton_, this); int v = get_dict() @@ -602,7 +602,6 @@ namespace spot tgba_kv_complement::~tgba_kv_complement() { get_dict()->unregister_all_my_variables(this); - delete automaton_; } state* @@ -622,7 +621,7 @@ namespace spot down_cast(state); assert(s); - return new tgba_kv_complement_succ_iterator(automaton_, + return new tgba_kv_complement_succ_iterator(automaton_.get(), the_acceptance_cond_, acc_list_, s); } @@ -650,7 +649,7 @@ namespace spot ++i) { ss << " {" << automaton_->format_state(i->first.get()) - << ", " << i->second.format(this) << "}\n"; + << ", " << i->second.format(get_dict()) << "}\n"; } ss << "} odd-less: {"; diff --git a/src/tgba/tgbakvcomplement.hh b/src/tgba/tgbakvcomplement.hh index 4605f814c..6a8d094ef 100644 --- a/src/tgba/tgbakvcomplement.hh +++ b/src/tgba/tgbakvcomplement.hh @@ -86,7 +86,7 @@ namespace spot class SPOT_API tgba_kv_complement : public tgba { public: - tgba_kv_complement(const tgba* a); + tgba_kv_complement(const const_tgba_ptr& a); virtual ~tgba_kv_complement(); // tgba interface @@ -104,12 +104,20 @@ namespace spot /// They are inserted into \a acc_list_. void get_acc_list(); private: - const tgba_sgba_proxy* automaton_; + const_tgba_sgba_proxy_ptr automaton_; bdd the_acceptance_cond_; unsigned nb_states_; acc_list_t acc_list_; }; // end class tgba_kv_complement. + typedef std::shared_ptr tgba_kv_complement_ptr; + typedef std::shared_ptr + const_tgba_kv_complement_ptr; + inline tgba_kv_complement_ptr + make_kv_complement(const const_tgba_ptr& a) + { + return std::make_shared(a); + } } // end namespace spot. diff --git a/src/tgba/tgbamask.cc b/src/tgba/tgbamask.cc index 9fea6a279..d46b16620 100644 --- a/src/tgba/tgbamask.cc +++ b/src/tgba/tgbamask.cc @@ -76,63 +76,81 @@ namespace spot transitions::const_iterator it_; }; - } - - tgba_mask::tgba_mask(const tgba* masked, - const state* init) - : tgba_proxy(masked), - init_(init) - { - if (!init) - init_ = masked->get_init_state(); - } - - tgba_mask::~tgba_mask() - { - init_->destroy(); - } - - state* tgba_mask::get_init_state() const - { - return init_->clone(); - } - - tgba_succ_iterator* - tgba_mask::succ_iter(const state* state) const - { - succ_iter_filtered* res; - if (iter_cache_) + /// \ingroup tgba_on_the_fly_algorithms + /// \brief A masked TGBA (abstract). + /// + /// Ignores some states from a TGBA. What state are preserved or + /// ignored is controlled by the wanted() method. + /// + /// This is an abstract class. You should inherit from it and + /// supply a wanted() method to specify which states to keep. + class tgba_mask: public tgba_proxy + { + protected: + /// \brief Constructor. + /// \param masked The automaton to mask + /// \param init Any state to use as initial state. This state will be + /// destroyed by the destructor. + tgba_mask(const const_tgba_ptr& masked, const state* init = 0): + tgba_proxy(masked), + init_(init) { - res = down_cast(iter_cache_); - res->trans_.clear(); - iter_cache_ = nullptr; + if (!init) + init_ = masked->get_init_state(); } - else + + + public: + virtual ~tgba_mask() { - res = new succ_iter_filtered; + init_->destroy(); } - for (auto it: original_->succ(state)) + + virtual state* get_init_state() const { - const spot::state* s = it->current_state(); - bdd acc = it->current_acceptance_conditions(); - if (!wanted(s, acc)) + return init_->clone(); + } + + virtual tgba_succ_iterator* + succ_iter(const state* local_state) const + { + succ_iter_filtered* res; + if (iter_cache_) { - s->destroy(); - continue; + res = down_cast(iter_cache_); + res->trans_.clear(); + iter_cache_ = nullptr; } - res->trans_.emplace_back(transition {s, it->current_condition(), acc}); + else + { + res = new succ_iter_filtered; + } + for (auto it: original_->succ(local_state)) + { + const spot::state* s = it->current_state(); + bdd acc = it->current_acceptance_conditions(); + if (!wanted(s, acc)) + { + s->destroy(); + continue; + } + res->trans_.emplace_back(transition {s, it->current_condition(), + acc}); + } + return res; } - return res; - } - namespace - { + virtual bool wanted(const state* s, const bdd& acc) const = 0; + + protected: + const state* init_; + }; class tgba_mask_keep: public tgba_mask { const state_set& mask_; public: - tgba_mask_keep(const tgba* masked, + tgba_mask_keep(const const_tgba_ptr& masked, const state_set& mask, const state* init) : tgba_mask(masked, init), @@ -151,7 +169,7 @@ namespace spot { const state_set& mask_; public: - tgba_mask_ignore(const tgba* masked, + tgba_mask_ignore(const const_tgba_ptr& masked, const state_set& mask, const state* init) : tgba_mask(masked, init), @@ -170,7 +188,7 @@ namespace spot { const bdd& mask_; public: - tgba_mask_acc_ignore(const tgba* masked, + tgba_mask_acc_ignore(const const_tgba_ptr& masked, const bdd& mask, const state* init) : tgba_mask(masked, init), @@ -184,32 +202,30 @@ namespace spot } }; - } - - const tgba* - build_tgba_mask_keep(const tgba* to_mask, + const_tgba_ptr + build_tgba_mask_keep(const const_tgba_ptr& to_mask, const state_set& to_keep, const state* init) { - return new tgba_mask_keep(to_mask, to_keep, init); + return std::make_shared(to_mask, to_keep, init); } - const tgba* - build_tgba_mask_ignore(const tgba* to_mask, + const_tgba_ptr + build_tgba_mask_ignore(const const_tgba_ptr& to_mask, const state_set& to_ignore, const state* init) { - return new tgba_mask_ignore(to_mask, to_ignore, init); + return std::make_shared(to_mask, to_ignore, init); } - const tgba* - build_tgba_mask_acc_ignore(const tgba* to_mask, + const_tgba_ptr + build_tgba_mask_acc_ignore(const const_tgba_ptr& to_mask, const bdd to_ignore, const state* init) { - return new tgba_mask_acc_ignore(to_mask, to_ignore, init); + return std::make_shared(to_mask, to_ignore, init); } } diff --git a/src/tgba/tgbamask.hh b/src/tgba/tgbamask.hh index cd38789da..02398165c 100644 --- a/src/tgba/tgbamask.hh +++ b/src/tgba/tgbamask.hh @@ -26,45 +26,14 @@ namespace spot { - /// \ingroup tgba_on_the_fly_algorithms - /// \brief A masked TGBA (abstract). - /// - /// Ignores some states from a TGBA. What state are preserved or - /// ignored is controlled by the wanted() method. - /// - /// This is an abstract class. You should inherit from it and - /// supply a wanted() method to specify which states to keep. - class SPOT_API tgba_mask: public tgba_proxy - { - protected: - /// \brief Constructor. - /// \param masked The automaton to mask - /// \param init Any state to use as initial state. This state will be - /// destroyed by the destructor. - tgba_mask(const tgba* masked, const state* init = 0); - - public: - virtual ~tgba_mask(); - - virtual state* get_init_state() const; - - virtual tgba_succ_iterator* - succ_iter(const state* local_state) const; - - virtual bool wanted(const state* s, const bdd& acc) const = 0; - - protected: - const state* init_; - }; - /// \ingroup tgba_on_the_fly_algorithms /// \brief Mask a TGBA, keeping a given set of states. /// /// Mask the TGBA \a to_mask, keeping only the /// states from \a to_keep. The initial state /// can optionally be reset to \a init. - SPOT_API const tgba* - build_tgba_mask_keep(const tgba* to_mask, + SPOT_API const_tgba_ptr + build_tgba_mask_keep(const const_tgba_ptr& to_mask, const state_set& to_keep, const state* init = 0); @@ -74,8 +43,8 @@ namespace spot /// Mask the TGBA \a to_mask, keeping only the states that are not /// in \a to_ignore. The initial state can optionally be reset to /// \a init. - SPOT_API const tgba* - build_tgba_mask_ignore(const tgba* to_mask, + SPOT_API const_tgba_ptr + build_tgba_mask_ignore(const const_tgba_ptr& to_mask, const state_set& to_ignore, const state* init = 0); @@ -91,8 +60,8 @@ namespace spot /// set of all acceptance set) is not changed, because so far this /// function is only needed in graph algorithms that do not call /// all_acceptance_conditions(). - SPOT_API const tgba* - build_tgba_mask_acc_ignore(const tgba* to_mask, + SPOT_API const_tgba_ptr + build_tgba_mask_acc_ignore(const const_tgba_ptr& to_mask, const bdd to_ignore, const state* init = 0); diff --git a/src/tgba/tgbaproduct.cc b/src/tgba/tgbaproduct.cc index 42563de10..4fd7cb5e5 100644 --- a/src/tgba/tgbaproduct.cc +++ b/src/tgba/tgbaproduct.cc @@ -89,8 +89,8 @@ namespace spot { } - void recycle(const tgba* l, tgba_succ_iterator* left, - const tgba* r, tgba_succ_iterator* right) + void recycle(const const_tgba_ptr& l, tgba_succ_iterator* left, + const_tgba_ptr r, tgba_succ_iterator* right) { l->release_iter(left_); left_ = left; @@ -284,7 +284,8 @@ namespace spot //////////////////////////////////////////////////////////// // tgba_product - tgba_product::tgba_product(const tgba* left, const tgba* right) + tgba_product::tgba_product(const const_tgba_ptr& left, + const const_tgba_ptr& right) : dict_(left->get_dict()), left_(left), right_(right), pool_(sizeof(state_product)) { @@ -293,11 +294,11 @@ namespace spot // If one of the side is a Kripke structure, it is easier to deal // with (we don't have to fix the acceptance conditions, and // computing the successors can be improved a bit). - if (dynamic_cast(left_)) + if (dynamic_cast(left_.get())) { left_kripke_ = true; } - else if (dynamic_cast(right_)) + else if (dynamic_cast(right_.get())) { std::swap(left_, right_); left_kripke_ = true; @@ -428,11 +429,11 @@ namespace spot } state* - tgba_product::project_state(const state* s, const tgba* t) const + tgba_product::project_state(const state* s, const const_tgba_ptr& t) const { const state_product* s2 = down_cast(s); assert(s2); - if (t == this) + if (t.get() == this) return s2->clone(); state* res = left_->project_state(s2->left(), t); if (res) @@ -470,7 +471,8 @@ namespace spot ////////////////////////////////////////////////////////////////////// // tgba_product_init - tgba_product_init::tgba_product_init(const tgba* left, const tgba* right, + tgba_product_init::tgba_product_init(const const_tgba_ptr& left, + const const_tgba_ptr& right, const state* left_init, const state* right_init) : tgba_product(left, right), diff --git a/src/tgba/tgbaproduct.hh b/src/tgba/tgbaproduct.hh index e15baba6c..bbaa96a66 100644 --- a/src/tgba/tgbaproduct.hh +++ b/src/tgba/tgbaproduct.hh @@ -85,7 +85,7 @@ namespace spot /// \param left The left automata in the product. /// \param right The right automata in the product. /// Do not be fooled by these arguments: a product is commutative. - tgba_product(const tgba* left, const tgba* right); + tgba_product(const const_tgba_ptr& left, const const_tgba_ptr& right); virtual ~tgba_product(); @@ -101,7 +101,7 @@ namespace spot virtual std::string transition_annotation(const tgba_succ_iterator* t) const; - virtual state* project_state(const state* s, const tgba* t) const; + virtual state* project_state(const state* s, const const_tgba_ptr& t) const; virtual bdd all_acceptance_conditions() const; virtual bdd neg_acceptance_conditions() const; @@ -111,8 +111,8 @@ namespace spot protected: bdd_dict_ptr dict_; - const tgba* left_; - const tgba* right_; + const_tgba_ptr left_; + const_tgba_ptr right_; bool left_kripke_; bdd left_acc_complement_; bdd right_acc_complement_; @@ -131,7 +131,7 @@ namespace spot class SPOT_API tgba_product_init: public tgba_product { public: - tgba_product_init(const tgba* left, const tgba* right, + tgba_product_init(const const_tgba_ptr& left, const const_tgba_ptr& right, const state* left_init, const state* right_init); virtual state* get_init_state() const; protected: @@ -139,6 +139,20 @@ namespace spot const state* right_init_; }; + inline tgba_product_ptr product(const const_tgba_ptr& left, + const const_tgba_ptr& right) + { + return std::make_shared(left, right); + } + + inline tgba_product_ptr product_at(const const_tgba_ptr& left, + const const_tgba_ptr& right, + const state* left_init, + const state* right_init) + { + return std::make_shared(left, right, + left_init, right_init); + } } #endif // SPOT_TGBA_TGBAPRODUCT_HH diff --git a/src/tgba/tgbaproxy.cc b/src/tgba/tgbaproxy.cc index 79a33dc27..32d6058a7 100644 --- a/src/tgba/tgbaproxy.cc +++ b/src/tgba/tgbaproxy.cc @@ -21,7 +21,7 @@ namespace spot { - tgba_proxy::tgba_proxy(const tgba* original) + tgba_proxy::tgba_proxy(const const_tgba_ptr& original) : original_(original) { get_dict()->register_all_variables_of(original, this); @@ -67,7 +67,7 @@ namespace spot } state* - tgba_proxy::project_state(const state* s, const tgba* t) const + tgba_proxy::project_state(const state* s, const const_tgba_ptr& t) const { return original_->project_state(s, t); } @@ -90,4 +90,3 @@ namespace spot return original_->support_conditions(state); } } - diff --git a/src/tgba/tgbaproxy.hh b/src/tgba/tgbaproxy.hh index 9aa5162d1..e67d31858 100644 --- a/src/tgba/tgbaproxy.hh +++ b/src/tgba/tgbaproxy.hh @@ -36,7 +36,7 @@ namespace spot class SPOT_API tgba_proxy: public tgba { protected: - tgba_proxy(const tgba* original); + tgba_proxy(const const_tgba_ptr& original); public: virtual ~tgba_proxy(); @@ -53,7 +53,7 @@ namespace spot virtual std::string transition_annotation(const tgba_succ_iterator* t) const; - virtual state* project_state(const state* s, const tgba* t) const; + virtual state* project_state(const state* s, const const_tgba_ptr& t) const; virtual bdd all_acceptance_conditions() const; @@ -61,7 +61,7 @@ namespace spot protected: virtual bdd compute_support_conditions(const state* state) const; - const tgba* original_; + const_tgba_ptr original_; }; } diff --git a/src/tgba/tgbasafracomplement.cc b/src/tgba/tgbasafracomplement.cc index 6b74b5b9d..ff568bccd 100644 --- a/src/tgba/tgbasafracomplement.cc +++ b/src/tgba/tgbasafracomplement.cc @@ -53,7 +53,7 @@ namespace spot /// \brief Automaton with Safra's tree as states. struct safra_tree_automaton { - safra_tree_automaton(const tgba_digraph* sba); + safra_tree_automaton(const const_tgba_digraph_ptr& sba); ~safra_tree_automaton(); typedef std::map transition_list; typedef @@ -66,14 +66,14 @@ namespace spot int get_nb_acceptance_pairs() const; safra_tree* get_initial_state() const; void set_initial_state(safra_tree* s); - const tgba_digraph* get_sba(void) const + const const_tgba_digraph_ptr& get_sba(void) const { return a_; } private: mutable int max_nb_pairs_; safra_tree* initial_state; - const tgba_digraph* a_; + const_tgba_digraph_ptr a_; }; /// \brief A Safra tree, used as state during the determinization @@ -569,12 +569,13 @@ namespace spot class safra_determinisation { public: - static safra_tree_automaton* create_safra_automaton(const tgba* a); + static safra_tree_automaton* + create_safra_automaton(const const_tgba_ptr& a); private: typedef std::set atomic_list_t; typedef std::set conjunction_list_t; static void retrieve_atomics(const safra_tree* node, - tgba_digraph* sba_aut, + tgba_digraph_ptr sba_aut, safra_tree::cache_t& cache, atomic_list_t& atomic_list); static void set_atomic_list(atomic_list_t& list, bdd condition); @@ -584,7 +585,7 @@ namespace spot /// \brief The body of Safra's construction. safra_tree_automaton* - safra_determinisation::create_safra_automaton(const tgba* a) + safra_determinisation::create_safra_automaton(const const_tgba_ptr& a) { // initialization. auto sba_aut = degeneralize(a); @@ -664,7 +665,7 @@ namespace spot /// of the states in the label of the node. void safra_determinisation::retrieve_atomics(const safra_tree* node, - tgba_digraph* sba_aut, + tgba_digraph_ptr sba_aut, safra_tree::cache_t& cache, atomic_list_t& atomic_list) { @@ -1031,7 +1032,7 @@ namespace spot // safra_tree_automaton //////////////////////// - safra_tree_automaton::safra_tree_automaton(const tgba_digraph* a) + safra_tree_automaton::safra_tree_automaton(const const_tgba_digraph_ptr& a) : max_nb_pairs_(-1), initial_state(0), a_(a) { a->get_dict()->register_all_variables_of(a, this); @@ -1041,7 +1042,6 @@ namespace spot { for (auto& p: automaton) delete p.first; - delete a_; } int @@ -1074,7 +1074,7 @@ namespace spot // tgba_safra_complement ////////////////////////// - tgba_safra_complement::tgba_safra_complement(const tgba* a) + tgba_safra_complement::tgba_safra_complement(const const_tgba_ptr& a) : automaton_(a), safra_(safra_determinisation::create_safra_automaton(a)) { assert(safra_ || !"safra construction fails"); @@ -1304,7 +1304,7 @@ namespace spot // display_safra: debug routine. ////////////////////////////// - void display_safra(const tgba_safra_complement* a) + void display_safra(const const_tgba_safra_complement_ptr& a) { test::print_safra_automaton(static_cast (a->get_safra())); diff --git a/src/tgba/tgbasafracomplement.hh b/src/tgba/tgbasafracomplement.hh index 95ab2a89b..363337717 100644 --- a/src/tgba/tgbasafracomplement.hh +++ b/src/tgba/tgbasafracomplement.hh @@ -50,7 +50,7 @@ namespace spot class SPOT_API tgba_safra_complement : public tgba { public: - tgba_safra_complement(const tgba* a); + tgba_safra_complement(const const_tgba_ptr& a); virtual ~tgba_safra_complement(); // tgba interface. @@ -70,7 +70,7 @@ namespace spot protected: virtual bdd compute_support_conditions(const state* state) const; private: - const tgba* automaton_; + const_tgba_ptr automaton_; void* safra_; #if TRANSFORM_TO_TBA bdd the_acceptance_cond_; @@ -83,12 +83,21 @@ namespace spot #endif }; + typedef std::shared_ptr tgba_safra_complement_ptr; + typedef std::shared_ptr + const_tgba_safra_complement_ptr; + inline tgba_safra_complement_ptr + make_safra_complement(const const_tgba_ptr& a) + { + return std::make_shared(a); + } + /// \brief Produce a dot output of the Safra automaton associated /// to \a a. /// /// \param a The \c tgba_safra_complement with an intermediate Safra /// automaton to display - void SPOT_API display_safra(const tgba_safra_complement* a); + void SPOT_API display_safra(const const_tgba_safra_complement_ptr& a); } #endif // SPOT_TGBA_TGBASAFRACOMPLEMENT_HH diff --git a/src/tgba/tgbascc.cc b/src/tgba/tgbascc.cc index a5da1fb7f..95b1351cf 100644 --- a/src/tgba/tgbascc.cc +++ b/src/tgba/tgbascc.cc @@ -23,7 +23,7 @@ namespace spot { - tgba_scc::tgba_scc(const tgba* aut, bool show) + tgba_scc::tgba_scc(const const_tgba_ptr& aut, bool show) : aut_(aut), scc_map_(aut), show_(show) { scc_map_.build_map(); @@ -82,7 +82,7 @@ namespace spot } state* - tgba_scc::project_state(const state* s, const tgba* t) const + tgba_scc::project_state(const state* s, const const_tgba_ptr& t) const { return aut_->project_state(s, t); } diff --git a/src/tgba/tgbascc.hh b/src/tgba/tgbascc.hh index 0dcae06f4..973891aef 100644 --- a/src/tgba/tgbascc.hh +++ b/src/tgba/tgbascc.hh @@ -40,7 +40,7 @@ namespace spot /// If \a show is set to true, then the format_state() method will /// include the SCC number computed for the given state in its /// output string. - tgba_scc(const tgba* aut, bool show = false); + tgba_scc(const const_tgba_ptr& aut, bool show = false); virtual ~tgba_scc(); /// Returns the number of the SCC \a s belongs to. @@ -62,14 +62,14 @@ namespace spot virtual std::string transition_annotation(const tgba_succ_iterator* t) const; - virtual state* project_state(const state* s, const tgba* t) const; + virtual state* project_state(const state* s, const const_tgba_ptr& t) const; virtual bdd all_acceptance_conditions() const; virtual bdd neg_acceptance_conditions() const; virtual bdd compute_support_conditions(const state* state) const; protected: - const tgba* aut_; // The wrapped TGBA. + const_tgba_ptr aut_; // The wrapped TGBA. scc_map scc_map_; // SCC informations. bool show_; // Wether to show future conditions // in the output of format_state(). diff --git a/src/tgba/tgbasgba.cc b/src/tgba/tgbasgba.cc index 501c56d06..11bd5cec5 100644 --- a/src/tgba/tgbasgba.cc +++ b/src/tgba/tgbasgba.cc @@ -165,7 +165,8 @@ namespace spot } // anonymous - tgba_sgba_proxy::tgba_sgba_proxy(const tgba* a, bool no_zero_acc) + tgba_sgba_proxy::tgba_sgba_proxy(const const_tgba_ptr& a, + bool no_zero_acc) : a_(a), emulate_acc_cond_(false) { if (no_zero_acc && a_->number_of_acceptance_conditions() == 0) diff --git a/src/tgba/tgbasgba.hh b/src/tgba/tgbasgba.hh index 6244251e7..9313898f6 100644 --- a/src/tgba/tgbasgba.hh +++ b/src/tgba/tgbasgba.hh @@ -36,7 +36,7 @@ namespace spot class SPOT_API tgba_sgba_proxy : public tgba { public: - tgba_sgba_proxy(const tgba* a, bool no_zero_acc = true); + tgba_sgba_proxy(const const_tgba_ptr& a, bool no_zero_acc = true); virtual ~tgba_sgba_proxy(); @@ -57,7 +57,7 @@ namespace spot virtual bdd compute_support_conditions(const state* state) const; private: - const tgba* a_; + const_tgba_ptr a_; // If the automaton has no acceptance condition, // every state is accepting. bool emulate_acc_cond_; @@ -67,5 +67,10 @@ namespace spot tgba_sgba_proxy& operator=(const tgba_sgba_proxy&) SPOT_DELETED; }; + inline tgba_sgba_proxy_ptr make_sgba(const const_tgba_ptr& a, + bool no_zero_acc = true) + { + return std::make_shared(a, no_zero_acc); + } } #endif // SPOT_TGBA_TGBASGBA_HH diff --git a/src/tgba/wdbacomp.cc b/src/tgba/wdbacomp.cc index b61b98e9f..0f4a6a689 100644 --- a/src/tgba/wdbacomp.cc +++ b/src/tgba/wdbacomp.cc @@ -95,7 +95,7 @@ namespace spot { } - void recycle(const tgba* a, tgba_succ_iterator* it) + void recycle(const const_tgba_ptr& a, tgba_succ_iterator* it) { a->release_iter(it_); it_ = it; @@ -183,7 +183,7 @@ namespace spot class tgba_wdba_comp_proxy: public tgba { public: - tgba_wdba_comp_proxy(const tgba* a) + tgba_wdba_comp_proxy(const const_tgba_ptr& a) : a_(a), the_acceptance_cond_(a->all_acceptance_conditions()) { if (the_acceptance_cond_ == bddfalse) @@ -247,12 +247,12 @@ namespace spot } virtual state* - project_state(const state* s, const tgba* t) const + project_state(const state* s, const const_tgba_ptr& t) const { const state_wdba_comp_proxy* s2 = down_cast(s); assert(s2); - if (t == this) + if (t.get() == this) return s2->clone(); return a_->project_state(s2->real_state(), t); } @@ -277,7 +277,7 @@ namespace spot return bddtrue; } - const tgba* a_; + const_tgba_ptr a_; private: bdd the_acceptance_cond_; @@ -288,9 +288,9 @@ namespace spot } - tgba* - wdba_complement(const tgba* aut) + const_tgba_ptr + wdba_complement(const const_tgba_ptr& aut) { - return new tgba_wdba_comp_proxy(aut); + return std::make_shared(aut); } } diff --git a/src/tgba/wdbacomp.hh b/src/tgba/wdbacomp.hh index 52c078ca6..ba739df9a 100644 --- a/src/tgba/wdbacomp.hh +++ b/src/tgba/wdbacomp.hh @@ -1,5 +1,5 @@ // -*- coding: utf-8 -*- -// Copyright (C) 2011, 2013 Laboratoire de Recherche et Développement +// Copyright (C) 2011, 2013, 2014 Laboratoire de Recherche et Développement // de l'Epita. // // This file is part of Spot, a model checking library. @@ -28,8 +28,8 @@ namespace spot /// \brief Complement a weak deterministic Büchi automaton /// \param aut a weak deterministic Büchi automaton to complement /// \return a new automaton that recognizes the complement language - SPOT_API tgba* - wdba_complement(const tgba* aut); + SPOT_API const_tgba_ptr + wdba_complement(const const_tgba_ptr& aut); } #endif diff --git a/src/tgbaalgos/bfssteps.cc b/src/tgbaalgos/bfssteps.cc index eb9eb4db4..d7f125419 100644 --- a/src/tgbaalgos/bfssteps.cc +++ b/src/tgbaalgos/bfssteps.cc @@ -25,7 +25,7 @@ namespace spot { - bfs_steps::bfs_steps(const tgba* a) + bfs_steps::bfs_steps(const const_tgba_ptr& a) : a_(a) { } diff --git a/src/tgbaalgos/bfssteps.hh b/src/tgbaalgos/bfssteps.hh index 134865583..9e2caea81 100644 --- a/src/tgbaalgos/bfssteps.hh +++ b/src/tgbaalgos/bfssteps.hh @@ -1,5 +1,5 @@ // -*- coding: utf-8 -*- -// Copyright (C) 2011, 2013 Laboratoire de Recherche et Developpement de +// Copyright (C) 2011, 2013, 2014 Laboratoire de Recherche et Developpement de // l'Epita (LRDE). // Copyright (C) 2004, 2005 Laboratoire d'Informatique de Paris 6 (LIP6), // département Systèmes Répartis Coopératifs (SRC), Université Pierre @@ -42,7 +42,7 @@ namespace spot class SPOT_API bfs_steps { public: - bfs_steps(const tgba* a); + bfs_steps(const const_tgba_ptr& a); virtual ~bfs_steps(); /// \brief Start the search from \a start, and append the @@ -99,7 +99,7 @@ namespace spot tgba_run::steps& l); protected: - const tgba* a_; ///< The spot::tgba we are searching into. + const_tgba_ptr a_; ///< The spot::tgba we are searching into. }; diff --git a/src/tgbaalgos/complete.cc b/src/tgbaalgos/complete.cc index 9b58f695c..2e29b40a2 100644 --- a/src/tgbaalgos/complete.cc +++ b/src/tgbaalgos/complete.cc @@ -22,7 +22,7 @@ namespace spot { - unsigned tgba_complete_here(tgba_digraph* aut) + unsigned tgba_complete_here(tgba_digraph_ptr aut) { unsigned n = aut->num_states(); unsigned sink = -1U; @@ -99,9 +99,9 @@ namespace spot return sink; } - tgba_digraph* tgba_complete(const tgba* aut) + tgba_digraph_ptr tgba_complete(const const_tgba_ptr& aut) { - tgba_digraph* res = tgba_dupexp_dfs(aut); + tgba_digraph_ptr res = tgba_dupexp_dfs(aut); tgba_complete_here(res); return res; } diff --git a/src/tgbaalgos/complete.hh b/src/tgbaalgos/complete.hh index 9a0216f09..34fedca8c 100644 --- a/src/tgbaalgos/complete.hh +++ b/src/tgbaalgos/complete.hh @@ -31,12 +31,12 @@ namespace spot /// state added for completion, or an existing non-accepting state /// that has been reused as sink state because it had not outgoing /// transitions apart from self-loops.) - SPOT_API unsigned tgba_complete_here(tgba_digraph* aut); + SPOT_API unsigned tgba_complete_here(tgba_digraph_ptr aut); /// \brief Clone a tgba and complete it. /// /// If the tgba has no acceptance set, one will be added. - SPOT_API tgba_digraph* tgba_complete(const tgba* aut); + SPOT_API tgba_digraph_ptr tgba_complete(const const_tgba_ptr& aut); } #endif // SPOT_TGBAALGOS_COMPLETE_HH diff --git a/src/tgbaalgos/compsusp.cc b/src/tgbaalgos/compsusp.cc index 43eb76caf..43a101eb0 100644 --- a/src/tgbaalgos/compsusp.cc +++ b/src/tgbaalgos/compsusp.cc @@ -212,18 +212,15 @@ namespace spot typedef std::deque pair_queue; static - tgba_digraph* - susp_prod(tgba* left, const ltl::formula* f, bdd v) + tgba_digraph_ptr + susp_prod(const const_tgba_ptr& left, const ltl::formula* f, bdd v) { bdd_dict_ptr dict = left->get_dict(); - const tgba_digraph* a1 = ltl_to_tgba_fm(f, dict, true, true); + auto right = + iterated_simulations(scc_filter(ltl_to_tgba_fm(f, dict, true, true), + false)); - const tgba_digraph* a2 = scc_filter(a1, false); - delete a1; - const tgba_digraph* right = iterated_simulations(a2); - delete a2; - - tgba_digraph* res = new tgba_digraph(dict); + tgba_digraph_ptr res = make_tgba_digraph(dict); dict->register_all_variables_of(left, res); dict->register_all_variables_of(right, res); dict->unregister_variable(bdd_var(v), res); @@ -342,14 +339,12 @@ namespace spot right->release_iter(ri); } } - delete left; - delete right; return res; } } - tgba_digraph* + tgba_digraph_ptr compsusp(const ltl::formula* f, bdd_dict_ptr dict, bool no_wdba, bool no_simulation, bool early_susp, bool no_susp_product, bool wdba_smaller, @@ -360,32 +355,23 @@ namespace spot ltl_suspender_visitor v(g2s, a2o, oblig); const ltl::formula* g = v.recurse(f); - tgba_digraph* res; - { - // Translate the patched formula, and remove useless SCCs. - tgba_digraph* aut = - spot::ltl_to_tgba_fm(g, dict, true, true, false, false, 0, 0); - res = scc_filter(aut, false); - delete aut; - } + // Translate the patched formula, and remove useless SCCs. + tgba_digraph_ptr res = + scc_filter(ltl_to_tgba_fm(g, dict, true, true, false, false, 0, 0), + false); if (!no_wdba) { - tgba_digraph* min = minimize_obligation(res, g, 0, wdba_smaller); + tgba_digraph_ptr min = minimize_obligation(res, g, 0, wdba_smaller); if (min != res) { - delete res; res = min; no_simulation = true; } } if (!no_simulation) - { - tgba_digraph* sim = spot::iterated_simulations(res); - delete res; - res = sim; - } + res = iterated_simulations(res); // Create a map of suspended formulae to BDD variables. spot::formula_bdd_map susp; @@ -409,9 +395,8 @@ namespace spot suspvars &= i->second; bdd allaccap = bddtrue; // set of atomic prop used in accepting SCCs. - tgba_digraph* aut = res; { - scc_info si(aut); + scc_info si(res); // Restrict suspvars to the set of suspension labels that occur // in accepting SCC. @@ -422,9 +407,8 @@ namespace spot bdd ignored = bdd_exist(suspvars, allaccap); suspvars = bdd_existcomp(suspvars, allaccap); - res = scc_filter_susp(aut, false, suspvars, ignored, early_susp, &si); + res = scc_filter_susp(res, false, suspvars, ignored, early_susp, &si); } - delete aut; // Do we need to synchronize any suspended formula? if (!susp.empty() && !no_susp_product) diff --git a/src/tgbaalgos/compsusp.hh b/src/tgbaalgos/compsusp.hh index 28a43d687..4000393c7 100644 --- a/src/tgbaalgos/compsusp.hh +++ b/src/tgbaalgos/compsusp.hh @@ -50,7 +50,7 @@ namespace spot /// This interface is subject to change, and clients aiming for /// long-term stability should better use the services of the /// spot::translator class instead. - SPOT_API tgba_digraph* + SPOT_API tgba_digraph_ptr compsusp(const ltl::formula* f, bdd_dict_ptr dict, bool no_wdba = false, bool no_simulation = false, bool early_susp = false, bool no_susp_product = false, diff --git a/src/tgbaalgos/cycles.hh b/src/tgbaalgos/cycles.hh index 63ffc7ddd..c72158c47 100644 --- a/src/tgbaalgos/cycles.hh +++ b/src/tgbaalgos/cycles.hh @@ -112,7 +112,7 @@ namespace spot typedef hash_type::iterator tagged_state; // The automaton we are working on. - const tgba* aut_; + const_tgba_ptr aut_; // The SCC map built for aut_. const scc_map& sm_; diff --git a/src/tgbaalgos/degen.cc b/src/tgbaalgos/degen.cc index b47e82586..b76602af6 100644 --- a/src/tgbaalgos/degen.cc +++ b/src/tgbaalgos/degen.cc @@ -71,7 +71,7 @@ namespace spot // SCC -- we do not care about the other) of some state. class outgoing_acc { - const tgba* a_; + const_tgba_ptr a_; typedef std::pair cache_entry; typedef std::unordered_map cache_t; @@ -79,7 +79,7 @@ namespace spot const scc_map* sm_; public: - outgoing_acc(const tgba* a, const scc_map* sm): a_(a), sm_(sm) + outgoing_acc(const const_tgba_ptr& a, const scc_map* sm): a_(a), sm_(sm) { } @@ -128,14 +128,14 @@ namespace spot // Check whether a state has an accepting self-loop, with a catch. class has_acc_loop { - const tgba* a_; + const_tgba_ptr a_; typedef std::unordered_map cache_t; cache_t cache_; state_unicity_table& uniq_; public: - has_acc_loop(const tgba* a, state_unicity_table& uniq): + has_acc_loop(const const_tgba_ptr& a, state_unicity_table& uniq): a_(a), uniq_(uniq) { @@ -250,16 +250,17 @@ namespace spot }; template - tgba_digraph* - degeneralize_aux(const tgba* a, bool use_z_lvl, bool use_cust_acc_orders, - int use_lvl_cache, bool skip_levels) + tgba_digraph_ptr + degeneralize_aux(const const_tgba_ptr& a, bool use_z_lvl, + bool use_cust_acc_orders, int use_lvl_cache, + bool skip_levels) { bool use_scc = use_lvl_cache || use_cust_acc_orders || use_z_lvl; bdd_dict_ptr dict = a->get_dict(); // The result automaton is an SBA. - auto res = new tgba_digraph(dict); + auto res = make_tgba_digraph(dict); res->copy_ap_of(a); res->set_single_acceptance_set(); if (want_sba) @@ -616,16 +617,18 @@ namespace spot } } - tgba_digraph* - degeneralize(const tgba* a, bool use_z_lvl, bool use_cust_acc_orders, + tgba_digraph_ptr + degeneralize(const const_tgba_ptr& a, + bool use_z_lvl, bool use_cust_acc_orders, int use_lvl_cache, bool skip_levels) { return degeneralize_aux(a, use_z_lvl, use_cust_acc_orders, use_lvl_cache, skip_levels); } - tgba_digraph* - degeneralize_tba(const tgba* a, bool use_z_lvl, bool use_cust_acc_orders, + tgba_digraph_ptr + degeneralize_tba(const const_tgba_ptr& a, + bool use_z_lvl, bool use_cust_acc_orders, int use_lvl_cache, bool skip_levels) { return degeneralize_aux(a, use_z_lvl, use_cust_acc_orders, diff --git a/src/tgbaalgos/degen.hh b/src/tgbaalgos/degen.hh index 4774330fc..75808b238 100644 --- a/src/tgbaalgos/degen.hh +++ b/src/tgbaalgos/degen.hh @@ -48,14 +48,14 @@ namespace spot /// The degeneralize_tba() variant produce a degeneralized automaton /// with transition-based acceptance. /// \@{ - SPOT_API tgba_digraph* - degeneralize(const tgba* a, bool use_z_lvl = true, + SPOT_API tgba_digraph_ptr + degeneralize(const const_tgba_ptr& a, bool use_z_lvl = true, bool use_cust_acc_orders = false, int use_lvl_cache = 1, bool skip_levels = true); - SPOT_API tgba_digraph* - degeneralize_tba(const tgba* a, bool use_z_lvl = true, + SPOT_API tgba_digraph_ptr + degeneralize_tba(const const_tgba_ptr& a, bool use_z_lvl = true, bool use_cust_acc_orders = false, int use_lvl_cache = 1, bool skip_levels = true); diff --git a/src/tgbaalgos/dotty.cc b/src/tgbaalgos/dotty.cc index 7cd9b1770..db6f42fbb 100644 --- a/src/tgbaalgos/dotty.cc +++ b/src/tgbaalgos/dotty.cc @@ -37,11 +37,11 @@ namespace spot class dotty_bfs : public tgba_reachable_iterator_breadth_first { public: - dotty_bfs(std::ostream& os, const tgba* a, bool mark_accepting_states, + dotty_bfs(std::ostream& os, const_tgba_ptr a, bool mark_accepting_states, dotty_decorator* dd) : tgba_reachable_iterator_breadth_first(a), os_(os), mark_accepting_states_(mark_accepting_states), dd_(dd), - sba_(dynamic_cast(a)) + sba_(std::dynamic_pointer_cast(a)) { } @@ -119,17 +119,17 @@ namespace spot std::ostream& os_; bool mark_accepting_states_; dotty_decorator* dd_; - const tgba_digraph* sba_; + const_tgba_digraph_ptr sba_; }; } std::ostream& - dotty_reachable(std::ostream& os, const tgba* g, + dotty_reachable(std::ostream& os, const const_tgba_ptr& g, bool assume_sba, dotty_decorator* dd) { if (!dd) dd = dotty_decorator::instance(); - if (const tgba_digraph* gd = dynamic_cast(g)) + if (auto gd = dynamic_cast(g.get())) assume_sba |= gd->get_bprop(tgba_digraph::StateBasedAcc); dotty_bfs d(os, g, assume_sba, dd); diff --git a/src/tgbaalgos/dotty.hh b/src/tgbaalgos/dotty.hh index 7fc6a39e2..6405adadb 100644 --- a/src/tgbaalgos/dotty.hh +++ b/src/tgbaalgos/dotty.hh @@ -1,5 +1,5 @@ // -*- coding: utf-8 -*- -// Copyright (C) 2011, 2012, 2013 Laboratoire de Recherche et +// Copyright (C) 2011, 2012, 2013, 2014 Laboratoire de Recherche et // Developpement de l'Epita (LRDE). // Copyright (C) 2003, 2004 Laboratoire d'Informatique de Paris 6 (LIP6), // département Systèmes Répartis Coopératifs (SRC), Université Pierre @@ -24,6 +24,7 @@ # define SPOT_TGBAALGOS_DOTTY_HH # include +# include # include "misc/common.hh" namespace spot @@ -44,7 +45,7 @@ namespace spot /// labels the transitions are encoded in UTF-8. SPOT_API std::ostream& dotty_reachable(std::ostream& os, - const tgba* g, + const const_tgba_ptr& g, bool assume_sba = false, dotty_decorator* dd = 0); } diff --git a/src/tgbaalgos/dottydec.cc b/src/tgbaalgos/dottydec.cc index 110fe6b47..337ab645e 100644 --- a/src/tgbaalgos/dottydec.cc +++ b/src/tgbaalgos/dottydec.cc @@ -1,7 +1,8 @@ -// Copyright (C) 2011 Laboratoire de Recherche et Developpement de +// -*- coding: utf-8 -*- +// Copyright (C) 2011, 2014 Laboratoire de Recherche et Developpement de // l'Epita (LRDE). // Copyright (C) 2004 Laboratoire d'Informatique de Paris 6 (LIP6), -// département Systèmes Répartis Coopératifs (SRC), Université Pierre +// département Systèmes Répartis Coopératifs (SRC), Université Pierre // et Marie Curie. // // This file is part of Spot, a model checking library. @@ -33,7 +34,7 @@ namespace spot } std::string - dotty_decorator::state_decl(const tgba*, const state*, int, + dotty_decorator::state_decl(const const_tgba_ptr&, const state*, int, tgba_succ_iterator*, const std::string& label, bool accepting) { @@ -44,7 +45,8 @@ namespace spot } std::string - dotty_decorator::link_decl(const tgba*, const state*, int, const state*, int, + dotty_decorator::link_decl(const const_tgba_ptr&, const state*, int, + const state*, int, const tgba_succ_iterator*, const std::string& label) { diff --git a/src/tgbaalgos/dottydec.hh b/src/tgbaalgos/dottydec.hh index 71b34f00e..eff5104c7 100644 --- a/src/tgbaalgos/dottydec.hh +++ b/src/tgbaalgos/dottydec.hh @@ -1,5 +1,5 @@ // -*- coding: utf-8 -*- -// Copyright (C) 2011, 2013 Laboratoire de Recherche et +// Copyright (C) 2011, 2013, 2014 Laboratoire de Recherche et // Developpement de l'Epita (LRDE). // Copyright (C) 2004 Laboratoire d'Informatique de Paris 6 (LIP6), // département Systèmes Répartis Coopératifs (SRC), Université Pierre @@ -25,11 +25,11 @@ # include "misc/common.hh" # include +# include namespace spot { class state; - class tgba; class tgba_succ_iterator; /// \addtogroup tgba_dotty Decorating the dot output @@ -57,7 +57,8 @@ namespace spot /// \param label the computed name of this state /// \param accepting whether the state is accepting (it makes sense only /// for state-acceptance automata) - virtual std::string state_decl(const tgba* a, const state* s, int n, + virtual std::string state_decl(const const_tgba_ptr& a, + const state* s, int n, tgba_succ_iterator* si, const std::string& label, bool accepting); @@ -80,7 +81,7 @@ namespace spot /// the current transition (owned by the caller and cannot /// be iterated) /// \param label the computed name of this state - virtual std::string link_decl(const tgba* a, + virtual std::string link_decl(const const_tgba_ptr& a, const state* in_s, int in, const state* out_s, int out, const tgba_succ_iterator* si, diff --git a/src/tgbaalgos/dtbasat.cc b/src/tgbaalgos/dtbasat.cc index 3217733b5..fb7c3210d 100644 --- a/src/tgbaalgos/dtbasat.cc +++ b/src/tgbaalgos/dtbasat.cc @@ -237,7 +237,7 @@ namespace spot bool state_based_; scc_map& sm_; public: - filler_dfs(const tgba* aut, dict& d, bdd ap, bool state_based, + filler_dfs(const const_tgba_ptr& aut, dict& d, bdd ap, bool state_based, scc_map& sm) : tgba_reachable_iterator_depth_first(aut), d(d), ap_(ap), state_based_(state_based), sm_(sm) @@ -324,7 +324,7 @@ namespace spot typedef std::pair sat_stats; static - sat_stats dtba_to_sat(std::ostream& out, const tgba* ref, + sat_stats dtba_to_sat(std::ostream& out, const_tgba_ptr ref, dict& d, bool state_based) { clause_counter nclauses; @@ -665,12 +665,12 @@ namespace spot return std::make_pair(d.nvars, nclauses.nb_clauses()); } - static tgba_digraph* + static tgba_digraph_ptr sat_build(const satsolver::solution& solution, dict& satdict, - const tgba* aut, bool state_based) + const_tgba_ptr aut, bool state_based) { auto autdict = aut->get_dict(); - auto a = new tgba_digraph(autdict); + auto a = make_tgba_digraph(autdict); a->copy_ap_of(aut); bdd acc = a->set_single_acceptance_set(); a->new_states(satdict.cand_size); @@ -769,8 +769,8 @@ namespace spot } } - tgba_digraph* - dtba_sat_synthetize(const tgba* a, int target_state_number, + tgba_digraph_ptr + dtba_sat_synthetize(const const_tgba_ptr& a, int target_state_number, bool state_based) { if (target_state_number == 0) @@ -791,7 +791,7 @@ namespace spot solution = solver.get_solution(); t.stop("solve"); - tgba_digraph* res = nullptr; + tgba_digraph_ptr res = nullptr; if (!solution.second.empty()) res = sat_build(solution.second, d, a, state_based); @@ -827,46 +827,42 @@ namespace spot return res; } - tgba_digraph* - dtba_sat_minimize(const tgba* a, bool state_based) + tgba_digraph_ptr + dtba_sat_minimize(const const_tgba_ptr& a, bool state_based) { int n_states = stats_reachable(a).states; - tgba_digraph* prev = nullptr; + tgba_digraph_ptr prev = nullptr; for (;;) { - tgba_digraph* next = + auto next = dtba_sat_synthetize(prev ? prev : a, --n_states, state_based); if (!next) - break; + return prev; else n_states = stats_reachable(next).states; - - delete prev; prev = next; } - return prev; + SPOT_UNREACHABLE(); } - tgba_digraph* - dtba_sat_minimize_dichotomy(const tgba* a, bool state_based) + tgba_digraph_ptr + dtba_sat_minimize_dichotomy(const const_tgba_ptr& a, bool state_based) { int max_states = stats_reachable(a).states - 1; int min_states = 1; - tgba_digraph* prev = nullptr; + tgba_digraph_ptr prev = nullptr; while (min_states <= max_states) { int target = (max_states + min_states) / 2; - tgba_digraph* next = - dtba_sat_synthetize(prev ? prev : a, target, state_based); + auto next = dtba_sat_synthetize(prev ? prev : a, target, state_based); if (!next) { min_states = target + 1; } else { - delete prev; prev = next; max_states = stats_reachable(next).states - 1; } diff --git a/src/tgbaalgos/dtbasat.hh b/src/tgbaalgos/dtbasat.hh index b9103a70b..65edfa939 100644 --- a/src/tgbaalgos/dtbasat.hh +++ b/src/tgbaalgos/dtbasat.hh @@ -40,8 +40,9 @@ namespace spot /// /// If no equivalent deterministic TBA with \a target_state_number /// states is found, a null pointer - SPOT_API tgba_digraph* - dtba_sat_synthetize(const tgba* a, int target_state_number, + SPOT_API tgba_digraph_ptr + dtba_sat_synthetize(const const_tgba_ptr& a, + int target_state_number, bool state_based = false); /// \brief Attempt to minimize a deterministic TBA with a SAT solver. @@ -50,8 +51,8 @@ namespace spot /// number of states, and returns the last successfully built TBA. /// /// If no smaller TBA exist, this returns a null pointer. - SPOT_API tgba_digraph* - dtba_sat_minimize(const tgba* a, bool state_based = false); + SPOT_API tgba_digraph_ptr + dtba_sat_minimize(const const_tgba_ptr& a, bool state_based = false); /// \brief Attempt to minimize a deterministic TBA with a SAT solver. /// @@ -59,8 +60,9 @@ namespace spot /// find the minimum number of states using a binary search. // /// If no smaller TBA exist, this returns a null pointer. - SPOT_API tgba_digraph* - dtba_sat_minimize_dichotomy(const tgba* a, bool state_based = false); + SPOT_API tgba_digraph_ptr + dtba_sat_minimize_dichotomy(const const_tgba_ptr& a, + bool state_based = false); } #endif // SPOT_TGBAALGOS_DTBASAT_HH diff --git a/src/tgbaalgos/dtgbacomp.cc b/src/tgbaalgos/dtgbacomp.cc index 32d9828a4..b96dd7433 100644 --- a/src/tgbaalgos/dtgbacomp.cc +++ b/src/tgbaalgos/dtgbacomp.cc @@ -22,10 +22,10 @@ namespace spot { - tgba_digraph* dtgba_complement(const tgba* aut) + tgba_digraph_ptr dtgba_complement(const const_tgba_ptr& aut) { // Clone the original automaton. - tgba_digraph* res = tgba_dupexp_dfs(aut); + tgba_digraph_ptr res = tgba_dupexp_dfs(aut); bdd oldaccs = aut->all_acceptance_conditions(); bdd oldnegs = aut->neg_acceptance_conditions(); diff --git a/src/tgbaalgos/dtgbacomp.hh b/src/tgbaalgos/dtgbacomp.hh index 0ca3269fa..0316b9fc2 100644 --- a/src/tgbaalgos/dtgbacomp.hh +++ b/src/tgbaalgos/dtgbacomp.hh @@ -30,8 +30,8 @@ namespace spot /// to be complete. Acceptance can be transition-based, or /// state-based. The resulting automaton is very unlikely to be /// deterministic. - SPOT_API tgba_digraph* - dtgba_complement(const tgba* aut); + SPOT_API tgba_digraph_ptr + dtgba_complement(const const_tgba_ptr& aut); } #endif // SPOT_TGBAALGOS_DTGBACOMP_HH diff --git a/src/tgbaalgos/dtgbasat.cc b/src/tgbaalgos/dtgbasat.cc index 3b7984a35..0502f3af6 100644 --- a/src/tgbaalgos/dtgbasat.cc +++ b/src/tgbaalgos/dtgbasat.cc @@ -243,12 +243,12 @@ namespace spot struct dict { - dict(const tgba* a) + dict(const const_tgba_ptr& a) : aut(a) { } - const tgba* aut; + const_tgba_ptr aut; typedef std::map trans_map; typedef std::map trans_acc_map; trans_map transid; @@ -296,7 +296,7 @@ namespace spot bool state_based_; scc_map& sm_; public: - filler_dfs(const tgba* aut, dict& d, bdd ap, bool state_based, + filler_dfs(const const_tgba_ptr& aut, dict& d, bdd ap, bool state_based, scc_map& sm) : tgba_reachable_iterator_depth_first(aut), d(d), ap_(ap), state_based_(state_based), sm_(sm) @@ -466,7 +466,7 @@ namespace spot typedef std::pair sat_stats; static - sat_stats dtgba_to_sat(std::ostream& out, const tgba* ref, + sat_stats dtgba_to_sat(std::ostream& out, const_tgba_ptr ref, dict& d, bool state_based) { clause_counter nclauses; @@ -837,12 +837,12 @@ namespace spot return std::make_pair(d.nvars, nclauses.nb_clauses()); } - static tgba_digraph* + static tgba_digraph_ptr sat_build(const satsolver::solution& solution, dict& satdict, - const tgba* aut, bool state_based) + const_tgba_ptr aut, bool state_based) { auto autdict = aut->get_dict(); - auto a = new tgba_digraph(autdict); + auto a = make_tgba_digraph(autdict); a->copy_ap_of(aut); a->set_acceptance_conditions(satdict.all_cand_acc.back()); @@ -935,9 +935,9 @@ namespace spot } } - tgba_digraph* - dtgba_sat_synthetize(const tgba* a, unsigned target_acc_number, - int target_state_number, bool state_based) + tgba_digraph_ptr + dtgba_sat_synthetize (const const_tgba_ptr& a, unsigned target_acc_number, + int target_state_number, bool state_based) { if (target_state_number == 0) return nullptr; @@ -960,7 +960,7 @@ namespace spot solution = solver.get_solution(); t.stop("solve"); - tgba_digraph* res = nullptr; + tgba_digraph_ptr res = nullptr; if (!solution.second.empty()) res = sat_build(solution.second, d, a, state_based); @@ -996,40 +996,41 @@ namespace spot return res; } - tgba_digraph* - dtgba_sat_minimize(const tgba* a, unsigned target_acc_number, + tgba_digraph_ptr + dtgba_sat_minimize(const const_tgba_ptr& a, + unsigned target_acc_number, bool state_based) { int n_states = stats_reachable(a).states; - tgba_digraph* prev = nullptr; + tgba_digraph_ptr prev = nullptr; for (;;) { - tgba_digraph* next = + auto next = dtgba_sat_synthetize(prev ? prev : a, target_acc_number, --n_states, state_based); if (!next) - break; + return prev; else n_states = stats_reachable(next).states; - delete prev; prev = next; } - return prev; + SPOT_UNREACHABLE(); } - tgba_digraph* - dtgba_sat_minimize_dichotomy(const tgba* a, unsigned target_acc_number, + tgba_digraph_ptr + dtgba_sat_minimize_dichotomy(const const_tgba_ptr& a, + unsigned target_acc_number, bool state_based) { int max_states = stats_reachable(a).states - 1; int min_states = 1; - tgba_digraph* prev = nullptr; + tgba_digraph_ptr prev = nullptr; while (min_states <= max_states) { int target = (max_states + min_states) / 2; - tgba_digraph* next = + auto next = dtgba_sat_synthetize(prev ? prev : a, target_acc_number, target, state_based); if (!next) @@ -1038,7 +1039,6 @@ namespace spot } else { - delete prev; prev = next; max_states = stats_reachable(next).states - 1; } diff --git a/src/tgbaalgos/dtgbasat.hh b/src/tgbaalgos/dtgbasat.hh index 63b684eb7..241dbc733 100644 --- a/src/tgbaalgos/dtgbasat.hh +++ b/src/tgbaalgos/dtgbasat.hh @@ -44,8 +44,9 @@ namespace spot /// acceptance sets and target_state_number states that is /// equivalent to \a a. If no such TGBA is found, a null pointer is /// returned. - SPOT_API tgba_digraph* - dtgba_sat_synthetize(const tgba* a, unsigned target_acc_number, + SPOT_API tgba_digraph_ptr + dtgba_sat_synthetize(const const_tgba_ptr& a, + unsigned target_acc_number, int target_state_number, bool state_based = false); @@ -55,8 +56,9 @@ namespace spot /// number of states, and returns the last successfully built TGBA. /// /// If no smaller TGBA exist, this returns a null pointer. - SPOT_API tgba_digraph* - dtgba_sat_minimize(const tgba* a, unsigned target_acc_number, + SPOT_API tgba_digraph_ptr + dtgba_sat_minimize(const const_tgba_ptr& a, + unsigned target_acc_number, bool state_based = false); /// \brief Attempt to minimize a deterministic TGBA with a SAT solver. @@ -65,8 +67,9 @@ namespace spot /// find the minimum number of states using a binary search. // /// If no smaller TBA exist, this returns a null pointer. - SPOT_API tgba_digraph* - dtgba_sat_minimize_dichotomy(const tgba* a, unsigned target_acc_number, + SPOT_API tgba_digraph_ptr + dtgba_sat_minimize_dichotomy(const const_tgba_ptr& a, + unsigned target_acc_number, bool state_based = false); } diff --git a/src/tgbaalgos/dupexp.cc b/src/tgbaalgos/dupexp.cc index 5ad9bee17..952b8b17b 100644 --- a/src/tgbaalgos/dupexp.cc +++ b/src/tgbaalgos/dupexp.cc @@ -34,14 +34,14 @@ namespace spot class dupexp_iter: public T { public: - dupexp_iter(const tgba* a) - : T(a), out_(new tgba_digraph(a->get_dict())) + dupexp_iter(const const_tgba_ptr& a) + : T(a), out_(make_tgba_digraph(a->get_dict())) { out_->copy_acceptance_conditions_of(a); out_->copy_ap_of(a); } - tgba_digraph* + tgba_digraph_ptr result() { return out_; @@ -66,14 +66,15 @@ namespace spot } protected: - tgba_digraph* out_; + tgba_digraph_ptr out_; }; template class dupexp_iter_save: public dupexp_iter { public: - dupexp_iter_save(const tgba* a, std::vector& relation) + dupexp_iter_save(const const_tgba_ptr& a, + std::vector& relation) : dupexp_iter(a), relation_(relation) { } @@ -91,32 +92,32 @@ namespace spot } // anonymous - tgba_digraph* - tgba_dupexp_bfs(const tgba* aut) + tgba_digraph_ptr + tgba_dupexp_bfs(const const_tgba_ptr& aut) { dupexp_iter di(aut); di.run(); return di.result(); } - tgba_digraph* - tgba_dupexp_dfs(const tgba* aut) + tgba_digraph_ptr + tgba_dupexp_dfs(const const_tgba_ptr& aut) { dupexp_iter di(aut); di.run(); return di.result(); } - tgba_digraph* - tgba_dupexp_bfs(const tgba* aut, std::vector& rel) + tgba_digraph_ptr + tgba_dupexp_bfs(const const_tgba_ptr& aut, std::vector& rel) { dupexp_iter_save di(aut, rel); di.run(); return di.result(); } - tgba_digraph* - tgba_dupexp_dfs(const tgba* aut, std::vector& rel) + tgba_digraph_ptr + tgba_dupexp_dfs(const const_tgba_ptr& aut, std::vector& rel) { dupexp_iter_save di(aut, rel); di.run(); diff --git a/src/tgbaalgos/dupexp.hh b/src/tgbaalgos/dupexp.hh index a0aedce66..cbd1b6bc7 100644 --- a/src/tgbaalgos/dupexp.hh +++ b/src/tgbaalgos/dupexp.hh @@ -30,13 +30,13 @@ namespace spot /// \ingroup tgba_misc /// \brief Build an explicit automaton from all states of \a aut, /// numbering states in bread first order as they are processed. - SPOT_API tgba_digraph* - tgba_dupexp_bfs(const tgba* aut); + SPOT_API tgba_digraph_ptr + tgba_dupexp_bfs(const const_tgba_ptr& aut); /// \ingroup tgba_misc /// \brief Build an explicit automaton from all states of \a aut, /// numbering states in depth first order as they are processed. - SPOT_API tgba_digraph* - tgba_dupexp_dfs(const tgba* aut); + SPOT_API tgba_digraph_ptr + tgba_dupexp_dfs(const const_tgba_ptr& aut); /// \ingroup tgba_misc /// \brief Build an explicit automaton from all states of \a aut, @@ -44,8 +44,9 @@ namespace spot /// \a aut the automaton to duplicate /// \a relation a map of all the new states (represented by /// their number) to the old states. - SPOT_API tgba_digraph* - tgba_dupexp_bfs(const tgba* aut, std::vector& relation); + SPOT_API tgba_digraph_ptr + tgba_dupexp_bfs(const const_tgba_ptr& aut, + std::vector& relation); /// \ingroup tgba_misc /// \brief Build an explicit automata from all states of \a aut, @@ -53,8 +54,9 @@ namespace spot /// \a aut the automaton to duplicate /// \a relation a map of all the new states (represented by /// their number) to the old states. - SPOT_API tgba_digraph* - tgba_dupexp_dfs(const tgba* aut, std::vector& relation); + SPOT_API tgba_digraph_ptr + tgba_dupexp_dfs(const const_tgba_ptr& aut, + std::vector& relation); } #endif // SPOT_TGBAALGOS_DUPEXP_HH diff --git a/src/tgbaalgos/emptiness.cc b/src/tgbaalgos/emptiness.cc index 9898790cf..524faccb0 100644 --- a/src/tgbaalgos/emptiness.cc +++ b/src/tgbaalgos/emptiness.cc @@ -77,7 +77,7 @@ namespace spot std::ostream& print_tgba_run(std::ostream& os, - const tgba* a, + const_tgba_ptr a, const tgba_run* run) { bdd_dict_ptr d = a->get_dict(); @@ -180,17 +180,16 @@ namespace spot namespace { - - spot::emptiness_check* - couvreur99_cons(const spot::tgba* a, spot::option_map o) + emptiness_check* + make_couvreur99(const const_tgba_ptr& a, spot::option_map o) { - return spot::couvreur99(a, o); + return couvreur99(a, o); } struct ec_algo { const char* name; - spot::emptiness_check* (*construct)(const spot::tgba*, + spot::emptiness_check* (*construct)(const const_tgba_ptr&, spot::option_map); unsigned int min_acc; unsigned int max_acc; @@ -198,7 +197,7 @@ namespace spot ec_algo ec_algos[] = { - { "Cou99", couvreur99_cons, 0, -1U }, + { "Cou99", make_couvreur99, 0, -1U }, { "CVWY90", spot::magic_search, 0, 1 }, { "GV04", spot::explicit_gv04_check, 0, 1 }, { "SE05", spot::se05, 0, 1 }, @@ -226,7 +225,7 @@ namespace spot } emptiness_check* - emptiness_check_instantiator::instantiate(const tgba* a) const + emptiness_check_instantiator::instantiate(const const_tgba_ptr& a) const { return static_cast(info_)->construct(a, o_); } @@ -282,11 +281,11 @@ namespace spot // tgba_run_to_tgba ////////////////////////////////////////////////////////////////////// - tgba_digraph* - tgba_run_to_tgba(const tgba* a, const tgba_run* run) + tgba_digraph_ptr + tgba_run_to_tgba(const const_tgba_ptr& a, const tgba_run* run) { auto d = a->get_dict(); - auto res = new tgba_digraph(d); + auto res = make_tgba_digraph(d); res->copy_ap_of(a); res->copy_acceptance_conditions_of(a); diff --git a/src/tgbaalgos/emptiness.hh b/src/tgbaalgos/emptiness.hh index 8666aedfc..c5621f7aa 100644 --- a/src/tgbaalgos/emptiness.hh +++ b/src/tgbaalgos/emptiness.hh @@ -78,7 +78,8 @@ namespace spot class SPOT_API emptiness_check_result { public: - emptiness_check_result(const tgba* a, option_map o = option_map()) + emptiness_check_result(const const_tgba_ptr& a, + option_map o = option_map()) : a_(a), o_(o) { } @@ -103,7 +104,7 @@ namespace spot virtual tgba_run* accepting_run(); /// The automaton on which an accepting_run() was found. - const tgba* + const const_tgba_ptr& automaton() const { return a_; @@ -126,7 +127,7 @@ namespace spot /// Notify option updates. virtual void options_updated(const option_map& old); - const tgba* a_; ///< The automaton. + const_tgba_ptr a_; ///< The automaton. option_map o_; ///< The options. }; @@ -134,14 +135,14 @@ namespace spot class SPOT_API emptiness_check { public: - emptiness_check(const tgba* a, option_map o = option_map()) + emptiness_check(const const_tgba_ptr& a, option_map o = option_map()) : a_(a), o_(o) { } virtual ~emptiness_check(); /// The automaton that this emptiness-check inspects. - const tgba* + const const_tgba_ptr& automaton() const { return a_; @@ -186,7 +187,7 @@ namespace spot virtual void options_updated(const option_map& old); protected: - const tgba* a_; ///< The automaton. + const_tgba_ptr a_; ///< The automaton. option_map o_; ///< The options }; @@ -208,7 +209,7 @@ namespace spot const char** err); /// Actually instantiate the emptiness check, for \a a. - emptiness_check* instantiate(const tgba* a) const; + emptiness_check* instantiate(const const_tgba_ptr& a) const; /// Accessor to the options. /// @{ @@ -288,14 +289,14 @@ namespace spot /// actually exists in the automaton (and will also display any /// transition annotation). SPOT_API std::ostream& - print_tgba_run(std::ostream& os, const tgba* a, const tgba_run* run); + print_tgba_run(std::ostream& os, const_tgba_ptr a, const tgba_run* run); /// \brief Return an explicit_tgba corresponding to \a run (i.e. comparable /// states are merged). /// /// \pre \a run must correspond to an actual run of the automaton \a a. - SPOT_API tgba_digraph* - tgba_run_to_tgba(const tgba* a, const tgba_run* run); + SPOT_API tgba_digraph_ptr + tgba_run_to_tgba(const const_tgba_ptr& a, const tgba_run* run); /// @} diff --git a/src/tgbaalgos/gtec/gtec.cc b/src/tgbaalgos/gtec/gtec.cc index acf631fa9..3d47ccca4 100644 --- a/src/tgbaalgos/gtec/gtec.cc +++ b/src/tgbaalgos/gtec/gtec.cc @@ -40,7 +40,7 @@ namespace spot typedef std::pair pair_state_iter; } - couvreur99_check::couvreur99_check(const tgba* a, option_map o) + couvreur99_check::couvreur99_check(const const_tgba_ptr& a, option_map o) : emptiness_check(a, o), removed_components(0) { @@ -319,7 +319,8 @@ namespace spot } } - couvreur99_check_shy::couvreur99_check_shy(const tgba* a, option_map o) + couvreur99_check_shy::couvreur99_check_shy(const const_tgba_ptr& a, + option_map o) : couvreur99_check(a, o), num(1) { group_ = o.get("group", 1); @@ -592,7 +593,7 @@ namespace spot } emptiness_check* - couvreur99(const tgba* a, option_map o) + couvreur99(const const_tgba_ptr& a, option_map o) { if (o.get("shy")) return new couvreur99_check_shy(a, o); diff --git a/src/tgbaalgos/gtec/gtec.hh b/src/tgbaalgos/gtec/gtec.hh index dc5de0e7e..909e1f145 100644 --- a/src/tgbaalgos/gtec/gtec.hh +++ b/src/tgbaalgos/gtec/gtec.hh @@ -137,7 +137,7 @@ namespace spot /// choosing a successor. Otherwise, only the successor of the /// topmost state on the DFS stack are considered. SPOT_API emptiness_check* - couvreur99(const tgba* a, option_map options = option_map()); + couvreur99(const const_tgba_ptr& a, option_map options = option_map()); /// \brief An implementation of the Couvreur99 emptiness-check algorithm. @@ -146,7 +146,7 @@ namespace spot class SPOT_API couvreur99_check: public emptiness_check, public ec_statistics { public: - couvreur99_check(const tgba* a, option_map o = option_map()); + couvreur99_check(const const_tgba_ptr& a, option_map o = option_map()); virtual ~couvreur99_check(); /// Check whether the automaton's language is empty. @@ -188,7 +188,7 @@ namespace spot class SPOT_API couvreur99_check_shy : public couvreur99_check { public: - couvreur99_check_shy(const tgba* a, option_map o = option_map()); + couvreur99_check_shy(const const_tgba_ptr& a, option_map o = option_map()); virtual ~couvreur99_check_shy(); virtual emptiness_check_result* check(); diff --git a/src/tgbaalgos/gtec/status.cc b/src/tgbaalgos/gtec/status.cc index 9869105da..f9a8044d2 100644 --- a/src/tgbaalgos/gtec/status.cc +++ b/src/tgbaalgos/gtec/status.cc @@ -25,7 +25,7 @@ namespace spot { - couvreur99_check_status::couvreur99_check_status(const tgba* aut) + couvreur99_check_status::couvreur99_check_status(const const_tgba_ptr& aut) : aut(aut) { } diff --git a/src/tgbaalgos/gtec/status.hh b/src/tgbaalgos/gtec/status.hh index 971401eef..e1e9c119d 100644 --- a/src/tgbaalgos/gtec/status.hh +++ b/src/tgbaalgos/gtec/status.hh @@ -37,11 +37,11 @@ namespace spot class SPOT_API couvreur99_check_status { public: - couvreur99_check_status(const tgba* aut); + couvreur99_check_status(const const_tgba_ptr& aut); ~couvreur99_check_status(); - const tgba* aut; + const_tgba_ptr aut; scc_stack root; typedef std::unordered_mapall_acceptance_conditions()) { assert(a->number_of_acceptance_conditions() <= 1); @@ -410,7 +410,7 @@ namespace spot } // anonymous emptiness_check* - explicit_gv04_check(const tgba* a, option_map o) + explicit_gv04_check(const const_tgba_ptr& a, option_map o) { return new gv04(a, o); } diff --git a/src/tgbaalgos/gv04.hh b/src/tgbaalgos/gv04.hh index 21a42a102..4325dc889 100644 --- a/src/tgbaalgos/gv04.hh +++ b/src/tgbaalgos/gv04.hh @@ -1,5 +1,5 @@ // -*- coding: utf-8 -*- -// Copyright (C) 2013 Laboratoire de Recherche et Developpement +// Copyright (C) 2013, 2014 Laboratoire de Recherche et Developpement // de l'Epita (LRDE). // Copyright (C) 2004, 2005 Laboratoire d'Informatique de Paris 6 (LIP6), // département Systèmes Répartis Coopératifs (SRC), Université Pierre @@ -23,11 +23,11 @@ #ifndef SPOT_TGBAALGOS_GV04_HH # define SPOT_TGBAALGOS_GV04_HH -#include "misc/optionmap.hh" +# include "misc/optionmap.hh" +# include "tgba/fwd.hh" namespace spot { - class tgba; class emptiness_check; /// \brief Emptiness check based on Geldenhuys and Valmari's @@ -55,7 +55,7 @@ namespace spot } \endverbatim */ SPOT_API emptiness_check* - explicit_gv04_check(const tgba* a, option_map o = option_map()); + explicit_gv04_check(const const_tgba_ptr& a, option_map o = option_map()); } #endif // SPOT_TGBAALGOS_GV04_HH diff --git a/src/tgbaalgos/isdet.cc b/src/tgbaalgos/isdet.cc index ee2c4654c..94aef3812 100644 --- a/src/tgbaalgos/isdet.cc +++ b/src/tgbaalgos/isdet.cc @@ -27,7 +27,7 @@ namespace spot { static unsigned - count_nondet_states_aux(const tgba* aut, bool count = true) + count_nondet_states_aux(const const_tgba_ptr& aut, bool count = true) { unsigned res = 0; typedef std::deque todo_list; @@ -80,19 +80,19 @@ namespace spot } unsigned - count_nondet_states(const tgba* aut) + count_nondet_states(const const_tgba_ptr& aut) { return count_nondet_states_aux(aut); } bool - is_deterministic(const tgba* aut) + is_deterministic(const const_tgba_ptr& aut) { return !count_nondet_states_aux(aut, false); } bool - is_complete(const tgba* aut) + is_complete(const const_tgba_ptr& aut) { state_set seen; typedef std::deque todo_list; diff --git a/src/tgbaalgos/isdet.hh b/src/tgbaalgos/isdet.hh index 3f17079fd..54989e8bd 100644 --- a/src/tgbaalgos/isdet.hh +++ b/src/tgbaalgos/isdet.hh @@ -33,7 +33,7 @@ namespace spot /// but it is more efficient to call is_deterministic() if you do not /// care about the number of nondeterministic states. SPOT_API unsigned - count_nondet_states(const tgba* aut); + count_nondet_states(const const_tgba_ptr& aut); /// \brief Return true iff \a aut is deterministic. /// @@ -41,14 +41,14 @@ namespace spot /// the automaton is nondeterministic, because it can return before /// the entire automaton has been explored. SPOT_API bool - is_deterministic(const tgba* aut); + is_deterministic(const const_tgba_ptr& aut); /// \brief Return true iff \a aut is complete. /// /// An automaton is complete if its translation relation is total, /// i.e., each state as a successor for any possible configuration. SPOT_API bool - is_complete(const tgba* aut); + is_complete(const const_tgba_ptr& aut); /// @} } diff --git a/src/tgbaalgos/isweakscc.cc b/src/tgbaalgos/isweakscc.cc index b8471274b..ab4d30840 100644 --- a/src/tgbaalgos/isweakscc.cc +++ b/src/tgbaalgos/isweakscc.cc @@ -91,7 +91,7 @@ namespace spot bool is_complete_scc(scc_map& map, unsigned scc) { - const spot::tgba *a = map.get_aut(); + auto a = map.get_aut(); for (auto s: map.states_of(scc)) { tgba_succ_iterator* it = a->succ_iter(s); diff --git a/src/tgbaalgos/lbtt.cc b/src/tgbaalgos/lbtt.cc index 68ac22251..95825bd28 100644 --- a/src/tgbaalgos/lbtt.cc +++ b/src/tgbaalgos/lbtt.cc @@ -24,7 +24,6 @@ #include #include #include -#include #include "tgba/formula2bdd.hh" #include "reachiter.hh" #include "misc/bddlt.hh" @@ -74,7 +73,7 @@ namespace spot class lbtt_bfs : public tgba_reachable_iterator_breadth_first { public: - lbtt_bfs(const tgba* a, std::ostream& os, bool sba_format) + lbtt_bfs(const const_tgba_ptr& a, std::ostream& os, bool sba_format) : tgba_reachable_iterator_breadth_first(a), os_(os), all_acc_conds_(a->all_acceptance_conditions()), @@ -83,7 +82,7 @@ namespace spot // Check if the automaton can be converted into a // tgba_digraph. This makes the state_is_accepting() // function more efficient. - sba_(dynamic_cast(a)) + sba_(std::dynamic_pointer_cast(a)) { if (sba_ && !sba_->get_bprop(tgba_digraph::SBA)) sba_ = nullptr; @@ -166,18 +165,18 @@ namespace spot bdd all_acc_conds_; acceptance_cond_splitter acs_; bool sba_format_; - const tgba_digraph* sba_; + const_tgba_digraph_ptr sba_; }; static - const tgba_digraph* + tgba_digraph_ptr lbtt_read_tgba(unsigned num_states, unsigned num_acc, std::istream& is, std::string& error, bdd_dict_ptr dict, ltl::environment& env, ltl::environment& envacc) { - auto aut = std::unique_ptr(new tgba_digraph(dict)); - acc_mapper_int acc_b(aut.get(), num_acc, envacc); + auto aut = make_tgba_digraph(dict); + acc_mapper_int acc_b(aut, num_acc, envacc); aut->new_states(num_states); for (unsigned n = 0; n < num_states; ++n) @@ -232,17 +231,17 @@ namespace spot aut->new_transition(src_state, dst_state, cond, acc); } } - return aut.release(); + return aut; } - const tgba_digraph* + tgba_digraph_ptr lbtt_read_gba(unsigned num_states, unsigned num_acc, std::istream& is, std::string& error, bdd_dict_ptr dict, ltl::environment& env, ltl::environment& envacc) { - auto aut = std::unique_ptr(new tgba_digraph(dict)); - acc_mapper_int acc_b(aut.get(), num_acc, envacc); + auto aut = make_tgba_digraph(dict); + acc_mapper_int acc_b(aut, num_acc, envacc); aut->new_states(num_states); aut->set_bprop(tgba_digraph::StateBasedAcc); @@ -298,14 +297,14 @@ namespace spot aut->new_transition(src_state, dst_state, cond, acc); } } - return aut.release(); + return aut; } } // anonymous std::ostream& - lbtt_reachable(std::ostream& os, const tgba* g, bool sba) + lbtt_reachable(std::ostream& os, const const_tgba_ptr& g, bool sba) { lbtt_bfs b(g, os, sba); b.run(); @@ -313,7 +312,7 @@ namespace spot } - const tgba_digraph* + tgba_digraph_ptr lbtt_parse(std::istream& is, std::string& error, bdd_dict_ptr dict, ltl::environment& env, ltl::environment& envacc) { @@ -332,7 +331,7 @@ namespace spot { std::string header; std::getline(is, header); - return new tgba_digraph(dict); + return make_tgba_digraph(dict); } unsigned num_acc = 0; diff --git a/src/tgbaalgos/lbtt.hh b/src/tgbaalgos/lbtt.hh index ed91234c6..0f3919f3a 100644 --- a/src/tgbaalgos/lbtt.hh +++ b/src/tgbaalgos/lbtt.hh @@ -37,7 +37,7 @@ namespace spot /// \param sba Assume \a g is an SBA and use LBTT's state-based /// acceptance format (similar to LBT's format). SPOT_API std::ostream& - lbtt_reachable(std::ostream& os, const tgba* g, bool sba = false); + lbtt_reachable(std::ostream& os, const const_tgba_ptr& g, bool sba = false); /// \ingroup tgba_io /// \brief Read an automaton in LBTT's format @@ -51,7 +51,7 @@ namespace spot /// \param envacc The environment of acceptance conditions into which parsing /// should take place. /// \return the read tgba or 0 on error. - SPOT_API const tgba_digraph* + SPOT_API tgba_digraph_ptr lbtt_parse(std::istream& is, std::string& error, bdd_dict_ptr dict, ltl::environment& env = ltl::default_environment::instance(), diff --git a/src/tgbaalgos/ltl2taa.cc b/src/tgbaalgos/ltl2taa.cc index f39be7513..4ad63e169 100644 --- a/src/tgbaalgos/ltl2taa.cc +++ b/src/tgbaalgos/ltl2taa.cc @@ -38,7 +38,8 @@ namespace spot class ltl2taa_visitor : public visitor { public: - ltl2taa_visitor(taa_tgba_formula* res, language_containment_checker* lcc, + ltl2taa_visitor(const taa_tgba_formula_ptr& res, + language_containment_checker* lcc, bool refined = false, bool negated = false) : res_(res), refined_(refined), negated_(negated), lcc_(lcc), init_(), succ_(), to_free_() @@ -50,7 +51,7 @@ namespace spot { } - taa_tgba_formula* + taa_tgba_formula_ptr& result() { for (unsigned i = 0; i < to_free_.size(); ++i) @@ -345,14 +346,12 @@ namespace spot } private: - taa_tgba_formula* res_; + taa_tgba_formula_ptr res_; bool refined_; bool negated_; language_containment_checker* lcc_; - typedef std::insert_iterator< - std::vector - > ii; + typedef std::insert_iterator> ii; struct succ_state { @@ -417,21 +416,22 @@ namespace spot }; } // anonymous - taa_tgba* - ltl_to_taa(const ltl::formula* f, bdd_dict_ptr dict, bool refined_rules) + taa_tgba_formula_ptr + ltl_to_taa(const ltl::formula* f, + const bdd_dict_ptr& dict, bool refined_rules) { // TODO: s/unabbreviate_ltl/unabbreviate_logic/ const ltl::formula* f1 = ltl::unabbreviate_ltl(f); const ltl::formula* f2 = ltl::negative_normal_form(f1); f1->destroy(); - spot::taa_tgba_formula* res = new spot::taa_tgba_formula(dict); + auto res = make_taa_tgba_formula(dict); language_containment_checker* lcc = new language_containment_checker(make_bdd_dict(), false, false, false, false); ltl2taa_visitor v(res, lcc, refined_rules); f2->accept(v); - taa_tgba* taa = v.result(); // Careful: before the destroy! + auto taa = v.result(); // Careful: before the destroy! f2->destroy(); delete lcc; return taa; diff --git a/src/tgbaalgos/ltl2taa.hh b/src/tgbaalgos/ltl2taa.hh index 75e22c350..cddd95a11 100644 --- a/src/tgbaalgos/ltl2taa.hh +++ b/src/tgbaalgos/ltl2taa.hh @@ -1,6 +1,6 @@ // -*- coding: utf-8 -*- -// Copyright (C) 2009, 2010, 2013 Laboratoire de Recherche et Développement -// de l'Epita (LRDE). +// Copyright (C) 2009, 2010, 2013, 2014 Laboratoire de Recherche et +// Développement de l'Epita (LRDE). // // This file is part of Spot, a model checking library. // @@ -48,8 +48,8 @@ namespace spot /// \param dict The spot::bdd_dict the constructed automata should use. /// \param refined_rules If this parameter is set, refined rules are used. /// \return A spot::taa that recognizes the language of \a f. - SPOT_API taa_tgba* - ltl_to_taa(const ltl::formula* f, bdd_dict_ptr dict, + SPOT_API taa_tgba_formula_ptr + ltl_to_taa(const ltl::formula* f, const bdd_dict_ptr& dict, bool refined_rules = false); } diff --git a/src/tgbaalgos/ltl2tgba_fm.cc b/src/tgbaalgos/ltl2tgba_fm.cc index e295df1ad..1004140f7 100644 --- a/src/tgbaalgos/ltl2tgba_fm.cc +++ b/src/tgbaalgos/ltl2tgba_fm.cc @@ -114,12 +114,12 @@ namespace spot formula_ptr_hash>::type namer; public: ratexp_to_dfa(translate_dict& dict); - std::tuple + std::tuple succ(const formula* f); ~ratexp_to_dfa(); protected: - typedef std::pair labelled_aut; + typedef std::pair labelled_aut; labelled_aut translate(const formula* f); private: @@ -976,7 +976,6 @@ namespace spot { for (auto i: automata_) { - delete i.first; for (auto n: i.second->names()) n->destroy(); delete i.second; @@ -988,7 +987,7 @@ namespace spot { assert(f->is_in_nenoform()); - auto a = new tgba_digraph(dict_.dict); + auto a = make_tgba_digraph(dict_.dict); auto namer = a->create_namer(); typedef std::set set_type; @@ -1107,7 +1106,6 @@ namespace spot } else { - delete a; for (auto n: namer->names()) n->destroy(); delete namer; @@ -1116,7 +1114,7 @@ namespace spot } // FIXME: use the new tgba::succ() interface - std::tuple ratexp_to_dfa::succ(const formula* f) @@ -2028,7 +2026,7 @@ namespace spot } - tgba_digraph* + tgba_digraph_ptr ltl_to_tgba_fm(const formula* f, bdd_dict_ptr dict, bool exprop, bool symb_merge, bool branching_postponement, bool fair_loop_approx, const atomic_prop_set* unobs, @@ -2108,7 +2106,7 @@ namespace spot bdd all_events = observable_events | unobservable_events; - tgba_digraph* a = new tgba_digraph(dict); + tgba_digraph_ptr a = make_tgba_digraph(dict); auto namer = a->create_namer(); // This is in case the initial state is equivalent to true... diff --git a/src/tgbaalgos/ltl2tgba_fm.hh b/src/tgbaalgos/ltl2tgba_fm.hh index a5df0ffae..3461ee48b 100644 --- a/src/tgbaalgos/ltl2tgba_fm.hh +++ b/src/tgbaalgos/ltl2tgba_fm.hh @@ -31,7 +31,7 @@ namespace spot { /// \ingroup tgba_ltl - /// \brief Build a spot::tgba_digraph* from an LTL formula. + /// \brief Build a spot::tgba_digraph_ptr from an LTL formula. /// /// This is based on the following paper. /** \verbatim @@ -122,7 +122,7 @@ namespace spot \endverbatim */ /// /// \return A spot::tgba_digraph that recognizes the language of \a f. - SPOT_API tgba_digraph* + SPOT_API tgba_digraph_ptr ltl_to_tgba_fm(const ltl::formula* f, bdd_dict_ptr dict, bool exprop = false, bool symb_merge = true, bool branching_postponement = false, diff --git a/src/tgbaalgos/magic.cc b/src/tgbaalgos/magic.cc index 11a4003e1..613eb52fa 100644 --- a/src/tgbaalgos/magic.cc +++ b/src/tgbaalgos/magic.cc @@ -54,7 +54,8 @@ namespace spot /// /// \pre The automaton \a a must have at most one acceptance /// condition (i.e. it is a TBA). - magic_search_(const tgba *a, size_t size, option_map o = option_map()) + magic_search_(const const_tgba_ptr& a, size_t size, + option_map o = option_map()) : emptiness_check(a, o), h(size), all_cond(a->all_acceptance_conditions()) @@ -583,19 +584,19 @@ namespace spot } // anonymous - emptiness_check* explicit_magic_search(const tgba *a, option_map o) + emptiness_check* explicit_magic_search(const const_tgba_ptr& a, option_map o) { return new magic_search_(a, 0, o); } - emptiness_check* bit_state_hashing_magic_search(const tgba *a, size_t size, - option_map o) + emptiness_check* bit_state_hashing_magic_search(const const_tgba_ptr& a, + size_t size, option_map o) { return new magic_search_(a, size, o); } emptiness_check* - magic_search(const tgba *a, option_map o) + magic_search(const const_tgba_ptr& a, option_map o) { size_t size = o.get("bsh"); if (size) diff --git a/src/tgbaalgos/magic.hh b/src/tgbaalgos/magic.hh index 08dee4ce2..be6967b94 100644 --- a/src/tgbaalgos/magic.hh +++ b/src/tgbaalgos/magic.hh @@ -1,5 +1,5 @@ // -*- coding: utf-8 -*- -// Copyright (C) 2013 Laboratoire de Recherche et Developpement +// Copyright (C) 2013, 2014 Laboratoire de Recherche et Developpement // de l'Epita (LRDE). // Copyright (C) 2004, 2005 Laboratoire d'Informatique de Paris 6 (LIP6), // département Systèmes Répartis Coopératifs (SRC), Université Pierre @@ -24,11 +24,11 @@ # define SPOT_TGBAALGOS_MAGIC_HH #include +#include "tgba/fwd.hh" #include "misc/optionmap.hh" namespace spot { - class tgba; class emptiness_check; /// \addtogroup emptiness_check_algorithms @@ -98,7 +98,7 @@ namespace spot /// \bug The name is misleading. Magic-search is the algorithm /// from \c godefroid.93.pstv, not \c courcoubetis.92.fmsd. SPOT_API emptiness_check* - explicit_magic_search(const tgba *a, + explicit_magic_search(const const_tgba_ptr& a, option_map o = option_map()); /// \brief Returns an emptiness checker on the spot::tgba automaton \a a. @@ -129,7 +129,7 @@ namespace spot /// \sa spot::explicit_magic_search /// SPOT_API emptiness_check* - bit_state_hashing_magic_search(const tgba *a, size_t size, + bit_state_hashing_magic_search(const const_tgba_ptr& a, size_t size, option_map o = option_map()); /// \brief Wrapper for the two magic_search implementations. @@ -139,7 +139,7 @@ namespace spot /// in the \c option_map. If \c "bsh" is set and non null, its value /// is used as the size of the hash map. SPOT_API emptiness_check* - magic_search(const tgba *a, option_map o = option_map()); + magic_search(const const_tgba_ptr& a, option_map o = option_map()); /// @} } diff --git a/src/tgbaalgos/minimize.cc b/src/tgbaalgos/minimize.cc index ec6e17547..6309fbca2 100644 --- a/src/tgbaalgos/minimize.cc +++ b/src/tgbaalgos/minimize.cc @@ -60,7 +60,9 @@ namespace spot namespace { static std::ostream& - dump_hash_set(const hash_set* hs, const tgba* aut, std::ostream& out) + dump_hash_set(const hash_set* hs, + const const_tgba_ptr& aut, + std::ostream& out) { out << '{'; const char* sep = ""; @@ -74,7 +76,7 @@ namespace spot } static std::string - format_hash_set(const hash_set* hs, const tgba* aut) + format_hash_set(const hash_set* hs, const_tgba_ptr aut) { std::ostringstream s; dump_hash_set(hs, aut, s); @@ -83,7 +85,7 @@ namespace spot } // Find all states of an automaton. - void build_state_set(const tgba* a, hash_set* seen) + void build_state_set(const const_tgba_ptr& a, hash_set* seen) { std::queue tovisit; // Perform breadth-first traversal. @@ -113,12 +115,12 @@ namespace spot // From the base automaton and the list of sets, build the minimal // resulting automaton - tgba_digraph* build_result(const tgba* a, - std::list& sets, - hash_set* final) + tgba_digraph_ptr build_result(const const_tgba_ptr& a, + std::list& sets, + hash_set* final) { auto dict = a->get_dict(); - auto res = new tgba_digraph(dict); + auto res = make_tgba_digraph(dict); res->copy_ap_of(a); res->set_bprop(tgba_digraph::StateBasedAcc); @@ -181,7 +183,7 @@ namespace spot struct wdba_search_acc_loop : public bfs_steps { - wdba_search_acc_loop(const tgba* det_a, + wdba_search_acc_loop(const const_tgba_ptr& det_a, unsigned scc_n, scc_map& sm, power_map& pm, const state* dest) : bfs_steps(det_a), scc_n(scc_n), sm(sm), pm(pm), dest(dest) @@ -213,8 +215,9 @@ namespace spot bool - wdba_scc_is_accepting(const tgba_digraph* det_a, unsigned scc_n, - const tgba* orig_a, scc_map& sm, power_map& pm) + wdba_scc_is_accepting(const const_tgba_digraph_ptr& det_a, unsigned scc_n, + const const_tgba_ptr& orig_a, scc_map& sm, + power_map& pm) { // Get some state from the SCC #n. @@ -228,23 +231,23 @@ namespace spot (void)reached; // Build an automaton representing this loop. - tgba_digraph loop_a(det_a->get_dict()); + auto loop_a = make_tgba_digraph(det_a->get_dict()); tgba_run::steps::const_iterator i; int loop_size = loop.size(); - loop_a.new_states(loop_size); + loop_a->new_states(loop_size); int n; for (n = 1, i = loop.begin(); n < loop_size; ++n, ++i) { - loop_a.new_transition(n - 1, n, i->label); + loop_a->new_transition(n - 1, n, i->label); i->s->destroy(); } assert(i != loop.end()); - loop_a.new_transition(n - 1, 0, i->label); + loop_a->new_transition(n - 1, 0, i->label); i->s->destroy(); assert(++i == loop.end()); - loop_a.set_init_state(0U); - const state* loop_a_init = loop_a.get_init_state(); + loop_a->set_init_state(0U); + const state* loop_a_init = loop_a->get_init_state(); // Check if the loop is accepting in the original automaton. bool accepting = false; @@ -257,12 +260,11 @@ namespace spot // Contrustruct a product between // LOOP_A, and ORIG_A starting in *IT. // FIXME: This could be sped up a lot! - tgba* p = new tgba_product_init(&loop_a, orig_a, loop_a_init, it); - emptiness_check* ec = couvreur99(p); + emptiness_check* ec = couvreur99(product_at(loop_a, orig_a, + loop_a_init, it)); emptiness_check_result* res = ec->check(); delete res; delete ec; - delete p; if (res) { @@ -277,8 +279,8 @@ namespace spot } - tgba_digraph* minimize_dfa(const tgba_digraph* det_a, - hash_set* final, hash_set* non_final) + tgba_digraph_ptr minimize_dfa(const const_tgba_digraph_ptr& det_a, + hash_set* final, hash_set* non_final) { typedef std::list partition_t; partition_t cur_run; @@ -465,7 +467,7 @@ namespace spot #endif // Build the result. - auto* res = build_result(det_a, done, final_copy); + auto res = build_result(det_a, done, final_copy); // Free all the allocated memory. delete final_copy; @@ -478,17 +480,16 @@ namespace spot std::list::iterator it; for (it = done.begin(); it != done.end(); ++it) delete *it; - delete det_a; return res; } - tgba_digraph* minimize_monitor(const tgba* a) + tgba_digraph_ptr minimize_monitor(const const_tgba_ptr& a) { hash_set* final = new hash_set; hash_set* non_final = new hash_set; - tgba_digraph* det_a; + tgba_digraph_ptr det_a; { power_map pm; @@ -502,12 +503,12 @@ namespace spot return minimize_dfa(det_a, final, non_final); } - tgba_digraph* minimize_wdba(const tgba* a) + tgba_digraph_ptr minimize_wdba(const const_tgba_ptr& a) { hash_set* final = new hash_set; hash_set* non_final = new hash_set; - tgba_digraph* det_a; + tgba_digraph_ptr det_a; { power_map pm; @@ -601,9 +602,10 @@ namespace spot return minimize_dfa(det_a, final, non_final); } - tgba_digraph* - minimize_obligation(const tgba_digraph* aut_f, - const ltl::formula* f, const tgba_digraph* aut_neg_f, + tgba_digraph_ptr + minimize_obligation(const const_tgba_digraph_ptr& aut_f, + const ltl::formula* f, + const_tgba_digraph_ptr aut_neg_f, bool reject_bigger) { auto min_aut_f = minimize_wdba(aut_f); @@ -613,10 +615,7 @@ namespace spot // Abort if min_aut_f has more states than aut_f. unsigned orig_states = aut_f->num_states(); if (orig_states < min_aut_f->num_states()) - { - delete min_aut_f; - return const_cast(aut_f); - } + return std::const_pointer_cast(aut_f); } // if f is a syntactic obligation formula, the WDBA minimization @@ -629,8 +628,6 @@ namespace spot if (is_guarantee_automaton(aut_f)) return min_aut_f; - const tgba* to_free = 0; - // Build negation automaton if not supplied. if (!aut_neg_f) { @@ -642,22 +639,18 @@ namespace spot ltl::unop::instance(ltl::unop::Not, f->clone()); aut_neg_f = ltl_to_tgba_fm(neg_f, aut_f->get_dict()); neg_f->destroy(); - // Remove useless SCCs. - auto tmp = scc_filter(aut_neg_f, true); - delete aut_neg_f; - to_free = aut_neg_f = tmp; + aut_neg_f = scc_filter(aut_neg_f, true); } else if (is_deterministic(aut_f)) { // If the automaton is deterministic, complementing is // easy. - to_free = aut_neg_f = dtgba_complement(aut_f); + aut_neg_f = dtgba_complement(aut_f); } else { // Otherwise, we cannot check if the minimization is safe. - delete min_aut_f; return nullptr; } } @@ -666,50 +659,33 @@ namespace spot // minimization is correct. if (is_guarantee_automaton(aut_neg_f)) { - delete to_free; return min_aut_f; } bool ok = false; - tgba* p = new tgba_product(min_aut_f, aut_neg_f); - emptiness_check* ec = couvreur99(p); + emptiness_check* ec = couvreur99(product(min_aut_f, aut_neg_f)); emptiness_check_result* res = ec->check(); if (!res) { delete ec; - delete p; // Complement the minimized WDBA. - tgba* neg_min_aut_f = wdba_complement(min_aut_f); - - tgba* p = new tgba_product(aut_f, neg_min_aut_f); - emptiness_check* ec = couvreur99(p); + auto neg_min_aut_f = wdba_complement(min_aut_f); + ec = couvreur99(product(aut_f, neg_min_aut_f)); res = ec->check(); - if (!res) { // Finally, we are now sure that it was safe // to minimize the automaton. ok = true; } - - delete res; - delete ec; - delete p; - delete neg_min_aut_f; } - else - { - delete res; - delete ec; - delete p; - } - delete to_free; + delete res; + delete ec; if (ok) return min_aut_f; - delete min_aut_f; - return const_cast(aut_f); + return std::const_pointer_cast(aut_f); } } diff --git a/src/tgbaalgos/minimize.hh b/src/tgbaalgos/minimize.hh index 57edcac8a..6e8ad4321 100644 --- a/src/tgbaalgos/minimize.hh +++ b/src/tgbaalgos/minimize.hh @@ -57,7 +57,7 @@ namespace spot /// \param a the automaton to convert into a minimal deterministic monitor /// \pre Dead SCCs should have been removed from \a a before /// calling this function. - SPOT_API tgba_digraph* minimize_monitor(const tgba* a); + SPOT_API tgba_digraph_ptr minimize_monitor(const const_tgba_ptr& a); /// \brief Minimize a Büchi automaton in the WDBA class. /// @@ -93,7 +93,7 @@ namespace spot month = oct } \endverbatim */ - SPOT_API tgba_digraph* minimize_wdba(const tgba* a); + SPOT_API tgba_digraph_ptr minimize_wdba(const const_tgba_ptr& a); /// \brief Minimize an automaton if it represents an obligation property. /// @@ -150,10 +150,11 @@ namespace spot /// determinization step during minimize_wdba().) Note that /// checking the size of the minimized WDBA occurs before ensuring /// that the minimized WDBA is correct. - SPOT_API tgba_digraph* minimize_obligation(const tgba_digraph* aut_f, - const ltl::formula* f = 0, - const tgba_digraph* aut_neg_f = 0, - bool reject_bigger = false); + SPOT_API tgba_digraph_ptr + minimize_obligation(const const_tgba_digraph_ptr& aut_f, + const ltl::formula* f = 0, + const_tgba_digraph_ptr aut_neg_f = nullptr, + bool reject_bigger = false); /// @} } diff --git a/src/tgbaalgos/ndfs_result.hxx b/src/tgbaalgos/ndfs_result.hxx index 6097d3364..90e8d2f7c 100644 --- a/src/tgbaalgos/ndfs_result.hxx +++ b/src/tgbaalgos/ndfs_result.hxx @@ -230,7 +230,8 @@ namespace spot typedef std::unordered_set state_set; - void clean(const tgba* a, stack_type& st1, state_set& seen, state_set& dead) + void clean(const const_tgba_ptr& a, stack_type& st1, + state_set& seen, state_set& dead) { while (!st1.empty()) { @@ -372,7 +373,7 @@ namespace spot { public: test_path(ars_statistics* ars, - const tgba* a, const state* t, + const const_tgba_ptr& a, const state* t, const state_set& d, const heap& h) : bfs_steps(a), ars(ars), target(t), dead(d), h(h) { @@ -467,7 +468,8 @@ namespace spot { public: min_path(ars_statistics* ars, - const tgba* a, const m_source_trans& target, const heap& h) + const const_tgba_ptr& a, + const m_source_trans& target, const heap& h) : bfs_steps(a), ars(ars), target(target), h(h) { } diff --git a/src/tgbaalgos/neverclaim.cc b/src/tgbaalgos/neverclaim.cc index 6b320c4a4..d749634dd 100644 --- a/src/tgbaalgos/neverclaim.cc +++ b/src/tgbaalgos/neverclaim.cc @@ -37,12 +37,12 @@ namespace spot class never_claim_bfs : public tgba_reachable_iterator_breadth_first { public: - never_claim_bfs(const tgba* a, std::ostream& os, + never_claim_bfs(const const_tgba_ptr& a, std::ostream& os, const ltl::formula* f, bool comments) : tgba_reachable_iterator_breadth_first(a), os_(os), f_(f), accept_all_(-1), fi_needed_(false), comments_(comments), all_acc_conds_(a->all_acceptance_conditions()), - sba_(dynamic_cast(a)) + sba_(std::dynamic_pointer_cast(a)) { assert(!sba_ || sba_->get_bprop(tgba_digraph::StateBasedAcc)); } @@ -194,12 +194,12 @@ namespace spot state* init_; bool comments_; bdd all_acc_conds_; - const tgba_digraph* sba_; + const_tgba_digraph_ptr sba_; }; } // anonymous std::ostream& - never_claim_reachable(std::ostream& os, const tgba* g, + never_claim_reachable(std::ostream& os, const const_tgba_ptr& g, const ltl::formula* f, bool comments) { assert(g->number_of_acceptance_conditions() <= 1); diff --git a/src/tgbaalgos/neverclaim.hh b/src/tgbaalgos/neverclaim.hh index b31b78c55..fd0f19cae 100644 --- a/src/tgbaalgos/neverclaim.hh +++ b/src/tgbaalgos/neverclaim.hh @@ -25,6 +25,7 @@ #include #include "ltlast/formula.hh" +#include "tgba/fwd.hh" namespace spot { @@ -45,7 +46,7 @@ namespace spot /// with the label of the \a g automaton. SPOT_API std::ostream& never_claim_reachable(std::ostream& os, - const tgba* g, + const const_tgba_ptr& g, const ltl::formula* f = 0, bool comments = false); } diff --git a/src/tgbaalgos/postproc.cc b/src/tgbaalgos/postproc.cc index 1ae46dd2f..d5673b7c0 100644 --- a/src/tgbaalgos/postproc.cc +++ b/src/tgbaalgos/postproc.cc @@ -74,7 +74,8 @@ namespace spot } } - const tgba_digraph* postprocessor::do_simul(const tgba_digraph* a, int opt) + tgba_digraph_ptr + postprocessor::do_simul(const tgba_digraph_ptr& a, int opt) { switch (opt) { @@ -94,8 +95,8 @@ namespace spot } } - const tgba_digraph* postprocessor::do_ba_simul(const tgba_digraph* a, - int opt) + tgba_digraph_ptr + postprocessor::do_ba_simul(const tgba_digraph_ptr& a, int opt) { switch (opt) { @@ -112,27 +113,22 @@ namespace spot } - const tgba_digraph* postprocessor::do_degen(const tgba_digraph* a) + tgba_digraph_ptr + postprocessor::do_degen(const tgba_digraph_ptr& a) { auto d = degeneralize(a, degen_reset_, degen_order_, degen_cache_, degen_lskip_); - delete a; if (ba_simul_ <= 0) return d; - - auto s = do_ba_simul(d, ba_simul_); - if (s != d) - delete d; - - return s; + return do_ba_simul(d, ba_simul_); } #define PREF_ (pref_ & (Small | Deterministic)) #define COMP_ (pref_ & Complete) - const tgba_digraph* - postprocessor::run(const tgba_digraph* a, const ltl::formula* f) + tgba_digraph_ptr + postprocessor::run(tgba_digraph_ptr a, const ltl::formula* f) { if (type_ == TGBA && PREF_ == Any && level_ == Low) return a; @@ -150,64 +146,35 @@ namespace spot // Remove useless SCCs. if (type_ == Monitor) - { - // Do not bother about acceptance conditions, they will be - // ignored. - auto s = scc_filter_states(a); - delete a; - a = s; - } + // Do not bother about acceptance conditions, they will be + // ignored. + a = scc_filter_states(a); else if (scc_filter_ > 0) - { - auto s = scc_filter(a, scc_filter_ > 1); - delete a; - a = s; - } + a = scc_filter(a, scc_filter_ > 1); if (type_ == Monitor) { if (PREF_ == Deterministic) - { - auto m = minimize_monitor(a); - delete a; - return m; - } + a = minimize_monitor(a); else - { - strip_acceptance_here(const_cast(a)); - } + strip_acceptance_here(a); + if (PREF_ == Any) return a; - auto sim = do_simul(a, simul_); - if (a == sim) - // simulation was disabled. - return a; - if (level_ != High) - { - delete a; - return sim; - } + a = do_simul(a, simul_); + // For Small,High we return the smallest between the output of // the simulation, and that of the deterministic minimization. - auto m = minimize_monitor(a); - delete a; - if (m->num_states() > sim->num_states()) + if (PREF_ == Small && level_ == High && simul_) { - delete m; - } - else - { - delete sim; - sim = m; + auto m = minimize_monitor(a); + if (m->num_states() < a->num_states()) + a = m; } if (COMP_ == Complete) - { - auto s = tgba_complete(sim); - delete sim; - sim = s; - } - return sim; + a = tgba_complete(a); + return a; } if (PREF_ == Any) @@ -219,8 +186,8 @@ namespace spot bool dba_is_wdba = false; bool dba_is_minimal = false; - const tgba_digraph* dba = 0; - const tgba_digraph* sim = 0; + tgba_digraph_ptr dba = 0; + tgba_digraph_ptr sim = 0; // (Small,Low) is the only configuration where we do not run // WDBA-minimization. @@ -228,8 +195,8 @@ namespace spot { bool reject_bigger = (PREF_ == Small) && (level_ == Medium); dba = minimize_obligation(a, f, 0, reject_bigger); - if (dba == a || dba == 0) // Minimization failed. - dba = 0; + if (dba == a || !dba) // Minimization failed. + dba = nullptr; else dba_is_minimal = dba_is_wdba = true; // The WDBA is a BA, so no degeneralization is required. @@ -240,18 +207,11 @@ namespace spot if (!dba || (level_ == High && PREF_ == Small)) { sim = do_simul(a, simul_); - if (sim != a) - delete a; - // Degeneralize the result of the simulation if needed. // No need to do that if tba_determinisation_ will be used. if (type_ == BA && !tba_determinisation_) sim = do_degen(sim); } - else - { - delete a; - } // If WDBA failed, but the simulation returned a deterministic // automaton, use it as dba. @@ -272,7 +232,7 @@ namespace spot // If we don't have a DBA, attempt tba-determinization if requested. if (tba_determinisation_ && !dba) { - const tgba_digraph* tmpd = 0; + tgba_digraph_ptr tmpd = nullptr; if (PREF_ == Deterministic && f && f->is_syntactic_recurrence() @@ -297,20 +257,17 @@ namespace spot (PREF_ == Small) ? 2 : 8, 1 << ((PREF_ == Small) ? 13 : 15), f); - if (tmp != 0 && tmp != in) + if (tmp && tmp != in) { // There is no point in running the reverse simulation on // a deterministic automaton, since all prefixes are // unique. dba = simulation(tmp); - delete tmp; } - delete tmpd; if (dba && PREF_ == Deterministic) { // disregard the result of the simulation. - delete sim; - sim = 0; + sim = nullptr; } else { @@ -340,17 +297,16 @@ namespace spot // sure it is at least 1. target_acc = original_acc > 0 ? original_acc : 1; - const tgba_digraph* in = 0; - const tgba_digraph* to_free = 0; + const_tgba_digraph_ptr in = 0; if (target_acc == 1) { // If we are seeking a minimal DBA with unknown number of // states, then we should start from the degeneralized, // because the input TBA might be smaller. if (state_based_) - to_free = in = degeneralize(dba); + in = degeneralize(dba); else if (dba->number_of_acceptance_conditions() != 1) - to_free = in = degeneralize_tba(dba); + in = degeneralize_tba(dba); else in = dba; } @@ -359,32 +315,29 @@ namespace spot in = dba; } - const tgba_digraph* cmp = tgba_complete(in); - const tgba_digraph* res = 0; + const_tgba_digraph_ptr res = tgba_complete(in); if (target_acc == 1) { if (sat_states_ != -1) - res = dtba_sat_synthetize(cmp, sat_states_, state_based_); + res = dtba_sat_synthetize(res, sat_states_, state_based_); else if (sat_minimize_ == 1 || sat_minimize_ == -1) - res = dtba_sat_minimize(cmp, state_based_); + res = dtba_sat_minimize(res, state_based_); else // sat_minimize_ == 2 - res = dtba_sat_minimize_dichotomy(cmp, state_based_); + res = dtba_sat_minimize_dichotomy(res, state_based_); } else { if (sat_states_ != -1) - res = dtgba_sat_synthetize(cmp, target_acc, sat_states_, + res = dtgba_sat_synthetize(res, target_acc, sat_states_, state_based_); else if (sat_minimize_ == 1 || sat_minimize_ == -1) - res = dtgba_sat_minimize(cmp, target_acc, state_based_); + res = dtgba_sat_minimize(res, target_acc, state_based_); else // sat_minimize_ == 2 - res = dtgba_sat_minimize_dichotomy(cmp, target_acc, state_based_); + res = dtgba_sat_minimize_dichotomy(res, target_acc, state_based_); } - delete cmp; - delete to_free; - if (res != 0) + + if (res) { - delete dba; if (state_based_) // FIXME: This does not simplify generalized acceptance // conditions, but calling scc_filter() would break the @@ -393,7 +346,6 @@ namespace spot dba = scc_filter_states(res); else dba = scc_filter(res, true); - delete res; dba_is_minimal = true; } } @@ -403,24 +355,14 @@ namespace spot if (dba && !dba_is_wdba && type_ == BA && !(dba_is_minimal && state_based_ && dba->number_of_acceptance_conditions() == 1)) - { - auto d = degeneralize(dba); - delete dba; - dba = d; - } + dba = degeneralize(dba); if (dba && sim) { if (dba->num_states() > sim->num_states()) - { - delete dba; - dba = 0; - } + dba = nullptr; else - { - delete sim; - sim = 0; - } + sim = nullptr; } @@ -428,28 +370,21 @@ namespace spot { if (dba && !dba_is_minimal) // WDBA is already clean. { - auto s = scc_filter(dba, true); - delete dba; + dba = scc_filter(dba, true); assert(!sim); - dba = s; } else if (sim) { - auto s = scc_filter(sim, true); - delete sim; + sim = scc_filter(sim, true); assert(!dba); - sim = s; } } sim = dba ? dba : sim; if (COMP_ == Complete) - { - auto s = tgba_complete(sim); - delete sim; - sim = s; - } + sim = tgba_complete(sim); + return sim; } } diff --git a/src/tgbaalgos/postproc.hh b/src/tgbaalgos/postproc.hh index 967de2df3..61f0e3660 100644 --- a/src/tgbaalgos/postproc.hh +++ b/src/tgbaalgos/postproc.hh @@ -96,14 +96,17 @@ namespace spot level_ = level; } - /// Return the optimized automaton and delete \a input_disown. - const tgba_digraph* run(const tgba_digraph* input_disown, - const ltl::formula* f); + /// \brief Optimize an automaton. + /// + /// The returned automaton might be a new automaton, + /// or an in-place modification of the \a input automaton. + tgba_digraph_ptr run(tgba_digraph_ptr input, + const ltl::formula* f); protected: - const tgba_digraph* do_simul(const tgba_digraph* input, int opt); - const tgba_digraph* do_ba_simul(const tgba_digraph* input, int opt); - const tgba_digraph* do_degen(const tgba_digraph* input); + tgba_digraph_ptr do_simul(const tgba_digraph_ptr& input, int opt); + tgba_digraph_ptr do_ba_simul(const tgba_digraph_ptr& input, int opt); + tgba_digraph_ptr do_degen(const tgba_digraph_ptr& input); output_type type_; int pref_; diff --git a/src/tgbaalgos/powerset.cc b/src/tgbaalgos/powerset.cc index a2003b28b..f41cf4770 100644 --- a/src/tgbaalgos/powerset.cc +++ b/src/tgbaalgos/powerset.cc @@ -42,8 +42,8 @@ namespace spot { - tgba_digraph* - tgba_powerset(const tgba* aut, power_map& pm, bool merge) + tgba_digraph_ptr + tgba_powerset(const const_tgba_ptr& aut, power_map& pm, bool merge) { typedef power_map::power_state power_state; typedef std::map power_set; @@ -51,7 +51,7 @@ namespace spot power_set seen; todo_list todo; - auto res = new tgba_digraph(aut->get_dict()); + auto res = make_tgba_digraph(aut->get_dict()); res->copy_ap_of(aut); { @@ -111,8 +111,8 @@ namespace spot return res; } - tgba_digraph* - tgba_powerset(const tgba* aut) + tgba_digraph_ptr + tgba_powerset(const const_tgba_ptr& aut) { power_map pm; return tgba_powerset(aut, pm); @@ -130,7 +130,7 @@ namespace spot typedef std::set trans_set; typedef std::vector set_set; protected: - const tgba* ref_; + const_tgba_ptr ref_; power_map& refmap_; trans_set reject_; // set of rejecting transitions set_set accept_; // set of cycles that are accepting @@ -139,8 +139,8 @@ namespace spot unsigned cycles_left_; // count of cycles left to explore public: - fix_scc_acceptance(const scc_map& sm, const tgba* ref, power_map& refmap, - unsigned threshold) + fix_scc_acceptance(const scc_map& sm, const_tgba_ptr ref, + power_map& refmap, unsigned threshold) : enumerate_cycles(sm), ref_(ref), refmap_(refmap), threshold_(threshold) { @@ -173,25 +173,26 @@ namespace spot bool is_cycle_accepting(cycle_iter begin, trans_set& ts) const { - auto a = down_cast(const_cast(aut_)); + auto a = std::static_pointer_cast + (std::const_pointer_cast(aut_)); // Build an automaton representing this loop. - tgba_digraph loop_a(aut_->get_dict()); + auto loop_a = make_tgba_digraph(aut_->get_dict()); int loop_size = std::distance(begin, dfs_.end()); - loop_a.new_states(loop_size); + loop_a->new_states(loop_size); int n; cycle_iter i; for (n = 1, i = begin; n <= loop_size; ++n, ++i) { trans* t = &a->trans_data(i->succ); - loop_a.new_transition(n - 1, n % loop_size, t->cond); + loop_a->new_transition(n - 1, n % loop_size, t->cond); if (reject_.find(t) == reject_.end()) ts.insert(t); } assert(i == dfs_.end()); - const state* loop_a_init = loop_a.get_init_state(); - assert(loop_a.state_number(loop_a_init) == 0); + const state* loop_a_init = loop_a->get_init_state(); + assert(loop_a->state_number(loop_a_init) == 0); // Check if the loop is accepting in the original automaton. bool accepting = false; @@ -202,17 +203,12 @@ namespace spot refmap_.states_of(a->state_number(begin->ts->first)); for (auto s: ps) { - // Construct a product between - // LOOP_A, and ORIG_A starting in S. - tgba* p = new tgba_product_init(&loop_a, ref_, loop_a_init, s); - - //spot::dotty_reachable(std::cout, p); - couvreur99_check* ec = down_cast(couvreur99(p)); - assert(ec); + // Check the product between LOOP_A, and ORIG_A starting + // in S. + auto ec = couvreur99(product_at(loop_a, ref_, loop_a_init, s)); emptiness_check_result* res = ec->check(); delete res; delete ec; - delete p; if (res) { accepting = true; @@ -275,8 +271,8 @@ namespace spot }; static bool - fix_dba_acceptance(tgba_digraph* det, - const tgba* ref, power_map& refmap, + fix_dba_acceptance(tgba_digraph_ptr det, + const_tgba_ptr ref, power_map& refmap, unsigned threshold) { det->copy_acceptance_conditions_of(ref); @@ -296,8 +292,8 @@ namespace spot } } - tgba_digraph* - tba_determinize(const tgba* aut, + tgba_digraph_ptr + tba_determinize(const const_tgba_ptr& aut, unsigned threshold_states, unsigned threshold_cycles) { power_map pm; @@ -308,27 +304,20 @@ namespace spot if ((threshold_states > 0) && (pm.map_.size() > pm.states_.size() * threshold_states)) - { - delete det; - return 0; - } + return nullptr; if (fix_dba_acceptance(det, aut, pm, threshold_cycles)) - { - delete det; - return 0; - } + return nullptr; det->merge_transitions(); return det; } - tgba* - tba_determinize_check(const tgba* aut, + tgba_digraph_ptr + tba_determinize_check(const tgba_digraph_ptr& aut, unsigned threshold_states, unsigned threshold_cycles, const ltl::formula* f, - const tgba_digraph* neg_aut) + const_tgba_digraph_ptr neg_aut) { - const tgba* built = 0; if (f == 0 && neg_aut == 0) return 0; if (aut->number_of_acceptance_conditions() > 1) @@ -347,26 +336,19 @@ namespace spot neg_f->destroy(); // Remove useless SCCs. - auto tmp = scc_filter(neg_aut, true); - delete neg_aut; - built = neg_aut = tmp; + neg_aut = scc_filter(neg_aut, true); } bool ok = false; - tgba* p = new tgba_product(det, neg_aut); - emptiness_check* ec = couvreur99(p); - emptiness_check_result* res = ec->check(); + auto ec = couvreur99(product(det, neg_aut)); + auto res = ec->check(); if (!res) { delete ec; - delete p; // Complement the DBA. - tgba* neg_det = dtgba_complement(det); - - tgba* p = new tgba_product(aut, neg_det); - emptiness_check* ec = couvreur99(p); + ec = couvreur99(product(aut, dtgba_complement(det))); res = ec->check(); if (!res) @@ -375,23 +357,12 @@ namespace spot // to determinize the automaton. ok = true; } - - delete res; - delete ec; - delete p; - delete neg_det; } - else - { - delete res; - delete ec; - delete p; - } - delete built; + delete res; + delete ec; if (ok) return det; - delete det; - return const_cast(aut); + return aut; } } diff --git a/src/tgbaalgos/powerset.hh b/src/tgbaalgos/powerset.hh index fdbdc378b..c2dc0c1e6 100644 --- a/src/tgbaalgos/powerset.hh +++ b/src/tgbaalgos/powerset.hh @@ -64,10 +64,10 @@ namespace spot /// The \a merge argument can be set to false to prevent merging of /// transitions. //@{ - SPOT_API tgba_digraph* - tgba_powerset(const tgba* aut, power_map& pm, bool merge = true); - SPOT_API tgba_digraph* - tgba_powerset(const tgba* aut); + SPOT_API tgba_digraph_ptr + tgba_powerset(const const_tgba_ptr& aut, power_map& pm, bool merge = true); + SPOT_API tgba_digraph_ptr + tgba_powerset(const const_tgba_ptr& aut); //@} @@ -106,8 +106,8 @@ namespace spot /// If \a threshold_cycles is non null, abort the construction /// whenever an SCC of the constructed automaton has more than \a /// threshold_cycles cycles. - SPOT_API tgba_digraph* - tba_determinize(const tgba* aut, + SPOT_API tgba_digraph_ptr + tba_determinize(const const_tgba_ptr& aut, unsigned threshold_states = 0, unsigned threshold_cycles = 0); @@ -138,12 +138,12 @@ namespace spot /// the automaton cannot be determinized, 0 if we do not know if the /// determinization is correct because neither \a f nor \a neg_aut /// were supplied. - SPOT_API tgba* - tba_determinize_check(const tgba* aut, + SPOT_API tgba_digraph_ptr + tba_determinize_check(const tgba_digraph_ptr& aut, unsigned threshold_states = 0, unsigned threshold_cycles = 0, const ltl::formula* f = 0, - const tgba_digraph* neg_aut = 0); + const_tgba_digraph_ptr neg_aut = 0); } diff --git a/src/tgbaalgos/projrun.cc b/src/tgbaalgos/projrun.cc index 75070cd85..fb140be47 100644 --- a/src/tgbaalgos/projrun.cc +++ b/src/tgbaalgos/projrun.cc @@ -1,4 +1,4 @@ -// Copyright (C) 2004 Laboratoire d'Informatique de Paris 6 (LIP6), +// Copyright (C) 2004, 2014 Laboratoire d'Informatique de Paris 6 (LIP6), // département Systèmes Répartis Coopératifs (SRC), Université Pierre // et Marie Curie. // @@ -25,7 +25,9 @@ namespace spot { tgba_run* - project_tgba_run(const tgba* a_run, const tgba* a_proj, const tgba_run* run) + project_tgba_run(const const_tgba_ptr& a_run, + const const_tgba_ptr& a_proj, + const tgba_run* run) { tgba_run* res = new tgba_run; for (tgba_run::steps::const_iterator i = run->prefix.begin(); diff --git a/src/tgbaalgos/projrun.hh b/src/tgbaalgos/projrun.hh index 0fe26c763..92b9a9570 100644 --- a/src/tgbaalgos/projrun.hh +++ b/src/tgbaalgos/projrun.hh @@ -1,5 +1,5 @@ // -*- coding: utf-8 -*- -// Copyright (C) 2013 Laboratoire de Recherche et Developpement +// Copyright (C) 2013, 2014 Laboratoire de Recherche et Developpement // de l'Epita (LRDE). // Copyright (C) 2004 Laboratoire d'Informatique de Paris 6 (LIP6), // département Systèmes Répartis Coopératifs (SRC), Université Pierre @@ -25,11 +25,11 @@ # include "misc/common.hh" # include +# include "tgba/fwd.hh" namespace spot { struct tgba_run; - class tgba; /// \ingroup tgba_run /// \brief Project a tgba_run on a tgba. @@ -42,9 +42,9 @@ namespace spot /// \param a_proj the automata on which to project the run /// \return true iff the run could be completed SPOT_API tgba_run* - project_tgba_run(const tgba* a_run, const tgba* a_proj, - -const tgba_run* run); + project_tgba_run(const const_tgba_ptr& a_run, + const const_tgba_ptr& a_proj, + const tgba_run* run); } #endif // SPOT_TGBAALGOS_PROJRUN_HH diff --git a/src/tgbaalgos/randomgraph.cc b/src/tgbaalgos/randomgraph.cc index 385840e6a..9fa80a47e 100644 --- a/src/tgbaalgos/randomgraph.cc +++ b/src/tgbaalgos/randomgraph.cc @@ -44,7 +44,7 @@ namespace spot } void - random_labels(tgba_digraph* aut, + random_labels(tgba_digraph_ptr aut, unsigned src, unsigned dest, int* props, int props_n, float t, @@ -80,14 +80,14 @@ namespace spot } } - tgba* + tgba_digraph_ptr random_graph(int n, float d, const ltl::atomic_prop_set* ap, bdd_dict_ptr dict, int n_acc, float a, float t, ltl::environment* env) { assert(n > 0); - auto res = new tgba_digraph(dict); + auto res = make_tgba_digraph(dict); int props_n = ap->size(); int* props = new int[props_n]; diff --git a/src/tgbaalgos/randomgraph.hh b/src/tgbaalgos/randomgraph.hh index ae8111d4a..67a3ec7d2 100644 --- a/src/tgbaalgos/randomgraph.hh +++ b/src/tgbaalgos/randomgraph.hh @@ -78,7 +78,7 @@ namespace spot /// \f$1+(n-1)d\f$ and variance \f$(n-1)d(1-d)\f$. (This is less /// accurate, but faster than considering all possible \a n /// successors one by one.) - SPOT_API tgba* + SPOT_API tgba_digraph_ptr random_graph(int n, float d, const ltl::atomic_prop_set* ap, bdd_dict_ptr dict, int n_acc = 0, float a = 0.1, float t = 0.5, diff --git a/src/tgbaalgos/reachiter.cc b/src/tgbaalgos/reachiter.cc index 7bfc74c56..dc2e95a2e 100644 --- a/src/tgbaalgos/reachiter.cc +++ b/src/tgbaalgos/reachiter.cc @@ -28,7 +28,7 @@ namespace spot // tgba_reachable_iterator ////////////////////////////////////////////////////////////////////// - tgba_reachable_iterator::tgba_reachable_iterator(const tgba* a) + tgba_reachable_iterator::tgba_reachable_iterator(const const_tgba_ptr& a) : aut_(a) { } @@ -122,7 +122,7 @@ namespace spot ////////////////////////////////////////////////////////////////////// tgba_reachable_iterator_breadth_first:: - tgba_reachable_iterator_breadth_first(const tgba* a) + tgba_reachable_iterator_breadth_first(const const_tgba_ptr& a) : tgba_reachable_iterator(a) { } @@ -147,7 +147,7 @@ namespace spot ////////////////////////////////////////////////////////////////////// tgba_reachable_iterator_depth_first:: - tgba_reachable_iterator_depth_first(const tgba* a) + tgba_reachable_iterator_depth_first(const const_tgba_ptr& a) : aut_(a) { } @@ -273,7 +273,7 @@ namespace spot tgba_reachable_iterator_depth_first_stack:: - tgba_reachable_iterator_depth_first_stack(const tgba* a) + tgba_reachable_iterator_depth_first_stack(const const_tgba_ptr& a) : tgba_reachable_iterator_depth_first(a) { } diff --git a/src/tgbaalgos/reachiter.hh b/src/tgbaalgos/reachiter.hh index 490d0046f..c75d3e06b 100644 --- a/src/tgbaalgos/reachiter.hh +++ b/src/tgbaalgos/reachiter.hh @@ -35,7 +35,7 @@ namespace spot class SPOT_API tgba_reachable_iterator { public: - tgba_reachable_iterator(const tgba* a); + tgba_reachable_iterator(const const_tgba_ptr& a); virtual ~tgba_reachable_iterator(); /// \brief Iterate over all reachable states of a spot::tgba. @@ -89,7 +89,7 @@ namespace spot const tgba_succ_iterator* si); protected: - const tgba* aut_; ///< The spot::tgba to explore. + const_tgba_ptr aut_; ///< The spot::tgba to explore. typedef std::unordered_map seen_map; @@ -103,7 +103,7 @@ namespace spot public tgba_reachable_iterator { public: - tgba_reachable_iterator_breadth_first(const tgba* a); + tgba_reachable_iterator_breadth_first(const const_tgba_ptr& a); virtual void add_state(const state* s); virtual const state* next_state(); @@ -117,7 +117,7 @@ namespace spot class SPOT_API tgba_reachable_iterator_depth_first { public: - tgba_reachable_iterator_depth_first(const tgba* a); + tgba_reachable_iterator_depth_first(const const_tgba_ptr& a); virtual ~tgba_reachable_iterator_depth_first(); /// \brief Iterate over all reachable states of a spot::tgba. @@ -159,7 +159,7 @@ namespace spot const tgba_succ_iterator* si); protected: - const tgba* aut_; ///< The spot::tgba to explore. + const_tgba_ptr aut_; ///< The spot::tgba to explore. typedef std::unordered_map seen_map; @@ -187,7 +187,7 @@ namespace spot : public tgba_reachable_iterator_depth_first { public: - tgba_reachable_iterator_depth_first_stack(const tgba* a); + tgba_reachable_iterator_depth_first_stack(const const_tgba_ptr& a); /// \brief Whether state sn is on the DFS stack. /// /// Note the destination state of a transition is only pushed to diff --git a/src/tgbaalgos/reducerun.cc b/src/tgbaalgos/reducerun.cc index f19da6ff5..ce4381625 100644 --- a/src/tgbaalgos/reducerun.cc +++ b/src/tgbaalgos/reducerun.cc @@ -32,7 +32,7 @@ namespace spot class shortest_path: public bfs_steps { public: - shortest_path(const tgba* a) + shortest_path(const const_tgba_ptr& a) : bfs_steps(a), target(0) { } @@ -87,7 +87,7 @@ namespace spot } tgba_run* - reduce_run(const tgba* a, const tgba_run* org) + reduce_run(const const_tgba_ptr& a, const tgba_run* org) { tgba_run* res = new tgba_run; state_set ss; diff --git a/src/tgbaalgos/reducerun.hh b/src/tgbaalgos/reducerun.hh index e0fb605d9..9dadcef29 100644 --- a/src/tgbaalgos/reducerun.hh +++ b/src/tgbaalgos/reducerun.hh @@ -1,6 +1,6 @@ // -*- coding: utf-8 -*- -// Copyright (C) 2010, 2013 Laboratoire de Recherche et Développement de -// l'Epita. +// Copyright (C) 2010, 2013, 2014 Laboratoire de Recherche et +// Développement de l'Epita. // Copyright (C) 2004 Laboratoire d'Informatique de Paris 6 (LIP6), // département Systèmes Répartis Coopératifs (SRC), Université Pierre // et Marie Curie. @@ -24,10 +24,10 @@ # define SPOT_TGBAALGOS_REDUCERUN_HH # include "misc/common.hh" +# include "tgba/fwd.hh" namespace spot { - class tgba; struct tgba_run; /// \ingroup tgba_run @@ -36,7 +36,7 @@ namespace spot /// Return a run which is accepting for \a a and that is no longer /// than \a org. SPOT_API tgba_run* - reduce_run(const tgba* a, const tgba_run* org); + reduce_run(const const_tgba_ptr& a, const tgba_run* org); } #endif // SPOT_TGBAALGOS_REDUCERUN_HH diff --git a/src/tgbaalgos/replayrun.cc b/src/tgbaalgos/replayrun.cc index 64f4308e6..b5d9a06b3 100644 --- a/src/tgbaalgos/replayrun.cc +++ b/src/tgbaalgos/replayrun.cc @@ -32,7 +32,7 @@ namespace spot namespace { void - print_annotation(std::ostream& os, const tgba* a, + print_annotation(std::ostream& os, const_tgba_ptr a, const tgba_succ_iterator* i) { std::string s = a->transition_annotation(i); @@ -43,8 +43,8 @@ namespace spot } bool - replay_tgba_run(std::ostream& os, const tgba* a, const tgba_run* run, - bool debug) + replay_tgba_run(std::ostream& os, const const_tgba_ptr& a, + const tgba_run* run, bool debug) { const state* s = a->get_init_state(); int serial = 1; diff --git a/src/tgbaalgos/replayrun.hh b/src/tgbaalgos/replayrun.hh index 46da88dbc..1f6ad50dc 100644 --- a/src/tgbaalgos/replayrun.hh +++ b/src/tgbaalgos/replayrun.hh @@ -1,5 +1,5 @@ // -*- coding: utf-8 -*- -// Copyright (C) 2013 Laboratoire de Recherche et Developpement +// Copyright (C) 2013, 2014 Laboratoire de Recherche et Developpement // de l'Epita (LRDE). // Copyright (C) 2004 Laboratoire d'Informatique de Paris 6 (LIP6), // département Systèmes Répartis Coopératifs (SRC), Université Pierre @@ -25,11 +25,11 @@ # include "misc/common.hh" # include +# include "tgba/fwd.hh" namespace spot { struct tgba_run; - class tgba; /// \ingroup tgba_run /// \brief Replay a tgba_run on a tgba. @@ -47,7 +47,8 @@ namespace spot /// debugging informations will be output on failure /// \return true iff the run could be completed SPOT_API bool - replay_tgba_run(std::ostream& os, const tgba* a, const tgba_run* run, + replay_tgba_run(std::ostream& os, + const const_tgba_ptr& a, const tgba_run* run, bool debug = false); } diff --git a/src/tgbaalgos/rundotdec.cc b/src/tgbaalgos/rundotdec.cc index 1201334ae..458591a2c 100644 --- a/src/tgbaalgos/rundotdec.cc +++ b/src/tgbaalgos/rundotdec.cc @@ -44,7 +44,8 @@ namespace spot } std::string - tgba_run_dotty_decorator::state_decl(const tgba*, const state* s, int, + tgba_run_dotty_decorator::state_decl(const const_tgba_ptr&, + const state* s, int, tgba_succ_iterator*, const std::string& label, bool accepting) @@ -80,7 +81,7 @@ namespace spot } std::string - tgba_run_dotty_decorator::link_decl(const tgba*, + tgba_run_dotty_decorator::link_decl(const const_tgba_ptr&, const state* in_s, int, const state* out_s, int, const tgba_succ_iterator* si, diff --git a/src/tgbaalgos/rundotdec.hh b/src/tgbaalgos/rundotdec.hh index eb888e20e..cad77251a 100644 --- a/src/tgbaalgos/rundotdec.hh +++ b/src/tgbaalgos/rundotdec.hh @@ -1,5 +1,5 @@ // -*- coding: utf-8 -*- -// Copyright (C) 2011, 2013 Laboratoire de Recherche et Developpement +// Copyright (C) 2011, 2013, 2014 Laboratoire de Recherche et Developpement // de l'Epita (LRDE). // Copyright (C) 2004 Laboratoire d'Informatique de Paris 6 (LIP6), // département Systèmes Répartis Coopératifs (SRC), Université Pierre @@ -41,11 +41,12 @@ namespace spot tgba_run_dotty_decorator(const tgba_run* run); virtual ~tgba_run_dotty_decorator(); - virtual std::string state_decl(const tgba* a, const state* s, int n, + virtual std::string state_decl(const const_tgba_ptr& a, + const state* s, int n, tgba_succ_iterator* si, const std::string& label, bool accepting); - virtual std::string link_decl(const tgba* a, + virtual std::string link_decl(const const_tgba_ptr& a, const state* in_s, int in, const state* out_s, int out, const tgba_succ_iterator* si, diff --git a/src/tgbaalgos/safety.cc b/src/tgbaalgos/safety.cc index 6b04b5680..032136bef 100644 --- a/src/tgbaalgos/safety.cc +++ b/src/tgbaalgos/safety.cc @@ -24,7 +24,7 @@ namespace spot { bool - is_guarantee_automaton(const tgba* aut, const scc_map* sm) + is_guarantee_automaton(const const_tgba_ptr& aut, const scc_map* sm) { // Create an scc_map of the user did not give one to us. bool need_sm = !sm; @@ -69,7 +69,7 @@ namespace spot return result; } - bool is_safety_mwdba(const tgba* aut) + bool is_safety_mwdba(const const_tgba_ptr& aut) { state_unicity_table seen; // States already seen. std::deque todo; // A queue of states yet to explore. diff --git a/src/tgbaalgos/safety.hh b/src/tgbaalgos/safety.hh index 2369ecc9a..f083a1d20 100644 --- a/src/tgbaalgos/safety.hh +++ b/src/tgbaalgos/safety.hh @@ -47,7 +47,7 @@ namespace spot /// built otherwise. If you supply an scc_map you should call /// build_map() before passing it to this function. SPOT_API bool - is_guarantee_automaton(const tgba* aut, const scc_map* sm = 0); + is_guarantee_automaton(const const_tgba_ptr& aut, const scc_map* sm = 0); /// \brief Whether a minimized WDBA represents a safety property. /// @@ -57,7 +57,7 @@ namespace spot /// /// \param aut the automaton to check SPOT_API bool - is_safety_mwdba(const tgba* aut); + is_safety_mwdba(const const_tgba_ptr& aut); } diff --git a/src/tgbaalgos/save.cc b/src/tgbaalgos/save.cc index fc1ac9d4c..eb6f1682d 100644 --- a/src/tgbaalgos/save.cc +++ b/src/tgbaalgos/save.cc @@ -35,7 +35,7 @@ namespace spot class save_bfs: public tgba_reachable_iterator_breadth_first { public: - save_bfs(const tgba* a, std::ostream& os) + save_bfs(const const_tgba_ptr& a, std::ostream& os) : tgba_reachable_iterator_breadth_first(a), os_(os) { } @@ -95,7 +95,7 @@ namespace spot } std::ostream& - tgba_save_reachable(std::ostream& os, const tgba* g) + tgba_save_reachable(std::ostream& os, const_tgba_ptr g) { save_bfs b(g, os); b.run(); diff --git a/src/tgbaalgos/save.hh b/src/tgbaalgos/save.hh index 73a47b2b7..420564934 100644 --- a/src/tgbaalgos/save.hh +++ b/src/tgbaalgos/save.hh @@ -31,7 +31,7 @@ namespace spot /// \ingroup tgba_io /// \brief Save reachable states in text format. SPOT_API std::ostream& - tgba_save_reachable(std::ostream& os, const tgba* g); + tgba_save_reachable(std::ostream& os, const_tgba_ptr g); } #endif // SPOT_TGBAALGOS_SAVE_HH diff --git a/src/tgbaalgos/scc.cc b/src/tgbaalgos/scc.cc index c9e915e01..eca0d75ed 100644 --- a/src/tgbaalgos/scc.cc +++ b/src/tgbaalgos/scc.cc @@ -40,7 +40,7 @@ namespace spot } - scc_map::scc_map(const tgba* aut) + scc_map::scc_map(const const_tgba_ptr& aut) : aut_(aut) { } @@ -89,7 +89,7 @@ namespace spot return acc_set_of(n) == aut_->all_acceptance_conditions(); } - const tgba* + const_tgba_ptr scc_map::get_aut() const { return aut_; @@ -460,7 +460,7 @@ namespace spot } scc_stats - build_scc_stats(const tgba* a) + build_scc_stats(const const_tgba_ptr& a) { scc_map m(a); m.build_map(); @@ -549,7 +549,7 @@ namespace spot } std::ostream& - dump_scc_dot(const tgba* a, std::ostream& out, bool verbose) + dump_scc_dot(const const_tgba_ptr& a, std::ostream& out, bool verbose) { scc_map m(a); m.build_map(); diff --git a/src/tgbaalgos/scc.hh b/src/tgbaalgos/scc.hh index 809a1c0a0..8f59506f7 100644 --- a/src/tgbaalgos/scc.hh +++ b/src/tgbaalgos/scc.hh @@ -1,5 +1,5 @@ // -*- coding: utf-8 -*- -// Copyright (C) 2008, 2009, 2010, 2011, 2012, 2013 Laboratoire de +// Copyright (C) 2008, 2009, 2010, 2011, 2012, 2013, 2014 Laboratoire de // Recherche et Développement de l'Epita. // // This file is part of Spot, a model checking library. @@ -77,7 +77,7 @@ namespace spot /// /// This will note compute the map initially. You should call /// build_map() to do so. - scc_map(const tgba* aut); + scc_map(const const_tgba_ptr& aut); ~scc_map(); @@ -85,7 +85,7 @@ namespace spot void build_map(); /// Get the automaton for which the map has been constructed. - const tgba* get_aut() const; + const_tgba_ptr get_aut() const; /// \brief Get the number of SCC in the automaton. /// @@ -216,7 +216,7 @@ namespace spot bdd useful_acc; }; - const tgba* aut_; // Automata to decompose. + const_tgba_ptr aut_; // Automata to decompose. typedef std::list stack_type; stack_type root_; // Stack of SCC roots. std::stack arc_acc_; // A stack of acceptance conditions @@ -248,12 +248,13 @@ namespace spot }; SPOT_API scc_stats - build_scc_stats(const tgba* a); + build_scc_stats(const const_tgba_ptr& a); SPOT_API scc_stats build_scc_stats(const scc_map& m); SPOT_API std::ostream& - dump_scc_dot(const tgba* a, std::ostream& out, bool verbose = false); + dump_scc_dot(const const_tgba_ptr& a, + std::ostream& out, bool verbose = false); SPOT_API std::ostream& dump_scc_dot(const scc_map& m, std::ostream& out, bool verbose = false); } diff --git a/src/tgbaalgos/sccfilter.cc b/src/tgbaalgos/sccfilter.cc index ec49d19f9..c8e4ed9c0 100644 --- a/src/tgbaalgos/sccfilter.cc +++ b/src/tgbaalgos/sccfilter.cc @@ -207,7 +207,7 @@ namespace spot std::vector useful_table(scc_count); std::vector useless_table(scc_count); unsigned max_num = 1; - const tgba_digraph* aut = this->si->get_aut(); + const_tgba_digraph_ptr aut = this->si->get_aut(); std::vector used_acc = this->si->used_acc(); @@ -431,10 +431,10 @@ namespace spot template - tgba_digraph* scc_filter_apply(const tgba_digraph* aut, + tgba_digraph_ptr scc_filter_apply(const_tgba_digraph_ptr aut, scc_info* given_si, Args&&... args) { - tgba_digraph* filtered = new tgba_digraph(aut->get_dict()); + tgba_digraph_ptr filtered = make_tgba_digraph(aut->get_dict()); unsigned in_n = aut->num_states(); // Number of input states. if (in_n == 0) // Nothing to filter. return filtered; @@ -495,8 +495,8 @@ namespace spot } - tgba_digraph* - scc_filter_states(const tgba_digraph* aut, scc_info* given_si) + tgba_digraph_ptr + scc_filter_states(const const_tgba_digraph_ptr& aut, scc_info* given_si) { bool sb = aut->get_bprop(tgba_digraph::StateBasedAcc); auto res = scc_filter_apply>(aut, given_si); @@ -505,11 +505,11 @@ namespace spot return res; } - tgba_digraph* - scc_filter(const tgba_digraph* aut, bool remove_all_useless, + tgba_digraph_ptr + scc_filter(const const_tgba_digraph_ptr& aut, bool remove_all_useless, scc_info* given_si) { - tgba_digraph* res; + tgba_digraph_ptr res; if (remove_all_useless) res = scc_filter_apply +#include "tgba/fwd.hh" namespace spot { class scc_map; - class tgba; - class tgba_digraph; class scc_info; @@ -60,8 +59,8 @@ namespace spot /// (i.e., transitions leaving accepting states are all marked as /// accepting) may destroy this property. Use scc_filter_states() /// instead. - SPOT_API tgba_digraph* - scc_filter(const tgba_digraph* aut, bool remove_all_useless = false, + SPOT_API tgba_digraph_ptr + scc_filter(const const_tgba_digraph_ptr& aut, bool remove_all_useless = false, scc_info* given_si = 0); /// \brief Prune unaccepting SCCs. @@ -72,8 +71,8 @@ namespace spot /// Especially, if the input TGBA has the SBA property, (i.e., /// transitions leaving accepting states are all marked as /// accepting), then the output TGBA will also have that property. - SPOT_API tgba_digraph* - scc_filter_states(const tgba_digraph* aut, scc_info* given_si = 0); + SPOT_API tgba_digraph_ptr + scc_filter_states(const const_tgba_digraph_ptr& aut, scc_info* given_si = 0); /// \brief Prune unaccepting SCCs, superfluous acceptance /// sets, and suspension variables. @@ -85,8 +84,8 @@ namespace spot /// /// This is used by compsusp(), and is probably useless for any /// other use. - SPOT_API tgba_digraph* - scc_filter_susp(const tgba_digraph* aut, bool remove_all_useless, + SPOT_API tgba_digraph_ptr + scc_filter_susp(const const_tgba_digraph_ptr& aut, bool remove_all_useless, bdd suspvars, bdd ignoredvars, bool early_susp, scc_info* given_si = 0); } diff --git a/src/tgbaalgos/sccinfo.cc b/src/tgbaalgos/sccinfo.cc index 07d612bdb..0c1acce98 100644 --- a/src/tgbaalgos/sccinfo.cc +++ b/src/tgbaalgos/sccinfo.cc @@ -45,7 +45,7 @@ namespace spot }; } - scc_info::scc_info(const tgba_digraph* aut) + scc_info::scc_info(const_tgba_digraph_ptr aut) : aut_(aut) { unsigned n = aut->num_states(); @@ -261,7 +261,7 @@ namespace spot std::ostream& dump_scc_info_dot(std::ostream& out, - const tgba_digraph* aut, scc_info* sccinfo) + const_tgba_digraph_ptr aut, scc_info* sccinfo) { scc_info* m = sccinfo ? sccinfo : new scc_info(aut); diff --git a/src/tgbaalgos/sccinfo.hh b/src/tgbaalgos/sccinfo.hh index 0d0f8ac38..840410f68 100644 --- a/src/tgbaalgos/sccinfo.hh +++ b/src/tgbaalgos/sccinfo.hh @@ -66,7 +66,7 @@ namespace spot std::vector sccof_; std::vector node_; - const tgba_digraph* aut_; + const_tgba_digraph_ptr aut_; const scc_node& node(unsigned scc) const @@ -76,9 +76,9 @@ namespace spot } public: - scc_info(const tgba_digraph* aut); + scc_info(const_tgba_digraph_ptr aut); - const tgba_digraph* get_aut() const + const_tgba_digraph_ptr get_aut() const { return aut_; } @@ -156,7 +156,7 @@ namespace spot /// If \a sccinfo is not given, it will be computed. SPOT_API std::ostream& dump_scc_info_dot(std::ostream& out, - const tgba_digraph* aut, scc_info* sccinfo = nullptr); + const_tgba_digraph_ptr aut, scc_info* sccinfo = nullptr); } diff --git a/src/tgbaalgos/se05.cc b/src/tgbaalgos/se05.cc index 0238fdf55..2f2381978 100644 --- a/src/tgbaalgos/se05.cc +++ b/src/tgbaalgos/se05.cc @@ -54,7 +54,8 @@ namespace spot /// /// \pre The automaton \a a must have at most one acceptance /// condition (i.e. it is a TBA). - se05_search(const tgba *a, size_t size, option_map o = option_map()) + se05_search(const const_tgba_ptr a, size_t size, + option_map o = option_map()) : emptiness_check(a, o), h(size), all_cond(a->all_acceptance_conditions()) @@ -674,19 +675,20 @@ namespace spot } // anonymous - emptiness_check* explicit_se05_search(const tgba *a, option_map o) + emptiness_check* explicit_se05_search(const const_tgba_ptr& a, option_map o) { return new se05_search(a, 0, o); } - emptiness_check* bit_state_hashing_se05_search(const tgba *a, size_t size, - option_map o) + emptiness_check* bit_state_hashing_se05_search(const const_tgba_ptr& a, + size_t size, + option_map o) { return new se05_search(a, size, o); } emptiness_check* - se05(const tgba *a, option_map o) + se05(const const_tgba_ptr& a, option_map o) { size_t size = o.get("bsh"); if (size) diff --git a/src/tgbaalgos/se05.hh b/src/tgbaalgos/se05.hh index 6df3fcb62..d50a9d856 100644 --- a/src/tgbaalgos/se05.hh +++ b/src/tgbaalgos/se05.hh @@ -1,5 +1,5 @@ // -*- coding: utf-8 -*- -// Copyright (C) 2013 Laboratoire de Recherche et Developpement +// Copyright (C) 2013, 2014 Laboratoire de Recherche et Developpement // de l'Epita (LRDE). // Copyright (C) 2004, 2005 Laboratoire d'Informatique de Paris 6 // (LIP6), département Systèmes Répartis Coopératifs (SRC), Université @@ -23,12 +23,12 @@ #ifndef SPOT_TGBAALGOS_SE05_HH # define SPOT_TGBAALGOS_SE05_HH -#include -#include "misc/optionmap.hh" +# include +# include "misc/optionmap.hh" +# include "tgba/fwd.hh" namespace spot { - class tgba; class emptiness_check; /// \addtogroup emptiness_check_algorithms @@ -103,7 +103,7 @@ namespace spot /// \sa spot::explicit_magic_search /// SPOT_API emptiness_check* - explicit_se05_search(const tgba *a, option_map o = option_map()); + explicit_se05_search(const const_tgba_ptr& a, option_map o = option_map()); /// \brief Returns an emptiness checker on the spot::tgba automaton \a a. /// @@ -133,7 +133,7 @@ namespace spot /// \sa spot::explicit_se05_search /// SPOT_API emptiness_check* - bit_state_hashing_se05_search(const tgba *a, size_t size, + bit_state_hashing_se05_search(const const_tgba_ptr& a, size_t size, option_map o = option_map()); @@ -144,7 +144,7 @@ namespace spot /// in the \c option_map. If \c "bsh" is set and non null, its value /// is used as the size of the hash map. SPOT_API emptiness_check* - se05(const tgba *a, option_map o); + se05(const const_tgba_ptr& a, option_map o); /// @} } diff --git a/src/tgbaalgos/simulation.cc b/src/tgbaalgos/simulation.cc index 84b198cec..c00084fe2 100644 --- a/src/tgbaalgos/simulation.cc +++ b/src/tgbaalgos/simulation.cc @@ -156,6 +156,18 @@ namespace spot { } + automaton_size(const tgba_digraph_ptr& a) + : transitions(a->num_transitions()), + states(a->num_states()) + { + } + + void set_size(const tgba_digraph_ptr& a) + { + states = a->num_states(); + transitions = a->num_transitions(); + } + inline bool operator!=(const automaton_size& r) { return transitions != r.transitions || states != r.states; @@ -204,7 +216,8 @@ namespace spot // Shortcut used in update_po and go_to_next_it. typedef std::map map_bdd_bdd; public: - direct_simulation(const tgba* t, const map_constraint* map_cst = 0) + direct_simulation(const const_tgba_ptr& t, + const map_constraint* map_cst = 0) : a_(0), po_size_(0), all_class_var_(bddtrue), @@ -230,7 +243,7 @@ namespace spot { if (Cosimulation) { - a_ = new tgba_digraph(a_->get_dict()); + a_ = make_tgba_digraph(a_->get_dict()); a_->copy_ap_of(old_a_); a_->copy_acceptance_conditions_of(old_a_); } @@ -311,11 +324,6 @@ namespace spot { a_->get_dict()->unregister_all_my_variables(this); delete scc_map_; - - delete old_a_; - // a_ is a new automaton only if we are doing a cosimulation. - if (Cosimulation) - delete a_; } // Update the name of the classes. @@ -363,7 +371,7 @@ namespace spot } // The core loop of the algorithm. - tgba_digraph* run() + tgba_digraph_ptr run() { main_loop(); return build_result(); @@ -518,13 +526,6 @@ namespace spot } } - automaton_size get_stat() const - { - assert(stat.states != 0); - - return stat; - } - bool result_is_deterministic() const { assert(stat.states != 0); @@ -535,7 +536,7 @@ namespace spot // Build the minimal resulting automaton. - tgba_digraph* build_result() + tgba_digraph_ptr build_result() { // We have all the a_'s acceptances conditions // complemented. So we need to complement it when adding a @@ -545,7 +546,7 @@ namespace spot acc_compl reverser(all_acceptance_conditions_, a_->neg_acceptance_conditions()); - tgba_digraph* res = new tgba_digraph(a_->get_dict()); + tgba_digraph_ptr res = make_tgba_digraph(a_->get_dict()); res->copy_ap_of(a_); res->set_acceptance_conditions(all_acceptance_conditions_); if (Sba) @@ -728,8 +729,8 @@ namespace spot protected: // The automaton which is simulated. - tgba_digraph* a_; - tgba_digraph* old_a_; + tgba_digraph_ptr a_; + tgba_digraph_ptr old_a_; // Relation is aimed to represent the same thing than // rel_. The difference is in the way it does. @@ -775,7 +776,7 @@ namespace spot const map_constraint* map_cst_; - const tgba* original_; + const_tgba_ptr original_; bdd all_acceptance_conditions_; @@ -795,7 +796,7 @@ namespace spot public: - direct_simulation_dont_care(const tgba* t) + direct_simulation_dont_care(const const_tgba_ptr& t) : direct_simulation(t) { // This variable is used in the new signature. @@ -1098,12 +1099,7 @@ namespace spot return res; } - inline automaton_size get_stat() const - { - return min_size_; - } - - tgba_digraph* run() + tgba_digraph_ptr run() { // Iterate the simulation until the end. We just don't return // an automaton. This allows us to get all the information @@ -1188,14 +1184,14 @@ namespace spot assert(previous_class_[i.second] == i.first); #endif - tgba_digraph* min = 0; + tgba_digraph_ptr min = nullptr; map_constraint cstr; if (has_limit_) - rec(cc, cstr, &min, limit_); + rec(cc, cstr, min, limit_); else - rec(cc, cstr, &min); + rec(cc, cstr, min); return min; } @@ -1247,7 +1243,7 @@ namespace spot // Compute recursively all the combinations. void rec(constraint_list constraints, map_constraint cstr, - tgba_digraph** min, + tgba_digraph_ptr& min, int max_depth = std::numeric_limits::max()) { assert(max_depth > 0); @@ -1265,19 +1261,14 @@ namespace spot empty_seen_ = true; direct_simulation dir_sim(original_, &cstr); - tgba_digraph* tmp = dir_sim.run(); - automaton_size cur_size = dir_sim.get_stat(); - if (*min == 0 || min_size_ > cur_size) + tgba_digraph_ptr tmp = dir_sim.run(); + automaton_size cur_size(tmp); + if (!min || min_size_ > cur_size) { - delete *min; - *min = tmp; + min = tmp; min_size_ = cur_size; res_is_deterministic = dir_sim.result_is_deterministic(); } - else - { - delete tmp; - } } void set_limit(int n) @@ -1309,29 +1300,29 @@ namespace spot } // End namespace anonymous. - tgba_digraph* - simulation(const tgba* t) + tgba_digraph_ptr + simulation(const const_tgba_ptr& t) { direct_simulation simul(t); return simul.run(); } - tgba_digraph* - simulation_sba(const tgba* t) + tgba_digraph_ptr + simulation_sba(const const_tgba_ptr& t) { direct_simulation simul(t); return simul.run(); } - tgba_digraph* - cosimulation(const tgba* t) + tgba_digraph_ptr + cosimulation(const const_tgba_ptr& t) { direct_simulation simul(t); return simul.run(); } - tgba_digraph* - cosimulation_sba(const tgba* t) + tgba_digraph_ptr + cosimulation_sba(const const_tgba_ptr& t) { direct_simulation simul(t); return simul.run(); @@ -1339,10 +1330,10 @@ namespace spot template - tgba_digraph* - iterated_simulations_(const tgba* t) + tgba_digraph_ptr + iterated_simulations_(const const_tgba_ptr& t) { - tgba_digraph* res = 0; + tgba_digraph_ptr res = 0; automaton_size prev; automaton_size next; @@ -1350,80 +1341,59 @@ namespace spot { prev = next; direct_simulation simul(res ? res : t); - tgba_digraph* after_simulation = simul.run(); - delete res; - + res = simul.run(); if (simul.result_is_deterministic()) - { - res = after_simulation; - break; - } + break; - direct_simulation cosimul(after_simulation); - tgba_digraph* after_cosimulation = cosimul.run(); - next = cosimul.get_stat(); - delete after_simulation; + direct_simulation cosimul(res); + res = cosimul.run(); + next.set_size(res); if (Sba) - res = scc_filter_states(after_cosimulation); + res = scc_filter_states(res); else - res = scc_filter(after_cosimulation, false); - delete after_cosimulation; + res = scc_filter(res, false); } while (prev != next); return res; } - tgba_digraph* - iterated_simulations(const tgba* t) + tgba_digraph_ptr + iterated_simulations(const const_tgba_ptr& t) { return iterated_simulations_(t); } - tgba_digraph* - iterated_simulations_sba(const tgba* t) + tgba_digraph_ptr + iterated_simulations_sba(const const_tgba_ptr& t) { return iterated_simulations_(t); } - tgba_digraph* - dont_care_simulation(const tgba* t, int limit) + tgba_digraph_ptr + dont_care_simulation(const const_tgba_ptr& t, int limit) { direct_simulation sim(t); - tgba_digraph* tmp = sim.run(); - - direct_simulation_dont_care s(tmp); + direct_simulation_dont_care s(sim.run()); if (limit > 0) s.set_limit(limit); - - tgba_digraph* res = s.run(); - delete tmp; - - return res; + return s.run(); } - tgba_digraph* - dont_care_iterated_simulations(const tgba* t, int limit) + tgba_digraph_ptr + dont_care_iterated_simulations(const const_tgba_ptr& t, int limit) { - tgba_digraph* res = 0; + tgba_digraph_ptr res = 0; automaton_size prev; automaton_size next; do { prev = next; - tgba_digraph* after_simulation = - dont_care_simulation(res ? res : t, limit); - delete res; - - direct_simulation cosimul(after_simulation); - tgba_digraph* after_cosimulation = cosimul.run(); - delete after_simulation; - - next = cosimul.get_stat(); - res = scc_filter(after_cosimulation, true); - delete after_cosimulation; + res = cosimulation(dont_care_simulation(res ? res : t, limit)); + res = scc_filter(res, true); + next.set_size(res); } while (prev != next); diff --git a/src/tgbaalgos/simulation.hh b/src/tgbaalgos/simulation.hh index 9eaa5cbe9..2cea31187 100644 --- a/src/tgbaalgos/simulation.hh +++ b/src/tgbaalgos/simulation.hh @@ -70,8 +70,8 @@ namespace spot /// \param automaton the automaton to simulate. /// \return a new automaton which is at worst a copy of the received /// one - SPOT_API tgba_digraph* simulation(const tgba* automaton); - SPOT_API tgba_digraph* simulation_sba(const tgba* automaton); + SPOT_API tgba_digraph_ptr simulation(const const_tgba_ptr& automaton); + SPOT_API tgba_digraph_ptr simulation_sba(const const_tgba_ptr& automaton); /// @} /// @{ @@ -121,8 +121,8 @@ namespace spot /// \param automaton the automaton to simulate. /// \return a new automaton which is at worst a copy of the received /// one - SPOT_API tgba_digraph* cosimulation(const tgba* automaton); - SPOT_API tgba_digraph* cosimulation_sba(const tgba* automaton); + SPOT_API tgba_digraph_ptr cosimulation(const const_tgba_ptr& automaton); + SPOT_API tgba_digraph_ptr cosimulation_sba(const const_tgba_ptr& automaton); /// @} /// @{ @@ -140,16 +140,18 @@ namespace spot /// \param automaton the automaton to simulate. /// \return a new automaton which is at worst a copy of the received /// one - SPOT_API tgba_digraph* iterated_simulations(const tgba* automaton); - SPOT_API tgba_digraph* iterated_simulations_sba(const tgba* automaton); + SPOT_API tgba_digraph_ptr + iterated_simulations(const const_tgba_ptr& automaton); + SPOT_API tgba_digraph_ptr + iterated_simulations_sba(const const_tgba_ptr& automaton); /// @} - SPOT_API tgba_digraph* - dont_care_simulation(const tgba* t, int limit = -1); + SPOT_API tgba_digraph_ptr + dont_care_simulation(const const_tgba_ptr& t, int limit = -1); - SPOT_API tgba_digraph* - dont_care_iterated_simulations(const tgba* t, int limit = -1); + SPOT_API tgba_digraph_ptr + dont_care_iterated_simulations(const const_tgba_ptr& t, int limit = -1); /// @} diff --git a/src/tgbaalgos/stats.cc b/src/tgbaalgos/stats.cc index 175552ffd..507134158 100644 --- a/src/tgbaalgos/stats.cc +++ b/src/tgbaalgos/stats.cc @@ -34,7 +34,7 @@ namespace spot class stats_bfs: public tgba_reachable_iterator_breadth_first { public: - stats_bfs(const tgba* a, tgba_statistics& s) + stats_bfs(const const_tgba_ptr& a, tgba_statistics& s) : tgba_reachable_iterator_breadth_first(a), s_(s) { } @@ -59,7 +59,7 @@ namespace spot class sub_stats_bfs: public stats_bfs { public: - sub_stats_bfs(const tgba* a, tgba_sub_statistics& s) + sub_stats_bfs(const const_tgba_ptr& a, tgba_sub_statistics& s) : stats_bfs(a, s), s_(s), seen_(bddtrue) { } @@ -116,7 +116,7 @@ namespace spot } tgba_statistics - stats_reachable(const tgba* g) + stats_reachable(const const_tgba_ptr& g) { tgba_statistics s; stats_bfs d(g, s); @@ -125,7 +125,7 @@ namespace spot } tgba_sub_statistics - sub_stats_reachable(const tgba* g) + sub_stats_reachable(const const_tgba_ptr& g) { tgba_sub_statistics s; sub_stats_bfs d(g, s); @@ -157,7 +157,7 @@ namespace spot } std::ostream& - stat_printer::print(const tgba* aut, + stat_printer::print(const const_tgba_ptr& aut, const ltl::formula* f, double run_time) { diff --git a/src/tgbaalgos/stats.hh b/src/tgbaalgos/stats.hh index 3c4fa41d6..5abbe3169 100644 --- a/src/tgbaalgos/stats.hh +++ b/src/tgbaalgos/stats.hh @@ -51,9 +51,9 @@ namespace spot }; /// \brief Compute statistics for an automaton. - SPOT_API tgba_statistics stats_reachable(const tgba* g); + SPOT_API tgba_statistics stats_reachable(const const_tgba_ptr& g); /// \brief Compute subended statistics for an automaton. - SPOT_API tgba_sub_statistics sub_stats_reachable(const tgba* g); + SPOT_API tgba_sub_statistics sub_stats_reachable(const const_tgba_ptr& g); class SPOT_API printable_formula: public printable_value @@ -85,7 +85,7 @@ namespace spot /// The \a f argument is not needed if the Formula does not need /// to be output, and so is \a run_time). std::ostream& - print(const tgba* aut, const ltl::formula* f = 0, + print(const const_tgba_ptr& aut, const ltl::formula* f = 0, double run_time = -1.); private: diff --git a/src/tgbaalgos/stripacc.cc b/src/tgbaalgos/stripacc.cc index 5a366f086..ee5a45ceb 100644 --- a/src/tgbaalgos/stripacc.cc +++ b/src/tgbaalgos/stripacc.cc @@ -22,7 +22,7 @@ namespace spot { - void strip_acceptance_here(tgba_digraph* a) + void strip_acceptance_here(tgba_digraph_ptr a) { unsigned n = a->num_states(); for (unsigned s = 0; s < n; ++s) diff --git a/src/tgbaalgos/stripacc.hh b/src/tgbaalgos/stripacc.hh index 7ff3346e7..ef785545c 100644 --- a/src/tgbaalgos/stripacc.hh +++ b/src/tgbaalgos/stripacc.hh @@ -29,7 +29,7 @@ namespace spot /// /// This is equivalent to marking all states/transitions as accepting. SPOT_API void - strip_acceptance_here(tgba_digraph* a); + strip_acceptance_here(tgba_digraph_ptr a); } #endif // SPOT_TGBAALGOS_STRIPACC_HH diff --git a/src/tgbaalgos/tau03.cc b/src/tgbaalgos/tau03.cc index 4ea97040a..e18c5d5c6 100644 --- a/src/tgbaalgos/tau03.cc +++ b/src/tgbaalgos/tau03.cc @@ -54,7 +54,7 @@ namespace spot { public: /// \brief Initialize the search algorithm on the automaton \a a - tau03_search(const tgba *a, size_t size, option_map o) + tau03_search(const const_tgba_ptr a, size_t size, option_map o) : emptiness_check(a, o), h(size), all_cond(a->all_acceptance_conditions()) @@ -374,7 +374,7 @@ namespace spot } // anonymous - emptiness_check* explicit_tau03_search(const tgba *a, option_map o) + emptiness_check* explicit_tau03_search(const const_tgba_ptr& a, option_map o) { return new tau03_search(a, 0, o); } diff --git a/src/tgbaalgos/tau03.hh b/src/tgbaalgos/tau03.hh index 0c0b2bc41..cf99a6239 100644 --- a/src/tgbaalgos/tau03.hh +++ b/src/tgbaalgos/tau03.hh @@ -1,5 +1,5 @@ // -*- coding: utf-8 -*- -// Copyright (C) 2013 Laboratoire de Recherche et Développement de +// Copyright (C) 2013, 2014 Laboratoire de Recherche et Développement de // l'Epita (LRDE). // Copyright (C) 2004, 2005 Laboratoire d'Informatique de Paris 6 (LIP6), // département Systèmes Répartis Coopératifs (SRC), Université Pierre @@ -23,11 +23,11 @@ #ifndef SPOT_TGBAALGOS_TAU03_HH # define SPOT_TGBAALGOS_TAU03_HH -#include "misc/optionmap.hh" +# include "misc/optionmap.hh" +# include "tgba/fwd.hh" namespace spot { - class tgba; class emptiness_check; /// \addtogroup emptiness_check_algorithms @@ -97,7 +97,7 @@ namespace spot \endverbatim */ /// SPOT_API emptiness_check* - explicit_tau03_search(const tgba *a, option_map o = option_map()); + explicit_tau03_search(const const_tgba_ptr& a, option_map o = option_map()); /// @} } diff --git a/src/tgbaalgos/tau03opt.cc b/src/tgbaalgos/tau03opt.cc index 33d5de731..0b042e1ed 100644 --- a/src/tgbaalgos/tau03opt.cc +++ b/src/tgbaalgos/tau03opt.cc @@ -65,7 +65,7 @@ namespace spot { public: /// \brief Initialize the search algorithm on the automaton \a a - tau03_opt_search(const tgba *a, size_t size, option_map o) + tau03_opt_search(const const_tgba_ptr& a, size_t size, option_map o) : emptiness_check(a, o), current_weight(a->neg_acceptance_conditions()), h(size), @@ -572,7 +572,8 @@ namespace spot } // anonymous - emptiness_check* explicit_tau03_opt_search(const tgba *a, option_map o) + emptiness_check* explicit_tau03_opt_search(const const_tgba_ptr& a, + option_map o) { return new tau03_opt_search(a, 0, o); } diff --git a/src/tgbaalgos/tau03opt.hh b/src/tgbaalgos/tau03opt.hh index 1ea721e36..f05addaa4 100644 --- a/src/tgbaalgos/tau03opt.hh +++ b/src/tgbaalgos/tau03opt.hh @@ -1,5 +1,5 @@ // -*- coding: utf-8 -*- -// Copyright (C) 2013 Laboratoire de Recherche et Développement de +// Copyright (C) 2013, 2014 Laboratoire de Recherche et Développement de // l'Epita (LRDE). // Copyright (C) 2004, 2005 Laboratoire d'Informatique de Paris 6 (LIP6), // département Systèmes Répartis Coopératifs (SRC), Université Pierre @@ -23,11 +23,11 @@ #ifndef SPOT_TGBAALGOS_TAU03OPT_HH # define SPOT_TGBAALGOS_TAU03OPT_HH -#include "misc/optionmap.hh" +# include "misc/optionmap.hh" +# include "tgba/fwd.hh" namespace spot { - class tgba; class emptiness_check; /// \addtogroup emptiness_check_algorithms @@ -99,7 +99,8 @@ namespace spot /// state of this stack. /// SPOT_API emptiness_check* - explicit_tau03_opt_search(const tgba *a, option_map o = option_map()); + explicit_tau03_opt_search(const const_tgba_ptr& a, + option_map o = option_map()); /// @} } diff --git a/src/tgbaalgos/translate.cc b/src/tgbaalgos/translate.cc index afbf6f2de..3f8ce0d4d 100644 --- a/src/tgbaalgos/translate.cc +++ b/src/tgbaalgos/translate.cc @@ -61,7 +61,7 @@ namespace spot simpl_owned_ = simpl_ = new ltl::ltl_simplifier(options, dict); } - const tgba_digraph* translator::run(const ltl::formula** f) + const_tgba_digraph_ptr translator::run(const ltl::formula** f) { const ltl::formula* r = simpl_->simplify(*f); (*f)->destroy(); @@ -71,7 +71,7 @@ namespace spot // natural way (improving the degeneralization). simpl_->clear_as_bdd_cache(); - const tgba_digraph* aut; + tgba_digraph_ptr aut; if (comp_susp_ > 0) { int skel_wdba = skel_wdba_; @@ -91,7 +91,7 @@ namespace spot return aut; } - const tgba_digraph* translator::run(const ltl::formula* f) + const_tgba_digraph_ptr translator::run(const ltl::formula* f) { f->clone(); auto aut = run(&f); diff --git a/src/tgbaalgos/translate.hh b/src/tgbaalgos/translate.hh index 2eb6ca16f..e2b1e7a89 100644 --- a/src/tgbaalgos/translate.hh +++ b/src/tgbaalgos/translate.hh @@ -103,14 +103,14 @@ namespace spot /// /// The formula \a f is simplified internally, but it is not /// not destroyed (this is the responsibility of the caller). - const tgba_digraph* run(const ltl::formula* f); + const_tgba_digraph_ptr run(const ltl::formula* f); /// \brief Convert \a f into an automaton, and update f. /// /// The formula *f is destroyed, and replaced /// by the simplified version, which should be destroyed by /// the caller. - const tgba_digraph* run(const ltl::formula** f); + const_tgba_digraph_ptr run(const ltl::formula** f); protected: void setup_opt(const option_map* opt); diff --git a/src/tgbaparse/public.hh b/src/tgbaparse/public.hh index fd62396f4..508a8f660 100644 --- a/src/tgbaparse/public.hh +++ b/src/tgbaparse/public.hh @@ -66,7 +66,7 @@ namespace spot /// /// \warning This function is not reentrant. SPOT_API - tgba_digraph* tgba_parse(const std::string& filename, + tgba_digraph_ptr tgba_parse(const std::string& filename, tgba_parse_error_list& error_list, bdd_dict_ptr dict, ltl::environment& env diff --git a/src/tgbaparse/tgbaparse.yy b/src/tgbaparse/tgbaparse.yy index fbd33bf02..e180f90e1 100644 --- a/src/tgbaparse/tgbaparse.yy +++ b/src/tgbaparse/tgbaparse.yy @@ -46,7 +46,7 @@ %parse-param {spot::tgba_parse_error_list& error_list} %parse-param {spot::ltl::environment& parse_environment} %parse-param {spot::acc_mapper_string& acc_map} -%parse-param {spot::tgba_digraph*& result} +%parse-param {spot::tgba_digraph_ptr& result} %parse-param {named_tgba_t*& namer} %parse-param {formula_cache& fcache} %union @@ -216,7 +216,7 @@ tgbayy::parser::error(const location_type& location, namespace spot { - tgba_digraph* + tgba_digraph_ptr tgba_parse(const std::string& name, tgba_parse_error_list& error_list, bdd_dict_ptr dict, @@ -231,7 +231,7 @@ namespace spot return 0; } formula_cache fcache; - tgba_digraph* result = new tgba_digraph(dict); + auto result = make_tgba_digraph(dict); auto namer = result->create_namer(); spot::acc_mapper_string acc_map(result, envacc); tgbayy::parser parser(error_list, env, acc_map, result, namer, fcache); @@ -246,7 +246,6 @@ namespace spot } else // Fatal error { - delete result; return nullptr; } } diff --git a/src/tgbatest/complementation.cc b/src/tgbatest/complementation.cc index 664e76d63..cb5aa9a90 100644 --- a/src/tgbatest/complementation.cc +++ b/src/tgbatest/complementation.cc @@ -130,16 +130,16 @@ int main(int argc, char* argv[]) { spot::ltl::environment& env(spot::ltl::default_environment::instance()); spot::tgba_parse_error_list pel; - spot::tgba* a = spot::tgba_parse(file, pel, dict, env); + spot::tgba_ptr a = spot::tgba_parse(file, pel, dict, env); if (spot::format_tgba_parse_errors(std::cerr, file, pel)) return 2; - spot::tgba* complement = 0; + spot::tgba_ptr complement = 0; if (safra) - complement = new spot::tgba_safra_complement(a); + complement = spot::make_safra_complement(a); else - complement = new spot::tgba_kv_complement(a); + complement = spot::make_kv_complement(a); if (print_automaton) { @@ -151,16 +151,14 @@ int main(int argc, char* argv[]) if (print_safra) { - spot::tgba_safra_complement* safra_complement = - dynamic_cast(complement); + auto safra_complement = + std::dynamic_pointer_cast(complement); spot::display_safra(safra_complement); } - delete complement; - delete a; } else if (print_formula) { - spot::tgba* a; + spot::tgba_ptr a; spot::ltl::parse_error_list p1; const spot::ltl::formula* f1 = spot::ltl::parse(file, p1); @@ -169,21 +167,18 @@ int main(int argc, char* argv[]) return 2; a = spot::ltl_to_tgba_fm(f1, dict); - - spot::tgba* complement = 0; + spot::tgba_ptr complement = 0; if (safra) - complement = new spot::tgba_safra_complement(a); + complement = spot::make_safra_complement(a); else - complement = new spot::tgba_kv_complement(a); + complement = spot::make_kv_complement(a); spot::dotty_reachable(std::cout, complement); f1->destroy(); - delete complement; - delete a; } else if (stats) { - spot::tgba* a; + spot::tgba_ptr a; const spot::ltl::formula* f1 = 0; if (formula) @@ -205,8 +200,7 @@ int main(int argc, char* argv[]) return 2; } - spot::tgba_safra_complement* safra_complement = - new spot::tgba_safra_complement(a); + auto safra_complement = spot::make_safra_complement(a); spot::tgba_statistics a_size = spot::stats_reachable(a); std::cout << "Original: " @@ -221,7 +215,6 @@ int main(int argc, char* argv[]) << buchi->num_transitions() << buchi->number_of_acceptance_conditions() << std::endl; - delete buchi; spot::tgba_statistics b_size = spot::stats_reachable(safra_complement); std::cout << "Safra Complement: " @@ -230,8 +223,7 @@ int main(int argc, char* argv[]) << safra_complement->number_of_acceptance_conditions() << std::endl; - spot::tgba_kv_complement* complement = - new spot::tgba_kv_complement(a); + auto complement = spot::make_kv_complement(a); b_size = spot::stats_reachable(complement); std::cout << "GBA Complement: " @@ -240,14 +232,12 @@ int main(int argc, char* argv[]) << complement->number_of_acceptance_conditions() << std::endl; - delete complement; - delete a; if (formula) { const spot::ltl::formula* nf1 = spot::ltl::unop::instance(spot::ltl::unop::Not, f1->clone()); - spot::tgba* a2 = spot::ltl_to_tgba_fm(nf1, dict); + spot::tgba_ptr a2 = spot::ltl_to_tgba_fm(nf1, dict); spot::tgba_statistics a_size = spot::stats_reachable(a2); std::cout << "Not Formula: " << a_size.states << ", " @@ -255,7 +245,6 @@ int main(int argc, char* argv[]) << a2->number_of_acceptance_conditions() << std::endl; - delete a2; f1->destroy(); nf1->destroy(); } @@ -268,25 +257,24 @@ int main(int argc, char* argv[]) if (spot::ltl::format_parse_errors(std::cerr, file, p1)) return 2; - spot::tgba* Af = spot::ltl_to_tgba_fm(f1, dict); + spot::tgba_ptr Af = spot::ltl_to_tgba_fm(f1, dict); const spot::ltl::formula* nf1 = spot::ltl::unop::instance(spot::ltl::unop::Not, f1->clone()); - spot::tgba* Anf = spot::ltl_to_tgba_fm(nf1, dict); + spot::tgba_ptr Anf = spot::ltl_to_tgba_fm(nf1, dict); - spot::tgba* nAf; - spot::tgba* nAnf; + spot::tgba_ptr nAf; + spot::tgba_ptr nAnf; if (safra) { - nAf = new spot::tgba_safra_complement(Af); - nAnf = new spot::tgba_safra_complement(Anf); + nAf = spot::make_safra_complement(Af); + nAnf = spot::make_safra_complement(Anf); } else { - nAf = new spot::tgba_kv_complement(Af); - nAnf = new spot::tgba_kv_complement(Anf); + nAf = spot::make_kv_complement(Af); + nAnf = spot::make_kv_complement(Anf); } - spot::tgba* prod = new spot::tgba_product(nAf, nAnf); - spot::emptiness_check* ec = spot::couvreur99(prod); + spot::emptiness_check* ec = spot::couvreur99(spot::product(nAf, nAnf)); spot::emptiness_check_result* res = ec->check(); spot::tgba_statistics a_size = spot::stats_reachable(ec->automaton()); std::cout << "States: " @@ -307,12 +295,6 @@ int main(int argc, char* argv[]) delete res; delete ec; - delete prod; - delete nAf; - delete Af; - delete nAnf; - delete Anf; - nf1->destroy(); f1->destroy(); diff --git a/src/tgbatest/explprod.cc b/src/tgbatest/explprod.cc index e47791b83..f9219cf0b 100644 --- a/src/tgbatest/explprod.cc +++ b/src/tgbatest/explprod.cc @@ -43,29 +43,24 @@ main(int argc, char** argv) if (argc != 3) syntax(argv[0]); - auto dict = spot::make_bdd_dict(); - - spot::ltl::environment& env(spot::ltl::default_environment::instance()); - spot::tgba_parse_error_list pel1; - spot::tgba* a1 = spot::tgba_parse(argv[1], pel1, dict, env); - if (spot::format_tgba_parse_errors(std::cerr, argv[1], pel1)) - return 2; - spot::tgba_parse_error_list pel2; - spot::tgba* a2 = spot::tgba_parse(argv[2], pel2, dict, env); - if (spot::format_tgba_parse_errors(std::cerr, argv[2], pel2)) - return 2; - { - spot::tgba_product p(a1, a2); - spot::tgba_save_reachable(std::cout, &p); - } + auto dict = spot::make_bdd_dict(); + spot::ltl::environment& env(spot::ltl::default_environment::instance()); + spot::tgba_parse_error_list pel1; + auto a1 = spot::tgba_parse(argv[1], pel1, dict, env); + if (spot::format_tgba_parse_errors(std::cerr, argv[1], pel1)) + return 2; + spot::tgba_parse_error_list pel2; + auto a2 = spot::tgba_parse(argv[2], pel2, dict, env); + if (spot::format_tgba_parse_errors(std::cerr, argv[2], pel2)) + return 2; + + spot::tgba_save_reachable(std::cout, product(a1, a2)); + } assert(spot::ltl::unop::instance_count() == 0); assert(spot::ltl::binop::instance_count() == 0); assert(spot::ltl::multop::instance_count() == 0); - assert(spot::ltl::atomic_prop::instance_count() != 0); - delete a1; - delete a2; assert(spot::ltl::atomic_prop::instance_count() == 0); return exit_code; } diff --git a/src/tgbatest/ltl2tgba.cc b/src/tgbatest/ltl2tgba.cc index 949177594..0fd2214dd 100644 --- a/src/tgbatest/ltl2tgba.cc +++ b/src/tgbatest/ltl2tgba.cc @@ -324,8 +324,16 @@ to_int(const char* s) return res; } +spot::tgba_digraph_ptr ensure_digraph(const spot::tgba_ptr& a) +{ + auto aa = std::dynamic_pointer_cast(a); + if (aa) + return aa; + return spot::tgba_dupexp_dfs(a); +} + int -main(int argc, char** argv) +checked_main(int argc, char** argv) { int exit_code = 0; @@ -379,8 +387,7 @@ main(int argc, char** argv) bool spin_comments = false; spot::ltl::environment& env(spot::ltl::default_environment::instance()); spot::ltl::atomic_prop_set* unobservables = 0; - spot::tgba* system_aut = 0; - const spot::tgba* product_to_free = 0; + spot::tgba_ptr system_aut = 0; auto dict = spot::make_bdd_dict(); spot::timer_map tm; bool use_timer = false; @@ -390,16 +397,11 @@ main(int argc, char** argv) bool reduction_dont_care_sim = false; int limit_dont_care_sim = 0; bool reduction_iterated_dont_care_sim = false; - spot::tgba* temp_dir_sim = 0; bool ta_opt = false; bool tgta_opt = false; bool opt_with_artificial_initial_state = true; bool opt_single_pass_emptiness_check = false; bool opt_with_artificial_livelock = false; - spot::tgba* temp_rev_sim = 0; - spot::tgba* temp_iterated_sim = 0; - spot::tgba* temp_dont_care_sim = 0; - spot::tgba* temp_dont_care_iterated_sim = 0; bool cs_nowdba = true; bool cs_wdba_smaller = false; bool cs_nosimul = true; @@ -632,7 +634,7 @@ main(int argc, char** argv) tm.start("reading -P's argument"); spot::tgba_parse_error_list pel; - spot::tgba_digraph* s; + spot::tgba_digraph_ptr s; s = spot::tgba_parse(argv[formula_index] + 2, pel, dict, env, env, debug_opt); if (spot::format_tgba_parse_errors(std::cerr, @@ -998,9 +1000,7 @@ main(int argc, char** argv) if (f || from_file) { - const spot::tgba* to_free = 0; - const spot::tgba* to_free2 = 0; - spot::tgba* a = 0; + spot::tgba_ptr a = 0; bool assume_sba = false; if (from_file) @@ -1009,33 +1009,27 @@ main(int argc, char** argv) { case ReadSpot: { - spot::tgba_digraph* e; + spot::tgba_digraph_ptr e; spot::tgba_parse_error_list pel; tm.start("parsing automaton"); - to_free = a = e = spot::tgba_parse(input, pel, dict, + a = e = spot::tgba_parse(input, pel, dict, env, env, debug_opt); tm.stop("parsing automaton"); if (spot::format_tgba_parse_errors(std::cerr, input, pel)) - { - delete to_free; - return 2; - } + return 2; e->merge_transitions(); } break; case ReadNeverclaim: { - spot::tgba_digraph* e; + spot::tgba_digraph_ptr e; spot::neverclaim_parse_error_list pel; tm.start("parsing neverclaim"); - to_free = a = e = spot::neverclaim_parse(input, pel, dict, + a = e = spot::neverclaim_parse(input, pel, dict, env, debug_opt); tm.stop("parsing neverclaim"); if (spot::format_neverclaim_parse_errors(std::cerr, input, pel)) - { - delete to_free; - return 2; - } + return 2; assume_sba = true; e->merge_transitions(); } @@ -1055,13 +1049,10 @@ main(int argc, char** argv) } } tm.start("parsing lbtt"); - to_free = a = - const_cast(spot::lbtt_parse(*in, - error, dict, - env, env)); + a = spot::lbtt_parse(*in, error, dict, env, env); tm.stop("parsing lbtt"); delete f; - if (!to_free) + if (!a) { std::cerr << error << std::endl; return 2; @@ -1072,43 +1063,37 @@ main(int argc, char** argv) { spot::dstar_parse_error_list pel; tm.start("parsing dstar"); - spot::dstar_aut* daut; - daut = spot::dstar_parse(input, pel, dict, - env, debug_opt); + auto daut = spot::dstar_parse(input, pel, dict, env, debug_opt); tm.stop("parsing dstar"); if (spot::format_dstar_parse_errors(std::cerr, input, pel)) - { - delete to_free; - return 2; - } + return 2; tm.start("dstar2tgba"); if (nra2nba) { if (daut->type == spot::Rabin) { - spot::tgba_digraph* res; + spot::tgba_digraph_ptr res; if (dra2dba) res = spot::dstar_to_tgba(daut); else res = spot::nra_to_nba(daut); - to_free = a = res; + a = res; assert(res->get_bprop(spot::tgba_digraph::SBA)); assume_sba = true; } else { - to_free = a = spot::nsa_to_tgba(daut); + a = spot::nsa_to_tgba(daut); assume_sba = false; } } else { - to_free = a = daut->aut; + a = daut->aut; daut->aut = 0; assume_sba = false; } tm.stop("dstar2tgba"); - delete daut; } break; } @@ -1170,7 +1155,6 @@ main(int argc, char** argv) break; } tm.stop("translating formula"); - to_free = a; if (simp && simpcache_stats) { @@ -1197,42 +1181,24 @@ main(int argc, char** argv) // Remove dead SCCs and useless acceptance conditions before // degeneralization. - const spot::tgba* aut_scc = 0; if (scc_filter) { - auto aa = dynamic_cast(a); - bool freeit = false; - if (!aa) - { - freeit = true; - aa = tgba_dupexp_dfs(a); - } - assert(aa); tm.start("SCC-filter"); - aut_scc = a = spot::scc_filter(aa, scc_filter_all); + a = spot::scc_filter(ensure_digraph(a), scc_filter_all); tm.stop("SCC-filter"); assume_sba = false; - if (freeit) - delete aa; } - const spot::tgba* degeneralized = 0; - - spot::tgba_digraph* minimized = 0; + bool wdba_minimization_is_success = false; if (opt_minimize) { + auto aa = ensure_digraph(a); tm.start("obligation minimization"); - auto aa = dynamic_cast(a); - bool freeit = false; - if (!aa) - { - freeit = true; - aa = tgba_dupexp_dfs(a); - } - minimized = minimize_obligation(aa, f, 0, reject_bigger); + auto minimized = minimize_obligation(aa, + f, 0, reject_bigger); tm.stop("obligation minimization"); - if (minimized == 0) + if (!minimized) { // if (!f) { @@ -1244,11 +1210,12 @@ main(int argc, char** argv) } else if (minimized == aa) { - minimized = 0; + minimized = nullptr; } else { a = minimized; + wdba_minimization_is_success = true; // When the minimization succeed, simulation is useless. reduction_dir_sim = false; reduction_rev_sim = false; @@ -1257,15 +1224,12 @@ main(int argc, char** argv) reduction_iterated_sim = false; assume_sba = true; } - if (freeit) - delete aa; } if (reduction_dir_sim && !reduction_iterated_sim) { tm.start("direct simulation"); - temp_dir_sim = spot::simulation(a); - a = temp_dir_sim; + a = spot::simulation(a); tm.stop("direct simulation"); assume_sba = false; } @@ -1273,8 +1237,7 @@ main(int argc, char** argv) if (reduction_rev_sim && !reduction_iterated_sim) { tm.start("reverse simulation"); - temp_rev_sim = spot::cosimulation(a); - a = temp_rev_sim; + a = spot::cosimulation(a); tm.stop("reverse simulation"); assume_sba = false; } @@ -1283,9 +1246,7 @@ main(int argc, char** argv) if (reduction_iterated_dont_care_sim) { tm.start("don't care iterated simulation"); - temp_dont_care_iterated_sim - = spot::dont_care_iterated_simulations(a, limit_dont_care_sim); - a = temp_dont_care_iterated_sim; + a = spot::dont_care_iterated_simulations(a, limit_dont_care_sim); tm.stop("don't care iterated simulation"); assume_sba = false; } @@ -1293,45 +1254,30 @@ main(int argc, char** argv) if (reduction_iterated_sim) { tm.start("Reduction w/ iterated simulations"); - temp_iterated_sim = spot::iterated_simulations(a); - a = temp_iterated_sim; + a = spot::iterated_simulations(a); tm.stop("Reduction w/ iterated simulations"); assume_sba = false; } if (scc_filter && (reduction_dir_sim || reduction_rev_sim)) { - auto aa = dynamic_cast(a); - bool freeit = false; - if (!aa) - { - freeit = true; - aa = spot::tgba_dupexp_dfs(a); - } tm.start("SCC-filter post-sim"); - delete aut_scc; - aut_scc = a = spot::scc_filter(aa, scc_filter_all); + a = spot::scc_filter(ensure_digraph(a), scc_filter_all); tm.stop("SCC-filter post-sim"); - if (freeit) - delete aa; } if (reduction_dont_care_sim) { tm.start("don't care simulation"); - temp_dont_care_sim - = spot::dont_care_simulation(a, limit_dont_care_sim); - a = temp_dont_care_sim; + a = spot::dont_care_simulation(a, limit_dont_care_sim); tm.stop("don't care simulation"); if (scc_filter) { - auto aa = down_cast(a); + auto aa = std::static_pointer_cast(a); assert(aa); tm.start("SCC-filter on don't care"); a = spot::scc_filter(aa, true); - delete temp_dont_care_sim; - temp_dont_care_sim = a; tm.stop("SCC-filter on don't care"); } assume_sba = false; @@ -1351,57 +1297,49 @@ main(int argc, char** argv) { if (degeneralize_opt == DegenTBA) { - degeneralized = a = spot::degeneralize_tba(a, - degen_reset, - degen_order, - degen_cache); + a = spot::degeneralize_tba(a, degen_reset, degen_order, + degen_cache); } else if (degeneralize_opt == DegenSBA) { tm.start("degeneralization"); - degeneralized = a = spot::degeneralize(a, - degen_reset, - degen_order, - degen_cache); + a = spot::degeneralize(a, degen_reset, degen_order, + degen_cache); tm.stop("degeneralization"); assume_sba = true; } else if (labeling_opt == StateLabeled) { - degeneralized = a = new spot::tgba_sgba_proxy(a); + a = spot::make_sgba(a); } } - spot::tgba* determinized = 0; if (opt_determinize && a->number_of_acceptance_conditions() <= 1 && (!f || f->is_syntactic_recurrence())) { tm.start("determinization 2"); - determinized = tba_determinize(a, 0, opt_determinize_threshold); + auto determinized = tba_determinize(a, 0, opt_determinize_threshold); tm.stop("determinization 2"); if (determinized) a = determinized; } - const spot::tgba* monitor = 0; if (opt_monitor) { tm.start("Monitor minimization"); - monitor = a = minimize_monitor(a); + a = minimize_monitor(a); tm.stop("Monitor minimization"); assume_sba = false; // All states are accepting, so double // circles in the dot output are // pointless. } - if (degeneralized || determinized) + if (degeneralize_opt != NoDegen || opt_determinize) { if (reduction_dir_sim && !reduction_iterated_sim) { tm.start("direct simulation 2"); - spot::tgba* tmp = spot::simulation(a); - delete temp_dir_sim; - a = temp_dir_sim = tmp; + a = spot::simulation(a); tm.stop("direct simulation 2"); assume_sba = false; } @@ -1409,9 +1347,7 @@ main(int argc, char** argv) if (reduction_rev_sim && !reduction_iterated_sim) { tm.start("reverse simulation 2"); - spot::tgba* tmp = spot::cosimulation(a); - delete temp_rev_sim; - a = temp_rev_sim = tmp; + a = spot::cosimulation(a); tm.stop("reverse simulation 2"); assume_sba = false; } @@ -1419,27 +1355,23 @@ main(int argc, char** argv) if (reduction_iterated_sim) { tm.start("Reduction w/ iterated simulations"); - spot::tgba* tmp = spot::iterated_simulations(a); - delete temp_iterated_sim; - a = temp_iterated_sim = tmp; + a = spot::iterated_simulations(a); tm.stop("Reduction w/ iterated simulations"); assume_sba = false; } } - spot::tgba* completed = 0; if (opt_complete) { tm.start("determinization"); - a = completed = tgba_complete(a); + a = tgba_complete(a); tm.stop("determinization"); } - spot::tgba* satminimized = 0; if (opt_dtbasat >= 0) { tm.start("dtbasat"); - satminimized = dtba_sat_synthetize(a, opt_dtbasat); + auto satminimized = dtba_sat_synthetize(a, opt_dtbasat); tm.stop("dtbasat"); if (satminimized) a = satminimized; @@ -1447,31 +1379,30 @@ main(int argc, char** argv) else if (opt_dtgbasat >= 0) { tm.start("dtgbasat"); - satminimized = dtgba_sat_minimize(a, opt_dtgbasat); + auto satminimized = dtgba_sat_minimize(a, opt_dtgbasat); tm.stop("dtgbasat"); if (satminimized) a = satminimized; } - spot::tgba* complemented = 0; if (opt_dtgbacomp) { tm.start("DTGBA complement"); - a = complemented = dtgba_complement(a); + a = dtgba_complement(a); tm.stop("DTGBA complement"); } - if (complemented || satminimized || determinized) + if (opt_determinize || opt_dtgbacomp || opt_dtbasat >= 0 + || opt_dtgbasat >= 0) { if (scc_filter && (reduction_dir_sim || reduction_rev_sim)) { tm.start("SCC-filter post-sim"); - delete aut_scc; - auto aa = down_cast(a); + auto aa = std::dynamic_pointer_cast(a); assert(aa); // Do not filter_all for SBA - aut_scc = a = spot::scc_filter(aa, assume_sba ? - false : scc_filter_all); + a = spot::scc_filter(aa, assume_sba ? + false : scc_filter_all); tm.stop("SCC-filter post-sim"); } } @@ -1479,23 +1410,22 @@ main(int argc, char** argv) if (opt_monitor) { tm.start("Monitor minimization"); - a = minimized = minimize_monitor(a); + a = minimize_monitor(a); tm.stop("Monitor minimization"); assume_sba = false; // All states are accepting, so double // circles in the dot output are // pointless. } - const spot::tgba* expl = 0; switch (dupexp) { case NoneDup: break; case BFS: - expl = a = tgba_dupexp_bfs(a); + a = tgba_dupexp_bfs(a); break; case DFS: - expl = a = tgba_dupexp_dfs(a); + a = tgba_dupexp_dfs(a); break; } @@ -1507,14 +1437,14 @@ main(int argc, char** argv) if (ta_opt) { tm.start("conversion to TA"); - spot::ta* testing_automaton + auto testing_automaton = tgba_to_ta(a, atomic_props_set_bdd, degeneralize_opt == DegenSBA, opt_with_artificial_initial_state, opt_single_pass_emptiness_check, opt_with_artificial_livelock); tm.stop("conversion to TA"); - spot::ta* testing_automaton_nm = 0; + spot::ta_ptr testing_automaton_nm = 0; if (opt_bisim_ta) { tm.start("TA bisimulation"); @@ -1540,31 +1470,22 @@ main(int argc, char** argv) } tm.stop("producing output"); } - - delete testing_automaton_nm; - delete testing_automaton; - delete a; a = 0; - degeneralized = 0; - if (degeneralize_opt != DegenSBA) - to_free = 0; output = -1; } if (tgta_opt) { - spot::tgta_explicit* tgta = tgba_to_tgta(a, atomic_props_set_bdd); + auto tgta = tgba_to_tgta(a, atomic_props_set_bdd); if (opt_bisim_ta) { tm.start("TA bisimulation"); a = minimize_tgta(tgta); tm.stop("TA bisimulation"); - delete tgta; } else { a = tgta; } - to_free2 = a; if (output != -1) { @@ -1572,8 +1493,8 @@ main(int argc, char** argv) switch (output) { case 0: - spot::dotty_reachable(std::cout, - dynamic_cast(a)->get_ta()); + spot::dotty_reachable(std::cout, std::dynamic_pointer_cast + (a)->get_ta()); break; case 12: stats_reachable(a).dump(std::cout); @@ -1588,11 +1509,9 @@ main(int argc, char** argv) } } - spot::tgba* product_degeneralized = 0; - if (system_aut) { - product_to_free = a = new spot::tgba_product(system_aut, a); + a = spot::product(system_aut, a); assume_sba = false; @@ -1605,21 +1524,19 @@ main(int argc, char** argv) if (degeneralize_opt == DegenTBA) { tm.start("degeneralize product"); - product_degeneralized = a = - spot::degeneralize_tba(a, - degen_reset, - degen_order, - degen_cache); + a = spot::degeneralize_tba(a, + degen_reset, + degen_order, + degen_cache); tm.stop("degeneralize product"); } else if (degeneralize_opt == DegenSBA) { tm.start("degeneralize product"); - product_degeneralized = a = - spot::degeneralize(a, - degen_reset, - degen_order, - degen_cache); + a = spot::degeneralize(a, + degen_reset, + degen_order, + degen_cache); tm.stop("degeneralize product"); assume_sba = true; } @@ -1646,7 +1563,7 @@ main(int argc, char** argv) if (show_fc) { - a = new spot::future_conditions_collector(a, true); + a = spot::make_future_conditions_collector(a, true); } if (output != -1) @@ -1676,12 +1593,9 @@ main(int argc, char** argv) // It is possible that we have applied other // operations to the automaton since its initial // degeneralization. Let's degeneralize again! - spot::tgba* s = spot::degeneralize(a, - degen_reset, - degen_order, - degen_cache); + auto s = spot::degeneralize(a, degen_reset, + degen_order, degen_cache); spot::never_claim_reachable(std::cout, s, f, spin_comments); - delete s; } break; } @@ -1691,18 +1605,18 @@ main(int argc, char** argv) break; case 10: { - const spot::tgba_digraph* g = - dynamic_cast(a); - if (!g) + auto aa = + std::dynamic_pointer_cast(a); + if (!aa) dump_scc_dot(a, std::cout, false); else - dump_scc_info_dot(std::cout, g); + dump_scc_info_dot(std::cout, aa); } break; case 11: { - //const spot::tgba_digraph* g = - // dynamic_cast(a); + //const spot::tgba_digraph_ptr g = + // dynamic_cast(a); //if (!g) dump_scc_dot(a, std::cout, true); //else @@ -1718,21 +1632,18 @@ main(int argc, char** argv) << count_nondet_states(a) << std::endl; break; case 14: - if (minimized == 0) + if (!wdba_minimization_is_success) { std::cout << "this is not an obligation property"; - const spot::tgba* tmp = - tba_determinize_check(a, 0, opt_o_threshold, f, 0); + auto tmp = tba_determinize_check(ensure_digraph(a), + 0, opt_o_threshold, f, 0); if (tmp != 0 && tmp != a) - { - std::cout << ", but it is a recurrence property"; - delete tmp; - } + std::cout << ", but it is a recurrence property"; } else { - bool g = is_guarantee_automaton(minimized); - bool s = is_safety_mwdba(minimized); + bool g = is_guarantee_automaton(a); + bool s = is_safety_mwdba(a); if (g && !s) { std::cout << "this is a guarantee property (hence, " @@ -1898,10 +1809,8 @@ main(int argc, char** argv) } else if (graph_run_tgba_opt) { - spot::tgba* ar = - spot::tgba_run_to_tgba(a, run); + auto ar = spot::tgba_run_to_tgba(a, run); spot::dotty_reachable(std::cout, ar, false); - delete ar; } else { @@ -1923,31 +1832,9 @@ main(int argc, char** argv) while (search_many); delete ec; } - - delete to_free2; - if (show_fc) - delete a; if (f) f->destroy(); - delete product_degeneralized; - delete product_to_free; - delete system_aut; - delete expl; - delete monitor; - delete minimized; - delete satminimized; - delete degeneralized; - delete determinized; - delete completed; - delete complemented; - delete aut_scc; - delete to_free; delete echeck_inst; - delete temp_dir_sim; - delete temp_rev_sim; - delete temp_iterated_sim; - delete temp_dont_care_sim; - delete temp_dont_care_iterated_sim; } else { @@ -1965,6 +1852,14 @@ main(int argc, char** argv) delete unobservables; } + return exit_code; +} + + +int +main(int argc, char** argv) +{ + int exit_code = checked_main(argc, argv); spot::ltl::atomic_prop::dump_instances(std::cerr); spot::ltl::unop::dump_instances(std::cerr); spot::ltl::binop::dump_instances(std::cerr); diff --git a/src/tgbatest/ltlprod.cc b/src/tgbatest/ltlprod.cc index a16b405d8..11b2ee5d8 100644 --- a/src/tgbatest/ltlprod.cc +++ b/src/tgbatest/ltlprod.cc @@ -44,33 +44,30 @@ main(int argc, char** argv) if (argc != 3) syntax(argv[0]); - spot::ltl::environment& env(spot::ltl::default_environment::instance()); - - spot::ltl::parse_error_list pel1; - const spot::ltl::formula* f1 = spot::ltl::parse(argv[1], pel1, env); - - if (spot::ltl::format_parse_errors(std::cerr, argv[1], pel1)) - return 2; - - spot::ltl::parse_error_list pel2; - const spot::ltl::formula* f2 = spot::ltl::parse(argv[2], pel2, env); - - if (spot::ltl::format_parse_errors(std::cerr, argv[2], pel2)) - return 2; - - auto dict = spot::make_bdd_dict(); { - auto a1 = spot::ltl_to_tgba_fm(f1, dict); - auto a2 = spot::ltl_to_tgba_fm(f2, dict); - f1->destroy(); - f2->destroy(); - auto p = new spot::tgba_product(a1, a2); - spot::dotty_reachable(std::cout, p); - delete p; - delete a1; - delete a2; - } + spot::ltl::environment& env(spot::ltl::default_environment::instance()); + spot::ltl::parse_error_list pel1; + const spot::ltl::formula* f1 = spot::ltl::parse(argv[1], pel1, env); + + if (spot::ltl::format_parse_errors(std::cerr, argv[1], pel1)) + return 2; + + spot::ltl::parse_error_list pel2; + const spot::ltl::formula* f2 = spot::ltl::parse(argv[2], pel2, env); + + if (spot::ltl::format_parse_errors(std::cerr, argv[2], pel2)) + return 2; + + auto dict = spot::make_bdd_dict(); + { + auto a1 = spot::ltl_to_tgba_fm(f1, dict); + auto a2 = spot::ltl_to_tgba_fm(f2, dict); + f1->destroy(); + f2->destroy(); + spot::dotty_reachable(std::cout, product(a1, a2)); + } + } assert(spot::ltl::atomic_prop::instance_count() == 0); assert(spot::ltl::unop::instance_count() == 0); assert(spot::ltl::binop::instance_count() == 0); diff --git a/src/tgbatest/maskacc.cc b/src/tgbatest/maskacc.cc index 2bc0e29ed..cbe61fe1b 100755 --- a/src/tgbatest/maskacc.cc +++ b/src/tgbatest/maskacc.cc @@ -40,30 +40,30 @@ main(int argc, char** argv) if (argc != 2) syntax(argv[0]); - auto dict = spot::make_bdd_dict(); + { + auto dict = spot::make_bdd_dict(); - spot::ltl::environment& env(spot::ltl::default_environment::instance()); - spot::tgba_parse_error_list pel; - spot::tgba* aut = spot::tgba_parse(argv[1], pel, dict, env); - if (spot::format_tgba_parse_errors(std::cerr, argv[1], pel)) - return 2; + spot::ltl::environment& env(spot::ltl::default_environment::instance()); + spot::tgba_parse_error_list pel; + auto aut = spot::tgba_parse(argv[1], pel, dict, env); + if (spot::format_tgba_parse_errors(std::cerr, argv[1], pel)) + return 2; - bdd allneg = aut->neg_acceptance_conditions(); + bdd allneg = aut->neg_acceptance_conditions(); - for (bdd cur = allneg; cur != bddtrue; cur = bdd_low(cur)) - { - int i = bdd_var(cur); - bdd one = bdd_compose(allneg, bdd_nithvar(i), i); - const spot::tgba* masked = spot::build_tgba_mask_acc_ignore(aut, one); - spot::tgba_save_reachable(std::cout, masked); - delete masked; - } + for (bdd cur = allneg; cur != bddtrue; cur = bdd_low(cur)) + { + int i = bdd_var(cur); + bdd one = bdd_compose(allneg, bdd_nithvar(i), i); + auto masked = spot::build_tgba_mask_acc_ignore(aut, one); + spot::tgba_save_reachable(std::cout, masked); + } + } assert(spot::ltl::unop::instance_count() == 0); assert(spot::ltl::binop::instance_count() == 0); assert(spot::ltl::multop::instance_count() == 0); assert(spot::ltl::atomic_prop::instance_count() != 0); - delete aut; assert(spot::ltl::atomic_prop::instance_count() == 0); return exit_code; } diff --git a/src/tgbatest/powerset.cc b/src/tgbatest/powerset.cc index 90bc490d4..5aeab8f3c 100644 --- a/src/tgbatest/powerset.cc +++ b/src/tgbatest/powerset.cc @@ -44,28 +44,28 @@ main(int argc, char** argv) if (argc != 2) syntax(argv[0]); - auto dict = spot::make_bdd_dict(); + { + auto dict = spot::make_bdd_dict(); - spot::ltl::environment& env(spot::ltl::default_environment::instance()); - spot::tgba_parse_error_list pel; - spot::tgba* a = spot::tgba_parse(argv[1], pel, dict, env); - if (spot::format_tgba_parse_errors(std::cerr, argv[1], pel)) - return 2; + spot::ltl::environment& env(spot::ltl::default_environment::instance()); + spot::tgba_parse_error_list pel; + auto a = spot::tgba_parse(argv[1], pel, dict, env); + if (spot::format_tgba_parse_errors(std::cerr, argv[1], pel)) + return 2; #ifndef DOTTY - auto e = spot::tgba_powerset(a); - spot::tgba_save_reachable(std::cout, e); - delete e; + auto e = spot::tgba_powerset(a); + spot::tgba_save_reachable(std::cout, e); #else - spot::dotty_reachable(std::cout, a); + spot::dotty_reachable(std::cout, a); #endif + } assert(spot::ltl::unop::instance_count() == 0); assert(spot::ltl::binop::instance_count() == 0); assert(spot::ltl::multop::instance_count() == 0); assert(spot::ltl::atomic_prop::instance_count() != 0); - delete a; assert(spot::ltl::atomic_prop::instance_count() == 0); return exit_code; } diff --git a/src/tgbatest/randtgba.cc b/src/tgbatest/randtgba.cc index e1b8c0e47..29134e635 100644 --- a/src/tgbatest/randtgba.cc +++ b/src/tgbatest/randtgba.cc @@ -85,8 +85,9 @@ const char* default_algos[] = { std::vector ec_algos; spot::emptiness_check* -cons_emptiness_check(int num, const spot::tgba* a, - const spot::tgba* degen, unsigned int n_acc) +cons_emptiness_check(int num, spot::const_tgba_ptr a, + const spot::const_tgba_ptr& degen, + unsigned int n_acc) { spot::emptiness_check_instantiator* inst = ec_algos[num].inst; if (n_acc < inst->min_acceptance_conditions() @@ -94,7 +95,7 @@ cons_emptiness_check(int num, const spot::tgba* a, a = degen; if (a) return inst->instantiate(a); - return 0; + return nullptr; } void @@ -578,8 +579,8 @@ main(int argc, char** argv) bool stop_on_first_difference = false; - spot::tgba* formula = 0; - spot::tgba* product = 0; + spot::tgba_ptr formula = nullptr; + spot::tgba_ptr product = nullptr; spot::option_map options; @@ -905,13 +906,12 @@ main(int argc, char** argv) std::cout << "seed: " << opt_ec_seed << std::endl; spot::srand(opt_ec_seed); - spot::tgba* a; - spot::tgba* r = a = spot::random_graph(opt_n, opt_d, apf, dict, - opt_n_acc, opt_a, opt_t, - &env); + spot::tgba_ptr a = + spot::random_graph(opt_n, opt_d, apf, dict, + opt_n_acc, opt_a, opt_t, &env); if (formula) - a = product = new spot::tgba_product(formula, a); + a = spot::product(formula, a); int real_n_acc = a->number_of_acceptance_conditions(); @@ -926,7 +926,7 @@ main(int argc, char** argv) } else { - spot::tgba* degen = 0; + spot::tgba_ptr degen = nullptr; if (opt_degen && real_n_acc > 1) degen = degeneralize_tba(a); @@ -1134,13 +1134,8 @@ main(int argc, char** argv) << std::endl; failed_seeds.insert(opt_ec_seed); } - - delete degen; } - delete product; - delete r; - if (opt_ec) { --opt_ec; @@ -1155,7 +1150,6 @@ main(int argc, char** argv) opt_ec_seed += init_opt_ec; } - delete formula; if (opt_F) --opt_F; opt_ec = init_opt_ec; diff --git a/src/tgbatest/taatgba.cc b/src/tgbatest/taatgba.cc index 120cf8cc7..3f28ce82c 100644 --- a/src/tgbatest/taatgba.cc +++ b/src/tgbatest/taatgba.cc @@ -28,26 +28,27 @@ int main() { - spot::ltl::default_environment& e = - spot::ltl::default_environment::instance(); - spot::taa_tgba_string* a = new spot::taa_tgba_string(spot::make_bdd_dict()); + { + spot::ltl::default_environment& e = + spot::ltl::default_environment::instance(); + auto a = spot::make_taa_tgba_string(spot::make_bdd_dict()); - typedef spot::taa_tgba::transition trans; + typedef spot::taa_tgba::transition trans; - std::string ss1_values[] = { "state 2", "state 3" }; - std::vector ss1_vector(ss1_values, ss1_values + 2); - trans* t1 = a->create_transition("state 1", ss1_vector); - trans* t2 = a->create_transition("state 2", "state 3"); - trans* t3 = a->create_transition("state 2", "state 4"); + std::string ss1_values[] = { "state 2", "state 3" }; + std::vector ss1_vector(ss1_values, ss1_values + 2); + trans* t1 = a->create_transition("state 1", ss1_vector); + trans* t2 = a->create_transition("state 2", "state 3"); + trans* t3 = a->create_transition("state 2", "state 4"); - a->add_condition(t1, e.require("a")); - a->add_condition(t2, e.require("b")); - a->add_condition(t3, e.require("c")); + a->add_condition(t1, e.require("a")); + a->add_condition(t2, e.require("b")); + a->add_condition(t3, e.require("c")); - a->set_init_state("state 1"); - spot::dotty_reachable(std::cout, a); + a->set_init_state("state 1"); + spot::dotty_reachable(std::cout, a); + } - delete a; assert(spot::ltl::atomic_prop::instance_count() == 0); assert(spot::ltl::unop::instance_count() == 0); assert(spot::ltl::binop::instance_count() == 0); diff --git a/src/tgbatest/tgbaread.cc b/src/tgbatest/tgbaread.cc index 5c7c8e782..a55e43b87 100644 --- a/src/tgbatest/tgbaread.cc +++ b/src/tgbatest/tgbaread.cc @@ -41,36 +41,33 @@ main(int argc, char** argv) if (argc < 2) syntax(argv[0]); - bool debug = false; - int filename_index = 1; + { + bool debug = false; + int filename_index = 1; - if (!strcmp(argv[1], "-d")) - { - debug = true; - if (argc < 3) - syntax(argv[0]); - filename_index = 2; - } + if (!strcmp(argv[1], "-d")) + { + debug = true; + if (argc < 3) + syntax(argv[0]); + filename_index = 2; + } - auto dict = spot::make_bdd_dict(); + auto dict = spot::make_bdd_dict(); - spot::ltl::environment& env(spot::ltl::default_environment::instance()); - spot::tgba_parse_error_list pel; - spot::tgba* a = spot::tgba_parse(argv[filename_index], - pel, dict, env, env, debug); + spot::ltl::environment& env(spot::ltl::default_environment::instance()); + spot::tgba_parse_error_list pel; + auto a = spot::tgba_parse(argv[filename_index], + pel, dict, env, env, debug); - if (spot::format_tgba_parse_errors(std::cerr, argv[filename_index], pel)) - return 2; + if (spot::format_tgba_parse_errors(std::cerr, argv[filename_index], pel)) + return 2; - if (a) - { + if (a) spot::dotty_reachable(std::cout, a); - delete a; - } - else - { + else return 1; - } + } assert(spot::ltl::atomic_prop::instance_count() == 0); assert(spot::ltl::unop::instance_count() == 0); diff --git a/src/tgbatest/tripprod.cc b/src/tgbatest/tripprod.cc index 021c7f6a4..56b0aef29 100644 --- a/src/tgbatest/tripprod.cc +++ b/src/tgbatest/tripprod.cc @@ -42,36 +42,29 @@ main(int argc, char** argv) if (argc != 4) syntax(argv[0]); - - auto dict = spot::make_bdd_dict(); - - spot::ltl::environment& env(spot::ltl::default_environment::instance()); - spot::tgba_parse_error_list pel1; - spot::tgba* a1 = spot::tgba_parse(argv[1], pel1, dict, env); - if (spot::format_tgba_parse_errors(std::cerr, argv[1], pel1)) - return 2; - spot::tgba_parse_error_list pel2; - spot::tgba* a2 = spot::tgba_parse(argv[2], pel2, dict, env); - if (spot::format_tgba_parse_errors(std::cerr, argv[2], pel2)) - return 2; - spot::tgba_parse_error_list pel3; - spot::tgba* a3 = spot::tgba_parse(argv[3], pel3, dict, env); - if (spot::format_tgba_parse_errors(std::cerr, argv[3], pel3)) - return 2; - { - spot::tgba_product p(a1, a2); - spot::tgba_product p2(&p, a3); - spot::tgba_save_reachable(std::cout, &p2); + auto dict = spot::make_bdd_dict(); + + spot::ltl::environment& env(spot::ltl::default_environment::instance()); + spot::tgba_parse_error_list pel1; + auto a1 = spot::tgba_parse(argv[1], pel1, dict, env); + if (spot::format_tgba_parse_errors(std::cerr, argv[1], pel1)) + return 2; + spot::tgba_parse_error_list pel2; + auto a2 = spot::tgba_parse(argv[2], pel2, dict, env); + if (spot::format_tgba_parse_errors(std::cerr, argv[2], pel2)) + return 2; + spot::tgba_parse_error_list pel3; + auto a3 = spot::tgba_parse(argv[3], pel3, dict, env); + if (spot::format_tgba_parse_errors(std::cerr, argv[3], pel3)) + return 2; + + spot::tgba_save_reachable(std::cout, product(product(a1, a2), a3)); } assert(spot::ltl::unop::instance_count() == 0); assert(spot::ltl::binop::instance_count() == 0); assert(spot::ltl::multop::instance_count() == 0); - assert(spot::ltl::atomic_prop::instance_count() != 0); - delete a1; - delete a2; - delete a3; assert(spot::ltl::atomic_prop::instance_count() == 0); return exit_code; } diff --git a/wrap/python/ajax/spot.in b/wrap/python/ajax/spot.in index fc47be371..4f2418d2f 100755 --- a/wrap/python/ajax/spot.in +++ b/wrap/python/ajax/spot.in @@ -467,8 +467,8 @@ if output_type == 'f': if not f.is_syntactic_safety() or not f.is_syntactic_guarantee(): dict = spot.bdd_dict() automaton = spot.ltl_to_tgba_fm(f, dict, False, True) - minimized = spot.minimize_obligation_new(automaton, f) - if minimized: + minimized = spot.minimize_obligation(automaton, f) + if minimized != automaton: g = spot.is_guarantee_automaton(minimized) s = spot.is_safety_mwdba(minimized) if s and not f.is_syntactic_safety(): @@ -669,8 +669,8 @@ if prune_scc: issba = False if wdba_minimize: - minimized = spot.minimize_obligation_new(automaton, f) - if minimized: + minimized = spot.minimize_obligation(automaton, f) + if minimized != automaton: automaton = minimized minimized = 0 degen = False # No need to degeneralize anymore diff --git a/wrap/python/spot.i b/wrap/python/spot.i index b203fac1d..a83769ebb 100644 --- a/wrap/python/spot.i +++ b/wrap/python/spot.i @@ -28,9 +28,35 @@ %module(directors="1") spot +%include "std_shared_ptr.i" %include "std_string.i" %include "std_list.i" + // git grep 'typedef.*std::shared_ptr' | grep -v const + // sed 's/.*<\(.*\)>.*/%shared_ptr(spot::\1)/g' +%shared_ptr(spot::bdd_dict) +%shared_ptr(spot::dstar_aut) +%shared_ptr(spot::dstar_aut) +%shared_ptr(spot::future_conditions_collector) +%shared_ptr(spot::kripke) +%shared_ptr(spot::saba) +%shared_ptr(spot::saba_complement_tgba) +%shared_ptr(spot::ta) +%shared_ptr(spot::taa_tgba_formula) +%shared_ptr(spot::taa_tgba_string) +%shared_ptr(spot::ta_explicit) +%shared_ptr(spot::ta_product) +%shared_ptr(spot::taa_tgba) +%shared_ptr(spot::tgba) +%shared_ptr(spot::tgba_digraph) +%shared_ptr(spot::tgba_kv_complement) +%shared_ptr(spot::tgba_product) +%shared_ptr(spot::tgba_product_init) +%shared_ptr(spot::tgba_safra_complement) +%shared_ptr(spot::tgba_sgba_proxy) +%shared_ptr(spot::tgta) +%shared_ptr(spot::tgta_explicit) + namespace std { %template(liststr) list; }; @@ -76,6 +102,7 @@ namespace std { #include "tgba/bddprint.hh" #include "tgba/state.hh" #include "tgba/succiter.hh" +#include "tgba/fwd.hh" #include "tgba/tgba.hh" #include "tgba/taatgba.hh" #include "tgba/tgbaproduct.hh" @@ -185,37 +212,16 @@ using namespace spot; %feature("new") spot::emptiness_check_result::accepting_run; %feature("new") spot::explicit_magic_search; %feature("new") spot::explicit_se05_search; -%feature("new") spot::ltl_to_taa; -%feature("new") spot::ltl_to_tgba_fm; -%feature("new") spot::compsusp; -%feature("new") spot::minimize_wdba; -%feature("new") spot::minimize_monitor; -%feature("new") spot::scc_filter; -%feature("new") spot::tgba_dupexp_bfs; -%feature("new") spot::tgba_dupexp_dfs; %feature("new") spot::tgba::get_init_state; %feature("new") spot::tgba::succ_iter; %feature("new") spot::tgba_succ_iterator::current_state; -%feature("new") spot::simulation; -%feature("new") spot::cosimulation; -%feature("new") spot::iterated_simulations; -%feature("new") spot::degeneralize; -%feature("new") spot::degeneralize_tba; -%feature("new") spot::tgba_parse; -%feature("new") spot::tgba_to_ta; -%feature("new") spot::tgba_to_tgta; -%feature("new") spot::postprocessor::run; - -// The argument to postprocessor::run() will be deleted. -// Apparently SWIG can only disown arguments based on their -// names... -%apply SWIGTYPE *DISOWN { SWIGTYPE * input_disown }; // Help SWIG with namespace lookups. #define ltl spot::ltl %include "tgba/bddprint.hh" %include "tgba/state.hh" %include "tgba/succiter.hh" +%include "tgba/fwd.hh" %include "tgba/tgba.hh" %include "tgba/taatgba.hh" %include "tgba/tgbaproduct.hh" @@ -313,32 +319,7 @@ namespace std { }; } -%feature("new") minimize_obligation_new; - %inline %{ - -// A variant of minimize_obligation() that always return a new object. -const spot::tgba_digraph* -minimize_obligation_new(const spot::tgba* a, const spot::ltl::formula* f) -{ - auto aa = dynamic_cast(a); - bool freeit = false; - if (!aa) - { - freeit = true; - aa = tgba_dupexp_dfs(a); - } - auto res = spot::minimize_obligation(aa, f); - // Return 0 if the output is the same as the input, otherwise - // it is hard for swig to know if the output is "new" or not. - if (freeit) - delete aa; - if (res == aa) - return 0; - else - return res; -} - spot::ltl::parse_error_list empty_parse_error_list() { diff --git a/wrap/python/tests/interdep.py b/wrap/python/tests/interdep.py index 3c8522b54..6c4e89643 100755 --- a/wrap/python/tests/interdep.py +++ b/wrap/python/tests/interdep.py @@ -50,8 +50,9 @@ while not it.done(): it.next() buddy.bdd_printset(b); spot.nl_cout() sys.stdout.write("%s\n" % b) +del it +del s0 del b del c del f -del a del simp