CBMC
|
Class for generating initialisation code for compound structures. More...
#include <recursive_initialization.h>
Classes | |
struct | constructor_keyt |
Public Types | |
using | recursion_sett = std::set< irep_idt > |
using | equal_cluster_idt = std::size_t |
using | type_constructor_namest = std::map< constructor_keyt, irep_idt > |
Public Member Functions | |
recursive_initializationt (recursive_initialization_configt initialization_config, goto_modelt &goto_model) | |
void | initialize (const exprt &lhs, const exprt &depth, code_blockt &body) |
Generate initialisation code for lhs into body. More... | |
symbol_exprt | get_free_function () |
Get the free function as symbol expression, and inserts it into the goto-model if it doesn't exist already. More... | |
bool | needs_freeing (const exprt &expr) const |
void | free_if_possible (const exprt &expr, code_blockt &body) |
void | free_cluster_origins (code_blockt &body) |
Static Public Member Functions | |
static bool | is_initialization_allowed (const symbolt &symbol) |
Private Member Functions | |
symbol_exprt | get_malloc_function () |
Get the malloc function as symbol exprt, and inserts it into the goto-model if it doesn't exist already. More... | |
bool | should_be_treated_as_array (const irep_idt &pointer_name) const |
std::optional< equal_cluster_idt > | find_equal_cluster (const irep_idt &name) const |
bool | is_array_size_parameter (const irep_idt &cmdline_arg) const |
std::optional< irep_idt > | get_associated_size_variable (const irep_idt &array_name) const |
bool | should_be_treated_as_cstring (const irep_idt &pointer_name) const |
irep_idt | get_fresh_global_name (const std::string &symbol_name, const exprt &initial_value) const |
Construct a new global symbol of type int and set it's value to initial_value . More... | |
symbol_exprt | get_fresh_global_symexpr (const std::string &symbol_name) const |
Construct a new global symbol of type int initialised to 0. More... | |
symbol_exprt | get_fresh_local_symexpr (const std::string &symbol_name) const |
Construct a new local symbol of type int initialised to 0. More... | |
symbol_exprt | get_fresh_local_typed_symexpr (const std::string &symbol_name, const typet &type) const |
Construct a new local symbol of type type initialised to init_value . More... | |
const symbolt & | get_fresh_fun_symbol (const std::string &fun_name, const typet &fun_type) |
Construct a new function symbol of type fun_type . More... | |
symbolt & | get_fresh_param_symbol (const std::string ¶m_name, const typet ¶m_type) |
Construct a new parameter symbol of type param_type . More... | |
symbol_exprt | get_symbol_expr (const irep_idt &symbol_name) const |
Recover the symbol expression from symbol table. More... | |
std::string | type2id (const typet &type) const |
Simple pretty-printer for typet. More... | |
code_blockt | build_constructor_body (const exprt &depth_symbol, const symbol_exprt &result_symbol, const std::optional< exprt > &size_symbol, const std::optional< irep_idt > &lhs_name, const bool is_nullable) |
Case analysis for which constructor should be used. More... | |
irep_idt | build_constructor (const exprt &expr) |
Check if a constructor for the type of expr already exists and create it if not. More... | |
code_blockt | build_function_pointer_constructor (const symbol_exprt &result, bool is_nullable) |
Constructor for function pointers. More... | |
code_blockt | build_pointer_constructor (const exprt &depth, const symbol_exprt &result) |
Generic constructor for all pointers: only builds one pointee (not an array) but may recourse in case the pointee contains more pointers, e.g. More... | |
code_blockt | build_struct_constructor (const exprt &depth, const symbol_exprt &result) |
Constructor for structures: simply iterates over members and initialise each one. More... | |
code_blockt | build_nondet_constructor (const symbol_exprt &result) const |
Default constructor: assigns non-deterministic value of the right type. More... | |
code_blockt | build_array_constructor (const exprt &depth, const symbol_exprt &result) |
Constructor for arrays: simply iterates over elements and initialise each one. More... | |
code_blockt | build_dynamic_array_constructor (const exprt &depth, const symbol_exprt &result, const exprt &size, const std::optional< irep_idt > &lhs_name) |
Constructor for dynamic arrays: allocate memory for n elements (n is random but bounded) and initialise each one. More... | |
void | initialize_selected_member (const exprt &lhs, const exprt &depth, code_blockt &body, const std::vector< irep_idt > &selection_spec) |
Select the specified struct-member to be non-deterministically initialized. More... | |
Private Attributes | |
const recursive_initialization_configt | initialization_config |
goto_modelt & | goto_model |
irep_idt | max_depth_var_name |
irep_idt | min_depth_var_name |
type_constructor_namest | type_constructor_names |
std::vector< std::optional< exprt > > | common_arguments_origins |
Class for generating initialisation code for compound structures.
Definition at line 62 of file recursive_initialization.h.
using recursive_initializationt::equal_cluster_idt = std::size_t |
Definition at line 66 of file recursive_initialization.h.
using recursive_initializationt::recursion_sett = std::set<irep_idt> |
Definition at line 65 of file recursive_initialization.h.
using recursive_initializationt::type_constructor_namest = std::map<constructor_keyt, irep_idt> |
Definition at line 89 of file recursive_initialization.h.
recursive_initializationt::recursive_initializationt | ( | recursive_initialization_configt | initialization_config, |
goto_modelt & | goto_model | ||
) |
Definition at line 118 of file recursive_initialization.cpp.
|
private |
Constructor for arrays: simply iterates over elements and initialise each one.
depth | symbol of the depth parameter |
result | symbol of the result parameter |
Definition at line 747 of file recursive_initialization.cpp.
Check if a constructor for the type of expr
already exists and create it if not.
expr | the expression to be constructed |
Definition at line 291 of file recursive_initialization.cpp.
|
private |
Case analysis for which constructor should be used.
depth_symbol | the symbol for depth parameter |
result_symbol | the symbol for result parameter |
size_symbol | maybe the symbol for size parameter |
lhs_name | the name of the original symbol |
is_nullable | flag for setting a function pointer nullable |
Definition at line 246 of file recursive_initialization.cpp.
|
private |
Constructor for dynamic arrays: allocate memory for n
elements (n
is random but bounded) and initialise each one.
depth | symbol of the depth parameter |
result | symbol of the result parameter |
size | symbol of the size parameter |
lhs_name | name of the original symbol |
Definition at line 819 of file recursive_initialization.cpp.
|
private |
Constructor for function pointers.
result | symbol of the result parameter |
is_nullable | if the function pointer can be null |
Definition at line 986 of file recursive_initialization.cpp.
|
private |
Default constructor: assigns non-deterministic value of the right type.
result | symbol of the result parameter |
Definition at line 807 of file recursive_initialization.cpp.
|
private |
Generic constructor for all pointers: only builds one pointee (not an array) but may recourse in case the pointee contains more pointers, e.g.
a struct.
depth | symbol of the depth parameter |
result | symbol of the result parameter |
Definition at line 651 of file recursive_initialization.cpp.
|
private |
Constructor for structures: simply iterates over members and initialise each one.
depth | symbol of the depth parameter |
result | symbol of the result parameter |
Definition at line 769 of file recursive_initialization.cpp.
|
private |
Definition at line 401 of file recursive_initialization.cpp.
void recursive_initializationt::free_cluster_origins | ( | code_blockt & | body | ) |
Definition at line 978 of file recursive_initialization.cpp.
void recursive_initializationt::free_if_possible | ( | const exprt & | expr, |
code_blockt & | body | ||
) |
Definition at line 945 of file recursive_initialization.cpp.
|
private |
Definition at line 421 of file recursive_initialization.cpp.
symbol_exprt recursive_initializationt::get_free_function | ( | ) |
Get the free
function as symbol expression, and inserts it into the goto-model if it doesn't exist already.
free
function Definition at line 633 of file recursive_initialization.cpp.
|
private |
Construct a new function symbol of type fun_type
.
fun_name | the base name for the new symbol |
fun_type | type for the new symbol |
Definition at line 559 of file recursive_initialization.cpp.
|
private |
Construct a new global symbol of type int
and set it's value to initial_value
.
symbol_name | the base name for the new symbol |
initial_value | the value the symbol should be initialised with |
symbol_name
) Definition at line 503 of file recursive_initialization.cpp.
|
private |
Construct a new global symbol of type int
initialised to 0.
symbol_name | the base name for the new symbol |
Definition at line 516 of file recursive_initialization.cpp.
|
private |
Construct a new local symbol of type int
initialised to 0.
symbol_name | the base name for the new symbol |
Definition at line 528 of file recursive_initialization.cpp.
|
private |
Construct a new local symbol of type type
initialised to init_value
.
symbol_name | the base name for the new symbol |
type | type for the new symbol |
Definition at line 543 of file recursive_initialization.cpp.
|
private |
Construct a new parameter symbol of type param_type
.
param_name | the base name for the new parameter |
param_type | type for the new symbol |
Definition at line 580 of file recursive_initialization.cpp.
|
private |
Get the malloc function as symbol exprt, and inserts it into the goto-model if it doesn't exist already.
Definition at line 375 of file recursive_initialization.cpp.
|
private |
Recover the symbol expression from symbol table.
symbol_name | the name of the symbol to get |
Definition at line 599 of file recursive_initialization.cpp.
void recursive_initializationt::initialize | ( | const exprt & | lhs, |
const exprt & | depth, | ||
code_blockt & | body | ||
) |
Generate initialisation code for lhs into body.
lhs | The expression to initialise. |
depth | The number of pointer follows. Starts at 0. |
body | The code block to write initialisation code to. |
Definition at line 138 of file recursive_initialization.cpp.
|
private |
Select the specified struct-member to be non-deterministically initialized.
lhs | symbol expression of the top structure |
depth | only to be passed |
body | code block for the initializing assignment |
selection_spec | the user specification of the particular member to havoc |
Definition at line 1059 of file recursive_initialization.cpp.
|
private |
Definition at line 413 of file recursive_initialization.cpp.
|
inlinestatic |
Definition at line 106 of file recursive_initialization.h.
bool recursive_initializationt::needs_freeing | ( | const exprt & | expr | ) | const |
Definition at line 926 of file recursive_initialization.cpp.
|
private |
Definition at line 393 of file recursive_initialization.cpp.
|
private |
Definition at line 429 of file recursive_initialization.cpp.
|
private |
Simple pretty-printer for typet.
Produces strings that can decorate variable names in C.
type | type to be pretty-printed |
Definition at line 606 of file recursive_initialization.cpp.
|
private |
Definition at line 126 of file recursive_initialization.h.
|
private |
Definition at line 122 of file recursive_initialization.h.
|
private |
Definition at line 121 of file recursive_initialization.h.
|
private |
Definition at line 123 of file recursive_initialization.h.
|
private |
Definition at line 124 of file recursive_initialization.h.
|
private |
Definition at line 125 of file recursive_initialization.h.