* src/ltlvisit/lunabbrev.cc, src/ltlvisit/lunabbrev.hh: New files.
* src/ltlvisit/Makefile.am (libltlvisit_a_SOURCES): Add them. * src/ltlast/multop.cc (multop::multop(type)): New constructor. * src/ltlast/multop.hh (multop::multop(type)): New constructor. * src/ltltest/lunabbrev.test: New file. * src/ltltest/Makefile.am (TESTS): Add lunabbrev.test. (check_PROGRAMS): Add lunabbrev. (lunabbrev_SOURCES, lunabbrev_CPPFLAGS): New variables. * src/ltltest/equals.cc (main) [LUNABBREV]: Call unabbreviate_logic.
This commit is contained in:
parent
5d714612a3
commit
526012a795
10 changed files with 197 additions and 5 deletions
|
|
@ -8,4 +8,6 @@ libltlvisit_a_SOURCES = \
|
|||
dump.cc \
|
||||
dump.hh \
|
||||
equals.cc \
|
||||
equals.hh
|
||||
equals.hh \
|
||||
lunabbrev.hh \
|
||||
lunabbrev.cc
|
||||
|
|
|
|||
99
src/ltlvisit/lunabbrev.cc
Normal file
99
src/ltlvisit/lunabbrev.cc
Normal file
|
|
@ -0,0 +1,99 @@
|
|||
#include "ltlast/allnodes.hh"
|
||||
#include "lunabbrev.hh"
|
||||
|
||||
namespace spot
|
||||
{
|
||||
namespace ltl
|
||||
{
|
||||
unabbreviate_logic_visitor::unabbreviate_logic_visitor()
|
||||
{
|
||||
}
|
||||
|
||||
unabbreviate_logic_visitor::~unabbreviate_logic_visitor()
|
||||
{
|
||||
}
|
||||
|
||||
formula*
|
||||
unabbreviate_logic_visitor::result() const
|
||||
{
|
||||
return result_;
|
||||
}
|
||||
|
||||
void
|
||||
unabbreviate_logic_visitor::visit(const atomic_prop* ap)
|
||||
{
|
||||
result_ = new atomic_prop(ap->name());
|
||||
}
|
||||
|
||||
void
|
||||
unabbreviate_logic_visitor::visit(const constant* c)
|
||||
{
|
||||
result_ = new constant(c->val());
|
||||
}
|
||||
|
||||
void
|
||||
unabbreviate_logic_visitor::visit(const unop* uo)
|
||||
{
|
||||
result_ = new unop(uo->op(), unabbreviate_logic(uo->child()));
|
||||
}
|
||||
|
||||
void
|
||||
unabbreviate_logic_visitor::visit(const binop* bo)
|
||||
{
|
||||
formula* f1 = unabbreviate_logic(bo->first());
|
||||
formula* f2 = unabbreviate_logic(bo->second());
|
||||
switch (bo->op())
|
||||
{
|
||||
/* f1 ^ f2 == (f1 & !f2) | (f2 & !f1) */
|
||||
case binop::Xor:
|
||||
result_ = new multop(multop::Or,
|
||||
new multop(multop::And, f1,
|
||||
new unop(unop::Not, f2)),
|
||||
new multop(multop::And, f2,
|
||||
new unop(unop::Not, f1)));
|
||||
return;
|
||||
/* f1 => f2 == !f1 | f2 */
|
||||
case binop::Implies:
|
||||
result_ = new multop(multop::Or, new unop(unop::Not, f1), f2);
|
||||
return;
|
||||
/* f1 <=> f2 == (f1 & f2) | (!f1 & !f2) */
|
||||
case binop::Equiv:
|
||||
result_ = new multop(multop::Or,
|
||||
new multop(multop::And, f1, f2),
|
||||
new multop(multop::And,
|
||||
new unop(unop::Not, f1),
|
||||
new unop(unop::Not, f2)));
|
||||
return;
|
||||
/* f1 U f2 == f1 U f2 */
|
||||
/* f1 R f2 == f1 R f2 */
|
||||
case binop::U:
|
||||
case binop::R:
|
||||
result_ = new binop(bo->op(), f1, f2);
|
||||
return;
|
||||
}
|
||||
/* Unreachable code. */
|
||||
assert(0);
|
||||
}
|
||||
|
||||
void
|
||||
unabbreviate_logic_visitor::visit(const multop* mo)
|
||||
{
|
||||
multop* res = new multop(mo->op());
|
||||
unsigned mos = mo->size();
|
||||
for (unsigned i = 0; i < mos; ++i)
|
||||
{
|
||||
res->add(unabbreviate_logic(mo->nth(i)));
|
||||
}
|
||||
result_ = res;
|
||||
}
|
||||
|
||||
formula*
|
||||
unabbreviate_logic(const formula* f)
|
||||
{
|
||||
unabbreviate_logic_visitor v;
|
||||
f->accept(v);
|
||||
return v.result();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
30
src/ltlvisit/lunabbrev.hh
Normal file
30
src/ltlvisit/lunabbrev.hh
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
#include "ltlast/formula.hh"
|
||||
#include "ltlast/visitor.hh"
|
||||
|
||||
namespace spot
|
||||
{
|
||||
namespace ltl
|
||||
{
|
||||
// This visitor is public, because it's convenient
|
||||
// to derive from it and override part of its methods.
|
||||
class unabbreviate_logic_visitor : public const_visitor
|
||||
{
|
||||
public:
|
||||
unabbreviate_logic_visitor();
|
||||
virtual ~unabbreviate_logic_visitor();
|
||||
|
||||
formula* result() const;
|
||||
|
||||
void visit(const atomic_prop* ap);
|
||||
void visit(const unop* uo);
|
||||
void visit(const binop* bo);
|
||||
void visit(const multop* mo);
|
||||
void visit(const constant* c);
|
||||
|
||||
private:
|
||||
formula* result_;
|
||||
};
|
||||
|
||||
formula* unabbreviate_logic(const formula* f);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue