[Patch, Fortran] Follow-up to used-before-typed patch

Daniel Kraft d@domob.eu
Fri Aug 22 10:25:00 GMT 2008


Hi Tobias,

this is a follow-up to my used-before-typed patch addressing the problem 
with indexing.  While implementing, I realized that I could in fact 
reuse gfc_traverse_expr and rewrote the logic to do that; this gets the 
index thing right and makes the code hopefully cleaner.

No regressions on GNU/Linux-x86-32 (to 99% sure, test is still running).

What do you think about this patch?  Unfortunatelly the diff got a bit 
weird, at the bottom of the message I've copied in the new bottom-part 
of expr.c replacing the old gfc_expr_check_typed.

Regarding the in_prefix and parser-state, I've tried to do this but got 
two failures for function_kind_2.f90 and function_type_1.f90 (IIRC) as 
the logic handling those is bailing out because of the new parser-state. 
  I'm not sure if this is really a good idea; maybe I should just rename 
in_prefix to gfc_matching_prefix, for instance, to get consistent with 
e.g. gfc_matching_function?

Another idea would be to construct some sort of global flag-structure 
combining gfc_matching_function, gfc_matching_prefix and possibly others 
like this.   Any comments regarding this part?

Thanks, Daniel

===================================

/* Walk an expression tree and check each variable encountered for being 
typed.
    If strict is not set, a top-level variable is tolerated untyped in 
-std=gnu
    mode; this is for things in legacy-code like:

      INTEGER :: arr(n), n

    The namespace is needed for IMPLICIT typing.  */

static gfc_namespace* check_typed_ns;

static bool
expr_check_typed_help (gfc_expr* e, gfc_symbol* sym ATTRIBUTE_UNUSED,
                        int* f ATTRIBUTE_UNUSED)
{
   gfc_try t;

   if (e->expr_type != EXPR_VARIABLE)
     return false;

   gcc_assert (e->symtree);
   t = gfc_check_symbol_typed (e->symtree->n.sym, check_typed_ns,
                               true, e->where);

   return (t == FAILURE);
}

gfc_try
gfc_expr_check_typed (gfc_expr* e, gfc_namespace* ns, bool strict)
{
   bool error_found;

   /* If this is a top-level variable, do the check with strict given to 
us.  */
   if (!strict && e->expr_type == EXPR_VARIABLE && !e->ref)
     return gfc_check_symbol_typed (e->symtree->n.sym, ns, strict, 
e->where);

   /* Otherwise, walk the expression and do it strictly.  */
   check_typed_ns = ns;
   error_found = gfc_traverse_expr (e, NULL, &expr_check_typed_help, 0);

   return error_found ? FAILURE : SUCCESS;
}

=====================================

-- 
Done:     Arc-Bar-Cav-Sam-Val-Wiz, Dwa-Elf-Gno-Hum-Orc, Law-Neu-Cha, Fem-Mal
To go:    Hea-Kni-Mon-Pri-Ran-Rog-Tou
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: patch.diff
URL: <http://gcc.gnu.org/pipermail/gcc-patches/attachments/20080822/d122d446/attachment.ksh>


More information about the Gcc-patches mailing list