Another patch/hack for predecrement/preincrement

Boehm, Hans hans_boehm@hp.com
Sat Sep 29 11:59:00 GMT 2001


Here's the patch I've been using.  It effectively turns ++e into e+=1.  It
needs more systematic testing, but it also appears to work.  It would be
nice if we could get either Tang Ching-Hui's patch, this one, or one that
really fixes the underlying problem, into the tree.

Hans

Index: parse.y
===================================================================
RCS file: /cvs/gcc/gcc/gcc/java/parse.y,v
retrieving revision 1.307
diff -u -r1.307 parse.y
--- parse.y     2001/09/04 21:50:31     1.307
+++ parse.y     2001/09/29 17:59:12
@@ -2324,14 +2324,34 @@
 
 pre_increment_expression:
        INCR_TK unary_expression
-               {$$ = build_incdec ($1.token, $1.location, $2, 0); }
+               { 
+                 /* FIXME: This used to read, and probably should
+                  * still read:
+                  * {$$ = build_incdec ($1.token, $1.location, $2, 0); }
+                  * but that seems to lose the final store when the
+                  * tree for something like ++a[i] is converted to RTL.
+                  */
+                 tree const1 = build_int_2(1, 0);
+                 TREE_TYPE(const1) = int_type_node;
+                 $$ = build_assignment (PLUS_ASSIGN_TK, $1.location,
+                                        $2, const1);
+               }
 |      INCR_TK error
                {yyerror ("Missing term"); RECOVER}
 ;
 
 pre_decrement_expression:
        DECR_TK unary_expression
-               {$$ = build_incdec ($1.token, $1.location, $2, 0); }
+               { 
+                 /* FIXME: This hould probably read:
+                  * {$$ = build_incdec ($1.token, $1.location, $2, 0); }
+                  * But see above.
+                  */
+                 tree const1 = build_int_2(1, 0);
+                 TREE_TYPE(const1) = int_type_node;
+                 $$ = build_assignment (MINUS_ASSIGN_TK, $1.location,
+                                        $2, const1);
+               }
 |      DECR_TK error
                {yyerror ("Missing term"); RECOVER}
 ;



More information about the Java-patches mailing list