KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > soot > toolkits > scalar > InitAnalysis


1 /* Soot - a J*va Optimization Framework
2  * Copyright (C) 2004 Ganesh Sittampalam
3  *
4  * This compiler 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 compiler 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 compiler, in the file LESSER-GPL;
16  * if not, write to the Free Software Foundation, Inc.,
17  * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18  */

19
20 package soot.toolkits.scalar;
21
22 import java.util.*;
23 import soot.*;
24 import soot.jimple.*;
25 import soot.util.*;
26 import soot.toolkits.graph.*;
27
28 /** An analysis to check whether or not local variables have been
29  * initialised.
30  * @author Ganesh Sittampalam
31  */

32 public class InitAnalysis extends ForwardFlowAnalysis {
33     FlowSet allLocals;
34
35     public InitAnalysis(UnitGraph g) {
36     super(g);
37     Chain locs=g.getBody().getLocals();
38     allLocals=new ArraySparseSet();
39     Iterator it=locs.iterator();
40     while(it.hasNext()) {
41         Local loc=(Local) it.next();
42         allLocals.add(loc);
43     }
44
45     doAnalysis();
46     }
47
48     protected Object JavaDoc entryInitialFlow() {
49     return new ArraySparseSet();
50     }
51     protected Object JavaDoc newInitialFlow() {
52     FlowSet ret=new ArraySparseSet();
53     allLocals.copy(ret);
54     return ret;
55     }
56
57     protected void flowThrough(Object JavaDoc in,Object JavaDoc unit,Object JavaDoc out) {
58     FlowSet inSet=(FlowSet) in;
59     FlowSet outSet=(FlowSet) out;
60     Stmt s=(Stmt) unit;
61
62     inSet.copy(outSet);
63
64     if(s instanceof DefinitionStmt) {
65         DefinitionStmt ds=(DefinitionStmt) s;
66         if(ds.getLeftOp() instanceof Local) {
67         Local l=(Local) ds.getLeftOp();
68         outSet.add(l);
69         }
70     }
71     }
72
73     protected void merge(Object JavaDoc in1,Object JavaDoc in2,Object JavaDoc out) {
74     FlowSet outSet=(FlowSet) out;
75     FlowSet inSet1=(FlowSet) in1;
76     FlowSet inSet2=(FlowSet) in2;
77     inSet1.intersection(inSet2,outSet);
78     }
79
80     protected void copy(Object JavaDoc source,Object JavaDoc dest) {
81     FlowSet sourceSet=(FlowSet) source;
82     FlowSet destSet=(FlowSet) dest;
83     sourceSet.copy(destSet);
84     }
85     
86
87 }
88
Popular Tags