]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR fortran/21302 (Max line length in free form mode)
authorBernhard Fischer <rep.nop@aon.at>
Wed, 30 Nov 2005 23:57:44 +0000 (00:57 +0100)
committerSteven G. Kargl <kargl@gcc.gnu.org>
Wed, 30 Nov 2005 23:57:44 +0000 (23:57 +0000)
2005-11-30  Bernhard Fischer <rep.nop@aon.at>
PR fortran/21302
* lang.opt: New options -ffree-line-length- and -ffree-line-length-none.
* gfortran.h: Add free_line_length and add description of
free_line_length and fixed_line_length.
* options.c (gfc_init_options, gfc_handle_option): Initialize
and set free_line_length and fixed_line_length.
* scanner.c (load_line): Set free_line_length to 132 and
fixed_line_length to 72 or user requested values.
* scanner.c: Typo in comment.
* invoke.texi: Document -ffree-line-length- and
-ffree-line-length-none

gfortran.dg/line_length_1.f: New test:
gfortran.dg/line_length_2.f90: Ditto.

From-SVN: r107745

gcc/fortran/ChangeLog
gcc/fortran/gfortran.h
gcc/fortran/invoke.texi
gcc/fortran/lang.opt
gcc/fortran/options.c
gcc/fortran/scanner.c
gcc/testsuite/ChangeLog
gcc/testsuite/gfortran.dg/line_length_1.f [new file with mode: 0644]
gcc/testsuite/gfortran.dg/line_length_2.f90 [new file with mode: 0644]

index a55a82898d396eca96814c0bcb281b9d884af388..f787fb76e57e028110ff5bf52eec290a4a7fafaf 100644 (file)
@@ -1,3 +1,18 @@
+2005-11-30  Bernhard Fischer <rep.nop@aon.at>
+
+       PR fortran/21302
+       * lang.opt: New options -ffree-line-length- and -ffree-line-length-none.
+       * gfortran.h: Add free_line_length and add description of
+       free_line_length and fixed_line_length.
+       * options.c (gfc_init_options, gfc_handle_option): Initialize
+       and set free_line_length and fixed_line_length.
+       * scanner.c (load_line): Set free_line_length to 132 and
+       fixed_line_length to 72 or user requested values.
+       * scanner.c: Typo in comment.
+       * invoke.texi: Document -ffree-line-length- and
+       -ffree-line-length-none
+
+
 2005-11-30  Paul Thomas  <pault@gcc.gnu.org>
 
        PR fortran/15809
