This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH] Move common code to a new function
- From: Steve Kargl <sgk at troutmask dot apl dot washington dot edu>
- To: fortran at gcc dot gnu dot org, gcc-patches at gcc dot gnu dot org
- Date: Sun, 15 Apr 2007 18:04:18 -0700
- Subject: [PATCH] Move common code to a new function
The attached patch has been compiled and regression tested
on i386-*-freebsd. It moves common code in primary.c and
io.c into a new function in match.c. The code should be
self-explanatory. Ok for mainline?
2007-04-15 Steven G. Kargl <kargl@gcc.gnu.org>
* match.c (gfc_match_special_char): New function. Match special char.
* match.h: Add prototype.
* io.c (next_char): Use it.
* primary.c (next_string_char): Ditto.
--
Steve
Index: io.c
===================================================================
--- io.c (revision 123850)
+++ io.c (working copy)
@@ -142,39 +142,8 @@ next_char (int in_string)
if (gfc_option.flag_backslash && c == '\\')
{
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;
-
- 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");
Index: match.c
===================================================================
--- match.c (revision 123850)
+++ match.c (working copy)
@@ -91,6 +91,53 @@ gfc_match_space (void)
}
+/* 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;
+ default:
+ /* Unknown backslash codes are simply not expanded. */
+ m = MATCH_NO;
+ break;
+ }
+
+ return m;
+}
+
+
/* Match an end of statement. End of statement is optional
whitespace, followed by a ';' or '\n' or comment '!'. If a
semicolon is found, we continue to eat whitespace and semicolons. */
Index: match.h
===================================================================
--- match.h (revision 123850)
+++ match.h (working copy)
@@ -40,6 +40,7 @@ extern gfc_st_label *gfc_statement_label
/* Generic match subroutines */
match gfc_match_space (void);
match gfc_match_eos (void);
+match gfc_match_special_char (int *);
match gfc_match_small_literal_int (int *, int *);
match gfc_match_st_label (gfc_st_label **);
match gfc_match_label (void);
Index: primary.c
===================================================================
--- primary.c (revision 123850)
+++ primary.c (working copy)
@@ -731,39 +731,8 @@ next_string_char (char delimiter)
if (gfc_option.flag_backslash && c == '\\')
{
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");