On Thu, Feb 14, 2013 at 8:44 PM, Lawrence Crowl <cr...@google.com> wrote: > On 2/14/13, Richard Biener <richard.guent...@gmail.com> wrote: >> On Tue, Feb 12, 2013 at 8:47 PM, Lawrence Crowl <cr...@google.com> 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