Skip to content

Commit cf17239

Browse files
author
Daniel Kroening
authored
Merge pull request #693 from owen-jones-diffblue/cleanup/java-object-factory
Cleanup/java object factory
2 parents 4ea27a3 + 9a1dae0 commit cf17239

File tree

2 files changed

+48
-105
lines changed

2 files changed

+48
-105
lines changed

src/java_bytecode/java_object_factory.cpp

+48-93
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,6 @@ Author: Daniel Kroening, [email protected]
2525
#include "java_types.h"
2626
#include "java_utils.h"
2727

28-
/*******************************************************************\
29-
30-
Function: gen_nondet_init
31-
32-
Inputs:
33-
34-
Outputs:
35-
36-
Purpose:
37-
38-
\*******************************************************************/
39-
4028
class java_object_factoryt:public messaget
4129
{
4230
code_blockt &init_code;
@@ -75,25 +63,20 @@ class java_object_factoryt:public messaget
7563
bool is_sub,
7664
irep_idt class_identifier,
7765
const source_locationt &loc,
78-
bool skip_classid,
7966
bool create_dynamic_objects,
8067
bool override=false,
8168
const typet &override_type=empty_typet());
8269
};
8370

84-
8571
/*******************************************************************\
8672
87-
Function: gen_nondet_array_init
73+
Function: java_object_factoryt::allocate_object
8874
89-
Inputs: the target expression, desired object type, source location
90-
and Boolean whether to create a dynamic object
75+
Inputs:
9176
92-
Outputs: the allocated object
77+
Outputs:
9378
94-
Purpose: Returns false if we can't figure out the size of allocate_type.
95-
allocate_type may differ from target_expr, e.g. for target_expr
96-
having type int* and allocate_type being an int[10].
79+
Purpose:
9780
9881
\*******************************************************************/
9982

@@ -165,16 +148,33 @@ exprt java_object_factoryt::allocate_object(
165148
}
166149
}
167150

