diff options
-rw-r--r-- | gcc/fortran/ChangeLog | 17 | ||||
-rw-r--r-- | gcc/fortran/gfortran.h | 2 | ||||
-rw-r--r-- | gcc/fortran/options.c | 4 | ||||
-rw-r--r-- | gcc/fortran/scanner.c | 63 |
4 files changed, 79 insertions, 7 deletions
diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog index e574f186944..983d892958b 100644 --- a/gcc/fortran/ChangeLog +++ b/gcc/fortran/ChangeLog @@ -1,3 +1,20 @@ +2006-10-02 Jerry DeLisle <jvdelisle@gcc.gnu.org> + + PR fortran/19262 + * gfortran.h (gfc_option_t): Add max_continue_fixed and max_continue_free. + * options.c (gfc_init_options): Initialize fixed form and free form + consecutive continuation line limits. + * scanner.c (gfc_scanner_init_1): Initialize continue_line + and continue_count. (gfc_next_char_literal): Count the number of + continuation lines in the current statement and warn if + limit is exceeded. + +2006-10-02 Jerry DeLisle <jvdelisle@gcc.gnu.org> + + PR fortran/19260 + * scanner.c (gfc_next_char_literal): Add check for missing '&' + and warn if in_string, otherwise return ' '. + 2006-10-02 Francois-Xavier Coudert <coudert@clipper.ens.fr> PR fortran/29210 diff --git a/gcc/fortran/gfortran.h b/gcc/fortran/gfortran.h index 60a53335cfb..0daa8f58888 100644 --- a/gcc/fortran/gfortran.h +++ b/gcc/fortran/gfortran.h @@ -1613,6 +1613,8 @@ typedef struct 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 max_continue_fixed; + int max_continue_free; int max_identifier_length; int verbose; diff --git a/gcc/fortran/options.c b/gcc/fortran/options.c index cd550d449e6..4d76030548c 100644 --- a/gcc/fortran/options.c +++ b/gcc/fortran/options.c @@ -48,6 +48,8 @@ gfc_init_options (unsigned int argc ATTRIBUTE_UNUSED, gfc_option.source_form = FORM_UNKNOWN; gfc_option.fixed_line_length = -1; gfc_option.free_line_length = -1; + gfc_option.max_continue_fixed = 19; + gfc_option.max_continue_free = 39; gfc_option.max_identifier_length = GFC_MAX_SYMBOL_LEN; gfc_option.verbose = 0; @@ -586,6 +588,8 @@ gfc_handle_option (size_t scode, const char *arg, int value) gfc_option.allow_std = GFC_STD_F95_OBS | GFC_STD_F77 | GFC_STD_F2003 | GFC_STD_F95; gfc_option.warn_std = GFC_STD_F95_OBS; + gfc_option.max_continue_fixed = 255; + gfc_option.max_continue_free = 255; gfc_option.max_identifier_length = 63; gfc_option.warn_ampersand = 1; break; diff --git a/gcc/fortran/scanner.c b/gcc/fortran/scanner.c index e79fa37b922..59b2e704bfa 100644 --- a/gcc/fortran/scanner.c +++ b/gcc/fortran/scanner.c @@ -61,6 +61,7 @@ static gfc_directorylist *include_dirs; static gfc_file *file_head, *current_file; static int continue_flag, end_flag, openmp_flag; +static int continue_count, continue_line; static locus openmp_locus; gfc_source_form gfc_current_form; @@ -71,6 +72,7 @@ const char *gfc_source_file; static FILE *gfc_src_file; static char *gfc_src_preprocessor_lines[2]; +extern int pedantic; /* Main scanner initialization. */ @@ -81,6 +83,9 @@ gfc_scanner_init_1 (void) line_head = NULL; line_tail = NULL; + continue_count = 0; + continue_line = 0; + end_flag = 0; } @@ -585,7 +590,10 @@ gfc_next_char_literal (int in_string) restart: c = next_char (); if (gfc_at_end ()) - return c; + { + continue_count = 0; + return c; + } if (gfc_current_form == FORM_FREE) { @@ -644,8 +652,22 @@ restart: else gfc_advance_line (); - /* We've got a continuation line and need to find where it continues. - First eat any comment lines. */ + /* We've got a continuation line. If we are on the very next line after + the last continuation, increment the continuation line count and + check whether the limit has been exceeded. */ + if (gfc_current_locus.lb->linenum == continue_line + 1) + { + if (++continue_count == gfc_option.max_continue_free) + { + if (gfc_notification_std (GFC_STD_GNU) + || pedantic) + gfc_warning ("Limit of %d continuations exceeded in statement at %C", + gfc_option.max_continue_free); + } + } + continue_line = gfc_current_locus.lb->linenum; + + /* Now find where it continues. First eat any comment lines. */ gfc_skip_comments (); if (prev_openmp_flag != openmp_flag) @@ -681,10 +703,18 @@ restart: if (c != '&') { - if (in_string && gfc_option.warn_ampersand) - gfc_warning ("Missing '&' in continued character constant at %C"); - - gfc_current_locus.nextc--; + if (in_string) + { + if (gfc_option.warn_ampersand) + gfc_warning_now ("Missing '&' in continued character constant at %C"); + gfc_current_locus.nextc--; + } + else + { + c = ' '; + gfc_current_locus = old_loc; + goto done; + } } } else @@ -738,6 +768,23 @@ restart: c = next_char (); if (c == '0' || c == ' ' || c == '\n') goto not_continuation; + + /* We've got a continuation line. If we are on the very next line after + the last continuation, increment the continuation line count and + check whether the limit has been exceeded. */ + if (gfc_current_locus.lb->linenum == continue_line + 1) + { + if (++continue_count == gfc_option.max_continue_fixed) + { + if (gfc_notification_std (GFC_STD_GNU) + || pedantic) + gfc_warning ("Limit of %d continuations exceeded in statement at %C", + gfc_option.max_continue_fixed); + } + } + + if (continue_line < gfc_current_locus.lb->linenum) + continue_line = gfc_current_locus.lb->linenum; } /* Ready to read first character of continuation line, which might @@ -749,6 +796,8 @@ not_continuation: gfc_current_locus = old_loc; done: + if (c == '\n') + continue_count = 0; continue_flag = 0; return c; } |