Janus Weil <janus@gcc.gnu.org>
PR fortran/37336
* class.c (gfc_is_finalizable): New function.
* gfortran.h (gfc_is_finalizable): Its prototype.
* module.c (mio_component): Read initializer for vtype's _final.
* resolve.c (resolve_fl_derived0): Call gfc_is_finalizable.
* trans-expr.c (gfc_vtable_final_get): New function.
(conv_parent_component_references): Fix comment.
(gfc_conv_variable): Fix for scalar coarray components.
* trans-intrinsic.c (conv_intrinsic_move_alloc): For BT_CLASS,
pass the BT_CLASS type and not the declared type to
gfc_deallocate_scalar_with_status.
* trans.h (gfc_vtable_final_get): New prototype.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@194104
138bc75d-0d04-0410-961f-
82ee72b054a4
2012-12-03 Tobias Burnus <burnus@net-b.de>
+ Janus Weil <janus@gcc.gnu.org>
+
+ PR fortran/37336
+ * class.c (gfc_is_finalizable): New function.
+ * gfortran.h (gfc_is_finalizable): Its prototype.
+ * module.c (mio_component): Read initializer for vtype's _final.
+ * resolve.c (resolve_fl_derived0): Call gfc_is_finalizable.
+ * trans-expr.c (gfc_vtable_final_get): New function.
+ (conv_parent_component_references): Fix comment.
+ (gfc_conv_variable): Fix for scalar coarray components.
+ * trans-intrinsic.c (conv_intrinsic_move_alloc): For BT_CLASS,
+ pass the BT_CLASS type and not the declared type to
+ gfc_deallocate_scalar_with_status.
+ * trans.h (gfc_vtable_final_get): New prototype.
+
+2012-12-03 Tobias Burnus <burnus@net-b.de>
PR fortran/55475
* scanner.c (gfc_next_char_literal): Fix setting locus
}
+/* Check if a derived type is finalizable. That is the case if it
+ (1) has a FINAL subroutine or
+ (2) has a nonpointer nonallocatable component of finalizable type.
+ If it is finalizable, return an expression containing the
+ finalization wrapper. */
+
+bool
+gfc_is_finalizable (gfc_symbol *derived, gfc_expr **final_expr)
+{
+ gfc_symbol *vtab;
+ gfc_component *c;
+
+ /* (1) Check for FINAL subroutines. */
+ if (derived->f2k_derived && derived->f2k_derived->finalizers)
+ goto yes;
+
+ /* (2) Check for components of finalizable type. */
+ for (c = derived->components; c; c = c->next)
+ if (c->ts.type == BT_DERIVED
+ && !c->attr.pointer && !c->attr.proc_pointer && !c->attr.allocatable
+ && gfc_is_finalizable (c->ts.u.derived, NULL))
+ goto yes;
+
+ return false;
+
+yes:
+ /* Make sure vtab is generated. */
+ vtab = gfc_find_derived_vtab (derived);
+ if (final_expr)
+ {
+ /* Return finalizer expression. */
+ gfc_component *final;
+ final = vtab->ts.u.derived->components->next->next->next->next->next;
+ gcc_assert (strcmp (final->name, "_final") == 0);
+ gcc_assert (final->initializer
+ && final->initializer->expr_type != EXPR_NULL);
+ *final_expr = final->initializer;
+ }
+ return true;
+}
+
+
/* General worker function to find either a type-bound procedure or a
type-bound user operator. */
#define gfc_add_hash_component(e) gfc_add_component_ref(e,"_hash")
#define gfc_add_size_component(e) gfc_add_component_ref(e,"_size")
#define gfc_add_def_init_component(e) gfc_add_component_ref(e,"_def_init")
+#define gfc_add_final_component(e) gfc_add_component_ref(e,"_final")
bool gfc_is_class_array_ref (gfc_expr *, bool *);
bool gfc_is_class_scalar_expr (gfc_expr *);
bool gfc_is_class_container_ref (gfc_expr *e);
gfc_intrinsic_op, bool,
locus*);
gfc_symtree* gfc_get_tbp_symtree (gfc_symtree**, const char*);
+bool gfc_is_finalizable (gfc_symbol *, gfc_expr **);
#define CLASS_DATA(sym) sym->ts.u.derived->components
c->attr.class_ok = 1;
c->attr.access = MIO_NAME (gfc_access) (c->attr.access, access_types);
- if (!vtype)
+ if (!vtype || strcmp (c->name, "_final") == 0)
mio_expr (&c->initializer);
if (c->attr.proc_pointer)
/* Add derived type to the derived type list. */
add_dt_to_dt_list (sym);
+ /* Check if the type is finalizable. This is done in order to ensure that the
+ finalization wrapper is generated early enough. */
+ gfc_is_finalizable (sym, NULL);
+
return SUCCESS;
}
#define VTABLE_EXTENDS_FIELD 2
#define VTABLE_DEF_INIT_FIELD 3
#define VTABLE_COPY_FIELD 4
+#define VTABLE_FINAL_FIELD 5
tree
}
+tree
+gfc_vtable_final_get (tree decl)
+{
+ return gfc_vtable_field_get (decl, VTABLE_FINAL_FIELD);
+}
+
+
#undef CLASS_DATA_FIELD
#undef CLASS_VPTR_FIELD
#undef VTABLE_HASH_FIELD
#undef VTABLE_EXTENDS_FIELD
#undef VTABLE_DEF_INIT_FIELD
#undef VTABLE_COPY_FIELD
+#undef VTABLE_FINAL_FIELD
/* Obtain the vptr of the last class reference in an expression. */
dt = ref->u.c.sym;
c = ref->u.c.component;
- /* Return if the component is not in the parent type. */
+ /* Return if the component is in the parent type. */
for (cmp = dt->components; cmp; cmp = cmp->next)
if (strcmp (c->name, cmp->name) == 0)
return;
conv_parent_component_references (se, ref);
gfc_conv_component_ref (se, ref);
+ if (!ref->next && ref->u.c.sym->attr.codimension
+ && se->want_pointer && se->descriptor_only)
+ return;
break;
/* Deallocate "to". */
tmp = gfc_deallocate_scalar_with_status (to_se.expr, NULL_TREE, true,
- to_expr2, to_expr->ts);
+ to_expr, to_expr->ts);
gfc_add_expr_to_block (&block, tmp);
/* Assign (_data) pointers. */
tree gfc_vtable_extends_get (tree);
tree gfc_vtable_def_init_get (tree);
tree gfc_vtable_copy_get (tree);
+tree gfc_vtable_final_get (tree);
tree gfc_get_vptr_from_expr (tree);
tree gfc_get_class_array_ref (tree, tree);
tree gfc_copy_class_to_class (tree, tree, tree);