@@ -540,6 +540,43 @@ void goto_convertt::do_cpp_new(
540540 dest.destructive_append (tmp_initializer);
541541}
542542
543+ void goto_convertt::do_java_new (
544+ const exprt &lhs,
545+ const side_effect_exprt &rhs,
546+ goto_programt &dest)
547+ {
548+ PRECONDITION (!lhs.is_nil ());
549+ PRECONDITION (rhs.operands ().empty ());
550+ PRECONDITION (rhs.type ().id () == ID_pointer);
551+ source_locationt location=rhs.source_location ();
552+ typet object_type=rhs.type ().subtype ();
553+
554+ // build size expression
555+ exprt object_size=size_of_expr (object_type, ns);
556+ CHECK_RETURN (object_size.is_not_nil ());
557+
558+ // we produce a malloc side-effect, which stays
559+ side_effect_exprt malloc_expr (ID_allocate);
560+ malloc_expr.copy_to_operands (object_size);
561+ // could use true and get rid of the code below
562+ malloc_expr.copy_to_operands (false_exprt ());
563+ malloc_expr.type ()=rhs.type ();
564+
565+ goto_programt::targett t_n=dest.add_instruction (ASSIGN);
566+ t_n->code =code_assignt (lhs, malloc_expr);
567+ t_n->source_location =location;
568+
569+ // zero-initialize the object
570+ dereference_exprt deref (lhs, object_type);
571+ exprt zero_object=
572+ zero_initializer (object_type, location, ns, get_message_handler ());
573+ set_class_identifier (
574+ to_struct_expr (zero_object), ns, to_symbol_type (object_type));
575+ goto_programt::targett t_i=dest.add_instruction (ASSIGN);
576+ t_i->code =code_assignt (deref, zero_object);
577+ t_i->source_location =location;
578+ }
579+
543580void goto_convertt::do_java_new_array (
544581 const exprt &lhs,
545582 const side_effect_exprt &rhs,
0 commit comments