cprover
generate_function_bodies.cpp
Go to the documentation of this file.
1 /*******************************************************************\
2 
3 Module: Replace bodies of goto functions
4 
5 Author: Diffblue Ltd.
6 
7 \*******************************************************************/
8 
10 
13 
17 
18 #include <util/arith_tools.h>
19 #include <util/format_expr.h>
20 #include <util/fresh_symbol.h>
21 #include <util/make_unique.h>
22 #include <util/pointer_expr.h>
23 #include <util/prefix.h>
24 #include <util/string2int.h>
25 #include <util/string_utils.h>
26 
28  goto_functiont &function,
29  symbol_tablet &symbol_table,
30  const irep_idt &function_name) const
31 {
32  PRECONDITION(!function.body_available());
33  generate_parameter_names(function, symbol_table, function_name);
34  generate_function_body_impl(function, symbol_table, function_name);
35 }
36 
38  goto_functiont &function,
39  symbol_tablet &symbol_table,
40  const irep_idt &function_name) const
41 {
42  auto &function_symbol = symbol_table.get_writeable_ref(function_name);
43  auto &parameters = to_code_type(function_symbol.type).parameters();
44 
45  int param_counter = 0;
46  for(auto &parameter : parameters)
47  {
48  if(parameter.get_identifier().empty())
49  {
50  const std::string param_base_name =
51  parameter.get_base_name().empty()
52  ? "__param$" + std::to_string(param_counter++)
53  : id2string(parameter.get_base_name());
54  irep_idt new_param_identifier =
55  id2string(function_name) + "::" + param_base_name;
56  parameter.set_base_name(param_base_name);
57  parameter.set_identifier(new_param_identifier);
58  parameter_symbolt new_param_sym;
59  new_param_sym.name = new_param_identifier;
60  new_param_sym.type = parameter.type();
61  new_param_sym.base_name = param_base_name;
62  new_param_sym.mode = function_symbol.mode;
63  new_param_sym.module = function_symbol.module;
64  new_param_sym.location = function_symbol.location;
65  symbol_table.add(new_param_sym);
66  }
67  }
68  function.set_parameter_identifiers(to_code_type(function_symbol.type));
69 }
70 
72 {
73 protected:
75  goto_functiont &function,
76  symbol_tablet &symbol_table,
77  const irep_idt &function_name) const override
78  {
79  auto const &function_symbol = symbol_table.lookup_ref(function_name);
80  // NOLINTNEXTLINE
81  auto add_instruction = [&](goto_programt::instructiont &&i) {
82  auto instruction = function.body.add(std::move(i));
83  instruction->source_location = function_symbol.location;
84  return instruction;
85  };
86  add_instruction(goto_programt::make_assumption(false_exprt()));
87  add_instruction(goto_programt::make_end_function());
88  }
89 };
90 
92 {
93 protected:
95  goto_functiont &function,
96  symbol_tablet &symbol_table,
97  const irep_idt &function_name) const override
98  {
99  auto const &function_symbol = symbol_table.lookup_ref(function_name);
100  // NOLINTNEXTLINE
101  auto add_instruction = [&](goto_programt::instructiont &&i) {
102  auto instruction = function.body.add(std::move(i));
103  instruction->source_location = function_symbol.location;
104  instruction->source_location.set_function(function_name);
105  return instruction;
106  };
107  auto assert_instruction =
108  add_instruction(goto_programt::make_assertion(false_exprt()));
109  const namespacet ns(symbol_table);
110  std::ostringstream comment_stream;
111  comment_stream << id2string(ID_assertion) << " "
112  << format(assert_instruction->get_condition());
113  assert_instruction->source_location.set_comment(comment_stream.str());
114  assert_instruction->source_location.set_property_class(ID_assertion);
115  add_instruction(goto_programt::make_end_function());
116  }
117 };
118 
121 {
122 protected:
124  goto_functiont &function,
125  symbol_tablet &symbol_table,
126  const irep_idt &function_name) const override
127  {
128  auto const &function_symbol = symbol_table.lookup_ref(function_name);
129  // NOLINTNEXTLINE
130  auto add_instruction = [&](goto_programt::instructiont &&i) {
131  auto instruction = function.body.add(std::move(i));
132  instruction->source_location = function_symbol.location;
133  instruction->source_location.set_function(function_name);
134  return instruction;
135  };
136  auto assert_instruction =
137  add_instruction(goto_programt::make_assertion(false_exprt()));
138  const namespacet ns(symbol_table);
139  std::ostringstream comment_stream;
140  comment_stream << id2string(ID_assertion) << " "
141  << format(assert_instruction->get_condition());
142  assert_instruction->source_location.set_comment(comment_stream.str());
143  assert_instruction->source_location.set_property_class(ID_assertion);
144  add_instruction(goto_programt::make_assumption(false_exprt()));
145  add_instruction(goto_programt::make_end_function());
146  }
147 };
148 
150 {
151 public:
153  std::vector<irep_idt> globals_to_havoc,
154  std::regex parameters_to_havoc,
156  message_handlert &message_handler)
161  message(message_handler)
162  {
163  }
164 
166  std::vector<irep_idt> globals_to_havoc,
167  std::vector<std::size_t> param_numbers_to_havoc,
169  message_handlert &message_handler)
174  message(message_handler)
175  {
176  }
177 
178 private:
180  const exprt &lhs,
181  const std::size_t initial_depth,
182  const source_locationt &source_location,
183  const irep_idt &function_id,
184  symbol_tablet &symbol_table,
185  goto_programt &dest) const
186  {
187  symbol_factoryt symbol_factory(
188  symbol_table,
189  source_location,
190  function_id,
193 
194  code_blockt assignments;
195 
196  symbol_factory.gen_nondet_init(
197  assignments,
198  lhs,
199  initial_depth,
201  false); // do not initialize const objects at the top level
202 
203  code_blockt init_code;
204 
205  symbol_factory.declare_created_symbols(init_code);
206  init_code.append(assignments);
207 
208  goto_programt tmp_dest;
209  goto_convert(
210  init_code, symbol_table, tmp_dest, message.get_message_handler(), ID_C);
211 
212  dest.destructive_append(tmp_dest);
213  }
214 
216  const std::string &param_name,
217  std::size_t param_number) const
218  {
219  if(parameters_to_havoc.has_value())
220  {
221  return std::regex_match(param_name, *parameters_to_havoc);
222  }
223  else
224  {
226  return std::binary_search(
227  param_numbers_to_havoc->begin(),
228  param_numbers_to_havoc->end(),
229  param_number);
230  }
231  }
232 
233 protected:
235  goto_functiont &function,
236  symbol_tablet &symbol_table,
237  const irep_idt &function_name) const override
238  {
239  const namespacet ns(symbol_table);
240  // some user input checking
241  if(param_numbers_to_havoc.has_value() && !param_numbers_to_havoc->empty())
242  {
243  auto max_param_number = std::max_element(
245  if(*max_param_number >= function.parameter_identifiers.size())
246  {
248  "function " + id2string(function_name) + " does not take " +
249  std::to_string(*max_param_number + 1) + " arguments",
250  "--generate-havocing-body"};
251  }
252  for(const auto number : *param_numbers_to_havoc)
253  {
254  const auto &parameter = function.parameter_identifiers[number];
255  const symbolt &parameter_symbol = ns.lookup(parameter);
256  if(parameter_symbol.type.id() != ID_pointer)
257  {
259  "argument number " + std::to_string(number) + " of function " +
260  id2string(function_name) + " is not a pointer",
261  "--generate-havocing-body"};
262  }
263  }
264  }
265 
266  auto const &function_symbol = symbol_table.lookup_ref(function_name);
267  // NOLINTNEXTLINE
268  auto add_instruction = [&](goto_programt::instructiont &&i) {
269  auto instruction = function.body.add(std::move(i));
270  instruction->source_location = function_symbol.location;
271  return instruction;
272  };
273 
274  for(std::size_t i = 0; i < function.parameter_identifiers.size(); ++i)
275  {
276  const auto &parameter = function.parameter_identifiers[i];
277  const symbolt &parameter_symbol = ns.lookup(parameter);
278  if(
279  parameter_symbol.type.id() == ID_pointer &&
280  !parameter_symbol.type.subtype().get_bool(ID_C_constant) &&
281  should_havoc_param(id2string(parameter_symbol.base_name), i))
282  {
283  auto goto_instruction =
285  parameter_symbol.symbol_expr(),
286  null_pointer_exprt(to_pointer_type(parameter_symbol.type)))));
287 
288  dereference_exprt dereference_expr(
289  parameter_symbol.symbol_expr(), parameter_symbol.type.subtype());
290 
291  goto_programt dest;
293  dereference_expr,
294  1, // depth 1 since we pass the dereferenced pointer
295  function_symbol.location,
296  function_name,
297  symbol_table,
298  dest);
299 
300  function.body.destructive_append(dest);
301 
302  auto label_instruction = add_instruction(goto_programt::make_skip());
303  goto_instruction->complete_goto(label_instruction);
304  }
305  }
306 
307  for(auto const &global_id : globals_to_havoc)
308  {
309  auto const &global_sym = symbol_table.lookup_ref(global_id);
310 
311  goto_programt dest;
312 
314  symbol_exprt(global_sym.name, global_sym.type),
315  0,
316  function_symbol.location,
317  irep_idt(),
318  symbol_table,
319  dest);
320 
321  function.body.destructive_append(dest);
322  }
323 
324  const typet &return_type = to_code_type(function_symbol.type).return_type();
325  if(return_type != empty_typet())
326  {
327  typet type(return_type);
328  type.remove(ID_C_constant);
329 
330  symbolt &aux_symbol = get_fresh_aux_symbol(
331  type,
332  id2string(function_name),
333  "return_value",
334  function_symbol.location,
335  ID_C,
336  symbol_table);
337 
338  aux_symbol.is_static_lifetime = false;
339 
340  add_instruction(goto_programt::make_decl(aux_symbol.symbol_expr()));
341 
342  goto_programt dest;
343 
345  aux_symbol.symbol_expr(),
346  0,
347  function_symbol.location,
348  function_name,
349  symbol_table,
350  dest);
351 
352  function.body.destructive_append(dest);
353 
354  exprt return_expr =
355  typecast_exprt::conditional_cast(aux_symbol.symbol_expr(), return_type);
356 
357  add_instruction(goto_programt::make_return(code_returnt(return_expr)));
358 
359  add_instruction(goto_programt::make_dead(aux_symbol.symbol_expr()));
360  }
361 
362  add_instruction(goto_programt::make_end_function());
363 
364  remove_skip(function.body);
365  }
366 
367 private:
368  const std::vector<irep_idt> globals_to_havoc;
372  mutable messaget message;
373 };
374 
375 class generate_function_bodies_errort : public std::runtime_error
376 {
377 public:
378  explicit generate_function_bodies_errort(const std::string &reason)
379  : runtime_error(reason)
380  {
381  }
382 };
383 
386 std::unique_ptr<generate_function_bodiest> generate_function_bodies_factory(
387  const std::string &options,
388  const c_object_factory_parameterst &object_factory_parameters,
389  const symbol_tablet &symbol_table,
390  message_handlert &message_handler)
391 {
392  if(options.empty() || options == "nondet-return")
393  {
394  return util_make_unique<havoc_generate_function_bodiest>(
395  std::vector<irep_idt>{},
396  std::regex{},
397  object_factory_parameters,
398  message_handler);
399  }
400 
401  if(options == "assume-false")
402  {
403  return util_make_unique<assume_false_generate_function_bodiest>();
404  }
405 
406  if(options == "assert-false")
407  {
408  return util_make_unique<assert_false_generate_function_bodiest>();
409  }
410 
411  if(options == "assert-false-assume-false")
412  {
413  return util_make_unique<
415  }
416 
417  const std::vector<std::string> option_components = split_string(options, ',');
418  if(!option_components.empty() && option_components[0] == "havoc")
419  {
420  std::regex globals_regex;
421  std::regex params_regex;
422  std::vector<std::size_t> param_numbers;
423  for(std::size_t i = 1; i < option_components.size(); ++i)
424  {
425  const std::vector<std::string> key_value_pair =
426  split_string(option_components[i], ':');
427  if(key_value_pair.size() != 2)
428  {
430  "Expected key_value_pair of form argument:value");
431  }
432  if(key_value_pair[0] == "globals")
433  {
434  globals_regex = key_value_pair[1];
435  }
436  else if(key_value_pair[0] == "params")
437  {
438  auto param_identifiers = split_string(key_value_pair[1], ';');
439  if(param_identifiers.size() == 1)
440  {
441  auto maybe_nondet_param_number =
442  string2optional_size_t(param_identifiers.back());
443  if(!maybe_nondet_param_number.has_value())
444  {
445  params_regex = key_value_pair[1];
446  continue;
447  }
448  }
449  std::transform(
450  param_identifiers.begin(),
451  param_identifiers.end(),
452  std::back_inserter(param_numbers),
453  [](const std::string &param_id) {
454  auto maybe_nondet_param_number = string2optional_size_t(param_id);
455  INVARIANT(
456  maybe_nondet_param_number.has_value(),
457  param_id + " not a number");
458  return *maybe_nondet_param_number;
459  });
460  std::sort(param_numbers.begin(), param_numbers.end());
461  }
462  else
463  {
465  "Unknown option \"" + key_value_pair[0] + "\"");
466  }
467  }
468  std::vector<irep_idt> globals_to_havoc;
469  namespacet ns(symbol_table);
470  messaget messages(message_handler);
471  const std::regex cprover_prefix = std::regex("__CPROVER.*");
472  for(auto const &symbol : symbol_table.symbols)
473  {
474  if(
475  symbol.second.is_lvalue && symbol.second.is_static_lifetime &&
476  std::regex_match(id2string(symbol.first), globals_regex))
477  {
478  if(std::regex_match(id2string(symbol.first), cprover_prefix))
479  {
480  messages.warning() << "generate function bodies: "
481  << "matched global '" << id2string(symbol.first)
482  << "' begins with __CPROVER, "
483  << "havoc-ing this global may interfere"
484  << " with analysis" << messaget::eom;
485  }
486  globals_to_havoc.push_back(symbol.first);
487  }
488  }
489  if(param_numbers.empty())
490  return util_make_unique<havoc_generate_function_bodiest>(
491  std::move(globals_to_havoc),
492  std::move(params_regex),
493  object_factory_parameters,
494  message_handler);
495  else
496  return util_make_unique<havoc_generate_function_bodiest>(
497  std::move(globals_to_havoc),
498  std::move(param_numbers),
499  object_factory_parameters,
500  message_handler);
501  }
502  throw generate_function_bodies_errort("Can't parse \"" + options + "\"");
503 }
504 
513  const std::regex &functions_regex,
514  const generate_function_bodiest &generate_function_body,
515  goto_modelt &model,
516  message_handlert &message_handler)
517 {
518  messaget messages(message_handler);
519  const std::regex cprover_prefix = std::regex("__CPROVER.*");
520  bool did_generate_body = false;
521  for(auto &function : model.goto_functions.function_map)
522  {
523  if(
524  !function.second.body_available() &&
525  std::regex_match(id2string(function.first), functions_regex))
526  {
527  if(std::regex_match(id2string(function.first), cprover_prefix))
528  {
529  messages.warning() << "generate function bodies: matched function '"
530  << id2string(function.first)
531  << "' begins with __CPROVER "
532  << "the generated body for this function "
533  << "may interfere with analysis" << messaget::eom;
534  }
535  did_generate_body = true;
536  generate_function_body.generate_function_body(
537  function.second, model.symbol_table, function.first);
538  }
539  }
540  if(!did_generate_body)
541  {
542  messages.warning()
543  << "generate function bodies: No function name matched regex"
544  << messaget::eom;
545  }
546 }
547 
549  const std::string &function_name,
550  const std::string &call_site_id,
551  const generate_function_bodiest &generate_function_body,
552  goto_modelt &model,
553  message_handlert &message_handler)
554 {
555  PRECONDITION(!has_prefix(function_name, CPROVER_PREFIX));
556  auto call_site_number = string2optional_size_t(call_site_id);
557  PRECONDITION(call_site_number.has_value());
558 
559  messaget messages(message_handler);
560 
561  bool found = false;
562  irep_idt function_mode;
563  typet function_type;
564 
565  // get the mode and type from symbol table
566  for(auto const &symbol_pair : model.symbol_table)
567  {
568  auto const symbol = symbol_pair.second;
569  if(symbol.type.id() == ID_code && symbol.name == function_name)
570  {
571  function_mode = symbol.mode;
572  function_type = symbol.type;
573  found = true;
574  break;
575  }
576  }
577  CHECK_RETURN(found);
578 
579  // add function of the right name to the symbol table
580  symbolt havoc_function_symbol{};
581  havoc_function_symbol.name = havoc_function_symbol.base_name =
582  havoc_function_symbol.pretty_name = function_name + "." + call_site_id;
583 
584  havoc_function_symbol.is_lvalue = true;
585  havoc_function_symbol.mode = function_mode;
586  havoc_function_symbol.type = function_type;
587 
588  model.symbol_table.insert(havoc_function_symbol);
589 
590  auto const &generated_havoc =
591  model.symbol_table.lookup_ref(havoc_function_symbol.name);
592 
593  // convert to get the function stub to goto-model
594  goto_convert(model.symbol_table, model.goto_functions, message_handler);
595 
596  // now generate body as above
597  for(auto &function : model.goto_functions.function_map)
598  {
599  if(
600  !function.second.body_available() &&
601  havoc_function_symbol.name == id2string(function.first))
602  {
603  generate_function_body.generate_function_body(
604  function.second, model.symbol_table, function.first);
605  }
606  }
607 
608  auto is_havoc_function_call = [&function_name](const exprt &expr) {
609  if(expr.id() != ID_symbol)
610  return false;
611  std::string called_function_name =
612  id2string(to_symbol_expr(expr).get_identifier());
613  if(called_function_name == function_name)
614  return true;
615 
616  return (has_prefix(called_function_name, function_name + "."));
617  };
618 
619  // finally, rename the (right) call site
620  std::size_t counter = 0;
621  for(auto &function : model.goto_functions.function_map)
622  {
623  for(auto &instruction : function.second.body.instructions)
624  {
625  if(instruction.is_function_call())
626  {
627  auto &called_function =
628  to_code_function_call(instruction.code).function();
629  if(is_havoc_function_call(called_function))
630  {
631  if(++counter == *call_site_number)
632  {
633  called_function = generated_havoc.symbol_expr();
634  return;
635  }
636  }
637  }
638  }
639  }
640 }
@ DYNAMIC
Allocate dynamic objects (using ALLOCATE)
C Nondet Symbol Factory.
void generate_function_body_impl(goto_functiont &function, symbol_tablet &symbol_table, const irep_idt &function_name) const override
Produce a body for the passed function At this point the body of function is always empty,...
void generate_function_body_impl(goto_functiont &function, symbol_tablet &symbol_table, const irep_idt &function_name) const override
Produce a body for the passed function At this point the body of function is always empty,...
void generate_function_body_impl(goto_functiont &function, symbol_tablet &symbol_table, const irep_idt &function_name) const override
Produce a body for the passed function At this point the body of function is always empty,...
A codet representing sequential composition of program statements.
Definition: std_code.h:170
void append(const code_blockt &extra_block)
Add all the codets from extra_block to the current code_blockt.
Definition: std_code.cpp:88
exprt & function()
Definition: std_code.h:1250
codet representation of a "return from a function" statement.
Definition: std_code.h:1342
const typet & return_type() const
Definition: std_types.h:850
const parameterst & parameters() const
Definition: std_types.h:860
Operator to dereference a pointer.
Definition: pointer_expr.h:256
dstringt has one field, an unsigned integer no which is an index into a static table of strings.
Definition: dstring.h:37
The empty type.
Definition: std_types.h:46
Equality.
Definition: std_expr.h:1140
Base class for all expressions.
Definition: expr.h:54
The Boolean constant false.
Definition: std_expr.h:2726
generate_function_bodies_errort(const std::string &reason)
Base class for replace_function_body implementations.
void generate_function_body(goto_functiont &function, symbol_tablet &symbol_table, const irep_idt &function_name) const
Replace the function body with one based on the replace_function_body class being used.
void generate_parameter_names(goto_functiont &function, symbol_tablet &symbol_table, const irep_idt &function_name) const
Generate parameter names for unnamed parameters.
virtual void generate_function_body_impl(goto_functiont &function, symbol_tablet &symbol_table, const irep_idt &function_name) const =0
Produce a body for the passed function At this point the body of function is always empty,...
function_mapt function_map
A goto function, consisting of function body (see body) and parameter identifiers (see parameter_iden...
Definition: goto_function.h:27
symbol_tablet symbol_table
Symbol table.
Definition: goto_model.h:30
goto_functionst goto_functions
GOTO functions.
Definition: goto_model.h:33
This class represents an instruction in the GOTO intermediate representation.
Definition: goto_program.h:180
A generic container class for the GOTO intermediate representation of one function.
Definition: goto_program.h:74
static instructiont make_assumption(const exprt &g, const source_locationt &l=source_locationt::nil())
Definition: goto_program.h:876
static instructiont make_return(const source_locationt &l=source_locationt::nil())
Definition: goto_program.h:809
static instructiont make_dead(const symbol_exprt &symbol, const source_locationt &l=source_locationt::nil())
Definition: goto_program.h:898
static instructiont make_end_function(const source_locationt &l=source_locationt::nil())
Definition: goto_program.h:928
void destructive_append(goto_programt &p)
Appends the given program p to *this. p is destroyed.
Definition: goto_program.h:640
static instructiont make_skip(const source_locationt &l=source_locationt::nil())
Definition: goto_program.h:822
static instructiont make_decl(const symbol_exprt &symbol, const source_locationt &l=source_locationt::nil())
Definition: goto_program.h:891
static instructiont make_assertion(const exprt &g, const source_locationt &l=source_locationt::nil())
Definition: goto_program.h:864
static instructiont make_incomplete_goto(const exprt &_cond, const source_locationt &l=source_locationt::nil())
Definition: goto_program.h:938
havoc_generate_function_bodiest(std::vector< irep_idt > globals_to_havoc, std::vector< std::size_t > param_numbers_to_havoc, const c_object_factory_parameterst &object_factory_parameters, message_handlert &message_handler)
const std::vector< irep_idt > globals_to_havoc
havoc_generate_function_bodiest(std::vector< irep_idt > globals_to_havoc, std::regex parameters_to_havoc, const c_object_factory_parameterst &object_factory_parameters, message_handlert &message_handler)
bool should_havoc_param(const std::string &param_name, std::size_t param_number) const
optionalt< std::vector< std::size_t > > param_numbers_to_havoc
void generate_function_body_impl(goto_functiont &function, symbol_tablet &symbol_table, const irep_idt &function_name) const override
Produce a body for the passed function At this point the body of function is always empty,...
const c_object_factory_parameterst & object_factory_parameters
void havoc_expr_rec(const exprt &lhs, const std::size_t initial_depth, const source_locationt &source_location, const irep_idt &function_id, symbol_tablet &symbol_table, goto_programt &dest) const
Thrown when users pass incorrect command line arguments, for example passing no files to analysis or ...
bool get_bool(const irep_namet &name) const
Definition: irep.cpp:64
const irep_idt & id() const
Definition: irep.h:407
void remove(const irep_namet &name)
Definition: irep.cpp:93
Class that provides messages with a built-in verbosity 'level'.
Definition: message.h:155
mstreamt & warning() const
Definition: message.h:404
message_handlert & get_message_handler()
Definition: message.h:184
static eomt eom
Definition: message.h:297
A namespacet is essentially one or two symbol tables bound together, to allow for symbol lookups in t...
Definition: namespace.h:92
bool lookup(const irep_idt &name, const symbolt *&symbol) const override
See documentation for namespace_baset::lookup().
Definition: namespace.cpp:140
The null pointer constant.
Definition: std_expr.h:2751
Symbol table entry of function parameterThis is a symbol generated as part of type checking.
Definition: symbol.h:171
void set_function(const irep_idt &function)
Expression to hold a symbol (variable)
Definition: std_expr.h:81
void gen_nondet_init(code_blockt &assignments, const exprt &expr, const std::size_t depth=0, recursion_sett recursion_set=recursion_sett(), const bool assign_const=true)
Creates a nondet for expr, including calling itself recursively to make appropriate symbols to point ...
std::set< irep_idt > recursion_sett
void declare_created_symbols(code_blockt &init_code)
symbolt & get_writeable_ref(const irep_idt &name)
Find a symbol in the symbol table for read-write access.
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.
bool add(const symbolt &symbol)
Add a new symbol to the symbol table.
The symbol table.
Definition: symbol_table.h:20
virtual std::pair< symbolt &, bool > insert(symbolt symbol) override
Author: Diffblue Ltd.
Symbol table entry.
Definition: symbol.h:28
irep_idt base_name
Base (non-scoped) name.
Definition: symbol.h:46
irep_idt module
Name of module the symbol belongs to.
Definition: symbol.h:43
bool is_static_lifetime
Definition: symbol.h:65
source_locationt location
Source code location of definition of symbol.
Definition: symbol.h:37
class symbol_exprt symbol_expr() const
Produces a symbol_exprt for a symbol.
Definition: symbol.cpp:122
typet type
Type of symbol.
Definition: symbol.h:31
irep_idt name
The unique identifier.
Definition: symbol.h:40
irep_idt mode
Language mode.
Definition: symbol.h:49
static exprt conditional_cast(const exprt &expr, const typet &type)
Definition: std_expr.h:1789
The type of an expression, extends irept.
Definition: type.h:28
const typet & subtype() const
Definition: type.h:47
bool has_prefix(const std::string &s, const std::string &prefix)
Definition: converter.cpp:13
#define CPROVER_PREFIX
static format_containert< T > format(const T &o)
Definition: format.h:37
symbolt & get_fresh_aux_symbol(const typet &type, const std::string &name_prefix, const std::string &basename_prefix, const source_locationt &source_location, const irep_idt &symbol_mode, const namespacet &ns, symbol_table_baset &symbol_table)
Installs a fresh-named symbol with respect to the given namespace ns with the requested name pattern ...
Fresh auxiliary symbol creation.
std::unique_ptr< generate_function_bodiest > generate_function_bodies_factory(const std::string &options, const c_object_factory_parameterst &object_factory_parameters, const symbol_tablet &symbol_table, message_handlert &message_handler)
Create the type that actually generates the functions.
void generate_function_bodies(const std::regex &functions_regex, const generate_function_bodiest &generate_function_body, goto_modelt &model, message_handlert &message_handler)
Generate function bodies with some default behavior: assert-false, assume-false, assert-false-assume-...
void goto_convert(const codet &code, symbol_table_baset &symbol_table, goto_programt &dest, message_handlert &message_handler, const irep_idt &mode)
Program Transformation.
Goto Programs with Functions.
const std::string & id2string(const irep_idt &d)
Definition: irep.h:49
std::unique_ptr< T > util_make_unique(Ts &&... ts)
Definition: make_unique.h:19
nonstd::optional< T > optionalt
Definition: optional.h:35
API to expression classes for Pointers.
void remove_skip(goto_programt &goto_program, goto_programt::targett begin, goto_programt::targett end)
remove unnecessary skip statements
Definition: remove_skip.cpp:85
Program Transformation.
#define CHECK_RETURN(CONDITION)
Definition: invariant.h:496
#define PRECONDITION(CONDITION)
Definition: invariant.h:464
const code_function_callt & to_code_function_call(const codet &code)
Definition: std_code.h:1326
const symbol_exprt & to_symbol_expr(const exprt &expr)
Cast an exprt to a symbol_exprt.
Definition: std_expr.h:190
const code_typet & to_code_type(const typet &type)
Cast a typet to a code_typet.
Definition: std_types.h:949
const pointer_typet & to_pointer_type(const typet &type)
Cast a typet to a pointer_typet.
Definition: std_types.h:1533
optionalt< std::size_t > string2optional_size_t(const std::string &str, int base)
Convert string to size_t similar to the stoul or stoull functions, return nullopt when the conversion...
Definition: string2int.cpp:72
std::string to_string(const string_not_contains_constraintt &expr)
Used for debug printing.
void split_string(const std::string &s, char delim, std::vector< std::string > &result, bool strip, bool remove_empty)