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] cp/cp-tree.h: Remove FUNCTION_FIRST_USER_PARMTYPE.


Hi,

Attached is a patch to remove FUNCTION_FIRST_USER_PARMTYPE.

One of the things we would like to do on the LTO branch is to change
TYPE_ARG_TYPES to use a TREE_VEC.  This means that we will not be able
to apply TREE_CHAIN to a type list.  We will have to use TREE_VEC_ELT.

While FUNCTION_FIRST_USER_PARMTYPE may seem nice abstraction at first
glance, it uses TREE_CHAIN indirectly via skip_artificial_parms_for.

This patch cancels the abstraction and pastes the macro definition
everywhere FUNCTION_FIRST_USER_PARMTYPE is used.

To compute the number of artificial parameters for a given function,
I've introduced num_artificial_parms_for.  A caller of this function
would take the result, say to a variable SKIP, and then uses it to
skip the first SKIP parameters.

  tree arg_types = TYPE_ARG_TYPES (TREE_TYPE (fn));
  int skip = num_artificial_parms_for (fn);
  while (skip--)
    arg_types = TREE_CHAIN (arg_types);

The "while" loop above will be converted to something else as the
development continues, but I don't want to do too many things at once.

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

Kazu Hirata

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

	* cp-tree.h (FUNCTION_FIRST_USER_PARMTYPE): Remove.
	Add a prototype for num_artificial_parms_for.
	* call.c (add_template_candidate_real): Don't use
	FUNCTION_FIRST_USER_PARMTYPE.
	* cxx-pretty-print.c (pp_cxx_parameter_declaration_clause):
	Likewise.
	* decl.c (grokdeclarator, copy_fn_p): Likewise.
	* error.c (dump_function_decl): Likewise.
	* method.c (synthesize_method): Likewise.
	(num_artificial_parms_for): New.

