This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
RFA: PATCH to add chain lookup by index
- From: Jason Merrill <jason at redhat dot com>
- To: gcc-patches List <gcc-patches at gcc dot gnu dot org>
- Date: Thu, 10 Sep 2009 17:09:32 -0400
- Subject: RFA: PATCH to add chain lookup by index
It seems odd to me that this function didn't already exist, am I missing
something? I want to use it for a C++ patch which will follow once this
is in.
Tested x86_64-pc-linux-gnu. OK?
commit c72cdc4d6d659121d8171f5f2bedd3c27b7a54e0
Author: Jason Merrill <jason@redhat.com>
Date: Thu Sep 10 17:05:45 2009 -0400
* tree.c (chain_index): New fn.
* tree.h: Declare it.
diff --git a/gcc/tree.c b/gcc/tree.c
index 2f0e03c..27ab46c 100644
--- a/gcc/tree.c
+++ b/gcc/tree.c
@@ -1905,6 +1905,17 @@ purpose_member (const_tree elem, tree list)
return NULL_TREE;
}
+/* Returns element number IDX (zero-origin) of chain CHAIN, or
+ NULL_TREE. */
+
+tree
+chain_index (int idx, tree chain)
+{
+ for (; chain && idx > 0; --idx)
+ chain = TREE_CHAIN (chain);
+ return chain;
+}
+
/* Return nonzero if ELEM is part of the chain CHAIN. */
int
diff --git a/gcc/tree.h b/gcc/tree.h
index 9881090..7b431af 100644
--- a/gcc/tree.h
+++ b/gcc/tree.h
@@ -3914,6 +3914,7 @@ extern bool range_in_array_bounds_p (tree);
extern tree value_member (tree, tree);
extern tree purpose_member (const_tree, tree);
+extern tree chain_index (int, tree);
extern int attribute_list_equal (const_tree, const_tree);
extern int attribute_list_contained (const_tree, const_tree);