Skip to content

Commit b6fa3e8

Browse files
committedJan 2, 2018
Factorize source location initialization
1 parent 8da5395 commit b6fa3e8

6 files changed

+23
-46
lines changed
 

‎src/goto-instrument/cover_instrument.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,18 @@ class cover_instrumenter_baset
6161
goto_programt::targett &,
6262
const cover_basic_blockst &) const = 0;
6363

64+
void initialize_source_location(
65+
goto_programt::targett t,
66+
const std::string &comment,
67+
const irep_idt &function) const
68+
{
69+
t->source_location.set_comment(comment);
70+
t->source_location.set(ID_coverage_criterion, coverage_criterion);
71+
t->source_location.set_property_class(property_class);
72+
t->source_location.set_function(function);
73+
t->function = function;
74+
}
75+
6476
bool is_non_cover_assertion(goto_programt::const_targett t) const
6577
{
6678
return t->is_assert() &&

‎src/goto-instrument/cover_instrument_branch.cpp

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,7 @@ void cover_branch_instrumentert::instrument(
3131
goto_programt::targett t = goto_program.insert_before(i_it);
3232
t->make_assertion(false_exprt());
3333
t->source_location = source_location;
34-
t->source_location.set_comment(comment);
35-
t->source_location.set(ID_coverage_criterion, coverage_criterion);
36-
t->source_location.set_property_class(property_class);
37-
t->source_location.set_function(i_it->function);
38-
t->function = i_it->function;
34+
initialize_source_location(t, comment, i_it->function);
3935
}
4036

4137
if(
@@ -50,23 +46,16 @@ void cover_branch_instrumentert::instrument(
5046
exprt guard = i_it->guard;
5147
const irep_idt function = i_it->function;
5248
source_locationt source_location = i_it->source_location;
53-
source_location.set_function(function);
5449

5550
goto_program.insert_before_swap(i_it);
5651
i_it->make_assertion(not_exprt(guard));
5752
i_it->source_location = source_location;
58-
i_it->source_location.set_comment(true_comment);
59-
i_it->source_location.set(ID_coverage_criterion, coverage_criterion);
60-
i_it->source_location.set_property_class(property_class);
61-
i_it->function = function;
53+
initialize_source_location(i_it, true_comment, function);
6254

6355
goto_program.insert_before_swap(i_it);
6456
i_it->make_assertion(guard);
6557
i_it->source_location = source_location;
66-
i_it->source_location.set_comment(false_comment);
67-
i_it->source_location.set(ID_coverage_criterion, coverage_criterion);
68-
i_it->source_location.set_property_class(property_class);
69-
i_it->function = function;
58+
initialize_source_location(i_it, false_comment, function);
7059

7160
std::advance(i_it, 2);
7261
}

‎src/goto-instrument/cover_instrument_condition.cpp

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -37,21 +37,13 @@ void cover_condition_instrumentert::instrument(
3737
goto_program.insert_before_swap(i_it);
3838
i_it->make_assertion(c);
3939
i_it->source_location = source_location;
40-
i_it->source_location.set_comment(comment_t);
41-
i_it->source_location.set(ID_coverage_criterion, coverage_criterion);
42-
i_it->source_location.set_property_class(property_class);
43-
i_it->source_location.set_function(function);
44-
i_it->function = function;
40+
initialize_source_location(i_it, comment_t, function);
4541

4642
const std::string comment_f = "condition `" + c_string + "' false";
4743
goto_program.insert_before_swap(i_it);
4844
i_it->make_assertion(not_exprt(c));
4945
i_it->source_location = source_location;
50-
i_it->source_location.set_comment(comment_f);
51-
i_it->source_location.set(ID_coverage_criterion, coverage_criterion);
52-
i_it->source_location.set_property_class(property_class);
53-
i_it->source_location.set_function(function);
54-
i_it->function = function;
46+
initialize_source_location(i_it, comment_f, function);
5547
}
5648

5749
for(std::size_t i = 0; i < conditions.size() * 2; i++)

‎src/goto-instrument/cover_instrument_decision.cpp

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -37,21 +37,13 @@ void cover_decision_instrumentert::instrument(
3737
goto_program.insert_before_swap(i_it);
3838
i_it->make_assertion(d);
3939
i_it->source_location = source_location;
40-
i_it->source_location.set_comment(comment_t);
41-
i_it->source_location.set(ID_coverage_criterion, coverage_criterion);
42-
i_it->source_location.set_property_class(property_class);
43-
i_it->source_location.set_function(function);
44-
i_it->function = function;
40+
initialize_source_location(i_it, comment_t, function);
4541

4642
const std::string comment_f = "decision `" + d_string + "' false";
4743
goto_program.insert_before_swap(i_it);
4844
i_it->make_assertion(not_exprt(d));
4945
i_it->source_location = source_location;
50-
i_it->source_location.set_comment(comment_f);
51-
i_it->source_location.set(ID_coverage_criterion, coverage_criterion);
52-
i_it->source_location.set_property_class(property_class);
53-
i_it->source_location.set_function(function);
54-
i_it->function = function;
46+
initialize_source_location(i_it, comment_f, function);
5547
}
5648

5749
// advance iterator beyond the inserted instructions

‎src/goto-instrument/cover_instrument_location.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,7 @@ void cover_location_instrumentert::instrument(
4040
goto_program.insert_before_swap(i_it);
4141
i_it->make_assertion(false_exprt());
4242
i_it->source_location = source_location;
43-
i_it->source_location.set_comment(comment);
44-
i_it->source_location.set(ID_coverage_criterion, coverage_criterion);
45-
i_it->source_location.set_property_class(property_class);
46-
i_it->source_location.set_function(function);
47-
i_it->function = function;
43+
initialize_source_location(i_it, comment, function);
4844
i_it++;
4945
}
5046
}

‎src/goto-instrument/cover_instrument_other.cpp

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,8 @@ void cover_assertion_instrumentert::instrument(
3333
if(is_non_cover_assertion(i_it))
3434
{
3535
i_it->guard = false_exprt();
36-
i_it->source_location.set(ID_coverage_criterion, coverage_criterion);
37-
i_it->source_location.set_property_class(property_class);
38-
i_it->source_location.set_function(i_it->function);
36+
initialize_source_location(
37+
i_it, id2string(i_it->source_location.get_comment()), i_it->function);
3938
}
4039
}
4140

@@ -60,10 +59,7 @@ void cover_cover_instrumentert::instrument(
6059
i_it->guard = not_exprt(c);
6160
i_it->type = ASSERT;
6261
i_it->code.clear();
63-
i_it->source_location.set_comment(comment);
64-
i_it->source_location.set(ID_coverage_criterion, coverage_criterion);
65-
i_it->source_location.set_property_class(property_class);
66-
i_it->source_location.set_function(i_it->function);
62+
initialize_source_location(i_it, comment, i_it->function);
6763
}
6864
}
6965
else if(is_non_cover_assertion(i_it))

0 commit comments

Comments
 (0)
Please sign in to comment.