KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > soot > grimp > Grimp


1 /* Soot - a J*va Optimization Framework
2  * Copyright (C) 1999 Patrick Lam
3  * Copyright (C) 2004 Ondrej Lhotak
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the
17  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18  * Boston, MA 02111-1307, USA.
19  */

20
21 /*
22  * Modified by the Sable Research Group and others 1997-1999.
23  * See the 'credits' file distributed with Soot for the complete list of
24  * contributors. (Soot is distributed at http://www.sable.mcgill.ca/soot)
25  */

26
27
28
29
30
31
32 package soot.grimp;
33
34 import soot.*;
35 import soot.jimple.*;
36 import soot.grimp.internal.*;
37 import soot.util.*;
38 import java.util.*;
39 import java.io.*;
40
41 /**
42     The Grimp class contains all the constructors for the components of the Grimp
43     grammar for the Grimp body. <br><br>
44
45     Immediate -> Local | Constant <br>
46     RValue -> Local | Constant | ConcreteRef | Expr<br>
47     Variable -> Local | ArrayRef | InstanceFieldRef | StaticFieldRef <br>
48  */

49
50
51 public class Grimp
52 {
53     public Grimp( Singletons.Global g ) {}
54     public static Grimp v() { return G.v().soot_grimp_Grimp(); }
55
56     /**
57         Constructs a XorExpr(Expr, Expr) grammar chunk.
58      */

59
60     public XorExpr newXorExpr(Value op1, Value op2)
61     {
62         return new GXorExpr(op1, op2);
63     }
64
65
66     /**
67         Constructs a UshrExpr(Expr, Expr) grammar chunk.
68      */

69
70     public UshrExpr newUshrExpr(Value op1, Value op2)
71     {
72         return new GUshrExpr(op1, op2);
73     }
74
75
76     /**
77         Constructs a SubExpr(Expr, Expr) grammar chunk.
78      */

79
80     public SubExpr newSubExpr(Value op1, Value op2)
81     {
82         return new GSubExpr(op1, op2);
83     }
84
85
86     /**
87         Constructs a ShrExpr(Expr, Expr) grammar chunk.
88      */

89
90     public ShrExpr newShrExpr(Value op1, Value op2)
91     {
92         return new GShrExpr(op1, op2);
93     }
94
95
96     /**
97         Constructs a ShlExpr(Expr, Expr) grammar chunk.
98      */

99
100     public ShlExpr newShlExpr(Value op1, Value op2)
101     {
102         return new GShlExpr(op1, op2);
103     }
104
105
106     /**
107         Constructs a RemExpr(Expr, Expr) grammar chunk.
108      */

109
110     public RemExpr newRemExpr(Value op1, Value op2)
111     {
112         return new GRemExpr(op1, op2);
113     }
114
115
116     /**
117         Constructs a OrExpr(Expr, Expr) grammar chunk.
118      */

119
120     public OrExpr newOrExpr(Value op1, Value op2)
121     {
122         return new GOrExpr(op1, op2);
123     }
124
125
126     /**
127         Constructs a NeExpr(Expr, Expr) grammar chunk.
128      */

129
130     public NeExpr newNeExpr(Value op1, Value op2)
131     {
132         return new GNeExpr(op1, op2);
133     }
134
135
136     /**
137         Constructs a MulExpr(Expr, Expr) grammar chunk.
138      */

139
140     public MulExpr newMulExpr(Value op1, Value op2)
141     {
142         return new GMulExpr(op1, op2);
143     }
144
145
146     /**
147         Constructs a LeExpr(Expr, Expr) grammar chunk.
148      */

149
150     public LeExpr newLeExpr(Value op1, Value op2)
151     {
152         return new GLeExpr(op1, op2);
153     }
154
155
156     /**
157         Constructs a GeExpr(Expr, Expr) grammar chunk.
158      */

159
160     public GeExpr newGeExpr(Value op1, Value op2)
161     {
162         return new GGeExpr(op1, op2);
163     }
164
165
166     /**
167         Constructs a EqExpr(Expr, Expr) grammar chunk.
168      */

169
170     public EqExpr newEqExpr(Value op1, Value op2)
171     {
172         return new GEqExpr(op1, op2);
173     }
174
175     /**
176         Constructs a DivExpr(Expr, Expr) grammar chunk.
177      */

178
179     public DivExpr newDivExpr(Value op1, Value op2)
180     {
181         return new GDivExpr(op1, op2);
182     }
183
184
185     /**
186         Constructs a CmplExpr(Expr, Expr) grammar chunk.
187      */

188
189     public CmplExpr newCmplExpr(Value op1, Value op2)
190     {
191         return new GCmplExpr(op1, op2);
192     }
193
194
195     /**
196         Constructs a CmpgExpr(Expr, Expr) grammar chunk.
197      */

198
199     public CmpgExpr newCmpgExpr(Value op1, Value op2)
200     {
201         return new GCmpgExpr(op1, op2);
202     }
203
204
205     /**
206         Constructs a CmpExpr(Expr, Expr) grammar chunk.
207      */

208
209     public CmpExpr newCmpExpr(Value op1, Value op2)
210     {
211         return new GCmpExpr(op1, op2);
212     }
213
214
215     /**
216         Constructs a GtExpr(Expr, Expr) grammar chunk.
217      */

218
219     public GtExpr newGtExpr(Value op1, Value op2)
220     {
221         return new GGtExpr(op1, op2);
222     }
223
224
225     /**
226         Constructs a LtExpr(Expr, Expr) grammar chunk.
227      */

228
229     public LtExpr newLtExpr(Value op1, Value op2)
230     {
231         return new GLtExpr(op1, op2);
232     }
233
234     /**
235         Constructs a AddExpr(Expr, Expr) grammar chunk.
236      */

237
238     public AddExpr newAddExpr(Value op1, Value op2)
239     {
240         return new GAddExpr(op1, op2);
241     }
242
243
244     /**
245         Constructs a AndExpr(Expr, Expr) grammar chunk.
246      */

247
248     public AndExpr newAndExpr(Value op1, Value op2)
249     {
250         return new GAndExpr(op1, op2);
251     }
252
253
254     /**
255         Constructs a NegExpr(Expr, Expr) grammar chunk.
256      */

257
258     public NegExpr newNegExpr(Value op)
259     {
260         return new GNegExpr(op);
261     }
262
263
264     /**
265         Constructs a LengthExpr(Expr) grammar chunk.
266      */

267
268     public LengthExpr newLengthExpr(Value op)
269     {
270         return new GLengthExpr(op);
271     }
272
273
274     /**
275         Constructs a CastExpr(Expr, Type) grammar chunk.
276      */

277
278     public CastExpr newCastExpr(Value op1, Type t)
279     {
280         return new GCastExpr(op1, t);
281     }
282
283     /**
284         Constructs a InstanceOfExpr(Expr, Type)
285         grammar chunk.
286      */

287
288     public InstanceOfExpr newInstanceOfExpr(Value op1, Type t)
289     {
290         return new GInstanceOfExpr(op1, t);
291     }
292
293
294     /**
295         Constructs a NewExpr(RefType) grammar chunk.
296      */

297
298     NewExpr newNewExpr(RefType type)
299     {
300         return Jimple.v().newNewExpr(type);
301     }
302
303
304     /**
305         Constructs a NewArrayExpr(Type, Expr) grammar chunk.
306      */

307
308     public NewArrayExpr newNewArrayExpr(Type type, Value size)
309     {
310         return new GNewArrayExpr(type, size);
311     }
312
313     /**
314         Constructs a NewMultiArrayExpr(ArrayType, List of Expr) grammar chunk.
315      */

316
317     public NewMultiArrayExpr newNewMultiArrayExpr(ArrayType type, List sizes)
318     {
319         return new GNewMultiArrayExpr(type, sizes);
320     }
321
322     /**
323         Constructs a NewInvokeExpr(Local base, List of Expr) grammar chunk.
324      */

325
326     public NewInvokeExpr newNewInvokeExpr(RefType base, SootMethodRef method, List args)
327     {
328         return new GNewInvokeExpr(base, method, args);
329     }
330
331     /**
332         Constructs a StaticInvokeExpr(ArrayType, List of Expr) grammar chunk.
333      */

334
335     public StaticInvokeExpr newStaticInvokeExpr(SootMethodRef method, List args)
336     {
337         return new GStaticInvokeExpr(method, args);
338     }
339
340
341     /**
342         Constructs a SpecialInvokeExpr(Local base, SootMethodRef method, List of Expr) grammar chunk.
343      */

344
345     public SpecialInvokeExpr newSpecialInvokeExpr(Local base, SootMethodRef method, List args)
346     {
347         return new GSpecialInvokeExpr(base, method, args);
348     }
349
350
351     /**
352         Constructs a VirtualInvokeExpr(Local base, SootMethodRef method, List of Expr) grammar chunk.
353      */

354
355     public VirtualInvokeExpr newVirtualInvokeExpr(Local base, SootMethodRef method, List args)
356     {
357         return new GVirtualInvokeExpr(base, method, args);
358     }
359
360
361     /**
362         Constructs a InterfaceInvokeExpr(Local base, SootMethodRef method, List of Expr) grammar chunk.
363      */

364
365     public InterfaceInvokeExpr newInterfaceInvokeExpr(Local base, SootMethodRef method, List args)
366     {
367         return new GInterfaceInvokeExpr(base, method, args);
368     }
369
370
371     /**
372         Constructs a ThrowStmt(Expr) grammar chunk.
373      */

374
375     public ThrowStmt newThrowStmt(Value op)
376     {
377         return new GThrowStmt(op);
378     }
379
380     public ThrowStmt newThrowStmt(ThrowStmt s)
381     {
382         return new GThrowStmt(s.getOp());
383     }
384
385     /**
386         Constructs a ExitMonitorStmt(Expr) grammar chunk
387      */

388
389     public ExitMonitorStmt newExitMonitorStmt(Value op)
390     {
391         return new GExitMonitorStmt(op);
392     }
393
394     public ExitMonitorStmt newExitMonitorStmt(ExitMonitorStmt s)
395     {
396         return new GExitMonitorStmt(s.getOp());
397     }
398
399     /**
400         Constructs a EnterMonitorStmt(Expr) grammar chunk.
401      */

402
403     public EnterMonitorStmt newEnterMonitorStmt(Value op)
404     {
405         return new GEnterMonitorStmt(op);
406     }
407
408     public EnterMonitorStmt newEnterMonitorStmt(EnterMonitorStmt s)
409     {
410         return new GEnterMonitorStmt(s.getOp());
411     }
412
413     /**
414         Constructs a BreakpointStmt() grammar chunk.
415      */

416
417     public BreakpointStmt newBreakpointStmt()
418     {
419         return Jimple.v().newBreakpointStmt();
420     }
421     
422     public BreakpointStmt newBreakpointStmt(BreakpointStmt s)
423     {
424         return Jimple.v().newBreakpointStmt();
425     }
426
427     /**
428         Constructs a GotoStmt(Stmt) grammar chunk.
429      */

430
431     public GotoStmt newGotoStmt(Unit target)
432     {
433         return Jimple.v().newGotoStmt(target);
434     }
435
436     public GotoStmt newGotoStmt(GotoStmt s)
437     {
438         return Jimple.v().newGotoStmt(s.getTarget());
439     }
440
441     /**
442         Constructs a NopStmt() grammar chunk.
443      */

444
445     public NopStmt newNopStmt()
446     {
447         return Jimple.v().newNopStmt();
448     }
449
450     public NopStmt newNopStmt(NopStmt s)
451     {
452         return Jimple.v().newNopStmt();
453     }
454
455     /**
456         Constructs a ReturnVoidStmt() grammar chunk.
457      */

458
459     public ReturnVoidStmt newReturnVoidStmt()
460     {
461         return Jimple.v().newReturnVoidStmt();
462     }
463
464     public ReturnVoidStmt newReturnVoidStmt(ReturnVoidStmt s)
465     {
466         return Jimple.v().newReturnVoidStmt();
467     }
468
469     /**
470         Constructs a ReturnStmt(Expr) grammar chunk.
471      */

472
473     public ReturnStmt newReturnStmt(Value op)
474     {
475         return new GReturnStmt(op);
476     }
477
478     public ReturnStmt newReturnStmt(ReturnStmt s)
479     {
480         return new GReturnStmt(s.getOp());
481     }
482
483     /**
484         Constructs a IfStmt(Condition, Stmt) grammar chunk.
485      */

486
487     public IfStmt newIfStmt(Value condition, Unit target)
488     {
489         return new GIfStmt(condition, target);
490     }
491
492     public IfStmt newIfStmt(IfStmt s)
493     {
494         return new GIfStmt(s.getCondition(), s.getTarget());
495     }
496
497     /**
498         Constructs a IdentityStmt(Local, IdentityRef) grammar chunk.
499      */

500
501     public IdentityStmt newIdentityStmt(Value local, Value identityRef)
502     {
503         return new GIdentityStmt(local, identityRef);
504     }
505
506     public IdentityStmt newIdentityStmt(IdentityStmt s)
507     {
508         return new GIdentityStmt(s.getLeftOp(), s.getRightOp());
509     }
510
511     /**
512         Constructs a AssignStmt(Variable, RValue) grammar chunk.
513      */

514
515     public AssignStmt newAssignStmt(Value variable, Value rvalue)
516     {
517         return new GAssignStmt(variable, rvalue);
518     }
519
520     public AssignStmt newAssignStmt(AssignStmt s)
521     {
522         return new GAssignStmt(s.getLeftOp(), s.getRightOp());
523     }
524
525     /**
526         Constructs a InvokeStmt(InvokeExpr) grammar chunk.
527      */

528
529     public InvokeStmt newInvokeStmt(Value op)
530     {
531         return new GInvokeStmt(op);
532     }
533
534     public InvokeStmt newInvokeStmt(InvokeStmt s)
535     {
536         return new GInvokeStmt(s.getInvokeExpr());
537     }
538
539     /**
540         Constructs a TableSwitchStmt(Expr, int, int, List of Unit, Stmt) grammar chunk.
541      */

542
543     public TableSwitchStmt newTableSwitchStmt(Value key, int lowIndex, int highIndex, List targets, Unit defaultTarget)
544     {
545         return new GTableSwitchStmt(key, lowIndex, highIndex, targets, defaultTarget);
546     }
547
548     public TableSwitchStmt newTableSwitchStmt(TableSwitchStmt s)
549     {
550         return new GTableSwitchStmt(s.getKey(), s.getLowIndex(),
551                                     s.getHighIndex(), s.getTargets(),
552                                     s.getDefaultTarget());
553     }
554
555     /**
556         Constructs a LookupSwitchStmt(Expr, List of Expr, List of Unit, Stmt) grammar chunk.
557      */

558
559     public LookupSwitchStmt newLookupSwitchStmt(Value key, List lookupValues, List targets, Unit defaultTarget)
560     {
561         return new GLookupSwitchStmt(key, lookupValues, targets, defaultTarget);
562     }
563
564     public LookupSwitchStmt newLookupSwitchStmt(LookupSwitchStmt s)
565     {
566         return new GLookupSwitchStmt(s.getKey(), s.getLookupValues(),
567                                      s.getTargets(), s.getDefaultTarget());
568     }
569
570     /**
571         Constructs a Local with the given name and type.
572     */

573
574     public Local newLocal(String JavaDoc name, Type t)
575     {
576         return Jimple.v().newLocal(name, t);
577     }
578
579     /**
580         Constructs a new Trap for the given exception on the given Stmt range with the given Stmt handler.
581     */

582
583     public Trap newTrap(SootClass exception, Unit beginStmt, Unit endStmt, Unit handlerStmt)
584     {
585         return new GTrap(exception, beginStmt, endStmt, handlerStmt);
586     }
587
588     public Trap newTrap(Trap trap)
589     {
590         return new GTrap(trap.getException(), trap.getBeginUnit(),
591                          trap.getEndUnit(), trap.getHandlerUnit());
592     }
593
594     /**
595         Constructs a StaticFieldRef(SootFieldRef) grammar chunk.
596      */

597
598     public StaticFieldRef newStaticFieldRef(SootFieldRef f)
599     {
600         return Jimple.v().newStaticFieldRef(f);
601     }
602
603
604     /**
605         Constructs a ThisRef(RefType) grammar chunk.
606      */

607
608     public ThisRef newThisRef(RefType t)
609     {
610         return Jimple.v().newThisRef(t);
611     }
612
613
614     /**
615         Constructs a ParameterRef(SootMethod, int) grammar chunk.
616      */

617
618     public ParameterRef newParameterRef(Type paramType, int number)
619     {
620         return Jimple.v().newParameterRef(paramType, number);
621     }
622
623     /**
624         Constructs a InstanceFieldRef(Value, SootFieldRef) grammar chunk.
625      */

626
627     public InstanceFieldRef newInstanceFieldRef(Value base, SootFieldRef f)
628     {
629         return new GInstanceFieldRef(base, f);
630     }
631
632
633     /**
634         Constructs a CaughtExceptionRef() grammar chunk.
635      */

636
637     public CaughtExceptionRef newCaughtExceptionRef()
638     {
639         return Jimple.v().newCaughtExceptionRef();
640     }
641
642
643     /**
644         Constructs a ArrayRef(Local, Expr) grammar chunk.
645      */

646
647     public ArrayRef newArrayRef(Value base, Value index)
648     {
649         return new GArrayRef(base, index);
650     }
651
652     public ValueBox newVariableBox(Value value)
653     {
654         return Jimple.v().newVariableBox(value);
655     }
656
657     public ValueBox newLocalBox(Value value)
658     {
659         return Jimple.v().newLocalBox(value);
660     }
661
662     public ValueBox newRValueBox(Value value)
663     {
664         return new GRValueBox(value);
665     }
666
667     public ValueBox newImmediateBox(Value value)
668     {
669         return Jimple.v().newImmediateBox(value);
670     }
671
672     public ValueBox newExprBox(Value value)
673     {
674         return new ExprBox(value);
675     }
676
677     public ValueBox newArgBox(Value value)
678     {
679         return new ExprBox(value);
680     }
681
682     public ValueBox newObjExprBox(Value value)
683     {
684         return new ObjExprBox(value);
685     }
686
687     public ValueBox newIdentityRefBox(Value value)
688     {
689         return Jimple.v().newIdentityRefBox(value);
690     }
691
692     public ValueBox newConditionExprBox(Value value)
693     {
694         return Jimple.v().newConditionExprBox(value);
695     }
696
697     public ValueBox newInvokeExprBox(Value value)
698     {
699         return Jimple.v().newInvokeExprBox(value);
700     }
701
702     public UnitBox newStmtBox(Unit unit)
703     {
704         return Jimple.v().newStmtBox((Stmt) unit);
705     }
706
707     /** Carries out the mapping from other Value's to Grimp Value's */
708     public Value newExpr(Value value)
709     {
710         if (value instanceof Expr)
711             {
712                 final ExprBox returnedExpr = new ExprBox(IntConstant.v(0));
713                 ((Expr)value).apply(new AbstractExprSwitch()
714                 {
715                     public void caseAddExpr(AddExpr v)
716                     {
717                         returnedExpr.setValue
718                             (newAddExpr(newExpr(v.getOp1()),
719                                         newExpr(v.getOp2())));
720                     }
721
722                     public void caseAndExpr(AndExpr v)
723                     {
724                         returnedExpr.setValue
725                             (newAndExpr(newExpr(v.getOp1()),
726                                         newExpr(v.getOp2())));
727                     }
728
729                     public void caseCmpExpr(CmpExpr v)
730                     {
731                         returnedExpr.setValue
732                             (newCmpExpr(newExpr(v.getOp1()),
733                                         newExpr(v.getOp2())));
734                     }
735
736                     public void caseCmpgExpr(CmpgExpr v)
737                     {
738                         returnedExpr.setValue
739                             (newCmpgExpr(newExpr(v.getOp1()),
740                                         newExpr(v.getOp2())));
741                     }
742
743                     public void caseCmplExpr(CmplExpr v)
744                     {
745                         returnedExpr.setValue
746                             (newCmplExpr(newExpr(v.getOp1()),
747                                         newExpr(v.getOp2())));
748                     }
749
750                     public void caseDivExpr(DivExpr v)
751                     {
752                         returnedExpr.setValue
753                             (newDivExpr(newExpr(v.getOp1()),
754                                         newExpr(v.getOp2())));
755                     }
756
757                     public void caseEqExpr(EqExpr v)
758                     {
759                         returnedExpr.setValue
760                             (newEqExpr(newExpr(v.getOp1()),
761                                         newExpr(v.getOp2())));
762                     }
763
764                     public void caseNeExpr(NeExpr v)
765                     {
766                         returnedExpr.setValue
767                             (newNeExpr(newExpr(v.getOp1()),
768                                         newExpr(v.getOp2())));
769                     }
770
771                     public void caseGeExpr(GeExpr v)
772                     {
773                         returnedExpr.setValue
774                             (newGeExpr(newExpr(v.getOp1()),
775                                         newExpr(v.getOp2())));
776                     }
777
778                     public void caseGtExpr(GtExpr v)
779                     {
780                         returnedExpr.setValue
781                             (newGtExpr(newExpr(v.getOp1()),
782                                         newExpr(v.getOp2())));
783                     }
784
785                     public void caseLeExpr(LeExpr v)
786                     {
787                         returnedExpr.setValue
788                             (newLeExpr(newExpr(v.getOp1()),
789                                         newExpr(v.getOp2())));
790                     }
791
792                     public void caseLtExpr(LtExpr v)
793                     {
794                         returnedExpr.setValue
795                             (newLtExpr(newExpr(v.getOp1()),
796                                         newExpr(v.getOp2())));
797                     }
798
799                     public void caseMulExpr(MulExpr v)
800                     {
801                         returnedExpr.setValue
802                             (newMulExpr(newExpr(v.getOp1()),
803                                         newExpr(v.getOp2())));
804                     }
805
806                     public void caseOrExpr(OrExpr v)
807                     {
808                         returnedExpr.setValue
809                             (newOrExpr(newExpr(v.getOp1()),
810                                         newExpr(v.getOp2())));
811                     }
812
813                     public void caseRemExpr(RemExpr v)
814                     {
815                         returnedExpr.setValue
816                             (newRemExpr(newExpr(v.getOp1()),
817                                         newExpr(v.getOp2())));
818                     }
819
820                     public void caseShlExpr(ShlExpr v)
821                     {
822                         returnedExpr.setValue
823                             (newShlExpr(newExpr(v.getOp1()),
824                                         newExpr(v.getOp2())));
825                     }
826
827                     public void caseShrExpr(ShrExpr v)
828                     {
829                         returnedExpr.setValue
830                             (newShrExpr(newExpr(v.getOp1()),
831                                         newExpr(v.getOp2())));
832                     }
833
834                     public void caseUshrExpr(UshrExpr v)
835                     {
836                         returnedExpr.setValue
837                             (newUshrExpr(newExpr(v.getOp1()),
838                                         newExpr(v.getOp2())));
839                     }
840
841                     public void caseSubExpr(SubExpr v)
842                     {
843                         returnedExpr.setValue
844                             (newSubExpr(newExpr(v.getOp1()),
845                                         newExpr(v.getOp2())));
846                     }
847
848                     public void caseXorExpr(XorExpr v)
849                     {
850                         returnedExpr.setValue
851                             (newXorExpr(newExpr(v.getOp1()),
852                                         newExpr(v.getOp2())));
853                     }
854
855                     public void caseInterfaceInvokeExpr(InterfaceInvokeExpr v)
856                     {
857                         ArrayList newArgList = new ArrayList();
858                         for (int i = 0; i < v.getArgCount(); i++)
859                             newArgList.add(newExpr(v.getArg(i)));
860                         returnedExpr.setValue
861                             (newInterfaceInvokeExpr((Local)(v.getBase()),
862                                                     v.getMethodRef(),
863                                                     newArgList));
864                     }
865
866                     public void caseSpecialInvokeExpr(SpecialInvokeExpr v)
867                     {
868                         ArrayList newArgList = new ArrayList();
869                         for (int i = 0; i < v.getArgCount(); i++)
870                             newArgList.add(newExpr(v.getArg(i)));
871                         returnedExpr.setValue
872                             (newSpecialInvokeExpr((Local)(v.getBase()),
873                                                     v.getMethodRef(),
874                                                     newArgList));
875                     }
876
877                     public void caseStaticInvokeExpr(StaticInvokeExpr v)
878                     {
879                         ArrayList newArgList = new ArrayList();
880                         for (int i = 0; i < v.getArgCount(); i++)
881                             newArgList.add(newExpr(v.getArg(i)));
882                         returnedExpr.setValue
883                             (newStaticInvokeExpr(v.getMethodRef(),
884                                                  newArgList));
885                     }
886
887                     public void caseVirtualInvokeExpr(VirtualInvokeExpr v)
888                     {
889                         ArrayList newArgList = new ArrayList();
890                         for (int i = 0; i < v.getArgCount(); i++)
891                             newArgList.add(newExpr(v.getArg(i)));
892                         returnedExpr.setValue
893                             (newVirtualInvokeExpr((Local)(v.getBase()),
894                                                   v.getMethodRef(),
895                                                   newArgList));
896                     }
897
898                     public void caseCastExpr(CastExpr v)
899                     {
900                         returnedExpr.setValue(newCastExpr(newExpr(v.getOp()),
901                                                           v.getType()));
902                     }
903
904                     public void caseInstanceOfExpr(InstanceOfExpr v)
905                     {
906                         returnedExpr.setValue(newInstanceOfExpr
907                                               (newExpr(v.getOp()),
908                                                v.getCheckType()));
909                     }
910
911                     public void caseNewArrayExpr(NewArrayExpr v)
912                     {
913                         returnedExpr.setValue(newNewArrayExpr(v.getBaseType(),
914                                               v.getSize()));
915                     }
916
917                     public void caseNewMultiArrayExpr(NewMultiArrayExpr v)
918                      {
919                         returnedExpr.setValue(newNewMultiArrayExpr
920                                               (v.getBaseType(),
921                                               v.getSizes()));
922                     }
923
924                     public void caseNewExpr(NewExpr v)
925                     {
926                         returnedExpr.setValue(newNewExpr(v.getBaseType()));
927                     }
928
929                     public void caseLengthExpr(LengthExpr v)
930                       {
931                         returnedExpr.setValue(newLengthExpr
932                                               (newExpr(v.getOp())));
933                     }
934
935                     public void caseNegExpr(NegExpr v)
936                     {
937                         returnedExpr.setValue(newNegExpr(newExpr(v.getOp())));
938                     }
939
940                     public void defaultCase(Object JavaDoc v)
941                     {
942                         returnedExpr.setValue((Expr)v);
943                     }
944                 });
945                 return returnedExpr.getValue();
946             }
947         else
948             {
949                 if (value instanceof ArrayRef)
950                     return newArrayRef(((ArrayRef)value).getBase(),
951                                        newExpr(((ArrayRef)value).getIndex()));
952                 if (value instanceof InstanceFieldRef)
953                     return newInstanceFieldRef
954                         (newExpr((((InstanceFieldRef)value).getBase())),
955                          ((InstanceFieldRef)value).getFieldRef());
956                 /* have Ref/Value, which is fine -- not Jimple-specific. */
957                 return value;
958             }
959     }
960
961     /** Returns an empty GrimpBody associated with method m. */
962     public GrimpBody newBody(SootMethod m)
963     {
964         return new GrimpBody(m);
965     }
966
967     /** Returns a GrimpBody constructed from b. */
968     public GrimpBody newBody(Body b, String JavaDoc phase)
969     {
970         return new GrimpBody(b);
971     }
972
973     public static Value cloneIfNecessary(Value val)
974     {
975         if( val instanceof Local || val instanceof Constant )
976             return val;
977         else
978             return (Value) val.clone();
979     }
980 }
981
Popular Tags