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  
24    * contributors.  (Soot is distributed at http://www.sable.mcgill.ca/soot)
25   */
26  
27  
28  
29  
30  
31  
32  package org.kit.furia.fragment.soot.representation.internal;
33  
34  import org.kit.furia.fragment.soot.representation.Frimp;
35  import org.kit.furia.fragment.soot.representation.Precedence;
36  import org.kit.furia.fragment.soot.representation.PrecedenceTest;
37  import org.kit.furia.fragment.soot.representation.Qable;
38  
39  import soot.*;
40  import soot.jimple.internal.*;
41  
42  public class FArrayRef extends JArrayRef implements Precedence, Qable
43  {
44    /**
45  	 * 
46  	 */
47  	private static final long serialVersionUID = -7207388997738085867L;
48  
49  public FArrayRef(Value base, Value index)
50      {
51        super(Frimp.v().newObjExprBox(base),
52              Frimp.v().newExprBox(index));
53      }
54    
55    public int getPrecedence() { return 950; }
56  
57    private String toString(Value op1, 
58                            String leftOp, String rightOp) // NOPMD by amuller on 11/16/06 4:08 PM
59      {
60        if (op1 instanceof Precedence && 
61            ((Precedence)op1).getPrecedence() < getPrecedence()) 
62          leftOp = "(" + leftOp + ")";
63        
64        return leftOp + "[" + rightOp + "]";
65      }
66  
67      public void toString( UnitPrinter up ) {
68          if( PrecedenceTest.needsBrackets( baseBox, this ) ) up.literal("(");
69          baseBox.toString(up);
70          if( PrecedenceTest.needsBrackets( baseBox, this ) ) up.literal(")");
71          up.literal("[");
72          indexBox.toString(up);
73          up.literal("]");
74      }
75  
76    public String toString()
77      {
78        Value op1 = getBase(), op2 = getIndex();
79        String leftOp = op1.toString(), rightOp = op2.toString();
80        
81        return toString(op1, leftOp, rightOp);
82      }
83  
84      public Object clone()  // NOPMD by amuller on 11/16/06 4:08 PM
85      {
86          return new FArrayRef(Frimp.cloneIfNecessary(getBase()), Frimp.cloneIfNecessary(getIndex()));
87      }
88  
89  	public String toQ() throws Exception {
90  
91  		
92  		Value op1 = getBase(), op2 = getIndex();
93  	    String leftOp = Frimp.toQ(op1), rightOp = Frimp.toQ(op2);
94  		
95  	    //if (op1 instanceof Precedence && 
96  	    //        ((Precedence)op1).getPrecedence() < getPrecedence()) 
97  	     //     leftOp = "(" + leftOp + ")";
98  	        
99  	        return FuriaConstructDefinitions.FURIA_farrayRef +"("+ leftOp + "," +  rightOp + ")";	    		
100 	}
101     
102     
103 
104   }
105 
106 
107 
108 
109 
110 
111 
112 
113 
114 
115 
116 
117