View Javadoc

1   /* Soot - a J*va Optimization Framework
2    * Copyright (C) 1999 Patrick Lam
3    *
4    * This library is free software; you can redistribute it and/or
5    * modify it under the terms of the GNU Lesser General Public
6    * License as published by the Free Software Foundation; either
7    * version 2.1 of the License, or (at your option) any later version.
8    *
9    * This library is distributed in the hope that it will be useful,
10   * but WITHOUT ANY WARRANTY; without even the implied warranty of
11   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12   * Lesser General Public License for more details.
13   *
14   * You should have received a copy of the GNU Lesser General Public
15   * License along with this library; if not, write to the
16   * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17   * Boston, MA 02111-1307, USA.
18   */
19  
20  /*
21   * Modified by the Sable Research Group and others 1997-1999.  
22   * See the 'credits' file distributed with Soot for the complete list of
23   * contributors.  (Soot is distributed at http://www.sable.mcgill.ca/soot)
24   */
25  
26  
27  package org.kit.furia.fragment.soot.representation.internal;
28  
29  import org.kit.furia.fragment.soot.representation.Frimp;
30  import org.kit.furia.fragment.soot.representation.Precedence;
31  import org.kit.furia.fragment.soot.representation.Qable;
32  
33  import soot.*;
34  
35  import soot.jimple.*;
36  import soot.jimple.internal.*;
37  
38  abstract public class AbstractFrimpIntLongBinopExpr
39      extends AbstractIntLongBinopExpr implements Precedence, Qable
40  {
41      AbstractFrimpIntLongBinopExpr(Value op1, Value op2)
42      {
43          this(Frimp.v().newArgBox(op1),
44               Frimp.v().newArgBox(op2));
45      }
46  
47      protected AbstractFrimpIntLongBinopExpr(ValueBox op1Box, ValueBox op2Box)
48      {
49          this.op1Box = op1Box;
50          this.op2Box = op2Box;
51      }
52  
53      abstract public int getPrecedence();
54  
55      private String toString(Value op1, Value op2, 
56                              String leftOp, String rightOp, String symbol) // NOPMD by amuller on 11/16/06 4:08 PM
57      {
58          if (op1 instanceof Precedence && 
59              ((Precedence)op1).getPrecedence() < getPrecedence()) 
60              leftOp = "(" + leftOp + ")";
61  
62  	if (op2 instanceof Precedence) {
63  	    int opPrec = ((Precedence) op2).getPrecedence(),
64  		myPrec = getPrecedence();
65  	    
66  	    if ((opPrec < myPrec) ||
67  		((opPrec == myPrec) && ((this instanceof SubExpr) || (this instanceof DivExpr))))		
68  		rightOp = "(" + rightOp + ")";
69  	}
70  		//return "(" + leftOp + ")" + symbol + "(" + rightOp + ")";
71          return leftOp + symbol + rightOp;
72      }
73  
74      public String toString()
75      {
76          Value op1 = op1Box.getValue(), op2 = op2Box.getValue();
77          String leftOp = op1.toString(), rightOp = op2.toString();
78  
79          return toString(op1, op2, leftOp, rightOp, getSymbol());
80      }
81      
82      public String toQ() throws Exception {	
83      	Value op1 = op1Box.getValue(), op2 = op2Box.getValue();
84          String leftOp = Frimp.toQ(op1), rightOp = Frimp.toQ(op2);
85  
86          //return toString(op1, op2, leftOp, rightOp, getQSymbol());
87          return getQSymbol() + "(" + leftOp  + "," +  rightOp + ")"; 
88  	}
89      
90      public abstract String getQSymbol();
91  }