From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 18150 invoked by alias); 15 Feb 2013 09:04:33 -0000 Received: (qmail 18141 invoked by uid 22791); 15 Feb 2013 09:04:32 -0000 X-SWARE-Spam-Status: No, hits=-5.0 required=5.0 tests=AWL,BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,KHOP_RCVD_TRUST,KHOP_THREADED,RCVD_IN_DNSWL_LOW,RCVD_IN_HOSTKARMA_YE X-Spam-Check-By: sourceware.org Received: from mail-wg0-f41.google.com (HELO mail-wg0-f41.google.com) (74.125.82.41) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Fri, 15 Feb 2013 09:04:21 +0000 Received: by mail-wg0-f41.google.com with SMTP id ds1so693917wgb.4 for ; Fri, 15 Feb 2013 01:04:20 -0800 (PST) MIME-Version: 1.0 X-Received: by 10.195.13.11 with SMTP id eu11mr2635014wjd.39.1360919060342; Fri, 15 Feb 2013 01:04:20 -0800 (PST) Received: by 10.194.179.130 with HTTP; Fri, 15 Feb 2013 01:04:20 -0800 (PST) In-Reply-To: References: <20130209065835.F0DCF12084A@jade.mtv.corp.google.com> Date: Fri, 15 Feb 2013 09:04:00 -0000 Message-ID: Subject: Re: [cxx-conversion] Add Record Builder Class From: Richard Biener To: Lawrence Crowl Cc: dnovillo@google.com, nathan@codesourcery.com, gcc-patches List Content-Type: text/plain; charset=ISO-8859-1 X-IsSubscribed: yes Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org X-SW-Source: 2013-02/txt/msg00764.txt.bz2 On Thu, Feb 14, 2013 at 8:44 PM, Lawrence Crowl wrote: > On 2/14/13, Richard Biener wrote: >> On Tue, Feb 12, 2013 at 8:47 PM, Lawrence Crowl wrote: >> > Add class record_builder to ease construction of records and unions. Use >> > it >> > in some appropriate places. > .... >> > tree >> > -default_emutls_var_fields (tree type, tree *name ATTRIBUTE_UNUSED) >> > +default_emutls_object_type (void) >> > { >> > - tree word_type_node, field, next_field; >> > - >> > - field = build_decl (UNKNOWN_LOCATION, >> > - FIELD_DECL, get_identifier ("__templ"), ptr_type_node); >> > - DECL_CONTEXT (field) = type; >> > - next_field = field; >> > - >> > - field = build_decl (UNKNOWN_LOCATION, >> > - FIELD_DECL, get_identifier ("__offset"), >> > - ptr_type_node); >> > - DECL_CONTEXT (field) = type; >> > - DECL_CHAIN (field) = next_field; >> > - next_field = field; >> > - >> > - word_type_node = lang_hooks.types.type_for_mode (word_mode, 1); >> > - field = build_decl (UNKNOWN_LOCATION, >> > - FIELD_DECL, get_identifier ("__align"), >> > - word_type_node); >> > - DECL_CONTEXT (field) = type; >> > - DECL_CHAIN (field) = next_field; >> > - next_field = field; >> > - >> > - field = build_decl (UNKNOWN_LOCATION, >> > - FIELD_DECL, get_identifier ("__size"), word_type_node); >> > - DECL_CONTEXT (field) = type; >> > - DECL_CHAIN (field) = next_field; >> > - >> > - return field; >> > + tree word_type_node = lang_hooks.types.type_for_mode (word_mode, 1); >> > + record_builder rec; >> > + rec.add_field ("__size", word_type_node); >> > + rec.add_field ("__align", word_type_node); >> > + rec.add_field ("__offset", ptr_type_node); >> > + rec.add_field ("__templ", ptr_type_node); >> > + rec.layout (); >> >> That's awkward - you want to hide the fact that layout has >> to happen and that it has to happen "last". Just make it a >> side-effect of .as_tree (). > > Sometimes you want to construct recursive types, and for that you > need .as_tree to execute before layout. This feature is used in > the patch. > >> Note that add_field want's to return the FIELD_DECL created, >> people may want to alter it. > > Do you have a use case? Until we have one, I'm not convinced that > we should widen the interface. > >> Note that tag_name does not allow the way C++ uses this (it can >> be a TYPE_DECL). > > That is what the .decl_name member function does. > >> Overall I'm not sure this is a good abstraction unless you manage >> to make the frontends use it. > > The intent is for use by the middle/back ends constructing code. > As such, it should be using middle/back end types, not front-end > types. Note that there is no such thing as a "middle-end" or "back-end" type. Richard. > -- > Lawrence Crowl