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 
13 
15 
16 class optionst;
17 
42 {
43 public:
51  typedef std::function<
52  void(goto_model_functiont &function, const abstract_goto_modelt &model)>
54 
60  typedef std::function<bool(goto_modelt &goto_model)> post_process_functionst;
61 
70 
93 
127 
129 
131  {
132  goto_model = std::move(other.goto_model);
133  language_files = std::move(other.language_files);
134  return *this;
135  }
136 
151  template <typename THandler>
153  THandler &handler,
154  const optionst &options,
156  {
157  return lazy_goto_modelt(
158  [&handler,
159  &options](goto_model_functiont &fun, const abstract_goto_modelt &model) {
160  handler.process_goto_function(fun, model, options);
161  },
162  [&handler, &options](goto_modelt &goto_model) -> bool {
163  return handler.process_goto_functions(goto_model, options);
164  },
165  [&handler](const irep_idt &name) -> bool {
166  return handler.can_generate_function_body(name);
167  },
168  [&handler](
169  const irep_idt &function_name,
171  goto_functiont &function,
172  bool is_first_chance) {
173  return handler.generate_function_body(
174  function_name, symbol_table, function, is_first_chance);
175  },
177  }
178 
179  void
180  initialize(const std::vector<std::string> &files, const optionst &options);
181 
183  void load_all_functions() const;
184 
185  language_filet &add_language_file(const std::string &filename)
186  {
187  return language_files.add_file(filename);
188  }
189 
196  static std::unique_ptr<goto_modelt>
198  {
199  if(model.finalize())
200  return nullptr;
201  return std::move(model.goto_model);
202  }
203 
204  // Implement the abstract_goto_modelt interface:
205 
210  const goto_functionst &get_goto_functions() const override
211  {
212  return goto_model->goto_functions;
213  }
214 
215  const symbol_tablet &get_symbol_table() const override
216  {
217  return symbol_table;
218  }
219 
220  bool can_produce_function(const irep_idt &id) const override;
221 
237  get_goto_function(const irep_idt &id) override
238  {
239  return goto_functions.at(id);
240  }
241 
246  void validate(
248  const goto_model_validation_optionst &goto_model_validation_options =
249  goto_model_validation_optionst{}) const override
250  {
251  goto_model->validate(vm, goto_model_validation_options);
252  }
253 
254 private:
255  std::unique_ptr<goto_modelt> goto_model;
256 
257 public:
260 
261 private:
264 
265  // Function/module processing functions
270 
273 
274  bool finalize();
275 };
276 
277 #endif // CPROVER_GOTO_PROGRAMS_LAZY_GOTO_MODEL_H
Abstract interface to eager or lazy GOTO models.
Abstract interface to eager or lazy GOTO models.
dstringt has one field, an unsigned integer no which is an index into a static table of strings.
Definition: dstring.h:38
A collection of goto functions.
::goto_functiont goto_functiont
A goto function, consisting of function body (see body) and parameter identifiers (see parameter_iden...
Definition: goto_function.h:24
Interface providing access to a single function in a GOTO model, plus its associated symbol table.
Definition: goto_model.h:190
language_filet & add_file(const std::string &filename)
Definition: language_file.h:77
Provides a wrapper for a map of lazily loaded goto_functiont.
const_mapped_type at(const key_type &name) const
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
std::function< bool(const irep_idt &name)> can_generate_function_bodyt
A GOTO model that produces function bodies on demand.
void load_all_functions() const
Eagerly loads all functions from the symbol table.
std::unique_ptr< goto_modelt > goto_model
lazy_goto_modelt(lazy_goto_modelt &&other)
const can_generate_function_bodyt driver_program_can_generate_function_body
const post_process_functiont post_process_function
const generate_function_bodyt driver_program_generate_function_body
lazy_goto_modelt & operator=(lazy_goto_modelt &&other)
const goto_functionst::goto_functiont & get_goto_function(const irep_idt &id) override
Get a GOTO function body.
const goto_functionst & get_goto_functions() const override
Accessor to retrieve the internal goto_functionst.
bool can_produce_function(const irep_idt &id) const override
Determines if this model can produce a body for the given function.
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.
const lazy_goto_functions_mapt goto_functions
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...
language_filest language_files
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.
const post_process_functionst post_process_functions
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...
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.
message_handlert & message_handler
Logging helper field.
std::function< bool(goto_modelt &goto_model)> post_process_functionst
Callback function that post-processes a whole GOTO model.
language_filet & add_language_file(const std::string &filename)
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 ...
std::function< void(goto_model_functiont &function, const abstract_goto_modelt &model)> post_process_functiont
Callback function that post-processes a GOTO function.
symbol_tablet & symbol_table
Reference to symbol_table in the internal goto_model.
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...
const symbol_tablet & get_symbol_table() const override
Accessor to get the symbol table.
The symbol table base class interface.
The symbol table.
Definition: symbol_table.h:14
Symbol Table + CFG.
Author: Diffblue Ltd.
validation_modet