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.

error.hpp 1.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. #pragma once
  2. #include <exception>
  3. #include <optional>
  4. #include "type.hpp"
  5. #include "location.hh"
  6. #include "parse_driver.hpp"
  7. using maybe_location = std::optional<yy::location>;
  8. class compiler_error : std::exception {
  9. private:
  10. std::string description;
  11. maybe_location loc;
  12. public:
  13. compiler_error(std::string d, maybe_location l = std::nullopt)
  14. : description(std::move(d)), loc(std::move(l)) {}
  15. const char* what() const noexcept override;
  16. void print_about(std::ostream& to);
  17. void print_location(std::ostream& to, file_mgr& fm, bool highlight = false);
  18. void pretty_print(std::ostream& to, file_mgr& fm);
  19. };
  20. class type_error : compiler_error {
  21. private:
  22. public:
  23. type_error(std::string d, maybe_location l = std::nullopt)
  24. : compiler_error(std::move(d), std::move(l)) {}
  25. const char* what() const noexcept override;
  26. void pretty_print(std::ostream& to, file_mgr& fm);
  27. };
  28. class unification_error : public type_error {
  29. private:
  30. type_ptr left;
  31. type_ptr right;
  32. public:
  33. unification_error(type_ptr l, type_ptr r, maybe_location loc = std::nullopt)
  34. : left(std::move(l)), right(std::move(r)),
  35. type_error("failed to unify types", std::move(loc)) {}
  36. void pretty_print(std::ostream& to, file_mgr& fm, type_mgr& mgr);
  37. };