Skip to content

Commit f777e29

Browse files
author
Owen Jones
committed
Refactor java code
Following the review of the equivalent C code, these changes were made: set replaced with unordered set; helper functions declared static and not exported in header; zero_initializer() replaced with from_integer() and all uses of message_handlert removed;
1 parent 2194b31 commit f777e29

File tree

3 files changed

+58
-89
lines changed

3 files changed

+58
-89
lines changed

src/java_bytecode/java_entry_point.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,7 @@ bool java_static_lifetime_init(
142142
allow_null,
143143
symbol_table,
144144
max_nondet_array_length,
145-
source_location,
146-
message_handler);
145+
source_location);
147146
code_assignt assignment(sym.symbol_expr(), newsym);
148147
code_block.add(assignment);
149148
}
@@ -234,8 +233,7 @@ exprt::operandst java_build_arguments(
234233
allow_null,
235234
symbol_table,
236235
max_nondet_array_length,
237-
function.location,
238-
message_handler);
236+
function.location);
239237

240238
const symbolt &p_symbol=
241239
symbol_table.lookup(parameters[param_number].get_identifier());

src/java_bytecode/java_object_factory.cpp

Lines changed: 55 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,14 @@ Author: Daniel Kroening, [email protected]
66
77
\*******************************************************************/
88

9-
#include <set>
9+
#include <unordered_set>
1010
#include <sstream>
1111

1212
#include <util/arith_tools.h>
1313
#include <util/fresh_symbol.h>
1414
#include <util/std_types.h>
1515
#include <util/std_code.h>
1616
#include <util/std_expr.h>
17-
#include <util/message.h>
1817
#include <util/namespace.h>
1918
#include <util/pointer_offset_size.h>
2019
#include <util/prefix.h>
@@ -25,28 +24,71 @@ Author: Daniel Kroening, [email protected]
2524
#include "java_types.h"
2625
#include "java_utils.h"
2726

28-
class java_object_factoryt:public messaget
27+
/*******************************************************************\
28+
29+
Function: new_tmp_symbol
30+
31+
Inputs:
32+
33+
Outputs:
34+
35+
Purpose:
36+
37+
\*******************************************************************/
38+
39+
static symbolt &new_tmp_symbol(
40+
symbol_tablet &symbol_table,
41+
const source_locationt &loc,
42+
const typet &type,
43+
const std::string &prefix="tmp_object_factory")
44+
{
45+
return get_fresh_aux_symbol(
46+
type,
47+
"",
48+
prefix,
49+
loc,
50+
ID_java,
51+
symbol_table);
52+
}
53+
54+
/*******************************************************************\
55+
56+
Function: get_nondet_bool
57+
58+
Inputs: Desired type (C_bool or plain bool)
59+
60+
Outputs: nondet expr of that type
61+
62+
Purpose:
63+
64+
\*******************************************************************/
65+
66+
static exprt get_nondet_bool(const typet &type)
67+
{
68+
// We force this to 0 and 1 and won't consider
69+
// other values.
70+
return typecast_exprt(side_effect_expr_nondett(bool_typet()), type);
71+
}
72+
73+
class java_object_factoryt
2974
{
3075
code_blockt &init_code;
31-
std::set<irep_idt> recursion_set;
76+
std::unordered_set<irep_idt, irep_id_hash> recursion_set;
3277
bool assume_non_null;
3378
size_t max_nondet_array_length;
3479
symbol_tablet &symbol_table;
35-
message_handlert &message_handler;
3680
namespacet ns;
3781

3882
public:
3983
java_object_factoryt(
4084
code_blockt &_init_code,
4185
bool _assume_non_null,
4286
size_t _max_nondet_array_length,
43-
symbol_tablet &_symbol_table,
44-
message_handlert &_message_handler):
87+
symbol_tablet &_symbol_table):
4588
init_code(_init_code),
4689
assume_non_null(_assume_non_null),
4790
max_nondet_array_length(_max_nondet_array_length),
4891
symbol_table(_symbol_table),
49-
message_handler(_message_handler),
5092
ns(_symbol_table)
5193
{}
5294

