Skip to content

Commit 1e55404

Browse files
author
thk123
committed
CI lazy methods take vector of method loaders
These method loads can be used to manually load additional methods for ci_lazy_methods
1 parent 2fb9e21 commit 1e55404

File tree

2 files changed

+13
-57
lines changed

2 files changed

+13
-57
lines changed

jbmc/src/java_bytecode/ci_lazy_methods.cpp

+8-51
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ ci_lazy_methodst::ci_lazy_methodst(
3434
const symbol_tablet &symbol_table,
3535
const irep_idt &main_class,
3636
const std::vector<irep_idt> &main_jar_classes,
37-
const std::vector<irep_idt> &lazy_methods_extra_entry_points,
37+
const std::vector<load_extra_methodst> &lazy_methods_extra_entry_points,
3838
java_class_loadert &java_class_loader,
3939
const std::vector<irep_idt> &extra_instantiated_classes,
4040
const select_pointer_typet &pointer_type_selector,
@@ -103,8 +103,13 @@ bool ci_lazy_methodst::operator()(
103103

104104
// Add any extra entry points specified; we should elaborate these in the
105105
// same way as the main function.
106-
std::vector<irep_idt> extra_entry_points=lazy_methods_extra_entry_points;
107-
resolve_method_names(extra_entry_points, symbol_table);
106+
std::vector<irep_idt> extra_entry_points;
107+
for(const auto &extra_function_generator : lazy_methods_extra_entry_points)
108+
{
109+
const auto &extra_methods = extra_function_generator(symbol_table);
110+
extra_entry_points.insert(
111+
extra_entry_points.end(), extra_methods.begin(), extra_methods.end());
112+
}
108113
methods_to_convert_later.insert(
109114
extra_entry_points.begin(), extra_entry_points.end());
110115

@@ -355,54 +360,6 @@ ci_lazy_methodst::entry_point_methods(const symbol_tablet &symbol_table)
355360
return methods_to_convert_later;
356361
}
357362

358-
/// Translates the given list of method names from human-readable to
359-
/// internal syntax.
360-
/// Expands any wildcards (entries ending in '.*') in the given method
361-
/// list to include all non-static methods defined on the given class.
362-
/// \param [in, out] methods: List of methods to expand. Any wildcard entries
363-
/// will be deleted and the expanded entries appended to the end.
364-
/// \param symbol_table: global symbol table
365-
void ci_lazy_methodst::resolve_method_names(
366-
std::vector<irep_idt> &methods,
367-
const symbol_tablet &symbol_table)
368-
{
369-
std::vector<irep_idt> new_methods;
370-
for(const irep_idt &method : methods)
371-
{
372-
const std::string &method_str=id2string(method);
373-
if(!has_suffix(method_str, ".*"))
374-
{
375-
std::string error_message;
376-
irep_idt internal_name=
377-
resolve_friendly_method_name(
378-
method_str,
379-
symbol_table,
380-
error_message);
381-
if(internal_name==irep_idt())
382-
throw "entry point "+error_message;
383-
new_methods.push_back(internal_name);
384-
}
385-
else
386-
{
387-
irep_idt classname="java::"+method_str.substr(0, method_str.length()-2);
388-
if(!symbol_table.has_symbol(classname))
389-
throw "wildcard entry point '"+method_str+"': unknown class";
390-
391-
for(const auto &name_symbol : symbol_table.symbols)
392-
{
393-
if(name_symbol.second.type.id()!=ID_code)
394-
continue;
395-
if(!to_code_type(name_symbol.second.type).has_this())
396-
continue;
397-
if(has_prefix(id2string(name_symbol.first), id2string(classname)))
398-
new_methods.push_back(name_symbol.first);
399-
}
400-
}
401-
}
402-
403-
methods=std::move(new_methods);
404-
}
405-
406363
/// Build up a list of methods whose type may be passed around reachable
407364
/// from the entry point.
408365
/// \param entry_points: list of fully-qualified function names that

jbmc/src/java_bytecode/ci_lazy_methods.h

+5-6
Original file line numberDiff line numberDiff line change
@@ -91,14 +91,17 @@ typedef std::function<
9191
bool(const irep_idt &function_id, ci_lazy_methods_neededt)>
9292
method_convertert;
9393

94+
typedef std::function<std::vector<irep_idt>(const symbol_tablet &)>
95+
load_extra_methodst;
96+
9497
class ci_lazy_methodst:public messaget
9598
{
9699
public:
97100
ci_lazy_methodst(
98101
const symbol_tablet &symbol_table,
99102
const irep_idt &main_class,
100103
const std::vector<irep_idt> &main_jar_classes,
101-
const std::vector<irep_idt> &lazy_methods_extra_entry_points,
104+
const std::vector<load_extra_methodst> &lazy_methods_extra_entry_points,
102105
java_class_loadert &java_class_loader,
103106
const std::vector<irep_idt> &extra_instantiated_classes,
104107
const select_pointer_typet &pointer_type_selector,
@@ -112,10 +115,6 @@ class ci_lazy_methodst:public messaget
112115
const method_convertert &method_converter);
113116

114117
private:
115-
void resolve_method_names(
116-
std::vector<irep_idt> &methods,
117-
const symbol_tablet &symbol_table);
118-
119118
void initialize_instantiated_classes(
120119
const std::unordered_set<irep_idt> &entry_points,
121120
const namespacet &ns,
@@ -149,7 +148,7 @@ class ci_lazy_methodst:public messaget
149148
class_hierarchyt class_hierarchy;
150149
irep_idt main_class;
151150
std::vector<irep_idt> main_jar_classes;
152-
std::vector<irep_idt> lazy_methods_extra_entry_points;
151+
const std::vector<load_extra_methodst> &lazy_methods_extra_entry_points;
153152
java_class_loadert &java_class_loader;
154153
const std::vector<irep_idt> &extra_instantiated_classes;
155154
const select_pointer_typet &pointer_type_selector;

0 commit comments

Comments
 (0)