Implements spot::ltl::destroy() and exercise it.
* src/ltlast/atomic_prop.hh: Declare instance_count(). * src/ltlast/binop.hh, src/ltlast/unop.hh, src/ltlast/multop.hh: Likewise. Also, really inherit for ref_formula this time. * src/ltlast/atomic_prop.cc, src/ltlast/binop.cc, src/ltlast/unop.cc, src/ltlast/multop.cc: On destruction, suppress the instance from the instance map. Implement instance_count(). * src/ltlast/formula.cc, src/ltlast/formula.hh, src/ltlast/ref_formula.cc, src/ltlast/ref_formula.hh: Add virtual destructors. * src/ltlparse/ltlparse.yy: Recover from binary operators with missing right hand operand (the point is just to destroy the the left hand operand). * src/ltltest/equals.cc, src/ltltest/readltl.cc, src/ltltest/tostring.cc: Destroy used formulae. Make sure instance_count()s are null are the end. * src/ltltest/parseerr.test: Adjust expected result, now that the parser lnows about missing right hand operands. * src/ltlvisit/destroy.hh, src/ltlvisit/destroy.cc, src/ltlvisit/postfix.hh, src/ltlvisit/postfix.cc: New files. * src/ltlvisit/Makefile.am (libltlvisit_la_SOURCES): Add them. * src/ltlvisit/lunabbrev.cc (Xor, Equiv): Clone formulae occurring twice in the rewritten expression.
This commit is contained in:
parent
5f6d8b6234
commit
9123e56ff9
24 changed files with 382 additions and 24 deletions
|
|
@ -5,6 +5,8 @@
|
|||
#include "ltlvisit/tunabbrev.hh"
|
||||
#include "ltlvisit/dump.hh"
|
||||
#include "ltlvisit/nenoform.hh"
|
||||
#include "ltlvisit/destroy.hh"
|
||||
#include "ltlast/allnodes.hh"
|
||||
|
||||
void
|
||||
syntax(char* prog)
|
||||
|
|
@ -19,7 +21,7 @@ main(int argc, char** argv)
|
|||
if (argc != 3)
|
||||
syntax(argv[0]);
|
||||
|
||||
|
||||
|
||||
spot::ltl::parse_error_list p1;
|
||||
spot::ltl::formula* f1 = spot::ltl::parse(argv[1], p1);
|
||||
|
||||
|
|
@ -28,28 +30,48 @@ main(int argc, char** argv)
|
|||
|
||||
spot::ltl::parse_error_list p2;
|
||||
spot::ltl::formula* f2 = spot::ltl::parse(argv[2], p2);
|
||||
|
||||
|
||||
if (spot::ltl::format_parse_errors(std::cerr, argv[2], p2))
|
||||
return 2;
|
||||
|
||||
#if (defined LUNABBREV) || (defined TUNABBREV) || (defined NENOFORM)
|
||||
spot::ltl::formula* tmp;
|
||||
#endif
|
||||
#ifdef LUNABBREV
|
||||
tmp = f1;
|
||||
std::cout << spot::ltl::atomic_prop::instance_count() << std::endl;
|
||||
f1 = spot::ltl::unabbreviate_logic(f1);
|
||||
std::cout << spot::ltl::atomic_prop::instance_count() << std::endl;
|
||||
spot::ltl::destroy(tmp);
|
||||
std::cout << spot::ltl::atomic_prop::instance_count() << std::endl;
|
||||
spot::ltl::dump(*f1, std::cout);
|
||||
std::cout << std::endl;
|
||||
#endif
|
||||
#ifdef TUNABBREV
|
||||
tmp = f1;
|
||||
f1 = spot::ltl::unabbreviate_ltl(f1);
|
||||
spot::ltl::destroy(tmp);
|
||||
spot::ltl::dump(*f1, std::cout);
|
||||
std::cout << std::endl;
|
||||
#endif
|
||||
#ifdef NENOFORM
|
||||
tmp = f1;
|
||||
f1 = spot::ltl::negative_normal_form(f1);
|
||||
spot::ltl::destroy(tmp);
|
||||
spot::ltl::dump(*f1, std::cout);
|
||||
std::cout << std::endl;
|
||||
#endif
|
||||
|
||||
if (equals(f1, f2))
|
||||
return 0;
|
||||
return 1;
|
||||
int exit_code = !equals(f1, f2);
|
||||
|
||||
spot::ltl::destroy(f1);
|
||||
std::cout << spot::ltl::atomic_prop::instance_count() << std::endl;
|
||||
spot::ltl::destroy(f2);
|
||||
std::cout << spot::ltl::atomic_prop::instance_count() << std::endl;
|
||||
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);
|
||||
|
||||
return exit_code;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -33,17 +33,19 @@ check()
|
|||
# Empty or unparsable strings
|
||||
check '' ''
|
||||
check '+' ''
|
||||
check 'a U' ''
|
||||
check 'a U b V c R' ''
|
||||
|
||||
# leading and trailing garbage are skipped
|
||||
check '/2/3/4/5 a + b /6/7/8/' 'multop(Or, AP(a), AP(b))'
|
||||
check 'a U b c' 'binop(U, AP(a), AP(b))'
|
||||
check 'a &&& b' 'AP(b)'
|
||||
check 'a &&& b' 'multop(And, constant(0), AP(b))'
|
||||
# (check multop merging while we are at it)
|
||||
check 'a & b & c & d e' 'multop(And, AP(a), AP(b), AP(c), AP(d))'
|
||||
check 'a & (b | c) & d should work' 'multop(And, AP(a), multop(Or, AP(b), AP(c)), AP(d))'
|
||||
|
||||
# Binop recovery
|
||||
check 'a U' 'constant(0)'
|
||||
check 'a U b V c R' 'constant(0)'
|
||||
|
||||
# Recovery inside parentheses
|
||||
check 'a U (b c) U e R (f g <=> h)' \
|
||||
'binop(R, binop(U, binop(U, AP(a), AP(b)), AP(e)), AP(f))'
|
||||
|
|
|
|||
|
|
@ -2,6 +2,8 @@
|
|||
#include "ltlparse/public.hh"
|
||||
#include "ltlvisit/dump.hh"
|
||||
#include "ltlvisit/dotty.hh"
|
||||
#include "ltlvisit/destroy.hh"
|
||||
#include "ltlast/allnodes.hh"
|
||||
|
||||
void
|
||||
syntax(char* prog)
|
||||
|
|
@ -27,15 +29,15 @@ main(int argc, char** argv)
|
|||
if (argc < 3)
|
||||
syntax(argv[0]);
|
||||
formula_index = 2;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
spot::ltl::environment& env(spot::ltl::default_environment::instance());
|
||||
spot::ltl::parse_error_list pel;
|
||||
spot::ltl::formula* f = spot::ltl::parse(argv[formula_index],
|
||||
spot::ltl::formula* f = spot::ltl::parse(argv[formula_index],
|
||||
pel, env, debug);
|
||||
|
||||
spot::ltl::parse_error_list::iterator it;
|
||||
exit_code =
|
||||
exit_code =
|
||||
spot::ltl::format_parse_errors(std::cerr, argv[formula_index], pel);
|
||||
|
||||
if (f)
|
||||
|
|
@ -46,11 +48,16 @@ main(int argc, char** argv)
|
|||
spot::ltl::dump(*f, std::cout);
|
||||
std::cout << std::endl;
|
||||
#endif
|
||||
spot::ltl::destroy(f);
|
||||
}
|
||||
else
|
||||
{
|
||||
exit_code = 1;
|
||||
}
|
||||
|
||||
|
||||
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);
|
||||
return exit_code;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,6 +2,8 @@
|
|||
#include "ltlparse/public.hh"
|
||||
#include "ltlvisit/tostring.hh"
|
||||
#include "ltlvisit/equals.hh"
|
||||
#include "ltlvisit/destroy.hh"
|
||||
#include "ltlast/allnodes.hh"
|
||||
|
||||
void
|
||||
syntax(char *prog)
|
||||
|
|
@ -45,5 +47,12 @@ main(int argc, char **argv)
|
|||
|
||||
if (f2s != f1s)
|
||||
return 1;
|
||||
|
||||
spot::ltl::destroy(f1);
|
||||
spot::ltl::destroy(f2);
|
||||
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);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue