[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

questions about fixing dava for wrong precedence order of lengthand cast



To fix the dava for wrong precedence order of length and cast,
for example, dava omit the parentheses for a expression such as
(java.lang.Object[] obj).length
I modified the toString(UnitPrinter) method for DLengthExpr
and added getPrecedence() to implement Precedence interface.
(See attached diff.)

I have three questions about this fix:
1. is the precedence of length op. 900 ?
2. Do I need to fix toString() method too ?
3. If so, should i not use PrecedenceTest class to compare the
precedence of operations, as same as toString() methods for
DInterfaceInvokeExpr and DVirtualInvokeExpr classes ?

Haruyuki Kawabe
Haruyuki.Kawabe@unisys.co.jp
*** DLengthExpr.java.orig	Wed Sep 24 13:55:56 2003
--- DLengthExpr.java	Wed Sep 24 14:52:26 2003
***************
*** 24,31 ****
  import soot.jimple.*;
  import soot.jimple.internal.*;
  
! public class DLengthExpr extends AbstractLengthExpr
  {
      public DLengthExpr(Value op)
      {
          super(Grimp.v().newObjExprBox(op));
--- 24,33 ----
  import soot.jimple.*;
  import soot.jimple.internal.*;
  
! public class DLengthExpr extends AbstractLengthExpr implements Precedence
  {
+     public int getPrecedence() { return 900; }
+ 
      public DLengthExpr(Value op)
      {
          super(Grimp.v().newObjExprBox(op));
***************
*** 37,43 ****
--- 39,47 ----
      }
  
      public void toString( UnitPrinter up ) {
+ 	if( PrecedenceTest.needsBrackets( getOpBox(), this ) ) up.literal("(");
          getOpBox().toString(up);
+ 	if( PrecedenceTest.needsBrackets( getOpBox(), this ) ) up.literal(")");
          up.literal(".");
          up.literal("length");
      }