re PR fortran/32223 (Backslash handling inconsistent)
authorSteven G. Kargl <kargl@gcc.gnu.org>
Fri, 8 Jun 2007 04:49:23 +0000 (04:49 +0000)
committerJerry DeLisle <jvdelisle@gcc.gnu.org>
Fri, 8 Jun 2007 04:49:23 +0000 (04:49 +0000)
2007-06-07  Steven G. Kargl  <kargl@gcc.gnu.org>
    Jerry DeLisle  <jvdelisle@gcc.gnu.org>

PR fortran/32223
* match.c (gfc_match_special_char): New function.  Match special char.
Add handling '\0'.
* match.h: Add prototype.
* io.c (next_char): Use it.
* primary.c (next_string_char): Ditto.

Co-Authored-By: Jerry DeLisle <jvdelisle@gcc.gnu.org>
From-SVN: r125557

gcc/fortran/ChangeLog
gcc/fortran/io.c
gcc/fortran/match.c
gcc/fortran/match.h
gcc/fortran/primary.c

index 4a7edfdacabbcbafa28602680148388f804e17b7..248bbf886350755871082e138cb13774d3ed9836 100644 (file)
@@ -1,3 +1,13 @@
+2007-06-07  Steven G. Kargl  <kargl@gcc.gnu.org>
+           Jerry DeLisle  <jvdelisle@gcc.gnu.org>
+
+       PR fortran/32223
+       * match.c (gfc_match_special_char): New function.  Match special char.
+       Add handling '\0'.
+       * match.h: Add prototype.
+       * io.c (next_char): Use it.
+       * primary.c (next_string_char): Ditto.
+
 2007-06-06  Steven G. Kargl  <kargl@gcc.gnu.org>
 
        * decl.c: Miscellaneous whitespace fixes.
index 8e81d6a19fea3de5786d04b30b6b92cd277a7261..4d12b2416fb36e062ac92ba4376fc0adaa1d9e8b 100644 (file)
@@ -141,40 +141,17 @@ next_char (int in_string)
 
   if (gfc_option.flag_backslash && c == '\\')
     {
+      int tmp;
       locus old_locus = gfc_current_locus;
 
-      switch (gfc_next_char_literal (1))
-       {
-       case 'a':
-         c = '\a';
-         break;
-       case 'b':
-         c = '\b';
-         break;
-       case 't':
-         c = '\t';
-         break;
-       case 'f':
-         c = '\f';
-         break;
-       case 'n':
-         c = '\n';
-         break;
-       case 'r':
-         c = '\r';
-         break;
-       case 'v':
-         c = '\v';
-         break;
-       case '\\':
-         c = '\\';
-         break;
+      /* Use a temp variable to avoid side effects from gfc_match_special_char
+        since it uses an int * for its argument.  */
+      tmp = (int)c;
 
-       default:
-         /* Unknown backslash codes are simply not expanded.  */
-         gfc_current_locus = old_locus;
-         break;
-       }
+      if (gfc_match_special_char (&tmp) == MATCH_NO)
+       gfc_current_locus = old_locus;
+
+      c = (char)tmp;
 
       if (!(gfc_option.allow_std & GFC_STD_GNU) && !inhibit_warnings)
        gfc_warning ("Extension: backslash character at %C");
index 0f99a521189ab78e1b82877a335ead9d38553fd6..e544d6d2a32339694f69de808c641addceeb79a4 100644 (file)
@@ -64,6 +64,56 @@ mstring intrinsic_operators[] = {
 
 /******************** Generic matching subroutines ************************/
 
+/* See if the next character is a special character that has
+   escaped by a \ via the -fbackslash option.  */
+
+match
+gfc_match_special_char (int *c)
+{
+
+  match m;
+
+  m = MATCH_YES;
+
+  switch (gfc_next_char_literal (1))
+    {
+    case 'a':
+      *c = '\a';
+      break;
+    case 'b':
+      *c = '\b';
+      break;
+    case 't':
+      *c = '\t';
+      break;
+    case 'f':
+      *c = '\f';
+      break;
+    case 'n':
+      *c = '\n';
+      break;
+    case 'r':
+      *c = '\r';
+      break;
+    case 'v':
+      *c = '\v';
+      break;
+    case '\\':
+      *c = '\\';
+      break;
+    case '0':
+      *c = '\0';
+      break;
+    default:
+      /* Unknown backslash codes are simply not expanded.  */
+      m = MATCH_NO;
+      break;
+    }
+
+  return m;
+}
+
+
 /* In free form, match at least one space.  Always matches in fixed
    form.  */
 
index ffba10251a4b3b3ac5ef67e1dee1b15d57514050..8a309c5f2dd69ed50f544b4a958a8ce6e106ccea 100644 (file)
@@ -39,6 +39,7 @@ extern gfc_st_label *gfc_statement_label;
 /* match.c.  */
 
 /* Generic match subroutines.  */
+match gfc_match_special_char (int *);
 match gfc_match_space (void);
 match gfc_match_eos (void);
 match gfc_match_small_literal_int (int *, int *);
index ce81f44fd2d1da36a3c594e29222088ad7911a6b..90b1d6840e4e55c3d60abd0c6604b3dc9f2ff663 100644 (file)
@@ -732,38 +732,8 @@ next_string_char (char delimiter)
     {
       old_locus = gfc_current_locus;
 
-      switch (gfc_next_char_literal (1))
-       {
-       case 'a':
-         c = '\a';
-         break;
-       case 'b':
-         c = '\b';
-         break;
-       case 't':
-         c = '\t';
-         break;
-       case 'f':
-         c = '\f';
-         break;
-       case 'n':
-         c = '\n';
-         break;
-       case 'r':
-         c = '\r';
-         break;
-       case 'v':
-         c = '\v';
-         break;
-       case '\\':
-         c = '\\';
-         break;
-
-       default:
-         /* Unknown backslash codes are simply not expanded */
-         gfc_current_locus = old_locus;
-         break;
-       }
+      if (gfc_match_special_char (&c) == MATCH_NO)
+       gfc_current_locus = old_locus;
 
       if (!(gfc_option.allow_std & GFC_STD_GNU) && !inhibit_warnings)
        gfc_warning ("Extension: backslash character at %C");