diff options
Diffstat (limited to 'src/unify.cpp')
-rw-r--r-- | src/unify.cpp | 51 |
1 files changed, 26 insertions, 25 deletions
diff --git a/src/unify.cpp b/src/unify.cpp index aeb024f..f8ebe1d 100644 --- a/src/unify.cpp +++ b/src/unify.cpp @@ -70,16 +70,16 @@ substitute(const AST* in, const AST* from, const AST* to) return from; List ret; - FOREACHP(ATuple::const_iterator, i, tup->as_tuple()) { - if (**i == *from) { + for (const auto& i : *tup->as_tuple()) { + if (*i == *from) { ret.push_back(to); // FIXME: should be a copy w/ (*i)->loc - } else if (*i != to) { - if (AType::is_expr(*i)) - ret.push_back(substitute(*i, from, to)); + } else if (i != to) { + if (AType::is_expr(i)) + ret.push_back(substitute(i, from, to)); else - ret.push_back(*i); + ret.push_back(i); } else { - ret.push_back(*i); + ret.push_back(i); } } return ret.head; @@ -88,9 +88,9 @@ substitute(const AST* in, const AST* from, const AST* to) void Subst::augment(const Subst& subst) { - for (Subst::const_iterator s = subst.begin(); s != subst.end(); ++s) { - if (!contains(s->first)) { - add(s->first, s->second); + for (auto s : subst) { + if (!contains(s.first)) { + add(s.first, s.second); } } } @@ -100,13 +100,13 @@ Subst Subst::compose(const Subst& delta, const Subst& gamma) { Subst r; - for (Subst::const_iterator g = gamma.begin(); g != gamma.end(); ++g) { - Subst::const_iterator d = delta.find(g->second); - r.add(g->first, ((d != delta.end()) ? d : g)->second); + for (const auto& g : gamma) { + Subst::const_iterator d = delta.find(g.second); + r.add(g.first, ((d != delta.end()) ? *d : g).second); } - for (Subst::const_iterator d = delta.begin(); d != delta.end(); ++d) { - if (gamma.find(d->first) == gamma.end()) - r.add(d->first, d->second); + for (const auto& d : delta) { + if (gamma.find(d.first) == gamma.end()) + r.add(d.first, d.second); } return r; } @@ -115,20 +115,21 @@ Subst::compose(const Subst& delta, const Subst& gamma) Constraints& Constraints::replace(const AST* s, const AST* t) { - for (Constraints::iterator c = begin(); c != end(); ++c) { - if (*c->first == *s) { - c->first = t; // FIXME: should be copy w/ c->first->loc; - } else if (AType::is_expr(c->first)) { - c->first = substitute(c->first, s, t); + for (auto& c : *this) { + if (*c.first == *s) { + c.first = t; // FIXME: should be copy w/ c.first->loc; + } else if (AType::is_expr(c.first)) { + c.first = substitute(c.first, s, t); } - if (*c->second == *s) { - c->second = t; // FIXME: should be copy w/ c->second->loc; - } else if (AType::is_expr(c->second)) { - c->second = substitute(c->second, s, t); + if (*c.second == *s) { + c.second = t; // FIXME: should be copy w/ c.second->loc; + } else if (AType::is_expr(c.second)) { + c.second = substitute(c.second, s, t); } } return *this; } + /// Unify a type constraint set (TAPL 22.4) Subst unify(const Constraints& constraints) |