Add support for diagnostics
This commit is contained in:
22
src/Diagnostics/Diagnostic.hpp
Normal file
22
src/Diagnostics/Diagnostic.hpp
Normal file
@@ -0,0 +1,22 @@
|
||||
|
||||
#ifndef PORYGONLANG_DIAGNOSTIC_HPP
|
||||
#define PORYGONLANG_DIAGNOSTIC_HPP
|
||||
|
||||
#include "DiagnosticSeverity.hpp"
|
||||
#include "DiagnosticCode.hpp"
|
||||
|
||||
class Diagnostic{
|
||||
DiagnosticSeverity _severity;
|
||||
DiagnosticCode _code;
|
||||
unsigned int _start;
|
||||
unsigned int _length;
|
||||
public:
|
||||
Diagnostic(DiagnosticSeverity severity, DiagnosticCode code, unsigned int start, unsigned int length){
|
||||
_severity = severity;
|
||||
_code = code;
|
||||
_start = start;
|
||||
_length = length;
|
||||
}
|
||||
};
|
||||
|
||||
#endif //PORYGONLANG_DIAGNOSTIC_HPP
|
||||
9
src/Diagnostics/DiagnosticCode.hpp
Normal file
9
src/Diagnostics/DiagnosticCode.hpp
Normal file
@@ -0,0 +1,9 @@
|
||||
|
||||
#ifndef PORYGONLANG_DIAGNOSTICCODE_HPP
|
||||
#define PORYGONLANG_DIAGNOSTICCODE_HPP
|
||||
|
||||
enum class DiagnosticCode{
|
||||
UnexpectedCharacter,
|
||||
};
|
||||
|
||||
#endif //PORYGONLANG_DIAGNOSTICCODE_HPP
|
||||
11
src/Diagnostics/DiagnosticSeverity.hpp
Normal file
11
src/Diagnostics/DiagnosticSeverity.hpp
Normal file
@@ -0,0 +1,11 @@
|
||||
|
||||
#ifndef PORYGONLANG_DIAGNOSTICSEVERITY_HPP
|
||||
#define PORYGONLANG_DIAGNOSTICSEVERITY_HPP
|
||||
|
||||
enum class DiagnosticSeverity{
|
||||
Info,
|
||||
Warning,
|
||||
Error,
|
||||
};
|
||||
|
||||
#endif //PORYGONLANG_DIAGNOSTICSEVERITY_HPP
|
||||
44
src/Diagnostics/Diagnostics.hpp
Normal file
44
src/Diagnostics/Diagnostics.hpp
Normal file
@@ -0,0 +1,44 @@
|
||||
|
||||
#ifndef PORYGONLANG_DIAGNOSTICS_HPP
|
||||
#define PORYGONLANG_DIAGNOSTICS_HPP
|
||||
|
||||
#include <vector>
|
||||
#include "DiagnosticSeverity.hpp"
|
||||
#include "DiagnosticCode.hpp"
|
||||
#include "Diagnostic.hpp"
|
||||
|
||||
using namespace std;
|
||||
|
||||
class Diagnostics {
|
||||
bool _hasErrors;
|
||||
vector<Diagnostic> _diagnostics;
|
||||
public:
|
||||
Diagnostics(){
|
||||
_hasErrors = false;
|
||||
}
|
||||
|
||||
void Log(DiagnosticSeverity severity, DiagnosticCode code, unsigned int start, unsigned int length){
|
||||
_diagnostics.emplace_back(severity, code, start, length);
|
||||
if (severity >= DiagnosticSeverity::Error){
|
||||
_hasErrors = true;
|
||||
}
|
||||
}
|
||||
void LogError(DiagnosticCode code, unsigned int start, unsigned int length){
|
||||
Log(DiagnosticSeverity::Error, code, start, length);
|
||||
}
|
||||
|
||||
void LogWarning(DiagnosticCode code, unsigned int start, unsigned int length){
|
||||
Log(DiagnosticSeverity::Warning, code, start, length);
|
||||
}
|
||||
|
||||
void LogInfo(DiagnosticCode code, unsigned int start, unsigned int length){
|
||||
Log(DiagnosticSeverity::Info, code, start, length);
|
||||
}
|
||||
|
||||
bool HasErrors(){
|
||||
return _hasErrors;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
#endif //PORYGONLANG_DIAGNOSTICS_HPP
|
||||
Reference in New Issue
Block a user