summaryrefslogtreecommitdiff
path: root/willow/lib/IR/DiagnosticEngine.cpp
diff options
context:
space:
mode:
authorStefan Weigl-Bosker <stefan@s00.xyz>2026-02-19 18:45:44 -0500
committerStefan Weigl-Bosker <stefan@s00.xyz>2026-02-19 18:45:44 -0500
commitaf3d0ad1926eb825f64152cf217fc9a4777f0be3 (patch)
tree8d7f73ce6c3c89863418382d8d553a06c668bbb3 /willow/lib/IR/DiagnosticEngine.cpp
parentd11fbc8268f5775ad783f8570478daad4a9e81cf (diff)
downloadcompiler-more-tests.tar.gz
[willow]: more cleanup, testsmore-tests
Diffstat (limited to 'willow/lib/IR/DiagnosticEngine.cpp')
-rw-r--r--willow/lib/IR/DiagnosticEngine.cpp28
1 files changed, 28 insertions, 0 deletions
diff --git a/willow/lib/IR/DiagnosticEngine.cpp b/willow/lib/IR/DiagnosticEngine.cpp
new file mode 100644
index 0000000..f0cc280
--- /dev/null
+++ b/willow/lib/IR/DiagnosticEngine.cpp
@@ -0,0 +1,28 @@
+#include <willow/IR/DiagnosticEngine.h>
+
+namespace willow {
+
+void DiagnosticEngine::report(Diagnostic d) {
+ if (handler)
+ handler(std::move(d));
+}
+
+DiagnosticBuilder::DiagnosticBuilder(DiagnosticBuilder &&other) noexcept
+ : engine(std::exchange(other.engine, nullptr)), diag(std::move(other.diag)),
+ os(std::move(other.os)) {}
+DiagnosticBuilder::~DiagnosticBuilder() {
+ if (!engine) // was moved from
+ return;
+
+ diag.message += os.str();
+ engine->report(std::move(diag));
+}
+
+DiagnosticBuilder::DiagnosticBuilder(DiagnosticEngine &eng, Severity severity,
+ std::optional<Location> loc)
+ : engine(&eng) {
+ diag.severity = severity;
+ diag.location = loc;
+}
+
+} // namespace willow