CBMC
remove_const_function_pointers.h
Go to the documentation of this file.
1 /*******************************************************************\
2 
3 Module: Goto Programs
4 
5 Author: Thomas Kiley, thomas.kiley@diffblue.com
6 
7 \*******************************************************************/
8 
11 
12 #ifndef CPROVER_GOTO_PROGRAMS_REMOVE_CONST_FUNCTION_POINTERS_H
13 #define CPROVER_GOTO_PROGRAMS_REMOVE_CONST_FUNCTION_POINTERS_H
14 
15 #include <list>
16 #include <unordered_set>
17 
18 #include <util/expr.h>
19 #include <util/message.h>
20 #include <util/mp_arith.h>
21 
22 class address_of_exprt;
23 class dereference_exprt;
24 class index_exprt;
25 class member_exprt;
26 class namespacet;
27 class struct_exprt;
28 class symbol_exprt;
29 class symbol_tablet;
30 class typecast_exprt;
31 
33 {
34 public:
35  typedef std::unordered_set<symbol_exprt, irep_hash> functionst;
36  typedef std::list<exprt> expressionst;
38  message_handlert &message_handler,
39  const namespacet &ns,
41 
42  bool operator()(const exprt &base_expression, functionst &out_functions);
43 
44 private:
45  exprt replace_const_symbols(const exprt &expression) const;
46  exprt resolve_symbol(const symbol_exprt &symbol_expr) const;
47 
48  // recursive functions for dealing with the function pointer
49  bool try_resolve_function_call(const exprt &expr, functionst &out_functions);
50 
52  const expressionst &exprs, functionst &out_functions);
53 
55  const index_exprt &index_expr, functionst &out_functions);
56 
58  const member_exprt &member_expr, functionst &out_functions);
59 
61  const address_of_exprt &address_expr, functionst &out_functions);
62 
64  const dereference_exprt &deref_expr, functionst &out_functions);
65 
67  const typecast_exprt &typecast_expr, functionst &out_functions);
68 
69  // recursive functions for dealing with the auxiliary elements
71  const exprt &expr,
72  expressionst &out_resolved_expression,
73  bool &out_is_const);
74 
76  const index_exprt &index_expr,
77  expressionst &out_expressions,
78  bool &out_is_const);
79 
80  bool try_resolve_member(
81  const member_exprt &member_expr,
82  expressionst &out_expressions,
83  bool &out_is_const);
84 
86  const dereference_exprt &deref_expr,
87  expressionst &out_expressions,
88  bool &out_is_const);
89 
91  const typecast_exprt &typecast_expr,
92  expressionst &out_expressions,
93  bool &out_is_const);
94 
95  bool is_const_expression(const exprt &expression) const;
96  bool is_const_type(const typet &type) const;
97 
99  const exprt &index_value_expr, mp_integer &out_array_index);
100 
102  const struct_exprt &struct_expr, const member_exprt &member_expr);
103 
105  const namespacet &ns;
107 };
108 
109 #define OPT_REMOVE_CONST_FUNCTION_POINTERS \
110  "(remove-const-function-pointers)"
111 
112 #define HELP_REMOVE_CONST_FUNCTION_POINTERS \
113  " --remove-const-function-pointers\n" \
114  " remove function pointers that are constant" \
115  " or constant part of an array\n"
116 
117 #endif // CPROVER_GOTO_PROGRAMS_REMOVE_CONST_FUNCTION_POINTERS_H
messaget
Class that provides messages with a built-in verbosity 'level'.
Definition: message.h:154
remove_const_function_pointerst::operator()
bool operator()(const exprt &base_expression, functionst &out_functions)
To take a function call on a function pointer, and if possible resolve it to a small collection of po...
Definition: remove_const_function_pointers.cpp:52
remove_const_function_pointerst::try_resolve_typecast
bool try_resolve_typecast(const typecast_exprt &typecast_expr, expressionst &out_expressions, bool &out_is_const)
To squash a typecast access.
Definition: remove_const_function_pointers.cpp:746
remove_const_function_pointerst::try_resolve_member
bool try_resolve_member(const member_exprt &member_expr, expressionst &out_expressions, bool &out_is_const)
To squash an member access by first finding the struct it is accessing Then return the squashed value...
Definition: remove_const_function_pointers.cpp:609
symbol_tablet
The symbol table.
Definition: symbol_table.h:13
remove_const_function_pointerst::try_resolve_dereference_function_call
bool try_resolve_dereference_function_call(const dereference_exprt &deref_expr, functionst &out_functions)
To resolve an expression to the specific function calls it can be.
Definition: remove_const_function_pointers.cpp:327
mp_integer
BigInt mp_integer
Definition: smt_terms.h:17
remove_const_function_pointerst::is_const_expression
bool is_const_expression(const exprt &expression) const
To evaluate the const-ness of the expression type.
Definition: remove_const_function_pointers.cpp:776
remove_const_function_pointerst::try_resolve_dereference
bool try_resolve_dereference(const dereference_exprt &deref_expr, expressionst &out_expressions, bool &out_is_const)
To squash a dereference access by first finding the address_of the dereference is dereferencing.
Definition: remove_const_function_pointers.cpp:676
mp_arith.h
typet
The type of an expression, extends irept.
Definition: type.h:28
remove_const_function_pointerst::try_resolve_function_calls
bool try_resolve_function_calls(const expressionst &exprs, functionst &out_functions)
To resolve a collection of expressions to the specific function calls they can be.
Definition: remove_const_function_pointers.cpp:208
dereference_exprt
Operator to dereference a pointer.
Definition: pointer_expr.h:659
remove_const_function_pointerst::replace_const_symbols
exprt replace_const_symbols(const exprt &expression) const
To collapse the symbols down to their values where possible This takes a very general approach,...
Definition: remove_const_function_pointers.cpp:68
remove_const_function_pointerst::try_resolve_function_call
bool try_resolve_function_call(const exprt &expr, functionst &out_functions)
To resolve an expression to the specific function calls it can be.
Definition: remove_const_function_pointers.cpp:124
remove_const_function_pointerst::try_resolve_expression
bool try_resolve_expression(const exprt &expr, expressionst &out_resolved_expression, bool &out_is_const)
To squash various expr types to simplify the expression.
Definition: remove_const_function_pointers.cpp:396
remove_const_function_pointerst::try_resolve_index_of_function_call
bool try_resolve_index_of_function_call(const index_exprt &index_expr, functionst &out_functions)
To resolve an expression to the specific function calls it can be.
Definition: remove_const_function_pointers.cpp:243
exprt
Base class for all expressions.
Definition: expr.h:55
remove_const_function_pointerst::symbol_table
const symbol_tablet & symbol_table
Definition: remove_const_function_pointers.h:106
remove_const_function_pointerst::is_const_type
bool is_const_type(const typet &type) const
To evaluate the const-ness of the type.
Definition: remove_const_function_pointers.cpp:786
symbol_exprt
Expression to hold a symbol (variable)
Definition: std_expr.h:112
remove_const_function_pointerst::functionst
std::unordered_set< symbol_exprt, irep_hash > functionst
Definition: remove_const_function_pointers.h:35
expr.h
remove_const_function_pointerst::get_component_value
exprt get_component_value(const struct_exprt &struct_expr, const member_exprt &member_expr)
To extract the value of the specific component within a struct.
Definition: remove_const_function_pointers.cpp:799
struct_exprt
Struct constructor from list of elements.
Definition: std_expr.h:1818
remove_const_function_pointerst::ns
const namespacet & ns
Definition: remove_const_function_pointers.h:105
namespacet
A namespacet is essentially one or two symbol tables bound together, to allow for symbol lookups in t...
Definition: namespace.h:90
remove_const_function_pointerst::try_resolve_index_of
bool try_resolve_index_of(const index_exprt &index_expr, expressionst &out_expressions, bool &out_is_const)
To squash an index access by first finding the array it is accessing Then if the index can be resolve...
Definition: remove_const_function_pointers.cpp:507
remove_const_function_pointerst::try_resolve_typecast_function_call
bool try_resolve_typecast_function_call(const typecast_exprt &typecast_expr, functionst &out_functions)
To resolve an expression to the specific function calls it can be.
Definition: remove_const_function_pointers.cpp:359
message_handlert
Definition: message.h:27
remove_const_function_pointerst::try_resolve_index_value
bool try_resolve_index_value(const exprt &index_value_expr, mp_integer &out_array_index)
Given an index into an array, resolve, if possible, the index that is being accessed.
Definition: remove_const_function_pointers.cpp:465
remove_const_function_pointerst
Definition: remove_const_function_pointers.h:32
remove_const_function_pointerst::expressionst
std::list< exprt > expressionst
Definition: remove_const_function_pointers.h:36
remove_const_function_pointerst::try_resolve_member_function_call
bool try_resolve_member_function_call(const member_exprt &member_expr, functionst &out_functions)
To resolve an expression to the specific function calls it can be.
Definition: remove_const_function_pointers.cpp:275
member_exprt
Extract member of struct or union.
Definition: std_expr.h:2793
remove_const_function_pointerst::resolve_symbol
exprt resolve_symbol(const symbol_exprt &symbol_expr) const
Look up a symbol in the symbol table and return its value.
Definition: remove_const_function_pointers.cpp:109
remove_const_function_pointerst::remove_const_function_pointerst
remove_const_function_pointerst(message_handlert &message_handler, const namespacet &ns, const symbol_tablet &symbol_table)
To take a function call on a function pointer, and if possible resolve it to a small collection of po...
Definition: remove_const_function_pointers.cpp:34
index_exprt
Array index operator.
Definition: std_expr.h:1409
address_of_exprt
Operator to return the address of an object.
Definition: pointer_expr.h:370
typecast_exprt
Semantic type conversion.
Definition: std_expr.h:2016
message.h
remove_const_function_pointerst::log
messaget log
Definition: remove_const_function_pointers.h:104
remove_const_function_pointerst::try_resolve_address_of_function_call
bool try_resolve_address_of_function_call(const address_of_exprt &address_expr, functionst &out_functions)
To resolve an expression to the specific function calls it can be.
Definition: remove_const_function_pointers.cpp:306