From patchwork Sun Aug 8 01:33:27 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nathan Froyd X-Patchwork-Id: 61195 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]) by ozlabs.org (Postfix) with SMTP id 23F88B6EE9 for ; Sun, 8 Aug 2010 11:33:36 +1000 (EST) Received: (qmail 17292 invoked by alias); 8 Aug 2010 01:33:34 -0000 Received: (qmail 17282 invoked by uid 22791); 8 Aug 2010 01:33:34 -0000 X-SWARE-Spam-Status: No, hits=-1.7 required=5.0 tests=AWL, BAYES_00, T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mail.codesourcery.com (HELO mail.codesourcery.com) (38.113.113.100) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Sun, 08 Aug 2010 01:33:29 +0000 Received: (qmail 9298 invoked from network); 8 Aug 2010 01:33:27 -0000 Received: from unknown (HELO localhost) (froydnj@127.0.0.2) by mail.codesourcery.com with ESMTPA; 8 Aug 2010 01:33:27 -0000 Date: Sat, 7 Aug 2010 18:33:27 -0700 From: Nathan Froyd To: gcc-patches@gcc.gnu.org Subject: [PATCH] centralize building of c_arg_info structure Message-ID: <20100808013327.GR17362@codesourcery.com> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.17+20080114 (2008-01-14) X-IsSubscribed: yes 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 struct c_arg_info is allocated and initialized nearly identically in several different places. This patch moves all of that code to a common function. The initialization of the tags field in build_arg_info will work without my patch to convert tags to a VEC, but the initialization will be more correct with said patch. Tested on x86_64-unknown-linux-gnu. OK to commit? -Nathan * c-tree.h (build_arg_info): Declare. * c-decl.c (build_arg_info): Define. (get_parm_info): Call it. Delete initialization code. * c-parser.c (c_parser_parms_declarator): Likewise. (c_parser_parms_list_declaractor): Likewise. diff --git a/gcc/c-decl.c b/gcc/c-decl.c index e4e872d..ec66692 100644 --- a/gcc/c-decl.c +++ b/gcc/c-decl.c @@ -6176,6 +6176,22 @@ grokparms (struct c_arg_info *arg_info, bool funcdef_flag) } } +/* Allocate and initialize a c_arg_info structure from the parser's + obstack. */ + +struct c_arg_info * +build_arg_info (void) +{ + struct c_arg_info *ret = XOBNEW (&parser_obstack, struct c_arg_info); + ret->parms = NULL_TREE; + ret->tags = NULL; + ret->types = NULL_TREE; + ret->others = NULL_TREE; + ret->pending_sizes = NULL; + ret->had_vla_unspec = 0; + return ret; +} + /* Take apart the current scope and return a c_arg_info structure with info on a parameter list just parsed. @@ -6188,8 +6204,8 @@ struct c_arg_info * get_parm_info (bool ellipsis) { struct c_binding *b = current_scope->bindings; - struct c_arg_info *arg_info = XOBNEW (&parser_obstack, - struct c_arg_info); + struct c_arg_info *arg_info = build_arg_info (); + tree parms = 0; tree tags = 0; tree types = 0; @@ -6198,11 +6214,6 @@ get_parm_info (bool ellipsis) static bool explained_incomplete_types = false; bool gave_void_only_once_err = false; - arg_info->parms = 0; - arg_info->tags = 0; - arg_info->types = 0; - arg_info->others = 0; - arg_info->pending_sizes = 0; arg_info->had_vla_unspec = current_scope->had_vla_unspec; /* The bindings in this scope must not get put into a block. diff --git a/gcc/c-parser.c b/gcc/c-parser.c index 306d46b..031c688 100644 --- a/gcc/c-parser.c +++ b/gcc/c-parser.c @@ -194,7 +194,6 @@ typedef struct GTY(()) c_parser { static GTY (()) c_parser *the_parser; - /* Read in and lex a single token, storing it in *TOKEN. */ static void @@ -2672,13 +2671,8 @@ c_parser_parms_declarator (c_parser *parser, bool id_list_ok, tree attrs) } if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN)) { - struct c_arg_info *ret = XOBNEW (&parser_obstack, struct c_arg_info); - ret->parms = 0; - ret->tags = 0; + struct c_arg_info *ret = build_arg_info (); ret->types = list; - ret->others = 0; - ret->pending_sizes = 0; - ret->had_vla_unspec = 0; c_parser_consume_token (parser); pop_scope (); return ret; @@ -2715,24 +2709,13 @@ c_parser_parms_list_declarator (c_parser *parser, tree attrs) declarations. */ if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN)) { - struct c_arg_info *ret = XOBNEW (&parser_obstack, struct c_arg_info); - ret->parms = 0; - ret->tags = 0; - ret->types = 0; - ret->others = 0; - ret->pending_sizes = 0; - ret->had_vla_unspec = 0; + struct c_arg_info *ret = build_arg_info (); c_parser_consume_token (parser); return ret; } if (c_parser_next_token_is (parser, CPP_ELLIPSIS)) { - struct c_arg_info *ret = XOBNEW (&parser_obstack, struct c_arg_info); - ret->parms = 0; - ret->tags = 0; - ret->others = 0; - ret->pending_sizes = 0; - ret->had_vla_unspec = 0; + struct c_arg_info *ret = build_arg_info (); /* Suppress -Wold-style-definition for this case. */ ret->types = error_mark_node; error_at (c_parser_peek_token (parser)->location, diff --git a/gcc/c-tree.h b/gcc/c-tree.h index 745dd05..a04d45c 100644 --- a/gcc/c-tree.h +++ b/gcc/c-tree.h @@ -444,6 +444,7 @@ extern tree finish_enum (tree, tree, tree); extern void finish_function (void); extern tree finish_struct (location_t, tree, tree, tree, struct c_struct_parse_info *); +extern struct c_arg_info *build_arg_info (void); extern struct c_arg_info *get_parm_info (bool); extern tree grokfield (location_t, struct c_declarator *, struct c_declspecs *, tree, tree *);