[Patch, Fortran] attributes for gfc_component
Janus Weil
jaydub66@googlemail.com
Fri Aug 15 15:14:00 GMT 2008
Hi all,
I have started implementing "procedure-pointer components" (i.e.
procedure pointers as components of derived types), and noticed that
this will require "gfc_component" to hold a lot of new attributes
(like function, subroutine, proc_pointer, untyped, pure, elemental,
recursive, always_explicit, ...).
Now there are two possibilities: Either add each of these as separate
fields to gfc_component (like it has already been done with pointer,
allocatable, dimension and access), or simply reuse the
symbol_attributes structure. I would prefer the second option,
although it means that gfc_component will carry along a few extra
fields, which are not actually needed.
The attached patch adds a symbol_attribute field to gfc_component, and
removes those attributes that were already part of gfc_component:
--- gcc/fortran/gfortran.h (revision 139115)
+++ gcc/fortran/gfortran.h (working copy)
@@ -834,8 +834,7 @@ typedef struct gfc_component
const char *name;
gfc_typespec ts;
- int pointer, allocatable, dimension;
- gfc_access access;
+ symbol_attribute attr;
gfc_array_spec *as;
Most of the patch is fairly mechanical, just replacing things like
"c->pointer" with the equivalent "c->attr.pointer". There are a few
changes though, which are not quite as mechanical (hoping they are
ok), e.g.:
--- gcc/fortran/symbol.c (revision 139116)
+++ gcc/fortran/symbol.c (working copy)
@@ -1917,11 +1917,7 @@ free_components (gfc_component *p)
void
gfc_set_component_attr (gfc_component *c, symbol_attribute *attr)
{
-
- c->dimension = attr->dimension;
- c->pointer = attr->pointer;
- c->allocatable = attr->allocatable;
- c->access = attr->access;
+ c->attr = *attr;
}
@@ -1931,12 +1927,8 @@ gfc_set_component_attr (gfc_component *c
void
gfc_get_component_attr (symbol_attribute *attr, gfc_component *c)
{
-
gfc_clear_attr (attr);
- attr->dimension = c->dimension;
- attr->pointer = c->pointer;
- attr->allocatable = c->allocatable;
- attr->access = c->access;
+ *attr = c->attr;
}
--- gcc/fortran/module.c (revision 139115)
+++ gcc/fortran/module.c (working copy)
@@ -2252,10 +2252,8 @@ mio_component (gfc_component *c)
mio_typespec (&c->ts);
mio_array_spec (&c->as);
- mio_integer (&c->dimension);
- mio_integer (&c->pointer);
- mio_integer (&c->allocatable);
- c->access = MIO_NAME (gfc_access) (c->access, access_types);
+ mio_symbol_attribute (&c->attr);
+ c->attr.access = MIO_NAME (gfc_access) (c->attr.access, access_types);
mio_expr (&c->initializer);
mio_rparen ();
So, would there be any advantages of choosing the other option, or do
you think this patch is the right way to go?
I would like to commit this in preparation of procedure-pointer
components, and I think it would be just as useful for type-bound
procedures. The patch is regression-tested on i686-pc-linux-gnu
without any failures.
Cheers,
Janus
2008-08-15 Janus Weil <janus@gcc.gnu.org>
* gfortran.h (gfc_component): Add field "symbol_attribute attr", remove
fields "pointer", "allocatable", "dimension", "access".
* interface.c (gfc_compare_derived_types): Ditto.
* trans-array.c (gfc_array_allocate,structure_alloc_comps): Ditto.
* trans-expr.c (gfc_conv_component_ref,gfc_trans_subcomponent_assign,
gfc_conv_structure): Ditto.
* symbol.c (gfc_find_component,free_components,gfc_set_component_attr,
verify_bind_c_derived_type,generate_isocbinding_symbol): Ditto.
* decl.c (build_struct): Ditto.
* dump-parse-tree.c (show_components): Ditto.
* trans-stmt.c (gfc_trans_deallocate): Ditto.
* expr.c (gfc_check_assign,gfc_check_pointer_assign,
gfc_default_initializer): Ditto.
* module.c (mio_component): Ditto.
* trans-types.c (copy_dt_decls_ifequal,gfc_get_derived_type): Ditto.
* resolve.c (has_default_initializer,resolve_structure_cons,
gfc_iso_c_func_interface,find_array_spec,resolve_ref,
resolve_deallocate_expr,resolve_allocate_expr,resolve_fl_derived,
resolve_equivalence_derived): Ditto.
* trans-io.c (transfer_expr): Ditto.
* parse.c (parse_derived): Ditto.
* dependency.c (gfc_check_dependency): Ditto.
* primary.c (gfc_variable_attr): Ditto.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: comp_attr.diff
Type: text/x-patch
Size: 23568 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/fortran/attachments/20080815/63630dfa/attachment.bin>
More information about the Fortran
mailing list