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

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);
}
......
This diff is collapsed.
......@@ -56,9 +56,9 @@ namespace spot
break;
case op::Star:
if (!bounded)
out = visit(f.nth(0)); // Strip the star.
out = visit(f[0]); // Strip the star.
else
out = formula::Star(visit(f.nth(0)),
out = formula::Star(visit(f[0]),
std::max(unsigned(f.min()), 1U), f.max());
break;
case op::Concat:
......@@ -91,7 +91,7 @@ namespace spot
std::vector<formula> v;
v.reserve(s);
for (unsigned pos = 0; pos < s; ++pos)
v.emplace_back(visit(f.nth(pos)));
v.emplace_back(visit(f[pos]));
out = formula::OrRat(v);
break;
}
......
......@@ -119,7 +119,7 @@ namespace spot
// F f = true U f
if (!re_f_)
break;
out = formula::U(formula::tt(), out.nth(0));
out = formula::U(formula::tt(), out[0]);
break;
case op::G:
// G f = false R f
......@@ -130,16 +130,16 @@ namespace spot
break;
if (!re_r_)
{
out = formula::R(formula::ff(), out.nth(0));
out = formula::R(formula::ff(), out[0]);
break;
}
if (!re_w_)
{
out = formula::W(out.nth(0), formula::ff());
out = formula::W(out[0], formula::ff());
break;
}
{
auto nc = formula::Not(out.nth(0));
auto nc = formula::Not(out[0]);
if (!re_f_)
{
out = formula::Not(formula::F(nc));
......@@ -154,8 +154,8 @@ namespace spot
if (!re_xor_)
break;
{
auto f1 = out.nth(0);
auto f2 = out.nth(1);
auto f1 = out[0];
auto f2 = out[1];
if (!re_e_)
{
out = formula::Not(formula::Equiv(f1, f2));
......@@ -172,15 +172,15 @@ namespace spot
// f1 => f2 == !f1 | f2
if (!re_i_)
break;
out = formula::Or({formula::Not(out.nth(0)), out.nth(1)});
out = formula::Or({formula::Not(out[0]), out[1]});
break;
case op::Equiv:
// f1 <=> f2 == (f1 & f2) | (!f1 & !f2)
if (!re_e_)
break;
{
auto f1 = out.nth(0);
auto f2 = out.nth(1);
auto f1 = out[0];
auto f2 = out[1];
auto nf1 = formula::Not(f1);
auto nf2 = formula::Not(f2);
auto term1 = formula::And({f1, f2});
......@@ -196,8 +196,8 @@ namespace spot
if (!re_r_)
break;
{
auto f1 = out.nth(0);
auto f2 = out.nth(1);
auto f1 = out[0];
auto f2 = out[1];
auto f12 = formula::And({f1, f2});
if (!re_w_)
{
......@@ -218,8 +218,8 @@ namespace spot
if (!re_w_)
break;
{
auto f1 = out.nth(0);
auto f2 = out.nth(1);
auto f1 = out[0];
auto f2 = out[1];
if (!re_r_)
{
out = formula::R(f2, formula::Or({f2, f1}));
......@@ -236,8 +236,8 @@ namespace spot
if (!re_m_)
break;
{
auto f2 = out.nth(1);
out = formula::U(f2, formula::And({f2, out.nth(0)}));
auto f2 = out[1];
out = formula::U(f2, formula::And({f2, out[0]}));
break;
}
}
......
......@@ -101,13 +101,13 @@ namespace spot
case op::AP:
return bdd_ithvar(d->register_proposition(f, owner));
case op::Not:
return bdd_not(recurse(f.nth(0)));
return bdd_not(recurse(f[0]));
case op::Xor:
return bdd_apply(recurse(f.nth(0)), recurse(f.nth(1)), bddop_xor);
return bdd_apply(recurse(f[0]), recurse(f[1]), bddop_xor);
case op::Implies:
return bdd_apply(recurse(f.nth(0)), recurse(f.nth(1)), bddop_imp);
return bdd_apply(recurse(f[0]), recurse(f[1]), bddop_imp);
case op::Equiv:
return bdd_apply(recurse(f.nth(0)), recurse(f.nth(1)), bddop_biimp);
return bdd_apply(recurse(f[0]), recurse(f[1]), bddop_biimp);
case op::And:
case op::Or:
{
......@@ -120,7 +120,7 @@ namespace spot
}
unsigned s = f.size();
for (unsigned n = 0; n < s; ++n)
res = bdd_apply(res, recurse(f.nth(n)), op);
res = bdd_apply(res, recurse(f[n]), op);
return res;
}
}
......
......@@ -64,7 +64,7 @@ namespace spot
unsigned mos = f.size();
for (unsigned i = 0; i < mos; ++i)
{
ltl::formula c = f.nth(i);
ltl::formula c = f[i];
if (c.is_boolean())
res.push_back(c);
else if (oblig_ && c.is_syntactic_obligation())
......@@ -91,7 +91,7 @@ namespace spot
{
// res || susp -> (res && G![susp]) || G[susp])
auto r = ltl::formula::multop(op, res);
auto gn = ltl::formula::G(ltl::formula::Not(g.nth(0)));
auto gn = ltl::formula::G(ltl::formula::Not(g[0]));
return ltl::formula::Or({ltl::formula::And({r, gn}), g});
}
}
......
......@@ -86,7 +86,7 @@ namespace spot
}
case op::X:
{
ltl2taa_visitor v = recurse(f.nth(0));
ltl2taa_visitor v = recurse(f[0]);
std::vector<formula> dst;
std::vector<formula> a;
if (v.succ_.empty()) // Handle X(0)
......@@ -104,7 +104,7 @@ namespace spot
case op::Not:
{
negated_ = true;
ltl2taa_visitor v = recurse(f.nth(0));
ltl2taa_visitor v = recurse(f[0]);
// Done in recurse
succ_ = v.succ_;
return;
......@@ -143,8 +143,8 @@ namespace spot
void
visit_binop(formula f)
{
ltl2taa_visitor v1 = recurse(f.nth(0));
ltl2taa_visitor v2 = recurse(f.nth(1));
ltl2taa_visitor v1 = recurse(f[0]);
ltl2taa_visitor v2 = recurse(f[1]);
std::vector<succ_state>::iterator i1;
std::vector<succ_state>::iterator i2;
......@@ -159,7 +159,7 @@ namespace spot
// fall thru
case op::W:
if (refined_)
contained = lcc_->contained(f.nth(0), f.nth(1));
contained = lcc_->contained(f[0], f[1]);
for (i1 = v1.succ_.begin(); i1 != v1.succ_.end(); ++i1)
{
// Refined rule
......@@ -169,11 +169,11 @@ namespace spot
i1->Q.push_back(init_); // Add the initial state
if (strong)