Add OpenFileFailedDiagnostic

This commit is contained in:
Sam Vervaeck 2025-02-14 16:13:51 +01:00
parent d4050a6686
commit 76bfa1c0e2
Signed by: samvv
SSH key fingerprint: SHA256:dIg0ywU1OP+ZYifrYxy8c5esO72cIKB+4/9wkZj1VaY
2 changed files with 34 additions and 1 deletions

View file

@ -1,8 +1,8 @@
#pragma once
#include <cwchar>
#include <vector>
#include <filesystem>
#include "bolt/ByteString.hpp"
#include "bolt/String.hpp"
@ -22,6 +22,7 @@ enum class DiagnosticKind : unsigned char {
UnexpectedString,
UnexpectedToken,
TypeMismatchError,
OpenFileFailedDiagnostic,
};
class Diagnostic {
@ -119,4 +120,25 @@ public:
};
class OpenFileFailedDiagnostic : public Diagnostic {
public:
std::filesystem::path Filename;
std::error_code Code;
inline OpenFileFailedDiagnostic(
std::filesystem::path Filename,
std::error_code Code
): Diagnostic(DiagnosticKind::OpenFileFailedDiagnostic), Filename(Filename), Code(Code) {}
inline Node* getNode() const override {
return nullptr;
}
unsigned getCode() const override {
return 101;
}
};
}

View file

@ -1,6 +1,7 @@
// FIXME writeExcerpt does not work well with the last line in a file
#include <cstring>
#include <functional>
#include <cmath>
@ -608,6 +609,16 @@ void ConsolePrinter::writeDiagnostic(const Diagnostic& D) {
return;
}
case DiagnosticKind::OpenFileFailedDiagnostic:
{
auto E = static_cast<const OpenFileFailedDiagnostic&>(D);
write("failed to open file ");
write(E.Filename.c_str());
write(": ");
write(strerror(E.Code.value()));
return;
}
case DiagnosticKind::TypeMismatchError:
{
auto& E = static_cast<const TypeMismatchError&>(D);