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 
9 #include <unordered_set>
10 
13 
14 #include <langapi/language_file.h>
16 #include <util/message.h>
18 
30 {
31 public:
32  // NOLINTNEXTLINE(readability/identifiers) - name matches those used in STL
33  typedef irep_idt key_type;
34  // NOLINTNEXTLINE(readability/identifiers) - name matches those used in STL
37  // NOLINTNEXTLINE(readability/identifiers) - name matches mapped_type
39  // NOLINTNEXTLINE(readability/identifiers) - name matches those used in STL
40  typedef std::pair<const key_type, goto_functiont> value_type;
41  // NOLINTNEXTLINE(readability/identifiers) - name matches those used in STL
43  // NOLINTNEXTLINE(readability/identifiers) - name matches those used in STL
44  typedef const value_type &const_reference;
45  // NOLINTNEXTLINE(readability/identifiers) - name matches those used in STL
46  typedef value_type *pointer;
47  // NOLINTNEXTLINE(readability/identifiers) - name matches those used in STL
48  typedef const value_type *const_pointer;
49  // NOLINTNEXTLINE(readability/identifiers) - name matches those used in STL
50  typedef std::size_t size_type;
51 
52  typedef std::function<void(
53  const irep_idt &name,
55  journalling_symbol_tablet &function_symbols)>
57  typedef std::function<bool(const irep_idt &name)> can_generate_function_bodyt;
58  typedef std::function<bool(
59  const irep_idt &function_name,
61  goto_functiont &function,
62  bool body_available)>
64 
65 private:
66  typedef std::map<key_type, goto_functiont> underlying_mapt;
71  mutable std::unordered_set<irep_idt> processed_functions;
72 
79 
80 public:
99  {
100  }
101 
105  const_mapped_type at(const key_type &name) const
106  {
107  return ensure_function_loaded_internal(name).second;
108  }
109 
113  mapped_type at(const key_type &name)
114  {
115  return ensure_function_loaded_internal(name).second;
116  }
117 
123  bool can_produce_function(const key_type &name) const
124  {
127  }
128 
129  void unload(const key_type &name) const
130  {
131  goto_functions.erase(name);
132  }
133 
134  void ensure_function_loaded(const key_type &name) const
135  {
137  }
138 
139 private:
140  // This returns a non-const reference, but if you use this method from a
141  // const method then you should not return such a reference without making it
142  // const first
144  {
145  symbol_table_buildert symbol_table_builder =
147 
148  journalling_symbol_tablet journalling_table =
149  journalling_symbol_tablet::wrap(symbol_table_builder);
150  reference named_function = ensure_entry_converted(name, journalling_table);
151  mapped_type function = named_function.second;
152  if(processed_functions.count(name) == 0)
153  {
154  // Run function-pass conversions
155  post_process_function(name, function, journalling_table);
156  // Assign procedure-local location numbers for now
157  function.body.compute_location_numbers();
158  processed_functions.insert(name);
159  }
160  return named_function;
161  }
162 
172  const key_type &name,
173  symbol_table_baset &function_symbol_table) const
174  {
175  // Fill in symbol table entry body if not already done
176  language_files.convert_lazy_method(name, function_symbol_table);
177 
178  underlying_mapt::iterator it = goto_functions.find(name);
179  if(it != goto_functions.end())
180  return *it;
181 
182  goto_functiont function;
183 
184  // First chance: see if the driver program wants to provide a replacement:
185  bool body_provided = driver_program_generate_function_body(
186  name,
187  function_symbol_table,
188  function,
190 
191  // Second chance: see if language_filest can provide a body:
192  if(!body_provided)
193  {
194  // Create goto_functiont
195  goto_convert_functionst convert_functions(
196  function_symbol_table, message_handler);
197  convert_functions.convert_function(name, function);
198  }
199 
200  // Add to map
201  return *goto_functions.emplace(name, std::move(function)).first;
202  }
203 };
204 
205 #endif // CPROVER_GOTO_PROGRAMS_LAZY_GOTO_FUNCTIONS_MAP_H
dstringt
dstringt has one field, an unsigned integer no which is an index into a static table of strings.
Definition: dstring.h:36
lazy_goto_functions_mapt::symbol_table
symbol_tablet & symbol_table
Definition: lazy_goto_functions_map.h:74
lazy_goto_functions_mapt::can_produce_function
bool can_produce_function(const key_type &name) const
Determines if this lazy GOTO functions map can produce a body for the given function.
Definition: lazy_goto_functions_map.h:123
lazy_goto_functions_mapt::can_generate_function_bodyt
std::function< bool(const irep_idt &name)> can_generate_function_bodyt
Definition: lazy_goto_functions_map.h:57
symbol_tablet
The symbol table.
Definition: symbol_table.h:13
journalling_symbol_tablet::wrap
static journalling_symbol_tablet wrap(symbol_table_baset &base_symbol_table)
Definition: journalling_symbol_table.h:80
lazy_goto_functions_mapt::post_process_function
const post_process_functiont post_process_function
Definition: lazy_goto_functions_map.h:75
lazy_goto_functions_mapt::language_files
language_filest & language_files
Definition: lazy_goto_functions_map.h:73
goto_convert_functionst::convert_function
void convert_function(const irep_idt &identifier, goto_functionst::goto_functiont &result)
Definition: goto_convert_functions.cpp:142
lazy_goto_functions_mapt::ensure_function_loaded_internal
reference ensure_function_loaded_internal(const key_type &name) const
Definition: lazy_goto_functions_map.h:143
lazy_goto_functions_mapt::ensure_entry_converted
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...
Definition: lazy_goto_functions_map.h:171
lazy_goto_functions_mapt
Provides a wrapper for a map of lazily loaded goto_functiont.
Definition: lazy_goto_functions_map.h:29
journalling_symbol_table.h
Author: Diffblue Ltd.
lazy_goto_functions_mapt::unload
void unload(const key_type &name) const
Definition: lazy_goto_functions_map.h:129
lazy_goto_functions_mapt::key_type
irep_idt key_type
Definition: lazy_goto_functions_map.h:33
lazy_goto_functions_mapt::mapped_type
goto_functiont & mapped_type
Definition: lazy_goto_functions_map.h:35
lazy_goto_functions_mapt::post_process_functiont
std::function< void(const irep_idt &name, goto_functionst::goto_functiont &function, journalling_symbol_tablet &function_symbols)> post_process_functiont
Definition: lazy_goto_functions_map.h:56
lazy_goto_functions_mapt::const_reference
const typedef value_type & const_reference
Definition: lazy_goto_functions_map.h:44
lazy_goto_functions_mapt::message_handler
message_handlert & message_handler
Definition: lazy_goto_functions_map.h:78
lazy_goto_functions_mapt::at
const_mapped_type at(const key_type &name) const
Gets the body for a given function.
Definition: lazy_goto_functions_map.h:105
lazy_goto_functions_mapt::const_mapped_type
const typedef goto_functiont & const_mapped_type
The type of elements returned by const members.
Definition: lazy_goto_functions_map.h:38
symbol_table_baset
The symbol table base class interface.
Definition: symbol_table_base.h:21
lazy_goto_functions_mapt::reference
value_type & reference
Definition: lazy_goto_functions_map.h:42
goto_convert_functionst
Definition: goto_convert_functions.h:40
lazy_goto_functions_mapt::generate_function_bodyt
std::function< bool(const irep_idt &function_name, symbol_table_baset &symbol_table, goto_functiont &function, bool body_available)> generate_function_bodyt
Definition: lazy_goto_functions_map.h:63
lazy_goto_functions_mapt::value_type
std::pair< const key_type, goto_functiont > value_type
Definition: lazy_goto_functions_map.h:40
lazy_goto_functions_mapt::driver_program_can_generate_function_body
const can_generate_function_bodyt driver_program_can_generate_function_body
Definition: lazy_goto_functions_map.h:76
message_handlert
Definition: message.h:27
goto_functiont
A goto function, consisting of function body (see body) and parameter identifiers (see parameter_iden...
Definition: goto_function.h:23
lazy_goto_functions_mapt::const_pointer
const typedef value_type * const_pointer
Definition: lazy_goto_functions_map.h:48
language_filest::convert_lazy_method
void convert_lazy_method(const irep_idt &id, symbol_table_baset &symbol_table)
Definition: language_file.h:121
lazy_goto_functions_mapt::lazy_goto_functions_mapt
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.
Definition: lazy_goto_functions_map.h:82
goto_functionst::goto_functiont
::goto_functiont goto_functiont
Definition: goto_functions.h:27
lazy_goto_functions_mapt::processed_functions
std::unordered_set< irep_idt > processed_functions
Names of functions that are already fully available in the programt state.
Definition: lazy_goto_functions_map.h:71
symbol_table_buildert::wrap
static symbol_table_buildert wrap(symbol_table_baset &base_symbol_table)
Definition: symbol_table_builder.h:42
symbol_table_buildert
Author: Diffblue Ltd.
Definition: symbol_table_builder.h:13
lazy_goto_functions_mapt::ensure_function_loaded
void ensure_function_loaded(const key_type &name) const
Definition: lazy_goto_functions_map.h:134
goto_functions.h
lazy_goto_functions_mapt::size_type
std::size_t size_type
Definition: lazy_goto_functions_map.h:50
lazy_goto_functions_mapt::pointer
value_type * pointer
Definition: lazy_goto_functions_map.h:46
lazy_goto_functions_mapt::driver_program_generate_function_body
const generate_function_bodyt driver_program_generate_function_body
Definition: lazy_goto_functions_map.h:77
language_filest::can_convert_lazy_method
bool can_convert_lazy_method(const irep_idt &id) const
Definition: language_file.h:131
lazy_goto_functions_mapt::underlying_mapt
std::map< key_type, goto_functiont > underlying_mapt
Definition: lazy_goto_functions_map.h:66
goto_convert_functions.h
lazy_goto_functions_mapt::goto_functions
underlying_mapt & goto_functions
Definition: lazy_goto_functions_map.h:67
lazy_goto_functions_mapt::at
mapped_type at(const key_type &name)
Gets the body for a given function.
Definition: lazy_goto_functions_map.h:113
message.h
symbol_table_builder.h
journalling_symbol_tablet
A symbol table wrapper that records which entries have been updated/removed.
Definition: journalling_symbol_table.h:35
language_file.h
language_filest
Definition: language_file.h:62