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-14 18:50:51 +00:00
|
|
|
#include <set>
|
|
|
|
#include "util/buffer.h"
|
2013-10-01 00:58:46 +00:00
|
|
|
#include "kernel/trace.h"
|
|
|
|
|
|
|
|
namespace lean {
|
2013-10-16 00:32:02 +00:00
|
|
|
void trace_cell::add_pos_info(format & r, expr const & e, pos_info_provider const * p) {
|
|
|
|
if (!p || !e)
|
|
|
|
return;
|
|
|
|
format f = p->pp(e);
|
|
|
|
if (!f)
|
|
|
|
return;
|
|
|
|
r += f;
|
|
|
|
r += space();
|
|
|
|
}
|
|
|
|
|
|
|
|
format trace_cell::pp(formatter const & fmt, options const & opts, pos_info_provider const * p, bool display_children) const {
|
|
|
|
format r;
|
|
|
|
add_pos_info(r, get_main_expr(), p);
|
|
|
|
r += pp_header(fmt, opts);
|
|
|
|
if (display_children) {
|
|
|
|
buffer<trace_cell *> children;
|
|
|
|
get_children(children);
|
|
|
|
unsigned indent = get_pp_indent(opts);
|
|
|
|
for (trace_cell * child : children) {
|
|
|
|
r += nest(indent, compose(line(), child->pp(fmt, opts, p, display_children)));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2013-10-01 00:58:46 +00:00
|
|
|
bool trace::has_children() const {
|
2013-10-14 18:50:51 +00:00
|
|
|
buffer<trace_cell *> r;
|
2013-10-01 00:58:46 +00:00
|
|
|
get_children(r);
|
|
|
|
return !r.empty();
|
|
|
|
}
|
2013-10-14 18:50:51 +00:00
|
|
|
|
|
|
|
bool depends_on(trace const & t, trace const & d) {
|
|
|
|
buffer<trace_cell *> todo;
|
|
|
|
std::set<trace_cell *> visited;
|
|
|
|
buffer<trace_cell *> children;
|
|
|
|
todo.push_back(t.raw());
|
2013-10-21 17:27:18 +00:00
|
|
|
while (!todo.empty()) {
|
2013-10-14 18:50:51 +00:00
|
|
|
trace_cell * curr = todo.back();
|
|
|
|
todo.pop_back();
|
|
|
|
if (curr == d.raw()) {
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
children.clear();
|
|
|
|
curr->get_children(children);
|
|
|
|
for (trace_cell * child : children) {
|
|
|
|
if (child->is_shared()) {
|
|
|
|
if (visited.find(child) == visited.end()) {
|
|
|
|
visited.insert(child);
|
|
|
|
todo.push_back(child);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
todo.push_back(child);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2013-10-01 00:58:46 +00:00
|
|
|
}
|