Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
87 changes: 87 additions & 0 deletions compiler/src/dmd/errors.d
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,10 @@ class ErrorSinkCompiler : ErrorSink

void plugSink()
{
if (global.params.v.messageStyle == MessageStyle.diagreport)
{
}

// Exit if there are no collected diagnostics
if (!diagnostics.length) return;

Expand Down Expand Up @@ -452,6 +456,54 @@ private struct DiagnosticContext
bool supplemental; // true if supplemental error
}

/**
* Collects diagnostics for the diagreport messagestyle.
* Params:
* loc = location of error
* format = printf-style format specification
* ap = printf-style variadic arguments
* kind = kind of error being printed
*/
private void collectDiagnostic(const SourceLoc loc, const(char)* format, va_list ap, ErrorKind kind) nothrow
{
// A new primary diagnostic means the previous causal group is complete
/*if (diagnostics.length > 0)
{
completedEvents ~= diagnostics;
diagnostics.length = 0;
}*/

OutBuffer tmp;
tmp.vprintf(format, ap);

Diagnostic d;
d.loc = loc;
d.kind = kind;
d.message = tmp.extractSlice().idup;
diagnostics ~= d;
}

/**
* Collects supplementals of diagnostics for the diagreport messagestyle.
* Params:
* loc = location of error
* format = printf-style format specification
* ap = printf-style variadic arguments
* kind = kind of error being printed
*/
private void collectSupplemental(const SourceLoc loc, const(char)* format, va_list ap, ErrorKind kind) nothrow
{
// Append to the currently open causal group
OutBuffer tmp;
tmp.vprintf(format, ap);

Diagnostic d;
d.loc = loc;
d.kind = kind;
d.message = tmp.extractSlice().idup;
diagnostics ~= d;
}

/**
* Implements $(D error), $(D warning), $(D deprecation), $(D message), and
* $(D tip). Report a diagnostic error, taking a va_list parameter, and
Expand Down Expand Up @@ -487,6 +539,11 @@ private extern(C++) void vreportDiagnostic(const SourceLoc loc, const(char)* for
addSarifDiagnostic(loc, format, ap, kind);
return;
}
if (global.params.v.messageStyle == MessageStyle.diagreport)
{
collectDiagnostic(loc, format, ap, kind);
return;
}
printDiagnostic(format, ap, info);
if (global.params.v.errorLimit && global.errors >= global.params.v.errorLimit)
{
Expand Down Expand Up @@ -521,6 +578,11 @@ private extern(C++) void vreportDiagnostic(const SourceLoc loc, const(char)* for
addSarifDiagnostic(loc, format, ap, kind);
return;
}
if (global.params.v.messageStyle == MessageStyle.diagreport)
{
collectDiagnostic(loc, format, ap, kind);
return;
}
printDiagnostic(format, ap, info);
}
}
Expand All @@ -542,6 +604,11 @@ private extern(C++) void vreportDiagnostic(const SourceLoc loc, const(char)* for
addSarifDiagnostic(loc, format, ap, kind);
return;
}
if (global.params.v.messageStyle == MessageStyle.diagreport)
{
collectDiagnostic(loc, format, ap, kind);
return;
}
printDiagnostic(format, ap, info);
if (global.params.useWarnings == DiagnosticReporting.error)
global.warnings++;
Expand All @@ -558,6 +625,11 @@ private extern(C++) void vreportDiagnostic(const SourceLoc loc, const(char)* for
addSarifDiagnostic(loc, format, ap, kind);
return;
}
if (global.params.v.messageStyle == MessageStyle.diagreport)
{
collectDiagnostic(loc, format, ap, kind);
return;
}
printDiagnostic(format, ap, info);
}
return;
Expand All @@ -578,6 +650,11 @@ private extern(C++) void vreportDiagnostic(const SourceLoc loc, const(char)* for
addSarifDiagnostic(loc, format, ap, kind);
return;
}
if (global.params.v.messageStyle == MessageStyle.diagreport)
{
collectDiagnostic(loc, format, ap, kind);
return;
}
return;
}
}
Expand Down Expand Up @@ -614,6 +691,11 @@ private extern(C++) void vsupplementalDiagnostic(const SourceLoc loc, const(char
}
else
info.headerColor = Classification.error;
if (global.params.v.messageStyle == MessageStyle.diagreport)
{
collectSupplemental(loc, format, ap, kind);
return;
}
printDiagnostic(format, ap, info);
return;

Expand All @@ -625,6 +707,11 @@ private extern(C++) void vsupplementalDiagnostic(const SourceLoc loc, const(char
if (global.params.v.errorLimit == 0 || global.deprecations <= global.params.v.errorLimit)
{
info.headerColor = Classification.deprecation;
if (global.params.v.messageStyle == MessageStyle.diagreport)
{
collectSupplemental(loc, format, ap, kind);
return;
}
printDiagnostic(format, ap, info);
}
}
Expand Down
Loading