Create entry point to get diagnostic string message
continuous-integration/drone/push Build is passing Details

This commit is contained in:
Deukhoofd 2019-06-19 13:37:39 +02:00
parent 6bcedaf743
commit 7958576b6a
No known key found for this signature in database
GPG Key ID: B4C087AC81641654
3 changed files with 18 additions and 13 deletions

View File

@ -97,25 +97,30 @@ const string PrettyDiagnostic ( const char * format, vector<string> arguments)
return result;
}
std::string DiagnosticsHolder::GetFullErrorMessage(Diagnostic diagnostic) {
std::string DiagnosticsHolder::GetFullDiagnostic(Diagnostic* diagnostic) {
stringstream stream;
stream << "[" << SeverityToString(diagnostic.GetSeverity()) << "] ";
auto startPos = diagnostic.GetStartPosition();
stream << "[" << SeverityToString(diagnostic->GetSeverity()) << "] ";
auto startPos = diagnostic->GetStartPosition();
auto line = this -> GetLineFromPosition(startPos);
auto linePos = startPos - this ->GetStartPositionForLine(line);
stream << " (" << line + 1 << ", " << linePos + 1 << ") ";
auto unformatted = ErrorMessages.find(diagnostic.GetCode());
auto unformatted = ErrorMessages.find(diagnostic->GetCode());
if (unformatted != ErrorMessages.end()){
stream << PrettyDiagnostic(unformatted->second, diagnostic.GetArguments());
stream << PrettyDiagnostic(unformatted->second, diagnostic->GetArguments());
}
return stream.str();
}
extern "C" int GetDiagnosticsCount (DiagnosticsHolder* diagnostics){
return diagnostics->DiagnosticsCount();
}
extern "C" {
int GetDiagnosticsCount (DiagnosticsHolder* diagnostics){
return diagnostics->DiagnosticsCount();
}
extern "C" Diagnostic* GetDiagnosticAt(DiagnosticsHolder* diagnostics, int position){
return diagnostics->GetDiagnosticAt(position);
}
Diagnostic* GetDiagnosticAt(DiagnosticsHolder* diagnostics, int position){
return diagnostics->GetDiagnosticAt(position);
}
const char* GetFullDiagnostic(DiagnosticsHolder* diagnostics, Diagnostic* diag){
return diagnostics ->GetFullDiagnostic(diag).c_str();
}
}

View File

@ -58,7 +58,7 @@ namespace Porygon::Diagnostics {
return _lineStarts[i];
}
std::string GetFullErrorMessage(Diagnostic diagnostic);
std::string GetFullDiagnostic(Diagnostic* diagnostic);
};
}

View File

@ -47,7 +47,7 @@ TEST_CASE( "Get full diagnostic message", "[integration]" ) {
)");
REQUIRE(script->Diagnostics -> HasErrors());
auto diags = script->Diagnostics -> GetDiagnostics();
auto msg = script -> Diagnostics -> GetFullErrorMessage(diags[0]);
auto msg = script->Diagnostics->GetFullDiagnostic(&diags[0]);
REQUIRE(msg == "[Error] (2, 2) '\\x' is not a valid control character.");
delete script;
}