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]

Re: [patch, fortran] PR31495 Is this continuation line legal?


:ADDPATCH fortran:
forgot that
Jerry DeLisle wrote:
The answer to the bug reporters question is 'yes'.

I started to do some analysis on this and ended up with a state diagram with at least 6 states. I then worked up a test program with a rewrite of this section of code, dutifully implementing the state machine.

Then I decided this is too complicated and not worth it.

So I came up with the attached patch. I alternate the value of seen_ampersand in case someone does something stupid and puts multiple '&' on a line.

I eliminated the check for the lone '&' with comments, because a '!' is perfectly legit in a quoted string. I realize I could get more sophisticated in here and I may submit a later patch with a full blown state machine. For now, I think this is sufficient to close this bug.

Regression tested and new test case.

OK for trunk?

Regards,

Jerry

2007-04-21 Jerry DeLisle <jvdelisle@gcc.gnu.org>

    PR fortran/31495
    * scanner.c (load_line):  Remove check for comment after ampersand and
    adjust tracking of ampersand.


------------------------------------------------------------------------


Index: scanner.c
===================================================================
*** scanner.c (revision 124014)
--- scanner.c (working copy)
*************** load_line (FILE *input, char **pbuf, int
*** 1050,1056 ****
{
/* Check for illegal use of ampersand. See F95 Standard 3.3.1.3. */
if (gfc_current_form == FORM_FREE ! && !seen_printable && seen_ampersand)
{
if (pedantic)
gfc_error_now ("'&' not allowed by itself in line %d",
--- 1050,1056 ----
{
/* Check for illegal use of ampersand. See F95 Standard 3.3.1.3. */
if (gfc_current_form == FORM_FREE ! && !seen_printable && seen_ampersand)
{
if (pedantic)
gfc_error_now ("'&' not allowed by itself in line %d",
*************** load_line (FILE *input, char **pbuf, int
*** 1067,1091 ****
if (c == '\0')
continue;
- /* Check for illegal use of ampersand. See F95 Standard 3.3.1.3. */
if (c == '&')
! seen_ampersand = 1;
! ! if ((c != ' ' && c != '&' && c != '!') || (c == '!' && !seen_ampersand))
! seen_printable = 1;
! ! if (gfc_current_form == FORM_FREE ! && c == '!' && !seen_printable && seen_ampersand)
! {
! if (pedantic)
! gfc_error_now ("'&' not allowed by itself with comment in "
! "line %d", current_line);
else
! gfc_warning_now ("'&' not allowed by itself with comment in "
! "line %d", current_line);
! seen_printable = 1;
}
/* Is this a fixed-form comment? */
if (gfc_current_form == FORM_FIXED && i == 0
&& (c == '*' || c == 'c' || c == 'd'))
--- 1067,1083 ----
if (c == '\0')
continue;
if (c == '&')
! {
! if (seen_ampersand)
! seen_ampersand = 0;
else
! seen_ampersand = 1;
}
+ if ((c != '&' && c != '!') || (c == '!' && !seen_ampersand))
+ seen_printable = 1;
+ /* Is this a fixed-form comment? */
if (gfc_current_form == FORM_FIXED && i == 0
&& (c == '*' || c == 'c' || c == 'd'))



------------------------------------------------------------------------


! { dg-do run }
! PR31495 Is this continuation legal? program print_ascertain
character (len=50) :: str
str = "hello world &
& &
&!"
if (str.ne."hello world !") call abort
end program print_ascertain


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