2014-08-15 00:44:07 +00:00
|
|
|
/*
|
|
|
|
Copyright (c) 2014 Microsoft Corporation. All rights reserved.
|
|
|
|
Released under Apache 2.0 license as described in the file LICENSE.
|
|
|
|
|
|
|
|
Author: Leonardo de Moura
|
|
|
|
*/
|
2014-08-15 01:19:17 +00:00
|
|
|
#include <string>
|
2014-08-15 00:44:07 +00:00
|
|
|
#include "library/declaration_index.h"
|
|
|
|
|
|
|
|
namespace lean {
|
2014-08-23 19:39:59 +00:00
|
|
|
void declaration_index::add_decl(std::string const fname, pos_info const & p, name const & n, name const & k, expr const & t) {
|
2014-09-04 14:42:18 +00:00
|
|
|
m_decls.insert(n, decl(fname, p, k, t));
|
2014-08-15 00:44:07 +00:00
|
|
|
}
|
2014-09-04 16:30:25 +00:00
|
|
|
void declaration_index::add_abbrev(name const & n, name const & d) {
|
|
|
|
m_abbrevs.emplace_back(n, d);
|
|
|
|
}
|
2014-08-15 00:44:07 +00:00
|
|
|
void declaration_index::add_ref(std::string const fname, pos_info const & p, name const & n) {
|
2014-09-04 14:42:18 +00:00
|
|
|
m_refs.emplace_back(fname, p, n);
|
2014-08-15 00:44:07 +00:00
|
|
|
}
|
2014-08-23 19:39:59 +00:00
|
|
|
void declaration_index::save(io_state_stream const & out) const {
|
2014-09-04 14:42:18 +00:00
|
|
|
std::string fname; pos_info p; name n, k; expr t;
|
|
|
|
options const & opts = out.get_options();
|
|
|
|
m_decls.for_each([&](name const & n, decl const & d) {
|
|
|
|
std::tie(fname, p, k, t) = d;
|
|
|
|
out << "d" << "|" << fname << "|" << p.first << "|" << p.second << "|" << n;
|
|
|
|
out << "|" << k << "|";
|
2014-08-23 19:39:59 +00:00
|
|
|
out.get_stream() << mk_pair(flatten(out.get_formatter()(t)), opts);
|
2014-09-04 14:42:18 +00:00
|
|
|
out << endl;
|
|
|
|
});
|
2014-09-04 16:30:25 +00:00
|
|
|
for (auto const & a : m_abbrevs) {
|
|
|
|
out << "a" << "|" << a.first << "|" << a.second << endl;
|
|
|
|
}
|
2014-09-04 14:42:18 +00:00
|
|
|
for (auto const & r : m_refs) {
|
|
|
|
std::tie(fname, p, n) = r;
|
|
|
|
out << "r" << "|" << fname << "|" << p.first << "|" << p.second << "|" << n << endl;
|
2014-08-15 00:44:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|