3#include <unordered_map>
13class IReporterRenderer;
43 [[nodiscard]]
size_t line_number()
const {
return _line_number; }
50 [[nodiscard]]
const std::set<Label>&
labels()
const {
return _labels; }
57 [[nodiscard]] std::set<Label>&
labels() {
return _labels; }
60 std::set<Label> _labels;
99 [[nodiscard]]
const std::shared_ptr<Source>&
source()
const {
return _source; }
102 std::shared_ptr<Source> _source;
126 std::optional<std::string>
note, std::optional<std::string>
help);
162 [[nodiscard]]
const std::string&
message()
const {
return _message; }
169 [[nodiscard]]
const std::optional<std::string>&
note()
const {
return _note; }
176 [[nodiscard]]
const std::optional<std::string>&
help()
const {
return _help; }
183 [[nodiscard]]
const std::optional<std::string>&
code()
const {
return _code; }
186 std::optional<std::string> _code, _note, _help;
188 std::string _message;
301 std::optional<std::string> _message, _note, _help, _code;
302 std::optional<Severity> _severity;
Groups LineGroups belonging to the same Source
Definition: report.hpp:67
FileGroup(const std::shared_ptr< Source > &source, MappedLineGroups line_groups)
Constructs a group for a source file with its line groups.
MappedLineGroups & line_groups()
Returns the map of line groups.
Definition: report.hpp:92
std::map< size_t, LineGroup > MappedLineGroups
Definition: report.hpp:69
const MappedLineGroups & line_groups() const
Returns the map of line groups.
Definition: report.hpp:85
const std::shared_ptr< Source > & source() const
Returns the source this file group refers to.
Definition: report.hpp:99
Interface implemented by renderers that turn reports into output (e.g., text)
Definition: report.hpp:195
virtual void render(const FileGroup &file_group, std::ostream &stream)=0
Renders a single file group.
virtual ~IReporterRenderer()=default
virtual void render(const LineGroup &line_group, std::ostream &stream)=0
Renders a single line group.
virtual void render(const Report &report, std::ostream &stream)=0
Renders an entire report.
virtual void render(const Severity &severity, std::ostream &stream)=0
Renders just the severity label (e.g. "error", "warning")
A set of labels that belong to the same 1-based line number.
Definition: report.hpp:28
size_t line_number() const
Returns the 1-based line number.
Definition: report.hpp:43
std::set< Label > & labels()
Returns the set of labels for this line.
Definition: report.hpp:57
LineGroup(size_t line_number, std::set< Label > labels)
Constructs a group for a single line and its labels.
const std::set< Label > & labels() const
Returns the set of labels for this line.
Definition: report.hpp:50
Fluent builder for constructing Report instances.
Definition: report.hpp:235
Builder & severity(Severity severity)
Sets report severity.
Builder & help(std::string help)
Sets optional help text.
Report build() const
Builds a complete Report
Builder & message(std::string message)
Sets the main diagnostic message.
Builder & code(std::string code)
Sets an optional error code or identifier.
Builder & note(std::string note)
Sets an optional note.
Builder & label(std::string text, Span span)
Adds a label to the report.
Represents a fully constructed diagnostic report to be rendered.
Definition: report.hpp:109
MappedFileGroups & file_groups()
Returns the mapping of sources to file groups.
Definition: report.hpp:148
const std::optional< std::string > & code() const
Returns an optional error code or identifier.
Definition: report.hpp:183
void render(IReporterRenderer &renderer, std::ostream &stream=std::cout) const
Renders the report using the provided renderer to the output stream.
const std::string & message() const
Returns the primary diagnostic message.
Definition: report.hpp:162
std::unordered_map< std::shared_ptr< Source >, FileGroup > MappedFileGroups
Definition: report.hpp:111
const MappedFileGroups & file_groups() const
Returns the mapping of sources to file groups.
Definition: report.hpp:141
Severity severity() const
Returns the severity of this report.
Definition: report.hpp:155
Report(std::string message, std::optional< std::string > code, Severity severity, MappedFileGroups file_groups, std::optional< std::string > note, std::optional< std::string > help)
Constructs a report.
const std::optional< std::string > & help() const
Returns optional help text with suggestions.
Definition: report.hpp:176
const std::optional< std::string > & note() const
Returns an optional note with additional context.
Definition: report.hpp:169
Represents a contiguous region within a Source
Definition: span.hpp:12
Severity
Indicates the importance of a diagnostic.
Definition: report.hpp:18
@ Warning
Suspicious or suboptimal situation.
@ Info
Informational message.
@ Unknown
Unspecified or not set.
@ Error
Serious problem that usually prevents progress.