00001 package ca.mcgill.sable.soot.grimp; 00002 00003 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 00004 * Grimp, an aggregated-expression Java(TM) bytecode representation. * 00005 * Copyright (C) 1998 Patrick Lam (plam@sable.mcgill.ca) * 00006 * All rights reserved. * 00007 * * 00008 * Modifications by Raja Vallee-Rai (plam@sable.mcgill.ca) are * 00009 * Copyright (C) 1999 Raja Vallee-Rai. 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 * This work was done as a project of the Sable Research Group, * 00016 * School of Computer Science, McGill University, Canada * 00017 * (http://www.sable.mcgill.ca/). It is understood that any * 00018 * modification not identified as such is not covered by the * 00019 * preceding statement. * 00020 * * 00021 * This work is free software; you can redistribute it and/or * 00022 * modify it under the terms of the GNU Library General Public * 00023 * License as published by the Free Software Foundation; either * 00024 * version 2 of the License, or (at your option) any later version. * 00025 * * 00026 * This work is distributed in the hope that it will be useful, * 00027 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00028 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * 00029 * Library General Public License for more details. * 00030 * * 00031 * You should have received a copy of the GNU Library General Public * 00032 * License along with this library; if not, write to the * 00033 * Free Software Foundation, Inc., 59 Temple Place - Suite 330, * 00034 * Boston, MA 02111-1307, USA. * 00035 * * 00036 * Java is a trademark of Sun Microsystems, Inc. * 00037 * * 00038 * To submit a bug report, send a comment, or get the latest news on * 00039 * this project and other Sable Research Group projects, please * 00040 * visit the web site: http://www.sable.mcgill.ca/ * 00041 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ 00042 00043 /* 00044 Reference Version 00045 ----------------- 00046 This is the latest official version on which this file is based. 00047 The reference version is: $SootVersion: 1.beta.4 $ 00048 00049 Change History 00050 -------------- 00051 A) Notes: 00052 00053 Please use the following template. Most recent changes should 00054 appear at the top of the list. 00055 00056 - Modified on [date (March 1, 1900)] by [name]. [(*) if appropriate] 00057 [description of modification]. 00058 00059 Any Modification flagged with "(*)" was done as a project of the 00060 Sable Research Group, School of Computer Science, 00061 McGill University, Canada (http://www.sable.mcgill.ca/). 00062 00063 You should add your copyright, using the following template, at 00064 the top of this file, along with other copyrights. 00065 00066 * * 00067 * Modifications by [name] are * 00068 * Copyright (C) [year(s)] [your name (or company)]. All rights * 00069 * reserved. * 00070 * * 00071 00072 B) Changes: 00073 00074 - Modified on March 1, 1999 by Raja Vallee-Rai (rvalleerai@sable.mcgill.ca) (*) 00075 Added methods to manipulate the base type. 00076 Changed class to inherit from AbstractStaticInvokeExpr. 00077 00078 00079 - Modified on February 3, 1999 by Patrick Lam (plam@sable.mcgill.ca). (*) 00080 First release of Grimp. 00081 */ 00082 00083 import ca.mcgill.sable.soot.*; 00084 import ca.mcgill.sable.soot.jimple.*; 00085 import ca.mcgill.sable.util.*; 00086 00087 class GNewInvokeExpr extends AbstractStaticInvokeExpr 00088 implements NewInvokeExpr, Precedence 00089 { 00090 RefType type; 00091 00092 GNewInvokeExpr(RefType type, SootMethod method, List args) 00093 { 00094 super(method, new ExprBox[args.size()]); 00095 00096 this.type = type; 00097 00098 for(int i = 0; i < args.size(); i++) 00099 this.argBoxes[i] = Grimp.v().newExprBox((Value) args.get(i)); 00100 } 00101 public void apply(Switch sw) 00102 { 00103 ((ExprSwitch) sw).caseNewInvokeExpr(this); 00104 } 00105 /* 00106 protected GNewInvokeExpr(RefType type, ExprBox[] argBoxes) 00107 { 00108 this.type = type; 00109 this.argBoxes = argBoxes; 00110 } 00111 */ 00112 00113 public RefType getBaseType() 00114 { 00115 return type; 00116 } 00117 public int getPrecedence() { return 850; } 00118 public Type getType() 00119 { 00120 return type; 00121 } 00122 public List getUseBoxes() 00123 { 00124 List list = new ArrayList(); 00125 00126 for(int i = 0; i < argBoxes.length; i++) 00127 { 00128 list.addAll(argBoxes[i].getValue().getUseBoxes()); 00129 list.add(argBoxes[i]); 00130 } 00131 00132 return list; 00133 } 00134 public void setBaseType(RefType type) 00135 { 00136 this.type = type; 00137 } 00138 public String toBriefString() 00139 { 00140 StringBuffer buffer = new StringBuffer(); 00141 00142 buffer.append("new " + 00143 ((ToBriefString) type).toBriefString() + "("); 00144 00145 for(int i = 0; i < argBoxes.length; i++) 00146 { 00147 if(i != 0) 00148 buffer.append(", "); 00149 00150 buffer.append(((ToBriefString) argBoxes[i].getValue()).toBriefString()); 00151 } 00152 00153 buffer.append(")"); 00154 00155 return buffer.toString(); 00156 } 00157 public String toString() 00158 { 00159 StringBuffer buffer = new StringBuffer(); 00160 00161 buffer.append("new " + type.toString() + "("); 00162 00163 for(int i = 0; i < argBoxes.length; i++) 00164 { 00165 if(i != 0) 00166 buffer.append(", "); 00167 00168 buffer.append(argBoxes[i].getValue().toString()); 00169 } 00170 00171 buffer.append(")"); 00172 00173 return buffer.toString(); 00174 } 00175 }