Skip to content

Commit 24b6936

Browse files
Extract entry_point_methods method
1 parent 360fabe commit 24b6936

File tree

2 files changed

+45
-28
lines changed

2 files changed

+45
-28
lines changed

jbmc/src/java_bytecode/ci_lazy_methods.cpp

Lines changed: 42 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -98,34 +98,8 @@ bool ci_lazy_methodst::operator()(
9898
method_bytecodet &method_bytecode,
9999
const method_convertert &method_converter)
100100
{
101-
std::unordered_set<irep_idt> methods_to_convert_later;
102-
103-
main_function_resultt main_function =
104-
get_main_symbol(symbol_table, main_class, get_message_handler());
105-
if(!main_function.is_success())
106-
{
107-
// Failed, mark all functions in the given main class(es)
108-
// reachable.
109-
std::vector<irep_idt> reachable_classes;
110-
if(!main_class.empty())
111-
reachable_classes.push_back(main_class);
112-
else
113-
reachable_classes = main_jar_classes;
114-
for(const irep_idt &class_name : reachable_classes)
115-
{
116-
const auto &methods =
117-
java_class_loader.get_original_class(class_name).parsed_class.methods;
118-
for(const auto &method : methods)
119-
{
120-
const irep_idt methodid =
121-
"java::" + id2string(class_name) + "." + id2string(method.name)
122-
+ ":" + id2string(method.descriptor);
123-
methods_to_convert_later.insert(methodid);
124-
}
125-
}
126-
}
127-
else
128-
methods_to_convert_later.insert(main_function.main_function.name);
101+
std::unordered_set<irep_idt> methods_to_convert_later =
102+
entry_point_methods(symbol_table);
129103

130104
// Add any extra entry points specified; we should elaborate these in the
131105
// same way as the main function.
@@ -297,6 +271,46 @@ bool ci_lazy_methodst::operator()(
297271
return false;
298272
}
299273

274+
/// Entry point methods are either:
275+
/// * the "main" function of the `main_class` if it exists
276+
/// * all the methods of the main class if it is not empty
277+
/// * all the methods of the main jar file
278+
/// \return set of identifiers of entry point methods
279+
std::unordered_set<irep_idt>
280+
ci_lazy_methodst::entry_point_methods(const symbol_tablet &symbol_table)
281+
{
282+
std::unordered_set<irep_idt> methods_to_convert_later;
283+
284+
const main_function_resultt main_function = get_main_symbol(
285+
symbol_table, this->main_class, this->get_message_handler());
286+
if(!main_function.is_success())
287+
{
288+
// Failed, mark all functions in the given main class(es)
289+
// reachable.
290+
std::vector<irep_idt> reachable_classes;
291+
if(!this->main_class.empty())
292+
reachable_classes.push_back(this->main_class);
293+
else
294+
reachable_classes = this->main_jar_classes;
295+
for(const irep_idt &class_name : reachable_classes)
296+
{
297+
const auto &methods =
298+
this->java_class_loader.get_original_class(class_name)
299+
.parsed_class.methods;
300+
for(const auto &method : methods)
301+
{
302+
const irep_idt methodid = "java::" + id2string(class_name) + "." +
303+
id2string(method.name) + ":" +
304+
id2string(method.descriptor);
305+
methods_to_convert_later.insert(methodid);
306+
}
307+
}
308+
}
309+
else
310+
methods_to_convert_later.insert(main_function.main_function.name);
311+
return methods_to_convert_later;
312+
}
313+
300314
/// Translates the given list of method names from human-readable to
301315
/// internal syntax.
302316
/// Expands any wildcards (entries ending in '.*') in the given method

jbmc/src/java_bytecode/ci_lazy_methods.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,9 @@ class ci_lazy_methodst:public messaget
169169
const std::vector<irep_idt> &extra_instantiated_classes;
170170
const select_pointer_typet &pointer_type_selector;
171171
const synthetic_methods_mapt &synthetic_methods;
172+
173+
std::unordered_set<irep_idt>
174+
entry_point_methods(const symbol_tablet &symbol_table);
172175
};
173176

174177
#endif // CPROVER_JAVA_BYTECODE_GATHER_METHODS_LAZILY_H

0 commit comments

Comments
 (0)