[PATCH] Fortran frontend walker

Thomas Koenig tkoenig@netcologne.de
Wed Sep 15 22:15:00 GMT 2010


Hi Jakub,


> Here are two possible patches, which add the walker and
> convert optimize_namespace to use it.
> 
> The difference between the two patches is that the first patch
> passes around address of gfc_code * or gfc_expr *, so it is possible to
> change it easily, while the latter passes around gfc_code * or
> gfc_expr *.  In all the changes I've looked at the simplifications were done
> by adjusting fields in gfc_expr (possible turning it into different type
> and changing its arguments), so perhaps the second patch might be
> sufficient.

Two remarks:

1. I see you have left the optimize_namespace function 'as is'.   Was
  this intentional?  My feeling would be that this is more a part of the
  walker, but maybe this would complicate the callback scheme more than
  it is worth.  This is not critical, though.

2. I would prefer the address of gfc_code ** variant, because it is
   likely we would want to insert, delete or move code.

The patch is OK.  Thanks a lot for your patch!

One remark you might want to consider before following the static
analysis:

In this version, references are not followed.  You would have to
insert code like

  ...
  case EXPR_VARIABLE:
  if ((*e)->ref)
    {
       gfc_array_ref *ar;
       switch ((*e)->ref->type)
         {
            case REF_ARRAY:
               ar=&e->u.ar;
               for (i=0; i<ar->dimen; i++)
                 {
                     if (ar->dimen_type[i] == DIMEN_RANGE)
                        {
			  WALK_SUBEXPR(ar->start[n]);
                          ...
                        }
                     else
                    ... Have to handle integer array indices as well
                 }
         }
    }

to handle array references, similar (but more simple) for substrings, if
you want complete coverage of all expressions.

	Thomas



More information about the Gcc-patches mailing list