read-md.c and read-rtl.c repeatedly use this pattern:

    c = read_skip_spaces ();
    if (c != ')')
      fatal_expected_char (')', c);

Simplify them by introduce a helper function to do this.

Successfully bootstrapped&regrtested on x86_64-pc-linux-gnu.

OK for trunk?

gcc/ChangeLog:
        * read-md.c (require_char_ws): New function.
        (read_string): Simplify using require_char_ws.
        (handle_constants): Likewise.
        (handle_enum): Likewise.
        (handle_file): Likewise.
        * read-md.h (require_char_ws): New declaration.
        * read-rtl.c (read_conditions): Simplify using require_char_ws.
        (read_mapping): Likewise.
        (read_rtx_code): Likewise.
        (read_nested_rtx): Likewise.
---
 gcc/read-md.c  | 32 +++++++++++++++-----------------
 gcc/read-md.h  |  1 +
 gcc/read-rtl.c | 33 ++++++++-------------------------
 3 files changed, 24 insertions(+), 42 deletions(-)

diff --git a/gcc/read-md.c b/gcc/read-md.c
index 6c58878..fb78be7 100644
--- a/gcc/read-md.c
+++ b/gcc/read-md.c
@@ -391,6 +391,16 @@ read_skip_spaces (void)
     }
 }
 
+/* Consume any whitespace, then consume the next non-whitespace
+   character, issuing a fatal error if it is not EXPECTED.  */
+
+void require_char_ws (char expected)
+{
+  int ch = read_skip_spaces ();
+  if (ch != expected)
+    fatal_expected_char (expected, ch);
+}
+
 /* Read an rtx code name into NAME.  It is terminated by any of the
    punctuation chars of rtx printed syntax.  */
 
@@ -603,11 +613,7 @@ read_string (int star_if_braced)
     fatal_with_file_and_line ("expected `\"' or `{', found `%c'", c);
 
   if (saw_paren)
-    {
-      c = read_skip_spaces ();
-      if (c != ')')
-       fatal_expected_char (')', c);
-    }
+    require_char_ws (')');
 
   set_md_ptr_loc (stringbuf, read_md_filename, old_lineno);
   return stringbuf;
@@ -764,9 +770,7 @@ handle_constants (void)
   int c;
   htab_t defs;
 
-  c = read_skip_spaces ();
-  if (c != '[')
-    fatal_expected_char ('[', c);
+  require_char_ws ('[');
 
   /* Disable constant expansion during definition processing.  */
   defs = md_constants;
@@ -782,9 +786,7 @@ handle_constants (void)
       read_name (&value);
       add_constant (defs, xstrdup (name.string), xstrdup (value.string), 0);
 
-      c = read_skip_spaces ();
-      if (c != ')')
-       fatal_expected_char (')', c);
+      require_char_ws (')');
     }
   md_constants = defs;
 }
@@ -846,9 +848,7 @@ handle_enum (file_location loc, bool md_p)
       *slot = def;
     }
 
-  c = read_skip_spaces ();
-  if (c != '[')
-    fatal_expected_char ('[', c);
+  require_char_ws ('[');
 
   while ((c = read_skip_spaces ()) != ']')
     {
@@ -1007,9 +1007,7 @@ handle_file (directive_handler_t handle_directive)
       else
        read_skip_construct (1, loc);
 
-      c = read_skip_spaces ();
-      if (c != ')')
-       fatal_expected_char (')', c);
+      require_char_ws (')');
     }
   fclose (read_md_file);
 }
diff --git a/gcc/read-md.h b/gcc/read-md.h
index fc3b077..fa25951 100644
--- a/gcc/read-md.h
+++ b/gcc/read-md.h
@@ -141,6 +141,7 @@ extern void fatal_with_file_and_line (const char *, ...)
   ATTRIBUTE_PRINTF_1 ATTRIBUTE_NORETURN;
 extern void fatal_expected_char (int, int) ATTRIBUTE_NORETURN;
 extern int read_skip_spaces (void);
+extern void require_char_ws (char expected);
 extern void read_name (struct md_name *);
 extern char *read_quoted_string (void);
 extern char *read_string (int);
diff --git a/gcc/read-rtl.c b/gcc/read-rtl.c
index 79f42bf..dc3a336 100644
--- a/gcc/read-rtl.c
+++ b/gcc/read-rtl.c
@@ -742,9 +742,7 @@ read_conditions (void)
 {
   int c;
 
-  c = read_skip_spaces ();
-  if (c != '[')
-    fatal_expected_char ('[', c);
+  require_char_ws ('[');
 
   while ( (c = read_skip_spaces ()) != ']')
     {
@@ -759,14 +757,10 @@ read_conditions (void)
       validate_const_int (name.string);
       value = atoi (name.string);
 
-      c = read_skip_spaces ();
-      if (c != '"')
-       fatal_expected_char ('"', c);
+      require_char_ws ('"');
       expr = read_quoted_string ();
 
-      c = read_skip_spaces ();
-      if (c != ')')
-       fatal_expected_char (')', c);
+      require_char_ws (')');
 
       add_c_test (expr, value);
     }
@@ -890,9 +884,7 @@ read_mapping (struct iterator_group *group, htab_t table)
   read_name (&name);
   m = add_mapping (group, table, name.string);
 
-  c = read_skip_spaces ();
-  if (c != '[')
-    fatal_expected_char ('[', c);
+  require_char_ws ('[');
 
   /* Read each value.  */
   end_ptr = &m->values;
@@ -912,9 +904,7 @@ read_mapping (struct iterator_group *group, htab_t table)
          /* A "(name string)" pair.  */
          read_name (&name);
          string = read_string (false);
-         c = read_skip_spaces ();
-         if (c != ')')
-           fatal_expected_char (')', c);
+         require_char_ws (')');
        }
       number = group->find_builtin (name.string);
       end_ptr = add_map_value (end_ptr, number, string);
@@ -1181,9 +1171,7 @@ read_rtx_code (const char *code_name)
          int list_counter = 0;
          rtvec return_vec = NULL_RTVEC;
 
-         c = read_skip_spaces ();
-         if (c != '[')
-           fatal_expected_char ('[', c);
+         require_char_ws ('[');
 
          /* Add expressions to a list, while keeping a count.  */
          obstack_init (&vector_stack);
@@ -1398,12 +1386,9 @@ static rtx
 read_nested_rtx (void)
 {
   struct md_name name;
-  int c;
   rtx return_rtx;
 
-  c = read_skip_spaces ();
-  if (c != '(')
-    fatal_expected_char ('(', c);
+  require_char_ws ('(');
 
   read_name (&name);
   if (strcmp (name.string, "nil") == 0)
@@ -1411,9 +1396,7 @@ read_nested_rtx (void)
   else
     return_rtx = read_rtx_code (name.string);
 
-  c = read_skip_spaces ();
-  if (c != ')')
-    fatal_expected_char (')', c);
+  require_char_ws (')');
 
   return return_rtx;
 }
-- 
1.8.5.3

Reply via email to