KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > edu > umd > cs > findbugs > ba > DataflowAnalysis


1 /*
2  * Bytecode Analysis Framework
3  * Copyright (C) 2003,2004 University of Maryland
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library 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 library; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18  */

19
20 package edu.umd.cs.findbugs.ba;
21
22 import org.apache.bcel.generic.InstructionHandle;
23 import edu.umd.cs.findbugs.annotations.*;
24
25 /**
26  * A dataflow analysis to be used with the {@link Dataflow} class.
27  *
28  * @author David Hovemeyer
29  * @see Dataflow
30  */

31 public interface DataflowAnalysis <Fact> {
32     /**
33      * Create empty (uninitialized) dataflow facts for one program point.
34      * A valid value will be copied into it before it is used.
35      */

36     public Fact createFact();
37
38     
39     /**
40      * Get the start fact for given basic block.
41      *
42      * @param block the basic block
43      */

44     public Fact getStartFact(BasicBlock block);
45
46     /**
47      * Get the result fact for given basic block.
48      *
49      * @param block the basic block
50      */

51     public Fact getResultFact(BasicBlock block);
52
53     /**
54      * Copy dataflow facts.
55      */

56     public void copy(Fact source, Fact dest);
57
58     /**
59      * Initialize the "entry" fact for the graph.
60      */

61     public void initEntryFact(Fact result) throws DataflowAnalysisException;
62
63     /**
64      * Initialize result fact for block.
65      * The start facts for a block are initialized as the meet of the
66      * "logical" predecessor's result facts. Note that a "logical predecessor"
67      * is actually a CFG successor if the analysis is backwards.
68      */

69     public void initResultFact(Fact result);
70
71     /**
72      * Make given fact the top value.
73      */

74     public void makeFactTop(Fact fact);
75
76     /**
77      * Is the given fact the top value.
78      */

79     public boolean isTop(Fact fact);
80     /**
81      * Returns true if the analysis is forwards, false if backwards.
82      */

83     public boolean isForwards();
84
85     /**
86      * Return the BlockOrder specifying the order in which BasicBlocks
87      * should be visited in the main dataflow loop.
88      *
89      * @param cfg the CFG upon which we're performing dataflow analysis
90      */

91     public BlockOrder getBlockOrder(CFG cfg);
92
93     /**
94      * Are given dataflow facts the same?
95      */

96     public boolean same(Fact fact1, Fact fact2);
97
98     /**
99      * Transfer function for the analysis.
100      * Taking dataflow facts at start (which might be either the entry or
101      * exit of the block, depending on whether the analysis is forwards
102      * or backwards), modify result to be the facts at the other end
103      * of the block.
104      *
105      * @param basicBlock the basic block
106      * @param end if nonnull, stop before considering this instruction;
107      * otherwise, consider all of the instructions in the basic block
108      * @param start dataflow facts at beginning of block (if forward analysis)
109      * or end of block (if backwards analysis)
110      * @param result resulting dataflow facts at other end of block
111      */

112     public void transfer(BasicBlock basicBlock, @CheckForNull InstructionHandle end, Fact start, Fact result) throws DataflowAnalysisException;
113
114     /**
115      * Edge transfer function.
116      * Modify the given fact that is true on the (logical) edge source
117      * to modify it so that it is true at the (logical) edge target.
118      *
119      * <p>
120      * A do-nothing implementation is legal, and appropriate for
121      * analyses where branches are not significant.
122      * </p>
123      *
124      * @param edge the Edge
125      * @param fact a dataflow fact
126      * @throws DataflowAnalysisException
127      */

128     public void edgeTransfer(Edge edge, Fact fact) throws DataflowAnalysisException;
129     
130     /**
131      * Meet a dataflow fact associated with an incoming edge into another fact.
132      * This is used to determine the start fact for a basic block.
133      *
134      * @param fact the predecessor fact (incoming edge)
135      * @param edge the edge from the predecessor
136      * @param result the result fact
137      */

138     public void meetInto(Fact fact, Edge edge, Fact result) throws DataflowAnalysisException;
139     
140     /**
141      * Called before beginning an iteration of analysis.
142      * Each iteration visits every basic block in the CFG.
143      */

144     public void startIteration();
145
146     /**
147      * Called after finishing an iteration of analysis.
148      */

149     public void finishIteration();
150     
151     public int getLastUpdateTimestamp(Fact fact);
152     
153     public void setLastUpdateTimestamp(Fact fact, int timestamp);
154 }
155
156 // vim:ts=4
157
Popular Tags