This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[Patch, fortran] PR19262 more than thirty-nine continuation lines should issue a std-warn
- From: Jerry DeLisle <jvdelisle at verizon dot net>
- To: Fortran List <fortran at gcc dot gnu dot org>
- Cc: gcc-patches <gcc-patches at gcc dot gnu dot org>
- Date: Fri, 22 Sep 2006 23:17:37 -0700
- Subject: [Patch, fortran] PR19262 more than thirty-nine continuation lines should issue a std-warn
:ADDPATCH fortran:
The attach patch modifies scanner.c to keep track of the number of continuation
lines in a statement. The F95 standard 3.3.1.4 says the number shall not exceed
39. F2003 changes this to 255. I have set the limit to default to 255. If
-pedantic is given, it is set to 39. If the limit is exceeded an error is issued.
I chose an error rather than warn because the standard states "shall not". If
others feel strongly that should be a warn, I can easily change.
Regression tested. OK for trunk?
(The attached patch includes the patch for pr19260 since it is in the same
function. I can commit them together.)
Regards
Jerry
2006-09-22 Jerry DeLisle <jvdelisle@gcc.gnu.org>
PR fortran/19262
* scanner.c (gfc_scanner_init_1): Initialize continuation line count
and set the line count limit.
(gfc_next_char_literal): Count the number of continuation lines in the
current statement and error if limit is exceeded.
Index: scanner.c
===================================================================
*** scanner.c (revision 117065)
--- scanner.c (working copy)
*************** static gfc_directorylist *include_dirs;
*** 61,66 ****
--- 61,67 ----
static gfc_file *file_head, *current_file;
static int continue_flag, end_flag, openmp_flag;
+ static int continue_count, continue_line, continue_max;
static locus openmp_locus;
gfc_source_form gfc_current_form;
*************** const char *gfc_source_file;
*** 71,76 ****
--- 72,78 ----
static FILE *gfc_src_file;
static char *gfc_src_preprocessor_lines[2];
+ extern int pedantic;
/* Main scanner initialization. */
*************** gfc_scanner_init_1 (void)
*** 81,86 ****
--- 83,99 ----
line_head = NULL;
line_tail = NULL;
+ continue_count = 0;
+ continue_line = 0;
+
+ /* F95 standard 3.3.1.4, "A free form statement shall not have more than 39
+ continuation lines." F2003 standard 3.3.1.4, "A free form statement shall
+ not have more than 255 continuation lines." Default to 255. */
+ if (pedantic)
+ continue_max = 39;
+ else
+ continue_max = 255;
+
end_flag = 0;
}
*************** gfc_next_char_literal (int in_string)
*** 585,591 ****
restart:
c = next_char ();
if (gfc_at_end ())
! return c;
if (gfc_current_form == FORM_FREE)
{
--- 598,607 ----
restart:
c = next_char ();
if (gfc_at_end ())
! {
! continue_count = 0;
! return c;
! }
if (gfc_current_form == FORM_FREE)
{
*************** restart:
*** 644,651 ****
else
gfc_advance_line ();
! /* We've got a continuation line and need to find where it continues.
! First eat any comment lines. */
gfc_skip_comments ();
if (prev_openmp_flag != openmp_flag)
--- 660,679 ----
else
gfc_advance_line ();
! /* We've got a continuation line. If we are on the very next line after
! the last continuation, increment the continuation line count and
! check whether the limit has been exceeded. */
! if (gfc_current_locus.lb->linenum == continue_line + 1)
! {
! if (++continue_count == continue_max)
! {
! continue_count = 0;
! gfc_error_now ("Too many continuations in statement at %C");
! }
! }
! continue_line = gfc_current_locus.lb->linenum;
!
! /* Now find where it continues. First eat any comment lines. */
gfc_skip_comments ();
if (prev_openmp_flag != openmp_flag)
*************** restart:
*** 681,690 ****
if (c != '&')
{
! if (in_string && gfc_option.warn_ampersand)
! gfc_warning ("Missing '&' in continued character constant at %C");
!
! gfc_current_locus.nextc--;
}
}
else
--- 709,726 ----
if (c != '&')
{
! if (in_string)
! {
! if (gfc_option.warn_ampersand)
! gfc_warning ("Missing '&' in continued character constant at %C");
! gfc_current_locus.nextc--;
! }
! else
! {
! c = ' ';
! gfc_current_locus = old_loc;
! goto done;
! }
}
}
else
*************** not_continuation:
*** 749,754 ****
--- 785,792 ----
gfc_current_locus = old_loc;
done:
+ if (c == '\n')
+ continue_count = 0;
continue_flag = 0;
return c;
}
! { dg-do compile }
! { dg-options -pedantic }
! PR 19262 Test limit on line continuations. Test case derived form case in PR
! by Steve Kargl. Submitted by Jerry DeLisle <jvdelisle@gcc.gnu.org>
print *, &
"1" // & ! 1
"2" // & ! 2
"3" // & ! 3
"4" // & ! 4
"5" // & ! 5
"6" // & ! 6
"7" // & ! 7
"8" // & ! 8
"9" // & ! 9
"0" // & ! 10
"1" // & ! 11
"2" // & ! 12
"3" // & ! 13
"4" // & ! 14
"5" // & ! 15
"6" // & ! 16
"7" // & ! 17
"8" // & ! 18
"9" // & ! 19
"0" // & ! 20
"1" // & ! 21
"2" // & ! 22
"3" // & ! 23
"4" // & ! 24
"5" // & ! 25
"6" // & ! 26
"7" // & ! 27
"8" // & ! 28
"9" // & ! 29
"0" // & ! 30
"1" // & ! 31
"2" // & ! 32
"3" // & ! 33
"4" // & ! 34
"5" // & ! 35
"6" // & ! 36
"7" // & ! 37
"8" // & ! 38
"9"
print *, &
"1" // & ! 1
"2" // & ! 2
"3" // & ! 3
"4" // & ! 4
"5" // & ! 5
"6" // & ! 6
"7" // & ! 7
"8" // & ! 8
"9" // & ! 9
"0" // & ! 10
"1" // & ! 11
"2" // & ! 12
"3" // & ! 13
"4" // & ! 14
"5" // & ! 15
"6" // & ! 16
"7" // & ! 17
"8" // & ! 18
"9" // & ! 19
"0" // & ! 20
"1" // & ! 21
"2" // & ! 22
"3" // & ! 23
"4" // & ! 24
"5" // & ! 25
"6" // & ! 26
"7" // & ! 27
"8" // & ! 28
"9" // & ! 29
"0" // & ! 30
"1" // & ! 31
"2" // & ! 32
"3" // & ! 33
"4" // & ! 34
"5" // & ! 35
"6" // & ! 36
"7" // & ! 37
"8" // & ! 38
"9" // & ! 39
"0" ! { dg-error "Too many continuations in statement" }
end