FE 0.13.1
Header-only C++ frontend library
Loading...
Searching...
No Matches

Collects diagnostics and hands each to the Diag that lays it out. More...

#include <fe/error.h>

Classes

class  Bail
 What Error::ack and Error::bail throw. More...
struct  Note
 A secondary message elaborating a Msg. More...
struct  Msg
 One Tag::Error or Tag::Warn together with the Notes that belong to it. More...

Public Types

using Tag = Diag::Tag

Public Member Functions

 Error (const Driver &driver)
 A sink of your own; Driver::error is the one every frontend building block already reports to.
Getters
const auto & msgs () const
bool empty () const
bool ok () const
 Nothing recorded that must stop the compilation?
size_t num_errors () const
size_t num_warnings () const
size_t num_notes () const
bool truncated () const
 Did Diag::max_errors drop anything?
Add a Message

Each of these yields the Error again, so a diagnostic, its Notes, and a closing Error::bail chain.

Errormsg (Loc loc, Tag tag, const std::function< std::string()> &fmt)
template<class... Args>
Errormsg (Loc loc, Tag tag, std::format_string< Args... > s, Args &&... args)
template<class... Args>
Errorerror (Loc loc, std::format_string< Args... > s, Args &&... args)
template<class... Args>
Errorwarn (Loc loc, std::format_string< Args... > s, Args &&... args)
template<class... Args>
Errornote (std::format_string< Args... > s, Args &&... args)
 A = note: continuation of the diagnostic being built; it has no Loc of its own to point at.
template<class... Args>
Errornote (Loc loc, std::format_string< Args... > s, Args &&... args)
 A Note that points elsewhere; dropped when loc adds nothing.
Handle Errors/Warnings
void clear ()
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.
size_t report (std::ostream &os=std::cerr)
 Streams everything collected so far to os and claims it.
void bail (std::ostream &os=std::cerr)
 Claims everything collected so far and throws it as a Bail rendered for os.
void ack (std::ostream &os=std::cerr)
 If errors occurred, Error::bail; otherwise Error::report any warnings to os.

Friends

std::ostream & operator<< (std::ostream &os, const Error &e)
 Hands every Msg, its Notes, and the closing summary to Diag.

Detailed Description

Collects diagnostics and hands each to the Diag that lays it out.

Error::ack once you are done: it throws an Error::Bail if anything went wrong.

Definition at line 27 of file error.h.


Class Documentation

◆ fe::Error::Note

struct fe::Error::Note

A secondary message elaborating a Msg.

A Note with a Loc of its own reads as a diagnostic of its own - header line plus snippet; one without has nowhere else to point and renders as a = note: continuation line.

Definition at line 56 of file error.h.

Class Members
Loc loc
string str

◆ fe::Error::Msg

struct fe::Error::Msg

One Tag::Error or Tag::Warn together with the Notes that belong to it.

Definition at line 62 of file error.h.

Class Members
Loc loc
vector< Note > notes
string str
Tag tag

Member Typedef Documentation

◆ Tag

Definition at line 29 of file error.h.

Constructor & Destructor Documentation

◆ Error()

fe::Error::Error ( const Driver & driver)
inlineexplicit

A sink of your own; Driver::error is the one every frontend building block already reports to.

Warning
A Msg::loc points into driver's SrcMap and Error::msg renders through Diag::render, so driver must outlive this Error.

Definition at line 72 of file error.h.

Referenced by error(), msg(), msg(), note(), note(), operator<<, and warn().

Member Function Documentation

◆ ack()

void fe::Error::ack ( std::ostream & os = std::cerr)
inline

If errors occurred, Error::bail; otherwise Error::report any warnings to os.

Definition at line 158 of file error.h.

References bail(), num_errors(), and report().

◆ bail()

void fe::Error::bail ( std::ostream & os = std::cerr)
inline

Claims everything collected so far and throws it as a Bail rendered for os.

Definition at line 151 of file error.h.

References fe::Error::Bail::Bail(), bail(), clear(), num_errors(), num_warnings(), and str().

