CBMC
dfcc_utils.h
Go to the documentation of this file.
1 /*******************************************************************\
2 
3 Module: Dynamic frame condition checking for function contracts
4 
5 Author: Remi Delmas, delmasrd@amazon.com
6 Date: August 2022
7 
8 \*******************************************************************/
9 
12 
13 #ifndef CPROVER_GOTO_INSTRUMENT_CONTRACTS_DYNAMIC_FRAMES_DFCC_UTILS_H
14 #define CPROVER_GOTO_INSTRUMENT_CONTRACTS_DYNAMIC_FRAMES_DFCC_UTILS_H
15 
16 #include <util/message.h>
17 #include <util/namespace.h>
18 #include <util/std_expr.h>
19 
20 #include <set>
21 
22 class goto_modelt;
23 class goto_programt;
24 class message_handlert;
25 class symbolt;
26 
28 {
30  static bool
31  function_symbol_exists(const goto_modelt &, const irep_idt &function_id);
33  const goto_modelt &,
34  const irep_idt &function_id);
35 
37  static symbolt &
38  get_function_symbol(symbol_table_baset &, const irep_idt &function_id);
39 
47  const typet &type,
48  const irep_idt &function_id,
49  const std::string &base_name,
50  const source_locationt &source_location);
51 
63  static const symbolt &create_static_symbol(
65  const typet &type,
66  const std::string &prefix,
67  const std::string &base_name,
68  const source_locationt &source_location,
69  const irep_idt &mode,
70  const irep_idt &module,
71  const exprt &initial_value,
72  const bool no_nondet_initialization = true);
73 
77  const irep_idt &function_id,
78  const std::string &base_name,
79  const typet &type);
80 
84  static void add_parameter(
85  goto_modelt &,
86  const symbolt &symbol,
87  const irep_idt &function_id);
88 
91  static const symbolt &add_parameter(
92  goto_modelt &,
93  const irep_idt &function_id,
94  const std::string &base_name,
95  const typet &type);
96 
103  static const symbolt &clone_and_rename_function(
104  goto_modelt &goto_model,
105  const irep_idt &function_id,
106  const irep_idt &new_function_id,
107  std::optional<typet> new_return_type);
108 
137  static void wrap_function(
138  goto_modelt &goto_model,
139  const irep_idt &function_id,
140  const irep_idt &wrapped_function_id);
141 
143  static const exprt make_null_check_expr(const exprt &ptr);
144 
146  static exprt make_sizeof_expr(const exprt &expr, const namespacet &);
147 
150  static void inline_function(
151  goto_modelt &goto_model,
152  const irep_idt &function_id,
153  message_handlert &message_handler);
154 
157  static void inline_function(
158  goto_modelt &goto_model,
159  const irep_idt &function_id,
160  std::set<irep_idt> &no_body,
161  std::set<irep_idt> &recursive_call,
162  std::set<irep_idt> &missing_function,
163  std::set<irep_idt> &not_enough_arguments,
164  message_handlert &message_handler);
165 
168  static void inline_program(
169  goto_modelt &goto_model,
170  goto_programt &goto_program,
171  std::set<irep_idt> &no_body,
172  std::set<irep_idt> &recursive_call,
173  std::set<irep_idt> &missing_function,
174  std::set<irep_idt> &not_enough_arguments,
175  message_handlert &message_handler);
176 };
177 
178 #endif
dstringt has one field, an unsigned integer no which is an index into a static table of strings.
Definition: dstring.h:38
Base class for all expressions.
Definition: expr.h:56
A generic container class for the GOTO intermediate representation of one function.
Definition: goto_program.h:73
A namespacet is essentially one or two symbol tables bound together, to allow for symbol lookups in t...
Definition: namespace.h:94
Expression to hold a symbol (variable)
Definition: std_expr.h:131
The symbol table base class interface.
Symbol table entry.
Definition: symbol.h:28
The type of an expression, extends irept.
Definition: type.h:29
API to expression classes.
static symbolt & get_function_symbol(symbol_table_baset &, const irep_idt &function_id)
Returns the symbolt for function_id.
Definition: dfcc_utils.cpp:72
static void inline_function(goto_modelt &goto_model, const irep_idt &function_id, message_handlert &message_handler)
Inlines the given function, aborts on recursive calls during inlining.
Definition: dfcc_utils.cpp:443
static bool function_symbol_with_body_exists(const goto_modelt &, const irep_idt &function_id)
Definition: dfcc_utils.cpp:65
static const exprt make_null_check_expr(const exprt &ptr)
Returns the expression expr == NULL.
Definition: dfcc_utils.cpp:406
static bool function_symbol_exists(const goto_modelt &, const irep_idt &function_id)
Returns true iff the given symbol exists and satisfies requirements.
Definition: dfcc_utils.cpp:58
static exprt make_sizeof_expr(const exprt &expr, const namespacet &)
Returns the expression sizeof(expr).
Definition: dfcc_utils.cpp:411
static const symbolt & create_new_parameter_symbol(symbol_table_baset &, const irep_idt &function_id, const std::string &base_name, const typet &type)
Creates a new parameter symbol for the given function_id.
Definition: dfcc_utils.cpp:124
static void wrap_function(goto_modelt &goto_model, const irep_idt &function_id, const irep_idt &wrapped_function_id)
Given a function to wrap foo and a new name wrapped_foo
Definition: dfcc_utils.cpp:324
static const symbolt & create_static_symbol(symbol_table_baset &, const typet &type, const std::string &prefix, const std::string &base_name, const source_locationt &source_location, const irep_idt &mode, const irep_idt &module, const exprt &initial_value, const bool no_nondet_initialization=true)
Adds a new static symbol named prefix::base_name of type type with value initial_value in the symbol ...
Definition: dfcc_utils.cpp:103
static const symbolt & clone_and_rename_function(goto_modelt &goto_model, const irep_idt &function_id, const irep_idt &new_function_id, std::optional< typet > new_return_type)
Creates a new function symbol and goto_function entry in the goto_functions_map by cloning the given ...
Definition: dfcc_utils.cpp:300
static void add_parameter(goto_modelt &, const symbolt &symbol, const irep_idt &function_id)
Adds the given symbol as parameter to the function symbol's code_type.
Definition: dfcc_utils.cpp:156
static void inline_program(goto_modelt &goto_model, goto_programt &goto_program, std::set< irep_idt > &no_body, std::set< irep_idt > &recursive_call, std::set< irep_idt > &missing_function, std::set< irep_idt > &not_enough_arguments, message_handlert &message_handler)
Inlines the given program, and returns function symbols that caused warnings.
Definition: dfcc_utils.cpp:487
static symbol_exprt create_symbol(symbol_table_baset &, const typet &type, const irep_idt &function_id, const std::string &base_name, const source_locationt &source_location)
Adds a new symbol named function_id::base_name of type type with given attributes in the symbol table...
Definition: dfcc_utils.cpp:81