A Hugo incarnation of the blog.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

type_env.hpp 1.7KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. #pragma once
  2. #include <map>
  3. #include <string>
  4. #include <set>
  5. #include "graph.hpp"
  6. #include "type.hpp"
  7. struct type_env;
  8. using type_env_ptr = std::shared_ptr<type_env>;
  9. enum class visibility { global,local };
  10. struct type_env {
  11. struct variable_data {
  12. type_scheme_ptr type;
  13. visibility vis;
  14. std::string mangled_name;
  15. variable_data()
  16. : variable_data(nullptr, visibility::local, "") {}
  17. variable_data(type_scheme_ptr t, visibility v, std::string n)
  18. : type(std::move(t)), vis(v), mangled_name(std::move(n)) {}
  19. };
  20. type_env_ptr parent;
  21. std::map<std::string, variable_data> names;
  22. std::map<std::string, type_ptr> type_names;
  23. type_env(type_env_ptr p) : parent(std::move(p)) {}
  24. type_env() : type_env(nullptr) {}
  25. void find_free(const type_mgr& mgr, std::set<std::string>& into) const;
  26. void find_free_except(const type_mgr& mgr, const group& avoid,
  27. std::set<std::string>& into) const;
  28. type_scheme_ptr lookup(const std::string& name) const;
  29. bool is_global(const std::string& name) const;
  30. void set_mangled_name(const std::string& name, const std::string& mangled);
  31. const std::string& get_mangled_name(const std::string& name) const;
  32. type_ptr lookup_type(const std::string& name) const;
  33. void bind(const std::string& name, type_ptr t,
  34. visibility v = visibility::local);
  35. void bind(const std::string& name, type_scheme_ptr t,
  36. visibility v = visibility::local);
  37. void bind_type(const std::string& type_name, type_ptr t);
  38. void generalize(const std::string& name, const group& grp, type_mgr& mgr);
  39. };
  40. type_env_ptr type_scope(type_env_ptr parent);