KickJava   Java API By Example, From Geeks To Geeks.

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


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
27 package soot.toolkits.scalar;
28
29 import soot.*;
30 import soot.toolkits.graph.*;
31 import soot.util.*;
32 import java.util.*;
33 import soot.options.*;
34 import soot.toolkits.graph.interaction.*;
35
36 /** An abstract class providing a metaframework for carrying out
37  * dataflow analysis. This class provides common methods and fields
38  * required by the BranchedFlowAnalysis and FlowAnalysis abstract classes.
39  */

40 public abstract class AbstractFlowAnalysis
41 {
42     /** Maps graph nodes to IN sets. */
43     protected Map unitToBeforeFlow;
44
45     /** Filtered: Maps graph nodes to IN sets. */
46     protected Map filterUnitToBeforeFlow;
47
48     /** The graph being analysed. */
49     protected DirectedGraph graph;
50
51     /** Constructs a flow analysis on the given <code>DirectedGraph</code>. */
52     public AbstractFlowAnalysis(DirectedGraph graph)
53     {
54         unitToBeforeFlow = new HashMap(graph.size() * 2 + 1, 0.7f);
55         this.graph = graph;
56         if (Options.v().interactive_mode()){
57             InteractionHandler.v().handleCfgEvent(graph);
58         }
59     }
60
61     /**
62      * Returns the flow object corresponding to the initial values for
63      * each graph node.
64      */

65     protected abstract Object JavaDoc newInitialFlow();
66
67     /**
68      * Returns the initial flow value for entry/exit graph nodes.
69      */

70     protected abstract Object JavaDoc entryInitialFlow();
71
72     /**
73      * We hereby retract the API for customizeInitialFlowGraph().
74      */

75     protected final void customizeInitialFlowGraph() {}
76
77     /**
78      * Determines whether <code>entryInitialFlow()</code>
79      * is applied to trap handlers.
80      */

81     protected boolean treatTrapHandlersAsEntries() { return false; }
82
83     /** Returns true if this analysis is forwards. */
84     protected abstract boolean isForward();
85
86     /** Compute the merge of the <code>in1</code> and <code>in2</code> sets, putting the result into <code>out</code>.
87      * The behavior of this function depends on the implementation ( it may be necessary to check whether
88      * <code>in1</code> and <code>in2</code> are equal or aliased ).
89      * Used by the doAnalysis method. */

90     protected abstract void merge(Object JavaDoc in1, Object JavaDoc in2, Object JavaDoc out);
91
92     /** Creates a copy of the <code>source</code> flow object in <code>dest</code>. */
93     protected abstract void copy(Object JavaDoc source, Object JavaDoc dest);
94
95     /** Carries out the actual flow analysis.
96      * Typically called from a concrete FlowAnalysis's constructor.*/

97     protected abstract void doAnalysis();
98
99     /** Accessor function returning value of IN set for s. */
100     public Object JavaDoc getFlowBefore(Object JavaDoc s)
101     {
102         return unitToBeforeFlow.get(s);
103     }
104
105     protected void merge(Object JavaDoc inout, Object JavaDoc in) {
106         Object JavaDoc tmp = newInitialFlow();
107         merge(inout, in, tmp);
108         copy(tmp, inout);
109     }
110 }
111
Popular Tags