* 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:
Alexandre Duret-Lutz 2004-05-26 12:48:22 +00:00
parent d973c1dad0
commit cdbb199c4d
6 changed files with 120 additions and 180 deletions

View file

@ -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> 2004-05-25 Alexandre Duret-Lutz <adl@src.lip6.fr>
* src/ltlvisit/formlength.cc: Rename as ... * src/ltlvisit/formlength.cc: Rename as ...

View file

@ -81,7 +81,7 @@ namespace spot
case unop::X: case unop::X:
// X(true) = true // X(true) = true
// X(false) = false // X(false) = false
if (node_type(result_) == (node_type_form_visitor::Const)) if (dynamic_cast<constant*>(result_))
return; return;
// XGF(f) = GF(f) // XGF(f) = GF(f)
@ -123,10 +123,9 @@ namespace spot
return; return;
case unop::F: case unop::F:
// F(true) = true // F(true) = true
// F(false) = false // F(false) = false
if (node_type(result_) == (node_type_form_visitor::Const)) if (dynamic_cast<constant*>(result_))
return; return;
// FX(a) = XF(a) // FX(a) = XF(a)
@ -177,10 +176,9 @@ namespace spot
return; return;
case unop::G: case unop::G:
// G(true) = true // G(true) = true
// G(false) = false // G(false) = false
if (node_type(result_) == (node_type_form_visitor::Const)) if (dynamic_cast<constant*>(result_))
return; return;
// G(a R b) = G(b) // G(a R b) = G(b)
@ -249,8 +247,6 @@ namespace spot
formula* f1 = bo->first(); formula* f1 = bo->first();
formula* f2 = bo->second(); formula* f2 = bo->second();
formula* ftmp = NULL; formula* ftmp = NULL;
node_type_form_visitor v1;
node_type_form_visitor v2;
unop* fu1 = NULL; unop* fu1 = NULL;
unop* fu2 = NULL; unop* fu2 = NULL;
switch (bo->op()) switch (bo->op())
@ -275,7 +271,7 @@ namespace spot
// a U false = false // a U false = false
// a U true = true // a U true = true
if (node_type(f2) == (node_type_form_visitor::Const)) if (dynamic_cast<constant*>(f2))
{ {
result_ = f2; result_ = f2;
return; return;
@ -308,7 +304,7 @@ namespace spot
// a R false = false // a R false = false
// a R true = true // a R true = true
if (node_type(f2) == (node_type_form_visitor::Const)) if (dynamic_cast<constant*>(f2))
{ {
result_ = f2; result_ = f2;
return; return;
@ -358,9 +354,6 @@ namespace spot
multop::vec* tmpOther = new multop::vec; multop::vec* tmpOther = new multop::vec;
unop* uo = NULL;
unop* uo2 = NULL;
binop* bo = NULL;
formula* ftmp = NULL; formula* ftmp = NULL;
for (unsigned i = 0; i < mos; ++i) for (unsigned i = 0; i < mos; ++i)
@ -375,47 +368,43 @@ namespace spot
{ {
if (*i == NULL) if (*i == NULL)
continue; 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) if (uo && uo->op() == unop::X)
{ {
// Xa & Xb = X(a & b)
tmpX->push_back(basic_reduce_form(uo->child())); tmpX->push_back(basic_reduce_form(uo->child()));
break;
} }
else if (is_FG(*i))
{
// FG(a) & FG(b) = FG(a & b) // FG(a) & FG(b) = FG(a & b)
if (is_FG(*i)) unop* uo2 = dynamic_cast<unop*>(uo->child());
{
uo2 = dynamic_cast<unop*>(uo->child());
tmpFG->push_back(basic_reduce_form(uo2->child())); tmpFG->push_back(basic_reduce_form(uo2->child()));
break;
} }
tmpOther->push_back(basic_reduce_form(*i)); else
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)
{ {
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(); ftmp = dynamic_cast<binop*>(*i)->second();
tmpUright = new multop::vec; tmpUright = new multop::vec;
for (multop::vec::iterator j = i; j != res->end(); j++) for (multop::vec::iterator j = i; j != res->end(); j++)
{ {
if (!*j) if (!*j)
continue; continue;
if (node_type(*j) == node_type_form_visitor::Binop binop* bo2 = dynamic_cast<binop*>(*j);
&& dynamic_cast<binop*>(*j)->op() == binop::U if (bo2 && bo2->op() == binop::U
&& ftmp == dynamic_cast<binop*>(*j)->second()) && ftmp == bo2->second())
{ {
bo = dynamic_cast<binop*>(*j);
tmpUright tmpUright
->push_back(basic_reduce_form(bo->first())); ->push_back(basic_reduce_form(bo2->first()));
if (j != i) if (j != i)
{ {
destroy(*j); destroy(*j);
@ -430,25 +419,22 @@ namespace spot
And, And,
tmpUright), tmpUright),
basic_reduce_form(ftmp))); basic_reduce_form(ftmp)));
break;
} }
else if (bo->op() == binop::R)
// (a R b) & (a R c) = a R (b & c)
if (dynamic_cast<binop*>(*i)->op() == binop::R)
{ {
// (a R b) & (a R c) = a R (b & c)
ftmp = dynamic_cast<binop*>(*i)->first(); ftmp = dynamic_cast<binop*>(*i)->first();
tmpRright = new multop::vec; tmpRright = new multop::vec;
for (multop::vec::iterator j = i; j != res->end(); j++) for (multop::vec::iterator j = i; j != res->end(); j++)
{ {
if (!*j) if (!*j)
continue; continue;
if (node_type(*j) == node_type_form_visitor::Binop binop* bo2 = dynamic_cast<binop*>(*j);
&& dynamic_cast<binop*>(*j)->op() == binop::R if (bo2 && bo2->op() == binop::R
&& ftmp == dynamic_cast<binop*>(*j)->first()) && ftmp == bo2->first())
{ {
bo = dynamic_cast<binop*>(*j);
tmpRright tmpRright
->push_back(basic_reduce_form(bo->second())); ->push_back(basic_reduce_form(bo2->second()));
if (j != i) if (j != i)
{ {
destroy(*j); destroy(*j);
@ -462,19 +448,21 @@ namespace spot
multop:: multop::
instance(multop::And, instance(multop::And,
tmpRright))); tmpRright)));
break;
} }
else
{
tmpOther->push_back(basic_reduce_form(*i)); tmpOther->push_back(basic_reduce_form(*i));
break; }
default: }
else
{
tmpOther->push_back(basic_reduce_form(*i)); tmpOther->push_back(basic_reduce_form(*i));
break;
} }
destroy(*i); destroy(*i);
} }
delete(tmpGF); delete tmpGF;
tmpGF = NULL; tmpGF = 0;
break; break;
@ -484,47 +472,43 @@ namespace spot
{ {
if (!*i) if (!*i)
continue; 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) if (uo && uo->op() == unop::X)
{ {
// Xa | Xb = X(a | b)
tmpX->push_back(basic_reduce_form(uo->child())); tmpX->push_back(basic_reduce_form(uo->child()));
break;
} }
else if (is_GF(*i))
{
// GF(a) | GF(b) = GF(a | b) // GF(a) | GF(b) = GF(a | b)
if (is_GF(*i)) unop* uo2 = dynamic_cast<unop*>(uo->child());
{
uo2 = dynamic_cast<unop*>(uo->child());
tmpGF->push_back(basic_reduce_form(uo2->child())); tmpGF->push_back(basic_reduce_form(uo2->child()));
break;
} }
tmpOther->push_back(basic_reduce_form(*i)); else
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)
{ {
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; tmpUright = new multop::vec;
for (multop::vec::iterator j = i; j != res->end(); j++) for (multop::vec::iterator j = i; j != res->end(); j++)
{ {
if (!*j) if (!*j)
continue; continue;
if (node_type(*j) == node_type_form_visitor::Binop binop* bo2 = dynamic_cast<binop*>(*j);
&& dynamic_cast<binop*>(*j)->op() == binop::U if (bo2 && bo2->op() == binop::U
&& ftmp == dynamic_cast<binop*>(*j)->first()) && ftmp == bo2->first())
{ {
bo = dynamic_cast<binop*>(*j);
tmpUright tmpUright
->push_back(basic_reduce_form(bo->second())); ->push_back(basic_reduce_form(bo2->second()));
if (j != i) if (j != i)
{ {
destroy(*j); destroy(*j);
@ -537,23 +521,20 @@ namespace spot
multop:: multop::
instance(multop::Or, instance(multop::Or,
tmpUright))); tmpUright)));
break;
} }
else if (bo->op() == binop::R)
// (a R b) | (c R b) = (a | c) R b
if (dynamic_cast<binop*>(*i)->op() == binop::R)
{ {
// (a R b) | (c R b) = (a | c) R b
ftmp = dynamic_cast<binop*>(*i)->second(); ftmp = dynamic_cast<binop*>(*i)->second();
tmpRright = new multop::vec; tmpRright = new multop::vec;
for (multop::vec::iterator j = i; j != res->end(); j++) for (multop::vec::iterator j = i; j != res->end(); j++)
{ {
if (!*j) if (!*j)
continue; continue;
if (node_type(*j) == node_type_form_visitor::Binop binop* bo2 = dynamic_cast<binop*>(*j);
&& dynamic_cast<binop*>(*j)->op() == binop::R if (bo2 && bo2->op() == binop::R
&& ftmp == dynamic_cast<binop*>(*j)->second()) && ftmp == bo2->second())
{ {
bo = dynamic_cast<binop*>(*j);
tmpRright tmpRright
->push_back(basic_reduce_form(bo->first())); ->push_back(basic_reduce_form(bo->first()));
if (j != i) if (j != i)
@ -569,40 +550,44 @@ namespace spot
instance(multop::Or, instance(multop::Or,
tmpRright), tmpRright),
basic_reduce_form(ftmp))); basic_reduce_form(ftmp)));
break;
} }
else
{
tmpOther->push_back(basic_reduce_form(*i)); tmpOther->push_back(basic_reduce_form(*i));
break; }
default: }
else
{
tmpOther->push_back(basic_reduce_form(*i)); tmpOther->push_back(basic_reduce_form(*i));
break;
} }
destroy(*i); destroy(*i);
} }
delete(tmpFG); delete tmpFG;
tmpFG = NULL; tmpFG = 0;
break; break;
} }
res->clear(); res->clear();
delete(res); delete res;
if (tmpX->size()) if (tmpX->size())
tmpOther->push_back(unop::instance(unop::X, tmpOther->push_back(unop::instance(unop::X,
multop::instance(mo->op(), multop::instance(mo->op(),
tmpX))); tmpX)));
else delete(tmpX); else
delete tmpX;
if (tmpU->size()) if (tmpU->size())
tmpOther->push_back(multop::instance(mo->op(), tmpU)); tmpOther->push_back(multop::instance(mo->op(), tmpU));
else delete(tmpU); else
delete tmpU;
if (tmpR->size()) if (tmpR->size())
tmpOther->push_back(multop::instance(mo->op(), tmpR)); tmpOther->push_back(multop::instance(mo->op(), tmpR));
else delete(tmpR); else
delete tmpR;
if ((tmpGF != NULL) && if ((tmpGF != NULL) &&
(tmpGF->size())) (tmpGF->size()))

