Patchwork don't use build_function_type in the Java FE

login
register
mail settings
Submitter Nathan Froyd
Date May 10, 2011, 1:20 p.m.
Message ID <20110510132035.GV23480@codesourcery.com>
Download mbox | patch
Permalink /patch/95009/
State New
Headers show

Comments

Nathan Froyd - May 10, 2011, 1:20 p.m.
As $SUBJECT suggests.  Nothing much to see here.

Tested on x86_64-unknown-linux-gnu.  OK to commit?

-Nathan

gcc/java/
	* expr.c (build_jni_stub): Don't call build_function_type; call
	build_function_type_vec instead.
	* typeck.c (parse_signature_string): Likewise.

Patch

diff --git a/gcc/java/expr.c b/gcc/java/expr.c
index 3be1cff..5d9811a 100644
--- a/gcc/java/expr.c
+++ b/gcc/java/expr.c
@@ -2616,7 +2616,7 @@  expand_invoke (int opcode, int method_ref_index, int nargs ATTRIBUTE_UNUSED)
 tree
 build_jni_stub (tree method)
 {
-  tree jnifunc, call, body, method_sig, arg_types;
+  tree jnifunc, call, body, method_sig, arg_type;
   tree jniarg0, jniarg1, jniarg2, jniarg3;
   tree jni_func_type, tem;
   tree env_var, res_var = NULL_TREE, block;
@@ -2624,7 +2624,9 @@  build_jni_stub (tree method)
   tree meth_var;
   tree bind;
   VEC(tree,gc) *args = NULL;
+  VEC(tree,gc) *arg_types = NULL;
   int args_size = 0;
+  function_args_iterator iter;
 
   tree klass = DECL_CONTEXT (method);
   klass = build_class_ref (klass);
@@ -2684,13 +2686,17 @@  build_jni_stub (tree method)
 
       VEC_safe_push (tree, gc, args, tem);
     }
-  arg_types = TYPE_ARG_TYPES (TREE_TYPE (method));
 
-  /* Argument types for static methods and the JNIEnv structure.
-     FIXME: Write and use build_function_type_vec to avoid this.  */
+  /* Argument types for static methods and the JNIEnv structure.  */
+  VEC_safe_push (tree, gc, arg_types, ptr_type_node);
   if (METHOD_STATIC (method))
-    arg_types = tree_cons (NULL_TREE, object_ptr_type_node, arg_types);
-  arg_types = tree_cons (NULL_TREE, ptr_type_node, arg_types);
+    VEC_safe_push (tree, gc, arg_types, object_ptr_type_node);
+  FOREACH_FUNCTION_ARGS (TREE_TYPE (method), arg_type, iter)
+    {
+      if (arg_type == void_type_node)
+	break;
+      VEC_safe_push (tree, gc, arg_types, arg_type);
+    }
 
   /* We call _Jv_LookupJNIMethod to find the actual underlying
      function pointer.  _Jv_LookupJNIMethod will throw the appropriate
@@ -2703,7 +2709,7 @@  build_jni_stub (tree method)
 			     IDENTIFIER_LENGTH (method_sig)));
   jniarg3 = build_int_cst (NULL_TREE, args_size);
 
-  tem = build_function_type (TREE_TYPE (TREE_TYPE (method)), arg_types);
+  tem = build_function_type_vec (TREE_TYPE (TREE_TYPE (method)), arg_types);
 
 #ifdef MODIFY_JNI_METHOD_CALL
   tem = MODIFY_JNI_METHOD_CALL (tem);
diff --git a/gcc/java/typeck.c b/gcc/java/typeck.c
index 6755217..247fd64 100644
--- a/gcc/java/typeck.c
+++ b/gcc/java/typeck.c
@@ -407,18 +407,17 @@  parse_signature_string (const unsigned char *sig_string, int sig_length)
 
   if (str < limit && str[0] == '(')
     {
-      tree argtype_list = NULL_TREE;
+      VEC(tree,gc) *argtypes = NULL;
       str++;
       while (str < limit && str[0] != ')')
 	{
 	  tree argtype = parse_signature_type (&str, limit);
-	  argtype_list = tree_cons (NULL_TREE, argtype, argtype_list);
+	  VEC_safe_push (tree, gc, argtypes, argtype);
 	}
       if (str++, str >= limit)
 	abort ();
       result_type = parse_signature_type (&str, limit);
-      argtype_list = chainon (nreverse (argtype_list), end_params_node);
-      result_type = build_function_type (result_type, argtype_list);
+      result_type = build_function_type_vec (result_type, argtypes);
     }
   else
     result_type = parse_signature_type (&str, limit);