Skip to content

Commit 201c3b5

Browse files
author
Daniel Kroening
committed
remove_instanceof now takes function identifier
1 parent 75eda5a commit 201c3b5

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
@@ -33,10 +33,14 @@ class remove_instanceoft
3333
}
3434

3535
// Lower instanceof for a single function
36-
bool lower_instanceof(goto_programt &);
36+
bool lower_instanceof(
37+
const irep_idt &function_identifier,
38+
goto_programt &);
3739

3840
// Lower instanceof for a single instruction
39-
bool lower_instanceof(goto_programt &, goto_programt::targett);
41+
bool lower_instanceof(
42+
const irep_idt &function_identifier,
43+
goto_programt &, goto_programt::targett);
4044

4145
protected:
4246
symbol_table_baset &symbol_table;
@@ -45,6 +49,7 @@ class remove_instanceoft
4549
message_handlert &message_handler;
4650

4751
bool lower_instanceof(
52+
const irep_idt &function_identifier,
4853
exprt &, goto_programt &, goto_programt::targett);
4954
};
5055

@@ -56,6 +61,7 @@ class remove_instanceoft
5661
/// \param this_inst: instruction the expression is found at
5762
/// \return true if any instanceof instructionw was replaced
5863
bool remove_instanceoft::lower_instanceof(
64+
const irep_idt &function_identifier,
5965
exprt &expr,
6066
goto_programt &goto_program,
6167
goto_programt::targett this_inst)
@@ -64,7 +70,7 @@ bool remove_instanceoft::lower_instanceof(
6470
{
6571
bool changed = false;
6672
Forall_operands(it, expr)
67-
changed |= lower_instanceof(*it, goto_program, this_inst);
73+
changed |= lower_instanceof(function_identifier, *it, goto_program, this_inst);
6874
return changed;
6975
}
7076

@@ -107,15 +113,15 @@ bool remove_instanceoft::lower_instanceof(
107113

108114
symbolt &clsid_tmp_sym = get_fresh_aux_symbol(
109115
object_clsid.type(),
110-
id2string(this_inst->function),
116+
id2string(function_identifier),
111117
"class_identifier_tmp",
112118
source_locationt(),
113119
ID_java,
114120
symbol_table);
115121

116122
symbolt &instanceof_result_sym = get_fresh_aux_symbol(
117123
bool_typet(),
118-
id2string(this_inst->function),
124+
id2string(function_identifier),
119125
"instanceof_result_tmp",
120126
source_locationt(),
121127
ID_java,
@@ -193,6 +199,7 @@ static bool contains_instanceof(const exprt &e)
193199
/// \param target: instruction to check for instanceof expressions
194200
/// \return true if an instanceof has been replaced
195201
bool remove_instanceoft::lower_instanceof(
202+
const irep_idt &function_identifier,
196203
goto_programt &goto_program,
197204
goto_programt::targett target)
198205
{
@@ -208,24 +215,26 @@ bool remove_instanceoft::lower_instanceof(
208215
++target;
209216
}
210217

211-
return lower_instanceof(target->code, goto_program, target) |
212-
lower_instanceof(target->guard, goto_program, target);
218+
return lower_instanceof(function_identifier, target->code, goto_program, target) |
219+
lower_instanceof(function_identifier, target->guard, goto_program, target);
213220
}
214221

215222
/// Replace every instanceof in the passed function body with an explicit
216223
/// class-identifier test.
217224
/// Extra auxiliary variables may be introduced into symbol_table.
218225
/// \param goto_program: The function body to work on.
219226
/// \return true if one or more instanceof expressions have been replaced
220-
bool remove_instanceoft::lower_instanceof(goto_programt &goto_program)
227+
bool remove_instanceoft::lower_instanceof(
228+
const irep_idt &function_identifier,
229+
goto_programt &goto_program)
221230
{
222231
bool changed=false;
223232
for(goto_programt::instructionst::iterator target=
224233
goto_program.instructions.begin();
225234
target!=goto_program.instructions.end();
226235
++target)
227236
{
228-
changed=lower_instanceof(goto_program, target) || changed;
237+
changed=lower_instanceof(function_identifier, goto_program, target) || changed;
229238
}
230239
if(!changed)
231240
return false;
@@ -242,13 +251,14 @@ bool remove_instanceoft::lower_instanceof(goto_programt &goto_program)
242251
/// \param symbol_table: The symbol table to add symbols to.
243252
/// \param message_handler: logging output
244253
void remove_instanceof(
254+
const irep_idt &function_identifier,
245255
goto_programt::targett target,
246256
goto_programt &goto_program,
247257
symbol_table_baset &symbol_table,
248258
message_handlert &message_handler)
249259
{
250260
remove_instanceoft rem(symbol_table, message_handler);
251-
rem.lower_instanceof(goto_program, target);
261+
rem.lower_instanceof(function_identifier, goto_program, target);
252262
}
253263

254264
/// Replace every instanceof in the passed function with an explicit
@@ -258,12 +268,13 @@ void remove_instanceof(
258268
/// \param symbol_table: The symbol table to add symbols to.
259269
/// \param message_handler: logging output
260270
void remove_instanceof(
271+
const irep_idt &function_identifier,
261272
goto_functionst::goto_functiont &function,
262273
symbol_table_baset &symbol_table,
263274
message_handlert &message_handler)
264275
{
265276
remove_instanceoft rem(symbol_table, message_handler);
266-
rem.lower_instanceof(function.body);
277+
rem.lower_instanceof(function_identifier, function.body);
267278
}
268279

269280
/// Replace every instanceof in every function with an explicit
@@ -280,7 +291,7 @@ void remove_instanceof(
280291
remove_instanceoft rem(symbol_table, message_handler);
281292
bool changed=false;
282293
for(auto &f : goto_functions.function_map)
283-
changed=rem.lower_instanceof(f.second.body) || changed;
294+
changed=rem.lower_instanceof(f.first, f.second.body) || changed;
284295
if(changed)
285296
goto_functions.compute_location_numbers();
286297
}

jbmc/src/java_bytecode/remove_instanceof.h

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

8888
void remove_instanceof(
89+
const irep_idt &function_identifier,
8990
goto_programt::targett target,
9091
goto_programt &goto_program,
9192
symbol_table_baset &symbol_table,
9293
message_handlert &);
9394

9495
void remove_instanceof(
96+
const irep_idt &function_identifier,
9597
goto_functionst::goto_functiont &function,
9698
symbol_table_baset &symbol_table,
9799
message_handlert &);

0 commit comments

Comments
 (0)