CBMC
state_encoding_targets.h
Go to the documentation of this file.
1 /*******************************************************************\
2 
3 Module: State Encoding Targets
4 
5 Author: Daniel Kroening, dkr@amazon.com
6 
7 \*******************************************************************/
8 
9 #ifndef CPROVER_CPROVER_STATE_ENCODING_TARGETS_H
10 #define CPROVER_CPROVER_STATE_ENCODING_TARGETS_H
11 
12 #include <solvers/smt2/smt2_conv.h>
13 
14 #include <iosfwd>
15 
17 {
18 public:
19  virtual void annotation(const std::string &)
20  {
21  }
22 
23  virtual void set_to_true(source_locationt, exprt) = 0;
24 
25  void set_to_true(exprt expr)
26  {
27  set_to_true(source_location, std::move(expr));
28  }
29 
30  void set_source_location(source_locationt __source_location)
31  {
32  source_location = std::move(__source_location);
33  }
34 
35  virtual ~encoding_targett() = default;
36 
37 protected:
39 };
40 
42 {
43 public:
45 
46  using constraintst = std::vector<exprt>;
48 
50  {
53 
54  constraints.emplace_back(std::move(expr));
55  }
56 
57 protected:
59 };
60 
61 static inline void operator<<(encoding_targett &target, exprt constraint)
62 {
63  target.set_to_true(std::move(constraint));
64 }
65 
66 static inline void
68 {
69  for(const auto &constraint : src.constraints)
70  target << constraint;
71 }
72 
74 {
75 public:
76  state_encoding_smt2_convt(const namespacet &ns, std::ostream &_out)
77  : smt2_convt(ns, "", "cprover", "", smt2_convt::solvert::GENERIC, _out)
78 
79  {
80  use_array_of_bool = true;
81  use_as_const = true;
83  }
84 
85  void add_converters();
86 };
87 
89 {
90 public:
91  smt2_encoding_targett(const namespacet &ns, std::ostream &_out)
92  : out(_out), smt2_conv(ns, _out)
93  {
94  }
95 
97  {
98  // finish the conversion to SMT-LIB2
99  smt2_conv();
100  }
101 
102  void set_to_true(source_locationt, exprt expr) override
103  {
104  smt2_conv.set_to_true(std::move(expr));
105  }
106 
107  void annotation(const std::string &text) override
108  {
109  if(text.empty())
110  out << '\n';
111  else
112  out << ';' << ' ' << text << '\n';
113  }
114 
115 protected:
116  std::ostream &out;
118 
120 };
121 
123 {
124 public:
125  explicit ascii_encoding_targett(std::ostream &_out) : out(_out)
126  {
127  }
128 
129  void set_to_true(source_locationt, exprt) override;
130 
131  void annotation(const std::string &text) override
132  {
133  out << text << '\n';
134  }
135 
136 protected:
137  std::ostream &out;
138  std::size_t counter = 0;
139 };
140 
141 #endif // CPROVER_CPROVER_STATE_ENCODING_TARGETS_H
void annotation(const std::string &text) override
ascii_encoding_targett(std::ostream &_out)
void set_to_true(source_locationt, exprt) override
container_encoding_targett()=default
std::vector< exprt > constraintst
void set_to_true(source_locationt source_location, exprt expr) override
void set_to_true(const exprt &)
For a Boolean expression expr, add the constraint 'expr'.
void set_to_true(exprt expr)
virtual void annotation(const std::string &)
virtual ~encoding_targett()=default
void set_source_location(source_locationt __source_location)
virtual void set_to_true(source_locationt, exprt)=0
source_locationt source_location
Base class for all expressions.
Definition: expr.h:56
source_locationt & add_source_location()
Definition: expr.h:236
bool is_not_nil() const
Definition: irep.h:368
A namespacet is essentially one or two symbol tables bound together, to allow for symbol lookups in t...
Definition: namespace.h:94
const namespacet & ns
Definition: smt2_conv.h:98
bool use_as_const
Definition: smt2_conv.h:67
bool use_array_of_bool
Definition: smt2_conv.h:66
void set_to_true(source_locationt, exprt expr) override
smt2_encoding_targett(const namespacet &ns, std::ostream &_out)
void annotation(const std::string &text) override
state_encoding_smt2_convt smt2_conv
static const source_locationt & nil()
state_encoding_smt2_convt(const namespacet &ns, std::ostream &_out)
static void operator<<(encoding_targett &target, exprt constraint)