Skip to content

Commit faa637d

Browse files
committed
parser-json-cov: detect redefinition of key events
Related: #222
1 parent 802fb19 commit faa637d

File tree

3 files changed

+20
-6
lines changed

3 files changed

+20
-6
lines changed

src/lib/parser-json-cov.cc

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,19 @@
2323

2424
struct CovTreeDecoder::Private {
2525
KeyEventDigger keDigger;
26+
InStream &input;
2627
const pt::ptree *pSrc;
2728

29+
Private(InStream &input_):
30+
input(input_)
31+
{
32+
}
33+
2834
void readEvents(Defect *def);
2935
};
3036

31-
CovTreeDecoder::CovTreeDecoder():
32-
d(new Private)
37+
CovTreeDecoder::CovTreeDecoder(InStream &input):
38+
d(new Private(input))
3339
{
3440
}
3541

@@ -50,10 +56,18 @@ void CovTreeDecoder::Private::readEvents(Defect *def)
5056
evt.event = valueOf<std::string>(evtNode, "eventTag");
5157
evt.msg = valueOf<std::string>(evtNode, "eventDescription");
5258

53-
if (evtNode.get<bool>("main"))
59+
if (evtNode.get<bool>("main")) {
5460
// this is a key event
55-
// TODO: detect and report re-definitions of key events
61+
62+
if (def->keyEventIdx)
63+
// key event redefinition (TODO: more detailed diagnostic msg)
64+
std::cerr << this->input.fileName()
65+
<< ": warning: key event redefinition detected"
66+
<< std::endl;
67+
68+
// record key event index
5669
def->keyEventIdx = def->events.size();
70+
}
5771

5872
// push the event to the list of events
5973
def->events.push_back(std::move(evt));

src/lib/parser-json-cov.hh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
/// tree decoder of the Coverity JSON format
2626
class CovTreeDecoder: public AbstractTreeDecoder {
2727
public:
28-
CovTreeDecoder();
28+
CovTreeDecoder(InStream &input);
2929
~CovTreeDecoder() override;
3030
bool readNode(Defect *def) override;
3131

src/lib/parser-json.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ JsonParser::JsonParser(InStream &input):
8989
d->decoder.reset(new SimpleTreeDecoder(d->input));
9090
else if (findChildOf(&node, d->root, "issues"))
9191
// Coverity JSON format
92-
d->decoder.reset(new CovTreeDecoder);
92+
d->decoder.reset(new CovTreeDecoder(d->input));
9393
else if (findChildOf(&node, d->root, "runs"))
9494
// SARIF format
9595
d->decoder.reset(new SarifTreeDecoder);

0 commit comments

Comments
 (0)