Skip to content

Commit 746b8b4

Browse files
committed
parser-json-cov: introduce readEvents() helper method
... to make the code easier to extend. No change in behavior intended. Related: #222
1 parent 20ed4e6 commit 746b8b4

File tree

1 file changed

+34
-25
lines changed

1 file changed

+34
-25
lines changed

src/lib/parser-json-cov.cc

Lines changed: 34 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@
2323

2424
struct CovTreeDecoder::Private {
2525
KeyEventDigger keDigger;
26+
const pt::ptree *pSrc;
27+
28+
void readEvents(Defect *def);
2629
};
2730

2831
CovTreeDecoder::CovTreeDecoder():
@@ -32,15 +35,41 @@ CovTreeDecoder::CovTreeDecoder():
3235

3336
CovTreeDecoder::~CovTreeDecoder() = default;
3437

38+
void CovTreeDecoder::Private::readEvents(Defect *def)
39+
{
40+
// count the events and allocate dst array
41+
const pt::ptree &evtList = this->pSrc->get_child("events");
42+
def->events.resize(evtList.size());
43+
44+
// decode events one by one
45+
unsigned idx = 0;
46+
pt::ptree::const_iterator it;
47+
for (it = evtList.begin(); it != evtList.end(); ++it, ++idx) {
48+
const pt::ptree &evtNode = it->second;
49+
DefEvent &evt = def->events[idx];
50+
51+
evt.fileName = valueOf<std::string>(evtNode, "filePathname");
52+
evt.line = valueOf<int> (evtNode, "lineNumber");
53+
evt.column = valueOf<int> (evtNode, "columnNumber");
54+
evt.event = valueOf<std::string>(evtNode, "eventTag");
55+
evt.msg = valueOf<std::string>(evtNode, "eventDescription");
56+
57+
if (evtNode.get<bool>("main"))
58+
// this is a key event
59+
// TODO: detect and report re-definitions of key events
60+
def->keyEventIdx = idx;
61+
}
62+
}
63+
3564
bool CovTreeDecoder::readNode(Defect *def)
3665
{
3766
// move the iterator after we get the current position
38-
const pt::ptree *pNode = this->nextNode();
39-
if (!pNode)
67+
d->pSrc = this->nextNode();
68+
if (!d->pSrc)
4069
// failed initialization or EOF
4170
return false;
4271

43-
const pt::ptree &defNode = *pNode;
72+
const pt::ptree &defNode = *d->pSrc;
4473

4574
// read per-defect properties
4675
def->checker = defNode.get<std::string>("checkerName");
@@ -61,28 +90,8 @@ bool CovTreeDecoder::readNode(Defect *def)
6190
def->imp = 1;
6291
}
6392

64-
// count the events and allocate dst array
65-
const pt::ptree &evtList = defNode.get_child("events");
66-
def->events.resize(evtList.size());
67-
68-
// decode events one by one
69-
unsigned idx = 0;
70-
pt::ptree::const_iterator it;
71-
for (it = evtList.begin(); it != evtList.end(); ++it, ++idx) {
72-
const pt::ptree &evtNode = it->second;
73-
DefEvent &evt = def->events[idx];
74-
75-
evt.fileName = valueOf<std::string>(evtNode, "filePathname");
76-
evt.line = valueOf<int> (evtNode, "lineNumber");
77-
evt.column = valueOf<int> (evtNode, "columnNumber");
78-
evt.event = valueOf<std::string>(evtNode, "eventTag");
79-
evt.msg = valueOf<std::string>(evtNode, "eventDescription");
80-
81-
if (evtNode.get<bool>("main"))
82-
// this is a key event
83-
// TODO: detect and report re-definitions of key events
84-
def->keyEventIdx = idx;
85-
}
93+
// read all events
94+
d->readEvents(def);
8695

8796
// initialize verbosity level of all events
8897
d->keDigger.initVerbosity(def);

0 commit comments

Comments
 (0)