Commit 23693898 authored by Alexandre Duret-Lutz's avatar Alexandre Duret-Lutz

formula: replace nth() by operator[]()

* src/ltlast/formula.hh (formula::nth): Replace by ...
(formula::operator[]): ... this.
* src/ltlvisit/mark.cc, src/ltlvisit/mutation.cc, src/ltlvisit/print.cc,
src/ltlvisit/relabel.cc, src/ltlvisit/remove_x.cc,
src/ltlvisit/simpfg.cc, src/ltlvisit/simplify.cc, src/ltlvisit/snf.cc,
src/ltlvisit/unabbrev.cc, src/twa/formula2bdd.cc,
src/twaalgos/compsusp.cc, src/twaalgos/ltl2taa.cc,
src/twaalgos/ltl2tgba_fm.cc, wrap/python/spot_impl.i: Adjust.
parent 53326800
......@@ -1076,12 +1076,12 @@ namespace spot
{
return ptr_->end();
}
#endif
formula nth(unsigned i) const
formula operator[](unsigned i) const
{
return formula(ptr_->nth(i)->clone());
}
#endif
static formula ff()
{
......@@ -1206,7 +1206,7 @@ namespace spot
case op::Closure:
case op::NegClosure:
case op::NegClosureMarked:
return unop(o, trans(nth(0)));
return unop(o, trans((*this)[0]));
case op::Xor:
case op::Implies:
case op::Equiv:
......@@ -1218,8 +1218,8 @@ namespace spot
case op::EConcatMarked:
case op::UConcat:
{
formula tmp = trans(nth(0));
return binop(o, tmp, trans(nth(1)));
formula tmp = trans((*this)[0]);
return binop(o, tmp, trans((*this)[1]));
}
case op::Or:
case op::OrRat:
......@@ -1237,7 +1237,7 @@ namespace spot
}
case op::Star:
case op::FStar:
return bunop(o, trans(nth(0)), min(), max());
return bunop(o, trans((*this)[0]), min(), max());
}
SPOT_UNREACHABLE();
}
......
......@@ -63,10 +63,10 @@ namespace spot
res = f;
break;
case op::NegClosure:
res = ltl::formula::NegClosureMarked(f.nth(0));
res = ltl::formula::NegClosureMarked(f[0]);
break;
case op::EConcat:
res = ltl::formula::EConcatMarked(f.nth(0), f.nth(1));
res = ltl::formula::EConcatMarked(f[0], f[1]);
break;
case op::Or:
case op::And:
......@@ -138,7 +138,7 @@ namespace spot
{
if (c.is(op::EConcatMarked))
{
empairs.emplace(c.nth(0), c.nth(1));
empairs.emplace(c[0], c[1]);
v.push_back(c.map(recurse));
}
else if (c.is(op::EConcat))
......@@ -147,7 +147,7 @@ namespace spot
}
else if (c.is(op::NegClosureMarked))
{
nmset.insert(c.nth(0));
nmset.insert(c[0]);
v.push_back(c.map(recurse));
}
else if (c.is(op::NegClosure))
......@@ -162,13 +162,13 @@ namespace spot
// Keep only the non-marked EConcat for which we
// have not seen a similar EConcatMarked.
for (auto e: elist)
if (empairs.find(std::make_pair(e.nth(0), e.nth(1)))
if (empairs.find(std::make_pair(e[0], e[1]))
== empairs.end())
v.push_back(e);
// Keep only the non-marked NegClosure for which we
// have not seen a similar NegClosureMarked.
for (auto n: nlist)
if (nmset.find(n.nth(0)) == nmset.end())
if (nmset.find(n[0]) == nmset.end())
v.push_back(n);
res = ltl::formula::And(v);
}
......
......@@ -86,7 +86,7 @@ namespace spot
case op::G:
if ((opts_ & Mut_Remove_Ops)
&& mutation_counter_-- == 0)
return f.nth(0);
return f[0];
// fall through
case op::Closure:
case op::NegClosure:
......@@ -118,7 +118,7 @@ namespace spot
{
vec v1;
vec v2;
v1.push_back(f.nth(0));
v1.push_back(f[0]);
bool reverse = false;
int i = 1;
while (i < mos)
......@@ -130,10 +130,10 @@ namespace spot
reverse = true;
break;
}
v1.push_back(f.nth(i++));
v1.push_back(f[i++]);
}
for (; i < mos; ++i)
v2.push_back(f.nth(i));
v2.push_back(f[i]);
formula first = AndNLM_(v1);
formula second = AndNLM_(v2);
formula ost = formula::one_star();
......@@ -164,8 +164,8 @@ namespace spot
case op::EConcatMarked:
case op::UConcat:
{
formula first = f.nth(0);
formula second = f.nth(1);
formula first = f[0];
formula second = f[1];
op o = f.kind();
bool left_is_sere = o == op::EConcat
|| o == op::EConcatMarked
......@@ -242,7 +242,7 @@ namespace spot
case op::Star:
case op::FStar:
{
formula c = f.nth(0);
formula c = f[0];
op o = f.kind();
if (opts_ & Mut_Remove_Ops && mutation_counter_-- == 0)
return c;
......
......@@ -348,10 +348,10 @@ namespace spot
match_goto(formula mo, unsigned i)
{
assert(i + 1 < mo.size());
formula b = strip_star_not(mo.nth(i));
formula b = strip_star_not(mo[i]);
if (b == nullptr || !b.is_boolean())
return nullptr;
if (mo.nth(i + 1) == b)
if (mo[i + 1] == b)
return b;
return nullptr;
}
......@@ -482,7 +482,7 @@ namespace spot
break;
case op::Not:
{
formula c = f.nth(0);
formula c = f[0];
if (c.is(op::AP))
{
// If we negate a single letter in UTF-8, use a
......@@ -514,15 +514,15 @@ namespace spot
}
case op::X:
emit(KX);
visit(f.nth(0));
visit(f[0]);
break;
case op::F:
emit(KF);
visit(f.nth(0));
visit(f[0]);
break;
case op::G:
emit(KG);
visit(f.nth(0));
visit(f[0]);
break;
case op::NegClosure:
case op::NegClosureMarked:
......@@ -534,45 +534,45 @@ namespace spot
os_ << '{';
in_ratexp_ = true;
top_level_ = true;
visit(f.nth(0));
visit(f[0]);
os_ << '}';
in_ratexp_ = false;
top_level_ = false;
break;
case op::Xor:
visit(f.nth(0));
visit(f[0]);
emit(KXor);
visit(f.nth(1));
visit(f[1]);
break;
case op::Implies:
visit(f.nth(0));
visit(f[0]);
emit(KImplies);
visit(f.nth(1));
visit(f[1]);
break;
case op::Equiv:
visit(f.nth(0));
visit(f[0]);
emit(KEquiv);
visit(f.nth(1));
visit(f[1]);
break;
case op::U:
visit(f.nth(0));
visit(f[0]);
emit(KU);
visit(f.nth(1));
visit(f[1]);
break;
case op::R:
visit(f.nth(0));
visit(f[0]);
emit(KR);
visit(f.nth(1));
visit(f[1]);
break;
case op::W:
visit(f.nth(0));
visit(f[0]);
emit(KW);
visit(f.nth(1));
visit(f[1]);
break;
case op::M:
visit(f.nth(0));
visit(f[0]);
emit(KM);
visit(f.nth(1));
visit(f[1]);
break;
case op::EConcat:
case op::EConcatMarked:
......@@ -581,11 +581,11 @@ namespace spot
in_ratexp_ = true;
openp();
top_level_ = true;
formula left = f.nth(0);
formula right = f.nth(1);
formula left = f[0];
formula right = f[1];
unsigned last = left.size() - 1;
bool onelast = false;
if (left.is(op::Concat) && left.nth(last).is(op::True))
if (left.is(op::Concat) && left[last].is_true())
{
visit(left.all_but(last));
onelast = true;
......@@ -609,7 +609,7 @@ namespace spot
}
else if (o == op::EConcat)
{
if (f.nth(1).is(op::True))
if (f[1].is(op::True))
{
os_ << '!';
// No recursion on right.
......@@ -633,7 +633,7 @@ namespace spot
case op::AndNLM:
case op::Fusion:
{
visit(f.nth(0));
visit(f[0]);
keyword k = KFalse; // Initialize to something to please GCC.
switch (o)
{
......@@ -664,7 +664,7 @@ namespace spot
for (unsigned n = 1; n < max; ++n)
{
emit(k);
visit(f.nth(n));
visit(f[n]);
}
break;
}
......@@ -686,7 +686,7 @@ namespace spot
// Wait... maybe we are looking at (!b)[*];b;(!b)[*]
// in which case it's b[=1].
if (i + 2 < max && f.nth(i) == f.nth(i + 2))
if (i + 2 < max && f[i] == f[i + 2])
{
emit(KEqualBunop);
os_ << '1';
......@@ -702,12 +702,12 @@ namespace spot
continue;
}
// Try to match ((!b)[*];b)[*i..j];(!b)[*]
formula fi = f.nth(i);
formula fi = f[i];
if (fi.is(op::Star))
{
if (formula b2 = strip_star_not(f.nth(i + 1)))
if (formula b2 = strip_star_not(f[i + 1]))
{
formula fic = fi.nth(0);
formula fic = fi[0];
if (fic.is(op::Concat))
if (formula b1 = match_goto(fic, 0))
if (b1 == b2)
......@@ -730,14 +730,14 @@ namespace spot
}
}
}
visit(f.nth(i));
visit(f[i]);
}
break;
}
case op::Star:
case op::FStar:
{
formula c = f.nth(0);
formula c = f[0];
enum { Star, FStar, Goto } sugar = Star;
unsigned default_min = 0;
unsigned default_max = formula::unbounded();
......
......@@ -280,24 +280,24 @@ namespace spot
visit(b);
}
for (; i < sz; ++i)
visit(f.nth(i));
visit(f[i]);
if (sz > 1 && f.is_boolean())
{
// For Boolean nodes, connect all children in a
// loop. This way the node can only be a cut-point
// if it separates all children from the reset of
// the graph (not only one).
formula pred = f.nth(0);
formula pred = f[0];
for (i = 1; i < sz; ++i)
{
formula next = f.nth(i);
formula next = f[i];
// Note that we only add an edge in one
// direction, because we are building a cycle
// between all children anyway.
g[pred].push_back(next);
pred = next;
}
g[pred].push_back(f.nth(0));
g[pred].push_back(f[0]);
}
s.pop();
}
......@@ -446,7 +446,7 @@ namespace spot
res.reserve(sz);
}
for (; i < sz; ++i)
res.push_back(visit(f.nth(i)));
res.push_back(visit(f[i]));
return formula::multop(f.kind(), res);
}
};
......
......@@ -41,7 +41,7 @@ namespace spot
if (!f.is(op::X))
return f.map(rec);
formula c = rec(f.nth(0));
formula c = rec(f[0]);
std::vector<formula> vo;
for (auto i: aps)
......
......@@ -29,17 +29,17 @@ namespace spot
formula simplify_f_g(formula p)
{
// 1 U p = Fp
if (p.is(op::U) && p.nth(0).is_true())
return formula::F(p.nth(1));
if (p.is(op::U) && p[0].is_true())
return formula::F(p[1]);
// 0 R p = Gp
if (p.is(op::R) && p.nth(0).is_false())
return formula::G(p.nth(1));
if (p.is(op::R) && p[0].is_false())
return formula::G(p[1]);
// p W 0 = Gp
if (p.is(op::W) && p.nth(1).is_false())
return formula::G(p.nth(0));
if (p.is(op::W) && p[1].is_false())
return formula::G(p[0]);
// p M 1 = Fp
if (p.is(op::M) && p.nth(1).is_true())
return formula::F(p.nth(0));
if (p.is(op::M) && p[1].is_true())
return formula::F(p[0]);
return p.map(simplify_f_g);
}
......
......@@ -110,16 +110,16 @@ namespace spot
result = bdd_ithvar(dict->register_proposition(f, this));
break;
case op::Not:
result = !as_bdd(f.nth(0));
result = !as_bdd(f[0]);
break;
case op::Xor:
result = bdd_apply(as_bdd(f.nth(0)), as_bdd(f.nth(1)), bddop_xor);
result = bdd_apply(as_bdd(f[0]), as_bdd(f[1]), bddop_xor);
break;
case op::Implies:
result = bdd_apply(as_bdd(f.nth(0)), as_bdd(f.nth(1)), bddop_imp);
result = bdd_apply(as_bdd(f[0]), as_bdd(f[1]), bddop_imp);
break;
case op::Equiv:
result = bdd_apply(as_bdd(f.nth(0)), as_bdd(f.nth(1)), bddop_biimp);
result = bdd_apply(as_bdd(f[0]), as_bdd(f[1]), bddop_biimp);
break;
case op::And:
{
......@@ -361,7 +361,7 @@ namespace spot
if (f.is(op::Not))
{
negated = !negated;
f = f.nth(0);
f = f[0];
}
formula key = f;
......@@ -398,83 +398,83 @@ namespace spot
break;
case op::X:
// !Xa == X!a
result = formula::X(rec(f.nth(0), negated));
result = formula::X(rec(f[0], negated));
break;
case op::F:
// !Fa == G!a
result = formula::unop(negated ? op::G : op::F,
rec(f.nth(0), negated));
rec(f[0], negated));
break;
case op::G:
// !Ga == F!a
result = formula::unop(negated ? op::F : op::G,
rec(f.nth(0), negated));
rec(f[0], negated));
break;
case op::Closure:
result = formula::unop(negated ?
op::NegClosure : op::Closure,
rec(f.nth(0), false));
rec(f[0], false));
break;
case op::NegClosure:
case op::NegClosureMarked:
result = formula::unop(negated ? op::Closure : o,
rec(f.nth(0), false));
rec(f[0], false));
break;
case op::Implies:
if (negated)
// !(a => b) == a & !b
{
auto f2 = rec(f.nth(1), true);
result = formula::And({rec(f.nth(0), false), f2});
auto f2 = rec(f[1], true);
result = formula::And({rec(f[0], false), f2});
}
else // a => b == !a | b
{
auto f2 = rec(f.nth(1), false);
result = formula::Or({rec(f.nth(0), true), f2});
auto f2 = rec(f[1], false);
result = formula::Or({rec(f[0], true), f2});
}
break;
case op::Xor:
{
// !(a ^ b) == a <=> b
result = equiv_or_xor(negated, f.nth(0), f.nth(1), c);
result = equiv_or_xor(negated, f[0], f[1], c);
break;
}
case op::Equiv:
{
// !(a <=> b) == a ^ b
result = equiv_or_xor(!negated, f.nth(0), f.nth(1), c);
result = equiv_or_xor(!negated, f[0], f[1], c);
break;
}
case op::U:
{
// !(a U b) == !a R !b
auto f1 = rec(f.nth(0), negated);
auto f2 = rec(f.nth(1), negated);
auto f1 = rec(f[0], negated);
auto f2 = rec(f[1], negated);
result = formula::binop(negated ? op::R : op::U, f1, f2);
break;
}
case op::R:
{
// !(a R b) == !a U !b
auto f1 = rec(f.nth(0), negated);
auto f2 = rec(f.nth(1), negated);
auto f1 = rec(f[0], negated);
auto f2 = rec(f[1], negated);
result = formula::binop(negated ? op::U : op::R, f1, f2);
break;
}
case op::W:
{
// !(a W b) == !a M !b
auto f1 = rec(f.nth(0), negated);
auto f2 = rec(f.nth(1), negated);
auto f1 = rec(f[0], negated);
auto f2 = rec(f[1], negated);
result = formula::binop(negated ? op::M : op::W, f1, f2);
break;
}
case op::M:
{
// !(a M b) == !a W !b
auto f1 = rec(f.nth(0), negated);
auto f2 = rec(f.nth(1), negated);
auto f1 = rec(f[0], negated);
auto f2 = rec(f[1], negated);
result = formula::binop(negated ? op::W : op::M, f1, f2);
break;
}
......@@ -484,7 +484,7 @@ namespace spot
unsigned mos = f.size();
vec v;
for (unsigned i = 0; i < mos; ++i)
v.push_back(rec(f.nth(i), negated));
v.push_back(rec(f[i], negated));
op on = o;
if (negated)
on = o == op::Or ? op::And : op::Or;
......@@ -511,8 +511,8 @@ namespace spot
case op::EConcatMarked:
{
// !(a <>-> b) == a[]-> !b
auto f1 = f.nth(0);
auto f2 = f.nth(1);
auto f1 = f[0];
auto f2 = f[1];
result = formula::binop(negated ? op::UConcat : o,
rec(f1, false), rec(f2, negated));
break;
......@@ -520,8 +520,8 @@ namespace spot
case op::UConcat:
{
// !(a []-> b) == a<>-> !b
auto f1 = f.nth(0);
auto f2 = f.nth(1);
auto f1 = f[0];
auto f2 = f[1];
result = formula::binop(negated ? op::EConcat : op::UConcat,
rec(f1, false), rec(f2, negated));
break;
......@@ -553,10 +553,10 @@ namespace spot
{
if (!f.is(op::R, op::M))
return nullptr;
auto left = f.nth(0);
auto left = f[0];
if (!left.is(op::X))
return nullptr;
return left.nth(0);
return left[0];
}
// X(a) W b or X(a) U b
......@@ -566,10 +566,10 @@ namespace spot
{
if (!f.is(op::W, op::U))
return nullptr;
auto left = f.nth(0);
auto left = f[0];
if (!left.is(op::X))
return nullptr;
return left.nth(0);
return left[0];
}
// b & X(b W a) or b & X(b U a)
......@@ -582,14 +582,14 @@ namespace spot
unsigned s = f.size();
for (unsigned pos = 0; pos < s; ++pos)
{
auto p = f.nth(pos);
auto p = f[pos];
if (!(p.is(op::X)))
continue;
auto c = p.nth(0);
auto c = p[0];
if (!c.is(op::U, op::W))
continue;
formula b = f.all_but(pos);