langhooks for function.c

Neil Booth neil@daikokuya.demon.co.uk
Fri Apr 19 10:14:00 GMT 2002


Bootstrapped x86 Linux without regressions.  OK?

Neil.

	* Makefile.in: Update.
	* decl.c (push_c_function_context, pop_c_function_context,
	mark_c_function_context): Rename for consistency.
	* c-objc-common.c (c_objc_common_init): Langhooks set elsewhere.
	* c-tree.h (push_c_function_context, pop_c_function_context,
	mark_c_function_context): Rename for consistency.
	* c-lang.c (LANG_HOOKS_FUNCTION_ENTER_NESTED,
	LANG_HOOKS_FUNCTION_LEAVE_NESTED, LANG_HOOKS_FUNCTION_MARK): Redefine.
	* function.c (init_lang_status, save_lang_status,
	restore_lang_status, mark_lang_status, free_lang_status):
	Move to langhooks.h.
	(push_function_context_to, pop_function_context_from,
	free_after_parsing, prepare_function_start, ggc_mark_struct_function):
	Update.
	* function.h (init_lang_status, save_lang_status,
	restore_lang_status, mark_lang_status, free_lang_status):
	Move to langhooks.h.
	* langhooks-def.h (LANG_HOOKS_FUNCTION_ENTER,
	LANG_HOOKS_FUNCTION_LEAVE, LANG_HOOKS_FUNCTION_ENTER_NESTED,
	LANG_HOOKS_FUNCTION_LEAVE_NESTED, LANG_HOOKS_FUNCTION_MARK,
	LANG_HOOKS_FUNCTION_INITIALIZER): New.
	(LANG_HOOKS_INITIALIZER): Update.
	(lhd_do_nothing_f): New.
	* langhooks.h (struct lang_hooks_for_functions): New.
	(struct lang_hooks): New hooks.
	* langhooks.c (lhd_do_nothing_f): New.
cp:
	* cp-lang.c (LANG_HOOKS_FUNCTION_ENTER,
	LANG_HOOKS_FUNCTION_LEAVE, LANG_HOOKS_FUNCTION_MARK): Redefine.
	* cp-tree.h (cxx_push_function_context, cxx_pop_function_context,
	cxx_mark_function_context): New.
	* decl.c (push_cp_function_context, pop_cp_function_context,
	mark_cp_function_context): Rename for consistency.
	(cxx_init_decl_processing): Don't set old hooks.
objc:
	* objc-lang.c (LANG_HOOKS_FUNCTION_ENTER_NESTED,
	LANG_HOOKS_FUNCTION_LEAVE_NESTED, LANG_HOOKS_FUNCTION_MARK): Redefine.

============================================================
Index: gcc/Makefile.in
--- gcc/Makefile.in	19 Apr 2002 06:21:54 -0000	1.859
+++ gcc/Makefile.in	19 Apr 2002 06:50:35 -0000
@@ -1154,9 +1154,9 @@ c-decl.o : c-decl.c $(CONFIG_H) $(SYSTEM
 c-typeck.o : c-typeck.c $(CONFIG_H) $(SYSTEM_H) $(TREE_H) $(C_TREE_H) \
     $(TARGET_H) flags.h intl.h output.h $(EXPR_H) $(RTL_H) toplev.h $(TM_P_H)
 c-lang.o : c-lang.c $(CONFIG_H) $(SYSTEM_H) $(TREE_H) $(C_TREE_H) \
-    langhooks.h langhooks-def.h
+    langhooks.h langhooks-def.h c-common.h
 c-lex.o : c-lex.c $(CONFIG_H) $(SYSTEM_H) $(TREE_H) $(RTL_H) c-lex.h \
-    debug.h $(C_TREE_H) \
+    debug.h $(C_TREE_H) c-common.h \
     c-pragma.h input.h intl.h flags.h toplev.h output.h \
     mbchar.h $(CPPLIB_H) $(EXPR_H) $(TM_P_H)
 c-objc-common.o : c-objc-common.c $(CONFIG_H) $(SYSTEM_H) $(TREE_H) \
============================================================
Index: gcc/c-decl.c
--- gcc/c-decl.c	19 Apr 2002 06:21:55 -0000	1.318
+++ gcc/c-decl.c	19 Apr 2002 06:50:53 -0000
@@ -6712,7 +6712,7 @@ finish_function (nested, can_defer_p)
 
       /* Let the error reporting routines know that we're outside a
 	 function.  For a nested function, this value is used in
-	 pop_c_function_context and then reset via pop_function_context.  */
+	 c_pop_function_context and then reset via pop_function_context.  */
       current_function_decl = NULL;
     }
 }