168-
// Override type says to ignore the LHS' real type, and init it with the given
169-
// type regardless. Used at the moment for reference arrays, which are
170-
// implemented as void* arrays but should be init'd as their true type with
171-
// appropriate casts.
151+
/*******************************************************************\
152+
153+
Function: java_object_factoryt::gen_nondet_init
154+
155+
Inputs:
156+
expr -
157+
is_sub -
158+
class_identifier -
159+
loc -
160+
create_dynamic_objects -
161+
override - Ignore the LHS' real type. Used at the moment for
162+
reference arrays, which are implemented as void*
163+
arrays but should be init'd as their true type with
164+
appropriate casts.
165+
override_type - Type to use if ignoring the LHS' real type
166+
167+
Outputs:
168+
169+
Purpose:
170+
171+
\*******************************************************************/
172+
172173
void java_object_factoryt::gen_nondet_init(
173174
const exprt &expr,
174175
bool is_sub,
175176
irep_idt class_identifier,
176177
const source_locationt &loc,
177-
bool skip_classid,
178178
bool create_dynamic_objects,
179179
bool override,
180180
const typet &override_type)
@@ -250,20 +250,17 @@ void java_object_factoryt::gen_nondet_init(
250250
{
251251
exprt allocated=
252252
allocate_object(expr, subtype, loc, create_dynamic_objects);
253-
{
254-
exprt init_expr;
255-
if(allocated.id()==ID_address_of)
256-
init_expr=allocated.op0();
257-
else
258-
init_expr=dereference_exprt(allocated, allocated.type().subtype());
259-
gen_nondet_init(
260-
init_expr,
261-
false,
262-
"",
263-
loc,
264-
false,
265-
create_dynamic_objects);
266-
}
253+
exprt init_expr;
254+
if(allocated.id()==ID_address_of)
255+
init_expr=allocated.op0();
256+
else
257+
init_expr=dereference_exprt(allocated, allocated.type().subtype());
258+
gen_nondet_init(
259+
init_expr,
260+
false,
261+
"",
262+
loc,
263+
create_dynamic_objects);
267264
}
268265

269266
if(!assume_non_null)
@@ -297,9 +294,6 @@ void java_object_factoryt::gen_nondet_init(
297294

298295
if(name=="@class_identifier")
299296
{
300-
if(skip_classid)
301-
continue;
302-
303297
irep_idt qualified_clsid="java::"+as_string(class_identifier);
304298
constant_exprt ci(qualified_clsid, string_typet());
305299
code_assignt code(me, ci);
@@ -327,7 +321,6 @@ void java_object_factoryt::gen_nondet_init(
327321
_is_sub,
328322
class_identifier,
329323
loc,
330-
false,
331324
create_dynamic_objects);
332325
}
333326
}
@@ -345,7 +338,7 @@ void java_object_factoryt::gen_nondet_init(
345338

346339
/*******************************************************************\
347340
348-
Function: gen_nondet_array_init
341+
Function: java_object_factoryt::gen_nondet_array_init
349342
350343
Inputs:
351344
@@ -379,7 +372,7 @@ void java_object_factoryt::gen_nondet_array_init(
379372
const auto &length_sym_expr=length_sym.symbol_expr();
380373

381374
// Initialize array with some undetermined length:
382-
gen_nondet_init(length_sym_expr, false, irep_idt(), loc, false, false);
375+
gen_nondet_init(length_sym_expr, false, irep_idt(), loc, false);
383376

384377
// Insert assumptions to bound its length:
385378
binary_relation_exprt
@@ -464,7 +457,6 @@ void java_object_factoryt::gen_nondet_array_init(
464457
false,
465458
irep_idt(),
466459
loc,
467-
false,
468460
true,
469461
true,
470462
element_type);
@@ -479,44 +471,6 @@ void java_object_factoryt::gen_nondet_array_init(
479471

480472
/*******************************************************************\
481473
482-
Function: gen_nondet_init
483-
484-
Inputs:
485-
486-
Outputs:
487-
488-
Purpose:
489-
490-
\*******************************************************************/
491-
492-
void gen_nondet_init(
493-
const exprt &expr,
494-
code_blockt &init_code,
495-
symbol_tablet &symbol_table,
496-
const source_locationt &loc,
497-
bool skip_classid,
498-
bool create_dyn_objs,
499-
bool assume_non_null,
500-
message_handlert &message_handler,
501-
size_t max_nondet_array_length)
502-
{
503-
java_object_factoryt state(
504-
init_code,
505-
assume_non_null,
506-
max_nondet_array_length,
507-
symbol_table,
508-
message_handler);
509-
state.gen_nondet_init(
510-
expr,
511-
false,
512-
"",
513-
loc,
514-
skip_classid,
515-
create_dyn_objs);
516-
}
517-
518-
/*******************************************************************\
519-
520474
Function: new_tmp_symbol
521475
522476
Inputs:
@@ -592,17 +546,18 @@ exprt object_factory(
592546

593547
exprt object=aux_symbol.symbol_expr();
594548

595-
const namespacet ns(symbol_table);
596-
gen_nondet_init(
597-
object,
549+
java_object_factoryt state(
598550
init_code,
551+
!allow_null,
552+
max_nondet_array_length,
599553
symbol_table,
600-
loc,
601-
false,
554+
message_handler);
555+
state.gen_nondet_init(
556+
object,
602557
false,
603-
!allow_null,
604-
message_handler,
605-
max_nondet_array_length);
558+
"",
559+
loc,
560+
false);
606561

607562
return object;
608563
}

src/java_bytecode/java_object_factory.h

-12
Original file line numberDiff line numberDiff line change
@@ -22,18 +22,6 @@ exprt object_factory(
2222
const source_locationt &,
2323
message_handlert &message_handler);
2424

25-
void gen_nondet_init(
26-
const exprt &expr,
27-
code_blockt &init_code,
28-
symbol_tablet &symbol_table,
29-
const source_locationt &,
30-
bool skip_classid,
31-
bool create_dynamic_objects,
32-
bool assume_non_null,
33-
message_handlert &message_handler,
34-
size_t max_nondet_array_length=5);
35-
36-
3725
exprt get_nondet_bool(const typet &);
3826

3927
symbolt &new_tmp_symbol(

0 commit comments

Comments
 (0)