01: /* Soot - a J*va Optimization Framework
02: * Copyright (C) 1997-2000 Etienne Gagnon. All rights reserved.
03: *
04: * This library is free software; you can redistribute it and/or
05: * modify it under the terms of the GNU Lesser General Public
06: * License as published by the Free Software Foundation; either
07: * version 2.1 of the License, or (at your option) any later version.
08: *
09: * 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.toolkits.typing;
27:
28: import soot.*;
29: import soot.options.*;
30: import soot.jimple.*;
31: import java.util.*;
32:
33: /**
34: * This transformer assigns types to local variables.
35: **/
36: public class TypeAssigner extends BodyTransformer {
37: public TypeAssigner(Singletons.Global g) {
38: }
39:
40: public static TypeAssigner v() {
41: return G.v().soot_jimple_toolkits_typing_TypeAssigner();
42: }
43:
44: /** Assign types to local variables. **/
45: protected void internalTransform(Body b, String phaseName,
46: Map options) {
47: if (b == null) {
48: throw new NullPointerException();
49: }
50:
51: Date start = new Date();
52:
53: if (Options.v().verbose())
54: G.v().out
55: .println("[TypeAssigner] typing system started on "
56: + start);
57:
58: TypeResolver.resolve((JimpleBody) b, Scene.v());
59:
60: Date finish = new Date();
61: if (Options.v().verbose()) {
62: long runtime = finish.getTime() - start.getTime();
63: long mins = runtime / 60000;
64: long secs = (runtime % 60000) / 1000;
65: G.v().out
66: .println("[TypeAssigner] typing system ended. It took "
67: + mins + " mins and " + secs + " secs.");
68: }
69:
70: if (typingFailed((JimpleBody) b))
71: throw new RuntimeException("type inference failed!");
72: }
73:
74: private boolean typingFailed(JimpleBody b) {
75: // Check to see if any locals are untyped
76: {
77: Iterator localIt = b.getLocals().iterator();
78:
79: while (localIt.hasNext()) {
80: Local l = (Local) localIt.next();
81:
82: if (l.getType().equals(UnknownType.v())
83: || l.getType().equals(ErroneousType.v())) {
84: return true;
85: }
86: }
87: }
88:
89: return false;
90: }
91:
92: }
|