View file

@ -58,53 +58,6 @@ namespace spot
return false; 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 class form_eventual_universal_visitor : public const_visitor
{ {
public: public:
@ -578,7 +531,8 @@ namespace spot
return false; 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* ftmp1;
const formula* ftmp2; const formula* ftmp2;

View file

@ -144,14 +144,15 @@ namespace spot
return; return;
} }
/* a < b => a U (b U c) = (b U c) */ /* 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 binop* bo = dynamic_cast<binop*>(f2);
&& inf_form(f1, dynamic_cast<binop*>(f2)->first())) if (bo && bo->op() == binop::U && inf_form(f1, bo->first()))
{ {
result_ = f2; result_ = f2;
destroy(f1); destroy(f1);
return; return;
} }
}
break; break;
case binop::R: case binop::R:
@ -170,16 +171,16 @@ namespace spot
return; return;
} }
/* b < a => a R (b R c) = b R c */ /* 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 binop* bo = dynamic_cast<binop*>(f2);
&& inf_form(dynamic_cast<binop*>(f2)->first(), f1)) if (bo && bo->op() == binop::R && inf_form(bo->first(), f1))
{ {
result_ = f2; result_ = f2;
destroy(f1); destroy(f1);
return; return;
} }
}
break; break;
} }
} }
result_ = binop::instance(bo->op(), f1, f2); result_ = binop::instance(bo->op(), f1, f2);

View file

@ -74,24 +74,6 @@ namespace spot
/// FIXME: Describe what universal formulae are. Cite paper. /// FIXME: Describe what universal formulae are. Cite paper.
bool is_universal(const formula* f); 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. /// Whether a formula starts with GF.
bool is_GF(const formula* f); bool is_GF(const formula* f);
/// Whether a formula starts with FG. /// Whether a formula starts with FG.

View file

@ -44,6 +44,9 @@ for dir in "${INCDIR-..}" "${INCDIR-..}"/../iface; do
grep '[ ]if (.*).*;' $tmp && grep '[ ]if (.*).*;' $tmp &&
diag 'if body should be on another line.' diag 'if body should be on another line.'
grep '[ ]else.*;' $tmp &&
diag 'else body should be on another line.'
grep '[ ]while(' $tmp && grep '[ ]while(' $tmp &&
diag 'Missing space after "while"' diag 'Missing space after "while"'
@ -104,6 +107,12 @@ for dir in "${INCDIR-..}" "${INCDIR-..}"/../iface; do
grep '{.*{' $tmp && grep '{.*{' $tmp &&
diag 'No two { on the same line.' 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 $fail && echo "$file" >>failures
done done
done done