public inbox for fortran@gcc.gnu.org
 help / color / mirror / Atom feed
* DEC Extension Patches: [5] Form feed as whitespace
@ 2016-04-13  0:31 Fritz Reese
  0 siblings, 0 replies; only message in thread
From: Fritz Reese @ 2016-04-13  0:31 UTC (permalink / raw)
  To: fortran

[-- Attachment #1: Type: text/plain, Size: 1059 bytes --]

All,

Attached is another DEC extension. For convenience, this patch is
based on previous DEC extension patches. That way when the other DEC
extensions are merged in the next release, this patch can be merged on
top of them. Therefore it depends on the most recently published patch:
[4] AUTOMATIC and STATIC attributes.
https://gcc.gnu.org/ml/fortran/2016-04/msg00039.html

Attached is [5] Form feed as whitespace. (Upon request an independent
patch can be submitted based directly on trunk.)

Historically the form feed character was interpreted by line printers
to cause the rest of the page to feed through the printer. Some old
Fortran source code included these characters so the source code would
better align on page boundaries when printed. In both fixed-form and
free-form this causes issues with GNU Fortran. This patch introduces a
new flag -ffeed which causes the form feed character ('\f', or ASCII
'\x0c') to be recognized as whitespace. This flag is also enabled with
the '-fdec' flag introduced in the STRUCTURE/UNION patch.

---
Fritz Reese

[-- Attachment #2: 0001-Treat-form-feed-as-whitespace-with-new-option-ffeed.patch --]
[-- Type: application/octet-stream, Size: 6856 bytes --]

From 5278a1c7d16bc1e273887d0da159d1ed4a971195 Mon Sep 17 00:00:00 2001
From: tschwinge <tschwinge@138bc75d-0d04-0410-961f-82ee72b054a4>
Date: Fri, 8 Apr 2016 13:47:37 +0000
Subject: [PATCH] Treat form feed as whitespace with new option -ffeed.

gcc/fortran/
	* invoke.texi, lang.opt, gfortran.texi: New flag -ffeed.
	* gfortran.h (gfc_is_whitespace): Include form feed with -ffeed.
	* parse.c (next_fixed): Skip '\f' as whitespace with -ffeed.

gcc/testsuite/gfortran.dg/
	* formfeed_01.f90, formfeed_02.f90, formfeed_03.f90: New testcases.
---
 gcc/fortran/gfortran.h                    |    3 ++-
 gcc/fortran/gfortran.texi                 |   12 ++++++++++++
 gcc/fortran/invoke.texi                   |    9 ++++++---
 gcc/fortran/lang.opt                      |    4 ++++
 gcc/fortran/options.c                     |    1 +
 gcc/fortran/parse.c                       |    3 +++
 gcc/testsuite/gfortran.dg/formfeed_01.f90 |    7 +++++++
 gcc/testsuite/gfortran.dg/formfeed_02.f90 |    7 +++++++
 gcc/testsuite/gfortran.dg/formfeed_03.f90 |    7 +++++++
 9 files changed, 49 insertions(+), 4 deletions(-)
 create mode 100644 gcc/testsuite/gfortran.dg/formfeed_01.f90
 create mode 100644 gcc/testsuite/gfortran.dg/formfeed_02.f90
 create mode 100644 gcc/testsuite/gfortran.dg/formfeed_03.f90

diff --git a/gcc/fortran/gfortran.h b/gcc/fortran/gfortran.h
index 37aa89f..62240c0 100644
--- a/gcc/fortran/gfortran.h
+++ b/gcc/fortran/gfortran.h
@@ -60,7 +60,8 @@ not after.
 #define MAX_SUBRECORD_LENGTH 2147483639   /* 2**31-9 */
 
 
-#define gfc_is_whitespace(c) ((c==' ') || (c=='\t'))
+#define gfc_is_whitespace(c) ((c==' ') || (c=='\t') \
+                              || (flag_feed && c=='\f'))
 
 /* Macros to check for groups of structure-like types and flavors since
    derived types, structures, maps, unions are often treated similarly. */
diff --git a/gcc/fortran/gfortran.texi b/gcc/fortran/gfortran.texi
index b110e58..0684669 100644
--- a/gcc/fortran/gfortran.texi
+++ b/gcc/fortran/gfortran.texi
@@ -1462,6 +1462,7 @@ without warning.
 * STRUCTURE and RECORD::
 * UNION and MAP::
 * AUTOMATIC and STATIC attributes::
+* Form feed as whitespace::
 @end menu
 
 @node Old-style kind specifications
@@ -2120,6 +2121,7 @@ consider @code{BACKSPACE} or @code{REWIND} to properly position
 the file before the EOF marker.  As an extension, the run-time error may
 be disabled using -std=legacy.
 
+
 @node STRUCTURE and RECORD
 @subsection @code{STRUCTURE} and @code{RECORD}
 @cindex @code{STRUCTURE}
@@ -2423,6 +2425,16 @@ subroutine f
 endsubroutine
 @end example
 
+@node Form feed as whitespace
+@subsection Form feed as whitespace
+@cindex form feed whitespace
+
+Historically, DEC allowed insertion of form feed characters ('\f', ASCII 0xC)
+at the beginning of lines for formatted output to line printers. GNU Fortran
+supports the interpretation of form feed characters in source as whitespace
+with @option{-ffeed}.
+
+
 @node Extensions not implemented in GNU Fortran
 @section Extensions not implemented in GNU Fortran
 @cindex extensions, not implemented
diff --git a/gcc/fortran/invoke.texi b/gcc/fortran/invoke.texi
index d592d15..223fd22 100644
--- a/gcc/fortran/invoke.texi
+++ b/gcc/fortran/invoke.texi
@@ -116,8 +116,7 @@ by type.  Explanations are in the following sections.
 @xref{Fortran Dialect Options,,Options controlling Fortran dialect}.
 @gccoptlist{-fall-intrinsics -fbackslash -fcray-pointer -fd-lines-as-code @gol
 -fd-lines-as-comments -fdefault-double-8 -fdefault-integer-8 @gol
--fdec -fdec-structure -fdec-static @gol
--fdefault-real-8 -fdollar-ok -ffixed-line-length-@var{n} @gol
+-fdec -fdec-structure -fdec-static -ffeed @gol
 -ffixed-line-length-none -ffree-form -ffree-line-length-@var{n} @gol
 -ffree-line-length-none -fimplicit-none -finteger-4-integer-8 @gol
 -fmax-identifier-length -fmodule-private -ffixed-form -fno-range-check @gol
@@ -239,7 +238,7 @@ full documentation.
 
 Other flags enabled by this switch are:
 @option{-fdollar-ok} @option{-fcray-pointer} @option{-fdec-structure}
-@option{-fdec-static}
+@option{-fdec-static} @option{-ffeed}
 
 @item -fdec-structure
 @opindex @code{fdec-structure}
@@ -253,6 +252,10 @@ instead where possible.
 Enable STATIC and AUTOMATIC as attributes specifying storage location.
 STATIC is equivalent to SAVE, and locals are typically AUTOMATIC by default.
 
+@item -ffeed
+@opindex @code{ffeed}
+Treat form feed ('\f') characters as whitespace in the source.
+
 @item -fdollar-ok
 @opindex @code{fdollar-ok}
 @cindex @code{$}
diff --git a/gcc/fortran/lang.opt b/gcc/fortran/lang.opt
index 71c2bce..bd90c4c 100644
--- a/gcc/fortran/lang.opt
+++ b/gcc/fortran/lang.opt
@@ -468,6 +468,10 @@ ff2c
 Fortran Var(flag_f2c)
 Use f2c calling convention.
 
+ffeed
+Fortran Var(flag_feed)
+Enable form feeds in source.
+
 ffixed-form
 Fortran RejectNegative
 Assume that the source file is fixed form.
diff --git a/gcc/fortran/options.c b/gcc/fortran/options.c
index d57d095..aa41127 100644
--- a/gcc/fortran/options.c
+++ b/gcc/fortran/options.c
@@ -54,6 +54,7 @@ set_dec_flags (int value)
 {
     gfc_option.flag_dec_structure  = value;
     flag_dec_static = value;
+    flag_feed = value;
 }
 
 
diff --git a/gcc/fortran/parse.c b/gcc/fortran/parse.c
index d8b0081..8fe4b5b 100644
--- a/gcc/fortran/parse.c
+++ b/gcc/fortran/parse.c
@@ -1203,6 +1203,9 @@ next_fixed (void)
 	  /* Comments have already been skipped by the time we get
 	     here so don't bother checking for them.  */
 
+        case '\f':
+          if (flag_feed)
+            break;
 	default:
 	  gfc_buffer_error (false);
 	  gfc_error ("Non-numeric character in statement label at %C");
diff --git a/gcc/testsuite/gfortran.dg/formfeed_01.f90 b/gcc/testsuite/gfortran.dg/formfeed_01.f90
new file mode 100644
index 0000000..42eeffb
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/formfeed_01.f90
@@ -0,0 +1,7 @@
+! { dg-do compile }
+! { dg-options "-ffeed" }
+! Test acceptance of form feed character in source with -ffeed.
+
+\f
+
+end
diff --git a/gcc/testsuite/gfortran.dg/formfeed_02.f90 b/gcc/testsuite/gfortran.dg/formfeed_02.f90
new file mode 100644
index 0000000..306c4fe
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/formfeed_02.f90
@@ -0,0 +1,7 @@
+! { dg-do compile }
+! { dg-options "-ffree-form" }
+! Test rejection of form feed character in free source without -ffeed.
+
+\f ! { dg-error "Invalid character in name" }
+
+end
diff --git a/gcc/testsuite/gfortran.dg/formfeed_03.f90 b/gcc/testsuite/gfortran.dg/formfeed_03.f90
new file mode 100644
index 0000000..7713b42
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/formfeed_03.f90
@@ -0,0 +1,7 @@
+      ! { dg-do compile }
+      ! { dg-options "-ffixed-form" }
+      ! Test rejection of form feed character in fixed source without -ffeed.
+
+\f    ! { dg-error "Non-numeric character in statement label" }
+
+      end
-- 
1.7.1


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2016-04-13  0:31 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-04-13  0:31 DEC Extension Patches: [5] Form feed as whitespace Fritz Reese

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).