Referenced by ack(), bail(), and fe::Error::Bail::operator<<.

◆ clear()

void fe::Error::clear ( )
inline

Definition at line 126 of file error.h.

Referenced by bail(), and report().

◆ empty()

bool fe::Error::empty ( ) const
inline

Definition at line 78 of file error.h.

Referenced by report().

◆ error()

template<class... Args>
Error & fe::Error::error ( Loc loc,
std::format_string< Args... > s,
Args &&... args )
inline

◆ msg() [1/2]

Error & fe::Error::msg ( Loc loc,
Tag tag,
const std::function< std::string()> & fmt )
inline

Records the message fmt renders; see Diag::render. tag must be Tag::Error or Tag::Warn - a Tag::Note belongs to Error::note.

Definition at line 91 of file error.h.

References Error().

Referenced by error(), operator<<, and warn().

◆ msg() [2/2]

template<class... Args>
Error & fe::Error::msg ( Loc loc,
Tag tag,
std::format_string< Args... > s,
Args &&... args )
inline
Note
Formats via std::vformat because Diag::render may render s more than once.

Definition at line 98 of file error.h.

References Error().

◆ msgs()

const auto & fe::Error::msgs ( ) const
inline

Definition at line 77 of file error.h.

◆ note() [1/2]

template<class... Args>
Error & fe::Error::note ( Loc loc,
std::format_string< Args... > s,
Args &&... args )
inline

A Note that points elsewhere; dropped when loc adds nothing.

A loc overlapping the primary one is already covered by its snippet and so points nowhere new. An invalid loc points nowhere and degrades to the = note: continuation above. The renderer gives loc a header line of its own, so phrase the message to stand alone.

Definition at line 116 of file error.h.

References Error().

◆ note() [2/2]

template<class... Args>
Error & fe::Error::note ( std::format_string< Args... > s,
Args &&... args )
inline

A = note: continuation of the diagnostic being built; it has no Loc of its own to point at.

Definition at line 107 of file error.h.

References Error(), and fe::Loc::Loc().

Referenced by fe::Driver::note(), fe::Driver::note(), and operator<<.

◆ num_errors()

size_t fe::Error::num_errors ( ) const
inline

Definition at line 80 of file error.h.

Referenced by ack(), bail(), ok(), operator<<, and report().

◆ num_notes()

size_t fe::Error::num_notes ( ) const
inline

Definition at line 82 of file error.h.

◆ num_warnings()

size_t fe::Error::num_warnings ( ) const
inline

Definition at line 81 of file error.h.

Referenced by bail(), and operator<<.

◆ ok()

bool fe::Error::ok ( ) const
inline

Nothing recorded that must stop the compilation?

Definition at line 79 of file error.h.

References num_errors().

◆ report()

size_t fe::Error::report ( std::ostream & os = std::cerr)
inline

Streams everything collected so far to os and claims it.

Returns
the number of Tag::Errors that were reported.

Definition at line 143 of file error.h.

References clear(), empty(), and num_errors().

Referenced by ack().

◆ str()

std::string fe::Error::str ( std::ostream & os = std::cerr) const
inline

Renders everything collected so far the way it would appear on os; os only decides the coloring.

Definition at line 134 of file error.h.

References fe::term::Always, fe::term::Never, and fe::term::use_color().

Referenced by bail(), and operator<<.

◆ truncated()

bool fe::Error::truncated ( ) const
inline

Did Diag::max_errors drop anything?

Definition at line 83 of file error.h.

◆ warn()

template<class... Args>
Error & fe::Error::warn ( Loc loc,
std::format_string< Args... > s,
Args &&... args )
inline

Definition at line 104 of file error.h.

References Error(), and msg().

Referenced by fe::Driver::warn().

◆ operator<<

std::ostream & operator<< ( std::ostream & os,
const Error & e )
friend

Hands every Msg, its Notes, and the closing summary to Diag.

Definition at line 165 of file error.h.

References Error(), msg(), note(), num_errors(), num_warnings(), str(), and fe::Diag::summary().


The documentation for this class was generated from the following file: