CBMC
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
abstract_pointer_object.cpp
Go to the documentation of this file.
1/*******************************************************************\
2
3 Module: analyses variable-sensitivity
4
5 Author: Thomas Kiley, thomas.kiley@diffblue.com
6
7\*******************************************************************/
8
11
12#include <util/pointer_expr.h>
13
15
17 const typet &type,
18 bool top,
19 bool bottom)
20 : abstract_objectt(type, top, bottom)
21{
23}
24
26 const exprt &e,
27 const abstract_environmentt &environment,
28 const namespacet &ns)
29 : abstract_objectt(e, environment, ns)
30{
32}
33
34static bool is_dereference(const exprt &expr);
35static bool is_typecast_from_void_ptr(const exprt &expr);
36
38 const exprt &expr,
39 const std::vector<abstract_object_pointert> &operands,
40 const abstract_environmentt &environment,
41 const namespacet &ns) const
42{
43 if(is_dereference(expr))
44 return read_dereference(environment, ns);
45
47 return typecast_from_void_ptr(expr, operands, environment, ns);
48
49 if(is_ptr_diff(expr))
50 return eval_ptr_diff(expr, operands, environment, ns);
51
52 if(is_ptr_comparison(expr))
53 return eval_ptr_comparison(expr, operands, environment, ns);
54
56 expr, operands, environment, ns);
57}
58
60 abstract_environmentt &environment,
61 const namespacet &ns,
62 const std::stack<exprt> &stack,
63 const exprt &specifier,
64 const abstract_object_pointert &value,
65 bool merging_write) const
66{
67 return write_dereference(environment, ns, stack, value, merging_write);
68}
69
74 const namespacet &ns) const
75{
76 abstract_objectt::get_statistics(statistics, visited, env, ns);
77 ++statistics.number_of_pointers;
78}
79
81 const exprt &expr,
82 const std::vector<abstract_object_pointert> &operands,
83 const abstract_environmentt &environment,
84 const namespacet &ns) const
85{
86 auto pointer =
87 std::dynamic_pointer_cast<const abstract_pointer_objectt>(operands.front());
88 if(pointer)
89 return pointer->typecast(expr.type(), environment, ns);
90
92 expr, operands, environment, ns);
93}
94
96 const exprt &expr,
97 const std::vector<abstract_object_pointert> &operands,
98 const abstract_environmentt &environment,
99 const namespacet &ns) const
100{
101 if(is_top() || operands[1]->is_top())
102 return environment.abstract_object_factory(expr.type(), ns, true, false);
103
104 return ptr_diff(expr, operands, environment, ns);
105}
106
108 const exprt &expr,
109 const std::vector<abstract_object_pointert> &operands,
110 const abstract_environmentt &environment,
111 const namespacet &ns) const
112{
113 auto result = ptr_comparison_expr(expr, operands, environment, ns);
114 return environment.eval(result, ns);
115}
116
117static bool is_dereference(const exprt &expr)
118{
119 return expr.id() == ID_dereference;
120}
121
122static bool is_typecast_from_void_ptr(const exprt &expr)
123{
124 if(expr.id() != ID_typecast)
125 return false;
126
127 const typecast_exprt &tce = to_typecast_expr(expr);
128 return tce.op().id() == ID_symbol && is_void_pointer(tce.op().type());
129}
bool is_ptr_comparison(const exprt &expr)
bool is_ptr_diff(const exprt &expr)
An abstract version of a program environment.
std::set< abstract_object_pointert > abstract_object_visitedt
sharing_ptrt< class abstract_objectt > abstract_object_pointert
Statistics gathering for the variable senstivity domain.
static bool is_dereference(const exprt &expr)
static bool is_typecast_from_void_ptr(const exprt &expr)
The base of all pointer abstractions.
virtual abstract_object_pointert eval(const exprt &expr, const namespacet &ns) const
These three are really the heart of the method.
virtual abstract_object_pointert abstract_object_factory(const typet &type, const namespacet &ns, bool top, bool bottom) const
Look at the configuration for the sensitivity and create an appropriate abstract_object.
virtual bool is_top() const
Find out if the abstract object is top.
virtual abstract_object_pointert expression_transform(const exprt &expr, const std::vector< abstract_object_pointert > &operands, const abstract_environmentt &environment, const namespacet &ns) const
Interface for transforms.
virtual void get_statistics(abstract_object_statisticst &statistics, abstract_object_visitedt &visited, const abstract_environmentt &env, const namespacet &ns) const
virtual const typet & type() const
Get the real type of the variable this abstract object is representing.
abstract_object_pointert eval_ptr_diff(const exprt &expr, const std::vector< abstract_object_pointert > &operands, const abstract_environmentt &environment, const namespacet &ns) const
abstract_pointer_objectt(const typet &type, bool top, bool bottom)
Start the abstract object at either top or bottom or neither Asserts if both top and bottom are true.
abstract_object_pointert typecast_from_void_ptr(const exprt &expr, const std::vector< abstract_object_pointert > &operands, const abstract_environmentt &environment, const namespacet &ns) const
abstract_object_pointert write(abstract_environmentt &environment, const namespacet &ns, const std::stack< exprt > &stack, const exprt &specifier, const abstract_object_pointert &value, bool merging_write) const override
A helper function to evaluate writing to a component of an abstract object.
virtual abstract_object_pointert write_dereference(abstract_environmentt &environment, const namespacet &ns, const std::stack< exprt > &stack, const abstract_object_pointert &value, bool merging_write) const =0
Evaluate writing to a pointer's value.
virtual exprt ptr_comparison_expr(const exprt &expr, const std::vector< abstract_object_pointert > &operands, const abstract_environmentt &environment, const namespacet &ns) const =0
virtual abstract_object_pointert read_dereference(const abstract_environmentt &env, const namespacet &ns) const =0
A helper function to read elements from an array.
void get_statistics(abstract_object_statisticst &statistics, abstract_object_visitedt &visited, const abstract_environmentt &env, const namespacet &ns) const override
virtual abstract_object_pointert ptr_diff(const exprt &expr, const std::vector< abstract_object_pointert > &operands, const abstract_environmentt &environment, const namespacet &ns) const =0
abstract_object_pointert expression_transform(const exprt &expr, const std::vector< abstract_object_pointert > &operands, const abstract_environmentt &environment, const namespacet &ns) const override
Interface for transforms.
abstract_object_pointert eval_ptr_comparison(const exprt &expr, const std::vector< abstract_object_pointert > &operands, const abstract_environmentt &environment, const namespacet &ns) const
ait supplies three of the four components needed: an abstract interpreter (in this case handling func...
Definition ai.h:562
Base class for all expressions.
Definition expr.h:56
typet & type()
Return the type of the expression.
Definition expr.h:84
const irep_idt & id() const
Definition irep.h:388
A namespacet is essentially one or two symbol tables bound together, to allow for symbol lookups in t...
Definition namespace.h:91
Semantic type conversion.
Definition std_expr.h:2073
The type of an expression, extends irept.
Definition type.h:29
API to expression classes for Pointers.
bool is_void_pointer(const typet &type)
This method tests, if the given typet is a pointer of type void.
#define PRECONDITION(CONDITION)
Definition invariant.h:463
const typecast_exprt & to_typecast_expr(const exprt &expr)
Cast an exprt to a typecast_exprt.
Definition std_expr.h:2107