00001 package ca.mcgill.sable.soot.jimple; 00002 00003 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 00004 * Jimple, a 3-address code Java(TM) bytecode representation. * 00005 * Copyright (C) 1997, 1998 Raja Vallee-Rai (kor@sable.mcgill.ca) * 00006 * All rights reserved. * 00007 * * 00008 * Modifications by Patrick Lam (plam@sable.mcgill.ca) are * 00009 * Copyright (C) 1999 Patrick Lam. All rights reserved. * 00010 * * 00011 * This work was done as a project of the Sable Research Group, * 00012 * School of Computer Science, McGill University, Canada * 00013 * (http://www.sable.mcgill.ca/). It is understood that any * 00014 * modification not identified as such is not covered by the * 00015 * preceding statement. * 00016 * * 00017 * This work is free software; you can redistribute it and/or * 00018 * modify it under the terms of the GNU Library General Public * 00019 * License as published by the Free Software Foundation; either * 00020 * version 2 of the License, or (at your option) any later version. * 00021 * * 00022 * This work is distributed in the hope that it will be useful, * 00023 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00024 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * 00025 * Library General Public License for more details. * 00026 * * 00027 * You should have received a copy of the GNU Library General Public * 00028 * License along with this library; if not, write to the * 00029 * Free Software Foundation, Inc., 59 Temple Place - Suite 330, * 00030 * Boston, MA 02111-1307, USA. * 00031 * * 00032 * Java is a trademark of Sun Microsystems, Inc. * 00033 * * 00034 * To submit a bug report, send a comment, or get the latest news on * 00035 * this project and other Sable Research Group projects, please * 00036 * visit the web site: http://www.sable.mcgill.ca/ * 00037 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ 00038 00039 /* 00040 Reference Version 00041 ----------------- 00042 This is the latest official version on which this file is based. 00043 The reference version is: $SootVersion: 1.beta.4 $ 00044 00045 Change History 00046 -------------- 00047 A) Notes: 00048 00049 Please use the following template. Most recent changes should 00050 appear at the top of the list. 00051 00052 - Modified on [date (March 1, 1900)] by [name]. [(*) if appropriate] 00053 [description of modification]. 00054 00055 Any Modification flagged with "(*)" was done as a project of the 00056 Sable Research Group, School of Computer Science, 00057 McGill University, Canada (http://www.sable.mcgill.ca/). 00058 00059 You should add your copyright, using the following template, at 00060 the top of this file, along with other copyrights. 00061 00062 * * 00063 * Modifications by [name] are * 00064 * Copyright (C) [year(s)] [your name (or company)]. All rights * 00065 * reserved. * 00066 * * 00067 00068 B) Changes: 00069 00070 - Modified on March 5, 1999 by Raja Vallee-Rai (rvalleerai@sable.mcgill.ca) (*) 00071 Decided that array references with a null base such as null[0] has type NullType(). 00072 00073 - Modified on February 28, 1999 by Raja Vallee-Rai (rvalleerai@sable.mcgill.ca) (*) 00074 Fixed bug with use boxes. 00075 00076 - Modified on February 3, 1999 by Patrick Lam (plam@sable.mcgill.ca) (*) 00077 Added changes in support of the Grimp intermediate 00078 representation (with aggregated-expressions). 00079 00080 - Modified on November 2, 1998 by Raja Vallee-Rai (kor@sable.mcgill.ca) (*) 00081 Repackaged all source files and performed extensive modifications. 00082 First initial release of Soot. 00083 00084 - Modified on September 22, 1998 by Raja Vallee-Rai (kor@sable.mcgill.ca). (*) 00085 Changed the base from Immediate to Local. 00086 00087 - Modified on 15-Jun-1998 by Raja Vallee-Rai (kor@sable.mcgill.ca). (*) 00088 First internal release (Version 0.1). 00089 */ 00090 00091 import ca.mcgill.sable.soot.*; 00092 import ca.mcgill.sable.util.*; 00093 00094 public class JArrayRef implements ArrayRef 00095 { 00096 ValueBox baseBox; 00097 ValueBox indexBox; 00098 00099 00100 JArrayRef(Value base, Value index) 00101 { 00102 this(Jimple.v().newLocalBox(base), 00103 Jimple.v().newImmediateBox(index)); 00104 } 00105 protected JArrayRef(ValueBox baseBox, ValueBox indexBox) 00106 { 00107 this.baseBox = baseBox; 00108 this.indexBox = indexBox; 00109 } 00110 public void apply(Switch sw) 00111 { 00112 ((RefSwitch) sw).caseArrayRef(this); 00113 } 00114 public boolean equals(Object o) 00115 { 00116 if (o instanceof ArrayRef) 00117 { 00118 return (getBase().equals(((ArrayRef)o).getBase()) 00119 && getIndex().equals(((ArrayRef)o).getIndex())); 00120 } 00121 return false; 00122 } 00123 public Value getBase() 00124 { 00125 return baseBox.getValue(); 00126 } 00127 public ValueBox getBaseBox() 00128 { 00129 return baseBox; 00130 } 00131 public Value getIndex() 00132 { 00133 return indexBox.getValue(); 00134 } 00135 public ValueBox getIndexBox() 00136 { 00137 return indexBox; 00138 } 00139 public Type getType() 00140 { 00141 Value base = (Value) baseBox.getValue(); 00142 Type type = base.getType(); 00143 00144 if(type.equals(UnknownType.v())) 00145 return UnknownType.v(); 00146 else if(type.equals(NullType.v())) 00147 return NullType.v(); 00148 else { 00149 ArrayType arrayType = (ArrayType) type; 00150 00151 if(arrayType.numDimensions == 1) 00152 return arrayType.baseType; 00153 else 00154 return ArrayType.v(arrayType.baseType, arrayType.numDimensions - 1); 00155 } 00156 } 00157 public List getUseBoxes() 00158 { 00159 List useBoxes = new ArrayList(); 00160 00161 useBoxes.addAll(baseBox.getValue().getUseBoxes()); 00162 useBoxes.add(baseBox); 00163 00164 useBoxes.addAll(indexBox.getValue().getUseBoxes()); 00165 useBoxes.add(indexBox); 00166 00167 return useBoxes; 00168 } 00169 public void setBase(Local base) 00170 { 00171 baseBox.setValue(base); 00172 } 00173 public void setIndex(Value index) 00174 { 00175 indexBox.setValue(index); 00176 } 00177 public String toBriefString() 00178 { 00179 return ((ToBriefString) baseBox.getValue()).toBriefString() + 00180 "[" + ((ToBriefString) indexBox.getValue()).toBriefString() 00181 + "]"; 00182 } 00183 public String toString() 00184 { 00185 return baseBox.getValue().toString() + "[" + indexBox.getValue().toString() + "]"; 00186 } 00187 }