This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [C++ PATCH] namespace stat hack representation


On Mon, May 29, 2017 at 11:11:12AM -0400, Nathan Sidwell wrote:
> Currently bindings have two slots, a 'value' slot for the regular binding,
> and a 'type' slot for the struct name binding, which is only used when the
> value slot is holding something else.  for instance:
> 
> struct foo {...} foo;
> 
> The value slot will be a VAR_DECL, and the type slot an artificial
> TYPE_DECL.
> 
> The type slot is very rarely non-null, because such code use is terribly
> confusing.  But as the name suggests, it's needed because of the C library's
> definition:
> 
>   struct stat {...};
>   int stat (const char *, struct stat *);
> 
> This patch changes the representation for namespace bindings, so we only use
> one slot, and if the stat hack is needed, it contains an OVERLOAD that is
> marked with LOOKUP_P (such overloads cannot otherwise appear in a binding).
> In that case the TYPE holds the TYPE_DECL and the FUNCTION holds the value
> binding.
> 
> This patch doesn't change the use of cxx_binding, so the underlying accessor
> find_namespace_slot simply returns the address of the value field.  (The
> next patch will remove cxx_binding for namespaces.)
> 
> nathan
> 
> -- 
> Nathan Sidwell

> 2017-05-29  Nathan Sidwell  <nathan@acm.org>
> 
> 	Stat hack representation
> 	* name-lookup.c (STAT_HACK_P, STAT_TYPE, STAT_DECL,
> 	MAYBE_STAT_DECL, MAYBE_STAT_TYPE): New.
> 	(stat_hack): New.
> 	(find_namespace_binding): Replace with ...
> 	(find_namespace_slot): ... this.
> 	(find_namespace_value): New.
> 	(name_lookup::search_namespace_only,
> 	name_lookup::adl_namespace_only): Adjust.
> 	(update_binding): Add SLOT parameter, adjust.
> 	(check_local_shadow): Use find_namespace_value.
> 	(set_local_extern_decl_linkage): Likewise.
> 	(do_pushdecl): Adjust for namespace slot.
> 	(push_local_binding): Assert not a namespace binding.
> 	(check_for_out_of_scope_variable): Use find_namespace_value.
> 	(set_identifier_type_value_with_scope): Likewise.
> 	(get_namespace_binding): Likewise.
> 	(set_namespace_binding): Delete.
> 	(set_global_binding): Directly update the binding.
> 	(finish_namespace_using_decl): Likewise.
> 	(lookup_type_scope_1): Use find_namespace_slot and update.
> 	(do_push_nested_namespace): Use find_namespace_value.
> 
> Index: name-lookup.c
> ===================================================================
> --- name-lookup.c	(revision 248573)
> +++ name-lookup.c	(working copy)
> @@ -38,6 +38,27 @@ static cp_binding_level *innermost_noncl
>  static void set_identifier_type_value_with_scope (tree id, tree decl,
>  						  cp_binding_level *b);
>  
> +/* Create an overload suitable for recording an artificial TYPE_DECL
> +   and another decl.  We use this machanism to implement the struct
> +   stat hack within a namespace.  It'd be nice to use it everywhere.  */
> +
> +#define STAT_HACK_P(N) ((N) && TREE_CODE (N) == OVERLOAD && OVL_LOOKUP_P (N))
> +#define STAT_TYPE(N) TREE_TYPE (N)
> +#define STAT_DECL(N) OVL_FUNCTION (N)
> +#define MAYBE_STAT_DECL(N) (STAT_HACK_P (N) ? STAT_DECL (N) : N)
> +#define MAYBE_STAT_TYPE(N) (STAT_HACK_P (N) ? STAT_TYPE (N) : NULL_TREE)
> +
> +static tree stat_hack (tree decl = NULL_TREE, tree type = NULL_TREE)

Should be
static tree
stat_hack (tree decl = NULL_TREE, tree type = NULL_TREE)
to make it easier to grep for the function with ^stat_hack.

(Didn't check the rest of the patch.)

	Marek


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]