This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[lto] Introduce num_parm_types and nth_parm_type.


Hi,

Attached is a patch to introduce num_parm_types and nth_parm_type.

Since we eventually want to convert TYPE_ARG_TYPES to use TREE_VEC, we
have to deal with indexes into a TREE_VEC.  In order to facilitate the
conversion process, especially in the C++ frontend, this patch
introduces two new functions to hide implementation details of a
parameter type list.  This patch itself does not add any use of the
new functions.

I'm aware that if I use nth_parm_type in a loop, I would be
introducing small quadratic behavior.  However, that will be all
solved by the end of the conversion.

Tested on x86_64-pc-linux-gnu.  OK to apply to the LTO branch?

Kazu Hirata

2006-06-18  Kazu Hirata  <kazu@codesourcery.com>

	* tree.c (num_parm_types, nth_parm_type): New.
	* tree.h: Add prototypes for the two new functions.

Index: tree.c
===================================================================
--- tree.c	(revision 114751)
+++ tree.c	(working copy)
@@ -1563,6 +1563,29 @@ list_length (tree t)
   return len;
 }
 
+/* Return the length of a parameter type list.  */
+
+int
+num_parm_types (tree t)
+{
+  return list_length (t);
+}
+
+/* Return the Nth parameter type.  */
+
+tree
+nth_parm_type (tree list, int n)
+{
+  while (n--)
+    {
+      gcc_assert (list);
+      list = TREE_CHAIN (list);
+    }
+
+  gcc_assert (list);
+  return TREE_VALUE (list);
+}
+
 /* Returns the number of FIELD_DECLs in TYPE.  */
 
 int
Index: tree.h
===================================================================
--- tree.h	(revision 114751)
+++ tree.h	(working copy)
@@ -3911,6 +3911,14 @@ extern tree nreverse (tree);
 
 extern int list_length (tree);
 
+/* Return the length of a parameter type list.  */
+
+extern int num_parm_types (tree);
+
+/* Return the Nth parameter type.  */
+
+extern tree nth_parm_type (tree, int);
+
 /* Returns the number of FIELD_DECLs in a type.  */
 
 extern int fields_length (tree);


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]