Index: cp/call.c
===================================================================
--- cp/call.c	(revision 114647)
+++ cp/call.c	(working copy)
@@ -2248,7 +2248,10 @@ add_template_candidate_real (struct z_ca
      have that form.  */
   if (DECL_CONSTRUCTOR_P (fn) && list_length (arglist) == 2)
     {
-      tree arg_types = FUNCTION_FIRST_USER_PARMTYPE (fn);
+      tree arg_types = TYPE_ARG_TYPES (TREE_TYPE (fn));
+      int skip = num_artificial_parms_for (fn);
+      while (skip--)
+	arg_types = TREE_CHAIN (arg_types);
       if (arg_types && same_type_p (TYPE_MAIN_VARIANT (TREE_VALUE (arg_types)),
 				    ctype))
 	return NULL;
Index: cp/cp-tree.h
===================================================================
--- cp/cp-tree.h	(revision 114648)
+++ cp/cp-tree.h	(working copy)
@@ -920,11 +920,8 @@ enum languages { lang_c, lang_cplusplus,
   ((cp_type_quals (NODE) & (TYPE_QUAL_CONST | TYPE_QUAL_VOLATILE))	\
    == TYPE_QUAL_CONST)
 
-/* Given a FUNCTION_DECL, returns the first TREE_LIST out of TYPE_ARG_TYPES
+/* Given a FUNCTION_DECL, returns the first TREE_LIST out of DECL_ARGUMENTS
    which refers to a user-written parameter.  */
-#define FUNCTION_FIRST_USER_PARMTYPE(NODE) \
-  skip_artificial_parms_for ((NODE), TYPE_ARG_TYPES (TREE_TYPE (NODE)))
-
 /* Similarly, but for DECL_ARGUMENTS.  */
 #define FUNCTION_FIRST_USER_PARM(NODE)						\
   skip_artificial_parms_for ((NODE),						\
@@ -4069,6 +4066,7 @@ extern void synthesize_method			(tree);
 extern tree lazily_declare_fn			(special_function_kind,
 						 tree);
 extern tree skip_artificial_parms_for		(tree, tree);
+extern int num_artificial_parms_for		(tree);
 extern tree make_alias_for			(tree, tree);
 
 /* In optimize.c */
Index: cp/cxx-pretty-print.c
===================================================================
--- cp/cxx-pretty-print.c	(revision 114647)
+++ cp/cxx-pretty-print.c	(working copy)
@@ -1216,11 +1216,21 @@ static void
 pp_cxx_parameter_declaration_clause (cxx_pretty_printer *pp, tree t)
 {
   tree args = TYPE_P (t) ? NULL : FUNCTION_FIRST_USER_PARM (t);
-  tree types =
-    TYPE_P (t) ? TYPE_ARG_TYPES (t) : FUNCTION_FIRST_USER_PARMTYPE (t);
+  tree types;
   const bool abstract = args == NULL
     || pp_c_base (pp)->flags & pp_c_flag_abstract;
   bool first = true;
+  int skip;
+
+  if (TYPE_P (t))
+    types = TYPE_ARG_TYPES (t);
+  else
+    {
+      types = TYPE_ARG_TYPES (TREE_TYPE (t));
+      skip = num_artificial_parms_for (t);
+      while (skip--)
+	types = TREE_CHAIN (types);
+    }
 
   /* Skip artificial parameter for nonstatic member functions.  */
   if (TREE_CODE (t) == METHOD_TYPE)
Index: cp/decl.c
===================================================================
--- cp/decl.c	(revision 114647)
+++ cp/decl.c	(working copy)
@@ -8264,8 +8264,12 @@ grokdeclarator (const cp_declarator *dec
 		   parameter if there is at least one parameter, and
 		   any subsequent parameters have default arguments.
 		   Ignore any compiler-added parms.  */
-		tree arg_types = FUNCTION_FIRST_USER_PARMTYPE (decl);
+		tree arg_types = TYPE_ARG_TYPES (TREE_TYPE (decl));
 		tree parm_decls = FUNCTION_FIRST_USER_PARM (decl);
+		int skip = num_artificial_parms_for (decl);
+
+		while (skip--)
+		  arg_types = TREE_CHAIN (arg_types);
 
 		if (arg_types == void_list_node
 		    || (arg_types
@@ -8850,6 +8854,7 @@ copy_fn_p (tree d)
   tree args, parm_decls;
   tree arg_type;
   int result = 1;
+  int skip;
 
   if (!DECL_FUNCTION_MEMBER_P (d))
     /* Non-members are invalid.  We complained, but kept the declaration.  */
@@ -8864,7 +8869,10 @@ copy_fn_p (tree d)
        accept those as copy functions.  */
     return 0;
 
-  args = FUNCTION_FIRST_USER_PARMTYPE (d);
+  args = TYPE_ARG_TYPES (TREE_TYPE (d));
+  skip = num_artificial_parms_for (d);
+  while (skip--)
+    args = TREE_CHAIN (args);
   parm_decls = FUNCTION_FIRST_USER_PARM (d);
   if (!args)
     return 0;
Index: cp/error.c
===================================================================
--- cp/error.c	(revision 114647)
+++ cp/error.c	(working copy)
@@ -987,6 +987,7 @@ dump_function_decl (tree t, int flags)
   tree template_args = NULL_TREE;
   tree template_parms = NULL_TREE;
   int show_return = flags & TFF_RETURN_TYPE || flags & TFF_DECL_SPECIFIERS;
+  int skip;
 
   if (TREE_CODE (t) == TEMPLATE_DECL)
     t = DECL_TEMPLATE_RESULT (t);
@@ -1006,7 +1007,10 @@ dump_function_decl (tree t, int flags)
     }
 
   fntype = TREE_TYPE (t);
-  parmtypes = FUNCTION_FIRST_USER_PARMTYPE (t);
+  parmtypes = TYPE_ARG_TYPES (TREE_TYPE (t));
+  skip = num_artificial_parms_for (t);
+  while (skip--)
+    parmtypes = TREE_CHAIN (parmtypes);
   parmdecls = FUNCTION_FIRST_USER_PARM (t);
 
   if (DECL_CLASS_SCOPE_P (t))
Index: cp/method.c
===================================================================
--- cp/method.c	(revision 114647)
+++ cp/method.c	(working copy)
@@ -777,7 +777,10 @@ synthesize_method (tree fndecl)
     }
   else if (DECL_CONSTRUCTOR_P (fndecl))
     {
-      tree arg_chain = FUNCTION_FIRST_USER_PARMTYPE (fndecl);
+      tree arg_chain = TYPE_ARG_TYPES (TREE_TYPE (fndecl));
+      int skip = num_artificial_parms_for (fndecl);
+      while (skip--)
+	arg_chain = TREE_CHAIN (arg_chain);
       if (arg_chain != void_list_node)
 	do_build_copy_constructor (fndecl);
       else if (TYPE_NEEDS_CONSTRUCTING (current_class_type))
@@ -1180,4 +1183,24 @@ skip_artificial_parms_for (tree fn, tree
   return list;
 }
 
+/* Given a FUNCTION_DECL FN and a chain LIST, return the number of
+   artificial parms in FN.  */
+
+int
+num_artificial_parms_for (tree fn)
+{
+  int count = 0;
+
+  if (DECL_NONSTATIC_MEMBER_FUNCTION_P (fn))
+    count++;
+  else
+    return 0;
+
+  if (DECL_HAS_IN_CHARGE_PARM_P (fn))
+    count++;
+  if (DECL_HAS_VTT_PARM_P (fn))
+    count++;
+  return count;
+}
+
 #include "gt-cp-method.h"


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