@@ -6887,7 +6887,7 @@ c_expand_body (fndecl, nested_p, can_def
       /* Stop pointing to the local nodes about to be freed.
 	 But DECL_INITIAL must remain nonzero so we know this
 	 was an actual function definition.
-	 For a nested function, this is done in pop_c_function_context.
+	 For a nested function, this is done in c_pop_function_context.
 	 If rest_of_compilation set this to 0, leave it 0.  */
       if (DECL_INITIAL (fndecl) != 0)
 	DECL_INITIAL (fndecl) = error_mark_node;
@@ -6998,7 +6998,7 @@ struct c_language_function
    used during compilation of a C function.  */
 
 void
-push_c_function_context (f)
+c_push_function_context (f)
      struct function *f;
 {
   struct c_language_function *p;
@@ -7021,7 +7021,7 @@ push_c_function_context (f)
 /* Restore the variables used during compilation of a C function.  */
 
 void
-pop_c_function_context (f)
+c_pop_function_context (f)
      struct function *f;
 {
   struct c_language_function *p
@@ -7062,7 +7062,7 @@ pop_c_function_context (f)
 /* Mark the language specific parts of F for GC.  */
 
 void
-mark_c_function_context (f)
+c_mark_function_context (f)
      struct function *f;
 {
   struct c_language_function *p
============================================================
Index: gcc/c-lang.c
--- gcc/c-lang.c	19 Apr 2002 06:21:56 -0000	1.89
+++ gcc/c-lang.c	19 Apr 2002 06:50:54 -0000
@@ -74,6 +74,12 @@ static void c_post_options PARAMS ((void
 #define LANG_HOOKS_PRINT_IDENTIFIER c_print_identifier
 #undef LANG_HOOKS_SET_YYDEBUG
 #define LANG_HOOKS_SET_YYDEBUG c_set_yydebug
+#undef LANG_HOOKS_FUNCTION_ENTER_NESTED
+#define LANG_HOOKS_FUNCTION_ENTER_NESTED c_push_function_context
+#undef LANG_HOOKS_FUNCTION_LEAVE_NESTED
+#define LANG_HOOKS_FUNCTION_LEAVE_NESTED c_pop_function_context
+#undef LANG_HOOKS_FUNCTION_MARK
+#define LANG_HOOKS_FUNCTION_MARK c_mark_function_context
 #undef LANG_HOOKS_DUP_LANG_SPECIFIC_DECL
 #define LANG_HOOKS_DUP_LANG_SPECIFIC_DECL c_dup_lang_specific_decl
 
============================================================
Index: gcc/c-objc-common.c
--- gcc/c-objc-common.c	3 Apr 2002 22:39:43 -0000	1.11
+++ gcc/c-objc-common.c	19 Apr 2002 06:50:54 -0000
@@ -234,9 +234,6 @@ c_objc_common_init (filename)
   if (filename == NULL)
     return NULL;
 
-  save_lang_status = &push_c_function_context;
-  restore_lang_status = &pop_c_function_context;
-  mark_lang_status = &mark_c_function_context;
   lang_expand_decl_stmt = c_expand_decl_stmt;
 
   /* These were not defined in the Objective-C front end, but I'm
============================================================
Index: gcc/c-tree.h
--- gcc/c-tree.h	19 Apr 2002 06:21:56 -0000	1.94
+++ gcc/c-tree.h	19 Apr 2002 06:50:55 -0000
@@ -206,9 +206,9 @@ extern tree lookup_name                 
 extern tree lookup_name_current_level		PARAMS ((tree));
 extern void parmlist_tags_warning               PARAMS ((void));
 extern void pending_xref_error                  PARAMS ((void));
-extern void mark_c_function_context             PARAMS ((struct function *));
-extern void push_c_function_context             PARAMS ((struct function *));
-extern void pop_c_function_context              PARAMS ((struct function *));
+extern void c_mark_function_context             PARAMS ((struct function *));
+extern void c_push_function_context             PARAMS ((struct function *));
+extern void c_pop_function_context              PARAMS ((struct function *));
 extern void pop_label_level                     PARAMS ((void));
 extern void push_label_level                    PARAMS ((void));
 extern void push_parm_decl                      PARAMS ((tree));
============================================================
Index: gcc/function.c
--- gcc/function.c	19 Apr 2002 04:41:34 -0000	1.356
+++ gcc/function.c	19 Apr 2002 06:51:16 -0000
@@ -133,13 +133,6 @@ void (*free_machine_status) PARAMS ((str
    that will need garbage collection.  */
 void (*mark_machine_status) PARAMS ((struct function *));
 
-/* Likewise, but for language-specific data.  */
-void (*init_lang_status) PARAMS ((struct function *));
-void (*save_lang_status) PARAMS ((struct function *));
-void (*restore_lang_status) PARAMS ((struct function *));
-void (*mark_lang_status) PARAMS ((struct function *));
-void (*free_lang_status) PARAMS ((struct function *));
-
 /* The FUNCTION_DECL for an inline function currently being expanded.  */
 tree inline_function_decl;
 
@@ -328,7 +321,7 @@ find_function_data (decl)
 
 /* Save the current context for compilation of a nested function.
    This is called from language-specific code.  The caller should use
-   the save_lang_status callback to save any language-specific state,
+   the enter_nested langhook to save any language-specific state,
    since this function knows only about language-independent
    variables.  */
 
@@ -357,8 +350,7 @@ push_function_context_to (context)
   outer_function_chain = p;
   p->fixup_var_refs_queue = 0;
 
-  if (save_lang_status)
-    (*save_lang_status) (p);
+  (*lang_hooks.function.enter_nested) (p);
 
   cfun = 0;
 }
@@ -387,8 +379,7 @@ pop_function_context_from (context)
 
   restore_emit_status (p);
 
-  if (restore_lang_status)
-    (*restore_lang_status) (p);
+  (*lang_hooks.function.leave_nested) (p);
 
   /* Finish doing put_var_into_stack for any of our variables which became
      addressable during the nested function.  If only one entry has to be
@@ -441,8 +432,7 @@ free_after_parsing (f)
   /* f->varasm is used by code generation.  */
   /* f->eh->eh_return_stub_label is used by code generation.  */
 
-  if (free_lang_status)
-    (*free_lang_status) (f);
+  (*lang_hooks.function.leave) (f);
   free_stmt_status (f);
 }
 
@@ -6272,8 +6262,7 @@ prepare_function_start ()
 
   current_function_outgoing_args_size = 0;
 
-  if (init_lang_status)
-    (*init_lang_status) (cfun);
+  (*lang_hooks.function.enter) (cfun);
   if (init_machine_status)
     (*init_machine_status) (cfun);
 }
@@ -8006,8 +7995,7 @@ ggc_mark_struct_function (f)
 
   if (mark_machine_status)
     (*mark_machine_status) (f);
-  if (mark_lang_status)
-    (*mark_lang_status) (f);
+  (*lang_hooks.function.mark) (f);
 
   if (f->original_arg_vector)
     ggc_mark_rtvec ((rtvec) f->original_arg_vector);
============================================================
Index: gcc/function.h
--- gcc/function.h	15 Mar 2002 10:17:16 -0000	1.76
+++ gcc/function.h	19 Apr 2002 06:51:19 -0000
@@ -574,13 +574,6 @@ extern void (*free_machine_status)	PARAM
    that will need garbage collection.  */
 extern void (*mark_machine_status)	PARAMS ((struct function *));
 
-/* Likewise, but for language-specific data.  */
-extern void (*init_lang_status)         PARAMS ((struct function *));
-extern void (*mark_lang_status)		PARAMS ((struct function *));
-extern void (*save_lang_status)		PARAMS ((struct function *));
-extern void (*restore_lang_status)	PARAMS ((struct function *));
-extern void (*free_lang_status)         PARAMS ((struct function *));
-
 /* Save and restore status information for a nested function.  */
 extern void restore_emit_status		PARAMS ((struct function *));
 extern void free_after_parsing		PARAMS ((struct function *));
============================================================
Index: gcc/langhooks-def.h
--- gcc/langhooks-def.h	19 Apr 2002 06:21:57 -0000	1.29
+++ gcc/langhooks-def.h	19 Apr 2002 06:51:20 -0000
@@ -41,6 +41,7 @@ extern HOST_WIDE_INT hook_get_alias_set_
 
 extern void lhd_do_nothing PARAMS ((void));
 extern void lhd_do_nothing_t PARAMS ((tree));
+extern void lhd_do_nothing_f PARAMS ((struct function *));
 extern int lhd_decode_option PARAMS ((int, char **));
 extern HOST_WIDE_INT lhd_get_alias_set PARAMS ((tree));
 extern tree lhd_return_tree PARAMS ((tree));
@@ -109,6 +110,12 @@ tree lhd_tree_inlining_convert_parm_for_
 #define LANG_HOOKS_DECL_PRINTABLE_NAME	lhd_decl_printable_name
 #define LANG_HOOKS_SET_YYDEBUG		lhd_set_yydebug
 
+#define LANG_HOOKS_FUNCTION_ENTER	lhd_do_nothing_f
+#define LANG_HOOKS_FUNCTION_LEAVE	lhd_do_nothing_f
+#define LANG_HOOKS_FUNCTION_ENTER_NESTED lhd_do_nothing_f
+#define LANG_HOOKS_FUNCTION_LEAVE_NESTED lhd_do_nothing_f
+#define LANG_HOOKS_FUNCTION_MARK	lhd_do_nothing_f
+
 /* Tree inlining hooks.  */
 #define LANG_HOOKS_TREE_INLINING_WALK_SUBTREES lhd_tree_inlining_walk_subtrees
 #define LANG_HOOKS_TREE_INLINING_CANNOT_INLINE_TREE_FN \
@@ -146,6 +153,14 @@ tree lhd_tree_inlining_convert_parm_for_
   LANG_HOOKS_TREE_INLINING_CONVERT_PARM_FOR_INLINING \
 } \
 
+#define LANG_HOOKS_FUNCTION_INITIALIZER { \
+  LANG_HOOKS_FUNCTION_ENTER, \
+  LANG_HOOKS_FUNCTION_LEAVE, \
+  LANG_HOOKS_FUNCTION_ENTER_NESTED, \
+  LANG_HOOKS_FUNCTION_LEAVE_NESTED, \
+  LANG_HOOKS_FUNCTION_MARK \
+}
+
 /* Tree dump hooks.  */
 int lhd_tree_dump_dump_tree 			PARAMS ((void *, tree));
 int lhd_tree_dump_type_quals			PARAMS ((tree));
@@ -231,6 +246,7 @@ int lhd_tree_dump_type_quals			PARAMS ((
   LANG_HOOKS_DECL_PRINTABLE_NAME, \
   LANG_HOOKS_PRINT_ERROR_FUNCTION, \
   LANG_HOOKS_SET_YYDEBUG, \
+  LANG_HOOKS_FUNCTION_INITIALIZER, \
   LANG_HOOKS_TREE_INLINING_INITIALIZER, \
   LANG_HOOKS_TREE_DUMP_INITIALIZER, \
   LANG_HOOKS_DECLS, \
============================================================
Index: gcc/langhooks.c
--- gcc/langhooks.c	19 Apr 2002 06:21:57 -0000	1.28
+++ gcc/langhooks.c	19 Apr 2002 06:51:20 -0000
@@ -39,11 +39,19 @@ lhd_do_nothing ()
 {
 }
 
-/* Do nothing.  */
+/* Do nothing (tree).  */
 
 void
 lhd_do_nothing_t (t)
      tree t ATTRIBUTE_UNUSED;
+{
+}
+
+/* Do nothing (function).  */
+
+void
+lhd_do_nothing_f (f)
+     struct function *f ATTRIBUTE_UNUSED;
 {
 }
 
============================================================
Index: gcc/langhooks.h
--- gcc/langhooks.h	19 Apr 2002 06:21:57 -0000	1.36
+++ gcc/langhooks.h	19 Apr 2002 06:51:24 -0000
@@ -57,6 +57,26 @@ struct lang_hooks_for_tree_inlining
 							 union tree_node *));
 };
 
