26 const std::vector<exprt> &conditions,
27 std::set<exprt> &result)
30 if(src.
id() == ID_and || src.
id() == ID_or)
32 std::vector<exprt> operands;
35 if(operands.size() == 1)
37 exprt e = *operands.begin();
40 else if(!operands.empty())
42 for(std::size_t i = 0; i < operands.size(); i++)
44 const exprt op = operands[i];
50 std::vector<exprt> others1, others2;
51 if(!conditions.empty())
57 for(std::size_t j = 0; j < operands.size(); j++)
59 others1.push_back(
not_exprt(operands[j]));
61 others2.push_back(
not_exprt(operands[j]));
63 others2.push_back((operands[j]));
71 std::vector<exprt> o = operands;
74 std::vector<exprt> new_conditions = conditions;
84 std::vector<exprt> others;
85 others.reserve(operands.size() - 1);
87 for(std::size_t j = 0; j < operands.size(); j++)
93 others.push_back(operands[j]);
97 std::vector<exprt> new_conditions = conditions;
98 new_conditions.push_back(c);
105 else if(src.
id() == ID_not)
113 std::vector<exprt> new_conditions1 = conditions;
114 new_conditions1.push_back(src);
118 std::vector<exprt> new_conditions2 = conditions;
119 new_conditions2.push_back(e);
133 std::set<exprt> result;
135 for(
const auto &d : decisions)
144 const std::set<exprt> &replacement_exprs,
145 const std::vector<exprt> &operands,
148 std::set<exprt> result;
149 for(
auto &y : replacement_exprs)
151 std::vector<exprt> others;
152 for(std::size_t j = 0; j < operands.size(); j++)
154 others.push_back(operands[j]);
171 std::set<exprt> result;
174 for(
auto &src : controlling)
176 std::set<exprt>
s1,
s2;
187 bool changed =
false;
200 std::vector<exprt> operands;
203 for(std::size_t i = 0; i < operands.size(); i++)
209 if(operands[i].
id() == ID_not)
215 std::set<exprt> ctrl_no;
223 std::set<exprt> ctrl;
224 ctrl.insert(operands[i]);
230 s2.insert(co.begin(), co.end());
248 result.insert(
s1.begin(),
s1.end());
260 std::set<signed> signs;
282 std::vector<exprt> ops;
284 for(
const auto &x : ops)
288 else if(x.id() == ID_not)
296 signs.insert(re.begin(), re.end());
302 signs.insert(re.begin(), re.end());
315 std::set<exprt> conditions;
319 conditions.insert(new_conditions.begin(), new_conditions.end());
323 std::set<exprt> new_exprs;
327 for(
auto &c : conditions)
349 for(
auto &y : new_exprs)
352 for(
auto &c : conditions)
356 int s1 = signs1.size(),
s2 = signs2.size();
365 if(
s1 == 0 &&
s2 == 0)
368 if(*(signs1.begin()) != *(signs2.begin()))
397 std::vector<exprt> operands;
400 if(src.
id() == ID_and)
402 for(
auto &x : operands)
408 else if(src.
id() == ID_or)
410 std::size_t fcount = 0;
412 for(
auto &x : operands)
416 if(fcount < operands.size())
422 else if(src.
id() == ID_not)
430 if(atomic_exprs.find(src)->second == +1)
438 std::map<exprt, signed>
441 std::map<exprt, signed> atomic_exprs;
442 for(
auto &c : conditions)
448 atomic_exprs.insert(std::pair<exprt, signed>(c, 0));
452 if(signs.size() != 1)
455 atomic_exprs.insert(std::pair<exprt, signed>(c, *signs.begin()));
468 const std::set<exprt> &conditions,
469 const exprt &decision)
477 std::map<exprt, signed> atomic_exprs_e1 =
479 std::map<exprt, signed> atomic_exprs_e2 =
483 signed cs1 = atomic_exprs_e1.find(c)->second;
484 signed cs2 = atomic_exprs_e2.find(c)->second;
486 if(cs1 == 0 || cs2 == 0)
505 auto e1_it = atomic_exprs_e1.begin();
506 auto e2_it = atomic_exprs_e2.begin();
507 while(e1_it != atomic_exprs_e1.end())
509 if(e1_it->second != e2_it->second)
527 const std::set<exprt> &expr_set,
528 const std::set<exprt> &conditions,
529 const exprt &decision)
531 for(
auto y1 : expr_set)
533 for(
auto y2 : expr_set)
551 std::set<exprt> &controlling,
552 const exprt &decision)
555 std::set<exprt> conditions;
556 for(
auto &x : controlling)
559 conditions.insert(new_conditions.begin(), new_conditions.end());
564 std::set<exprt> new_controlling;
565 bool ctrl_update =
false;
580 for(
auto &x : controlling)
583 new_controlling.clear();
584 for(
auto &y : controlling)
586 new_controlling.insert(y);
588 bool removing_x =
true;
591 for(
auto &c : conditions)
593 bool cOK =
has_mcdc_pair(c, new_controlling, conditions, decision);
615 controlling = new_controlling;
630 i_it->turn_into_skip();
637 if(!i_it->source_location().is_built_in())
642 std::set<exprt> both;
648 inserter(both, both.end()));
652 for(
const auto &p : both)
654 bool is_decision = decisions.
find(p) != decisions.end();
655 bool is_condition = conditions.find(p) != conditions.end();
658 ?
"decision/condition"
659 : is_decision ?
"decision" :
"condition";
661 std::string p_string =
from_expr(
ns, function_id, p);
663 std::string comment_t = description +
" '" + p_string +
"' true";
670 *i_it = make_assertion(
not_exprt(p), annotated_location);
672 std::string comment_f = description +
" '" + p_string +
"' false";
674 annotated_location = source_location;
679 *i_it = make_assertion(p, annotated_location);
682 std::set<exprt> controlling;
687 if(!decisions.empty())
692 for(
const auto &p : controlling)
694 std::string p_string =
from_expr(
ns, function_id, p);
696 std::string description =
697 "MC/DC independence condition '" + p_string +
"'";
705 *i_it = make_assertion(
not_exprt(p), annotated_location);
708 for(std::size_t i = 0; i < both.size() * 2 + controlling.size(); i++)
const irep_idt property_class
const irep_idt coverage_criterion
bool is_non_cover_assertion(goto_programt::const_targett t) const
std::function< goto_programt::instructiont(const exprt &, const source_locationt &)> assertion_factoryt
The type of function used to make goto_program assertions.
void instrument(const irep_idt &function_id, goto_programt &, goto_programt::targett &, const cover_blocks_baset &, const assertion_factoryt &) const override
Override this method to implement an instrumenter.
dstringt has one field, an unsigned integer no which is an index into a static table of strings.
Base class for all expressions.
A generic container class for the GOTO intermediate representation of one function.
void insert_before_swap(targett target)
Insertion that preserves jumps to "target".
instructionst::iterator targett
const irept & find(const irep_idt &name) const
void set(const irep_idt &name, const irep_idt &value)
const irep_idt & id() const
void set_comment(const irep_idt &comment)
void set_property_class(const irep_idt &property_class)
void set_function(const irep_idt &function)
Coverage Instrumentation.
std::set< exprt > collect_mcdc_controlling_nested(const std::set< exprt > &decisions)
This nested method iteratively applies ''collect_mcdc_controlling'' to every non-atomic expr within a...
bool is_mcdc_pair(const exprt &e1, const exprt &e2, const exprt &c, const std::set< exprt > &conditions, const exprt &decision)
To check if the two input controlling exprs are mcdc pairs regarding an atomic expr ''c''.
void remove_repetition(std::set< exprt > &exprs)
After the ''collect_mcdc_controlling_nested'', there can be the recurrence of the same expr in the re...
void collect_mcdc_controlling_rec(const exprt &src, const std::vector< exprt > &conditions, std::set< exprt > &result)
To recursively collect controlling exprs for for mcdc coverage.
bool eval_expr(const std::map< exprt, signed > &atomic_exprs, const exprt &src)
To evaluate the value of expr ''src'', according to the atomic expr values.
std::map< exprt, signed > values_of_atomic_exprs(const exprt &e, const std::set< exprt > &conditions)
To obtain values of atomic exprs within the super expr.
void minimize_mcdc_controlling(std::set< exprt > &controlling, const exprt &decision)
This method minimizes the controlling conditions for mcdc coverage.
std::set< signed > sign_of_expr(const exprt &e, const exprt &E)
The sign of expr ''e'' within the super-expr ''E''.
std::set< exprt > collect_mcdc_controlling(const std::set< exprt > &decisions)
bool has_mcdc_pair(const exprt &c, const std::set< exprt > &expr_set, const std::set< exprt > &conditions, const exprt &decision)
To check if we can find the mcdc pair of the input ''expr_set'' regarding the atomic expr ''c''.
std::set< exprt > replacement_conjunction(const std::set< exprt > &replacement_exprs, const std::vector< exprt > &operands, const std::size_t i)
To replace the i-th expr of ''operands'' with each expr inside ''replacement_exprs''.
std::set< exprt > collect_conditions(const exprt &src)
std::set< exprt > collect_decisions(const goto_programt::const_targett t)
void collect_operands(const exprt &src, std::vector< exprt > &dest)
bool is_condition(const exprt &src)
Coverage Instrumentation Utilities.
exprt boolean_negate(const exprt &src)
negate a Boolean expression, possibly removing a not_exprt, and swapping false and true
Deprecated expression utility functions.
std::string from_expr(const namespacet &ns, const irep_idt &identifier, const exprt &expr)
exprt conjunction(const exprt::operandst &op)
1) generates a conjunction for two or more operands 2) for one operand, returns the operand 3) return...
const not_exprt & to_not_expr(const exprt &expr)
Cast an exprt to an not_exprt.