diff mbox

cleanup in c-parser

Message ID CALsyMRgwhb3uK4z-S-FXTekQONYP+0porbu54VX-=o9t3xAMHw@mail.gmail.com
State New
Headers show

Commit Message

Anthony Brandon Oct. 12, 2014, 7:37 p.m. UTC
Hi,

I'm a new contributor and I don't yet have a copyright assignment or
commit access.

This is a cleanup of code duplication in c-parser.
I bootstrapped and tested on x86_64-linux.


gcc/c/ChangeLog:

2014-10-12  Anthony Brandon  <anthony.brandon@gmail.com>

        * c-parser.c (c_parser_all_labels): New function to replace
the duplicate code.
        (c_parser_statement): Call the new function.

Comments

Andrew Pinski Oct. 12, 2014, 8:09 p.m. UTC | #1
> On Oct 12, 2014, at 12:37 PM, Anthony Brandon <anthony.brandon@gmail.com> wrote:
> 
> Hi,
> 
> I'm a new contributor and I don't yet have a copyright assignment or
> commit access.


Thanks for you contribution.  Your new function is missing a comment before it saying what it does. Yes it might be obvious what the function does but the coding style requires it. 

Thanks,
Andrew

> 
> This is a cleanup of code duplication in c-parser.
> I bootstrapped and tested on x86_64-linux.
> 
> 
> gcc/c/ChangeLog:
> 
> 2014-10-12  Anthony Brandon  <anthony.brandon@gmail.com>
> 
>        * c-parser.c (c_parser_all_labels): New function to replace
> the duplicate code.
>        (c_parser_statement): Call the new function.
> <cleanup.diff>
diff mbox

Patch

Index: gcc/c/c-parser.c
===================================================================
--- gcc/c/c-parser.c	(revision 215973)
+++ gcc/c/c-parser.c	(working copy)
@@ -4654,6 +4654,16 @@ 
   mark_valid_location_for_stdc_pragma (save_valid_for_pragma);
 }
 
+static void
+c_parser_all_labels (c_parser *parser)
+{
+  while (c_parser_next_token_is_keyword (parser, RID_CASE)
+	 || c_parser_next_token_is_keyword (parser, RID_DEFAULT)
+	 || (c_parser_next_token_is (parser, CPP_NAME)
+	     && c_parser_peek_2nd_token (parser)->type == CPP_COLON))
+    c_parser_label (parser);
+}
+
 /* Parse a label (C90 6.6.1, C99 6.8.1).
 
    label:
@@ -4854,11 +4864,7 @@ 
 static void
 c_parser_statement (c_parser *parser)
 {
-  while (c_parser_next_token_is_keyword (parser, RID_CASE)
-	 || c_parser_next_token_is_keyword (parser, RID_DEFAULT)
-	 || (c_parser_next_token_is (parser, CPP_NAME)
-	     && c_parser_peek_2nd_token (parser)->type == CPP_COLON))
-    c_parser_label (parser);
+  c_parser_all_labels (parser);
   c_parser_statement_after_labels (parser);
 }
 
@@ -5090,11 +5096,7 @@ 
 {
   tree block = c_begin_compound_stmt (flag_isoc99);
   location_t body_loc = c_parser_peek_token (parser)->location;
-  while (c_parser_next_token_is_keyword (parser, RID_CASE)
-	 || c_parser_next_token_is_keyword (parser, RID_DEFAULT)
-	 || (c_parser_next_token_is (parser, CPP_NAME)
-	     && c_parser_peek_2nd_token (parser)->type == CPP_COLON))
-    c_parser_label (parser);
+  c_parser_all_labels (parser);
   *if_p = c_parser_next_token_is_keyword (parser, RID_IF);
   if (c_parser_next_token_is (parser, CPP_SEMICOLON))
     {
@@ -5121,11 +5123,7 @@ 
 {
   location_t else_loc = c_parser_peek_token (parser)->location;
   tree block = c_begin_compound_stmt (flag_isoc99);
-  while (c_parser_next_token_is_keyword (parser, RID_CASE)
-	 || c_parser_next_token_is_keyword (parser, RID_DEFAULT)
-	 || (c_parser_next_token_is (parser, CPP_NAME)
-	     && c_parser_peek_2nd_token (parser)->type == CPP_COLON))
-    c_parser_label (parser);
+  c_parser_all_labels (parser);
   if (c_parser_next_token_is (parser, CPP_SEMICOLON))
     {
       location_t loc = c_parser_peek_token (parser)->location;