CBMC
cover_goals.cpp
Go to the documentation of this file.
1 /*******************************************************************\
2 
3 Module: Cover a set of goals incrementally
4 
5 Author: Daniel Kroening, kroening@kroening.com
6 
7 \*******************************************************************/
8 
11 
12 #include "cover_goals.h"
13 
14 #include <util/message.h>
15 #include <util/std_expr.h>
16 
18 {
19 }
20 
23 {
24  // notify observers
25  for(const auto &o : observers)
26  o->satisfying_assignment();
27 
28  for(auto &g : goals)
29  if(
30  g.status == goalt::statust::UNKNOWN &&
31  decision_procedure.get(g.condition).is_true())
32  {
33  g.status=goalt::statust::COVERED;
35 
36  // notify observers
37  for(const auto &o : observers)
38  o->goal_covered(g);
39  }
40 }
41 
44 {
45  exprt::operandst disjuncts;
46 
47  // cover at least one unknown goal
48 
49  for(const auto &g : goals)
50  if(g.status == goalt::statust::UNKNOWN && !g.condition.is_false())
51  disjuncts.push_back(g.condition);
52 
53  // this is 'false' if there are no disjuncts
55 }
56 
59 operator()(message_handlert &message_handler)
60 {
62 
64 
65  do
66  {
67  // We want (at least) one of the remaining goals, please!
68  _iterations++;
69 
70  constraint();
71  dec_result = decision_procedure();
72 
73  switch(dec_result)
74  {
76  return dec_result;
77 
79  // mark the goals we got, and notify observers
80  mark();
81  break;
82 
84  {
85  messaget log(message_handler);
86  log.error() << "decision procedure has failed" << messaget::eom;
87  return dec_result;
88  }
89  }
90  }
92  number_covered()<size());
93 
95 }
messaget
Class that provides messages with a built-in verbosity 'level'.
Definition: message.h:154
decision_proceduret::get
virtual exprt get(const exprt &expr) const =0
Return expr with variables replaced by values from satisfying assignment if available.
cover_goalst::~cover_goalst
virtual ~cover_goalst()
Definition: cover_goals.cpp:17
cover_goalst::goals
goalst goals
Definition: cover_goals.h:54
cover_goalst::operator()
decision_proceduret::resultt operator()(message_handlert &)
Try to cover all goals.
Definition: cover_goals.cpp:59
decision_proceduret::resultt::D_UNSATISFIABLE
@ D_UNSATISFIABLE
decision_proceduret::set_to_true
void set_to_true(const exprt &expr)
For a Boolean expression expr, add the constraint 'expr'.
Definition: decision_procedure.cpp:23
cover_goalst::_number_covered
std::size_t _number_covered
Definition: cover_goals.h:96
messaget::eom
static eomt eom
Definition: message.h:297
exprt::is_true
bool is_true() const
Return whether the expression is a constant representing true.
Definition: expr.cpp:34
cover_goalst::number_covered
std::size_t number_covered() const
Definition: cover_goals.h:58
decision_proceduret::resultt::D_SATISFIABLE
@ D_SATISFIABLE
disjunction
exprt disjunction(const exprt::operandst &op)
1) generates a disjunction for two or more operands 2) for one operand, returns the operand 3) return...
Definition: std_expr.cpp:50
messaget::error
mstreamt & error() const
Definition: message.h:399
cover_goalst::mark
void mark()
Mark goals that are covered.
Definition: cover_goals.cpp:22
cover_goalst::constraint
void constraint()
Build clause.
Definition: cover_goals.cpp:43
cover_goalst::observers
observerst observers
Definition: cover_goals.h:101
cover_goalst::_iterations
unsigned _iterations
Definition: cover_goals.h:97
cover_goalst::size
goalst::size_type size() const
Definition: cover_goals.h:68
decision_proceduret::resultt::D_ERROR
@ D_ERROR
cover_goalst::decision_procedure
decision_proceduret & decision_procedure
Definition: cover_goals.h:98
message_handlert
Definition: message.h:27
exprt::operandst
std::vector< exprt > operandst
Definition: expr.h:58
cover_goalst::goalt::statust::UNKNOWN
@ UNKNOWN
decision_proceduret::resultt
resultt
Result of running the decision procedure.
Definition: decision_procedure.h:43
cover_goalst::goalt::statust::COVERED
@ COVERED
message.h
cover_goals.h
std_expr.h