-/* Gimplify a NEW_ARRAY_INIT node into array/element assignments. */
-
-static tree
-java_gimplify_new_array_init (tree exp)
-{
- tree array_type = TREE_TYPE (TREE_TYPE (exp));
- tree data_field = lookup_field (&array_type, get_identifier ("data"));
- tree element_type = TYPE_ARRAY_ELEMENT (array_type);
- HOST_WIDE_INT ilength = java_array_type_length (array_type);
- tree length = build_int_cst (NULL_TREE, ilength);
- tree init = TREE_OPERAND (exp, 0);
- tree values = CONSTRUCTOR_ELTS (init);
-
- tree array_ptr_type = build_pointer_type (array_type);
- tree tmp = create_tmp_var (array_ptr_type, "array");
- tree body = build2 (MODIFY_EXPR, array_ptr_type, tmp,
- build_new_array (element_type, length));
-
- int index = 0;
-
- /* FIXME: try to allocate array statically? */
- while (values != NULL_TREE)
- {
- /* FIXME: Should use build_java_arrayaccess here, but avoid
- bounds checking. */
- tree lhs = build3 (COMPONENT_REF, TREE_TYPE (data_field),
- build_java_indirect_ref (array_type, tmp, 0),
- data_field, NULL_TREE);
- tree assignment = build2 (MODIFY_EXPR, element_type,
- build4 (ARRAY_REF, element_type, lhs,
- build_int_cst (NULL_TREE, index++),
- NULL_TREE, NULL_TREE),
- TREE_VALUE (values));
- body = build2 (COMPOUND_EXPR, element_type, body, assignment);
- values = TREE_CHAIN (values);
- }
-
- return build2 (COMPOUND_EXPR, array_ptr_type, body, tmp);
-}
-
-static tree
-java_gimplify_try_expr (tree try_expr)
-{
- tree body = TREE_OPERAND (try_expr, 0);
- tree handler = TREE_OPERAND (try_expr, 1);
- tree catch = NULL_TREE;
-
- /* Build a CATCH_EXPR for each handler. */
- while (handler)
- {
- tree java_catch = TREE_OPERAND (handler, 0);
- tree catch_type = TREE_TYPE (TREE_TYPE (BLOCK_EXPR_DECLS (java_catch)));
- tree expr = build2 (CATCH_EXPR, void_type_node,
- prepare_eh_table_type (catch_type),
- handler);
- if (catch)
- catch = build2 (COMPOUND_EXPR, void_type_node, catch, expr);
- else
- catch = expr;
- handler = TREE_CHAIN (handler);
- }
- return build2 (TRY_CATCH_EXPR, void_type_node, body, catch);
-}
-