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.cpp 1.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. #include "error.hpp"
  2. const char* compiler_error::what() const noexcept {
  3. return "an error occured while compiling the program";
  4. }
  5. void compiler_error::print_about(std::ostream& to) {
  6. to << what() << ": ";
  7. to << description << std::endl;
  8. }
  9. void compiler_error::print_location(std::ostream& to, file_mgr& fm, bool highlight) {
  10. if(!loc) return;
  11. to << "occuring on line " << loc->begin.line << ":" << std::endl;
  12. fm.print_location(to, *loc, highlight);
  13. }
  14. void compiler_error::pretty_print(std::ostream& to, file_mgr& fm) {
  15. print_about(to);
  16. print_location(to, fm);
  17. }
  18. const char* type_error::what() const noexcept {
  19. return "an error occured while checking the types of the program";
  20. }
  21. void type_error::pretty_print(std::ostream& to, file_mgr& fm) {
  22. print_about(to);
  23. print_location(to, fm, true);
  24. }
  25. void unification_error::pretty_print(std::ostream& to, file_mgr& fm, type_mgr& mgr) {
  26. type_error::pretty_print(to, fm);
  27. to << "the expected type was:" << std::endl;
  28. to << " \033[34m";
  29. left->print(mgr, to);
  30. to << std::endl << "\033[0mwhile the actual type was:" << std::endl;
  31. to << " \033[32m";
  32. right->print(mgr, to);
  33. to << "\033[0m" << std::endl;
  34. }