FE 0.15.0
A C++23 toolkit for writing compiler/interpreter frontends.
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, cite_string< Args... > s, Args &&... args)
 The backticks of s delimit a `citation` ; those of an argument are data and get escaped - see Cite.
template<class... Args>
Errore (Loc loc, cite_string< Args... > s, Args &&... args)
template<class... Args>
Errorw (Loc loc, cite_string< Args... > s, Args &&... args)
template<class... Args>
Errorn (cite_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>
Errorn (Loc loc, cite_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 23 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 52 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 58 of file error.h.

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

Member Typedef Documentation

◆ Tag

Definition at line 25 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 68 of file error.h.

Referenced by e(), msg(), msg(), n(), n(), operator<<, and w().

Member Function Documentation

◆ ack()

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

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

◆ bail()

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

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

Referenced by fe::Error::Bail::operator<<.

◆ clear()

void fe::Error::clear ( )

◆ e()

template<class... Args>
Error & fe::Error::e ( Loc loc,
cite_string< Args... > s,
Args &&... args )
inline

◆ empty()

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

Definition at line 74 of file error.h.

◆ msg() [1/2]

template<class... Args>
Error & fe::Error::msg ( Loc loc,
Tag tag,
cite_string< Args... > s,
Args &&... args )
inline

The backticks of s delimit a `citation` ; those of an argument are data and get escaped - see Cite.

Note
Formats via std::vformat because Diag::render may render s more than once.

Definition at line 92 of file error.h.

References Error(), and msg().

◆ msg() [2/2]

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

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

References Error().

Referenced by e(), msg(), and w().

◆ msgs()

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

Definition at line 73 of file error.h.

◆ n() [1/2]

template<class... Args>
Error & fe::Error::n ( cite_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 100 of file error.h.

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

Referenced by n().

◆ n() [2/2]

template<class... Args>
Error & fe::Error::n ( Loc loc,
cite_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 106 of file error.h.

References Error().

◆ num_errors()

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

Definition at line 76 of file error.h.

Referenced by ok().

◆ num_notes()

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

Definition at line 78 of file error.h.

◆ num_warnings()

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

Definition at line 77 of file error.h.

◆ ok()

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

Nothing recorded that must stop the compilation?

Definition at line 75 of file error.h.

References num_errors().

◆ report()

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

Streams everything collected so far to os and claims it.

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

◆ str()

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

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

◆ truncated()

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

Did Diag::max_errors drop anything?

Definition at line 79 of file error.h.

◆ w()

template<class... Args>
Error & fe::Error::w ( Loc loc,
cite_string< Args... > s,
Args &&... args )
inline

Definition at line 97 of file error.h.

References Error(), and msg().

◆ operator<<

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

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

References e(), and Error().


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