KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > soot > jimple > toolkits > typing > TypeAssigner


1 /* Soot - a J*va Optimization Framework
2  * Copyright (C) 1997-2000 Etienne Gagnon. All rights reserved.
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
27 package soot.jimple.toolkits.typing;
28
29 import soot.*;
30 import soot.options.*;
31 import soot.jimple.*;
32 import soot.util.*;
33 import java.util.*;
34 import java.util.*;
35
36 /**
37  * This transformer assigns types to local variables.
38  **/

39 public class TypeAssigner extends BodyTransformer
40 {
41     public TypeAssigner( Singletons.Global g ) {}
42     public static TypeAssigner v() { return G.v().soot_jimple_toolkits_typing_TypeAssigner(); }
43
44   /** Assign types to local variables. **/
45   protected void internalTransform(Body b, String JavaDoc phaseName, Map options)
46   {
47     if(b == null)
48       {
49     throw new NullPointerException JavaDoc();
50       }
51
52     Date start = new Date();
53     
54     if (Options.v().verbose())
55       G.v().out.println("[TypeAssigner] typing system started on "+start);
56
57     TypeResolver.resolve((JimpleBody)b, Scene.v());
58
59     Date finish = new Date();
60     if (Options.v().verbose())
61       {
62     long runtime = finish.getTime()-start.getTime();
63     long mins = runtime/60000;
64     long secs = (runtime%60000)/1000;
65     G.v().out.println("[TypeAssigner] typing system ended. It took "+mins+" mins and "+secs+" secs.");
66       }
67
68     if(typingFailed((JimpleBody) b))
69       throw new RuntimeException JavaDoc("type inference failed!");
70   }
71     private boolean typingFailed(JimpleBody b)
72     {
73         // Check to see if any locals are untyped
74
{
75             Iterator localIt = b.getLocals().iterator();
76
77             while(localIt.hasNext())
78             {
79                 Local l = (Local) localIt.next();
80
81                   if(l.getType().equals(UnknownType.v()) ||
82                     l.getType().equals(ErroneousType.v()))
83                 {
84           return true;
85                 }
86             }
87         }
88         
89         return false;
90     }
91
92
93 }
94
95
Popular Tags