01: /* Soot - a J*va Optimization Framework
02: * Copyright (C) 2004 Ganesh Sittampalam
03: * Copyright (C) 2007 Eric Bodden
04: *
05: * This compiler is free software; you can redistribute it and/or
06: * modify it under the terms of the GNU Lesser General Public
07: * License as published by the Free Software Foundation; either
08: * version 2.1 of the License, or (at your option) any later version.
09: *
10: * This compiler 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 compiler, in the file LESSER-GPL;
17: * if not, write to the Free Software Foundation, Inc.,
18: * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19: */
20:
21: package soot.toolkits.scalar;
22:
23: import java.util.Iterator;
24: import java.util.List;
25:
26: import soot.Local;
27: import soot.Unit;
28: import soot.Value;
29: import soot.ValueBox;
30: import soot.toolkits.graph.UnitGraph;
31: import soot.util.Chain;
32:
33: /**
34: * An analysis to check whether or not local variables have been initialised.
35: *
36: * @author Ganesh Sittampalam
37: * @author Eric Bodden
38: */
39: public class InitAnalysis extends ForwardFlowAnalysis {
40: FlowSet allLocals;
41:
42: public InitAnalysis(UnitGraph g) {
43: super (g);
44: Chain locs = g.getBody().getLocals();
45: allLocals = new ArraySparseSet();
46: Iterator it = locs.iterator();
47: while (it.hasNext()) {
48: Local loc = (Local) it.next();
49: allLocals.add(loc);
50: }
51:
52: doAnalysis();
53: }
54:
55: protected Object entryInitialFlow() {
56: return new ArraySparseSet();
57: }
58:
59: protected Object newInitialFlow() {
60: FlowSet ret = new ArraySparseSet();
61: allLocals.copy(ret);
62: return ret;
63: }
64:
65: protected void flowThrough(Object in, Object unit, Object out) {
66: FlowSet inSet = (FlowSet) in;
67: FlowSet outSet = (FlowSet) out;
68: Unit s = (Unit) unit;
69:
70: inSet.copy(outSet);
71:
72: List<ValueBox> defBoxes = s.getDefBoxes();
73: for (ValueBox defBox : defBoxes) {
74: Value lhs = defBox.getValue();
75: if (lhs instanceof Local) {
76: outSet.add(lhs);
77: }
78: }
79: }
80:
81: protected void merge(Object in1, Object in2, Object out) {
82: FlowSet outSet = (FlowSet) out;
83: FlowSet inSet1 = (FlowSet) in1;
84: FlowSet inSet2 = (FlowSet) in2;
85: inSet1.intersection(inSet2, outSet);
86: }
87:
88: protected void copy(Object source, Object dest) {
89: FlowSet sourceSet = (FlowSet) source;
90: FlowSet destSet = (FlowSet) dest;
91: sourceSet.copy(destSet);
92: }
93:
94: }
|