bloglang/13/error.hpp

31 lines
883 B
C++
Raw Normal View History

2020-09-08 18:38:05 -07:00
#pragma once
#include <exception>
2020-09-09 15:08:43 -07:00
#include <optional>
2020-09-08 18:38:05 -07:00
#include "type.hpp"
2020-09-09 15:08:43 -07:00
#include "location.hh"
#include "parse_driver.hpp"
using maybe_location = std::optional<yy::location>;
2020-09-08 18:38:05 -07:00
struct type_error : std::exception {
std::string description;
2020-09-09 15:08:43 -07:00
std::optional<yy::location> loc;
2020-09-08 18:38:05 -07:00
2020-09-09 15:08:43 -07:00
type_error(std::string d, maybe_location l = std::nullopt)
: description(std::move(d)), loc(std::move(l)) {}
2020-09-08 18:38:05 -07:00
const char* what() const noexcept override;
2020-09-09 15:08:43 -07:00
void pretty_print(std::ostream& to, parse_driver& drv);
2020-09-08 18:38:05 -07:00
};
struct unification_error : public type_error {
type_ptr left;
type_ptr right;
2020-09-09 15:08:43 -07:00
unification_error(type_ptr l, type_ptr r, maybe_location loc = std::nullopt)
2020-09-08 18:38:05 -07:00
: left(std::move(l)), right(std::move(r)),
2020-09-09 15:08:43 -07:00
type_error("failed to unify types", std::move(loc)) {}
void pretty_print(std::ostream& to, parse_driver& drv, type_mgr& mgr);
2020-09-08 18:38:05 -07:00
};