Add support for diagnostics

This commit is contained in:
2019-05-21 13:56:08 +02:00
parent 26f1ed27a3
commit 2b35da3a7b
11 changed files with 161 additions and 68 deletions

View 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

View File

@@ -0,0 +1,9 @@
#ifndef PORYGONLANG_DIAGNOSTICCODE_HPP
#define PORYGONLANG_DIAGNOSTICCODE_HPP
enum class DiagnosticCode{
UnexpectedCharacter,
};
#endif //PORYGONLANG_DIAGNOSTICCODE_HPP

View File

@@ -0,0 +1,11 @@
#ifndef PORYGONLANG_DIAGNOSTICSEVERITY_HPP
#define PORYGONLANG_DIAGNOSTICSEVERITY_HPP
enum class DiagnosticSeverity{
Info,
Warning,
Error,
};
#endif //PORYGONLANG_DIAGNOSTICSEVERITY_HPP

View 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