This is the mail archive of the fortran@gcc.gnu.org mailing list for the GNU Fortran project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Patch, Fortran] PR34899 - Support <tab><digit> as continuation line marker (fixed form)


In standard fixed-form Fortran source code, a "normal" line begins with 6 spaces and a continuation line with 5 spaces plus some character such as '*' (there are some restrictions, see F95/F2003 standard).

A very common vendor extension is to support <tab> as replacement for 6 spaces, which also gfortran supports. However, how to create then a continuation line? Well, for g77, NAG f95, ifort, openf95, sunf95, pathscale, pgf95, Absoft the answer is: <tab><digit> where digit is not zero.

The attached patch now does the following: It replaces '\t' by 6 spaces (before it was 7) and if the the tab is followed by a non-zero digit, it places it at position 6.


Build and regression tested on x86-64-linux. OK for the trunk?

Tobias


PS: The patch was motivated to get to build http://www.chara.gsu.edu/~gudehus/fits_library_package.html. However, due to other problems it still won't build. gfortran stops first for integer_var = .true. (unless -std=legacy) and then for "real_var = ' '". Replacing them by transfer it stops at the same line as ifort.



PPS: There are dozens of possibilities with <tab><digit>, which are differently treated with the different compilers, e.g. " <tab><digit>" or "<tab> <digit>", where different compilers produce different results. With this patch " <tab><digit>" is supported while "<tab> <digit>" is rejected. The latter is in line with ifort but a regression with regards to g77, which I believe we can ignore.
2008-01-21  Tobias Burnus  <burnus@net-b.de>

	PR fortran/34899
	* scanner.c (load_line): Support <tab><digit> continuation lines.
	* invoke.texi (-Wtabs): Document this.

2008-01-21  Tobias Burnus  <burnus@net-b.de>

	PR fortran/34899
	* gfortran.dg/tab_continuation.f: New.

Index: gcc/fortran/scanner.c
===================================================================
--- gcc/fortran/scanner.c	(revision 131700)
+++ gcc/fortran/scanner.c	(working copy)
@@ -1106,6 +1106,7 @@ load_line (FILE *input, char **pbuf, int
   int trunc_flag = 0, seen_comment = 0;
   int seen_printable = 0, seen_ampersand = 0;
   char *buffer;
+  bool found_tab = false;
 
   /* Determine the maximum allowed line length.  */
   if (gfc_current_form == FORM_FREE)
@@ -1184,17 +1185,30 @@ load_line (FILE *input, char **pbuf, int
 	  && (c == '*' || c == 'c' || c == 'd'))
 	seen_comment = 1;
 
-      if (gfc_current_form == FORM_FIXED && c == '\t' && i <= 6)
+      /* Vendor extension: "<tab>1" marks a continuation line.  */
+      if (found_tab)
 	{
+	  found_tab = false;
+	  if (c >= '1' && c <= '9')
+	    {
+	      *(buffer-1) = c;
+	      continue;
+	    }
+	}
+
+      if (gfc_current_form == FORM_FIXED && c == '\t' && i < 6)
+	{
+	  found_tab = true;
+
 	  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);
+	      gfc_warning_now ("Nonconforming tab character in column %d "
+			       "of line %d", i+1, linenum);
 	    }
 
-	  while (i <= 6)
+	  while (i < 6)
 	    {
 	      *buffer++ = ' ';
 	      i++;
Index: gcc/fortran/invoke.texi
===================================================================
--- gcc/fortran/invoke.texi	(revision 131700)
+++ gcc/fortran/invoke.texi	(working copy)
@@ -499,10 +499,11 @@ A TRANSFER specifies a source that is sh
 @cindex warnings, tabs
 @cindex tabulators
 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}, @option{-std=f2003}, and
-@option{-Wall}.
+of the Fortran Character Set.  For continuation lines, a tab followed
+by a digit between 1 and 9 is supported.  @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}, @option{-std=f2003},
+and @option{-Wall}.
 
 @item -Wunderflow
 @opindex @code{Wunderflow}
Index: gcc/testsuite/gfortran.dg/tab_continuation.f
===================================================================
--- gcc/testsuite/gfortran.dg/tab_continuation.f	(revision 0)
+++ gcc/testsuite/gfortran.dg/tab_continuation.f	(revision 0)
@@ -0,0 +1,15 @@
+! { dg-do compile }
+!
+! PR fortran/34899
+!
+! Allow <tab>1 to <tab>9 as continuation marker, which is a very common
+! vendor extension.
+!
+	PARAMETER (LUMIN=11,LUMAX=20,MAPMAX=256,NPLANEMAX=999)
+	INTEGER NAXIS(0:MAPMAX,LUMIN:LUMAX),NAXIS1(0:MAPMAX,LUMIN:LUMAX),
+	1NAXIS2(0:MAPMAX,LUMIN:LUMAX),NAXIS3(0:MAPMAX,LUMIN:LUMAX)
+	end
+! { dg-warning "Nonconforming tab character in column 1 of line 8" "Nonconforming tab" {target "*-*-*"} 0 }
+! { dg-warning "Nonconforming tab character in column 1 of line 9" "Nonconforming tab" {target "*-*-*"} 0 }
+! { dg-warning "Nonconforming tab character in column 1 of line 10" "Nonconforming tab" {target "*-*-*"} 0 }
+! { dg-warning "Nonconforming tab character in column 1 of line 11" "Nonconforming tab" {target "*-*-*"} 0 }

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]