This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: Fwd: [Patch, Fortran] PR 43199 - Handle class%component references when reading .mod files
Dear Paul,
Paul Richard Thomas wrote:
> It is my intention to go through the OOP implementation routing out
> references to derived->components->.... in favour of using gfc_find_component
> (derived, "$data", true, true) just so as not to weld in and bolt down
> the representation of CLASS. Could you do so here, please?
>
Well, I somehow find it a bit clumsy as one has to convert a pointer to
a name, does string comparisons, goes back to a symbol; somehow
gfc_find_component sounds like the wrong tool for this special task of
fixing expressions after a module read. I will try to get something
working, but a first try with the approach below ends with the
Error: Derived type 's' at (1) is being used before it is defined
for the test case included in the previous patch / PR 43199.
Thus, I still prefer my previous patch which was approved by Janus on
#gfortran (unmodified version).
:-)
Tobias
Index: gcc/fortran/resolve.c
===================================================================
--- gcc/fortran/resolve.c (Revision 157126)
+++ gcc/fortran/resolve.c (Arbeitskopie)
@@ -3982,15 +3982,14 @@
find_array_spec (gfc_expr *e)
{
gfc_array_spec *as;
- gfc_component *c;
- gfc_symbol *derived;
+ gfc_component *c, *derived = NULL;
+ gfc_symbol *sym;
gfc_ref *ref;
if (e->symtree->n.sym->ts.type == BT_CLASS)
as = e->symtree->n.sym->ts.u.derived->components->as;
else
as = e->symtree->n.sym->as;
- derived = NULL;
for (ref = e->ref; ref; ref = ref->next)
switch (ref->type)
@@ -4005,27 +4004,17 @@
case REF_COMPONENT:
if (derived == NULL)
- derived = e->symtree->n.sym->ts.u.derived;
+ sym = e->symtree->n.sym;
+ else
+ sym = derived->ts.u.derived;
- c = derived->components;
+ derived = gfc_find_component (sym, ref->u.c.component->name, true, true);
- for (; c; c = c->next)
- if (c == ref->u.c.component)
- {
- /* Track the sequence of component references. */
- if (c->ts.type == BT_DERIVED)
- derived = c->ts.u.derived;
- break;
- }
-
- if (c == NULL)
- gfc_internal_error ("find_array_spec(): Component not found");
-
if (c->attr.dimension)
{
if (as != NULL)
gfc_internal_error ("find_array_spec(): unused as(1)");
- as = c->as;
+ as = derived->as;
}
break;