diff --git a/include/bolt/Diagnostics.hpp b/include/bolt/Diagnostics.hpp index ddefc9d48..b52420d53 100644 --- a/include/bolt/Diagnostics.hpp +++ b/include/bolt/Diagnostics.hpp @@ -1,8 +1,8 @@ #pragma once -#include #include +#include #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; + } + +}; + } diff --git a/src/ConsolePrinter.cc b/src/ConsolePrinter.cc index c59a56d3d..d6f50b004 100644 --- a/src/ConsolePrinter.cc +++ b/src/ConsolePrinter.cc @@ -1,6 +1,7 @@ // FIXME writeExcerpt does not work well with the last line in a file +#include #include #include @@ -608,6 +609,16 @@ void ConsolePrinter::writeDiagnostic(const Diagnostic& D) { return; } + case DiagnosticKind::OpenFileFailedDiagnostic: + { + auto E = static_cast(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(D);