From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 1179 invoked by alias); 29 Oct 2010 15:28:24 -0000 Received: (qmail 1164 invoked by uid 22791); 29 Oct 2010 15:28:21 -0000 X-SWARE-Spam-Status: No, hits=-0.4 required=5.0 tests=AWL,BAYES_50,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,TW_BJ,TW_JC,TW_TM X-Spam-Check-By: sourceware.org Received: from mail-gx0-f175.google.com (HELO mail-gx0-f175.google.com) (209.85.161.175) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Fri, 29 Oct 2010 15:28:15 +0000 Received: by gxk26 with SMTP id 26so674331gxk.20 for ; Fri, 29 Oct 2010 08:28:13 -0700 (PDT) MIME-Version: 1.0 Received: by 10.42.211.13 with SMTP id gm13mr4204075icb.249.1288366093421; Fri, 29 Oct 2010 08:28:13 -0700 (PDT) Received: by 10.231.144.197 with HTTP; Fri, 29 Oct 2010 08:28:13 -0700 (PDT) In-Reply-To: <5AEA56D9-052C-4FE7-B8E0-D78BDFCD3C57@sandoe-acoustics.co.uk> References: <5AEA56D9-052C-4FE7-B8E0-D78BDFCD3C57@sandoe-acoustics.co.uk> Date: Fri, 29 Oct 2010 16:12:00 -0000 Message-ID: Subject: Re: [Patch, RFC, c*, ObjC* ] make the translation unit decl avail. via a lang hook From: Richard Guenther To: IainS Cc: GCC Patches , Mike Stump , Nicola Pero Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable 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: 2010-10/txt/msg02537.txt.bz2 On Fri, Oct 29, 2010 at 3:44 PM, IainS w= rote: > given that my current understanding is: > (a) we should make vars file-scope by setting DECL_CONTEXT =3D translation > unit decl > (b) there should only be one translation unit decl per TU > (c) at present none of the FEs export the t_u_d where other parts of the > machinery can see it. > > would the following patch be appropriate? > (it can be extended to fortran and java, I believe, fairly easily). Sounds like a hack. Note that frontends might end up with multiple TUs (for example for things in fortran modules). It's a hack because it's a frontend hook that is only used by the frontend (which means a single global variable does do it as well, like other FEs do it). Richard. > --- > > (With this applied I can use > =A0DECL_CONTEXT (decl) =3D (*lang_hooks.decls.translation_unit_context) (= ); > > =A0in each place that it is currently set to NULL in objc-act.c > =A0and also replace the two instances of pushdecl_top_level () with the s= ame. > > =A0and I get no new test-suite fails for ObjC* > ) > > comments? > Iain > > > Index: gcc/c-family/c-common.h > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D > --- gcc/c-family/c-common.h =A0 =A0 (revision 166059) > +++ gcc/c-family/c-common.h =A0 =A0 (working copy) > @@ -514,6 +514,7 @@ extern tree add_stmt (tree); > =A0extern void push_cleanup (tree, tree, bool); > =A0extern tree pushdecl_top_level (tree); > =A0extern tree pushdecl (tree); > +extern tree c_translation_unit_decl (void); > =A0extern tree build_modify_expr (location_t, tree, tree, enum tree_code, > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 location_t, t= ree, tree); > =A0extern tree build_indirect_ref (location_t, tree, ref_operator); > Index: gcc/cp/decl.c > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D > --- gcc/cp/decl.c =A0 =A0 =A0 (revision 166059) > +++ gcc/cp/decl.c =A0 =A0 =A0 (working copy) > @@ -3427,6 +3427,19 @@ initialize_predefined_identifiers (void) > =A0 =A0 } > =A0} > > +/* The current translation unit. =A0*/ > +static GTY(()) tree current_translation_unit =3D NULL_TREE; > + > +/* The function used to return the current t_u_d for the > + =A0 translation_unit_context langhook. =A0*/ > + > +tree > +cp_translation_unit_decl (void) > +{ > + =A0gcc_assert (current_translation_unit); > + =A0return current_translation_unit; > +} > + > =A0/* Create the predefined scalar types of C, > =A0 =A0and some nodes representing standard constants (0, 1, (void *)0). > =A0 =A0Initialize the global binding level. > @@ -3452,7 +3465,8 @@ cxx_init_decl_processing (void) > =A0 gcc_assert (global_namespace =3D=3D NULL_TREE); > =A0 global_namespace =3D build_lang_decl (NAMESPACE_DECL, global_scope_na= me, > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 = =A0void_type_node); > - =A0DECL_CONTEXT (global_namespace) =3D build_translation_unit_decl > (NULL_TREE); > + =A0current_translation_unit =3D build_translation_unit_decl (NULL_TREE); > + =A0DECL_CONTEXT (global_namespace) =3D current_translation_unit; > =A0 TREE_PUBLIC (global_namespace) =3D 1; > =A0 begin_scope (sk_namespace, global_namespace); > > Index: gcc/cp/cp-objcp-common.h > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D > --- gcc/cp/cp-objcp-common.h =A0 =A0(revision 166059) > +++ gcc/cp/cp-objcp-common.h =A0 =A0(working copy) > @@ -132,6 +132,8 @@ extern bool cp_function_decl_explicit_p (tree decl > =A0#define LANG_HOOKS_GIMPLIFY_EXPR cp_gimplify_expr > =A0#undef LANG_HOOKS_FUNCTION_DECL_EXPLICIT_P > =A0#define LANG_HOOKS_FUNCTION_DECL_EXPLICIT_P cp_function_decl_explicit_p > +#undef =A0LANG_HOOKS_TUD > +#define LANG_HOOKS_TUD cp_translation_unit_decl > =A0#undef LANG_HOOKS_OMP_PREDETERMINED_SHARING > =A0#define LANG_HOOKS_OMP_PREDETERMINED_SHARING cxx_omp_predetermined_sha= ring > =A0#undef LANG_HOOKS_OMP_CLAUSE_DEFAULT_CTOR > Index: gcc/cp/cp-tree.h > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D > --- gcc/cp/cp-tree.h =A0 =A0(revision 166059) > +++ gcc/cp/cp-tree.h =A0 =A0(working copy) > @@ -4764,6 +4764,7 @@ extern tree current_decl_namespace > =A0(void); > > =A0/* decl.c */ > =A0extern tree poplevel =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 = =A0 (int, int, int); > +extern tree cp_translation_unit_decl =A0 =A0 =A0 =A0 =A0 (void); > =A0extern void cxx_init_decl_processing =A0 =A0 =A0 =A0 =A0 (void); > =A0enum cp_tree_node_structure_enum cp_tree_node_structure > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 = =A0 =A0 =A0 =A0 =A0 =A0(union lang_tree_node *); > Index: gcc/c-objc-common.h > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D > --- gcc/c-objc-common.h (revision 166059) > +++ gcc/c-objc-common.h (working copy) > @@ -85,6 +85,8 @@ along with GCC; see the file COPYING3. =A0If not see > =A0#define LANG_HOOKS_TO_TARGET_CHARSET c_common_to_target_charset > =A0#undef LANG_HOOKS_EXPR_TO_DECL > =A0#define LANG_HOOKS_EXPR_TO_DECL c_expr_to_decl > +#undef =A0LANG_HOOKS_TUD > +#define LANG_HOOKS_TUD c_translation_unit_decl > > =A0/* The C front end's scoping structure is very different from > =A0 =A0that expected by the language-independent code; it is best > Index: gcc/c-decl.c > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D > --- gcc/c-decl.c =A0 =A0 =A0 =A0(revision 166059) > +++ gcc/c-decl.c =A0 =A0 =A0 =A0(working copy) > @@ -454,6 +454,8 @@ static GTY((deletable)) struct c_binding *binding_ > =A0 t_->to##_last =3D f_->from##_last; =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 = =A0 =A0 =A0 =A0 =A0 =A0 \ > =A0} while (0) > > +static GTY(()) tree current_translation_unit =3D NULL_TREE; > + > =A0/* A c_inline_static structure stores details of a static identifier > =A0 =A0referenced in a definition of a function that may be an inline > =A0 =A0definition if no subsequent declaration of that function uses > @@ -528,6 +530,14 @@ static tree grokdeclarator (const struct c_declara > =A0static tree grokparms (struct c_arg_info *, bool); > =A0static void layout_array_type (tree); > > +/* Return the translation unit decl for the current TU. =A0*/ > +tree > +c_translation_unit_decl (void) > +{ > + =A0gcc_assert (current_translation_unit); > + =A0return current_translation_unit; > +} > + > =A0/* T is a statement. =A0Add it to the statement-tree. =A0This is the > =A0 =A0C/ObjC version--C++ has a slightly different version of this > =A0 =A0function. =A0*/ > @@ -1066,8 +1076,7 @@ pop_scope (void) > =A0 =A0 context =3D current_function_decl; > =A0 else if (scope =3D=3D file_scope) > =A0 =A0 { > - =A0 =A0 =A0tree file_decl =3D build_translation_unit_decl (NULL_TREE); > - =A0 =A0 =A0context =3D file_decl; > + =A0 =A0 =A0context =3D (*lang_hooks.decls.translation_unit_context) (); > =A0 =A0 } > =A0 else > =A0 =A0 context =3D block; > @@ -3461,6 +3470,9 @@ c_init_decl_processing (void) > > =A0 c_common_nodes_and_builtins (); > > + =A0/* The current translation unit. =A0*/ > + =A0current_translation_unit =3D build_translation_unit_decl (NULL_TREE); > + > =A0 /* In C, comparisons and TRUTH_* expressions have type int. =A0*/ > =A0 truthvalue_type_node =3D integer_type_node; > =A0 truthvalue_true_node =3D integer_one_node; > Index: gcc/langhooks.h > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D > --- gcc/langhooks.h =A0 =A0 (revision 166059) > +++ gcc/langhooks.h =A0 =A0 (working copy) > @@ -152,6 +152,9 @@ struct lang_hooks_for_decls > =A0 =A0 =A0symbol is already declared, may return a different decl for th= at > =A0 =A0 =A0name. =A0*/ > =A0 tree (*pushdecl) (tree); > + > + =A0/* To add a decl to 'file scope' set its DECL_CONTEXT to this. =A0*/ > + =A0tree (*translation_unit_context) (void); > > =A0 /* Returns the chain of decls so far in the current scope level. =A0*/ > =A0 tree (*getdecls) (void); > Index: gcc/langhooks-def.h > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D > --- gcc/langhooks-def.h (revision 166059) > +++ gcc/langhooks-def.h (working copy) > @@ -200,6 +200,7 @@ extern tree lhd_make_node (enum tree_code); > =A0/* Declaration hooks. =A0*/ > =A0#define LANG_HOOKS_GLOBAL_BINDINGS_P global_bindings_p > =A0#define LANG_HOOKS_PUSHDECL =A0 =A0pushdecl > +#define LANG_HOOKS_TUD lhd_return_null_tree_v > =A0#define LANG_HOOKS_GETDECLS =A0 =A0getdecls > =A0#define LANG_HOOKS_FUNCTION_DECL_EXPLICIT_P hook_bool_tree_false > =A0#define LANG_HOOKS_WARN_UNUSED_GLOBAL_DECL lhd_warn_unused_global_decl > @@ -220,6 +221,7 @@ extern tree lhd_make_node (enum tree_code); > =A0#define LANG_HOOKS_DECLS { \ > =A0 LANG_HOOKS_GLOBAL_BINDINGS_P, \ > =A0 LANG_HOOKS_PUSHDECL, \ > + =A0LANG_HOOKS_TUD, \ > =A0 LANG_HOOKS_GETDECLS, \ > =A0 LANG_HOOKS_FUNCTION_DECL_EXPLICIT_P, \ > =A0 LANG_HOOKS_GENERIC_GENERIC_PARAMETER_DECL_P, \ > >