CBMC
goto_model.h
Go to the documentation of this file.
1 /*******************************************************************\
2 
3 Module: Symbol Table + CFG
4 
5 Author: Daniel Kroening, kroening@kroening.com
6 
7 \*******************************************************************/
8 
11 
12 #ifndef CPROVER_GOTO_PROGRAMS_GOTO_MODEL_H
13 #define CPROVER_GOTO_PROGRAMS_GOTO_MODEL_H
14 
16 #include <util/namespace.h>
17 #include <util/symbol_table.h>
18 
19 #include "abstract_goto_model.h"
20 #include "goto_functions.h"
21 #include "validate_goto_model.h"
22 
23 // A model is a pair consisting of a symbol table
24 // and the CFGs for the functions.
25 
27 {
28 public:
35 
36  void clear()
37  {
40  }
41 
43  {
44  }
45 
46  // Copying is normally too expensive
47  goto_modelt(const goto_modelt &)=delete;
48  goto_modelt &operator=(const goto_modelt &)=delete;
49 
50  // Move operations need to be explicitly enabled as they are deleted with the
51  // copy operations
52  // default for move operations isn't available on Windows yet, so define
53  // explicitly (see https://msdn.microsoft.com/en-us/library/hh567368.aspx
54  // under "Defaulted and Deleted Functions")
55 
57  symbol_table(std::move(other.symbol_table)),
58  goto_functions(std::move(other.goto_functions))
59  {
60  }
61 
63  {
64  symbol_table=std::move(other.symbol_table);
65  goto_functions=std::move(other.goto_functions);
66  return *this;
67  }
68 
72  std::size_t unload(const irep_idt &name)
73  {
74  return goto_functions.unload(name);
75  }
76 
77  // Implement the abstract goto model interface:
78 
79  const goto_functionst &get_goto_functions() const override
80  {
81  return goto_functions;
82  }
83 
84  const symbol_tablet &get_symbol_table() const override
85  {
86  return symbol_table;
87  }
88 
90  const irep_idt &id) override
91  {
92  return goto_functions.function_map.at(id);
93  }
94 
95  bool can_produce_function(const irep_idt &id) const override
96  {
97  return goto_functions.function_map.find(id) !=
99  }
100 
105  void validate(
107  const goto_model_validation_optionst &goto_model_validation_options =
108  goto_model_validation_optionst{}) const override
109  {
111 
112  // Does a number of checks at the function_mapt level to ensure the
113  // goto_program is well formed. Does not call any validate methods
114  // (at the goto_functiont level or below)
115  validate_goto_model(goto_functions, vm, goto_model_validation_options);
116 
117  const namespacet ns(symbol_table);
118  goto_functions.validate(ns, vm);
119  }
120 };
121 
125 {
126 public:
132  {
133  }
134 
135  const goto_functionst &get_goto_functions() const override
136  {
137  return goto_functions;
138  }
139 
140  const symbol_tablet &get_symbol_table() const override
141  {
142  return symbol_table;
143  }
144 
146  const irep_idt &id) override
147  {
148  return goto_functions.function_map.at(id);
149  }
150 
151  bool can_produce_function(const irep_idt &id) const override
152  {
153  return goto_functions.function_map.find(id) !=
155  }
156 
161  void validate(
162  const validation_modet vm,
163  const goto_model_validation_optionst &goto_model_validation_options)
164  const override
165  {
167 
168  // Does a number of checks at the function_mapt level to ensure the
169  // goto_program is well formed. Does not call any validate methods
170  // (at the goto_functiont level or below)
171  validate_goto_model(goto_functions, vm, goto_model_validation_options);
172 
173  const namespacet ns(symbol_table);
174  goto_functions.validate(ns, vm);
175  }
176 
177 private:
180 };
181 
190 {
191 public:
204  const irep_idt &function_id,
210  {
211  }
212 
217  {
219  }
220 
226  {
227  return symbol_table;
228  }
229 
233  {
234  return goto_function;
235  }
236 
240  {
241  return function_id;
242  }
243 
244 private:
249 };
250 
251 #endif // CPROVER_GOTO_PROGRAMS_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.
std::size_t unload(const irep_idt &name)
Remove the function named name from the function map, if it exists.
function_mapt function_map
::goto_functiont goto_functiont
void compute_location_numbers()
void validate(const namespacet &, validation_modet) const
Check that the goto functions are well-formed.
Interface providing access to a single function in a GOTO model, plus its associated symbol table.
Definition: goto_model.h:190
journalling_symbol_tablet & symbol_table
Definition: goto_model.h:245
const irep_idt & get_function_id()
Get function id.
Definition: goto_model.h:239
goto_model_functiont(journalling_symbol_tablet &symbol_table, goto_functionst &goto_functions, const irep_idt &function_id, goto_functionst::goto_functiont &goto_function)
Construct a function wrapper.
Definition: goto_model.h:201
goto_functionst::goto_functiont & get_goto_function()
Get GOTO function.
Definition: goto_model.h:232
goto_functionst::goto_functiont & goto_function
Definition: goto_model.h:248
void compute_location_numbers()
Re-number our goto_function.
Definition: goto_model.h:216
goto_functionst & goto_functions
Definition: goto_model.h:246
journalling_symbol_tablet & get_symbol_table()
Get symbol table.
Definition: goto_model.h:225
const goto_functionst & get_goto_functions() const override
Accessor to get a raw goto_functionst.
Definition: goto_model.h:79
const goto_functionst::goto_functiont & get_goto_function(const irep_idt &id) override
Get a GOTO function by name, or throw if no such function exists.
Definition: goto_model.h:89
goto_modelt & operator=(const goto_modelt &)=delete
const symbol_tablet & get_symbol_table() const override
Accessor to get the symbol table.
Definition: goto_model.h:84
goto_modelt & operator=(goto_modelt &&other)
Definition: goto_model.h:62
void clear()
Definition: goto_model.h:36
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: goto_model.h:105
bool can_produce_function(const irep_idt &id) const override
Determines if this model can produce a body for the given function.
Definition: goto_model.h:95
symbol_tablet symbol_table
Symbol table.
Definition: goto_model.h:31
goto_modelt(const goto_modelt &)=delete
goto_modelt(goto_modelt &&other)
Definition: goto_model.h:56
goto_functionst goto_functions
GOTO functions.
Definition: goto_model.h:34
std::size_t unload(const irep_idt &name)
Remove the function named name from the function map, if it exists.
Definition: goto_model.h:72
A symbol table wrapper that records which entries have been updated/removedA caller can pass a journa...
A namespacet is essentially one or two symbol tables bound together, to allow for symbol lookups in t...
Definition: namespace.h:94
The symbol table.
Definition: symbol_table.h:14
virtual void clear() override
Wipe internal state of the symbol table.
Definition: symbol_table.h:101
void validate(const validation_modet vm=validation_modet::INVARIANT) const override
Check that the symbol table is well-formed.
Class providing the abstract GOTO model interface onto an unrelated symbol table and goto_functionst.
Definition: goto_model.h:125
const symbol_tablet & symbol_table
Definition: goto_model.h:178
const goto_functionst & goto_functions
Definition: goto_model.h:179
bool can_produce_function(const irep_idt &id) const override
Determines if this model can produce a body for the given function.
Definition: goto_model.h:151
const goto_functionst::goto_functiont & get_goto_function(const irep_idt &id) override
Get a GOTO function by name, or throw if no such function exists.
Definition: goto_model.h:145
const goto_functionst & get_goto_functions() const override
Accessor to get a raw goto_functionst.
Definition: goto_model.h:135
void validate(const validation_modet vm, const goto_model_validation_optionst &goto_model_validation_options) const override
Check that the goto model is well-formed.
Definition: goto_model.h:161
wrapper_goto_modelt(const symbol_tablet &symbol_table, const goto_functionst &goto_functions)
Definition: goto_model.h:127
const symbol_tablet & get_symbol_table() const override
Accessor to get the symbol table.
Definition: goto_model.h:140
Goto Programs with Functions.
Author: Diffblue Ltd.
Author: Diffblue Ltd.
void validate_goto_model(const goto_functionst &goto_functions, const validation_modet vm, const goto_model_validation_optionst validation_options)
validation_modet