CBMC
smt2_incremental_decision_procedure.h
Go to the documentation of this file.
1 // Author: Diffblue Ltd.
2 
5 
6 #ifndef CPROVER_SOLVERS_SMT2_INCREMENTAL_SMT2_INCREMENTAL_DECISION_PROCEDURE_H
7 #define CPROVER_SOLVERS_SMT2_INCREMENTAL_SMT2_INCREMENTAL_DECISION_PROCEDURE_H
8 
9 #include <util/expr.h> // Needed for `exprt` values. IWYU pragma: keep
10 #include <util/message.h>
11 
19 
20 #include <memory>
21 #include <unordered_map>
22 
23 class namespacet;
24 class smt_base_solver_processt; // IWYU pragma: keep
25 class string_constantt;
26 class union_tag_typet;
27 
30 {
31 public:
39  const namespacet &_ns,
40  std::unique_ptr<smt_base_solver_processt> solver_process,
41  message_handlert &message_handler);
42 
43  // Implementation of public decision_proceduret member functions.
44  exprt handle(const exprt &expr) override;
45  exprt get(const exprt &expr) const override;
46  void print_assignment(std::ostream &out) const override;
47  std::string decision_procedure_text() const override;
48  std::size_t get_number_of_solver_calls() const override;
49  void set_to(const exprt &expr, bool value) override;
50 
51  // Implementation of public stack_decision_proceduret member functions.
52  void push(const std::vector<exprt> &assumptions) override;
53  void push() override;
54  void pop() override;
55 
59  std::optional<exprt>
60  get_expr(const smt_termt &descriptor, const typet &type) const;
61  std::optional<exprt>
62  get_expr(const smt_termt &struct_term, const struct_tag_typet &type) const;
63  std::optional<exprt>
64  get_expr(const smt_termt &union_term, const union_tag_typet &type) const;
65  std::optional<exprt>
66  get_expr(const smt_termt &array, const array_typet &type) const;
67 
68 protected:
69  // Implementation of protected decision_proceduret member function.
70  resultt dec_solve(const exprt &) override;
78  template <typename t_exprt>
79  void define_array_function(const t_exprt &array);
83  const array_exprt &array,
84  const smt_identifier_termt &array_identifier);
92  const array_of_exprt &array,
93  const smt_identifier_termt &array_identifier);
95  const string_constantt &string,
96  const smt_identifier_termt &array_identifier);
99  void define_dependent_functions(const exprt &expr);
103  void ensure_handle_for_expr_defined(const exprt &expr);
106  smt_termt convert_expr_to_smt(const exprt &expr);
107  void define_index_identifiers(const exprt &expr);
119  exprt lower(exprt expression) const;
120  std::optional<smt_termt> get_identifier(const exprt &expr) const;
121 
126  const namespacet &ns;
132  std::unique_ptr<smt_base_solver_processt> solver_process;
137  class sequencet
138  {
139  size_t next_id = 0;
140 
141  public:
142  size_t operator()()
143  {
144  return next_id++;
145  }
153  std::unordered_map<exprt, smt_identifier_termt, irep_hash>
163  std::unordered_map<exprt, smt_identifier_termt, irep_hash>
172  std::unordered_map<irep_idt, smt_identifier_termt> identifier_table;
181  std::vector<bool> object_properties_defined;
194 };
195 
196 #endif // CPROVER_SOLVERS_SMT2_INCREMENTAL_SMT2_INCREMENTAL_DECISION_PROCEDURE_H
Array constructor from list of elements.
Definition: std_expr.h:1616
Array constructor from single element.
Definition: std_expr.h:1553
Arrays with given size.
Definition: std_types.h:807
resultt
Result of running the decision procedure.
Base class for all expressions.
Definition: expr.h:56
Class that provides messages with a built-in verbosity 'level'.
Definition: message.h:155
A namespacet is essentially one or two symbol tables bound together, to allow for symbol lookups in t...
Definition: namespace.h:94
Generators of sequences of uniquely identifying numbers used for naming SMT functions introduced by t...
smt_object_sizet object_size_function
Implementation of the SMT formula for the object size function.
size_t number_of_solver_calls
The number of times dec_solve() has been called.
std::unordered_map< exprt, smt_identifier_termt, irep_hash > expression_identifiers
As part of the decision procedure's overall translation of CBMCs exprts into SMT terms,...
exprt handle(const exprt &expr) override
Generate a handle, which is an expression that has the same value as the argument in any model that i...
exprt lower(exprt expression) const
Performs a combination of transformations which reduces the set of possible expression forms by expre...
exprt substitute_defined_padding(exprt expr)
In the case where lowering passes insert instances of the anonymous nondet_padding_exprt,...
std::optional< exprt > get_expr(const smt_termt &descriptor, const typet &type) const
Gets the value of descriptor from the solver and returns the solver response expressed as an exprt of...
std::size_t get_number_of_solver_calls() const override
Return the number of incremental solver calls.
std::string decision_procedure_text() const override
Return a textual description of the decision procedure.
smt_is_dynamic_objectt is_dynamic_object_function
Implementation of the SMT formula for the dynamic object status lookup function.
void ensure_handle_for_expr_defined(const exprt &expr)
If a function has not been defined for handling expr, then a new function is defined.
void define_dependent_functions(const exprt &expr)
Defines any functions which expr depends on, which have not yet been defined, along with their depend...
void initialize_array_elements(const array_exprt &array, const smt_identifier_termt &array_identifier)
Generate and send to the SMT solver clauses asserting that each array element is as specified by arra...
void print_assignment(std::ostream &out) const override
Print satisfying assignment to out.
resultt dec_solve(const exprt &) override
Implementation of the decision procedure.
void push() override
Push a new context on the stack This context becomes a child context nested in the current context.
messaget log
For reporting errors, warnings and debugging information back to the user.
void pop() override
Pop whatever is on top of the stack.
class smt2_incremental_decision_proceduret::sequencet padding_sequence
std::optional< smt_termt > get_identifier(const exprt &expr) const
std::unordered_map< irep_idt, smt_identifier_termt > identifier_table
This maps from the unsorted/untyped string/symbol for the identifiers which we have declared in SMT s...
smt_object_mapt object_map
This map is used to track object related state.
class smt2_incremental_decision_proceduret::sequencet array_sequence
std::vector< bool > object_properties_defined
The size of each object and the dynamic object stus is separately defined as a pre-solving step.
class smt2_incremental_decision_proceduret::sequencet index_sequence
void define_object_properties()
Sends the solver the definitions of the object sizes and dynamic memory statuses.
smt_termt convert_expr_to_smt(const exprt &expr)
Add objects in expr to object_map if needed and convert to smt.
const namespacet & ns
Namespace for looking up the expressions which symbol_exprts relate to.
exprt get(const exprt &expr) const override
Return expr with variables replaced by values from satisfying assignment if available.
type_size_mapt pointer_sizes_map
Precalculated type sizes used for pointer arithmetic.
std::unordered_map< exprt, smt_identifier_termt, irep_hash > expression_handle_identifiers
When the handle(exprt) member function is called, the decision procedure commands the SMT solver to d...
std::unique_ptr< smt_base_solver_processt > solver_process
For handling the lifetime of and communication with the separate SMT solver process.
void set_to(const exprt &expr, bool value) override
For a Boolean expression expr, add the constraint 'expr' if value is true, otherwise add 'not expr'.
class smt2_incremental_decision_proceduret::sequencet handle_sequence
smt2_incremental_decision_proceduret(const namespacet &_ns, std::unique_ptr< smt_base_solver_processt > solver_process, message_handlert &message_handler)
void define_array_function(const t_exprt &array)
Defines a function of array sort and asserts the element values from array_exprt or array_of_exprt.
Stores identifiers in unescaped and unquoted form.
Definition: smt_terms.h:93
Encodes struct types/values into non-struct expressions/types.
A struct tag type, i.e., struct_typet with an identifier.
Definition: std_types.h:493
The type of an expression, extends irept.
Definition: type.h:29
A union tag type, i.e., union_typet with an identifier.
Definition: c_types.h:199
Data structures and algorithms used by smt2_incremental_decision_proceduret to track data about the o...
std::unordered_map< exprt, decision_procedure_objectt, irep_hash > smt_object_mapt
Mapping from an object's base expression to the set of information about it which we track.
Decision procedure with incremental solving with contexts and assumptions.
Specifics of how the dynamic object status lookup is implemented in SMT terms.
Specifics of how the object size lookup is implemented in SMT terms.
Utilities for making a map of types to associated sizes.
std::unordered_map< typet, smt_termt, irep_hash > type_size_mapt