[gfortran,patch] add -fbackslash

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

[gfortran,patch] add -fbackslash

FX Coudert
This patch adds -fbackslash/-fno-backslash flags, for compatibility with
g77 (and many other compilers). Two testcases to go with, and the ChangeLog.

Don't know what more I can say. The core of the patch is really trivial,
so I hope some can approve this one quickly.

Regtested on i686-linux. OK for mainline and 4.0?

2005-06-19  Francois-Xavier Coudert  <[hidden email]>

        * gfortran.h: Add flag_backslash compile-time option.
        * lang.opt: Add support for -fbackslash option.
        * options.c: Likewise.
        * primary.c: Implement behavior for -fno-backslash.
        * invoke.texi: Add doc for -fbackslash option.
        * gfortran.texi: Remove mention of -fno-backslash as a
        possible extension.


2005-06-19  Francois-Xavier Coudert  <[hidden email]>

        * gfortran.dg/backslash_1.f90: New test.
        * gfortran.dg/backslash_2.f90: New test.


Index: gfortran.h
===================================================================
RCS file: /cvsroot/gcc/gcc/gcc/fortran/gfortran.h,v
retrieving revision 1.70
diff -u -3 -p -r1.70 gfortran.h
--- gfortran.h 30 May 2005 22:16:08 -0000 1.70
+++ gfortran.h 19 Jun 2005 20:56:36 -0000
@@ -1421,6 +1422,7 @@ typedef struct
   int flag_pack_derived;
   int flag_repack_arrays;
   int flag_f2c;
+  int flag_backslash;
 
   int q_kind;
 
Index: gfortran.texi
===================================================================
RCS file: /cvsroot/gcc/gcc/gcc/fortran/gfortran.texi,v
retrieving revision 1.15
diff -u -3 -p -r1.15 gfortran.texi
--- gfortran.texi 1 Jun 2005 19:17:33 -0000 1.15
+++ gfortran.texi 19 Jun 2005 20:56:36 -0000
@@ -504,10 +504,6 @@ Flag to cause the compiler to distinguis
 names.  The Fortran 95 standard does not distinguish them.
 
 @item
-Compile switch for changing the interpretation of a backslash from a
-character to ``C''-style escape characters.
-
-@item
 Compile flag to generate code for array conformance checking (suggest -CC).
 
 @item
Index: invoke.texi
===================================================================
RCS file: /cvsroot/gcc/gcc/gcc/fortran/invoke.texi,v
retrieving revision 1.16
diff -u -3 -p -r1.16 invoke.texi
--- invoke.texi 5 Jun 2005 13:13:09 -0000 1.16
+++ invoke.texi 19 Jun 2005 20:56:36 -0000
@@ -208,6 +208,15 @@ Do nothing if this is already the defaul
 @cindex character set
 Allow @samp{$} as a valid character in a symbol name.
 
+@cindex -fbackslash option
+@cindex options, -fbackslash
+@item -fbackslash
+@cindex backslash
+@cindex escape characters
+@item
+Compile switch for changing the interpretation of a backslash from a
+character to ``C''-style escape characters.
+
 @cindex -ffixed-line-length-@var{n} option
 @cindex options, -ffixed-line-length-@var{n}
 @item -ffixed-line-length-@var{n}
Index: lang.opt
===================================================================
RCS file: /cvsroot/gcc/gcc/gcc/fortran/lang.opt,v
retrieving revision 1.13
diff -u -3 -p -r1.13 lang.opt
--- lang.opt 30 May 2005 22:16:08 -0000 1.13
+++ lang.opt 19 Jun 2005 20:56:36 -0000
@@ -85,6 +85,10 @@ fdollar-ok
 F95
 Allow dollar signs in entity names
 
+fbackslash
+F95
+Specify that backslash in string introduces an escape character
+
 fdump-parse-tree
 F95
 Display the code tree after parsing.
