PorygonLang/src/Diagnostics/Diagnostics.hpp

53 lines
1.3 KiB
C++

#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;
}
~Diagnostics(){
_diagnostics.clear();
}
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;
}
vector<Diagnostic> GetDiagnostics(){
return _diagnostics;
}
};
#endif //PORYGONLANG_DIAGNOSTICS_HPP