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  package org.kit.furia.fragment.soot.representation.internal;
26  
27  import org.kit.furia.fragment.soot.representation.Frimp;
28  import org.kit.furia.fragment.soot.representation.Precedence;
29  import org.kit.furia.fragment.soot.representation.Qable;
30  
31  import soot.*;
32  import soot.jimple.*;
33  import soot.jimple.internal.*;
34  
35  abstract public class AbstractFrimpFloatBinopExpr
36      extends AbstractFloatBinopExpr implements Precedence, Qable
37  {
38      AbstractFrimpFloatBinopExpr(Value op1, Value op2)
39      {
40          this(Frimp.v().newArgBox(op1),
41               Frimp.v().newArgBox(op2));
42      }
43  
44      protected AbstractFrimpFloatBinopExpr(ValueBox op1Box, ValueBox op2Box)
45      {
46          this.op1Box = op1Box;
47          this.op2Box = op2Box;
48      }
49  
50      abstract public int getPrecedence();
51  
52      private String toString(Value op1, Value op2, 
53                              String leftOp, String rightOp, String symbol) // NOPMD by amuller on 11/16/06 4:08 PM
54      {
55          if (op1 instanceof Precedence && 
56              ((Precedence)op1).getPrecedence() < getPrecedence()) 
57              leftOp = "(" + leftOp + ")";
58  
59  	if (op2 instanceof Precedence) {
60  	    int opPrec = ((Precedence) op2).getPrecedence(),
61  		myPrec = getPrecedence();
62  	    
63  	    if ((opPrec < myPrec) ||
64  		((opPrec == myPrec) && ((this instanceof SubExpr) || (this instanceof DivExpr))))		
65  		rightOp = "(" + rightOp + ")";
66  	}
67  		return leftOp + symbol + rightOp;
68  	//	return "(" + leftOp + ")" + symbol + "(" + rightOp + ")";			       
69          
70      }
71  
72      public String toString()
73      {
74          Value op1 = op1Box.getValue(), op2 = op2Box.getValue();
75          String leftOp = op1.toString(), rightOp = op2.toString();
76  
77          return toString(op1, op2, leftOp, rightOp, getSymbol());
78      }
79      
80      public String toQ() throws Exception {	
81      	Value op1 = op1Box.getValue(), op2 = op2Box.getValue();
82      	String leftOp = Frimp.toQ(op1), rightOp = Frimp.toQ(op2);
83      	//toString(op1, op2, leftOp, rightOp, getQSymbol());
84          return getQSymbol() + "(" + leftOp  + "," +  rightOp + ")"; 
85  	}
86      
87      public abstract String getQSymbol();
88  }