f97c260b0b
The environment object is a "smart-pointer". Before this commit, the use of "const &" for environment objects was broken. For example, suppose we have a function f that should not modify the input environment. Before this commit, its signature would be void f(environment const & env) This is broken, f's implementation can easilty convert it to a read-write pointer by using the copy constructor. environment rw_env(env); Now, f can use rw_env to update env. To fix this issue, we now have ro_environment. It is a shared *const* pointer. We can convert an environment into a ro_environment, but not the other way around. ro_environment can also be seen as a form of documentation. For example, now it is clear that type_inferer is not updating the environment, since its constructor takes a ro_environment. Signed-off-by: Leonardo de Moura <leonardo@microsoft.com>
38 lines
1.2 KiB
C++
38 lines
1.2 KiB
C++
/*
|
|
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 <sstream>
|
|
#include "kernel/kernel_exception.h"
|
|
#include "kernel/printer.h"
|
|
#include "kernel/formatter.h"
|
|
|
|
namespace lean {
|
|
class simple_formatter_cell : public formatter_cell {
|
|
public:
|
|
virtual format operator()(expr const & e, options const &) {
|
|
std::ostringstream s; s << e; return format(s.str());
|
|
}
|
|
virtual format operator()(context const & c, options const &) {
|
|
std::ostringstream s; s << c; return format(s.str());
|
|
}
|
|
virtual format operator()(context const & c, expr const & e, bool format_ctx, options const &) {
|
|
std::ostringstream s;
|
|
if (format_ctx)
|
|
s << c << " |- ";
|
|
s << mk_pair(e, c);
|
|
return format(s.str());
|
|
}
|
|
virtual format operator()(object const & obj, options const &) {
|
|
std::ostringstream s; s << obj; return format(s.str());
|
|
}
|
|
virtual format operator()(ro_environment const & env, options const &) {
|
|
std::ostringstream s; s << env; return format(s.str());
|
|
}
|
|
};
|
|
formatter mk_simple_formatter() {
|
|
return mk_formatter(simple_formatter_cell());
|
|
}
|
|
}
|