Skip to content

Commit

Permalink
fixup! parser-json-gcc: read endLine/endColumn if available
Browse files Browse the repository at this point in the history
  • Loading branch information
kdudka committed Apr 3, 2024
1 parent 10afff8 commit e886689
Showing 1 changed file with 14 additions and 16 deletions.
30 changes: 14 additions & 16 deletions src/lib/parser-json-gcc.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@

#include "parser-gcc.hh" // for GccPostProcessor

using std::string;

struct GccTreeDecoder::Private {
GccPostProcessor postProc;
};
Expand All @@ -34,23 +36,23 @@ GccTreeDecoder::~GccTreeDecoder() = default;

static bool gccReadLocRegion(
DefEvent *pEvt,
const pt::ptree &beg,
const pt::ptree &end)
const pt::ptree &start,
const pt::ptree &finish)
{
// read file name
pEvt->fileName = valueOf<std::string>(beg, "file", "<unknown>");
if (pEvt->fileName != valueOf<std::string>(end, "file", "<unknown>"))
pEvt->fileName = valueOf<string>(start, "file", "<unknown>");
if (pEvt->fileName != valueOf<string>(finish, "file", "<unknown>"))
return false;

// read line
if ((pEvt->line = valueOf<int>(beg, "line"))) {
const int endLine = valueOf<int>(end, "line");
if ((pEvt->line = valueOf<int>(start, "line"))) {
const int endLine = valueOf<int>(finish, "line");
pEvt->vSize = diffNums(pEvt->line, endLine);
}

// read column
if ((pEvt->column = valueOf<int>(beg, "byte-column"))) {
const int endColumn = valueOf<int>(end, "byte-column");
if ((pEvt->column = valueOf<int>(start, "byte-column"))) {
const int endColumn = valueOf<int>(finish, "byte-column");
pEvt->hSize = diffNums(pEvt->column, endColumn);
}

Expand All @@ -59,18 +61,16 @@ static bool gccReadLocRegion(

static void gccReadLocation(DefEvent *pEvt, const pt::ptree *locs)
{
using std::string;

if (locs->empty())
return;

const pt::ptree &firstLoc = locs->begin()->second;

// try to read a region between start..finish
const pt::ptree *beg, *end;
if (findChildOf(&beg, firstLoc, "start")
&& findChildOf(&end, firstLoc, "finish")
&& gccReadLocRegion(pEvt, *beg, *end))
const pt::ptree *start, *finish;
if (findChildOf(&start, firstLoc, "start")
&& findChildOf(&finish, firstLoc, "finish")
&& gccReadLocRegion(pEvt, *start, *finish))
return;

// fallback to caret
Expand All @@ -84,8 +84,6 @@ static void gccReadLocation(DefEvent *pEvt, const pt::ptree *locs)

static bool gccReadEvent(DefEvent *pEvt, const pt::ptree &evtNode)
{
using std::string;

// read kind (error, warning, note)
string &evtName = pEvt->event;
evtName = valueOf<string>(evtNode, "kind");
Expand Down

0 comments on commit e886689

Please sign in to comment.