+/* Lang hooks for management of language-specific data or status
+   when entering / leaving functions etc.  */
+struct lang_hooks_for_functions
+{
+  /* Called when entering a function.  */
+  void (*enter) PARAMS ((struct function *));
+
+  /* Called when leaving a function.  */
+  void (*leave) PARAMS ((struct function *));
+
+  /* Called when entering a nested function.  */
+  void (*enter_nested) PARAMS ((struct function *));
+
+  /* Called when leaving a nested function.  */
+  void (*leave_nested) PARAMS ((struct function *));
+
+  /* Lang-specific function data marking for GC.  */
+  void (*mark) PARAMS ((struct function *));
+};
+
 /* The following hooks are used by tree-dump.c.  */
 
 struct lang_hooks_for_tree_dump
@@ -311,6 +331,9 @@ struct lang_hooks
      command line.  By default, if the parameter is non-zero, prints a
      warning that the front end does not use such a parser.  */
   void (*set_yydebug) PARAMS ((int));
+
+  /* Function-related language hooks.  */
+  struct lang_hooks_for_functions function;
 
   struct lang_hooks_for_tree_inlining tree_inlining;
   
============================================================
Index: gcc/cp/cp-lang.c
--- gcc/cp/cp-lang.c	19 Apr 2002 06:22:13 -0000	1.30
+++ gcc/cp/cp-lang.c	19 Apr 2002 06:51:25 -0000
@@ -93,6 +93,13 @@ static bool cxx_warn_unused_global_decl 
 #undef LANG_HOOKS_WARN_UNUSED_GLOBAL_DECL
 #define LANG_HOOKS_WARN_UNUSED_GLOBAL_DECL cxx_warn_unused_global_decl
 
