2013-07-30 08:39:29 +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
|
|
|
|
*/
|
|
|
|
#include "context.h"
|
|
|
|
#include "exception.h"
|
2013-08-14 02:12:23 +00:00
|
|
|
#include "expr_formatter.h"
|
2013-07-30 08:39:29 +00:00
|
|
|
|
|
|
|
namespace lean {
|
2013-08-14 02:12:23 +00:00
|
|
|
format pp(expr_formatter & fmt, context const & c) {
|
2013-07-30 08:39:29 +00:00
|
|
|
if (c) {
|
2013-08-14 02:12:23 +00:00
|
|
|
format r;
|
2013-07-30 08:39:29 +00:00
|
|
|
if (tail(c))
|
2013-08-14 02:12:23 +00:00
|
|
|
r = format{pp(fmt, tail(c)), line()};
|
2013-07-30 08:39:29 +00:00
|
|
|
context_entry const & e = head(c);
|
|
|
|
if (e.get_name().is_anonymous())
|
2013-08-14 02:12:23 +00:00
|
|
|
r += format("_");
|
2013-07-30 08:39:29 +00:00
|
|
|
else
|
2013-08-14 02:12:23 +00:00
|
|
|
r += format(e.get_name());
|
|
|
|
r += format{space(), colon(), space(), fmt(e.get_type(), tail(c))};
|
|
|
|
return r;
|
|
|
|
} else {
|
|
|
|
return format();
|
2013-07-30 08:39:29 +00:00
|
|
|
}
|
2013-08-14 02:12:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
std::ostream & operator<<(std::ostream & out, context const & c) {
|
|
|
|
auto fmt = mk_simple_expr_formatter();
|
|
|
|
out << pp(*fmt, c);
|
2013-07-30 08:39:29 +00:00
|
|
|
return out;
|
|
|
|
}
|
|
|
|
|
|
|
|
context const & lookup(context const & c, unsigned i) {
|
|
|
|
context const * it1 = &c;
|
|
|
|
while (*it1) {
|
|
|
|
if (i == 0)
|
|
|
|
return *it1;
|
|
|
|
--i;
|
|
|
|
it1 = &tail(*it1);
|
|
|
|
}
|
|
|
|
throw exception("unknown free variable");
|
|
|
|
}
|
|
|
|
}
|