From 35d6528e27b433049ab73eb5698ce84f5f03d914 Mon Sep 17 00:00:00 2001 From: kargl Date: Tue, 14 Mar 2006 19:37:49 +0000 Subject: [PATCH] PR 18537 * gfortran.h: Wrap Copyright line. (gfc_option_t): add warn_tabs member. * lang.opt: Update Coyright year. Add the Wtabs. * invoke.texi: Document -Wtabs. * scanner.c (gfc_gobble_whitespace): Use warn_tabs. Add linenum to suppress multiple warnings. (load_line): Use warn_tabs. Add linenum, current_line, seen_comment to suppress multiple warnings. * options.c (gfc_init_options): Initialize warn_tabs. (set_Wall): set warn_tabs for -Wall. (gfc_post_options): Adjust flag_tabs depending on -pedantic. (gfc_handle_option): Process command-line option -W[no-]tabs git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@112066 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/fortran/ChangeLog | 16 ++++++++++++++++ gcc/fortran/gfortran.h | 7 ++++--- gcc/fortran/invoke.texi | 17 +++++++++++++---- gcc/fortran/lang.opt | 6 +++++- gcc/fortran/options.c | 23 +++++++++++++++-------- gcc/fortran/scanner.c | 32 ++++++++++++++++++++++++++++++-- 6 files changed, 83 insertions(+), 18 deletions(-) diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog index b5f7d7330be..47e6afd1704 100644 --- a/gcc/fortran/ChangeLog +++ b/gcc/fortran/ChangeLog @@ -1,3 +1,19 @@ +2006-03-14 Steven G. Kargl + + PR 18537 + * gfortran.h: Wrap Copyright line. + (gfc_option_t): add warn_tabs member. + * lang.opt: Update Coyright year. Add the Wtabs. + * invoke.texi: Document -Wtabs. + * scanner.c (gfc_gobble_whitespace): Use warn_tabs. Add linenum to + suppress multiple warnings. + (load_line): Use warn_tabs. Add linenum, current_line, seen_comment + to suppress multiple warnings. + * options.c (gfc_init_options): Initialize warn_tabs. + (set_Wall): set warn_tabs for -Wall. + (gfc_post_options): Adjust flag_tabs depending on -pedantic. + (gfc_handle_option): Process command-line option -W[no-]tabs + 2006-03-13 Paul Thomas PR fortran/25378 diff --git a/gcc/fortran/gfortran.h b/gcc/fortran/gfortran.h index 99b98652a9f..0e6b21c541e 100644 --- a/gcc/fortran/gfortran.h +++ b/gcc/fortran/gfortran.h @@ -1,6 +1,6 @@ /* gfortran header file - Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006 Free Software - Foundation, Inc. + Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006 + Free Software Foundation, Inc. Contributed by Andy Vaught This file is part of GCC. @@ -1605,8 +1605,9 @@ typedef struct int warn_conversion; int warn_implicit_interface; int warn_line_truncation; - int warn_underflow; int warn_surprising; + int warn_tabs; + int warn_underflow; int warn_unused_labels; int flag_default_double; diff --git a/gcc/fortran/invoke.texi b/gcc/fortran/invoke.texi index c031cd41a2d..a65fbffa313 100644 --- a/gcc/fortran/invoke.texi +++ b/gcc/fortran/invoke.texi @@ -128,8 +128,8 @@ by type. Explanations are in the following sections. @xref{Warning Options,,Options to Request or Suppress Warnings}. @gccoptlist{ -fsyntax-only -pedantic -pedantic-errors @gol --w -Wall -Waliasing -Wconversion @gol --Wimplicit-interface -Wnonstd-intrinsics -Wsurprising -Wunderflow @gol +-w -Wall -Waliasing -Wconversion -Wimplicit-interface @gol +-Wtabs -Wnonstd-intrinsics -Wsurprising -Wunderflow @gol -Wunused-labels -Wline-truncation -W} @item Debugging Options @@ -378,8 +378,8 @@ Inhibit all warning messages. Enables commonly used warning options that which pertain to usage that we recommend avoiding and that we believe is easy to avoid. This currently includes @option{-Wunused-labels}, @option{-Waliasing}, -@option{-Wsurprising}, @option{-Wnonstd-intrinsic} and -@option{-Wline-truncation}. +@option{-Wsurprising}, @option{-Wnonstd-intrinsic}, @option{-Wno-tabs}, +and @option{-Wline-truncation}. @cindex -Waliasing option @@ -445,6 +445,15 @@ lower value is greater than its upper value. A LOGICAL SELECT construct has three CASE statements. @end itemize +@cindex -Wtabs +@cindex options, -Wtabs +@item -Wtabs +@cindex Tabs +By default, tabs are accepted as whitespace, but tabs are not members +of the Fortran Character Set. @option{-Wno-tabs} will cause a warning +to be issued if a tab is encountered. Note, @option{-Wno-tabs} is active +for @option{-pedantic}, @option{-std=f95}, and @option{-Wall}. + @cindex -Wunderflow @cindex options, -Wunderflow @item -Wunderflow diff --git a/gcc/fortran/lang.opt b/gcc/fortran/lang.opt index 17522040272..bbf5d81e21a 100644 --- a/gcc/fortran/lang.opt +++ b/gcc/fortran/lang.opt @@ -1,5 +1,5 @@ ; Options for the Fortran 95 front end. -; Copyright (C) 2003, 2004, 2005 Free Software Foundation, Inc. +; Copyright (C) 2003, 2004, 2005, 2006 Free Software Foundation, Inc. ; ; This file is part of GCC. ; @@ -61,6 +61,10 @@ Wsurprising Fortran Warn about \"suspicious\" constructs +Wtabs +Fortran +Warn about nonconforming uses of the tab character + Wunderflow Fortran Warn about underflow of numerical constant expressions diff --git a/gcc/fortran/options.c b/gcc/fortran/options.c index 6a9bec9b3a0..f0ab3993e89 100644 --- a/gcc/fortran/options.c +++ b/gcc/fortran/options.c @@ -55,8 +55,9 @@ gfc_init_options (unsigned int argc ATTRIBUTE_UNUSED, gfc_option.warn_conversion = 0; gfc_option.warn_implicit_interface = 0; gfc_option.warn_line_truncation = 0; - gfc_option.warn_underflow = 1; gfc_option.warn_surprising = 0; + gfc_option.warn_tabs = 1; + gfc_option.warn_underflow = 1; gfc_option.warn_unused_labels = 0; gfc_option.flag_default_double = 0; @@ -283,11 +284,12 @@ set_Wall (void) gfc_option.warn_aliasing = 1; gfc_option.warn_line_truncation = 1; - gfc_option.warn_underflow = 1; + gfc_option.warn_nonstd_intrinsics = 1; gfc_option.warn_surprising = 1; + gfc_option.warn_tabs = 0; + gfc_option.warn_underflow = 1; gfc_option.warn_unused_labels = 1; - gfc_option.warn_nonstd_intrinsics = 1; - + set_Wunused (1); warn_return_type = 1; warn_switch = 1; @@ -395,14 +397,18 @@ gfc_handle_option (size_t scode, const char *arg, int value) gfc_option.warn_line_truncation = value; break; - case OPT_Wunderflow: - gfc_option.warn_underflow = value; - break; - case OPT_Wsurprising: gfc_option.warn_surprising = value; break; + case OPT_Wtabs: + gfc_option.warn_tabs = value; + break; + + case OPT_Wunderflow: + gfc_option.warn_underflow = value; + break; + case OPT_Wunused_labels: gfc_option.warn_unused_labels = value; break; @@ -547,6 +553,7 @@ gfc_handle_option (size_t scode, const char *arg, int value) gfc_option.allow_std = GFC_STD_F95_OBS | GFC_STD_F95 | GFC_STD_F77; gfc_option.warn_std = GFC_STD_F95_OBS; gfc_option.max_identifier_length = 31; + gfc_option.warn_tabs = 0; break; case OPT_std_f2003: diff --git a/gcc/fortran/scanner.c b/gcc/fortran/scanner.c index 2aadc1cc68e..7c09b40a203 100644 --- a/gcc/fortran/scanner.c +++ b/gcc/fortran/scanner.c @@ -836,6 +836,7 @@ gfc_error_recovery (void) void gfc_gobble_whitespace (void) { + static int linenum = 0; locus old_loc; int c; @@ -843,6 +844,15 @@ gfc_gobble_whitespace (void) { old_loc = gfc_current_locus; c = gfc_next_char_literal (0); + /* Issue a warning for nonconforming tabs. We keep track of the line + number because the Fortran matchers will often back up and the same + line will be scanned multiple times. */ + if (!gfc_option.warn_tabs && c == '\t' + && gfc_current_locus.lb->linenum != linenum) + { + linenum = gfc_current_locus.lb->linenum; + gfc_warning_now ("Nonconforming tab character at %C"); + } } while (gfc_is_whitespace (c)); @@ -865,8 +875,9 @@ gfc_gobble_whitespace (void) static int load_line (FILE * input, char **pbuf, int *pbuflen) { + static int linenum = 0, current_line = 1; int c, maxlen, i, preprocessor_flag, buflen = *pbuflen; - int trunc_flag = 0; + int trunc_flag = 0, seen_comment = 0; char *buffer; /* Determine the maximum allowed line length. @@ -932,8 +943,24 @@ load_line (FILE * input, char **pbuf, int *pbuflen) break; } + /* Is this a fixed-form comment? */ + if (gfc_current_form == FORM_FIXED && i == 0 + && (c == '*' || c == 'c' || c == 'd')) + seen_comment = 1; + if (gfc_current_form == FORM_FIXED && c == '\t' && i <= 6) - { /* Tab expansion. */ + { + /* The error machinery isn't available at this point, so we can't + easily report line and column numbers consistent with other + parts of gfortran. */ + if (!gfc_option.warn_tabs && seen_comment == 0 + && current_line != linenum) + { + linenum = current_line; + gfc_warning_now ( + "Nonconforming tab character in column 1 of line %d", linenum); + } + while (i <= 6) { *buffer++ = ' '; @@ -985,6 +1012,7 @@ load_line (FILE * input, char **pbuf, int *pbuflen) *buffer = '\0'; *pbuflen = buflen; + current_line++; return trunc_flag; } -- 2.11.0