index dd74019447705aaf2403026a91f6820066eb41cf..83de26754892a65ea044b4624c6d7b964c78e6c5 100644 (file)
@@ -1460,7 +1460,20 @@ typedef struct
 {
   char *module_dir;
   gfc_source_form source_form;
-  int fixed_line_length;
+  /* When fixed_line_length or free_line_length are 0, the whole line is used.
+
+     Default is -1, the maximum line length mandated by the respective source
+     form is used:
+     for FORM_FREE GFC_MAX_LINE (132)
+     else 72.
+
+     If fixed_line_length or free_line_length is not 0 nor -1 then the user has
+     requested a specific line-length.
+
+     If the user requests a fixed_line_length <7 then gfc_init_options()
+     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_identifier_length;
   int verbose;
 
index d482b32a54e09a643a87f14ab97bce2415f3c648..5816207d4a6b798930e1e88d017d447e5ab03121 100644 (file)
@@ -119,6 +119,7 @@ by type.  Explanations are in the following sections.
 -fdollar-ok  -fimplicit-none  -fmax-identifier-length @gol
 -std=@var{std} -fd-lines-as-code -fd-lines-as-comments @gol
 -ffixed-line-length-@var{n}  -ffixed-line-length-none @gol
+-ffree-line-length-@var{n}  -ffree-line-length-none @gol
 -fdefault-double-8  -fdefault-integer-8  -fdefault-real-8 @gol
 -fcray-pointer }
 
@@ -251,6 +252,20 @@ to them to fill out the line.
 @option{-ffixed-line-length-0} means the same thing as
 @option{-ffixed-line-length-none}.
 
+@cindex -ffree-line-length-@var{n} option
+@cindex options, -ffree-line-length-@var{n}
+@item -ffree-line-length-@var{n}
+@cindex source file format
+@cindex lines, length
+@cindex length of source lines
+@cindex free form
+@cindex limits, lengths of source lines
+Set column after which characters are ignored in typical free-form
+lines in the source file. For free-form, the default value is 132.
+@var{n} may be @samp{none}, meaning that the entire line is meaningful.
+@option{-ffree-line-length-0} means the same thing as
+@option{-ffree-line-length-none}.
+
 @cindex -fmax-identifier-length=@var{n} option
 @cindex option -fmax-identifier-length=@var{n}
 @item -fmax-identifier-length=@var{n}
index 66f79db3bee28d2e59ade0f1602c4e4f683a1015..95388e5afe1baf10b09fe839618e840ae859f302 100644 (file)
@@ -141,6 +141,14 @@ ffixed-line-length-
 Fortran RejectNegative Joined UInteger
 -ffixed-line-length-<n>                Use n as character line width in fixed mode
 
+ffree-line-length-none
+Fortran RejectNegative
+Allow arbitrary character line width in free mode
+
+ffree-line-length-
+Fortran RejectNegative Joined UInteger
+-ffree-line-length-<n>         Use n as character line width in free mode
+
 fmax-identifier-length=
 Fortran RejectNegative Joined UInteger
 -fmax-identifier-length=<n>    Maximum identifier length
index a39876b80b5f48553d63d25d6ba96c85d95eee64..64fa8a2744146d73571521df5b0bce79f1465ec7 100644 (file)
@@ -46,7 +46,8 @@ gfc_init_options (unsigned int argc ATTRIBUTE_UNUSED,
   gfc_source_file = NULL;
   gfc_option.module_dir = NULL;
   gfc_option.source_form = FORM_UNKNOWN;
-  gfc_option.fixed_line_length = 72;
+  gfc_option.fixed_line_length = -1;
+  gfc_option.free_line_length = -1;
   gfc_option.max_identifier_length = GFC_MAX_SYMBOL_LEN;
   gfc_option.verbose = 0;
 
@@ -423,10 +424,28 @@ gfc_handle_option (size_t scode, const char *arg, int value)
       gfc_option.source_form = FORM_FIXED;
       break;
 
+    case OPT_ffixed_line_length_none:
+      gfc_option.fixed_line_length = 0;
+      break;
+
+    case OPT_ffixed_line_length_:
+      if (value != 0 && value < 7)
+       gfc_fatal_error ("Fixed line length must be at least seven.");
+      gfc_option.fixed_line_length = value;
+      break;
+
     case OPT_ffree_form:
       gfc_option.source_form = FORM_FREE;
       break;
 
+    case OPT_ffree_line_length_none:
+      gfc_option.free_line_length = 0;
+      break;
+
+    case OPT_ffree_line_length_:
+      gfc_option.free_line_length = value;
+      break;
+
     case OPT_funderscoring:
       gfc_option.flag_underscoring = value;
       break;
@@ -459,16 +478,6 @@ gfc_handle_option (size_t scode, const char *arg, int value)
       gfc_option.flag_repack_arrays = value;
       break;
 
-    case OPT_ffixed_line_length_none:
-      gfc_option.fixed_line_length = 0;
-      break;
-
-    case OPT_ffixed_line_length_:
-      if (value != 0 && value < 7)
-       gfc_fatal_error ("Fixed line length must be at least seven.");
-      gfc_option.fixed_line_length = value;
-      break;
-
     case OPT_fmax_identifier_length_:
       if (value > GFC_MAX_SYMBOL_LEN)
        gfc_fatal_error ("Maximum supported idenitifier length is %d",
index 883576166ffa6ad9bc953d7bdf590a45c2594c2b..4b76f9c73e9be09e7f6a7b693489d790913562b7 100644 (file)
@@ -694,7 +694,7 @@ gfc_gobble_whitespace (void)
    In fixed mode, we expand a tab that occurs within the statement
    label region to expand to spaces that leave the next character in
    the source region.
-   load_line returns wether the line was truncated.  */
+   load_line returns whether the line was truncated.  */
 
 static int
 load_line (FILE * input, char **pbuf, int *pbuflen)
@@ -703,11 +703,25 @@ load_line (FILE * input, char **pbuf, int *pbuflen)
   int trunc_flag = 0;
   char *buffer;
 
-  /* Determine the maximum allowed line length.  */
+  /* Determine the maximum allowed line length.
+     The default for free-form is GFC_MAX_LINE, for fixed-form or for
+     unknown form it is 72. Refer to the documentation in gfc_option_t.  */
   if (gfc_current_form == FORM_FREE)
-    maxlen = GFC_MAX_LINE;
+    {
+      if (gfc_option.free_line_length == -1)
+       maxlen = GFC_MAX_LINE;
+      else
+       maxlen = gfc_option.free_line_length;
+    }
+  else if (gfc_current_form == FORM_FIXED)
+    {
+      if (gfc_option.fixed_line_length == -1)
+       maxlen = 72;
+      else
+       maxlen = gfc_option.fixed_line_length;
+    }
   else
-    maxlen = gfc_option.fixed_line_length;
+    maxlen = 72;
 
   if (*pbuf == NULL)
     {
@@ -778,7 +792,7 @@ load_line (FILE * input, char **pbuf, int *pbuflen)
            }
        }
       else if (i >= maxlen)