+#undef LANG_HOOKS_FUNCTION_ENTER
+#define LANG_HOOKS_FUNCTION_ENTER cxx_push_function_context
+#undef LANG_HOOKS_FUNCTION_LEAVE
+#define LANG_HOOKS_FUNCTION_LEAVE cxx_pop_function_context
+#undef LANG_HOOKS_FUNCTION_MARK
+#define LANG_HOOKS_FUNCTION_MARK cxx_mark_function_context
+
 #undef LANG_HOOKS_TREE_INLINING_WALK_SUBTREES
 #define LANG_HOOKS_TREE_INLINING_WALK_SUBTREES \
   cp_walk_subtrees
============================================================
Index: gcc/cp/cp-tree.h
--- gcc/cp/cp-tree.h	19 Apr 2002 06:22:13 -0000	1.707
+++ gcc/cp/cp-tree.h	19 Apr 2002 06:51:38 -0000
@@ -3658,6 +3658,9 @@ extern void cxx_init_decl_processing		PA
 extern void cxx_mark_tree			PARAMS ((tree));
 extern void cxx_insert_default_attributes	PARAMS ((tree));
 extern bool cxx_mark_addressable		PARAMS ((tree));
+extern void cxx_push_function_context		PARAMS ((struct function *));
+extern void cxx_pop_function_context		PARAMS ((struct function *));
+extern void cxx_mark_function_context		PARAMS ((struct function *));
 extern int toplevel_bindings_p			PARAMS ((void));
 extern int namespace_bindings_p			PARAMS ((void));
 extern void keep_next_level			PARAMS ((int));
