CBMC
lazy_goto_model.h
Go to the documentation of this file.
1 
5 
6 #ifndef CPROVER_GOTO_PROGRAMS_LAZY_GOTO_MODEL_H
7 #define CPROVER_GOTO_PROGRAMS_LAZY_GOTO_MODEL_H
8 
10 
14 
16 
17 class optionst;
18 
43 {
44 public:
52  typedef std::function<
53  void(goto_model_functiont &function, const abstract_goto_modelt &model)>
55 
61  typedef std::function<bool(goto_modelt &goto_model)> post_process_functionst;
62 
71 
94 
122  explicit lazy_goto_modelt(
128 
130 
132  {
133  goto_model = std::move(other.goto_model);
134  language_files = std::move(other.language_files);
135  return *this;
136  }
137 
152  template <typename THandler>
154  THandler &handler,
155  const optionst &options,
157  {
158  return lazy_goto_modelt(
159  [&handler,
160  &options](goto_model_functiont &fun, const abstract_goto_modelt &model) {
161  handler.process_goto_function(fun, model, options);
162  },
163  [&handler, &options](goto_modelt &goto_model) -> bool {
164  return handler.process_goto_functions(goto_model, options);
165  },
166  [&handler](const irep_idt &name) -> bool {
167  return handler.can_generate_function_body(name);
168  },
169  [&handler](
170  const irep_idt &function_name,
172  goto_functiont &function,
173  bool is_first_chance) {
174  return handler.generate_function_body(
175  function_name, symbol_table, function, is_first_chance);
176  },
178  }
179 
180  void
181  initialize(const std::vector<std::string> &files, const optionst &options);
182 
184  void load_all_functions() const;
185 
186  language_filet &add_language_file(const std::string &filename)
187  {
188  return language_files.add_file(filename);
189  }
190 
197  static std::unique_ptr<goto_modelt>
199  {
200  if(model.finalize())
201  return nullptr;
202  return std::move(model.goto_model);
203  }
204 
205  // Implement the abstract_goto_modelt interface:
206 
211  const goto_functionst &get_goto_functions() const override
212  {
213  return goto_model->goto_functions;
214  }
215 
216  const symbol_tablet &get_symbol_table() const override
217  {
218  return symbol_table;
219  }
220 
221  bool can_produce_function(const irep_idt &id) const override;
222 
238  get_goto_function(const irep_idt &id) override
239  {
240  return goto_functions.at(id);
241  }
242 
247  void validate(
249  const goto_model_validation_optionst &goto_model_validation_options =
250  goto_model_validation_optionst{}) const override
251  {
252  goto_model->validate(vm, goto_model_validation_options);
253  }
254 
255 private:
256  std::unique_ptr<goto_modelt> goto_model;
257 
258 public:
261 
262 private:
265 
266  // Function/module processing functions
271 
274 
275  bool finalize();
276 };
277 
278 #endif // CPROVER_GOTO_PROGRAMS_LAZY_GOTO_MODEL_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::can_generate_function_bodyt
std::function< bool(const irep_idt &name)> can_generate_function_bodyt
Definition: lazy_goto_functions_map.h:57
lazy_goto_modelt::symbol_table
symbol_tablet & symbol_table
Reference to symbol_table in the internal goto_model.
Definition: lazy_goto_model.h:260
symbol_tablet
The symbol table.
Definition: symbol_table.h:13
lazy_goto_modelt::validate
void validate(const validation_modet vm=validation_modet::INVARIANT, const goto_model_validation_optionst &goto_model_validation_options=goto_model_validation_optionst{}) const override
Check that the goto model is well-formed.
Definition: lazy_goto_model.h:247
lazy_goto_modelt::driver_program_generate_function_body
const generate_function_bodyt driver_program_generate_function_body
Definition: lazy_goto_model.h:270
optionst
Definition: options.h:22
lazy_goto_modelt::goto_functions
const lazy_goto_functions_mapt goto_functions
Definition: lazy_goto_model.h:263
lazy_goto_modelt::process_whole_model_and_freeze
static std::unique_ptr< goto_modelt > process_whole_model_and_freeze(lazy_goto_modelt &&model)
The model returned here has access to the functions we've already loaded but is frozen in the sense t...
Definition: lazy_goto_model.h:198
lazy_goto_modelt::add_language_file
language_filet & add_language_file(const std::string &filename)
Definition: lazy_goto_model.h:186
lazy_goto_modelt::language_files
language_filest language_files
Definition: lazy_goto_model.h:264
language_filet
Definition: language_file.h:41
goto_model_validation_optionst
Definition: validate_goto_model.h:15
goto_model.h
lazy_goto_functions_mapt
Provides a wrapper for a map of lazily loaded goto_functiont.
Definition: lazy_goto_functions_map.h:29
goto_modelt
Definition: goto_model.h:25
lazy_goto_modelt::operator=
lazy_goto_modelt & operator=(lazy_goto_modelt &&other)
Definition: lazy_goto_model.h:131
lazy_goto_modelt::can_produce_function
bool can_produce_function(const irep_idt &id) const override
Determines if this model can produce a body for the given function.
Definition: lazy_goto_model.cpp:241
lazy_goto_modelt::message_handler
message_handlert & message_handler
Logging helper field.
Definition: lazy_goto_model.h:273
lazy_goto_modelt::can_generate_function_bodyt
lazy_goto_functions_mapt::can_generate_function_bodyt can_generate_function_bodyt
Callback function that determines whether the creator of a lazy_goto_modelt can itself supply a funct...
Definition: lazy_goto_model.h:70
lazy_goto_modelt::driver_program_can_generate_function_body
const can_generate_function_bodyt driver_program_can_generate_function_body
Definition: lazy_goto_model.h:269
lazy_goto_modelt::finalize
bool finalize()
Definition: lazy_goto_model.cpp:216
lazy_goto_modelt::from_handler_object
static lazy_goto_modelt from_handler_object(THandler &handler, const optionst &options, message_handlert &message_handler)
Create a lazy_goto_modelt from a object that defines function/module pass handlers.
Definition: lazy_goto_model.h:153
lazy_goto_modelt::get_goto_function
const goto_functionst::goto_functiont & get_goto_function(const irep_idt &id) override
Get a GOTO function body.
Definition: lazy_goto_model.h:238
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
abstract_goto_model.h
lazy_goto_modelt
A GOTO model that produces function bodies on demand.
Definition: lazy_goto_model.h:42
symbol_table_baset
The symbol table base class interface.
Definition: symbol_table_base.h:21
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_modelt::generate_function_bodyt
lazy_goto_functions_mapt::generate_function_bodyt generate_function_bodyt
Callback function that may provide a body for a GOTO function, either as a fallback (when we don't ha...
Definition: lazy_goto_model.h:93
lazy_goto_functions_map.h
Author: Diffblue Ltd.
lazy_goto_modelt::goto_model
std::unique_ptr< goto_modelt > goto_model
Definition: lazy_goto_model.h:256
validation_modet
validation_modet
Definition: validation_mode.h:12
language_filest::add_file
language_filet & add_file(const std::string &filename)
Definition: language_file.h:77
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_modelt::initialize
void initialize(const std::vector< std::string > &files, const optionst &options)
Performs initial symbol table and language_filest initialization from a given commandline and parsed ...
Definition: lazy_goto_model.cpp:114
lazy_goto_modelt::post_process_functions
const post_process_functionst post_process_functions
Definition: lazy_goto_model.h:268
lazy_goto_modelt::post_process_function
const post_process_functiont post_process_function
Definition: lazy_goto_model.h:267
goto_functionst::goto_functiont
::goto_functiont goto_functiont
Definition: goto_functions.h:27
goto_functionst
A collection of goto functions.
Definition: goto_functions.h:24
abstract_goto_modelt
Abstract interface to eager or lazy GOTO models.
Definition: abstract_goto_model.h:20
lazy_goto_modelt::load_all_functions
void load_all_functions() const
Eagerly loads all functions from the symbol table.
Definition: lazy_goto_model.cpp:187
lazy_goto_modelt::post_process_functiont
std::function< void(goto_model_functiont &function, const abstract_goto_modelt &model)> post_process_functiont
Callback function that post-processes a GOTO function.
Definition: lazy_goto_model.h:54
goto_convert_functions.h
lazy_goto_modelt::get_goto_functions
const goto_functionst & get_goto_functions() const override
Accessor to retrieve the internal goto_functionst.
Definition: lazy_goto_model.h:211
lazy_goto_modelt::post_process_functionst
std::function< bool(goto_modelt &goto_model)> post_process_functionst
Callback function that post-processes a whole GOTO model.
Definition: lazy_goto_model.h:61
goto_model_functiont
Interface providing access to a single function in a GOTO model, plus its associated symbol table.
Definition: goto_model.h:182
lazy_goto_modelt::lazy_goto_modelt
lazy_goto_modelt(post_process_functiont post_process_function, post_process_functionst post_process_functions, can_generate_function_bodyt driver_program_can_generate_function_body, generate_function_bodyt driver_program_generate_function_body, message_handlert &message_handler)
Construct a lazy GOTO model, supplying callbacks that customise its behaviour.
lazy_goto_modelt::get_symbol_table
const symbol_tablet & get_symbol_table() const override
Accessor to get the symbol table.
Definition: lazy_goto_model.h:216
validation_modet::INVARIANT
@ INVARIANT
language_file.h
language_filest
Definition: language_file.h:62