From patchwork Sun Oct 12 19:37:58 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anthony Brandon X-Patchwork-Id: 399013 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 D13B91400F4 for ; Mon, 13 Oct 2014 06:38:11 +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:date:message-id:subject:from:to:cc:content-type; q=dns; s=default; b=Wn5kZelWxy8R3cRZyOxybrKWK0cKjDNO1KL+6bP/EpV jqMk9QUQ5tMveQfn4pSplCQnu+a/tvluJgO4hqymmTxvifNwHfzKMm2nIY708C0E NPtOpVGx3Kb6sCs3MgFzY9MbRQX26774/mt30UU6xqb2IGZ2GFa1nDjbCpKfL1AE = 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:date:message-id:subject:from:to:cc:content-type; s=default; bh=+MZBxotAR+Vkgu3Xm0Viwn5kWlc=; b=JThhX2k+b+x1F2bYI X6O00dWIEdKAWiF4GXqkm+iuV/7ju4Xx62zsa9875KzjWSMZQ0VYx8rHhZ10lKUB 8Wexw0rZ9rpfm6FwJFnRFQ4WvRnYn3o05wiOf++9K5p+msFybgbos6f9JFWVs8Sb b+unl+fkZjSG9Qz0JijsYAB7f8= Received: (qmail 16483 invoked by alias); 12 Oct 2014 19:38:02 -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 16468 invoked by uid 89); 12 Oct 2014 19:38:02 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.9 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-qc0-f182.google.com Received: from mail-qc0-f182.google.com (HELO mail-qc0-f182.google.com) (209.85.216.182) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-SHA encrypted) ESMTPS; Sun, 12 Oct 2014 19:38:01 +0000 Received: by mail-qc0-f182.google.com with SMTP id i17so4217849qcy.27 for ; Sun, 12 Oct 2014 12:37:58 -0700 (PDT) MIME-Version: 1.0 X-Received: by 10.224.65.72 with SMTP id h8mr34092733qai.96.1413142678653; Sun, 12 Oct 2014 12:37:58 -0700 (PDT) Received: by 10.140.95.193 with HTTP; Sun, 12 Oct 2014 12:37:58 -0700 (PDT) Date: Sun, 12 Oct 2014 21:37:58 +0200 Message-ID: Subject: [PATCH] cleanup in c-parser From: Anthony Brandon To: gcc-patches@gcc.gnu.org Cc: manu@gcc.gnu.org, joseph@codesourcery.com X-IsSubscribed: yes 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 * c-parser.c (c_parser_all_labels): New function to replace the duplicate code. (c_parser_statement): Call the new function. 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;