============================================================
Index: gcc/cp/decl.c
--- gcc/cp/decl.c	19 Apr 2002 06:22:14 -0000	1.899
+++ gcc/cp/decl.c	19 Apr 2002 06:52:17 -0000
@@ -128,11 +128,8 @@ static void layout_var_decl PARAMS ((tre
 static void maybe_commonize_var PARAMS ((tree));
 static tree check_initializer PARAMS ((tree, tree));
 static void make_rtl_for_nonlocal_decl PARAMS ((tree, tree, const char *));
-static void push_cp_function_context PARAMS ((struct function *));
-static void pop_cp_function_context PARAMS ((struct function *));
 static void mark_binding_level PARAMS ((void *));
 static void mark_named_label_lists PARAMS ((void *, void *));
-static void mark_cp_function_context PARAMS ((struct function *));
 static void mark_saved_scope PARAMS ((void *));
 static void mark_lang_function PARAMS ((struct cp_language_function *));
 static void save_function_data PARAMS ((tree));
@@ -6481,9 +6478,6 @@ cxx_init_decl_processing ()
   initialize_predefined_identifiers ();
 
   /* Fill in back-end hooks.  */
-  init_lang_status = &push_cp_function_context;
-  free_lang_status = &pop_cp_function_context;
-  mark_lang_status = &mark_cp_function_context;
   lang_missing_noreturn_ok_p = &cp_missing_noreturn_ok_p;
 
   cp_parse_init ();
@@ -14340,7 +14334,7 @@ finish_function (flags)
   if (! nested)
     /* Let the error reporting routines know that we're outside a
        function.  For a nested function, this value is used in
-       pop_cp_function_context and then reset via pop_function_context.  */
+       cxx_pop_function_context and then reset via pop_function_context.  */
     current_function_decl = NULL_TREE;
 
   return fndecl;
@@ -14629,8 +14623,8 @@ revert_static_member_fn (decl)
 /* Initialize the variables used during compilation of a C++
    function.  */
 
-static void
-push_cp_function_context (f)
+void
+cxx_push_function_context (f)
      struct function *f;
 {
   struct cp_language_function *p
@@ -14650,8 +14644,8 @@ push_cp_function_context (f)
 /* Free the language-specific parts of F, now that we've finished
    compiling the function.  */
 
-static void
-pop_cp_function_context (f)
+void
+cxx_pop_function_context (f)
      struct function *f;
 {
   if (f->language)
@@ -14689,8 +14683,8 @@ mark_lang_function (p)
 
 /* Mark the language-specific data in F for GC.  */
 
-static void
-mark_cp_function_context (f)
+void
+cxx_mark_function_context (f)
      struct function *f;
 {
   mark_lang_function ((struct cp_language_function *) f->language);
============================================================
Index: gcc/objc/objc-lang.c
--- gcc/objc/objc-lang.c	19 Apr 2002 06:22:18 -0000	1.18
+++ gcc/objc/objc-lang.c	19 Apr 2002 06:52:17 -0000
@@ -73,6 +73,13 @@ static void objc_post_options           
 #undef LANG_HOOKS_WARN_UNUSED_GLOBAL_DECL
 #define LANG_HOOKS_WARN_UNUSED_GLOBAL_DECL c_warn_unused_global_decl
 
+#undef LANG_HOOKS_FUNCTION_ENTER_NESTED
+#define LANG_HOOKS_FUNCTION_ENTER_NESTED c_push_function_context
+#undef LANG_HOOKS_FUNCTION_LEAVE_NESTED
+#define LANG_HOOKS_FUNCTION_LEAVE_NESTED c_pop_function_context
+#undef LANG_HOOKS_FUNCTION_MARK
+#define LANG_HOOKS_FUNCTION_MARK c_mark_function_context
+
 /* Inlining hooks same as the C front end.  */
 #undef LANG_HOOKS_TREE_INLINING_CANNOT_INLINE_TREE_FN
 #define LANG_HOOKS_TREE_INLINING_CANNOT_INLINE_TREE_FN \



More information about the Gcc-patches mailing list