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 ...@@ -1076,12 +1076,12 @@ namespace spot
{ {
return ptr_->end(); return ptr_->end();
} }
#endif
formula nth(unsigned i) const formula operator[](unsigned i) const
{ {
return formula(ptr_->nth(i)->clone()); return formula(ptr_->nth(i)->clone());
} }
#endif
static formula ff() static formula ff()
{ {
...@@ -1206,7 +1206,7 @@ namespace spot ...@@ -1206,7 +1206,7 @@ namespace spot
case op::Closure: case op::Closure:
case op::NegClosure: case op::NegClosure:
case op::NegClosureMarked: case op::NegClosureMarked:
return unop(o, trans(nth(0))); return unop(o, trans((*this)[0]));
case op::Xor: case op::Xor:
case op::Implies: case op::Implies:
case op::Equiv: case op::Equiv:
...@@ -1218,8 +1218,8 @@ namespace spot ...@@ -1218,8 +1218,8 @@ namespace spot
case op::EConcatMarked: case op::EConcatMarked:
case op::UConcat: case op::UConcat:
{ {
formula tmp = trans(nth(0)); formula tmp = trans((*this)[0]);
return binop(o, tmp, trans(nth(1))); return binop(o, tmp, trans((*this)[1]));
} }
case op::Or: case op::Or:
case op::OrRat: case op::OrRat:
...@@ -1237,7 +1237,7 @@ namespace spot ...@@ -1237,7 +1237,7 @@ namespace spot
} }
case op::Star: case op::Star:
case op::FStar: case op::FStar:
return bunop(o, trans(nth(0)), min(), max()); return bunop(o, trans((*this)[0]), min(), max());
} }
SPOT_UNREACHABLE(); SPOT_UNREACHABLE();
} }
......
...@@ -63,10 +63,10 @@ namespace spot ...@@ -63,10 +63,10 @@ namespace spot
res = f; res = f;
break; break;
case op::NegClosure: case op::NegClosure:
res = ltl::formula::NegClosureMarked(f.nth(0)); res = ltl::formula::NegClosureMarked(f[0]);
break; break;
case op::EConcat: case op::EConcat:
res = ltl::formula::EConcatMarked(f.nth(0), f.nth(1)); res = ltl::formula::EConcatMarked(f[0], f[1]);
break; break;
case op::Or: case op::Or:
case op::And: case op::And:
...@@ -138,7 +138,7 @@ namespace spot ...@@ -138,7 +138,7 @@ namespace spot
{ {
if (c.is(op::EConcatMarked)) 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)); v.push_back(c.map(recurse));
} }
else if (c.is(op::EConcat)) else if (c.is(op::EConcat))
...@@ -147,7 +147,7 @@ namespace spot ...@@ -147,7 +147,7 @@ namespace spot
} }
else if (c.is(op::NegClosureMarked)) else if (c.is(op::NegClosureMarked))
{ {
nmset.insert(c.nth(0)); nmset.insert(c[0]);
v.push_back(c.map(recurse)); v.push_back(c.map(recurse));
} }
else if (c.is(op::NegClosure)) else if (c.is(op::NegClosure))
...@@ -162,13 +162,13 @@ namespace spot ...@@ -162,13 +162,13 @@ namespace spot
// Keep only the non-marked EConcat for which we // Keep only the non-marked EConcat for which we
// have not seen a similar EConcatMarked. // have not seen a similar EConcatMarked.
for (auto e: elist) 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()) == empairs.end())
v.push_back(e); v.push_back(e);
// Keep only the non-marked NegClosure for which we // Keep only the non-marked NegClosure for which we
// have not seen a similar NegClosureMarked. // have not seen a similar NegClosureMarked.
for (auto n: nlist) for (auto n: nlist)
if (nmset.find(n.nth(0)) == nmset.end()) if (nmset.find(n[0]) == nmset.end())
v.push_back(n); v.push_back(n);
res = ltl::formula::And(v); res = ltl::formula::And(v);
} }
......
...@@ -86,7 +86,7 @@ namespace spot ...@@ -86,7 +86,7 @@ namespace spot
case op::G: case op::G:
if ((opts_ & Mut_Remove_Ops) if ((opts_ & Mut_Remove_Ops)
&& mutation_counter_-- == 0) && mutation_counter_-- == 0)
return f.nth(0); return f[0];
// fall through // fall through
case op::Closure: case op::Closure:
case op::NegClosure: case op::NegClosure:
...@@ -118,7 +118,7 @@ namespace spot ...@@ -118,7 +118,7 @@ namespace spot
{ {
vec v1; vec v1;
vec v2; vec v2;
v1.push_back(f.nth(0)); v1.push_back(f[0]);
bool reverse = false; bool reverse = false;
int i = 1; int i = 1;
while (i < mos) while (i < mos)
...@@ -130,10 +130,10 @@ namespace spot ...@@ -130,10 +130,10 @@ namespace spot
reverse = true; reverse = true;
break; break;
} }
v1.push_back(f.nth(i++)); v1.push_back(f[i++]);
} }
for (; i < mos; ++i) for (; i < mos; ++i)
v2.push_back(f.nth(i)); v2.push_back(f[i]);
formula first = AndNLM_(v1); formula first = AndNLM_(v1);
formula second = AndNLM_(v2); formula second = AndNLM_(v2);
formula ost = formula::one_star(); formula ost = formula::one_star();
...@@ -164,8 +164,8 @@ namespace spot ...@@ -164,8 +164,8 @@ namespace spot
case op::EConcatMarked: case op::EConcatMarked:
case op::UConcat: case op::UConcat:
{ {
formula first = f.nth(0); formula first = f[0];
formula second = f.nth(1); formula second = f[1];
op o = f.kind(); op o = f.kind();
bool left_is_sere = o == op::EConcat bool left_is_sere = o == op::EConcat
|| o == op::EConcatMarked || o == op::EConcatMarked
...@@ -242,7 +242,7 @@ namespace spot ...@@ -242,7 +242,7 @@ namespace spot
case op::Star: case op::Star:
case op::FStar: case op::FStar:
{ {
formula c = f.nth(0); formula c = f[0];
op o = f.kind(); op o = f.kind();
if (opts_ & Mut_Remove_Ops && mutation_counter_-- == 0) if (opts_ & Mut_Remove_Ops && mutation_counter_-- == 0)
return c; return c;
......
...@@ -348,10 +348,10 @@ namespace spot ...@@ -348,10 +348,10 @@ namespace spot
match_goto(formula mo, unsigned i) match_goto(formula mo, unsigned i)
{ {
assert(i + 1 < mo.size()); 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()) if (b == nullptr || !b.is_boolean())
return nullptr; return nullptr;
if (mo.nth(i + 1) == b) if (mo[i + 1] == b)
return b; return b;
return nullptr; return nullptr;
} }
...@@ -482,7 +482,7 @@ namespace spot ...@@ -482,7 +482,7 @@ namespace spot
break; break;
case op::Not: case op::Not:
{ {
formula c = f.nth(0); formula c = f[0];
if (c.is(op::AP)) if (c.is(op::AP))
{ {
// If we negate a single letter in UTF-8, use a // If we negate a single letter in UTF-8, use a
...@@ -514,15 +514,15 @@ namespace spot ...@@ -514,15 +514,15 @@ namespace spot
} }
case op::X: case op::X:
emit(KX); emit(KX);
visit(f.nth(0)); visit(f[0]);
break; break;
case op::F: case op::F:
emit(KF); emit(KF);
visit(f.nth(0)); visit(f[0]);
break; break;
case op::G: case op::G:
emit(KG); emit(KG);
visit(f.nth(0)); visit(f[0]);
break; break;
case op::NegClosure: case op::NegClosure:
case op::NegClosureMarked: case op::NegClosureMarked:
...@@ -534,45 +534,45 @@ namespace spot ...@@ -534,45 +534,45 @@ namespace spot
os_ << '{'; os_ << '{';
in_ratexp_ = true; in_ratexp_ = true;
top_level_ = true; top_level_ = true;
visit(f.nth(0)); visit(f[0]);
os_ << '}'; os_ << '}';
in_ratexp_ = false; in_ratexp_ = false;
top_level_ = false; top_level_ = false;
break; break;
case op::Xor: case op::Xor:
visit(f.nth(0)); visit(f[0]);
emit(KXor); emit(KXor);
visit(f.nth(1)); visit(f[1]);
break; break;
case op::Implies: case op::Implies:
visit(f.nth(0)); visit(f[0]);
emit(KImplies); emit(KImplies);
visit(f.nth(1)); visit(f[1]);
break; break;
case op::Equiv: case op::Equiv:
visit(f.nth(0)); visit(f[0]);
emit(KEquiv); emit(KEquiv);
visit(f.nth(1)); visit(f[1]);
break; break;
case op::U: case op::U:
visit(f.nth(0)); visit(f[0]);
emit(KU); emit(KU);
visit(f.nth(1)); visit(f[1]);
break; break;
case op::R: case op::R:
visit(f.nth(0)); visit(f[0]);
emit(KR); emit(KR);
visit(f.nth(1)); visit(f[1]);
break; break;
case op::W: case op::W:
visit(f.nth(0)); visit(f[0]);
emit(KW); emit(KW);
visit(f.nth(1)); visit(f[1]);
break; break;
case op::M: case op::M:
visit(f.nth(0)); visit(f[0]);
emit(KM); emit(KM);
visit(f.nth(1)); visit(f[1]);
break; break;
case op::EConcat: case op::EConcat:
case op::EConcatMarked: case op::EConcatMarked:
...@@ -581,11 +581,11 @@ namespace spot ...@@ -581,11 +581,11 @@ namespace spot
in_ratexp_ = true; in_ratexp_ = true;
openp(); openp();
top_level_ = true; top_level_ = true;
formula left = f.nth(0); formula left = f[0];
formula right = f.nth(1); formula right = f[1];
unsigned last = left.size() - 1; unsigned last = left.size() - 1;
bool onelast = false; 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)); visit(left.all_but(last));
onelast = true; onelast = true;
...@@ -609,7 +609,7 @@ namespace spot ...@@ -609,7 +609,7 @@ namespace spot
} }
else if (o == op::EConcat) else if (o == op::EConcat)
{ {
if (f.nth(1).is(op::True)) if (f[1].is(op::True))
{ {
os_ << '!'; os_ << '!';
// No recursion on right. // No recursion on right.
...@@ -633,7 +633,7 @@ namespace spot ...@@ -633,7 +633,7 @@ namespace spot
case op::AndNLM: case op::AndNLM:
case op::Fusion: case op::Fusion:
{ {
visit(f.nth(0)); visit(f[0]);
keyword k = KFalse; // Initialize to something to please GCC. keyword k = KFalse; // Initialize to something to please GCC.
switch (o) switch (o)
{ {
...@@ -664,7 +664,7 @@ namespace spot ...@@ -664,7 +664,7 @@ namespace spot
for (unsigned n = 1; n < max; ++n) for (unsigned n = 1; n < max; ++n)
{ {
emit(k); emit(k);
visit(f.nth(n)); visit(f[n]);
} }
break; break;
} }
...@@ -686,7 +686,7 @@ namespace spot ...@@ -686,7 +686,7 @@ namespace spot
// Wait... maybe we are looking at (!b)[*];b;(!b)[*] // Wait... maybe we are looking at (!b)[*];b;(!b)[*]
// in which case it's b[=1]. // 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); emit(KEqualBunop);
os_ << '1'; os_ << '1';
...@@ -702,12 +702,12 @@ namespace spot ...@@ -702,12 +702,12 @@ namespace spot
continue; continue;
} }
// Try to match ((!b)[*];b)[*i..j];(!b)[*] // Try to match ((!b)[*];b)[*i..j];(!b)[*]
formula fi = f.nth(i); formula fi = f[i];
if (fi.is(op::Star)) 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 (fic.is(op::Concat))
if (formula b1 = match_goto(fic, 0)) if (formula b1 = match_goto(fic, 0))
if (b1 == b2) if (b1 == b2)
...@@ -730,14 +730,14 @@ namespace spot ...@@ -730,14 +730,14 @@ namespace spot
} }
} }
} }
visit(f.nth(i)); visit(f[i]);
} }
break; break;
} }
case op::Star: case op::Star:
case op::FStar: case op::FStar:
{ {
formula c = f.nth(0); formula c = f[0];
enum { Star, FStar, Goto } sugar = Star; enum { Star, FStar, Goto } sugar = Star;
unsigned default_min = 0; unsigned default_min = 0;
unsigned default_max = formula::unbounded(); unsigned default_max = formula::unbounded();
......
...@@ -280,24 +280,24 @@ namespace spot ...@@ -280,24 +280,24 @@ namespace spot
visit(b); visit(b);
} }
for (; i < sz; ++i) for (; i < sz; ++i)
visit(f.nth(i)); visit(f[i]);
if (sz > 1 && f.is_boolean()) if (sz > 1 && f.is_boolean())
{ {
// For Boolean nodes, connect all children in a // For Boolean nodes, connect all children in a
// loop. This way the node can only be a cut-point // loop. This way the node can only be a cut-point
// if it separates all children from the reset of // if it separates all children from the reset of
// the graph (not only one). // the graph (not only one).
formula pred = f.nth(0); formula pred = f[0];
for (i = 1; i < sz; ++i) for (i = 1; i < sz; ++i)
{ {
formula next = f.nth(i); formula next = f[i];
// Note that we only add an edge in one // Note that we only add an edge in one
// direction, because we are building a cycle // direction, because we are building a cycle
// between all children anyway. // between all children anyway.
g[pred].push_back(next); g[pred].push_back(next);
pred = next; pred = next;
} }
g[pred].push_back(f.nth(0)); g[pred].push_back(f[0]);
} }
s.pop(); s.pop();
} }
...@@ -446,7 +446,7 @@ namespace spot ...@@ -446,7 +446,7 @@ namespace spot
res.reserve(sz); res.reserve(sz);
} }
for (; i < sz; ++i) for (; i < sz; ++i)
res.push_back(visit(f.nth(i))); res.push_back(visit(f[i]));
return formula::multop(f.kind(), res); return formula::multop(f.kind(), res);
} }
}; };
......
...@@ -41,7 +41,7 @@ namespace spot ...@@ -41,7 +41,7 @@ namespace spot
if (!f.is(op::X)) if (!f.is(op::X))
return f.map(rec); return f.map(rec);
formula c = rec(f.nth(0)); formula c = rec(f[0]);
std::vector<formula> vo; std::vector<formula> vo;
for (auto i: aps) for (auto i: aps)
......
...@@ -29,17 +29,17 @@ namespace spot ...@@ -29,17 +29,17 @@ namespace spot
formula simplify_f_g(formula p) formula simplify_f_g(formula p)
{ {
// 1 U p = Fp // 1 U p = Fp
if (p.is(op::U) && p.nth(0).is_true()) if (p.is(op::U) && p[0].is_true())
return formula::F(p.nth(1)); return formula::F(p[1]);
// 0 R p = Gp // 0 R p = Gp
if (p.is(op::R) && p.nth(0).is_false()) if (p.is(op::R) && p[0].is_false())
return formula::G(p.nth(1)); return formula::G(p[1]);
// p W 0 = Gp // p W 0 = Gp
if (p.is(op::W) && p.nth(1).is_false()) if (p.is(op::W) && p[1].is_false())
return formula::G(p.nth(0)); return formula::G(p[0]);
// p M 1 = Fp // p M 1 = Fp
if (p.is(op::M) && p.nth(1).is_true()) if (p.is(op::M) && p[1].is_true())
return formula::F(p.nth(0)); return formula::F(p[0]);
return p.map(simplify_f_g); return p.map(simplify_f_g);
} }
......
This diff is collapsed.
...@@ -56,9 +56,9 @@ namespace spot ...@@ -56,9 +56,9 @@ namespace spot
break; break;
case op::Star: case op::Star:
if (!bounded) if (!bounded)
out = visit(f.nth(0)); // Strip the star. out = visit(f[0]); // Strip the star.
else else
out = formula::Star(visit(f.nth(0)), out = formula::Star(visit(f[0]),
std::max(unsigned(f.min()), 1U), f.max()); std::max(unsigned(f.min()), 1U), f.max());
break; break;
case op::Concat: case op::Concat:
...@@ -91,7 +91,7 @@ namespace spot ...@@ -91,7 +91,7 @@ namespace spot
std::vector<formula> v; std::vector<formula> v;
v.reserve(s);