aboutsummaryrefslogtreecommitdiff
path: root/gcc/cp/semantics.c
diff options
context:
space:
mode:
authorZack Weinberg <zack@wolery.cumb.org>2000-09-06 05:52:51 +0000
committerZack Weinberg <zack@gcc.gnu.org>2000-09-06 05:52:51 +0000
commit11f53b6a0879e853b8aa3e12b81b56f1582c38f6 (patch)
tree70e50e84e9a226d6722859ba63eba0a30b37d9c9 /gcc/cp/semantics.c
parent3392dafcfdcbe74f8c60e14fa0f3ea73363552ab (diff)
downloadgcc-11f53b6a0879e853b8aa3e12b81b56f1582c38f6.zip
gcc-11f53b6a0879e853b8aa3e12b81b56f1582c38f6.tar.gz
gcc-11f53b6a0879e853b8aa3e12b81b56f1582c38f6.tar.bz2
tree.c (walk_tree): Expose tail recursion.
* tree.c (walk_tree): Expose tail recursion. (walk_stmt_tree): New function. * cp-tree.h: Prototype walk_stmt_tree. * semantics.c (prune_unused_decls): Operate on SCOPE_STMTs not the BLOCKs directly. If a BLOCK has no variables after pruning, discard it. (finish_stmt_tree): Use walk_stmt_tree. No need to save and restore the line number. From-SVN: r36178
Diffstat (limited to 'gcc/cp/semantics.c')
-rw-r--r--gcc/cp/semantics.c37
1 files changed, 20 insertions, 17 deletions
diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c
index 7c46d1d..295c37a 100644
--- a/gcc/cp/semantics.c
+++ b/gcc/cp/semantics.c
@@ -2274,21 +2274,28 @@ prune_unused_decls (tp, walk_subtrees, data)
return prune_unused_decls (tp, walk_subtrees, data);
}
}
- else if (TREE_CODE (t) == BLOCK)
+ else if (TREE_CODE (t) == SCOPE_STMT)
{
- /* walk_tree doesn't inspect BLOCK_VARS, so we must do it by hand. */
- tree *vp;
+ /* Remove all unused decls from the BLOCK of this SCOPE_STMT. */
+ tree block = SCOPE_STMT_BLOCK (t);
- for (vp = &BLOCK_VARS (t); *vp; )
+ if (block)
{
- 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 */
+ 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;
}
- if (BLOCK_VARS (t) == NULL_TREE)
- TREE_USED (t) = 0;
}
return NULL_TREE;
}
@@ -2314,18 +2321,14 @@ finish_stmt_tree (t)
tree *t;
{
tree stmt;
- int old_lineno;
/* Remove the fake extra statement added in begin_stmt_tree. */
stmt = TREE_CHAIN (*t);
*t = stmt;
SET_LAST_STMT (NULL_TREE);
- /* Remove unused decls from the stmt tree. walk_tree messes with
- the line number, so save/restore it. */
- old_lineno = lineno;
- walk_tree_without_duplicates (t, prune_unused_decls, NULL);
- lineno = old_lineno;
+ /* Remove unused decls from the stmt tree. */
+ walk_stmt_tree (t, prune_unused_decls, NULL);
if (cfun)
{