Index: options.c
===================================================================
RCS file: /cvsroot/gcc/gcc/gcc/fortran/options.c,v
retrieving revision 1.20
diff -u -3 -p -r1.20 options.c
--- options.c 30 May 2005 22:16:08 -0000 1.20
+++ options.c 19 Jun 2005 20:56:36 -0000
@@ -70,6 +70,7 @@ gfc_init_options (unsigned int argc ATTR
   gfc_option.flag_no_backend = 0;
   gfc_option.flag_pack_derived = 0;
   gfc_option.flag_repack_arrays = 0;
+  gfc_option.flag_backslash = 1;
 
   gfc_option.q_kind = gfc_default_double_kind;
 
@@ -233,6 +234,10 @@ gfc_handle_option (size_t scode, const c
       gfc_option.flag_dollar_ok = value;
       break;
 
+    case OPT_fbackslash:
+      gfc_option.flag_backslash = value;
+      break;
+
     case OPT_fdump_parse_tree:
       gfc_option.verbose = value;
       break;
Index: primary.c
===================================================================
RCS file: /cvsroot/gcc/gcc/gcc/fortran/primary.c,v
retrieving revision 1.25
diff -u -3 -p -r1.25 primary.c
--- primary.c 25 Apr 2005 00:08:59 -0000 1.25
+++ primary.c 19 Jun 2005 20:56:36 -0000
@@ -637,7 +637,7 @@ next_string_char (char delimiter)
   if (c == '\n')
     return -2;
 
-  if (c == '\\')
+  if (gfc_option.flag_backslash && c == '\\')
     {
       old_locus = gfc_current_locus;
 

! { dg-do run }
! { dg-options "-fno-backslash" }
      character(len=4) a
      open (10, status='scratch')
      write (10,'(A)') '1\n2'
      rewind (10)
      read (10,'(A)') a
      if (a /= '1\n2') call abort
      end

! { dg-do run }
! { dg-options "-fbackslash" }
      integer :: i, e
      open (10, status='scratch')
      write (10,'(A)') '1\n2'
      rewind (10)
      read (10,*,iostat=e) i
      if (e /= 0 .or. i /= 1) call abort
      read (10,*,iostat=e) i
      if (e /= 0 .or. i /= 2) call abort
      end
Reply | Threaded
Open this post in threaded view
|

Re: [gfortran,patch] add -fbackslash

Steve Kargl
On Sun, Jun 19, 2005 at 11:28:12PM +0200, FX Coudert wrote:
> This patch adds -fbackslash/-fno-backslash flags, for compatibility with
> g77 (and many other compilers). Two testcases to go with, and the ChangeLog.
>

OK.

--
Steve
Reply | Threaded
Open this post in threaded view
|

Re: [gfortran,patch] add -fbackslash

Tobias Schlüter
In reply to this post by FX Coudert
FX Coudert wrote:

> Index: invoke.texi
> ===================================================================
> RCS file: /cvsroot/gcc/gcc/gcc/fortran/invoke.texi,v
> retrieving revision 1.16
> diff -u -3 -p -r1.16 invoke.texi
> --- invoke.texi 5 Jun 2005 13:13:09 -0000 1.16
> +++ invoke.texi 19 Jun 2005 20:56:36 -0000
> @@ -208,6 +208,15 @@ Do nothing if this is already the defaul
>  @cindex character set
>  Allow @samp{$} as a valid character in a symbol name.
>  
> +@cindex -fbackslash option
> +@cindex options, -fbackslash
> +@item -fbackslash
> +@cindex backslash
> +@cindex escape characters
> +@item
> +Compile switch for changing the interpretation of a backslash from a
> +character to ``C''-style escape characters.
> +
>  @cindex -ffixed-line-length-@var{n} option
>  @cindex options, -ffixed-line-length-@var{n}
>  @item -ffixed-line-length-@var{n}

We default to -fbackslash, so you should document -fno-backslash.  (Not in
lang.opt, though.  The convention seems to be the other way round there.

Apart from that, this is of course ok

- Tobi
Reply | Threaded
Open this post in threaded view
|

Re: [gfortran,patch] add -fbackslash

FX Coudert
> We default to -fbackslash, so you should document -fno-backslash.  (Not in
> lang.opt, though.  The convention seems to be the other way round there.

Committed with this change.

FX