2020-09-08 18:38:05 -07:00
|
|
|
#include "error.hpp"
|
|
|
|
|
2020-09-11 21:29:49 -07:00
|
|
|
const char* compiler_error::what() const noexcept {
|
|
|
|
return "an error occured while compiling the program";
|
|
|
|
}
|
|
|
|
|
|
|
|
void compiler_error::print_about(std::ostream& to) {
|
|
|
|
to << what() << ": ";
|
|
|
|
to << description << std::endl;
|
|
|
|
}
|
|
|
|
|
|
|
|
void compiler_error::print_location(std::ostream& to, parse_driver& drv, bool highlight) {
|
|
|
|
if(!loc) return;
|
|
|
|
to << "occuring on line " << loc->begin.line << ":" << std::endl;
|
|
|
|
drv.print_location(to, *loc, highlight);
|
|
|
|
}
|
|
|
|
|
|
|
|
void compiler_error::pretty_print(std::ostream& to, parse_driver& drv) {
|
|
|
|
print_about(to);
|
|
|
|
print_location(to, drv);
|
|
|
|
}
|
|
|
|
|
2020-09-08 18:38:05 -07:00
|
|
|
const char* type_error::what() const noexcept {
|
|
|
|
return "an error occured while checking the types of the program";
|
|
|
|
}
|
2020-09-09 15:08:43 -07:00
|
|
|
|
|
|
|
void type_error::pretty_print(std::ostream& to, parse_driver& drv) {
|
2020-09-11 21:29:49 -07:00
|
|
|
print_about(to);
|
|
|
|
print_location(to, drv, true);
|
2020-09-09 15:08:43 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void unification_error::pretty_print(std::ostream& to, parse_driver& drv, type_mgr& mgr) {
|
|
|
|
type_error::pretty_print(to, drv);
|
|
|
|
to << "the expected type was:" << std::endl;
|
|
|
|
to << " \033[34m";
|
|
|
|
left->print(mgr, to);
|
|
|
|
to << std::endl << "\033[0mwhile the actual type was:" << std::endl;
|
|
|
|
to << " \033[32m";
|
|
|
|
right->print(mgr, to);
|
|
|
|
to << "\033[0m" << std::endl;
|
|
|
|
}
|