* src/ltlvisit/basereduc.cc, src/ltlvisit/reducform.cc: Use
dynamic_cast instead of node_type_form_visitor, this is usually smaller. * src/ltlvisit/reducform.hh, src/ltlvisit/forminf.cc (node_type_form_visitor): Delete. * src/sanity/style.test: Two more checks.
This commit is contained in:
parent
d973c1dad0
commit
cdbb199c4d
6 changed files with 120 additions and 180 deletions
|
|
@ -1,3 +1,12 @@
|
|||
2004-05-26 Alexandre Duret-Lutz <adl@src.lip6.fr>
|
||||
|
||||
* src/ltlvisit/basereduc.cc, src/ltlvisit/reducform.cc: Use
|
||||
dynamic_cast instead of node_type_form_visitor, this is usually
|
||||
smaller.
|
||||
* src/ltlvisit/reducform.hh,
|
||||
src/ltlvisit/forminf.cc (node_type_form_visitor): Delete.
|
||||
* src/sanity/style.test: Two more checks.
|
||||
|
||||
2004-05-25 Alexandre Duret-Lutz <adl@src.lip6.fr>
|
||||
|
||||
* src/ltlvisit/formlength.cc: Rename as ...
|
||||
|
|
|
|||
|
|
@ -81,7 +81,7 @@ namespace spot
|
|||
case unop::X:
|
||||
// X(true) = true
|
||||
// X(false) = false
|
||||
if (node_type(result_) == (node_type_form_visitor::Const))
|
||||
if (dynamic_cast<constant*>(result_))
|
||||
return;
|
||||
|
||||
// XGF(f) = GF(f)
|
||||
|
|
@ -123,10 +123,9 @@ namespace spot
|
|||
return;
|
||||
|
||||
case unop::F:
|
||||
|
||||
// F(true) = true
|
||||
// F(false) = false
|
||||
if (node_type(result_) == (node_type_form_visitor::Const))
|
||||
if (dynamic_cast<constant*>(result_))
|
||||
return;
|
||||
|
||||
// FX(a) = XF(a)
|
||||
|
|
@ -177,10 +176,9 @@ namespace spot
|
|||
return;
|
||||
|
||||
case unop::G:
|
||||
|
||||
// G(true) = true
|
||||
// G(false) = false
|
||||
if (node_type(result_) == (node_type_form_visitor::Const))
|
||||
if (dynamic_cast<constant*>(result_))
|
||||
return;
|
||||
|
||||
// G(a R b) = G(b)
|
||||
|
|
@ -249,8 +247,6 @@ namespace spot
|
|||
formula* f1 = bo->first();
|
||||
formula* f2 = bo->second();
|
||||
formula* ftmp = NULL;
|
||||
node_type_form_visitor v1;
|
||||
node_type_form_visitor v2;
|
||||
unop* fu1 = NULL;
|
||||
unop* fu2 = NULL;
|
||||
switch (bo->op())
|
||||
|
|
@ -275,7 +271,7 @@ namespace spot
|
|||
|
||||
// a U false = false
|
||||
// a U true = true
|
||||
if (node_type(f2) == (node_type_form_visitor::Const))
|
||||
if (dynamic_cast<constant*>(f2))
|
||||
{
|
||||
result_ = f2;
|
||||
return;
|
||||
|
|
@ -308,7 +304,7 @@ namespace spot
|
|||
|
||||
// a R false = false
|
||||
// a R true = true
|
||||
if (node_type(f2) == (node_type_form_visitor::Const))
|
||||
if (dynamic_cast<constant*>(f2))
|
||||
{
|
||||
result_ = f2;
|
||||
return;
|
||||
|
|
@ -358,9 +354,6 @@ namespace spot
|
|||
|
||||
multop::vec* tmpOther = new multop::vec;
|
||||
|
||||
unop* uo = NULL;
|
||||
unop* uo2 = NULL;
|
||||
binop* bo = NULL;
|
||||
formula* ftmp = NULL;
|
||||
|
||||
for (unsigned i = 0; i < mos; ++i)
|
||||
|
|
@ -375,47 +368,43 @@ namespace spot
|
|||
{
|
||||
if (*i == NULL)
|
||||
continue;
|
||||
switch (node_type(*i))
|
||||
unop* uo = dynamic_cast<unop*>(*i);
|
||||
binop* bo = dynamic_cast<binop*>(*i);
|
||||
if (uo)
|
||||
{
|
||||
|
||||
case node_type_form_visitor::Unop:
|
||||
|
||||
// Xa & Xb = X(a & b)
|
||||
uo = dynamic_cast<unop*>(*i);
|
||||
if (uo && uo->op() == unop::X)
|
||||
{
|
||||
// Xa & Xb = X(a & b)
|
||||
tmpX->push_back(basic_reduce_form(uo->child()));
|
||||
break;
|
||||
}
|
||||
|
||||
else if (is_FG(*i))
|
||||
{
|
||||
// FG(a) & FG(b) = FG(a & b)
|
||||
if (is_FG(*i))
|
||||
{
|
||||
uo2 = dynamic_cast<unop*>(uo->child());
|
||||
unop* uo2 = dynamic_cast<unop*>(uo->child());
|
||||
tmpFG->push_back(basic_reduce_form(uo2->child()));
|
||||
break;
|
||||
}
|
||||
tmpOther->push_back(basic_reduce_form(*i));
|
||||
break;
|
||||
|
||||
case node_type_form_visitor::Binop:
|
||||
|
||||
// (a U b) & (c U b) = (a & c) U b
|
||||
if (dynamic_cast<binop*>(*i)->op() == binop::U)
|
||||
else
|
||||
{
|
||||
tmpOther->push_back(basic_reduce_form(*i));
|
||||
}
|
||||
}
|
||||
else if (bo)
|
||||
{
|
||||
if (bo->op() == binop::U)
|
||||
{
|
||||
// (a U b) & (c U b) = (a & c) U b
|
||||
ftmp = dynamic_cast<binop*>(*i)->second();
|
||||
tmpUright = new multop::vec;
|
||||
for (multop::vec::iterator j = i; j != res->end(); j++)
|
||||
{
|
||||
if (!*j)
|
||||
continue;
|
||||
if (node_type(*j) == node_type_form_visitor::Binop
|
||||
&& dynamic_cast<binop*>(*j)->op() == binop::U
|
||||
&& ftmp == dynamic_cast<binop*>(*j)->second())
|
||||
binop* bo2 = dynamic_cast<binop*>(*j);
|
||||
if (bo2 && bo2->op() == binop::U
|
||||
&& ftmp == bo2->second())
|
||||
{
|
||||
bo = dynamic_cast<binop*>(*j);
|
||||
tmpUright
|
||||
->push_back(basic_reduce_form(bo->first()));
|
||||
->push_back(basic_reduce_form(bo2->first()));
|
||||
if (j != i)
|
||||
{
|
||||
destroy(*j);
|
||||
|
|
@ -430,25 +419,22 @@ namespace spot
|
|||
And,
|
||||
tmpUright),
|
||||
basic_reduce_form(ftmp)));
|
||||
break;
|
||||
}
|
||||
|
||||
// (a R b) & (a R c) = a R (b & c)
|
||||
if (dynamic_cast<binop*>(*i)->op() == binop::R)
|
||||
else if (bo->op() == binop::R)
|
||||
{
|
||||
// (a R b) & (a R c) = a R (b & c)
|
||||
ftmp = dynamic_cast<binop*>(*i)->first();
|
||||
tmpRright = new multop::vec;
|
||||
for (multop::vec::iterator j = i; j != res->end(); j++)
|
||||
{
|
||||
if (!*j)
|
||||
continue;
|
||||
if (node_type(*j) == node_type_form_visitor::Binop
|
||||
&& dynamic_cast<binop*>(*j)->op() == binop::R
|
||||
&& ftmp == dynamic_cast<binop*>(*j)->first())
|
||||
binop* bo2 = dynamic_cast<binop*>(*j);
|
||||
if (bo2 && bo2->op() == binop::R
|
||||
&& ftmp == bo2->first())
|
||||
{
|
||||
bo = dynamic_cast<binop*>(*j);
|
||||
tmpRright
|
||||
->push_back(basic_reduce_form(bo->second()));
|
||||
->push_back(basic_reduce_form(bo2->second()));
|
||||
if (j != i)
|
||||
{
|
||||
destroy(*j);
|
||||
|
|
@ -462,19 +448,21 @@ namespace spot
|
|||
multop::
|
||||
instance(multop::And,
|
||||
tmpRright)));
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
tmpOther->push_back(basic_reduce_form(*i));
|
||||
break;
|
||||
default:
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
tmpOther->push_back(basic_reduce_form(*i));
|
||||
break;
|
||||
}
|
||||
destroy(*i);
|
||||
}
|
||||
|
||||
delete(tmpGF);
|
||||
tmpGF = NULL;
|
||||
delete tmpGF;
|
||||
tmpGF = 0;
|
||||
|
||||
break;
|
||||
|
||||
|
|
@ -484,47 +472,43 @@ namespace spot
|
|||
{
|
||||
if (!*i)
|
||||
continue;
|
||||
switch (node_type(*i))
|
||||
unop* uo = dynamic_cast<unop*>(*i);
|
||||
binop* bo = dynamic_cast<binop*>(*i);
|
||||
if (uo)
|
||||
{
|
||||
|
||||
case node_type_form_visitor::Unop:
|
||||
|
||||
// Xa | Xb = X(a | b)
|
||||
uo = dynamic_cast<unop*>(*i);
|
||||
if (uo && uo->op() == unop::X)
|
||||
{
|
||||
// Xa | Xb = X(a | b)
|
||||
tmpX->push_back(basic_reduce_form(uo->child()));
|
||||
break;
|
||||
}
|
||||
|
||||
else if (is_GF(*i))
|
||||
{
|
||||
// GF(a) | GF(b) = GF(a | b)
|
||||
if (is_GF(*i))
|
||||
{
|
||||
uo2 = dynamic_cast<unop*>(uo->child());
|
||||
unop* uo2 = dynamic_cast<unop*>(uo->child());
|
||||
tmpGF->push_back(basic_reduce_form(uo2->child()));
|
||||
break;
|
||||
}
|
||||
tmpOther->push_back(basic_reduce_form(*i));
|
||||
break;
|
||||
|
||||
case node_type_form_visitor::Binop:
|
||||
|
||||
// (a U b) | (a U c) = a U (b | c)
|
||||
if (dynamic_cast<binop*>(*i)->op() == binop::U)
|
||||
else
|
||||
{
|
||||
ftmp = dynamic_cast<binop*>(*i)->first();
|
||||
tmpOther->push_back(basic_reduce_form(*i));
|
||||
}
|
||||
}
|
||||
else if (bo)
|
||||
{
|
||||
if (bo->op() == binop::U)
|
||||
{
|
||||
// (a U b) | (a U c) = a U (b | c)
|
||||
ftmp = bo->first();
|
||||
tmpUright = new multop::vec;
|
||||
for (multop::vec::iterator j = i; j != res->end(); j++)
|
||||
{
|
||||
if (!*j)
|
||||
continue;
|
||||
if (node_type(*j) == node_type_form_visitor::Binop
|
||||
&& dynamic_cast<binop*>(*j)->op() == binop::U
|
||||
&& ftmp == dynamic_cast<binop*>(*j)->first())
|
||||
binop* bo2 = dynamic_cast<binop*>(*j);
|
||||
if (bo2 && bo2->op() == binop::U
|
||||
&& ftmp == bo2->first())
|
||||
{
|
||||
bo = dynamic_cast<binop*>(*j);
|
||||
tmpUright
|
||||
->push_back(basic_reduce_form(bo->second()));
|
||||
->push_back(basic_reduce_form(bo2->second()));
|
||||
if (j != i)
|
||||
{
|
||||
destroy(*j);
|
||||
|
|
@ -537,23 +521,20 @@ namespace spot
|
|||
multop::
|
||||
instance(multop::Or,
|
||||
tmpUright)));
|
||||
break;
|
||||
}
|
||||
|
||||
// (a R b) | (c R b) = (a | c) R b
|
||||
if (dynamic_cast<binop*>(*i)->op() == binop::R)
|
||||
else if (bo->op() == binop::R)
|
||||
{
|
||||
// (a R b) | (c R b) = (a | c) R b
|
||||
ftmp = dynamic_cast<binop*>(*i)->second();
|
||||
tmpRright = new multop::vec;
|
||||
for (multop::vec::iterator j = i; j != res->end(); j++)
|
||||
{
|
||||
if (!*j)
|
||||
continue;
|
||||
if (node_type(*j) == node_type_form_visitor::Binop
|
||||
&& dynamic_cast<binop*>(*j)->op() == binop::R
|
||||
&& ftmp == dynamic_cast<binop*>(*j)->second())
|
||||
binop* bo2 = dynamic_cast<binop*>(*j);
|
||||
if (bo2 && bo2->op() == binop::R
|
||||
&& ftmp == bo2->second())
|
||||
{
|
||||
bo = dynamic_cast<binop*>(*j);
|
||||
tmpRright
|
||||
->push_back(basic_reduce_form(bo->first()));
|
||||
if (j != i)
|
||||
|
|
@ -569,40 +550,44 @@ namespace spot
|
|||
instance(multop::Or,
|
||||
tmpRright),
|
||||
basic_reduce_form(ftmp)));
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
tmpOther->push_back(basic_reduce_form(*i));
|
||||
break;
|
||||
default:
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
tmpOther->push_back(basic_reduce_form(*i));
|
||||
break;
|
||||
}
|
||||
destroy(*i);
|
||||
}
|
||||
|
||||
delete(tmpFG);
|
||||
tmpFG = NULL;
|
||||
delete tmpFG;
|
||||
tmpFG = 0;
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
res->clear();
|
||||
delete(res);
|
||||
delete res;
|
||||
|
||||
if (tmpX->size())
|
||||
tmpOther->push_back(unop::instance(unop::X,
|
||||
multop::instance(mo->op(),
|
||||
tmpX)));
|
||||
else delete(tmpX);
|
||||
else
|
||||
delete tmpX;
|
||||
|
||||
if (tmpU->size())
|
||||
tmpOther->push_back(multop::instance(mo->op(), tmpU));
|
||||
else delete(tmpU);
|
||||
else
|
||||
delete tmpU;
|
||||
|
||||
if (tmpR->size())
|
||||
tmpOther->push_back(multop::instance(mo->op(), tmpR));
|
||||
else delete(tmpR);
|
||||
else
|
||||
delete tmpR;
|
||||
|
||||
if ((tmpGF != NULL) &&
|
||||
(tmpGF->size()))
|
||||
|
|
|
|||
|
|
@ -58,53 +58,6 @@ namespace spot
|
|||
return false;
|
||||
}
|
||||
|
||||
node_type_form_visitor::node_type_form_visitor(){}
|
||||
|
||||
node_type_form_visitor::type
|
||||
node_type_form_visitor::result() const
|
||||
{
|
||||
return result_;
|
||||
}
|
||||
|
||||
void
|
||||
node_type_form_visitor::visit(const atomic_prop*)
|
||||
{
|
||||
result_ = node_type_form_visitor::Atom;
|
||||
}
|
||||
|
||||
void
|
||||
node_type_form_visitor::visit(const constant*)
|
||||
{
|
||||
result_ = node_type_form_visitor::Const;
|
||||
}
|
||||
|
||||
void
|
||||
node_type_form_visitor::visit(const unop*)
|
||||
{
|
||||
result_ = node_type_form_visitor::Unop;
|
||||
}
|
||||
|
||||
void
|
||||
node_type_form_visitor::visit(const binop*)
|
||||
{
|
||||
result_ = node_type_form_visitor::Binop;
|
||||
}
|
||||
|
||||
void
|
||||
node_type_form_visitor::visit(const multop*)
|
||||
{
|
||||
result_ = node_type_form_visitor::Multop;
|
||||
}
|
||||
|
||||
node_type_form_visitor::type
|
||||
node_type(const formula* f)
|
||||
{
|
||||
node_type_form_visitor v;
|
||||
assert(f != NULL);
|
||||
const_cast<formula*>(f)->accept(v);
|
||||
return v.result();
|
||||
}
|
||||
|
||||
class form_eventual_universal_visitor : public const_visitor
|
||||
{
|
||||
public:
|
||||
|
|
@ -578,7 +531,8 @@ namespace spot
|
|||
return false;
|
||||
}
|
||||
|
||||
bool infneg_form(const formula* f1, const formula* f2, int n)
|
||||
bool
|
||||
infneg_form(const formula* f1, const formula* f2, int n)
|
||||
{
|
||||
const formula* ftmp1;
|
||||
const formula* ftmp2;
|
||||
|
|
|
|||
|
|
@ -144,14 +144,15 @@ namespace spot
|
|||
return;
|
||||
}
|
||||
/* a < b => a U (b U c) = (b U c) */
|
||||
if (node_type(f2) == node_type_form_visitor::Binop
|
||||
&& dynamic_cast<binop*>(f2)->op() == binop::U
|
||||
&& inf_form(f1, dynamic_cast<binop*>(f2)->first()))
|
||||
{
|
||||
binop* bo = dynamic_cast<binop*>(f2);
|
||||
if (bo && bo->op() == binop::U && inf_form(f1, bo->first()))
|
||||
{
|
||||
result_ = f2;
|
||||
destroy(f1);
|
||||
return;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case binop::R:
|
||||
|
|
@ -170,16 +171,16 @@ namespace spot
|
|||
return;
|
||||
}
|
||||
/* b < a => a R (b R c) = b R c */
|
||||
if (node_type(f2) == node_type_form_visitor::Binop
|
||||
&& dynamic_cast<binop*>(f2)->op() == binop::R
|
||||
&& inf_form(dynamic_cast<binop*>(f2)->first(), f1))
|
||||
{
|
||||
binop* bo = dynamic_cast<binop*>(f2);
|
||||
if (bo && bo->op() == binop::R && inf_form(bo->first(), f1))
|
||||
{
|
||||
result_ = f2;
|
||||
destroy(f1);
|
||||
return;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
result_ = binop::instance(bo->op(), f1, f2);
|
||||
|
|
|
|||
|
|
@ -74,24 +74,6 @@ namespace spot
|
|||
/// FIXME: Describe what universal formulae are. Cite paper.
|
||||
bool is_universal(const formula* f);
|
||||
|
||||
/// Type the first node of a formula.
|
||||
class node_type_form_visitor : public const_visitor
|
||||
{
|
||||
public:
|
||||
enum type { Atom, Const, Unop, Binop, Multop };
|
||||
node_type_form_visitor();
|
||||
virtual ~node_type_form_visitor(){};
|
||||
type result() const;
|
||||
void visit(const atomic_prop* ap);
|
||||
void visit(const constant* c);
|
||||
void visit(const unop* uo);
|
||||
void visit(const binop* bo);
|
||||
void visit(const multop* mo);
|
||||
protected:
|
||||
type result_;
|
||||
};
|
||||
node_type_form_visitor::type node_type(const formula* f);
|
||||
|
||||
/// Whether a formula starts with GF.
|
||||
bool is_GF(const formula* f);
|
||||
/// Whether a formula starts with FG.
|
||||
|
|
|
|||
|
|
@ -44,6 +44,9 @@ for dir in "${INCDIR-..}" "${INCDIR-..}"/../iface; do
|
|||
grep '[ ]if (.*).*;' $tmp &&
|
||||
diag 'if body should be on another line.'
|
||||
|
||||
grep '[ ]else.*;' $tmp &&
|
||||
diag 'else body should be on another line.'
|
||||
|
||||
grep '[ ]while(' $tmp &&
|
||||
diag 'Missing space after "while"'
|
||||
|
||||
|
|
@ -104,6 +107,12 @@ for dir in "${INCDIR-..}" "${INCDIR-..}"/../iface; do
|
|||
grep '{.*{' $tmp &&
|
||||
diag 'No two { on the same line.'
|
||||
|
||||
grep -e 'delete[ ]*[(][^(]*[)];' $tmp &&
|
||||
diag 'No useless parentheses after delete.'
|
||||
|
||||
grep -e 'return[ ]*[(][^(]*[)];' $tmp &&
|
||||
diag 'No useless parentheses after delete.'
|
||||
|
||||
$fail && echo "$file" >>failures
|
||||
done
|
||||
done
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue