@@ -15,39 +15,67 @@ namespace lbd::diagnostics
1515 class DiagnosticEmitter
1616 {
1717 public:
18- explicit DiagnosticEmitter (DiagnosticRenderer &diagnosticRenderer);
18+ DiagnosticEmitter (DiagnosticRenderer &diagnosticRenderer, bool exitOnError );
1919
2020 void pushContext (source::Range range, std::string message);
2121
2222 void popContext ();
2323
24- // / NOTE: Use this only to report errors caused by external systems (e.g. filesystem or I/O), not by language diagnostics.
25- [[noreturn]] void error (const source::Range &range, const std::string &message) const noexcept ;
24+ [[nodiscard]] bool shouldExitOnError () const noexcept { return m_exitOnError; }
2625
27- template <typename ... Args>
28- [[noreturn]] void error (const source::Range &range, const DiagnosticId id, Args &&... args)
26+ void setExitOnError (const bool exitOnError) noexcept { m_exitOnError = exitOnError; }
27+
28+ // Message only.
29+ void info (const std::string_view message) const { emit (Severity::INFO , std::nullopt , message); }
30+
31+ void warning (const std::string_view message) const { emit (Severity::WARNING , std::nullopt , message); }
32+
33+ [[noreturn]] void error (const std::string_view message) const { emit (Severity::ERR , std::nullopt , message); }
34+
35+ // Range + message.
36+ void info (const std::optional<source::Range> &range, std::string_view message) const ;
37+
38+ void warning (const std::optional<source::Range> &range, std::string_view message) const ;
39+
40+ [[noreturn]] void error (const std::optional<source::Range> &range, std::string_view message) const ;
41+
42+ // Range + DiagnosticId + format args.
43+ template <typename ... Arguments>
44+ void info (const std::optional<source::Range> &range, DiagnosticId id, Arguments &&... args) const
2945 {
30- fmt::dynamic_format_arg_store<fmt::format_context> store;
31- (store.push_back (std::forward<Args>(args)), ...);
32- emit (Severity::ERR , id, range, store);
33- unreachable_impl ();
46+ emitImpl (Severity::INFO , range, id, std::forward<Arguments>(args)...);
3447 }
3548
36- template <typename ... Args>
37- [[noreturn]] void warning (const source::Range &range, const DiagnosticId id, Args &&... args)
49+ template <typename ... Arguments>
50+ void warning (const std::optional<source::Range> &range, DiagnosticId id, Arguments &&... args) const
51+ {
52+ emitImpl (Severity::WARNING , range, id, std::forward<Arguments>(args)...);
53+ }
54+
55+ template <typename ... Arguments>
56+ [[noreturn]] void error (const std::optional<source::Range> &range, DiagnosticId id, Arguments &&... args) const
57+ {
58+ emitImpl (Severity::ERR , range, id, std::forward<Arguments>(args)...);
59+ }
60+
61+ private:
62+ template <typename ... Arguments>
63+ void emitImpl (const Severity severity, const std::optional<source::Range> &range, const DiagnosticId id,
64+ Arguments &&... arguments) const
3865 {
3966 fmt::dynamic_format_arg_store<fmt::format_context> store;
40- (store.push_back (std::forward<Args>(args)), ...);
41- emit (Severity::WARNING , id, range, store);
67+ (store.push_back (std::forward<Arguments>(arguments)), ...);
68+
69+ emit (severity, id, range, store);
4270 }
4371
44- void emit (Severity severity, DiagnosticId id, const source::Range &range,
72+ void emit (Severity severity, DiagnosticId id, const std::optional< source::Range> &range,
4573 const fmt::dynamic_format_arg_store<fmt::format_context> &arguments) const ;
4674
47- void emit (Severity severity, const source::Range &range, const std::string & message) const noexcept ;
75+ void emit (Severity severity, const std::optional< source::Range> &range, std::string_view message) const ;
4876
49- private:
5077 DiagnosticRenderer &diagnosticRenderer;
5178 std::vector<ContextFrame> contextStack;
79+ bool m_exitOnError;
5280 };
5381}
0 commit comments