Skip to content

Commit cac016d

Browse files
Extract a convert_and_analyze_method method
1 parent ca0adc9 commit cac016d

File tree

2 files changed

+78
-28
lines changed

2 files changed

+78
-28
lines changed

jbmc/src/java_bytecode/ci_lazy_methods.cpp

+62-28
Original file line numberDiff line numberDiff line change
@@ -137,34 +137,17 @@ bool ci_lazy_methodst::operator()(
137137
std::swap(methods_to_convert, methods_to_convert_later);
138138
for(const auto &mname : methods_to_convert)
139139
{
140-
if(!methods_already_populated.insert(mname).second)
141-
continue;
142-
debug() << "CI lazy methods: elaborate " << mname << eom;
143-
if(
144-
method_converter(
145-
mname,
146-
// Note this wraps *references* to methods_to_convert_later &
147-
// instantiated_classes
148-
ci_lazy_methods_neededt(
149-
methods_to_convert_later, instantiated_classes, symbol_table)))
150-
{
151-
// Couldn't convert this function
152-
continue;
153-
}
154-
const exprt &method_body = symbol_table.lookup_ref(mname).value;
155-
156-
gather_virtual_callsites(method_body, virtual_function_calls);
157-
158-
if(!class_initializer_seen && references_class_model(method_body))
159-
{
160-
class_initializer_seen = true;
161-
irep_idt initializer_signature =
162-
get_java_class_literal_initializer_signature();
163-
if(symbol_table.has_symbol(initializer_signature))
164-
methods_to_convert_later.insert(initializer_signature);
165-
}
166-
167-
any_new_methods = true;
140+
const auto conversion_result = convert_and_analyze_method(
141+
method_converter,
142+
methods_already_populated,
143+
class_initializer_seen,
144+
mname,
145+
symbol_table,
146+
methods_to_convert_later,
147+
instantiated_classes,
148+
virtual_function_calls);
149+
any_new_methods |= conversion_result.new_method_seen;
150+
class_initializer_seen |= conversion_result.class_initializer_seen;
168151
}
169152
}
170153

@@ -272,6 +255,57 @@ bool ci_lazy_methodst::operator()(
272255
return false;
273256
}
274257

258+
/// Convert a method, add it to the populated set, add needed methods to
259+
/// methods_to_convert_later and add virtual calls from the method to
260+
/// virtual_function_calls
261+
/// \return structure containing two Booleans:
262+
/// * class_initializer_seen which is true if the class_initializer_seen
263+
/// argument was false and the class_model is referenced in
264+
/// the body of the method
265+
/// * new_method_seen if the method was not converted before and was
266+
/// converted successfully here
267+
ci_lazy_methodst::convert_method_resultt
268+
ci_lazy_methodst::convert_and_analyze_method(
269+
const method_convertert &method_converter,
270+
std::unordered_set<irep_idt> &methods_already_populated,
271+
const bool class_initializer_already_seen,
272+
const irep_idt &method_name,
273+
symbol_tablet &symbol_table,
274+
std::unordered_set<irep_idt> &methods_to_convert_later,
275+
std::unordered_set<irep_idt> &instantiated_classes,
276+
std::unordered_set<exprt, irep_hash> &virtual_function_calls)
277+
{
278+
convert_method_resultt result;
279+
if(!methods_already_populated.insert(method_name).second)
280+
return result;
281+
282+
debug() << "CI lazy methods: elaborate " << method_name << eom;
283+
284+
// Note this wraps *references* to methods_to_convert_later &
285+
// instantiated_classes
286+
ci_lazy_methods_neededt needed_methods(
287+
methods_to_convert_later, instantiated_classes, symbol_table);
288+
289+
const bool could_not_convert_function =
290+
method_converter(method_name, needed_methods);
291+
if(could_not_convert_function)
292+
return result;
293+
294+
const exprt &method_body = symbol_table.lookup_ref(method_name).value;
295+
gather_virtual_callsites(method_body, virtual_function_calls);
296+
297+
if(!class_initializer_already_seen && references_class_model(method_body))
298+
{
299+
result.class_initializer_seen = true;
300+
const irep_idt initializer_signature =
301+
get_java_class_literal_initializer_signature();
302+
if(symbol_table.has_symbol(initializer_signature))
303+
methods_to_convert_later.insert(initializer_signature);
304+
}
305+
result.new_method_seen = true;
306+
return result;
307+
}
308+
275309
/// Entry point methods are either:
276310
/// * the "main" function of the `main_class` if it exists
277311
/// * all the methods of the main class if it is not empty

jbmc/src/java_bytecode/ci_lazy_methods.h

+16
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,22 @@ class ci_lazy_methodst:public messaget
172172

173173
std::unordered_set<irep_idt>
174174
entry_point_methods(const symbol_tablet &symbol_table);
175+
176+
struct convert_method_resultt
177+
{
178+
bool class_initializer_seen = false;
179+
bool new_method_seen = false;
180+
};
181+
182+
convert_method_resultt convert_and_analyze_method(
183+
const method_convertert &method_converter,
184+
std::unordered_set<irep_idt> &methods_already_populated,
185+
const bool class_initializer_already_seen,
186+
const irep_idt &method_name,
187+
symbol_tablet &symbol_table,
188+
std::unordered_set<irep_idt> &methods_to_convert_later,
189+
std::unordered_set<irep_idt> &instantiated_classes,
190+
std::unordered_set<exprt, irep_hash> &virtual_function_calls);
175191
};
176192

177193
#endif // CPROVER_JAVA_BYTECODE_GATHER_METHODS_LAZILY_H

0 commit comments

Comments
 (0)