From patchwork Wed May 8 21:26:26 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 242647 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 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client CN "localhost", Issuer "www.qmailtoaster.com" (not verified)) by ozlabs.org (Postfix) with ESMTPS id 863602C00F5 for ; Thu, 9 May 2013 07:26:43 +1000 (EST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :message-id:date:from:mime-version:to:cc:subject:references :in-reply-to:content-type; q=dns; s=default; b=suGhihyy7iuAfAtxh 2frdwavgrzz4PIAafVjQAxXbcpT19PyDoEzlzmOLIlpKdjcsBZHek7IJqauUAobf EzeU5+ksxIznNn3dohTKjsjZqIC94wa3VnW7QQzS14LxGwOe5XJeCYaGcGeA9B9W RsB9dttIxlqh57jMgniZjGQkd4= 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 :message-id:date:from:mime-version:to:cc:subject:references :in-reply-to:content-type; s=default; bh=QOqX/KqihuxTdv4Qrhv1awR tm04=; b=Q+Pykbe5OfdsCqHJ5zy4V3BJq4IyKCCXxx/oLz+CNli7nu+nCmdn7MG uSYl46ERzCI4DfVnnWPynfqxYgRBQDqMYwWcu1/q/CE+phwadW/1BcOiECBiCMTd tPpFEWdFIGbZ4fK7RIqZE0pbBZxOfqKAc7BKH/Q60dC5dAXhfm1c= Received: (qmail 29917 invoked by alias); 8 May 2013 21:26:37 -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 29906 invoked by uid 89); 8 May 2013 21:26:36 -0000 X-Spam-SWARE-Status: No, score=-7.9 required=5.0 tests=AWL, BAYES_00, KHOP_THREADED, RCVD_IN_HOSTKARMA_W, RCVD_IN_HOSTKARMA_WL, RP_MATCHES_RCVD, SPF_HELO_PASS, SPF_PASS autolearn=ham version=3.3.1 Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.84/v0.84-167-ge50287c) with ESMTP; Wed, 08 May 2013 21:26:36 +0000 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r48LQYfO027332 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Wed, 8 May 2013 17:26:34 -0400 Received: from [10.3.113.66] (ovpn-113-66.phx2.redhat.com [10.3.113.66]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id r48LQRal025241; Wed, 8 May 2013 17:26:30 -0400 Message-ID: <518AC302.6050603@redhat.com> Date: Wed, 08 May 2013 17:26:26 -0400 From: Jason Merrill User-Agent: Mozilla/5.0 (X11; Linux i686; rv:22.0) Gecko/20100101 Thunderbird/22.0a2 MIME-Version: 1.0 To: Richard Biener CC: gcc-patches List , Jakub Jelinek Subject: Re: RFA: PATCH to add variadic version of build_constructor References: <518872E0.3090904@redhat.com> In-Reply-To: X-Virus-Found: No On 05/07/2013 04:41 AM, Richard Biener wrote: > Eh, two NULL_TREE terminators are ugly ... callers know the number of elements, > so maybe instead pass that number as argument? OK, sure. > Can we overload build_constructor with a variadic variant? Thus, > > tree build_constructor (tree type, vec *vals); > tree build_constructor (tree type, unsigned n, ...); Unfortunately, no; with that overload set, build_constructor (type, NULL) is ambiguous. Here's what I'm applying: commit ba2a6ab026009ee8368f8d381263ce2a5a527142 Author: Jason Merrill Date: Mon May 6 23:15:08 2013 -0400 * tree.c (build_constructor_va): New. * tree.h: Declare it. diff --git a/gcc/tree.c b/gcc/tree.c index 444c876..55fa99b 100644 --- a/gcc/tree.c +++ b/gcc/tree.c @@ -1467,6 +1467,27 @@ build_constructor_from_list (tree type, tree vals) return build_constructor (type, v); } +/* Return a new CONSTRUCTOR node whose type is TYPE. NELTS is the number + of elements, provided as index/value pairs. */ + +tree +build_constructor_va (tree type, int nelts, ...) +{ + vec *v = NULL; + va_list p; + + va_start (p, nelts); + vec_alloc (v, nelts); + while (nelts--) + { + tree index = va_arg (p, tree); + tree value = va_arg (p, tree); + CONSTRUCTOR_APPEND_ELT (v, index, value); + } + va_end (p); + return build_constructor (type, v); +} + /* Return a new FIXED_CST node whose type is TYPE and value is F. */ tree diff --git a/gcc/tree.h b/gcc/tree.h index 2b6f13b..cd1d7613 100644 --- a/gcc/tree.h +++ b/gcc/tree.h @@ -4763,6 +4763,7 @@ extern tree build_vector_from_val (tree, tree); extern tree build_constructor (tree, vec *); extern tree build_constructor_single (tree, tree, tree); extern tree build_constructor_from_list (tree, tree); +extern tree build_constructor_va (tree, int, ...); extern tree build_real_from_int_cst (tree, const_tree); extern tree build_complex (tree, tree, tree); extern tree build_one_cst (tree);