This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH] Cleanup {push,pop}_function_context (also removing {enter,leave}_nested langhooks)
- From: Paolo Bonzini <bonzini at gnu dot org>
- To: GCC Patches <gcc-patches at gcc dot gnu dot org>
- Date: Wed, 02 Apr 2008 17:46:08 +0200
- Subject: [PATCH] Cleanup {push,pop}_function_context (also removing {enter,leave}_nested langhooks)
These two functions just call push_function_context_to and
pop_function_context_from, whose arguments are unused. Therefore, this
patch just leaves the zero-argument variants and remove the one-argument
functions.
Also, the langhooks are used only by the C front-end. After the
simplification that goes on in function.c, and given that the C
front-end only calls the function when it knows that cfun != 0, I think
it's better to provide wrappers for {push,pop}_function_context instead,
and call those from the front-end.
This is what the patch (bootstrapped/regtested i686-pc-linux-gnu) does.
Ok for mainline?
Paolo
2008-04-02 Paolo Bonzini <bonzini@gnu.org>
* c-objc-common.h (LANG_HOOKS_FUNCTION_ENTER_NESTED,
LANG_HOOKS_FUNCTION_LEAVE_NESTED): Delete.
* c-tree.h (c_push_function_context, c_pop_function_context): Remove
argument.
* c-decl.c (c_push_function_context, c_pop_function_context): Remove
argument, call {push,pop}_function_context from here.
* c-parser.c: Use c_{push,pop}_function_context.
* function.c (push_function_context_to): Move meat ...
(push_function_context): ... here. Simplify.
* function.c (pop_function_context_from): Move meat ...
(pop_function_context): ... here. Simplify.
* langhooks.h (struct lang_hooks_for_functions): Remove enter_nested,
leave_nested).
* langhooks-def.h (LANG_HOOKS_FUNCTION_ENTER_NESTED,
LANG_HOOKS_FUNCTION_LEAVE_NESTED): Delete.
(LANG_HOOKS_FUNCTION_INITIALIZER): Delete them from here.
* tree.h (push_function_context_to, pop_function_context_from): Remove.
cp:
2008-04-02 Paolo Bonzini <bonzini@gnu.org>
* method.c (synthesize_method): Use {push,pop}_function_context.
* name-lookup.c (push_to_top_level): Likewise.
* parser.c (cp_parser_late_parsing_for_member): Likewise.
Index: tree.h
===================================================================
--- tree.h (revision 133832)
+++ tree.h (working copy)
@@ -4958,8 +4958,6 @@ extern void preserve_temp_slots (rtx);
extern int aggregate_value_p (const_tree, const_tree);
extern void push_function_context (void);
extern void pop_function_context (void);
-extern void push_function_context_to (tree);
-extern void pop_function_context_from (tree);
extern tree gimplify_parameters (void);
/* In print-rtl.c */
Index: cp/method.c
===================================================================
--- cp/method.c (revision 133832)
+++ cp/method.c (working copy)
@@ -772,7 +772,7 @@ synthesize_method (tree fndecl)
if (! context)
push_to_top_level ();
else if (nested)
- push_function_context_to (context);
+ push_function_context ();
input_location = DECL_SOURCE_LOCATION (fndecl);
@@ -810,7 +810,7 @@ synthesize_method (tree fndecl)
if (! context)
pop_from_top_level ();
else if (nested)
- pop_function_context_from (context);
+ pop_function_context ();
pop_deferring_access_checks ();
Index: cp/name-lookup.c
===================================================================
--- cp/name-lookup.c (revision 133832)
+++ cp/name-lookup.c (working copy)
@@ -5101,7 +5101,7 @@ push_to_top_level (void)
if (cfun)
{
need_pop = true;
- push_function_context_to (NULL_TREE);
+ push_function_context ();
}
else
need_pop = false;
@@ -5180,7 +5180,7 @@ pop_from_top_level (void)
/* If we were in the middle of compiling a function, restore our
state. */
if (s->need_pop_function_context)
- pop_function_context_from (NULL_TREE);
+ pop_function_context ();
current_function_decl = s->function_decl;
skip_evaluation = s->skip_evaluation;
timevar_pop (TV_NAME_LOOKUP);
Index: cp/parser.c
===================================================================
--- cp/parser.c (revision 133832)
+++ cp/parser.c (working copy)
@@ -17426,8 +17426,7 @@ cp_parser_late_parsing_for_member (cp_pa
function. */
function_scope = current_function_decl;
if (function_scope)
- push_function_context_to (function_scope);
-
+ push_function_context ();
/* Push the body of the function onto the lexer stack. */
cp_parser_push_lexer_for_tokens (parser, tokens);
@@ -17450,7 +17449,7 @@ cp_parser_late_parsing_for_member (cp_pa
/* Leave the scope of the containing function. */
if (function_scope)
- pop_function_context_from (function_scope);
+ pop_function_context ();
cp_parser_pop_lexer (parser);
}
Index: c-objc-common.h
===================================================================
--- c-objc-common.h (revision 133832)
+++ c-objc-common.h (working copy)
@@ -65,10 +63,6 @@ extern void c_initialize_diagnostics (di
#define LANG_HOOKS_PRINT_IDENTIFIER c_print_identifier
#undef LANG_HOOKS_TYPES_COMPATIBLE_P
#define LANG_HOOKS_TYPES_COMPATIBLE_P c_types_compatible_p
-#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_MISSING_NORETURN_OK_P
#define LANG_HOOKS_FUNCTION_MISSING_NORETURN_OK_P c_missing_noreturn_ok_p
#undef LANG_HOOKS_DUP_LANG_SPECIFIC_DECL
Index: c-tree.h
===================================================================
--- c-tree.h (revision 133832)
+++ c-tree.h (working copy)
@@ -483,8 +483,8 @@ extern tree grokparm (const struct c_par
extern tree implicitly_declare (tree);
extern void keep_next_level (void);
extern void pending_xref_error (void);
-extern void c_push_function_context (struct function *);
-extern void c_pop_function_context (struct function *);
+extern void c_push_function_context (void);
+extern void c_pop_function_context (void);
extern void push_parm_decl (const struct c_parm *);
extern struct c_declarator *set_array_declarator_inner (struct c_declarator *,
struct c_declarator *);
Index: c-decl.c
===================================================================
--- c-decl.c (revision 133832)
+++ c-decl.c (working copy)
@@ -6886,11 +6886,11 @@ check_for_loop_decls (void)
used during compilation of a C function. */
void
-c_push_function_context (struct function *f)
+c_push_function_context (void)
{
struct language_function *p;
p = GGC_NEW (struct language_function);
- f->language = p;
+ cfun->language = p;
p->base.x_stmt_tree = c_stmt_tree;
p->x_break_label = c_break_label;
@@ -6901,14 +6901,20 @@ c_push_function_context (struct function
p->returns_null = current_function_returns_null;
p->returns_abnormally = current_function_returns_abnormally;
p->warn_about_return_type = warn_about_return_type;
+
+ push_function_context ();
}
/* Restore the variables used during compilation of a C function. */
void
-c_pop_function_context (struct function *f)
+c_pop_function_context (void)
{
- struct language_function *p = f->language;
+ struct language_function *p;
+
+ pop_function_context ();
+ p = cfun->language;
+ cfun->language = NULL;
if (DECL_STRUCT_FUNCTION (current_function_decl) == 0
&& DECL_SAVED_TREE (current_function_decl) == NULL_TREE)
@@ -6929,8 +6935,6 @@ c_pop_function_context (struct function
current_function_returns_null = p->returns_null;
current_function_returns_abnormally = p->returns_abnormally;
warn_about_return_type = p->warn_about_return_type;
-
- f->language = NULL;
}
/* Copy the DECL_LANG_SPECIFIC data associated with DECL. */
Index: function.c
===================================================================
--- function.c (revision 133832)
+++ function.c (working copy)
@@ -234,60 +234,36 @@ find_function_data (tree decl)
}
/* Save the current context for compilation of a nested function.
- This is called from language-specific code. The caller should use
- the enter_nested langhook to save any language-specific state,
- since this function knows only about language-independent
- variables. */
+ This is called from language-specific code. */
void
-push_function_context_to (tree context ATTRIBUTE_UNUSED)
+push_function_context (void)
{
- struct function *p;
-
if (cfun == 0)
allocate_struct_function (NULL, false);
- p = cfun;
-
- p->outer = outer_function_chain;
- outer_function_chain = p;
-
- lang_hooks.function.enter_nested (p);
+ cfun->outer = outer_function_chain;
+ outer_function_chain = cfun;
set_cfun (NULL);
}
-void
-push_function_context (void)
-{
- push_function_context_to (current_function_decl);
-}
-
/* Restore the last saved context, at the end of a nested function.
This function is called from language-specific code. */
void
-pop_function_context_from (tree context ATTRIBUTE_UNUSED)
+pop_function_context (void)
{
struct function *p = outer_function_chain;
set_cfun (p);
outer_function_chain = p->outer;
-
current_function_decl = p->decl;
- lang_hooks.function.leave_nested (p);
-
/* Reset variables that have known state during rtx generation. */
virtuals_instantiated = 0;
generating_concat_p = 1;
}
-void
-pop_function_context (void)
-{
- pop_function_context_from (current_function_decl);
-}
-
/* Clear out all parts of the state in F that can safely be discarded
after the function has been parsed, but not compiled, to let
garbage collection reclaim the memory. */
Index: langhooks.h
===================================================================
--- langhooks.h (revision 133832)
+++ langhooks.h (working copy)
@@ -64,12 +64,6 @@ struct lang_hooks_for_functions
/* Called when leaving a function. */
void (*final) (struct function *);
- /* Called when entering a nested function. */
- void (*enter_nested) (struct function *);
-
- /* Called when leaving a nested function. */
- void (*leave_nested) (struct function *);
-
/* Determines if it's ok for a function to have no noreturn attribute. */
bool (*missing_noreturn_ok_p) (tree);
};
Index: c-parser.c
===================================================================
--- c-parser.c (revision 133832)
+++ c-parser.c (working copy)
@@ -1374,7 +1374,7 @@ c_parser_declaration_or_fndef (c_parser
{
if (pedantic)
pedwarn ("%HISO C forbids nested functions", &here);
- push_function_context ();
+ c_push_function_context ();
}
if (!start_function (specs, declarator, all_prefix_attrs))
{
@@ -1384,7 +1384,7 @@ c_parser_declaration_or_fndef (c_parser
c_parser_error (parser, "expected %<=%>, %<,%>, %<;%>, %<asm%> "
"or %<__attribute__%>");
if (nested)
- pop_function_context ();
+ c_pop_function_context ();
break;
}
/* Parse old-style parameter declarations. ??? Attributes are
@@ -1411,7 +1411,7 @@ c_parser_declaration_or_fndef (c_parser
tree decl = current_function_decl;
add_stmt (fnbody);
finish_function ();
- pop_function_context ();
+ c_pop_function_context ();
add_stmt (build_stmt (DECL_EXPR, decl));
}
else
Index: langhooks-def.h
===================================================================
--- langhooks-def.h (revision 133832)
+++ langhooks-def.h (working copy)
@@ -117,8 +117,6 @@ extern void lhd_omp_firstprivatize_type_
#define LANG_HOOKS_FUNCTION_INIT lhd_do_nothing_f
#define LANG_HOOKS_FUNCTION_FINAL 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_MISSING_NORETURN_OK_P hook_bool_tree_true
/* Attribute hooks. */
@@ -145,8 +143,6 @@ extern void lhd_omp_firstprivatize_type_
#define LANG_HOOKS_FUNCTION_INITIALIZER { \
LANG_HOOKS_FUNCTION_INIT, \
LANG_HOOKS_FUNCTION_FINAL, \
- LANG_HOOKS_FUNCTION_ENTER_NESTED, \
- LANG_HOOKS_FUNCTION_LEAVE_NESTED, \
LANG_HOOKS_FUNCTION_MISSING_NORETURN_OK_P \
}