KickJava   Java API By Example, From Geeks To Geeks.

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


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 java.util.BitSet JavaDoc;
23
24 import org.apache.bcel.classfile.Method;
25
26 import edu.umd.cs.findbugs.SystemProperties;
27
28 /**
29  * Dataflow analysis to compute postdominator sets for a CFG.
30  *
31  * @author David Hovemeyer
32  * @see CFG
33  * @see AbstractDominatorsAnalysis
34  */

35 public class PostDominatorsAnalysis extends AbstractDominatorsAnalysis {
36     final private ReverseDepthFirstSearch rdfs;
37     final private DepthFirstSearch dfs;
38     
39     /**
40      * Constructor.
41      *
42      * @param cfg the CFG to compute dominator relationships for
43      * @param rdfs the ReverseDepthFirstSearch on the CFG
44      * @param dfs TODO
45      * @param edgeChooser EdgeChooser to choose which Edges to consider significant
46      */

47     public PostDominatorsAnalysis(CFG cfg, ReverseDepthFirstSearch rdfs, DepthFirstSearch dfs, EdgeChooser edgeChooser) {
48         super(cfg, edgeChooser);
49         this.rdfs = rdfs;
50         this.dfs = dfs;
51     }
52
53     /**
54      * Constructor.
55      *
56      * @param cfg the CFG to compute dominator relationships for
57      * @param rdfs the ReverseDepthFirstSearch on the CFG
58      * @param dfs TODO
59      * @param ignoreExceptionEdges true if exception edges should be ignored
60      */

61     public PostDominatorsAnalysis(CFG cfg, ReverseDepthFirstSearch rdfs,
62                                   DepthFirstSearch dfs, boolean ignoreExceptionEdges) {
63         super(cfg, ignoreExceptionEdges);
64         this.rdfs = rdfs;
65         this.dfs = dfs;
66     }
67
68     public boolean isForwards() {
69         return false;
70     }
71
72     public BlockOrder getBlockOrder(CFG cfg) {
73         return new ReverseDFSOrder(cfg, rdfs, dfs);
74     }
75     
76     public static void main(String JavaDoc[] args) throws Exception JavaDoc {
77         if (args.length != 1) {
78             System.err.println("Usage: " + PostDominatorsAnalysis.class.getName() + " <classfile>");
79             System.exit(1);
80         }
81         
82         DataflowTestDriver<BitSet JavaDoc, PostDominatorsAnalysis> driver =
83             new DataflowTestDriver<BitSet JavaDoc, PostDominatorsAnalysis>() {
84             
85             /* (non-Javadoc)
86              * @see edu.umd.cs.findbugs.ba.DataflowTestDriver#createDataflow(edu.umd.cs.findbugs.ba.ClassContext, org.apache.bcel.classfile.Method)
87              */

88             @Override JavaDoc
89             public Dataflow<BitSet JavaDoc, PostDominatorsAnalysis> createDataflow(ClassContext classContext, Method method) throws CFGBuilderException, DataflowAnalysisException {
90                 CFG cfg = classContext.getCFG(method);
91                 ReverseDepthFirstSearch rdfs = classContext.getReverseDepthFirstSearch(method);
92                 
93                 PostDominatorsAnalysis analysis =
94                     new PostDominatorsAnalysis(cfg, rdfs, classContext.getDepthFirstSearch(method), SystemProperties.getBoolean("dominators.ignoreexceptionedges"));
95             
96                 Dataflow<BitSet JavaDoc, PostDominatorsAnalysis> dataflow =
97                     new Dataflow<BitSet JavaDoc, PostDominatorsAnalysis>(cfg, analysis);
98                 
99                 dataflow.execute();
100                 
101                 return dataflow;
102             }
103             
104         };
105         
106         driver.execute(args[0]);
107     }
108 }
109
110 // vim:ts=4
111
Popular Tags