aboutsummaryrefslogtreecommitdiff
path: root/backend/include/rcc/Support/TextDiagnostic.h
diff options
context:
space:
mode:
authorRichard-Qin-X <richard.qin.001@gmail.com>2026-08-01 16:47:16 +0800
committerRichard-Qin-X <richard.qin.001@gmail.com>2026-08-01 16:47:16 +0800
commit85eed8fb2d6563fea750f7b55730c9feaecc5898 (patch)
tree81663a7028c73e245ce573cd6b52e2a751146cd6 /backend/include/rcc/Support/TextDiagnostic.h
parent924dcd36ebed84f04729de05ec08b311a36a04c1 (diff)
downloadrcc-project-85eed8fb2d6563fea750f7b55730c9feaecc5898.tar.gz
rcc-project-85eed8fb2d6563fea750f7b55730c9feaecc5898.tar.xz
[Support] Add MIR YAML parsing infrastructure
Introduce source ranges, deterministic text diagnostics, and an independently authored YAML stream parser for the fixed LLVM MIR container shapes. Record the compatibility matrix and Stage 6 validation state.
Diffstat (limited to 'backend/include/rcc/Support/TextDiagnostic.h')
-rw-r--r--backend/include/rcc/Support/TextDiagnostic.h83
1 files changed, 83 insertions, 0 deletions
diff --git a/backend/include/rcc/Support/TextDiagnostic.h b/backend/include/rcc/Support/TextDiagnostic.h
new file mode 100644
index 0000000..4c21486
--- /dev/null
+++ b/backend/include/rcc/Support/TextDiagnostic.h
@@ -0,0 +1,83 @@
+// SPDX-License-Identifier: GPL-3.0-or-later
+
+#ifndef RCC_SUPPORT_TEXTDIAGNOSTIC_H
+#define RCC_SUPPORT_TEXTDIAGNOSTIC_H
+
+#include <cstddef>
+#include <span>
+#include <string>
+#include <string_view>
+#include <vector>
+
+namespace rcc {
+
+struct TextPosition final {
+ std::size_t Offset = 0;
+ std::size_t Line = 1;
+ std::size_t Column = 1;
+
+ friend constexpr bool operator==(TextPosition Left, TextPosition Right) noexcept = default;
+};
+
+struct TextRange final {
+ TextPosition Begin;
+ TextPosition End;
+
+ [[nodiscard]] constexpr bool isOrdered() const noexcept {
+ return Begin.Offset <= End.Offset;
+ }
+
+ friend constexpr bool operator==(TextRange Left, TextRange Right) noexcept = default;
+};
+
+enum class DiagnosticSeverity : unsigned char {
+ Note,
+ Warning,
+ Error,
+};
+
+[[nodiscard]] std::string_view getDiagnosticSeverityName(DiagnosticSeverity Severity) noexcept;
+
+struct TextDiagnostic final {
+ DiagnosticSeverity Severity = DiagnosticSeverity::Error;
+ std::string Category;
+ std::string Message;
+ std::string SourceName;
+ TextRange Range;
+};
+
+class TextSource final {
+public:
+ TextSource(std::string Name, std::string Text);
+
+ [[nodiscard]] std::string_view name() const noexcept {
+ return Name;
+ }
+
+ [[nodiscard]] std::string_view text() const noexcept {
+ return Text;
+ }
+
+ [[nodiscard]] std::size_t lineCount() const noexcept {
+ return LineOffsets.size();
+ }
+
+ [[nodiscard]] TextPosition positionAt(std::size_t Offset) const noexcept;
+ [[nodiscard]] TextRange range(std::size_t Begin, std::size_t End) const noexcept;
+ [[nodiscard]] std::string_view line(std::size_t OneBasedLine) const noexcept;
+ [[nodiscard]] std::span<const std::size_t> lineOffsets() const noexcept {
+ return LineOffsets;
+ }
+
+private:
+ std::string Name;
+ std::string Text;
+ std::vector<std::size_t> LineOffsets;
+};
+
+[[nodiscard]] std::string formatTextDiagnostic(const TextDiagnostic &Diagnostic,
+ const TextSource &Source);
+
+} // namespace rcc
+
+#endif // RCC_SUPPORT_TEXTDIAGNOSTIC_H