|
CBMC
|
Class for generating initialisation code for compound structures. More...
#include <recursive_initialization.h>
Collaboration diagram for recursive_initializationt: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. | |
| 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 | |
| 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. | |
| symbol_exprt | get_fresh_global_symexpr (const std::string &symbol_name) const |
Construct a new global symbol of type int initialised to 0. | |
| symbol_exprt | get_fresh_local_symexpr (const std::string &symbol_name) const |
Construct a new local symbol of type int initialised to 0. | |
| 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. | |
| const symbolt & | get_fresh_fun_symbol (const std::string &fun_name, const typet &fun_type) |
Construct a new function symbol of type fun_type. | |
| symbolt & | get_fresh_param_symbol (const std::string ¶m_name, const typet ¶m_type) |
Construct a new parameter symbol of type param_type. | |
| symbol_exprt | get_symbol_expr (const irep_idt &symbol_name) const |
| Recover the symbol expression from symbol table. | |
| std::string | type2id (const typet &type) const |
| Simple pretty-printer for typet. | |
| 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. | |
| irep_idt | build_constructor (const exprt &expr) |
Check if a constructor for the type of expr already exists and create it if not. | |
| code_blockt | build_function_pointer_constructor (const symbol_exprt &result, bool is_nullable) |
| Constructor for function pointers. | |
| 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. | |
| code_blockt | build_struct_constructor (const exprt &depth, const symbol_exprt &result) |
| Constructor for structures: simply iterates over members and initialise each one. | |
| code_blockt | build_nondet_constructor (const symbol_exprt &result) const |
| Default constructor: assigns non-deterministic value of the right type. | |
| code_blockt | build_array_constructor (const exprt &depth, const symbol_exprt &result) |
| Constructor for arrays: simply iterates over elements and initialise each one. | |
| 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. | |
| 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. | |
| code_blockt | deallocate_code (const exprt &pointer) const |
Generate code mimicking __CPROVER_deallocate (which is what C's free calls) with pointer as argument. | |
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.
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 714 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 786 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 976 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 774 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 615 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 736 of file recursive_initialization.cpp.
|
private |
Generate code mimicking __CPROVER_deallocate (which is what C's free calls) with pointer as argument.
Definition at line 919 of file recursive_initialization.cpp.
|
private |
Definition at line 383 of file recursive_initialization.cpp.
| void recursive_initializationt::free_cluster_origins | ( | code_blockt & | body | ) |
Definition at line 968 of file recursive_initialization.cpp.
| void recursive_initializationt::free_if_possible | ( | const exprt & | expr, |
| code_blockt & | body | ||
| ) |
Definition at line 936 of file recursive_initialization.cpp.
|
private |
Definition at line 403 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 541 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 485 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 498 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 510 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 525 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 562 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 581 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 1049 of file recursive_initialization.cpp.
|
private |
Definition at line 395 of file recursive_initialization.cpp.
|
inlinestatic |
Definition at line 101 of file recursive_initialization.h.
Definition at line 899 of file recursive_initialization.cpp.
|
private |
Definition at line 375 of file recursive_initialization.cpp.
|
private |
Definition at line 411 of file recursive_initialization.cpp.
Simple pretty-printer for typet.
Produces strings that can decorate variable names in C.
| type | type to be pretty-printed |
Definition at line 588 of file recursive_initialization.cpp.
|
private |
Definition at line 121 of file recursive_initialization.h.
|
private |
Definition at line 117 of file recursive_initialization.h.
|
private |
Definition at line 116 of file recursive_initialization.h.
|
private |
Definition at line 118 of file recursive_initialization.h.
|
private |
Definition at line 119 of file recursive_initialization.h.
|
private |
Definition at line 120 of file recursive_initialization.h.