Get rid of all dynamic_cast<>s while working on LTL formulae.

They are too slow.

* src/ltlast/formula.hh (opkind, kind, kind_): Use an enum
to indicate the actual kind of the formula.  This way we can
check the kind of a formula without relying on dynamic_cast.
* src/ltlast/atomic_prop.cc, src/ltlast/automatop.cc,
src/ltlast/binop.cc, src/ltlast/bunop.cc, src/ltlast/constant.cc,
src/ltlast/multop.cc, src/ltlast/refformula.cc,
src/ltlast/refformula.hh, src/ltlast/unop.cc: Adjust constructors.
* src/ltlvisit/basicreduce.cc, src/ltlvisit/mark.cc,
src/ltlvisit/reduce.cc, src/ltlvisit/syntimpl.cc,
src/ltlvisit/tostring.cc: Replace all dynamic_cast by a
call to kind() followed by a static_cast.
This commit is contained in:
Alexandre Duret-Lutz 2010-12-09 13:19:44 +01:00
parent 48cde88b9b
commit 957ba664b7
15 changed files with 743 additions and 609 deletions

View file

@ -179,16 +179,17 @@ namespace spot
}
/* a < b => a U (b U c) = (b U c) */
/* a < b => a U (b W c) = (b W c) */
{
binop* bo = dynamic_cast<binop*>(f2);
if (bo && (bo->op() == binop::U || bo->op() == binop::W)
&& syntactic_implication(f1, bo->first()))
{
result_ = f2;
f1->destroy();
return;
}
}
if (f2->kind() == formula::BinOp)
{
binop* bo = static_cast<binop*>(f2);
if ((bo->op() == binop::U || bo->op() == binop::W)
&& syntactic_implication(f1, bo->first()))
{
result_ = f2;
f1->destroy();
return;
}
}
break;
case binop::R:
@ -206,30 +207,29 @@ namespace spot
f1->destroy();
return;
}
/* b < a => a R (b R c) = b R c */
/* b < a => a R (b M c) = b M c */
{
binop* bo = dynamic_cast<binop*>(f2);
if (bo && (bo->op() == binop::R || bo->op() == binop::M)
&& syntactic_implication(bo->first(), f1))
{
result_ = f2;
f1->destroy();
return;
}
}
/* a < b => a R (b R c) = a R c */
{
binop* bo = dynamic_cast<binop*>(f2);
if (bo && bo->op() == binop::R
&& syntactic_implication(f1, bo->first()))
{
result_ = binop::instance(binop::R, f1,
bo->second()->clone());
f2->destroy();
return;
}
}
if (f2->kind() == formula::BinOp)
{
/* b < a => a R (b R c) = b R c */
/* b < a => a R (b M c) = b M c */
binop* bo = static_cast<binop*>(f2);
if ((bo->op() == binop::R || bo->op() == binop::M)
&& syntactic_implication(bo->first(), f1))
{
result_ = f2;
f1->destroy();
return;
}
/* a < b => a R (b R c) = a R c */
if (bo->op() == binop::R
&& syntactic_implication(f1, bo->first()))
{
result_ = binop::instance(binop::R, f1,
bo->second()->clone());
f2->destroy();
return;
}
}
break;
case binop::W:
@ -249,16 +249,17 @@ namespace spot
return;
}
/* a < b => a W (b W c) = (b W c) */
{
binop* bo = dynamic_cast<binop*>(f2);
if (bo && bo->op() == binop::W
&& syntactic_implication(f1, bo->first()))
{
result_ = f2;
f1->destroy();
return;
}
}
if (f2->kind() == formula::BinOp)
{
binop* bo = static_cast<binop*>(f2);
if (bo->op() == binop::W
&& syntactic_implication(f1, bo->first()))
{
result_ = f2;
f1->destroy();
return;
}
}
break;
case binop::M:
@ -277,30 +278,29 @@ namespace spot
f2->destroy();
return;
}
/* b < a => a M (b M c) = b M c */
{
binop* bo = dynamic_cast<binop*>(f2);
if (bo && bo->op() == binop::M
&& syntactic_implication(bo->first(), f1))
{
result_ = f2;
f1->destroy();
return;
}
}
/* a < b => a M (b M c) = a M c */
/* a < b => a M (b R c) = a M c */
{
binop* bo = dynamic_cast<binop*>(f2);
if (bo && (bo->op() == binop::M || bo->op() == binop::R)
&& syntactic_implication(f1, bo->first()))
{
result_ = binop::instance(binop::M, f1,
bo->second()->clone());
f2->destroy();
return;
}
}
if (f2->kind() == formula::BinOp)
{
/* b < a => a M (b M c) = b M c */
binop* bo = static_cast<binop*>(f2);
if (bo->op() == binop::M
&& syntactic_implication(bo->first(), f1))
{
result_ = f2;
f1->destroy();
return;
}
/* a < b => a M (b M c) = a M c */
/* a < b => a M (b R c) = a M c */
if ((bo->op() == binop::M || bo->op() == binop::R)
&& syntactic_implication(f1, bo->first()))
{
result_ = binop::instance(binop::M, f1,
bo->second()->clone());
f2->destroy();
return;
}
}
break;
}
}