Skip to content

Commit

Permalink
Extract entry_point_methods method
Browse files Browse the repository at this point in the history
  • Loading branch information
romainbrenguier committed Jun 17, 2018
1 parent 360fabe commit 24b6936
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 28 deletions.
70 changes: 42 additions & 28 deletions jbmc/src/java_bytecode/ci_lazy_methods.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,34 +98,8 @@ bool ci_lazy_methodst::operator()(
method_bytecodet &method_bytecode,
const method_convertert &method_converter)
{
std::unordered_set<irep_idt> methods_to_convert_later;

main_function_resultt main_function =
get_main_symbol(symbol_table, main_class, get_message_handler());
if(!main_function.is_success())
{
// Failed, mark all functions in the given main class(es)
// reachable.
std::vector<irep_idt> reachable_classes;
if(!main_class.empty())
reachable_classes.push_back(main_class);
else
reachable_classes = main_jar_classes;
for(const irep_idt &class_name : reachable_classes)
{
const auto &methods =
java_class_loader.get_original_class(class_name).parsed_class.methods;
for(const auto &method : methods)
{
const irep_idt methodid =
"java::" + id2string(class_name) + "." + id2string(method.name)
+ ":" + id2string(method.descriptor);
methods_to_convert_later.insert(methodid);
}
}
}
else
methods_to_convert_later.insert(main_function.main_function.name);
std::unordered_set<irep_idt> methods_to_convert_later =
entry_point_methods(symbol_table);

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

/// Entry point methods are either:
/// * the "main" function of the `main_class` if it exists
/// * all the methods of the main class if it is not empty
/// * all the methods of the main jar file
/// \return set of identifiers of entry point methods
std::unordered_set<irep_idt>
ci_lazy_methodst::entry_point_methods(const symbol_tablet &symbol_table)
{
std::unordered_set<irep_idt> methods_to_convert_later;

const main_function_resultt main_function = get_main_symbol(
symbol_table, this->main_class, this->get_message_handler());
if(!main_function.is_success())
{
// Failed, mark all functions in the given main class(es)
// reachable.
std::vector<irep_idt> reachable_classes;
if(!this->main_class.empty())
reachable_classes.push_back(this->main_class);
else
reachable_classes = this->main_jar_classes;
for(const irep_idt &class_name : reachable_classes)
{
const auto &methods =
this->java_class_loader.get_original_class(class_name)
.parsed_class.methods;
for(const auto &method : methods)
{
const irep_idt methodid = "java::" + id2string(class_name) + "." +
id2string(method.name) + ":" +
id2string(method.descriptor);
methods_to_convert_later.insert(methodid);
}
}
}
else
methods_to_convert_later.insert(main_function.main_function.name);
return methods_to_convert_later;
}

/// Translates the given list of method names from human-readable to
/// internal syntax.
/// Expands any wildcards (entries ending in '.*') in the given method
Expand Down
3 changes: 3 additions & 0 deletions jbmc/src/java_bytecode/ci_lazy_methods.h
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,9 @@ class ci_lazy_methodst:public messaget
const std::vector<irep_idt> &extra_instantiated_classes;
const select_pointer_typet &pointer_type_selector;
const synthetic_methods_mapt &synthetic_methods;

std::unordered_set<irep_idt>
entry_point_methods(const symbol_tablet &symbol_table);
};

#endif // CPROVER_JAVA_BYTECODE_GATHER_METHODS_LAZILY_H

0 comments on commit 24b6936

Please sign in to comment.