3#include <absl/container/flat_hash_map.h>
4#include <absl/container/flat_hash_set.h>
31 return print(os,
"{}{}: {}: {}{}", rang::fg::yellow,
msg.loc,
msg.tag, rang::fg::reset,
msg.str);
32 return print(os,
"{}{}: {}: {}{}", rang::fg::yellow,
msg.loc,
msg.tag, rang::fg::reset,
msg.str);
45 Error(Loc loc,
const std::string& str)
53 const auto&
msgs()
const {
return msgs_; }
65 template<
class... Args>
67 msgs_.emplace_back(loc, tag,
fmt(s, std::forward<Args>(args)...));
72 template<
class... Args>
Error&
error(Loc loc,
const char* s, Args&&... args) { ++num_errors_;
return msg(loc,
Tag::Error, s, std::forward<Args>(args)...); }
73 template<
class... Args>
Error&
warn (Loc loc,
const char* s, Args&&... args) { ++num_warnings_;
return msg(loc,
Tag::Warn, s, std::forward<Args>(args)...); }
74 template<
class... Args>
Error&
note (Loc loc,
const char* s, Args&&... args) {
84 void ack(std::ostream& os = std::cerr);
90 case Tag::Error:
return o << rang::fg::red <<
"error";
91 case Tag::Warn:
return o << rang::fg::magenta <<
"warning";
92 case Tag::Note:
return o << rang::fg::green <<
"note";
93 default: fe::unreachable();
99 for (
const auto&
msg : e.msgs())
100 os <<
msg << std::endl;
107 swap(e1.msgs_, e2.msgs_);
108 swap(e1.num_errors_, e2.num_errors_);
109 swap(e1.num_warnings_, e2.num_warnings_);
110 swap(e1.num_notes_, e2.num_notes_);
115 std::vector<Msg> msgs_;
116 size_t num_errors_ = 0;
117 size_t num_warnings_ = 0;
118 size_t num_notes_ = 0;
124template<
class... Args>
125[[noreturn]]
void error(Loc loc,
const char* f, Args&&... args) {
126 throw Error(loc,
fmt(f, std::forward<Args>(args)...));
134 constexpr Dbg() noexcept = default;
135 constexpr
Dbg(const
Dbg&) noexcept = default;
148 Sym
sym()
const {
return sym_; }
149 Loc
loc()
const {
return loc_; }
151 explicit operator bool()
const {
return sym().operator bool(); }
164 friend std::ostream&
operator<<(std::ostream& os,
const Dbg& dbg) {
return os << dbg.sym(); }
friend void swap(Error &e1, Error &e2) noexcept
Error & error(Loc loc, const char *s, Args &&... args)
const auto & msgs() const
Error(const Error &)=default
friend std::ostream & operator<<(std::ostream &o, Tag tag)
Error & note(Loc loc, const char *s, Args &&... args)
friend std::ostream & operator<<(std::ostream &os, const Error &e)
Error & warn(Loc loc, const char *s, Args &&... args)
size_t num_errors() const
Error(Loc loc, const std::string &str)
Creates a single Tag::Error message.
size_t num_warnings() const
Error & msg(Loc loc, Tag tag, const char *s, Args &&... args)
std::ostream & print(std::ostream &os, const char *s)
Base case.
std::string fmt(const char *s, Args &&... args)
Wraps mim::print to output a formatted std:string.
void error(Loc loc, const char *f, Args &&... args)
Dbg & operator=(const Dbg &) noexcept=default
friend std::ostream & operator<<(std::ostream &os, const Dbg &dbg)
constexpr Dbg(Loc loc) noexcept
constexpr Dbg() noexcept=default
constexpr Dbg(Sym sym) noexcept
friend std::ostream & operator<<(std::ostream &os, const Msg &msg)