Skip to content

Commit 5513f6b

Browse files
Daniel Kroeningtautschnig
Daniel Kroening
authored andcommitted
remove_java_new now takes function identifier
We are working towards removing the "function" field from goto_programt::instructionst::instructiont, and thus need to pass the identifier of the function whenever it actually is required.
1 parent dcbda65 commit 5513f6b

File tree

3 files changed

+34
-15
lines changed

3 files changed

+34
-15
lines changed

jbmc/src/java_bytecode/remove_java_new.cpp

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -33,23 +33,27 @@ class remove_java_newt : public messaget
3333
}
3434

3535
// Lower java_new for a single function
36-
bool lower_java_new(goto_programt &);
36+
bool lower_java_new(const irep_idt &function_identifier, goto_programt &);
3737

3838
// Lower java_new for a single instruction
39-
goto_programt::targett
40-
lower_java_new(goto_programt &, goto_programt::targett);
39+
goto_programt::targett lower_java_new(
40+
const irep_idt &function_identifier,
41+
goto_programt &,
42+
goto_programt::targett);
4143

4244
protected:
4345
symbol_table_baset &symbol_table;
4446
namespacet ns;
4547

4648
goto_programt::targett lower_java_new(
49+
const irep_idt &function_identifier,
4750
exprt lhs,
4851
side_effect_exprt rhs,
4952
goto_programt &,
5053
goto_programt::targett);
5154

