[PATCH] Rewrite match_attr_spec, eliminate gfc_match_strings

Roger Sayle roger@eyesopen.com
Fri Aug 31 15:11:00 GMT 2007


My first attempts at posting this (with a new mail client) didn't make it 
through, so I'm trying again...

The following patch restructures the gfortran front-end's match_attr_spec 
parser to use effiicient in-line pattern matching rather than call the large 
hammer gfc_match_strings.  This being the last remaining caller of 
gfc_match_strings, allows it to be deleted.

The implementation follows the same idiom as used to replace the two 
previous callers of gfc_match_strings.  One minor difference/implementation 
choice is the decision to perform the matching in the body of decl.c's 
match_attr_spec.  This both avoids exposing the function local "enum 
decl_types" outside this function, and allows better integration with the 
new "BIND(C)" parsing code which was previously a separate processing step 
performed when the initial table-based declaration parsing failed.  Another 
minor benefit is that we can now avoid the enumerated value DECL_COLON 
(returned by matching "::") which was used as a terminator value purely to 
indicate that we should break out of the loop.  The new inline code is now 
able to "break;" directly and so we no longer need this sentinel.  Finally, 
the one small remaining inefficiency/backtracking is in the code to parse 
the attribute list following "intent", either "(in)", "(out)" or "(inout)". 
The current patch simply uses gfc_match, duplicating identical code in 
match_intent_spec.  I'll propose a follow-up patch to improve 
match_intent_spec, and re-use it from here in match_attr_spec, but that 
change is independent, and may potentially affect the diagnostics we choose 
to generate for "intent (foo)".  I've marked the relevant spot with a "TODO" 
comment.

The following patch has been tested on x86_64-unknown-linux-gnu with a full 
"make bootstrap", including gfortran, and regression tested with a top-level 
"make -k check" with no new failures.  Ok for mainline?


2007-08-30  Roger Sayle  <roger@eyesopen.com>

        * decl.c (match_string_p): New helper function to explicitly match
        a string of characters.
        (match_attr_spec): Remove no longer needed DECL_COLON from 
decl_types.
        Delete decls array and peek_char.  Rewrite decl attribute parser to
        avoid calling gfc_match_strings.
        * match.c (gfc_match_strings): Delete unused function.
        * match.h (gfc_match_strings): Delete prototype.


Roger
--
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: patch.txt
URL: <http://gcc.gnu.org/pipermail/fortran/attachments/20070831/981f5935/attachment.txt>


More information about the Fortran mailing list