CBMC
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
lazy_goto_functions_map.h
Go to the documentation of this file.
1
2
5
6#ifndef CPROVER_GOTO_PROGRAMS_LAZY_GOTO_FUNCTIONS_MAP_H
7#define CPROVER_GOTO_PROGRAMS_LAZY_GOTO_FUNCTIONS_MAP_H
8
10#include <util/message.h>
12
14
17
18#include <unordered_set>
19
31{
32public:
33 // NOLINTNEXTLINE(readability/identifiers) - name matches those used in STL
35 // NOLINTNEXTLINE(readability/identifiers) - name matches those used in STL
38 // NOLINTNEXTLINE(readability/identifiers) - name matches mapped_type
40 // NOLINTNEXTLINE(readability/identifiers) - name matches those used in STL
41 typedef std::pair<const key_type, goto_functiont> value_type;
42 // NOLINTNEXTLINE(readability/identifiers) - name matches those used in STL
44 // NOLINTNEXTLINE(readability/identifiers) - name matches those used in STL
46 // NOLINTNEXTLINE(readability/identifiers) - name matches those used in STL
48 // NOLINTNEXTLINE(readability/identifiers) - name matches those used in STL
49 typedef const value_type *const_pointer;
50 // NOLINTNEXTLINE(readability/identifiers) - name matches those used in STL
51 typedef std::size_t size_type;
52
53 typedef std::function<void(
54 const irep_idt &name,
58 typedef std::function<bool(const irep_idt &name)> can_generate_function_bodyt;
59 typedef std::function<bool(
60 const irep_idt &function_name,
62 goto_functiont &function,
63 bool body_available)>
65
66private:
67 typedef std::map<key_type, goto_functiont> underlying_mapt;
72 mutable std::unordered_set<irep_idt> processed_functions;
73
80
81public:
102
106 const_mapped_type at(const key_type &name) const
107 {
108 return ensure_function_loaded_internal(name).second;
109 }
110
115 {
116 return ensure_function_loaded_internal(name).second;
117 }
118
129
133 std::size_t unload(const key_type &name) const
134 {
135 return goto_functions.erase(name);
136 }
137
138 void ensure_function_loaded(const key_type &name) const
139 {
141 }
142
143private:
144 // This returns a non-const reference, but if you use this method from a
145 // const method then you should not return such a reference without making it
146 // const first
148 {
151
155 mapped_type function = named_function.second;
156 if(processed_functions.count(name) == 0)
157 {
158 // Run function-pass conversions
160 // Assign procedure-local location numbers for now
162 processed_functions.insert(name);
163 }
164 return named_function;
165 }
166
176 const key_type &name,
178 {
179 // Fill in symbol table entry body if not already done
182
183 underlying_mapt::iterator it = goto_functions.find(name);
184 if(it != goto_functions.end())
185 return *it;
186
187 goto_functiont function;
188
189 // First chance: see if the driver program wants to provide a replacement:
191 name,
193 function,
195
196 // Second chance: see if language_filest can provide a body:
197 if(!body_provided)
198 {
199 // Create goto_functiont
202 convert_functions.convert_function(name, function);
203 }
204
205 // Add to map
206 return *goto_functions.emplace(name, std::move(function)).first;
207 }
208};
209
210#endif // CPROVER_GOTO_PROGRAMS_LAZY_GOTO_FUNCTIONS_MAP_H
ait supplies three of the four components needed: an abstract interpreter (in this case handling func...
Definition ai.h:562
dstringt has one field, an unsigned integer no which is an index into a static table of strings.
Definition dstring.h:38
::goto_functiont goto_functiont
A goto function, consisting of function body (see body) and parameter identifiers (see parameter_iden...
goto_programt body
void compute_location_numbers(unsigned &nr)
Compute location numbers.
A symbol table wrapper that records which entries have been updated/removedA caller can pass a journa...
static journalling_symbol_tablet wrap(symbol_table_baset &base_symbol_table)
void convert_lazy_method(const irep_idt &id, symbol_table_baset &symbol_table, message_handlert &message_handler)
bool can_convert_lazy_method(const irep_idt &id) const
Provides a wrapper for a map of lazily loaded goto_functiont.
lazy_goto_functions_mapt(underlying_mapt &goto_functions, language_filest &language_files, symbol_tablet &symbol_table, post_process_functiont post_process_function, can_generate_function_bodyt driver_program_can_generate_function_body, generate_function_bodyt driver_program_generate_function_body, message_handlert &message_handler)
Creates a lazy_goto_functions_mapt.
std::size_t unload(const key_type &name) const
Remove the function named name from the function map, if it exists.
const post_process_functiont post_process_function
reference ensure_entry_converted(const key_type &name, symbol_table_baset &function_symbol_table) const
Convert a function if not already converted, then return a reference to its goto_functionst map entry...
void ensure_function_loaded(const key_type &name) const
const_mapped_type at(const key_type &name) const
Gets the body for a given function.
std::unordered_set< irep_idt > processed_functions
Names of functions that are already fully available in the programt state.
mapped_type at(const key_type &name)
Gets the body for a given function.
std::function< bool(const irep_idt &function_name, symbol_table_baset &symbol_table, goto_functiont &function, bool body_available)> generate_function_bodyt
const goto_functiont & const_mapped_type
The type of elements returned by const members.
std::function< bool(const irep_idt &name)> can_generate_function_bodyt
std::pair< const key_type, goto_functiont > value_type
std::map< key_type, goto_functiont > underlying_mapt
const can_generate_function_bodyt driver_program_can_generate_function_body
std::function< void(const irep_idt &name, goto_functionst::goto_functiont &function, journalling_symbol_tablet &function_symbols)> post_process_functiont
const generate_function_bodyt driver_program_generate_function_body
bool can_produce_function(const key_type &name) const
Determines if this lazy GOTO functions map can produce a body for the given function.
reference ensure_function_loaded_internal(const key_type &name) const
The symbol table base class interface.
Author: Diffblue Ltd.
static symbol_table_buildert wrap(symbol_table_baset &base_symbol_table)
The symbol table.
Goto Programs with Functions.
Goto Programs with Functions.
Author: Diffblue Ltd.