Skip to content

Commit

Permalink
Use SourceLoc for generateSarifReport
Browse files Browse the repository at this point in the history
  • Loading branch information
dkorpel authored and thewilsonator committed Oct 24, 2024
1 parent afd4c4d commit 4b94c9f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 14 deletions.
15 changes: 4 additions & 11 deletions compiler/src/dmd/errors.d
Original file line number Diff line number Diff line change
Expand Up @@ -476,11 +476,9 @@ private extern(C++) void verrorReport(const SourceLoc loc, const(char)* format,
info.headerColor = Classification.error;
verrorPrint(format, ap, info);

// Fix: Convert filename to const(char)* using .ptr
Loc sourceLoc = Loc(info.loc.filename.ptr, info.loc.linnum, info.loc.charnum);
if (global.params.v.messageStyle == MessageStyle.sarif)
{
generateSarifReport(sourceLoc, format, ap, info.kind);
generateSarifReport(loc, format, ap, info.kind);
}
if (global.params.v.errorLimit && global.errors >= global.params.v.errorLimit)
{
Expand Down Expand Up @@ -512,11 +510,9 @@ private extern(C++) void verrorReport(const SourceLoc loc, const(char)* format,
info.headerColor = Classification.deprecation;
verrorPrint(format, ap, info);

// Fix: Convert filename to const(char)* using .ptr
Loc sourceLoc = Loc(info.loc.filename.ptr, info.loc.linnum, info.loc.charnum);
if (global.params.v.messageStyle == MessageStyle.sarif)
{
generateSarifReport(sourceLoc, format, ap, info.kind);
generateSarifReport(loc, format, ap, info.kind);
}
}
}
Expand Down Expand Up @@ -551,10 +547,9 @@ private extern(C++) void verrorReport(const SourceLoc loc, const(char)* format,
verrorPrint(format, ap, info);

// Fix: Convert filename to const(char)* using .ptr
Loc sourceLoc = Loc(info.loc.filename.ptr, info.loc.linnum, info.loc.charnum);
if (global.params.v.messageStyle == MessageStyle.sarif)
{
generateSarifReport(sourceLoc, format, ap, info.kind);
generateSarifReport(loc, format, ap, info.kind);
}
}
return;
Expand All @@ -570,11 +565,9 @@ private extern(C++) void verrorReport(const SourceLoc loc, const(char)* format,
fputs(tmp.peekChars(), stdout);
fputc('\n', stdout);
fflush(stdout); // ensure it gets written out in case of compiler aborts
// Fix: Convert filename to const(char)* using .ptr
Loc sourceLoc = Loc(info.loc.filename.ptr, info.loc.linnum, info.loc.charnum);
if (global.params.v.messageStyle == MessageStyle.sarif)
{
generateSarifReport(sourceLoc, format, ap, info.kind);
generateSarifReport(loc, format, ap, info.kind);
}
return;
}
Expand Down
7 changes: 4 additions & 3 deletions compiler/src/dmd/sarif.d
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ string formatErrorMessage(const(char)* format, va_list ap) nothrow
return buffer[0 .. buffer.length].dup;
}

void generateSarifReport(const ref Loc loc, const(char)* format, va_list ap, ErrorKind kind) nothrow
void generateSarifReport(const ref SourceLoc loc, const(char)* format, va_list ap, ErrorKind kind) nothrow
{
// Format the error message
string formattedMessage = formatErrorMessage(format, ap);
Expand Down Expand Up @@ -155,8 +155,9 @@ void generateSarifReport(const ref Loc loc, const(char)* format, va_list ap, Err
ob.writestringln(`"locations": [{`);
ob.writestringln(`"physicalLocation": {`);
ob.writestringln(`"artifactLocation": {`);
ob.printf(`"uri": "%s"`, loc.filename);
ob.writestringln("},");
ob.writestring(`"uri": "`);
ob.writestring(loc.filename);
ob.writestringln(`"},`);
ob.writestringln(`"region": {`);
ob.printf(`"startLine": %d,`, loc.linnum);
ob.printf(`"startColumn": %d`, loc.charnum);
Expand Down

0 comments on commit 4b94c9f

Please sign in to comment.