blog-static/code/compiler/13/error.cpp

42 lines
1.2 KiB
C++

#include "error.hpp"
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);
}
const char* type_error::what() const noexcept {
return "an error occured while checking the types of the program";
}
void type_error::pretty_print(std::ostream& to, parse_driver& drv) {
print_about(to);
print_location(to, drv, true);
}
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;
}