From patchwork Mon Oct 13 11:11:56 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anthony Brandon X-Patchwork-Id: 399161 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 51657140095 for ; Mon, 13 Oct 2014 22:12:08 +1100 (EST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :mime-version:in-reply-to:references:date:message-id:subject :from:to:cc:content-type; q=dns; s=default; b=NRlDsEXVm8soB6cLRM Budgmac5MGjwexZs6ybv2ySLpp5az7udLnisowkBxLJenZ3zEo/aRs4+j9z3DZh5 5iT00VTHTuVyAZdX5NQli7fhfxuxb1emc4lQhnbyObpGNn329pDagFGcWbn+q4yP fB1WYuakTLiGIePaz+/S6k0Rc= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :mime-version:in-reply-to:references:date:message-id:subject :from:to:cc:content-type; s=default; bh=z3F+8tWUlH8UFgEtvK05/udD qHY=; b=q/DzwrqSsxjcWGoW3atgH+VgUwReaGZOqbGaUwFpBKSWYn7j81e693Tk Jp2dANeFuwcc+4SCzMWSQGy0KukowpaLnRLnv6o3Z/AOsEyxWeejuc46sB5ONShX JbepPM/8wPxHMe4UjTvHOtkaB+plwfYeHm99z3NYGbx5UvQxe0Y= Received: (qmail 11506 invoked by alias); 13 Oct 2014 11:12:01 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 11486 invoked by uid 89); 13 Oct 2014 11:12:00 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.0 required=5.0 tests=AWL, BAYES_00, FREEMAIL_FROM, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham version=3.3.2 X-Spam-User: qpsmtpd, 2 recipients X-HELO: mail-qa0-f48.google.com Received: from mail-qa0-f48.google.com (HELO mail-qa0-f48.google.com) (209.85.216.48) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-SHA encrypted) ESMTPS; Mon, 13 Oct 2014 11:11:59 +0000 Received: by mail-qa0-f48.google.com with SMTP id dc16so4215728qab.21 for ; Mon, 13 Oct 2014 04:11:56 -0700 (PDT) MIME-Version: 1.0 X-Received: by 10.140.44.6 with SMTP id f6mr37324166qga.93.1413198716758; Mon, 13 Oct 2014 04:11:56 -0700 (PDT) Received: by 10.140.95.193 with HTTP; Mon, 13 Oct 2014 04:11:56 -0700 (PDT) In-Reply-To: <044D8CC4-A3A3-4B5A-9D9A-FB01FB845131@gmail.com> References: <044D8CC4-A3A3-4B5A-9D9A-FB01FB845131@gmail.com> Date: Mon, 13 Oct 2014 13:11:56 +0200 Message-ID: Subject: Re: [PATCH] cleanup in c-parser From: Anthony Brandon To: pinskia@gmail.com Cc: "gcc-patches@gcc.gnu.org" , "manu@gcc.gnu.org" , "joseph@codesourcery.com" X-IsSubscribed: yes 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, wrote: > > > > >> On Oct 12, 2014, at 12:37 PM, Anthony Brandon 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 >> >> * c-parser.c (c_parser_all_labels): New function to replace >> the duplicate code. >> (c_parser_statement): Call the new function. >> 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;