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 &&
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 ==
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
440  {
441  const irep_idt property_class=it->source_location.get_property_class();
442  const irep_idt comment=it->source_location.get_comment();
443  it->source_location=target->source_location;
444  if(!property_class.empty())
445  it->source_location.set_property_class(property_class);
446  if(!comment.empty())
447  it->source_location.set_comment(comment);
448  }
449 
450  goto_program.destructive_insert(next_target, new_code);
451 
452  // finally, kill original invocation
453  target->turn_into_skip();
454 
455  // only remove skips within the virtual-function handling block
456  remove_skip(goto_program, target, next_target);
457 
458  return next_target;
459 }
460 
471  const irep_idt &function_id,
472  goto_programt &goto_program,
473  goto_programt::targett target)
474 {
475  const code_function_callt &code = target->get_function_call();
476 
477  const exprt &function = code.function();
478  INVARIANT(
480  "remove_virtual_function must take a function call instruction whose "
481  "function is a class method descriptor ");
482  INVARIANT(
483  !code.arguments().empty(),
484  "virtual function calls must have at least a this-argument");
485 
487  dispatch_table_entriest functions;
488  get_callees.get_functions(function, functions);
489 
491  symbol_table,
492  function_id,
493  goto_program,
494  target,
495  functions,
497 }
498 
513  const irep_idt &this_id,
514  const optionalt<symbol_exprt> &last_method_defn,
515  const irep_idt &component_name,
516  dispatch_table_entriest &functions,
517  dispatch_table_entries_mapt &entry_map) const
518 {
519  auto findit=class_hierarchy.class_map.find(this_id);
520  if(findit==class_hierarchy.class_map.end())
521  return;
522 
523  for(const auto &child : findit->second.children)
524  {
525  // Skip if we have already visited this and we found a function call that
526  // did not resolve to non java.lang.Object.
527  auto it = entry_map.find(child);
528  if(
529  it != entry_map.end() &&
530  (!it->second.symbol_expr.has_value() ||
531  !has_prefix(
532  id2string(it->second.symbol_expr->get_identifier()),
533  "java::java.lang.Object")))
534  {
535  continue;
536  }
537  exprt method = get_method(child, component_name);
538  dispatch_table_entryt function(child);
539  if(method.is_not_nil())
540  {
541  function.symbol_expr=to_symbol_expr(method);
542  function.symbol_expr->set(ID_C_class, child);
543  }
544  else
545  {
546  function.symbol_expr=last_method_defn;
547  }
548  if(!function.symbol_expr.has_value())
549  {
550  const auto resolved_call = get_inherited_method_implementation(
551  component_name, child, symbol_table);
552  if(resolved_call)
553  {
554  function.class_id = resolved_call->get_class_identifier();
555  const symbolt &called_symbol = symbol_table.lookup_ref(
556  resolved_call->get_full_component_identifier());
557 
558  function.symbol_expr = called_symbol.symbol_expr();
559  function.symbol_expr->set(
560  ID_C_class, resolved_call->get_class_identifier());
561  }
562  }
563  functions.push_back(function);
564  entry_map.emplace(child, function);
565 
567  child, function.symbol_expr, component_name, functions, entry_map);
568  }
569 }
570 
576  const exprt &function,
577  dispatch_table_entriest &functions) const
578 {
579  // class part of function to call
580  const irep_idt class_id=function.get(ID_C_class);
581  const std::string class_id_string(id2string(class_id));
582  const irep_idt function_name = function.get(ID_component_name);
583  const std::string function_name_string(id2string(function_name));
584  INVARIANT(!class_id.empty(), "All virtual functions must have a class");
585 
586  auto resolved_call =
587  get_inherited_method_implementation(function_name, class_id, symbol_table);
588 
589  // might be an abstract function
590  dispatch_table_entryt root_function(class_id);
591 
592  if(resolved_call)
593  {
594  root_function.class_id = resolved_call->get_class_identifier();
595 
596  const symbolt &called_symbol =
597  symbol_table.lookup_ref(resolved_call->get_full_component_identifier());
598 
599  root_function.symbol_expr=called_symbol.symbol_expr();
600  root_function.symbol_expr->set(
601  ID_C_class, resolved_call->get_class_identifier());
602  }
603 
604  // iterate over all children, transitively
605  dispatch_table_entries_mapt entry_map;
607  class_id, root_function.symbol_expr, function_name, functions, entry_map);
608 
609  if(root_function.symbol_expr.has_value())
610  functions.push_back(root_function);
611 
612  // Sort for the identifier of the function call symbol expression, grouping
613  // together calls to the same function. Keep java.lang.Object entries at the
614  // end for fall through. The reasoning is that this is the case with most
615  // entries in realistic cases.
616  std::sort(
617  functions.begin(),
618  functions.end(),
619  [](const dispatch_table_entryt &a, const dispatch_table_entryt &b) {
620  irep_idt a_id = a.symbol_expr.has_value()
621  ? a.symbol_expr->get_identifier()
622  : irep_idt();
623  irep_idt b_id = b.symbol_expr.has_value()
624  ? b.symbol_expr->get_identifier()
625  : irep_idt();
626 
627  if(has_prefix(id2string(a_id), "java::java.lang.Object"))
628  return false;
629  else if(has_prefix(id2string(b_id), "java::java.lang.Object"))
630  return true;
631  else
632  {
633  int cmp = a_id.compare(b_id);
634  if(cmp == 0)
635  return a.class_id < b.class_id;
636  else
637  return cmp < 0;
638  }
639  });
640 }
641 
648  const irep_idt &class_id,
649  const irep_idt &component_name) const
650 {
651  const irep_idt &id=
653  class_id, component_name);
654 
655  const symbolt *symbol;
656  if(ns.lookup(id, symbol))
657  return nil_exprt();
658 
659  return symbol->symbol_expr();
660 }
661 
666  const irep_idt &function_id,
667  goto_programt &goto_program)
668 {
669  bool did_something=false;
670 
671  for(goto_programt::instructionst::iterator
672  target = goto_program.instructions.begin();
673  target != goto_program.instructions.end();
674  ) // remove_virtual_function returns the next instruction to process
675  {
676  if(target->is_function_call())
677  {
678  const code_function_callt &code = target->get_function_call();
679 
681  {
682  target = remove_virtual_function(function_id, goto_program, target);
683  did_something=true;
684  continue;
685  }
686  }
687 
688  ++target;
689  }
690 
691  if(did_something)
692  goto_program.update();
693 
694  return did_something;
695 }
696 
700 {
701  bool did_something=false;
702 
703  for(goto_functionst::function_mapt::iterator f_it=
704  functions.function_map.begin();
705  f_it!=functions.function_map.end();
706  f_it++)
707  {
708  const irep_idt &function_id = f_it->first;
709  goto_programt &goto_program=f_it->second.body;
710 
711  if(remove_virtual_functions(function_id, goto_program))
712  did_something=true;
713  }
714 
715  if(did_something)
716  functions.compute_location_numbers();
717 }
718 
724  symbol_table_baset &symbol_table,
725  goto_functionst &goto_functions)
726 {
727  class_hierarchyt class_hierarchy;
728  class_hierarchy(symbol_table);
729  remove_virtual_functionst rvf(symbol_table, class_hierarchy);
730  rvf(goto_functions);
731 }
732 
741  symbol_table_baset &symbol_table,
742  goto_functionst &goto_functions,
743  const class_hierarchyt &class_hierarchy)
744 {
745  remove_virtual_functionst rvf(symbol_table, class_hierarchy);
746  rvf(goto_functions);
747 }
748 
752 {
754  goto_model.symbol_table, goto_model.goto_functions);
755 }
756 
763  goto_modelt &goto_model,
764  const class_hierarchyt &class_hierarchy)
765 {
767  goto_model.symbol_table, goto_model.goto_functions, class_hierarchy);
768 }
769 
775 {
776  class_hierarchyt class_hierarchy;
777  class_hierarchy(function.get_symbol_table());
778  remove_virtual_functionst rvf(function.get_symbol_table(), class_hierarchy);
780  function.get_function_id(), function.get_goto_function().body);
781 }
782 
791  goto_model_functiont &function,
792  const class_hierarchyt &class_hierarchy)
793 {
794  remove_virtual_functionst rvf(function.get_symbol_table(), class_hierarchy);
796  function.get_function_id(), function.get_goto_function().body);
797 }
798 
818  symbol_tablet &symbol_table,
819  const irep_idt &function_id,
820  goto_programt &goto_program,
821  goto_programt::targett instruction,
822  const dispatch_table_entriest &dispatch_table,
823  virtual_dispatch_fallback_actiont fallback_action)
824 {
826  symbol_table,
827  function_id,
828  goto_program,
829  instruction,
830  dispatch_table,
831  fallback_action);
832 
833  goto_program.update();
834 
835  return next;
836 }
837 
839  goto_modelt &goto_model,
840  const irep_idt &function_id,
841  goto_programt &goto_program,
842  goto_programt::targett instruction,
843  const dispatch_table_entriest &dispatch_table,
844  virtual_dispatch_fallback_actiont fallback_action)
845 {
847  goto_model.symbol_table,
848  function_id,
849  goto_program,
850  instruction,
851  dispatch_table,
852  fallback_action);
853 }
854 
856  const exprt &function,
857  const symbol_table_baset &symbol_table,
858  const class_hierarchyt &class_hierarchy,
859  dispatch_table_entriest &overridden_functions)
860 {
861  get_virtual_calleest get_callees(symbol_table, class_hierarchy);
862  get_callees.get_functions(function, overridden_functions);
863 }
Forall_goto_program_instructions
#define Forall_goto_program_instructions(it, program)
Definition: goto_program.h:1201
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...
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
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:139
class_hierarchyt
Non-graph-based representation of the class hierarchy.
Definition: class_hierarchy.h:43
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:331
virtual_dispatch_fallback_actiont::ASSUME_FALSE
@ ASSUME_FALSE
When no callee type matches, ASSUME false, thus preventing any complete trace from using this path.
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:512
typet
The type of an expression, extends irept.
Definition: type.h:29
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:85
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:56
prefix.h
goto_programt::update
void update()
Update all indices.
Definition: goto_program.cpp:541
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:686
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:723
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:762
exprt
Base class for all expressions.
Definition: expr.h:53
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:490
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:32
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:82
goto_programt::make_decl
static instructiont make_decl(const symbol_exprt &symbol, const source_locationt &l=source_locationt::nil())
Definition: goto_program.h:920
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:1190
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:1024
goto_programt::make_goto
static instructiont make_goto(targett _target, const source_locationt &l=source_locationt::nil())
Definition: goto_program.h:998
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:665
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:575
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:1049
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:470
exprt::type
typet & type()
Return the type of the expression.
Definition: expr.h:81
namespacet::lookup
bool lookup(const irep_idt &name, const symbolt *&symbol) const override
See documentation for namespace_baset::lookup().
Definition: namespace.cpp:140
code_function_callt
codet representation of a function call statement.
Definition: std_code.h:1183
irept::is_not_nil
bool is_not_nil() const
Definition: irep.h:402
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:639
to_code_type
const code_typet & to_code_type(const typet &type)
Cast a typet to a code_typet.
Definition: std_types.h:946
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:893
symbolt::mode
irep_idt mode
Language mode.
Definition: symbol.h:49
empty_typet
The empty type.
Definition: std_types.h:46
or_exprt
Boolean OR.
Definition: std_expr.h:2245
goto_programt::destructive_insert
void destructive_insert(const_targett target, goto_programt &p)
Inserts the given program p before target.
Definition: goto_program.h:677
id2string
const std::string & id2string(const irep_idt &d)
Definition: irep.h:44
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:851
symbol_exprt::get_identifier
const irep_idt & get_identifier() const
Definition: std_expr.h:111
symbol_table_baset
The symbol table base class interface.
Definition: symbol_table_base.h:22
nil_exprt
The NIL expression.
Definition: std_expr.h:3973
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:177
irept::id
const irep_idt & id() const
Definition: irep.h:418
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:3964
code_typet::parameters
const parameterst & parameters() const
Definition: std_types.h:857
code_function_callt::arguments
argumentst & arguments()
Definition: std_code.h:1228
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:669
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:817
goto_programt::instructions
instructionst instructions
The list of instructions in the goto program.
Definition: goto_program.h:585
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:4608
symbolt
Symbol table entry.
Definition: symbol.h:28
irept::set
void set(const irep_namet &name, const irep_idt &value)
Definition: irep.h:442
ASSUME
@ ASSUME
Definition: goto_program.h:35
string_typet
String type.
Definition: std_types.h:1655
goto_programt
A generic container class for the GOTO intermediate representation of one function.
Definition: goto_program.h:73
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:580
has_prefix
bool has_prefix(const std::string &s, const std::string &prefix)
Definition: converter.cpp:13
goto_programt::make_assumption
static instructiont make_assumption(const exprt &g, const source_locationt &l=source_locationt::nil())
Definition: goto_program.h:905
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:2013
remove_skip.h
Program Transformation.
true_exprt
The Boolean constant true.
Definition: std_expr.h:3955
constant_exprt
A constant literal expression.
Definition: std_expr.h:3906
exprt::depth_end
depth_iteratort depth_end()
Definition: expr.cpp:333
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:855
ASSERT
@ ASSERT
Definition: goto_program.h:36
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:647
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:579
code_function_callt::function
exprt & function()
Definition: std_code.h:1218
validation_modet::INVARIANT
@ INVARIANT
remove_virtual_functionst
Definition: remove_virtual_functions.cpp:61
get_virtual_calleest
Definition: remove_virtual_functions.cpp:26
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:699