Skip to content

Commit 99a5489

Browse files
lucasccordeirotautschnig
authored andcommitted
method to construct a coverage_goalst object
1 parent b531025 commit 99a5489

File tree

2 files changed

+51
-2
lines changed

2 files changed

+51
-2
lines changed

src/goto-instrument/cover.cpp

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,55 @@ class basic_blockst
102102
}
103103
};
104104

105+
coverage_goalst coverage_goalst::get_coverage_goals(const std::string &coverage,
106+
message_handlert &message_handler)
107+
{
108+
jsont json;
109+
coverage_goalst goals;
110+
source_locationt source_location;
111+
112+
//check coverage file
113+
if(parse_json(coverage, message_handler, json))
114+
{
115+
messaget message(message_handler);
116+
message.error() << coverage << " file is not a valid json file"
117+
<< messaget::eom;
118+
exit(0);
119+
}
120+
121+
//make sure that we have an array of elements
122+
if(!json.is_array())
123+
{
124+
messaget message(message_handler);
125+
message.error() << "expecting an array in the " << coverage << " file, but got "
126+
<< json << messaget::eom;
127+
exit(0);
128+
}
129+
130+
irep_idt line_number;
131+
for(jsont::arrayt::const_iterator
132+
it=json.array.begin();
133+
it!=json.array.end();
134+
it++)
135+
{
136+
//get the goals array
137+
if ((*it)["goals"].is_array())
138+
{
139+
for(jsont::arrayt::const_iterator
140+
itg=(*it)["goals"].array.begin();
141+
itg!=(*it)["goals"].array.end();
142+
itg++)
143+
{
144+
//get the line of each existing goal
145+
line_number=(*itg)["sourceLocation"]["line"].value;
146+
source_location.set_line(line_number);
147+
goals.set_goals(source_location);
148+
}
149+
}
150+
}
151+
return goals;
152+
}
153+
105154
bool coverage_goalst::is_existing_goal(source_locationt source_location)
106155
{
107156
std::vector<source_locationt>::iterator it = existing_goals.begin();

src/goto-instrument/cover.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ class message_handlert;
2222
class coverage_goalst
2323
{
2424
public:
25-
void get_coverage(const std::string &coverage,
26-
message_handlert &message_handler);
25+
static coverage_goalst get_coverage_goals(const std::string &coverage,
26+
message_handlert &message_handler);
2727
void set_goals(source_locationt goal);
2828
bool is_existing_goal(source_locationt source_location);
2929

0 commit comments

Comments
 (0)