CBMC
type_size_mapping.cpp
Go to the documentation of this file.
1 // Author: Diffblue Ltd.
2 
3 #include "type_size_mapping.h"
4 
5 #include <util/arith_tools.h>
6 #include <util/c_types.h>
7 #include <util/invariant.h>
8 #include <util/pointer_expr.h>
10 
12 
14  const exprt &expression,
15  const namespacet &ns,
16  type_size_mapt &type_size_map,
17  const smt_object_mapt &object_map,
19 {
20  expression.visit_pre([&](const exprt &sub_expression) {
21  if(
22  const auto &pointer_type =
23  type_try_dynamic_cast<pointer_typet>(sub_expression.type()))
24  {
25  const auto find_result = type_size_map.find(pointer_type->base_type());
26  if(find_result != type_size_map.cend())
27  return;
28  exprt pointer_size_expr;
29  // There's a special case for a pointer subtype here: the case where the
30  // pointer is `void *`. This means that we don't know the underlying base
31  // type, so we're just assigning a size expression value of 1 (given that
32  // this is going to be used in a multiplication and 1 is the identity
33  // value for multiplication)
34  if(is_void_pointer(*pointer_type))
35  {
36  pointer_size_expr = from_integer(1, size_type());
37  }
38  else
39  {
40  auto pointer_size_opt = size_of_expr(pointer_type->base_type(), ns);
41  PRECONDITION(pointer_size_opt.has_value());
42  pointer_size_expr = pointer_size_opt.value();
43  }
44  auto pointer_size_term = convert_expr_to_smt(
45  pointer_size_expr, object_map, type_size_map, object_size);
46  type_size_map.emplace_hint(
47  find_result, pointer_type->base_type(), pointer_size_term);
48  }
49  });
50 }
pointer_offset_size.h
arith_tools.h
type_size_mapping.h
convert_expr_to_smt
static smt_termt convert_expr_to_smt(const symbol_exprt &symbol_expr)
Definition: convert_expr_to_smt.cpp:117
invariant.h
exprt
Base class for all expressions.
Definition: expr.h:55
namespacet
A namespacet is essentially one or two symbol tables bound together, to allow for symbol lookups in t...
Definition: namespace.h:90
exprt::type
typet & type()
Return the type of the expression.
Definition: expr.h:84
pointer_expr.h
pointer_type
pointer_typet pointer_type(const typet &subtype)
Definition: c_types.cpp:253
object_size
exprt object_size(const exprt &pointer)
Definition: pointer_predicates.cpp:33
smt_function_application_termt::factoryt< smt_command_functiont >
smt_object_mapt
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.
Definition: object_tracking.h:89
pointer_typet::base_type
const typet & base_type() const
The type of the data what we point to.
Definition: pointer_expr.h:35
exprt::visit_pre
void visit_pre(std::function< void(exprt &)>)
Definition: expr.cpp:245
type_size_mapt
std::unordered_map< typet, smt_termt, irep_full_hash > type_size_mapt
Definition: type_size_mapping.h:17
associate_pointer_sizes
void associate_pointer_sizes(const exprt &expression, const namespacet &ns, type_size_mapt &type_size_map, const smt_object_mapt &object_map, const smt_object_sizet::make_applicationt &object_size)
This function populates the (pointer) type -> size map.
Definition: type_size_mapping.cpp:13
c_types.h
convert_expr_to_smt.h