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


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

[PATCH] Java: fixing java/1315.


This fixes java/1315:

  http://gcc.gnu.org/ml/java-prs/2000-q3/msg00092.html

And requires a modification in a test case result that was previously
incorrect. I tested the patch and didn't see any regression. It allows
use improve `make check' results. I'd like to check that in the
branch. Is the libjava/testsuite part OK?

./A

2001-03-29  Alexandre Petit-Bianco  <apbianco@redhat.com>

	* libjava.lang/instinit2.out: Fixed.

Index: libjava.lang/instinit2.out
===================================================================
RCS file: /cvs/gcc/gcc/libjava/testsuite/libjava.lang/instinit2.out,v
retrieving revision 1.1
diff -u -p -r1.1 instinit2.out
--- instinit2.out	2000/02/07 21:40:18	1.1
+++ instinit2.out	2001/03/29 23:36:59
@@ -1,4 +1,3 @@
 Testing class `instinit2'...
-Ctor
 Checking the oink...
 java.lang.Exception: It just oinked

2001-04-04  Alexandre Petit-Bianco  <apbianco@redhat.com>

	* java-tree.h (struct lang_decl): New macro
	`DECL_FIXED_CONSTRUCTOR_P.' New field `fixed_ctor.'
	* parse.y (build_instance_initializer): New function.
	(add_instance_initializer): Use it.
	(java_fix_constructors): Set `current_class' before fix pass.
	(fix_constructors): Just return if already fixed. Move `super()'
	invokation ahead. Use `build_instance_initializer.'
	Fixes PR java/1315.

Index: java-tree.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/java/java-tree.h,v
retrieving revision 1.97.2.7
diff -u -p -r1.97.2.7 java-tree.h
--- java-tree.h	2001/04/04 19:50:42	1.97.2.7
+++ java-tree.h	2001/04/05 21:14:09
@@ -713,6 +713,7 @@ struct lang_identifier
 /* True if DECL initializes all its finals */
 #define DECL_FUNCTION_ALL_FINAL_INITIALIZED(DECL) \
   (DECL_LANG_SPECIFIC(DECL)->init_final)
+#define DECL_FIXED_CONSTRUCTOR_P(DECL) (DECL_LANG_SPECIFIC(DECL)->fixed_ctor)
 
 /* True when DECL aliases an outer context local variable.  */
 #define FIELD_LOCAL_ALIAS(DECL) DECL_LANG_FLAG_6 (DECL)
@@ -862,6 +863,7 @@ struct lang_decl
   int native : 1;		/* Nonzero if this is a native method  */
   int synthetic_ctor : 1;	/* Nonzero if this is a synthetic ctor */
   int init_final : 1;		/* Nonzero all finals are initialized */
+  int fixed_ctor : 1;
 };
 
 /* init_test_table hash table entry structure.  */
Index: parse.y
===================================================================
RCS file: /cvs/gcc/gcc/gcc/java/parse.y,v
retrieving revision 1.251.2.14
diff -u -p -r1.251.2.14 parse.y
--- parse.y	2001/04/05 19:44:54	1.251.2.14
+++ parse.y	2001/04/05 21:14:45
@@ -238,6 +238,7 @@ static const char *get_printable_method_
 static tree patch_conditional_expr PARAMS ((tree, tree, tree));
 static tree generate_finit PARAMS ((tree));
 static void add_instance_initializer PARAMS ((tree));
+static tree build_instance_initializer PARAMS ((tree));
 static void fix_constructors PARAMS ((tree));
 static tree build_alias_initializer_parameter_list PARAMS ((int, tree,
 							    tree, int *));
@@ -4302,24 +4303,31 @@ generate_finit (class_type)
   return mdecl;
 }
 
-static void
-add_instance_initializer (mdecl)
+static tree
+build_instance_initializer (mdecl)
      tree mdecl;
 {
-  tree current;
-  tree stmt_list = TYPE_II_STMT_LIST (DECL_CONTEXT (mdecl));
   tree compound = NULL_TREE;
+  tree stmt_list = TYPE_II_STMT_LIST (DECL_CONTEXT (mdecl));
+  tree current;
 
-  if (stmt_list)
-    {
-      for (current = stmt_list; current; current = TREE_CHAIN (current))
-	compound = add_stmt_to_compound (compound, NULL_TREE, current);
+  for (current = stmt_list; current; current = TREE_CHAIN (current))
+    compound = add_stmt_to_compound (compound, NULL_TREE, current);
 
-      java_method_add_stmt (mdecl, build1 (INSTANCE_INITIALIZERS_EXPR,
-					   NULL_TREE, compound));
-    }
+  return compound;
 }
 
+static void
+add_instance_initializer (mdecl)
+     tree mdecl;
+{
+  tree compound = build_instance_initializer (mdecl);
+
+  if (compound)
+    java_method_add_stmt (mdecl, build1 (INSTANCE_INITIALIZERS_EXPR,
+					 NULL_TREE, compound));
+}
+
 /* Shared accros method_declarator and method_header to remember the
    patch stage that was reached during the declaration of the method.
    A method DECL is built differently is there is no patch
@@ -5233,6 +5241,7 @@ java_fix_constructors ()
       if (CLASS_INTERFACE (TYPE_NAME (class_type)))
 	continue;
 
+      current_class = class_type;
       for (decl = TYPE_METHODS (class_type); decl; decl = TREE_CHAIN (decl))
 	{
 	  if (DECL_CONSTRUCTOR_P (decl))
@@ -8470,6 +8479,10 @@ fix_constructors (mdecl)
   tree thisn_assign, compound = NULL_TREE;
   tree class_type = DECL_CONTEXT (mdecl);
 
+  if (DECL_FIXED_CONSTRUCTOR_P (mdecl))
+    return;
+  DECL_FIXED_CONSTRUCTOR_P (mdecl) = 1;
+
   if (!body)
     {
       /* It is an error for the compiler to generate a default
@@ -8513,7 +8526,9 @@ fix_constructors (mdecl)
   else 
     {
       int found = 0;
+      tree found_call = NULL_TREE;
       tree main_block = BLOCK_EXPR_BODY (body);
+      tree ii;			/* Instance Initializer */
       
       while (body)
 	switch (TREE_CODE (body))
@@ -8524,9 +8539,11 @@ fix_constructors (mdecl)
 	    break;
 	  case COMPOUND_EXPR:
 	  case EXPR_WITH_FILE_LOCATION:
+	    found_call = body;
 	    body = TREE_OPERAND (body, 0);
 	    break;
 	  case BLOCK:
+	    found_call = body;
 	    body = BLOCK_EXPR_BODY (body);
 	    break;
 	  default:
@@ -8537,14 +8554,23 @@ fix_constructors (mdecl)
       if (!found)
 	compound = add_stmt_to_compound (compound, NULL_TREE,
                                          build_super_invocation (mdecl));
+
+      /* Explicit super() invokation should be kept as the first
+         statement, we move it. */
+      else
+	{
+	  compound = add_stmt_to_compound (compound, NULL_TREE,
+					   TREE_OPERAND (found_call, 0));
+	  TREE_OPERAND (found_call, 0) = empty_stmt_node;
+	}
       
       /* Generate the assignment to this$<n>, if necessary */
       if ((thisn_assign = build_thisn_assign ()))
         compound = add_stmt_to_compound (compound, NULL_TREE, thisn_assign);
 
-      /* Insert the instance initializer block right here, after the
-         super invocation. */
-      add_instance_initializer (mdecl);
+      /* Insert the instance initializer block right after. */
+      if ((ii = build_instance_initializer (mdecl)))
+	compound = add_stmt_to_compound (compound, NULL_TREE, ii);
 
       /* Fix the constructor main block if we're adding extra stmts */
       if (compound)


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