Skip to content

Commit 4af678a

Browse files
author
Daniel Kroening
committed
remove_instanceof now takes function identifier
1 parent ea77ca5 commit 4af678a

File tree

2 files changed

+25
-12
lines changed

2 files changed

+25
-12
lines changed

jbmc/src/java_bytecode/remove_instanceof.cpp

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,14 @@ class remove_instanceoft
3535
}
3636

3737
// Lower instanceof for a single function
38-
bool lower_instanceof(goto_programt &);
38+
bool lower_instanceof(
39+
const irep_idt &function_identifier,
40+
goto_programt &);
3941

4042
// Lower instanceof for a single instruction
41-
bool lower_instanceof(goto_programt &, goto_programt::targett);
43+
bool lower_instanceof(
44+
const irep_idt &function_identifier,
45+
goto_programt &, goto_programt::targett);
4246

4347
protected:
4448
symbol_table_baset &symbol_table;
@@ -47,6 +51,7 @@ class remove_instanceoft
4751
message_handlert &message_handler;
4852

4953
bool lower_instanceof(
54+
const irep_idt &function_identifier,
5055
exprt &, goto_programt &, goto_programt::targett);
5156
};
5257

@@ -58,6 +63,7 @@ class remove_instanceoft
5863
/// \param this_inst: instruction the expression is found at
5964
/// \return true if any instanceof instructionw was replaced
6065
bool remove_instanceoft::lower_instanceof(
66+
const irep_idt &function_identifier,
6167
exprt &expr,
6268
goto_programt &goto_program,
6369
goto_programt::targett this_inst)
@@ -66,7 +72,7 @@ bool remove_instanceoft::lower_instanceof(
6672
{
6773
bool changed = false;
6874
Forall_operands(it, expr)
69-
changed |= lower_instanceof(*it, goto_program, this_inst);
75+
changed |= lower_instanceof(function_identifier, *it, goto_program, this_inst);
7076
return changed;
7177
}
7278

@@ -109,15 +115,15 @@ bool remove_instanceoft::lower_instanceof(
109115

110116
symbolt &clsid_tmp_sym = get_fresh_aux_symbol(
111117
object_clsid.type(),
112-
id2string(this_inst->function),
118+
id2string(function_identifier),
113119
"class_identifier_tmp",
114120
source_locationt(),
115121
ID_java,
116122
symbol_table);
117123

118124
symbolt &instanceof_result_sym = get_fresh_aux_symbol(
119125
bool_typet(),
120-
id2string(this_inst->function),
126+
id2string(function_identifier),
121127
"instanceof_result_tmp",
122128
source_locationt(),
123129
ID_java,
@@ -195,6 +201,7 @@ static bool contains_instanceof(const exprt &e)
195201
/// \param target: instruction to check for instanceof expressions
196202
/// \return true if an instanceof has been replaced
197203
bool remove_instanceoft::lower_instanceof(
204+
const irep_idt &function_identifier,
198205
goto_programt &goto_program,
199206
goto_programt::targett target)
200207
{
@@ -210,24 +217,26 @@ bool remove_instanceoft::lower_instanceof(
210217
++target;
211218
}
212219

213-
return lower_instanceof(target->code, goto_program, target) |
214-
lower_instanceof(target->guard, goto_program, target);
220+
return lower_instanceof(function_identifier, target->code, goto_program, target) |
221+
lower_instanceof(function_identifier, target->guard, goto_program, target);
215222
}
216223

217224
/// Replace every instanceof in the passed function body with an explicit
218225
/// class-identifier test.
219226
/// Extra auxiliary variables may be introduced into symbol_table.
220227
/// \param goto_program: The function body to work on.
221228
/// \return true if one or more instanceof expressions have been replaced
222-
bool remove_instanceoft::lower_instanceof(goto_programt &goto_program)
229+
bool remove_instanceoft::lower_instanceof(
230+
const irep_idt &function_identifier,
231+
goto_programt &goto_program)
223232
{
224233
bool changed=false;
225234
for(goto_programt::instructionst::iterator target=
226235
goto_program.instructions.begin();
227236
target!=goto_program.instructions.end();
228237
++target)
229238
{
230-
changed=lower_instanceof(goto_program, target) || changed;
239+
changed=lower_instanceof(function_identifier, goto_program, target) || changed;
231240
}
232241
if(!changed)
233242
return false;
@@ -244,14 +253,15 @@ bool remove_instanceoft::lower_instanceof(goto_programt &goto_program)
244253
/// \param class_hierarchy: class hierarchy analysis of symbol_table
245254
/// \param message_handler: logging output
246255
void remove_instanceof(
256+
const irep_idt &function_identifier,
247257
goto_programt::targett target,
248258
goto_programt &goto_program,
249259
symbol_table_baset &symbol_table,
250260
const class_hierarchyt &class_hierarchy,
251261
message_handlert &message_handler)
252262
{
253263
remove_instanceoft rem(symbol_table, class_hierarchy, message_handler);
254-
rem.lower_instanceof(goto_program, target);
264+
rem.lower_instanceof(function_identifier, goto_program, target);
255265
}
256266

257267
/// Replace every instanceof in the passed function with an explicit
@@ -262,13 +272,14 @@ void remove_instanceof(
262272
/// \param class_hierarchy: class hierarchy analysis of symbol_table
263273
/// \param message_handler: logging output
264274
void remove_instanceof(
275+
const irep_idt &function_identifier,
265276
goto_functionst::goto_functiont &function,
266277
symbol_table_baset &symbol_table,
267278
const class_hierarchyt &class_hierarchy,
268279
message_handlert &message_handler)
269280
{
270281
remove_instanceoft rem(symbol_table, class_hierarchy, message_handler);
271-
rem.lower_instanceof(function.body);
282+
rem.lower_instanceof(function_identifier, function.body);
272283
}
273284

274285
/// Replace every instanceof in every function with an explicit
@@ -287,7 +298,7 @@ void remove_instanceof(
287298
remove_instanceoft rem(symbol_table, class_hierarchy, message_handler);
288299
bool changed=false;
289300
for(auto &f : goto_functions.function_map)
290-
changed=rem.lower_instanceof(f.second.body) || changed;
301+
changed=rem.lower_instanceof(f.first, f.second.body) || changed;
291302
if(changed)
292303
goto_functions.compute_location_numbers();
293304
}

jbmc/src/java_bytecode/remove_instanceof.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,13 +87,15 @@ Author: Chris Smowton, [email protected]
8787
#include <util/symbol_table.h>
8888

8989
void remove_instanceof(
90+
const irep_idt &function_identifier,
9091
goto_programt::targett target,
9192
goto_programt &goto_program,
9293
symbol_table_baset &symbol_table,
9394
const class_hierarchyt &class_hierarchy,
9495
message_handlert &);
9596

9697
void remove_instanceof(
98+
const irep_idt &function_identifier,
9799
goto_functionst::goto_functiont &function,
98100
symbol_table_baset &symbol_table,
99101
const class_hierarchyt &class_hierarchy,

0 commit comments

Comments
 (0)