Massage the AST so that identical sub-formula share the same
reference-counted formula*. One can't call constructors for AST items anymore, everything need to be acquired through instance() class methods. * src/ltlast/formula.cc, src/ltlast/refformula.cc, src/ltlast/refformula.hh: New files. * src/ltlast/Makefile.am (libltlast_la_SOURCES): Add them. * src/ltlast/atomic_prop.cc, src/ltlast/atomic_prop.hh, src/ltlast/unop.cc, src/ltlast/unop.hh, src/ltlast/binop.cc, src/ltlast/binop.hh: Make the constructor and destructor protected. Define a static function `instance()' to get an instance with specific argument. Use a map called `instances' to store all known instances. Inherit from ref_formula. * src/ltlast/constant.hh, src/ltlast/constant.cc: Protect the constructor and destructor. Provide the false_instance() and true_instance() functions instead. * src/formula.hh (ref, unref, ref_, unref_): New methods. * src/ltlast/multop.cc, src/ltlast/multop.hh: Protect the constructor, destructor, as well as the add() method. Provides the instance(), and add() class methods instead. Store children_ as a pointer. * src/ltlenv/defaultenv.cc (require): Adjust to call atomic_prop::instance. * src/ltlparse/ltlparse.yy: Adjust to call instance() functions instead of constructors. * src/ltltest/Makefile.am (LDADD): Tweak library ordering. * src/ltlvisit/clone.hh (clone_visitor): Inherit from visitor, not const_visitor, and adjust all prototypes appropriately. * src/ltlvisit/clone.cc (clone_visitor): Likewise. Call ref() or instance() methods instead of copy constructors. * src/ltlvisit/equals.cc: Simplify atomic_prop and constant cases. * src/ltlvisit/lunabbrev.hh, src/ltlvisit/lunabbrev.cc, src/ltlvisit/tunabbrev.hh, src/ltlvisit/tunabbrev.cc, src/ltlvisit/nenoform.hh, src/ltlvisit/nenoform.cc: Use instance() methods instead of constructor. Make these children of visitor, not const_visitor. * src/ltltest/readltl.c (main): Do not delete the formula.
This commit is contained in:
parent
f1838ab8ef
commit
5f6d8b6234
29 changed files with 548 additions and 253 deletions
|
|
@ -101,15 +101,15 @@ subformula: ATOMIC_PROP
|
|||
delete $1;
|
||||
}
|
||||
| CONST_TRUE
|
||||
{ $$ = new constant(constant::True); }
|
||||
{ $$ = constant::true_instance(); }
|
||||
| CONST_FALSE
|
||||
{ $$ = new constant(constant::False); }
|
||||
{ $$ = constant::false_instance(); }
|
||||
| PAR_OPEN subformula PAR_CLOSE
|
||||
{ $$ = $2; }
|
||||
| PAR_OPEN error PAR_CLOSE
|
||||
{ error_list.push_back(parse_error(@$,
|
||||
"treating this parenthetical block as false"));
|
||||
$$ = new constant(constant::False);
|
||||
$$ = constant::false_instance();
|
||||
}
|
||||
| PAR_OPEN subformula many_errors PAR_CLOSE
|
||||
{ error_list.push_back(parse_error(@3,
|
||||
|
|
@ -117,27 +117,27 @@ subformula: ATOMIC_PROP
|
|||
$$ = $2;
|
||||
}
|
||||
| OP_NOT subformula
|
||||
{ $$ = new unop(unop::Not, $2); }
|
||||
{ $$ = unop::instance(unop::Not, $2); }
|
||||
| subformula OP_AND subformula
|
||||
{ $$ = new multop(multop::And, $1, $3); }
|
||||
{ $$ = multop::instance(multop::And, $1, $3); }
|
||||
| subformula OP_OR subformula
|
||||
{ $$ = new multop(multop::Or, $1, $3); }
|
||||
{ $$ = multop::instance(multop::Or, $1, $3); }
|
||||
| subformula OP_XOR subformula
|
||||
{ $$ = new binop(binop::Xor, $1, $3); }
|
||||
{ $$ = binop::instance(binop::Xor, $1, $3); }
|
||||
| subformula OP_IMPLIES subformula
|
||||
{ $$ = new binop(binop::Implies, $1, $3); }
|
||||
{ $$ = binop::instance(binop::Implies, $1, $3); }
|
||||
| subformula OP_EQUIV subformula
|
||||
{ $$ = new binop(binop::Equiv, $1, $3); }
|
||||
{ $$ = binop::instance(binop::Equiv, $1, $3); }
|
||||
| subformula OP_U subformula
|
||||
{ $$ = new binop(binop::U, $1, $3); }
|
||||
{ $$ = binop::instance(binop::U, $1, $3); }
|
||||
| subformula OP_R subformula
|
||||
{ $$ = new binop(binop::R, $1, $3); }
|
||||
{ $$ = binop::instance(binop::R, $1, $3); }
|
||||
| OP_F subformula
|
||||
{ $$ = new unop(unop::F, $2); }
|
||||
{ $$ = unop::instance(unop::F, $2); }
|
||||
| OP_G subformula
|
||||
{ $$ = new unop(unop::G, $2); }
|
||||
{ $$ = unop::instance(unop::G, $2); }
|
||||
| OP_X subformula
|
||||
{ $$ = new unop(unop::X, $2); }
|
||||
{ $$ = unop::instance(unop::X, $2); }
|
||||
// | subformula many_errors
|
||||
// { error_list->push_back(parse_error(@2,
|
||||
// "ignoring these unexpected trailing tokens"));
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue