KickJava   Java API By Example, From Geeks To Geeks.

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


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

38 public class DominatorsAnalysis extends AbstractDominatorsAnalysis {
39     private DepthFirstSearch dfs;
40
41     /**
42      * Constructor.
43      *
44      * @param cfg the CFG to compute dominator relationships for
45      * @param dfs the DepthFirstSearch on the CFG
46      * @param ignoreExceptionEdges true if exception edges should be ignored
47      */

48     public DominatorsAnalysis(CFG cfg, DepthFirstSearch dfs, boolean ignoreExceptionEdges) {
49         super(cfg, ignoreExceptionEdges);
50         this.dfs = dfs;
51     }
52
53     public boolean isForwards() {
54         return true;
55     }
56
57     public BlockOrder getBlockOrder(CFG cfg) {
58         return new ReversePostOrder(cfg, dfs);
59     }
60
61     public static void main(String JavaDoc[] argv) throws Exception JavaDoc {
62         if (argv.length != 1) {
63             System.err.println("Usage: " + DominatorsAnalysis.class.getName() + " <classfile>");
64             System.exit(1);
65         }
66         
67         DataflowTestDriver<BitSet JavaDoc, DominatorsAnalysis> driver =
68             new DataflowTestDriver<BitSet JavaDoc, DominatorsAnalysis>() {
69             
70             /* (non-Javadoc)
71              * @see edu.umd.cs.findbugs.ba.DataflowTestDriver#createDataflow(edu.umd.cs.findbugs.ba.ClassContext, org.apache.bcel.classfile.Method)
72              */

73             @Override JavaDoc
74             public Dataflow<BitSet JavaDoc, DominatorsAnalysis> createDataflow(ClassContext classContext, Method method) throws CFGBuilderException, DataflowAnalysisException {
75                 CFG cfg = classContext.getCFG(method);
76                 DepthFirstSearch dfs = classContext.getDepthFirstSearch(method);
77                 
78                 DominatorsAnalysis analysis =
79                     new DominatorsAnalysis(cfg, dfs, SystemProperties.getBoolean("dominators.ignoreexceptionedges"));
80             
81                 Dataflow<BitSet JavaDoc, DominatorsAnalysis> dataflow =
82                     new Dataflow<BitSet JavaDoc, DominatorsAnalysis>(cfg, analysis);
83                 
84                 dataflow.execute();
85                 
86                 return dataflow;
87             }
88             
89         };
90         
91         driver.execute(argv[0]);
92     }
93 }
94
95 // vim:ts=4
96
Popular Tags