cprover
remove_virtual_functions.cpp
Go to the documentation of this file.
1 /*******************************************************************\
2 
3 Module: Remove Virtual Function (Method) Calls
4 
5 Author: Daniel Kroening, kroening@kroening.com
6 
7 \*******************************************************************/
8 
12 
13 #include <algorithm>
14 
15 #include <util/expr_iterator.h>
16 #include <util/expr_util.h>
17 #include <util/fresh_symbol.h>
18 #include <util/prefix.h>
19 
20 #include "class_identifier.h"
21 #include "goto_model.h"
22 #include "remove_skip.h"
24 
26 {
27 public:
29  const symbol_table_baset &_symbol_table,
30  const class_hierarchyt &_class_hierarchy)
31  : ns(_symbol_table),
32  symbol_table(_symbol_table),
33  class_hierarchy(_class_hierarchy)
34  {
35  }
36 
37  void get_functions(const exprt &, dispatch_table_entriest &) const;
38 
39 private:
40  const namespacet ns;
42 
44 
45  typedef std::function<
47  const irep_idt &,
48  const irep_idt &)>
51  const irep_idt &,
53  const irep_idt &,
56  exprt
57  get_method(const irep_idt &class_id, const irep_idt &component_name) const;
58 };
59 
61 {
62 public:
64  symbol_table_baset &_symbol_table,
65  const class_hierarchyt &_class_hierarchy)
66  : class_hierarchy(_class_hierarchy),
67  symbol_table(_symbol_table),
69  {
70  }
71 
72  void operator()(goto_functionst &functions);
73 
75  const irep_idt &function_id,
76  goto_programt &goto_program);
77 
78 private:
82 
84  const irep_idt &function_id,
85  goto_programt &goto_program,
86  goto_programt::targett target);
87 };
88 
94  code_function_callt &call,
95  const symbol_exprt &function_symbol,
96  const namespacet &ns)
97 {
98  call.function() = function_symbol;
99  // Cast the pointers to the correct type for the new callee:
100  // Note the `this` pointer is expected to change type, but other pointers
101  // could also change due to e.g. using a different alias to refer to the same
102  // type (in Java, for example, we see ArrayList.add(ArrayList::E arg)
103  // overriding Collection.add(Collection::E arg))
104  const auto &callee_parameters =
105  to_code_type(ns.lookup(function_symbol.get_identifier()).type).parameters();
106  auto &call_args = call.arguments();
107 
108  INVARIANT(
109  callee_parameters.size() == call_args.size(),
110  "function overrides must have matching argument counts");
111 
112  for(std::size_t i = 0; i < call_args.size(); ++i)
113  {
114  const typet &need_type = callee_parameters[i].type();
115 
116  if(call_args[i].type() != need_type)
117  {
118  // If this wasn't language agnostic code we'd also like to check
119  // compatibility-- for example, Java overrides may have differing generic
120  // qualifiers, but not different base types.
121  INVARIANT(
122  call_args[i].type().id() == ID_pointer,
123  "where overriding function argument types differ, "
124  "those arguments must be pointer-typed");
125  call_args[i] = typecast_exprt(call_args[i], need_type);
126  }
127  }
128 }
129 
143  const goto_programt &goto_program,
145  const exprt &argument_for_this,
146  const symbol_exprt &temp_var_for_this)
147 {
148  goto_programt checks_directly_preceding_function_call;
149 
150  while(instr_it != goto_program.instructions.cbegin())
151  {
152  instr_it = std::prev(instr_it);
153 
154  if(instr_it->type == ASSERT)
155  {
156  continue;
157  }
158 
159  if(instr_it->type != ASSUME)
160  {
161  break;
162  }
163 
164  exprt guard = instr_it->get_condition();
165 
166  bool changed = false;
167  for(auto expr_it = guard.depth_begin(); expr_it != guard.depth_end();
168  ++expr_it)
169  {
170  if(*expr_it == argument_for_this)
171  {
172  expr_it.mutate() = temp_var_for_this;
173  changed = true;
174  }
175  }
176 
177  if(changed)
178  {
179  checks_directly_preceding_function_call.insert_before(
180  checks_directly_preceding_function_call.instructions.cbegin(),
182  }
183  }
184 
185  return checks_directly_preceding_function_call;
186 }
187 
200  const irep_idt &function_id,
201  const goto_programt &goto_program,
202  const goto_programt::targett target,
203  exprt &argument_for_this,
204  symbol_table_baset &symbol_table,
205  const source_locationt &vcall_source_loc,
206  goto_programt &new_code_for_this_argument)
207 {
208  if(has_subexpr(argument_for_this, ID_dereference))
209  {
210  // Create a temporary for the `this` argument. This is so that
211  // \ref goto_symext::try_filter_value_sets can reduce the value-set for
212  // `this` to those elements with the correct class identifier.
213  symbolt &temp_symbol = get_fresh_aux_symbol(
214  argument_for_this.type(),
215  id2string(function_id),
216  "this_argument",
217  vcall_source_loc,
218  symbol_table.lookup_ref(function_id).mode,
219  symbol_table);
220  const symbol_exprt temp_var_for_this = temp_symbol.symbol_expr();
221 
222  new_code_for_this_argument.add(
223  goto_programt::make_decl(temp_var_for_this, vcall_source_loc));
224  new_code_for_this_argument.add(
226  temp_var_for_this, argument_for_this, vcall_source_loc));
227 
228  goto_programt checks_directly_preceding_function_call =
230  goto_program, target, argument_for_this, temp_var_for_this);
231 
232  new_code_for_this_argument.destructive_append(
233  checks_directly_preceding_function_call);
234 
235  argument_for_this = temp_var_for_this;
236  }
237 }
238 
258  symbol_table_baset &symbol_table,
259  const irep_idt &function_id,
260  goto_programt &goto_program,
261  goto_programt::targett target,
262  const dispatch_table_entriest &functions,
263  virtual_dispatch_fallback_actiont fallback_action)
264 {
265  INVARIANT(
266  target->is_function_call(),
267  "remove_virtual_function must target a FUNCTION_CALL instruction");
268 
269  namespacet ns(symbol_table);
270  goto_programt::targett next_target = std::next(target);
271 
272  if(functions.empty())
273  {
274  target->turn_into_skip();
275  remove_skip(goto_program, target, next_target);
276  return next_target; // give up
277  }
278 
279  // only one option?
280  if(functions.size()==1 &&
281  fallback_action==virtual_dispatch_fallback_actiont::CALL_LAST_FUNCTION)
282  {
283  if(!functions.front().symbol_expr.has_value())
284  {
285  target->turn_into_skip();
286  remove_skip(goto_program, target, next_target);
287  }
288  else
289  {
290  auto c = target->get_function_call();
291  create_static_function_call(c, *functions.front().symbol_expr, ns);
292  target->set_function_call(c);
293  }
294  return next_target;
295  }
296 
297  const auto &vcall_source_loc=target->source_location;
298 
299  code_function_callt code(target->get_function_call());
300  goto_programt new_code_for_this_argument;
301 
303  function_id,
304  goto_program,
305  target,
306  code.arguments()[0],
307  symbol_table,
308  vcall_source_loc,
309  new_code_for_this_argument);
310 
311  const exprt &this_expr = code.arguments()[0];
312 
313  // Create a skip as the final target for each branch to jump to at the end
314  goto_programt final_skip;
315 
316  goto_programt::targett t_final =
317  final_skip.add(goto_programt::make_skip(vcall_source_loc));
318 
319  // build the calls and gotos
320 
321  goto_programt new_code_calls;
322  goto_programt new_code_gotos;
323 
324  INVARIANT(
325  this_expr.type().id() == ID_pointer, "this parameter must be a pointer");
326  INVARIANT(
327  this_expr.type().subtype() != empty_typet(),
328  "this parameter must not be a void pointer");
329 
330  // So long as `this` is already not `void*` typed, the second parameter
331  // is ignored:
332  exprt this_class_identifier =
334 
335  // If instructed, add an ASSUME(FALSE) to handle the case where we don't
336  // match any expected type:
338  {
339  new_code_calls.add(
340  goto_programt::make_assumption(false_exprt(), vcall_source_loc));
341  }
342 
343  // get initial identifier for grouping
344  INVARIANT(!functions.empty(), "Function dispatch table cannot be empty.");
345  const auto &last_function_symbol = functions.back().symbol_expr;
346 
347  std::map<irep_idt, goto_programt::targett> calls;
348  // Note backwards iteration, to get the fallback candidate first.
349  for(auto it=functions.crbegin(), itend=functions.crend(); it!=itend; ++it)
350  {
351  const auto &fun=*it;
352  irep_idt id_or_empty = fun.symbol_expr.has_value()
353  ? fun.symbol_expr->get_identifier()
354  : irep_idt();
355  auto insertit = calls.insert({id_or_empty, goto_programt::targett()});
356 
357  // Only create one call sequence per possible target:
358  if(insertit.second)
359  {
360  if(fun.symbol_expr.has_value())
361  {
362  // call function
363  auto new_call = code;
364 
365  create_static_function_call(new_call, *fun.symbol_expr, ns);
366 
367  goto_programt::targett t1 = new_code_calls.add(
368  goto_programt::make_function_call(new_call, vcall_source_loc));
369 
370  insertit.first->second = t1;
371  }
372  else
373  {
374  goto_programt::targett t1 = new_code_calls.add(
375  goto_programt::make_assertion(false_exprt(), vcall_source_loc));
376 
377  // No definition for this type; shouldn't be possible...
378  t1->source_location.set_comment(
379  "cannot find calls for " +
380  id2string(code.function().get(ID_identifier)) + " dispatching " +
381  id2string(fun.class_id));
382 
383  insertit.first->second = t1;
384  }
385 
386  // goto final
387  new_code_calls.add(
388  goto_programt::make_goto(t_final, true_exprt(), vcall_source_loc));
389  }
390 
391  // Fall through to the default callee if possible:
392  if(
393  fallback_action ==
394  virtual_dispatch_fallback_actiont::CALL_LAST_FUNCTION &&
395  fun.symbol_expr.has_value() == last_function_symbol.has_value() &&
396  (!fun.symbol_expr.has_value() ||
397  *fun.symbol_expr == *last_function_symbol))
398  {
399  // Nothing to do
400  }
401  else
402  {
403  const constant_exprt fun_class_identifier(fun.class_id, string_typet());
404  const equal_exprt class_id_test(
405  fun_class_identifier, this_class_identifier);
406 
407  // If the previous GOTO goes to the same callee, join it
408  // (e.g. turning IF x GOTO y into IF x || z GOTO y)
409  if(
410  it != functions.crbegin() &&
411  std::prev(it)->symbol_expr.has_value() == fun.symbol_expr.has_value() &&
412  (!fun.symbol_expr.has_value() ||
413  *(std::prev(it)->symbol_expr) == *fun.symbol_expr))
414  {
415  INVARIANT(
416  !new_code_gotos.empty(),
417  "a dispatch table entry has been processed already, "
418  "which should have created a GOTO");
419  new_code_gotos.instructions.back().guard =
420  or_exprt(new_code_gotos.instructions.back().guard, class_id_test);
421  }
422  else
423  {
424  new_code_gotos.add(goto_programt::make_goto(
425  insertit.first->second, class_id_test, vcall_source_loc));
426  }
427  }
428  }
429 
430  goto_programt new_code;
431 
432  // patch them all together
433  new_code.destructive_append(new_code_for_this_argument);
434  new_code.destructive_append(new_code_gotos);
435  new_code.destructive_append(new_code_calls);
436  new_code.destructive_append(final_skip);
437 
438  // set locations
439  for(auto &instruction : new_code.instructions)
440  {
441  source_locationt &source_location = instruction.source_location;
442 
443  const irep_idt property_class = source_location.get_property_class();
444  const irep_idt comment = source_location.get_comment();
445  source_location = target->source_location;
446  if(!property_class.empty())
447  source_location.set_property_class(property_class);
448  if(!comment.empty())
449  source_location.set_comment(comment);
450  }
451 
452  goto_program.destructive_insert(next_target, new_code);
453 
454  // finally, kill original invocation
455  target->turn_into_skip();
456 
457  // only remove skips within the virtual-function handling block
458  remove_skip(goto_program, target, next_target);
459 
460  return next_target;
461 }
462 
473  const irep_idt &function_id,
474  goto_programt &goto_program,
475  goto_programt::targett target)
476 {
477  const code_function_callt &code = target->get_function_call();
478 
479  const exprt &function = code.function();
480  INVARIANT(
482  "remove_virtual_function must take a function call instruction whose "
483  "function is a class method descriptor ");
484  INVARIANT(
485  !code.arguments().empty(),
486  "virtual function calls must have at least a this-argument");
487 
489  dispatch_table_entriest functions;
490  get_callees.get_functions(function, functions);
491 
493  symbol_table,
494  function_id,
495  goto_program,
496  target,
497  functions,
498  virtual_dispatch_fallback_actiont::CALL_LAST_FUNCTION);
499 }
500 
515  const irep_idt &this_id,
516  const optionalt<symbol_exprt> &last_method_defn,
517  const irep_idt &component_name,
518  dispatch_table_entriest &functions,
519  dispatch_table_entries_mapt &entry_map) const
520 {
521  auto findit=class_hierarchy.class_map.find(this_id);
522  if(findit==class_hierarchy.class_map.end())
523  return;
524 
525  for(const auto &child : findit->second.children)
526  {
527  // Skip if we have already visited this and we found a function call that
528  // did not resolve to non java.lang.Object.
529  auto it = entry_map.find(child);
530  if(
531  it != entry_map.end() &&
532  (!it->second.symbol_expr.has_value() ||
533  !has_prefix(
534  id2string(it->second.symbol_expr->get_identifier()),
535  "java::java.lang.Object")))
536  {
537  continue;
538  }
539  exprt method = get_method(child, component_name);
540  dispatch_table_entryt function(child);
541  if(method.is_not_nil())
542  {
543  function.symbol_expr=to_symbol_expr(method);
544  function.symbol_expr->set(ID_C_class, child);
545  }
546  else
547  {
548  function.symbol_expr=last_method_defn;
549  }
550  if(!function.symbol_expr.has_value())
551  {
552  const auto resolved_call = get_inherited_method_implementation(
553  component_name, child, symbol_table);
554  if(resolved_call)
555  {
556  function.class_id = resolved_call->get_class_identifier();
557  const symbolt &called_symbol = symbol_table.lookup_ref(
558  resolved_call->get_full_component_identifier());
559 
560  function.symbol_expr = called_symbol.symbol_expr();
561  function.symbol_expr->set(
562  ID_C_class, resolved_call->get_class_identifier());
563  }
564  }
565  functions.push_back(function);
566  entry_map.emplace(child, function);
567 
569  child, function.symbol_expr, component_name, functions, entry_map);
570  }
571 }
572 
578  const exprt &function,
579  dispatch_table_entriest &functions) const
580 {
581  // class part of function to call
582  const irep_idt class_id=function.get(ID_C_class);
583  const std::string class_id_string(id2string(class_id));
584  const irep_idt function_name = function.get(ID_component_name);
585  const std::string function_name_string(id2string(function_name));
586  INVARIANT(!class_id.empty(), "All virtual functions must have a class");
587 
588  auto resolved_call =
589  get_inherited_method_implementation(function_name, class_id, symbol_table);
590 
591  // might be an abstract function
592  dispatch_table_entryt root_function(class_id);
593 
594  if(resolved_call)
595  {
596  root_function.class_id = resolved_call->get_class_identifier();
597 
598  const symbolt &called_symbol =
599  symbol_table.lookup_ref(resolved_call->get_full_component_identifier());
600 
601  root_function.symbol_expr=called_symbol.symbol_expr();
602  root_function.symbol_expr->set(
603  ID_C_class, resolved_call->get_class_identifier());
604  }
605 
606  // iterate over all children, transitively
607  dispatch_table_entries_mapt entry_map;
609  class_id, root_function.symbol_expr, function_name, functions, entry_map);
610 
611  if(root_function.symbol_expr.has_value())
612  functions.push_back(root_function);
613 
614  // Sort for the identifier of the function call symbol expression, grouping
615  // together calls to the same function. Keep java.lang.Object entries at the
616  // end for fall through. The reasoning is that this is the case with most
617  // entries in realistic cases.
618  std::sort(
619  functions.begin(),
620  functions.end(),
621  [](const dispatch_table_entryt &a, const dispatch_table_entryt &b) {
622  irep_idt a_id = a.symbol_expr.has_value()
623  ? a.symbol_expr->get_identifier()
624  : irep_idt();
625  irep_idt b_id = b.symbol_expr.has_value()
626  ? b.symbol_expr->get_identifier()
627  : irep_idt();
628 
629  if(has_prefix(id2string(a_id), "java::java.lang.Object"))
630  return false;
631  else if(has_prefix(id2string(b_id), "java::java.lang.Object"))
632  return true;
633  else
634  {
635  int cmp = a_id.compare(b_id);
636  if(cmp == 0)
637  return a.class_id < b.class_id;
638  else
639  return cmp < 0;
640  }
641  });
642 }
643 
650  const irep_idt &class_id,
651  const irep_idt &component_name) const
652 {
653  const irep_idt &id=
655  class_id, component_name);
656 
657  const symbolt *symbol;
658  if(ns.lookup(id, symbol))
659  return nil_exprt();
660 
661  return symbol->symbol_expr();
662 }
663 
668  const irep_idt &function_id,
669  goto_programt &goto_program)
670 {
671  bool did_something=false;
672 
673  for(goto_programt::instructionst::iterator
674  target = goto_program.instructions.begin();
675  target != goto_program.instructions.end();
676  ) // remove_virtual_function returns the next instruction to process
677  {
678  if(target->is_function_call())
679  {
680  const code_function_callt &code = target->get_function_call();
681 
683  {
684  target = remove_virtual_function(function_id, goto_program, target);
685  did_something=true;
686  continue;
687  }
688  }
689 
690  ++target;
691  }
692 
693  if(did_something)
694  goto_program.update();
695 
696  return did_something;
697 }
698 
702 {
703  bool did_something=false;
704 
705  for(goto_functionst::function_mapt::iterator f_it=
706  functions.function_map.begin();
707  f_it!=functions.function_map.end();
708  f_it++)
709  {
710  const irep_idt &function_id = f_it->first;
711  goto_programt &goto_program=f_it->second.body;
712 
713  if(remove_virtual_functions(function_id, goto_program))
714  did_something=true;
715  }
716 
717  if(did_something)
718  functions.compute_location_numbers();
719 }
720 
726  symbol_table_baset &symbol_table,
727  goto_functionst &goto_functions)
728 {
729  class_hierarchyt class_hierarchy;
730  class_hierarchy(symbol_table);
731  remove_virtual_functionst rvf(symbol_table, class_hierarchy);
732  rvf(goto_functions);
733 }
734 
743  symbol_table_baset &symbol_table,
744  goto_functionst &goto_functions,
745  const class_hierarchyt &class_hierarchy)
746 {
747  remove_virtual_functionst rvf(symbol_table, class_hierarchy);
748  rvf(goto_functions);
749 }
750 
754 {
756  goto_model.symbol_table, goto_model.goto_functions);
757 }
758 
765  goto_modelt &goto_model,
766  const class_hierarchyt &class_hierarchy)
767 {
769  goto_model.symbol_table, goto_model.goto_functions, class_hierarchy);
770 }
771 
777 {
778  class_hierarchyt class_hierarchy;
779  class_hierarchy(function.get_symbol_table());
780  remove_virtual_functionst rvf(function.get_symbol_table(), class_hierarchy);
782  function.get_function_id(), function.get_goto_function().body);
783 }
784 
793  goto_model_functiont &function,
794  const class_hierarchyt &class_hierarchy)
795 {
796  remove_virtual_functionst rvf(function.get_symbol_table(), class_hierarchy);
798  function.get_function_id(), function.get_goto_function().body);
799 }
800 
820  symbol_tablet &symbol_table,
821  const irep_idt &function_id,
822  goto_programt &goto_program,
823  goto_programt::targett instruction,
824  const dispatch_table_entriest &dispatch_table,
825  virtual_dispatch_fallback_actiont fallback_action)
826 {
828  symbol_table,
829  function_id,
830  goto_program,
831  instruction,
832  dispatch_table,
833  fallback_action);
834 
835  goto_program.update();
836 
837  return next;
838 }
839 
841  goto_modelt &goto_model,
842  const irep_idt &function_id,
843  goto_programt &goto_program,
844  goto_programt::targett instruction,
845  const dispatch_table_entriest &dispatch_table,
846  virtual_dispatch_fallback_actiont fallback_action)
847 {
849  goto_model.symbol_table,
850  function_id,
851  goto_program,
852  instruction,
853  dispatch_table,
854  fallback_action);
855 }
856 
858  const exprt &function,
859  const symbol_table_baset &symbol_table,
860  const class_hierarchyt &class_hierarchy,
861  dispatch_table_entriest &overridden_functions)
862 {
863  get_virtual_calleest get_callees(symbol_table, class_hierarchy);
864  get_callees.get_functions(function, overridden_functions);
865 }
dstringt
dstringt has one field, an unsigned integer no which is an index into a static table of strings.
Definition: dstring.h:37
virtual_dispatch_fallback_actiont::CALL_LAST_FUNCTION
@ CALL_LAST_FUNCTION
When no callee type matches, call the last passed function, which is expected to be some safe default...
source_locationt::get_comment
const irep_idt & get_comment() const
Definition: source_location.h:71
virtual_dispatch_fallback_actiont
virtual_dispatch_fallback_actiont
Specifies remove_virtual_function's behaviour when the actual supplied parameter does not match any o...
Definition: remove_virtual_functions.h:58
dispatch_table_entryt
Definition: remove_virtual_functions.h:68
symbol_tablet
The symbol table.
Definition: symbol_table.h:20
source_locationt::get_property_class
const irep_idt & get_property_class() const
Definition: source_location.h:66
symbol_table_baset::lookup_ref
const symbolt & lookup_ref(const irep_idt &name) const
Find a symbol in the symbol table for read-only access.
Definition: symbol_table_base.h:104
typet::subtype
const typet & subtype() const
Definition: type.h:47
has_subexpr
bool has_subexpr(const exprt &expr, const std::function< bool(const exprt &)> &pred)
returns true if the expression has a subexpression that satisfies pred
Definition: expr_util.cpp:141
class_hierarchyt
Non-graph-based representation of the class hierarchy.
Definition: class_hierarchy.h:43
source_locationt::set_comment
void set_comment(const irep_idt &comment)
Definition: source_location.h:141
get_callees
std::set< irep_idt > get_callees(const call_grapht::directed_grapht &graph, const irep_idt &function)
Get functions directly callable from a given function.
Definition: call_graph_helpers.cpp:31
get_inherited_method_implementation
optionalt< resolve_inherited_componentt::inherited_componentt > get_inherited_method_implementation(const irep_idt &call_basename, const irep_idt &classname, const symbol_tablet &symbol_table)
Given a class and a component, identify the concrete method it is resolved to.
Definition: resolve_inherited_component.cpp:124
exprt::depth_begin
depth_iteratort depth_begin()
Definition: expr.cpp:292
get_virtual_calleest::get_child_functions_rec
void get_child_functions_rec(const irep_idt &, const optionalt< symbol_exprt > &, const irep_idt &, dispatch_table_entriest &, dispatch_table_entries_mapt &) const
Used by get_functions to track the most-derived parent that provides an override of a given function.
Definition: remove_virtual_functions.cpp:514
typet
The type of an expression, extends irept.
Definition: type.h:28
fresh_symbol.h
Fresh auxiliary symbol creation.
dispatch_table_entryt::class_id
irep_idt class_id
Definition: remove_virtual_functions.h:98
remove_skip
void remove_skip(goto_programt &goto_program, goto_programt::targett begin, goto_programt::targett end)
remove unnecessary skip statements
Definition: remove_skip.cpp:86
create_static_function_call
static void create_static_function_call(code_function_callt &call, const symbol_exprt &function_symbol, const namespacet &ns)
Create a concrete function call to replace a virtual one.
Definition: remove_virtual_functions.cpp:93
get_class_identifier_field
exprt get_class_identifier_field(const exprt &this_expr_in, const struct_tag_typet &suggested_type, const namespacet &ns)
Definition: class_identifier.cpp:57
prefix.h
goto_programt::update
void update()
Update all indices.
Definition: goto_program.cpp:540
remove_virtual_functions.h
Functions for replacing virtual function call with a static function calls in functions,...
goto_programt::add
targett add(instructiont &&instruction)
Adds a given instruction at the end.
Definition: goto_program.h:670
remove_virtual_functions
void remove_virtual_functions(symbol_table_baset &symbol_table, goto_functionst &goto_functions)
Remove virtual function calls from all functions in the specified list and replace them with their mo...
Definition: remove_virtual_functions.cpp:725
goto_model.h
Symbol Table + CFG.
goto_functionst::compute_location_numbers
void compute_location_numbers()
Definition: goto_functions.cpp:18
goto_programt::empty
bool empty() const
Is the program empty?
Definition: goto_program.h:746
exprt
Base class for all expressions.
Definition: expr.h:54
goto_modelt
Definition: goto_model.h:26
struct_tag_typet
A struct tag type, i.e., struct_typet with an identifier.
Definition: std_types.h:443
dispatch_table_entriest
std::vector< dispatch_table_entryt > dispatch_table_entriest
Definition: remove_virtual_functions.h:101
remove_virtual_functionst::remove_virtual_functionst
remove_virtual_functionst(symbol_table_baset &_symbol_table, const class_hierarchyt &_class_hierarchy)
Definition: remove_virtual_functions.cpp:63
irep_idt
dstringt irep_idt
Definition: irep.h:37
get_virtual_calleest::function_call_resolvert
std::function< optionalt< resolve_inherited_componentt::inherited_componentt > const irep_idt &, const irep_idt &)> function_call_resolvert
Definition: remove_virtual_functions.cpp:49
goto_functionst::function_map
function_mapt function_map
Definition: goto_functions.h:27
symbol_exprt
Expression to hold a symbol (variable)
Definition: std_expr.h:80
goto_programt::make_decl
static instructiont make_decl(const symbol_exprt &symbol, const source_locationt &l=source_locationt::nil())
Definition: goto_program.h:904
replace_virtual_function_with_dispatch_table
static goto_programt::targett replace_virtual_function_with_dispatch_table(symbol_table_baset &symbol_table, const irep_idt &function_id, goto_programt &goto_program, goto_programt::targett target, const dispatch_table_entriest &functions, virtual_dispatch_fallback_actiont fallback_action)
Replace virtual function call with a static function call Achieved by substituting a virtual function...
Definition: remove_virtual_functions.cpp:257
equal_exprt
Equality.
Definition: std_expr.h:1139
get_virtual_calleest::ns
const namespacet ns
Definition: remove_virtual_functions.cpp:40
remove_virtual_functionst::ns
namespacet ns
Definition: remove_virtual_functions.cpp:81
goto_programt::make_assignment
static instructiont make_assignment(const code_assignt &_code, const source_locationt &l=source_locationt::nil())
Create an assignment instruction.
Definition: goto_program.h:1008
goto_programt::make_goto
static instructiont make_goto(targett _target, const source_locationt &l=source_locationt::nil())
Definition: goto_program.h:982
resolve_inherited_component.h
Given a class and a component (either field or method), find the closest parent that defines that com...
remove_virtual_functionst::remove_virtual_functions
bool remove_virtual_functions(const irep_idt &function_id, goto_programt &goto_program)
Remove all virtual function calls in a GOTO program and replace them with calls to their most derived...
Definition: remove_virtual_functions.cpp:667
get_virtual_calleest::get_functions
void get_functions(const exprt &, dispatch_table_entriest &) const
Used to get dispatch entries to call for the given function.
Definition: remove_virtual_functions.cpp:577
namespacet
A namespacet is essentially one or two symbol tables bound together, to allow for symbol lookups in t...
Definition: namespace.h:92
goto_programt::make_function_call
static instructiont make_function_call(const code_function_callt &_code, const source_locationt &l=source_locationt::nil())
Create a function call instruction.
Definition: goto_program.h:1033
remove_virtual_functionst::remove_virtual_function
goto_programt::targett remove_virtual_function(const irep_idt &function_id, goto_programt &goto_program, goto_programt::targett target)
Replace specified virtual function call with a static call to its most derived implementation.
Definition: remove_virtual_functions.cpp:472
exprt::type
typet & type()
Return the type of the expression.
Definition: expr.h:82
namespacet::lookup
bool lookup(const irep_idt &name, const symbolt *&symbol) const override
See documentation for namespace_baset::lookup().
Definition: namespace.cpp:141
code_function_callt
codet representation of a function call statement.
Definition: std_code.h:1215
irept::is_not_nil
bool is_not_nil() const
Definition: irep.h:391
goto_programt::insert_before
targett insert_before(const_targett target)
Insertion before the instruction pointed-to by the given instruction iterator target.
Definition: goto_program.h:623
to_code_type
const code_typet & to_code_type(const typet &type)
Cast a typet to a code_typet.
Definition: std_types.h:738
get_virtual_calleest::class_hierarchy
const class_hierarchyt & class_hierarchy
Definition: remove_virtual_functions.cpp:43
goto_programt::make_assertion
static instructiont make_assertion(const exprt &g, const source_locationt &l=source_locationt::nil())
Definition: goto_program.h:877
symbolt::mode
irep_idt mode
Language mode.
Definition: symbol.h:49
empty_typet
The empty type.
Definition: std_types.h:45
has_prefix
bool has_prefix(const std::string &s, const std::string &prefix)
Definition: converter.cpp:13
or_exprt
Boolean OR.
Definition: std_expr.h:1942
goto_programt::destructive_insert
void destructive_insert(const_targett target, goto_programt &p)
Inserts the given program p before target.
Definition: goto_program.h:661
id2string
const std::string & id2string(const irep_idt &d)
Definition: irep.h:49
get_virtual_calleest::get_virtual_calleest
get_virtual_calleest(const symbol_table_baset &_symbol_table, const class_hierarchyt &_class_hierarchy)
Definition: remove_virtual_functions.cpp:28
goto_programt::make_skip
static instructiont make_skip(const source_locationt &l=source_locationt::nil())
Definition: goto_program.h:835
symbol_exprt::get_identifier
const irep_idt & get_identifier() const
Definition: std_expr.h:109
symbol_table_baset
The symbol table base class interface.
Definition: symbol_table_base.h:22
nil_exprt
The NIL expression.
Definition: std_expr.h:2734
get_virtual_calleest::symbol_table
const symbol_table_baset & symbol_table
Definition: remove_virtual_functions.cpp:41
symbolt::symbol_expr
class symbol_exprt symbol_expr() const
Produces a symbol_exprt for a symbol.
Definition: symbol.cpp:122
dispatch_table_entryt::symbol_expr
optionalt< symbol_exprt > symbol_expr
Definition: remove_virtual_functions.h:97
to_symbol_expr
const symbol_exprt & to_symbol_expr(const exprt &expr)
Cast an exprt to a symbol_exprt.
Definition: std_expr.h:189
irept::id
const irep_idt & id() const
Definition: irep.h:407
dispatch_table_entries_mapt
std::map< irep_idt, dispatch_table_entryt > dispatch_table_entries_mapt
Definition: remove_virtual_functions.h:102
class_hierarchyt::class_map
class_mapt class_map
Definition: class_hierarchy.h:55
dstringt::empty
bool empty() const
Definition: dstring.h:88
false_exprt
The Boolean constant false.
Definition: std_expr.h:2725
code_typet::parameters
const parameterst & parameters() const
Definition: std_types.h:649
code_function_callt::arguments
argumentst & arguments()
Definition: std_code.h:1260
optionalt
nonstd::optional< T > optionalt
Definition: optional.h:35
goto_programt::destructive_append
void destructive_append(goto_programt &p)
Appends the given program p to *this. p is destroyed.
Definition: goto_program.h:653
source_locationt
Definition: source_location.h:20
remove_virtual_function
goto_programt::targett remove_virtual_function(symbol_tablet &symbol_table, const irep_idt &function_id, goto_programt &goto_program, goto_programt::targett instruction, const dispatch_table_entriest &dispatch_table, virtual_dispatch_fallback_actiont fallback_action)
Replace virtual function call with a static function call Achieved by substituting a virtual function...
Definition: remove_virtual_functions.cpp:819
goto_programt::instructions
instructionst instructions
The list of instructions in the goto program.
Definition: goto_program.h:569
expr_util.h
Deprecated expression utility functions.
goto_functionst
A collection of goto functions.
Definition: goto_functions.h:23
process_this_argument
static void process_this_argument(const irep_idt &function_id, const goto_programt &goto_program, const goto_programt::targett target, exprt &argument_for_this, symbol_table_baset &symbol_table, const source_locationt &vcall_source_loc, goto_programt &new_code_for_this_argument)
If argument_for_this contains a dereference then create a temporary variable for it and use that inst...
Definition: remove_virtual_functions.cpp:199
expr_iterator.h
Forward depth-first search iterators These iterators' copy operations are expensive,...
goto_modelt::goto_functions
goto_functionst goto_functions
GOTO functions.
Definition: goto_model.h:33
remove_virtual_functionst::symbol_table
symbol_table_baset & symbol_table
Definition: remove_virtual_functions.cpp:80
irept::get
const irep_idt & get(const irep_namet &name) const
Definition: irep.cpp:51
can_cast_expr< class_method_descriptor_exprt >
bool can_cast_expr< class_method_descriptor_exprt >(const exprt &base)
Definition: std_expr.h:3199
symbolt
Symbol table entry.
Definition: symbol.h:28
irept::set
void set(const irep_namet &name, const irep_idt &value)
Definition: irep.h:431
ASSUME
@ ASSUME
Definition: goto_program.h:36
string_typet
String type.
Definition: std_types.h:874
goto_programt
A generic container class for the GOTO intermediate representation of one function.
Definition: goto_program.h:74
class_identifier.h
Extract class identifier.
analyse_checks_directly_preceding_function_call
static goto_programt analyse_checks_directly_preceding_function_call(const goto_programt &goto_program, goto_programt::const_targett instr_it, const exprt &argument_for_this, const symbol_exprt &temp_var_for_this)
Duplicate ASSUME instructions involving argument_for_this for temp_var_for_this.
Definition: remove_virtual_functions.cpp:142
goto_programt::const_targett
instructionst::const_iterator const_targett
Definition: goto_program.h:564
goto_programt::make_assumption
static instructiont make_assumption(const exprt &g, const source_locationt &l=source_locationt::nil())
Definition: goto_program.h:889
resolve_inherited_componentt::build_full_component_identifier
static irep_idt build_full_component_identifier(const irep_idt &class_name, const irep_idt &component_name)
Build a component name as found in a GOTO symbol table equivalent to the name of a concrete component...
Definition: resolve_inherited_component.cpp:92
INVARIANT
#define INVARIANT(CONDITION, REASON)
This macro uses the wrapper function 'invariant_violated_string'.
Definition: invariant.h:424
typecast_exprt
Semantic type conversion.
Definition: std_expr.h:1780
remove_skip.h
Program Transformation.
true_exprt
The Boolean constant true.
Definition: std_expr.h:2716
constant_exprt
A constant literal expression.
Definition: std_expr.h:2667
exprt::depth_end
depth_iteratort depth_end()
Definition: expr.cpp:294
collect_virtual_function_callees
void collect_virtual_function_callees(const exprt &function, const symbol_table_baset &symbol_table, const class_hierarchyt &class_hierarchy, dispatch_table_entriest &overridden_functions)
Given a function expression representing a virtual method of a class, the function computes all overr...
Definition: remove_virtual_functions.cpp:857
ASSERT
@ ASSERT
Definition: goto_program.h:37
comment
static std::string comment(const rw_set_baset::entryt &entry, bool write)
Definition: race_check.cpp:109
goto_modelt::symbol_table
symbol_tablet symbol_table
Symbol table.
Definition: goto_model.h:30
get_fresh_aux_symbol
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 ...
Definition: fresh_symbol.cpp:32
get_virtual_calleest::get_method
exprt get_method(const irep_idt &class_id, const irep_idt &component_name) const
Returns symbol pointing to a specified method in a specified class.
Definition: remove_virtual_functions.cpp:649
goto_model_functiont
Interface providing access to a single function in a GOTO model, plus its associated symbol table.
Definition: goto_model.h:183
remove_virtual_functionst::class_hierarchy
const class_hierarchyt & class_hierarchy
Definition: remove_virtual_functions.cpp:79
goto_programt::targett
instructionst::iterator targett
Definition: goto_program.h:563
code_function_callt::function
exprt & function()
Definition: std_code.h:1250
remove_virtual_functionst
Definition: remove_virtual_functions.cpp:61
get_virtual_calleest
Definition: remove_virtual_functions.cpp:26
source_locationt::set_property_class
void set_property_class(const irep_idt &property_class)
Definition: source_location.h:136
remove_virtual_functionst::operator()
void operator()(goto_functionst &functions)
Remove virtual function calls from all functions in the specified list and replace them with their mo...
Definition: remove_virtual_functions.cpp:701