5255
goto_programt::targett lower_java_new_array(
56+
const irep_idt &function_identifier,
5357
exprt lhs,
5458
side_effect_exprt rhs,
5559
goto_programt &,
@@ -68,6 +72,7 @@ class remove_java_newt : public messaget
6872
/// Note: we have to take a copy of `lhs` and `rhs` since they would suffer
6973
/// destruction when replacing the instruction.
7074
goto_programt::targett remove_java_newt::lower_java_new(
75+
const irep_idt &function_identifier,
7176
exprt lhs,
7277
side_effect_exprt rhs,
7378
goto_programt &dest,
@@ -116,6 +121,7 @@ goto_programt::targett remove_java_newt::lower_java_new(
116121
/// Note: we have to take a copy of `lhs` and `rhs` since they would suffer
117122
/// destruction when replacing the instruction.
118123
goto_programt::targett remove_java_newt::lower_java_new_array(
124+
const irep_idt &function_identifier,
119125
exprt lhs,
120126
side_effect_exprt rhs,
121127
goto_programt &dest,
@@ -206,7 +212,7 @@ goto_programt::targett remove_java_newt::lower_java_new_array(
206212
// `x=typecast_exprt(side_effect_exprt(...))`
207213
symbol_exprt new_array_data_symbol = get_fresh_aux_symbol(
208214
data_java_new_expr.type(),
209-
id2string(target->function),
215+
id2string(function_identifier),
210216
"tmp_new_data_array",
211217
location,
212218
ID_java,
@@ -254,7 +260,7 @@ goto_programt::targett remove_java_newt::lower_java_new_array(
254260

255261
symbol_exprt tmp_i = get_fresh_aux_symbol(
256262
length.type(),
257-
id2string(target->function),
263+
id2string(function_identifier),
258264
"tmp_index",
259265
location,
260266
ID_java,
@@ -286,7 +292,7 @@ goto_programt::targett remove_java_newt::lower_java_new_array(
286292
code_blockt for_body;
287293
symbol_exprt init_sym = get_fresh_aux_symbol(
288294
sub_type,
289-
id2string(target->function),
295+
id2string(function_identifier),
290296
"subarray_init",
291297
location,
292298
ID_java,
@@ -311,7 +317,7 @@ goto_programt::targett remove_java_newt::lower_java_new_array(
311317
goto_convert(for_loop, symbol_table, tmp, get_message_handler(), ID_java);
312318

313319
// lower new side effects recursively
314-
lower_java_new(tmp);
320+
lower_java_new(function_identifier, tmp);
315321

316322
dest.destructive_insert(next, tmp);
317323
}
@@ -325,6 +331,7 @@ goto_programt::targett remove_java_newt::lower_java_new_array(
325331
/// \param target: instruction to check for java_new expressions
326332
/// \return true if a replacement has been made
327333
goto_programt::targett remove_java_newt::lower_java_new(
334+
const irep_idt &function_identifier,
328335
goto_programt &goto_program,
329336
goto_programt::targett target)
330337
{
@@ -338,13 +345,14 @@ goto_programt::targett remove_java_newt::lower_java_new(
338345

339346
if(rhs.id() == ID_side_effect && rhs.get(ID_statement) == ID_java_new)
340347
{
341-
return lower_java_new(lhs, to_side_effect_expr(rhs), goto_program, target);
348+
return lower_java_new(
349+
function_identifier, lhs, to_side_effect_expr(rhs), goto_program, target);
342350
}
343351

344352
if(rhs.id() == ID_side_effect && rhs.get(ID_statement) == ID_java_new_array)
345353
{
346354
return lower_java_new_array(
347-
lhs, to_side_effect_expr(rhs), goto_program, target);
355+
function_identifier, lhs, to_side_effect_expr(rhs), goto_program, target);
348356
}
349357

350358
return target;
@@ -355,15 +363,18 @@ goto_programt::targett remove_java_newt::lower_java_new(
355363
/// Extra auxiliary variables may be introduced into symbol_table.
356364
/// \param goto_program: The function body to work on.
357365
/// \return true if one or more java_new expressions have been replaced
358-
bool remove_java_newt::lower_java_new(goto_programt &goto_program)
366+
bool remove_java_newt::lower_java_new(
367+
const irep_idt &function_identifier,
368+
goto_programt &goto_program)
359369
{
360370
bool changed = false;
361371
for(goto_programt::instructionst::iterator target =
362372
goto_program.instructions.begin();
363373
target != goto_program.instructions.end();
364374
++target)
365375
{
366-
goto_programt::targett new_target = lower_java_new(goto_program, target);
376+
goto_programt::targett new_target =
377+
lower_java_new(function_identifier, goto_program, target);
367378
changed = changed || new_target == target;
368379
target = new_target;
369380
}
@@ -381,13 +392,14 @@ bool remove_java_newt::lower_java_new(goto_programt &goto_program)
381392
/// \param symbol_table: The symbol table to add symbols to.
382393
/// \param message_handler: a message handler
383394
void remove_java_new(
395+
const irep_idt &function_identifier,
384396
goto_programt::targett target,
385397
goto_programt &goto_program,
386398
symbol_table_baset &symbol_table,
387399
message_handlert &message_handler)
388400
{
389401
remove_java_newt rem(symbol_table, message_handler);
390-
rem.lower_java_new(goto_program, target);
402+
rem.lower_java_new(function_identifier, goto_program, target);
391403
}
392404

393405
/// Replace every java_new or java_new_array by a malloc side-effect
@@ -397,12 +409,13 @@ void remove_java_new(
397409
/// \param symbol_table: The symbol table to add symbols to.
398410
/// \param message_handler: a message handler
399411
void remove_java_new(
412+
const irep_idt &function_identifier,
400413
goto_functionst::goto_functiont &function,
401414
symbol_table_baset &symbol_table,
402415
message_handlert &message_handler)
403416
{
404417
remove_java_newt rem(symbol_table, message_handler);
405-
rem.lower_java_new(function.body);
418+
rem.lower_java_new(function_identifier, function.body);
406419
}
407420

408421
/// Replace every java_new or java_new_array by a malloc side-effect
@@ -419,7 +432,7 @@ void remove_java_new(
419432
remove_java_newt rem(symbol_table, message_handler);
420433
bool changed = false;
421434
for(auto &f : goto_functions.function_map)
422-
changed = rem.lower_java_new(f.second.body) || changed;
435+
changed = rem.lower_java_new(f.first, f.second.body) || changed;
423436
if(changed)
424437
goto_functions.compute_location_numbers();
425438
}

jbmc/src/java_bytecode/remove_java_new.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,14 @@ Author: Peter Schrammel
2020
class message_handlert;
2121

2222
void remove_java_new(
23+
const irep_idt &function_identifier,
2324
goto_programt::targett target,
2425
goto_programt &goto_program,
2526
symbol_table_baset &symbol_table,
2627
message_handlert &_message_handler);
2728

2829
void remove_java_new(
30+
const irep_idt &function_identifier,
2931
goto_functionst::goto_functiont &function,
3032
symbol_table_baset &symbol_table,
3133
message_handlert &_message_handler);

jbmc/src/jbmc/jbmc_parse_options.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -809,7 +809,11 @@ void jbmc_parse_optionst::process_goto_function(
809809
goto_check(ns, options, ID_java, function.get_goto_function());
810810

811811
// Replace Java new side effects
812-
remove_java_new(goto_function, symbol_table, get_message_handler());
812+
remove_java_new(
813+
function.get_function_id(),
814+
goto_function,
815+
symbol_table,
816+
get_message_handler());
813817

814818
// checks don't know about adjusted float expressions
815819
adjust_float_expressions(goto_function, ns);

0 commit comments

Comments
 (0)