/* Copyright (c) 2015 Microsoft Corporation. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Author: Leonardo de Moura */ #include "kernel/type_checker.h" #include "library/tc_multigraph.h" namespace lean { pair> tc_multigraph::add(environment const & env, name const & /* e */, unsigned /* num_args */) { // TODO(Leo) return mk_pair(env, list()); } pair> tc_multigraph::add(environment const & env, name const & e) { declaration const & d = env.get(e); return add(env, e, get_arity(d.get_type())); } void tc_multigraph::erase(name const & e) { auto src = m_edges.find(e); if (!src) return; auto succ_lst = m_successors.find(*src); lean_assert(it); name tgt; list> new_succ_lst = filter(*succ_lst, [&](pair const & p) { if (p.first == e) { lean_assert(tgt.is_anonymous()); tgt = p.second; return false; } else { return true; } }); lean_assert(!tgt.is_anonymous()); m_successors.insert(*src, new_succ_lst); if (std::all_of(new_succ_lst.begin(), new_succ_lst.end(), [&](pair const & p) { return p.second != tgt; })) { // e is the last edge from src to tgt auto pred_lst = m_predecessors.find(tgt); lean_assert(pred_list); list new_pred_lst = filter(*pred_lst, [&](name const & n) { return n != *src; }); m_predecessors.insert(tgt, new_pred_lst); } m_edges.erase(e); } bool tc_multigraph::is_edge(name const & e) const { return m_edges.contains(e); } bool tc_multigraph::is_node(name const & c) const { return m_successors.contains(c) || m_predecessors.contains(c); } list> tc_multigraph::get_successors(name const & c) const { if (auto r = m_successors.find(c)) return *r; else return list>(); } list tc_multigraph::get_predecessors(name const & c) const { if (auto r = m_predecessors.find(c)) return *r; else return list(); } }