[PATCH] Java: cleanup patche.

Alexandre Petit-Bianco apbianco@cygnus.com
Tue Apr 18 18:52:00 GMT 2000


I'm checking in the following cleanup patch. It optimizes the handling
of the String concatenation operator, fixes a package bug and a string
building operation.

./A

2000-04-18  Alexandre Petit-Bianco  <apbianco@cygnus.com>

	* parse.y (maybe_make_nested_class_name): Use `obstack_grow0'.

2000-04-14  Alexandre Petit-Bianco  <apbianco@cygnus.com>

	* parse.y (java_expand_classes): Reverse the package list once.
	(java_complete_lhs): PLUS_EXPR: don't try rhs and lhs at string
	reduction.
	(patch_binop): New temp `cn'. Call patch_string on LHS/RHS of
	the `==' and `!=' operators.

Index: parse.y
===================================================================
RCS file: /cvs/gcc/egcs/gcc/java/parse.y,v
retrieving revision 1.150
diff -u -p -r1.150 parse.y
--- parse.y	2000/04/06 05:29:30	1.150
+++ parse.y	2000/04/19 01:23:30
@@ -3539,9 +3539,9 @@ maybe_make_nested_class_name (name)
   if (CPC_INNER_P ())
     {
       make_nested_class_name (GET_CPC_LIST ());
-      obstack_grow (&temporary_obstack,
-		    IDENTIFIER_POINTER (name), 
-		    IDENTIFIER_LENGTH (name));
+      obstack_grow0 (&temporary_obstack,
+		     IDENTIFIER_POINTER (name), 
+		     IDENTIFIER_LENGTH (name));
       id = get_identifier (obstack_finish (&temporary_obstack));
       if (ctxp->package)
 	QUALIFIED_P (id) = 1;
@@ -8239,6 +8239,12 @@ java_expand_classes ()
   java_layout_classes ();
   java_parse_abort_on_error ();
 
+  /* The list of packages declaration seen so far needs to be
+     reversed, so that package declared in a file being compiled gets
+     priority over packages declared as a side effect of parsing other
+     files.*/
+  package_list = nreverse (package_list);
+
   saved_ctxp = ctxp_for_generation;
   for (; ctxp_for_generation; ctxp_for_generation = ctxp_for_generation->next)
     {
@@ -10963,8 +10969,7 @@ java_complete_lhs (node)
           nn = java_complete_tree (wfl_op1);
           if (nn == error_mark_node)
             return error_mark_node;
-          if ((cn = patch_string (nn)))
-            nn = cn;
+
           TREE_OPERAND (node, 0) = nn;
         }
       if (TREE_CODE (node) != PLUS_EXPR || !JSTRING_P (wfl_op2))
@@ -10972,8 +10977,7 @@ java_complete_lhs (node)
           nn = java_complete_tree (wfl_op2);
           if (nn == error_mark_node)
             return error_mark_node;
-          if ((cn = patch_string (nn)))
-            nn = cn;
+
           TREE_OPERAND (node, 1) = nn;
         }
       return force_evaluation_order (patch_binop (node, wfl_op1, wfl_op2));
@@ -12089,7 +12093,7 @@ patch_binop (node, wfl_op1, wfl_op2)
   tree op2 = TREE_OPERAND (node, 1);
   tree op1_type = TREE_TYPE (op1);
   tree op2_type = TREE_TYPE (op2);
-  tree prom_type = NULL_TREE;
+  tree prom_type = NULL_TREE, cn;
   int code = TREE_CODE (node);
 
   /* If 1, tell the routine that we have to return error_mark_node
@@ -12367,6 +12371,18 @@ patch_binop (node, wfl_op1, wfl_op2)
       /* 15.20 Equality Operator */
     case EQ_EXPR:
     case NE_EXPR:
+      /* It's time for us to patch the strings. */
+      if ((cn = patch_string (op1))) 
+       {
+         op1 = cn;
+         op1_type = TREE_TYPE (op1);
+       }
+      if ((cn = patch_string (op2))) 
+       {
+         op2 = cn;
+         op2_type = TREE_TYPE (op2);
+       }
+      
       /* 15.20.1 Numerical Equality Operators == and != */
       /* Binary numeric promotion is performed on the operands */
       if (JNUMERIC_TYPE_P (op1_type) && JNUMERIC_TYPE_P (op2_type))



More information about the Gcc-patches mailing list