cprover
ci_lazy_methods.h
Go to the documentation of this file.
1 /*******************************************************************\
2 
3  Module: Java Bytecode
4 
5  Author: Diffblue Ltd.
6 
7 \*******************************************************************/
8 
11 
12 #ifndef CPROVER_JAVA_BYTECODE_GATHER_METHODS_LAZILY_H
13 #define CPROVER_JAVA_BYTECODE_GATHER_METHODS_LAZILY_H
14 
15 #include "ci_lazy_methods_needed.h"
17 #include "java_class_loader.h"
18 #include "select_pointer_type.h"
19 #include "synthetic_methods_map.h"
20 
21 #include <map>
22 #include <functional>
23 
24 #include <util/irep.h>
25 #include <util/symbol_table.h>
26 #include <util/message.h>
27 
29 
31 
32 // Map from method id to class_method_and_bytecodet
34 {
35 public:
38  {
42  };
43 
46 
47 private:
48  typedef std::map<irep_idt, class_method_and_bytecodet> mapt;
50 
51 public:
52  bool contains_method(const irep_idt &method_id) const
53  {
54  return map.count(method_id) != 0;
55  }
56 
57  void add(const class_method_and_bytecodet &method_class_and_bytecode)
58  {
59  map.emplace(
60  std::make_pair(
61  method_class_and_bytecode.method_id, method_class_and_bytecode));
62  }
63 
64  void add(
65  const irep_idt &class_id,
66  const irep_idt &method_id,
68  {
69  add(class_method_and_bytecodet{class_id, method_id, method});
70  }
71 
72  mapt::const_iterator begin() const
73  {
74  return map.begin();
75  }
76  mapt::const_iterator end() const
77  {
78  return map.end();
79  }
80 
81  opt_reft get(const irep_idt &method_id)
82  {
83  const auto it = map.find(method_id);
84  if(it == map.end())
85  return opt_reft();
86  return std::cref(it->second);
87  }
88 };
89 
90 typedef std::function<
91  bool(const irep_idt &function_id, ci_lazy_methods_neededt)>
93 
95 {
96 public:
98  const symbol_tablet &symbol_table,
99  const irep_idt &main_class,
100  const std::vector<irep_idt> &main_jar_classes,
101  const std::vector<irep_idt> &lazy_methods_extra_entry_points,
103  const std::vector<irep_idt> &extra_instantiated_classes,
107 
108  // not const since messaget
109  bool operator()(
110  symbol_tablet &symbol_table,
111  method_bytecodet &method_bytecode,
112  const method_convertert &method_converter);
113 
114 private:
116  std::vector<irep_idt> &methods,
117  const symbol_tablet &symbol_table);
118 
120  const std::unordered_set<irep_idt> &entry_points,
121  const namespacet &ns,
122  ci_lazy_methods_neededt &needed_lazy_methods);
123 
125  const exprt &e,
126  std::unordered_set<exprt, irep_hash> &result);
127 
129  const exprt &called_function,
130  const std::unordered_set<irep_idt> &instantiated_classes,
131  std::unordered_set<irep_idt> &callable_methods,
132  symbol_tablet &symbol_table);
133 
135  const exprt &e,
136  const symbol_tablet &symbol_table,
137  symbol_tablet &needed);
138 
140  const std::unordered_set<irep_idt> &instantiated_classes,
141  const irep_idt &call_basename,
142  const irep_idt &classname,
143  const symbol_tablet &symbol_table);
144 
146  const irep_idt &class_name,
147  const irep_idt &component_method_name);
148 
151  std::vector<irep_idt> main_jar_classes;
152  std::vector<irep_idt> lazy_methods_extra_entry_points;
154  const std::vector<irep_idt> &extra_instantiated_classes;
157 
158  std::unordered_set<irep_idt>
159  entry_point_methods(const symbol_tablet &symbol_table);
160 
162  {
164  bool new_method_seen = false;
165  };
166 
168  const method_convertert &method_converter,
169  std::unordered_set<irep_idt> &methods_already_populated,
170  const bool class_initializer_already_seen,
171  const irep_idt &method_name,
172  symbol_tablet &symbol_table,
173  std::unordered_set<irep_idt> &methods_to_convert_later,
174  std::unordered_set<irep_idt> &instantiated_classes,
175  std::unordered_set<exprt, irep_hash> &virtual_function_calls);
176 
178  std::unordered_set<irep_idt> &methods_to_convert_later,
179  std::unordered_set<irep_idt> &instantiated_classes,
180  const std::unordered_set<exprt, irep_hash> &virtual_function_calls,
181  symbol_tablet &symbol_table);
182 };
183 
184 #endif // CPROVER_JAVA_BYTECODE_GATHER_METHODS_LAZILY_H
ci_lazy_methodst(const symbol_tablet &symbol_table, const irep_idt &main_class, const std::vector< irep_idt > &main_jar_classes, const std::vector< irep_idt > &lazy_methods_extra_entry_points, java_class_loadert &java_class_loader, const std::vector< irep_idt > &extra_instantiated_classes, const select_pointer_typet &pointer_type_selector, message_handlert &message_handler, const synthetic_methods_mapt &synthetic_methods)
Constructor for lazy-method loading.
convert_method_resultt convert_and_analyze_method(const method_convertert &method_converter, std::unordered_set< irep_idt > &methods_already_populated, const bool class_initializer_already_seen, const irep_idt &method_name, symbol_tablet &symbol_table, std::unordered_set< irep_idt > &methods_to_convert_later, std::unordered_set< irep_idt > &instantiated_classes, std::unordered_set< exprt, irep_hash > &virtual_function_calls)
Convert a method, add it to the populated set, add needed methods to methods_to_convert_later and add...
optionalt< std::reference_wrapper< const class_method_and_bytecodet > > opt_reft
bool handle_virtual_methods_with_no_callees(std::unordered_set< irep_idt > &methods_to_convert_later, std::unordered_set< irep_idt > &instantiated_classes, const std::unordered_set< exprt, irep_hash > &virtual_function_calls, symbol_tablet &symbol_table)
Look for virtual callsites with no candidate targets.
const select_pointer_typet & pointer_type_selector
mapt::const_iterator end() const
std::function< bool(const irep_idt &function_id, ci_lazy_methods_neededt)> method_convertert
void resolve_method_names(std::vector< irep_idt > &methods, const symbol_tablet &symbol_table)
Translates the given list of method names from human-readable to internal syntax. ...
const std::vector< irep_idt > & extra_instantiated_classes
irep_idt get_virtual_method_target(const std::unordered_set< irep_idt > &instantiated_classes, const irep_idt &call_basename, const irep_idt &classname, const symbol_tablet &symbol_table)
Find a virtual callee, if one is defined and the callee type is known to exist.
void gather_virtual_callsites(const exprt &e, std::unordered_set< exprt, irep_hash > &result)
Get places where virtual functions are called.
Class Hierarchy.
void add(const class_method_and_bytecodet &method_class_and_bytecode)
std::vector< irep_idt > lazy_methods_extra_entry_points
void initialize_instantiated_classes(const std::unordered_set< irep_idt > &entry_points, const namespacet &ns, ci_lazy_methods_neededt &needed_lazy_methods)
Build up a list of methods whose type may be passed around reachable from the entry point...
void gather_needed_globals(const exprt &e, const symbol_tablet &symbol_table, symbol_tablet &needed)
See output.
java_class_loadert & java_class_loader
nonstd::optional< T > optionalt
Definition: optional.h:35
The symbol table.
Definition: symbol_table.h:19
TO_BE_DOCUMENTED.
Definition: namespace.h:74
void add(const irep_idt &class_id, const irep_idt &method_id, const java_bytecode_parse_treet::methodt &method)
const synthetic_methods_mapt & synthetic_methods
Author: Diffblue Ltd.
const java_bytecode_parse_treet::methodt & method
bool contains_method(const irep_idt &method_id) const
mstreamt & result() const
Definition: message.h:312
Base class for all expressions.
Definition: expr.h:42
std::unordered_set< irep_idt > entry_point_methods(const symbol_tablet &symbol_table)
Entry point methods are either:
std::vector< irep_idt > main_jar_classes
Synthetic methods are particular methods internally generated by the Java frontend, including thunks to ensure static initializers are run once and initializers created for unknown / stub types.
static irep_idt build_virtual_method_name(const irep_idt &class_name, const irep_idt &component_method_name)
mapt::const_iterator begin() const
Context-insensitive lazy methods container.
std::unordered_map< irep_idt, synthetic_method_typet > synthetic_methods_mapt
Maps method names on to a synthetic method kind.
void get_virtual_method_targets(const exprt &called_function, const std::unordered_set< irep_idt > &instantiated_classes, std::unordered_set< irep_idt > &callable_methods, symbol_tablet &symbol_table)
Find possible callees, excluding types that are not known to be instantiated.
bool operator()(symbol_tablet &symbol_table, method_bytecodet &method_bytecode, const method_convertert &method_converter)
Uses a simple context-insensitive (&#39;ci&#39;) analysis to determine which methods may be reachable from th...
message_handlert * message_handler
Definition: message.h:342
Handle selection of correct pointer type (for example changing abstract classes to concrete versions)...
class_hierarchyt class_hierarchy
std::map< irep_idt, class_method_and_bytecodet > mapt