summaryrefslogtreecommitdiffhomepage
path: root/dev/CompilerKit/ErrorOr.h
diff options
context:
space:
mode:
authorAmlal El Mahrouss <amlal@nekernel.org>2025-07-30 08:50:15 +0100
committerAmlal El Mahrouss <amlal@nekernel.org>2025-07-30 08:50:15 +0100
commit1c8c5cff67b20d86c442b0917d6c1fc6407140df (patch)
tree53ebea660bef14cdc2ff5b7ebefb4049f705f997 /dev/CompilerKit/ErrorOr.h
parent073811d89c98d6e1c078a032ca2eedefebf80384 (diff)
feat! Breaking API changes of NeCTI's LibCompiler and LibDebugger.
what: - They've now become CompilerKit and DebuggerKit. - Expanding XCoff for NeBoot PowerPC backend. Signed-off-by: Amlal El Mahrouss <amlal@nekernel.org>
Diffstat (limited to 'dev/CompilerKit/ErrorOr.h')
-rw-r--r--dev/CompilerKit/ErrorOr.h50
1 files changed, 50 insertions, 0 deletions
diff --git a/dev/CompilerKit/ErrorOr.h b/dev/CompilerKit/ErrorOr.h
new file mode 100644
index 0000000..700da23
--- /dev/null
+++ b/dev/CompilerKit/ErrorOr.h
@@ -0,0 +1,50 @@
+/*
+ * ========================================================
+ *
+ * CompilerKit
+ * Copyright (C) 2024-2025 Amlal El Mahrouss, all rights reserved.
+ *
+ * ========================================================
+ */
+
+#pragma once
+
+#include <CompilerKit/Defines.h>
+#include <CompilerKit/ErrorID.h>
+#include <CompilerKit/Ref.h>
+
+namespace CompilerKit {
+using ErrorT = UInt32;
+
+template <typename T>
+class ErrorOr final {
+ public:
+ ErrorOr() = default;
+ ~ErrorOr() = default;
+
+ public:
+ explicit ErrorOr(Int32 err) : mId(err) {}
+
+ explicit ErrorOr(nullPtr Null) {}
+
+ explicit ErrorOr(T Class) : mRef(Class) {}
+
+ ErrorOr& operator=(const ErrorOr&) = default;
+ ErrorOr(const ErrorOr&) = default;
+
+ Ref<T> Leak() { return mRef; }
+
+ Int32 Error() { return mId; }
+
+ BOOL HasError() { return mId != LIBCOMPILER_SUCCESS; }
+
+ operator bool() { return mRef; }
+
+ private:
+ Ref<T> mRef;
+ Int32 mId{0};
+};
+
+using ErrorOrAny = ErrorOr<voidPtr>;
+
+} // namespace CompilerKit