@@ -130,33 +130,27 @@ namespace pl::core::err {
130130 std::vector<Location> m_trace;
131131 };
132132
133- class ErrorCollector {
133+ class ErrorCollectorExplicitLocation
134+ {
134135 public:
135-
136- virtual ~ErrorCollector () = default ;
137-
138- virtual Location location () = 0;
136+ virtual ~ErrorCollectorExplicitLocation () = default ;
139137
140138 template <typename ... Args>
141- void error (const fmt::format_string<Args...>& fmt, Args&&... args) {
142- this ->m_errors .emplace_back (fmt::format (fmt, std::forward<Args>(args)...), location () );
139+ void error (const Location &location, const fmt::format_string<Args...> & fmt, Args&&... args) {
140+ this ->m_errors .emplace_back (fmt::format (fmt, std::forward<Args>(args)...), location);
143141 }
144142
145- void error (const std::string &message) {
146- this ->m_errors .emplace_back (message, location ());
147- }
148-
149- void errorDesc (const std::string &message, const std::string &description) {
150- this ->m_errors .emplace_back (message, description, location ());
143+ void errorDesc (const Location &location, const std::string &message, const std::string &description) {
144+ this ->m_errors .emplace_back (message, description, location);
151145 }
152146
153147 template <typename ... Args>
154- void errorDesc (const fmt::format_string<Args...>& message, const std::string &description, Args&&... args) {
155- this ->m_errors .emplace_back (fmt::format (message, std::forward<Args>(args)...), description, location () );
148+ void errorDesc (const Location &location, const fmt::format_string<Args...>& message, const std::string &description, Args&&... args) {
149+ this ->m_errors .emplace_back (fmt::format (message, std::forward<Args>(args)...), description, location);
156150 }
157151
158- void error (CompileError& error) {
159- error.getTrace ().push_back (location () );
152+ void error (const Location &location, CompileError& error) {
153+ error.getTrace ().push_back (location);
160154 this ->m_errors .push_back (std::move (error));
161155 }
162156
@@ -188,8 +182,39 @@ namespace pl::core::err {
188182 void clear () {
189183 this ->m_errors .clear ();
190184 }
185+
191186 private:
192187 std::vector<CompileError> m_errors;
193188 };
194189
190+ class ErrorCollector : public ErrorCollectorExplicitLocation {
191+ public:
192+
193+ virtual ~ErrorCollector () = default ;
194+
195+ virtual Location location () = 0;
196+
197+ template <typename ... Args>
198+ void error (const fmt::format_string<Args...> &fmt, Args&&... args) {
199+ this ->ErrorCollectorExplicitLocation ::error (location (), fmt, std::forward<Args>(args)...);
200+ }
201+
202+ void error (const std::string &message) {
203+ this ->errorAt (location (), message);
204+ }
205+
206+ void errorDesc (const std::string &message, const std::string &description) {
207+ this ->ErrorCollectorExplicitLocation ::errorDesc (location (), message, description);
208+ }
209+
210+ template <typename ... Args>
211+ void errorDesc (const fmt::format_string<Args...>& message, const std::string &description, Args&&... args) {
212+ this ->ErrorCollectorExplicitLocation ::errorDesc (location (), message, description, std::forward<Args>(args)...);
213+ }
214+
215+ void error (CompileError& error) {
216+ this ->ErrorCollectorExplicitLocation ::error (location (), error);
217+ }
218+ };
219+
195220}
0 commit comments