diff options
author | Mark Mitchell <mark@codesourcery.com> | 2000-09-07 01:36:11 +0000 |
---|---|---|
committer | Mark Mitchell <mmitchel@gcc.gnu.org> | 2000-09-07 01:36:11 +0000 |
commit | ae499ccea4f2eee460c8612d920755773cacfe47 (patch) | |
tree | 1ae8ce0d3f4f58cfa7b33b9fac7c1209e34d27a7 /gcc/c-semantics.c | |
parent | 4f4b88d0832c7279722b5dee73d9ce9f1704452f (diff) | |
download | gcc-ae499ccea4f2eee460c8612d920755773cacfe47.zip gcc-ae499ccea4f2eee460c8612d920755773cacfe47.tar.gz gcc-ae499ccea4f2eee460c8612d920755773cacfe47.tar.bz2 |
Move statement-tree facilities from C++ to C front-end.
* c-common.h (c_tree_index): Add CTI_VOID_ZERO.
(void_zero_node): New macro.
(struct stmt_tree_s): New type.
(stmt_tree): New typedef.
(struct language_function): New type.
(last_tree): New macro.
(last_expr_type): Likewise.
(walk_tree_fn): New typedef.
(current_stmt_tree): New function.
(begin_stmt_tree): Likewise.
(add_stmt): Likewise.
(finish_stmt_tree): Likewise.
(statement_code_p): Likewise.
(lang_statement_code_p): New variable.
(walk_stmt_tree): New function.
(STMT_IS_FULL_EXPR_P): New macro.
* c-common.c (lang_statement_code_p): New variable.
(c_common_nodes_and_builtins): Initialize void_zero_node.
(statement_code_p): New function.
(walk_stmt_tree): Likewise.
* c-decl.c (language_function): Rename to ...
(c_language_function): ... this. Include language_function.
(push_c_function_context): Adjust accordingly.
(pop_c_function_context): Likewise.
(mark_c_function_context): Likewise.
(current_stmt_tree): Define.
* c-semantics.c (begin_stmt_tree): New function.
(add_stmt): Likewise.
(prune_unused_decls): Likewise.
(finish_stmt_tree): Likewise.
Move statement-tree facilities from C++ to C front-end.
* cp-tree.h (cp_tree_index): Remove CPTI_VOID_ZERO.
(void_zero_node): Remove.
(stmt_tree): Likewise.
(scope_chain): Adjust.
(language_function): Rename to cp_language_function.
(cp_function_chain): Adjust.
(current_stmt_tree): Remove.
(last_tree): Likewise.
(last_expr_type): Likewise.
(struct lang_decl): Adjust.
(STMT_IS_FULL_EXPR_P): Remove.
(add_tree): Remove.
(begin_stmt_tree): Likewise.
(finish_stmt_tree): Likewise.
(walk_tree_fn): Likewise.
(walk_stmt_tree): Likewise.
* class.c (finish_struct): Replace use of add_tree with add_stmt.
* decl.c (mark_stmt_tree): Adjust type.
(init_decl_processing): Don't build void_zero_node.
(initialize_local_var): Adjust usage of current_stmt_tree.
(finish_enum): Use add_stmt, not add_tree.
(save_function_data): Adjust use of language_function.
(finish_constructor_body): Use add_stmt, not add_tree.
(finish_destructor_body): Likewise.
(push_cp_function_context): Adjust use of language_function.
(pop_cp_function_context): Likewise.
(mark_lang_function): Likewise.
(mark_cp_function_context): Likewise.
* init.c (build_aggr_init): Adjust use of current_stmt_tree.
(build_vec_init): Likewise.
* semantics.c (SET_LAST_STMT): Remove.
(RECHAIN_STMTS): Don't use it.
(stmts_are_full_exprs_p): Adjust use of current_stmt_tree.
(current_stmt_tree): Define.
(add_tree): Remove.
(finish_goto_stmt): Use add_stmt, not add_tree.
(finish_expr_stmt): Likewise.
(begin_if_stmt): Likewise.
(finish_then_clause): Likewise.
(begin_while_stmt): Likewise.
(begin_do_stmt): Likewise.
(finish_return_stmt): Likewise.
(begin_for_stmt): Likewise.
(finish_break_stmt): Likewise.
(finish_continue_stmt): Likewise.
(begin_switch_stmt): Likewise.
(finish_case_label): Likewise.
(begin_try_block): Likewise.
(begin_function_try_block): Likewise.
(begin_handler): Likewise.
(begin_catch_block): Likewise.
(begin_compound_stmt): Likewise.
(begin_asm_stmt): Likewise.
(finish_asm_stmt): Likewise.
(finish_label_stmt): Likewise.
(add_decl_stmt): Likewise.
(finish_subobject): Likewise.
(finish_decl_cleanup): Likewise.
(finish_named_return_value): Likewise.
(setup_vtbl_ptr): Likewise.
(add_scope_stmt): Likewise.
(finish_stmt_expr): Likewise.
(prune_unused_decls): Remove.
(begin_stmt_tree): Likewise.
(finish_stmt_tree): Likewise.
(prep_stmt): Adjust use of current_stmt_tree.
(lang_expand_stmt): Likewise.
* tree.c (statement_code_p): Remove.
(cp_statement_code_p): New function.
(walk_stmt_tree): Remove.
(init_tree): Set lang_statement_code_p.
From-SVN: r36221
Diffstat (limited to 'gcc/c-semantics.c')
-rw-r--r-- | gcc/c-semantics.c | 113 |
1 files changed, 113 insertions, 0 deletions
diff --git a/gcc/c-semantics.c b/gcc/c-semantics.c index 2e0d537..eea9f92 100644 --- a/gcc/c-semantics.c +++ b/gcc/c-semantics.c @@ -36,6 +36,119 @@ Boston, MA 02111-1307, USA. */ #include "output.h" #include "timevar.h" +static tree prune_unused_decls PARAMS ((tree *, int *, void *)); + +/* Create an empty statement tree rooted at T. */ + +void +begin_stmt_tree (t) + tree *t; +{ + /* We create a trivial EXPR_STMT so that last_tree is never NULL in + what follows. We remove the extraneous statement in + finish_stmt_tree. */ + *t = build_nt (EXPR_STMT, void_zero_node); + last_tree = *t; + last_expr_type = NULL_TREE; +} + +/* T is a statement. Add it to the statement-tree. */ + +void +add_stmt (t) + tree t; +{ + /* Add T to the statement-tree. */ + TREE_CHAIN (last_tree) = t; + last_tree = t; + /* When we expand a statement-tree, we must know whether or not the + statements are full-expresions. We record that fact here. */ + STMT_IS_FULL_EXPR_P (last_tree) = stmts_are_full_exprs_p (); +} + +/* Remove declarations of internal variables that are not used from a + stmt tree. To qualify, the variable must have a name and must have + a zero DECL_SOURCE_LINE. We tried to remove all variables for + which TREE_USED was false, but it turns out that there's tons of + variables for which TREE_USED is false but that are still in fact + used. */ + +static tree +prune_unused_decls (tp, walk_subtrees, data) + tree *tp; + int *walk_subtrees ATTRIBUTE_UNUSED; + void *data ATTRIBUTE_UNUSED; +{ + tree t = *tp; + + if (t == NULL_TREE) + { + *walk_subtrees = 0; + return NULL_TREE; + } + + if (TREE_CODE (t) == DECL_STMT) + { + tree d = DECL_STMT_DECL (t); + if (!TREE_USED (d) && DECL_NAME (d) && DECL_SOURCE_LINE (d) == 0) + { + *tp = TREE_CHAIN (t); + /* Recurse on the new value of tp, otherwise we will skip + the next statement. */ + return prune_unused_decls (tp, walk_subtrees, data); + } + } + else if (TREE_CODE (t) == SCOPE_STMT) + { + /* Remove all unused decls from the BLOCK of this SCOPE_STMT. */ + tree block = SCOPE_STMT_BLOCK (t); + + if (block) + { + tree *vp; + + for (vp = &BLOCK_VARS (block); *vp; ) + { + tree v = *vp; + if (! TREE_USED (v) && DECL_NAME (v) && DECL_SOURCE_LINE (v) == 0) + *vp = TREE_CHAIN (v); /* drop */ + else + vp = &TREE_CHAIN (v); /* advance */ + } + /* If there are now no variables, the entire BLOCK can be dropped. + (This causes SCOPE_NULLIFIED_P (t) to be true.) */ + if (BLOCK_VARS (block) == NULL_TREE) + SCOPE_STMT_BLOCK (t) = NULL_TREE; + } + } + return NULL_TREE; +} + +/* Finish the statement tree rooted at T. */ + +void +finish_stmt_tree (t) + tree *t; +{ + tree stmt; + + /* Remove the fake extra statement added in begin_stmt_tree. */ + stmt = TREE_CHAIN (*t); + *t = stmt; + last_tree = NULL_TREE; + + /* Remove unused decls from the stmt tree. */ + walk_stmt_tree (t, prune_unused_decls, NULL); + + if (cfun) + { + /* The line-number recorded in the outermost statement in a function + is the line number of the end of the function. */ + STMT_LINENO (stmt) = lineno; + STMT_LINENO_FOR_FN_P (stmt) = 1; + } +} + /* Build a generic statement based on the given type of node and arguments. Similar to `build_nt', except that we set TREE_COMPLEXITY to be the current line number. */ |