Make type_mgr a class.
This commit is contained in:
parent
55e4e61906
commit
c17d532802
|
@ -26,9 +26,9 @@ type_ptr type_scheme::instantiate(type_mgr& mgr) const {
|
||||||
}
|
}
|
||||||
|
|
||||||
void type_var::print(const type_mgr& mgr, std::ostream& to) const {
|
void type_var::print(const type_mgr& mgr, std::ostream& to) const {
|
||||||
auto it = mgr.types.find(name);
|
auto type = mgr.lookup(name);
|
||||||
if(it != mgr.types.end()) {
|
if(type) {
|
||||||
it->second->print(mgr, to);
|
type->print(mgr, to);
|
||||||
} else {
|
} else {
|
||||||
to << name;
|
to << name;
|
||||||
}
|
}
|
||||||
|
@ -82,6 +82,12 @@ type_ptr type_mgr::new_arrow_type() {
|
||||||
return type_ptr(new type_arr(new_type(), new_type()));
|
return type_ptr(new type_arr(new_type(), new_type()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type_ptr type_mgr::lookup(const std::string& var) const {
|
||||||
|
auto types_it = types.find(var);
|
||||||
|
if(types_it != types.end()) return types_it->second;
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
type_ptr type_mgr::resolve(type_ptr t, type_var*& var) const {
|
type_ptr type_mgr::resolve(type_ptr t, type_var*& var) const {
|
||||||
type_var* cast;
|
type_var* cast;
|
||||||
|
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
#include <optional>
|
#include <optional>
|
||||||
#include "location.hh"
|
#include "location.hh"
|
||||||
|
|
||||||
struct type_mgr;
|
class type_mgr;
|
||||||
|
|
||||||
struct type {
|
struct type {
|
||||||
virtual ~type() = default;
|
virtual ~type() = default;
|
||||||
|
@ -90,10 +90,12 @@ struct type_app : public type {
|
||||||
void print(const type_mgr& mgr, std::ostream& to) const;
|
void print(const type_mgr& mgr, std::ostream& to) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct type_mgr {
|
class type_mgr {
|
||||||
|
private:
|
||||||
int last_id = 0;
|
int last_id = 0;
|
||||||
std::map<std::string, type_ptr> types;
|
std::map<std::string, type_ptr> types;
|
||||||
|
|
||||||
|
public:
|
||||||
std::string new_type_name();
|
std::string new_type_name();
|
||||||
type_ptr new_type();
|
type_ptr new_type();
|
||||||
type_ptr new_arrow_type();
|
type_ptr new_arrow_type();
|
||||||
|
@ -102,6 +104,7 @@ struct type_mgr {
|
||||||
type_ptr substitute(
|
type_ptr substitute(
|
||||||
const std::map<std::string, type_ptr>& subst,
|
const std::map<std::string, type_ptr>& subst,
|
||||||
const type_ptr& t) const;
|
const type_ptr& t) const;
|
||||||
|
type_ptr lookup(const std::string& var) const;
|
||||||
type_ptr resolve(type_ptr t, type_var*& var) const;
|
type_ptr resolve(type_ptr t, type_var*& var) const;
|
||||||
void bind(const std::string& s, type_ptr t);
|
void bind(const std::string& s, type_ptr t);
|
||||||
void find_free(const type_ptr& t, std::set<std::string>& into) const;
|
void find_free(const type_ptr& t, std::set<std::string>& into) const;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user