KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > soot > jimple > JimpleBody


1 /* Soot - a J*va Optimization Framework
2  * Copyright (C) 1997-1999 Raja Vallee-Rai
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  * contributors. (Soot is distributed at http://www.sable.mcgill.ca/soot)
24  */

25
26 package soot.jimple;
27
28 import soot.*;
29 import soot.toolkits.scalar.*;
30 import soot.util.*;
31 import java.util.*;
32 import java.io.*;
33
34 /** Implementation of the Body class for the Jimple IR. */
35 public class JimpleBody extends StmtBody
36 {
37     /**
38         Construct an empty JimpleBody
39      **/

40     
41     JimpleBody(SootMethod m)
42     {
43         super(m);
44     }
45
46     /**
47        Construct an extremely empty JimpleBody, for parsing into.
48     **/

49
50     JimpleBody()
51     {
52     }
53
54     /** Clones the current body, making deep copies of the contents. */
55     public Object JavaDoc clone()
56     {
57         Body b = new JimpleBody(getMethod());
58         b.importBodyContentsFrom(this);
59         return b;
60     }
61
62     /** Make sure that the JimpleBody is well formed. If not, throw
63      * an exception. Right now, performs only a handful of checks.
64      */

65     public void validate()
66     {
67         super.validate();
68
69         // Check validity of traps.
70
/* this check may not hold when jop.bcm is enabled.
71      * disabled by Feng Qian, May 2002
72          */

73     /*
74         {
75             Iterator it = getTraps().iterator();
76             
77             while(it.hasNext())
78             {
79                 Trap t = (Trap) it.next();
80                 
81                 Stmt s = (Stmt) t.getHandlerUnit();
82                                 
83                 if(!(s instanceof IdentityStmt)
84            || !(((IdentityStmt) s).getRightOp() instanceof CaughtExceptionRef)){
85                     G.v().out.println(s);
86                     throw new RuntimeException("Trap handler is not of the form x := caughtexceptionref");
87                 }
88             }
89         }
90     */

91     }
92     
93     /** Inserts usual statements for handling this & parameters into body. */
94     public void insertIdentityStmts()
95     {
96         int i = 0;
97
98         if (!getMethod().isStatic())
99          {
100              Local l = Jimple.v().newLocal("this",
101                                            RefType.v(getMethod().getDeclaringClass()));
102              getLocals().add(l);
103              getUnits().addFirst(Jimple.v().newIdentityStmt(l, Jimple.v().newThisRef((RefType)l.getType())));
104          }
105
106         Iterator parIt = getMethod().getParameterTypes().iterator();
107         while (parIt.hasNext())
108         {
109             Type t = (Type)parIt.next();
110             Local l = Jimple.v().newLocal("parameter"+i, t);
111             getLocals().add(l);
112             getUnits().addFirst(Jimple.v().newIdentityStmt(l, Jimple.v().newParameterRef(l.getType(), i)));
113             i++;
114         }
115     }
116
117     /** Returns the first non-identity stmt in this body. */
118     public Stmt getFirstNonIdentityStmt()
119     {
120         Iterator it = getUnits().iterator();
121         Object JavaDoc o = null;
122         while (it.hasNext())
123             if (!((o = it.next()) instanceof IdentityStmt))
124                 break;
125         if (o == null)
126             throw new RuntimeException JavaDoc("no non-id statements!");
127         return (Stmt)o;
128     }
129 }
130
131
132
133
Popular Tags