re PR fortran/16465 (parser chokes with ffixed-line-length-7)
PR fortran/16465 * lang.opt (ffixed-line-length-none, ffixed-line-length-): New options. (ffixed-line-length-80, ffixed-line-length-132): Remove. * options.c (gfc_handle_options): Deal with changed options. * scanner.c (load_line): Change second arg to 'char **', allocate if pointing to NULL. Keep track of buffer's length. Adapt buffer size to overlong lines. Pad lines to full length in fixed form. (load_file): Adapt to new interface of load_line. From-SVN: r84891
This commit is contained in:
parent
9cdc381b1a
commit
f56c5d5d5b
@ -1,3 +1,16 @@
|
||||
2004-07-18 Tobias Schlueter <tobias.schlueter@physik.uni-muenchen.de>
|
||||
|
||||
PR fortran/16465
|
||||
* lang.opt (ffixed-line-length-none, ffixed-line-length-): New
|
||||
options.
|
||||
(ffixed-line-length-80, ffixed-line-length-132): Remove.
|
||||
* options.c (gfc_handle_options): Deal with changed options.
|
||||
* scanner.c (load_line): Change second arg to 'char **',
|
||||
allocate if pointing to NULL. Keep track of buffer's length.
|
||||
Adapt buffer size to overlong lines. Pad lines to full length
|
||||
in fixed form.
|
||||
(load_file): Adapt to new interface of load_line.
|
||||
|
||||
2004-07-17 Joseph S. Myers <jsm@polyomino.org.uk>
|
||||
|
||||
* trans.h (builtin_function): Declare.
|
||||
|
@ -97,13 +97,13 @@ fimplicit-none
|
||||
F95
|
||||
Specify that no implicit typing is allowed, unless overridden by explicit IMPLICIT statements
|
||||
|
||||
ffixed-line-length-80
|
||||
ffixed-line-length-none
|
||||
F95 RejectNegative
|
||||
Use 80 character line width in fixed mode
|
||||
Allow arbitrary character line width in fixed mode
|
||||
|
||||
ffixed-line-length-132
|
||||
F95 RejectNegative
|
||||
Use 132 character line width in fixed mode
|
||||
ffixed-line-length-
|
||||
F95 RejectNegative Joined UInteger
|
||||
-ffixed-line-length-<n> Use n as character line width in fixed mode
|
||||
|
||||
fmax-identifier-length=
|
||||
F95 RejectNegative Joined UInteger
|
||||
|
@ -260,12 +260,14 @@ gfc_handle_option (size_t scode, const char *arg, int value)
|
||||
gfc_option.flag_repack_arrays = value;
|
||||
break;
|
||||
|
||||
case OPT_ffixed_line_length_80:
|
||||
gfc_option.fixed_line_length = 80;
|
||||
case OPT_ffixed_line_length_none:
|
||||
gfc_option.fixed_line_length = 0;
|
||||
break;
|
||||
|
||||
case OPT_ffixed_line_length_132:
|
||||
gfc_option.fixed_line_length = 132;
|
||||
case OPT_ffixed_line_length_:
|
||||
if (value != 0 && value < 7)
|
||||
gfc_fatal_error ("Fixed line length must be at least seven.");
|
||||
gfc_option.fixed_line_length = value;
|
||||
break;
|
||||
|
||||
case OPT_fmax_identifier_length_:
|
||||
|
@ -671,26 +671,49 @@ gfc_gobble_whitespace (void)
|
||||
}
|
||||
|
||||
|
||||
/* Load a single line into the buffer. We truncate lines that are too
|
||||
long. In fixed mode, we expand a tab that occurs within the
|
||||
statement label region to expand to spaces that leave the next
|
||||
character in the source region. */
|
||||
/* Load a single line into pbuf.
|
||||
|
||||
If pbuf points to a NULL pointer, it is allocated.
|
||||
We truncate lines that are too long, unless we're dealing with
|
||||
preprocessor lines or if the option -ffixed-line-length-none is set,
|
||||
in which case we reallocate the buffer to fit the entire line, if
|
||||
need be.
|
||||
In fixed mode, we expand a tab that occurs within the statement
|
||||
label region to expand to spaces that leave the next character in
|
||||
the source region. */
|
||||
|
||||
static void
|
||||
load_line (FILE * input, char *buffer, char *filename, int linenum)
|
||||
load_line (FILE * input, char **pbuf, char *filename, int linenum)
|
||||
{
|
||||
int c, maxlen, i, trunc_flag, preprocessor_flag;
|
||||
static int buflen = 0;
|
||||
char *buffer;
|
||||
|
||||
maxlen = (gfc_current_form == FORM_FREE)
|
||||
? 132
|
||||
: gfc_option.fixed_line_length;
|
||||
/* Detemine the maximum allowed line length. */
|
||||
if (gfc_current_form == FORM_FREE)
|
||||
maxlen = GFC_MAX_LINE;
|
||||
else
|
||||
maxlen = gfc_option.fixed_line_length;
|
||||
|
||||
if (*pbuf == NULL)
|
||||
{
|
||||
/* Allocate the line buffer, storing its length into buflen. */
|
||||
if (maxlen > 0)
|
||||
buflen = maxlen;
|
||||
else
|
||||
buflen = GFC_MAX_LINE;
|
||||
|
||||
*pbuf = gfc_getmem (buflen + 1);
|
||||
}
|
||||
|
||||
i = 0;
|
||||
buffer = *pbuf;
|
||||
|
||||
preprocessor_flag = 0;
|
||||
c = fgetc (input);
|
||||
if (c == '#')
|
||||
/* Don't truncate preprocessor lines. */
|
||||
/* In order to not truncate preprocessor lines, we have to
|
||||
remember that this is one. */
|
||||
preprocessor_flag = 1;
|
||||
ungetc (c, input);
|
||||
|
||||
@ -729,8 +752,17 @@ load_line (FILE * input, char *buffer, char *filename, int linenum)
|
||||
*buffer++ = c;
|
||||
i++;
|
||||
|
||||
if (i >= maxlen && !preprocessor_flag)
|
||||
{ /* Truncate the rest of the line. */
|
||||
if (i >= buflen && (maxlen == 0 || preprocessor_flag))
|
||||
{
|
||||
/* Reallocate line buffer to double size to hold the
|
||||
overlong line. */
|
||||
buflen = buflen * 2;
|
||||
*pbuf = xrealloc (*pbuf, buflen);
|
||||
buffer = (*pbuf)+i;
|
||||
}
|
||||
else if (i >= buflen)
|
||||
{
|
||||
/* Truncate the rest of the line. */
|
||||
trunc_flag = 1;
|
||||
|
||||
for (;;)
|
||||
@ -753,6 +785,14 @@ load_line (FILE * input, char *buffer, char *filename, int linenum)
|
||||
}
|
||||
}
|
||||
|
||||
/* Pad lines to the selected line length in fixed form. */
|
||||
if (gfc_current_form == FORM_FIXED
|
||||
&& gfc_option.fixed_line_length > 0
|
||||
&& !preprocessor_flag
|
||||
&& c != EOF)
|
||||
while (i++ < buflen)
|
||||
*buffer++ = ' ';
|
||||
|
||||
*buffer = '\0';
|
||||
}
|
||||
|
||||
@ -925,7 +965,7 @@ include_line (char *line)
|
||||
static try
|
||||
load_file (char *filename, bool initial)
|
||||
{
|
||||
char line[GFC_MAX_LINE+1];
|
||||
char *line;
|
||||
gfc_linebuf *b;
|
||||
gfc_file *f;
|
||||
FILE *input;
|
||||
@ -963,10 +1003,11 @@ load_file (char *filename, bool initial)
|
||||
f->up = current_file;
|
||||
current_file = f;
|
||||
current_file->line = 1;
|
||||
line = NULL;
|
||||
|
||||
for (;;)
|
||||
{
|
||||
load_line (input, line, filename, current_file->line);
|
||||
load_line (input, &line, filename, current_file->line);
|
||||
|
||||
len = strlen (line);
|
||||
if (feof (input) && len == 0)
|
||||
@ -1003,6 +1044,9 @@ load_file (char *filename, bool initial)
|
||||
line_tail = b;
|
||||
}
|
||||
|
||||
/* Release the line buffer allocated in load_line. */
|
||||
gfc_free (line);
|
||||
|
||||
fclose (input);
|
||||
|
||||
current_file = current_file->up;
|
||||
|
Loading…
Reference in New Issue
Block a user