Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

parser-json-sarif: attempt to read generic trace events #199

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
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
34 changes: 22 additions & 12 deletions src/lib/parser-json-sarif.cc
Original file line number Diff line number Diff line change
Expand Up @@ -270,25 +270,28 @@ static void sarifReadCodeFlow(Defect *pDef, const pt::ptree &cf)
for (const auto &item : *locs) {
const pt::ptree &tfLoc = item.second;

const pt::ptree *kindList;
if (!findChildOf(&kindList, tfLoc, "kinds") || kindList->empty())
// kind of the event not specified
continue;

// concatenate event name
std::string evtName;
for (const auto &kindItem : *kindList) {
const pt::ptree &kind = kindItem.second;
if (!evtName.empty())
evtName += "_";
evtName += kind.data();
const pt::ptree *kindList;
if (findChildOf(&kindList, tfLoc, "kinds")) {
// calculate event name from the `kinds` list
for (const auto &kindItem : *kindList) {
const pt::ptree &kind = kindItem.second;
if (!evtName.empty())
evtName += "_";
evtName += kind.data();
}
}

// append a new event of the specified kind
events.push_back(DefEvent(evtName));
DefEvent &evt = events.back();

evt.verbosityLevel = valueOf<int>(tfLoc, "nestingLevel", 1);
// read/infer verbosity level
evt.verbosityLevel = valueOf<int>(tfLoc, "nestingLevel",
(evt.event.empty())
? /* trace */ 2
: /* info */ 1);

if (!evt.verbosityLevel)
// update key event
keyEventIdx = events.size() - 1U;
Expand All @@ -300,6 +303,13 @@ static void sarifReadCodeFlow(Defect *pDef, const pt::ptree &cf)

sarifReadLocation(&evt, *loc);
sarifReadMsg(&evt.msg, *loc);

if (evt.event.empty()) {
// if no `kind` is given, assume a generic trace event
evt.event = "path";
if (evt.msg.empty())
evt.msg = "generic trace event";
}
}

if (events.size() <= 1U)
Expand Down
Loading