@@ -209,37 +251,23 @@ void java_object_factoryt::gen_nondet_init(
209251
code_labelt set_null_label;
210252
code_labelt init_done_label;
211253

212-
static size_t synthetic_constructor_count=0;
213-
214254
if(!assume_non_null)
215255
{
216-
auto returns_null_sym=
217-
new_tmp_symbol(
218-
symbol_table,
219-
loc,
220-
c_bool_typet(1),
221-
"opaque_returns_null");
222-
auto returns_null=returns_null_sym.symbol_expr();
223-
auto assign_returns_null=
224-
code_assignt(returns_null, get_nondet_bool(returns_null_sym.type));
225-
assign_returns_null.add_source_location()=loc;
226-
init_code.move_to_operands(assign_returns_null);
227-
228256
auto set_null_inst=
229257
code_assignt(expr, null_pointer_exprt(pointer_type));
230258
set_null_inst.add_source_location()=loc;
231259

260+
static size_t synthetic_constructor_count=0;
232261
std::string fresh_label=
233262
"post_synthetic_malloc_"+std::to_string(++synthetic_constructor_count);
234263
set_null_label=code_labelt(fresh_label, set_null_inst);
235264

236265
init_done_label=code_labelt(fresh_label+"_init_done", code_skipt());
237266

238267
code_ifthenelset null_check;
239-
exprt null_return=
240-
zero_initializer(returns_null_sym.type, loc, ns, message_handler);
268+
exprt null_return=from_integer(0, c_bool_typet(1));
241269
null_check.cond()=
242-
notequal_exprt(returns_null, null_return);
270+
notequal_exprt(get_nondet_bool(c_bool_typet(1)), null_return);
243271
null_check.then_case()=code_gotot(fresh_label);
244272
init_code.move_to_operands(null_check);
245273
}
@@ -471,52 +499,6 @@ void java_object_factoryt::gen_nondet_array_init(
471499

472500
/*******************************************************************\
473501
474-
Function: new_tmp_symbol
475-
476-
Inputs:
477-
478-
Outputs:
479-
480-
Purpose:
481-
482-
\*******************************************************************/
483-
484-
symbolt &new_tmp_symbol(
485-
symbol_tablet &symbol_table,
486-
const source_locationt &loc,
487-
const typet &type,
488-
const std::string &prefix)
489-
{
490-
return get_fresh_aux_symbol(
491-
type,
492-
"",
493-
prefix,
494-
loc,
495-
ID_java,
496-
symbol_table);
497-
}
498-
499-
/*******************************************************************\
500-
501-
Function: get_nondet_bool
502-
503-
Inputs: Desired type (C_bool or plain bool)
504-
505-
Outputs: nondet expr of that type
506-
507-
Purpose:
508-
509-
\*******************************************************************/
510-
511-
exprt get_nondet_bool(const typet &type)
512-
{
513-
// We force this to 0 and 1 and won't consider
514-
// other values.
515-
return typecast_exprt(side_effect_expr_nondett(bool_typet()), type);
516-
}
517-
518-
/*******************************************************************\
519-
520502
Function: object_factory
521503
522504
Inputs:
@@ -533,8 +515,7 @@ exprt object_factory(
533515
bool allow_null,
534516
symbol_tablet &symbol_table,
535517
size_t max_nondet_array_length,
536-
const source_locationt &loc,
537-
message_handlert &message_handler)
518+
const source_locationt &loc)
538519
{
539520
if(type.id()==ID_pointer)
540521
{
@@ -550,8 +531,7 @@ exprt object_factory(
550531
init_code,
551532
!allow_null,
552533
max_nondet_array_length,
553-
symbol_table,
554-
message_handler);
534+
symbol_table);
555535
state.gen_nondet_init(
556536
object,
557537
false,

src/java_bytecode/java_object_factory.h

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,6 @@ exprt object_factory(
1919
bool allow_null,
2020
symbol_tablet &symbol_table,
2121
size_t max_nondet_array_length,
22-
const source_locationt &,
23-
message_handlert &message_handler);
24-
25-
exprt get_nondet_bool(const typet &);
26-
27-
symbolt &new_tmp_symbol(
28-
symbol_tablet &symbol_table,
29-
const source_locationt &,
30-
const typet &,
31-
const std::string &prefix="tmp_object_factory");
22+
const source_locationt &);
3223

3324
#endif // CPROVER_JAVA_BYTECODE_JAVA_OBJECT_FACTORY_H

0 commit comments

Comments
 (0)