This is the mail archive of the
fortran@gcc.gnu.org
mailing list for the GNU Fortran project.
[patch, fortran] Simplify line-length constants, remove GFC_MAX_LINE
- From: Brooks Moses <brooks dot moses at codesourcery dot com>
- To: fortran at gcc dot gnu dot org
- Cc: gcc-patches at gcc dot gnu dot org
- Date: Thu, 09 Nov 2006 22:40:08 -0800
- Subject: [patch, fortran] Simplify line-length constants, remove GFC_MAX_LINE
- Organization: Stanford University
The current handling of maximum line lengths in gfortran is rather more
complicated than it needs to be. In particular, the gfc_option elements
fixed_line_length and free_line_length have default values of -1, and
the line-length checking in scanner.c checks for this value and then
sets the maximum length to 72 or GFC_MAX_LINE, respectively. This
probably made sense when there was only one line-length parameter for
both source modes, but as of now there is no reason not to simply
default the option values to 72 and GFC_MAX_LINE.
Furthermore, GFC_MAX_LINE is not an especially meaningful constant at
this point. It's used in only two places, and they don't have any
reason to use the same value. It's used to set the default line limit
for free-form source, and it's used to set the initial line-buffer size
in the case where the line length is not limited. (The buffer then gets
reallocated if this length is exceeded, so this is only an initial
value.) And it's defined in gfortran.h in a section of other constants
that represent hard limits on buffers, which is somewhat misleading
because at this point it isn't a hard limit on anything.
Therefore, I'm proposing that the fixed_line_length and free_line_length
elements of gfc_option be simplified to remove the special -1 flag
handling and just be initialized with their default values, and that the
GFC_MAX_LINE constant be removed -- it makes more sense to put in the
"magic number" for the default free_line_length in option.c with all the
rest of the magic numbers for default line lengths and numbers of
continuation lines and so forth, and since the only other use is a
single place where the value has minimal significance (and isn't a
maximum line length, so the name is misleading), it seemed clearest just
to put the initial buffer size directly in scanner.c and eliminate
GFC_MAX_LINE altogether.
The following patch implements this. Regression tested on
i686-pc-linux-gnu. Ok for trunk?
-----------------------------------------------------------------
2006-11-09 Brooks Moses <brooks.moses@codesourcery.com>
* gfortran.h (GFC_MAX_LINE): Remove constant definition.
(gfc_option_t): Clarify comments.
* options.c: Set default line length limits to actual default
values, rather than flag values.
* scanner.c: Eliminate checking and handling of the
fixed/free_line_length flag values.
-----------------------------------------------------------------
- Brooks
Index: gfortran.h
===================================================================
--- gfortran.h (revision 118617)
+++ gfortran.h (working copy)
@@ -55,8 +55,7 @@
/* Major control parameters. */
-#define GFC_MAX_SYMBOL_LEN 63
-#define GFC_MAX_LINE 132 /* Characters beyond this are not seen. */
+#define GFC_MAX_SYMBOL_LEN 63 /* Must be at least 63 for F2003. */
#define GFC_MAX_DIMENSIONS 7 /* Maximum dimensions in an array. */
#define GFC_LETTERS 26 /* Number of letters in the alphabet. */
@@ -1602,20 +1601,16 @@
{
char *module_dir;
gfc_source_form source_form;
- /* When fixed_line_length or free_line_length are 0, the whole line is used.
+ /* Maximum line lengths in fixed- and free-form source, respectively.
+ When fixed_line_length or free_line_length are 0, the whole line is used,
+ regardless of length.
- Default is -1, the maximum line length mandated by the respective source
- form is used:
- for FORM_FREE GFC_MAX_LINE (132)
- else 72.
-
- If fixed_line_length or free_line_length is not 0 nor -1 then the user has
- requested a specific line-length.
-
If the user requests a fixed_line_length <7 then gfc_init_options()
emits a fatal error. */
- int fixed_line_length; /* maximum line length in fixed-form. */
- int free_line_length; /* maximum line length in free-form. */
+ int fixed_line_length;
+ int free_line_length;
+ /* Maximum number of continuation lines in fixed- and free-form source,
+ respectively. */
int max_continue_fixed;
int max_continue_free;
int max_identifier_length;
Index: options.c
===================================================================
--- options.c (revision 118617)
+++ options.c (working copy)
@@ -46,8 +46,8 @@
gfc_source_file = NULL;
gfc_option.module_dir = NULL;
gfc_option.source_form = FORM_UNKNOWN;
- gfc_option.fixed_line_length = -1;
- gfc_option.free_line_length = -1;
+ gfc_option.fixed_line_length = 72;
+ gfc_option.free_line_length = 132;
gfc_option.max_continue_fixed = 19;
gfc_option.max_continue_free = 39;
gfc_option.max_identifier_length = GFC_MAX_SYMBOL_LEN;
Index: scanner.c
===================================================================
--- scanner.c (revision 118617)
+++ scanner.c (working copy)
@@ -955,33 +955,25 @@
int seen_printable = 0, seen_ampersand = 0;
char *buffer;
- /* Determine the maximum allowed line length.
- The default for free-form is GFC_MAX_LINE, for fixed-form or for
- unknown form it is 72. Refer to the documentation in gfc_option_t. */
+ /* Determine the maximum allowed line length. */
if (gfc_current_form == FORM_FREE)
- {
- if (gfc_option.free_line_length == -1)
- maxlen = GFC_MAX_LINE;
- else
- maxlen = gfc_option.free_line_length;
- }
+ maxlen = gfc_option.free_line_length;
else if (gfc_current_form == FORM_FIXED)
- {
- if (gfc_option.fixed_line_length == -1)
- maxlen = 72;
- else
- maxlen = gfc_option.fixed_line_length;
- }
+ maxlen = gfc_option.fixed_line_length;
else
maxlen = 72;
if (*pbuf == NULL)
{
- /* Allocate the line buffer, storing its length into buflen. */
+ /* Allocate the line buffer, storing its length into buflen.
+ Note that if maxlen==0, indicating that arbitrary-length lines
+ are allowed, the buffer will be reallocated if this length is
+ insufficient; since 132 characters is the length of a standard
+ free-form line, we use that as a starting guess. */
if (maxlen > 0)
buflen = maxlen;
else
- buflen = GFC_MAX_LINE;
+ buflen = 132;
*pbuf = gfc_getmem (buflen + 1);
}