Skip to content

Commit 2aa5835

Browse files
author
Lukasz A.J. Wrona
committed
Conver the last function
1 parent e497293 commit 2aa5835

File tree

1 file changed

+55
-51
lines changed

1 file changed

+55
-51
lines changed

jbmc/src/java_bytecode/lambda_synthesis.cpp

Lines changed: 55 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,56 @@ static symbolt create_constructor_symbol(
206206
constructor_symbol.type = constructor_type;
207207
set_declaring_class(constructor_symbol, synthetic_class_name);
208208
return constructor_symbol;
209-
}
209+
}
210+
211+
symbolt create_implemented_method_symbol(
212+
synthetic_methods_mapt &synthetic_methods,
213+
const symbolt &interface_method_symbol,
214+
const struct_tag_typet &implemented_interface_tag,
215+
const irep_idt &synthetic_class_name)
216+
{
217+
const std::string implemented_method_name = [&] {
218+
std::string implemented_method_name =
219+
id2string(interface_method_symbol.name);
220+
const std::string &implemented_interface_tag_str =
221+
id2string(implemented_interface_tag.get_identifier());
222+
INVARIANT(
223+
has_prefix(implemented_method_name, implemented_interface_tag_str),
224+
"method names should be prefixed by their defining type");
225+
implemented_method_name.replace(
226+
0,
227+
implemented_interface_tag_str.length(),
228+
id2string(synthetic_class_name));
229+
return implemented_method_name;
230+
}();
231+
232+
symbolt implemented_method_symbol;
233+
implemented_method_symbol.name = implemented_method_name;
234+
synthetic_methods[implemented_method_symbol.name] =
235+
synthetic_method_typet::INVOKEDYNAMIC_METHOD;
236+
implemented_method_symbol.pretty_name = implemented_method_symbol.name;
237+
implemented_method_symbol.base_name = interface_method_symbol.base_name;
238+
implemented_method_symbol.mode = ID_java;
239+
implemented_method_symbol.type = interface_method_symbol.type;
240+
auto &implemented_method_type = to_code_type(implemented_method_symbol.type);
241+
implemented_method_type.parameters()[0].type() =
242+
java_reference_type(struct_tag_typet(synthetic_class_name));
243+
244+
size_t field_idx = 0;
245+
for(auto &param : implemented_method_type.parameters())
246+
{
247+
irep_idt param_basename =
248+
field_idx == 0 ? "this" : "param_" + std::to_string(field_idx);
249+
param.set_base_name(param_basename);
250+
param.set_identifier(
251+
id2string(implemented_method_name) + "::" + id2string(param_basename));
252+
253+
++field_idx;
254+
}
255+
256+
set_declaring_class(implemented_method_symbol, synthetic_class_name);
257+
return implemented_method_symbol;
258+
}
210259

211260
void create_invokedynamic_synthetic_classes(
212261
const irep_idt &method_identifier,
@@ -288,56 +337,11 @@ void create_invokedynamic_synthetic_classes(
288337
symbol_table.add(create_constructor_symbol(
289338
synthetic_methods, synthetic_class_name, dynamic_method_type));
290339

291-
// Create implemented method symbol:
292-
293-
symbol_table.add([&] {
294-
const symbolt &interface_method_symbol =
295-
ns.lookup(*interface_method_id);
296-
297-
const std::string implemented_method_name = [&] {
298-
std::string implemented_method_name =
299-
id2string(interface_method_symbol.name);
300-
const std::string &implemented_interface_tag_str =
301-
id2string(implemented_interface_tag.get_identifier());
302-
INVARIANT(
303-
has_prefix(implemented_method_name, implemented_interface_tag_str),
304-
"method names should be prefixed by their defining type");
305-
implemented_method_name.replace(
306-
0,
307-
implemented_interface_tag_str.length(),
308-
id2string(synthetic_class_name));
309-
return implemented_method_name;
310-
}();
311-
312-
symbolt implemented_method_symbol;
313-
implemented_method_symbol.name = implemented_method_name;
314-
synthetic_methods[implemented_method_symbol.name] =
315-
synthetic_method_typet::INVOKEDYNAMIC_METHOD;
316-
implemented_method_symbol.pretty_name = implemented_method_symbol.name;
317-
implemented_method_symbol.base_name = interface_method_symbol.base_name;
318-
implemented_method_symbol.mode = ID_java;
319-
implemented_method_symbol.type = interface_method_symbol.type;
320-
auto &implemented_method_type =
321-
to_code_type(implemented_method_symbol.type);
322-
implemented_method_type.parameters()[0].type() =
323-
java_reference_type(struct_tag_typet(synthetic_class_name));
324-
325-
size_t field_idx = 0;
326-
for(auto &param : implemented_method_type.parameters())
327-
{
328-
irep_idt param_basename =
329-
field_idx == 0 ? "this" : "param_" + std::to_string(field_idx);
330-
param.set_base_name(param_basename);
331-
param.set_identifier(
332-
id2string(implemented_method_name) +
333-
"::" + id2string(param_basename));
334-
335-
++field_idx;
336-
}
337-
338-
set_declaring_class(implemented_method_symbol, synthetic_class_name);
339-
return implemented_method_symbol;
340-
}());
340+
symbol_table.add(create_implemented_method_symbol(
341+
synthetic_methods,
342+
ns.lookup(*interface_method_id),
343+
implemented_interface_tag,
344+
synthetic_class_name));
341345

342346
// Register class symbol:
343347

0 commit comments

Comments
 (0)