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:
parent
48cde88b9b
commit
957ba664b7
15 changed files with 743 additions and 609 deletions
File diff suppressed because it is too large
Load diff
|
|
@ -221,13 +221,13 @@ namespace spot
|
|||
{
|
||||
formula* f = mo->nth(i);
|
||||
|
||||
binop* bo = dynamic_cast<binop*>(f);
|
||||
if (!bo)
|
||||
if (f->kind() != formula::BinOp)
|
||||
{
|
||||
res->push_back(recurse(f));
|
||||
}
|
||||
else
|
||||
{
|
||||
binop* bo = static_cast<binop*>(f);
|
||||
switch (bo->op())
|
||||
{
|
||||
case binop::Xor:
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -96,8 +96,10 @@ namespace spot
|
|||
return;
|
||||
case unop::X:
|
||||
{
|
||||
const unop* op = dynamic_cast<const unop*>(f);
|
||||
if (op && op->op() == unop::X)
|
||||
if (f->kind() != formula::UnOp)
|
||||
return;
|
||||
const unop* op = static_cast<const unop*>(f);
|
||||
if (op->op() == unop::X)
|
||||
result_ = syntactic_implication(op->child(), f1);
|
||||
}
|
||||
return;
|
||||
|
|
@ -124,8 +126,6 @@ namespace spot
|
|||
{
|
||||
const formula* f1 = bo->first();
|
||||
const formula* f2 = bo->second();
|
||||
const binop* fb = dynamic_cast<const binop*>(f);
|
||||
const unop* fu = dynamic_cast<const unop*>(f);
|
||||
switch (bo->op())
|
||||
{
|
||||
case binop::Xor:
|
||||
|
|
@ -141,39 +141,55 @@ namespace spot
|
|||
result_ = true;
|
||||
return;
|
||||
case binop::R:
|
||||
if (fb && fb->op() == binop::R)
|
||||
if (syntactic_implication(fb->first(), f1) &&
|
||||
syntactic_implication(fb->second(), f2))
|
||||
{
|
||||
result_ = true;
|
||||
return;
|
||||
}
|
||||
if (fu && fu->op() == unop::G)
|
||||
if (f1 == constant::false_instance() &&
|
||||
syntactic_implication(fu->child(), f2))
|
||||
{
|
||||
result_ = true;
|
||||
return;
|
||||
}
|
||||
if (f->kind() == formula::BinOp)
|
||||
{
|
||||
const binop* fb = static_cast<const binop*>(f);
|
||||
if (fb->op() == binop::R
|
||||
&& syntactic_implication(fb->first(), f1)
|
||||
&& syntactic_implication(fb->second(), f2))
|
||||
{
|
||||
result_ = true;
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (f->kind() == formula::UnOp)
|
||||
{
|
||||
const unop* fu = static_cast<const unop*>(f);
|
||||
if (fu->op() == unop::G
|
||||
&& f1 == constant::false_instance()
|
||||
&& syntactic_implication(fu->child(), f2))
|
||||
{
|
||||
result_ = true;
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (syntactic_implication(f, f1)
|
||||
&& syntactic_implication(f, f2))
|
||||
result_ = true;
|
||||
return;
|
||||
case binop::M:
|
||||
if (fb && fb->op() == binop::M)
|
||||
if (syntactic_implication(fb->first(), f1) &&
|
||||
syntactic_implication(fb->second(), f2))
|
||||
{
|
||||
result_ = true;
|
||||
return;
|
||||
}
|
||||
if (fu && fu->op() == unop::F)
|
||||
if (f2 == constant::true_instance() &&
|
||||
syntactic_implication(fu->child(), f1))
|
||||
if (f->kind() == formula::BinOp)
|
||||
{
|
||||
const binop* fb = static_cast<const binop*>(f);
|
||||
if (fb->op() == binop::M
|
||||
&& syntactic_implication(fb->first(), f1)
|
||||
&& syntactic_implication(fb->second(), f2))
|
||||
{
|
||||
result_ = true;
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (f->kind() == formula::UnOp)
|
||||
{
|
||||
const unop* fu = static_cast<const unop*>(f);
|
||||
if (fu->op() == unop::F
|
||||
&& f2 == constant::true_instance()
|
||||
&& syntactic_implication(fu->child(), f1))
|
||||
{
|
||||
result_ = true;
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (syntactic_implication(f, f1)
|
||||
&& syntactic_implication(f, f2))
|
||||
result_ = true;
|
||||
|
|
@ -238,8 +254,10 @@ namespace spot
|
|||
bool
|
||||
special_case(const binop* f2)
|
||||
{
|
||||
const binop* fb = dynamic_cast<const binop*>(f);
|
||||
if (fb && fb->op() == f2->op()
|
||||
if (f->kind() != formula::BinOp)
|
||||
return false;
|
||||
const binop* fb = static_cast<const binop*>(f);
|
||||
if (fb->op() == f2->op()
|
||||
&& syntactic_implication(f2->first(), fb->first())
|
||||
&& syntactic_implication(f2->second(), fb->second()))
|
||||
return true;
|
||||
|
|
@ -249,10 +267,9 @@ namespace spot
|
|||
bool
|
||||
special_case_check(const formula* f2)
|
||||
{
|
||||
const binop* f2b = dynamic_cast<const binop*>(f2);
|
||||
if (!f2b)
|
||||
if (f2->kind() != formula::BinOp)
|
||||
return false;
|
||||
return special_case(f2b);
|
||||
return special_case(static_cast<const binop*>(f2));
|
||||
}
|
||||
|
||||
int
|
||||
|
|
@ -307,11 +324,12 @@ namespace spot
|
|||
result_ = true;
|
||||
return;
|
||||
case unop::X:
|
||||
{
|
||||
const unop* op = dynamic_cast<const unop*>(f);
|
||||
if (op && op->op() == unop::X)
|
||||
result_ = syntactic_implication(f1, op->child());
|
||||
}
|
||||
if (f->kind() == formula::UnOp)
|
||||
{
|
||||
const unop* op = static_cast<const unop*>(f);
|
||||
if (op->op() == unop::X)
|
||||
result_ = syntactic_implication(f1, op->child());
|
||||
}
|
||||
return;
|
||||
case unop::F:
|
||||
{
|
||||
|
|
@ -367,8 +385,6 @@ namespace spot
|
|||
|
||||
const formula* f1 = bo->first();
|
||||
const formula* f2 = bo->second();
|
||||
const binop* fb = dynamic_cast<const binop*>(f);
|
||||
const unop* fu = dynamic_cast<const unop*>(f);
|
||||
switch (bo->op())
|
||||
{
|
||||
case binop::Xor:
|
||||
|
|
@ -380,63 +396,87 @@ namespace spot
|
|||
return;
|
||||
case binop::U:
|
||||
/* (a < c) && (c < d) => a U b < c U d */
|
||||
if (fb && fb->op() == binop::U)
|
||||
if (syntactic_implication(f1, fb->first()) &&
|
||||
syntactic_implication(f2, fb->second()))
|
||||
{
|
||||
result_ = true;
|
||||
return;
|
||||
}
|
||||
if (fu && fu->op() == unop::F)
|
||||
if (f1 == constant::true_instance() &&
|
||||
syntactic_implication(f2, fu->child()))
|
||||
{
|
||||
result_ = true;
|
||||
return;
|
||||
}
|
||||
if (f->kind() == formula::BinOp)
|
||||
{
|
||||
const binop* fb = static_cast<const binop*>(f);
|
||||
if (fb->op() == binop::U
|
||||
&& syntactic_implication(f1, fb->first())
|
||||
&& syntactic_implication(f2, fb->second()))
|
||||
{
|
||||
result_ = true;
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (f->kind() == formula::UnOp)
|
||||
{
|
||||
const unop* fu = static_cast<const unop*>(f);
|
||||
if (fu->op() == unop::F
|
||||
&& f1 == constant::true_instance()
|
||||
&& syntactic_implication(f2, fu->child()))
|
||||
{
|
||||
result_ = true;
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (syntactic_implication(f1, f)
|
||||
&& syntactic_implication(f2, f))
|
||||
result_ = true;
|
||||
return;
|
||||
case binop::W:
|
||||
/* (a < c) && (c < d) => a W b < c W d */
|
||||
if (fb && fb->op() == binop::W)
|
||||
if (syntactic_implication(f1, fb->first()) &&
|
||||
syntactic_implication(f2, fb->second()))
|
||||
{
|
||||
result_ = true;
|
||||
return;
|
||||
}
|
||||
if (fu && fu->op() == unop::G)
|
||||
if (f2 == constant::false_instance() &&
|
||||
syntactic_implication(f1, fu->child()))
|
||||
{
|
||||
result_ = true;
|
||||
return;
|
||||
}
|
||||
if (f->kind() == formula::BinOp)
|
||||
{
|
||||
const binop* fb = static_cast<const binop*>(f);
|
||||
if (fb->op() == binop::W
|
||||
&& syntactic_implication(f1, fb->first())
|
||||
&& syntactic_implication(f2, fb->second()))
|
||||
{
|
||||
result_ = true;
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (f->kind() == formula::UnOp)
|
||||
{
|
||||
const unop* fu = static_cast<const unop*>(f);
|
||||
if (fu && fu->op() == unop::G
|
||||
&& f2 == constant::false_instance()
|
||||
&& syntactic_implication(f1, fu->child()))
|
||||
{
|
||||
result_ = true;
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (syntactic_implication(f1, f)
|
||||
&& syntactic_implication(f2, f))
|
||||
result_ = true;
|
||||
return;
|
||||
case binop::R:
|
||||
if (fu && fu->op() == unop::G)
|
||||
if (f1 == constant::false_instance() &&
|
||||
syntactic_implication(f2, fu->child()))
|
||||
if (f->kind() == formula::UnOp)
|
||||
{
|
||||
const unop* fu = static_cast<const unop*>(f);
|
||||
if (fu->op() == unop::G
|
||||
&& f1 == constant::false_instance()
|
||||
&& syntactic_implication(f2, fu->child()))
|
||||
{
|
||||
result_ = true;
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (syntactic_implication(f2, f))
|
||||
result_ = true;
|
||||
return;
|
||||
case binop::M:
|
||||
if (fu && fu->op() == unop::F)
|
||||
if (f2 == constant::true_instance() &&
|
||||
syntactic_implication(f1, fu->child()))
|
||||
if (f->kind() == formula::UnOp)
|
||||
{
|
||||
const unop* fu = static_cast<const unop*>(f);
|
||||
if (fu->op() == unop::F
|
||||
&& f2 == constant::true_instance()
|
||||
&& syntactic_implication(f1, fu->child()))
|
||||
{
|
||||
result_ = true;
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (syntactic_implication(f2, f))
|
||||
result_ = true;
|
||||
return;
|
||||
|
|
|
|||
|
|
@ -188,7 +188,7 @@ namespace spot
|
|||
// a[*] is OK, no need to print {a}[*].
|
||||
// However want braces for {!a}[*], the only unary
|
||||
// operator that can be nested with [*].
|
||||
bool need_parent = !!dynamic_cast<const unop*>(bo->child());
|
||||
bool need_parent = (bo->child()->kind() == formula::UnOp);
|
||||
|
||||
if (need_parent || full_parent_)
|
||||
openp();
|
||||
|
|
@ -206,7 +206,7 @@ namespace spot
|
|||
top_level_ = false;
|
||||
// The parser treats F0, F1, G0, G1, X0, and X1 as atomic
|
||||
// propositions. So make sure we output F(0), G(1), etc.
|
||||
bool need_parent = !!dynamic_cast<const constant*>(uo->child());
|
||||
bool need_parent = (uo->child()->kind() == formula::Constant);
|
||||
bool top_level = top_level_;
|
||||
|
||||
if (full_parent_)
|
||||
|
|
@ -456,7 +456,7 @@ namespace spot
|
|||
case unop::X:
|
||||
// The parser treats X0, and X1 as atomic
|
||||
// propositions. So make sure we output X(0) and X(1).
|
||||
need_parent = !!dynamic_cast<const constant*>(uo->child());
|
||||
need_parent = (uo->child()->kind() == formula::Constant);
|
||||
if (full_parent_)
|
||||
need_parent = false;
|
||||
os_ << "X";
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue