Main Page   Packages   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members  

Jimple.java

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 Etienne Gagnon (gagnon@sable.mcgill.ca) are      *
00009  * Copyright (C) 1998 Etienne Gagnon (gagnon@sable.mcgill.ca).  All  *
00010  * rights reserved.                                                  *
00011  *                                                                   *
00012  * Modifications by Patrick Lam (plam@sable.mcgill.ca) are           *
00013  * Copyright (C) 1999 Patrick Lam.  All rights reserved.             *
00014  *                                                                   *
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    Temporarily took out the NextNextRef until the jsrs are fixed.
00076    
00077  - Modified on February 3, 1999 by Patrick Lam (plam@sable.mcgill.ca) (*)
00078    Added changes in support of the Grimp intermediate
00079    representation (with aggregated-expressions).
00080 
00081  - Modified on November 2, 1998 by Raja Vallee-Rai (kor@sable.mcgill.ca) (*)
00082    Repackaged all source files and performed extensive modifications.
00083    First initial release of Soot.
00084 
00085  - Modified on September 12, 1998 by Raja Vallee-Rai (kor@sable.mcgill.ca (*)
00086    Changed PrintStream to PrintWriter.
00087 
00088  - Modified on 31-Aug-1998 by Raja Vallee-Rai (kor@sable.mcgill.ca). (*)
00089    Minor print changes.
00090 
00091  - Modified on 23-Jul-1998 by Raja Vallee-Rai (kor@sable.mcgill.ca). (*)
00092    Changed Hashtable to HashMap.
00093 
00094  - Modified on July 5, 1998 by Etienne Gagnon (gagnon@sable.mcgill.ca). (*)
00095    Changed caseDefault to defaultCase, to avoid name conflicts (and conform
00096    to the standard).
00097 
00098  - Modified on 15-Jun-1998 by Raja Vallee-Rai (kor@sable.mcgill.ca). (*)
00099    First internal release (Version 0.1).
00100 */
00101 
00102 import ca.mcgill.sable.soot.*;
00103 import ca.mcgill.sable.util.*;
00104 import java.io.*;
00105 
00106 /**
00107     The Jimple class contains all the constructors for the components of the Jimple
00108     grammar for the Jimple body. <br><br>
00109 
00110     Immediate -> Local | Constant <br>
00111     RValue -> Local | Constant | ConcreteRef | Expr<br>
00112     Variable -> Local | ArrayRef | InstanceFieldRef | StaticFieldRef <br>
00113  */
00114 
00115 
00116 public class Jimple implements BodyRepresentation
00117 {
00118     private static Jimple jimpleRepresentation = new Jimple();
00119 
00120     protected Jimple()
00121     {
00122     }
00123     public Body buildBodyOfFrom(SootMethod m, Body b, int buildBodyOptions)
00124     {
00125         return new JimpleBody(m, b, buildBodyOptions);
00126     }
00127     /**
00128         Constructs a AddExpr(Immediate, Immediate) grammar chunk.
00129      */
00130 
00131     public AddExpr newAddExpr(Value op1, Value op2)
00132     {
00133         return new JAddExpr(op1, op2);
00134     }
00135     /**
00136         Constructs a AndExpr(Immediate, Immediate) grammar chunk.
00137      */
00138 
00139     public AndExpr newAndExpr(Value op1, Value op2)
00140     {
00141         return new JAndExpr(op1, op2);
00142     }
00143     public ValueBox newArgBox(Value value)
00144     {
00145         return new ImmediateBox(value);
00146     }
00147     /**
00148         Constructs a ArrayRef(Local, Immediate) grammar chunk.
00149      */
00150 
00151     public ArrayRef newArrayRef(Value base, Value index)
00152     {
00153         return new JArrayRef(base, index);
00154     }
00155     /**
00156         Constructs a AssignStmt(Variable, RValue) grammar chunk.
00157      */
00158 
00159     public AssignStmt newAssignStmt(Value variable, Value rvalue)
00160     {
00161         return new JAssignStmt(variable, rvalue);
00162     }
00163     /**
00164         Constructs an empty JimpleBody for the given method.
00165      */
00166      
00167     public Body newBody(SootMethod m)
00168     {
00169         return new JimpleBody(m);
00170     }
00171     /**
00172         Constructs a BreakpointStmt() grammar chunk.
00173      */
00174 
00175     public BreakpointStmt newBreakpointStmt()
00176     {
00177         return new JBreakpointStmt();
00178     }
00179     /**
00180         Constructs a CastExpr(Immediate, Type) grammar chunk.
00181      */
00182 
00183     public CastExpr newCastExpr(Value op1, Type t)
00184     {
00185         return new JCastExpr(op1, t);
00186     }
00187     /**
00188         Constructs a CaughtExceptionRef() grammar chunk.
00189      */
00190 
00191     public CaughtExceptionRef newCaughtExceptionRef(JimpleBody b)
00192     {
00193         return new JCaughtExceptionRef(b);
00194     }
00195     /**
00196         Constructs a CmpExpr(Immediate, Immediate) grammar chunk.
00197      */
00198 
00199     public CmpExpr newCmpExpr(Value op1, Value op2)
00200     {
00201         return new JCmpExpr(op1, op2);
00202     }
00203     /**
00204         Constructs a CmpgExpr(Immediate, Immediate) grammar chunk.
00205      */
00206 
00207     public CmpgExpr newCmpgExpr(Value op1, Value op2)
00208     {
00209         return new JCmpgExpr(op1, op2);
00210     }
00211     /**
00212         Constructs a CmplExpr(Immediate, Immediate) grammar chunk.
00213      */
00214 
00215     public CmplExpr newCmplExpr(Value op1, Value op2)
00216     {
00217         return new JCmplExpr(op1, op2);
00218     }
00219     public ValueBox newConditionExprBox(Value value)
00220     {
00221         return new ConditionExprBox(value);
00222     }
00223     /**
00224         Constructs a DivExpr(Immediate, Immediate) grammar chunk.
00225      */
00226 
00227     public DivExpr newDivExpr(Value op1, Value op2)
00228     {
00229         return new JDivExpr(op1, op2);
00230     }
00231     /**
00232         Constructs a EnterMonitorStmt(Immediate) grammar chunk.
00233      */
00234 
00235     public EnterMonitorStmt newEnterMonitorStmt(Value op)
00236     {
00237         return new JEnterMonitorStmt(op);
00238     }
00239     /**
00240         Constructs a EqExpr(Immediate, Immediate) grammar chunk.
00241      */
00242 
00243     public EqExpr newEqExpr(Value op1, Value op2)
00244     {
00245         return new JEqExpr(op1, op2);
00246     }
00247     /**
00248         Constructs a ExitMonitorStmt(Immediate) grammar chunk
00249      */
00250 
00251     public ExitMonitorStmt newExitMonitorStmt(Value op)
00252     {
00253         return new JExitMonitorStmt(op);
00254     }
00255     /**
00256         Constructs a GeExpr(Immediate, Immediate) grammar chunk.
00257      */
00258 
00259     public GeExpr newGeExpr(Value op1, Value op2)
00260     {
00261         return new JGeExpr(op1, op2);
00262     }
00263     /**
00264         Constructs a GotoStmt(Stmt) grammar chunk.
00265      */
00266 
00267     public GotoStmt newGotoStmt(Unit target)
00268     {
00269         return new JGotoStmt(target);
00270     }
00271     /**
00272         Constructs a GtExpr(Immediate, Immediate) grammar chunk.
00273      */
00274 
00275     public GtExpr newGtExpr(Value op1, Value op2)
00276     {
00277         return new JGtExpr(op1, op2);
00278     }
00279     public ValueBox newIdentityRefBox(Value value)
00280     {
00281         return new IdentityRefBox(value);
00282     }
00283     /**
00284         Constructs a IdentityStmt(Local, IdentityRef) grammar chunk.
00285      */
00286 
00287     public IdentityStmt newIdentityStmt(Value local, Value identityRef)
00288     {
00289         return new JIdentityStmt(local, identityRef);
00290     }
00291     /**
00292         Constructs a IfStmt(Condition, Stmt) grammar chunk.
00293      */
00294 
00295     public IfStmt newIfStmt(Value condition, Unit target)
00296     {
00297         return new JIfStmt(condition, target);
00298     }
00299     public ValueBox newImmediateBox(Value value)
00300     {
00301         return new ImmediateBox(value);
00302     }
00303     /**
00304         Constructs a NextNextStmtRef() grammar chunk.
00305      */
00306 
00307      /*
00308     public NextNextStmtRef newNextNextStmtRef()
00309     {
00310         return new NextNextStmtRef();
00311     }
00312 */
00313 
00314     /**
00315         Constructs a InstanceFieldRef(Value, SootField) grammar chunk.
00316      */
00317 
00318     public InstanceFieldRef newInstanceFieldRef(Value base, SootField f)
00319     {
00320         return new JInstanceFieldRef(base, f);
00321     }
00322     /**
00323         Constructs a InstanceOfExpr(Immediate, Type)
00324         grammar chunk.
00325      */
00326 
00327     public InstanceOfExpr newInstanceOfExpr(Value op1, Type t)
00328     {
00329         return new JInstanceOfExpr(op1, t);
00330     }
00331     /**
00332         Constructs a NewInterfaceInvokeExpr(Local base, SootMethod method, List of Immediate) grammar chunk.
00333      */
00334 
00335     public InterfaceInvokeExpr newInterfaceInvokeExpr(Local base, SootMethod method, List args)
00336     {
00337         return new JInterfaceInvokeExpr(base, method, args);
00338     }
00339     public ValueBox newInvokeExprBox(Value value)
00340     {
00341         return new InvokeExprBox(value);
00342     }
00343     /**
00344         Constructs a InvokeStmt(InvokeExpr) grammar chunk.
00345      */
00346 
00347     public InvokeStmt newInvokeStmt(Value op)
00348     {
00349         return new JInvokeStmt(op);
00350     }
00351     /**
00352         Constructs a LeExpr(Immediate, Immediate) grammar chunk.
00353      */
00354 
00355     public LeExpr newLeExpr(Value op1, Value op2)
00356     {
00357         return new JLeExpr(op1, op2);
00358     }
00359     /**
00360         Constructs a LengthExpr(Immediate) grammar chunk.
00361      */
00362 
00363     public LengthExpr newLengthExpr(Value op)
00364     {
00365         return new JLengthExpr(op);
00366     }
00367     /**
00368         Constructs a Local with the given name and type.
00369     */
00370 
00371     public Local newLocal(String name, Type t)
00372     {
00373         return new Local(name, t);
00374     }
00375     public ValueBox newLocalBox(Value value)
00376     {
00377         return new LocalBox(value);
00378     }
00379     /**
00380         Constructs a LookupSwitchStmt(Immediate, List of Immediate, List of Unit, Stmt) grammar chunk.
00381      */
00382 
00383     public LookupSwitchStmt newLookupSwitchStmt(Value key, List lookupValues, List targets, Unit defaultTarget)
00384     {
00385         return new JLookupSwitchStmt(key, lookupValues, targets, defaultTarget);
00386     }
00387     /**
00388         Constructs a LtExpr(Immediate, Immediate) grammar chunk.
00389      */
00390 
00391     public LtExpr newLtExpr(Value op1, Value op2)
00392     {
00393         return new JLtExpr(op1, op2);
00394     }
00395     /**
00396         Constructs a MulExpr(Immediate, Immediate) grammar chunk.
00397      */
00398 
00399     public MulExpr newMulExpr(Value op1, Value op2)
00400     {
00401         return new JMulExpr(op1, op2);
00402     }
00403     /**
00404         Constructs a NeExpr(Immediate, Immediate) grammar chunk.
00405      */
00406 
00407     public NeExpr newNeExpr(Value op1, Value op2)
00408     {
00409         return new JNeExpr(op1, op2);
00410     }
00411     /**
00412         Constructs a NegExpr(Immediate, Immediate) grammar chunk.
00413      */
00414 
00415     public NegExpr newNegExpr(Value op)
00416     {
00417         return new JNegExpr(op);
00418     }
00419     /**
00420         Constructs a NewArrayExpr(Type, Immediate) grammar chunk.
00421      */
00422 
00423     public NewArrayExpr newNewArrayExpr(Type type, Value size)
00424     {
00425         return new JNewArrayExpr(type, size);
00426     }
00427     /**
00428         Constructs a NewExpr(RefType) grammar chunk.
00429      */
00430 
00431     public NewExpr newNewExpr(RefType type)
00432     {
00433         return new JNewExpr(type);
00434     }
00435     /**
00436         Constructs a NewMultiArrayExpr(ArrayType, List of Immediate) grammar chunk.
00437      */
00438 
00439     public NewMultiArrayExpr newNewMultiArrayExpr(ArrayType type, List sizes)
00440     {
00441         return new JNewMultiArrayExpr(type, sizes);
00442     }
00443     /**
00444         Constructs a NopStmt() grammar chunk.
00445      */
00446 
00447     public NopStmt newNopStmt()
00448     {
00449         return new JNopStmt();
00450     }
00451     /**
00452         Constructs a OrExpr(Immediate, Immediate) grammar chunk.
00453      */
00454 
00455     public OrExpr newOrExpr(Value op1, Value op2)
00456     {
00457         return new JOrExpr(op1, op2);
00458     }
00459     /**
00460         Constructs a ParameterRef(SootMethod, int) grammar chunk.
00461      */
00462 
00463     public ParameterRef newParameterRef(SootMethod m, int number)
00464     {
00465         return new ParameterRef(m, number);
00466     }
00467     /**
00468         Constructs a RemExpr(Immediate, Immediate) grammar chunk.
00469      */
00470 
00471     public RemExpr newRemExpr(Value op1, Value op2)
00472     {
00473         return new JRemExpr(op1, op2);
00474     }
00475     /**
00476         Constructs a RetStmt(Local) grammar chunk.
00477      */
00478 
00479     public RetStmt newRetStmt(Value stmtAddress)
00480     {
00481         return new JRetStmt(stmtAddress);
00482     }
00483     /**
00484         Constructs a ReturnStmt(Immediate) grammar chunk.
00485      */
00486 
00487     public ReturnStmt newReturnStmt(Value op)
00488     {
00489         return new JReturnStmt(op);
00490     }
00491     /**
00492         Constructs a ReturnVoidStmt() grammar chunk.
00493      */
00494 
00495     public ReturnVoidStmt newReturnVoidStmt()
00496     {
00497         return new JReturnVoidStmt();
00498     }
00499     public ValueBox newRValueBox(Value value)
00500     {
00501         return new RValueBox(value);
00502     }
00503     /**
00504         Constructs a ShlExpr(Immediate, Immediate) grammar chunk.
00505      */
00506 
00507     public ShlExpr newShlExpr(Value op1, Value op2)
00508     {
00509         return new JShlExpr(op1, op2);
00510     }
00511     /**
00512         Constructs a ShrExpr(Immediate, Immediate) grammar chunk.
00513      */
00514 
00515     public ShrExpr newShrExpr(Value op1, Value op2)
00516     {
00517         return new JShrExpr(op1, op2);
00518     }
00519     /**
00520         Constructs a NewSpecialInvokeExpr(Local base, SootMethod method, List of Immediate) grammar chunk.
00521      */
00522 
00523     public SpecialInvokeExpr newSpecialInvokeExpr(Local base, SootMethod method, List args)
00524     {
00525         return new JSpecialInvokeExpr(base, method, args);
00526     }
00527     /**
00528         Constructs a StaticFieldRef(SootField) grammar chunk.
00529      */
00530 
00531     public StaticFieldRef newStaticFieldRef(SootField f)
00532     {
00533         return new StaticFieldRef(f);
00534     }
00535     /**
00536         Constructs a NewStaticInvokeExpr(ArrayType, List of Immediate) grammar chunk.
00537      */
00538 
00539     public StaticInvokeExpr newStaticInvokeExpr(SootMethod method, List args)
00540     {
00541         return new JStaticInvokeExpr(method, args);
00542     }
00543     public UnitBox newStmtBox(Unit unit)
00544     {
00545         return new StmtBox((Stmt) unit);
00546     }
00547     /**
00548         Constructs a SubExpr(Immediate, Immediate) grammar chunk.
00549      */
00550 
00551     public SubExpr newSubExpr(Value op1, Value op2)
00552     {
00553         return new JSubExpr(op1, op2);
00554     }
00555     /**
00556         Constructs a TableSwitchStmt(Immediate, int, int, List of Unit, Stmt) grammar chunk.
00557      */
00558 
00559     public TableSwitchStmt newTableSwitchStmt(Value key, int lowIndex, int highIndex, List targets, Unit defaultTarget)
00560     {
00561         return new JTableSwitchStmt(key, lowIndex, highIndex, targets, defaultTarget);
00562     }
00563     /**
00564         Constructs a ThisRef(SootClass) grammar chunk.
00565      */
00566 
00567     public ThisRef newThisRef(SootClass c)
00568     {
00569         return new ThisRef(c);
00570     }
00571     /**
00572         Constructs a ThrowStmt(Immediate) grammar chunk.
00573      */
00574 
00575     public ThrowStmt newThrowStmt(Value op)
00576     {
00577         return new JThrowStmt(op);
00578     }
00579     /**
00580         Constructs a new JTrap for the given exception on the given Stmt range with the given Stmt handler.
00581     */
00582 
00583     public Trap newTrap(SootClass exception, Unit beginStmt, Unit endStmt, Unit handlerStmt)
00584     {
00585         return new JTrap(exception, beginStmt, endStmt, handlerStmt);
00586     }
00587     /**
00588         Constructs a UshrExpr(Immediate, Immediate) grammar chunk.
00589      */
00590 
00591     public UshrExpr newUshrExpr(Value op1, Value op2)
00592     {
00593         return new JUshrExpr(op1, op2);
00594     }
00595     public ValueBox newVariableBox(Value value)
00596     {
00597         return new VariableBox(value);
00598     }
00599     /**
00600         Constructs a NewVirtualInvokeExpr(Local base, SootMethod method, List of Immediate) grammar chunk.
00601      */
00602 
00603     public VirtualInvokeExpr newVirtualInvokeExpr(Local base, SootMethod method, List args)
00604     {
00605         return new JVirtualInvokeExpr(base, method, args);
00606     }
00607     /**
00608         Constructs a XorExpr(Immediate, Immediate) grammar chunk.
00609      */
00610 
00611     public XorExpr newXorExpr(Value op1, Value op2)
00612     {
00613         return new JXorExpr(op1, op2);
00614     }
00615     public static Jimple v()
00616     {
00617         return jimpleRepresentation;
00618     }
00619 }

Generated at Thu Feb 7 06:48:40 2002 for Bandera by doxygen1.2.10 written by Dimitri van Heesch, © 1997-2001