Add OpenFileFailedDiagnostic
This commit is contained in:
parent
d4050a6686
commit
76bfa1c0e2
2 changed files with 34 additions and 1 deletions
|
@ -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;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue