@@ -118,6 +118,14 @@ class java_object_factoryt
118118 const irep_idt &class_identifier,
119119 bool create_dynamic_objects,
120120 const pointer_typet &pointer_type);
121+
122+ void gen_nondet_struct_init (
123+ code_blockt &assignments,
124+ const exprt &expr,
125+ bool is_sub,
126+ irep_idt class_identifier,
127+ bool create_dynamic_objects,
128+ const struct_typet &struct_type);
121129};
122130
123131// / \param assignments: The code block to add code to
@@ -326,6 +334,77 @@ void java_object_factoryt::gen_nondet_pointer_init(
326334 }
327335}
328336
337+ // / Initialises an object tree rooted at `expr`, allocating child objects as
338+ // / necessary and nondet-initialising their members.
339+ // / \param assignments: The code block to append the new
340+ // / instructions to
341+ // / \param expr: pointer-typed lvalue expression to initialise
342+ // / \param is_sub: If true, `expr` is a substructure of a larger object, which
343+ // / in Java necessarily means a base class. not match *expr (for example, expr
344+ // / might be void*)
345+ // / \param class_identifier: clsid to initialise @java.lang.Object.
346+ // / @class_identifier
347+ // / \param create_dynamic_objects: if true, use malloc to allocate objects;
348+ // / otherwise generate fresh static symbols.
349+ // / \param struct_type - The type of the struct we are initalising
350+ void java_object_factoryt::gen_nondet_struct_init (
351+ code_blockt &assignments,
352+ const exprt &expr,
353+ bool is_sub,
354+ irep_idt class_identifier,
355+ bool create_dynamic_objects,
356+ const struct_typet &struct_type)
357+ {
358+ typedef struct_typet::componentst componentst;
359+
360+ const irep_idt struct_tag=struct_type.get_tag ();
361+
362+ const componentst &components=struct_type.components ();
363+
364+ if (!is_sub)
365+ class_identifier=struct_tag;
366+
367+ recursion_set.insert (struct_tag);
368+ assert (!recursion_set.empty ());
369+
370+ for (const auto &component : components)
371+ {
372+ const typet &component_type=component.type ();
373+ irep_idt name=component.get_name ();
374+
375+ member_exprt me (expr, name, component_type);
376+
377+ if (name==" @class_identifier" )
378+ {
379+ irep_idt qualified_clsid=" java::" +as_string (class_identifier);
380+ constant_exprt ci (qualified_clsid, string_typet ());
381+ code_assignt code (me, ci);
382+ code.add_source_location ()=loc;
383+ assignments.copy_to_operands (code);
384+ }
385+ else if (name==" @lock" )
386+ {
387+ code_assignt code (me, from_integer (0 , me.type ()));
388+ code.add_source_location ()=loc;
389+ assignments.copy_to_operands (code);
390+ }
391+ else
392+ {
393+ assert (!name.empty ());
394+
395+ bool _is_sub=name[0 ]==' @' ;
396+
397+ gen_nondet_init (
398+ assignments,
399+ me,
400+ _is_sub,
401+ class_identifier,
402+ create_dynamic_objects);
403+ }
404+ }
405+ recursion_set.erase (struct_tag);
406+ }
407+
329408// / Creates a nondet for expr, including calling itself recursively to make
330409// / appropriate symbols to point to if expr is a pointer or struct
331410// / \param expr: The expression which we are generating a non-determinate value
@@ -362,59 +441,14 @@ void java_object_factoryt::gen_nondet_init(
362441 }
363442 else if (type.id ()==ID_struct)
364443 {
365- typedef struct_typet::componentst componentst;
366-
367444 const struct_typet &struct_type=to_struct_type (type);
368- const irep_idt struct_tag=struct_type.get_tag ();
369-
370- const componentst &components=struct_type.components ();
371-
372- if (!is_sub)
373- class_identifier=struct_tag;
374-
375- recursion_set.insert (struct_tag);
376- assert (!recursion_set.empty ());
377-
378- for (const auto &component : components)
379- {
380- const typet &component_type=component.type ();
381- irep_idt name=component.get_name ();
382-
383- member_exprt me (expr, name, component_type);
384-
385- if (name==" @class_identifier" )
386- {
387- irep_idt qualified_clsid=" java::" +as_string (class_identifier);
388- constant_exprt ci (qualified_clsid, string_typet ());
389- code_assignt code (me, ci);
390- code.add_source_location ()=loc;
391- assignments.copy_to_operands (code);
392- }
393- else if (name==" @lock" )
394- {
395- code_assignt code (me, from_integer (0 , me.type ()));
396- code.add_source_location ()=loc;
397- assignments.copy_to_operands (code);
398- }
399- else
400- {
401- assert (!name.empty ());
402-
403- bool _is_sub=name[0 ]==' @' ;
404- #if 0
405- irep_idt _class_identifier=
406- _is_sub?(class_identifier.empty()?struct_tag:class_identifier):"";
407- #endif
408-
409- gen_nondet_init (
410- assignments,
411- me,
412- _is_sub,
413- class_identifier,
414- create_dynamic_objects);
415- }
416- }
417- recursion_set.erase (struct_tag);
445+ gen_nondet_struct_init (
446+ assignments,
447+ expr,
448+ is_sub,
449+ class_identifier,
450+ create_dynamic_objects,
451+ struct_type);
418452 }
419453 else
420454 {
0 commit comments