30 class Bail :
public std::exception {
37 const char*
what() const noexcept
override {
return what_.c_str(); }
73 const auto&
msgs()
const {
return msgs_; }
74 bool empty()
const {
return msgs_.empty(); }
76 size_t num_errors()
const {
return num_[size_t(Tag::E)]; }
78 size_t num_notes()
const {
return num_[size_t(Tag::N)]; }
93 return msg(loc, tag, [&] {
return term::detail::vformat_cite(s.get(), args...); });
107 if (loc && (loc & primary_loc_()))
return *
this;
108 note_(loc, [&] {
return term::detail::vformat_cite(s.get(), args...); });
119 std::string
str(std::ostream& os = std::cerr)
const;
123 size_t report(std::ostream& os = std::cerr);
126 [[noreturn]]
void bail(std::ostream& os = std::cerr);
129 void ack(std::ostream& os = std::cerr);
136 const Diag& diag()
const;
139 Loc primary_loc_()
const {
return msgs_.empty() ?
Loc() : msgs_.back().loc; }
141 void note_(
Loc loc,
const std::function<std::string()>& fmt);
144 std::vector<Msg> msgs_;
145 std::array<size_t, 3> num_ = {};
146 bool truncated_ =
false;
147 bool dropped_ =
false;
How a diagnostic lays out - and how much of it an Error keeps.
Bail(std::string what, size_t num_errors, size_t num_warnings)
size_t num_warnings() const
size_t num_errors() const
friend std::ostream & operator<<(std::ostream &os, const Bail &bail)
const char * what() const noexcept override
Error(const Driver &driver)
A sink of your own; Driver::error is the one every frontend building block already reports to.
Error & n(cite_string< Args... > s, Args &&... args)
A = note: continuation of the diagnostic being built; it has no Loc of its own to point at.
std::string str(std::ostream &os=std::cerr) const
Renders everything collected so far the way it would appear on os; os only decides the coloring.
Error & msg(Loc loc, Tag tag, const std::function< std::string()> &fmt)
void ack(std::ostream &os=std::cerr)
If errors occurred, Error::bail; otherwise Error::report any warnings to os.
Error & n(Loc loc, cite_string< Args... > s, Args &&... args)
A Note that points elsewhere; dropped when loc adds nothing.
Error & w(Loc loc, cite_string< Args... > s, Args &&... args)
const auto & msgs() const
void bail(std::ostream &os=std::cerr)
Claims everything collected so far and throws it as a Bail rendered for os.
bool truncated() const
Did Diag::max_errors drop anything?
friend std::ostream & operator<<(std::ostream &os, const Error &e)
Hands every Msg, its Notes, and the closing summary to Diag.
size_t report(std::ostream &os=std::cerr)
Streams everything collected so far to os and claims it.
size_t num_warnings() const
size_t num_errors() const
Error & msg(Loc loc, Tag tag, cite_string< Args... > s, Args &&... args)
The backticks of s delimit a `citation` ; those of an argument are data and get escaped - see Cite.
Error & e(Loc loc, cite_string< Args... > s, Args &&... args)
std::vector< Note > notes
bool ok() const
Nothing recorded that must stop the compilation?
One Tag::Error or Tag::Warn together with the Notes that belong to it.
A secondary message elaborating a Msg.
std::format_string< detail::cite_arg_t< Args >... > cite_string
A std::format_string whose backticks delimit a `citation` while those of its arguments are data.
basic_ostream_formatter< char > ostream_formatter
Use/derive from this class for "global" variables that you need all over the place.
Location within a Src: the half-open byte range [Loc::begin, Loc::end).
constexpr Loc() noexcept=default
Creates an invalid Location.