001: /*
002: * Bytecode Analysis Framework
003: * Copyright (C) 2003,2004 University of Maryland
004: *
005: * This library is free software; you can redistribute it and/or
006: * modify it under the terms of the GNU Lesser General Public
007: * License as published by the Free Software Foundation; either
008: * version 2.1 of the License, or (at your option) any later version.
009: *
010: * This library is distributed in the hope that it will be useful,
011: * but WITHOUT ANY WARRANTY; without even the implied warranty of
012: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
013: * Lesser General Public License for more details.
014: *
015: * You should have received a copy of the GNU Lesser General Public
016: * License along with this library; if not, write to the Free Software
017: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
018: */
019:
020: package edu.umd.cs.findbugs.ba;
021:
022: import java.util.BitSet;
023:
024: import org.apache.bcel.classfile.Method;
025:
026: import edu.umd.cs.findbugs.SystemProperties;
027:
028: /**
029: * Dataflow analysis to compute postdominator sets for a CFG.
030: *
031: * @author David Hovemeyer
032: * @see CFG
033: * @see AbstractDominatorsAnalysis
034: */
035: public class PostDominatorsAnalysis extends AbstractDominatorsAnalysis {
036: final private ReverseDepthFirstSearch rdfs;
037: final private DepthFirstSearch dfs;
038:
039: /**
040: * Constructor.
041: *
042: * @param cfg the CFG to compute dominator relationships for
043: * @param rdfs the ReverseDepthFirstSearch on the CFG
044: * @param dfs the DepthFirstSearch on the CFG
045: * @param edgeChooser EdgeChooser to choose which Edges to consider significant
046: */
047: protected PostDominatorsAnalysis(CFG cfg,
048: ReverseDepthFirstSearch rdfs, DepthFirstSearch dfs,
049: EdgeChooser edgeChooser) {
050: super (cfg, edgeChooser);
051: this .rdfs = rdfs;
052: this .dfs = dfs;
053: }
054:
055: /**
056: * Constructor.
057: *
058: * @param cfg the CFG to compute dominator relationships for
059: * @param rdfs the ReverseDepthFirstSearch on the CFG
060: * @param dfs the DepthFirstSearch on the CFG
061: * @param ignoreExceptionEdges true if exception edges should be ignored
062: */
063: protected PostDominatorsAnalysis(CFG cfg,
064: ReverseDepthFirstSearch rdfs, DepthFirstSearch dfs,
065: boolean ignoreExceptionEdges) {
066: super (cfg, ignoreExceptionEdges);
067: this .rdfs = rdfs;
068: this .dfs = dfs;
069: }
070:
071: public boolean isForwards() {
072: return false;
073: }
074:
075: public BlockOrder getBlockOrder(CFG cfg) {
076: return new ReverseDFSOrder(cfg, rdfs, dfs);
077: }
078:
079: public static void main(String[] args) throws Exception {
080: if (args.length != 1) {
081: System.err.println("Usage: "
082: + PostDominatorsAnalysis.class.getName()
083: + " <classfile>");
084: System.exit(1);
085: }
086:
087: DataflowTestDriver<BitSet, PostDominatorsAnalysis> driver = new DataflowTestDriver<BitSet, PostDominatorsAnalysis>() {
088:
089: /* (non-Javadoc)
090: * @see edu.umd.cs.findbugs.ba.DataflowTestDriver#createDataflow(edu.umd.cs.findbugs.ba.ClassContext, org.apache.bcel.classfile.Method)
091: */
092: @Override
093: public Dataflow<BitSet, PostDominatorsAnalysis> createDataflow(
094: ClassContext classContext, Method method)
095: throws CFGBuilderException,
096: DataflowAnalysisException {
097: CFG cfg = classContext.getCFG(method);
098: ReverseDepthFirstSearch rdfs = classContext
099: .getReverseDepthFirstSearch(method);
100:
101: PostDominatorsAnalysis analysis = new PostDominatorsAnalysis(
102: cfg,
103: rdfs,
104: classContext.getDepthFirstSearch(method),
105: SystemProperties
106: .getBoolean("dominators.ignoreexceptionedges"));
107:
108: Dataflow<BitSet, PostDominatorsAnalysis> dataflow = new Dataflow<BitSet, PostDominatorsAnalysis>(
109: cfg, analysis);
110:
111: dataflow.execute();
112:
113: return dataflow;
114: }
115:
116: };
117:
118: driver.execute(args[0]);
119: }
120: }
121:
122: // vim:ts=4
|