CBMC
lazy_goto_functions_map.h
Go to the documentation of this file.
1 
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 
16 #include <langapi/language_file.h>
17 
18 #include <unordered_set>
19 
31 {
32 public:
33  // NOLINTNEXTLINE(readability/identifiers) - name matches those used in STL
34  typedef irep_idt key_type;
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
45  typedef const value_type &const_reference;
46  // NOLINTNEXTLINE(readability/identifiers) - name matches those used in STL
47  typedef value_type *pointer;
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,
56  journalling_symbol_tablet &function_symbols)>
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 
66 private:
67  typedef std::map<key_type, goto_functiont> underlying_mapt;
72  mutable std::unordered_set<irep_idt> processed_functions;
73 
80 
81 public:
100  {
101  }
102 
106  const_mapped_type at(const key_type &name) const
107  {
108  return ensure_function_loaded_internal(name).second;
109  }
110 
114  mapped_type at(const key_type &name)
115  {
116  return ensure_function_loaded_internal(name).second;
117  }
118 
124  bool can_produce_function(const key_type &name) const
125  {
128  }
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 
143 private:
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  {
149  symbol_table_buildert symbol_table_builder =
151 
152  journalling_symbol_tablet journalling_table =
153  journalling_symbol_tablet::wrap(symbol_table_builder);
154  reference named_function = ensure_entry_converted(name, journalling_table);
155  mapped_type function = named_function.second;
156  if(processed_functions.count(name) == 0)
157  {
158  // Run function-pass conversions
159  post_process_function(name, function, journalling_table);
160  // Assign procedure-local location numbers for now
161  function.body.compute_location_numbers();
162  processed_functions.insert(name);
163  }
164  return named_function;
165  }
166 
176  const key_type &name,
177  symbol_table_baset &function_symbol_table) const
178  {
179  // Fill in symbol table entry body if not already done
181  name, function_symbol_table, message_handler);
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:
190  bool body_provided = driver_program_generate_function_body(
191  name,
192  function_symbol_table,
193  function,
195 
196  // Second chance: see if language_filest can provide a body:
197  if(!body_provided)
198  {
199  // Create goto_functiont
200  goto_convert_functionst convert_functions(
201  function_symbol_table, message_handler);
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
dstringt has one field, an unsigned integer no which is an index into a static table of strings.
Definition: dstring.h:38
void convert_function(const irep_idt &identifier, goto_functionst::goto_functiont &result)
::goto_functiont goto_functiont
A goto function, consisting of function body (see body) and parameter identifiers (see parameter_iden...
Definition: goto_function.h:24
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 value_type & const_reference
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
message_handlert & message_handler
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.
Definition: symbol_table.h:14
Goto Programs with Functions.
Goto Programs with Functions.
Author: Diffblue Ltd.