-       {                       
+       {
          /* Truncate the rest of the line.  */
          for (;;)
            {
@@ -1055,7 +1069,7 @@ load_file (const char *filename, bool initial)
   line = NULL;
   line_len = 0;
 
-  for (;;) 
+  for (;;)
     {
       int trunc = load_line (input, &line, &line_len);
 
index 901f023ceca42b1f889d05020d339cf32a522850..2f0f297ca5cf77230cb5d3aadc6b6be155f1be30 100644 (file)
@@ -1,4 +1,8 @@
-2005-11-30  Richard Guenther  <rguenther@suse.de>
+2005-11-30  Bernhard Fischer  <rep.nop@aon.at>
+
+       PR fortran/21302
+       * gfortran.dg/line_length_1.f: New test.
+       * gfortran.dg/line_length_2.f90: Ditto.
 
        PR tree-optimization/21655
        * g++.dg/tree-ssa/pr14814.C: Remove XFAIL.
diff --git a/gcc/testsuite/gfortran.dg/line_length_1.f b/gcc/testsuite/gfortran.dg/line_length_1.f
new file mode 100644 (file)
index 0000000..1ac8033
--- /dev/null
@@ -0,0 +1,7 @@
+! Testcase for -ffixed-line-length-none
+! { dg-do compile }
+! { dg-options "-ffixed-line-length-none" }
+      program one
+       if (abs(aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa).gt.999.d0.or.abs(bbbbbbbbbbbbbbbbbbbbbbbbbbbbbb).gt.999.d0.or.abs(cccccccccccccccccccc).gt.999.d0) THEN
+       endif
+      end program one
diff --git a/gcc/testsuite/gfortran.dg/line_length_2.f90 b/gcc/testsuite/gfortran.dg/line_length_2.f90
new file mode 100644 (file)
index 0000000..e1ab722
--- /dev/null
@@ -0,0 +1,8 @@
+! Testcase for -ffree-line-length-none
+! See PR fortran/21302
+! { dg-do compile }
+! { dg-options "-ffree-line-length-none" }
+program two
+ if (abs(aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa).gt.999.d0.or.abs(bbbbbbbbbbbbbbbbbbbbbbbbbbbbbb).gt.999.d0.or.abs(cccccccccccccccccccc).gt.999.d0) THEN
+ endif
+end program two