Skip to content

Commit 60f91f3

Browse files
Extract a convert_method method
1 parent 21a4324 commit 60f91f3

File tree

2 files changed

+69
-28
lines changed

2 files changed

+69
-28
lines changed

jbmc/src/java_bytecode/ci_lazy_methods.cpp

Lines changed: 53 additions & 28 deletions
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 convertion_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 |= convertion_result.new_method_seen;
150+
class_initializer_seen |= convertion_result.class_initializer_seen;
168151
}
169152
}
170153

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

258+
ci_lazy_methodst::convert_method_resultt
259+
ci_lazy_methodst::convert_and_analyze_method(
260+
const method_convertert &method_converter,
261+
std::unordered_set<irep_idt> &methods_already_populated,
262+
const bool class_initializer_seen,
263+
const dstringt &mname,
264+
symbol_tablet &symbol_table,
265+
std::unordered_set<irep_idt> &methods_to_convert_later,
266+
std::unordered_set<irep_idt> &instantiated_classes,
267+
std::unordered_set<exprt, irep_hash> &virtual_function_calls)
268+
{
269+
convert_method_resultt result;
270+
if(!methods_already_populated.insert(mname).second)
271+
return result;
272+
273+
debug() << "CI lazy methods: elaborate " << mname << eom;
274+
275+
// Note this wraps *references* to methods_to_convert_later &
276+
// instantiated_classes
277+
ci_lazy_methods_neededt needed_methods(
278+
methods_to_convert_later, instantiated_classes, symbol_table);
279+
280+
const bool could_not_convert_function =
281+
method_converter(mname, needed_methods);
282+
if(could_not_convert_function)
283+
return result;
284+
285+
const exprt &method_body = symbol_table.lookup_ref(mname).value;
286+
gather_virtual_callsites(method_body, virtual_function_calls);
287+
288+
if(!class_initializer_seen && references_class_model(method_body))
289+
{
290+
result.class_initializer_seen = true;
291+
const irep_idt initializer_signature =
292+
get_java_class_literal_initializer_signature();
293+
if(symbol_table.has_symbol(initializer_signature))
294+
methods_to_convert_later.insert(initializer_signature);
295+
}
296+
result.new_method_seen = true;
297+
return result;
298+
}
299+
275300
/// Entry point methods are either:
276301
/// * the "main" function of the `main_class` if it exists
277302
/// * all the methods of the main class if it is not empty

jbmc/src/java_bytecode/ci_lazy_methods.h

Lines changed: 16 additions & 0 deletions
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_seen,
186+
const dstringt &mname,
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)