This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC 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/RFC] Fix fortran/14569


This tries to address PR14569 as suggested in the audit thread
by remembering truncated lines in the scanner and defer warning
to the parser.  Somehow error reporting gets in the way of
some warnings though.

F.i we produce for

      SUBROUTINE foo(x,y)
      x =							  4.3	+
1.2
      END

 In file /tmp/t2.f:2

      x =							  4.3
								       1
Warning: Line truncated at (1)

but for

      SUBROUTINE foo(x,y)
      x =							  4.3 +
1.2
      END

 In file /tmp/t2.f:2

      x =							  4.3 +
								      1
Error: Syntax error in expression at (1)


Any idea how to fix the above?


Bootstrapped on x86_64-unknown-linux-gnu, testing in progress.
Ok for mainline anyway if testing succeeds?


Richard.



2005-04-15  Richard Guenther  <rguenth@gcc.gnu.org>

	PR fortran/14569
	* gfortran.h (gfc_linebuf): Add truncated field.
	* parse.c (next_statement): Handle warning for truncated
	lines.
	* scanner.c (load_line): Return if line was truncated.
	No longer warn for truncated lines.  Remove unused parameters.
	(load_file): Store load_line return value to linebuf.

Index: gfortran.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/fortran/gfortran.h,v
retrieving revision 1.64
diff -c -3 -p -r1.64 gfortran.h
*** gfortran.h	14 Apr 2005 16:29:31 -0000	1.64
--- gfortran.h	15 Apr 2005 14:43:49 -0000
*************** typedef struct gfc_linebuf
*** 481,486 ****
--- 481,488 ----
    struct gfc_file *file;
    struct gfc_linebuf *next;

+   int truncated;
+
    char line[1];
  } gfc_linebuf;

Index: parse.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/fortran/parse.c,v
retrieving revision 1.25
diff -c -3 -p -r1.25 parse.c
*** parse.c	23 Feb 2005 19:02:13 -0000	1.25
--- parse.c	15 Apr 2005 14:43:49 -0000
*************** next_statement (void)
*** 479,485 ****
        gfc_buffer_error (1);

        if (gfc_at_eol ())
! 	gfc_advance_line ();

        gfc_skip_comments ();

--- 479,491 ----
        gfc_buffer_error (1);

        if (gfc_at_eol ())
! 	{
! 	  if (gfc_option.warn_line_truncation
! 	      && gfc_current_locus.lb->truncated)
! 	    gfc_warning_now ("Line truncated at %C");
!
! 	  gfc_advance_line ();
! 	}

        gfc_skip_comments ();

Index: scanner.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/fortran/scanner.c,v
retrieving revision 1.16
diff -c -3 -p -r1.16 scanner.c
*** scanner.c	18 Jan 2005 12:11:54 -0000	1.16
--- scanner.c	15 Apr 2005 14:43:49 -0000
*************** gfc_gobble_whitespace (void)
*** 677,688 ****
     need be.
     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.  */

! static void
! load_line (FILE * input, char **pbuf, char *filename, int linenum)
  {
!   int c, maxlen, i, trunc_flag, preprocessor_flag;
    static int buflen = 0;
    char *buffer;

--- 677,690 ----
     need be.
     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.  */

! static int
! load_line (FILE * input, char **pbuf)
  {
!   int c, maxlen, i, preprocessor_flag;
!   int trunc_flag = 0;
    static int buflen = 0;
    char *buffer;

*************** load_line (FILE * input, char **pbuf, ch
*** 767,781 ****
  	      c = fgetc (input);
  	      if (c == '\n' || c == EOF)
  		break;
-
- 	      if (gfc_option.warn_line_truncation
- 		  && trunc_flag
- 		  && !gfc_is_whitespace (c))
- 		{
- 		  gfc_warning_now ("%s:%d: Line is being truncated",
- 				   filename, linenum);
- 		  trunc_flag = 0;
- 		}
  	    }

  	  ungetc ('\n', input);
--- 769,774 ----
*************** load_line (FILE * input, char **pbuf, ch
*** 791,796 ****
--- 784,791 ----
        *buffer++ = ' ';

    *buffer = '\0';
+
+   return trunc_flag;
  }


*************** load_file (char *filename, bool initial)
*** 1034,1040 ****

    for (;;)
      {
!       load_line (input, &line, filename, current_file->line);

        len = strlen (line);
        if (feof (input) && len == 0)
--- 1029,1035 ----

    for (;;)
      {
!       int trunc = load_line (input, &line);

        len = strlen (line);
        if (feof (input) && len == 0)
*************** load_file (char *filename, bool initial)
*** 1066,1071 ****
--- 1061,1067 ----
        b->linenum = current_file->line++;
  #endif
        b->file = current_file;
+       b->truncated = trunc;
        strcpy (b->line, line);

        if (line_head == NULL)


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