Skip to content

Commit f70eadf

Browse files
lucasccordeiropeterschrammel
authored andcommitted
implement get_coverage method
Signed-off-by: Lucas Cordeiro <[email protected]>
1 parent 143b53e commit f70eadf

File tree

4 files changed

+62
-0
lines changed

4 files changed

+62
-0
lines changed

src/goto-instrument/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ OBJ += ../ansi-c/ansi-c$(LIBEXT) \
3737
../langapi/langapi$(LIBEXT) \
3838
../xmllang/xmllang$(LIBEXT) \
3939
../util/util$(LIBEXT) \
40+
../json/json$(LIBEXT) \
4041
../solvers/solvers$(LIBEXT)
4142

4243
INCLUDES= -I ..

src/goto-instrument/cover.cpp

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ Date: May 2016
1616
#include <util/prefix.h>
1717
#include <util/string2int.h>
1818

19+
#include <json/json_parser.h>
20+
1921
#include "cover.h"
2022

2123
class basic_blockst
@@ -98,6 +100,62 @@ class basic_blockst
98100

99101
/*******************************************************************\
100102
103+
Function: coverage_goalst::get_coverage
104+
105+
Inputs:
106+
107+
Outputs:
108+
109+
Purpose:
110+
111+
\*******************************************************************/
112+
113+
void coverage_goalst::get_coverage(const std::string &coverage,
114+
message_handlert &message_handler)
115+
{
116+
jsont json;
117+
118+
//check coverage file
119+
if(parse_json(coverage, message_handler, json))
120+
{
121+
messaget message(message_handler);
122+
message.error() << coverage << " file is not a valid json file"
123+
<< messaget::eom;
124+
exit(0);
125+
}
126+
127+
//make sure that we have an array of elements
128+
if(!json.is_array())
129+
{
130+
messaget message(message_handler);
131+
message.error() << "expecting an array in the " << coverage << " file, but got "
132+
<< json << messaget::eom;
133+
exit(0);
134+
}
135+
136+
for(jsont::arrayt::const_iterator
137+
it=json.array.begin();
138+
it!=json.array.end();
139+
it++)
140+
{
141+
//get the goals array
142+
if ((*it)["goals"].is_array())
143+
{
144+
for(jsont::arrayt::const_iterator
145+
itg=(*it)["goals"].array.begin();
146+
itg!=(*it)["goals"].array.end();
147+
itg++)
148+
{
149+
//get the line of each existing goal
150+
const std::string line=(*itg)["sourceLocation"]["line"].value;
151+
set_goals(line);
152+
}
153+
}
154+
}
155+
}
156+
157+
/*******************************************************************\
158+
101159
Function: coverage_goalst::set_goals
102160
103161
Inputs:

src/goto-instrument/cover.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ Date: May 2016
1616
class coverage_goalst
1717
{
1818
public:
19+
void get_coverage(const std::string &coverage,
20+
message_handlert &message_handler);
1921
void set_goals(std::string goal);
2022
bool is_existing_goal(source_locationt source_location);
2123

src/symex/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ OBJ += ../ansi-c/ansi-c$(LIBEXT) \
1616
../goto-symex/rewrite_union$(OBJEXT) \
1717
../pointer-analysis/dereference$(OBJEXT) \
1818
../goto-instrument/cover$(OBJEXT) \
19+
../json/json$(LIBEXT) \
1920
../path-symex/path-symex$(LIBEXT)
2021

2122
INCLUDES= -I ..

0 commit comments

Comments
 (0)