public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] cleanup in c-parser
@ 2014-10-12 19:41 Anthony Brandon
  2014-10-12 20:36 ` pinskia
  0 siblings, 1 reply; 5+ messages in thread
From: Anthony Brandon @ 2014-10-12 19:41 UTC (permalink / raw)
  To: gcc-patches; +Cc: manu, joseph

[-- Attachment #1: Type: text/plain, Size: 403 bytes --]

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.

[-- Attachment #2: cleanup.diff --]
[-- Type: text/plain, Size: 2186 bytes --]

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;

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] cleanup in c-parser
  2014-10-12 19:41 [PATCH] cleanup in c-parser Anthony Brandon
@ 2014-10-12 20:36 ` pinskia
  2014-10-13 11:21   ` Anthony Brandon
  0 siblings, 1 reply; 5+ messages in thread
From: pinskia @ 2014-10-12 20:36 UTC (permalink / raw)
  To: Anthony Brandon; +Cc: gcc-patches, manu, joseph





> 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>

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] cleanup in c-parser
  2014-10-12 20:36 ` pinskia
@ 2014-10-13 11:21   ` Anthony Brandon
  2014-10-13 18:54     ` Jeff Law
  0 siblings, 1 reply; 5+ messages in thread
From: Anthony Brandon @ 2014-10-13 11:21 UTC (permalink / raw)
  To: pinskia; +Cc: gcc-patches, manu, joseph

[-- Attachment #1: Type: text/plain, Size: 1102 bytes --]

I updated the patch with a comment. Actually, Manuel handed me this
patch just to help me get familiar with the process of submitting and
testing.
Generating this one with git diff looks different so I'm not sure if
that's a problem or not.

Thanks,
Anthony

On Sun, Oct 12, 2014 at 10:09 PM,  <pinskia@gmail.com> wrote:
>
>
>
>
>> 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>



-- 
Anthony

[-- Attachment #2: cleanup-2.diff --]
[-- Type: text/plain, Size: 2358 bytes --]

diff --git a/gcc/c/c-parser.c b/gcc/c/c-parser.c
index 0d159fd..346448a 100644
--- a/gcc/c/c-parser.c
+++ b/gcc/c/c-parser.c
@@ -4654,6 +4654,18 @@ c_parser_compound_statement_nostart (c_parser *parser)
   mark_valid_location_for_stdc_pragma (save_valid_for_pragma);
 }
 
+/* Parse all consecutive labels. */
+
+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 +4866,7 @@ c_parser_label (c_parser *parser)
 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 +5098,7 @@ c_parser_if_body (c_parser *parser, bool *if_p)
 {
   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 +5125,7 @@ c_parser_else_body (c_parser *parser)
 {
   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;

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] cleanup in c-parser
  2014-10-13 11:21   ` Anthony Brandon
@ 2014-10-13 18:54     ` Jeff Law
  2014-10-13 21:05       ` Manuel López-Ibáñez
  0 siblings, 1 reply; 5+ messages in thread
From: Jeff Law @ 2014-10-13 18:54 UTC (permalink / raw)
  To: Anthony Brandon, pinskia; +Cc: gcc-patches, manu, joseph

On 10/13/14 05:11, Anthony Brandon wrote:
> I updated the patch with a comment. Actually, Manuel handed me this
> patch just to help me get familiar with the process of submitting and
> testing.
> Generating this one with git diff looks different so I'm not sure if
> that's a problem or not.
This version is fine.  Please install on the trunk.

Thanks,
jeff

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] cleanup in c-parser
  2014-10-13 18:54     ` Jeff Law
@ 2014-10-13 21:05       ` Manuel López-Ibáñez
  0 siblings, 0 replies; 5+ messages in thread
From: Manuel López-Ibáñez @ 2014-10-13 21:05 UTC (permalink / raw)
  To: Jeff Law; +Cc: Anthony Brandon, gcc-patches, Manuel López-Ibáñez

On 13 October 2014 20:52, Jeff Law <law@redhat.com> wrote:
> On 10/13/14 05:11, Anthony Brandon wrote:
>>
>> I updated the patch with a comment. Actually, Manuel handed me this
>> patch just to help me get familiar with the process of submitting and
>> testing.
>> Generating this one with git diff looks different so I'm not sure if
>> that's a problem or not.
>
> This version is fine.  Please install on the trunk.

Committed as revision https://gcc.gnu.org/r216165

Congratulations Anthony, you cleared the tutorial level!

Have you decided what are you going to fix next?

Cheers,

Manuel.

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2014-10-13 21:02 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-10-12 19:41 [PATCH] cleanup in c-parser Anthony Brandon
2014-10-12 20:36 ` pinskia
2014-10-13 11:21   ` Anthony Brandon
2014-10-13 18:54     ` Jeff Law
2014-10-13 21:05       ` Manuel López-Ibáñez

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).