@@ -366,20 +366,21 @@ void instrument_cover_goals(
366
366
case coverage_criteriont::CONDITION:
367
367
// Conditions are all atomic predicates in the programs.
368
368
{
369
- std::set<exprt> conditions=
370
- collect_conditions (i_it);
369
+ const std::set<exprt> conditions=collect_conditions (i_it);
371
370
372
- source_locationt source_location=i_it->source_location ;
371
+ const source_locationt source_location=i_it->source_location ;
373
372
374
373
for (const auto & c : conditions)
375
374
{
376
- std::string comment_t =" condition `" +from_expr (ns, " " , c)+" ' true" ;
375
+ const std::string c_string=from_expr (ns, " " , c);
376
+
377
+ const std::string comment_t =" condition `" +c_string+" ' true" ;
377
378
goto_program.insert_before_swap (i_it);
378
379
i_it->make_assertion (c);
379
380
i_it->source_location =source_location;
380
381
i_it->source_location .set_comment (comment_t );
381
382
382
- std::string comment_f=" condition `" +from_expr (ns, " " , c) +" ' false" ;
383
+ const std::string comment_f=" condition `" +c_string +" ' false" ;
383
384
goto_program.insert_before_swap (i_it);
384
385
i_it->make_assertion (not_exprt (c));
385
386
i_it->source_location =source_location;
@@ -394,20 +395,21 @@ void instrument_cover_goals(
394
395
case coverage_criteriont::DECISION:
395
396
// Decisions are maximal Boolean combinations of conditions.
396
397
{
397
- std::set<exprt> decisions=
398
- collect_decisions (i_it);
398
+ const std::set<exprt> decisions=collect_decisions (i_it);
399
399
400
- source_locationt source_location=i_it->source_location ;
400
+ const source_locationt source_location=i_it->source_location ;
401
401
402
402
for (const auto & d : decisions)
403
403
{
404
- std::string comment_t =" decision `" +from_expr (ns, " " , d)+" ' true" ;
404
+ const std::string d_string=from_expr (ns, " " , d);
405
+
406
+ const std::string comment_t =" decision `" +d_string+" ' true" ;
405
407
goto_program.insert_before_swap (i_it);
406
408
i_it->make_assertion (d);
407
409
i_it->source_location =source_location;
408
410
i_it->source_location .set_comment (comment_t );
409
411
410
- std::string comment_f=" decision `" +from_expr (ns, " " , d) +" ' false" ;
412
+ const std::string comment_f=" decision `" +d_string +" ' false" ;
411
413
goto_program.insert_before_swap (i_it);
412
414
i_it->make_assertion (not_exprt (d));
413
415
i_it->source_location =source_location;
@@ -418,14 +420,51 @@ void instrument_cover_goals(
418
420
i_it++;
419
421
}
420
422
break ;
421
-
422
423
423
424
case coverage_criteriont::MCDC:
424
425
// 1. Each entry and exit point is invoked
425
426
// 2. Each decision takes every possible outcome
426
427
// 3. Each condition in a decision takes every possible outcome
427
428
// 4. Each condition in a decision is shown to independently
428
429
// affect the outcome of the decision.
430
+ {
431
+ const std::set<exprt> conditions=collect_conditions (i_it);
432
+ const std::set<exprt> decisions=collect_decisions (i_it);
433
+
434
+ std::set<exprt> both;
435
+ std::set_union (conditions.begin (), conditions.end (),
436
+ decisions.begin (), decisions.end (),
437
+ inserter (both, both.end ()));
438
+
439
+ const source_locationt source_location=i_it->source_location ;
440
+
441
+ for (const auto & p : both)
442
+ {
443
+ bool is_decision=decisions.find (p)!=decisions.end ();
444
+ bool is_condition=conditions.find (p)!=conditions.end ();
445
+
446
+ std::string description=
447
+ (is_decision && is_condition)?" decision/condition" :
448
+ is_decision?" decision" :" condition" ;
449
+
450
+ std::string p_string=from_expr (ns, " " , p);
451
+
452
+ std::string comment_t =description+" `" +p_string+" ' true" ;
453
+ goto_program.insert_before_swap (i_it);
454
+ i_it->make_assertion (p);
455
+ i_it->source_location =source_location;
456
+ i_it->source_location .set_comment (comment_t );
457
+
458
+ std::string comment_f=description+" `" +p_string+" ' false" ;
459
+ goto_program.insert_before_swap (i_it);
460
+ i_it->make_assertion (not_exprt (p));
461
+ i_it->source_location =source_location;
462
+ i_it->source_location .set_comment (comment_f);
463
+ }
464
+
465
+ for (unsigned i=0 ; i<both.size ()*2 ; i++)
466
+ i_it++;
467
+ }
429
468
break ;
430
469
431
470
case coverage_criteriont::PATH:
0 commit comments