cprover
rebuild_goto_start_function.cpp
Go to the documentation of this file.
1 /*******************************************************************\
2 
3 Module: Goto Programs
4 
5 Author: Thomas Kiley, thomas@diffblue.com
6 
7 \*******************************************************************/
8 
11 
13 
14 #include <util/symbol.h>
15 #include <util/symbol_table.h>
16 #include <util/prefix.h>
17 #include <util/cmdline.h>
18 
19 #include <langapi/mode.h>
20 #include <langapi/language.h>
21 
23 
24 #include <memory>
25 
26 std::unique_ptr<languaget> get_entry_point_language(
27  const symbol_table_baset &symbol_table,
28  const optionst &options,
29  message_handlert &message_handler)
30 {
31  const irep_idt &mode = get_entry_point_mode(symbol_table);
32 
33  // Get the relevant languaget to generate the new entry point with.
34  std::unique_ptr<languaget> language = get_language_from_mode(mode);
35  // This might fail if the driver program hasn't registered that language.
36  INVARIANT(language, "No language found for mode: " + id2string(mode));
37  language->set_message_handler(message_handler);
38  language->set_language_options(options);
39  return language;
40 }
41 
43 {
44  const symbolt &current_entry_point =
46  return current_entry_point.mode;
47 }
48 
50 {
51  // Remove the function itself
52  symbol_table.remove(goto_functionst::entry_point());
53 
54  // And any symbols created in the scope of the entry point
55  std::vector<irep_idt> entry_point_symbols;
56  for(const auto &symbol_entry : symbol_table.symbols)
57  {
58  const bool is_entry_point_symbol=
59  has_prefix(
60  id2string(symbol_entry.first),
62 
63  if(is_entry_point_symbol)
64  entry_point_symbols.push_back(symbol_entry.first);
65  }
66 
67  for(const irep_idt &entry_point_symbol : entry_point_symbols)
68  {
69  symbol_table.remove(entry_point_symbol);
70  }
71 }
dstringt has one field, an unsigned integer no which is an index into a static table of strings.
Definition: dstring.h:37
static irep_idt entry_point()
Get the identifier of the entry point to a goto model.
The symbol table base class interface.
bool remove(const irep_idt &name)
Remove a symbol from the symbol table.
const symbolst & symbols
Read-only field, used to look up symbols given their names.
const symbolt & lookup_ref(const irep_idt &name) const
Find a symbol in the symbol table for read-only access.
Symbol table entry.
Definition: symbol.h:28
irep_idt mode
Language mode.
Definition: symbol.h:49
bool has_prefix(const std::string &s, const std::string &prefix)
Definition: converter.cpp:13
Goto Programs with Functions.
const std::string & id2string(const irep_idt &d)
Definition: irep.h:49
Abstract interface to support a programming language.
std::unique_ptr< languaget > get_language_from_mode(const irep_idt &mode)
Get the language corresponding to the given mode.
Definition: mode.cpp:50
void remove_existing_entry_point(symbol_table_baset &symbol_table)
Eliminate the existing entry point function symbol and any symbols created in that scope from the sym...
std::unique_ptr< languaget > get_entry_point_language(const symbol_table_baset &symbol_table, const optionst &options, message_handlert &message_handler)
Find the language corresponding to the __CPROVER_start function.
const irep_idt & get_entry_point_mode(const symbol_table_baset &symbol_table)
Find out the mode of the current entry point to determine the mode of the replacement entry point.
Goto Programs Author: Thomas Kiley, thomas@diffblue.com.
#define INVARIANT(CONDITION, REASON)
This macro uses the wrapper function 'invariant_violated_string'.
Definition: invariant.h:424
Symbol table entry.
Author: Diffblue Ltd.