2013-10-01 00:58:46 +00:00
|
|
|
/*
|
|
|
|
Copyright (c) 2013 Microsoft Corporation. All rights reserved.
|
|
|
|
Released under Apache 2.0 license as described in the file LICENSE.
|
|
|
|
|
|
|
|
Author: Leonardo de Moura
|
|
|
|
*/
|
2013-10-27 18:02:29 +00:00
|
|
|
#include <vector>
|
2013-10-14 18:50:51 +00:00
|
|
|
#include "util/buffer.h"
|
2013-10-23 20:42:14 +00:00
|
|
|
#include "kernel/justification.h"
|
2014-01-04 01:13:10 +00:00
|
|
|
#include "kernel/metavar.h"
|
2013-10-01 00:58:46 +00:00
|
|
|
|
|
|
|
namespace lean {
|
2013-12-08 07:21:07 +00:00
|
|
|
void justification_cell::add_pos_info(format & r, optional<expr> const & e, pos_info_provider const * p) {
|
2013-10-16 00:32:02 +00:00
|
|
|
if (!p || !e)
|
|
|
|
return;
|
2013-12-08 07:21:07 +00:00
|
|
|
format f = p->pp(*e);
|
2013-10-16 00:32:02 +00:00
|
|
|
if (!f)
|
|
|
|
return;
|
|
|
|
r += f;
|
|
|
|
r += space();
|
|
|
|
}
|
|
|
|
|
2014-01-04 01:13:10 +00:00
|
|
|
format justification_cell::pp(formatter const & fmt, options const & opts, pos_info_provider const * p, bool display_children,
|
|
|
|
optional<metavar_env> const & menv) const {
|
2013-10-16 00:32:02 +00:00
|
|
|
format r;
|
|
|
|
add_pos_info(r, get_main_expr(), p);
|
2014-01-04 01:13:10 +00:00
|
|
|
r += pp_header(fmt, opts, menv);
|
2013-10-16 00:32:02 +00:00
|
|
|
if (display_children) {
|
2013-10-23 20:42:14 +00:00
|
|
|
buffer<justification_cell *> children;
|
2013-10-16 00:32:02 +00:00
|
|
|
get_children(children);
|
|
|
|
unsigned indent = get_pp_indent(opts);
|
2013-10-23 20:42:14 +00:00
|
|
|
for (justification_cell * child : children) {
|
2014-01-04 01:13:10 +00:00
|
|
|
r += nest(indent, compose(line(), child->pp(fmt, opts, p, display_children, menv)));
|
2013-10-16 00:32:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2013-10-23 20:42:14 +00:00
|
|
|
bool justification::has_children() const {
|
|
|
|
buffer<justification_cell *> r;
|
2013-10-01 00:58:46 +00:00
|
|
|
get_children(r);
|
|
|
|
return !r.empty();
|
|
|
|
}
|
2014-01-04 01:13:10 +00:00
|
|
|
format justification::pp(formatter const & fmt, options const & opts, pos_info_provider const * p,
|
|
|
|
bool display_children, optional<metavar_env> const & menv) const {
|
|
|
|
lean_assert(m_ptr);
|
|
|
|
return m_ptr->pp(fmt, opts, p, display_children, menv);
|
|
|
|
}
|
|
|
|
format justification::pp(formatter const & fmt, options const & opts, pos_info_provider const * p, bool display_children) const {
|
|
|
|
lean_assert(m_ptr);
|
|
|
|
return m_ptr->pp(fmt, opts, p, display_children, optional<metavar_env>());
|
|
|
|
}
|
2013-10-14 18:50:51 +00:00
|
|
|
|
2013-10-26 21:21:29 +00:00
|
|
|
assumption_justification::assumption_justification(unsigned idx):m_idx(idx) {}
|
|
|
|
void assumption_justification::get_children(buffer<justification_cell*> &) const {}
|
2013-12-08 18:34:38 +00:00
|
|
|
optional<expr> assumption_justification::get_main_expr() const { return none_expr(); }
|
2014-01-04 01:13:10 +00:00
|
|
|
format assumption_justification::pp_header(formatter const &, options const &, optional<metavar_env> const &) const {
|
2013-10-27 18:02:29 +00:00
|
|
|
return format{format("Assumption"), space(), format(m_idx)};
|
2013-10-26 21:21:29 +00:00
|
|
|
}
|
|
|
|
|
2014-01-04 01:13:10 +00:00
|
|
|
|
2013-10-23 20:42:14 +00:00
|
|
|
bool depends_on(justification const & t, justification const & d) {
|
|
|
|
buffer<justification_cell *> todo;
|
|
|
|
buffer<justification_cell *> children;
|
2013-10-14 18:50:51 +00:00
|
|
|
todo.push_back(t.raw());
|
2013-10-21 17:27:18 +00:00
|
|
|
while (!todo.empty()) {
|
2013-10-23 20:42:14 +00:00
|
|
|
justification_cell * curr = todo.back();
|
2013-10-14 18:50:51 +00:00
|
|
|
todo.pop_back();
|
|
|
|
if (curr == d.raw()) {
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
children.clear();
|
|
|
|
curr->get_children(children);
|
2013-10-23 20:42:14 +00:00
|
|
|
for (justification_cell * child : children) {
|
2013-10-25 17:26:05 +00:00
|
|
|
todo.push_back(child);
|
2013-10-14 18:50:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2013-10-01 00:58:46 +00:00
|
|
|
}
|